bnx2x: poll mode driver
v5 cover bnx2x: poll mode driver
Changes in this version (v5):
- rebase to 2.1.0-rc1
- fix version map for 2.1
- fix doxygen comments
- add BCM57410 ids
Stephen Hemminger (4):
eal: provide functions to access PCI config
bnx2x: driver core
bnx2x: driver support routines
bnx2x: enable PMD build
MAINTAINERS | 3 + config/common_linuxapp | 10 + drivers/net/Makefile | 1 + drivers/net/bnx2x/Makefile | 28 + drivers/net/bnx2x/bnx2x.c | 11821 +++++++++++++++++++ drivers/net/bnx2x/bnx2x.h | 1998 ++++ drivers/net/bnx2x/bnx2x_ethdev.c | 542 + drivers/net/bnx2x/bnx2x_ethdev.h | 79 + drivers/net/bnx2x/bnx2x_logs.h | 51 + drivers/net/bnx2x/bnx2x_rxtx.c | 487 + drivers/net/bnx2x/bnx2x_rxtx.h | 85 + drivers/net/bnx2x/bnx2x_stats.c | 1619 +++ drivers/net/bnx2x/bnx2x_stats.h | 632 + drivers/net/bnx2x/bnx2x_vfpf.c | 597 + drivers/net/bnx2x/bnx2x_vfpf.h | 315 + drivers/net/bnx2x/debug.c | 113 + drivers/net/bnx2x/ecore_fw_defs.h | 422 + drivers/net/bnx2x/ecore_hsi.h | 6348 ++++++++++ drivers/net/bnx2x/ecore_init.h | 841 ++ drivers/net/bnx2x/ecore_init_ops.h | 886 ++ drivers/net/bnx2x/ecore_mfw_req.h | 206 + drivers/net/bnx2x/ecore_reg.h | 3663 ++++++ drivers/net/bnx2x/ecore_sp.c | 5455 +++++++++ drivers/net/bnx2x/ecore_sp.h | 1795 +++ drivers/net/bnx2x/elink.c | 13378 ++++++++++++++++++++++ drivers/net/bnx2x/elink.h | 609 + drivers/net/bnx2x/rte_pmd_bnx2x_version.map | 4 + lib/librte_eal/bsdapp/eal/eal_pci.c | 83 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 3 +- lib/librte_eal/common/include/rte_pci.h | 32 + lib/librte_eal/common/include/rte_pci_dev_ids.h | 61 + lib/librte_eal/linuxapp/eal/eal_pci.c | 50 + lib/librte_eal/linuxapp/eal/eal_pci_init.h | 11 + lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 14 + lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 16 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 3 +- mk/rte.app.mk | 2 + 37 files changed, 52261 insertions(+), 2 deletions(-) create mode 100644 drivers/net/bnx2x/Makefile create mode 100644 drivers/net/bnx2x/bnx2x.c create mode 100644 drivers/net/bnx2x/bnx2x.h create mode 100644 drivers/net/bnx2x/bnx2x_ethdev.c create mode 100644 drivers/net/bnx2x/bnx2x_ethdev.h create mode 100644 drivers/net/bnx2x/bnx2x_logs.h create mode 100644 drivers/net/bnx2x/bnx2x_rxtx.c create mode 100644 drivers/net/bnx2x/bnx2x_rxtx.h create mode 100644 drivers/net/bnx2x/bnx2x_stats.c create mode 100644 drivers/net/bnx2x/bnx2x_stats.h create mode 100644 drivers/net/bnx2x/bnx2x_vfpf.c create mode 100644 drivers/net/bnx2x/bnx2x_vfpf.h create mode 100644 drivers/net/bnx2x/debug.c create mode 100644 drivers/net/bnx2x/ecore_fw_defs.h create mode 100644 drivers/net/bnx2x/ecore_hsi.h create mode 100644 drivers/net/bnx2x/ecore_init.h create mode 100644 drivers/net/bnx2x/ecore_init_ops.h create mode 100644 drivers/net/bnx2x/ecore_mfw_req.h create mode 100644 drivers/net/bnx2x/ecore_reg.h create mode 100644 drivers/net/bnx2x/ecore_sp.c create mode 100644 drivers/net/bnx2x/ecore_sp.h create mode 100644 drivers/net/bnx2x/elink.c create mode 100644 drivers/net/bnx2x/elink.h create mode 100644 drivers/net/bnx2x/rte_pmd_bnx2x_version.map
Signature · 1 line
2.1.4
PATCH v5 1/4 eal: provide functions to access PCI config
Some drivers need ability to access PCI config (for example for power management). This adds an abstraction to do this for both Linux and BSD.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 83 +++++++++++++++++++++++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 3 +- lib/librte_eal/common/include/rte_pci.h | 32 ++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 50 +++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci_init.h | 11 ++++ lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 14 +++++ lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 16 +++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 3 +- 8 files changed, 210 insertions(+), 2 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +83 -0
@@ -397,6 +397,89 @@ error:return -1 ; } +/* Read PCI config space. */ +int rte_eal_pci_read_config (const struct rte_pci_device *dev, +void *buf,size_t len,off_t offset) +{ +int fd =-1 ; +struct pci_io pi = { + .pi_sel = { + .pc_domain = dev->addr.domain, + .pc_bus = dev->addr.bus, + .pc_dev = dev->addr.devid, + .pc_func = dev->addr.function, + }, + .pi_reg = offset, + .pi_width = len, + }; + +if (len ==3 || len >sizeof (pi.pi_data)) { +RTE_LOG (ERR ,EAL ,"%s(): invalid pci read length\n" , __func__); + goto error; + } + + fd =open ("/dev/pci" ,O_RDONLY ); +if (fd <0 ) { +RTE_LOG (ERR ,EAL ,"%s(): error opening /dev/pci\n" , __func__); + goto error; + } + +if (ioctl (fd,PCIOCREAD , &pi) <0 ) + goto error; +close (fd); + +memcpy (buf, &pi.pi_data, len); +return 0 ; + + error: +if (fd >=0 ) +close (fd); +return -1 ; +} + +/* Write PCI config space. */ +int rte_eal_pci_write_config (const struct rte_pci_device *dev, +const void *buf,size_t len,off_t offset) +{ +int fd =-1 ; + +struct pci_io pi = { + .pi_sel = { + .pc_domain = dev->addr.domain, + .pc_bus = dev->addr.bus, + .pc_dev = dev->addr.devid, + .pc_func = dev->addr.function, + }, + .pi_reg = offset, + .pi_data = *(u_int32_t *)buf, + .pi_width = len, + }; + +if (len ==3 || len >sizeof (pi.pi_data)) { +RTE_LOG (ERR ,EAL ,"%s(): invalid pci read length\n" , __func__); + goto error; + } + +memcpy (pi.pi_data, buf, len); + + fd =open ("/dev/pci" ,O_RDONLY ); +if (fd <0 ) { +RTE_LOG (ERR ,EAL ,"%s(): error opening /dev/pci\n" , __func__); + goto error; + } + +if (ioctl (fd,PCIOCWRITE , &pi) <0 ) + goto error; + +close (fd); +return 0 ; + + error: +if (fd >=0 ) +close (fd); +return -1 ; +} +/* Init the PCI EAL subsystem */ int rte_eal_pci_init (void )
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -1
@@ -117,5 +117,6 @@ DPDK_2.1 { rte_eal_pci_detach; rte_memzone_free; - + rte_eal_pci_read_config; + rte_eal_pci_write_config; } DPDK_2.0;
lib/librte_eal/common/include/rte_pci.h +32 -0
@@ -455,6 +455,38 @@ void rte_eal_pci_register(struct rte_pci_driver *driver);*/ void rte_eal_pci_unregister (struct rte_pci_driver *driver); +/** +* Read PCI config space. +* +* @param device +* A pointer to a rte_pci_device structure describing the device +* to use +* @param buf +* A data buffer where the bytes should be read into +* @param len +* The length of the data buffer. +* @param offset +* The offset into PCI config space +*/ +int rte_eal_pci_read_config (const struct rte_pci_device *device, +void *buf,size_t len,off_t offset); + +/** +* Write PCI config space. +* +* @param device +* A pointer to a rte_pci_device structure describing the device +* to use +* @param buf +* A data buffer containing the bytes should be written +* @param len +* The length of the data buffer. +* @param offset +* The offset into PCI config space +*/ +int rte_eal_pci_write_config (const struct rte_pci_device *device, +const void *buf,size_t len,off_t offset); + #ifdef __cplusplus }#endif
lib/librte_eal/linuxapp/eal/eal_pci.c +50 -0
56 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_pci_init.h +11 -0
@@ -49,6 +49,11 @@ void pci_uio_free_resource(struct rte_pci_device *dev,int pci_uio_map_resource_by_index (struct rte_pci_device *dev,int res_idx,struct mapped_pci_resource *uio_res,int map_idx); +int pci_uio_read_config (const struct rte_intr_handle *intr_handle, +void *buf,size_t len,off_t offs); +int pci_uio_write_config (const struct rte_intr_handle *intr_handle, +const void *buf,size_t len,off_t offs); +#ifdef VFIO_PRESENT #define VFIO_MAX_GROUPS 64
@@ -57,6 +62,12 @@ int pci_vfio_enable(void);int pci_vfio_is_enabled (void );int pci_vfio_mp_sync_setup (void ); +/* access config space */ +int pci_vfio_read_config (const struct rte_intr_handle *intr_handle, +void *buf,size_t len,off_t offs); +int pci_vfio_write_config (const struct rte_intr_handle *intr_handle, +const void *buf,size_t len,off_t offs); +/* map VFIO resource prototype */ int pci_vfio_map_resource (struct rte_pci_device *dev);int pci_vfio_get_group_fd (int iommu_group_fd);
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +14 -0
@@ -53,6 +53,20 @@ void *pci_map_addr = NULL;#define OFF_MAX ((uint64_t)(off_t)-1) +int +pci_uio_read_config (const struct rte_intr_handle *intr_handle, +void *buf,size_t len,off_t offset) +{ +return pread (intr_handle->uio_cfg_fd, buf, len, offset); +} + +int +pci_uio_write_config (const struct rte_intr_handle *intr_handle, +const void *buf,size_t len,off_t offset) +{ +return pwrite (intr_handle->uio_cfg_fd, buf, len, offset); +} +static int pci_uio_set_bus_master (int dev_fd) {
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +16 -0
@@ -77,6 +77,22 @@ EAL_REGISTER_TAILQ(rte_vfio_tailq)/* per-process VFIO config */ static struct vfio_config vfio_cfg; +int +pci_vfio_read_config (const struct rte_intr_handle *intr_handle, +void *buf,size_t len,off_t offs) +{ +return pread64 (intr_handle->vfio_dev_fd, buf, len, +VFIO_GET_REGION_ADDR (VFIO_PCI_CONFIG_REGION_INDEX ) + offs); +} + +int +pci_vfio_write_config (const struct rte_intr_handle *intr_handle, +const void *buf,size_t len,off_t offs) +{ +return pwrite64 (intr_handle->vfio_dev_fd, buf, len, +VFIO_GET_REGION_ADDR (VFIO_PCI_CONFIG_REGION_INDEX ) + offs); +} +/* get PCI BAR number where MSI-X interrupts are */ static int pci_vfio_get_msix_bar(int fd, int *msix_bar, uint32_t *msix_table_offset,
lib/librte_eal/linuxapp/eal/rte_eal_version.map +2 -1
@@ -117,5 +117,6 @@ DPDK_2.1 { rte_eal_pci_detach; rte_memzone_free; - + rte_eal_pci_read_config; + rte_eal_pci_write_config; } DPDK_2.0;
Signature · 1 line
2.1.4
PATCH v5 2/4 bnx2x: driver core
In reply to Stephen HemmingerThis is the first of several parts for a new driver supporting Broadcom/Qlogic NetXtremeII 10 gigabit devices.
--- drivers/net/bnx2x/bnx2x.c | 11821 +++++++++++++++++++++++++++++++++++++ drivers/net/bnx2x/bnx2x.h | 1998 +++++++ drivers/net/bnx2x/bnx2x_ethdev.c | 542 ++ drivers/net/bnx2x/bnx2x_ethdev.h | 79 + drivers/net/bnx2x/bnx2x_logs.h | 51 + drivers/net/bnx2x/bnx2x_rxtx.c | 487 ++ drivers/net/bnx2x/bnx2x_rxtx.h | 85 + drivers/net/bnx2x/bnx2x_stats.c | 1619 +++++ drivers/net/bnx2x/bnx2x_stats.h | 632 ++ drivers/net/bnx2x/bnx2x_vfpf.c | 597 ++ drivers/net/bnx2x/bnx2x_vfpf.h | 315 + 11 files changed, 18226 insertions(+) create mode 100644 drivers/net/bnx2x/bnx2x.c create mode 100644 drivers/net/bnx2x/bnx2x.h create mode 100644 drivers/net/bnx2x/bnx2x_ethdev.c create mode 100644 drivers/net/bnx2x/bnx2x_ethdev.h create mode 100644 drivers/net/bnx2x/bnx2x_logs.h create mode 100644 drivers/net/bnx2x/bnx2x_rxtx.c create mode 100644 drivers/net/bnx2x/bnx2x_rxtx.h create mode 100644 drivers/net/bnx2x/bnx2x_stats.c create mode 100644 drivers/net/bnx2x/bnx2x_stats.h create mode 100644 drivers/net/bnx2x/bnx2x_vfpf.c create mode 100644 drivers/net/bnx2x/bnx2x_vfpf.h
drivers/net/bnx2x/bnx2x.c new file +11821 -0
@@ -0,0 +1,11821 @@ +/*- +* Copyright (c) 2007-2013 QLogic Corporation. All rights reserved. +* +* Eric Davis <[email protected]> +* David Christensen <[email protected]> +* Gary Zambrano <[email protected]> +* +* Copyright (c) 2013-2015 Brocade Communications Systems, Inc. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 3. Neither the name of Broadcom Corporation nor the name of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written consent. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS' +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +* THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#define BNX2X_DRIVER_VERSION "1.78.18" + +#include "bnx2x.h" +#include "bnx2x_vfpf.h" +#include "ecore_sp.h" +#include "ecore_init.h" +#include "ecore_init_ops.h" + +#include "rte_pci_dev_ids.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <zlib.h> + +static z_stream zlib_stream; + +#define EVL_VLID_MASK 0x0FFF + +#define BNX2X_DEF_SB_ATT_IDX 0x0001 +#define BNX2X_DEF_SB_IDX 0x0002 + +/* +* FLR Support - bnx2x_pf_flr_clnup() is called during nic_load in the per +* function HW initialization. +*/ +#define FLR_WAIT_USEC 10000/* 10 msecs */ +#define FLR_WAIT_INTERVAL 50/* usecs */ +#define FLR_POLL_CNT (FLR_WAIT_USEC / FLR_WAIT_INTERVAL)/* 200 */ + +struct pbf_pN_buf_regs { +int pN; +uint32_t init_crd; +uint32_t crd; +uint32_t crd_freed; +}; + +struct pbf_pN_cmd_regs { +int pN; +uint32_t lines_occup; +uint32_t lines_freed; +}; + +/* resources needed for unloading a previously loaded device */ + +#define BNX2X_PREV_WAIT_NEEDED 1 +rte_spinlock_t bnx2x_prev_mtx; +struct bnx2x_prev_list_node { +LIST_ENTRY (bnx2x_prev_list_node) node; +uint8_t bus; +uint8_t slot; +uint8_t path; +uint8_t aer; +uint8_t undi; +}; + +static LIST_HEAD(, bnx2x_prev_list_node) bnx2x_prev_list + =LIST_HEAD_INITIALIZER (bnx2x_prev_list); + +static int load_count[2 ][3 ] = { {0 } }; +/* per-path: 0-common, 1-port0, 2-port1 */ + +static void bnx2x_cmng_fns_init (struct bnx2x_softc *sc,uint8_t read_cfg, +uint8_t cmng_type); +static int bnx2x_get_cmng_fns_mode (struct bnx2x_softc *sc); +static void storm_memset_cmng (struct bnx2x_softc *sc,struct cmng_init *cmng, +uint8_t port); +static void bnx2x_set_reset_global (struct bnx2x_softc *sc); +static void bnx2x_set_reset_in_progress (struct bnx2x_softc *sc); +static uint8_t bnx2x_reset_is_done (struct bnx2x_softc *sc,int engine); +static uint8_t bnx2x_clear_pf_load (struct bnx2x_softc *sc); +static uint8_t bnx2x_chk_parity_attn (struct bnx2x_softc *sc,uint8_t * global, +uint8_t print); +static void bnx2x_int_disable (struct bnx2x_softc *sc); +static int bnx2x_release_leader_lock (struct bnx2x_softc *sc); +static void bnx2x_pf_disable (struct bnx2x_softc *sc); +static void bnx2x_update_rx_prod (struct bnx2x_softc *sc, +struct bnx2x_fastpath *fp, +uint16_t rx_bd_prod,uint16_t rx_cq_prod); +static void bnx2x_link_report (struct bnx2x_softc *sc); +void bnx2x_link_status_update (struct bnx2x_softc *sc); +static int bnx2x_alloc_mem (struct bnx2x_softc *sc); +static void bnx2x_free_mem (struct bnx2x_softc *sc); +static int bnx2x_alloc_fw_stats_mem (struct bnx2x_softc *sc); +static void bnx2x_free_fw_stats_mem (struct bnx2x_softc *sc); +static __attribute__ ((noinline)) +int bnx2x_nic_load (struct bnx2x_softc *sc); + +static int bnx2x_handle_sp_tq (struct bnx2x_softc *sc); +static void bnx2x_handle_fp_tq (struct bnx2x_fastpath *fp,int scan_fp); +static void bnx2x_periodic_stop (struct bnx2x_softc *sc); +static void bnx2x_ack_sb (struct bnx2x_softc *sc,uint8_t igu_sb_id, +uint8_t storm,uint16_t index,uint8_t op, +uint8_t update); + +int bnx2x_test_bit (int nr,volatile unsigned long *addr) +{ +int res; + +mb (); + res = ((*addr) & (1UL << nr)) !=0 ; +mb (); +return res; +} + +void bnx2x_set_bit (unsigned int nr,volatile unsigned long *addr) +{ +__sync_fetch_and_or (addr, (1UL << nr)); +} + +void bnx2x_clear_bit (int nr,volatile unsigned long *addr) +{ +__sync_fetch_and_and (addr, ~(1UL << nr)); +} + +int bnx2x_test_and_clear_bit (int nr,volatile unsigned long *addr) +{ +unsigned long mask = (1UL << nr); +return __sync_fetch_and_and (addr, ~mask) & mask; +} + +int bnx2x_cmpxchg (volatile int *addr,int old,int new) +{ +return __sync_val_compare_and_swap (addr, old, new); +} + +int +bnx2x_dma_alloc (struct bnx2x_softc *sc,size_t size,struct bnx2x_dma *dma, +const char *msg,uint32_t align) +{ +char mz_name[RTE_MEMZONE_NAMESIZE ]; +const struct rte_memzone *z; + + dma->sc = sc; +if (IS_PF (sc)) +sprintf (mz_name,"bnx2x%d_%s_%lx" ,SC_ABS_FUNC (sc), msg, +rte_get_timer_cycles ()); +else +sprintf (mz_name,"bnx2x%d_%s_%lx" , sc->pcie_device, msg, +rte_get_timer_cycles ()); + +/* Caller must take care that strlen(mz_name) < RTE_MEMZONE_NAMESIZE */ + z =rte_memzone_reserve_aligned (mz_name, (uint64_t ) (size), +rte_lcore_to_socket_id (rte_lcore_id ()), +0 , align); +if (z ==NULL ) { +PMD_DRV_LOG (ERR ,"DMA alloc failed for %s" , msg); +return -ENOMEM ; + } + dma->paddr = (uint64_t ) z->phys_addr; + dma->vaddr = z->addr; + +PMD_DRV_LOG (DEBUG ,"%s: virt=%p phys=%lx" , msg, dma->vaddr, dma->paddr); + +return 0 ; +} + +static int bnx2x_acquire_hw_lock (struct bnx2x_softc *sc,uint32_t resource) +{ +uint32_t lock_status; +uint32_t resource_bit = (1 << resource); +int func =SC_FUNC (sc); +uint32_t hw_lock_control_reg; +int cnt; + +PMD_INIT_FUNC_TRACE (); + +/* validate the resource is within range */ +if (resource >HW_LOCK_MAX_RESOURCE_VALUE ) { +PMD_DRV_LOG (NOTICE , +"resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE" , + resource); +return -1 ; + } + +if (func <=5 ) { + hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func *8 )); + }else { + hw_lock_control_reg = + (MISC_REG_DRIVER_CONTROL_7 + ((func -6 ) *8 )); + } + +/* validate the resource is not already taken */ + lock_status =REG_RD (sc, hw_lock_control_reg); +if (lock_status & resource_bit) { +PMD_DRV_LOG (NOTICE , +"resource in use (status 0x%x bit 0x%x)" , + lock_status, resource_bit); +return -1 ; + } + +/* try every 5ms for 5 seconds */ +for (cnt =0 ; cnt <1000 ; cnt++) { +REG_WR (sc, (hw_lock_control_reg +4 ), resource_bit); + lock_status =REG_RD (sc, hw_lock_control_reg); +if (lock_status & resource_bit) { +return 0 ; + } +DELAY (5000 ); + } + +PMD_DRV_LOG (NOTICE ,"Resource lock timeout!" ); +return -1 ; +} + +static int bnx2x_release_hw_lock (struct bnx2x_softc *sc,uint32_t resource) +{ +uint32_t lock_status; +uint32_t resource_bit = (1 << resource); +int func =SC_FUNC (sc); +uint32_t hw_lock_control_reg; + +PMD_INIT_FUNC_TRACE (); + +/* validate the resource is within range */ +if (resource >HW_LOCK_MAX_RESOURCE_VALUE ) { +PMD_DRV_LOG (NOTICE , +"resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE" , + resource); +return -1 ; + } + +if (func <=5 ) { + hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func *8 )); + }else { + hw_lock_control_reg = + (MISC_REG_DRIVER_CONTROL_7 + ((func -6 ) *8 )); + } + +/* validate the resource is currently taken */ + lock_status =REG_RD (sc, hw_lock_control_reg); +if (!(lock_status & resource_bit)) { +PMD_DRV_LOG (NOTICE , +"resource not in use (status 0x%x bit 0x%x)" , + lock_status, resource_bit); +return -1 ; + } + +REG_WR (sc, hw_lock_control_reg, resource_bit); +return 0 ; +} + +/* copy command into DMAE command memory and set DMAE command Go */ +void bnx2x_post_dmae (struct bnx2x_softc *sc,struct dmae_command *dmae,int idx) +{ +uint32_t cmd_offset; +uint32_t i; + + cmd_offset = (DMAE_REG_CMD_MEM + (sizeof (struct dmae_command ) * idx)); +for (i =0 ; i < ((sizeof (struct dmae_command ) /4 )); i++) { +REG_WR (sc, (cmd_offset + (i *4 )), *(((uint32_t *) dmae) + i)); + } + +REG_WR (sc, dmae_reg_go_c[idx],1 ); +} + +uint32_t bnx2x_dmae_opcode_add_comp (uint32_t opcode,uint8_t comp_type) +{ +return (opcode | ((comp_type <<DMAE_COMMAND_C_DST_SHIFT ) | +DMAE_COMMAND_C_TYPE_ENABLE )); +} + +uint32_t bnx2x_dmae_opcode_clr_src_reset (uint32_t opcode) +{ +return (opcode & ~DMAE_COMMAND_SRC_RESET ); +} + +uint32_t +bnx2x_dmae_opcode (struct bnx2x_softc * sc,uint8_t src_type,uint8_t dst_type, +uint8_t with_comp,uint8_t comp_type) +{ +uint32_t opcode =0 ; + + opcode |= ((src_type <<DMAE_COMMAND_SRC_SHIFT ) | + (dst_type <<DMAE_COMMAND_DST_SHIFT )); + + opcode |= (DMAE_COMMAND_SRC_RESET |DMAE_COMMAND_DST_RESET ); + + opcode |= (SC_PORT (sc) ?DMAE_CMD_PORT_1 :DMAE_CMD_PORT_0 ); + + opcode |= ((SC_VN (sc) <<DMAE_COMMAND_E1HVN_SHIFT ) | + (SC_VN (sc) <<DMAE_COMMAND_DST_VN_SHIFT )); + + opcode |= (DMAE_COM_SET_ERR <<DMAE_COMMAND_ERR_POLICY_SHIFT ); + +#ifdef __BIG_ENDIAN + opcode |=DMAE_CMD_ENDIANITY_B_DW_SWAP ; +#else + opcode |=DMAE_CMD_ENDIANITY_DW_SWAP ; +#endif + +if (with_comp) { + opcode =bnx2x_dmae_opcode_add_comp (opcode, comp_type); + } + +return opcode; +} + +static void +bnx2x_prep_dmae_with_comp (struct bnx2x_softc *sc,struct dmae_command *dmae, +uint8_t src_type,uint8_t dst_type) +{ +memset (dmae,0 ,sizeof (struct dmae_command )); + +/* set the opcode */ + dmae->opcode =bnx2x_dmae_opcode (sc, src_type, dst_type, + TRUE,DMAE_COMP_PCI ); + +/* fill in the completion parameters */ + dmae->comp_addr_lo =U64_LO (BNX2X_SP_MAPPING (sc, wb_comp)); + dmae->comp_addr_hi =U64_HI (BNX2X_SP_MAPPING (sc, wb_comp)); + dmae->comp_val =DMAE_COMP_VAL ; +} + +/* issue a DMAE command over the init channel and wait for completion */ +static int +bnx2x_issue_dmae_with_comp (struct bnx2x_softc *sc,struct dmae_command *dmae) +{ +uint32_t *wb_comp =BNX2X_SP (sc, wb_comp); +int timeout =CHIP_REV_IS_SLOW (sc) ?400000 :4000 ; + +/* reset completion */ + *wb_comp =0 ; + +/* post the command on the channel used for initializations */ +bnx2x_post_dmae (sc, dmae,INIT_DMAE_C (sc)); + +/* wait for completion */ +DELAY (500 ); + +while ((*wb_comp & ~DMAE_PCI_ERR_FLAG ) !=DMAE_COMP_VAL ) { +if (!timeout || + (sc->recovery_state !=BNX2X_RECOVERY_DONE && + sc->recovery_state !=BNX2X_RECOVERY_NIC_LOADING )) { +PMD_DRV_LOG (INFO ,"DMAE timeout!" ); +return DMAE_TIMEOUT ; + } + + timeout--; +DELAY (50 ); + } + +if (*wb_comp &DMAE_PCI_ERR_FLAG ) { +PMD_DRV_LOG (INFO ,"DMAE PCI error!" ); +return DMAE_PCI_ERROR ; + } + +return 0 ; +} + +void bnx2x_read_dmae (struct bnx2x_softc *sc,uint32_t src_addr,uint32_t len32) +{ +struct dmae_command dmae; +uint32_t *data; +uint32_t i; +int rc; + +if (!sc->dmae_ready) { + data =BNX2X_SP (sc, wb_data[0 ]); + +for (i =0 ; i < len32; i++) { + data[i] =REG_RD (sc, (src_addr + (i *4 ))); + } + +return ; + } + +/* set opcode and fixed command fields */ +bnx2x_prep_dmae_with_comp (sc, &dmae,DMAE_SRC_GRC ,DMAE_DST_PCI ); + +/* fill in addresses and len */ + dmae.src_addr_lo = (src_addr >>2 );/* GRC addr has dword resolution */ + dmae.src_addr_hi =0 ; + dmae.dst_addr_lo =U64_LO (BNX2X_SP_MAPPING (sc, wb_data)); + dmae.dst_addr_hi =U64_HI (BNX2X_SP_MAPPING (sc, wb_data)); + dmae.len = len32; + +/* issue the command and wait for completion */ +if ((rc =bnx2x_issue_dmae_with_comp (sc, &dmae)) !=0 ) { +rte_panic ("DMAE failed (%d)" , rc); + }; +} + +void +bnx2x_write_dmae (struct bnx2x_softc *sc,phys_addr_t dma_addr,uint32_t dst_addr, +uint32_t len32) +{ +struct dmae_command dmae; +int rc; + +if (!sc->dmae_ready) { +ecore_init_str_wr (sc, dst_addr,BNX2X_SP (sc, wb_data[0 ]), len32); +return ; + } + +/* set opcode and fixed command fields */ +bnx2x_prep_dmae_with_comp (sc, &dmae,DMAE_SRC_PCI ,DMAE_DST_GRC ); + +/* fill in addresses and len */ + dmae.src_addr_lo =U64_LO (dma_addr); + dmae.src_addr_hi =U64_HI (dma_addr); + dmae.dst_addr_lo = (dst_addr >>2 );/* GRC addr has dword resolution */ + dmae.dst_addr_hi =0 ; + dmae.len = len32; + +/* issue the command and wait for completion */ +if ((rc =bnx2x_issue_dmae_with_comp (sc, &dmae)) !=0 ) { +rte_panic ("DMAE failed (%d)" , rc); + } +} + +static void +bnx2x_write_dmae_phys_len (struct bnx2x_softc *sc,phys_addr_t phys_addr, +uint32_t addr,uint32_t len) +{ +uint32_t dmae_wr_max =DMAE_LEN32_WR_MAX (sc); +uint32_t offset =0 ; + +while (len > dmae_wr_max) { +bnx2x_write_dmae (sc, (phys_addr + offset),/* src DMA address */ + (addr + offset),/* dst GRC address */ + dmae_wr_max); + offset += (dmae_wr_max *4 ); + len -= dmae_wr_max; + } + +bnx2x_write_dmae (sc, (phys_addr + offset),/* src DMA address */ + (addr + offset),/* dst GRC address */ + len); +} + +void +bnx2x_set_ctx_validation (struct bnx2x_softc *sc,struct eth_context *cxt, +uint32_t cid) +{ +/* ustorm cxt validation */ + cxt->ustorm_ag_context.cdu_usage = +CDU_RSRVD_VALUE_TYPE_A (HW_CID (sc, cid), +CDU_REGION_NUMBER_UCM_AG , +ETH_CONNECTION_TYPE ); +/* xcontext validation */ + cxt->xstorm_ag_context.cdu_reserved = +CDU_RSRVD_VALUE_TYPE_A (HW_CID (sc, cid), +CDU_REGION_NUMBER_XCM_AG , +ETH_CONNECTION_TYPE ); +} + +static void +bnx2x_storm_memset_hc_timeout (struct bnx2x_softc *sc,uint8_t fw_sb_id, +uint8_t sb_index,uint8_t ticks) +{ +uint32_t addr = + (BAR_CSTRORM_INTMEM + +CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET (fw_sb_id, sb_index)); + +REG_WR8 (sc, addr, ticks); +} + +static void +bnx2x_storm_memset_hc_disable (struct bnx2x_softc *sc,uint16_t fw_sb_id, +uint8_t sb_index,uint8_t disable) +{ +uint32_t enable_flag = + (disable) ?0 : (1 <<HC_INDEX_DATA_HC_ENABLED_SHIFT ); +uint32_t addr = + (BAR_CSTRORM_INTMEM + +CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET (fw_sb_id, sb_index)); +uint8_t flags; + +/* clear and set */ + flags =REG_RD8 (sc, addr); + flags &= ~HC_INDEX_DATA_HC_ENABLED ; + flags |= enable_flag; +REG_WR8 (sc, addr, flags); +} + +void +bnx2x_update_coalesce_sb_index (struct bnx2x_softc *sc,uint8_t fw_sb_id, +uint8_t sb_index,uint8_t disable,uint16_t usec) +{ +uint8_t ticks = (usec /4 ); + +bnx2x_storm_memset_hc_timeout (sc, fw_sb_id, sb_index, ticks); + + disable = (disable) ?1 : ((usec) ?0 :1 ); +bnx2x_storm_memset_hc_disable (sc, fw_sb_id, sb_index, disable); +} + +uint32_t elink_cb_reg_read (struct bnx2x_softc *sc,uint32_t reg_addr) +{ +return REG_RD (sc, reg_addr); +} + +void elink_cb_reg_write (struct bnx2x_softc *sc,uint32_t reg_addr,uint32_t val) +{ +REG_WR (sc, reg_addr, val); +} + +void +elink_cb_event_log(__rte_unused struct bnx2x_softc *sc, + __rte_unused const elink_log_id_t elink_log_id, ...) +{ +PMD_DRV_LOG (DEBUG ,"ELINK EVENT LOG (%d)" , elink_log_id); +} + +static int bnx2x_set_spio (struct bnx2x_softc *sc,int spio,uint32_t mode) +{ +uint32_t spio_reg; + +/* Only 2 SPIOs are configurable */ +if ((spio !=MISC_SPIO_SPIO4 ) && (spio !=MISC_SPIO_SPIO5 )) { +PMD_DRV_LOG (NOTICE ,"Invalid SPIO 0x%x" , spio); +return -1 ; + } + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_SPIO ); + +/* read SPIO and mask except the float bits */ + spio_reg = (REG_RD (sc,MISC_REG_SPIO ) &MISC_SPIO_FLOAT ); + +switch (mode) { +case MISC_SPIO_OUTPUT_LOW : +/* clear FLOAT and set CLR */ + spio_reg &= ~(spio <<MISC_SPIO_FLOAT_POS ); + spio_reg |= (spio <<MISC_SPIO_CLR_POS ); +break ; + +case MISC_SPIO_OUTPUT_HIGH : +/* clear FLOAT and set SET */ + spio_reg &= ~(spio <<MISC_SPIO_FLOAT_POS ); + spio_reg |= (spio <<MISC_SPIO_SET_POS ); +break ; + +case MISC_SPIO_INPUT_HI_Z : +/* set FLOAT */ + spio_reg |= (spio <<MISC_SPIO_FLOAT_POS ); +break ; + +default : +break ; + } + +REG_WR (sc,MISC_REG_SPIO , spio_reg); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_SPIO ); + +return 0 ; +} + +static int bnx2x_gpio_read (struct bnx2x_softc *sc,int gpio_num,uint8_t port) +{ +/* The GPIO should be swapped if swap register is set and active */ +int gpio_port = ((REG_RD (sc,NIG_REG_PORT_SWAP ) && +REG_RD (sc,NIG_REG_STRAP_OVERRIDE )) ^ port); +int gpio_shift = gpio_num; +if (gpio_port) + gpio_shift +=MISC_REGISTERS_GPIO_PORT_SHIFT ; + +uint32_t gpio_mask = (1 << gpio_shift); +uint32_t gpio_reg; + +if (gpio_num >MISC_REGISTERS_GPIO_3 ) { +PMD_DRV_LOG (NOTICE ,"Invalid GPIO %d" , gpio_num); +return -1 ; + } + +/* read GPIO value */ + gpio_reg =REG_RD (sc,MISC_REG_GPIO ); + +/* get the requested pin value */ +return ((gpio_reg & gpio_mask) == gpio_mask) ?1 :0 ; +} + +static int +bnx2x_gpio_write (struct bnx2x_softc *sc,int gpio_num,uint32_t mode,uint8_t port) +{ +/* The GPIO should be swapped if swap register is set and active */ +int gpio_port = ((REG_RD (sc,NIG_REG_PORT_SWAP ) && +REG_RD (sc,NIG_REG_STRAP_OVERRIDE )) ^ port); +int gpio_shift = gpio_num; +if (gpio_port) + gpio_shift +=MISC_REGISTERS_GPIO_PORT_SHIFT ; + +uint32_t gpio_mask = (1 << gpio_shift); +uint32_t gpio_reg; + +if (gpio_num >MISC_REGISTERS_GPIO_3 ) { +PMD_DRV_LOG (NOTICE ,"Invalid GPIO %d" , gpio_num); +return -1 ; + } + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_GPIO ); + +/* read GPIO and mask except the float bits */ + gpio_reg = (REG_RD (sc,MISC_REG_GPIO ) &MISC_REGISTERS_GPIO_FLOAT ); + +switch (mode) { +case MISC_REGISTERS_GPIO_OUTPUT_LOW : +/* clear FLOAT and set CLR */ + gpio_reg &= ~(gpio_mask <<MISC_REGISTERS_GPIO_FLOAT_POS ); + gpio_reg |= (gpio_mask <<MISC_REGISTERS_GPIO_CLR_POS ); +break ; + +case MISC_REGISTERS_GPIO_OUTPUT_HIGH : +/* clear FLOAT and set SET */ + gpio_reg &= ~(gpio_mask <<MISC_REGISTERS_GPIO_FLOAT_POS ); + gpio_reg |= (gpio_mask <<MISC_REGISTERS_GPIO_SET_POS ); +break ; + +case MISC_REGISTERS_GPIO_INPUT_HI_Z : +/* set FLOAT */ + gpio_reg |= (gpio_mask <<MISC_REGISTERS_GPIO_FLOAT_POS ); +break ; + +default : +break ; + } + +REG_WR (sc,MISC_REG_GPIO , gpio_reg); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_GPIO ); + +return 0 ; +} + +static int +bnx2x_gpio_mult_write (struct bnx2x_softc *sc,uint8_t pins,uint32_t mode) +{ +uint32_t gpio_reg; + +/* any port swapping should be handled by caller */ + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_GPIO ); + +/* read GPIO and mask except the float bits */ + gpio_reg =REG_RD (sc,MISC_REG_GPIO ); + gpio_reg &= ~(pins <<MISC_REGISTERS_GPIO_FLOAT_POS ); + gpio_reg &= ~(pins <<MISC_REGISTERS_GPIO_CLR_POS ); + gpio_reg &= ~(pins <<MISC_REGISTERS_GPIO_SET_POS ); + +switch (mode) { +case MISC_REGISTERS_GPIO_OUTPUT_LOW : +/* set CLR */ + gpio_reg |= (pins <<MISC_REGISTERS_GPIO_CLR_POS ); +break ; + +case MISC_REGISTERS_GPIO_OUTPUT_HIGH : +/* set SET */ + gpio_reg |= (pins <<MISC_REGISTERS_GPIO_SET_POS ); +break ; + +case MISC_REGISTERS_GPIO_INPUT_HI_Z : +/* set FLOAT */ + gpio_reg |= (pins <<MISC_REGISTERS_GPIO_FLOAT_POS ); +break ; + +default : +PMD_DRV_LOG (NOTICE ,"Invalid GPIO mode assignment %d" , mode); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_GPIO ); +return -1 ; + } + +REG_WR (sc,MISC_REG_GPIO , gpio_reg); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_GPIO ); + +return 0 ; +} + +static int +bnx2x_gpio_int_write (struct bnx2x_softc *sc,int gpio_num,uint32_t mode, +uint8_t port) +{ +/* The GPIO should be swapped if swap register is set and active */ +int gpio_port = ((REG_RD (sc,NIG_REG_PORT_SWAP ) && +REG_RD (sc,NIG_REG_STRAP_OVERRIDE )) ^ port); +int gpio_shift = gpio_num; +if (gpio_port) + gpio_shift +=MISC_REGISTERS_GPIO_PORT_SHIFT ; + +uint32_t gpio_mask = (1 << gpio_shift); +uint32_t gpio_reg; + +if (gpio_num >MISC_REGISTERS_GPIO_3 ) { +PMD_DRV_LOG (NOTICE ,"Invalid GPIO %d" , gpio_num); +return -1 ; + } + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_GPIO ); + +/* read GPIO int */ + gpio_reg =REG_RD (sc,MISC_REG_GPIO_INT ); + +switch (mode) { +case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR : +/* clear SET and set CLR */ + gpio_reg &= ~(gpio_mask <<MISC_REGISTERS_GPIO_INT_SET_POS ); + gpio_reg |= (gpio_mask <<MISC_REGISTERS_GPIO_INT_CLR_POS ); +break ; + +case MISC_REGISTERS_GPIO_INT_OUTPUT_SET : +/* clear CLR and set SET */ + gpio_reg &= ~(gpio_mask <<MISC_REGISTERS_GPIO_INT_CLR_POS ); + gpio_reg |= (gpio_mask <<MISC_REGISTERS_GPIO_INT_SET_POS ); +break ; + +default : +break ; + } + +REG_WR (sc,MISC_REG_GPIO_INT , gpio_reg); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_GPIO ); + +return 0 ; +} + +uint32_t +elink_cb_gpio_read (struct bnx2x_softc * sc,uint16_t gpio_num,uint8_t port) +{ +return bnx2x_gpio_read (sc, gpio_num, port); +} + +uint8_t elink_cb_gpio_write (struct bnx2x_softc * sc,uint16_t gpio_num,uint8_t mode,/* 0=low 1=high */ +uint8_t port) +{ +return bnx2x_gpio_write (sc, gpio_num, mode, port); +} + +uint8_t +elink_cb_gpio_mult_write (struct bnx2x_softc * sc,uint8_t pins, +uint8_t mode/* 0=low 1=high */ ) +{ +return bnx2x_gpio_mult_write (sc, pins, mode); +} + +uint8_t elink_cb_gpio_int_write (struct bnx2x_softc * sc,uint16_t gpio_num,uint8_t mode,/* 0=low 1=high */ +uint8_t port) +{ +return bnx2x_gpio_int_write (sc, gpio_num, mode, port); +} + +void elink_cb_notify_link_changed (struct bnx2x_softc *sc) +{ +REG_WR (sc, (MISC_REG_AEU_GENERAL_ATTN_12 + + (SC_FUNC (sc) *sizeof (uint32_t ))),1 ); +} + +/* send the MCP a request, block until there is a reply */ +uint32_t +elink_cb_fw_command (struct bnx2x_softc *sc,uint32_t command,uint32_t param) +{ +int mb_idx =SC_FW_MB_IDX (sc); +uint32_t seq; +uint32_t rc =0 ; +uint32_t cnt =1 ; +uint8_t delay =CHIP_REV_IS_SLOW (sc) ?100 :10 ; + + seq = ++sc->fw_seq; +SHMEM_WR (sc, func_mb[mb_idx].drv_mb_param, param); +SHMEM_WR (sc, func_mb[mb_idx].drv_mb_header, (command | seq)); + +PMD_DRV_LOG (DEBUG , +"wrote command 0x%08x to FW MB param 0x%08x" , + (command | seq), param); + +/* Let the FW do it's magic. GIve it up to 5 seconds... */ +do { +DELAY (delay *1000 ); + rc =SHMEM_RD (sc, func_mb[mb_idx].fw_mb_header); + }while ((seq != (rc &FW_MSG_SEQ_NUMBER_MASK )) && (cnt++ <500 )); + +/* is this a reply to our command? */ +if (seq == (rc &FW_MSG_SEQ_NUMBER_MASK )) { + rc &=FW_MSG_CODE_MASK ; + }else { +/* Ruh-roh! */ +PMD_DRV_LOG (NOTICE ,"FW failed to respond!" ); + rc =0 ; + } + +return rc; +} + +static uint32_t +bnx2x_fw_command (struct bnx2x_softc *sc,uint32_t command,uint32_t param) +{ +return elink_cb_fw_command (sc, command, param); +} + +static void +__storm_memset_dma_mapping (struct bnx2x_softc *sc,uint32_t addr, +phys_addr_t mapping) +{ +REG_WR (sc, addr,U64_LO (mapping)); +REG_WR (sc, (addr +4 ),U64_HI (mapping)); +} + +static void +storm_memset_spq_addr (struct bnx2x_softc *sc,phys_addr_t mapping, +uint16_t abs_fid) +{ +uint32_t addr = (XSEM_REG_FAST_MEMORY + +XSTORM_SPQ_PAGE_BASE_OFFSET (abs_fid)); +__storm_memset_dma_mapping (sc, addr, mapping); +} + +static void +storm_memset_vf_to_pf (struct bnx2x_softc *sc,uint16_t abs_fid,uint16_t pf_id) +{ +REG_WR8 (sc, (BAR_XSTRORM_INTMEM +XSTORM_VF_TO_PF_OFFSET (abs_fid)), + pf_id); +REG_WR8 (sc, (BAR_CSTRORM_INTMEM +CSTORM_VF_TO_PF_OFFSET (abs_fid)), + pf_id); +REG_WR8 (sc, (BAR_TSTRORM_INTMEM +TSTORM_VF_TO_PF_OFFSET (abs_fid)), + pf_id); +REG_WR8 (sc, (BAR_USTRORM_INTMEM +USTORM_VF_TO_PF_OFFSET (abs_fid)), + pf_id); +} + +static void +storm_memset_func_en (struct bnx2x_softc *sc,uint16_t abs_fid,uint8_t enable) +{ +REG_WR8 (sc, (BAR_XSTRORM_INTMEM +XSTORM_FUNC_EN_OFFSET (abs_fid)), + enable); +REG_WR8 (sc, (BAR_CSTRORM_INTMEM +CSTORM_FUNC_EN_OFFSET (abs_fid)), + enable); +REG_WR8 (sc, (BAR_TSTRORM_INTMEM +TSTORM_FUNC_EN_OFFSET (abs_fid)), + enable); +REG_WR8 (sc, (BAR_USTRORM_INTMEM +USTORM_FUNC_EN_OFFSET (abs_fid)), + enable); +} + +static void +storm_memset_eq_data (struct bnx2x_softc *sc,struct event_ring_data *eq_data, +uint16_t pfid) +{ +uint32_t addr; +size_t size; + + addr = (BAR_CSTRORM_INTMEM +CSTORM_EVENT_RING_DATA_OFFSET (pfid)); + size =sizeof (struct event_ring_data ); +ecore_storm_memset_struct (sc, addr, size, (uint32_t *) eq_data); +} + +static void +storm_memset_eq_prod (struct bnx2x_softc *sc,uint16_t eq_prod,uint16_t pfid) +{ +uint32_t addr = (BAR_CSTRORM_INTMEM + +CSTORM_EVENT_RING_PROD_OFFSET (pfid)); +REG_WR16 (sc, addr, eq_prod); +} + +/* +* Post a slowpath command. +* +* A slowpath command is used to propogate a configuration change through +* the controller in a controlled manner, allowing each STORM processor and +* other H/W blocks to phase in the change. The commands sent on the +* slowpath are referred to as ramrods. Depending on the ramrod used the +* completion of the ramrod will occur in different ways. Here's a +* breakdown of ramrods and how they complete: +* +* RAMROD_CMD_ID_ETH_PORT_SETUP +* Used to setup the leading connection on a port. Completes on the +* Receive Completion Queue (RCQ) of that port (typically fp[0]). +* +* RAMROD_CMD_ID_ETH_CLIENT_SETUP +* Used to setup an additional connection on a port. Completes on the +* RCQ of the multi-queue/RSS connection being initialized. +* +* RAMROD_CMD_ID_ETH_STAT_QUERY +* Used to force the storm processors to update the statistics database +* in host memory. This ramrod is send on the leading connection CID and +* completes as an index increment of the CSTORM on the default status +* block. +* +* RAMROD_CMD_ID_ETH_UPDATE +* Used to update the state of the leading connection, usually to udpate +* the RSS indirection table. Completes on the RCQ of the leading +* connection. (Not currently used under FreeBSD until OS support becomes +* available.) +* +* RAMROD_CMD_ID_ETH_HALT +* Used when tearing down a connection prior to driver unload. Completes +* on the RCQ of the multi-queue/RSS connection being torn down. Don't +* use this on the leading connection. +* +* RAMROD_CMD_ID_ETH_SET_MAC +* Sets the Unicast/Broadcast/Multicast used by the port. Completes on +* the RCQ of the leading connection. +* +* RAMROD_CMD_ID_ETH_CFC_DEL +* Used when tearing down a conneciton prior to driver unload. Completes +* on the RCQ of the leading connection (since the current connection +* has been completely removed from controller memory). +* +* RAMROD_CMD_ID_ETH_PORT_DEL +* Used to tear down the leading connection prior to driver unload, +* typically fp[0]. Completes as an index increment of the CSTORM on the +* default status block. +* +* RAMROD_CMD_ID_ETH_FORWARD_SETUP +* Used for connection offload. Completes on the RCQ of the multi-queue +* RSS connection that is being offloaded. (Not currently used under +* FreeBSD.) +* +* There can only be one command pending per function. +* +* Returns: +* 0 = Success, !0 = Failure. +*/ + +/* must be called under the spq lock */ +static inline struct eth_spe *bnx2x_sp_get_next (struct bnx2x_softc *sc) +{ +struct eth_spe *next_spe = sc->spq_prod_bd; + +if (sc->spq_prod_bd == sc->spq_last_bd) { +/* wrap back to the first eth_spq */ + sc->spq_prod_bd = sc->spq; + sc->spq_prod_idx =0 ; + }else { + sc->spq_prod_bd++; + sc->spq_prod_idx++; + } + +return next_spe; +} + +/* must be called under the spq lock */ +static void bnx2x_sp_prod_update (struct bnx2x_softc *sc) +{ +int func =SC_FUNC (sc); + +/* +* Make sure that BD data is updated before writing the producer. +* BD data is written to the memory, the producer is read from the +* memory, thus we need a full memory barrier to ensure the ordering. +*/ +mb (); + +REG_WR16 (sc, (BAR_XSTRORM_INTMEM +XSTORM_SPQ_PROD_OFFSET (func)), + sc->spq_prod_idx); + +mb (); +} + +/** +* bnx2x_is_contextless_ramrod - check if the current command ends on EQ +* +* @cmd: command to check +* @cmd_type: command type +*/ +static int bnx2x_is_contextless_ramrod (int cmd,int cmd_type) +{ +if ((cmd_type ==NONE_CONNECTION_TYPE ) || + (cmd ==RAMROD_CMD_ID_ETH_FORWARD_SETUP ) || + (cmd ==RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES ) || + (cmd ==RAMROD_CMD_ID_ETH_FILTER_RULES ) || + (cmd ==RAMROD_CMD_ID_ETH_MULTICAST_RULES ) || + (cmd ==RAMROD_CMD_ID_ETH_SET_MAC ) || + (cmd ==RAMROD_CMD_ID_ETH_RSS_UPDATE )) { +return TRUE; + }else { +return FALSE; + } +} + +/** +* bnx2x_sp_post - place a single command on an SP ring +* +* @sc: driver handle +* @command: command to place (e.g. SETUP, FILTER_RULES, etc.) +* @cid: SW CID the command is related to +* @data_hi: command private data address (high 32 bits) +* @data_lo: command private data address (low 32 bits) +* @cmd_type: command type (e.g. NONE, ETH) +* +* SP data is handled as if it's always an address pair, thus data fields are +* not swapped to little endian in upper functions. Instead this function swaps +* data as if it's two uint32 fields. +*/ +int +bnx2x_sp_post (struct bnx2x_softc *sc,int command,int cid,uint32_t data_hi, +uint32_t data_lo,int cmd_type) +{ +struct eth_spe *spe; +uint16_t type; +int common; + + common =bnx2x_is_contextless_ramrod (command, cmd_type); + +if (common) { +if (!atomic_load_acq_long (&sc->eq_spq_left)) { +PMD_DRV_LOG (INFO ,"EQ ring is full!" ); +return -1 ; + } + }else { +if (!atomic_load_acq_long (&sc->cq_spq_left)) { +PMD_DRV_LOG (INFO ,"SPQ ring is full!" ); +return -1 ; + } + } + + spe =bnx2x_sp_get_next (sc); + +/* CID needs port number to be encoded int it */ + spe->hdr.conn_and_cmd_data = +htole32 ((command <<SPE_HDR_CMD_ID_SHIFT ) |HW_CID (sc, cid)); + + type = (cmd_type <<SPE_HDR_CONN_TYPE_SHIFT ) &SPE_HDR_CONN_TYPE ; + +/* TBD: Check if it works for VFs */ + type |= ((SC_FUNC (sc) <<SPE_HDR_FUNCTION_ID_SHIFT ) & +SPE_HDR_FUNCTION_ID ); + + spe->hdr.type =htole16 (type); + + spe->data.update_data_addr.hi =htole32 (data_hi); + spe->data.update_data_addr.lo =htole32 (data_lo); + +/* +* It's ok if the actual decrement is issued towards the memory +* somewhere between the lock and unlock. Thus no more explict +* memory barrier is needed. +*/ +if (common) { +atomic_subtract_acq_long (&sc->eq_spq_left,1 ); + }else { +atomic_subtract_acq_long (&sc->cq_spq_left,1 ); + } + +PMD_DRV_LOG (DEBUG , +"SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x" +"data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)" , + sc->spq_prod_idx, + (uint32_t )U64_HI (sc->spq_dma.paddr), + (uint32_t ) (U64_LO (sc->spq_dma.paddr) + + (uint8_t *) sc->spq_prod_bd - + (uint8_t *) sc->spq), command, common, +HW_CID (sc, cid), data_hi, data_lo, type, +atomic_load_acq_long (&sc->cq_spq_left), +atomic_load_acq_long (&sc->eq_spq_left)); + +bnx2x_sp_prod_update (sc); + +return 0 ; +} + +static void bnx2x_drv_pulse (struct bnx2x_softc *sc) +{ +SHMEM_WR (sc, func_mb[SC_FW_MB_IDX (sc)].drv_pulse_mb, + sc->fw_drv_pulse_wr_seq); +} + +static int bnx2x_tx_queue_has_work (const struct bnx2x_fastpath *fp) +{ +uint16_t hw_cons; +struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index]; + +if (unlikely (!txq)) { +PMD_TX_LOG (ERR ,"ERROR: TX queue is NULL" ); +return 0 ; + } + +mb ();/* status block fields can change */ + hw_cons =le16toh (*fp->tx_cons_sb); +return (hw_cons != txq->tx_pkt_head); +} + +static uint8_t bnx2x_has_tx_work (struct bnx2x_fastpath *fp) +{ +/* expand this for multi-cos if ever supported */ +return bnx2x_tx_queue_has_work (fp); +} + +static int bnx2x_has_rx_work (struct bnx2x_fastpath *fp) +{ +uint16_t rx_cq_cons_sb; +struct bnx2x_rx_queue *rxq; + rxq = fp->sc->rx_queues[fp->index]; +if (unlikely (!rxq)) { +PMD_RX_LOG (ERR ,"ERROR: RX queue is NULL" ); +return 0 ; + } + +mb ();/* status block fields can change */ + rx_cq_cons_sb =le16toh (*fp->rx_cq_cons_sb); +if (unlikely ((rx_cq_cons_sb &MAX_RCQ_ENTRIES (rxq)) == +MAX_RCQ_ENTRIES (rxq))) + rx_cq_cons_sb++; +return (rxq->rx_cq_head != rx_cq_cons_sb); +} + +static void +bnx2x_sp_event (struct bnx2x_softc *sc,struct bnx2x_fastpath *fp, +union eth_rx_cqe *rr_cqe) +{ +#ifdef RTE_LIBRTE_BNX2X_DEBUG +int cid =SW_CID (rr_cqe->ramrod_cqe.conn_and_cmd_data); +#endif +int command =CQE_CMD (rr_cqe->ramrod_cqe.conn_and_cmd_data); +enum ecore_queue_cmd drv_cmd =ECORE_Q_CMD_MAX ; +struct ecore_queue_sp_obj *q_obj = &BNX2X_SP_OBJ (sc, fp).q_obj; + +PMD_DRV_LOG (DEBUG , +"fp=%d cid=%d got ramrod #%d state is %x type is %d" , + fp->index, cid, command, sc->state, + rr_cqe->ramrod_cqe.ramrod_type); + +switch (command) { +case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE ): +PMD_DRV_LOG (DEBUG ,"got UPDATE ramrod. CID %d" , cid); + drv_cmd =ECORE_Q_CMD_UPDATE ; +break ; + +case (RAMROD_CMD_ID_ETH_CLIENT_SETUP ): +PMD_DRV_LOG (DEBUG ,"got MULTI[%d] setup ramrod" , cid); + drv_cmd =ECORE_Q_CMD_SETUP ; +break ; + +case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP ): +PMD_DRV_LOG (DEBUG ,"got MULTI[%d] tx-only setup ramrod" , cid); + drv_cmd =ECORE_Q_CMD_SETUP_TX_ONLY ; +break ; + +case (RAMROD_CMD_ID_ETH_HALT ): +PMD_DRV_LOG (DEBUG ,"got MULTI[%d] halt ramrod" , cid); + drv_cmd =ECORE_Q_CMD_HALT ; +break ; + +case (RAMROD_CMD_ID_ETH_TERMINATE ): +PMD_DRV_LOG (DEBUG ,"got MULTI[%d] teminate ramrod" , cid); + drv_cmd =ECORE_Q_CMD_TERMINATE ; +break ; + +case (RAMROD_CMD_ID_ETH_EMPTY ): +PMD_DRV_LOG (DEBUG ,"got MULTI[%d] empty ramrod" , cid); + drv_cmd =ECORE_Q_CMD_EMPTY ; +break ; + +default : +PMD_DRV_LOG (DEBUG , +"ERROR: unexpected MC reply (%d)" +"on fp[%d]" , command, fp->index); +return ; + } + +if ((drv_cmd !=ECORE_Q_CMD_MAX ) && + q_obj->complete_cmd (sc, q_obj, drv_cmd)) { +/* +* q_obj->complete_cmd() failure means that this was +* an unexpected completion. +* +* In this case we don't want to increase the sc->spq_left +* because apparently we haven't sent this command the first +* place. +*/ +// rte_panic("Unexpected SP completion"); +return ; + } + +atomic_add_acq_long (&sc->cq_spq_left,1 ); + +PMD_DRV_LOG (DEBUG ,"sc->cq_spq_left 0x%lx" , +atomic_load_acq_long (&sc->cq_spq_left)); +} + +static uint8_t bnx2x_rxeof (struct bnx2x_softc *sc,struct bnx2x_fastpath *fp) +{ +struct bnx2x_rx_queue *rxq; +uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons; +uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod; + + rxq = sc->rx_queues[fp->index]; +if (!rxq) { +PMD_RX_LOG (ERR ,"RX queue %d is NULL" , fp->index); +return 0 ; + } + +/* CQ "next element" is of the size of the regular element */ + hw_cq_cons =le16toh (*fp->rx_cq_cons_sb); +if (unlikely ((hw_cq_cons &USABLE_RCQ_ENTRIES_PER_PAGE ) == +USABLE_RCQ_ENTRIES_PER_PAGE )) { + hw_cq_cons++; + } + + bd_cons = rxq->rx_bd_head; + bd_prod = rxq->rx_bd_tail; + bd_prod_fw = bd_prod; + sw_cq_cons = rxq->rx_cq_head; + sw_cq_prod = rxq->rx_cq_tail; + +/* +* Memory barrier necessary as speculative reads of the rx +* buffer can be ahead of the index in the status block +*/ +rmb (); + +while (sw_cq_cons != hw_cq_cons) { +union eth_rx_cqe *cqe; +struct eth_fast_path_rx_cqe *cqe_fp; +uint8_t cqe_fp_flags; +enum eth_rx_cqe_type cqe_fp_type; + + comp_ring_cons =RCQ_ENTRY (sw_cq_cons, rxq); + bd_prod =RX_BD (bd_prod, rxq); + bd_cons =RX_BD (bd_cons, rxq); + + cqe = &rxq->cq_ring[comp_ring_cons]; + cqe_fp = &cqe->fast_path_cqe; + cqe_fp_flags = cqe_fp->type_error_flags; + cqe_fp_type = cqe_fp_flags Ð_FAST_PATH_RX_CQE_TYPE ; + +/* is this a slowpath msg? */ +if (CQE_TYPE_SLOW (cqe_fp_type)) { +bnx2x_sp_event (sc, fp, cqe); + goto next_cqe; + } + +/* is this an error packet? */ +if (unlikely (cqe_fp_flags & +ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG )) { +PMD_RX_LOG (DEBUG ,"flags 0x%x rx packet %u" , + cqe_fp_flags, sw_cq_cons); + goto next_rx; + } + +PMD_RX_LOG (DEBUG ,"Dropping fastpath called from attn poller!" ); + +next_rx: + bd_cons =NEXT_RX_BD (bd_cons); + bd_prod =NEXT_RX_BD (bd_prod); + bd_prod_fw =NEXT_RX_BD (bd_prod_fw); + +next_cqe: + sw_cq_prod =NEXT_RCQ_IDX (sw_cq_prod); + sw_cq_cons =NEXT_RCQ_IDX (sw_cq_cons); + + }/* while work to do */ + + rxq->rx_bd_head = bd_cons; + rxq->rx_bd_tail = bd_prod_fw; + rxq->rx_cq_head = sw_cq_cons; + rxq->rx_cq_tail = sw_cq_prod; + +/* Update producers */ +bnx2x_update_rx_prod (sc, fp, bd_prod_fw, sw_cq_prod); + +return (sw_cq_cons != hw_cq_cons); +} + +static uint16_t +bnx2x_free_tx_pkt(__rte_unused struct bnx2x_fastpath *fp, struct bnx2x_tx_queue *txq, +uint16_t pkt_idx,uint16_t bd_idx) +{ +struct eth_tx_start_bd *tx_start_bd = + &txq->tx_ring[TX_BD (bd_idx, txq)].start_bd; +uint16_t nbd =rte_le_to_cpu_16 (tx_start_bd->nbd); +struct rte_mbuf *tx_mbuf = txq->sw_ring[TX_BD (pkt_idx, txq)]; + +if (likely (tx_mbuf !=NULL )) { +rte_pktmbuf_free (tx_mbuf); + }else { +PMD_RX_LOG (ERR ,"fp[%02d] lost mbuf %lu" , + fp->index,TX_BD (pkt_idx, txq)); + } + + txq->sw_ring[TX_BD (pkt_idx, txq)] =NULL ; + txq->nb_tx_avail += nbd; + +while (nbd--) + bd_idx =NEXT_TX_BD (bd_idx); + +return bd_idx; +} + +/* processes transmit completions */ +uint8_t bnx2x_txeof(__rte_unused struct bnx2x_softc * sc, struct bnx2x_fastpath * fp) +{ +uint16_t bd_cons, hw_cons, sw_cons; + __rte_unused uint16_t tx_bd_avail; + +struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index]; + +if (unlikely (!txq)) { +PMD_TX_LOG (ERR ,"ERROR: TX queue is NULL" ); +return 0 ; + } + + bd_cons = txq->tx_bd_head; + hw_cons =rte_le_to_cpu_16 (*fp->tx_cons_sb); + sw_cons = txq->tx_pkt_head; + +while (sw_cons != hw_cons) { + bd_cons =bnx2x_free_tx_pkt (fp, txq, sw_cons, bd_cons); + sw_cons++; + } + + txq->tx_pkt_head = sw_cons; + txq->tx_bd_head = bd_cons; + + tx_bd_avail = txq->nb_tx_avail; + +PMD_TX_LOG (DEBUG ,"fp[%02d] avail=%u cons_sb=%u, " +"pkt_head=%u pkt_tail=%u bd_head=%u bd_tail=%u" , + fp->index, tx_bd_avail, hw_cons, + txq->tx_pkt_head, txq->tx_pkt_tail, + txq->tx_bd_head, txq->tx_bd_tail); +return TRUE; +} + +static void bnx2x_drain_tx_queues (struct bnx2x_softc *sc) +{ +struct bnx2x_fastpath *fp; +int i, count; + +/* wait until all TX fastpath tasks have completed */ +for (i =0 ; i < sc->num_queues; i++) { + fp = &sc->fp[i]; + + count =1000 ; + +while (bnx2x_has_tx_work (fp)) { +bnx2x_txeof (sc, fp); + +if (count ==0 ) { +PMD_TX_LOG (ERR , +"Timeout waiting for fp[%d] " +"transmits to complete!" , i); +rte_panic ("tx drain failure" ); +return ; + } + + count--; +DELAY (1000 ); +rmb (); + } + } + +return ; +} + +static int +bnx2x_del_all_macs (struct bnx2x_softc *sc,struct ecore_vlan_mac_obj *mac_obj, +int mac_type,uint8_t wait_for_comp) +{ +unsigned long ramrod_flags =0 , vlan_mac_flags =0 ; +int rc; + +/* wait for completion of requested */ +if (wait_for_comp) { +bnx2x_set_bit (RAMROD_COMP_WAIT , &ramrod_flags); + } + +/* Set the mac type of addresses we want to clear */ +bnx2x_set_bit (mac_type, &vlan_mac_flags); + + rc = mac_obj->delete_all (sc, mac_obj, &vlan_mac_flags, &ramrod_flags); +if (rc <0 ) +PMD_DRV_LOG (ERR ,"Failed to delete MACs (%d)" , rc); + +return rc; +} + +int +bnx2x_fill_accept_flags (struct bnx2x_softc *sc,uint32_t rx_mode, +unsigned long *rx_accept_flags, +unsigned long *tx_accept_flags) +{ +/* Clear the flags first */ + *rx_accept_flags =0 ; + *tx_accept_flags =0 ; + +switch (rx_mode) { +case BNX2X_RX_MODE_NONE : +/* +* 'drop all' supersedes any accept flags that may have been +* passed to the function. +*/ +break ; + +case BNX2X_RX_MODE_NORMAL : +bnx2x_set_bit (ECORE_ACCEPT_UNICAST , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_MULTICAST , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_BROADCAST , rx_accept_flags); + +/* internal switching mode */ +bnx2x_set_bit (ECORE_ACCEPT_UNICAST , tx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_MULTICAST , tx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_BROADCAST , tx_accept_flags); + +break ; + +case BNX2X_RX_MODE_ALLMULTI : +bnx2x_set_bit (ECORE_ACCEPT_UNICAST , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_ALL_MULTICAST , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_BROADCAST , rx_accept_flags); + +/* internal switching mode */ +bnx2x_set_bit (ECORE_ACCEPT_UNICAST , tx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_ALL_MULTICAST , tx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_BROADCAST , tx_accept_flags); + +break ; + +case BNX2X_RX_MODE_PROMISC : +/* +* According to deffinition of SI mode, iface in promisc mode +* should receive matched and unmatched (in resolution of port) +* unicast packets. +*/ +bnx2x_set_bit (ECORE_ACCEPT_UNMATCHED , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_UNICAST , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_ALL_MULTICAST , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_BROADCAST , rx_accept_flags); + +/* internal switching mode */ +bnx2x_set_bit (ECORE_ACCEPT_ALL_MULTICAST , tx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_BROADCAST , tx_accept_flags); + +if (IS_MF_SI (sc)) { +bnx2x_set_bit (ECORE_ACCEPT_ALL_UNICAST , tx_accept_flags); + }else { +bnx2x_set_bit (ECORE_ACCEPT_UNICAST , tx_accept_flags); + } + +break ; + +default : +PMD_RX_LOG (ERR ,"Unknown rx_mode (%d)" , rx_mode); +return -1 ; + } + +/* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */ +if (rx_mode !=BNX2X_RX_MODE_NONE ) { +bnx2x_set_bit (ECORE_ACCEPT_ANY_VLAN , rx_accept_flags); +bnx2x_set_bit (ECORE_ACCEPT_ANY_VLAN , tx_accept_flags); + } + +return 0 ; +} + +static int +bnx2x_set_q_rx_mode (struct bnx2x_softc *sc,uint8_t cl_id, +unsigned long rx_mode_flags, +unsigned long rx_accept_flags, +unsigned long tx_accept_flags,unsigned long ramrod_flags) +{ +struct ecore_rx_mode_ramrod_params ramrod_param; +int rc; + +memset (&ramrod_param,0 ,sizeof (ramrod_param)); + +/* Prepare ramrod parameters */ + ramrod_param.cid =0 ; + ramrod_param.cl_id = cl_id; + ramrod_param.rx_mode_obj = &sc->rx_mode_obj; + ramrod_param.func_id =SC_FUNC (sc); + + ramrod_param.pstate = &sc->sp_state; + ramrod_param.state =ECORE_FILTER_RX_MODE_PENDING ; + + ramrod_param.rdata =BNX2X_SP (sc, rx_mode_rdata); + ramrod_param.rdata_mapping = + (phys_addr_t) ((void *)BNX2X_SP_MAPPING (sc, rx_mode_rdata)), +bnx2x_set_bit (ECORE_FILTER_RX_MODE_PENDING , &sc->sp_state); + + ramrod_param.ramrod_flags = ramrod_flags; + ramrod_param.rx_mode_flags = rx_mode_flags; + + ramrod_param.rx_accept_flags = rx_accept_flags; + ramrod_param.tx_accept_flags = tx_accept_flags; + + rc =ecore_config_rx_mode (sc, &ramrod_param); +if (rc <0 ) { +PMD_RX_LOG (ERR ,"Set rx_mode %d failed" , sc->rx_mode); +return rc; + } + +return 0 ; +} + +int bnx2x_set_storm_rx_mode (struct bnx2x_softc *sc) +{ +unsigned long rx_mode_flags =0 , ramrod_flags =0 ; +unsigned long rx_accept_flags =0 , tx_accept_flags =0 ; +int rc; + + rc =bnx2x_fill_accept_flags (sc, sc->rx_mode, &rx_accept_flags, + &tx_accept_flags); +if (rc) { +return rc; + } + +bnx2x_set_bit (RAMROD_RX , &ramrod_flags); +bnx2x_set_bit (RAMROD_TX , &ramrod_flags); +bnx2x_set_bit (RAMROD_COMP_WAIT , &ramrod_flags); + +return bnx2x_set_q_rx_mode (sc, sc->fp[0 ].cl_id, rx_mode_flags, + rx_accept_flags, tx_accept_flags, + ramrod_flags); +} + +/* returns the "mcp load_code" according to global load_count array */ +static int bnx2x_nic_load_no_mcp (struct bnx2x_softc *sc) +{ +int path =SC_PATH (sc); +int port =SC_PORT (sc); + +PMD_DRV_LOG (INFO ,"NO MCP - load counts[%d] %d, %d, %d" , + path, load_count[path][0 ], load_count[path][1 ], + load_count[path][2 ]); + + load_count[path][0 ]++; + load_count[path][1 + port]++; +PMD_DRV_LOG (INFO ,"NO MCP - new load counts[%d] %d, %d, %d" , + path, load_count[path][0 ], load_count[path][1 ], + load_count[path][2 ]); +if (load_count[path][0 ] ==1 ) +return FW_MSG_CODE_DRV_LOAD_COMMON ; +else if (load_count[path][1 + port] ==1 ) +return FW_MSG_CODE_DRV_LOAD_PORT ; +else +return FW_MSG_CODE_DRV_LOAD_FUNCTION ; +} + +/* returns the "mcp load_code" according to global load_count array */ +static int bnx2x_nic_unload_no_mcp (struct bnx2x_softc *sc) +{ +int port =SC_PORT (sc); +int path =SC_PATH (sc); + +PMD_DRV_LOG (INFO ,"NO MCP - load counts[%d] %d, %d, %d" , + path, load_count[path][0 ], load_count[path][1 ], + load_count[path][2 ]); + load_count[path][0 ]--; + load_count[path][1 + port]--; +PMD_DRV_LOG (INFO ,"NO MCP - new load counts[%d] %d, %d, %d" , + path, load_count[path][0 ], load_count[path][1 ], + load_count[path][2 ]); +if (load_count[path][0 ] ==0 ) { +return FW_MSG_CODE_DRV_UNLOAD_COMMON ; + }else if (load_count[path][1 + port] ==0 ) { +return FW_MSG_CODE_DRV_UNLOAD_PORT ; + }else { +return FW_MSG_CODE_DRV_UNLOAD_FUNCTION ; + } +} + +/* request unload mode from the MCP: COMMON, PORT or FUNCTION */ +static uint32_t bnx2x_send_unload_req (struct bnx2x_softc *sc,int unload_mode) +{ +uint32_t reset_code =0 ; + +/* Select the UNLOAD request mode */ +if (unload_mode ==UNLOAD_NORMAL ) { + reset_code =DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS ; + }else { + reset_code =DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS ; + } + +/* Send the request to the MCP */ +if (!BNX2X_NOMCP (sc)) { + reset_code =bnx2x_fw_command (sc, reset_code,0 ); + }else { + reset_code =bnx2x_nic_unload_no_mcp (sc); + } + +return reset_code; +} + +/* send UNLOAD_DONE command to the MCP */ +static void bnx2x_send_unload_done (struct bnx2x_softc *sc,uint8_t keep_link) +{ +uint32_t reset_param = + keep_link ?DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET :0 ; + +/* Report UNLOAD_DONE to MCP */ +if (!BNX2X_NOMCP (sc)) { +bnx2x_fw_command (sc,DRV_MSG_CODE_UNLOAD_DONE , reset_param); + } +} + +static int bnx2x_func_wait_started (struct bnx2x_softc *sc) +{ +int tout =50 ; + +if (!sc->port.pmf) { +return 0 ; + } + +/* +* (assumption: No Attention from MCP at this stage) +* PMF probably in the middle of TX disable/enable transaction +* 1. Sync IRS for default SB +* 2. Sync SP queue - this guarantees us that attention handling started +* 3. Wait, that TX disable/enable transaction completes +* +* 1+2 guarantee that if DCBX attention was scheduled it already changed +* pending bit of transaction from STARTED-->TX_STOPPED, if we already +* received completion for the transaction the state is TX_STOPPED. +* State will return to STARTED after completion of TX_STOPPED-->STARTED +* transaction. +*/ + +while (ecore_func_get_state (sc, &sc->func_obj) != +ECORE_F_STATE_STARTED && tout--) { +DELAY (20000 ); + } + +if (ecore_func_get_state (sc, &sc->func_obj) !=ECORE_F_STATE_STARTED ) { +/* +* Failed to complete the transaction in a "good way" +* Force both transactions with CLR bit. +*/ +struct ecore_func_state_params func_params = {NULL }; + +PMD_DRV_LOG (NOTICE ,"Unexpected function state! " +"Forcing STARTED-->TX_STOPPED-->STARTED" ); + + func_params.f_obj = &sc->func_obj; +bnx2x_set_bit (RAMROD_DRV_CLR_ONLY , &func_params.ramrod_flags); + +/* STARTED-->TX_STOPPED */ + func_params.cmd =ECORE_F_CMD_TX_STOP ; +ecore_func_state_change (sc, &func_params); + +/* TX_STOPPED-->STARTED */ + func_params.cmd =ECORE_F_CMD_TX_START ; +return ecore_func_state_change (sc, &func_params); + } + +return 0 ; +} + +static int bnx2x_stop_queue (struct bnx2x_softc *sc,int index) +{ +struct bnx2x_fastpath *fp = &sc->fp[index]; +struct ecore_queue_state_params q_params = {NULL }; +int rc; + +PMD_DRV_LOG (DEBUG ,"stopping queue %d cid %d" , index, fp->index); + + q_params.q_obj = &sc->sp_objs[fp->index].q_obj; +/* We want to wait for completion in this context */ +bnx2x_set_bit (RAMROD_COMP_WAIT , &q_params.ramrod_flags); + +/* Stop the primary connection: */ + +/* ...halt the connection */ + q_params.cmd =ECORE_Q_CMD_HALT ; + rc =ecore_queue_state_change (sc, &q_params); +if (rc) { +return rc; + } + +/* ...terminate the connection */ + q_params.cmd =ECORE_Q_CMD_TERMINATE ; +memset (&q_params.params.terminate,0 , +sizeof (q_params.params.terminate)); + q_params.params.terminate.cid_index =FIRST_TX_COS_INDEX ; + rc =ecore_queue_state_change (sc, &q_params); +if (rc) { +return rc; + } + +/* ...delete cfc entry */ + q_params.cmd =ECORE_Q_CMD_CFC_DEL ; +memset (&q_params.params.cfc_del,0 ,sizeof (q_params.params.cfc_del)); + q_params.params.cfc_del.cid_index =FIRST_TX_COS_INDEX ; +return ecore_queue_state_change (sc, &q_params); +} + +/* wait for the outstanding SP commands */ +static uint8_t bnx2x_wait_sp_comp (struct bnx2x_softc *sc,unsigned long mask) +{ +unsigned long tmp; +int tout =5000 ;/* wait for 5 secs tops */ + +while (tout--) { +mb (); +if (!(atomic_load_acq_long (&sc->sp_state) & mask)) { +return TRUE; + } + +DELAY (1000 ); + } + +mb (); + + tmp =atomic_load_acq_long (&sc->sp_state); +if (tmp & mask) { +PMD_DRV_LOG (INFO ,"Filtering completion timed out: " +"sp_state 0x%lx, mask 0x%lx" , tmp, mask); +return FALSE; + } + +return FALSE; +} + +static int bnx2x_func_stop (struct bnx2x_softc *sc) +{ +struct ecore_func_state_params func_params = {NULL }; +int rc; + +/* prepare parameters for function state transitions */ +bnx2x_set_bit (RAMROD_COMP_WAIT , &func_params.ramrod_flags); + func_params.f_obj = &sc->func_obj; + func_params.cmd =ECORE_F_CMD_STOP ; + +/* +* Try to stop the function the 'good way'. If it fails (in case +* of a parity error during bnx2x_chip_cleanup()) and we are +* not in a debug mode, perform a state transaction in order to +* enable further HW_RESET transaction. +*/ + rc =ecore_func_state_change (sc, &func_params); +if (rc) { +PMD_DRV_LOG (NOTICE ,"FUNC_STOP ramrod failed. " +"Running a dry transaction" ); +bnx2x_set_bit (RAMROD_DRV_CLR_ONLY , &func_params.ramrod_flags); +return ecore_func_state_change (sc, &func_params); + } + +return 0 ; +} + +static int bnx2x_reset_hw (struct bnx2x_softc *sc,uint32_t load_code) +{ +struct ecore_func_state_params func_params = {NULL }; + +/* Prepare parameters for function state transitions */ +bnx2x_set_bit (RAMROD_COMP_WAIT , &func_params.ramrod_flags); + + func_params.f_obj = &sc->func_obj; + func_params.cmd =ECORE_F_CMD_HW_RESET ; + + func_params.params.hw_init.load_phase = load_code; + +return ecore_func_state_change (sc, &func_params); +} + +static void bnx2x_int_disable_sync (struct bnx2x_softc *sc,int disable_hw) +{ +if (disable_hw) { +/* prevent the HW from sending interrupts */ +bnx2x_int_disable (sc); + } +} + +static void +bnx2x_chip_cleanup (struct bnx2x_softc *sc,uint32_t unload_mode,uint8_t keep_link) +{ +int port =SC_PORT (sc); +struct ecore_mcast_ramrod_params rparam = {NULL }; +uint32_t reset_code; +int i, rc =0 ; + +bnx2x_drain_tx_queues (sc); + +/* give HW time to discard old tx messages */ +DELAY (1000 ); + +/* Clean all ETH MACs */ + rc =bnx2x_del_all_macs (sc, &sc->sp_objs[0 ].mac_obj,ECORE_ETH_MAC , + FALSE); +if (rc <0 ) { +PMD_DRV_LOG (NOTICE ,"Failed to delete all ETH MACs (%d)" , rc); + } + +/* Clean up UC list */ + rc =bnx2x_del_all_macs (sc, &sc->sp_objs[0 ].mac_obj,ECORE_UC_LIST_MAC , + TRUE); +if (rc <0 ) { +PMD_DRV_LOG (NOTICE ,"Failed to delete UC MACs list (%d)" , rc); + } + +/* Disable LLH */ +REG_WR (sc,NIG_REG_LLH0_FUNC_EN + port *8 ,0 ); + +/* Set "drop all" to stop Rx */ + +/* +* We need to take the if_maddr_lock() here in order to prevent +* a race between the completion code and this code. +*/ + +if (bnx2x_test_bit (ECORE_FILTER_RX_MODE_PENDING , &sc->sp_state)) { +bnx2x_set_bit (ECORE_FILTER_RX_MODE_SCHED , &sc->sp_state); + }else { +bnx2x_set_storm_rx_mode (sc); + } + +/* Clean up multicast configuration */ + rparam.mcast_obj = &sc->mcast_obj; + rc =ecore_config_mcast (sc, &rparam,ECORE_MCAST_CMD_DEL ); +if (rc <0 ) { +PMD_DRV_LOG (NOTICE , +"Failed to send DEL MCAST command (%d)" , rc); + } + +/* +* Send the UNLOAD_REQUEST to the MCP. This will return if +* this function should perform FUNCTION, PORT, or COMMON HW +* reset. +*/ + reset_code =bnx2x_send_unload_req (sc, unload_mode); + +/* +* (assumption: No Attention from MCP at this stage) +* PMF probably in the middle of TX disable/enable transaction +*/ + rc =bnx2x_func_wait_started (sc); +if (rc) { +PMD_DRV_LOG (NOTICE ,"bnx2x_func_wait_started failed" ); + } + +/* +* Close multi and leading connections +* Completions for ramrods are collected in a synchronous way +*/ +for (i =0 ; i < sc->num_queues; i++) { +if (bnx2x_stop_queue (sc, i)) { + goto unload_error; + } + } + +/* +* If SP settings didn't get completed so far - something +* very wrong has happen. +*/ +if (!bnx2x_wait_sp_comp (sc, ~0x0UL )) { +PMD_DRV_LOG (NOTICE ,"Common slow path ramrods got stuck!" ); + } + +unload_error: + + rc =bnx2x_func_stop (sc); +if (rc) { +PMD_DRV_LOG (NOTICE ,"Function stop failed!" ); + } + +/* disable HW interrupts */ +bnx2x_int_disable_sync (sc, TRUE); + +/* Reset the chip */ + rc =bnx2x_reset_hw (sc, reset_code); +if (rc) { +PMD_DRV_LOG (NOTICE ,"Hardware reset failed" ); + } + +/* Report UNLOAD_DONE to MCP */ +bnx2x_send_unload_done (sc, keep_link); +} + +static void bnx2x_disable_close_the_gate (struct bnx2x_softc *sc) +{ +uint32_t val; + +PMD_DRV_LOG (DEBUG ,"Disabling 'close the gates'" ); + + val =REG_RD (sc,MISC_REG_AEU_GENERAL_MASK ); + val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK | +MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK ); +REG_WR (sc,MISC_REG_AEU_GENERAL_MASK , val); +} + +/* +* Cleans the object that have internal lists without sending +* ramrods. Should be run when interrutps are disabled. +*/ +static void bnx2x_squeeze_objects (struct bnx2x_softc *sc) +{ +unsigned long ramrod_flags =0 , vlan_mac_flags =0 ; +struct ecore_mcast_ramrod_params rparam = {NULL }; +struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj; +int rc; + +/* Cleanup MACs' object first... */ + +/* Wait for completion of requested */ +bnx2x_set_bit (RAMROD_COMP_WAIT , &ramrod_flags); +/* Perform a dry cleanup */ +bnx2x_set_bit (RAMROD_DRV_CLR_ONLY , &ramrod_flags); + +/* Clean ETH primary MAC */ +bnx2x_set_bit (ECORE_ETH_MAC , &vlan_mac_flags); + rc = mac_obj->delete_all (sc, &sc->sp_objs->mac_obj, &vlan_mac_flags, + &ramrod_flags); +if (rc !=0 ) { +PMD_DRV_LOG (NOTICE ,"Failed to clean ETH MACs (%d)" , rc); + } + +/* Cleanup UC list */ + vlan_mac_flags =0 ; +bnx2x_set_bit (ECORE_UC_LIST_MAC , &vlan_mac_flags); + rc = mac_obj->delete_all (sc, mac_obj, &vlan_mac_flags, &ramrod_flags); +if (rc !=0 ) { +PMD_DRV_LOG (NOTICE ,"Failed to clean UC list MACs (%d)" , rc); + } + +/* Now clean mcast object... */ + + rparam.mcast_obj = &sc->mcast_obj; +bnx2x_set_bit (RAMROD_DRV_CLR_ONLY , &rparam.ramrod_flags); + +/* Add a DEL command... */ + rc =ecore_config_mcast (sc, &rparam,ECORE_MCAST_CMD_DEL ); +if (rc <0 ) { +PMD_DRV_LOG (NOTICE , +"Failed to send DEL MCAST command (%d)" , rc); + } + +/* now wait until all pending commands are cleared */ + + rc =ecore_config_mcast (sc, &rparam,ECORE_MCAST_CMD_CONT ); +while (rc !=0 ) { +if (rc <0 ) { +PMD_DRV_LOG (NOTICE , +"Failed to clean MCAST object (%d)" , rc); +return ; + } + + rc =ecore_config_mcast (sc, &rparam,ECORE_MCAST_CMD_CONT ); + } +} + +/* stop the controller */ +__attribute__ ((noinline)) +int +bnx2x_nic_unload (struct bnx2x_softc *sc,uint32_t unload_mode,uint8_t keep_link) +{ +uint8_t global = FALSE; +uint32_t val; + +PMD_DRV_LOG (DEBUG ,"Starting NIC unload..." ); + +/* stop the periodic callout */ +bnx2x_periodic_stop (sc); + +/* mark driver as unloaded in shmem2 */ +if (IS_PF (sc) &&SHMEM2_HAS (sc, drv_capabilities_flag)) { + val =SHMEM2_RD (sc, drv_capabilities_flag[SC_FW_MB_IDX (sc)]); +SHMEM2_WR (sc, drv_capabilities_flag[SC_FW_MB_IDX (sc)], + val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2 ); + } + +if (IS_PF (sc) && sc->recovery_state !=BNX2X_RECOVERY_DONE && + (sc->state ==BNX2X_STATE_CLOSED || sc->state ==BNX2X_STATE_ERROR )) { +/* +* We can get here if the driver has been unloaded +* during parity error recovery and is either waiting for a +* leader to complete or for other functions to unload and +* then ifconfig down has been issued. In this case we want to +* unload and let other functions to complete a recovery +* process. +*/ + sc->recovery_state =BNX2X_RECOVERY_DONE ; + sc->is_leader =0 ; +bnx2x_release_leader_lock (sc); +mb (); + +PMD_DRV_LOG (NOTICE ,"Can't unload in closed or error state" ); +return -1 ; + } + +/* +* Nothing to do during unload if previous bnx2x_nic_load() +* did not completed succesfully - all resourses are released. +*/ +if ((sc->state ==BNX2X_STATE_CLOSED ) || (sc->state ==BNX2X_STATE_ERROR )) { +return 0 ; + } + + sc->state =BNX2X_STATE_CLOSING_WAITING_HALT ; +mb (); + + sc->rx_mode =BNX2X_RX_MODE_NONE ; +bnx2x_set_rx_mode (sc); +mb (); + +if (IS_PF (sc)) { +/* set ALWAYS_ALIVE bit in shmem */ + sc->fw_drv_pulse_wr_seq |=DRV_PULSE_ALWAYS_ALIVE ; + +bnx2x_drv_pulse (sc); + +bnx2x_stats_handle (sc,STATS_EVENT_STOP ); +bnx2x_save_statistics (sc); + } + +/* wait till consumers catch up with producers in all queues */ +bnx2x_drain_tx_queues (sc); + +/* if VF indicate to PF this function is going down (PF will delete sp +* elements and clear initializations +*/ +if (IS_VF (sc)) { +bnx2x_vf_unload (sc); + }else if (unload_mode !=UNLOAD_RECOVERY ) { +/* if this is a normal/close unload need to clean up chip */ +bnx2x_chip_cleanup (sc, unload_mode, keep_link); + }else { +/* Send the UNLOAD_REQUEST to the MCP */ +bnx2x_send_unload_req (sc, unload_mode); + +/* +* Prevent transactions to host from the functions on the +* engine that doesn't reset global blocks in case of global +* attention once gloabl blocks are reset and gates are opened +* (the engine which leader will perform the recovery +* last). +*/ +if (!CHIP_IS_E1x (sc)) { +bnx2x_pf_disable (sc); + } + +/* disable HW interrupts */ +bnx2x_int_disable_sync (sc, TRUE); + +/* Report UNLOAD_DONE to MCP */ +bnx2x_send_unload_done (sc, FALSE); + } + +/* +* At this stage no more interrupts will arrive so we may safely clean +* the queue'able objects here in case they failed to get cleaned so far. +*/ +if (IS_PF (sc)) { +bnx2x_squeeze_objects (sc); + } + +/* There should be no more pending SP commands at this stage */ + sc->sp_state =0 ; + + sc->port.pmf =0 ; + +if (IS_PF (sc)) { +bnx2x_free_mem (sc); + } + +bnx2x_free_fw_stats_mem (sc); + + sc->state =BNX2X_STATE_CLOSED ; + +/* +* Check if there are pending parity attentions. If there are - set +* RECOVERY_IN_PROGRESS. +*/ +if (IS_PF (sc) &&bnx2x_chk_parity_attn (sc, &global, FALSE)) { +bnx2x_set_reset_in_progress (sc); + +/* Set RESET_IS_GLOBAL if needed */ +if (global) { +bnx2x_set_reset_global (sc); + } + } + +/* +* The last driver must disable a "close the gate" if there is no +* parity attention or "process kill" pending. +*/ +if (IS_PF (sc) && !bnx2x_clear_pf_load (sc) && +bnx2x_reset_is_done (sc,SC_PATH (sc))) { +bnx2x_disable_close_the_gate (sc); + } + +PMD_DRV_LOG (DEBUG ,"Ended NIC unload" ); + +return 0 ; +} + +/* +* Encapsulte an mbuf cluster into the tx bd chain and makes the memory +* visible to the controller. +* +* If an mbuf is submitted to this routine and cannot be given to the +* controller (e.g. it has too many fragments) then the function may free +* the mbuf and return to the caller. +* +* Returns: +* 0 = Success, !0 = Failure +* Note the side effect that an mbuf may be freed if it causes a problem. +*/ +int bnx2x_tx_encap (struct bnx2x_tx_queue *txq,struct rte_mbuf **m_head,int m_pkts) +{ +struct rte_mbuf *m0; +struct eth_tx_start_bd *tx_start_bd; +uint16_t bd_prod, pkt_prod; +int m_tx; +struct bnx2x_softc *sc; +uint32_t nbds =0 ; +struct bnx2x_fastpath *fp; + + sc = txq->sc; + fp = &sc->fp[txq->queue_id]; + + bd_prod = txq->tx_bd_tail; + pkt_prod = txq->tx_pkt_tail; + +for (m_tx =0 ; m_tx < m_pkts; m_tx++) { + + m0 = *m_head++; + +if (unlikely (txq->nb_tx_avail <3 )) { +PMD_TX_LOG (ERR ,"no enough bds %d/%d" , + bd_prod, txq->nb_tx_avail); +return -ENOMEM ; + } + + txq->sw_ring[TX_BD (pkt_prod, txq)] = m0; + + tx_start_bd = &txq->tx_ring[TX_BD (bd_prod, txq)].start_bd; + + tx_start_bd->addr = +rte_cpu_to_le_64 (RTE_MBUF_DATA_DMA_ADDR (m0)); + tx_start_bd->nbytes =rte_cpu_to_le_16 (m0->data_len); + tx_start_bd->bd_flags.as_bitfield =ETH_TX_BD_FLAGS_START_BD ; + tx_start_bd->general_data = + (1 <<ETH_TX_START_BD_HDR_NBDS_SHIFT ); + + tx_start_bd->nbd =rte_cpu_to_le_16 (2 ); + +if (m0->ol_flags &PKT_TX_VLAN_PKT ) { + tx_start_bd->vlan_or_ethertype = +rte_cpu_to_le_16 (m0->vlan_tci); + tx_start_bd->bd_flags.as_bitfield |= + (X_ETH_OUTBAND_VLAN << +ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT ); + }else { +if (IS_PF (sc)) + tx_start_bd->vlan_or_ethertype = +rte_cpu_to_le_16 (pkt_prod); +else { +struct ether_hdr *eh + = rte_pktmbuf_mtod(m0, struct ether_hdr *); + + tx_start_bd->vlan_or_ethertype = eh->ether_type; + } + } + + bd_prod =NEXT_TX_BD (bd_prod); +if (IS_VF (sc)) { +struct eth_tx_parse_bd_e2 *tx_parse_bd; + uint8_t *data = rte_pktmbuf_mtod(m0, uint8_t *); + + tx_parse_bd = + &txq->tx_ring[TX_BD (bd_prod, txq)].parse_bd_e2; + tx_parse_bd->parsing_data = + (1 <<ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE_SHIFT ); + +rte_memcpy (&tx_parse_bd->data.mac_addr.dst_hi, + &data[0 ],2 ); +rte_memcpy (&tx_parse_bd->data.mac_addr.dst_mid, + &data[2 ],2 ); +rte_memcpy (&tx_parse_bd->data.mac_addr.dst_lo, + &data[4 ],2 ); +rte_memcpy (&tx_parse_bd->data.mac_addr.src_hi, + &data[6 ],2 ); +rte_memcpy (&tx_parse_bd->data.mac_addr.src_mid, + &data[8 ],2 ); +rte_memcpy (&tx_parse_bd->data.mac_addr.src_lo, + &data[10 ],2 ); + + tx_parse_bd->data.mac_addr.dst_hi = +rte_cpu_to_be_16 (tx_parse_bd->data.mac_addr.dst_hi); + tx_parse_bd->data.mac_addr.dst_mid = +rte_cpu_to_be_16 (tx_parse_bd->data. + mac_addr.dst_mid); + tx_parse_bd->data.mac_addr.dst_lo = +rte_cpu_to_be_16 (tx_parse_bd->data.mac_addr.dst_lo); + tx_parse_bd->data.mac_addr.src_hi = +rte_cpu_to_be_16 (tx_parse_bd->data.mac_addr.src_hi); + tx_parse_bd->data.mac_addr.src_mid = +rte_cpu_to_be_16 (tx_parse_bd->data. + mac_addr.src_mid); + tx_parse_bd->data.mac_addr.src_lo = +rte_cpu_to_be_16 (tx_parse_bd->data.mac_addr.src_lo); + +PMD_TX_LOG (DEBUG , +"PBD dst %x %x %x src %x %x %x p_data %x" , + tx_parse_bd->data.mac_addr.dst_hi, + tx_parse_bd->data.mac_addr.dst_mid, + tx_parse_bd->data.mac_addr.dst_lo, + tx_parse_bd->data.mac_addr.src_hi, + tx_parse_bd->data.mac_addr.src_mid, + tx_parse_bd->data.mac_addr.src_lo, + tx_parse_bd->parsing_data); + } + +PMD_TX_LOG (DEBUG , +"start bd: nbytes %d flags %x vlan %x\n" , + tx_start_bd->nbytes, + tx_start_bd->bd_flags.as_bitfield, + tx_start_bd->vlan_or_ethertype); + + bd_prod =NEXT_TX_BD (bd_prod); + pkt_prod++; + +if (TX_IDX (bd_prod) <2 ) { + nbds++; + } + } + + txq->nb_tx_avail -= m_pkts <<1 ; + txq->tx_bd_tail = bd_prod; + txq->tx_pkt_tail = pkt_prod; + +mb (); + fp->tx_db.data.prod += (m_pkts <<1 ) + nbds; +DOORBELL (sc, txq->queue_id, fp->tx_db.raw); +mb (); + +return 0 ; +} + +static uint16_t bnx2x_cid_ilt_lines (struct bnx2x_softc *sc) +{ +return L2_ILT_LINES (sc); +} + +static void bnx2x_ilt_set_info (struct bnx2x_softc *sc) +{ +struct ilt_client_info *ilt_client; +struct ecore_ilt *ilt = sc->ilt; +uint16_t line =0 ; + +PMD_INIT_FUNC_TRACE (); + + ilt->start_line =FUNC_ILT_BASE (SC_FUNC (sc)); + +/* CDU */ + ilt_client = &ilt->clients[ILT_CLIENT_CDU ]; + ilt_client->client_num =ILT_CLIENT_CDU ; + ilt_client->page_size =CDU_ILT_PAGE_SZ ; + ilt_client->flags =ILT_CLIENT_SKIP_MEM ; + ilt_client->start = line; + line +=bnx2x_cid_ilt_lines (sc); + +if (CNIC_SUPPORT (sc)) { + line +=CNIC_ILT_LINES ; + } + + ilt_client->end = (line -1 ); + +/* QM */ +if (QM_INIT (sc->qm_cid_count)) { + ilt_client = &ilt->clients[ILT_CLIENT_QM ]; + ilt_client->client_num =ILT_CLIENT_QM ; + ilt_client->page_size =QM_ILT_PAGE_SZ ; + ilt_client->flags =0 ; + ilt_client->start = line; + +/* 4 bytes for each cid */ + line +=DIV_ROUND_UP (sc->qm_cid_count *QM_QUEUES_PER_FUNC *4 , +QM_ILT_PAGE_SZ ); + + ilt_client->end = (line -1 ); + } + +if (CNIC_SUPPORT (sc)) { +/* SRC */ + ilt_client = &ilt->clients[ILT_CLIENT_SRC ]; + ilt_client->client_num =ILT_CLIENT_SRC ; + ilt_client->page_size =SRC_ILT_PAGE_SZ ; + ilt_client->flags =0 ; + ilt_client->start = line; + line +=SRC_ILT_LINES ; + ilt_client->end = (line -1 ); + +/* TM */ + ilt_client = &ilt->clients[ILT_CLIENT_TM ]; + ilt_client->client_num =ILT_CLIENT_TM ; + ilt_client->page_size =TM_ILT_PAGE_SZ ; + ilt_client->flags =0 ; + ilt_client->start = line; + line +=TM_ILT_LINES ; + ilt_client->end = (line -1 ); + } + +assert ((line <=ILT_MAX_LINES )); +} + +static void bnx2x_set_fp_rx_buf_size (struct bnx2x_softc *sc) +{ +int i; + +for (i =0 ; i < sc->num_queues; i++) { +/* get the Rx buffer size for RX frames */ + sc->fp[i].rx_buf_size = + (IP_HEADER_ALIGNMENT_PADDING +ETH_OVERHEAD + sc->mtu); + +/* get the mbuf allocation size for RX frames */ +if (sc->fp[i].rx_buf_size <=MCLBYTES ) { + sc->fp[i].mbuf_alloc_size =MCLBYTES ; + }else if (sc->fp[i].rx_buf_size <=BNX2X_PAGE_SIZE ) { + sc->fp[i].mbuf_alloc_size =PAGE_SIZE ; + }else { + sc->fp[i].mbuf_alloc_size =MJUM9BYTES ; + } + } +} + +int bnx2x_alloc_ilt_mem (struct bnx2x_softc *sc) +{ + + sc->ilt =rte_malloc ("" ,sizeof (struct ecore_ilt ),RTE_CACHE_LINE_SIZE ); + +return sc->ilt ==NULL ; +} + +static int bnx2x_alloc_ilt_lines_mem (struct bnx2x_softc *sc) +{ + sc->ilt->lines =rte_calloc ("" , +sizeof (struct ilt_line ),ILT_MAX_LINES , +RTE_CACHE_LINE_SIZE ); +return sc->ilt->lines ==NULL ; +} + +void bnx2x_free_ilt_mem (struct bnx2x_softc *sc) +{ +rte_free (sc->ilt); + sc->ilt =NULL ; +} + +static void bnx2x_free_ilt_lines_mem (struct bnx2x_softc *sc) +{ +if (sc->ilt->lines !=NULL ) { +rte_free (sc->ilt->lines); + sc->ilt->lines =NULL ; + } +} + +static void bnx2x_free_mem (struct bnx2x_softc *sc) +{ +uint32_t i; + +for (i =0 ; i <L2_ILT_LINES (sc); i++) { + sc->context[i].vcxt =NULL ; + sc->context[i].size =0 ; + } + +ecore_ilt_mem_op (sc,ILT_MEMOP_FREE ); + +bnx2x_free_ilt_lines_mem (sc); +} + +static int bnx2x_alloc_mem (struct bnx2x_softc *sc) +{ +int context_size; +int allocated; +int i; +char cdu_name[RTE_MEMZONE_NAMESIZE ]; + +/* +* Allocate memory for CDU context: +* This memory is allocated separately and not in the generic ILT +* functions because CDU differs in few aspects: +* 1. There can be multiple entities allocating memory for context - +* regular L2, CNIC, and SRIOV drivers. Each separately controls +* its own ILT lines. +* 2. Since CDU page-size is not a single 4KB page (which is the case +* for the other ILT clients), to be efficient we want to support +* allocation of sub-page-size in the last entry. +* 3. Context pointers are used by the driver to pass to FW / update +* the context (for the other ILT clients the pointers are used just to +* free the memory during unload). +*/ + context_size = (sizeof (union cdu_context ) *BNX2X_L2_CID_COUNT (sc)); +for (i =0 , allocated =0 ; allocated < context_size; i++) { + sc->context[i].size =min (CDU_ILT_PAGE_SZ , + (context_size - allocated)); + +snprintf (cdu_name,sizeof (cdu_name),"cdu_%d" , i); +if (bnx2x_dma_alloc (sc, sc->context[i].size, + &sc->context[i].vcxt_dma, + cdu_name,BNX2X_PAGE_SIZE ) !=0 ) { +bnx2x_free_mem (sc); +return -1 ; + } + + sc->context[i].vcxt = + (union cdu_context *)sc->context[i].vcxt_dma.vaddr; + + allocated += sc->context[i].size; + } + +bnx2x_alloc_ilt_lines_mem (sc); + +if (ecore_ilt_mem_op (sc,ILT_MEMOP_ALLOC )) { +PMD_DRV_LOG (NOTICE ,"ecore_ilt_mem_op ILT_MEMOP_ALLOC failed" ); +bnx2x_free_mem (sc); +return -1 ; + } + +return 0 ; +} + +static void bnx2x_free_fw_stats_mem (struct bnx2x_softc *sc) +{ + sc->fw_stats_num =0 ; + + sc->fw_stats_req_size =0 ; + sc->fw_stats_req =NULL ; + sc->fw_stats_req_mapping =0 ; + + sc->fw_stats_data_size =0 ; + sc->fw_stats_data =NULL ; + sc->fw_stats_data_mapping =0 ; +} + +static int bnx2x_alloc_fw_stats_mem (struct bnx2x_softc *sc) +{ +uint8_t num_queue_stats; +int num_groups, vf_headroom =0 ; + +/* number of queues for statistics is number of eth queues */ + num_queue_stats =BNX2X_NUM_ETH_QUEUES (sc); + +/* +* Total number of FW statistics requests = +* 1 for port stats + 1 for PF stats + num of queues +*/ + sc->fw_stats_num = (2 + num_queue_stats); + +/* +* Request is built from stats_query_header and an array of +* stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT +* rules. The real number or requests is configured in the +* stats_query_header. +*/ + num_groups = (sc->fw_stats_num + vf_headroom) /STATS_QUERY_CMD_COUNT ; +if ((sc->fw_stats_num + vf_headroom) %STATS_QUERY_CMD_COUNT ) + num_groups++; + + sc->fw_stats_req_size = + (sizeof (struct stats_query_header ) + + (num_groups *sizeof (struct stats_query_cmd_group ))); + +/* +* Data for statistics requests + stats_counter. +* stats_counter holds per-STORM counters that are incremented when +* STORM has finished with the current request. Memory for FCoE +* offloaded statistics are counted anyway, even if they will not be sent. +* VF stats are not accounted for here as the data of VF stats is stored +* in memory allocated by the VF, not here. +*/ + sc->fw_stats_data_size = + (sizeof (struct stats_counter ) + +sizeof (struct per_port_stats ) +sizeof (struct per_pf_stats ) + +/* sizeof(struct fcoe_statistics_params) + */ + (sizeof (struct per_queue_stats ) * num_queue_stats)); + +if (bnx2x_dma_alloc (sc, (sc->fw_stats_req_size + sc->fw_stats_data_size), + &sc->fw_stats_dma,"fw_stats" , +RTE_CACHE_LINE_SIZE ) !=0 ) { +bnx2x_free_fw_stats_mem (sc); +return -1 ; + } + +/* set up the shortcuts */ + + sc->fw_stats_req = (struct bnx2x_fw_stats_req *)sc->fw_stats_dma.vaddr; + sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr; + + sc->fw_stats_data = + (struct bnx2x_fw_stats_data *)((uint8_t *) sc->fw_stats_dma.vaddr + + sc->fw_stats_req_size); + sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr + + sc->fw_stats_req_size); + +return 0 ; +} + +/* +* Bits map: +* 0-7 - Engine0 load counter. +* 8-15 - Engine1 load counter. +* 16 - Engine0 RESET_IN_PROGRESS bit. +* 17 - Engine1 RESET_IN_PROGRESS bit. +* 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active +* function on the engine +* 19 - Engine1 ONE_IS_LOADED. +* 20 - Chip reset flow bit. When set none-leader must wait for both engines +* leader to complete (check for both RESET_IN_PROGRESS bits and not +* for just the one belonging to its engine). +*/ +#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1 +#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff +#define BNX2X_PATH0_LOAD_CNT_SHIFT 0 +#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00 +#define BNX2X_PATH1_LOAD_CNT_SHIFT 8 +#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000 +#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000 +#define BNX2X_GLOBAL_RESET_BIT 0x00040000 + +/* set the GLOBAL_RESET bit, should be run under rtnl lock */ +static void bnx2x_set_reset_global (struct bnx2x_softc *sc) +{ +uint32_t val; +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); + val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); +REG_WR (sc,BNX2X_RECOVERY_GLOB_REG , val |BNX2X_GLOBAL_RESET_BIT ); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); +} + +/* clear the GLOBAL_RESET bit, should be run under rtnl lock */ +static void bnx2x_clear_reset_global (struct bnx2x_softc *sc) +{ +uint32_t val; +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); + val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); +REG_WR (sc,BNX2X_RECOVERY_GLOB_REG , val & (~BNX2X_GLOBAL_RESET_BIT )); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); +} + +/* checks the GLOBAL_RESET bit, should be run under rtnl lock */ +static uint8_t bnx2x_reset_is_global (struct bnx2x_softc *sc) +{ +return (REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ) &BNX2X_GLOBAL_RESET_BIT ); +} + +/* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */ +static void bnx2x_set_reset_done (struct bnx2x_softc *sc) +{ +uint32_t val; +uint32_t bit =SC_PATH (sc) ?BNX2X_PATH1_RST_IN_PROG_BIT : +BNX2X_PATH0_RST_IN_PROG_BIT ; + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); + + val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); +/* Clear the bit */ + val &= ~bit; +REG_WR (sc,BNX2X_RECOVERY_GLOB_REG , val); + +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); +} + +/* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */ +static void bnx2x_set_reset_in_progress (struct bnx2x_softc *sc) +{ +uint32_t val; +uint32_t bit =SC_PATH (sc) ?BNX2X_PATH1_RST_IN_PROG_BIT : +BNX2X_PATH0_RST_IN_PROG_BIT ; + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); + + val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); +/* Set the bit */ + val |= bit; +REG_WR (sc,BNX2X_RECOVERY_GLOB_REG , val); + +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); +} + +/* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */ +static uint8_t bnx2x_reset_is_done (struct bnx2x_softc *sc,int engine) +{ +uint32_t val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); +uint32_t bit = engine ?BNX2X_PATH1_RST_IN_PROG_BIT : +BNX2X_PATH0_RST_IN_PROG_BIT ; + +/* return false if bit is set */ +return (val & bit) ? FALSE : TRUE; +} + +/* get the load status for an engine, should be run under rtnl lock */ +static uint8_t bnx2x_get_load_status (struct bnx2x_softc *sc,int engine) +{ +uint32_t mask = engine ?BNX2X_PATH1_LOAD_CNT_MASK : +BNX2X_PATH0_LOAD_CNT_MASK ; +uint32_t shift = engine ?BNX2X_PATH1_LOAD_CNT_SHIFT : +BNX2X_PATH0_LOAD_CNT_SHIFT ; +uint32_t val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); + + val = ((val & mask) >> shift); + +return (val !=0 ); +} + +/* set pf load mark */ +static void bnx2x_set_pf_load (struct bnx2x_softc *sc) +{ +uint32_t val; +uint32_t val1; +uint32_t mask =SC_PATH (sc) ?BNX2X_PATH1_LOAD_CNT_MASK : +BNX2X_PATH0_LOAD_CNT_MASK ; +uint32_t shift =SC_PATH (sc) ?BNX2X_PATH1_LOAD_CNT_SHIFT : +BNX2X_PATH0_LOAD_CNT_SHIFT ; + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); + +PMD_INIT_FUNC_TRACE (); + + val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); + +/* get the current counter value */ + val1 = ((val & mask) >> shift); + +/* set bit of this PF */ + val1 |= (1 <<SC_ABS_FUNC (sc)); + +/* clear the old value */ + val &= ~mask; + +/* set the new one */ + val |= ((val1 << shift) & mask); + +REG_WR (sc,BNX2X_RECOVERY_GLOB_REG , val); + +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); +} + +/* clear pf load mark */ +static uint8_t bnx2x_clear_pf_load (struct bnx2x_softc *sc) +{ +uint32_t val1, val; +uint32_t mask =SC_PATH (sc) ?BNX2X_PATH1_LOAD_CNT_MASK : +BNX2X_PATH0_LOAD_CNT_MASK ; +uint32_t shift =SC_PATH (sc) ?BNX2X_PATH1_LOAD_CNT_SHIFT : +BNX2X_PATH0_LOAD_CNT_SHIFT ; + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); + val =REG_RD (sc,BNX2X_RECOVERY_GLOB_REG ); + +/* get the current counter value */ + val1 = (val & mask) >> shift; + +/* clear bit of that PF */ + val1 &= ~(1 <<SC_ABS_FUNC (sc)); + +/* clear the old value */ + val &= ~mask; + +/* set the new one */ + val |= ((val1 << shift) & mask); + +REG_WR (sc,BNX2X_RECOVERY_GLOB_REG , val); +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_RECOVERY_REG ); +return val1 !=0 ; +} + +/* send load requrest to mcp and analyze response */ +static int bnx2x_nic_load_request (struct bnx2x_softc *sc,uint32_t * load_code) +{ +PMD_INIT_FUNC_TRACE (); + +/* init fw_seq */ + sc->fw_seq = + (SHMEM_RD (sc, func_mb[SC_FW_MB_IDX (sc)].drv_mb_header) & +DRV_MSG_SEQ_NUMBER_MASK ); + +PMD_DRV_LOG (DEBUG ,"initial fw_seq 0x%04x" , sc->fw_seq); + +#ifdef BNX2X_PULSE +/* get the current FW pulse sequence */ + sc->fw_drv_pulse_wr_seq = + (SHMEM_RD (sc, func_mb[SC_FW_MB_IDX (sc)].drv_pulse_mb) & +DRV_PULSE_SEQ_MASK ); +#else +/* set ALWAYS_ALIVE bit in shmem */ + sc->fw_drv_pulse_wr_seq |=DRV_PULSE_ALWAYS_ALIVE ; +bnx2x_drv_pulse (sc); +#endif + +/* load request */ + (*load_code) =bnx2x_fw_command (sc,DRV_MSG_CODE_LOAD_REQ , +DRV_MSG_CODE_LOAD_REQ_WITH_LFA ); + +/* if the MCP fails to respond we must abort */ +if (!(*load_code)) { +PMD_DRV_LOG (NOTICE ,"MCP response failure!" ); +return -1 ; + } + +/* if MCP refused then must abort */ +if ((*load_code) ==FW_MSG_CODE_DRV_LOAD_REFUSED ) { +PMD_DRV_LOG (NOTICE ,"MCP refused load request" ); +return -1 ; + } + +return 0 ; +} + +/* +* Check whether another PF has already loaded FW to chip. In virtualized +* environments a pf from anoth VM may have already initialized the device +* including loading FW. +*/ +static int bnx2x_nic_load_analyze_req (struct bnx2x_softc *sc,uint32_t load_code) +{ +uint32_t my_fw, loaded_fw; + +/* is another pf loaded on this engine? */ +if ((load_code !=FW_MSG_CODE_DRV_LOAD_COMMON_CHIP ) && + (load_code !=FW_MSG_CODE_DRV_LOAD_COMMON )) { +/* build my FW version dword */ + my_fw = (BNX2X_5710_FW_MAJOR_VERSION + + (BNX2X_5710_FW_MINOR_VERSION <<8 ) + + (BNX2X_5710_FW_REVISION_VERSION <<16 ) + + (BNX2X_5710_FW_ENGINEERING_VERSION <<24 )); + +/* read loaded FW from chip */ + loaded_fw =REG_RD (sc,XSEM_REG_PRAM ); +PMD_DRV_LOG (DEBUG ,"loaded FW 0x%08x / my FW 0x%08x" , + loaded_fw, my_fw); + +/* abort nic load if version mismatch */ +if (my_fw != loaded_fw) { +PMD_DRV_LOG (NOTICE , +"FW 0x%08x already loaded (mine is 0x%08x)" , + loaded_fw, my_fw); +return -1 ; + } + } + +return 0 ; +} + +/* mark PMF if applicable */ +static void bnx2x_nic_load_pmf (struct bnx2x_softc *sc,uint32_t load_code) +{ +uint32_t ncsi_oem_data_addr; + +PMD_INIT_FUNC_TRACE (); + +if ((load_code ==FW_MSG_CODE_DRV_LOAD_COMMON ) || + (load_code ==FW_MSG_CODE_DRV_LOAD_COMMON_CHIP ) || + (load_code ==FW_MSG_CODE_DRV_LOAD_PORT )) { +/* +* Barrier here for ordering between the writing to sc->port.pmf here +* and reading it from the periodic task. +*/ + sc->port.pmf =1 ; +mb (); + }else { + sc->port.pmf =0 ; + } + +PMD_DRV_LOG (DEBUG ,"pmf %d" , sc->port.pmf); + +if (load_code ==FW_MSG_CODE_DRV_LOAD_COMMON_CHIP ) { +if (SHMEM2_HAS (sc, ncsi_oem_data_addr)) { + ncsi_oem_data_addr =SHMEM2_RD (sc, ncsi_oem_data_addr); +if (ncsi_oem_data_addr) { +REG_WR (sc, + (ncsi_oem_data_addr + + offsetof(struct glob_ncsi_oem_data , + driver_version)),0 ); + } + } + } +} + +static void bnx2x_read_mf_cfg (struct bnx2x_softc *sc) +{ +int n = (CHIP_IS_MODE_4_PORT (sc) ?2 :1 ); +int abs_func; +int vn; + +if (BNX2X_NOMCP (sc)) { +return ;/* what should be the default bvalue in this case */ + } + +/* +* The formula for computing the absolute function number is... +* For 2 port configuration (4 functions per port): +* abs_func = 2 * vn + SC_PORT + SC_PATH +* For 4 port configuration (2 functions per port): +* abs_func = 4 * vn + 2 * SC_PORT + SC_PATH +*/ +for (vn =VN_0 ; vn <SC_MAX_VN_NUM (sc); vn++) { + abs_func = (n * (2 * vn +SC_PORT (sc)) +SC_PATH (sc)); +if (abs_func >=E1H_FUNC_MAX ) { +break ; + } + sc->devinfo.mf_info.mf_config[vn] = +MFCFG_RD (sc, func_mf_config[abs_func].config); + } + +if (sc->devinfo.mf_info.mf_config[SC_VN (sc)] & +FUNC_MF_CFG_FUNC_DISABLED ) { +PMD_DRV_LOG (DEBUG ,"mf_cfg function disabled" ); + sc->flags |=BNX2X_MF_FUNC_DIS ; + }else { +PMD_DRV_LOG (DEBUG ,"mf_cfg function enabled" ); + sc->flags &= ~BNX2X_MF_FUNC_DIS ; + } +} + +/* acquire split MCP access lock register */ +static int bnx2x_acquire_alr (struct bnx2x_softc *sc) +{ +uint32_t j, val; + +for (j =0 ; j <1000 ; j++) { + val = (1UL <<31 ); +REG_WR (sc,GRCBASE_MCP +0x9c , val); + val =REG_RD (sc,GRCBASE_MCP +0x9c ); +if (val & (1L <<31 )) +break ; + +DELAY (5000 ); + } + +if (!(val & (1L <<31 ))) { +PMD_DRV_LOG (NOTICE ,"Cannot acquire MCP access lock register" ); +return -1 ; + } + +return 0 ; +} + +/* release split MCP access lock register */ +static void bnx2x_release_alr (struct bnx2x_softc *sc) +{ +REG_WR (sc,GRCBASE_MCP +0x9c ,0 ); +} + +static void bnx2x_fan_failure (struct bnx2x_softc *sc) +{ +int port =SC_PORT (sc); +uint32_t ext_phy_config; + +/* mark the failure */ + ext_phy_config = +SHMEM_RD (sc, dev_info.port_hw_config[port].external_phy_config); + + ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK ; + ext_phy_config |=PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE ; +SHMEM_WR (sc, dev_info.port_hw_config[port].external_phy_config, + ext_phy_config); + +/* log the failure */ +PMD_DRV_LOG (INFO , +"Fan Failure has caused the driver to shutdown " +"the card to prevent permanent damage. " +"Please contact OEM Support for assistance" ); + +rte_panic ("Schedule task to handle fan failure" ); +} + +/* this function is called upon a link interrupt */ +static void bnx2x_link_attn (struct bnx2x_softc *sc) +{ +uint32_t pause_enabled =0 ; +struct host_port_stats *pstats; +int cmng_fns; + +/* Make sure that we are synced with the current statistics */ +bnx2x_stats_handle (sc,STATS_EVENT_STOP ); + +elink_link_update (&sc->link_params, &sc->link_vars); + +if (sc->link_vars.link_up) { + +/* dropless flow control */ +if (sc->dropless_fc) { + pause_enabled =0 ; + +if (sc->link_vars.flow_ctrl &ELINK_FLOW_CTRL_TX ) { + pause_enabled =1 ; + } + +REG_WR (sc, + (BAR_USTRORM_INTMEM + +USTORM_ETH_PAUSE_ENABLED_OFFSET (SC_PORT (sc))), + pause_enabled); + } + +if (sc->link_vars.mac_type !=ELINK_MAC_TYPE_EMAC ) { + pstats =BNX2X_SP (sc, port_stats); +/* reset old mac stats */ +memset (&(pstats->mac_stx[0 ]),0 , +sizeof (struct mac_stx )); + } + +if (sc->state ==BNX2X_STATE_OPEN ) { +bnx2x_stats_handle (sc,STATS_EVENT_LINK_UP ); + } + } + +if (sc->link_vars.link_up && sc->link_vars.line_speed) { + cmng_fns =bnx2x_get_cmng_fns_mode (sc); + +if (cmng_fns !=CMNG_FNS_NONE ) { +bnx2x_cmng_fns_init (sc, FALSE, cmng_fns); +storm_memset_cmng (sc, &sc->cmng,SC_PORT (sc)); + } + } + +bnx2x_link_report (sc); + +if (IS_MF (sc)) { +bnx2x_link_sync_notify (sc); + } +} + +static void bnx2x_attn_int_asserted (struct bnx2x_softc *sc,uint32_t asserted) +{ +int port =SC_PORT (sc); +uint32_t aeu_addr = port ?MISC_REG_AEU_MASK_ATTN_FUNC_1 : +MISC_REG_AEU_MASK_ATTN_FUNC_0 ; +uint32_t nig_int_mask_addr = port ?NIG_REG_MASK_INTERRUPT_PORT1 : +NIG_REG_MASK_INTERRUPT_PORT0 ; +uint32_t aeu_mask; +uint32_t nig_mask =0 ; +uint32_t reg_addr; +uint32_t igu_acked; +uint32_t cnt; + +if (sc->attn_state & asserted) { +PMD_DRV_LOG (ERR ,"IGU ERROR attn=0x%08x" , asserted); + } + +bnx2x_acquire_hw_lock (sc,HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); + + aeu_mask =REG_RD (sc, aeu_addr); + + aeu_mask &= ~(asserted &0x3ff ); + +REG_WR (sc, aeu_addr, aeu_mask); + +bnx2x_release_hw_lock (sc,HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); + + sc->attn_state |= asserted; + +if (asserted &ATTN_HARD_WIRED_MASK ) { +if (asserted &ATTN_NIG_FOR_FUNC ) { + +/* save nig interrupt mask */ + nig_mask =REG_RD (sc, nig_int_mask_addr); + +/* If nig_mask is not set, no need to call the update function */ +if (nig_mask) { +REG_WR (sc, nig_int_mask_addr,0 ); + +bnx2x_link_attn (sc); + } + +/* handle unicore attn? */ + } + +if (asserted &ATTN_SW_TIMER_4_FUNC ) { +PMD_DRV_LOG (DEBUG ,"ATTN_SW_TIMER_4_FUNC!" ); + } + +if (asserted &GPIO_2_FUNC ) { +PMD_DRV_LOG (DEBUG ,"GPIO_2_FUNC!" ); + } + +if (asserted &GPIO_3_FUNC ) { +PMD_DRV_LOG (DEBUG ,"GPIO_3_FUNC!" ); + } + +if (asserted &GPIO_4_FUNC ) { +PMD_DRV_LOG (DEBUG ,"GPIO_4_FUNC!" ); + } + +if (port ==0 ) { +if (asserted &ATTN_GENERAL_ATTN_1 ) { +PMD_DRV_LOG (DEBUG ,"ATTN_GENERAL_ATTN_1!" ); +REG_WR (sc,MISC_REG_AEU_GENERAL_ATTN_1 ,0x0 ); + } +if (asserted &ATTN_GENERAL_ATTN_2 ) {
Lines of this file are not shown. View the raw message.
drivers/net/bnx2x/bnx2x.h new file +1998 -0
1,998 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_ethdev.c new file +542 -0
542 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_ethdev.h new file +79 -0
79 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_logs.h new file +51 -0
51 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_rxtx.c new file +487 -0
487 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_rxtx.h new file +85 -0
85 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_stats.c new file +1619 -0
1,619 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_stats.h new file +632 -0
632 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_vfpf.c new file +597 -0
597 lines not on this page · raw message
drivers/net/bnx2x/bnx2x_vfpf.h new file +315 -0
315 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
Part of the diff is not shown here. View the raw message.
PATCH v5 3/4 bnx2x: driver support routines
In reply to Stephen HemmingerMore code for the Broadcom/Qlogic NetExtreme II poll mode driver. Split into pieces for review and not to overwhelm mailers.
--- drivers/net/bnx2x/debug.c | 113 + drivers/net/bnx2x/ecore_fw_defs.h | 422 + drivers/net/bnx2x/ecore_hsi.h | 6348 ++++++++++++ drivers/net/bnx2x/ecore_init.h | 841 ++ drivers/net/bnx2x/ecore_init_ops.h | 886 ++ drivers/net/bnx2x/ecore_mfw_req.h | 206 + drivers/net/bnx2x/ecore_reg.h | 3663 +++++++ drivers/net/bnx2x/ecore_sp.c | 5455 +++++++++++ drivers/net/bnx2x/ecore_sp.h | 1795 ++++ drivers/net/bnx2x/elink.c | 13378 ++++++++++++++++++++++++++ drivers/net/bnx2x/elink.h | 609 ++ drivers/net/bnx2x/rte_pmd_bnx2x_version.map | 4 + 12 files changed, 33720 insertions(+) create mode 100644 drivers/net/bnx2x/debug.c create mode 100644 drivers/net/bnx2x/ecore_fw_defs.h create mode 100644 drivers/net/bnx2x/ecore_hsi.h create mode 100644 drivers/net/bnx2x/ecore_init.h create mode 100644 drivers/net/bnx2x/ecore_init_ops.h create mode 100644 drivers/net/bnx2x/ecore_mfw_req.h create mode 100644 drivers/net/bnx2x/ecore_reg.h create mode 100644 drivers/net/bnx2x/ecore_sp.c create mode 100644 drivers/net/bnx2x/ecore_sp.h create mode 100644 drivers/net/bnx2x/elink.c create mode 100644 drivers/net/bnx2x/elink.h create mode 100644 drivers/net/bnx2x/rte_pmd_bnx2x_version.map
drivers/net/bnx2x/debug.c new file +113 -0
@@ -0,0 +1,113 @@ +/*- +* Copyright (c) 2007-2013 QLogic Corporation. All rights reserved. +* +* Eric Davis <[email protected]> +* David Christensen <[email protected]> +* Gary Zambrano <[email protected]> +* +* Copyright (c) 2013-2015 Brocade Communications Systems, Inc. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 3. Neither the name of Broadcom Corporation nor the name of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written consent. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS' +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +* THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "bnx2x.h" + + +/* +* Debug versions of the 8/16/32 bit OS register read/write functions to +* capture/display values read/written from/to the controller. +*/ +void +bnx2x_reg_write8 (struct bnx2x_softc *sc,size_t offset,uint8_t val) +{ +PMD_DRV_LOG (DEBUG ,"offset=0x%08lx val=0x%02x" , offset, val); + *((volatile uint8_t *)((uint64_t )sc->bar[BAR0 ].base_addr + offset)) = val; +} + +void +bnx2x_reg_write16 (struct bnx2x_softc *sc,size_t offset,uint16_t val) +{ +if ((offset %2 ) !=0 ) { +PMD_DRV_LOG (DEBUG ,"Unaligned 16-bit write to 0x%08lx" , offset); + } + +PMD_DRV_LOG (DEBUG ,"offset=0x%08lx val=0x%04x" , offset, val); + *((volatile uint16_t *)((uint64_t )sc->bar[BAR0 ].base_addr + offset)) = val; +} + +void +bnx2x_reg_write32 (struct bnx2x_softc *sc,size_t offset,uint32_t val) +{ +if ((offset %4 ) !=0 ) { +PMD_DRV_LOG (DEBUG ,"Unaligned 32-bit write to 0x%08lx" , offset); + } + +PMD_DRV_LOG (DEBUG ,"offset=0x%08lx val=0x%08x" , offset, val); + *((volatile uint32_t *)((uint64_t )sc->bar[BAR0 ].base_addr + offset)) = val; +} + +uint8_t +bnx2x_reg_read8 (struct bnx2x_softc *sc,size_t offset) +{ +uint8_t val; + + val = (uint8_t )(*((volatile uint8_t *)((uint64_t )sc->bar[BAR0 ].base_addr + offset))); +PMD_DRV_LOG (DEBUG ,"offset=0x%08lx val=0x%02x" , offset, val); + +return (val); +} + +uint16_t +bnx2x_reg_read16 (struct bnx2x_softc *sc,size_t offset) +{ +uint16_t val; + +if ((offset %2 ) !=0 ) { +PMD_DRV_LOG (DEBUG ,"Unaligned 16-bit read from 0x%08lx" , offset); + } + + val = (uint16_t )(*((volatile uint16_t *)((uint64_t )sc->bar[BAR0 ].base_addr + offset))); +PMD_DRV_LOG (DEBUG ,"offset=0x%08lx val=0x%08x" , offset, val); + +return (val); +} + +uint32_t +bnx2x_reg_read32 (struct bnx2x_softc *sc,size_t offset) +{ +uint32_t val; + +if ((offset %4 ) !=0 ) { +PMD_DRV_LOG (DEBUG ,"Unaligned 32-bit read from 0x%08lx" , offset); +return 0 ; + } + + val = (uint32_t )(*((volatile uint32_t *)((uint64_t )sc->bar[BAR0 ].base_addr + offset))); +PMD_DRV_LOG (DEBUG ,"offset=0x%08lx val=0x%08x" , offset, val); + +return (val); +}
drivers/net/bnx2x/ecore_fw_defs.h new file +422 -0
422 lines not on this page · raw message
drivers/net/bnx2x/ecore_hsi.h new file +6348 -0
2,465 lines not on this page · raw message
drivers/net/bnx2x/ecore_init.h new file +841 -0
841 lines not on this page · raw message
drivers/net/bnx2x/ecore_init_ops.h new file +886 -0
886 lines not on this page · raw message
drivers/net/bnx2x/ecore_mfw_req.h new file +206 -0
206 lines not on this page · raw message
drivers/net/bnx2x/ecore_reg.h new file +3663 -0
3,663 lines not on this page · raw message
drivers/net/bnx2x/ecore_sp.c new file +5455 -0
5,455 lines not on this page · raw message
drivers/net/bnx2x/ecore_sp.h new file +1795 -0
1,795 lines not on this page · raw message
drivers/net/bnx2x/elink.c new file +13378 -0
13,378 lines not on this page · raw message
drivers/net/bnx2x/elink.h new file +609 -0
609 lines not on this page · raw message
drivers/net/bnx2x/rte_pmd_bnx2x_version.map new file +4 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
Part of the diff is not shown here. View the raw message.
PATCH v5 4/4 bnx2x: enable PMD build
In reply to Stephen HemmingerThis is build infrastructure changes for bnx2x driver.
- enable BNX2X poll mode driver in default config.
- add it to mk
- put entry in MAINTAINERS
Note: I intentionally did not list myself as maintainer of this driver. QLogic has discussed taking over as maintainer.
---
v4 - Add PCI id's for 57840
--- MAINTAINERS | 3 ++ config/common_linuxapp | 10 ++++ drivers/net/Makefile | 1 + drivers/net/bnx2x/Makefile | 28 ++++++++++++ lib/librte_eal/common/include/rte_pci_dev_ids.h | 61 +++++++++++++++++++++++++ mk/rte.app.mk | 2 + 6 files changed, 105 insertions(+) create mode 100644 drivers/net/bnx2x/Makefile
MAINTAINERS +3 -0
@@ -277,6 +277,9 @@ M: John McNamara <[email protected]> F: drivers/net/pcap/ F: doc/guides/nics/pcap_ring.rst +Qlogic/Broadcom bnx2x +F: drivers/net/bnx2x/ + Ring PMD M: Bruce Richardson <[email protected]> F: drivers/net/ring/
config/common_linuxapp +10 -0
@@ -229,6 +229,16 @@ CONFIG_RTE_LIBRTE_ENIC_PMD=y CONFIG_RTE_LIBRTE_ENIC_DEBUG=n # +# Compile burst-oriented Broadcom PMD driver +# +CONFIG_RTE_LIBRTE_BNX2X_PMD=y +CONFIG_RTE_LIBRTE_BNX2X_DEBUG_INIT=n +CONFIG_RTE_LIBRTE_BNX2X_DEBUG=n +CONFIG_RTE_LIBRTE_BNX2X_MF_SUPPORT=n +CONFIG_RTE_LIBRTE_BNX2X_DEBUG_TX=n +CONFIG_RTE_LIBRTE_BNX2X_DEBUG_RX=n + +# # Compile burst-oriented VIRTIO PMD driver # CONFIG_RTE_LIBRTE_VIRTIO_PMD=y
drivers/net/Makefile +1 -0
@@ -47,6 +47,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_PMD_RING) += ring DIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio DIRS-$(CONFIG_RTE_LIBRTE_VMXNET3_PMD) += vmxnet3 DIRS-$(CONFIG_RTE_LIBRTE_PMD_XENVIRT) += xenvirt +DIRS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x include $(RTE_SDK)/mk/rte.sharelib.mk include $(RTE_SDK)/mk/rte.subdir.mk
drivers/net/bnx2x/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +include $(RTE_SDK)/mk/rte.vars.mk + +# +# library name +# +LIB = librte_pmd_bnx2x.a + +CFLAGS += -O3 -g +CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DZLIB_CONST + +# +# all source are stored in SRCS-y +# +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_rxtx.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_stats.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_ethdev.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += ecore_sp.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += elink.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_vfpf.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_DEBUG) += debug.c + +# this lib depends upon: +DEPDIRS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += lib/librte_eal lib/librte_ether lib/librte_hash +DEPDIRS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += lib/librte_mempool lib/librte_mbuf + +include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_eal/common/include/rte_pci_dev_ids.h +61 -0
84 lines not on this page · raw message
mk/rte.app.mk +2 -0
@@ -101,6 +101,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse endif _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += -libverbs +_LDLIBS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += -lz _LDLIBS-y += --start-group
@@ -138,6 +139,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_RING) += -lrte_pmd_ring _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lrte_pmd_pcap _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += -lrte_pmd_af_packet _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_NULL) += -lrte_pmd_null +_LDLIBS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += -lrte_pmd_bnx2x endif # ! $(CONFIG_RTE_BUILD_SHARED_LIB)
Signature · 1 line
2.1.4
Re: [PATCH v5 4/4] bnx2x: enable PMD build
Hi Stephen,
Quoted 236 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Monday, July 20, 2015 5:33 PM
To: [email protected]
Cc: [email protected]
Subject: [dpdk-dev] [PATCH v5 4/4] bnx2x: enable PMD buildThis is build infrastructure changes for bnx2x driver.
- enable BNX2X poll mode driver in default config.
- add it to mk
- put entry inMAINTAINERSNote: I intentionally did not list myself as maintainer of this driver. QLogic has discussed taking over as maintainer.
Signed-off-by Stephen Hemminger <[email protected]>---
v4 - Add PCI id's for 57840--- MAINTAINERS | 3 ++ config/common_linuxapp | 10 ++++ drivers/net/Makefile | 1 + drivers/net/bnx2x/Makefile | 28 ++++++++++++ lib/librte_eal/common/include/rte_pci_dev_ids.h | 61 +++++++++++++++++++++++++ mk/rte.app.mk | 2 + 6 files changed, 105 insertions(+) create mode 100644 drivers/net/bnx2x/MakefileMAINTAINERS +3
-0@@ -277,6 +277,9 @@ M: John McNamara <[email protected]> F: drivers/net/pcap/ F: doc/guides/nics/pcap_ring.rst +Qlogic/Broadcom bnx2x +F: drivers/net/bnx2x/ + Ring PMD M: Bruce Richardson <[email protected]> F: drivers/net/ring/config/common_linuxapp index renamed from config/common_linuxapp +0
-0579a5d7..a8a392e 100644
config/common_linuxapp +0
-0@@ -229,6 +229,16 @@ CONFIG_RTE_LIBRTE_ENIC_PMD=y
CONFIG_RTE_LIBRTE_ENIC_DEBUG=n#
config/common_linuxapp +2
-0+# Compile burst-oriented Broadcom PMD driver # +CONFIG_RTE_LIBRTE_BNX2X_PMD=y
CONFIG_RTE_LIBRTE_BNX2X_DEBUG_INIT=nconfig/common_linuxapp +6
-0+CONFIG_RTE_LIBRTE_BNX2X_DEBUG=n +CONFIG_RTE_LIBRTE_BNX2X_MF_SUPPORT=n +CONFIG_RTE_LIBRTE_BNX2X_DEBUG_TX=n +CONFIG_RTE_LIBRTE_BNX2X_DEBUG_RX=n + +# # Compile burst-oriented VIRTIO PMD driver #
CONFIG_RTE_LIBRTE_VIRTIO_PMD=ydiff --git a/drivers/net/Makefile b/drivers/net/Makefile index 6171430..6d519b6 100644drivers/net/Makefile +1
-0@@ -47,6 +47,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_PMD_RING) += ring DIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio DIRS-$(CONFIG_RTE_LIBRTE_VMXNET3_PMD) += vmxnet3 DIRS-$(CONFIG_RTE_LIBRTE_PMD_XENVIRT) += xenvirt +DIRS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x include $(RTE_SDK)/mk/rte.sharelib.mk include $(RTE_SDK)/mk/rte.subdir.mkdrivers/net/bnx2x/Makefile new renamed from drivers/net/bnx2x/Makefile +0
-0file mode 100644 index 0000000..0de5db9
drivers/net/bnx2x/Makefile new file +30
-0@@ -0,0 +1,28 @@ +include $(RTE_SDK)/mk/rte.vars.mk + +# +# library name +# +LIB = librte_pmd_bnx2x.a + +CFLAGS += -O3 -g +CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DZLIB_CONST + +# +# all source are stored in SRCS-y +# +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_rxtx.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_stats.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_ethdev.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += ecore_sp.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += elink.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += bnx2x_vfpf.c +SRCS-$(CONFIG_RTE_LIBRTE_BNX2X_DEBUG) += debug.c + +# this lib depends upon: +DEPDIRS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += lib/librte_eal +lib/librte_ether lib/librte_hash +DEPDIRS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += lib/librte_mempool +lib/librte_mbuf + +include $(RTE_SDK)/mk/rte.lib.mklib/librte_eal/common/include/rte_pci_dev_ids.h +40
-0@@ -144,6 +144,14 @@#define RTE_PCI_DEV_ID_DECL_ENIC (vend, dev) #endif +#ifndef RTE_PCI_DEV_ID_DECL_BNX2X +#define RTE_PCI_DEV_ID_DECL_BNX2X (vend, dev) #endif + +#ifndef RTE_PCI_DEV_ID_DECL_BNX2XVF +#define RTE_PCI_DEV_ID_DECL_BNX2XVF (vend, dev) #endif +#ifndef PCI_VENDOR_ID_INTEL /** Vendor ID used by Intel devices */ #define PCI_VENDOR_ID_INTEL 0x8086@@ -164,6 +172,11 @@#define PCI_VENDOR_ID_CISCO 0x1137#endif +#ifndef PCI_VENDOR_ID_BROADCOM +/** Vendor ID used by Broadcom devices */ #define +PCI_VENDOR_ID_BROADCOM 0x14E4 #endif +/******************** Physical EM devices from e1000_hw.h ********************/ #define E1000_DEV_ID_82542 0x1000@@ -566,6 +579,52 @@RTE_PCI_DEV_ID_DECL_FM10KVF (PCI_VENDOR_ID_INTEL , FM10K_DEV_ID_VF) RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET)RTE_PCI_DEV_ID_DECL_ENIC (PCI_VENDOR_ID_CISCO ,PCI_DEVICE_ID_CISCO_VIC_ENET_VF ) +/****************** QLogic devices ******************/ + +/* Broadcom/QLogic BNX2X */ +#define BNX2X_DEV_ID_57710 0x164e +#define BNX2X_DEV_ID_57711 0x164f +#define BNX2X_DEV_ID_57711E 0x1650 +#define BNX2X_DEV_ID_57712 0x1662 +#define BNX2X_DEV_ID_57712_MF 0x1663 +#define BNX2X_DEV_ID_57712_VF 0x166f +#define BNX2X_DEV_ID_57713 0x1651 +#define BNX2X_DEV_ID_57713E 0x1652 +#define BNX2X_DEV_ID_57800 0x168a +#define BNX2X_DEV_ID_57800_MF 0x16a5 +#define BNX2X_DEV_ID_57800_VF 0x16a9 +#define BNX2X_DEV_ID_57810 0x168e +#define BNX2X_DEV_ID_57810_MF 0x16ae +#define BNX2X_DEV_ID_57810_VF 0x16af +#define BNX2X_DEV_ID_57811 0x163d +#define BNX2X_DEV_ID_57811_MF 0x163e +#define BNX2X_DEV_ID_57811_VF 0x163f + +#define BNX2X_DEV_ID_57840_OBS 0x168d +#define BNX2X_DEV_ID_57840_OBS_MF 0x16ab +#define BNX2X_DEV_ID_57840_4_10 0x16a1 +#define BNX2X_DEV_ID_57840_2_20 0x16a2 +#define BNX2X_DEV_ID_57840_MF 0x16a4 +#define BNX2X_DEV_ID_57840_VF 0x16ad + + +RTE_PCI_DEV_ID_DECL_BNX2X(PCI_VENDOR_ID_BROADCOM,
BNX2X_DEV_ID_57800)lib/librte_eal/common/include/rte_pci_dev_ids.h +3
-0+RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57800_VF) +RTE_PCI_DEV_ID_DECL_BNX2X(PCI_VENDOR_ID_BROADCOM,
BNX2X_DEV_ID_57711) +RTE_PCI_DEV_ID_DECL_BNX2X(PCI_VENDOR_ID_BROADCOM,BNX2X_DEV_ID_57810)lib/librte_eal/common/include/rte_pci_dev_ids.h +3
-0+RTE_PCI_DEV_ID_DECL_BNX2XVF (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57810_VF) +RTE_PCI_DEV_ID_DECL_BNX2X(PCI_VENDOR_ID_BROADCOM,
BNX2X_DEV_ID_57811)lib/librte_eal/common/include/rte_pci_dev_ids.h +17
-0+RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57811_VF) +RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57840_OBS) +RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57840_4_10) +RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57840_2_20) +RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57840_VF) #ifdef RTE_LIBRTE_BNX2X_MF_SUPPORT +RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57810_MF) +RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57811_MF) +RTE_PCI_DEV_ID_DECL_BNX2X (PCI_VENDOR_ID_BROADCOM , +BNX2X_DEV_ID_57840_MF) #endif +/* * Undef all RTE_PCI_DEV_ID_DECL_* here. */ @@ -578,5 +637,7 @@ RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO,
PCI_DEVICE_ID_CISCO_VIC_ENET_VF) #undefRTE_PCI_DEV_ID_DECL_I40EVF#undefRTE_PCI_DEV_ID_DECL_VIRTIO#undefRTE_PCI_DEV_ID_DECL_VMXNET3lib/librte_eal/common/include/rte_pci_dev_ids.h +2
-0+#undef RTE_PCI_DEV_ID_DECL_BNX2X +#undef RTE_PCI_DEV_ID_DECL_BNX2XVF#undef RTE_PCI_DEV_ID_DECL_FM10K#undef RTE_PCI_DEV_ID_DECL_FM10KVFmk/rte.app.mk +0
-0@@ -101,6 +101,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lfuse
endif_LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += -libverbs
mk/rte.app.mk +1
-0+_LDLIBS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += -lz _LDLIBS-y += --start-group@@ -138,6 +139,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_RING) += -
lrte_pmd_ring
_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lrte_pmd_pcap
_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += -lrte_pmd_af_packet
_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_NULL) += -lrte_pmd_null
+_LDLIBS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD) += -lrte_pmd_bnx2x
Quoted 4 lines
endif # ! $(CONFIG_RTE_BUILD_SHARED_LIB)
--
2.1.4
Seeing a build error on Linux with build of bnx2x enabled
== Build drivers/net/bnx2x
CC bnx2x.o/root/dpdk_sforge_2/drivers/net/bnx2x/bnx2x.c:50:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
Regards,
Bernard.
^
Re: [PATCH v5 4/4] bnx2x: enable PMD build
2015-07-27 09:42, Iremonger, Bernard:
Quoted 6 lines
Seeing a build error on Linux with build of bnx2x enabled
== Build
drivers/net/bnx2x
CC bnx2x.o/root/dpdk_sforge_2/drivers/net/bnx2x/bnx2x.c:50:18: fatal error:zlib.h: No such file or directory
#include <zlib.h>
bnx2x requires zlib to be installed with its header.
Stephen, it would be smoother to have a build option for the zip feature and disable it by default.
Then the file pkg/dpdk.spec must be updated for this new dependency.
One day, a configure script could replace such build options.
Quoted 78 lines
Changes in this version (v5):
- rebase to 2.1.0-rc1
- fix version map for 2.1
- fix doxygen comments
- add BCM57410 idsStephen Hemminger (4):
eal: provide functions to access PCI config
bnx2x: driver core
bnx2x: driver support routines
bnx2x: enable PMD buildMAINTAINERS | 3 + config/common_linuxapp | 10 + drivers/net/Makefile | 1 + drivers/net/bnx2x/Makefile | 28 + drivers/net/bnx2x/bnx2x.c | 11821 +++++++++++++++++++ drivers/net/bnx2x/bnx2x.h | 1998 ++++ drivers/net/bnx2x/bnx2x_ethdev.c | 542 + drivers/net/bnx2x/bnx2x_ethdev.h | 79 + drivers/net/bnx2x/bnx2x_logs.h | 51 + drivers/net/bnx2x/bnx2x_rxtx.c | 487 + drivers/net/bnx2x/bnx2x_rxtx.h | 85 + drivers/net/bnx2x/bnx2x_stats.c | 1619 +++ drivers/net/bnx2x/bnx2x_stats.h | 632 + drivers/net/bnx2x/bnx2x_vfpf.c | 597 + drivers/net/bnx2x/bnx2x_vfpf.h | 315 + drivers/net/bnx2x/debug.c | 113 + drivers/net/bnx2x/ecore_fw_defs.h | 422 + drivers/net/bnx2x/ecore_hsi.h | 6348 ++++++++++ drivers/net/bnx2x/ecore_init.h | 841 ++ drivers/net/bnx2x/ecore_init_ops.h | 886 ++ drivers/net/bnx2x/ecore_mfw_req.h | 206 + drivers/net/bnx2x/ecore_reg.h | 3663 ++++++ drivers/net/bnx2x/ecore_sp.c | 5455 +++++++++ drivers/net/bnx2x/ecore_sp.h | 1795 +++ drivers/net/bnx2x/elink.c | 13378 ++++++++++++++++++++++ drivers/net/bnx2x/elink.h | 609 + drivers/net/bnx2x/rte_pmd_bnx2x_version.map | 4 + lib/librte_eal/bsdapp/eal/eal_pci.c | 83 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 3 +- lib/librte_eal/common/include/rte_pci.h | 32 + lib/librte_eal/common/include/rte_pci_dev_ids.h | 61 + lib/librte_eal/linuxapp/eal/eal_pci.c | 50 + lib/librte_eal/linuxapp/eal/eal_pci_init.h | 11 + lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 14 + lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 16 + lib/librte_eal/linuxapp/eal/rte_eal_version.map | 3 +- mk/rte.app.mk | 2 + 37 files changed, 52261 insertions(+), 2 deletions(-)create mode 100644
drivers/net/bnx2x/Makefile
create mode 100644drivers/net/bnx2x/bnx2x.c
create mode 100644drivers/net/bnx2x/bnx2x.h
create mode 100644drivers/net/bnx2x/bnx2x_ethdev.ccreate mode 100644drivers/net/bnx2x/bnx2x_ethdev.hcreate mode 100644drivers/net/bnx2x/bnx2x_logs.hcreate mode 100644drivers/net/bnx2x/bnx2x_rxtx.ccreate mode 100644drivers/net/bnx2x/bnx2x_rxtx.hcreate mode 100644drivers/net/bnx2x/bnx2x_stats.ccreate mode 100644drivers/net/bnx2x/bnx2x_stats.hcreate mode 100644drivers/net/bnx2x/bnx2x_vfpf.ccreate mode 100644drivers/net/bnx2x/bnx2x_vfpf.hcreate mode 100644drivers/net/bnx2x/debug.c
create mode 100644drivers/net/bnx2x/ecore_fw_defs.hcreate mode 100644drivers/net/bnx2x/ecore_hsi.hcreate mode 100644drivers/net/bnx2x/ecore_init.hcreate mode 100644drivers/net/bnx2x/ecore_init_ops.hcreate mode 100644drivers/net/bnx2x/ecore_mfw_req.hcreate mode 100644drivers/net/bnx2x/ecore_reg.hcreate mode 100644drivers/net/bnx2x/ecore_sp.ccreate mode 100644drivers/net/bnx2x/ecore_sp.hcreate mode 100644drivers/net/bnx2x/elink.c
create mode 100644drivers/net/bnx2x/elink.h
create mode 100644drivers/net/bnx2x/rte_pmd_bnx2x_version.map
Quoted 4 lines
--
2.1.4
Thanks,
Harish
________________________________
This message and any attached documents contain information from the sending company or its parent company(s), subsidiaries, divisions or branch offices that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
Quoted 7 lines
Quoted 5 lines
Stephen Hemminger (4):
eal: provide functions to access PCI config
bnx2x: driver core
bnx2x: driver support routines
bnx2x: enable PMD buildAcked-by Harish Patil <[email protected]>
This driver is too big, its style do not comply with the DPDK coding style, there is no git history (drop all in 2 patches), there is no documentation, no BSD support and it has no maintainer.
However, any new driver is welcome and can get a chance to live in the DPDK repository. That's why it has been applied.
But next changes must be clean, even if it implies a big refactoring. In case its maintenance cause problems and no declared maintainer can help, it will be dropped.
It has not been tested with all supported compilers. Please be prepare to fix the compilation shortly.