1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2007-2013 Broadcom Corporation.
4 * Eric Davis <edavis@broadcom.com>
5 * David Christensen <davidch@broadcom.com>
6 * Gary Zambrano <zambrano@broadcom.com>
8 * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
9 * Copyright (c) 2015-2018 Cavium Inc.
10 * All rights reserved.
14 #define BNX2X_DRIVER_VERSION "1.78.18"
17 #include "bnx2x_vfpf.h"
19 #include "ecore_init.h"
20 #include "ecore_init_ops.h"
22 #include "rte_version.h"
24 #include <sys/types.h>
28 #include <rte_string_fns.h>
30 #define BNX2X_PMD_VER_PREFIX "BNX2X PMD"
31 #define BNX2X_PMD_VERSION_MAJOR 1
32 #define BNX2X_PMD_VERSION_MINOR 0
33 #define BNX2X_PMD_VERSION_REVISION 7
34 #define BNX2X_PMD_VERSION_PATCH 1
36 static inline const char *
37 bnx2x_pmd_version(void)
39 static char version[32];
41 snprintf(version, sizeof(version), "%s %s_%d.%d.%d.%d",
44 BNX2X_PMD_VERSION_MAJOR,
45 BNX2X_PMD_VERSION_MINOR,
46 BNX2X_PMD_VERSION_REVISION,
47 BNX2X_PMD_VERSION_PATCH);
52 static z_stream zlib_stream;
54 #define EVL_VLID_MASK 0x0FFF
56 #define BNX2X_DEF_SB_ATT_IDX 0x0001
57 #define BNX2X_DEF_SB_IDX 0x0002
60 * FLR Support - bnx2x_pf_flr_clnup() is called during nic_load in the per
61 * function HW initialization.
63 #define FLR_WAIT_USEC 10000 /* 10 msecs */
64 #define FLR_WAIT_INTERVAL 50 /* usecs */
65 #define FLR_POLL_CNT (FLR_WAIT_USEC / FLR_WAIT_INTERVAL) /* 200 */
67 struct pbf_pN_buf_regs {
74 struct pbf_pN_cmd_regs {
80 /* resources needed for unloading a previously loaded device */
82 #define BNX2X_PREV_WAIT_NEEDED 1
83 rte_spinlock_t bnx2x_prev_mtx;
84 struct bnx2x_prev_list_node {
85 LIST_ENTRY(bnx2x_prev_list_node) node;
93 static LIST_HEAD(, bnx2x_prev_list_node) bnx2x_prev_list
94 = LIST_HEAD_INITIALIZER(bnx2x_prev_list);
96 static int load_count[2][3] = { { 0 } };
97 /* per-path: 0-common, 1-port0, 2-port1 */
99 static void bnx2x_cmng_fns_init(struct bnx2x_softc *sc, uint8_t read_cfg,
101 static int bnx2x_get_cmng_fns_mode(struct bnx2x_softc *sc);
102 static void storm_memset_cmng(struct bnx2x_softc *sc, struct cmng_init *cmng,
104 static void bnx2x_set_reset_global(struct bnx2x_softc *sc);
105 static void bnx2x_set_reset_in_progress(struct bnx2x_softc *sc);
106 static uint8_t bnx2x_reset_is_done(struct bnx2x_softc *sc, int engine);
107 static uint8_t bnx2x_clear_pf_load(struct bnx2x_softc *sc);
108 static uint8_t bnx2x_chk_parity_attn(struct bnx2x_softc *sc, uint8_t * global,
110 static void bnx2x_int_disable(struct bnx2x_softc *sc);
111 static int bnx2x_release_leader_lock(struct bnx2x_softc *sc);
112 static void bnx2x_pf_disable(struct bnx2x_softc *sc);
113 static void bnx2x_update_rx_prod(struct bnx2x_softc *sc,
114 struct bnx2x_fastpath *fp,
115 uint16_t rx_bd_prod, uint16_t rx_cq_prod);
116 static void bnx2x_link_report_locked(struct bnx2x_softc *sc);
117 static void bnx2x_link_report(struct bnx2x_softc *sc);
118 void bnx2x_link_status_update(struct bnx2x_softc *sc);
119 static int bnx2x_alloc_mem(struct bnx2x_softc *sc);
120 static void bnx2x_free_mem(struct bnx2x_softc *sc);
121 static int bnx2x_alloc_fw_stats_mem(struct bnx2x_softc *sc);
122 static void bnx2x_free_fw_stats_mem(struct bnx2x_softc *sc);
123 static __rte_noinline
124 int bnx2x_nic_load(struct bnx2x_softc *sc);
126 static int bnx2x_handle_sp_tq(struct bnx2x_softc *sc);
127 static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp);
128 static void bnx2x_ack_sb(struct bnx2x_softc *sc, uint8_t igu_sb_id,
129 uint8_t storm, uint16_t index, uint8_t op,
132 int bnx2x_test_bit(int nr, volatile unsigned long *addr)
137 res = ((*addr) & (1UL << nr)) != 0;
142 void bnx2x_set_bit(unsigned int nr, volatile unsigned long *addr)
144 __sync_fetch_and_or(addr, (1UL << nr));
147 void bnx2x_clear_bit(int nr, volatile unsigned long *addr)
149 __sync_fetch_and_and(addr, ~(1UL << nr));
152 int bnx2x_test_and_clear_bit(int nr, volatile unsigned long *addr)
154 unsigned long mask = (1UL << nr);
155 return __sync_fetch_and_and(addr, ~mask) & mask;
158 int bnx2x_cmpxchg(volatile int *addr, int old, int new)
160 return __sync_val_compare_and_swap(addr, old, new);
164 bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma,
165 const char *msg, uint32_t align)
167 char mz_name[RTE_MEMZONE_NAMESIZE];
168 const struct rte_memzone *z;
172 snprintf(mz_name, sizeof(mz_name), "bnx2x%d_%s_%" PRIx64, SC_ABS_FUNC(sc), msg,
173 rte_get_timer_cycles());
175 snprintf(mz_name, sizeof(mz_name), "bnx2x%d_%s_%" PRIx64, sc->pcie_device, msg,
176 rte_get_timer_cycles());
178 /* Caller must take care that strlen(mz_name) < RTE_MEMZONE_NAMESIZE */
179 z = rte_memzone_reserve_aligned(mz_name, (uint64_t)size,
181 RTE_MEMZONE_IOVA_CONTIG, align);
183 PMD_DRV_LOG(ERR, sc, "DMA alloc failed for %s", msg);
186 dma->paddr = (uint64_t) z->iova;
187 dma->vaddr = z->addr;
188 dma->mzone = (const void *)z;
190 PMD_DRV_LOG(DEBUG, sc,
191 "%s: virt=%p phys=%" PRIx64, msg, dma->vaddr, dma->paddr);
196 void bnx2x_dma_free(struct bnx2x_dma *dma)
198 if (dma->mzone == NULL)
201 rte_memzone_free((const struct rte_memzone *)dma->mzone);
209 static int bnx2x_acquire_hw_lock(struct bnx2x_softc *sc, uint32_t resource)
211 uint32_t lock_status;
212 uint32_t resource_bit = (1 << resource);
213 int func = SC_FUNC(sc);
214 uint32_t hw_lock_control_reg;
217 #ifndef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
219 PMD_INIT_FUNC_TRACE(sc);
221 PMD_INIT_FUNC_TRACE(sc);
224 /* validate the resource is within range */
225 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
226 PMD_DRV_LOG(NOTICE, sc,
227 "resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE",
233 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
235 hw_lock_control_reg =
236 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
239 /* validate the resource is not already taken */
240 lock_status = REG_RD(sc, hw_lock_control_reg);
241 if (lock_status & resource_bit) {
242 PMD_DRV_LOG(NOTICE, sc,
243 "resource in use (status 0x%x bit 0x%x)",
244 lock_status, resource_bit);
248 /* try every 5ms for 5 seconds */
249 for (cnt = 0; cnt < 1000; cnt++) {
250 REG_WR(sc, (hw_lock_control_reg + 4), resource_bit);
251 lock_status = REG_RD(sc, hw_lock_control_reg);
252 if (lock_status & resource_bit) {
258 PMD_DRV_LOG(NOTICE, sc, "Resource 0x%x resource_bit 0x%x lock timeout!",
259 resource, resource_bit);
263 static int bnx2x_release_hw_lock(struct bnx2x_softc *sc, uint32_t resource)
265 uint32_t lock_status;
266 uint32_t resource_bit = (1 << resource);
267 int func = SC_FUNC(sc);
268 uint32_t hw_lock_control_reg;
270 #ifndef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
272 PMD_INIT_FUNC_TRACE(sc);
274 PMD_INIT_FUNC_TRACE(sc);
277 /* validate the resource is within range */
278 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
279 PMD_DRV_LOG(NOTICE, sc,
280 "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
281 " resource_bit 0x%x", resource, resource_bit);
286 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
288 hw_lock_control_reg =
289 (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
292 /* validate the resource is currently taken */
293 lock_status = REG_RD(sc, hw_lock_control_reg);
294 if (!(lock_status & resource_bit)) {
295 PMD_DRV_LOG(NOTICE, sc,
296 "resource not in use (status 0x%x bit 0x%x)",
297 lock_status, resource_bit);
301 REG_WR(sc, hw_lock_control_reg, resource_bit);
305 static void bnx2x_acquire_phy_lock(struct bnx2x_softc *sc)
308 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_MDIO);
311 static void bnx2x_release_phy_lock(struct bnx2x_softc *sc)
313 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_MDIO);
314 BNX2X_PHY_UNLOCK(sc);
317 /* copy command into DMAE command memory and set DMAE command Go */
318 void bnx2x_post_dmae(struct bnx2x_softc *sc, struct dmae_command *dmae, int idx)
323 cmd_offset = (DMAE_REG_CMD_MEM + (sizeof(struct dmae_command) * idx));
324 for (i = 0; i < ((sizeof(struct dmae_command) / 4)); i++) {
325 REG_WR(sc, (cmd_offset + (i * 4)), *(((uint32_t *) dmae) + i));
328 REG_WR(sc, dmae_reg_go_c[idx], 1);
331 uint32_t bnx2x_dmae_opcode_add_comp(uint32_t opcode, uint8_t comp_type)
333 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
334 DMAE_COMMAND_C_TYPE_ENABLE);
337 uint32_t bnx2x_dmae_opcode_clr_src_reset(uint32_t opcode)
339 return opcode & ~DMAE_COMMAND_SRC_RESET;
343 bnx2x_dmae_opcode(struct bnx2x_softc * sc, uint8_t src_type, uint8_t dst_type,
344 uint8_t with_comp, uint8_t comp_type)
348 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
349 (dst_type << DMAE_COMMAND_DST_SHIFT));
351 opcode |= (DMAE_COMMAND_SRC_RESET | DMAE_COMMAND_DST_RESET);
353 opcode |= (SC_PORT(sc) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
355 opcode |= ((SC_VN(sc) << DMAE_COMMAND_E1HVN_SHIFT) |
356 (SC_VN(sc) << DMAE_COMMAND_DST_VN_SHIFT));
358 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
361 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
363 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
367 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
374 bnx2x_prep_dmae_with_comp(struct bnx2x_softc *sc, struct dmae_command *dmae,
375 uint8_t src_type, uint8_t dst_type)
377 memset(dmae, 0, sizeof(struct dmae_command));
380 dmae->opcode = bnx2x_dmae_opcode(sc, src_type, dst_type,
381 TRUE, DMAE_COMP_PCI);
383 /* fill in the completion parameters */
384 dmae->comp_addr_lo = U64_LO(BNX2X_SP_MAPPING(sc, wb_comp));
385 dmae->comp_addr_hi = U64_HI(BNX2X_SP_MAPPING(sc, wb_comp));
386 dmae->comp_val = DMAE_COMP_VAL;
389 /* issue a DMAE command over the init channel and wait for completion */
391 bnx2x_issue_dmae_with_comp(struct bnx2x_softc *sc, struct dmae_command *dmae)
393 uint32_t *wb_comp = BNX2X_SP(sc, wb_comp);
394 int timeout = CHIP_REV_IS_SLOW(sc) ? 400000 : 4000;
396 /* reset completion */
399 /* post the command on the channel used for initializations */
400 bnx2x_post_dmae(sc, dmae, INIT_DMAE_C(sc));
402 /* wait for completion */
405 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
407 (sc->recovery_state != BNX2X_RECOVERY_DONE &&
408 sc->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
409 PMD_DRV_LOG(INFO, sc, "DMAE timeout!");
417 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
418 PMD_DRV_LOG(INFO, sc, "DMAE PCI error!");
419 return DMAE_PCI_ERROR;
425 void bnx2x_read_dmae(struct bnx2x_softc *sc, uint32_t src_addr, uint32_t len32)
427 struct dmae_command dmae;
432 if (!sc->dmae_ready) {
433 data = BNX2X_SP(sc, wb_data[0]);
435 for (i = 0; i < len32; i++) {
436 data[i] = REG_RD(sc, (src_addr + (i * 4)));
442 /* set opcode and fixed command fields */
443 bnx2x_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
445 /* fill in addresses and len */
446 dmae.src_addr_lo = (src_addr >> 2); /* GRC addr has dword resolution */
447 dmae.src_addr_hi = 0;
448 dmae.dst_addr_lo = U64_LO(BNX2X_SP_MAPPING(sc, wb_data));
449 dmae.dst_addr_hi = U64_HI(BNX2X_SP_MAPPING(sc, wb_data));
452 /* issue the command and wait for completion */
453 if ((rc = bnx2x_issue_dmae_with_comp(sc, &dmae)) != 0) {
454 rte_panic("DMAE failed (%d)", rc);
459 bnx2x_write_dmae(struct bnx2x_softc *sc, rte_iova_t dma_addr, uint32_t dst_addr,
462 struct dmae_command dmae;
465 if (!sc->dmae_ready) {
466 ecore_init_str_wr(sc, dst_addr, BNX2X_SP(sc, wb_data[0]), len32);
470 /* set opcode and fixed command fields */
471 bnx2x_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
473 /* fill in addresses and len */
474 dmae.src_addr_lo = U64_LO(dma_addr);
475 dmae.src_addr_hi = U64_HI(dma_addr);
476 dmae.dst_addr_lo = (dst_addr >> 2); /* GRC addr has dword resolution */
477 dmae.dst_addr_hi = 0;
480 /* issue the command and wait for completion */
481 if ((rc = bnx2x_issue_dmae_with_comp(sc, &dmae)) != 0) {
482 rte_panic("DMAE failed (%d)", rc);
487 bnx2x_write_dmae_phys_len(struct bnx2x_softc *sc, rte_iova_t phys_addr,
488 uint32_t addr, uint32_t len)
490 uint32_t dmae_wr_max = DMAE_LEN32_WR_MAX(sc);
493 while (len > dmae_wr_max) {
494 bnx2x_write_dmae(sc, (phys_addr + offset), /* src DMA address */
495 (addr + offset), /* dst GRC address */
497 offset += (dmae_wr_max * 4);
501 bnx2x_write_dmae(sc, (phys_addr + offset), /* src DMA address */
502 (addr + offset), /* dst GRC address */
507 bnx2x_set_ctx_validation(struct bnx2x_softc *sc, struct eth_context *cxt,
510 /* ustorm cxt validation */
511 cxt->ustorm_ag_context.cdu_usage =
512 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
513 CDU_REGION_NUMBER_UCM_AG,
514 ETH_CONNECTION_TYPE);
515 /* xcontext validation */
516 cxt->xstorm_ag_context.cdu_reserved =
517 CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
518 CDU_REGION_NUMBER_XCM_AG,
519 ETH_CONNECTION_TYPE);
523 bnx2x_storm_memset_hc_timeout(struct bnx2x_softc *sc, uint8_t fw_sb_id,
524 uint8_t sb_index, uint8_t ticks)
527 (BAR_CSTRORM_INTMEM +
528 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index));
530 REG_WR8(sc, addr, ticks);
534 bnx2x_storm_memset_hc_disable(struct bnx2x_softc *sc, uint16_t fw_sb_id,
535 uint8_t sb_index, uint8_t disable)
537 uint32_t enable_flag =
538 (disable) ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
540 (BAR_CSTRORM_INTMEM +
541 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index));
545 flags = REG_RD8(sc, addr);
546 flags &= ~HC_INDEX_DATA_HC_ENABLED;
547 flags |= enable_flag;
548 REG_WR8(sc, addr, flags);
552 bnx2x_update_coalesce_sb_index(struct bnx2x_softc *sc, uint8_t fw_sb_id,
553 uint8_t sb_index, uint8_t disable, uint16_t usec)
555 uint8_t ticks = (usec / 4);
557 bnx2x_storm_memset_hc_timeout(sc, fw_sb_id, sb_index, ticks);
559 disable = (disable) ? 1 : ((usec) ? 0 : 1);
560 bnx2x_storm_memset_hc_disable(sc, fw_sb_id, sb_index, disable);
563 uint32_t elink_cb_reg_read(struct bnx2x_softc *sc, uint32_t reg_addr)
565 return REG_RD(sc, reg_addr);
568 void elink_cb_reg_write(struct bnx2x_softc *sc, uint32_t reg_addr, uint32_t val)
570 REG_WR(sc, reg_addr, val);
574 elink_cb_event_log(__rte_unused struct bnx2x_softc *sc,
575 __rte_unused const elink_log_id_t elink_log_id, ...)
577 PMD_DRV_LOG(DEBUG, sc, "ELINK EVENT LOG (%d)", elink_log_id);
580 static int bnx2x_set_spio(struct bnx2x_softc *sc, int spio, uint32_t mode)
584 /* Only 2 SPIOs are configurable */
585 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
586 PMD_DRV_LOG(NOTICE, sc, "Invalid SPIO 0x%x", spio);
590 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
592 /* read SPIO and mask except the float bits */
593 spio_reg = (REG_RD(sc, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
596 case MISC_SPIO_OUTPUT_LOW:
597 /* clear FLOAT and set CLR */
598 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
599 spio_reg |= (spio << MISC_SPIO_CLR_POS);
602 case MISC_SPIO_OUTPUT_HIGH:
603 /* clear FLOAT and set SET */
604 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
605 spio_reg |= (spio << MISC_SPIO_SET_POS);
608 case MISC_SPIO_INPUT_HI_Z:
610 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
617 REG_WR(sc, MISC_REG_SPIO, spio_reg);
618 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
623 static int bnx2x_gpio_read(struct bnx2x_softc *sc, int gpio_num, uint8_t port)
625 /* The GPIO should be swapped if swap register is set and active */
626 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
627 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
628 int gpio_shift = gpio_num;
630 gpio_shift += MISC_REGISTERS_GPIO_PORT_SHIFT;
632 uint32_t gpio_mask = (1 << gpio_shift);
635 if (gpio_num > MISC_REGISTERS_GPIO_3) {
636 PMD_DRV_LOG(NOTICE, sc, "Invalid GPIO %d", gpio_num);
640 /* read GPIO value */
641 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
643 /* get the requested pin value */
644 return ((gpio_reg & gpio_mask) == gpio_mask) ? 1 : 0;
648 bnx2x_gpio_write(struct bnx2x_softc *sc, int gpio_num, uint32_t mode, uint8_t port)
650 /* The GPIO should be swapped if swap register is set and active */
651 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
652 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
653 int gpio_shift = gpio_num;
655 gpio_shift += MISC_REGISTERS_GPIO_PORT_SHIFT;
657 uint32_t gpio_mask = (1 << gpio_shift);
660 if (gpio_num > MISC_REGISTERS_GPIO_3) {
661 PMD_DRV_LOG(NOTICE, sc, "Invalid GPIO %d", gpio_num);
665 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
667 /* read GPIO and mask except the float bits */
668 gpio_reg = (REG_RD(sc, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
671 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
672 /* clear FLOAT and set CLR */
673 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
674 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
677 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
678 /* clear FLOAT and set SET */
679 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
680 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
683 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
685 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
692 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
693 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
699 bnx2x_gpio_mult_write(struct bnx2x_softc *sc, uint8_t pins, uint32_t mode)
703 /* any port swapping should be handled by caller */
705 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
707 /* read GPIO and mask except the float bits */
708 gpio_reg = REG_RD(sc, MISC_REG_GPIO);
709 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
710 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
711 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
714 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
716 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
719 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
721 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
724 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
726 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
730 PMD_DRV_LOG(NOTICE, sc,
731 "Invalid GPIO mode assignment %d", mode);
732 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
736 REG_WR(sc, MISC_REG_GPIO, gpio_reg);
737 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
743 bnx2x_gpio_int_write(struct bnx2x_softc *sc, int gpio_num, uint32_t mode,
746 /* The GPIO should be swapped if swap register is set and active */
747 int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
748 REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
749 int gpio_shift = gpio_num;
751 gpio_shift += MISC_REGISTERS_GPIO_PORT_SHIFT;
753 uint32_t gpio_mask = (1 << gpio_shift);
756 if (gpio_num > MISC_REGISTERS_GPIO_3) {
757 PMD_DRV_LOG(NOTICE, sc, "Invalid GPIO %d", gpio_num);
761 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
764 gpio_reg = REG_RD(sc, MISC_REG_GPIO_INT);
767 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
768 /* clear SET and set CLR */
769 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
770 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
773 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
774 /* clear CLR and set SET */
775 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
776 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
783 REG_WR(sc, MISC_REG_GPIO_INT, gpio_reg);
784 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
790 elink_cb_gpio_read(struct bnx2x_softc * sc, uint16_t gpio_num, uint8_t port)
792 return bnx2x_gpio_read(sc, gpio_num, port);
795 uint8_t elink_cb_gpio_write(struct bnx2x_softc * sc, uint16_t gpio_num, uint8_t mode, /* 0=low 1=high */
798 return bnx2x_gpio_write(sc, gpio_num, mode, port);
802 elink_cb_gpio_mult_write(struct bnx2x_softc * sc, uint8_t pins,
803 uint8_t mode /* 0=low 1=high */ )
805 return bnx2x_gpio_mult_write(sc, pins, mode);
808 uint8_t elink_cb_gpio_int_write(struct bnx2x_softc * sc, uint16_t gpio_num, uint8_t mode, /* 0=low 1=high */
811 return bnx2x_gpio_int_write(sc, gpio_num, mode, port);
814 void elink_cb_notify_link_changed(struct bnx2x_softc *sc)
816 REG_WR(sc, (MISC_REG_AEU_GENERAL_ATTN_12 +
817 (SC_FUNC(sc) * sizeof(uint32_t))), 1);
820 /* send the MCP a request, block until there is a reply */
822 elink_cb_fw_command(struct bnx2x_softc *sc, uint32_t command, uint32_t param)
824 int mb_idx = SC_FW_MB_IDX(sc);
828 uint8_t delay = CHIP_REV_IS_SLOW(sc) ? 100 : 10;
831 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_param, param);
832 SHMEM_WR(sc, func_mb[mb_idx].drv_mb_header, (command | seq));
834 PMD_DRV_LOG(DEBUG, sc,
835 "wrote command 0x%08x to FW MB param 0x%08x",
836 (command | seq), param);
838 /* Let the FW do it's magic. GIve it up to 5 seconds... */
841 rc = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_header);
842 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
844 /* is this a reply to our command? */
845 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
846 rc &= FW_MSG_CODE_MASK;
849 PMD_DRV_LOG(NOTICE, sc, "FW failed to respond!");
857 bnx2x_fw_command(struct bnx2x_softc *sc, uint32_t command, uint32_t param)
859 return elink_cb_fw_command(sc, command, param);
863 __storm_memset_dma_mapping(struct bnx2x_softc *sc, uint32_t addr,
866 REG_WR(sc, addr, U64_LO(mapping));
867 REG_WR(sc, (addr + 4), U64_HI(mapping));
871 storm_memset_spq_addr(struct bnx2x_softc *sc, rte_iova_t mapping,
874 uint32_t addr = (XSEM_REG_FAST_MEMORY +
875 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid));
876 __storm_memset_dma_mapping(sc, addr, mapping);
880 storm_memset_vf_to_pf(struct bnx2x_softc *sc, uint16_t abs_fid, uint16_t pf_id)
882 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid)),
884 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid)),
886 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid)),
888 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid)),
893 storm_memset_func_en(struct bnx2x_softc *sc, uint16_t abs_fid, uint8_t enable)
895 REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid)),
897 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid)),
899 REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid)),
901 REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid)),
906 storm_memset_eq_data(struct bnx2x_softc *sc, struct event_ring_data *eq_data,
912 addr = (BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid));
913 size = sizeof(struct event_ring_data);
914 ecore_storm_memset_struct(sc, addr, size, (uint32_t *) eq_data);
918 storm_memset_eq_prod(struct bnx2x_softc *sc, uint16_t eq_prod, uint16_t pfid)
920 uint32_t addr = (BAR_CSTRORM_INTMEM +
921 CSTORM_EVENT_RING_PROD_OFFSET(pfid));
922 REG_WR16(sc, addr, eq_prod);
926 * Post a slowpath command.
928 * A slowpath command is used to propagate a configuration change through
929 * the controller in a controlled manner, allowing each STORM processor and
930 * other H/W blocks to phase in the change. The commands sent on the
931 * slowpath are referred to as ramrods. Depending on the ramrod used the
932 * completion of the ramrod will occur in different ways. Here's a
933 * breakdown of ramrods and how they complete:
935 * RAMROD_CMD_ID_ETH_PORT_SETUP
936 * Used to setup the leading connection on a port. Completes on the
937 * Receive Completion Queue (RCQ) of that port (typically fp[0]).
939 * RAMROD_CMD_ID_ETH_CLIENT_SETUP
940 * Used to setup an additional connection on a port. Completes on the
941 * RCQ of the multi-queue/RSS connection being initialized.
943 * RAMROD_CMD_ID_ETH_STAT_QUERY
944 * Used to force the storm processors to update the statistics database
945 * in host memory. This ramrod is send on the leading connection CID and
946 * completes as an index increment of the CSTORM on the default status
949 * RAMROD_CMD_ID_ETH_UPDATE
950 * Used to update the state of the leading connection, usually to udpate
951 * the RSS indirection table. Completes on the RCQ of the leading
952 * connection. (Not currently used under FreeBSD until OS support becomes
955 * RAMROD_CMD_ID_ETH_HALT
956 * Used when tearing down a connection prior to driver unload. Completes
957 * on the RCQ of the multi-queue/RSS connection being torn down. Don't
958 * use this on the leading connection.
960 * RAMROD_CMD_ID_ETH_SET_MAC
961 * Sets the Unicast/Broadcast/Multicast used by the port. Completes on
962 * the RCQ of the leading connection.
964 * RAMROD_CMD_ID_ETH_CFC_DEL
965 * Used when tearing down a conneciton prior to driver unload. Completes
966 * on the RCQ of the leading connection (since the current connection
967 * has been completely removed from controller memory).
969 * RAMROD_CMD_ID_ETH_PORT_DEL
970 * Used to tear down the leading connection prior to driver unload,
971 * typically fp[0]. Completes as an index increment of the CSTORM on the
972 * default status block.
974 * RAMROD_CMD_ID_ETH_FORWARD_SETUP
975 * Used for connection offload. Completes on the RCQ of the multi-queue
976 * RSS connection that is being offloaded. (Not currently used under
979 * There can only be one command pending per function.
982 * 0 = Success, !0 = Failure.
985 /* must be called under the spq lock */
986 static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x_softc *sc)
988 struct eth_spe *next_spe = sc->spq_prod_bd;
990 if (sc->spq_prod_bd == sc->spq_last_bd) {
991 /* wrap back to the first eth_spq */
992 sc->spq_prod_bd = sc->spq;
993 sc->spq_prod_idx = 0;
1002 /* must be called under the spq lock */
1003 static void bnx2x_sp_prod_update(struct bnx2x_softc *sc)
1005 int func = SC_FUNC(sc);
1008 * Make sure that BD data is updated before writing the producer.
1009 * BD data is written to the memory, the producer is read from the
1010 * memory, thus we need a full memory barrier to ensure the ordering.
1014 REG_WR16(sc, (BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func)),
1021 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
1023 * @cmd: command to check
1024 * @cmd_type: command type
1026 static int bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
1028 if ((cmd_type == NONE_CONNECTION_TYPE) ||
1029 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
1030 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
1031 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
1032 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
1033 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
1034 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) {
1042 * bnx2x_sp_post - place a single command on an SP ring
1044 * @sc: driver handle
1045 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
1046 * @cid: SW CID the command is related to
1047 * @data_hi: command private data address (high 32 bits)
1048 * @data_lo: command private data address (low 32 bits)
1049 * @cmd_type: command type (e.g. NONE, ETH)
1051 * SP data is handled as if it's always an address pair, thus data fields are
1052 * not swapped to little endian in upper functions. Instead this function swaps
1053 * data as if it's two uint32 fields.
1056 bnx2x_sp_post(struct bnx2x_softc *sc, int command, int cid, uint32_t data_hi,
1057 uint32_t data_lo, int cmd_type)
1059 struct eth_spe *spe;
1063 common = bnx2x_is_contextless_ramrod(command, cmd_type);
1066 if (!atomic_load_acq_long(&sc->eq_spq_left)) {
1067 PMD_DRV_LOG(INFO, sc, "EQ ring is full!");
1071 if (!atomic_load_acq_long(&sc->cq_spq_left)) {
1072 PMD_DRV_LOG(INFO, sc, "SPQ ring is full!");
1077 spe = bnx2x_sp_get_next(sc);
1079 /* CID needs port number to be encoded int it */
1080 spe->hdr.conn_and_cmd_data =
1081 htole32((command << SPE_HDR_CMD_ID_SHIFT) | HW_CID(sc, cid));
1083 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
1085 /* TBD: Check if it works for VFs */
1086 type |= ((SC_FUNC(sc) << SPE_HDR_FUNCTION_ID_SHIFT) &
1087 SPE_HDR_FUNCTION_ID);
1089 spe->hdr.type = htole16(type);
1091 spe->data.update_data_addr.hi = htole32(data_hi);
1092 spe->data.update_data_addr.lo = htole32(data_lo);
1095 * It's ok if the actual decrement is issued towards the memory
1096 * somewhere between the lock and unlock. Thus no more explict
1097 * memory barrier is needed.
1100 atomic_subtract_acq_long(&sc->eq_spq_left, 1);
1102 atomic_subtract_acq_long(&sc->cq_spq_left, 1);
1105 PMD_DRV_LOG(DEBUG, sc,
1106 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x"
1107 "data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)",
1109 (uint32_t) U64_HI(sc->spq_dma.paddr),
1110 (uint32_t) (U64_LO(sc->spq_dma.paddr) +
1111 (uint8_t *) sc->spq_prod_bd -
1112 (uint8_t *) sc->spq), command, common,
1113 HW_CID(sc, cid), data_hi, data_lo, type,
1114 atomic_load_acq_long(&sc->cq_spq_left),
1115 atomic_load_acq_long(&sc->eq_spq_left));
1117 /* RAMROD completion is processed in bnx2x_intr_legacy()
1118 * which can run from different contexts.
1119 * Ask bnx2x_intr_intr() to process RAMROD
1120 * completion whenever it gets scheduled.
1122 rte_atomic32_set(&sc->scan_fp, 1);
1123 bnx2x_sp_prod_update(sc);
1128 static void bnx2x_drv_pulse(struct bnx2x_softc *sc)
1130 SHMEM_WR(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb,
1131 sc->fw_drv_pulse_wr_seq);
1134 static int bnx2x_tx_queue_has_work(const struct bnx2x_fastpath *fp)
1137 struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
1139 if (unlikely(!txq)) {
1140 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
1144 mb(); /* status block fields can change */
1145 hw_cons = le16toh(*fp->tx_cons_sb);
1146 return hw_cons != txq->tx_pkt_head;
1149 static uint8_t bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
1151 /* expand this for multi-cos if ever supported */
1152 return bnx2x_tx_queue_has_work(fp);
1155 static int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
1157 uint16_t rx_cq_cons_sb;
1158 struct bnx2x_rx_queue *rxq;
1159 rxq = fp->sc->rx_queues[fp->index];
1160 if (unlikely(!rxq)) {
1161 PMD_RX_LOG(ERR, "ERROR: RX queue is NULL");
1165 mb(); /* status block fields can change */
1166 rx_cq_cons_sb = le16toh(*fp->rx_cq_cons_sb);
1167 if (unlikely((rx_cq_cons_sb & MAX_RCQ_ENTRIES(rxq)) ==
1168 MAX_RCQ_ENTRIES(rxq)))
1170 return rxq->rx_cq_head != rx_cq_cons_sb;
1174 bnx2x_sp_event(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
1175 union eth_rx_cqe *rr_cqe)
1177 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1178 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1179 enum ecore_queue_cmd drv_cmd = ECORE_Q_CMD_MAX;
1180 struct ecore_queue_sp_obj *q_obj = &BNX2X_SP_OBJ(sc, fp).q_obj;
1182 PMD_DRV_LOG(DEBUG, sc,
1183 "fp=%d cid=%d got ramrod #%d state is %x type is %d",
1184 fp->index, cid, command, sc->state,
1185 rr_cqe->ramrod_cqe.ramrod_type);
1188 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1189 PMD_DRV_LOG(DEBUG, sc, "got UPDATE ramrod. CID %d", cid);
1190 drv_cmd = ECORE_Q_CMD_UPDATE;
1193 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
1194 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] setup ramrod", cid);
1195 drv_cmd = ECORE_Q_CMD_SETUP;
1198 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
1199 PMD_DRV_LOG(DEBUG, sc,
1200 "got MULTI[%d] tx-only setup ramrod", cid);
1201 drv_cmd = ECORE_Q_CMD_SETUP_TX_ONLY;
1204 case (RAMROD_CMD_ID_ETH_HALT):
1205 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] halt ramrod", cid);
1206 drv_cmd = ECORE_Q_CMD_HALT;
1209 case (RAMROD_CMD_ID_ETH_TERMINATE):
1210 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] teminate ramrod", cid);
1211 drv_cmd = ECORE_Q_CMD_TERMINATE;
1214 case (RAMROD_CMD_ID_ETH_EMPTY):
1215 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] empty ramrod", cid);
1216 drv_cmd = ECORE_Q_CMD_EMPTY;
1220 PMD_DRV_LOG(DEBUG, sc,
1221 "ERROR: unexpected MC reply (%d)"
1222 "on fp[%d]", command, fp->index);
1226 if ((drv_cmd != ECORE_Q_CMD_MAX) &&
1227 q_obj->complete_cmd(sc, q_obj, drv_cmd)) {
1229 * q_obj->complete_cmd() failure means that this was
1230 * an unexpected completion.
1232 * In this case we don't want to increase the sc->spq_left
1233 * because apparently we haven't sent this command the first
1236 // rte_panic("Unexpected SP completion");
1240 atomic_add_acq_long(&sc->cq_spq_left, 1);
1242 PMD_DRV_LOG(DEBUG, sc, "sc->cq_spq_left 0x%lx",
1243 atomic_load_acq_long(&sc->cq_spq_left));
1246 static uint8_t bnx2x_rxeof(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp)
1248 struct bnx2x_rx_queue *rxq;
1249 uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
1250 uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod;
1252 rxq = sc->rx_queues[fp->index];
1254 PMD_RX_LOG(ERR, "RX queue %d is NULL", fp->index);
1258 /* CQ "next element" is of the size of the regular element */
1259 hw_cq_cons = le16toh(*fp->rx_cq_cons_sb);
1260 if (unlikely((hw_cq_cons & USABLE_RCQ_ENTRIES_PER_PAGE) ==
1261 USABLE_RCQ_ENTRIES_PER_PAGE)) {
1265 bd_cons = rxq->rx_bd_head;
1266 bd_prod = rxq->rx_bd_tail;
1267 bd_prod_fw = bd_prod;
1268 sw_cq_cons = rxq->rx_cq_head;
1269 sw_cq_prod = rxq->rx_cq_tail;
1272 * Memory barrier necessary as speculative reads of the rx
1273 * buffer can be ahead of the index in the status block
1277 while (sw_cq_cons != hw_cq_cons) {
1278 union eth_rx_cqe *cqe;
1279 struct eth_fast_path_rx_cqe *cqe_fp;
1280 uint8_t cqe_fp_flags;
1281 enum eth_rx_cqe_type cqe_fp_type;
1283 comp_ring_cons = RCQ_ENTRY(sw_cq_cons, rxq);
1284 bd_prod = RX_BD(bd_prod, rxq);
1285 bd_cons = RX_BD(bd_cons, rxq);
1287 cqe = &rxq->cq_ring[comp_ring_cons];
1288 cqe_fp = &cqe->fast_path_cqe;
1289 cqe_fp_flags = cqe_fp->type_error_flags;
1290 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
1292 /* is this a slowpath msg? */
1293 if (CQE_TYPE_SLOW(cqe_fp_type)) {
1294 bnx2x_sp_event(sc, fp, cqe);
1298 /* is this an error packet? */
1299 if (unlikely(cqe_fp_flags &
1300 ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG)) {
1301 PMD_RX_LOG(DEBUG, "flags 0x%x rx packet %u",
1302 cqe_fp_flags, sw_cq_cons);
1306 PMD_RX_LOG(DEBUG, "Dropping fastpath called from attn poller!");
1309 bd_cons = NEXT_RX_BD(bd_cons);
1310 bd_prod = NEXT_RX_BD(bd_prod);
1311 bd_prod_fw = NEXT_RX_BD(bd_prod_fw);
1314 sw_cq_prod = NEXT_RCQ_IDX(sw_cq_prod);
1315 sw_cq_cons = NEXT_RCQ_IDX(sw_cq_cons);
1317 } /* while work to do */
1319 rxq->rx_bd_head = bd_cons;
1320 rxq->rx_bd_tail = bd_prod_fw;
1321 rxq->rx_cq_head = sw_cq_cons;
1322 rxq->rx_cq_tail = sw_cq_prod;
1324 /* Update producers */
1325 bnx2x_update_rx_prod(sc, fp, bd_prod_fw, sw_cq_prod);
1327 return sw_cq_cons != hw_cq_cons;
1331 bnx2x_free_tx_pkt(__rte_unused struct bnx2x_fastpath *fp, struct bnx2x_tx_queue *txq,
1332 uint16_t pkt_idx, uint16_t bd_idx)
1334 struct eth_tx_start_bd *tx_start_bd =
1335 &txq->tx_ring[TX_BD(bd_idx, txq)].start_bd;
1336 uint16_t nbd = rte_le_to_cpu_16(tx_start_bd->nbd);
1337 struct rte_mbuf *tx_mbuf = txq->sw_ring[TX_BD(pkt_idx, txq)];
1339 if (likely(tx_mbuf != NULL)) {
1340 rte_pktmbuf_free_seg(tx_mbuf);
1342 PMD_RX_LOG(ERR, "fp[%02d] lost mbuf %lu",
1343 fp->index, (unsigned long)TX_BD(pkt_idx, txq));
1346 txq->sw_ring[TX_BD(pkt_idx, txq)] = NULL;
1347 txq->nb_tx_avail += nbd;
1350 bd_idx = NEXT_TX_BD(bd_idx);
1355 /* processes transmit completions */
1356 uint8_t bnx2x_txeof(__rte_unused struct bnx2x_softc * sc, struct bnx2x_fastpath * fp)
1358 uint16_t bd_cons, hw_cons, sw_cons;
1359 __rte_unused uint16_t tx_bd_avail;
1361 struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
1363 if (unlikely(!txq)) {
1364 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
1368 bd_cons = txq->tx_bd_head;
1369 hw_cons = rte_le_to_cpu_16(*fp->tx_cons_sb);
1370 sw_cons = txq->tx_pkt_head;
1372 while (sw_cons != hw_cons) {
1373 bd_cons = bnx2x_free_tx_pkt(fp, txq, sw_cons, bd_cons);
1377 txq->tx_pkt_head = sw_cons;
1378 txq->tx_bd_head = bd_cons;
1380 tx_bd_avail = txq->nb_tx_avail;
1382 PMD_TX_LOG(DEBUG, "fp[%02d] avail=%u cons_sb=%u, "
1383 "pkt_head=%u pkt_tail=%u bd_head=%u bd_tail=%u",
1384 fp->index, tx_bd_avail, hw_cons,
1385 txq->tx_pkt_head, txq->tx_pkt_tail,
1386 txq->tx_bd_head, txq->tx_bd_tail);
1390 static void bnx2x_drain_tx_queues(struct bnx2x_softc *sc)
1392 struct bnx2x_fastpath *fp;
1395 /* wait until all TX fastpath tasks have completed */
1396 for (i = 0; i < sc->num_queues; i++) {
1401 while (bnx2x_has_tx_work(fp)) {
1402 bnx2x_txeof(sc, fp);
1406 "Timeout waiting for fp[%d] "
1407 "transmits to complete!", i);
1408 rte_panic("tx drain failure");
1422 bnx2x_del_all_macs(struct bnx2x_softc *sc, struct ecore_vlan_mac_obj *mac_obj,
1423 int mac_type, uint8_t wait_for_comp)
1425 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
1428 /* wait for completion of requested */
1429 if (wait_for_comp) {
1430 bnx2x_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
1433 /* Set the mac type of addresses we want to clear */
1434 bnx2x_set_bit(mac_type, &vlan_mac_flags);
1436 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
1438 PMD_DRV_LOG(ERR, sc, "Failed to delete MACs (%d)", rc);
1444 bnx2x_fill_accept_flags(struct bnx2x_softc *sc, uint32_t rx_mode,
1445 unsigned long *rx_accept_flags,
1446 unsigned long *tx_accept_flags)
1448 /* Clear the flags first */
1449 *rx_accept_flags = 0;
1450 *tx_accept_flags = 0;
1453 case BNX2X_RX_MODE_NONE:
1455 * 'drop all' supersedes any accept flags that may have been
1456 * passed to the function.
1460 case BNX2X_RX_MODE_NORMAL:
1461 bnx2x_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
1462 bnx2x_set_bit(ECORE_ACCEPT_MULTICAST, rx_accept_flags);
1463 bnx2x_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
1465 /* internal switching mode */
1466 bnx2x_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
1467 bnx2x_set_bit(ECORE_ACCEPT_MULTICAST, tx_accept_flags);
1468 bnx2x_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
1472 case BNX2X_RX_MODE_ALLMULTI:
1473 bnx2x_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
1474 bnx2x_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
1475 bnx2x_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
1477 /* internal switching mode */
1478 bnx2x_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
1479 bnx2x_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
1480 bnx2x_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
1484 case BNX2X_RX_MODE_ALLMULTI_PROMISC:
1485 case BNX2X_RX_MODE_PROMISC:
1487 * According to deffinition of SI mode, iface in promisc mode
1488 * should receive matched and unmatched (in resolution of port)
1491 bnx2x_set_bit(ECORE_ACCEPT_UNMATCHED, rx_accept_flags);
1492 bnx2x_set_bit(ECORE_ACCEPT_UNICAST, rx_accept_flags);
1493 bnx2x_set_bit(ECORE_ACCEPT_ALL_MULTICAST, rx_accept_flags);
1494 bnx2x_set_bit(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
1496 /* internal switching mode */
1497 bnx2x_set_bit(ECORE_ACCEPT_ALL_MULTICAST, tx_accept_flags);
1498 bnx2x_set_bit(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
1501 bnx2x_set_bit(ECORE_ACCEPT_ALL_UNICAST, tx_accept_flags);
1503 bnx2x_set_bit(ECORE_ACCEPT_UNICAST, tx_accept_flags);
1509 PMD_RX_LOG(ERR, "Unknown rx_mode (%d)", rx_mode);
1513 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
1514 if (rx_mode != BNX2X_RX_MODE_NONE) {
1515 bnx2x_set_bit(ECORE_ACCEPT_ANY_VLAN, rx_accept_flags);
1516 bnx2x_set_bit(ECORE_ACCEPT_ANY_VLAN, tx_accept_flags);
1523 bnx2x_set_q_rx_mode(struct bnx2x_softc *sc, uint8_t cl_id,
1524 unsigned long rx_mode_flags,
1525 unsigned long rx_accept_flags,
1526 unsigned long tx_accept_flags, unsigned long ramrod_flags)
1528 struct ecore_rx_mode_ramrod_params ramrod_param;
1531 memset(&ramrod_param, 0, sizeof(ramrod_param));
1533 /* Prepare ramrod parameters */
1534 ramrod_param.cid = 0;
1535 ramrod_param.cl_id = cl_id;
1536 ramrod_param.rx_mode_obj = &sc->rx_mode_obj;
1537 ramrod_param.func_id = SC_FUNC(sc);
1539 ramrod_param.pstate = &sc->sp_state;
1540 ramrod_param.state = ECORE_FILTER_RX_MODE_PENDING;
1542 ramrod_param.rdata = BNX2X_SP(sc, rx_mode_rdata);
1543 ramrod_param.rdata_mapping =
1544 (rte_iova_t)BNX2X_SP_MAPPING(sc, rx_mode_rdata),
1545 bnx2x_set_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
1547 ramrod_param.ramrod_flags = ramrod_flags;
1548 ramrod_param.rx_mode_flags = rx_mode_flags;
1550 ramrod_param.rx_accept_flags = rx_accept_flags;
1551 ramrod_param.tx_accept_flags = tx_accept_flags;
1553 rc = ecore_config_rx_mode(sc, &ramrod_param);
1555 PMD_RX_LOG(ERR, "Set rx_mode %d failed", sc->rx_mode);
1562 int bnx2x_set_storm_rx_mode(struct bnx2x_softc *sc)
1564 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
1565 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
1568 rc = bnx2x_fill_accept_flags(sc, sc->rx_mode, &rx_accept_flags,
1574 bnx2x_set_bit(RAMROD_RX, &ramrod_flags);
1575 bnx2x_set_bit(RAMROD_TX, &ramrod_flags);
1576 bnx2x_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
1578 return bnx2x_set_q_rx_mode(sc, sc->fp[0].cl_id, rx_mode_flags,
1579 rx_accept_flags, tx_accept_flags,
1583 /* returns the "mcp load_code" according to global load_count array */
1584 static int bnx2x_nic_load_no_mcp(struct bnx2x_softc *sc)
1586 int path = SC_PATH(sc);
1587 int port = SC_PORT(sc);
1589 PMD_DRV_LOG(INFO, sc, "NO MCP - load counts[%d] %d, %d, %d",
1590 path, load_count[path][0], load_count[path][1],
1591 load_count[path][2]);
1593 load_count[path][0]++;
1594 load_count[path][1 + port]++;
1595 PMD_DRV_LOG(INFO, sc, "NO MCP - new load counts[%d] %d, %d, %d",
1596 path, load_count[path][0], load_count[path][1],
1597 load_count[path][2]);
1598 if (load_count[path][0] == 1)
1599 return FW_MSG_CODE_DRV_LOAD_COMMON;
1600 else if (load_count[path][1 + port] == 1)
1601 return FW_MSG_CODE_DRV_LOAD_PORT;
1603 return FW_MSG_CODE_DRV_LOAD_FUNCTION;
1606 /* returns the "mcp load_code" according to global load_count array */
1607 static int bnx2x_nic_unload_no_mcp(struct bnx2x_softc *sc)
1609 int port = SC_PORT(sc);
1610 int path = SC_PATH(sc);
1612 PMD_DRV_LOG(INFO, sc, "NO MCP - load counts[%d] %d, %d, %d",
1613 path, load_count[path][0], load_count[path][1],
1614 load_count[path][2]);
1615 load_count[path][0]--;
1616 load_count[path][1 + port]--;
1617 PMD_DRV_LOG(INFO, sc, "NO MCP - new load counts[%d] %d, %d, %d",
1618 path, load_count[path][0], load_count[path][1],
1619 load_count[path][2]);
1620 if (load_count[path][0] == 0) {
1621 return FW_MSG_CODE_DRV_UNLOAD_COMMON;
1622 } else if (load_count[path][1 + port] == 0) {
1623 return FW_MSG_CODE_DRV_UNLOAD_PORT;
1625 return FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
1629 /* request unload mode from the MCP: COMMON, PORT or FUNCTION */
1630 static uint32_t bnx2x_send_unload_req(struct bnx2x_softc *sc, int unload_mode)
1632 uint32_t reset_code = 0;
1634 /* Select the UNLOAD request mode */
1635 if (unload_mode == UNLOAD_NORMAL) {
1636 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
1638 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
1641 /* Send the request to the MCP */
1642 if (!BNX2X_NOMCP(sc)) {
1643 reset_code = bnx2x_fw_command(sc, reset_code, 0);
1645 reset_code = bnx2x_nic_unload_no_mcp(sc);
1651 /* send UNLOAD_DONE command to the MCP */
1652 static void bnx2x_send_unload_done(struct bnx2x_softc *sc, uint8_t keep_link)
1654 uint32_t reset_param =
1655 keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
1657 /* Report UNLOAD_DONE to MCP */
1658 if (!BNX2X_NOMCP(sc)) {
1659 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
1663 static int bnx2x_func_wait_started(struct bnx2x_softc *sc)
1667 if (!sc->port.pmf) {
1672 * (assumption: No Attention from MCP at this stage)
1673 * PMF probably in the middle of TX disable/enable transaction
1674 * 1. Sync IRS for default SB
1675 * 2. Sync SP queue - this guarantees us that attention handling started
1676 * 3. Wait, that TX disable/enable transaction completes
1678 * 1+2 guarantee that if DCBX attention was scheduled it already changed
1679 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
1680 * received completion for the transaction the state is TX_STOPPED.
1681 * State will return to STARTED after completion of TX_STOPPED-->STARTED
1685 while (ecore_func_get_state(sc, &sc->func_obj) !=
1686 ECORE_F_STATE_STARTED && tout--) {
1690 if (ecore_func_get_state(sc, &sc->func_obj) != ECORE_F_STATE_STARTED) {
1692 * Failed to complete the transaction in a "good way"
1693 * Force both transactions with CLR bit.
1695 struct ecore_func_state_params func_params = { NULL };
1697 PMD_DRV_LOG(NOTICE, sc, "Unexpected function state! "
1698 "Forcing STARTED-->TX_STOPPED-->STARTED");
1700 func_params.f_obj = &sc->func_obj;
1701 bnx2x_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
1703 /* STARTED-->TX_STOPPED */
1704 func_params.cmd = ECORE_F_CMD_TX_STOP;
1705 ecore_func_state_change(sc, &func_params);
1707 /* TX_STOPPED-->STARTED */
1708 func_params.cmd = ECORE_F_CMD_TX_START;
1709 return ecore_func_state_change(sc, &func_params);
1715 static int bnx2x_stop_queue(struct bnx2x_softc *sc, int index)
1717 struct bnx2x_fastpath *fp = &sc->fp[index];
1718 struct ecore_queue_state_params q_params = { NULL };
1721 PMD_DRV_LOG(DEBUG, sc, "stopping queue %d cid %d", index, fp->index);
1723 q_params.q_obj = &sc->sp_objs[fp->index].q_obj;
1724 /* We want to wait for completion in this context */
1725 bnx2x_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
1727 /* Stop the primary connection: */
1729 /* ...halt the connection */
1730 q_params.cmd = ECORE_Q_CMD_HALT;
1731 rc = ecore_queue_state_change(sc, &q_params);
1736 /* ...terminate the connection */
1737 q_params.cmd = ECORE_Q_CMD_TERMINATE;
1738 memset(&q_params.params.terminate, 0,
1739 sizeof(q_params.params.terminate));
1740 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
1741 rc = ecore_queue_state_change(sc, &q_params);
1746 /* ...delete cfc entry */
1747 q_params.cmd = ECORE_Q_CMD_CFC_DEL;
1748 memset(&q_params.params.cfc_del, 0, sizeof(q_params.params.cfc_del));
1749 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
1750 return ecore_queue_state_change(sc, &q_params);
1753 /* wait for the outstanding SP commands */
1754 static uint8_t bnx2x_wait_sp_comp(struct bnx2x_softc *sc, unsigned long mask)
1757 int tout = 5000; /* wait for 5 secs tops */
1761 if (!(atomic_load_acq_long(&sc->sp_state) & mask)) {
1770 tmp = atomic_load_acq_long(&sc->sp_state);
1772 PMD_DRV_LOG(INFO, sc, "Filtering completion timed out: "
1773 "sp_state 0x%lx, mask 0x%lx", tmp, mask);
1780 static int bnx2x_func_stop(struct bnx2x_softc *sc)
1782 struct ecore_func_state_params func_params = { NULL };
1785 /* prepare parameters for function state transitions */
1786 bnx2x_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
1787 func_params.f_obj = &sc->func_obj;
1788 func_params.cmd = ECORE_F_CMD_STOP;
1791 * Try to stop the function the 'good way'. If it fails (in case
1792 * of a parity error during bnx2x_chip_cleanup()) and we are
1793 * not in a debug mode, perform a state transaction in order to
1794 * enable further HW_RESET transaction.
1796 rc = ecore_func_state_change(sc, &func_params);
1798 PMD_DRV_LOG(NOTICE, sc, "FUNC_STOP ramrod failed. "
1799 "Running a dry transaction");
1800 bnx2x_set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
1801 return ecore_func_state_change(sc, &func_params);
1807 static int bnx2x_reset_hw(struct bnx2x_softc *sc, uint32_t load_code)
1809 struct ecore_func_state_params func_params = { NULL };
1811 /* Prepare parameters for function state transitions */
1812 bnx2x_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
1814 func_params.f_obj = &sc->func_obj;
1815 func_params.cmd = ECORE_F_CMD_HW_RESET;
1817 func_params.params.hw_init.load_phase = load_code;
1819 return ecore_func_state_change(sc, &func_params);
1822 static void bnx2x_int_disable_sync(struct bnx2x_softc *sc, int disable_hw)
1825 /* prevent the HW from sending interrupts */
1826 bnx2x_int_disable(sc);
1831 bnx2x_chip_cleanup(struct bnx2x_softc *sc, uint32_t unload_mode, uint8_t keep_link)
1833 int port = SC_PORT(sc);
1834 struct ecore_mcast_ramrod_params rparam = { NULL };
1835 uint32_t reset_code;
1838 bnx2x_drain_tx_queues(sc);
1840 /* give HW time to discard old tx messages */
1843 /* Clean all ETH MACs */
1844 rc = bnx2x_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_ETH_MAC,
1847 PMD_DRV_LOG(NOTICE, sc,
1848 "Failed to delete all ETH MACs (%d)", rc);
1851 /* Clean up UC list */
1852 rc = bnx2x_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_UC_LIST_MAC,
1855 PMD_DRV_LOG(NOTICE, sc,
1856 "Failed to delete UC MACs list (%d)", rc);
1860 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 0);
1862 /* Set "drop all" to stop Rx */
1865 * We need to take the if_maddr_lock() here in order to prevent
1866 * a race between the completion code and this code.
1869 if (bnx2x_test_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state)) {
1870 bnx2x_set_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state);
1872 bnx2x_set_storm_rx_mode(sc);
1875 /* Clean up multicast configuration */
1876 rparam.mcast_obj = &sc->mcast_obj;
1877 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
1879 PMD_DRV_LOG(NOTICE, sc,
1880 "Failed to send DEL MCAST command (%d)", rc);
1884 * Send the UNLOAD_REQUEST to the MCP. This will return if
1885 * this function should perform FUNCTION, PORT, or COMMON HW
1888 reset_code = bnx2x_send_unload_req(sc, unload_mode);
1891 * (assumption: No Attention from MCP at this stage)
1892 * PMF probably in the middle of TX disable/enable transaction
1894 rc = bnx2x_func_wait_started(sc);
1896 PMD_DRV_LOG(NOTICE, sc, "bnx2x_func_wait_started failed");
1900 * Close multi and leading connections
1901 * Completions for ramrods are collected in a synchronous way
1903 for (i = 0; i < sc->num_queues; i++) {
1904 if (bnx2x_stop_queue(sc, i)) {
1910 * If SP settings didn't get completed so far - something
1911 * very wrong has happen.
1913 if (!bnx2x_wait_sp_comp(sc, ~0x0UL)) {
1914 PMD_DRV_LOG(NOTICE, sc, "Common slow path ramrods got stuck!");
1919 rc = bnx2x_func_stop(sc);
1921 PMD_DRV_LOG(NOTICE, sc, "Function stop failed!");
1924 /* disable HW interrupts */
1925 bnx2x_int_disable_sync(sc, TRUE);
1927 /* Reset the chip */
1928 rc = bnx2x_reset_hw(sc, reset_code);
1930 PMD_DRV_LOG(NOTICE, sc, "Hardware reset failed");
1933 /* Report UNLOAD_DONE to MCP */
1934 bnx2x_send_unload_done(sc, keep_link);
1937 static void bnx2x_disable_close_the_gate(struct bnx2x_softc *sc)
1941 PMD_DRV_LOG(DEBUG, sc, "Disabling 'close the gates'");
1943 val = REG_RD(sc, MISC_REG_AEU_GENERAL_MASK);
1944 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
1945 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
1946 REG_WR(sc, MISC_REG_AEU_GENERAL_MASK, val);
1950 * Cleans the object that have internal lists without sending
1951 * ramrods. Should be run when interrutps are disabled.
1953 static void bnx2x_squeeze_objects(struct bnx2x_softc *sc)
1955 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
1956 struct ecore_mcast_ramrod_params rparam = { NULL };
1957 struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
1960 /* Cleanup MACs' object first... */
1962 /* Wait for completion of requested */
1963 bnx2x_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
1964 /* Perform a dry cleanup */
1965 bnx2x_set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
1967 /* Clean ETH primary MAC */
1968 bnx2x_set_bit(ECORE_ETH_MAC, &vlan_mac_flags);
1969 rc = mac_obj->delete_all(sc, &sc->sp_objs->mac_obj, &vlan_mac_flags,
1972 PMD_DRV_LOG(NOTICE, sc, "Failed to clean ETH MACs (%d)", rc);
1975 /* Cleanup UC list */
1977 bnx2x_set_bit(ECORE_UC_LIST_MAC, &vlan_mac_flags);
1978 rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
1980 PMD_DRV_LOG(NOTICE, sc,
1981 "Failed to clean UC list MACs (%d)", rc);
1984 /* Now clean mcast object... */
1986 rparam.mcast_obj = &sc->mcast_obj;
1987 bnx2x_set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
1989 /* Add a DEL command... */
1990 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
1992 PMD_DRV_LOG(NOTICE, sc,
1993 "Failed to send DEL MCAST command (%d)", rc);
1996 /* now wait until all pending commands are cleared */
1998 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
2001 PMD_DRV_LOG(NOTICE, sc,
2002 "Failed to clean MCAST object (%d)", rc);
2006 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
2010 /* stop the controller */
2013 bnx2x_nic_unload(struct bnx2x_softc *sc, uint32_t unload_mode, uint8_t keep_link)
2015 uint8_t global = FALSE;
2018 PMD_DRV_LOG(DEBUG, sc, "Starting NIC unload...");
2020 /* mark driver as unloaded in shmem2 */
2021 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
2022 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
2023 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
2024 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
2027 if (IS_PF(sc) && sc->recovery_state != BNX2X_RECOVERY_DONE &&
2028 (sc->state == BNX2X_STATE_CLOSED || sc->state == BNX2X_STATE_ERROR)) {
2030 * We can get here if the driver has been unloaded
2031 * during parity error recovery and is either waiting for a
2032 * leader to complete or for other functions to unload and
2033 * then ifconfig down has been issued. In this case we want to
2034 * unload and let other functions to complete a recovery
2037 sc->recovery_state = BNX2X_RECOVERY_DONE;
2039 bnx2x_release_leader_lock(sc);
2042 PMD_DRV_LOG(NOTICE, sc, "Can't unload in closed or error state");
2047 * Nothing to do during unload if previous bnx2x_nic_load()
2048 * did not completed successfully - all resourses are released.
2050 if ((sc->state == BNX2X_STATE_CLOSED) || (sc->state == BNX2X_STATE_ERROR)) {
2054 sc->state = BNX2X_STATE_CLOSING_WAITING_HALT;
2057 sc->rx_mode = BNX2X_RX_MODE_NONE;
2058 bnx2x_set_rx_mode(sc);
2062 /* set ALWAYS_ALIVE bit in shmem */
2063 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
2065 bnx2x_drv_pulse(sc);
2067 bnx2x_stats_handle(sc, STATS_EVENT_STOP);
2068 bnx2x_save_statistics(sc);
2071 /* wait till consumers catch up with producers in all queues */
2072 bnx2x_drain_tx_queues(sc);
2074 /* if VF indicate to PF this function is going down (PF will delete sp
2075 * elements and clear initializations
2078 bnx2x_vf_unload(sc);
2079 } else if (unload_mode != UNLOAD_RECOVERY) {
2080 /* if this is a normal/close unload need to clean up chip */
2081 bnx2x_chip_cleanup(sc, unload_mode, keep_link);
2083 /* Send the UNLOAD_REQUEST to the MCP */
2084 bnx2x_send_unload_req(sc, unload_mode);
2087 * Prevent transactions to host from the functions on the
2088 * engine that doesn't reset global blocks in case of global
2089 * attention once gloabl blocks are reset and gates are opened
2090 * (the engine which leader will perform the recovery
2093 if (!CHIP_IS_E1x(sc)) {
2094 bnx2x_pf_disable(sc);
2097 /* disable HW interrupts */
2098 bnx2x_int_disable_sync(sc, TRUE);
2100 /* Report UNLOAD_DONE to MCP */
2101 bnx2x_send_unload_done(sc, FALSE);
2105 * At this stage no more interrupts will arrive so we may safely clean
2106 * the queue'able objects here in case they failed to get cleaned so far.
2109 bnx2x_squeeze_objects(sc);
2112 /* There should be no more pending SP commands at this stage */
2121 bnx2x_free_fw_stats_mem(sc);
2123 sc->state = BNX2X_STATE_CLOSED;
2126 * Check if there are pending parity attentions. If there are - set
2127 * RECOVERY_IN_PROGRESS.
2129 if (IS_PF(sc) && bnx2x_chk_parity_attn(sc, &global, FALSE)) {
2130 bnx2x_set_reset_in_progress(sc);
2132 /* Set RESET_IS_GLOBAL if needed */
2134 bnx2x_set_reset_global(sc);
2139 * The last driver must disable a "close the gate" if there is no
2140 * parity attention or "process kill" pending.
2142 if (IS_PF(sc) && !bnx2x_clear_pf_load(sc) &&
2143 bnx2x_reset_is_done(sc, SC_PATH(sc))) {
2144 bnx2x_disable_close_the_gate(sc);
2147 PMD_DRV_LOG(DEBUG, sc, "Ended NIC unload");
2153 * Encapsulte an mbuf cluster into the tx bd chain and makes the memory
2154 * visible to the controller.
2156 * If an mbuf is submitted to this routine and cannot be given to the
2157 * controller (e.g. it has too many fragments) then the function may free
2158 * the mbuf and return to the caller.
2161 * int: Number of TX BDs used for the mbuf
2163 * Note the side effect that an mbuf may be freed if it causes a problem.
2165 int bnx2x_tx_encap(struct bnx2x_tx_queue *txq, struct rte_mbuf *m0)
2167 struct eth_tx_start_bd *tx_start_bd;
2168 uint16_t bd_prod, pkt_prod;
2169 struct bnx2x_softc *sc;
2173 bd_prod = txq->tx_bd_tail;
2174 pkt_prod = txq->tx_pkt_tail;
2176 txq->sw_ring[TX_BD(pkt_prod, txq)] = m0;
2178 tx_start_bd = &txq->tx_ring[TX_BD(bd_prod, txq)].start_bd;
2181 rte_cpu_to_le_64(rte_mbuf_data_iova(m0));
2182 tx_start_bd->nbytes = rte_cpu_to_le_16(m0->data_len);
2183 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
2184 tx_start_bd->general_data =
2185 (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
2187 tx_start_bd->nbd = rte_cpu_to_le_16(2);
2189 if (m0->ol_flags & PKT_TX_VLAN_PKT) {
2190 tx_start_bd->vlan_or_ethertype =
2191 rte_cpu_to_le_16(m0->vlan_tci);
2192 tx_start_bd->bd_flags.as_bitfield |=
2193 (X_ETH_OUTBAND_VLAN <<
2194 ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
2197 tx_start_bd->vlan_or_ethertype =
2198 rte_cpu_to_le_16(pkt_prod);
2200 struct rte_ether_hdr *eh =
2201 rte_pktmbuf_mtod(m0, struct rte_ether_hdr *);
2203 tx_start_bd->vlan_or_ethertype =
2204 rte_cpu_to_le_16(rte_be_to_cpu_16(eh->ether_type));
2208 bd_prod = NEXT_TX_BD(bd_prod);
2210 struct eth_tx_parse_bd_e2 *tx_parse_bd;
2211 const struct rte_ether_hdr *eh =
2212 rte_pktmbuf_mtod(m0, struct rte_ether_hdr *);
2213 uint8_t mac_type = UNICAST_ADDRESS;
2216 &txq->tx_ring[TX_BD(bd_prod, txq)].parse_bd_e2;
2217 if (rte_is_multicast_ether_addr(&eh->d_addr)) {
2218 if (rte_is_broadcast_ether_addr(&eh->d_addr))
2219 mac_type = BROADCAST_ADDRESS;
2221 mac_type = MULTICAST_ADDRESS;
2223 tx_parse_bd->parsing_data =
2224 (mac_type << ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE_SHIFT);
2226 rte_memcpy(&tx_parse_bd->data.mac_addr.dst_hi,
2227 &eh->d_addr.addr_bytes[0], 2);
2228 rte_memcpy(&tx_parse_bd->data.mac_addr.dst_mid,
2229 &eh->d_addr.addr_bytes[2], 2);
2230 rte_memcpy(&tx_parse_bd->data.mac_addr.dst_lo,
2231 &eh->d_addr.addr_bytes[4], 2);
2232 rte_memcpy(&tx_parse_bd->data.mac_addr.src_hi,
2233 &eh->s_addr.addr_bytes[0], 2);
2234 rte_memcpy(&tx_parse_bd->data.mac_addr.src_mid,
2235 &eh->s_addr.addr_bytes[2], 2);
2236 rte_memcpy(&tx_parse_bd->data.mac_addr.src_lo,
2237 &eh->s_addr.addr_bytes[4], 2);
2239 tx_parse_bd->data.mac_addr.dst_hi =
2240 rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.dst_hi);
2241 tx_parse_bd->data.mac_addr.dst_mid =
2242 rte_cpu_to_be_16(tx_parse_bd->data.
2244 tx_parse_bd->data.mac_addr.dst_lo =
2245 rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.dst_lo);
2246 tx_parse_bd->data.mac_addr.src_hi =
2247 rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.src_hi);
2248 tx_parse_bd->data.mac_addr.src_mid =
2249 rte_cpu_to_be_16(tx_parse_bd->data.
2251 tx_parse_bd->data.mac_addr.src_lo =
2252 rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.src_lo);
2255 "PBD dst %x %x %x src %x %x %x p_data %x",
2256 tx_parse_bd->data.mac_addr.dst_hi,
2257 tx_parse_bd->data.mac_addr.dst_mid,
2258 tx_parse_bd->data.mac_addr.dst_lo,
2259 tx_parse_bd->data.mac_addr.src_hi,
2260 tx_parse_bd->data.mac_addr.src_mid,
2261 tx_parse_bd->data.mac_addr.src_lo,
2262 tx_parse_bd->parsing_data);
2266 "start bd: nbytes %d flags %x vlan %x",
2267 tx_start_bd->nbytes,
2268 tx_start_bd->bd_flags.as_bitfield,
2269 tx_start_bd->vlan_or_ethertype);
2271 bd_prod = NEXT_TX_BD(bd_prod);
2274 if (TX_IDX(bd_prod) < 2)
2277 txq->nb_tx_avail -= 2;
2278 txq->tx_bd_tail = bd_prod;
2279 txq->tx_pkt_tail = pkt_prod;
2284 static uint16_t bnx2x_cid_ilt_lines(struct bnx2x_softc *sc)
2286 return L2_ILT_LINES(sc);
2289 static void bnx2x_ilt_set_info(struct bnx2x_softc *sc)
2291 struct ilt_client_info *ilt_client;
2292 struct ecore_ilt *ilt = sc->ilt;
2295 PMD_INIT_FUNC_TRACE(sc);
2297 ilt->start_line = FUNC_ILT_BASE(SC_FUNC(sc));
2300 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
2301 ilt_client->client_num = ILT_CLIENT_CDU;
2302 ilt_client->page_size = CDU_ILT_PAGE_SZ;
2303 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
2304 ilt_client->start = line;
2305 line += bnx2x_cid_ilt_lines(sc);
2307 if (CNIC_SUPPORT(sc)) {
2308 line += CNIC_ILT_LINES;
2311 ilt_client->end = (line - 1);
2314 if (QM_INIT(sc->qm_cid_count)) {
2315 ilt_client = &ilt->clients[ILT_CLIENT_QM];
2316 ilt_client->client_num = ILT_CLIENT_QM;
2317 ilt_client->page_size = QM_ILT_PAGE_SZ;
2318 ilt_client->flags = 0;
2319 ilt_client->start = line;
2321 /* 4 bytes for each cid */
2322 line += DIV_ROUND_UP(sc->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
2325 ilt_client->end = (line - 1);
2328 if (CNIC_SUPPORT(sc)) {
2330 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
2331 ilt_client->client_num = ILT_CLIENT_SRC;
2332 ilt_client->page_size = SRC_ILT_PAGE_SZ;
2333 ilt_client->flags = 0;
2334 ilt_client->start = line;
2335 line += SRC_ILT_LINES;
2336 ilt_client->end = (line - 1);
2339 ilt_client = &ilt->clients[ILT_CLIENT_TM];
2340 ilt_client->client_num = ILT_CLIENT_TM;
2341 ilt_client->page_size = TM_ILT_PAGE_SZ;
2342 ilt_client->flags = 0;
2343 ilt_client->start = line;
2344 line += TM_ILT_LINES;
2345 ilt_client->end = (line - 1);
2348 assert((line <= ILT_MAX_LINES));
2351 static void bnx2x_set_fp_rx_buf_size(struct bnx2x_softc *sc)
2355 for (i = 0; i < sc->num_queues; i++) {
2356 /* get the Rx buffer size for RX frames */
2357 sc->fp[i].rx_buf_size =
2358 (IP_HEADER_ALIGNMENT_PADDING + ETH_OVERHEAD + sc->mtu);
2362 int bnx2x_alloc_ilt_mem(struct bnx2x_softc *sc)
2365 sc->ilt = rte_malloc("", sizeof(struct ecore_ilt), RTE_CACHE_LINE_SIZE);
2367 return sc->ilt == NULL;
2370 static int bnx2x_alloc_ilt_lines_mem(struct bnx2x_softc *sc)
2372 sc->ilt->lines = rte_calloc("",
2373 sizeof(struct ilt_line), ILT_MAX_LINES,
2374 RTE_CACHE_LINE_SIZE);
2375 return sc->ilt->lines == NULL;
2378 void bnx2x_free_ilt_mem(struct bnx2x_softc *sc)
2384 static void bnx2x_free_ilt_lines_mem(struct bnx2x_softc *sc)
2386 if (sc->ilt->lines != NULL) {
2387 rte_free(sc->ilt->lines);
2388 sc->ilt->lines = NULL;
2392 static void bnx2x_free_mem(struct bnx2x_softc *sc)
2396 for (i = 0; i < L2_ILT_LINES(sc); i++) {
2397 sc->context[i].vcxt = NULL;
2398 sc->context[i].size = 0;
2401 ecore_ilt_mem_op(sc, ILT_MEMOP_FREE);
2403 bnx2x_free_ilt_lines_mem(sc);
2406 static int bnx2x_alloc_mem(struct bnx2x_softc *sc)
2411 char cdu_name[RTE_MEMZONE_NAMESIZE];
2414 * Allocate memory for CDU context:
2415 * This memory is allocated separately and not in the generic ILT
2416 * functions because CDU differs in few aspects:
2417 * 1. There can be multiple entities allocating memory for context -
2418 * regular L2, CNIC, and SRIOV drivers. Each separately controls
2419 * its own ILT lines.
2420 * 2. Since CDU page-size is not a single 4KB page (which is the case
2421 * for the other ILT clients), to be efficient we want to support
2422 * allocation of sub-page-size in the last entry.
2423 * 3. Context pointers are used by the driver to pass to FW / update
2424 * the context (for the other ILT clients the pointers are used just to
2425 * free the memory during unload).
2427 context_size = (sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(sc));
2428 for (i = 0, allocated = 0; allocated < context_size; i++) {
2429 sc->context[i].size = min(CDU_ILT_PAGE_SZ,
2430 (context_size - allocated));
2432 snprintf(cdu_name, sizeof(cdu_name), "cdu_%d", i);
2433 if (bnx2x_dma_alloc(sc, sc->context[i].size,
2434 &sc->context[i].vcxt_dma,
2435 cdu_name, BNX2X_PAGE_SIZE) != 0) {
2440 sc->context[i].vcxt =
2441 (union cdu_context *)sc->context[i].vcxt_dma.vaddr;
2443 allocated += sc->context[i].size;
2446 bnx2x_alloc_ilt_lines_mem(sc);
2448 if (ecore_ilt_mem_op(sc, ILT_MEMOP_ALLOC)) {
2449 PMD_DRV_LOG(NOTICE, sc, "ecore_ilt_mem_op ILT_MEMOP_ALLOC failed");
2457 static void bnx2x_free_fw_stats_mem(struct bnx2x_softc *sc)
2459 bnx2x_dma_free(&sc->fw_stats_dma);
2460 sc->fw_stats_num = 0;
2462 sc->fw_stats_req_size = 0;
2463 sc->fw_stats_req = NULL;
2464 sc->fw_stats_req_mapping = 0;
2466 sc->fw_stats_data_size = 0;
2467 sc->fw_stats_data = NULL;
2468 sc->fw_stats_data_mapping = 0;
2471 static int bnx2x_alloc_fw_stats_mem(struct bnx2x_softc *sc)
2473 uint8_t num_queue_stats;
2474 int num_groups, vf_headroom = 0;
2476 /* number of queues for statistics is number of eth queues */
2477 num_queue_stats = BNX2X_NUM_ETH_QUEUES(sc);
2480 * Total number of FW statistics requests =
2481 * 1 for port stats + 1 for PF stats + num of queues
2483 sc->fw_stats_num = (2 + num_queue_stats);
2486 * Request is built from stats_query_header and an array of
2487 * stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT
2488 * rules. The real number or requests is configured in the
2489 * stats_query_header.
2491 num_groups = (sc->fw_stats_num + vf_headroom) / STATS_QUERY_CMD_COUNT;
2492 if ((sc->fw_stats_num + vf_headroom) % STATS_QUERY_CMD_COUNT)
2495 sc->fw_stats_req_size =
2496 (sizeof(struct stats_query_header) +
2497 (num_groups * sizeof(struct stats_query_cmd_group)));
2500 * Data for statistics requests + stats_counter.
2501 * stats_counter holds per-STORM counters that are incremented when
2502 * STORM has finished with the current request. Memory for FCoE
2503 * offloaded statistics are counted anyway, even if they will not be sent.
2504 * VF stats are not accounted for here as the data of VF stats is stored
2505 * in memory allocated by the VF, not here.
2507 sc->fw_stats_data_size =
2508 (sizeof(struct stats_counter) +
2509 sizeof(struct per_port_stats) + sizeof(struct per_pf_stats) +
2510 /* sizeof(struct fcoe_statistics_params) + */
2511 (sizeof(struct per_queue_stats) * num_queue_stats));
2513 if (bnx2x_dma_alloc(sc, (sc->fw_stats_req_size + sc->fw_stats_data_size),
2514 &sc->fw_stats_dma, "fw_stats",
2515 RTE_CACHE_LINE_SIZE) != 0) {
2516 bnx2x_free_fw_stats_mem(sc);
2520 /* set up the shortcuts */
2522 sc->fw_stats_req = (struct bnx2x_fw_stats_req *)sc->fw_stats_dma.vaddr;
2523 sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr;
2526 (struct bnx2x_fw_stats_data *)((uint8_t *) sc->fw_stats_dma.vaddr +
2527 sc->fw_stats_req_size);
2528 sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr +
2529 sc->fw_stats_req_size);
2536 * 0-7 - Engine0 load counter.
2537 * 8-15 - Engine1 load counter.
2538 * 16 - Engine0 RESET_IN_PROGRESS bit.
2539 * 17 - Engine1 RESET_IN_PROGRESS bit.
2540 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active
2541 * function on the engine
2542 * 19 - Engine1 ONE_IS_LOADED.
2543 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
2544 * leader to complete (check for both RESET_IN_PROGRESS bits and not
2545 * for just the one belonging to its engine).
2547 #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
2548 #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
2549 #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
2550 #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
2551 #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
2552 #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
2553 #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
2554 #define BNX2X_GLOBAL_RESET_BIT 0x00040000
2556 /* set the GLOBAL_RESET bit, should be run under rtnl lock */
2557 static void bnx2x_set_reset_global(struct bnx2x_softc *sc)
2560 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2561 val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2562 REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
2563 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2566 /* clear the GLOBAL_RESET bit, should be run under rtnl lock */
2567 static void bnx2x_clear_reset_global(struct bnx2x_softc *sc)
2570 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2571 val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2572 REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
2573 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2576 /* checks the GLOBAL_RESET bit, should be run under rtnl lock */
2577 static uint8_t bnx2x_reset_is_global(struct bnx2x_softc *sc)
2579 return REG_RD(sc, BNX2X_RECOVERY_GLOB_REG) & BNX2X_GLOBAL_RESET_BIT;
2582 /* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */
2583 static void bnx2x_set_reset_done(struct bnx2x_softc *sc)
2586 uint32_t bit = SC_PATH(sc) ? BNX2X_PATH1_RST_IN_PROG_BIT :
2587 BNX2X_PATH0_RST_IN_PROG_BIT;
2589 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2591 val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2594 REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
2596 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2599 /* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */
2600 static void bnx2x_set_reset_in_progress(struct bnx2x_softc *sc)
2603 uint32_t bit = SC_PATH(sc) ? BNX2X_PATH1_RST_IN_PROG_BIT :
2604 BNX2X_PATH0_RST_IN_PROG_BIT;
2606 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2608 val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2611 REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
2613 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2616 /* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */
2617 static uint8_t bnx2x_reset_is_done(struct bnx2x_softc *sc, int engine)
2619 uint32_t val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2620 uint32_t bit = engine ? BNX2X_PATH1_RST_IN_PROG_BIT :
2621 BNX2X_PATH0_RST_IN_PROG_BIT;
2623 /* return false if bit is set */
2624 return (val & bit) ? FALSE : TRUE;
2627 /* get the load status for an engine, should be run under rtnl lock */
2628 static uint8_t bnx2x_get_load_status(struct bnx2x_softc *sc, int engine)
2630 uint32_t mask = engine ? BNX2X_PATH1_LOAD_CNT_MASK :
2631 BNX2X_PATH0_LOAD_CNT_MASK;
2632 uint32_t shift = engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
2633 BNX2X_PATH0_LOAD_CNT_SHIFT;
2634 uint32_t val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2636 val = ((val & mask) >> shift);
2641 /* set pf load mark */
2642 static void bnx2x_set_pf_load(struct bnx2x_softc *sc)
2646 uint32_t mask = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_MASK :
2647 BNX2X_PATH0_LOAD_CNT_MASK;
2648 uint32_t shift = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
2649 BNX2X_PATH0_LOAD_CNT_SHIFT;
2651 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2653 PMD_INIT_FUNC_TRACE(sc);
2655 val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2657 /* get the current counter value */
2658 val1 = ((val & mask) >> shift);
2660 /* set bit of this PF */
2661 val1 |= (1 << SC_ABS_FUNC(sc));
2663 /* clear the old value */
2666 /* set the new one */
2667 val |= ((val1 << shift) & mask);
2669 REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
2671 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2674 /* clear pf load mark */
2675 static uint8_t bnx2x_clear_pf_load(struct bnx2x_softc *sc)
2678 uint32_t mask = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_MASK :
2679 BNX2X_PATH0_LOAD_CNT_MASK;
2680 uint32_t shift = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
2681 BNX2X_PATH0_LOAD_CNT_SHIFT;
2683 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2684 val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
2686 /* get the current counter value */
2687 val1 = (val & mask) >> shift;
2689 /* clear bit of that PF */
2690 val1 &= ~(1 << SC_ABS_FUNC(sc));
2692 /* clear the old value */
2695 /* set the new one */
2696 val |= ((val1 << shift) & mask);
2698 REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
2699 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
2703 /* send load requrest to mcp and analyze response */
2704 static int bnx2x_nic_load_request(struct bnx2x_softc *sc, uint32_t * load_code)
2706 PMD_INIT_FUNC_TRACE(sc);
2710 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
2711 DRV_MSG_SEQ_NUMBER_MASK);
2713 PMD_DRV_LOG(DEBUG, sc, "initial fw_seq 0x%04x", sc->fw_seq);
2716 /* get the current FW pulse sequence */
2717 sc->fw_drv_pulse_wr_seq =
2718 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb) &
2719 DRV_PULSE_SEQ_MASK);
2721 /* set ALWAYS_ALIVE bit in shmem */
2722 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
2723 bnx2x_drv_pulse(sc);
2727 (*load_code) = bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
2728 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
2730 /* if the MCP fails to respond we must abort */
2731 if (!(*load_code)) {
2732 PMD_DRV_LOG(NOTICE, sc, "MCP response failure!");
2736 /* if MCP refused then must abort */
2737 if ((*load_code) == FW_MSG_CODE_DRV_LOAD_REFUSED) {
2738 PMD_DRV_LOG(NOTICE, sc, "MCP refused load request");
2746 * Check whether another PF has already loaded FW to chip. In virtualized
2747 * environments a pf from anoth VM may have already initialized the device
2748 * including loading FW.
2750 static int bnx2x_nic_load_analyze_req(struct bnx2x_softc *sc, uint32_t load_code)
2752 uint32_t my_fw, loaded_fw;
2754 /* is another pf loaded on this engine? */
2755 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
2756 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
2757 /* build my FW version dword */
2758 my_fw = (BNX2X_5710_FW_MAJOR_VERSION +
2759 (BNX2X_5710_FW_MINOR_VERSION << 8) +
2760 (BNX2X_5710_FW_REVISION_VERSION << 16) +
2761 (BNX2X_5710_FW_ENGINEERING_VERSION << 24));
2763 /* read loaded FW from chip */
2764 loaded_fw = REG_RD(sc, XSEM_REG_PRAM);
2765 PMD_DRV_LOG(DEBUG, sc, "loaded FW 0x%08x / my FW 0x%08x",
2768 /* abort nic load if version mismatch */
2769 if (my_fw != loaded_fw) {
2770 PMD_DRV_LOG(NOTICE, sc,
2771 "FW 0x%08x already loaded (mine is 0x%08x)",
2780 /* mark PMF if applicable */
2781 static void bnx2x_nic_load_pmf(struct bnx2x_softc *sc, uint32_t load_code)
2783 uint32_t ncsi_oem_data_addr;
2785 PMD_INIT_FUNC_TRACE(sc);
2787 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
2788 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
2789 (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
2791 * Barrier here for ordering between the writing to sc->port.pmf here
2792 * and reading it from the periodic task.
2800 PMD_DRV_LOG(DEBUG, sc, "pmf %d", sc->port.pmf);
2802 if (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) {
2803 if (SHMEM2_HAS(sc, ncsi_oem_data_addr)) {
2804 ncsi_oem_data_addr = SHMEM2_RD(sc, ncsi_oem_data_addr);
2805 if (ncsi_oem_data_addr) {
2807 (ncsi_oem_data_addr +
2808 offsetof(struct glob_ncsi_oem_data,
2809 driver_version)), 0);
2815 static void bnx2x_read_mf_cfg(struct bnx2x_softc *sc)
2817 int n = (CHIP_IS_MODE_4_PORT(sc) ? 2 : 1);
2821 if (BNX2X_NOMCP(sc)) {
2822 return; /* what should be the default bvalue in this case */
2826 * The formula for computing the absolute function number is...
2827 * For 2 port configuration (4 functions per port):
2828 * abs_func = 2 * vn + SC_PORT + SC_PATH
2829 * For 4 port configuration (2 functions per port):
2830 * abs_func = 4 * vn + 2 * SC_PORT + SC_PATH
2832 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
2833 abs_func = (n * (2 * vn + SC_PORT(sc)) + SC_PATH(sc));
2834 if (abs_func >= E1H_FUNC_MAX) {
2837 sc->devinfo.mf_info.mf_config[vn] =
2838 MFCFG_RD(sc, func_mf_config[abs_func].config);
2841 if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] &
2842 FUNC_MF_CFG_FUNC_DISABLED) {
2843 PMD_DRV_LOG(DEBUG, sc, "mf_cfg function disabled");
2844 sc->flags |= BNX2X_MF_FUNC_DIS;
2846 PMD_DRV_LOG(DEBUG, sc, "mf_cfg function enabled");
2847 sc->flags &= ~BNX2X_MF_FUNC_DIS;
2851 /* acquire split MCP access lock register */
2852 static int bnx2x_acquire_alr(struct bnx2x_softc *sc)
2856 for (j = 0; j < 1000; j++) {
2858 REG_WR(sc, GRCBASE_MCP + 0x9c, val);
2859 val = REG_RD(sc, GRCBASE_MCP + 0x9c);
2860 if (val & (1L << 31))
2866 if (!(val & (1L << 31))) {
2867 PMD_DRV_LOG(NOTICE, sc, "Cannot acquire MCP access lock register");
2874 /* release split MCP access lock register */
2875 static void bnx2x_release_alr(struct bnx2x_softc *sc)
2877 REG_WR(sc, GRCBASE_MCP + 0x9c, 0);
2880 static void bnx2x_fan_failure(struct bnx2x_softc *sc)
2882 int port = SC_PORT(sc);
2883 uint32_t ext_phy_config;
2885 /* mark the failure */
2887 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
2889 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
2890 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
2891 SHMEM_WR(sc, dev_info.port_hw_config[port].external_phy_config,
2894 /* log the failure */
2895 PMD_DRV_LOG(INFO, sc,
2896 "Fan Failure has caused the driver to shutdown "
2897 "the card to prevent permanent damage. "
2898 "Please contact OEM Support for assistance");
2900 rte_panic("Schedule task to handle fan failure");
2903 /* this function is called upon a link interrupt */
2904 static void bnx2x_link_attn(struct bnx2x_softc *sc)
2906 uint32_t pause_enabled = 0;
2907 struct host_port_stats *pstats;
2910 /* Make sure that we are synced with the current statistics */
2911 bnx2x_stats_handle(sc, STATS_EVENT_STOP);
2913 elink_link_update(&sc->link_params, &sc->link_vars);
2915 if (sc->link_vars.link_up) {
2917 /* dropless flow control */
2918 if (sc->dropless_fc) {
2921 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
2926 (BAR_USTRORM_INTMEM +
2927 USTORM_ETH_PAUSE_ENABLED_OFFSET(SC_PORT(sc))),
2931 if (sc->link_vars.mac_type != ELINK_MAC_TYPE_EMAC) {
2932 pstats = BNX2X_SP(sc, port_stats);
2933 /* reset old mac stats */
2934 memset(&(pstats->mac_stx[0]), 0,
2935 sizeof(struct mac_stx));
2938 if (sc->state == BNX2X_STATE_OPEN) {
2939 bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
2943 if (sc->link_vars.link_up && sc->link_vars.line_speed) {
2944 cmng_fns = bnx2x_get_cmng_fns_mode(sc);
2946 if (cmng_fns != CMNG_FNS_NONE) {
2947 bnx2x_cmng_fns_init(sc, FALSE, cmng_fns);
2948 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
2952 bnx2x_link_report_locked(sc);
2955 bnx2x_link_sync_notify(sc);
2959 static void bnx2x_attn_int_asserted(struct bnx2x_softc *sc, uint32_t asserted)
2961 int port = SC_PORT(sc);
2962 uint32_t aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
2963 MISC_REG_AEU_MASK_ATTN_FUNC_0;
2964 uint32_t nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
2965 NIG_REG_MASK_INTERRUPT_PORT0;
2967 uint32_t nig_mask = 0;
2972 if (sc->attn_state & asserted) {
2973 PMD_DRV_LOG(ERR, sc, "IGU ERROR attn=0x%08x", asserted);
2976 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2978 aeu_mask = REG_RD(sc, aeu_addr);
2980 aeu_mask &= ~(asserted & 0x3ff);
2982 REG_WR(sc, aeu_addr, aeu_mask);
2984 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
2986 sc->attn_state |= asserted;
2988 if (asserted & ATTN_HARD_WIRED_MASK) {
2989 if (asserted & ATTN_NIG_FOR_FUNC) {
2991 bnx2x_acquire_phy_lock(sc);
2992 /* save nig interrupt mask */
2993 nig_mask = REG_RD(sc, nig_int_mask_addr);
2995 /* If nig_mask is not set, no need to call the update function */
2997 REG_WR(sc, nig_int_mask_addr, 0);
2999 bnx2x_link_attn(sc);
3002 /* handle unicore attn? */
3005 if (asserted & ATTN_SW_TIMER_4_FUNC) {
3006 PMD_DRV_LOG(DEBUG, sc, "ATTN_SW_TIMER_4_FUNC!");
3009 if (asserted & GPIO_2_FUNC) {
3010 PMD_DRV_LOG(DEBUG, sc, "GPIO_2_FUNC!");
3013 if (asserted & GPIO_3_FUNC) {
3014 PMD_DRV_LOG(DEBUG, sc, "GPIO_3_FUNC!");
3017 if (asserted & GPIO_4_FUNC) {
3018 PMD_DRV_LOG(DEBUG, sc, "GPIO_4_FUNC!");
3022 if (asserted & ATTN_GENERAL_ATTN_1) {
3023 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_1!");
3024 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3026 if (asserted & ATTN_GENERAL_ATTN_2) {
3027 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_2!");
3028 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3030 if (asserted & ATTN_GENERAL_ATTN_3) {
3031 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_3!");
3032 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3035 if (asserted & ATTN_GENERAL_ATTN_4) {
3036 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_4!");
3037 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3039 if (asserted & ATTN_GENERAL_ATTN_5) {
3040 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_5!");
3041 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3043 if (asserted & ATTN_GENERAL_ATTN_6) {
3044 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_6!");
3045 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3050 if (sc->devinfo.int_block == INT_BLOCK_HC) {
3052 (HC_REG_COMMAND_REG + port * 32 +
3053 COMMAND_REG_ATTN_BITS_SET);
3055 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER * 8);
3058 PMD_DRV_LOG(DEBUG, sc, "about to mask 0x%08x at %s addr 0x%08x",
3060 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU",
3062 REG_WR(sc, reg_addr, asserted);
3064 /* now set back the mask */
3065 if (asserted & ATTN_NIG_FOR_FUNC) {
3067 * Verify that IGU ack through BAR was written before restoring
3068 * NIG mask. This loop should exit after 2-3 iterations max.
3070 if (sc->devinfo.int_block != INT_BLOCK_HC) {
3075 REG_RD(sc, IGU_REG_ATTENTION_ACK_BITS);
3076 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0)
3077 && (++cnt < MAX_IGU_ATTN_ACK_TO));
3080 PMD_DRV_LOG(ERR, sc,
3081 "Failed to verify IGU ack on time");
3087 REG_WR(sc, nig_int_mask_addr, nig_mask);
3089 bnx2x_release_phy_lock(sc);
3094 bnx2x_print_next_block(__rte_unused struct bnx2x_softc *sc, __rte_unused int idx,
3095 __rte_unused const char *blk)
3097 PMD_DRV_LOG(INFO, sc, "%s%s", idx ? ", " : "", blk);
3101 bnx2x_check_blocks_with_parity0(struct bnx2x_softc *sc, uint32_t sig, int par_num,
3104 uint32_t cur_bit = 0;
3107 for (i = 0; sig; i++) {
3108 cur_bit = ((uint32_t) 0x1 << i);
3109 if (sig & cur_bit) {
3111 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
3113 bnx2x_print_next_block(sc, par_num++,
3116 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
3118 bnx2x_print_next_block(sc, par_num++,
3121 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
3123 bnx2x_print_next_block(sc, par_num++,
3126 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
3128 bnx2x_print_next_block(sc, par_num++,
3131 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3133 bnx2x_print_next_block(sc, par_num++,
3136 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
3138 bnx2x_print_next_block(sc, par_num++,
3141 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3143 bnx2x_print_next_block(sc, par_num++,
3157 bnx2x_check_blocks_with_parity1(struct bnx2x_softc *sc, uint32_t sig, int par_num,
3158 uint8_t * global, uint8_t print)
3161 uint32_t cur_bit = 0;
3162 for (i = 0; sig; i++) {
3163 cur_bit = ((uint32_t) 0x1 << i);
3164 if (sig & cur_bit) {
3166 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3168 bnx2x_print_next_block(sc, par_num++,
3171 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
3173 bnx2x_print_next_block(sc, par_num++,
3176 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3178 bnx2x_print_next_block(sc, par_num++,
3181 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
3183 bnx2x_print_next_block(sc, par_num++,
3186 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3188 bnx2x_print_next_block(sc, par_num++,
3191 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
3193 bnx2x_print_next_block(sc, par_num++,
3196 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
3198 bnx2x_print_next_block(sc, par_num++,
3201 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3203 bnx2x_print_next_block(sc, par_num++,
3206 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
3208 bnx2x_print_next_block(sc, par_num++,
3212 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
3214 bnx2x_print_next_block(sc, par_num++,
3217 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
3219 bnx2x_print_next_block(sc, par_num++,
3222 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
3224 bnx2x_print_next_block(sc, par_num++,
3227 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
3229 bnx2x_print_next_block(sc, par_num++,
3232 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
3234 bnx2x_print_next_block(sc, par_num++,
3237 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
3239 bnx2x_print_next_block(sc, par_num++,
3242 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
3244 bnx2x_print_next_block(sc, par_num++,
3258 bnx2x_check_blocks_with_parity2(struct bnx2x_softc *sc, uint32_t sig, int par_num,
3261 uint32_t cur_bit = 0;
3264 for (i = 0; sig; i++) {
3265 cur_bit = ((uint32_t) 0x1 << i);
3266 if (sig & cur_bit) {
3268 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
3270 bnx2x_print_next_block(sc, par_num++,
3273 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
3275 bnx2x_print_next_block(sc, par_num++,
3278 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
3280 bnx2x_print_next_block(sc, par_num++,
3281 "PXPPCICLOCKCLIENT");
3283 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
3285 bnx2x_print_next_block(sc, par_num++,
3288 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
3290 bnx2x_print_next_block(sc, par_num++,
3293 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3295 bnx2x_print_next_block(sc, par_num++,
3298 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
3300 bnx2x_print_next_block(sc, par_num++,
3303 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
3305 bnx2x_print_next_block(sc, par_num++,
3319 bnx2x_check_blocks_with_parity3(struct bnx2x_softc *sc, uint32_t sig, int par_num,
3320 uint8_t * global, uint8_t print)
3322 uint32_t cur_bit = 0;
3325 for (i = 0; sig; i++) {
3326 cur_bit = ((uint32_t) 0x1 << i);
3327 if (sig & cur_bit) {
3329 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
3331 bnx2x_print_next_block(sc, par_num++,
3335 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
3337 bnx2x_print_next_block(sc, par_num++,
3341 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
3343 bnx2x_print_next_block(sc, par_num++,
3347 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
3349 bnx2x_print_next_block(sc, par_num++,
3364 bnx2x_check_blocks_with_parity4(struct bnx2x_softc *sc, uint32_t sig, int par_num,
3367 uint32_t cur_bit = 0;
3370 for (i = 0; sig; i++) {
3371 cur_bit = ((uint32_t) 0x1 << i);
3372 if (sig & cur_bit) {
3374 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
3376 bnx2x_print_next_block(sc, par_num++,
3379 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
3381 bnx2x_print_next_block(sc, par_num++,
3395 bnx2x_parity_attn(struct bnx2x_softc *sc, uint8_t * global, uint8_t print,
3400 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
3401 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
3402 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
3403 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
3404 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
3405 PMD_DRV_LOG(ERR, sc,
3406 "Parity error: HW block parity attention:"
3407 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x",
3408 (uint32_t) (sig[0] & HW_PRTY_ASSERT_SET_0),
3409 (uint32_t) (sig[1] & HW_PRTY_ASSERT_SET_1),
3410 (uint32_t) (sig[2] & HW_PRTY_ASSERT_SET_2),
3411 (uint32_t) (sig[3] & HW_PRTY_ASSERT_SET_3),
3412 (uint32_t) (sig[4] & HW_PRTY_ASSERT_SET_4));
3415 PMD_DRV_LOG(INFO, sc, "Parity errors detected in blocks: ");
3418 bnx2x_check_blocks_with_parity0(sc, sig[0] &
3419 HW_PRTY_ASSERT_SET_0,
3422 bnx2x_check_blocks_with_parity1(sc, sig[1] &
3423 HW_PRTY_ASSERT_SET_1,
3424 par_num, global, print);
3426 bnx2x_check_blocks_with_parity2(sc, sig[2] &
3427 HW_PRTY_ASSERT_SET_2,
3430 bnx2x_check_blocks_with_parity3(sc, sig[3] &
3431 HW_PRTY_ASSERT_SET_3,
3432 par_num, global, print);
3434 bnx2x_check_blocks_with_parity4(sc, sig[4] &
3435 HW_PRTY_ASSERT_SET_4,
3439 PMD_DRV_LOG(INFO, sc, "");
3448 bnx2x_chk_parity_attn(struct bnx2x_softc *sc, uint8_t * global, uint8_t print)
3450 struct attn_route attn = { {0} };
3451 int port = SC_PORT(sc);
3453 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port * 4);
3454 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port * 4);
3455 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port * 4);
3456 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port * 4);
3458 if (!CHIP_IS_E1x(sc))
3460 REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port * 4);
3462 return bnx2x_parity_attn(sc, global, print, attn.sig);
3465 static void bnx2x_attn_int_deasserted4(struct bnx2x_softc *sc, uint32_t attn)
3469 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
3470 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
3471 PMD_DRV_LOG(INFO, sc, "ERROR: PGLUE hw attention 0x%08x", val);
3472 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
3473 PMD_DRV_LOG(INFO, sc,
3474 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR");
3475 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
3476 PMD_DRV_LOG(INFO, sc,
3477 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR");
3478 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
3479 PMD_DRV_LOG(INFO, sc,
3480 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN");
3481 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
3482 PMD_DRV_LOG(INFO, sc,
3483 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN");
3485 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
3486 PMD_DRV_LOG(INFO, sc,
3487 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN");
3489 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
3490 PMD_DRV_LOG(INFO, sc,
3491 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN");
3492 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
3493 PMD_DRV_LOG(INFO, sc,
3494 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN");
3495 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
3496 PMD_DRV_LOG(INFO, sc,
3497 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN");
3498 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
3499 PMD_DRV_LOG(INFO, sc,
3500 "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW");
3503 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
3504 val = REG_RD(sc, ATC_REG_ATC_INT_STS_CLR);
3505 PMD_DRV_LOG(INFO, sc, "ERROR: ATC hw attention 0x%08x", val);
3506 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
3507 PMD_DRV_LOG(INFO, sc,
3508 "ERROR: ATC_ATC_INT_STS_REG_ADDRESS_ERROR");
3509 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
3510 PMD_DRV_LOG(INFO, sc,
3511 "ERROR: ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND");
3512 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
3513 PMD_DRV_LOG(INFO, sc,
3514 "ERROR: ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS");
3515 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
3516 PMD_DRV_LOG(INFO, sc,
3517 "ERROR: ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT");
3518 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
3519 PMD_DRV_LOG(INFO, sc,
3520 "ERROR: ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR");
3521 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
3522 PMD_DRV_LOG(INFO, sc,
3523 "ERROR: ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU");
3526 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3527 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
3528 PMD_DRV_LOG(INFO, sc,
3529 "ERROR: FATAL parity attention set4 0x%08x",
3531 (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
3533 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
3537 static void bnx2x_e1h_disable(struct bnx2x_softc *sc)
3539 int port = SC_PORT(sc);
3541 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 0);
3544 static void bnx2x_e1h_enable(struct bnx2x_softc *sc)
3546 int port = SC_PORT(sc);
3548 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
3552 * called due to MCP event (on pmf):
3553 * reread new bandwidth configuration
3555 * notify others function about the change
3557 static void bnx2x_config_mf_bw(struct bnx2x_softc *sc)
3559 if (sc->link_vars.link_up) {
3560 bnx2x_cmng_fns_init(sc, TRUE, CMNG_FNS_MINMAX);
3561 bnx2x_link_sync_notify(sc);
3564 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
3567 static void bnx2x_set_mf_bw(struct bnx2x_softc *sc)
3569 bnx2x_config_mf_bw(sc);
3570 bnx2x_fw_command(sc, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3573 static void bnx2x_handle_eee_event(struct bnx2x_softc *sc)
3575 bnx2x_fw_command(sc, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3578 #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3580 static void bnx2x_drv_info_ether_stat(struct bnx2x_softc *sc)
3582 struct eth_stats_info *ether_stat = &sc->sp->drv_info_to_mcp.ether_stat;
3584 strncpy(ether_stat->version, BNX2X_DRIVER_VERSION,
3585 ETH_STAT_INFO_VERSION_LEN);
3587 sc->sp_objs[0].mac_obj.get_n_elements(sc, &sc->sp_objs[0].mac_obj,
3588 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3589 ether_stat->mac_local + MAC_PAD,
3592 ether_stat->mtu_size = sc->mtu;
3594 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3595 ether_stat->promiscuous_mode = 0; // (flags & PROMISC) ? 1 : 0;
3597 ether_stat->txq_size = sc->tx_ring_size;
3598 ether_stat->rxq_size = sc->rx_ring_size;
3601 static void bnx2x_handle_drv_info_req(struct bnx2x_softc *sc)
3603 enum drv_info_opcode op_code;
3604 uint32_t drv_info_ctl = SHMEM2_RD(sc, drv_info_control);
3606 /* if drv_info version supported by MFW doesn't match - send NACK */
3607 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3608 bnx2x_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3612 op_code = ((drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3613 DRV_INFO_CONTROL_OP_CODE_SHIFT);
3615 memset(&sc->sp->drv_info_to_mcp, 0, sizeof(union drv_info_to_mcp));
3618 case ETH_STATS_OPCODE:
3619 bnx2x_drv_info_ether_stat(sc);
3621 case FCOE_STATS_OPCODE:
3622 case ISCSI_STATS_OPCODE:
3624 /* if op code isn't supported - send NACK */
3625 bnx2x_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3630 * If we got drv_info attn from MFW then these fields are defined in
3633 SHMEM2_WR(sc, drv_info_host_addr_lo,
3634 U64_LO(BNX2X_SP_MAPPING(sc, drv_info_to_mcp)));
3635 SHMEM2_WR(sc, drv_info_host_addr_hi,
3636 U64_HI(BNX2X_SP_MAPPING(sc, drv_info_to_mcp)));
3638 bnx2x_fw_command(sc, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3641 static void bnx2x_dcc_event(struct bnx2x_softc *sc, uint32_t dcc_event)
3643 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3645 * This is the only place besides the function initialization
3646 * where the sc->flags can change so it is done without any
3650 mf_info.mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_DISABLED) {
3651 PMD_DRV_LOG(DEBUG, sc, "mf_cfg function disabled");
3652 sc->flags |= BNX2X_MF_FUNC_DIS;
3653 bnx2x_e1h_disable(sc);
3655 PMD_DRV_LOG(DEBUG, sc, "mf_cfg function enabled");
3656 sc->flags &= ~BNX2X_MF_FUNC_DIS;
3657 bnx2x_e1h_enable(sc);
3659 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3662 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
3663 bnx2x_config_mf_bw(sc);
3664 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3667 /* Report results to MCP */
3669 bnx2x_fw_command(sc, DRV_MSG_CODE_DCC_FAILURE, 0);
3671 bnx2x_fw_command(sc, DRV_MSG_CODE_DCC_OK, 0);
3674 static void bnx2x_pmf_update(struct bnx2x_softc *sc)
3676 int port = SC_PORT(sc);
3682 * We need the mb() to ensure the ordering between the writing to
3683 * sc->port.pmf here and reading it from the bnx2x_periodic_task().
3687 /* enable nig attention */
3688 val = (0xff0f | (1 << (SC_VN(sc) + 4)));
3689 if (sc->devinfo.int_block == INT_BLOCK_HC) {
3690 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port * 8, val);
3691 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port * 8, val);
3692 } else if (!CHIP_IS_E1x(sc)) {
3693 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
3694 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
3697 bnx2x_stats_handle(sc, STATS_EVENT_PMF);
3700 static int bnx2x_mc_assert(struct bnx2x_softc *sc)
3704 __rte_unused uint32_t row0, row1, row2, row3;
3708 REG_RD8(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_INDEX_OFFSET);
3710 PMD_DRV_LOG(ERR, sc, "XSTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
3712 /* print the asserts */
3713 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
3717 BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i));
3720 BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) +
3724 BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) +
3728 BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) +
3731 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
3732 PMD_DRV_LOG(ERR, sc,
3733 "XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
3734 i, row3, row2, row1, row0);
3743 REG_RD8(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_INDEX_OFFSET);
3745 PMD_DRV_LOG(ERR, sc, "TSTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
3748 /* print the asserts */
3749 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
3753 BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i));
3756 BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) +
3760 BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) +
3764 BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) +
3767 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
3768 PMD_DRV_LOG(ERR, sc,
3769 "TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
3770 i, row3, row2, row1, row0);
3779 REG_RD8(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_INDEX_OFFSET);
3781 PMD_DRV_LOG(ERR, sc, "CSTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
3784 /* print the asserts */
3785 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
3789 BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i));
3792 BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) +
3796 BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) +
3800 BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) +
3803 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
3804 PMD_DRV_LOG(ERR, sc,
3805 "CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
3806 i, row3, row2, row1, row0);
3815 REG_RD8(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_INDEX_OFFSET);
3817 PMD_DRV_LOG(ERR, sc, "USTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
3820 /* print the asserts */
3821 for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
3825 BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i));
3828 BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) +
3832 BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) +
3836 BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) +
3839 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
3840 PMD_DRV_LOG(ERR, sc,
3841 "USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
3842 i, row3, row2, row1, row0);
3852 static void bnx2x_attn_int_deasserted3(struct bnx2x_softc *sc, uint32_t attn)
3854 int func = SC_FUNC(sc);
3857 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3859 if (attn & BNX2X_PMF_LINK_ASSERT(sc)) {
3861 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func * 4, 0);
3862 bnx2x_read_mf_cfg(sc);
3863 sc->devinfo.mf_info.mf_config[SC_VN(sc)] =
3865 func_mf_config[SC_ABS_FUNC(sc)].config);
3867 SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_status);
3869 if (val & DRV_STATUS_DCC_EVENT_MASK)
3872 DRV_STATUS_DCC_EVENT_MASK));
3874 if (val & DRV_STATUS_SET_MF_BW)
3875 bnx2x_set_mf_bw(sc);
3877 if (val & DRV_STATUS_DRV_INFO_REQ)
3878 bnx2x_handle_drv_info_req(sc);
3880 if ((sc->port.pmf == 0) && (val & DRV_STATUS_PMF))
3881 bnx2x_pmf_update(sc);
3883 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3884 bnx2x_handle_eee_event(sc);
3886 if (sc->link_vars.periodic_flags &
3887 ELINK_PERIODIC_FLAGS_LINK_EVENT) {
3888 /* sync with link */
3889 bnx2x_acquire_phy_lock(sc);
3890 sc->link_vars.periodic_flags &=
3891 ~ELINK_PERIODIC_FLAGS_LINK_EVENT;
3892 bnx2x_release_phy_lock(sc);
3894 bnx2x_link_sync_notify(sc);
3896 bnx2x_link_report(sc);
3900 * Always call it here: bnx2x_link_report() will
3901 * prevent the link indication duplication.
3903 bnx2x_link_status_update(sc);
3905 } else if (attn & BNX2X_MC_ASSERT_BITS) {
3907 PMD_DRV_LOG(ERR, sc, "MC assert!");
3908 bnx2x_mc_assert(sc);
3909 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3910 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3911 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3912 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3913 rte_panic("MC assert!");
3915 } else if (attn & BNX2X_MCP_ASSERT) {
3917 PMD_DRV_LOG(ERR, sc, "MCP assert!");
3918 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_11, 0);
3921 PMD_DRV_LOG(ERR, sc,
3922 "Unknown HW assert! (attn 0x%08x)", attn);
3926 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
3927 PMD_DRV_LOG(ERR, sc, "LATCHED attention 0x%08x (masked)", attn);
3928 if (attn & BNX2X_GRC_TIMEOUT) {
3929 val = REG_RD(sc, MISC_REG_GRC_TIMEOUT_ATTN);
3930 PMD_DRV_LOG(ERR, sc, "GRC time-out 0x%08x", val);
3932 if (attn & BNX2X_GRC_RSV) {
3933 val = REG_RD(sc, MISC_REG_GRC_RSV_ATTN);
3934 PMD_DRV_LOG(ERR, sc, "GRC reserved 0x%08x", val);
3936 REG_WR(sc, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
3940 static void bnx2x_attn_int_deasserted2(struct bnx2x_softc *sc, uint32_t attn)
3942 int port = SC_PORT(sc);
3944 uint32_t val0, mask0, val1, mask1;
3947 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3948 val = REG_RD(sc, CFC_REG_CFC_INT_STS_CLR);
3949 PMD_DRV_LOG(ERR, sc, "CFC hw attention 0x%08x", val);
3950 /* CFC error attention */
3952 PMD_DRV_LOG(ERR, sc, "FATAL error from CFC");
3956 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
3957 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_0);
3958 PMD_DRV_LOG(ERR, sc, "PXP hw attention-0 0x%08x", val);
3959 /* RQ_USDMDP_FIFO_OVERFLOW */
3960 if (val & 0x18000) {
3961 PMD_DRV_LOG(ERR, sc, "FATAL error from PXP");
3964 if (!CHIP_IS_E1x(sc)) {
3965 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_1);
3966 PMD_DRV_LOG(ERR, sc, "PXP hw attention-1 0x%08x", val);
3969 #define PXP2_EOP_ERROR_BIT PXP2_PXP2_INT_STS_CLR_0_REG_WR_PGLUE_EOP_ERROR
3970 #define AEU_PXP2_HW_INT_BIT AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT
3972 if (attn & AEU_PXP2_HW_INT_BIT) {
3973 /* CQ47854 workaround do not panic on
3974 * PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
3976 if (!CHIP_IS_E1x(sc)) {
3977 mask0 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_0);
3978 val1 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_1);
3979 mask1 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_1);
3980 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_0);
3982 * If the only PXP2_EOP_ERROR_BIT is set in
3983 * STS0 and STS1 - clear it
3985 * probably we lose additional attentions between
3986 * STS0 and STS_CLR0, in this case user will not
3987 * be notified about them
3989 if (val0 & mask0 & PXP2_EOP_ERROR_BIT &&
3991 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
3993 /* print the register, since no one can restore it */
3994 PMD_DRV_LOG(ERR, sc,
3995 "PXP2_REG_PXP2_INT_STS_CLR_0 0x%08x", val0);
3998 * if PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
4001 if (val0 & PXP2_EOP_ERROR_BIT) {
4002 PMD_DRV_LOG(ERR, sc, "PXP2_WR_PGLUE_EOP_ERROR");
4005 * if only PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR is
4006 * set then clear attention from PXP2 block without panic
4008 if (((val0 & mask0) == PXP2_EOP_ERROR_BIT) &&
4009 ((val1 & mask1) == 0))
4010 attn &= ~AEU_PXP2_HW_INT_BIT;
4015 if (attn & HW_INTERRUT_ASSERT_SET_2) {
4016 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
4017 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
4019 val = REG_RD(sc, reg_offset);
4020 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
4021 REG_WR(sc, reg_offset, val);
4023 PMD_DRV_LOG(ERR, sc,
4024 "FATAL HW block attention set2 0x%x",
4025 (uint32_t) (attn & HW_INTERRUT_ASSERT_SET_2));
4026 rte_panic("HW block attention set2");
4030 static void bnx2x_attn_int_deasserted1(struct bnx2x_softc *sc, uint32_t attn)
4032 int port = SC_PORT(sc);
4036 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
4037 val = REG_RD(sc, DORQ_REG_DORQ_INT_STS_CLR);
4038 PMD_DRV_LOG(ERR, sc, "DB hw attention 0x%08x", val);
4039 /* DORQ discard attention */
4041 PMD_DRV_LOG(ERR, sc, "FATAL error from DORQ");
4045 if (attn & HW_INTERRUT_ASSERT_SET_1) {
4046 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
4047 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
4049 val = REG_RD(sc, reg_offset);
4050 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
4051 REG_WR(sc, reg_offset, val);
4053 PMD_DRV_LOG(ERR, sc,
4054 "FATAL HW block attention set1 0x%08x",
4055 (uint32_t) (attn & HW_INTERRUT_ASSERT_SET_1));
4056 rte_panic("HW block attention set1");
4060 static void bnx2x_attn_int_deasserted0(struct bnx2x_softc *sc, uint32_t attn)
4062 int port = SC_PORT(sc);
4066 reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4067 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
4069 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
4070 val = REG_RD(sc, reg_offset);
4071 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
4072 REG_WR(sc, reg_offset, val);
4074 PMD_DRV_LOG(WARNING, sc, "SPIO5 hw attention");
4076 /* Fan failure attention */
4077 elink_hw_reset_phy(&sc->link_params);
4078 bnx2x_fan_failure(sc);
4081 if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) {
4082 bnx2x_acquire_phy_lock(sc);
4083 elink_handle_module_detect_int(&sc->link_params);
4084 bnx2x_release_phy_lock(sc);
4087 if (attn & HW_INTERRUT_ASSERT_SET_0) {
4088 val = REG_RD(sc, reg_offset);
4089 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
4090 REG_WR(sc, reg_offset, val);
4092 rte_panic("FATAL HW block attention set0 0x%lx",
4093 (attn & HW_INTERRUT_ASSERT_SET_0));
4097 static void bnx2x_attn_int_deasserted(struct bnx2x_softc *sc, uint32_t deasserted)
4099 struct attn_route attn;
4100 struct attn_route *group_mask;
4101 int port = SC_PORT(sc);
4106 uint8_t global = FALSE;
4109 * Need to take HW lock because MCP or other port might also
4110 * try to handle this event.
4112 bnx2x_acquire_alr(sc);
4114 if (bnx2x_chk_parity_attn(sc, &global, TRUE)) {
4115 sc->recovery_state = BNX2X_RECOVERY_INIT;
4117 /* disable HW interrupts */
4118 bnx2x_int_disable(sc);
4119 bnx2x_release_alr(sc);
4123 attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port * 4);
4124 attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port * 4);
4125 attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port * 4);
4126 attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port * 4);
4127 if (!CHIP_IS_E1x(sc)) {
4129 REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port * 4);
4134 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4135 if (deasserted & (1 << index)) {
4136 group_mask = &sc->attn_group[index];
4138 bnx2x_attn_int_deasserted4(sc,
4140 sig[4] & group_mask->sig[4]);
4141 bnx2x_attn_int_deasserted3(sc,
4143 sig[3] & group_mask->sig[3]);
4144 bnx2x_attn_int_deasserted1(sc,
4146 sig[1] & group_mask->sig[1]);
4147 bnx2x_attn_int_deasserted2(sc,
4149 sig[2] & group_mask->sig[2]);
4150 bnx2x_attn_int_deasserted0(sc,
4152 sig[0] & group_mask->sig[0]);
4156 bnx2x_release_alr(sc);
4158 if (sc->devinfo.int_block == INT_BLOCK_HC) {
4159 reg_addr = (HC_REG_COMMAND_REG + port * 32 +
4160 COMMAND_REG_ATTN_BITS_CLR);
4162 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER * 8);
4166 PMD_DRV_LOG(DEBUG, sc,
4167 "about to mask 0x%08x at %s addr 0x%08x", val,
4168 (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU",
4170 REG_WR(sc, reg_addr, val);
4172 if (~sc->attn_state & deasserted) {
4173 PMD_DRV_LOG(ERR, sc, "IGU error");
4176 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4177 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4179 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4181 aeu_mask = REG_RD(sc, reg_addr);
4183 aeu_mask |= (deasserted & 0x3ff);
4185 REG_WR(sc, reg_addr, aeu_mask);
4186 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4188 sc->attn_state &= ~deasserted;
4191 static void bnx2x_attn_int(struct bnx2x_softc *sc)
4193 /* read local copy of bits */
4194 uint32_t attn_bits = le32toh(sc->def_sb->atten_status_block.attn_bits);
4196 le32toh(sc->def_sb->atten_status_block.attn_bits_ack);
4197 uint32_t attn_state = sc->attn_state;
4199 /* look for changed bits */
4200 uint32_t asserted = attn_bits & ~attn_ack & ~attn_state;
4201 uint32_t deasserted = ~attn_bits & attn_ack & attn_state;
4203 PMD_DRV_LOG(DEBUG, sc,
4204 "attn_bits 0x%08x attn_ack 0x%08x asserted 0x%08x deasserted 0x%08x",
4205 attn_bits, attn_ack, asserted, deasserted);
4207 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) {
4208 PMD_DRV_LOG(ERR, sc, "BAD attention state");
4211 /* handle bits that were raised */
4213 bnx2x_attn_int_asserted(sc, asserted);
4217 bnx2x_attn_int_deasserted(sc, deasserted);
4221 static uint16_t bnx2x_update_dsb_idx(struct bnx2x_softc *sc)
4223 struct host_sp_status_block *def_sb = sc->def_sb;
4229 mb(); /* status block is written to by the chip */
4231 if (sc->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
4232 sc->def_att_idx = def_sb->atten_status_block.attn_bits_index;
4233 rc |= BNX2X_DEF_SB_ATT_IDX;
4236 if (sc->def_idx != def_sb->sp_sb.running_index) {
4237 sc->def_idx = def_sb->sp_sb.running_index;
4238 rc |= BNX2X_DEF_SB_IDX;
4246 static struct ecore_queue_sp_obj *bnx2x_cid_to_q_obj(struct bnx2x_softc *sc,
4249 return &sc->sp_objs[CID_TO_FP(cid, sc)].q_obj;
4252 static void bnx2x_handle_mcast_eqe(struct bnx2x_softc *sc)
4254 struct ecore_mcast_ramrod_params rparam;
4257 memset(&rparam, 0, sizeof(rparam));
4259 rparam.mcast_obj = &sc->mcast_obj;
4261 /* clear pending state for the last command */
4262 sc->mcast_obj.raw.clear_pending(&sc->mcast_obj.raw);
4264 /* if there are pending mcast commands - send them */
4265 if (sc->mcast_obj.check_pending(&sc->mcast_obj)) {
4266 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
4268 PMD_DRV_LOG(INFO, sc,
4269 "Failed to send pending mcast commands (%d)",
4276 bnx2x_handle_classification_eqe(struct bnx2x_softc *sc, union event_ring_elem *elem)
4278 unsigned long ramrod_flags = 0;
4280 uint32_t cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4281 struct ecore_vlan_mac_obj *vlan_mac_obj;
4283 /* always push next commands out, don't wait here */
4284 bnx2x_set_bit(RAMROD_CONT, &ramrod_flags);
4286 switch (le32toh(elem->message.data.eth_event.echo) >> BNX2X_SWCID_SHIFT) {
4287 case ECORE_FILTER_MAC_PENDING:
4288 PMD_DRV_LOG(DEBUG, sc, "Got SETUP_MAC completions");
4289 vlan_mac_obj = &sc->sp_objs[cid].mac_obj;
4292 case ECORE_FILTER_MCAST_PENDING:
4293 PMD_DRV_LOG(DEBUG, sc, "Got SETUP_MCAST completions");
4294 bnx2x_handle_mcast_eqe(sc);
4298 PMD_DRV_LOG(NOTICE, sc, "Unsupported classification command: %d",
4299 elem->message.data.eth_event.echo);
4303 rc = vlan_mac_obj->complete(sc, vlan_mac_obj, elem, &ramrod_flags);
4306 PMD_DRV_LOG(NOTICE, sc,
4307 "Failed to schedule new commands (%d)", rc);
4308 } else if (rc > 0) {
4309 PMD_DRV_LOG(DEBUG, sc, "Scheduled next pending commands...");
4313 static void bnx2x_handle_rx_mode_eqe(struct bnx2x_softc *sc)
4315 bnx2x_clear_bit(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
4317 /* send rx_mode command again if was requested */
4318 if (bnx2x_test_and_clear_bit(ECORE_FILTER_RX_MODE_SCHED, &sc->sp_state)) {
4319 bnx2x_set_storm_rx_mode(sc);
4323 static void bnx2x_update_eq_prod(struct bnx2x_softc *sc, uint16_t prod)
4325 storm_memset_eq_prod(sc, prod, SC_FUNC(sc));
4326 wmb(); /* keep prod updates ordered */
4329 static void bnx2x_eq_int(struct bnx2x_softc *sc)
4331 uint16_t hw_cons, sw_cons, sw_prod;
4332 union event_ring_elem *elem;
4337 struct ecore_queue_sp_obj *q_obj;
4338 struct ecore_func_sp_obj *f_obj = &sc->func_obj;
4339 struct ecore_raw_obj *rss_raw = &sc->rss_conf_obj.raw;
4341 hw_cons = le16toh(*sc->eq_cons_sb);
4344 * The hw_cons range is 1-255, 257 - the sw_cons range is 0-254, 256.
4345 * when we get to the next-page we need to adjust so the loop
4346 * condition below will be met. The next element is the size of a
4347 * regular element and hence incrementing by 1
4349 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) {
4354 * This function may never run in parallel with itself for a
4355 * specific sc and no need for a read memory barrier here.
4357 sw_cons = sc->eq_cons;
4358 sw_prod = sc->eq_prod;
4362 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4364 elem = &sc->eq[EQ_DESC(sw_cons)];
4366 /* elem CID originates from FW, actually LE */
4367 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4368 opcode = elem->message.opcode;
4370 /* handle eq element */
4372 case EVENT_RING_OPCODE_STAT_QUERY:
4373 PMD_DEBUG_PERIODIC_LOG(DEBUG, sc, "got statistics completion event %d",
4375 /* nothing to do with stats comp */
4378 case EVENT_RING_OPCODE_CFC_DEL:
4379 /* handle according to cid range */
4380 /* we may want to verify here that the sc state is HALTING */
4381 PMD_DRV_LOG(DEBUG, sc, "got delete ramrod for MULTI[%d]",
4383 q_obj = bnx2x_cid_to_q_obj(sc, cid);
4384 if (q_obj->complete_cmd(sc, q_obj, ECORE_Q_CMD_CFC_DEL)) {
4389 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4390 PMD_DRV_LOG(DEBUG, sc, "got STOP TRAFFIC");
4391 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_STOP)) {
4396 case EVENT_RING_OPCODE_START_TRAFFIC:
4397 PMD_DRV_LOG(DEBUG, sc, "got START TRAFFIC");
4398 if (f_obj->complete_cmd
4399 (sc, f_obj, ECORE_F_CMD_TX_START)) {
4404 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
4405 echo = elem->message.data.function_update_event.echo;
4406 if (echo == SWITCH_UPDATE) {
4407 PMD_DRV_LOG(DEBUG, sc,
4408 "got FUNC_SWITCH_UPDATE ramrod");
4409 if (f_obj->complete_cmd(sc, f_obj,
4410 ECORE_F_CMD_SWITCH_UPDATE))
4415 PMD_DRV_LOG(DEBUG, sc,
4416 "AFEX: ramrod completed FUNCTION_UPDATE");
4417 f_obj->complete_cmd(sc, f_obj,
4418 ECORE_F_CMD_AFEX_UPDATE);
4422 case EVENT_RING_OPCODE_FORWARD_SETUP:
4423 q_obj = &bnx2x_fwd_sp_obj(sc, q_obj);
4424 if (q_obj->complete_cmd(sc, q_obj,
4425 ECORE_Q_CMD_SETUP_TX_ONLY)) {
4430 case EVENT_RING_OPCODE_FUNCTION_START:
4431 PMD_DRV_LOG(DEBUG, sc, "got FUNC_START ramrod");
4432 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_START)) {
4437 case EVENT_RING_OPCODE_FUNCTION_STOP:
4438 PMD_DRV_LOG(DEBUG, sc, "got FUNC_STOP ramrod");
4439 if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_STOP)) {
4445 switch (opcode | sc->state) {
4446 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BNX2X_STATE_OPEN):
4447 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BNX2X_STATE_OPENING_WAITING_PORT):
4449 elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4450 PMD_DRV_LOG(DEBUG, sc, "got RSS_UPDATE ramrod. CID %d",
4452 rss_raw->clear_pending(rss_raw);
4455 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4456 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
4457 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_CLOSING_WAITING_HALT):
4458 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BNX2X_STATE_OPEN):
4459 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BNX2X_STATE_DIAG):
4460 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BNX2X_STATE_CLOSING_WAITING_HALT):
4461 PMD_DRV_LOG(DEBUG, sc,
4462 "got (un)set mac ramrod");
4463 bnx2x_handle_classification_eqe(sc, elem);
4466 case (EVENT_RING_OPCODE_MULTICAST_RULES | BNX2X_STATE_OPEN):
4467 case (EVENT_RING_OPCODE_MULTICAST_RULES | BNX2X_STATE_DIAG):
4468 case (EVENT_RING_OPCODE_MULTICAST_RULES | BNX2X_STATE_CLOSING_WAITING_HALT):
4469 PMD_DRV_LOG(DEBUG, sc,
4470 "got mcast ramrod");
4471 bnx2x_handle_mcast_eqe(sc);
4474 case (EVENT_RING_OPCODE_FILTERS_RULES | BNX2X_STATE_OPEN):
4475 case (EVENT_RING_OPCODE_FILTERS_RULES | BNX2X_STATE_DIAG):
4476 case (EVENT_RING_OPCODE_FILTERS_RULES | BNX2X_STATE_CLOSING_WAITING_HALT):
4477 PMD_DRV_LOG(DEBUG, sc,
4478 "got rx_mode ramrod");
4479 bnx2x_handle_rx_mode_eqe(sc);
4483 /* unknown event log error and continue */
4484 PMD_DRV_LOG(INFO, sc, "Unknown EQ event %d, sc->state 0x%x",
4485 elem->message.opcode, sc->state);
4493 atomic_add_acq_long(&sc->eq_spq_left, spqe_cnt);
4495 sc->eq_cons = sw_cons;
4496 sc->eq_prod = sw_prod;
4498 /* make sure that above mem writes were issued towards the memory */
4501 /* update producer */
4502 bnx2x_update_eq_prod(sc, sc->eq_prod);
4505 static int bnx2x_handle_sp_tq(struct bnx2x_softc *sc)
4510 PMD_DRV_LOG(DEBUG, sc, "---> SP TASK <---");
4512 /* what work needs to be performed? */
4513 status = bnx2x_update_dsb_idx(sc);
4515 PMD_DRV_LOG(DEBUG, sc, "dsb status 0x%04x", status);
4518 if (status & BNX2X_DEF_SB_ATT_IDX) {
4519 PMD_DRV_LOG(DEBUG, sc, "---> ATTN INTR <---");
4521 status &= ~BNX2X_DEF_SB_ATT_IDX;
4525 /* SP events: STAT_QUERY and others */
4526 if (status & BNX2X_DEF_SB_IDX) {
4527 /* handle EQ completions */
4528 PMD_DRV_LOG(DEBUG, sc, "---> EQ INTR <---");
4530 bnx2x_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
4531 le16toh(sc->def_idx), IGU_INT_NOP, 1);
4532 status &= ~BNX2X_DEF_SB_IDX;
4535 /* if status is non zero then something went wrong */
4536 if (unlikely(status)) {
4537 PMD_DRV_LOG(INFO, sc,
4538 "Got an unknown SP interrupt! (0x%04x)", status);
4541 /* ack status block only if something was actually handled */
4542 bnx2x_ack_sb(sc, sc->igu_dsb_id, ATTENTION_ID,
4543 le16toh(sc->def_att_idx), IGU_INT_ENABLE, 1);
4548 static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)
4550 struct bnx2x_softc *sc = fp->sc;
4551 uint8_t more_rx = FALSE;
4553 /* Make sure FP is initialized */
4554 if (!fp->sb_running_index)
4557 PMD_DEBUG_PERIODIC_LOG(DEBUG, sc,
4558 "---> FP TASK QUEUE (%d) <--", fp->index);
4560 /* update the fastpath index */
4561 bnx2x_update_fp_sb_idx(fp);
4563 if (rte_atomic32_read(&sc->scan_fp) == 1) {
4564 if (bnx2x_has_rx_work(fp)) {
4565 more_rx = bnx2x_rxeof(sc, fp);
4569 /* still more work to do */
4570 bnx2x_handle_fp_tq(fp);
4575 /* Assuming we have completed slow path completion, clear the flag */
4576 rte_atomic32_set(&sc->scan_fp, 0);
4577 bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
4578 le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
4582 * Legacy interrupt entry point.
4584 * Verifies that the controller generated the interrupt and
4585 * then calls a separate routine to handle the various
4586 * interrupt causes: link, RX, and TX.
4588 int bnx2x_intr_legacy(struct bnx2x_softc *sc)
4590 struct bnx2x_fastpath *fp;
4591 uint32_t status, mask;
4595 * 0 for ustorm, 1 for cstorm
4596 * the bits returned from ack_int() are 0-15
4597 * bit 0 = attention status block
4598 * bit 1 = fast path status block
4599 * a mask of 0x2 or more = tx/rx event
4600 * a mask of 1 = slow path event
4603 status = bnx2x_ack_int(sc);
4605 /* the interrupt is not for us */
4606 if (unlikely(status == 0)) {
4610 PMD_DEBUG_PERIODIC_LOG(DEBUG, sc, "Interrupt status 0x%04x", status);
4611 //bnx2x_dump_status_block(sc);
4613 FOR_EACH_ETH_QUEUE(sc, i) {
4615 mask = (0x2 << (fp->index + CNIC_SUPPORT(sc)));
4616 if (status & mask) {
4617 /* acknowledge and disable further fastpath interrupts */
4618 bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
4619 0, IGU_INT_DISABLE, 0);
4620 bnx2x_handle_fp_tq(fp);
4625 if (unlikely(status & 0x1)) {
4626 /* acknowledge and disable further slowpath interrupts */
4627 bnx2x_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
4628 0, IGU_INT_DISABLE, 0);
4629 rc = bnx2x_handle_sp_tq(sc);
4633 if (unlikely(status)) {
4634 PMD_DRV_LOG(WARNING, sc,
4635 "Unexpected fastpath status (0x%08x)!", status);
4641 static int bnx2x_init_hw_common_chip(struct bnx2x_softc *sc);
4642 static int bnx2x_init_hw_common(struct bnx2x_softc *sc);
4643 static int bnx2x_init_hw_port(struct bnx2x_softc *sc);
4644 static int bnx2x_init_hw_func(struct bnx2x_softc *sc);
4645 static void bnx2x_reset_common(struct bnx2x_softc *sc);
4646 static void bnx2x_reset_port(struct bnx2x_softc *sc);
4647 static void bnx2x_reset_func(struct bnx2x_softc *sc);
4648 static int bnx2x_init_firmware(struct bnx2x_softc *sc);
4649 static void bnx2x_release_firmware(struct bnx2x_softc *sc);
4652 ecore_func_sp_drv_ops bnx2x_func_sp_drv = {
4653 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
4654 .init_hw_cmn = bnx2x_init_hw_common,
4655 .init_hw_port = bnx2x_init_hw_port,
4656 .init_hw_func = bnx2x_init_hw_func,
4658 .reset_hw_cmn = bnx2x_reset_common,
4659 .reset_hw_port = bnx2x_reset_port,
4660 .reset_hw_func = bnx2x_reset_func,
4662 .init_fw = bnx2x_init_firmware,
4663 .release_fw = bnx2x_release_firmware,
4666 static void bnx2x_init_func_obj(struct bnx2x_softc *sc)
4670 PMD_INIT_FUNC_TRACE(sc);
4672 ecore_init_func_obj(sc,
4674 BNX2X_SP(sc, func_rdata),
4675 (rte_iova_t)BNX2X_SP_MAPPING(sc, func_rdata),
4676 BNX2X_SP(sc, func_afex_rdata),
4677 (rte_iova_t)BNX2X_SP_MAPPING(sc, func_afex_rdata),
4678 &bnx2x_func_sp_drv);
4681 static int bnx2x_init_hw(struct bnx2x_softc *sc, uint32_t load_code)
4683 struct ecore_func_state_params func_params = { NULL };
4686 PMD_INIT_FUNC_TRACE(sc);
4688 /* prepare the parameters for function state transitions */
4689 bnx2x_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
4691 func_params.f_obj = &sc->func_obj;
4692 func_params.cmd = ECORE_F_CMD_HW_INIT;
4694 func_params.params.hw_init.load_phase = load_code;
4697 * Via a plethora of function pointers, we will eventually reach
4698 * bnx2x_init_hw_common(), bnx2x_init_hw_port(), or bnx2x_init_hw_func().
4700 rc = ecore_func_state_change(sc, &func_params);
4706 bnx2x_fill(struct bnx2x_softc *sc, uint32_t addr, int fill, uint32_t len)
4710 if (!(len % 4) && !(addr % 4)) {
4711 for (i = 0; i < len; i += 4) {
4712 REG_WR(sc, (addr + i), fill);
4715 for (i = 0; i < len; i++) {
4716 REG_WR8(sc, (addr + i), fill);
4721 /* writes FP SP data to FW - data_size in dwords */
4723 bnx2x_wr_fp_sb_data(struct bnx2x_softc *sc, int fw_sb_id, uint32_t * sb_data_p,
4728 for (index = 0; index < data_size; index++) {
4730 (BAR_CSTRORM_INTMEM +
4731 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4732 (sizeof(uint32_t) * index)), *(sb_data_p + index));
4736 static void bnx2x_zero_fp_sb(struct bnx2x_softc *sc, int fw_sb_id)
4738 struct hc_status_block_data_e2 sb_data_e2;
4739 struct hc_status_block_data_e1x sb_data_e1x;
4740 uint32_t *sb_data_p;
4741 uint32_t data_size = 0;
4743 if (!CHIP_IS_E1x(sc)) {
4744 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4745 sb_data_e2.common.state = SB_DISABLED;
4746 sb_data_e2.common.p_func.vf_valid = FALSE;
4747 sb_data_p = (uint32_t *) & sb_data_e2;
4748 data_size = (sizeof(struct hc_status_block_data_e2) /
4751 memset(&sb_data_e1x, 0,
4752 sizeof(struct hc_status_block_data_e1x));
4753 sb_data_e1x.common.state = SB_DISABLED;
4754 sb_data_e1x.common.p_func.vf_valid = FALSE;
4755 sb_data_p = (uint32_t *) & sb_data_e1x;
4756 data_size = (sizeof(struct hc_status_block_data_e1x) /
4760 bnx2x_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
4763 (BAR_CSTRORM_INTMEM + CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id)), 0,
4764 CSTORM_STATUS_BLOCK_SIZE);
4765 bnx2x_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id)),
4766 0, CSTORM_SYNC_BLOCK_SIZE);
4770 bnx2x_wr_sp_sb_data(struct bnx2x_softc *sc,
4771 struct hc_sp_status_block_data *sp_sb_data)
4776 i < (sizeof(struct hc_sp_status_block_data) / sizeof(uint32_t));
4779 (BAR_CSTRORM_INTMEM +
4780 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(SC_FUNC(sc)) +
4781 (i * sizeof(uint32_t))),
4782 *((uint32_t *) sp_sb_data + i));
4786 static void bnx2x_zero_sp_sb(struct bnx2x_softc *sc)
4788 struct hc_sp_status_block_data sp_sb_data;
4790 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4792 sp_sb_data.state = SB_DISABLED;
4793 sp_sb_data.p_func.vf_valid = FALSE;
4795 bnx2x_wr_sp_sb_data(sc, &sp_sb_data);
4798 (BAR_CSTRORM_INTMEM +
4799 CSTORM_SP_STATUS_BLOCK_OFFSET(SC_FUNC(sc))),
4800 0, CSTORM_SP_STATUS_BLOCK_SIZE);
4802 (BAR_CSTRORM_INTMEM +
4803 CSTORM_SP_SYNC_BLOCK_OFFSET(SC_FUNC(sc))),
4804 0, CSTORM_SP_SYNC_BLOCK_SIZE);
4808 bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, int igu_sb_id,
4811 hc_sm->igu_sb_id = igu_sb_id;
4812 hc_sm->igu_seg_id = igu_seg_id;
4813 hc_sm->timer_value = 0xFF;
4814 hc_sm->time_to_expire = 0xFFFFFFFF;
4817 static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
4819 /* zero out state machine indices */
4822 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4825 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
4826 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
4827 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
4828 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
4833 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
4834 (SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
4837 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
4838 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
4839 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
4840 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
4841 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
4842 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
4843 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
4844 (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
4848 bnx2x_init_sb(struct bnx2x_softc *sc, rte_iova_t busaddr, int vfid,
4849 uint8_t vf_valid, int fw_sb_id, int igu_sb_id)
4851 struct hc_status_block_data_e2 sb_data_e2;
4852 struct hc_status_block_data_e1x sb_data_e1x;
4853 struct hc_status_block_sm *hc_sm_p;
4854 uint32_t *sb_data_p;
4858 if (CHIP_INT_MODE_IS_BC(sc)) {
4859 igu_seg_id = HC_SEG_ACCESS_NORM;
4861 igu_seg_id = IGU_SEG_ACCESS_NORM;
4864 bnx2x_zero_fp_sb(sc, fw_sb_id);
4866 if (!CHIP_IS_E1x(sc)) {
4867 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
4868 sb_data_e2.common.state = SB_ENABLED;
4869 sb_data_e2.common.p_func.pf_id = SC_FUNC(sc);
4870 sb_data_e2.common.p_func.vf_id = vfid;
4871 sb_data_e2.common.p_func.vf_valid = vf_valid;
4872 sb_data_e2.common.p_func.vnic_id = SC_VN(sc);
4873 sb_data_e2.common.same_igu_sb_1b = TRUE;
4874 sb_data_e2.common.host_sb_addr.hi = U64_HI(busaddr);
4875 sb_data_e2.common.host_sb_addr.lo = U64_LO(busaddr);
4876 hc_sm_p = sb_data_e2.common.state_machine;
4877 sb_data_p = (uint32_t *) & sb_data_e2;
4878 data_size = (sizeof(struct hc_status_block_data_e2) /
4880 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
4882 memset(&sb_data_e1x, 0,
4883 sizeof(struct hc_status_block_data_e1x));
4884 sb_data_e1x.common.state = SB_ENABLED;
4885 sb_data_e1x.common.p_func.pf_id = SC_FUNC(sc);
4886 sb_data_e1x.common.p_func.vf_id = 0xff;
4887 sb_data_e1x.common.p_func.vf_valid = FALSE;
4888 sb_data_e1x.common.p_func.vnic_id = SC_VN(sc);
4889 sb_data_e1x.common.same_igu_sb_1b = TRUE;
4890 sb_data_e1x.common.host_sb_addr.hi = U64_HI(busaddr);
4891 sb_data_e1x.common.host_sb_addr.lo = U64_LO(busaddr);
4892 hc_sm_p = sb_data_e1x.common.state_machine;
4893 sb_data_p = (uint32_t *) & sb_data_e1x;
4894 data_size = (sizeof(struct hc_status_block_data_e1x) /
4896 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
4899 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], igu_sb_id, igu_seg_id);
4900 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], igu_sb_id, igu_seg_id);
4902 /* write indices to HW - PCI guarantees endianity of regpairs */
4903 bnx2x_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
4906 static uint8_t bnx2x_fp_qzone_id(struct bnx2x_fastpath *fp)
4908 if (CHIP_IS_E1x(fp->sc)) {
4909 return fp->cl_id + SC_PORT(fp->sc) * ETH_MAX_RX_CLIENTS_E1H;
4916 bnx2x_rx_ustorm_prods_offset(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp)
4918 uint32_t offset = BAR_USTRORM_INTMEM;
4921 return PXP_VF_ADDR_USDM_QUEUES_START +
4922 (sc->acquire_resp.resc.hw_qid[fp->index] *
4923 sizeof(struct ustorm_queue_zone_data));
4924 } else if (!CHIP_IS_E1x(sc)) {
4925 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
4927 offset += USTORM_RX_PRODS_E1X_OFFSET(SC_PORT(sc), fp->cl_id);
4933 static void bnx2x_init_eth_fp(struct bnx2x_softc *sc, int idx)
4935 struct bnx2x_fastpath *fp = &sc->fp[idx];
4936 uint32_t cids[ECORE_MULTI_TX_COS] = { 0 };
4937 unsigned long q_type = 0;
4943 fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc));
4944 fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc));
4946 if (CHIP_IS_E1x(sc))
4947 fp->cl_id = SC_L_ID(sc) + idx;
4949 /* want client ID same as IGU SB ID for non-E1 */
4950 fp->cl_id = fp->igu_sb_id;
4951 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
4953 /* setup sb indices */
4954 if (!CHIP_IS_E1x(sc)) {
4955 fp->sb_index_values = fp->status_block.e2_sb->sb.index_values;
4956 fp->sb_running_index = fp->status_block.e2_sb->sb.running_index;
4958 fp->sb_index_values = fp->status_block.e1x_sb->sb.index_values;
4959 fp->sb_running_index =
4960 fp->status_block.e1x_sb->sb.running_index;
4964 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(sc, fp);
4966 fp->rx_cq_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS];
4968 for (cos = 0; cos < sc->max_cos; cos++) {
4971 fp->tx_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0];
4973 /* nothing more for a VF to do */
4978 bnx2x_init_sb(sc, fp->sb_dma.paddr, BNX2X_VF_ID_INVALID, FALSE,
4979 fp->fw_sb_id, fp->igu_sb_id);
4981 bnx2x_update_fp_sb_idx(fp);
4983 /* Configure Queue State object */
4984 bnx2x_set_bit(ECORE_Q_TYPE_HAS_RX, &q_type);
4985 bnx2x_set_bit(ECORE_Q_TYPE_HAS_TX, &q_type);
4987 ecore_init_queue_obj(sc,
4988 &sc->sp_objs[idx].q_obj,
4993 BNX2X_SP(sc, q_rdata),
4994 (rte_iova_t)BNX2X_SP_MAPPING(sc, q_rdata),
4997 /* configure classification DBs */
4998 ecore_init_mac_obj(sc,
4999 &sc->sp_objs[idx].mac_obj,
5003 BNX2X_SP(sc, mac_rdata),
5004 (rte_iova_t)BNX2X_SP_MAPPING(sc, mac_rdata),
5005 ECORE_FILTER_MAC_PENDING, &sc->sp_state,
5006 ECORE_OBJ_TYPE_RX_TX, &sc->macs_pool);
5010 bnx2x_update_rx_prod(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
5011 uint16_t rx_bd_prod, uint16_t rx_cq_prod)
5013 union ustorm_eth_rx_producers rx_prods;
5016 /* update producers */
5017 rx_prods.prod.bd_prod = rx_bd_prod;
5018 rx_prods.prod.cqe_prod = rx_cq_prod;
5019 rx_prods.prod.reserved = 0;
5022 * Make sure that the BD and SGE data is updated before updating the
5023 * producers since FW might read the BD/SGE right after the producer
5025 * This is only applicable for weak-ordered memory model archs such
5026 * as IA-64. The following barrier is also mandatory since FW will
5027 * assumes BDs must have buffers.
5031 for (i = 0; i < (sizeof(rx_prods) / 4); i++) {
5033 (fp->ustorm_rx_prods_offset + (i * 4)),
5034 rx_prods.raw_data[i]);
5037 wmb(); /* keep prod updates ordered */
5040 static void bnx2x_init_rx_rings(struct bnx2x_softc *sc)
5042 struct bnx2x_fastpath *fp;
5044 struct bnx2x_rx_queue *rxq;
5046 for (i = 0; i < sc->num_queues; i++) {
5048 rxq = sc->rx_queues[fp->index];
5050 PMD_RX_LOG(ERR, "RX queue is NULL");
5054 rxq->rx_bd_head = 0;
5055 rxq->rx_bd_tail = rxq->nb_rx_desc;
5056 rxq->rx_cq_head = 0;
5057 rxq->rx_cq_tail = TOTAL_RCQ_ENTRIES(rxq);
5058 *fp->rx_cq_cons_sb = 0;
5061 * Activate the BD ring...
5062 * Warning, this will generate an interrupt (to the TSTORM)
5063 * so this can only be done after the chip is initialized
5065 bnx2x_update_rx_prod(sc, fp, rxq->rx_bd_tail, rxq->rx_cq_tail);
5073 static void bnx2x_init_tx_ring_one(struct bnx2x_fastpath *fp)
5075 struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
5077 fp->tx_db.data.header.header = 1 << DOORBELL_HDR_DB_TYPE_SHIFT;
5078 fp->tx_db.data.zero_fill1 = 0;
5079 fp->tx_db.data.prod = 0;
5082 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
5086 txq->tx_pkt_tail = 0;
5087 txq->tx_pkt_head = 0;
5088 txq->tx_bd_tail = 0;
5089 txq->tx_bd_head = 0;
5092 static void bnx2x_init_tx_rings(struct bnx2x_softc *sc)
5096 for (i = 0; i < sc->num_queues; i++) {
5097 bnx2x_init_tx_ring_one(&sc->fp[i]);
5101 static void bnx2x_init_def_sb(struct bnx2x_softc *sc)
5103 struct host_sp_status_block *def_sb = sc->def_sb;
5104 rte_iova_t mapping = sc->def_sb_dma.paddr;
5105 int igu_sp_sb_index;
5107 int port = SC_PORT(sc);
5108 int func = SC_FUNC(sc);
5109 int reg_offset, reg_offset_en5;
5112 struct hc_sp_status_block_data sp_sb_data;
5114 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5116 if (CHIP_INT_MODE_IS_BC(sc)) {
5117 igu_sp_sb_index = DEF_SB_IGU_ID;
5118 igu_seg_id = HC_SEG_ACCESS_DEF;
5120 igu_sp_sb_index = sc->igu_dsb_id;
5121 igu_seg_id = IGU_SEG_ACCESS_DEF;
5125 section = ((uint64_t) mapping +
5126 offsetof(struct host_sp_status_block, atten_status_block));
5127 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
5130 reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5131 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
5133 reg_offset_en5 = (port) ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5134 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0;
5136 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
5137 /* take care of sig[0]..sig[4] */
5138 for (sindex = 0; sindex < 4; sindex++) {
5139 sc->attn_group[index].sig[sindex] =
5141 (reg_offset + (sindex * 0x4) +
5145 if (!CHIP_IS_E1x(sc)) {
5147 * enable5 is separate from the rest of the registers,
5148 * and the address skip is 4 and not 16 between the
5151 sc->attn_group[index].sig[4] =
5152 REG_RD(sc, (reg_offset_en5 + (0x4 * index)));
5154 sc->attn_group[index].sig[4] = 0;
5158 if (sc->devinfo.int_block == INT_BLOCK_HC) {
5160 port ? HC_REG_ATTN_MSG1_ADDR_L : HC_REG_ATTN_MSG0_ADDR_L;
5161 REG_WR(sc, reg_offset, U64_LO(section));
5162 REG_WR(sc, (reg_offset + 4), U64_HI(section));
5163 } else if (!CHIP_IS_E1x(sc)) {
5164 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5165 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5168 section = ((uint64_t) mapping +
5169 offsetof(struct host_sp_status_block, sp_sb));
5171 bnx2x_zero_sp_sb(sc);
5173 /* PCI guarantees endianity of regpair */
5174 sp_sb_data.state = SB_ENABLED;
5175 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5176 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5177 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5178 sp_sb_data.igu_seg_id = igu_seg_id;
5179 sp_sb_data.p_func.pf_id = func;
5180 sp_sb_data.p_func.vnic_id = SC_VN(sc);
5181 sp_sb_data.p_func.vf_id = 0xff;
5183 bnx2x_wr_sp_sb_data(sc, &sp_sb_data);
5185 bnx2x_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
5188 static void bnx2x_init_sp_ring(struct bnx2x_softc *sc)
5190 atomic_store_rel_long(&sc->cq_spq_left, MAX_SPQ_PENDING);
5191 sc->spq_prod_idx = 0;
5193 &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_ETH_DEF_CONS];
5194 sc->spq_prod_bd = sc->spq;
5195 sc->spq_last_bd = (sc->spq_prod_bd + MAX_SP_DESC_CNT);
5198 static void bnx2x_init_eq_ring(struct bnx2x_softc *sc)
5200 union event_ring_elem *elem;
5203 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5204 elem = &sc->eq[EQ_DESC_CNT_PAGE * i - 1];
5206 elem->next_page.addr.hi = htole32(U64_HI(sc->eq_dma.paddr +
5208 (i % NUM_EQ_PAGES)));
5209 elem->next_page.addr.lo = htole32(U64_LO(sc->eq_dma.paddr +
5211 (i % NUM_EQ_PAGES)));
5215 sc->eq_prod = NUM_EQ_DESC;
5216 sc->eq_cons_sb = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_EQ_CONS];
5218 atomic_store_rel_long(&sc->eq_spq_left,
5219 (min((MAX_SP_DESC_CNT - MAX_SPQ_PENDING),
5223 static void bnx2x_init_internal_common(struct bnx2x_softc *sc)
5229 * In switch independent mode, the TSTORM needs to accept
5230 * packets that failed classification, since approximate match
5231 * mac addresses aren't written to NIG LLH.
5234 (BAR_TSTRORM_INTMEM +
5235 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET), 2);
5238 (BAR_TSTRORM_INTMEM +
5239 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET), 0);
5242 * Zero this manually as its initialization is currently missing
5245 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) {
5247 (BAR_USTRORM_INTMEM + USTORM_AGG_DATA_OFFSET + (i * 4)),
5251 if (!CHIP_IS_E1x(sc)) {
5252 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET),
5253 CHIP_INT_MODE_IS_BC(sc) ? HC_IGU_BC_MODE :
5258 static void bnx2x_init_internal(struct bnx2x_softc *sc, uint32_t load_code)
5260 switch (load_code) {
5261 case FW_MSG_CODE_DRV_LOAD_COMMON:
5262 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5263 bnx2x_init_internal_common(sc);
5266 case FW_MSG_CODE_DRV_LOAD_PORT:
5270 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5271 /* internal memory per function is initialized inside bnx2x_pf_init */
5275 PMD_DRV_LOG(NOTICE, sc, "Unknown load_code (0x%x) from MCP",
5282 storm_memset_func_cfg(struct bnx2x_softc *sc,
5283 struct tstorm_eth_function_common_config *tcfg,
5289 addr = (BAR_TSTRORM_INTMEM +
5290 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid));
5291 size = sizeof(struct tstorm_eth_function_common_config);
5292 ecore_storm_memset_struct(sc, addr, size, (uint32_t *) tcfg);
5295 static void bnx2x_func_init(struct bnx2x_softc *sc, struct bnx2x_func_init_params *p)
5297 struct tstorm_eth_function_common_config tcfg = { 0 };
5299 if (CHIP_IS_E1x(sc)) {
5300 storm_memset_func_cfg(sc, &tcfg, p->func_id);
5303 /* Enable the function in the FW */
5304 storm_memset_vf_to_pf(sc, p->func_id, p->pf_id);
5305 storm_memset_func_en(sc, p->func_id, 1);
5308 if (p->func_flgs & FUNC_FLG_SPQ) {
5309 storm_memset_spq_addr(sc, p->spq_map, p->func_id);
5311 (XSEM_REG_FAST_MEMORY +
5312 XSTORM_SPQ_PROD_OFFSET(p->func_id)), p->spq_prod);
5317 * Calculates the sum of vn_min_rates.
5318 * It's needed for further normalizing of the min_rates.
5320 * sum of vn_min_rates.
5322 * 0 - if all the min_rates are 0.
5323 * In the later case fainess algorithm should be deactivated.
5324 * If all min rates are not zero then those that are zeroes will be set to 1.
5326 static void bnx2x_calc_vn_min(struct bnx2x_softc *sc, struct cmng_init_input *input)
5329 uint32_t vn_min_rate;
5333 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
5334 vn_cfg = sc->devinfo.mf_info.mf_config[vn];
5335 vn_min_rate = (((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
5336 FUNC_MF_CFG_MIN_BW_SHIFT) * 100);
5338 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
5339 /* skip hidden VNs */
5341 } else if (!vn_min_rate) {
5342 /* If min rate is zero - set it to 100 */
5343 vn_min_rate = DEF_MIN_RATE;
5348 input->vnic_min_rate[vn] = vn_min_rate;
5351 /* if ETS or all min rates are zeros - disable fairness */
5353 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
5355 input->flags.cmng_enables |= CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
5360 bnx2x_extract_max_cfg(__rte_unused struct bnx2x_softc *sc, uint32_t mf_cfg)
5362 uint16_t max_cfg = ((mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
5363 FUNC_MF_CFG_MAX_BW_SHIFT);
5366 PMD_DRV_LOG(DEBUG, sc,
5367 "Max BW configured to 0 - using 100 instead");
5375 bnx2x_calc_vn_max(struct bnx2x_softc *sc, int vn, struct cmng_init_input *input)
5377 uint16_t vn_max_rate;
5378 uint32_t vn_cfg = sc->devinfo.mf_info.mf_config[vn];
5381 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
5384 max_cfg = bnx2x_extract_max_cfg(sc, vn_cfg);
5387 /* max_cfg in percents of linkspeed */
5389 ((sc->link_vars.line_speed * max_cfg) / 100);
5390 } else { /* SD modes */
5391 /* max_cfg is absolute in 100Mb units */
5392 vn_max_rate = (max_cfg * 100);
5396 input->vnic_max_rate[vn] = vn_max_rate;
5400 bnx2x_cmng_fns_init(struct bnx2x_softc *sc, uint8_t read_cfg, uint8_t cmng_type)
5402 struct cmng_init_input input;
5405 memset(&input, 0, sizeof(struct cmng_init_input));
5407 input.port_rate = sc->link_vars.line_speed;
5409 if (cmng_type == CMNG_FNS_MINMAX) {
5410 /* read mf conf from shmem */
5412 bnx2x_read_mf_cfg(sc);
5415 /* get VN min rate and enable fairness if not 0 */
5416 bnx2x_calc_vn_min(sc, &input);
5418 /* get VN max rate */
5420 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
5421 bnx2x_calc_vn_max(sc, vn, &input);
5425 /* always enable rate shaping and fairness */
5426 input.flags.cmng_enables |= CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
5428 ecore_init_cmng(&input, &sc->cmng);
5433 static int bnx2x_get_cmng_fns_mode(struct bnx2x_softc *sc)
5435 if (CHIP_REV_IS_SLOW(sc)) {
5436 return CMNG_FNS_NONE;
5440 return CMNG_FNS_MINMAX;
5443 return CMNG_FNS_NONE;
5447 storm_memset_cmng(struct bnx2x_softc *sc, struct cmng_init *cmng, uint8_t port)
5454 addr = (BAR_XSTRORM_INTMEM + XSTORM_CMNG_PER_PORT_VARS_OFFSET(port));
5455 size = sizeof(struct cmng_struct_per_port);
5456 ecore_storm_memset_struct(sc, addr, size, (uint32_t *) & cmng->port);
5458 for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
5459 func = func_by_vn(sc, vn);
5461 addr = (BAR_XSTRORM_INTMEM +
5462 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func));
5463 size = sizeof(struct rate_shaping_vars_per_vn);
5464 ecore_storm_memset_struct(sc, addr, size,
5465 (uint32_t *) & cmng->
5466 vnic.vnic_max_rate[vn]);
5468 addr = (BAR_XSTRORM_INTMEM +
5469 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func));
5470 size = sizeof(struct fairness_vars_per_vn);
5471 ecore_storm_memset_struct(sc, addr, size,
5472 (uint32_t *) & cmng->
5473 vnic.vnic_min_rate[vn]);
5477 static void bnx2x_pf_init(struct bnx2x_softc *sc)
5479 struct bnx2x_func_init_params func_init;
5480 struct event_ring_data eq_data;
5483 memset(&eq_data, 0, sizeof(struct event_ring_data));
5484 memset(&func_init, 0, sizeof(struct bnx2x_func_init_params));
5486 if (!CHIP_IS_E1x(sc)) {
5487 /* reset IGU PF statistics: MSIX + ATTN */
5490 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
5491 (BNX2X_IGU_STAS_MSG_VF_CNT * 4) +
5492 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) *
5496 (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
5497 (BNX2X_IGU_STAS_MSG_VF_CNT * 4) +
5498 (BNX2X_IGU_STAS_MSG_PF_CNT * 4) +
5499 ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) *
5503 /* function setup flags */
5504 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
5506 func_init.func_flgs = flags;
5507 func_init.pf_id = SC_FUNC(sc);
5508 func_init.func_id = SC_FUNC(sc);
5509 func_init.spq_map = sc->spq_dma.paddr;
5510 func_init.spq_prod = sc->spq_prod_idx;
5512 bnx2x_func_init(sc, &func_init);
5514 memset(&sc->cmng, 0, sizeof(struct cmng_struct_per_port));
5517 * Congestion management values depend on the link rate.
5518 * There is no active link so initial link rate is set to 10Gbps.
5519 * When the link comes up the congestion management values are
5520 * re-calculated according to the actual link rate.
5522 sc->link_vars.line_speed = SPEED_10000;
5523 bnx2x_cmng_fns_init(sc, TRUE, bnx2x_get_cmng_fns_mode(sc));
5525 /* Only the PMF sets the HW */
5527 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
5530 /* init Event Queue - PCI bus guarantees correct endainity */
5531 eq_data.base_addr.hi = U64_HI(sc->eq_dma.paddr);
5532 eq_data.base_addr.lo = U64_LO(sc->eq_dma.paddr);
5533 eq_data.producer = sc->eq_prod;
5534 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
5535 eq_data.sb_id = DEF_SB_ID;
5536 storm_memset_eq_data(sc, &eq_data, SC_FUNC(sc));
5539 static void bnx2x_hc_int_enable(struct bnx2x_softc *sc)
5541 int port = SC_PORT(sc);
5542 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
5543 uint32_t val = REG_RD(sc, addr);
5544 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX)
5545 || (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
5546 uint8_t single_msix = (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
5547 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI);
5550 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
5551 HC_CONFIG_0_REG_INT_LINE_EN_0);
5552 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
5553 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
5555 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
5558 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
5559 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
5560 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
5561 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
5563 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
5564 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
5565 HC_CONFIG_0_REG_INT_LINE_EN_0 |
5566 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
5568 REG_WR(sc, addr, val);
5570 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
5573 REG_WR(sc, addr, val);
5575 /* ensure that HC_CONFIG is written before leading/trailing edge config */
5578 /* init leading/trailing edge */
5580 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
5582 /* enable nig and gpio3 attention */
5589 REG_WR(sc, (HC_REG_TRAILING_EDGE_0 + port * 8), val);
5590 REG_WR(sc, (HC_REG_LEADING_EDGE_0 + port * 8), val);
5592 /* make sure that interrupts are indeed enabled from here on */
5596 static void bnx2x_igu_int_enable(struct bnx2x_softc *sc)
5599 uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX)
5600 || (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
5601 uint8_t single_msix = (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
5602 uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI);
5604 val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
5607 val &= ~(IGU_PF_CONF_INT_LINE_EN | IGU_PF_CONF_SINGLE_ISR_EN);
5608 val |= (IGU_PF_CONF_MSI_MSIX_EN | IGU_PF_CONF_ATTN_BIT_EN);
5610 val |= IGU_PF_CONF_SINGLE_ISR_EN;
5613 val &= ~IGU_PF_CONF_INT_LINE_EN;
5614 val |= (IGU_PF_CONF_MSI_MSIX_EN |
5615 IGU_PF_CONF_ATTN_BIT_EN | IGU_PF_CONF_SINGLE_ISR_EN);
5617 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
5618 val |= (IGU_PF_CONF_INT_LINE_EN |
5619 IGU_PF_CONF_ATTN_BIT_EN | IGU_PF_CONF_SINGLE_ISR_EN);
5622 /* clean previous status - need to configure igu prior to ack */
5623 if ((!msix) || single_msix) {
5624 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
5628 val |= IGU_PF_CONF_FUNC_EN;
5630 PMD_DRV_LOG(DEBUG, sc, "write 0x%x to IGU mode %s",
5631 val, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
5633 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
5637 /* init leading/trailing edge */
5639 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
5641 /* enable nig and gpio3 attention */
5648 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
5649 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
5651 /* make sure that interrupts are indeed enabled from here on */
5655 static void bnx2x_int_enable(struct bnx2x_softc *sc)
5657 if (sc->devinfo.int_block == INT_BLOCK_HC) {
5658 bnx2x_hc_int_enable(sc);
5660 bnx2x_igu_int_enable(sc);
5664 static void bnx2x_hc_int_disable(struct bnx2x_softc *sc)
5666 int port = SC_PORT(sc);
5667 uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
5668 uint32_t val = REG_RD(sc, addr);
5670 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
5671 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
5672 HC_CONFIG_0_REG_INT_LINE_EN_0 | HC_CONFIG_0_REG_ATTN_BIT_EN_0);
5673 /* flush all outstanding writes */
5676 REG_WR(sc, addr, val);
5677 if (REG_RD(sc, addr) != val) {
5678 PMD_DRV_LOG(ERR, sc, "proper val not read from HC IGU!");
5682 static void bnx2x_igu_int_disable(struct bnx2x_softc *sc)
5684 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
5686 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
5687 IGU_PF_CONF_INT_LINE_EN | IGU_PF_CONF_ATTN_BIT_EN);
5689 PMD_DRV_LOG(DEBUG, sc, "write %x to IGU", val);
5691 /* flush all outstanding writes */
5694 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
5695 if (REG_RD(sc, IGU_REG_PF_CONFIGURATION) != val) {
5696 PMD_DRV_LOG(ERR, sc, "proper val not read from IGU!");
5700 static void bnx2x_int_disable(struct bnx2x_softc *sc)
5702 if (sc->devinfo.int_block == INT_BLOCK_HC) {
5703 bnx2x_hc_int_disable(sc);
5705 bnx2x_igu_int_disable(sc);
5709 static void bnx2x_nic_init(struct bnx2x_softc *sc, int load_code)
5713 PMD_INIT_FUNC_TRACE(sc);
5715 for (i = 0; i < sc->num_queues; i++) {
5716 bnx2x_init_eth_fp(sc, i);
5719 rmb(); /* ensure status block indices were read */
5721 bnx2x_init_rx_rings(sc);
5722 bnx2x_init_tx_rings(sc);
5725 bnx2x_memset_stats(sc);
5729 /* initialize MOD_ABS interrupts */
5730 elink_init_mod_abs_int(sc, &sc->link_vars,
5731 sc->devinfo.chip_id,
5732 sc->devinfo.shmem_base,
5733 sc->devinfo.shmem2_base, SC_PORT(sc));
5735 bnx2x_init_def_sb(sc);
5736 bnx2x_update_dsb_idx(sc);
5737 bnx2x_init_sp_ring(sc);
5738 bnx2x_init_eq_ring(sc);
5739 bnx2x_init_internal(sc, load_code);
5741 bnx2x_stats_init(sc);
5743 /* flush all before enabling interrupts */
5746 bnx2x_int_enable(sc);
5748 /* check for SPIO5 */
5749 bnx2x_attn_int_deasserted0(sc,
5751 (MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
5753 AEU_INPUTS_ATTN_BITS_SPIO5);
5756 static void bnx2x_init_objs(struct bnx2x_softc *sc)
5758 /* mcast rules must be added to tx if tx switching is enabled */
5759 ecore_obj_type o_type;
5760 if (sc->flags & BNX2X_TX_SWITCHING)
5761 o_type = ECORE_OBJ_TYPE_RX_TX;
5763 o_type = ECORE_OBJ_TYPE_RX;
5765 /* RX_MODE controlling object */
5766 ecore_init_rx_mode_obj(sc, &sc->rx_mode_obj);
5768 /* multicast configuration controlling object */
5769 ecore_init_mcast_obj(sc,
5775 BNX2X_SP(sc, mcast_rdata),
5776 (rte_iova_t)BNX2X_SP_MAPPING(sc, mcast_rdata),
5777 ECORE_FILTER_MCAST_PENDING,
5778 &sc->sp_state, o_type);
5780 /* Setup CAM credit pools */
5781 ecore_init_mac_credit_pool(sc,
5784 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
5785 VNICS_PER_PATH(sc));
5787 ecore_init_vlan_credit_pool(sc,
5789 SC_ABS_FUNC(sc) >> 1,
5790 CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
5791 VNICS_PER_PATH(sc));
5793 /* RSS configuration object */
5794 ecore_init_rss_config_obj(&sc->rss_conf_obj,
5799 BNX2X_SP(sc, rss_rdata),
5800 (rte_iova_t)BNX2X_SP_MAPPING(sc, rss_rdata),
5801 ECORE_FILTER_RSS_CONF_PENDING,
5802 &sc->sp_state, ECORE_OBJ_TYPE_RX);
5806 * Initialize the function. This must be called before sending CLIENT_SETUP
5807 * for the first client.
5809 static int bnx2x_func_start(struct bnx2x_softc *sc)
5811 struct ecore_func_state_params func_params = { NULL };
5812 struct ecore_func_start_params *start_params =
5813 &func_params.params.start;
5815 /* Prepare parameters for function state transitions */
5816 bnx2x_set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
5818 func_params.f_obj = &sc->func_obj;
5819 func_params.cmd = ECORE_F_CMD_START;
5821 /* Function parameters */
5822 start_params->mf_mode = sc->devinfo.mf_info.mf_mode;
5823 start_params->sd_vlan_tag = OVLAN(sc);
5825 if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
5826 start_params->network_cos_mode = STATIC_COS;
5827 } else { /* CHIP_IS_E1X */
5828 start_params->network_cos_mode = FW_WRR;
5831 start_params->gre_tunnel_mode = 0;
5832 start_params->gre_tunnel_rss = 0;
5834 return ecore_func_state_change(sc, &func_params);
5837 static int bnx2x_set_power_state(struct bnx2x_softc *sc, uint8_t state)
5841 /* If there is no power capability, silently succeed */
5842 if (!(sc->devinfo.pcie_cap_flags & BNX2X_PM_CAPABLE_FLAG)) {
5843 PMD_DRV_LOG(INFO, sc, "No power capability");
5847 pci_read(sc, (sc->devinfo.pcie_pm_cap_reg + PCIR_POWER_STATUS), &pmcsr,
5853 (sc->devinfo.pcie_pm_cap_reg +
5855 ((pmcsr & ~PCIM_PSTAT_DMASK) | PCIM_PSTAT_PME));
5857 if (pmcsr & PCIM_PSTAT_DMASK) {
5858 /* delay required during transition out of D3hot */
5865 /* don't shut down the power for emulation and FPGA */
5866 if (CHIP_REV_IS_SLOW(sc)) {
5870 pmcsr &= ~PCIM_PSTAT_DMASK;
5871 pmcsr |= PCIM_PSTAT_D3;
5874 pmcsr |= PCIM_PSTAT_PMEENABLE;
5878 (sc->devinfo.pcie_pm_cap_reg +
5879 PCIR_POWER_STATUS), pmcsr);
5882 * No more memory access after this point until device is brought back
5888 PMD_DRV_LOG(NOTICE, sc, "Can't support PCI power state = %d",
5896 /* return true if succeeded to acquire the lock */
5897 static uint8_t bnx2x_trylock_hw_lock(struct bnx2x_softc *sc, uint32_t resource)
5899 uint32_t lock_status;
5900 uint32_t resource_bit = (1 << resource);
5901 int func = SC_FUNC(sc);
5902 uint32_t hw_lock_control_reg;
5904 /* Validating that the resource is within range */
5905 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
5906 PMD_DRV_LOG(INFO, sc,
5907 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)",
5908 resource, HW_LOCK_MAX_RESOURCE_VALUE);
5913 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func * 8);
5915 hw_lock_control_reg =
5916 (MISC_REG_DRIVER_CONTROL_7 + (func - 6) * 8);
5919 /* try to acquire the lock */
5920 REG_WR(sc, hw_lock_control_reg + 4, resource_bit);
5921 lock_status = REG_RD(sc, hw_lock_control_reg);
5922 if (lock_status & resource_bit) {
5926 PMD_DRV_LOG(NOTICE, sc, "Failed to get a resource lock 0x%x", resource);
5932 * Get the recovery leader resource id according to the engine this function
5933 * belongs to. Currently only only 2 engines is supported.
5935 static int bnx2x_get_leader_lock_resource(struct bnx2x_softc *sc)
5938 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
5940 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
5944 /* try to acquire a leader lock for current engine */
5945 static uint8_t bnx2x_trylock_leader_lock(struct bnx2x_softc *sc)
5947 return bnx2x_trylock_hw_lock(sc, bnx2x_get_leader_lock_resource(sc));
5950 static int bnx2x_release_leader_lock(struct bnx2x_softc *sc)
5952 return bnx2x_release_hw_lock(sc, bnx2x_get_leader_lock_resource(sc));
5955 /* close gates #2, #3 and #4 */
5956 static void bnx2x_set_234_gates(struct bnx2x_softc *sc, uint8_t close)
5960 /* gates #2 and #4a are closed/opened */
5962 REG_WR(sc, PXP_REG_HST_DISCARD_DOORBELLS, ! !close);
5964 REG_WR(sc, PXP_REG_HST_DISCARD_INTERNAL_WRITES, ! !close);
5967 if (CHIP_IS_E1x(sc)) {
5968 /* prevent interrupts from HC on both ports */
5969 val = REG_RD(sc, HC_REG_CONFIG_1);
5971 REG_WR(sc, HC_REG_CONFIG_1, (val & ~(uint32_t)
5972 HC_CONFIG_1_REG_BLOCK_DISABLE_1));
5974 REG_WR(sc, HC_REG_CONFIG_1,
5975 (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1));
5977 val = REG_RD(sc, HC_REG_CONFIG_0);
5979 REG_WR(sc, HC_REG_CONFIG_0, (val & ~(uint32_t)
5980 HC_CONFIG_0_REG_BLOCK_DISABLE_0));
5982 REG_WR(sc, HC_REG_CONFIG_0,
5983 (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0));
5986 /* Prevent incoming interrupts in IGU */
5987 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
5990 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
5992 IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
5994 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
5996 IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
6002 /* poll for pending writes bit, it should get cleared in no more than 1s */
6003 static int bnx2x_er_poll_igu_vq(struct bnx2x_softc *sc)
6005 uint32_t cnt = 1000;
6006 uint32_t pend_bits = 0;
6009 pend_bits = REG_RD(sc, IGU_REG_PENDING_BITS_STATUS);
6011 if (pend_bits == 0) {
6016 } while (cnt-- > 0);
6019 PMD_DRV_LOG(NOTICE, sc, "Still pending IGU requests bits=0x%08x!",
6027 #define SHARED_MF_CLP_MAGIC 0x80000000 /* 'magic' bit */
6029 static void bnx2x_clp_reset_prep(struct bnx2x_softc *sc, uint32_t * magic_val)
6031 /* Do some magic... */
6032 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
6033 *magic_val = val & SHARED_MF_CLP_MAGIC;
6034 MFCFG_WR(sc, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
6037 /* restore the value of the 'magic' bit */
6038 static void bnx2x_clp_reset_done(struct bnx2x_softc *sc, uint32_t magic_val)
6040 /* Restore the 'magic' bit value... */
6041 uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
6042 MFCFG_WR(sc, shared_mf_config.clp_mb,
6043 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
6046 /* prepare for MCP reset, takes care of CLP configurations */
6047 static void bnx2x_reset_mcp_prep(struct bnx2x_softc *sc, uint32_t * magic_val)
6050 uint32_t validity_offset;
6052 /* set `magic' bit in order to save MF config */
6053 bnx2x_clp_reset_prep(sc, magic_val);
6055 /* get shmem offset */
6056 shmem = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
6058 offsetof(struct shmem_region, validity_map[SC_PORT(sc)]);
6060 /* Clear validity map flags */
6062 REG_WR(sc, shmem + validity_offset, 0);
6066 #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
6067 #define MCP_ONE_TIMEOUT 100 /* 100 ms */
6069 static void bnx2x_mcp_wait_one(struct bnx2x_softc *sc)
6071 /* special handling for emulation and FPGA (10 times longer) */
6072 if (CHIP_REV_IS_SLOW(sc)) {
6073 DELAY((MCP_ONE_TIMEOUT * 10) * 1000);
6075 DELAY((MCP_ONE_TIMEOUT) * 1000);
6079 /* initialize shmem_base and waits for validity signature to appear */
6080 static int bnx2x_init_shmem(struct bnx2x_softc *sc)
6086 sc->devinfo.shmem_base =
6087 sc->link_params.shmem_base =
6088 REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
6090 if (sc->devinfo.shmem_base) {
6091 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
6092 if (val & SHR_MEM_VALIDITY_MB)
6096 bnx2x_mcp_wait_one(sc);
6098 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
6100 PMD_DRV_LOG(NOTICE, sc, "BAD MCP validity signature");
6105 static int bnx2x_reset_mcp_comp(struct bnx2x_softc *sc, uint32_t magic_val)
6107 int rc = bnx2x_init_shmem(sc);
6109 /* Restore the `magic' bit value */
6110 bnx2x_clp_reset_done(sc, magic_val);
6115 static void bnx2x_pxp_prep(struct bnx2x_softc *sc)
6117 REG_WR(sc, PXP2_REG_RD_START_INIT, 0);
6118 REG_WR(sc, PXP2_REG_RQ_RBC_DONE, 0);
6123 * Reset the whole chip except for:
6125 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by one reset bit)
6127 * - MISC (including AEU)
6131 static void bnx2x_process_kill_chip_reset(struct bnx2x_softc *sc, uint8_t global)
6133 uint32_t not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
6134 uint32_t global_bits2, stay_reset2;
6137 * Bits that have to be set in reset_mask2 if we want to reset 'global'
6138 * (per chip) blocks.
6141 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
6142 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
6145 * Don't reset the following blocks.
6146 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
6147 * reset, as in 4 port device they might still be owned
6148 * by the MCP (there is only one leader per path).
6151 MISC_REGISTERS_RESET_REG_1_RST_HC |
6152 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
6153 MISC_REGISTERS_RESET_REG_1_RST_PXP;
6156 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
6157 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
6158 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
6159 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
6160 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
6161 MISC_REGISTERS_RESET_REG_2_RST_GRC |
6162 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
6163 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
6164 MISC_REGISTERS_RESET_REG_2_RST_ATC |
6165 MISC_REGISTERS_RESET_REG_2_PGLC |
6166 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
6167 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
6168 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
6169 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
6170 MISC_REGISTERS_RESET_REG_2_UMAC0 | MISC_REGISTERS_RESET_REG_2_UMAC1;
6173 * Keep the following blocks in reset:
6174 * - all xxMACs are handled by the elink code.
6177 MISC_REGISTERS_RESET_REG_2_XMAC |
6178 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
6180 /* Full reset masks according to the chip */
6181 reset_mask1 = 0xffffffff;
6183 if (CHIP_IS_E1H(sc))
6184 reset_mask2 = 0x1ffff;
6185 else if (CHIP_IS_E2(sc))
6186 reset_mask2 = 0xfffff;
6187 else /* CHIP_IS_E3 */
6188 reset_mask2 = 0x3ffffff;
6190 /* Don't reset global blocks unless we need to */
6192 reset_mask2 &= ~global_bits2;
6195 * In case of attention in the QM, we need to reset PXP
6196 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
6197 * because otherwise QM reset would release 'close the gates' shortly
6198 * before resetting the PXP, then the PSWRQ would send a write
6199 * request to PGLUE. Then when PXP is reset, PGLUE would try to
6200 * read the payload data from PSWWR, but PSWWR would not
6201 * respond. The write queue in PGLUE would stuck, dmae commands
6202 * would not return. Therefore it's important to reset the second
6203 * reset register (containing the
6204 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
6205 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
6208 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
6209 reset_mask2 & (~not_reset_mask2));
6211 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6212 reset_mask1 & (~not_reset_mask1));
6217 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
6218 reset_mask2 & (~stay_reset2));
6223 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
6227 static int bnx2x_process_kill(struct bnx2x_softc *sc, uint8_t global)
6231 uint32_t sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
6232 uint32_t tags_63_32 = 0;
6234 /* Empty the Tetris buffer, wait for 1s */
6236 sr_cnt = REG_RD(sc, PXP2_REG_RD_SR_CNT);
6237 blk_cnt = REG_RD(sc, PXP2_REG_RD_BLK_CNT);
6238 port_is_idle_0 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_0);
6239 port_is_idle_1 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_1);
6240 pgl_exp_rom2 = REG_RD(sc, PXP2_REG_PGL_EXP_ROM2);
6241 if (CHIP_IS_E3(sc)) {
6242 tags_63_32 = REG_RD(sc, PGLUE_B_REG_TAGS_63_32);
6245 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
6246 ((port_is_idle_0 & 0x1) == 0x1) &&
6247 ((port_is_idle_1 & 0x1) == 0x1) &&
6248 (pgl_exp_rom2 == 0xffffffff) &&
6249 (!CHIP_IS_E3(sc) || (tags_63_32 == 0xffffffff)))
6252 } while (cnt-- > 0);
6255 PMD_DRV_LOG(NOTICE, sc,
6256 "ERROR: Tetris buffer didn't get empty or there "
6257 "are still outstanding read requests after 1s! "
6258 "sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, "
6259 "port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x",
6260 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
6267 /* Close gates #2, #3 and #4 */
6268 bnx2x_set_234_gates(sc, TRUE);
6270 /* Poll for IGU VQs for 57712 and newer chips */
6271 if (!CHIP_IS_E1x(sc) && bnx2x_er_poll_igu_vq(sc)) {
6275 /* clear "unprepared" bit */
6276 REG_WR(sc, MISC_REG_UNPREPARED, 0);
6279 /* Make sure all is written to the chip before the reset */
6283 * Wait for 1ms to empty GLUE and PCI-E core queues,
6284 * PSWHST, GRC and PSWRD Tetris buffer.
6288 /* Prepare to chip reset: */
6291 bnx2x_reset_mcp_prep(sc, &val);
6298 /* reset the chip */
6299 bnx2x_process_kill_chip_reset(sc, global);
6302 /* Recover after reset: */
6304 if (global && bnx2x_reset_mcp_comp(sc, val)) {
6308 /* Open the gates #2, #3 and #4 */
6309 bnx2x_set_234_gates(sc, FALSE);
6314 static int bnx2x_leader_reset(struct bnx2x_softc *sc)
6317 uint8_t global = bnx2x_reset_is_global(sc);
6321 * If not going to reset MCP, load "fake" driver to reset HW while
6322 * driver is owner of the HW.
6324 if (!global && !BNX2X_NOMCP(sc)) {
6325 load_code = bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
6326 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
6328 PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
6330 goto exit_leader_reset;
6333 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
6334 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
6335 PMD_DRV_LOG(NOTICE, sc,
6336 "MCP unexpected response, aborting");
6338 goto exit_leader_reset2;
6341 load_code = bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
6343 PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
6345 goto exit_leader_reset2;
6349 /* try to recover after the failure */
6350 if (bnx2x_process_kill(sc, global)) {
6351 PMD_DRV_LOG(NOTICE, sc, "Something bad occurred on engine %d!",
6354 goto exit_leader_reset2;
6358 * Clear the RESET_IN_PROGRESS and RESET_GLOBAL bits and update the driver
6361 bnx2x_set_reset_done(sc);
6363 bnx2x_clear_reset_global(sc);
6368 /* unload "fake driver" if it was loaded */
6369 if (!global &&!BNX2X_NOMCP(sc)) {
6370 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
6371 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
6377 bnx2x_release_leader_lock(sc);
6384 * prepare INIT transition, parameters configured:
6385 * - HC configuration
6386 * - Queue's CDU context
6389 bnx2x_pf_q_prep_init(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
6390 struct ecore_queue_init_params *init_params)
6393 int cxt_index, cxt_offset;
6395 bnx2x_set_bit(ECORE_Q_FLG_HC, &init_params->rx.flags);
6396 bnx2x_set_bit(ECORE_Q_FLG_HC, &init_params->tx.flags);
6398 bnx2x_set_bit(ECORE_Q_FLG_HC_EN, &init_params->rx.flags);
6399 bnx2x_set_bit(ECORE_Q_FLG_HC_EN, &init_params->tx.flags);
6402 init_params->rx.hc_rate =
6403 sc->hc_rx_ticks ? (1000000 / sc->hc_rx_ticks) : 0;
6404 init_params->tx.hc_rate =
6405 sc->hc_tx_ticks ? (1000000 / sc->hc_tx_ticks) : 0;
6408 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = fp->fw_sb_id;
6410 /* CQ index among the SB indices */
6411 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
6412 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
6414 /* set maximum number of COSs supported by this queue */
6415 init_params->max_cos = sc->max_cos;
6417 /* set the context pointers queue object */
6418 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
6419 cxt_index = fp->index / ILT_PAGE_CIDS;
6420 cxt_offset = fp->index - (cxt_index * ILT_PAGE_CIDS);
6421 init_params->cxts[cos] =
6422 &sc->context[cxt_index].vcxt[cxt_offset].eth;
6426 /* set flags that are common for the Tx-only and not normal connections */
6427 static unsigned long
6428 bnx2x_get_common_flags(struct bnx2x_softc *sc, uint8_t zero_stats)
6430 unsigned long flags = 0;
6432 /* PF driver will always initialize the Queue to an ACTIVE state */
6433 bnx2x_set_bit(ECORE_Q_FLG_ACTIVE, &flags);
6436 * tx only connections collect statistics (on the same index as the
6437 * parent connection). The statistics are zeroed when the parent
6438 * connection is initialized.
6441 bnx2x_set_bit(ECORE_Q_FLG_STATS, &flags);
6443 bnx2x_set_bit(ECORE_Q_FLG_ZERO_STATS, &flags);
6447 * tx only connections can support tx-switching, though their
6448 * CoS-ness doesn't survive the loopback
6450 if (sc->flags & BNX2X_TX_SWITCHING) {
6451 bnx2x_set_bit(ECORE_Q_FLG_TX_SWITCH, &flags);
6454 bnx2x_set_bit(ECORE_Q_FLG_PCSUM_ON_PKT, &flags);
6459 static unsigned long bnx2x_get_q_flags(struct bnx2x_softc *sc, uint8_t leading)
6461 unsigned long flags = 0;
6464 bnx2x_set_bit(ECORE_Q_FLG_OV, &flags);
6468 bnx2x_set_bit(ECORE_Q_FLG_LEADING_RSS, &flags);
6469 bnx2x_set_bit(ECORE_Q_FLG_MCAST, &flags);
6472 bnx2x_set_bit(ECORE_Q_FLG_VLAN, &flags);
6474 /* merge with common flags */
6475 return flags | bnx2x_get_common_flags(sc, TRUE);
6479 bnx2x_pf_q_prep_general(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
6480 struct ecore_general_setup_params *gen_init, uint8_t cos)
6482 gen_init->stat_id = bnx2x_stats_id(fp);
6483 gen_init->spcl_id = fp->cl_id;
6484 gen_init->mtu = sc->mtu;
6485 gen_init->cos = cos;
6489 bnx2x_pf_rx_q_prep(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
6490 struct rxq_pause_params *pause,
6491 struct ecore_rxq_setup_params *rxq_init)
6493 struct bnx2x_rx_queue *rxq;
6495 rxq = sc->rx_queues[fp->index];
6497 PMD_RX_LOG(ERR, "RX queue is NULL");
6501 pause->bd_th_lo = BD_TH_LO(sc);
6502 pause->bd_th_hi = BD_TH_HI(sc);
6504 pause->rcq_th_lo = RCQ_TH_LO(sc);
6505 pause->rcq_th_hi = RCQ_TH_HI(sc);
6507 /* validate rings have enough entries to cross high thresholds */
6508 if (sc->dropless_fc &&
6509 pause->bd_th_hi + FW_PREFETCH_CNT > sc->rx_ring_size) {
6510 PMD_DRV_LOG(WARNING, sc, "rx bd ring threshold limit");
6513 if (sc->dropless_fc &&
6514 pause->rcq_th_hi + FW_PREFETCH_CNT > USABLE_RCQ_ENTRIES(rxq)) {
6515 PMD_DRV_LOG(WARNING, sc, "rcq ring threshold limit");
6521 rxq_init->dscr_map = (rte_iova_t)rxq->rx_ring_phys_addr;
6522 rxq_init->rcq_map = (rte_iova_t)rxq->cq_ring_phys_addr;
6523 rxq_init->rcq_np_map = (rte_iova_t)(rxq->cq_ring_phys_addr +
6527 * This should be a maximum number of data bytes that may be
6528 * placed on the BD (not including paddings).
6530 rxq_init->buf_sz = (fp->rx_buf_size - IP_HEADER_ALIGNMENT_PADDING);
6532 rxq_init->cl_qzone_id = fp->cl_qzone_id;
6533 rxq_init->rss_engine_id = SC_FUNC(sc);
6534 rxq_init->mcast_engine_id = SC_FUNC(sc);
6536 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
6537 rxq_init->fw_sb_id = fp->fw_sb_id;
6539 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
6542 * configure silent vlan removal
6543 * if multi function mode is afex, then mask default vlan
6545 if (IS_MF_AFEX(sc)) {
6546 rxq_init->silent_removal_value =
6547 sc->devinfo.mf_info.afex_def_vlan_tag;
6548 rxq_init->silent_removal_mask = EVL_VLID_MASK;
6553 bnx2x_pf_tx_q_prep(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
6554 struct ecore_txq_setup_params *txq_init, uint8_t cos)
6556 struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
6559 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
6562 txq_init->dscr_map = (rte_iova_t)txq->tx_ring_phys_addr;
6563 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
6564 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
6565 txq_init->fw_sb_id = fp->fw_sb_id;
6568 * set the TSS leading client id for TX classfication to the
6569 * leading RSS client id
6571 txq_init->tss_leading_cl_id = BNX2X_FP(sc, 0, cl_id);
6575 * This function performs 2 steps in a queue state machine:
6580 bnx2x_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, uint8_t leading)
6582 struct ecore_queue_state_params q_params = { NULL };
6583 struct ecore_queue_setup_params *setup_params = &q_params.params.setup;
6586 PMD_DRV_LOG(DEBUG, sc, "setting up queue %d", fp->index);
6588 bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
6590 q_params.q_obj = &BNX2X_SP_OBJ(sc, fp).q_obj;
6592 /* we want to wait for completion in this context */
6593 bnx2x_set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
6595 /* prepare the INIT parameters */
6596 bnx2x_pf_q_prep_init(sc, fp, &q_params.params.init);
6598 /* Set the command */
6599 q_params.cmd = ECORE_Q_CMD_INIT;
6601 /* Change the state to INIT */
6602 rc = ecore_queue_state_change(sc, &q_params);
6604 PMD_DRV_LOG(NOTICE, sc, "Queue(%d) INIT failed", fp->index);
6608 PMD_DRV_LOG(DEBUG, sc, "init complete");
6610 /* now move the Queue to the SETUP state */
6611 memset(setup_params, 0, sizeof(*setup_params));
6613 /* set Queue flags */
6614 setup_params->flags = bnx2x_get_q_flags(sc, leading);
6616 /* set general SETUP parameters */
6617 bnx2x_pf_q_prep_general(sc, fp, &setup_params->gen_params,
6618 FIRST_TX_COS_INDEX);
6620 bnx2x_pf_rx_q_prep(sc, fp,
6621 &setup_params->pause_params,
6622 &setup_params->rxq_params);
6624 bnx2x_pf_tx_q_prep(sc, fp, &setup_params->txq_params, FIRST_TX_COS_INDEX);
6626 /* Set the command */
6627 q_params.cmd = ECORE_Q_CMD_SETUP;
6629 /* change the state to SETUP */
6630 rc = ecore_queue_state_change(sc, &q_params);
6632 PMD_DRV_LOG(NOTICE, sc, "Queue(%d) SETUP failed", fp->index);
6639 static int bnx2x_setup_leading(struct bnx2x_softc *sc)
6642 return bnx2x_setup_queue(sc, &sc->fp[0], TRUE);
6644 return bnx2x_vf_setup_queue(sc, &sc->fp[0], TRUE);
6648 bnx2x_config_rss_pf(struct bnx2x_softc *sc, struct ecore_rss_config_obj *rss_obj,
6649 uint8_t config_hash)
6651 struct ecore_config_rss_params params = { NULL };
6655 * Although RSS is meaningless when there is a single HW queue we
6656 * still need it enabled in order to have HW Rx hash generated.
6659 params.rss_obj = rss_obj;
6661 bnx2x_set_bit(RAMROD_COMP_WAIT, ¶ms.ramrod_flags);
6663 bnx2x_set_bit(ECORE_RSS_MODE_REGULAR, ¶ms.rss_flags);
6665 /* RSS configuration */
6666 bnx2x_set_bit(ECORE_RSS_IPV4, ¶ms.rss_flags);
6667 bnx2x_set_bit(ECORE_RSS_IPV4_TCP, ¶ms.rss_flags);
6668 bnx2x_set_bit(ECORE_RSS_IPV6, ¶ms.rss_flags);
6669 bnx2x_set_bit(ECORE_RSS_IPV6_TCP, ¶ms.rss_flags);
6670 if (rss_obj->udp_rss_v4) {
6671 bnx2x_set_bit(ECORE_RSS_IPV4_UDP, ¶ms.rss_flags);
6673 if (rss_obj->udp_rss_v6) {
6674 bnx2x_set_bit(ECORE_RSS_IPV6_UDP, ¶ms.rss_flags);
6678 params.rss_result_mask = MULTI_MASK;
6680 rte_memcpy(params.ind_table, rss_obj->ind_table,
6681 sizeof(params.ind_table));
6685 for (i = 0; i < sizeof(params.rss_key) / 4; i++) {
6686 params.rss_key[i] = (uint32_t) rte_rand();
6689 bnx2x_set_bit(ECORE_RSS_SET_SRCH, ¶ms.rss_flags);
6693 return ecore_config_rss(sc, ¶ms);
6695 return bnx2x_vf_config_rss(sc, ¶ms);
6698 static int bnx2x_config_rss_eth(struct bnx2x_softc *sc, uint8_t config_hash)
6700 return bnx2x_config_rss_pf(sc, &sc->rss_conf_obj, config_hash);
6703 static int bnx2x_init_rss_pf(struct bnx2x_softc *sc)
6705 uint8_t num_eth_queues = BNX2X_NUM_ETH_QUEUES(sc);
6709 * Prepare the initial contents of the indirection table if
6712 for (i = 0; i < sizeof(sc->rss_conf_obj.ind_table); i++) {
6713 sc->rss_conf_obj.ind_table[i] =
6714 (sc->fp->cl_id + (i % num_eth_queues));
6718 sc->rss_conf_obj.udp_rss_v4 = sc->rss_conf_obj.udp_rss_v6 = 1;
6722 * For 57711 SEARCHER configuration (rss_keys) is
6723 * per-port, so if explicit configuration is needed, do it only
6726 * For 57712 and newer it's a per-function configuration.
6728 return bnx2x_config_rss_eth(sc, sc->port.pmf || !CHIP_IS_E1x(sc));
6732 bnx2x_set_mac_one(struct bnx2x_softc *sc, uint8_t * mac,
6733 struct ecore_vlan_mac_obj *obj, uint8_t set, int mac_type,
6734 unsigned long *ramrod_flags)
6736 struct ecore_vlan_mac_ramrod_params ramrod_param;
6739 memset(&ramrod_param, 0, sizeof(ramrod_param));
6741 /* fill in general parameters */
6742 ramrod_param.vlan_mac_obj = obj;
6743 ramrod_param.ramrod_flags = *ramrod_flags;
6745 /* fill a user request section if needed */
6746 if (!bnx2x_test_bit(RAMROD_CONT, ramrod_flags)) {
6747 rte_memcpy(ramrod_param.user_req.u.mac.mac, mac,
6750 bnx2x_set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
6752 /* Set the command: ADD or DEL */
6753 ramrod_param.user_req.cmd = (set) ? ECORE_VLAN_MAC_ADD :
6757 rc = ecore_config_vlan_mac(sc, &ramrod_param);
6759 if (rc == ECORE_EXISTS) {
6760 PMD_DRV_LOG(INFO, sc, "Failed to schedule ADD operations (EEXIST)");
6761 /* do not treat adding same MAC as error */
6763 } else if (rc < 0) {
6764 PMD_DRV_LOG(ERR, sc,
6765 "%s MAC failed (%d)", (set ? "Set" : "Delete"), rc);
6771 static int bnx2x_set_eth_mac(struct bnx2x_softc *sc, uint8_t set)
6773 unsigned long ramrod_flags = 0;
6775 PMD_DRV_LOG(DEBUG, sc, "Adding Ethernet MAC");
6777 bnx2x_set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6779 /* Eth MAC is set on RSS leading client (fp[0]) */
6780 return bnx2x_set_mac_one(sc, sc->link_params.mac_addr,
6781 &sc->sp_objs->mac_obj,
6782 set, ECORE_ETH_MAC, &ramrod_flags);
6785 static int bnx2x_get_cur_phy_idx(struct bnx2x_softc *sc)
6787 uint32_t sel_phy_idx = 0;
6789 if (sc->link_params.num_phys <= 1) {
6790 return ELINK_INT_PHY;
6793 if (sc->link_vars.link_up) {
6794 sel_phy_idx = ELINK_EXT_PHY1;
6795 /* In case link is SERDES, check if the ELINK_EXT_PHY2 is the one */
6796 if ((sc->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
6797 (sc->link_params.phy[ELINK_EXT_PHY2].supported &
6798 ELINK_SUPPORTED_FIBRE))
6799 sel_phy_idx = ELINK_EXT_PHY2;
6801 switch (elink_phy_selection(&sc->link_params)) {
6802 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
6803 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
6804 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
6805 sel_phy_idx = ELINK_EXT_PHY1;
6807 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
6808 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
6809 sel_phy_idx = ELINK_EXT_PHY2;
6817 static int bnx2x_get_link_cfg_idx(struct bnx2x_softc *sc)
6819 uint32_t sel_phy_idx = bnx2x_get_cur_phy_idx(sc);
6822 * The selected activated PHY is always after swapping (in case PHY
6823 * swapping is enabled). So when swapping is enabled, we need to reverse
6827 if (sc->link_params.multi_phy_config & PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
6828 if (sel_phy_idx == ELINK_EXT_PHY1)
6829 sel_phy_idx = ELINK_EXT_PHY2;
6830 else if (sel_phy_idx == ELINK_EXT_PHY2)
6831 sel_phy_idx = ELINK_EXT_PHY1;
6834 return ELINK_LINK_CONFIG_IDX(sel_phy_idx);
6837 static void bnx2x_set_requested_fc(struct bnx2x_softc *sc)
6840 * Initialize link parameters structure variables
6841 * It is recommended to turn off RX FC for jumbo frames
6842 * for better performance
6844 if (CHIP_IS_E1x(sc) && (sc->mtu > 5000)) {
6845 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_TX;
6847 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_BOTH;
6851 static void bnx2x_calc_fc_adv(struct bnx2x_softc *sc)
6853 uint8_t cfg_idx = bnx2x_get_link_cfg_idx(sc);
6854 switch (sc->link_vars.ieee_fc &
6855 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
6856 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
6858 sc->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
6862 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
6863 sc->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
6867 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
6868 sc->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
6873 static uint16_t bnx2x_get_mf_speed(struct bnx2x_softc *sc)
6875 uint16_t line_speed = sc->link_vars.line_speed;
6877 uint16_t maxCfg = bnx2x_extract_max_cfg(sc,
6879 mf_info.mf_config[SC_VN
6882 /* calculate the current MAX line speed limit for the MF devices */
6884 line_speed = (line_speed * maxCfg) / 100;
6885 } else { /* SD mode */
6886 uint16_t vn_max_rate = maxCfg * 100;
6888 if (vn_max_rate < line_speed) {
6889 line_speed = vn_max_rate;
6898 bnx2x_fill_report_data(struct bnx2x_softc *sc, struct bnx2x_link_report_data *data)
6900 uint16_t line_speed = bnx2x_get_mf_speed(sc);
6902 memset(data, 0, sizeof(*data));
6904 /* fill the report data with the effective line speed */
6905 data->line_speed = line_speed;
6908 if (!sc->link_vars.link_up || (sc->flags & BNX2X_MF_FUNC_DIS)) {
6909 bnx2x_set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
6910 &data->link_report_flags);
6914 if (sc->link_vars.duplex == DUPLEX_FULL) {
6915 bnx2x_set_bit(BNX2X_LINK_REPORT_FULL_DUPLEX,
6916 &data->link_report_flags);
6919 /* Rx Flow Control is ON */
6920 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_RX) {
6921 bnx2x_set_bit(BNX2X_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
6924 /* Tx Flow Control is ON */
6925 if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
6926 bnx2x_set_bit(BNX2X_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
6930 /* report link status to OS, should be called under phy_lock */
6931 static void bnx2x_link_report_locked(struct bnx2x_softc *sc)
6933 struct bnx2x_link_report_data cur_data;
6937 bnx2x_read_mf_cfg(sc);
6940 /* Read the current link report info */
6941 bnx2x_fill_report_data(sc, &cur_data);
6943 /* Don't report link down or exactly the same link status twice */
6944 if (!memcmp(&cur_data, &sc->last_reported_link, sizeof(cur_data)) ||
6945 (bnx2x_test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
6946 &sc->last_reported_link.link_report_flags) &&
6947 bnx2x_test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
6948 &cur_data.link_report_flags))) {
6952 ELINK_DEBUG_P2(sc, "Change in link status : cur_data = %lx, last_reported_link = %lx",
6953 cur_data.link_report_flags,
6954 sc->last_reported_link.link_report_flags);
6958 ELINK_DEBUG_P1(sc, "link status change count = %x", sc->link_cnt);
6959 /* report new link params and remember the state for the next time */
6960 rte_memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data));
6962 if (bnx2x_test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
6963 &cur_data.link_report_flags)) {
6964 ELINK_DEBUG_P0(sc, "NIC Link is Down");
6966 __rte_unused const char *duplex;
6967 __rte_unused const char *flow;
6969 if (bnx2x_test_and_clear_bit(BNX2X_LINK_REPORT_FULL_DUPLEX,
6970 &cur_data.link_report_flags)) {
6972 ELINK_DEBUG_P0(sc, "link set to full duplex");
6975 ELINK_DEBUG_P0(sc, "link set to half duplex");
6979 * Handle the FC at the end so that only these flags would be
6980 * possibly set. This way we may easily check if there is no FC
6983 if (cur_data.link_report_flags) {
6984 if (bnx2x_test_bit(BNX2X_LINK_REPORT_RX_FC_ON,
6985 &cur_data.link_report_flags) &&
6986 bnx2x_test_bit(BNX2X_LINK_REPORT_TX_FC_ON,
6987 &cur_data.link_report_flags)) {
6988 flow = "ON - receive & transmit";
6989 } else if (bnx2x_test_bit(BNX2X_LINK_REPORT_RX_FC_ON,
6990 &cur_data.link_report_flags) &&
6991 !bnx2x_test_bit(BNX2X_LINK_REPORT_TX_FC_ON,
6992 &cur_data.link_report_flags)) {
6993 flow = "ON - receive";
6994 } else if (!bnx2x_test_bit(BNX2X_LINK_REPORT_RX_FC_ON,
6995 &cur_data.link_report_flags) &&
6996 bnx2x_test_bit(BNX2X_LINK_REPORT_TX_FC_ON,
6997 &cur_data.link_report_flags)) {
6998 flow = "ON - transmit";
7000 flow = "none"; /* possible? */
7006 PMD_DRV_LOG(INFO, sc,
7007 "NIC Link is Up, %d Mbps %s duplex, Flow control: %s",
7008 cur_data.line_speed, duplex, flow);
7013 bnx2x_link_report(struct bnx2x_softc *sc)
7015 bnx2x_acquire_phy_lock(sc);
7016 bnx2x_link_report_locked(sc);
7017 bnx2x_release_phy_lock(sc);
7020 void bnx2x_link_status_update(struct bnx2x_softc *sc)
7022 if (sc->state != BNX2X_STATE_OPEN) {
7026 if (IS_PF(sc) && !CHIP_REV_IS_SLOW(sc)) {
7027 elink_link_status_update(&sc->link_params, &sc->link_vars);
7029 sc->port.supported[0] |= (ELINK_SUPPORTED_10baseT_Half |
7030 ELINK_SUPPORTED_10baseT_Full |
7031 ELINK_SUPPORTED_100baseT_Half |
7032 ELINK_SUPPORTED_100baseT_Full |
7033 ELINK_SUPPORTED_1000baseT_Full |
7034 ELINK_SUPPORTED_2500baseX_Full |
7035 ELINK_SUPPORTED_10000baseT_Full |
7036 ELINK_SUPPORTED_TP |
7037 ELINK_SUPPORTED_FIBRE |
7038 ELINK_SUPPORTED_Autoneg |
7039 ELINK_SUPPORTED_Pause |
7040 ELINK_SUPPORTED_Asym_Pause);
7041 sc->port.advertising[0] = sc->port.supported[0];
7043 sc->link_params.sc = sc;
7044 sc->link_params.port = SC_PORT(sc);
7045 sc->link_params.req_duplex[0] = DUPLEX_FULL;
7046 sc->link_params.req_flow_ctrl[0] = ELINK_FLOW_CTRL_NONE;
7047 sc->link_params.req_line_speed[0] = SPEED_10000;
7048 sc->link_params.speed_cap_mask[0] = 0x7f0000;
7049 sc->link_params.switch_cfg = ELINK_SWITCH_CFG_10G;
7051 if (CHIP_REV_IS_FPGA(sc)) {
7052 sc->link_vars.mac_type = ELINK_MAC_TYPE_EMAC;
7053 sc->link_vars.line_speed = ELINK_SPEED_1000;
7054 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
7055 LINK_STATUS_SPEED_AND_DUPLEX_1000TFD);
7057 sc->link_vars.mac_type = ELINK_MAC_TYPE_BMAC;
7058 sc->link_vars.line_speed = ELINK_SPEED_10000;
7059 sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
7060 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
7063 sc->link_vars.link_up = 1;
7065 sc->link_vars.duplex = DUPLEX_FULL;
7066 sc->link_vars.flow_ctrl = ELINK_FLOW_CTRL_NONE;
7070 NIG_REG_EGRESS_DRAIN0_MODE +
7071 sc->link_params.port * 4, 0);
7072 bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
7073 bnx2x_link_report(sc);
7078 if (sc->link_vars.link_up) {
7079 bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
7081 bnx2x_stats_handle(sc, STATS_EVENT_STOP);
7083 bnx2x_link_report(sc);
7085 bnx2x_link_report_locked(sc);
7086 bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
7090 static int bnx2x_initial_phy_init(struct bnx2x_softc *sc, int load_mode)
7092 int rc, cfg_idx = bnx2x_get_link_cfg_idx(sc);
7093 uint16_t req_line_speed = sc->link_params.req_line_speed[cfg_idx];
7094 struct elink_params *lp = &sc->link_params;
7096 bnx2x_set_requested_fc(sc);
7098 bnx2x_acquire_phy_lock(sc);
7100 if (load_mode == LOAD_DIAG) {
7101 lp->loopback_mode = ELINK_LOOPBACK_XGXS;
7102 /* Prefer doing PHY loopback at 10G speed, if possible */
7103 if (lp->req_line_speed[cfg_idx] < ELINK_SPEED_10000) {
7104 if (lp->speed_cap_mask[cfg_idx] &
7105 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
7106 lp->req_line_speed[cfg_idx] = ELINK_SPEED_10000;
7108 lp->req_line_speed[cfg_idx] = ELINK_SPEED_1000;
7113 if (load_mode == LOAD_LOOPBACK_EXT) {
7114 lp->loopback_mode = ELINK_LOOPBACK_EXT;
7117 rc = elink_phy_init(&sc->link_params, &sc->link_vars);
7119 bnx2x_release_phy_lock(sc);
7121 bnx2x_calc_fc_adv(sc);
7123 if (sc->link_vars.link_up) {
7124 bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
7125 bnx2x_link_report(sc);
7128 sc->link_params.req_line_speed[cfg_idx] = req_line_speed;
7132 /* update flags in shmem */
7134 bnx2x_update_drv_flags(struct bnx2x_softc *sc, uint32_t flags, uint32_t set)
7138 if (SHMEM2_HAS(sc, drv_flags)) {
7139 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
7140 drv_flags = SHMEM2_RD(sc, drv_flags);
7145 drv_flags &= ~flags;
7148 SHMEM2_WR(sc, drv_flags, drv_flags);
7150 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
7154 /* periodic timer callout routine, only runs when the interface is up */
7155 void bnx2x_periodic_callout(struct bnx2x_softc *sc)
7157 if ((sc->state != BNX2X_STATE_OPEN) ||
7158 (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP)) {
7159 PMD_DRV_LOG(DEBUG, sc, "periodic callout exit (state=0x%x)",
7163 if (!CHIP_REV_IS_SLOW(sc)) {
7165 * This barrier is needed to ensure the ordering between the writing
7166 * to the sc->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
7171 bnx2x_acquire_phy_lock(sc);
7172 elink_period_func(&sc->link_params, &sc->link_vars);
7173 bnx2x_release_phy_lock(sc);
7177 if (IS_PF(sc) && !BNX2X_NOMCP(sc)) {
7178 int mb_idx = SC_FW_MB_IDX(sc);
7182 ++sc->fw_drv_pulse_wr_seq;
7183 sc->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
7185 drv_pulse = sc->fw_drv_pulse_wr_seq;
7186 bnx2x_drv_pulse(sc);
7188 mcp_pulse = (SHMEM_RD(sc, func_mb[mb_idx].mcp_pulse_mb) &
7189 MCP_PULSE_SEQ_MASK);
7192 * The delta between driver pulse and mcp response should
7193 * be 1 (before mcp response) or 0 (after mcp response).
7195 if ((drv_pulse != mcp_pulse) &&
7196 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
7197 /* someone lost a heartbeat... */
7198 PMD_DRV_LOG(ERR, sc,
7199 "drv_pulse (0x%x) != mcp_pulse (0x%x)",
7200 drv_pulse, mcp_pulse);
7206 /* start the controller */
7207 static __rte_noinline
7208 int bnx2x_nic_load(struct bnx2x_softc *sc)
7211 uint32_t load_code = 0;
7214 PMD_INIT_FUNC_TRACE(sc);
7216 sc->state = BNX2X_STATE_OPENING_WAITING_LOAD;
7219 /* must be called before memory allocation and HW init */
7220 bnx2x_ilt_set_info(sc);
7223 bnx2x_set_fp_rx_buf_size(sc);
7226 if (bnx2x_alloc_mem(sc) != 0) {
7227 sc->state = BNX2X_STATE_CLOSED;
7229 goto bnx2x_nic_load_error0;
7233 if (bnx2x_alloc_fw_stats_mem(sc) != 0) {
7234 sc->state = BNX2X_STATE_CLOSED;
7236 goto bnx2x_nic_load_error0;
7240 rc = bnx2x_vf_init(sc);
7242 sc->state = BNX2X_STATE_ERROR;
7243 goto bnx2x_nic_load_error0;
7248 /* set pf load just before approaching the MCP */
7249 bnx2x_set_pf_load(sc);
7251 /* if MCP exists send load request and analyze response */
7252 if (!BNX2X_NOMCP(sc)) {
7253 /* attempt to load pf */
7254 if (bnx2x_nic_load_request(sc, &load_code) != 0) {
7255 sc->state = BNX2X_STATE_CLOSED;
7257 goto bnx2x_nic_load_error1;
7260 /* what did the MCP say? */
7261 if (bnx2x_nic_load_analyze_req(sc, load_code) != 0) {
7262 bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
7263 sc->state = BNX2X_STATE_CLOSED;
7265 goto bnx2x_nic_load_error2;
7268 PMD_DRV_LOG(INFO, sc, "Device has no MCP!");
7269 load_code = bnx2x_nic_load_no_mcp(sc);
7272 /* mark PMF if applicable */
7273 bnx2x_nic_load_pmf(sc, load_code);
7275 /* Init Function state controlling object */
7276 bnx2x_init_func_obj(sc);
7279 if (bnx2x_init_hw(sc, load_code) != 0) {
7280 PMD_DRV_LOG(NOTICE, sc, "HW init failed");
7281 bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
7282 sc->state = BNX2X_STATE_CLOSED;
7284 goto bnx2x_nic_load_error2;
7288 bnx2x_nic_init(sc, load_code);
7290 /* Init per-function objects */
7292 bnx2x_init_objs(sc);
7294 /* set AFEX default VLAN tag to an invalid value */
7295 sc->devinfo.mf_info.afex_def_vlan_tag = -1;
7297 sc->state = BNX2X_STATE_OPENING_WAITING_PORT;
7298 rc = bnx2x_func_start(sc);
7300 PMD_DRV_LOG(NOTICE, sc, "Function start failed!");
7301 bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
7302 sc->state = BNX2X_STATE_ERROR;
7303 goto bnx2x_nic_load_error3;
7306 /* send LOAD_DONE command to MCP */
7307 if (!BNX2X_NOMCP(sc)) {
7309 bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
7311 PMD_DRV_LOG(NOTICE, sc,
7312 "MCP response failure, aborting");
7313 sc->state = BNX2X_STATE_ERROR;
7315 goto bnx2x_nic_load_error3;
7320 rc = bnx2x_setup_leading(sc);
7322 PMD_DRV_LOG(NOTICE, sc, "Setup leading failed!");
7323 sc->state = BNX2X_STATE_ERROR;
7324 goto bnx2x_nic_load_error3;
7327 FOR_EACH_NONDEFAULT_ETH_QUEUE(sc, i) {
7329 rc = bnx2x_setup_queue(sc, &sc->fp[i], FALSE);
7330 else /* IS_VF(sc) */
7331 rc = bnx2x_vf_setup_queue(sc, &sc->fp[i], FALSE);
7334 PMD_DRV_LOG(NOTICE, sc, "Queue(%d) setup failed", i);
7335 sc->state = BNX2X_STATE_ERROR;
7336 goto bnx2x_nic_load_error3;
7340 rc = bnx2x_init_rss_pf(sc);
7342 PMD_DRV_LOG(NOTICE, sc, "PF RSS init failed");
7343 sc->state = BNX2X_STATE_ERROR;
7344 goto bnx2x_nic_load_error3;
7347 /* now when Clients are configured we are ready to work */
7348 sc->state = BNX2X_STATE_OPEN;
7350 /* Configure a ucast MAC */
7352 rc = bnx2x_set_eth_mac(sc, TRUE);
7353 } else { /* IS_VF(sc) */
7354 rc = bnx2x_vf_set_mac(sc, TRUE);
7358 PMD_DRV_LOG(NOTICE, sc, "Setting Ethernet MAC failed");
7359 sc->state = BNX2X_STATE_ERROR;
7360 goto bnx2x_nic_load_error3;
7364 rc = bnx2x_initial_phy_init(sc, LOAD_OPEN);
7366 sc->state = BNX2X_STATE_ERROR;
7367 goto bnx2x_nic_load_error3;
7371 sc->link_params.feature_config_flags &=
7372 ~ELINK_FEATURE_CONFIG_BOOT_FROM_SAN;
7375 switch (LOAD_OPEN) {
7381 case LOAD_LOOPBACK_EXT:
7382 sc->state = BNX2X_STATE_DIAG;
7390 bnx2x_update_drv_flags(sc, 1 << DRV_FLAGS_PORT_MASK, 0);
7392 bnx2x_link_status_update(sc);
7395 if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
7396 /* mark driver is loaded in shmem2 */
7397 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
7398 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
7400 DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
7401 DRV_FLAGS_CAPABILITIES_LOADED_L2));
7404 /* start fast path */
7405 /* Initialize Rx filter */
7406 bnx2x_set_rx_mode(sc);
7408 /* wait for all pending SP commands to complete */
7409 if (IS_PF(sc) && !bnx2x_wait_sp_comp(sc, ~0x0UL)) {
7410 PMD_DRV_LOG(NOTICE, sc, "Timeout waiting for all SPs to complete!");
7411 bnx2x_periodic_stop(sc);
7412 bnx2x_nic_unload(sc, UNLOAD_CLOSE, FALSE);
7416 PMD_DRV_LOG(DEBUG, sc, "NIC successfully loaded");
7420 bnx2x_nic_load_error3:
7423 bnx2x_int_disable_sync(sc, 1);
7425 /* clean out queued objects */
7426 bnx2x_squeeze_objects(sc);
7429 bnx2x_nic_load_error2:
7431 if (IS_PF(sc) && !BNX2X_NOMCP(sc)) {
7432 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
7433 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
7438 bnx2x_nic_load_error1:
7440 /* clear pf_load status, as it was already set */
7442 bnx2x_clear_pf_load(sc);
7445 bnx2x_nic_load_error0:
7447 bnx2x_free_fw_stats_mem(sc);
7454 * Handles controller initialization.
7456 int bnx2x_init(struct bnx2x_softc *sc)
7458 int other_engine = SC_PATH(sc) ? 0 : 1;
7459 uint8_t other_load_status, load_status;
7460 uint8_t global = FALSE;
7463 /* Check if the driver is still running and bail out if it is. */
7464 if (sc->state != BNX2X_STATE_CLOSED) {
7465 PMD_DRV_LOG(DEBUG, sc, "Init called while driver is running!");
7467 goto bnx2x_init_done;
7470 bnx2x_set_power_state(sc, PCI_PM_D0);
7473 * If parity occurred during the unload, then attentions and/or
7474 * RECOVERY_IN_PROGRESS may still be set. If so we want the first function
7475 * loaded on the current engine to complete the recovery. Parity recovery
7476 * is only relevant for PF driver.
7479 other_load_status = bnx2x_get_load_status(sc, other_engine);
7480 load_status = bnx2x_get_load_status(sc, SC_PATH(sc));
7482 if (!bnx2x_reset_is_done(sc, SC_PATH(sc)) ||
7483 bnx2x_chk_parity_attn(sc, &global, TRUE)) {
7486 * If there are attentions and they are in global blocks, set
7487 * the GLOBAL_RESET bit regardless whether it will be this
7488 * function that will complete the recovery or not.
7491 bnx2x_set_reset_global(sc);
7495 * Only the first function on the current engine should try
7496 * to recover in open. In case of attentions in global blocks
7497 * only the first in the chip should try to recover.
7500 && (!global ||!other_load_status))
7501 && bnx2x_trylock_leader_lock(sc)
7502 && !bnx2x_leader_reset(sc)) {
7503 PMD_DRV_LOG(INFO, sc,
7504 "Recovered during init");
7508 /* recovery has failed... */
7509 bnx2x_set_power_state(sc, PCI_PM_D3hot);
7511 sc->recovery_state = BNX2X_RECOVERY_FAILED;
7513 PMD_DRV_LOG(NOTICE, sc,
7514 "Recovery flow hasn't properly "
7515 "completed yet, try again later. "
7516 "If you still see this message after a "
7517 "few retries then power cycle is required.");
7520 goto bnx2x_init_done;
7525 sc->recovery_state = BNX2X_RECOVERY_DONE;
7527 rc = bnx2x_nic_load(sc);
7532 PMD_DRV_LOG(NOTICE, sc, "Initialization failed, "
7533 "stack notified driver is NOT running!");
7539 static void bnx2x_get_function_num(struct bnx2x_softc *sc)
7544 * Read the ME register to get the function number. The ME register
7545 * holds the relative-function number and absolute-function number. The
7546 * absolute-function number appears only in E2 and above. Before that
7547 * these bits always contained zero, therefore we cannot blindly use them.
7550 val = REG_RD(sc, BAR_ME_REGISTER);
7553 (uint8_t) ((val & ME_REG_PF_NUM) >> ME_REG_PF_NUM_SHIFT);
7555 (uint8_t) ((val & ME_REG_ABS_PF_NUM) >> ME_REG_ABS_PF_NUM_SHIFT) &
7558 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
7559 sc->pfunc_abs = ((sc->pfunc_rel << 1) | sc->path_id);
7561 sc->pfunc_abs = (sc->pfunc_rel | sc->path_id);
7564 PMD_DRV_LOG(DEBUG, sc,
7565 "Relative function %d, Absolute function %d, Path %d",
7566 sc->pfunc_rel, sc->pfunc_abs, sc->path_id);
7569 static uint32_t bnx2x_get_shmem_mf_cfg_base(struct bnx2x_softc *sc)
7571 uint32_t shmem2_size;
7573 uint32_t mf_cfg_offset_value;
7576 offset = (SHMEM_ADDR(sc, func_mb) +
7577 (MAX_FUNC_NUM * sizeof(struct drv_func_mb)));
7580 if (sc->devinfo.shmem2_base != 0) {
7581 shmem2_size = SHMEM2_RD(sc, size);
7582 if (shmem2_size > offsetof(struct shmem2_region, mf_cfg_addr)) {
7583 mf_cfg_offset_value = SHMEM2_RD(sc, mf_cfg_addr);
7584 if (SHMEM_MF_CFG_ADDR_NONE != mf_cfg_offset_value) {
7585 offset = mf_cfg_offset_value;
7593 static uint32_t bnx2x_pcie_capability_read(struct bnx2x_softc *sc, int reg)
7596 struct bnx2x_pci_cap *caps;
7598 /* ensure PCIe capability is enabled */
7599 caps = pci_find_cap(sc, PCIY_EXPRESS, BNX2X_PCI_CAP);
7601 PMD_DRV_LOG(DEBUG, sc, "Found PCIe capability: "
7602 "id=0x%04X type=0x%04X addr=0x%08X",
7603 caps->id, caps->type, caps->addr);
7604 pci_read(sc, (caps->addr + reg), &ret, 2);
7608 PMD_DRV_LOG(WARNING, sc, "PCIe capability NOT FOUND!!!");
7613 static uint8_t bnx2x_is_pcie_pending(struct bnx2x_softc *sc)
7615 return bnx2x_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_STA) &
7616 PCIM_EXP_STA_TRANSACTION_PND;
7620 * Walk the PCI capabiites list for the device to find what features are
7621 * supported. These capabilites may be enabled/disabled by firmware so it's
7622 * best to walk the list rather than make assumptions.
7624 static void bnx2x_probe_pci_caps(struct bnx2x_softc *sc)
7626 PMD_INIT_FUNC_TRACE(sc);
7628 struct bnx2x_pci_cap *caps;
7629 uint16_t link_status;
7632 /* check if PCI Power Management is enabled */
7633 caps = pci_find_cap(sc, PCIY_PMG, BNX2X_PCI_CAP);
7635 PMD_DRV_LOG(DEBUG, sc, "Found PM capability: "
7636 "id=0x%04X type=0x%04X addr=0x%08X",
7637 caps->id, caps->type, caps->addr);
7639 sc->devinfo.pcie_cap_flags |= BNX2X_PM_CAPABLE_FLAG;
7640 sc->devinfo.pcie_pm_cap_reg = caps->addr;
7643 link_status = bnx2x_pcie_capability_read(sc, PCIR_EXPRESS_LINK_STA);
7645 sc->devinfo.pcie_link_speed = (link_status & PCIM_LINK_STA_SPEED);
7646 sc->devinfo.pcie_link_width =
7647 ((link_status & PCIM_LINK_STA_WIDTH) >> 4);
7649 PMD_DRV_LOG(DEBUG, sc, "PCIe link speed=%d width=%d",
7650 sc->devinfo.pcie_link_speed, sc->devinfo.pcie_link_width);
7652 sc->devinfo.pcie_cap_flags |= BNX2X_PCIE_CAPABLE_FLAG;
7654 /* check if MSI capability is enabled */
7655 caps = pci_find_cap(sc, PCIY_MSI, BNX2X_PCI_CAP);
7657 PMD_DRV_LOG(DEBUG, sc, "Found MSI capability at 0x%04x", reg);
7659 sc->devinfo.pcie_cap_flags |= BNX2X_MSI_CAPABLE_FLAG;
7660 sc->devinfo.pcie_msi_cap_reg = caps->addr;
7663 /* check if MSI-X capability is enabled */
7664 caps = pci_find_cap(sc, PCIY_MSIX, BNX2X_PCI_CAP);
7666 PMD_DRV_LOG(DEBUG, sc, "Found MSI-X capability at 0x%04x", reg);
7668 sc->devinfo.pcie_cap_flags |= BNX2X_MSIX_CAPABLE_FLAG;
7669 sc->devinfo.pcie_msix_cap_reg = caps->addr;
7673 static int bnx2x_get_shmem_mf_cfg_info_sd(struct bnx2x_softc *sc)
7675 struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
7678 /* get the outer vlan if we're in switch-dependent mode */
7680 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
7681 mf_info->ext_id = (uint16_t) val;
7683 mf_info->multi_vnics_mode = 1;
7685 if (!VALID_OVLAN(mf_info->ext_id)) {
7686 PMD_DRV_LOG(NOTICE, sc, "Invalid VLAN (%d)", mf_info->ext_id);
7690 /* get the capabilities */
7691 if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
7692 FUNC_MF_CFG_PROTOCOL_ISCSI) {
7693 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ISCSI;
7694 } else if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK)
7695 == FUNC_MF_CFG_PROTOCOL_FCOE) {
7696 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_FCOE;
7698 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ETHERNET;
7701 mf_info->vnics_per_port =
7702 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
7707 static uint32_t bnx2x_get_shmem_ext_proto_support_flags(struct bnx2x_softc *sc)
7709 uint32_t retval = 0;
7712 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
7714 if (val & MACP_FUNC_CFG_FLAGS_ENABLED) {
7715 if (val & MACP_FUNC_CFG_FLAGS_ETHERNET) {
7716 retval |= MF_PROTO_SUPPORT_ETHERNET;
7718 if (val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
7719 retval |= MF_PROTO_SUPPORT_ISCSI;
7721 if (val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
7722 retval |= MF_PROTO_SUPPORT_FCOE;
7729 static int bnx2x_get_shmem_mf_cfg_info_si(struct bnx2x_softc *sc)
7731 struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
7735 * There is no outer vlan if we're in switch-independent mode.
7736 * If the mac is valid then assume multi-function.
7739 val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
7741 mf_info->multi_vnics_mode = ((val & MACP_FUNC_CFG_FLAGS_MASK) != 0);
7743 mf_info->mf_protos_supported =
7744 bnx2x_get_shmem_ext_proto_support_flags(sc);
7746 mf_info->vnics_per_port =
7747 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
7752 static int bnx2x_get_shmem_mf_cfg_info_niv(struct bnx2x_softc *sc)
7754 struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
7756 uint32_t func_config;
7757 uint32_t niv_config;
7759 mf_info->multi_vnics_mode = 1;
7761 e1hov_tag = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
7762 func_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
7763 niv_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].afex_config);
7766 (uint16_t) ((e1hov_tag & FUNC_MF_CFG_E1HOV_TAG_MASK) >>
7767 FUNC_MF_CFG_E1HOV_TAG_SHIFT);
7769 mf_info->default_vlan =
7770 (uint16_t) ((e1hov_tag & FUNC_MF_CFG_AFEX_VLAN_MASK) >>
7771 FUNC_MF_CFG_AFEX_VLAN_SHIFT);
7773 mf_info->niv_allowed_priorities =
7774 (uint8_t) ((niv_config & FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
7775 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT);
7777 mf_info->niv_default_cos =
7778 (uint8_t) ((func_config & FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
7779 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT);
7781 mf_info->afex_vlan_mode =
7782 ((niv_config & FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
7783 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT);
7785 mf_info->niv_mba_enabled =
7786 ((niv_config & FUNC_MF_CFG_AFEX_MBA_ENABLED_MASK) >>
7787 FUNC_MF_CFG_AFEX_MBA_ENABLED_SHIFT);
7789 mf_info->mf_protos_supported =
7790 bnx2x_get_shmem_ext_proto_support_flags(sc);
7792 mf_info->vnics_per_port =
7793 (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
7798 static int bnx2x_check_valid_mf_cfg(struct bnx2x_softc *sc)
7800 struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
7807 /* various MF mode sanity checks... */
7809 if (mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_HIDE) {
7810 PMD_DRV_LOG(NOTICE, sc,
7811 "Enumerated function %d is marked as hidden",
7816 if ((mf_info->vnics_per_port > 1) && !mf_info->multi_vnics_mode) {
7817 PMD_DRV_LOG(NOTICE, sc, "vnics_per_port=%d multi_vnics_mode=%d",
7818 mf_info->vnics_per_port, mf_info->multi_vnics_mode);
7822 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
7823 /* vnic id > 0 must have valid ovlan in switch-dependent mode */
7824 if ((SC_VN(sc) > 0) && !VALID_OVLAN(OVLAN(sc))) {
7825 PMD_DRV_LOG(NOTICE, sc, "mf_mode=SD vnic_id=%d ovlan=%d",
7826 SC_VN(sc), OVLAN(sc));
7830 if (!VALID_OVLAN(OVLAN(sc)) && mf_info->multi_vnics_mode) {
7831 PMD_DRV_LOG(NOTICE, sc,
7832 "mf_mode=SD multi_vnics_mode=%d ovlan=%d",
7833 mf_info->multi_vnics_mode, OVLAN(sc));
7838 * Verify all functions are either MF or SF mode. If MF, make sure
7839 * sure that all non-hidden functions have a valid ovlan. If SF,
7840 * make sure that all non-hidden functions have an invalid ovlan.
7842 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
7843 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
7844 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
7845 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
7846 (((mf_info->multi_vnics_mode)
7847 && !VALID_OVLAN(ovlan1))
7848 || ((!mf_info->multi_vnics_mode)
7849 && VALID_OVLAN(ovlan1)))) {
7850 PMD_DRV_LOG(NOTICE, sc,
7851 "mf_mode=SD function %d MF config "
7852 "mismatch, multi_vnics_mode=%d ovlan=%d",
7853 i, mf_info->multi_vnics_mode,
7859 /* Verify all funcs on the same port each have a different ovlan. */
7860 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
7861 mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
7862 ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
7863 /* iterate from the next function on the port to the max func */
7864 for (j = i + 2; j < MAX_FUNC_NUM; j += 2) {
7866 MFCFG_RD(sc, func_mf_config[j].config);
7868 MFCFG_RD(sc, func_mf_config[j].e1hov_tag);
7869 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE)
7870 && VALID_OVLAN(ovlan1)
7871 && !(mf_cfg2 & FUNC_MF_CFG_FUNC_HIDE)
7872 && VALID_OVLAN(ovlan2)
7873 && (ovlan1 == ovlan2)) {
7874 PMD_DRV_LOG(NOTICE, sc,
7875 "mf_mode=SD functions %d and %d "
7876 "have the same ovlan (%d)",
7883 /* MULTI_FUNCTION_SD */
7887 static int bnx2x_get_mf_cfg_info(struct bnx2x_softc *sc)
7889 struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
7890 uint32_t val, mac_upper;
7893 /* initialize mf_info defaults */
7894 mf_info->vnics_per_port = 1;
7895 mf_info->multi_vnics_mode = FALSE;
7896 mf_info->path_has_ovlan = FALSE;
7897 mf_info->mf_mode = SINGLE_FUNCTION;
7899 if (!CHIP_IS_MF_CAP(sc)) {
7903 if (sc->devinfo.mf_cfg_base == SHMEM_MF_CFG_ADDR_NONE) {
7904 PMD_DRV_LOG(NOTICE, sc, "Invalid mf_cfg_base!");
7908 /* get the MF mode (switch dependent / independent / single-function) */
7910 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
7912 switch (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK) {
7913 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
7916 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
7918 /* check for legal upper mac bytes */
7919 if (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT) {
7920 mf_info->mf_mode = MULTI_FUNCTION_SI;
7922 PMD_DRV_LOG(NOTICE, sc,
7923 "Invalid config for Switch Independent mode");
7928 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
7929 case SHARED_FEAT_CFG_FORCE_SF_MODE_SPIO4:
7931 /* get outer vlan configuration */
7932 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
7934 if ((val & FUNC_MF_CFG_E1HOV_TAG_MASK) !=
7935 FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
7936 mf_info->mf_mode = MULTI_FUNCTION_SD;
7938 PMD_DRV_LOG(NOTICE, sc,
7939 "Invalid config for Switch Dependent mode");
7944 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
7946 /* not in MF mode, vnics_per_port=1 and multi_vnics_mode=FALSE */
7949 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
7952 * Mark MF mode as NIV if MCP version includes NPAR-SD support
7953 * and the MAC address is valid.
7956 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
7958 if ((SHMEM2_HAS(sc, afex_driver_support)) &&
7959 (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT)) {
7960 mf_info->mf_mode = MULTI_FUNCTION_AFEX;
7962 PMD_DRV_LOG(NOTICE, sc, "Invalid config for AFEX mode");
7969 PMD_DRV_LOG(NOTICE, sc, "Unknown MF mode (0x%08x)",
7970 (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK));
7975 /* set path mf_mode (which could be different than function mf_mode) */
7976 if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
7977 mf_info->path_has_ovlan = TRUE;
7978 } else if (mf_info->mf_mode == SINGLE_FUNCTION) {
7980 * Decide on path multi vnics mode. If we're not in MF mode and in
7981 * 4-port mode, this is good enough to check vnic-0 of the other port
7984 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
7985 uint8_t other_port = !(PORT_ID(sc) & 1);
7986 uint8_t abs_func_other_port =
7987 (SC_PATH(sc) + (2 * other_port));
7992 [abs_func_other_port].e1hov_tag);
7994 mf_info->path_has_ovlan = VALID_OVLAN((uint16_t) val);
7998 if (mf_info->mf_mode == SINGLE_FUNCTION) {
7999 /* invalid MF config */
8000 if (SC_VN(sc) >= 1) {
8001 PMD_DRV_LOG(NOTICE, sc, "VNIC ID >= 1 in SF mode");
8008 /* get the MF configuration */
8009 mf_info->mf_config[SC_VN(sc)] =
8010 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
8012 switch (mf_info->mf_mode) {
8013 case MULTI_FUNCTION_SD:
8015 bnx2x_get_shmem_mf_cfg_info_sd(sc);
8018 case MULTI_FUNCTION_SI:
8020 bnx2x_get_shmem_mf_cfg_info_si(sc);
8023 case MULTI_FUNCTION_AFEX:
8025 bnx2x_get_shmem_mf_cfg_info_niv(sc);
8030 PMD_DRV_LOG(NOTICE, sc, "Get MF config failed (mf_mode=0x%08x)",
8035 /* get the congestion management parameters */
8038 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
8039 /* get min/max bw */
8040 val = MFCFG_RD(sc, func_mf_config[i].config);
8041 mf_info->min_bw[vnic] =
8042 ((val & FUNC_MF_CFG_MIN_BW_MASK) >>
8043 FUNC_MF_CFG_MIN_BW_SHIFT);
8044 mf_info->max_bw[vnic] =
8045 ((val & FUNC_MF_CFG_MAX_BW_MASK) >>
8046 FUNC_MF_CFG_MAX_BW_SHIFT);
8050 return bnx2x_check_valid_mf_cfg(sc);
8053 static int bnx2x_get_shmem_info(struct bnx2x_softc *sc)
8056 uint32_t mac_hi, mac_lo, val;
8058 PMD_INIT_FUNC_TRACE(sc);
8061 mac_hi = mac_lo = 0;
8063 sc->link_params.sc = sc;
8064 sc->link_params.port = port;
8066 /* get the hardware config info */
8067 sc->devinfo.hw_config = SHMEM_RD(sc, dev_info.shared_hw_config.config);
8068 sc->devinfo.hw_config2 =
8069 SHMEM_RD(sc, dev_info.shared_hw_config.config2);
8071 sc->link_params.hw_led_mode =
8072 ((sc->devinfo.hw_config & SHARED_HW_CFG_LED_MODE_MASK) >>
8073 SHARED_HW_CFG_LED_MODE_SHIFT);
8075 /* get the port feature config */
8077 SHMEM_RD(sc, dev_info.port_feature_config[port].config);
8079 /* get the link params */
8080 sc->link_params.speed_cap_mask[ELINK_INT_PHY] =
8081 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask)
8082 & PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
8083 sc->link_params.speed_cap_mask[ELINK_EXT_PHY1] =
8084 SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask2)
8085 & PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
8087 /* get the lane config */
8088 sc->link_params.lane_config =
8089 SHMEM_RD(sc, dev_info.port_hw_config[port].lane_config);
8091 /* get the link config */
8092 val = SHMEM_RD(sc, dev_info.port_feature_config[port].link_config);
8093 sc->port.link_config[ELINK_INT_PHY] = val;
8094 sc->link_params.switch_cfg = (val & PORT_FEATURE_CONNECTED_SWITCH_MASK);
8095 sc->port.link_config[ELINK_EXT_PHY1] =
8096 SHMEM_RD(sc, dev_info.port_feature_config[port].link_config2);
8098 /* get the override preemphasis flag and enable it or turn it off */
8099 val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
8100 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) {
8101 sc->link_params.feature_config_flags |=
8102 ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8104 sc->link_params.feature_config_flags &=
8105 ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8108 val = sc->devinfo.bc_ver >> 8;
8109 if (val < BNX2X_BC_VER) {
8110 /* for now only warn later we might need to enforce this */
8111 PMD_DRV_LOG(NOTICE, sc, "This driver needs bc_ver %X but found %X, please upgrade BC\n",
8114 sc->link_params.feature_config_flags |=
8115 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
8116 ELINK_FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY :
8119 sc->link_params.feature_config_flags |=
8120 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
8121 ELINK_FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
8122 sc->link_params.feature_config_flags |=
8123 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
8124 ELINK_FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
8125 sc->link_params.feature_config_flags |=
8126 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
8127 ELINK_FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
8129 /* get the initial value of the link params */
8130 sc->link_params.multi_phy_config =
8131 SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config);
8133 /* get external phy info */
8134 sc->port.ext_phy_config =
8135 SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
8137 /* get the multifunction configuration */
8138 bnx2x_get_mf_cfg_info(sc);
8140 /* get the mac address */
8143 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
8145 MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_lower);
8147 mac_hi = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_upper);
8148 mac_lo = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_lower);
8151 if ((mac_lo == 0) && (mac_hi == 0)) {
8152 *sc->mac_addr_str = 0;
8153 PMD_DRV_LOG(NOTICE, sc, "No Ethernet address programmed!");
8155 sc->link_params.mac_addr[0] = (uint8_t) (mac_hi >> 8);
8156 sc->link_params.mac_addr[1] = (uint8_t) (mac_hi);
8157 sc->link_params.mac_addr[2] = (uint8_t) (mac_lo >> 24);
8158 sc->link_params.mac_addr[3] = (uint8_t) (mac_lo >> 16);
8159 sc->link_params.mac_addr[4] = (uint8_t) (mac_lo >> 8);
8160 sc->link_params.mac_addr[5] = (uint8_t) (mac_lo);
8161 snprintf(sc->mac_addr_str, sizeof(sc->mac_addr_str),
8162 "%02x:%02x:%02x:%02x:%02x:%02x",
8163 sc->link_params.mac_addr[0],
8164 sc->link_params.mac_addr[1],
8165 sc->link_params.mac_addr[2],
8166 sc->link_params.mac_addr[3],
8167 sc->link_params.mac_addr[4],
8168 sc->link_params.mac_addr[5]);
8169 PMD_DRV_LOG(DEBUG, sc,
8170 "Ethernet address: %s", sc->mac_addr_str);
8176 static void bnx2x_media_detect(struct bnx2x_softc *sc)
8178 uint32_t phy_idx = bnx2x_get_cur_phy_idx(sc);
8179 switch (sc->link_params.phy[phy_idx].media_type) {
8180 case ELINK_ETH_PHY_SFPP_10G_FIBER:
8181 case ELINK_ETH_PHY_SFP_1G_FIBER:
8182 case ELINK_ETH_PHY_XFP_FIBER:
8183 case ELINK_ETH_PHY_KR:
8184 case ELINK_ETH_PHY_CX4:
8185 PMD_DRV_LOG(INFO, sc, "Found 10GBase-CX4 media.");
8186 sc->media = IFM_10G_CX4;
8188 case ELINK_ETH_PHY_DA_TWINAX:
8189 PMD_DRV_LOG(INFO, sc, "Found 10Gb Twinax media.");
8190 sc->media = IFM_10G_TWINAX;
8192 case ELINK_ETH_PHY_BASE_T:
8193 PMD_DRV_LOG(INFO, sc, "Found 10GBase-T media.");
8194 sc->media = IFM_10G_T;
8196 case ELINK_ETH_PHY_NOT_PRESENT:
8197 PMD_DRV_LOG(INFO, sc, "Media not present.");
8200 case ELINK_ETH_PHY_UNSPECIFIED:
8202 PMD_DRV_LOG(INFO, sc, "Unknown media!");
8208 #define GET_FIELD(value, fname) \
8209 (((value) & (fname##_MASK)) >> (fname##_SHIFT))
8210 #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
8211 #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
8213 static int bnx2x_get_igu_cam_info(struct bnx2x_softc *sc)
8215 int pfid = SC_FUNC(sc);
8218 uint8_t fid, igu_sb_cnt = 0;
8220 sc->igu_base_sb = 0xff;
8222 if (CHIP_INT_MODE_IS_BC(sc)) {
8224 igu_sb_cnt = sc->igu_sb_cnt;
8225 sc->igu_base_sb = ((CHIP_IS_MODE_4_PORT(sc) ? pfid : vn) *
8227 sc->igu_dsb_id = (E1HVN_MAX * FP_SB_MAX_E1x +
8228 (CHIP_IS_MODE_4_PORT(sc) ? pfid : vn));
8232 /* IGU in normal mode - read CAM */
8234 igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; igu_sb_id++) {
8235 val = REG_RD(sc, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
8236 if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) {
8240 if (fid & IGU_FID_ENCODE_IS_PF) {
8241 if ((fid & IGU_FID_PF_NUM_MASK) != pfid) {
8244 if (IGU_VEC(val) == 0) {
8245 /* default status block */
8246 sc->igu_dsb_id = igu_sb_id;
8248 if (sc->igu_base_sb == 0xff) {
8249 sc->igu_base_sb = igu_sb_id;
8257 * Due to new PF resource allocation by MFW T7.4 and above, it's optional
8258 * that number of CAM entries will not be equal to the value advertised in
8259 * PCI. Driver should use the minimal value of both as the actual status
8262 sc->igu_sb_cnt = min(sc->igu_sb_cnt, igu_sb_cnt);
8264 if (igu_sb_cnt == 0) {
8265 PMD_DRV_LOG(ERR, sc, "CAM configuration error");
8273 * Gather various information from the device config space, the device itself,
8274 * shmem, and the user input.
8276 static int bnx2x_get_device_info(struct bnx2x_softc *sc)
8281 /* get the chip revision (chip metal comes from pci config space) */
8282 sc->devinfo.chip_id = sc->link_params.chip_id =
8283 (((REG_RD(sc, MISC_REG_CHIP_NUM) & 0xffff) << 16) |
8284 ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12) |
8285 (((REG_RD(sc, PCICFG_OFFSET + PCI_ID_VAL3) >> 24) & 0xf) << 4) |
8286 ((REG_RD(sc, MISC_REG_BOND_ID) & 0xf) << 0));
8288 /* force 57811 according to MISC register */
8289 if (REG_RD(sc, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
8290 if (CHIP_IS_57810(sc)) {
8291 sc->devinfo.chip_id = ((CHIP_NUM_57811 << 16) |
8293 devinfo.chip_id & 0x0000ffff));
8294 } else if (CHIP_IS_57810_MF(sc)) {
8295 sc->devinfo.chip_id = ((CHIP_NUM_57811_MF << 16) |
8297 devinfo.chip_id & 0x0000ffff));
8299 sc->devinfo.chip_id |= 0x1;
8302 PMD_DRV_LOG(DEBUG, sc,
8303 "chip_id=0x%08x (num=0x%04x rev=0x%01x metal=0x%02x bond=0x%01x)",
8304 sc->devinfo.chip_id,
8305 ((sc->devinfo.chip_id >> 16) & 0xffff),
8306 ((sc->devinfo.chip_id >> 12) & 0xf),
8307 ((sc->devinfo.chip_id >> 4) & 0xff),
8308 ((sc->devinfo.chip_id >> 0) & 0xf));
8310 val = (REG_RD(sc, 0x2874) & 0x55);
8311 if ((sc->devinfo.chip_id & 0x1) || (CHIP_IS_E1H(sc) && (val == 0x55))) {
8312 sc->flags |= BNX2X_ONE_PORT_FLAG;
8313 PMD_DRV_LOG(DEBUG, sc, "single port device");
8316 /* set the doorbell size */
8317 sc->doorbell_size = (1 << BNX2X_DB_SHIFT);
8319 /* determine whether the device is in 2 port or 4 port mode */
8320 sc->devinfo.chip_port_mode = CHIP_PORT_MODE_NONE; /* E1h */
8321 if (CHIP_IS_E2E3(sc)) {
8323 * Read port4mode_en_ovwr[0]:
8324 * If 1, four port mode is in port4mode_en_ovwr[1].
8325 * If 0, four port mode is in port4mode_en[0].
8327 val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR);
8329 val = ((val >> 1) & 1);
8331 val = REG_RD(sc, MISC_REG_PORT4MODE_EN);
8334 sc->devinfo.chip_port_mode =
8335 (val) ? CHIP_4_PORT_MODE : CHIP_2_PORT_MODE;
8337 PMD_DRV_LOG(DEBUG, sc, "Port mode = %s", (val) ? "4" : "2");
8340 /* get the function and path info for the device */
8341 bnx2x_get_function_num(sc);
8343 /* get the shared memory base address */
8344 sc->devinfo.shmem_base =
8345 sc->link_params.shmem_base = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
8346 sc->devinfo.shmem2_base =
8347 REG_RD(sc, (SC_PATH(sc) ? MISC_REG_GENERIC_CR_1 :
8348 MISC_REG_GENERIC_CR_0));
8350 if (!sc->devinfo.shmem_base) {
8351 /* this should ONLY prevent upcoming shmem reads */
8352 PMD_DRV_LOG(INFO, sc, "MCP not active");
8353 sc->flags |= BNX2X_NO_MCP_FLAG;
8357 /* make sure the shared memory contents are valid */
8358 val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
8359 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) !=
8360 (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) {
8361 PMD_DRV_LOG(NOTICE, sc, "Invalid SHMEM validity signature: 0x%08x",
8366 /* get the bootcode version */
8367 sc->devinfo.bc_ver = SHMEM_RD(sc, dev_info.bc_rev);
8368 snprintf(sc->devinfo.bc_ver_str,
8369 sizeof(sc->devinfo.bc_ver_str),
8371 ((sc->devinfo.bc_ver >> 24) & 0xff),
8372 ((sc->devinfo.bc_ver >> 16) & 0xff),
8373 ((sc->devinfo.bc_ver >> 8) & 0xff));
8374 PMD_DRV_LOG(DEBUG, sc, "Bootcode version: %s", sc->devinfo.bc_ver_str);
8376 /* get the bootcode shmem address */
8377 sc->devinfo.mf_cfg_base = bnx2x_get_shmem_mf_cfg_base(sc);
8379 /* clean indirect addresses as they're not used */
8380 pci_write_long(sc, PCICFG_GRC_ADDRESS, 0);
8382 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F0, 0);
8383 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F0, 0);
8384 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F0, 0);
8385 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F0, 0);
8386 if (CHIP_IS_E1x(sc)) {
8387 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F1, 0);
8388 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F1, 0);
8389 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F1, 0);
8390 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F1, 0);
8394 /* get the nvram size */
8395 val = REG_RD(sc, MCP_REG_MCPR_NVM_CFG4);
8396 sc->devinfo.flash_size =
8397 (NVRAM_1MB_SIZE << (val & MCPR_NVM_CFG4_FLASH_SIZE));
8399 bnx2x_set_power_state(sc, PCI_PM_D0);
8400 /* get various configuration parameters from shmem */
8401 bnx2x_get_shmem_info(sc);
8403 /* initialize IGU parameters */
8404 if (CHIP_IS_E1x(sc)) {
8405 sc->devinfo.int_block = INT_BLOCK_HC;
8406 sc->igu_dsb_id = DEF_SB_IGU_ID;
8407 sc->igu_base_sb = 0;
8409 sc->devinfo.int_block = INT_BLOCK_IGU;
8411 /* do not allow device reset during IGU info preocessing */
8412 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
8414 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
8416 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8419 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
8420 REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, val);
8421 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x7f);
8423 while (tout && REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
8428 if (REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
8429 PMD_DRV_LOG(NOTICE, sc,
8430 "FORCING IGU Normal Mode failed!!!");
8431 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
8436 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8437 PMD_DRV_LOG(DEBUG, sc, "IGU Backward Compatible Mode");
8438 sc->devinfo.int_block |= INT_BLOCK_MODE_BW_COMP;
8440 PMD_DRV_LOG(DEBUG, sc, "IGU Normal Mode");
8443 rc = bnx2x_get_igu_cam_info(sc);
8445 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
8453 * Get base FW non-default (fast path) status block ID. This value is
8454 * used to initialize the fw_sb_id saved on the fp/queue structure to
8455 * determine the id used by the FW.
8457 if (CHIP_IS_E1x(sc)) {
8459 ((SC_PORT(sc) * FP_SB_MAX_E1x) + SC_L_ID(sc));
8462 * 57712+ - We currently use one FW SB per IGU SB (Rx and Tx of
8463 * the same queue are indicated on the same IGU SB). So we prefer
8464 * FW and IGU SBs to be the same value.
8466 sc->base_fw_ndsb = sc->igu_base_sb;
8469 elink_phy_probe(&sc->link_params);
8475 bnx2x_link_settings_supported(struct bnx2x_softc *sc, uint32_t switch_cfg)
8477 uint32_t cfg_size = 0;
8479 uint8_t port = SC_PORT(sc);
8481 /* aggregation of supported attributes of all external phys */
8482 sc->port.supported[0] = 0;
8483 sc->port.supported[1] = 0;
8485 switch (sc->link_params.num_phys) {
8487 sc->port.supported[0] =
8488 sc->link_params.phy[ELINK_INT_PHY].supported;
8492 sc->port.supported[0] =
8493 sc->link_params.phy[ELINK_EXT_PHY1].supported;
8497 if (sc->link_params.multi_phy_config &
8498 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
8499 sc->port.supported[1] =
8500 sc->link_params.phy[ELINK_EXT_PHY1].supported;
8501 sc->port.supported[0] =
8502 sc->link_params.phy[ELINK_EXT_PHY2].supported;
8504 sc->port.supported[0] =
8505 sc->link_params.phy[ELINK_EXT_PHY1].supported;
8506 sc->port.supported[1] =
8507 sc->link_params.phy[ELINK_EXT_PHY2].supported;
8513 if (!(sc->port.supported[0] || sc->port.supported[1])) {
8514 PMD_DRV_LOG(ERR, sc,
8515 "Invalid phy config in NVRAM (PHY1=0x%08x PHY2=0x%08x)",
8517 dev_info.port_hw_config
8518 [port].external_phy_config),
8520 dev_info.port_hw_config
8521 [port].external_phy_config2));
8526 sc->port.phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR);
8528 switch (switch_cfg) {
8529 case ELINK_SWITCH_CFG_1G:
8532 NIG_REG_SERDES0_CTRL_PHY_ADDR + port * 0x10);
8534 case ELINK_SWITCH_CFG_10G:
8537 NIG_REG_XGXS0_CTRL_PHY_ADDR + port * 0x18);
8540 PMD_DRV_LOG(ERR, sc,
8541 "Invalid switch config in"
8542 "link_config=0x%08x",
8543 sc->port.link_config[0]);
8548 PMD_DRV_LOG(INFO, sc, "PHY addr 0x%08x", sc->port.phy_addr);
8550 /* mask what we support according to speed_cap_mask per configuration */
8551 for (idx = 0; idx < cfg_size; idx++) {
8552 if (!(sc->link_params.speed_cap_mask[idx] &
8553 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) {
8554 sc->port.supported[idx] &=
8555 ~ELINK_SUPPORTED_10baseT_Half;
8558 if (!(sc->link_params.speed_cap_mask[idx] &
8559 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) {
8560 sc->port.supported[idx] &=
8561 ~ELINK_SUPPORTED_10baseT_Full;
8564 if (!(sc->link_params.speed_cap_mask[idx] &
8565 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) {
8566 sc->port.supported[idx] &=
8567 ~ELINK_SUPPORTED_100baseT_Half;
8570 if (!(sc->link_params.speed_cap_mask[idx] &
8571 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) {
8572 sc->port.supported[idx] &=
8573 ~ELINK_SUPPORTED_100baseT_Full;
8576 if (!(sc->link_params.speed_cap_mask[idx] &
8577 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) {
8578 sc->port.supported[idx] &=
8579 ~ELINK_SUPPORTED_1000baseT_Full;
8582 if (!(sc->link_params.speed_cap_mask[idx] &
8583 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) {
8584 sc->port.supported[idx] &=
8585 ~ELINK_SUPPORTED_2500baseX_Full;
8588 if (!(sc->link_params.speed_cap_mask[idx] &
8589 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
8590 sc->port.supported[idx] &=
8591 ~ELINK_SUPPORTED_10000baseT_Full;
8594 if (!(sc->link_params.speed_cap_mask[idx] &
8595 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) {
8596 sc->port.supported[idx] &=
8597 ~ELINK_SUPPORTED_20000baseKR2_Full;
8601 PMD_DRV_LOG(INFO, sc, "PHY supported 0=0x%08x 1=0x%08x",
8602 sc->port.supported[0], sc->port.supported[1]);
8605 static void bnx2x_link_settings_requested(struct bnx2x_softc *sc)
8607 uint32_t link_config;
8609 uint32_t cfg_size = 0;
8611 sc->port.advertising[0] = 0;
8612 sc->port.advertising[1] = 0;
8614 switch (sc->link_params.num_phys) {
8624 for (idx = 0; idx < cfg_size; idx++) {
8625 sc->link_params.req_duplex[idx] = DUPLEX_FULL;
8626 link_config = sc->port.link_config[idx];
8628 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
8629 case PORT_FEATURE_LINK_SPEED_AUTO:
8630 if (sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg) {
8631 sc->link_params.req_line_speed[idx] =
8632 ELINK_SPEED_AUTO_NEG;
8633 sc->port.advertising[idx] |=
8634 sc->port.supported[idx];
8635 if (sc->link_params.phy[ELINK_EXT_PHY1].type ==
8636 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833)
8637 sc->port.advertising[idx] |=
8638 (ELINK_SUPPORTED_100baseT_Half |
8639 ELINK_SUPPORTED_100baseT_Full);
8641 /* force 10G, no AN */
8642 sc->link_params.req_line_speed[idx] =
8644 sc->port.advertising[idx] |=
8645 (ADVERTISED_10000baseT_Full |
8651 case PORT_FEATURE_LINK_SPEED_10M_FULL:
8653 port.supported[idx] & ELINK_SUPPORTED_10baseT_Full)
8655 sc->link_params.req_line_speed[idx] =
8657 sc->port.advertising[idx] |=
8658 (ADVERTISED_10baseT_Full | ADVERTISED_TP);
8660 PMD_DRV_LOG(ERR, sc,
8661 "Invalid NVRAM config link_config=0x%08x "
8662 "speed_cap_mask=0x%08x",
8665 link_params.speed_cap_mask[idx]);
8670 case PORT_FEATURE_LINK_SPEED_10M_HALF:
8672 port.supported[idx] & ELINK_SUPPORTED_10baseT_Half)
8674 sc->link_params.req_line_speed[idx] =
8676 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
8677 sc->port.advertising[idx] |=
8678 (ADVERTISED_10baseT_Half | ADVERTISED_TP);
8680 PMD_DRV_LOG(ERR, sc,
8681 "Invalid NVRAM config link_config=0x%08x "
8682 "speed_cap_mask=0x%08x",
8685 link_params.speed_cap_mask[idx]);
8690 case PORT_FEATURE_LINK_SPEED_100M_FULL:
8692 port.supported[idx] & ELINK_SUPPORTED_100baseT_Full)
8694 sc->link_params.req_line_speed[idx] =
8696 sc->port.advertising[idx] |=
8697 (ADVERTISED_100baseT_Full | ADVERTISED_TP);
8699 PMD_DRV_LOG(ERR, sc,
8700 "Invalid NVRAM config link_config=0x%08x "
8701 "speed_cap_mask=0x%08x",
8704 link_params.speed_cap_mask[idx]);
8709 case PORT_FEATURE_LINK_SPEED_100M_HALF:
8711 port.supported[idx] & ELINK_SUPPORTED_100baseT_Half)
8713 sc->link_params.req_line_speed[idx] =
8715 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
8716 sc->port.advertising[idx] |=
8717 (ADVERTISED_100baseT_Half | ADVERTISED_TP);
8719 PMD_DRV_LOG(ERR, sc,
8720 "Invalid NVRAM config link_config=0x%08x "
8721 "speed_cap_mask=0x%08x",
8724 link_params.speed_cap_mask[idx]);
8729 case PORT_FEATURE_LINK_SPEED_1G:
8730 if (sc->port.supported[idx] &
8731 ELINK_SUPPORTED_1000baseT_Full) {
8732 sc->link_params.req_line_speed[idx] =
8734 sc->port.advertising[idx] |=
8735 (ADVERTISED_1000baseT_Full | ADVERTISED_TP);
8737 PMD_DRV_LOG(ERR, sc,
8738 "Invalid NVRAM config link_config=0x%08x "
8739 "speed_cap_mask=0x%08x",
8742 link_params.speed_cap_mask[idx]);
8747 case PORT_FEATURE_LINK_SPEED_2_5G:
8748 if (sc->port.supported[idx] &
8749 ELINK_SUPPORTED_2500baseX_Full) {
8750 sc->link_params.req_line_speed[idx] =
8752 sc->port.advertising[idx] |=
8753 (ADVERTISED_2500baseX_Full | ADVERTISED_TP);
8755 PMD_DRV_LOG(ERR, sc,
8756 "Invalid NVRAM config link_config=0x%08x "
8757 "speed_cap_mask=0x%08x",
8760 link_params.speed_cap_mask[idx]);
8765 case PORT_FEATURE_LINK_SPEED_10G_CX4:
8766 if (sc->port.supported[idx] &
8767 ELINK_SUPPORTED_10000baseT_Full) {
8768 sc->link_params.req_line_speed[idx] =
8770 sc->port.advertising[idx] |=
8771 (ADVERTISED_10000baseT_Full |
8774 PMD_DRV_LOG(ERR, sc,
8775 "Invalid NVRAM config link_config=0x%08x "
8776 "speed_cap_mask=0x%08x",
8779 link_params.speed_cap_mask[idx]);
8784 case PORT_FEATURE_LINK_SPEED_20G:
8785 sc->link_params.req_line_speed[idx] = ELINK_SPEED_20000;
8789 PMD_DRV_LOG(ERR, sc,
8790 "Invalid NVRAM config link_config=0x%08x "
8791 "speed_cap_mask=0x%08x", link_config,
8792 sc->link_params.speed_cap_mask[idx]);
8793 sc->link_params.req_line_speed[idx] =
8794 ELINK_SPEED_AUTO_NEG;
8795 sc->port.advertising[idx] = sc->port.supported[idx];
8799 sc->link_params.req_flow_ctrl[idx] =
8800 (link_config & PORT_FEATURE_FLOW_CONTROL_MASK);
8802 if (sc->link_params.req_flow_ctrl[idx] == ELINK_FLOW_CTRL_AUTO) {
8805 port.supported[idx] & ELINK_SUPPORTED_Autoneg)) {
8806 sc->link_params.req_flow_ctrl[idx] =
8807 ELINK_FLOW_CTRL_NONE;
8809 bnx2x_set_requested_fc(sc);
8815 static void bnx2x_get_phy_info(struct bnx2x_softc *sc)
8817 uint8_t port = SC_PORT(sc);
8820 PMD_INIT_FUNC_TRACE(sc);
8822 /* shmem data already read in bnx2x_get_shmem_info() */
8824 bnx2x_link_settings_supported(sc, sc->link_params.switch_cfg);
8825 bnx2x_link_settings_requested(sc);
8827 /* configure link feature according to nvram value */
8829 (((SHMEM_RD(sc, dev_info.port_feature_config[port].eee_power_mode))
8830 & PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
8831 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
8832 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
8833 sc->link_params.eee_mode = (ELINK_EEE_MODE_ADV_LPI |
8834 ELINK_EEE_MODE_ENABLE_LPI |
8835 ELINK_EEE_MODE_OUTPUT_TIME);
8837 sc->link_params.eee_mode = 0;
8840 /* get the media type */
8841 bnx2x_media_detect(sc);
8844 static void bnx2x_set_modes_bitmap(struct bnx2x_softc *sc)
8846 uint32_t flags = MODE_ASIC | MODE_PORT2;
8848 if (CHIP_IS_E2(sc)) {
8850 } else if (CHIP_IS_E3(sc)) {
8852 if (CHIP_REV(sc) == CHIP_REV_Ax) {
8853 flags |= MODE_E3_A0;
8854 } else { /*if (CHIP_REV(sc) == CHIP_REV_Bx) */
8856 flags |= MODE_E3_B0 | MODE_COS3;
8862 switch (sc->devinfo.mf_info.mf_mode) {
8863 case MULTI_FUNCTION_SD:
8864 flags |= MODE_MF_SD;
8866 case MULTI_FUNCTION_SI:
8867 flags |= MODE_MF_SI;
8869 case MULTI_FUNCTION_AFEX:
8870 flags |= MODE_MF_AFEX;
8877 #if defined(__LITTLE_ENDIAN)
8878 flags |= MODE_LITTLE_ENDIAN;
8879 #else /* __BIG_ENDIAN */
8880 flags |= MODE_BIG_ENDIAN;
8883 INIT_MODE_FLAGS(sc) = flags;
8886 int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
8888 struct bnx2x_fastpath *fp;
8893 /************************/
8894 /* DEFAULT STATUS BLOCK */
8895 /************************/
8897 if (bnx2x_dma_alloc(sc, sizeof(struct host_sp_status_block),
8898 &sc->def_sb_dma, "def_sb",
8899 RTE_CACHE_LINE_SIZE) != 0) {
8904 (struct host_sp_status_block *)sc->def_sb_dma.vaddr;
8909 if (bnx2x_dma_alloc(sc, BNX2X_PAGE_SIZE,
8910 &sc->eq_dma, "ev_queue",
8911 RTE_CACHE_LINE_SIZE) != 0) {
8916 sc->eq = (union event_ring_elem *)sc->eq_dma.vaddr;
8922 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_slowpath),
8924 RTE_CACHE_LINE_SIZE) != 0) {
8930 sc->sp = (struct bnx2x_slowpath *)sc->sp_dma.vaddr;
8932 /*******************/
8933 /* SLOW PATH QUEUE */
8934 /*******************/
8936 if (bnx2x_dma_alloc(sc, BNX2X_PAGE_SIZE,
8937 &sc->spq_dma, "sp_queue",
8938 RTE_CACHE_LINE_SIZE) != 0) {
8945 sc->spq = (struct eth_spe *)sc->spq_dma.vaddr;
8947 /***************************/
8948 /* FW DECOMPRESSION BUFFER */
8949 /***************************/
8951 if (bnx2x_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma,
8952 "fw_buf", RTE_CACHE_LINE_SIZE) != 0) {
8960 sc->gz_buf = (void *)sc->gz_buf_dma.vaddr;
8967 /* allocate DMA memory for each fastpath structure */
8968 for (i = 0; i < sc->num_queues; i++) {
8973 /*******************/
8974 /* FP STATUS BLOCK */
8975 /*******************/
8977 snprintf(buf, sizeof(buf), "fp_%d_sb", i);
8978 if (bnx2x_dma_alloc(sc, sizeof(union bnx2x_host_hc_status_block),
8979 &fp->sb_dma, buf, RTE_CACHE_LINE_SIZE) != 0) {
8980 PMD_DRV_LOG(NOTICE, sc, "Failed to alloc %s", buf);
8983 if (CHIP_IS_E2E3(sc)) {
8984 fp->status_block.e2_sb =
8985 (struct host_hc_status_block_e2 *)
8988 fp->status_block.e1x_sb =
8989 (struct host_hc_status_block_e1x *)
8998 void bnx2x_free_hsi_mem(struct bnx2x_softc *sc)
9000 struct bnx2x_fastpath *fp;
9003 for (i = 0; i < sc->num_queues; i++) {
9006 /*******************/
9007 /* FP STATUS BLOCK */
9008 /*******************/
9010 memset(&fp->status_block, 0, sizeof(fp->status_block));
9013 /***************************/
9014 /* FW DECOMPRESSION BUFFER */
9015 /***************************/
9019 /*******************/
9020 /* SLOW PATH QUEUE */
9021 /*******************/
9037 /************************/
9038 /* DEFAULT STATUS BLOCK */
9039 /************************/
9046 * Previous driver DMAE transaction may have occurred when pre-boot stage
9047 * ended and boot began. This would invalidate the addresses of the
9048 * transaction, resulting in was-error bit set in the PCI causing all
9049 * hw-to-host PCIe transactions to timeout. If this happened we want to clear
9050 * the interrupt which detected this from the pglueb and the was-done bit
9052 static void bnx2x_prev_interrupted_dmae(struct bnx2x_softc *sc)
9056 if (!CHIP_IS_E1x(sc)) {
9057 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS);
9058 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
9059 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
9065 static int bnx2x_prev_mcp_done(struct bnx2x_softc *sc)
9067 uint32_t rc = bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE,
9068 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
9070 PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
9077 static struct bnx2x_prev_list_node *bnx2x_prev_path_get_entry(struct bnx2x_softc *sc)
9079 struct bnx2x_prev_list_node *tmp;
9081 LIST_FOREACH(tmp, &bnx2x_prev_list, node) {
9082 if ((sc->pcie_bus == tmp->bus) &&
9083 (sc->pcie_device == tmp->slot) &&
9084 (SC_PATH(sc) == tmp->path)) {
9092 static uint8_t bnx2x_prev_is_path_marked(struct bnx2x_softc *sc)
9094 struct bnx2x_prev_list_node *tmp;
9097 rte_spinlock_lock(&bnx2x_prev_mtx);
9099 tmp = bnx2x_prev_path_get_entry(sc);
9102 PMD_DRV_LOG(DEBUG, sc,
9103 "Path %d/%d/%d was marked by AER",
9104 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
9107 PMD_DRV_LOG(DEBUG, sc,
9108 "Path %d/%d/%d was already cleaned from previous drivers",
9109 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
9113 rte_spinlock_unlock(&bnx2x_prev_mtx);
9118 static int bnx2x_prev_mark_path(struct bnx2x_softc *sc, uint8_t after_undi)
9120 struct bnx2x_prev_list_node *tmp;
9122 rte_spinlock_lock(&bnx2x_prev_mtx);
9124 /* Check whether the entry for this path already exists */
9125 tmp = bnx2x_prev_path_get_entry(sc);
9128 PMD_DRV_LOG(DEBUG, sc,
9129 "Re-marking AER in path %d/%d/%d",
9130 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
9132 PMD_DRV_LOG(DEBUG, sc,
9133 "Removing AER indication from path %d/%d/%d",
9134 sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
9138 rte_spinlock_unlock(&bnx2x_prev_mtx);
9142 rte_spinlock_unlock(&bnx2x_prev_mtx);
9144 /* Create an entry for this path and add it */
9145 tmp = rte_malloc("", sizeof(struct bnx2x_prev_list_node),
9146 RTE_CACHE_LINE_SIZE);
9148 PMD_DRV_LOG(NOTICE, sc, "Failed to allocate 'bnx2x_prev_list_node'");
9152 tmp->bus = sc->pcie_bus;
9153 tmp->slot = sc->pcie_device;
9154 tmp->path = SC_PATH(sc);
9156 tmp->undi = after_undi ? (1 << SC_PORT(sc)) : 0;
9158 rte_spinlock_lock(&bnx2x_prev_mtx);
9160 LIST_INSERT_HEAD(&bnx2x_prev_list, tmp, node);
9162 rte_spinlock_unlock(&bnx2x_prev_mtx);
9167 static int bnx2x_do_flr(struct bnx2x_softc *sc)
9171 /* only E2 and onwards support FLR */
9172 if (CHIP_IS_E1x(sc)) {
9173 PMD_DRV_LOG(WARNING, sc, "FLR not supported in E1H");
9177 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9178 if (sc->devinfo.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9179 PMD_DRV_LOG(WARNING, sc,
9180 "FLR not supported by BC_VER: 0x%08x",
9181 sc->devinfo.bc_ver);
9185 /* Wait for Transaction Pending bit clean */
9186 for (i = 0; i < 4; i++) {
9188 DELAY(((1 << (i - 1)) * 100) * 1000);
9191 if (!bnx2x_is_pcie_pending(sc)) {
9196 PMD_DRV_LOG(NOTICE, sc, "PCIE transaction is not cleared, "
9197 "proceeding with reset anyway");
9200 bnx2x_fw_command(sc, DRV_MSG_CODE_INITIATE_FLR, 0);
9205 struct bnx2x_mac_vals {
9213 uint32_t bmac_val[2];
9217 bnx2x_prev_unload_close_mac(struct bnx2x_softc *sc, struct bnx2x_mac_vals *vals)
9219 uint32_t val, base_addr, offset, mask, reset_reg;
9220 uint8_t mac_stopped = FALSE;
9221 uint8_t port = SC_PORT(sc);
9222 uint32_t wb_data[2];
9224 /* reset addresses as they also mark which values were changed */
9225 vals->bmac_addr = 0;
9226 vals->umac_addr = 0;
9227 vals->xmac_addr = 0;
9228 vals->emac_addr = 0;
9230 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_2);
9232 if (!CHIP_IS_E3(sc)) {
9233 val = REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9234 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9235 if ((mask & reset_reg) && val) {
9236 base_addr = SC_PORT(sc) ? NIG_REG_INGRESS_BMAC1_MEM
9237 : NIG_REG_INGRESS_BMAC0_MEM;
9238 offset = CHIP_IS_E2(sc) ? BIGMAC2_REGISTER_BMAC_CONTROL
9239 : BIGMAC_REGISTER_BMAC_CONTROL;
9242 * use rd/wr since we cannot use dmae. This is safe
9243 * since MCP won't access the bus due to the request
9244 * to unload, and no function on the path can be
9245 * loaded at this time.
9247 wb_data[0] = REG_RD(sc, base_addr + offset);
9248 wb_data[1] = REG_RD(sc, base_addr + offset + 0x4);
9249 vals->bmac_addr = base_addr + offset;
9250 vals->bmac_val[0] = wb_data[0];
9251 vals->bmac_val[1] = wb_data[1];
9252 wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE;
9253 REG_WR(sc, vals->bmac_addr, wb_data[0]);
9254 REG_WR(sc, vals->bmac_addr + 0x4, wb_data[1]);
9257 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + SC_PORT(sc) * 4;
9258 vals->emac_val = REG_RD(sc, vals->emac_addr);
9259 REG_WR(sc, vals->emac_addr, 0);
9262 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9263 base_addr = SC_PORT(sc) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9264 val = REG_RD(sc, base_addr + XMAC_REG_PFC_CTRL_HI);
9265 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI,
9267 REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI,
9269 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
9270 vals->xmac_val = REG_RD(sc, vals->xmac_addr);
9271 REG_WR(sc, vals->xmac_addr, 0);
9275 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9276 if (mask & reset_reg) {
9277 base_addr = SC_PORT(sc) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
9278 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
9279 vals->umac_val = REG_RD(sc, vals->umac_addr);
9280 REG_WR(sc, vals->umac_addr, 0);
9290 #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9291 #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9292 #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9293 #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9296 bnx2x_prev_unload_undi_inc(struct bnx2x_softc *sc, uint8_t port, uint8_t inc)
9299 uint32_t tmp_reg = REG_RD(sc, BNX2X_PREV_UNDI_PROD_ADDR(port));
9301 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9302 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9304 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9305 REG_WR(sc, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9308 static int bnx2x_prev_unload_common(struct bnx2x_softc *sc)
9310 uint32_t reset_reg, tmp_reg = 0, rc;
9311 uint8_t prev_undi = FALSE;
9312 struct bnx2x_mac_vals mac_vals;
9313 uint32_t timer_count = 1000;
9317 * It is possible a previous function received 'common' answer,
9318 * but hasn't loaded yet, therefore creating a scenario of
9319 * multiple functions receiving 'common' on the same path.
9321 memset(&mac_vals, 0, sizeof(mac_vals));
9323 if (bnx2x_prev_is_path_marked(sc)) {
9324 return bnx2x_prev_mcp_done(sc);
9327 reset_reg = REG_RD(sc, MISC_REG_RESET_REG_1);
9329 /* Reset should be performed after BRB is emptied */
9330 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
9331 /* Close the MAC Rx to prevent BRB from filling up */
9332 bnx2x_prev_unload_close_mac(sc, &mac_vals);
9334 /* close LLH filters towards the BRB */
9335 elink_set_rx_filter(&sc->link_params, 0);
9338 * Check if the UNDI driver was previously loaded.
9339 * UNDI driver initializes CID offset for normal bell to 0x7
9341 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
9342 tmp_reg = REG_RD(sc, DORQ_REG_NORM_CID_OFST);
9343 if (tmp_reg == 0x7) {
9344 PMD_DRV_LOG(DEBUG, sc, "UNDI previously loaded");
9346 /* clear the UNDI indication */
9347 REG_WR(sc, DORQ_REG_NORM_CID_OFST, 0);
9348 /* clear possible idle check errors */
9349 REG_RD(sc, NIG_REG_NIG_INT_STS_CLR_0);
9353 /* wait until BRB is empty */
9354 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
9355 while (timer_count) {
9358 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
9363 PMD_DRV_LOG(DEBUG, sc, "BRB still has 0x%08x", tmp_reg);
9365 /* reset timer as long as BRB actually gets emptied */
9366 if (prev_brb > tmp_reg) {
9372 /* If UNDI resides in memory, manually increment it */
9374 bnx2x_prev_unload_undi_inc(sc, SC_PORT(sc), 1);
9381 PMD_DRV_LOG(NOTICE, sc, "Failed to empty BRB");
9385 /* No packets are in the pipeline, path is ready for reset */
9386 bnx2x_reset_common(sc);
9388 if (mac_vals.xmac_addr) {
9389 REG_WR(sc, mac_vals.xmac_addr, mac_vals.xmac_val);
9391 if (mac_vals.umac_addr) {
9392 REG_WR(sc, mac_vals.umac_addr, mac_vals.umac_val);
9394 if (mac_vals.emac_addr) {
9395 REG_WR(sc, mac_vals.emac_addr, mac_vals.emac_val);
9397 if (mac_vals.bmac_addr) {
9398 REG_WR(sc, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
9399 REG_WR(sc, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
9402 rc = bnx2x_prev_mark_path(sc, prev_undi);
9404 bnx2x_prev_mcp_done(sc);
9408 return bnx2x_prev_mcp_done(sc);
9411 static int bnx2x_prev_unload_uncommon(struct bnx2x_softc *sc)
9415 /* Test if previous unload process was already finished for this path */
9416 if (bnx2x_prev_is_path_marked(sc)) {
9417 return bnx2x_prev_mcp_done(sc);
9421 * If function has FLR capabilities, and existing FW version matches
9422 * the one required, then FLR will be sufficient to clean any residue
9423 * left by previous driver
9425 rc = bnx2x_nic_load_analyze_req(sc, FW_MSG_CODE_DRV_LOAD_FUNCTION);
9427 /* fw version is good */
9428 rc = bnx2x_do_flr(sc);
9432 /* FLR was performed */
9436 PMD_DRV_LOG(INFO, sc, "Could not FLR");
9438 /* Close the MCP request, return failure */
9439 rc = bnx2x_prev_mcp_done(sc);
9441 rc = BNX2X_PREV_WAIT_NEEDED;
9447 static int bnx2x_prev_unload(struct bnx2x_softc *sc)
9449 int time_counter = 10;
9450 uint32_t fw, hw_lock_reg, hw_lock_val;
9453 PMD_INIT_FUNC_TRACE(sc);
9456 * Clear HW from errors which may have resulted from an interrupted
9459 bnx2x_prev_interrupted_dmae(sc);
9461 /* Release previously held locks */
9462 hw_lock_reg = (SC_FUNC(sc) <= 5) ?
9463 (MISC_REG_DRIVER_CONTROL_1 + SC_FUNC(sc) * 8) :
9464 (MISC_REG_DRIVER_CONTROL_7 + (SC_FUNC(sc) - 6) * 8);
9466 hw_lock_val = (REG_RD(sc, hw_lock_reg));
9468 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
9469 PMD_DRV_LOG(DEBUG, sc, "Releasing previously held NVRAM lock\n");
9470 REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
9471 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << SC_PORT(sc)));
9473 PMD_DRV_LOG(DEBUG, sc, "Releasing previously held HW lock\n");
9474 REG_WR(sc, hw_lock_reg, 0xffffffff);
9477 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(sc, MCP_REG_MCPR_ACCESS_LOCK)) {
9478 PMD_DRV_LOG(DEBUG, sc, "Releasing previously held ALR\n");
9479 REG_WR(sc, MCP_REG_MCPR_ACCESS_LOCK, 0);
9483 /* Lock MCP using an unload request */
9484 fw = bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
9486 PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
9491 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
9492 rc = bnx2x_prev_unload_common(sc);
9496 /* non-common reply from MCP might require looping */
9497 rc = bnx2x_prev_unload_uncommon(sc);
9498 if (rc != BNX2X_PREV_WAIT_NEEDED) {
9503 } while (--time_counter);
9505 if (!time_counter || rc) {
9506 PMD_DRV_LOG(NOTICE, sc, "Failed to unload previous driver!");
9514 bnx2x_dcbx_set_state(struct bnx2x_softc *sc, uint8_t dcb_on, uint32_t dcbx_enabled)
9516 if (!CHIP_IS_E1x(sc)) {
9517 sc->dcb_state = dcb_on;
9518 sc->dcbx_enabled = dcbx_enabled;
9520 sc->dcb_state = FALSE;
9521 sc->dcbx_enabled = BNX2X_DCBX_ENABLED_INVALID;
9523 PMD_DRV_LOG(DEBUG, sc,
9524 "DCB state [%s:%s]",
9525 dcb_on ? "ON" : "OFF",
9526 (dcbx_enabled == BNX2X_DCBX_ENABLED_OFF) ? "user-mode" :
9528 BNX2X_DCBX_ENABLED_ON_NEG_OFF) ? "on-chip static"
9530 BNX2X_DCBX_ENABLED_ON_NEG_ON) ?
9531 "on-chip with negotiation" : "invalid");
9534 static int bnx2x_set_qm_cid_count(struct bnx2x_softc *sc)
9536 int cid_count = BNX2X_L2_MAX_CID(sc);
9538 if (CNIC_SUPPORT(sc)) {
9539 cid_count += CNIC_CID_MAX;
9542 return roundup(cid_count, QM_CID_ROUND);
9545 static void bnx2x_init_multi_cos(struct bnx2x_softc *sc)
9549 uint32_t pri_map = 0;
9551 for (pri = 0; pri < BNX2X_MAX_PRIORITY; pri++) {
9552 cos = ((pri_map & (0xf << (pri * 4))) >> (pri * 4));
9553 if (cos < sc->max_cos) {
9554 sc->prio_to_cos[pri] = cos;
9556 PMD_DRV_LOG(WARNING, sc,
9557 "Invalid COS %d for priority %d "
9558 "(max COS is %d), setting to 0", cos, pri,
9560 sc->prio_to_cos[pri] = 0;
9565 static int bnx2x_pci_get_caps(struct bnx2x_softc *sc)
9572 struct bnx2x_pci_cap *cap;
9574 cap = sc->pci_caps = rte_zmalloc("caps", sizeof(struct bnx2x_pci_cap),
9575 RTE_CACHE_LINE_SIZE);
9577 PMD_DRV_LOG(NOTICE, sc, "Failed to allocate memory");
9582 pci_read(sc, PCI_STATUS, &status, 2);
9583 if (!(status & PCI_STATUS_CAP_LIST)) {
9585 pci_read(sc, PCIR_STATUS, &status, 2);
9586 if (!(status & PCIM_STATUS_CAPPRESENT)) {
9588 PMD_DRV_LOG(NOTICE, sc, "PCIe capability reading failed");
9593 pci_read(sc, PCI_CAPABILITY_LIST, &pci_cap.next, 1);
9595 pci_read(sc, PCIR_CAP_PTR, &pci_cap.next, 1);
9597 while (pci_cap.next) {
9598 cap->addr = pci_cap.next & ~3;
9599 pci_read(sc, pci_cap.next & ~3, &pci_cap, 2);
9600 if (pci_cap.id == 0xff)
9602 cap->id = pci_cap.id;
9603 cap->type = BNX2X_PCI_CAP;
9604 cap->next = rte_zmalloc("pci_cap",
9605 sizeof(struct bnx2x_pci_cap),
9606 RTE_CACHE_LINE_SIZE);
9608 PMD_DRV_LOG(NOTICE, sc, "Failed to allocate memory");
9617 static void bnx2x_init_rte(struct bnx2x_softc *sc)
9620 sc->max_tx_queues = min(BNX2X_VF_MAX_QUEUES_PER_VF,
9622 sc->max_rx_queues = min(BNX2X_VF_MAX_QUEUES_PER_VF,
9625 sc->max_rx_queues = BNX2X_MAX_RSS_COUNT(sc);
9626 sc->max_tx_queues = sc->max_rx_queues;
9630 #define FW_HEADER_LEN 104
9631 #define FW_NAME_57711 "/lib/firmware/bnx2x/bnx2x-e1h-7.2.51.0.fw"
9632 #define FW_NAME_57810 "/lib/firmware/bnx2x/bnx2x-e2-7.2.51.0.fw"
9634 void bnx2x_load_firmware(struct bnx2x_softc *sc)
9640 fwname = sc->devinfo.device_id == CHIP_NUM_57711
9641 ? FW_NAME_57711 : FW_NAME_57810;
9642 f = open(fwname, O_RDONLY);
9644 PMD_DRV_LOG(NOTICE, sc, "Can't open firmware file");
9648 if (fstat(f, &st) < 0) {
9649 PMD_DRV_LOG(NOTICE, sc, "Can't stat firmware file");
9654 sc->firmware = rte_zmalloc("bnx2x_fw", st.st_size, RTE_CACHE_LINE_SIZE);
9655 if (!sc->firmware) {
9656 PMD_DRV_LOG(NOTICE, sc, "Can't allocate memory for firmware");
9661 if (read(f, sc->firmware, st.st_size) != st.st_size) {
9662 PMD_DRV_LOG(NOTICE, sc, "Can't read firmware data");
9668 sc->fw_len = st.st_size;
9669 if (sc->fw_len < FW_HEADER_LEN) {
9670 PMD_DRV_LOG(NOTICE, sc,
9671 "Invalid fw size: %" PRIu64, sc->fw_len);
9674 PMD_DRV_LOG(DEBUG, sc, "fw_len = %" PRIu64, sc->fw_len);
9678 bnx2x_data_to_init_ops(uint8_t * data, struct raw_op *dst, uint32_t len)
9680 uint32_t *src = (uint32_t *) data;
9683 for (i = 0, j = 0; i < len / 8; ++i, j += 2) {
9684 tmp = rte_be_to_cpu_32(src[j]);
9685 dst[i].op = (tmp >> 24) & 0xFF;
9686 dst[i].offset = tmp & 0xFFFFFF;
9687 dst[i].raw_data = rte_be_to_cpu_32(src[j + 1]);
9692 bnx2x_data_to_init_offsets(uint8_t * data, uint16_t * dst, uint32_t len)
9694 uint16_t *src = (uint16_t *) data;
9697 for (i = 0; i < len / 2; ++i)
9698 dst[i] = rte_be_to_cpu_16(src[i]);
9701 static void bnx2x_data_to_init_data(uint8_t * data, uint32_t * dst, uint32_t len)
9703 uint32_t *src = (uint32_t *) data;
9706 for (i = 0; i < len / 4; ++i)
9707 dst[i] = rte_be_to_cpu_32(src[i]);
9710 static void bnx2x_data_to_iro_array(uint8_t * data, struct iro *dst, uint32_t len)
9712 uint32_t *src = (uint32_t *) data;
9715 for (i = 0, j = 0; i < len / sizeof(struct iro); ++i, ++j) {
9716 dst[i].base = rte_be_to_cpu_32(src[j++]);
9717 tmp = rte_be_to_cpu_32(src[j]);
9718 dst[i].m1 = (tmp >> 16) & 0xFFFF;
9719 dst[i].m2 = tmp & 0xFFFF;
9721 tmp = rte_be_to_cpu_32(src[j]);
9722 dst[i].m3 = (tmp >> 16) & 0xFFFF;
9723 dst[i].size = tmp & 0xFFFF;
9728 * Device attach function.
9730 * Allocates device resources, performs secondary chip identification, and
9731 * initializes driver instance variables. This function is called from driver
9732 * load after a successful probe.
9735 * 0 = Success, >0 = Failure
9737 int bnx2x_attach(struct bnx2x_softc *sc)
9741 PMD_DRV_LOG(DEBUG, sc, "Starting attach...");
9743 rc = bnx2x_pci_get_caps(sc);
9745 PMD_DRV_LOG(NOTICE, sc, "PCIe caps reading was failed");
9749 sc->state = BNX2X_STATE_CLOSED;
9751 pci_write_long(sc, PCICFG_GRC_ADDRESS, PCICFG_VENDOR_ID_OFFSET);
9753 sc->igu_base_addr = IS_VF(sc) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
9755 /* get PCI capabilites */
9756 bnx2x_probe_pci_caps(sc);
9758 if (sc->devinfo.pcie_msix_cap_reg != 0) {
9761 (sc->devinfo.pcie_msix_cap_reg + PCIR_MSIX_CTRL), &val,
9763 sc->igu_sb_cnt = (val & PCIM_MSIXCTRL_TABLE_SIZE) + 1;
9768 /* Init RTE stuff */
9772 /* Enable internal target-read (in case we are probed after PF
9773 * FLR). Must be done prior to any BAR read access. Only for
9776 if (!CHIP_IS_E1x(sc)) {
9777 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ,
9782 /* get device info and set params */
9783 if (bnx2x_get_device_info(sc) != 0) {
9784 PMD_DRV_LOG(NOTICE, sc, "getting device info");
9788 /* get phy settings from shmem and 'and' against admin settings */
9789 bnx2x_get_phy_info(sc);
9791 /* Left mac of VF unfilled, PF should set it for VF */
9792 memset(sc->link_params.mac_addr, 0, RTE_ETHER_ADDR_LEN);
9797 /* set the default MTU (changed via ifconfig) */
9798 sc->mtu = RTE_ETHER_MTU;
9800 bnx2x_set_modes_bitmap(sc);
9802 /* need to reset chip if UNDI was active */
9803 if (IS_PF(sc) && !BNX2X_NOMCP(sc)) {
9806 (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
9807 DRV_MSG_SEQ_NUMBER_MASK);
9808 PMD_DRV_LOG(DEBUG, sc, "prev unload fw_seq 0x%04x",
9810 bnx2x_prev_unload(sc);
9813 bnx2x_dcbx_set_state(sc, FALSE, BNX2X_DCBX_ENABLED_OFF);
9815 /* calculate qm_cid_count */
9816 sc->qm_cid_count = bnx2x_set_qm_cid_count(sc);
9819 bnx2x_init_multi_cos(sc);
9825 bnx2x_igu_ack_sb(struct bnx2x_softc *sc, uint8_t igu_sb_id, uint8_t segment,
9826 uint16_t index, uint8_t op, uint8_t update)
9828 uint32_t igu_addr = sc->igu_base_addr;
9829 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id) * 8;
9830 bnx2x_igu_ack_sb_gen(sc, segment, index, op, update, igu_addr);
9834 bnx2x_ack_sb(struct bnx2x_softc *sc, uint8_t igu_sb_id, uint8_t storm,
9835 uint16_t index, uint8_t op, uint8_t update)
9837 if (unlikely(sc->devinfo.int_block == INT_BLOCK_HC))
9838 bnx2x_hc_ack_sb(sc, igu_sb_id, storm, index, op, update);
9841 if (CHIP_INT_MODE_IS_BC(sc)) {
9843 } else if (igu_sb_id != sc->igu_dsb_id) {
9844 segment = IGU_SEG_ACCESS_DEF;
9845 } else if (storm == ATTENTION_ID) {
9846 segment = IGU_SEG_ACCESS_ATTN;
9848 segment = IGU_SEG_ACCESS_DEF;
9850 bnx2x_igu_ack_sb(sc, igu_sb_id, segment, index, op, update);
9855 bnx2x_igu_clear_sb_gen(struct bnx2x_softc *sc, uint8_t func, uint8_t idu_sb_id,
9858 uint32_t data, ctl, cnt = 100;
9859 uint32_t igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
9860 uint32_t igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
9861 uint32_t igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP +
9862 (idu_sb_id / 32) * 4;
9863 uint32_t sb_bit = 1 << (idu_sb_id % 32);
9864 uint32_t func_encode = func |
9865 (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
9866 uint32_t addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
9868 /* Not supported in BC mode */
9869 if (CHIP_INT_MODE_IS_BC(sc)) {
9873 data = ((IGU_USE_REGISTER_cstorm_type_0_sb_cleanup <<
9874 IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
9875 IGU_REGULAR_CLEANUP_SET | IGU_REGULAR_BCLEANUP);
9877 ctl = ((addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT) |
9878 (func_encode << IGU_CTRL_REG_FID_SHIFT) |
9879 (IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT));
9881 REG_WR(sc, igu_addr_data, data);
9885 PMD_DRV_LOG(DEBUG, sc, "write 0x%08x to IGU(via GRC) addr 0x%x",
9887 REG_WR(sc, igu_addr_ctl, ctl);
9891 /* wait for clean up to finish */
9892 while (!(REG_RD(sc, igu_addr_ack) & sb_bit) && --cnt) {
9896 if (!(REG_RD(sc, igu_addr_ack) & sb_bit)) {
9897 PMD_DRV_LOG(DEBUG, sc,
9898 "Unable to finish IGU cleanup: "
9899 "idu_sb_id %d offset %d bit %d (cnt %d)",
9900 idu_sb_id, idu_sb_id / 32, idu_sb_id % 32, cnt);
9904 static void bnx2x_igu_clear_sb(struct bnx2x_softc *sc, uint8_t idu_sb_id)
9906 bnx2x_igu_clear_sb_gen(sc, SC_FUNC(sc), idu_sb_id, TRUE /*PF*/);
9909 /*******************/
9910 /* ECORE CALLBACKS */
9911 /*******************/
9913 static void bnx2x_reset_common(struct bnx2x_softc *sc)
9915 uint32_t val = 0x1400;
9917 PMD_INIT_FUNC_TRACE(sc);
9920 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR),
9923 if (CHIP_IS_E3(sc)) {
9924 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
9925 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
9928 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR), val);
9931 static void bnx2x_common_init_phy(struct bnx2x_softc *sc)
9933 uint32_t shmem_base[2];
9934 uint32_t shmem2_base[2];
9936 /* Avoid common init in case MFW supports LFA */
9937 if (SHMEM2_RD(sc, size) >
9938 (uint32_t) offsetof(struct shmem2_region,
9939 lfa_host_addr[SC_PORT(sc)])) {
9943 shmem_base[0] = sc->devinfo.shmem_base;
9944 shmem2_base[0] = sc->devinfo.shmem2_base;
9946 if (!CHIP_IS_E1x(sc)) {
9947 shmem_base[1] = SHMEM2_RD(sc, other_shmem_base_addr);
9948 shmem2_base[1] = SHMEM2_RD(sc, other_shmem2_base_addr);
9951 bnx2x_acquire_phy_lock(sc);
9952 elink_common_init_phy(sc, shmem_base, shmem2_base,
9953 sc->devinfo.chip_id, 0);
9954 bnx2x_release_phy_lock(sc);
9957 static void bnx2x_pf_disable(struct bnx2x_softc *sc)
9959 uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
9961 val &= ~IGU_PF_CONF_FUNC_EN;
9963 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
9964 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
9965 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 0);
9968 static void bnx2x_init_pxp(struct bnx2x_softc *sc)
9971 int r_order, w_order;
9973 devctl = bnx2x_pcie_capability_read(sc, PCIR_EXPRESS_DEVICE_CTL);
9975 w_order = ((devctl & PCIM_EXP_CTL_MAX_PAYLOAD) >> 5);
9976 r_order = ((devctl & PCIM_EXP_CTL_MAX_READ_REQUEST) >> 12);
9978 ecore_init_pxp_arb(sc, r_order, w_order);
9981 static uint32_t bnx2x_get_pretend_reg(struct bnx2x_softc *sc)
9983 uint32_t base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9984 uint32_t stride = (PXP2_REG_PGL_PRETEND_FUNC_F1 - base);
9985 return base + (SC_ABS_FUNC(sc)) * stride;
9989 * Called only on E1H or E2.
9990 * When pretending to be PF, the pretend value is the function number 0..7.
9991 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
9994 static int bnx2x_pretend_func(struct bnx2x_softc *sc, uint16_t pretend_func_val)
9996 uint32_t pretend_reg;
9998 if (CHIP_IS_E1H(sc) && (pretend_func_val > E1H_FUNC_MAX))
10001 /* get my own pretend register */
10002 pretend_reg = bnx2x_get_pretend_reg(sc);
10003 REG_WR(sc, pretend_reg, pretend_func_val);
10004 REG_RD(sc, pretend_reg);
10008 static void bnx2x_setup_fan_failure_detection(struct bnx2x_softc *sc)
10015 val = (SHMEM_RD(sc, dev_info.shared_hw_config.config2) &
10016 SHARED_HW_CFG_FAN_FAILURE_MASK);
10018 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) {
10022 * The fan failure mechanism is usually related to the PHY type since
10023 * the power consumption of the board is affected by the PHY. Currently,
10024 * fan is required for most designs with SFX7101, BNX2X8727 and BNX2X8481.
10026 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) {
10027 for (port = PORT_0; port < PORT_MAX; port++) {
10028 is_required |= elink_fan_failure_det_req(sc,
10030 devinfo.shmem_base,
10032 devinfo.shmem2_base,
10037 if (is_required == 0) {
10041 /* Fan failure is indicated by SPIO 5 */
10042 bnx2x_set_spio(sc, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
10044 /* set to active low mode */
10045 val = REG_RD(sc, MISC_REG_SPIO_INT);
10046 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
10047 REG_WR(sc, MISC_REG_SPIO_INT, val);
10049 /* enable interrupt to signal the IGU */
10050 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
10051 val |= MISC_SPIO_SPIO5;
10052 REG_WR(sc, MISC_REG_SPIO_EVENT_EN, val);
10055 static void bnx2x_enable_blocks_attention(struct bnx2x_softc *sc)
10059 REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
10060 if (!CHIP_IS_E1x(sc)) {
10061 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0x40);
10063 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0);
10065 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
10066 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
10068 * mask read length error interrupts in brb for parser
10069 * (parsing unit and 'checksum and crc' unit)
10070 * these errors are legal (PU reads fixed length and CAC can cause
10071 * read length error on truncated packets)
10073 REG_WR(sc, BRB1_REG_BRB1_INT_MASK, 0xFC00);
10074 REG_WR(sc, QM_REG_QM_INT_MASK, 0);
10075 REG_WR(sc, TM_REG_TM_INT_MASK, 0);
10076 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_0, 0);
10077 REG_WR(sc, XSDM_REG_XSDM_INT_MASK_1, 0);
10078 REG_WR(sc, XCM_REG_XCM_INT_MASK, 0);
10079 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_0, 0); */
10080 /* REG_WR(sc, XSEM_REG_XSEM_INT_MASK_1, 0); */
10081 REG_WR(sc, USDM_REG_USDM_INT_MASK_0, 0);
10082 REG_WR(sc, USDM_REG_USDM_INT_MASK_1, 0);
10083 REG_WR(sc, UCM_REG_UCM_INT_MASK, 0);
10084 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_0, 0); */
10085 /* REG_WR(sc, USEM_REG_USEM_INT_MASK_1, 0); */
10086 REG_WR(sc, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
10087 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_0, 0);
10088 REG_WR(sc, CSDM_REG_CSDM_INT_MASK_1, 0);
10089 REG_WR(sc, CCM_REG_CCM_INT_MASK, 0);
10090 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_0, 0); */
10091 /* REG_WR(sc, CSEM_REG_CSEM_INT_MASK_1, 0); */
10093 val = (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
10094 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
10095 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN);
10096 if (!CHIP_IS_E1x(sc)) {
10097 val |= (PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
10098 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED);
10100 REG_WR(sc, PXP2_REG_PXP2_INT_MASK_0, val);
10102 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_0, 0);
10103 REG_WR(sc, TSDM_REG_TSDM_INT_MASK_1, 0);
10104 REG_WR(sc, TCM_REG_TCM_INT_MASK, 0);
10105 /* REG_WR(sc, TSEM_REG_TSEM_INT_MASK_0, 0); */
10107 if (!CHIP_IS_E1x(sc)) {
10108 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
10109 REG_WR(sc, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
10112 REG_WR(sc, CDU_REG_CDU_INT_MASK, 0);
10113 REG_WR(sc, DMAE_REG_DMAE_INT_MASK, 0);
10114 /* REG_WR(sc, MISC_REG_MISC_INT_MASK, 0); */
10115 REG_WR(sc, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
10119 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
10121 * @sc: driver handle
10123 static int bnx2x_init_hw_common(struct bnx2x_softc *sc)
10125 uint8_t abs_func_id;
10128 PMD_DRV_LOG(DEBUG, sc,
10129 "starting common init for func %d", SC_ABS_FUNC(sc));
10132 * take the RESET lock to protect undi_unload flow from accessing
10133 * registers while we are resetting the chip
10135 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
10137 bnx2x_reset_common(sc);
10139 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET), 0xffffffff);
10142 if (CHIP_IS_E3(sc)) {
10143 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
10144 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
10147 REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET), val);
10149 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
10151 ecore_init_block(sc, BLOCK_MISC, PHASE_COMMON);
10153 if (!CHIP_IS_E1x(sc)) {
10155 * 4-port mode or 2-port mode we need to turn off master-enable for
10156 * everyone. After that we turn it back on for self. So, we disregard
10157 * multi-function, and always disable all functions on the given path,
10158 * this means 0,2,4,6 for path 0 and 1,3,5,7 for path 1
10160 for (abs_func_id = SC_PATH(sc);
10161 abs_func_id < (E2_FUNC_MAX * 2); abs_func_id += 2) {
10162 if (abs_func_id == SC_ABS_FUNC(sc)) {
10164 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
10169 bnx2x_pretend_func(sc, abs_func_id);
10171 /* clear pf enable */
10172 bnx2x_pf_disable(sc);
10174 bnx2x_pretend_func(sc, SC_ABS_FUNC(sc));
10178 ecore_init_block(sc, BLOCK_PXP, PHASE_COMMON);
10180 ecore_init_block(sc, BLOCK_PXP2, PHASE_COMMON);
10181 bnx2x_init_pxp(sc);
10183 #ifdef __BIG_ENDIAN
10184 REG_WR(sc, PXP2_REG_RQ_QM_ENDIAN_M, 1);
10185 REG_WR(sc, PXP2_REG_RQ_TM_ENDIAN_M, 1);
10186 REG_WR(sc, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
10187 REG_WR(sc, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
10188 REG_WR(sc, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
10189 /* make sure this value is 0 */
10190 REG_WR(sc, PXP2_REG_RQ_HC_ENDIAN_M, 0);
10192 //REG_WR(sc, PXP2_REG_RD_PBF_SWAP_MODE, 1);
10193 REG_WR(sc, PXP2_REG_RD_QM_SWAP_MODE, 1);
10194 REG_WR(sc, PXP2_REG_RD_TM_SWAP_MODE, 1);
10195 REG_WR(sc, PXP2_REG_RD_SRC_SWAP_MODE, 1);
10196 REG_WR(sc, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
10199 ecore_ilt_init_page_size(sc, INITOP_SET);
10201 if (CHIP_REV_IS_FPGA(sc) && CHIP_IS_E1H(sc)) {
10202 REG_WR(sc, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
10205 /* let the HW do it's magic... */
10208 /* finish PXP init */
10210 val = REG_RD(sc, PXP2_REG_RQ_CFG_DONE);
10212 PMD_DRV_LOG(NOTICE, sc, "PXP2 CFG failed");
10215 val = REG_RD(sc, PXP2_REG_RD_INIT_DONE);
10217 PMD_DRV_LOG(NOTICE, sc, "PXP2 RD_INIT failed");
10222 * Timer bug workaround for E2 only. We need to set the entire ILT to have
10223 * entries with value "0" and valid bit on. This needs to be done by the
10224 * first PF that is loaded in a path (i.e. common phase)
10226 if (!CHIP_IS_E1x(sc)) {
10228 * In E2 there is a bug in the timers block that can cause function 6 / 7
10229 * (i.e. vnic3) to start even if it is marked as "scan-off".
10230 * This occurs when a different function (func2,3) is being marked
10231 * as "scan-off". Real-life scenario for example: if a driver is being
10232 * load-unloaded while func6,7 are down. This will cause the timer to access
10233 * the ilt, translate to a logical address and send a request to read/write.
10234 * Since the ilt for the function that is down is not valid, this will cause
10235 * a translation error which is unrecoverable.
10236 * The Workaround is intended to make sure that when this happens nothing
10237 * fatal will occur. The workaround:
10238 * 1. First PF driver which loads on a path will:
10239 * a. After taking the chip out of reset, by using pretend,
10240 * it will write "0" to the following registers of
10242 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
10243 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
10244 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
10245 * And for itself it will write '1' to
10246 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
10247 * dmae-operations (writing to pram for example.)
10248 * note: can be done for only function 6,7 but cleaner this
10250 * b. Write zero+valid to the entire ILT.
10251 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
10252 * VNIC3 (of that port). The range allocated will be the
10253 * entire ILT. This is needed to prevent ILT range error.
10254 * 2. Any PF driver load flow:
10255 * a. ILT update with the physical addresses of the allocated
10257 * b. Wait 20msec. - note that this timeout is needed to make
10258 * sure there are no requests in one of the PXP internal
10259 * queues with "old" ILT addresses.
10260 * c. PF enable in the PGLC.
10261 * d. Clear the was_error of the PF in the PGLC. (could have
10262 * occurred while driver was down)
10263 * e. PF enable in the CFC (WEAK + STRONG)
10264 * f. Timers scan enable
10265 * 3. PF driver unload flow:
10266 * a. Clear the Timers scan_en.
10267 * b. Polling for scan_on=0 for that PF.
10268 * c. Clear the PF enable bit in the PXP.
10269 * d. Clear the PF enable in the CFC (WEAK + STRONG)
10270 * e. Write zero+valid to all ILT entries (The valid bit must
10272 * f. If this is VNIC 3 of a port then also init
10273 * first_timers_ilt_entry to zero and last_timers_ilt_entry
10274 * to the last enrty in the ILT.
10277 * Currently the PF error in the PGLC is non recoverable.
10278 * In the future the there will be a recovery routine for this error.
10279 * Currently attention is masked.
10280 * Having an MCP lock on the load/unload process does not guarantee that
10281 * there is no Timer disable during Func6/7 enable. This is because the
10282 * Timers scan is currently being cleared by the MCP on FLR.
10283 * Step 2.d can be done only for PF6/7 and the driver can also check if
10284 * there is error before clearing it. But the flow above is simpler and
10286 * All ILT entries are written by zero+valid and not just PF6/7
10287 * ILT entries since in the future the ILT entries allocation for
10288 * PF-s might be dynamic.
10290 struct ilt_client_info ilt_cli;
10291 struct ecore_ilt ilt;
10293 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
10294 memset(&ilt, 0, sizeof(struct ecore_ilt));
10296 /* initialize dummy TM client */
10298 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
10299 ilt_cli.client_num = ILT_CLIENT_TM;
10302 * Step 1: set zeroes to all ilt page entries with valid bit on
10303 * Step 2: set the timers first/last ilt entry to point
10304 * to the entire range to prevent ILT range error for 3rd/4th
10305 * vnic (this code assumes existence of the vnic)
10307 * both steps performed by call to ecore_ilt_client_init_op()
10308 * with dummy TM client
10310 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
10311 * and his brother are split registers
10314 bnx2x_pretend_func(sc, (SC_PATH(sc) + 6));
10315 ecore_ilt_client_init_op_ilt(sc, &ilt, &ilt_cli, INITOP_CLEAR);
10316 bnx2x_pretend_func(sc, SC_ABS_FUNC(sc));
10318 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
10319 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
10320 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
10323 REG_WR(sc, PXP2_REG_RQ_DISABLE_INPUTS, 0);
10324 REG_WR(sc, PXP2_REG_RD_DISABLE_INPUTS, 0);
10326 if (!CHIP_IS_E1x(sc)) {
10329 ecore_init_block(sc, BLOCK_PGLUE_B, PHASE_COMMON);
10330 ecore_init_block(sc, BLOCK_ATC, PHASE_COMMON);
10332 /* let the HW do it's magic... */
10335 val = REG_RD(sc, ATC_REG_ATC_INIT_DONE);
10336 } while (factor-- && (val != 1));
10339 PMD_DRV_LOG(NOTICE, sc, "ATC_INIT failed");
10344 ecore_init_block(sc, BLOCK_DMAE, PHASE_COMMON);
10346 /* clean the DMAE memory */
10347 sc->dmae_ready = 1;
10348 ecore_init_fill(sc, TSEM_REG_PRAM, 0, 8);
10350 ecore_init_block(sc, BLOCK_TCM, PHASE_COMMON);
10352 ecore_init_block(sc, BLOCK_UCM, PHASE_COMMON);
10354 ecore_init_block(sc, BLOCK_CCM, PHASE_COMMON);
10356 ecore_init_block(sc, BLOCK_XCM, PHASE_COMMON);
10358 bnx2x_read_dmae(sc, XSEM_REG_PASSIVE_BUFFER, 3);
10359 bnx2x_read_dmae(sc, CSEM_REG_PASSIVE_BUFFER, 3);
10360 bnx2x_read_dmae(sc, TSEM_REG_PASSIVE_BUFFER, 3);
10361 bnx2x_read_dmae(sc, USEM_REG_PASSIVE_BUFFER, 3);
10363 ecore_init_block(sc, BLOCK_QM, PHASE_COMMON);
10365 /* QM queues pointers table */
10366 ecore_qm_init_ptr_table(sc, sc->qm_cid_count, INITOP_SET);
10368 /* soft reset pulse */
10369 REG_WR(sc, QM_REG_SOFT_RESET, 1);
10370 REG_WR(sc, QM_REG_SOFT_RESET, 0);
10372 if (CNIC_SUPPORT(sc))
10373 ecore_init_block(sc, BLOCK_TM, PHASE_COMMON);
10375 ecore_init_block(sc, BLOCK_DORQ, PHASE_COMMON);
10376 REG_WR(sc, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
10378 if (!CHIP_REV_IS_SLOW(sc)) {
10379 /* enable hw interrupt from doorbell Q */
10380 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
10383 ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
10385 ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
10386 REG_WR(sc, PRS_REG_A_PRSU_20, 0xf);
10387 REG_WR(sc, PRS_REG_E1HOV_MODE, sc->devinfo.mf_info.path_has_ovlan);
10389 if (!CHIP_IS_E1x(sc) && !CHIP_IS_E3B0(sc)) {
10390 if (IS_MF_AFEX(sc)) {
10392 * configure that AFEX and VLAN headers must be
10393 * received in AFEX mode
10395 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 0xE);
10396 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS, 0xA);
10397 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
10398 REG_WR(sc, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
10399 REG_WR(sc, PRS_REG_TAG_LEN_0, 0x4);
10402 * Bit-map indicating which L2 hdrs may appear
10403 * after the basic Ethernet header
10405 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC,
10406 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
10410 ecore_init_block(sc, BLOCK_TSDM, PHASE_COMMON);
10411 ecore_init_block(sc, BLOCK_CSDM, PHASE_COMMON);
10412 ecore_init_block(sc, BLOCK_USDM, PHASE_COMMON);
10413 ecore_init_block(sc, BLOCK_XSDM, PHASE_COMMON);
10415 if (!CHIP_IS_E1x(sc)) {
10416 /* reset VFC memories */
10417 REG_WR(sc, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
10418 VFC_MEMORIES_RST_REG_CAM_RST |
10419 VFC_MEMORIES_RST_REG_RAM_RST);
10420 REG_WR(sc, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
10421 VFC_MEMORIES_RST_REG_CAM_RST |
10422 VFC_MEMORIES_RST_REG_RAM_RST);
10427 ecore_init_block(sc, BLOCK_TSEM, PHASE_COMMON);
10428 ecore_init_block(sc, BLOCK_USEM, PHASE_COMMON);
10429 ecore_init_block(sc, BLOCK_CSEM, PHASE_COMMON);
10430 ecore_init_block(sc, BLOCK_XSEM, PHASE_COMMON);
10432 /* sync semi rtc */
10433 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x80000000);
10434 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x80000000);
10436 ecore_init_block(sc, BLOCK_UPB, PHASE_COMMON);
10437 ecore_init_block(sc, BLOCK_XPB, PHASE_COMMON);
10438 ecore_init_block(sc, BLOCK_PBF, PHASE_COMMON);
10440 if (!CHIP_IS_E1x(sc)) {
10441 if (IS_MF_AFEX(sc)) {
10443 * configure that AFEX and VLAN headers must be
10444 * sent in AFEX mode
10446 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 0xE);
10447 REG_WR(sc, PBF_REG_MUST_HAVE_HDRS, 0xA);
10448 REG_WR(sc, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
10449 REG_WR(sc, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
10450 REG_WR(sc, PBF_REG_TAG_LEN_0, 0x4);
10452 REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC,
10453 sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
10457 REG_WR(sc, SRC_REG_SOFT_RST, 1);
10459 ecore_init_block(sc, BLOCK_SRC, PHASE_COMMON);
10461 if (CNIC_SUPPORT(sc)) {
10462 REG_WR(sc, SRC_REG_KEYSEARCH_0, 0x63285672);
10463 REG_WR(sc, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
10464 REG_WR(sc, SRC_REG_KEYSEARCH_2, 0x223aef9b);
10465 REG_WR(sc, SRC_REG_KEYSEARCH_3, 0x26001e3a);
10466 REG_WR(sc, SRC_REG_KEYSEARCH_4, 0x7ae91116);
10467 REG_WR(sc, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
10468 REG_WR(sc, SRC_REG_KEYSEARCH_6, 0x298d8adf);
10469 REG_WR(sc, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
10470 REG_WR(sc, SRC_REG_KEYSEARCH_8, 0x1830f82f);
10471 REG_WR(sc, SRC_REG_KEYSEARCH_9, 0x01e46be7);
10473 REG_WR(sc, SRC_REG_SOFT_RST, 0);
10475 if (sizeof(union cdu_context) != 1024) {
10476 /* we currently assume that a context is 1024 bytes */
10477 PMD_DRV_LOG(NOTICE, sc,
10478 "please adjust the size of cdu_context(%ld)",
10479 (long)sizeof(union cdu_context));
10482 ecore_init_block(sc, BLOCK_CDU, PHASE_COMMON);
10483 val = (4 << 24) + (0 << 12) + 1024;
10484 REG_WR(sc, CDU_REG_CDU_GLOBAL_PARAMS, val);
10486 ecore_init_block(sc, BLOCK_CFC, PHASE_COMMON);
10488 REG_WR(sc, CFC_REG_INIT_REG, 0x7FF);
10489 /* enable context validation interrupt from CFC */
10490 REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
10492 /* set the thresholds to prevent CFC/CDU race */
10493 REG_WR(sc, CFC_REG_DEBUG0, 0x20020000);
10494 ecore_init_block(sc, BLOCK_HC, PHASE_COMMON);
10496 if (!CHIP_IS_E1x(sc) && BNX2X_NOMCP(sc)) {
10497 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x36);
10500 ecore_init_block(sc, BLOCK_IGU, PHASE_COMMON);
10501 ecore_init_block(sc, BLOCK_MISC_AEU, PHASE_COMMON);
10503 /* Reset PCIE errors for debug */
10504 REG_WR(sc, 0x2814, 0xffffffff);
10505 REG_WR(sc, 0x3820, 0xffffffff);
10507 if (!CHIP_IS_E1x(sc)) {
10508 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
10509 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
10510 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
10511 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
10512 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
10513 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
10514 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
10515 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
10516 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
10517 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
10518 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
10521 ecore_init_block(sc, BLOCK_NIG, PHASE_COMMON);
10523 /* in E3 this done in per-port section */
10524 if (!CHIP_IS_E3(sc))
10525 REG_WR(sc, NIG_REG_LLH_MF_MODE, IS_MF(sc));
10527 if (CHIP_IS_E1H(sc)) {
10528 /* not applicable for E2 (and above ...) */
10529 REG_WR(sc, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(sc));
10532 if (CHIP_REV_IS_SLOW(sc)) {
10536 /* finish CFC init */
10537 val = reg_poll(sc, CFC_REG_LL_INIT_DONE, 1, 100, 10);
10539 PMD_DRV_LOG(NOTICE, sc, "CFC LL_INIT failed");
10542 val = reg_poll(sc, CFC_REG_AC_INIT_DONE, 1, 100, 10);
10544 PMD_DRV_LOG(NOTICE, sc, "CFC AC_INIT failed");
10547 val = reg_poll(sc, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
10549 PMD_DRV_LOG(NOTICE, sc, "CFC CAM_INIT failed");
10552 REG_WR(sc, CFC_REG_DEBUG0, 0);
10554 bnx2x_setup_fan_failure_detection(sc);
10556 /* clear PXP2 attentions */
10557 REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
10559 bnx2x_enable_blocks_attention(sc);
10561 if (!CHIP_REV_IS_SLOW(sc)) {
10562 ecore_enable_blocks_parity(sc);
10565 if (!BNX2X_NOMCP(sc)) {
10566 if (CHIP_IS_E1x(sc)) {
10567 bnx2x_common_init_phy(sc);
10575 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
10577 * @sc: driver handle
10579 static int bnx2x_init_hw_common_chip(struct bnx2x_softc *sc)
10581 int rc = bnx2x_init_hw_common(sc);
10587 /* In E2 2-PORT mode, same ext phy is used for the two paths */
10588 if (!BNX2X_NOMCP(sc)) {
10589 bnx2x_common_init_phy(sc);
10595 static int bnx2x_init_hw_port(struct bnx2x_softc *sc)
10597 int port = SC_PORT(sc);
10598 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
10599 uint32_t low, high;
10602 PMD_DRV_LOG(DEBUG, sc, "starting port init for port %d", port);
10604 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4, 0);
10606 ecore_init_block(sc, BLOCK_MISC, init_phase);
10607 ecore_init_block(sc, BLOCK_PXP, init_phase);
10608 ecore_init_block(sc, BLOCK_PXP2, init_phase);
10611 * Timers bug workaround: disables the pf_master bit in pglue at
10612 * common phase, we need to enable it here before any dmae access are
10613 * attempted. Therefore we manually added the enable-master to the
10614 * port phase (it also happens in the function phase)
10616 if (!CHIP_IS_E1x(sc)) {
10617 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
10620 ecore_init_block(sc, BLOCK_ATC, init_phase);
10621 ecore_init_block(sc, BLOCK_DMAE, init_phase);
10622 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
10623 ecore_init_block(sc, BLOCK_QM, init_phase);
10625 ecore_init_block(sc, BLOCK_TCM, init_phase);
10626 ecore_init_block(sc, BLOCK_UCM, init_phase);
10627 ecore_init_block(sc, BLOCK_CCM, init_phase);
10628 ecore_init_block(sc, BLOCK_XCM, init_phase);
10630 /* QM cid (connection) count */
10631 ecore_qm_init_cid_count(sc, sc->qm_cid_count, INITOP_SET);
10633 if (CNIC_SUPPORT(sc)) {
10634 ecore_init_block(sc, BLOCK_TM, init_phase);
10635 REG_WR(sc, TM_REG_LIN0_SCAN_TIME + port * 4, 20);
10636 REG_WR(sc, TM_REG_LIN0_MAX_ACTIVE_CID + port * 4, 31);
10639 ecore_init_block(sc, BLOCK_DORQ, init_phase);
10641 ecore_init_block(sc, BLOCK_BRB1, init_phase);
10643 if (CHIP_IS_E1H(sc)) {
10645 low = (BNX2X_ONE_PORT(sc) ? 160 : 246);
10646 } else if (sc->mtu > 4096) {
10647 if (BNX2X_ONE_PORT(sc)) {
10651 /* (24*1024 + val*4)/256 */
10652 low = (96 + (val / 64) + ((val % 64) ? 1 : 0));
10655 low = (BNX2X_ONE_PORT(sc) ? 80 : 160);
10657 high = (low + 56); /* 14*1024/256 */
10658 REG_WR(sc, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port * 4, low);
10659 REG_WR(sc, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port * 4, high);
10662 if (CHIP_IS_MODE_4_PORT(sc)) {
10663 REG_WR(sc, SC_PORT(sc) ?
10664 BRB1_REG_MAC_GUARANTIED_1 :
10665 BRB1_REG_MAC_GUARANTIED_0, 40);
10668 ecore_init_block(sc, BLOCK_PRS, init_phase);
10669 if (CHIP_IS_E3B0(sc)) {
10670 if (IS_MF_AFEX(sc)) {
10671 /* configure headers for AFEX mode */
10673 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC_PORT_1,
10675 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0_PORT_1,
10677 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS_PORT_1, 0xA);
10679 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC_PORT_0,
10681 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0_PORT_0,
10683 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
10686 /* Ovlan exists only if we are in multi-function +
10687 * switch-dependent mode, in switch-independent there
10688 * is no ovlan headers
10690 REG_WR(sc, SC_PORT(sc) ?
10691 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
10692 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
10693 (sc->devinfo.mf_info.path_has_ovlan ? 7 : 6));
10697 ecore_init_block(sc, BLOCK_TSDM, init_phase);
10698 ecore_init_block(sc, BLOCK_CSDM, init_phase);
10699 ecore_init_block(sc, BLOCK_USDM, init_phase);
10700 ecore_init_block(sc, BLOCK_XSDM, init_phase);
10702 ecore_init_block(sc, BLOCK_TSEM, init_phase);
10703 ecore_init_block(sc, BLOCK_USEM, init_phase);
10704 ecore_init_block(sc, BLOCK_CSEM, init_phase);
10705 ecore_init_block(sc, BLOCK_XSEM, init_phase);
10707 ecore_init_block(sc, BLOCK_UPB, init_phase);
10708 ecore_init_block(sc, BLOCK_XPB, init_phase);
10710 ecore_init_block(sc, BLOCK_PBF, init_phase);
10712 if (CHIP_IS_E1x(sc)) {
10713 /* configure PBF to work without PAUSE mtu 9000 */
10714 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port * 4, 0);
10716 /* update threshold */
10717 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port * 4, (9040 / 16));
10718 /* update init credit */
10719 REG_WR(sc, PBF_REG_P0_INIT_CRD + port * 4,
10720 (9040 / 16) + 553 - 22);
10722 /* probe changes */
10723 REG_WR(sc, PBF_REG_INIT_P0 + port * 4, 1);
10725 REG_WR(sc, PBF_REG_INIT_P0 + port * 4, 0);
10728 if (CNIC_SUPPORT(sc)) {
10729 ecore_init_block(sc, BLOCK_SRC, init_phase);
10732 ecore_init_block(sc, BLOCK_CDU, init_phase);
10733 ecore_init_block(sc, BLOCK_CFC, init_phase);
10734 ecore_init_block(sc, BLOCK_HC, init_phase);
10735 ecore_init_block(sc, BLOCK_IGU, init_phase);
10736 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
10737 /* init aeu_mask_attn_func_0/1:
10738 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
10739 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
10740 * bits 4-7 are used for "per vn group attention" */
10741 val = IS_MF(sc) ? 0xF7 : 0x7;
10743 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port * 4, val);
10745 ecore_init_block(sc, BLOCK_NIG, init_phase);
10747 if (!CHIP_IS_E1x(sc)) {
10748 /* Bit-map indicating which L2 hdrs may appear after the
10749 * basic Ethernet header
10751 if (IS_MF_AFEX(sc)) {
10752 REG_WR(sc, SC_PORT(sc) ?
10753 NIG_REG_P1_HDRS_AFTER_BASIC :
10754 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
10756 REG_WR(sc, SC_PORT(sc) ?
10757 NIG_REG_P1_HDRS_AFTER_BASIC :
10758 NIG_REG_P0_HDRS_AFTER_BASIC,
10759 IS_MF_SD(sc) ? 7 : 6);
10762 if (CHIP_IS_E3(sc)) {
10763 REG_WR(sc, SC_PORT(sc) ?
10764 NIG_REG_LLH1_MF_MODE :
10765 NIG_REG_LLH_MF_MODE, IS_MF(sc));
10768 if (!CHIP_IS_E3(sc)) {
10769 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port * 4, 1);
10772 /* 0x2 disable mf_ov, 0x1 enable */
10773 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port * 4,
10774 (IS_MF_SD(sc) ? 0x1 : 0x2));
10776 if (!CHIP_IS_E1x(sc)) {
10778 switch (sc->devinfo.mf_info.mf_mode) {
10779 case MULTI_FUNCTION_SD:
10782 case MULTI_FUNCTION_SI:
10783 case MULTI_FUNCTION_AFEX:
10788 REG_WR(sc, (SC_PORT(sc) ? NIG_REG_LLH1_CLS_TYPE :
10789 NIG_REG_LLH0_CLS_TYPE), val);
10791 REG_WR(sc, NIG_REG_LLFC_ENABLE_0 + port * 4, 0);
10792 REG_WR(sc, NIG_REG_LLFC_OUT_EN_0 + port * 4, 0);
10793 REG_WR(sc, NIG_REG_PAUSE_ENABLE_0 + port * 4, 1);
10795 /* If SPIO5 is set to generate interrupts, enable it for this port */
10796 val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
10797 if (val & MISC_SPIO_SPIO5) {
10798 uint32_t reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
10799 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
10800 val = REG_RD(sc, reg_addr);
10801 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
10802 REG_WR(sc, reg_addr, val);
10809 bnx2x_flr_clnup_reg_poll(struct bnx2x_softc *sc, uint32_t reg,
10810 uint32_t expected, uint32_t poll_count)
10812 uint32_t cur_cnt = poll_count;
10815 while ((val = REG_RD(sc, reg)) != expected && cur_cnt--) {
10816 DELAY(FLR_WAIT_INTERVAL);
10823 bnx2x_flr_clnup_poll_hw_counter(struct bnx2x_softc *sc, uint32_t reg,
10824 __rte_unused const char *msg, uint32_t poll_cnt)
10826 uint32_t val = bnx2x_flr_clnup_reg_poll(sc, reg, 0, poll_cnt);
10829 PMD_DRV_LOG(NOTICE, sc, "%s usage count=%d", msg, val);
10836 /* Common routines with VF FLR cleanup */
10837 static uint32_t bnx2x_flr_clnup_poll_count(struct bnx2x_softc *sc)
10839 /* adjust polling timeout */
10840 if (CHIP_REV_IS_EMUL(sc)) {
10841 return FLR_POLL_CNT * 2000;
10844 if (CHIP_REV_IS_FPGA(sc)) {
10845 return FLR_POLL_CNT * 120;
10848 return FLR_POLL_CNT;
10851 static int bnx2x_poll_hw_usage_counters(struct bnx2x_softc *sc, uint32_t poll_cnt)
10853 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
10854 if (bnx2x_flr_clnup_poll_hw_counter(sc,
10855 CFC_REG_NUM_LCIDS_INSIDE_PF,
10856 "CFC PF usage counter timed out",
10861 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
10862 if (bnx2x_flr_clnup_poll_hw_counter(sc,
10863 DORQ_REG_PF_USAGE_CNT,
10864 "DQ PF usage counter timed out",
10869 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
10870 if (bnx2x_flr_clnup_poll_hw_counter(sc,
10871 QM_REG_PF_USG_CNT_0 + 4 * SC_FUNC(sc),
10872 "QM PF usage counter timed out",
10877 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
10878 if (bnx2x_flr_clnup_poll_hw_counter(sc,
10879 TM_REG_LIN0_VNIC_UC + 4 * SC_PORT(sc),
10880 "Timers VNIC usage counter timed out",
10885 if (bnx2x_flr_clnup_poll_hw_counter(sc,
10886 TM_REG_LIN0_NUM_SCANS +
10888 "Timers NUM_SCANS usage counter timed out",
10893 /* Wait DMAE PF usage counter to zero */
10894 if (bnx2x_flr_clnup_poll_hw_counter(sc,
10895 dmae_reg_go_c[INIT_DMAE_C(sc)],
10896 "DMAE dommand register timed out",
10904 #define OP_GEN_PARAM(param) \
10905 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
10906 #define OP_GEN_TYPE(type) \
10907 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
10908 #define OP_GEN_AGG_VECT(index) \
10909 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
10912 bnx2x_send_final_clnup(struct bnx2x_softc *sc, uint8_t clnup_func,
10915 uint32_t op_gen_command = 0;
10916 uint32_t comp_addr = (BAR_CSTRORM_INTMEM +
10917 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func));
10920 if (REG_RD(sc, comp_addr)) {
10921 PMD_DRV_LOG(NOTICE, sc,
10922 "Cleanup complete was not 0 before sending");
10926 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
10927 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
10928 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
10929 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
10931 REG_WR(sc, XSDM_REG_OPERATION_GEN, op_gen_command);
10933 if (bnx2x_flr_clnup_reg_poll(sc, comp_addr, 1, poll_cnt) != 1) {
10934 PMD_DRV_LOG(NOTICE, sc, "FW final cleanup did not succeed");
10935 PMD_DRV_LOG(DEBUG, sc, "At timeout completion address contained %x",
10936 (REG_RD(sc, comp_addr)));
10937 rte_panic("FLR cleanup failed");
10941 /* Zero completion for nxt FLR */
10942 REG_WR(sc, comp_addr, 0);
10948 bnx2x_pbf_pN_buf_flushed(struct bnx2x_softc *sc, struct pbf_pN_buf_regs *regs,
10949 uint32_t poll_count)
10951 uint32_t init_crd, crd, crd_start, crd_freed, crd_freed_start;
10952 uint32_t cur_cnt = poll_count;
10954 crd_freed = crd_freed_start = REG_RD(sc, regs->crd_freed);
10955 crd = crd_start = REG_RD(sc, regs->crd);
10956 init_crd = REG_RD(sc, regs->init_crd);
10958 while ((crd != init_crd) &&
10959 ((uint32_t) ((int32_t) crd_freed - (int32_t) crd_freed_start) <
10960 (init_crd - crd_start))) {
10962 DELAY(FLR_WAIT_INTERVAL);
10963 crd = REG_RD(sc, regs->crd);
10964 crd_freed = REG_RD(sc, regs->crd_freed);
10972 bnx2x_pbf_pN_cmd_flushed(struct bnx2x_softc *sc, struct pbf_pN_cmd_regs *regs,
10973 uint32_t poll_count)
10975 uint32_t occup, to_free, freed, freed_start;
10976 uint32_t cur_cnt = poll_count;
10978 occup = to_free = REG_RD(sc, regs->lines_occup);
10979 freed = freed_start = REG_RD(sc, regs->lines_freed);
10982 ((uint32_t) ((int32_t) freed - (int32_t) freed_start) <
10985 DELAY(FLR_WAIT_INTERVAL);
10986 occup = REG_RD(sc, regs->lines_occup);
10987 freed = REG_RD(sc, regs->lines_freed);
10994 static void bnx2x_tx_hw_flushed(struct bnx2x_softc *sc, uint32_t poll_count)
10996 struct pbf_pN_cmd_regs cmd_regs[] = {
10997 {0, (CHIP_IS_E3B0(sc)) ?
10998 PBF_REG_TQ_OCCUPANCY_Q0 : PBF_REG_P0_TQ_OCCUPANCY,
10999 (CHIP_IS_E3B0(sc)) ?
11000 PBF_REG_TQ_LINES_FREED_CNT_Q0 : PBF_REG_P0_TQ_LINES_FREED_CNT},
11001 {1, (CHIP_IS_E3B0(sc)) ?
11002 PBF_REG_TQ_OCCUPANCY_Q1 : PBF_REG_P1_TQ_OCCUPANCY,
11003 (CHIP_IS_E3B0(sc)) ?
11004 PBF_REG_TQ_LINES_FREED_CNT_Q1 : PBF_REG_P1_TQ_LINES_FREED_CNT},
11005 {4, (CHIP_IS_E3B0(sc)) ?
11006 PBF_REG_TQ_OCCUPANCY_LB_Q : PBF_REG_P4_TQ_OCCUPANCY,
11007 (CHIP_IS_E3B0(sc)) ?
11008 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
11009 PBF_REG_P4_TQ_LINES_FREED_CNT}
11012 struct pbf_pN_buf_regs buf_regs[] = {
11013 {0, (CHIP_IS_E3B0(sc)) ?
11014 PBF_REG_INIT_CRD_Q0 : PBF_REG_P0_INIT_CRD,
11015 (CHIP_IS_E3B0(sc)) ? PBF_REG_CREDIT_Q0 : PBF_REG_P0_CREDIT,
11016 (CHIP_IS_E3B0(sc)) ?
11017 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
11018 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
11019 {1, (CHIP_IS_E3B0(sc)) ?
11020 PBF_REG_INIT_CRD_Q1 : PBF_REG_P1_INIT_CRD,
11021 (CHIP_IS_E3B0(sc)) ? PBF_REG_CREDIT_Q1 : PBF_REG_P1_CREDIT,
11022 (CHIP_IS_E3B0(sc)) ?
11023 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
11024 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
11025 {4, (CHIP_IS_E3B0(sc)) ?
11026 PBF_REG_INIT_CRD_LB_Q : PBF_REG_P4_INIT_CRD,
11027 (CHIP_IS_E3B0(sc)) ? PBF_REG_CREDIT_LB_Q : PBF_REG_P4_CREDIT,
11028 (CHIP_IS_E3B0(sc)) ?
11029 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
11030 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
11035 /* Verify the command queues are flushed P0, P1, P4 */
11036 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) {
11037 bnx2x_pbf_pN_cmd_flushed(sc, &cmd_regs[i], poll_count);
11040 /* Verify the transmission buffers are flushed P0, P1, P4 */
11041 for (i = 0; i < ARRAY_SIZE(buf_regs); i++) {
11042 bnx2x_pbf_pN_buf_flushed(sc, &buf_regs[i], poll_count);
11046 static void bnx2x_hw_enable_status(struct bnx2x_softc *sc)
11048 __rte_unused uint32_t val;
11050 val = REG_RD(sc, CFC_REG_WEAK_ENABLE_PF);
11051 PMD_DRV_LOG(DEBUG, sc, "CFC_REG_WEAK_ENABLE_PF is 0x%x", val);
11053 val = REG_RD(sc, PBF_REG_DISABLE_PF);
11054 PMD_DRV_LOG(DEBUG, sc, "PBF_REG_DISABLE_PF is 0x%x", val);
11056 val = REG_RD(sc, IGU_REG_PCI_PF_MSI_EN);
11057 PMD_DRV_LOG(DEBUG, sc, "IGU_REG_PCI_PF_MSI_EN is 0x%x", val);
11059 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_EN);
11060 PMD_DRV_LOG(DEBUG, sc, "IGU_REG_PCI_PF_MSIX_EN is 0x%x", val);
11062 val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
11063 PMD_DRV_LOG(DEBUG, sc, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x", val);
11065 val = REG_RD(sc, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
11066 PMD_DRV_LOG(DEBUG, sc,
11067 "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x", val);
11069 val = REG_RD(sc, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
11070 PMD_DRV_LOG(DEBUG, sc,
11071 "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x", val);
11073 val = REG_RD(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
11074 PMD_DRV_LOG(DEBUG, sc, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x",
11079 * bnx2x_pf_flr_clnup
11080 * a. re-enable target read on the PF
11081 * b. poll cfc per function usgae counter
11082 * c. poll the qm perfunction usage counter
11083 * d. poll the tm per function usage counter
11084 * e. poll the tm per function scan-done indication
11085 * f. clear the dmae channel associated wit hthe PF
11086 * g. zero the igu 'trailing edge' and 'leading edge' regs (attentions)
11087 * h. call the common flr cleanup code with -1 (pf indication)
11089 static int bnx2x_pf_flr_clnup(struct bnx2x_softc *sc)
11091 uint32_t poll_cnt = bnx2x_flr_clnup_poll_count(sc);
11093 /* Re-enable PF target read access */
11094 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
11096 /* Poll HW usage counters */
11097 if (bnx2x_poll_hw_usage_counters(sc, poll_cnt)) {
11101 /* Zero the igu 'trailing edge' and 'leading edge' */
11103 /* Send the FW cleanup command */
11104 if (bnx2x_send_final_clnup(sc, (uint8_t) SC_FUNC(sc), poll_cnt)) {
11110 /* Verify TX hw is flushed */
11111 bnx2x_tx_hw_flushed(sc, poll_cnt);
11113 /* Wait 100ms (not adjusted according to platform) */
11116 /* Verify no pending pci transactions */
11117 if (bnx2x_is_pcie_pending(sc)) {
11118 PMD_DRV_LOG(NOTICE, sc, "PCIE Transactions still pending");
11122 bnx2x_hw_enable_status(sc);
11125 * Master enable - Due to WB DMAE writes performed before this
11126 * register is re-initialized as part of the regular function init
11128 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
11133 static int bnx2x_init_hw_func(struct bnx2x_softc *sc)
11135 int port = SC_PORT(sc);
11136 int func = SC_FUNC(sc);
11137 int init_phase = PHASE_PF0 + func;
11138 struct ecore_ilt *ilt = sc->ilt;
11139 uint16_t cdu_ilt_start;
11140 uint32_t addr, val;
11141 uint32_t main_mem_base, main_mem_size, main_mem_prty_clr;
11142 int main_mem_width, rc;
11145 PMD_DRV_LOG(DEBUG, sc, "starting func init for func %d", func);
11148 if (!CHIP_IS_E1x(sc)) {
11149 rc = bnx2x_pf_flr_clnup(sc);
11151 PMD_DRV_LOG(NOTICE, sc, "FLR cleanup failed!");
11156 /* set MSI reconfigure capability */
11157 if (sc->devinfo.int_block == INT_BLOCK_HC) {
11158 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
11159 val = REG_RD(sc, addr);
11160 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
11161 REG_WR(sc, addr, val);
11164 ecore_init_block(sc, BLOCK_PXP, init_phase);
11165 ecore_init_block(sc, BLOCK_PXP2, init_phase);
11168 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
11170 for (i = 0; i < L2_ILT_LINES(sc); i++) {
11171 ilt->lines[cdu_ilt_start + i].page = sc->context[i].vcxt;
11172 ilt->lines[cdu_ilt_start + i].page_mapping =
11173 (rte_iova_t)sc->context[i].vcxt_dma.paddr;
11174 ilt->lines[cdu_ilt_start + i].size = sc->context[i].size;
11176 ecore_ilt_init_op(sc, INITOP_SET);
11178 REG_WR(sc, PRS_REG_NIC_MODE, 1);
11180 if (!CHIP_IS_E1x(sc)) {
11181 uint32_t pf_conf = IGU_PF_CONF_FUNC_EN;
11183 /* Turn on a single ISR mode in IGU if driver is going to use
11186 if ((sc->interrupt_mode != INTR_MODE_MSIX)
11187 || (sc->interrupt_mode != INTR_MODE_SINGLE_MSIX)) {
11188 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
11192 * Timers workaround bug: function init part.
11193 * Need to wait 20msec after initializing ILT,
11194 * needed to make sure there are no requests in
11195 * one of the PXP internal queues with "old" ILT addresses
11200 * Master enable - Due to WB DMAE writes performed before this
11201 * register is re-initialized as part of the regular function
11204 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
11205 /* Enable the function in IGU */
11206 REG_WR(sc, IGU_REG_PF_CONFIGURATION, pf_conf);
11209 sc->dmae_ready = 1;
11211 ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
11213 if (!CHIP_IS_E1x(sc))
11214 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
11216 ecore_init_block(sc, BLOCK_ATC, init_phase);
11217 ecore_init_block(sc, BLOCK_DMAE, init_phase);
11218 ecore_init_block(sc, BLOCK_NIG, init_phase);
11219 ecore_init_block(sc, BLOCK_SRC, init_phase);
11220 ecore_init_block(sc, BLOCK_MISC, init_phase);
11221 ecore_init_block(sc, BLOCK_TCM, init_phase);
11222 ecore_init_block(sc, BLOCK_UCM, init_phase);
11223 ecore_init_block(sc, BLOCK_CCM, init_phase);
11224 ecore_init_block(sc, BLOCK_XCM, init_phase);
11225 ecore_init_block(sc, BLOCK_TSEM, init_phase);
11226 ecore_init_block(sc, BLOCK_USEM, init_phase);
11227 ecore_init_block(sc, BLOCK_CSEM, init_phase);
11228 ecore_init_block(sc, BLOCK_XSEM, init_phase);
11230 if (!CHIP_IS_E1x(sc))
11231 REG_WR(sc, QM_REG_PF_EN, 1);
11233 if (!CHIP_IS_E1x(sc)) {
11234 REG_WR(sc, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
11235 REG_WR(sc, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
11236 REG_WR(sc, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
11237 REG_WR(sc, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
11239 ecore_init_block(sc, BLOCK_QM, init_phase);
11241 ecore_init_block(sc, BLOCK_TM, init_phase);
11242 ecore_init_block(sc, BLOCK_DORQ, init_phase);
11244 ecore_init_block(sc, BLOCK_BRB1, init_phase);
11245 ecore_init_block(sc, BLOCK_PRS, init_phase);
11246 ecore_init_block(sc, BLOCK_TSDM, init_phase);
11247 ecore_init_block(sc, BLOCK_CSDM, init_phase);
11248 ecore_init_block(sc, BLOCK_USDM, init_phase);
11249 ecore_init_block(sc, BLOCK_XSDM, init_phase);
11250 ecore_init_block(sc, BLOCK_UPB, init_phase);
11251 ecore_init_block(sc, BLOCK_XPB, init_phase);
11252 ecore_init_block(sc, BLOCK_PBF, init_phase);
11253 if (!CHIP_IS_E1x(sc))
11254 REG_WR(sc, PBF_REG_DISABLE_PF, 0);
11256 ecore_init_block(sc, BLOCK_CDU, init_phase);
11258 ecore_init_block(sc, BLOCK_CFC, init_phase);
11260 if (!CHIP_IS_E1x(sc))
11261 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 1);
11264 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
11265 REG_WR(sc, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8, OVLAN(sc));
11268 ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
11270 /* HC init per function */
11271 if (sc->devinfo.int_block == INT_BLOCK_HC) {
11272 if (CHIP_IS_E1H(sc)) {
11273 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func * 4, 0);
11275 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port * 8, 0);
11276 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port * 8, 0);
11278 ecore_init_block(sc, BLOCK_HC, init_phase);
11281 uint32_t num_segs, sb_idx, prod_offset;
11283 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func * 4, 0);
11285 if (!CHIP_IS_E1x(sc)) {
11286 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
11287 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
11290 ecore_init_block(sc, BLOCK_IGU, init_phase);
11292 if (!CHIP_IS_E1x(sc)) {
11296 * E2 mode: address 0-135 match to the mapping memory;
11297 * 136 - PF0 default prod; 137 - PF1 default prod;
11298 * 138 - PF2 default prod; 139 - PF3 default prod;
11299 * 140 - PF0 attn prod; 141 - PF1 attn prod;
11300 * 142 - PF2 attn prod; 143 - PF3 attn prod;
11301 * 144-147 reserved.
11303 * E1.5 mode - In backward compatible mode;
11304 * for non default SB; each even line in the memory
11305 * holds the U producer and each odd line hold
11306 * the C producer. The first 128 producers are for
11307 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
11308 * producers are for the DSB for each PF.
11309 * Each PF has five segments: (the order inside each
11310 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
11311 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
11312 * 144-147 attn prods;
11314 /* non-default-status-blocks */
11315 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
11316 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
11317 for (sb_idx = 0; sb_idx < sc->igu_sb_cnt; sb_idx++) {
11318 prod_offset = (sc->igu_base_sb + sb_idx) *
11321 for (i = 0; i < num_segs; i++) {
11322 addr = IGU_REG_PROD_CONS_MEMORY +
11323 (prod_offset + i) * 4;
11324 REG_WR(sc, addr, 0);
11326 /* send consumer update with value 0 */
11327 bnx2x_ack_sb(sc, sc->igu_base_sb + sb_idx,
11328 USTORM_ID, 0, IGU_INT_NOP, 1);
11329 bnx2x_igu_clear_sb(sc, sc->igu_base_sb + sb_idx);
11332 /* default-status-blocks */
11333 num_segs = CHIP_INT_MODE_IS_BC(sc) ?
11334 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
11336 if (CHIP_IS_MODE_4_PORT(sc))
11337 dsb_idx = SC_FUNC(sc);
11339 dsb_idx = SC_VN(sc);
11341 prod_offset = (CHIP_INT_MODE_IS_BC(sc) ?
11342 IGU_BC_BASE_DSB_PROD + dsb_idx :
11343 IGU_NORM_BASE_DSB_PROD + dsb_idx);
11346 * igu prods come in chunks of E1HVN_MAX (4) -
11347 * does not matters what is the current chip mode
11349 for (i = 0; i < (num_segs * E1HVN_MAX); i += E1HVN_MAX) {
11350 addr = IGU_REG_PROD_CONS_MEMORY +
11351 (prod_offset + i) * 4;
11352 REG_WR(sc, addr, 0);
11354 /* send consumer update with 0 */
11355 if (CHIP_INT_MODE_IS_BC(sc)) {
11356 bnx2x_ack_sb(sc, sc->igu_dsb_id,
11357 USTORM_ID, 0, IGU_INT_NOP, 1);
11358 bnx2x_ack_sb(sc, sc->igu_dsb_id,
11359 CSTORM_ID, 0, IGU_INT_NOP, 1);
11360 bnx2x_ack_sb(sc, sc->igu_dsb_id,
11361 XSTORM_ID, 0, IGU_INT_NOP, 1);
11362 bnx2x_ack_sb(sc, sc->igu_dsb_id,
11363 TSTORM_ID, 0, IGU_INT_NOP, 1);
11364 bnx2x_ack_sb(sc, sc->igu_dsb_id,
11365 ATTENTION_ID, 0, IGU_INT_NOP, 1);
11367 bnx2x_ack_sb(sc, sc->igu_dsb_id,
11368 USTORM_ID, 0, IGU_INT_NOP, 1);
11369 bnx2x_ack_sb(sc, sc->igu_dsb_id,
11370 ATTENTION_ID, 0, IGU_INT_NOP, 1);
11372 bnx2x_igu_clear_sb(sc, sc->igu_dsb_id);
11374 /* !!! these should become driver const once
11375 rf-tool supports split-68 const */
11376 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
11377 REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
11378 REG_WR(sc, IGU_REG_SB_MASK_LSB, 0);
11379 REG_WR(sc, IGU_REG_SB_MASK_MSB, 0);
11380 REG_WR(sc, IGU_REG_PBA_STATUS_LSB, 0);
11381 REG_WR(sc, IGU_REG_PBA_STATUS_MSB, 0);
11385 /* Reset PCIE errors for debug */
11386 REG_WR(sc, 0x2114, 0xffffffff);
11387 REG_WR(sc, 0x2120, 0xffffffff);
11389 if (CHIP_IS_E1x(sc)) {
11390 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords */
11391 main_mem_base = HC_REG_MAIN_MEMORY +
11392 SC_PORT(sc) * (main_mem_size * 4);
11393 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
11394 main_mem_width = 8;
11396 val = REG_RD(sc, main_mem_prty_clr);
11398 PMD_DRV_LOG(DEBUG, sc,
11399 "Parity errors in HC block during function init (0x%x)!",
11403 /* Clear "false" parity errors in MSI-X table */
11404 for (i = main_mem_base;
11405 i < main_mem_base + main_mem_size * 4;
11406 i += main_mem_width) {
11407 bnx2x_read_dmae(sc, i, main_mem_width / 4);
11408 bnx2x_write_dmae(sc, BNX2X_SP_MAPPING(sc, wb_data),
11409 i, main_mem_width / 4);
11411 /* Clear HC parity attention */
11412 REG_RD(sc, main_mem_prty_clr);
11415 /* Enable STORMs SP logging */
11416 REG_WR8(sc, BAR_USTRORM_INTMEM +
11417 USTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
11418 REG_WR8(sc, BAR_TSTRORM_INTMEM +
11419 TSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
11420 REG_WR8(sc, BAR_CSTRORM_INTMEM +
11421 CSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
11422 REG_WR8(sc, BAR_XSTRORM_INTMEM +
11423 XSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
11425 elink_phy_probe(&sc->link_params);
11430 static void bnx2x_link_reset(struct bnx2x_softc *sc)
11432 if (!BNX2X_NOMCP(sc)) {
11433 bnx2x_acquire_phy_lock(sc);
11434 elink_lfa_reset(&sc->link_params, &sc->link_vars);
11435 bnx2x_release_phy_lock(sc);
11437 if (!CHIP_REV_IS_SLOW(sc)) {
11438 PMD_DRV_LOG(WARNING, sc,
11439 "Bootcode is missing - cannot reset link");
11444 static void bnx2x_reset_port(struct bnx2x_softc *sc)
11446 int port = SC_PORT(sc);
11449 /* reset physical Link */
11450 bnx2x_link_reset(sc);
11452 REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4, 0);
11454 /* Do not rcv packets to BRB */
11455 REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + port * 4, 0x0);
11456 /* Do not direct rcv packets that are not for MCP to the BRB */
11457 REG_WR(sc, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
11458 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
11460 /* Configure AEU */
11461 REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port * 4, 0);
11465 /* Check for BRB port occupancy */
11466 val = REG_RD(sc, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port * 4);
11468 PMD_DRV_LOG(DEBUG, sc,
11469 "BRB1 is not empty, %d blocks are occupied", val);
11473 static void bnx2x_ilt_wr(struct bnx2x_softc *sc, uint32_t index, rte_iova_t addr)
11476 uint32_t wb_write[2];
11478 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index * 8;
11480 wb_write[0] = ONCHIP_ADDR1(addr);
11481 wb_write[1] = ONCHIP_ADDR2(addr);
11482 REG_WR_DMAE(sc, reg, wb_write, 2);
11485 static void bnx2x_clear_func_ilt(struct bnx2x_softc *sc, uint32_t func)
11487 uint32_t i, base = FUNC_ILT_BASE(func);
11488 for (i = base; i < base + ILT_PER_FUNC; i++) {
11489 bnx2x_ilt_wr(sc, i, 0);
11493 static void bnx2x_reset_func(struct bnx2x_softc *sc)
11495 struct bnx2x_fastpath *fp;
11496 int port = SC_PORT(sc);
11497 int func = SC_FUNC(sc);
11500 /* Disable the function in the FW */
11501 REG_WR8(sc, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
11502 REG_WR8(sc, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
11503 REG_WR8(sc, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
11504 REG_WR8(sc, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
11507 FOR_EACH_ETH_QUEUE(sc, i) {
11509 REG_WR8(sc, BAR_CSTRORM_INTMEM +
11510 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
11515 REG_WR8(sc, BAR_CSTRORM_INTMEM +
11516 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), SB_DISABLED);
11518 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) {
11519 REG_WR(sc, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
11523 /* Configure IGU */
11524 if (sc->devinfo.int_block == INT_BLOCK_HC) {
11525 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port * 8, 0);
11526 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port * 8, 0);
11528 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
11529 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
11532 if (CNIC_LOADED(sc)) {
11533 /* Disable Timer scan */
11534 REG_WR(sc, TM_REG_EN_LINEAR0_TIMER + port * 4, 0);
11536 * Wait for at least 10ms and up to 2 second for the timers
11539 for (i = 0; i < 200; i++) {
11541 if (!REG_RD(sc, TM_REG_LIN0_SCAN_ON + port * 4))
11547 bnx2x_clear_func_ilt(sc, func);
11550 * Timers workaround bug for E2: if this is vnic-3,
11551 * we need to set the entire ilt range for this timers.
11553 if (!CHIP_IS_E1x(sc) && SC_VN(sc) == 3) {
11554 struct ilt_client_info ilt_cli;
11555 /* use dummy TM client */
11556 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
11558 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
11559 ilt_cli.client_num = ILT_CLIENT_TM;
11561 ecore_ilt_boundry_init_op(sc, &ilt_cli, 0);
11564 /* this assumes that reset_port() called before reset_func() */
11565 if (!CHIP_IS_E1x(sc)) {
11566 bnx2x_pf_disable(sc);
11569 sc->dmae_ready = 0;
11572 static void bnx2x_release_firmware(struct bnx2x_softc *sc)
11574 rte_free(sc->init_ops);
11575 rte_free(sc->init_ops_offsets);
11576 rte_free(sc->init_data);
11577 rte_free(sc->iro_array);
11580 static int bnx2x_init_firmware(struct bnx2x_softc *sc)
11583 uint8_t *p = sc->firmware;
11586 for (i = 0; i < 24; ++i)
11587 off[i] = rte_be_to_cpu_32(*((uint32_t *) sc->firmware + i));
11590 sc->init_ops = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
11593 bnx2x_data_to_init_ops(p + off[1], sc->init_ops, len);
11596 sc->init_ops_offsets = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
11597 if (!sc->init_ops_offsets)
11599 bnx2x_data_to_init_offsets(p + off[3], sc->init_ops_offsets, len);
11602 sc->init_data = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
11603 if (!sc->init_data)
11605 bnx2x_data_to_init_data(p + off[5], sc->init_data, len);
11607 sc->tsem_int_table_data = p + off[7];
11608 sc->tsem_pram_data = p + off[9];
11609 sc->usem_int_table_data = p + off[11];
11610 sc->usem_pram_data = p + off[13];
11611 sc->csem_int_table_data = p + off[15];
11612 sc->csem_pram_data = p + off[17];
11613 sc->xsem_int_table_data = p + off[19];
11614 sc->xsem_pram_data = p + off[21];
11617 sc->iro_array = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
11618 if (!sc->iro_array)
11620 bnx2x_data_to_iro_array(p + off[23], sc->iro_array, len);
11625 bnx2x_release_firmware(sc);
11629 static int cut_gzip_prefix(const uint8_t * zbuf, int len)
11631 #define MIN_PREFIX_SIZE (10)
11633 int n = MIN_PREFIX_SIZE;
11636 if (!(zbuf[0] == 0x1f && zbuf[1] == 0x8b && zbuf[2] == Z_DEFLATED) ||
11637 len <= MIN_PREFIX_SIZE) {
11641 /* optional extra fields are present */
11642 if (zbuf[3] & 0x4) {
11649 /* file name is present */
11650 if (zbuf[3] & 0x8) {
11651 while ((zbuf[n++] != 0) && (n < len)) ;
11657 static int ecore_gunzip(struct bnx2x_softc *sc, const uint8_t * zbuf, int len)
11660 int data_begin = cut_gzip_prefix(zbuf, len);
11662 PMD_DRV_LOG(DEBUG, sc, "ecore_gunzip %d", len);
11664 if (data_begin <= 0) {
11665 PMD_DRV_LOG(NOTICE, sc, "bad gzip prefix");
11669 memset(&zlib_stream, 0, sizeof(zlib_stream));
11670 zlib_stream.next_in = zbuf + data_begin;
11671 zlib_stream.avail_in = len - data_begin;
11672 zlib_stream.next_out = sc->gz_buf;
11673 zlib_stream.avail_out = FW_BUF_SIZE;
11675 ret = inflateInit2(&zlib_stream, -MAX_WBITS);
11677 PMD_DRV_LOG(NOTICE, sc, "zlib inflateInit2 error");
11681 ret = inflate(&zlib_stream, Z_FINISH);
11682 if ((ret != Z_STREAM_END) && (ret != Z_OK)) {
11683 PMD_DRV_LOG(NOTICE, sc, "zlib inflate error: %d %s", ret,
11687 sc->gz_outlen = zlib_stream.total_out;
11688 if (sc->gz_outlen & 0x3) {
11689 PMD_DRV_LOG(NOTICE, sc, "firmware is not aligned. gz_outlen == %d",
11692 sc->gz_outlen >>= 2;
11694 inflateEnd(&zlib_stream);
11696 if (ret == Z_STREAM_END)
11703 ecore_write_dmae_phys_len(struct bnx2x_softc *sc, rte_iova_t phys_addr,
11704 uint32_t addr, uint32_t len)
11706 bnx2x_write_dmae_phys_len(sc, phys_addr, addr, len);
11710 ecore_storm_memset_struct(struct bnx2x_softc *sc, uint32_t addr, size_t size,
11714 for (i = 0; i < size / 4; i++) {
11715 REG_WR(sc, addr + (i * 4), data[i]);
11719 static const char *get_ext_phy_type(uint32_t ext_phy_type)
11721 uint32_t phy_type_idx = ext_phy_type >> 8;
11722 static const char *types[] =
11723 { "DIRECT", "BNX2X-8071", "BNX2X-8072", "BNX2X-8073",
11724 "BNX2X-8705", "BNX2X-8706", "BNX2X-8726", "BNX2X-8481", "SFX-7101",
11726 "BNX2X-8727-NOC", "BNX2X-84823", "NOT_CONN", "FAILURE"
11729 if (phy_type_idx < 12)
11730 return types[phy_type_idx];
11731 else if (PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN == ext_phy_type)
11737 static const char *get_state(uint32_t state)
11739 uint32_t state_idx = state >> 12;
11740 static const char *states[] = { "CLOSED", "OPENING_WAIT4_LOAD",
11741 "OPENING_WAIT4_PORT", "OPEN", "CLOSING_WAIT4_HALT",
11742 "CLOSING_WAIT4_DELETE", "CLOSING_WAIT4_UNLOAD",
11743 "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
11744 "UNKNOWN", "DISABLED", "DIAG", "ERROR", "UNDEFINED"
11747 if (state_idx <= 0xF)
11748 return states[state_idx];
11750 return states[0x10];
11753 static const char *get_recovery_state(uint32_t state)
11755 static const char *states[] = { "NONE", "DONE", "INIT",
11756 "WAIT", "FAILED", "NIC_LOADING"
11758 return states[state];
11761 static const char *get_rx_mode(uint32_t mode)
11763 static const char *modes[] = { "NONE", "NORMAL", "ALLMULTI",
11764 "PROMISC", "MAX_MULTICAST", "ERROR"
11768 return modes[mode];
11769 else if (BNX2X_MAX_MULTICAST == mode)
11775 #define BNX2X_INFO_STR_MAX 256
11776 static const char *get_bnx2x_flags(uint32_t flags)
11779 static const char *flag[] = { "ONE_PORT ", "NO_ISCSI ",
11780 "NO_FCOE ", "NO_WOL ", "USING_DAC ", "USING_MSIX ",
11781 "USING_MSI ", "DISABLE_MSI ", "UNKNOWN ", "NO_MCP ",
11782 "SAFC_TX_FLAG ", "MF_FUNC_DIS ", "TX_SWITCHING "
11784 static char flag_str[BNX2X_INFO_STR_MAX];
11785 memset(flag_str, 0, BNX2X_INFO_STR_MAX);
11787 for (i = 0; i < 5; i++)
11788 if (flags & (1 << i)) {
11789 strlcat(flag_str, flag[i], sizeof(flag_str));
11793 static char unknown[BNX2X_INFO_STR_MAX];
11794 snprintf(unknown, 32, "Unknown flag mask %x", flags);
11795 strlcat(flag_str, unknown, sizeof(flag_str));
11800 /* Prints useful adapter info. */
11801 void bnx2x_print_adapter_info(struct bnx2x_softc *sc)
11805 PMD_DRV_LOG(INFO, sc, "========================================");
11806 /* DPDK and Driver versions */
11807 PMD_DRV_LOG(INFO, sc, "%12s : %s", "DPDK",
11809 PMD_DRV_LOG(INFO, sc, "%12s : %s", "Driver",
11810 bnx2x_pmd_version());
11811 /* Firmware versions. */
11812 PMD_DRV_LOG(INFO, sc, "%12s : %d.%d.%d",
11814 BNX2X_5710_FW_MAJOR_VERSION,
11815 BNX2X_5710_FW_MINOR_VERSION,
11816 BNX2X_5710_FW_REVISION_VERSION);
11817 PMD_DRV_LOG(INFO, sc, "%12s : %s",
11818 "Bootcode", sc->devinfo.bc_ver_str);
11819 /* Hardware chip info. */
11820 PMD_DRV_LOG(INFO, sc, "%12s : %#08x", "ASIC", sc->devinfo.chip_id);
11821 PMD_DRV_LOG(INFO, sc, "%12s : %c%d", "Rev", (CHIP_REV(sc) >> 12) + 'A',
11822 (CHIP_METAL(sc) >> 4));
11823 /* Bus PCIe info. */
11824 PMD_DRV_LOG(INFO, sc, "%12s : 0x%x", "Vendor Id",
11825 sc->devinfo.vendor_id);
11826 PMD_DRV_LOG(INFO, sc, "%12s : 0x%x", "Device Id",
11827 sc->devinfo.device_id);
11828 PMD_DRV_LOG(INFO, sc, "%12s : width x%d, ", "Bus PCIe",
11829 sc->devinfo.pcie_link_width);
11830 switch (sc->devinfo.pcie_link_speed) {
11832 PMD_DRV_LOG(INFO, sc, "%23s", "2.5 Gbps");
11835 PMD_DRV_LOG(INFO, sc, "%21s", "5 Gbps");
11838 PMD_DRV_LOG(INFO, sc, "%21s", "8 Gbps");
11841 PMD_DRV_LOG(INFO, sc, "%33s", "Unknown link speed");
11843 /* Device features. */
11844 PMD_DRV_LOG(INFO, sc, "%12s : ", "Flags");
11845 /* Miscellaneous flags. */
11846 if (sc->devinfo.pcie_cap_flags & BNX2X_MSI_CAPABLE_FLAG) {
11847 PMD_DRV_LOG(INFO, sc, "%18s", "MSI");
11850 if (sc->devinfo.pcie_cap_flags & BNX2X_MSIX_CAPABLE_FLAG) {
11852 PMD_DRV_LOG(INFO, sc, "|");
11853 PMD_DRV_LOG(INFO, sc, "%20s", "MSI-X");
11856 PMD_DRV_LOG(INFO, sc, "%12s : %s", "OVLAN", (OVLAN(sc) ? "YES" : "NO"));
11857 PMD_DRV_LOG(INFO, sc, "%12s : %s", "MF", (IS_MF(sc) ? "YES" : "NO"));
11858 PMD_DRV_LOG(INFO, sc, "========================================");
11861 /* Prints useful device info. */
11862 void bnx2x_print_device_info(struct bnx2x_softc *sc)
11864 __rte_unused uint32_t ext_phy_type;
11865 uint32_t offset, reg_val;
11867 PMD_INIT_FUNC_TRACE(sc);
11868 offset = offsetof(struct shmem_region,
11869 dev_info.port_hw_config[0].external_phy_config);
11870 reg_val = REG_RD(sc, sc->devinfo.shmem_base + offset);
11871 if (sc->link_vars.phy_flags & PHY_XGXS_FLAG)
11872 ext_phy_type = ELINK_XGXS_EXT_PHY_TYPE(reg_val);
11874 ext_phy_type = ELINK_SERDES_EXT_PHY_TYPE(reg_val);
11876 /* Device features. */
11877 PMD_DRV_LOG(INFO, sc, "%12s : %u", "Bnx2x Func", sc->pcie_func);
11878 PMD_DRV_LOG(INFO, sc,
11879 "%12s : %s", "Bnx2x Flags", get_bnx2x_flags(sc->flags));
11880 PMD_DRV_LOG(INFO, sc, "%12s : %s", "DMAE Is",
11881 (sc->dmae_ready ? "Ready" : "Not Ready"));
11882 PMD_DRV_LOG(INFO, sc, "%12s : %u", "MTU", sc->mtu);
11883 PMD_DRV_LOG(INFO, sc,
11884 "%12s : %s", "PHY Type", get_ext_phy_type(ext_phy_type));
11885 PMD_DRV_LOG(INFO, sc, "%12s : %x:%x:%x:%x:%x:%x", "MAC Addr",
11886 sc->link_params.mac_addr[0],
11887 sc->link_params.mac_addr[1],
11888 sc->link_params.mac_addr[2],
11889 sc->link_params.mac_addr[3],
11890 sc->link_params.mac_addr[4],
11891 sc->link_params.mac_addr[5]);
11892 PMD_DRV_LOG(INFO, sc, "%12s : %s", "RX Mode", get_rx_mode(sc->rx_mode));
11893 PMD_DRV_LOG(INFO, sc, "%12s : %s", "State", get_state(sc->state));
11894 if (sc->recovery_state)
11895 PMD_DRV_LOG(INFO, sc, "%12s : %s", "Recovery",
11896 get_recovery_state(sc->recovery_state));
11899 switch (sc->sp->rss_rdata.rss_mode) {
11900 case ETH_RSS_MODE_DISABLED:
11901 PMD_DRV_LOG(INFO, sc, "%12s : %s", "Queues", "RSS mode - None");
11903 case ETH_RSS_MODE_REGULAR:
11904 PMD_DRV_LOG(INFO, sc, "%12s : %s,", "Queues", "RSS mode - Regular");
11905 PMD_DRV_LOG(INFO, sc, "%16d", sc->num_queues);
11908 PMD_DRV_LOG(INFO, sc, "%12s : %s", "Queues", "RSS mode - Unknown");
11912 PMD_DRV_LOG(INFO, sc, "%12s : CQ = %lx, EQ = %lx", "SPQ Left",
11913 sc->cq_spq_left, sc->eq_spq_left);
11915 PMD_DRV_LOG(INFO, sc,
11916 "%12s : %x", "Switch", sc->link_params.switch_cfg);
11917 PMD_DRV_LOG(INFO, sc, "pcie_bus=%d, pcie_device=%d",
11918 sc->pcie_bus, sc->pcie_device);
11919 PMD_DRV_LOG(INFO, sc, "bar0.addr=%p, bar1.addr=%p",
11920 sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
11921 PMD_DRV_LOG(INFO, sc, "port=%d, path=%d, vnic=%d, func=%d",
11922 PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));