net/bnx2x: merge debug register operations into headers
[dpdk.git] / drivers / net / bnx2x / bnx2x.h
index 1b5e26e..5cefea4 100644 (file)
@@ -17,6 +17,7 @@
 #define __BNX2X_H__
 
 #include <rte_byteorder.h>
+#include <rte_spinlock.h>
 
 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
 #ifndef __LITTLE_ENDIAN
@@ -128,9 +129,6 @@ struct bnx2x_device_type {
        char     *bnx2x_name;
 };
 
-#define RTE_MBUF_DATA_DMA_ADDR(mb) \
-       ((uint64_t)((mb)->buf_physaddr + (mb)->data_off))
-
 #define BNX2X_PAGE_SHIFT       12
 #define BNX2X_PAGE_SIZE        (1 << BNX2X_PAGE_SHIFT)
 #define BNX2X_PAGE_MASK        (~(BNX2X_PAGE_SIZE - 1))
@@ -151,23 +149,6 @@ struct bnx2x_device_type {
 #define FW_PREFETCH_CNT      16U
 #define DROPLESS_FC_HEADROOM 100
 
-#ifndef MCLSHIFT
-#define MCLSHIFT                              11
-#endif
-#define MCLBYTES                              (1 << MCLSHIFT)
-
-#if !defined(MJUMPAGESIZE)
-#if BNX2X_PAGE_SIZE < 2048
-#define MJUMPAGESIZE    MCLBYTES
-#elif BNX2X_PAGE_SIZE <= 8192
-#define MJUMPAGESIZE    BNX2X_PAGE_SIZE
-#else
-#define MJUMPAGESIZE    (8 * 1024)
-#endif
-#endif
-#define MJUM9BYTES      (9 * 1024)
-#define MJUM16BYTES     (16 * 1024)
-
 /*
  * Transmit Buffer Descriptor (tx_bd) definitions*
  */
@@ -187,6 +168,8 @@ struct bnx2x_device_type {
 #define TX_PAGE(x)              (((x) & ~USABLE_TX_BD_PER_PAGE) >> 8)
 #define TX_IDX(x)               ((x) & USABLE_TX_BD_PER_PAGE)
 
+#define BDS_PER_TX_PKT         (3)
+
 /*
  * Trigger pending transmits when the number of available BDs is greater
  * than 1/8 of the total number of usable BDs.
@@ -322,10 +305,7 @@ struct bnx2x_device_type {
 /* TCP with Timestamp Option (32) + IPv6 (40) */
 
 /* max supported alignment is 256 (8 shift) */
-#define BNX2X_RX_ALIGN_SHIFT 8
-/* FW uses 2 cache lines alignment for start packet and size  */
-#define BNX2X_FW_RX_ALIGN_START (1 << BNX2X_RX_ALIGN_SHIFT)
-#define BNX2X_FW_RX_ALIGN_END   (1 << BNX2X_RX_ALIGN_SHIFT)
+#define BNX2X_RX_ALIGN_SHIFT   RTE_MAX(6, min(8, RTE_CACHE_LINE_SIZE_LOG2))
 
 #define BNX2X_PXP_DRAM_ALIGN (BNX2X_RX_ALIGN_SHIFT - 5)
 
@@ -402,7 +382,6 @@ struct bnx2x_fastpath {
        uint8_t fw_sb_id;  /* status block number in FW */
 
        uint32_t rx_buf_size;
-       int mbuf_alloc_size;
 
        int state;
 #define BNX2X_FP_STATE_CLOSED  0x01
@@ -1050,12 +1029,13 @@ struct bnx2x_softc {
        struct bnx2x_mac_ops mac_ops;
 
        /* structures for VF mbox/response/bulletin */
-       struct bnx2x_vf_mbx_msg *vf2pf_mbox;
-       struct bnx2x_dma                vf2pf_mbox_mapping;
-       struct vf_acquire_resp_tlv acquire_resp;
+       struct bnx2x_vf_mbx_msg         *vf2pf_mbox;
+       struct bnx2x_dma                 vf2pf_mbox_mapping;
+       struct vf_acquire_resp_tlv       acquire_resp;
        struct bnx2x_vf_bulletin        *pf2vf_bulletin;
-       struct bnx2x_dma                pf2vf_bulletin_mapping;
-       struct bnx2x_vf_bulletin        old_bulletin;
+       struct bnx2x_dma                 pf2vf_bulletin_mapping;
+       struct bnx2x_vf_bulletin         old_bulletin;
+       rte_spinlock_t                   vf2pf_lock;
 
        int             media;
 
@@ -1434,34 +1414,95 @@ struct bnx2x_func_init_params {
 #define BAR1 2
 #define BAR2 4
 
+static inline void
+bnx2x_reg_write8(struct bnx2x_softc *sc, size_t offset, uint8_t val)
+{
+       PMD_DEBUG_PERIODIC_LOG(DEBUG, "offset=0x%08lx val=0x%02x",
+                              (unsigned long)offset, val);
+       *((volatile uint8_t*)
+         ((uintptr_t)sc->bar[BAR0].base_addr + offset)) = val;
+}
+
+static inline void
+bnx2x_reg_write16(struct bnx2x_softc *sc, size_t offset, uint16_t val)
+{
 #ifdef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
-uint8_t bnx2x_reg_read8(struct bnx2x_softc *sc, size_t offset);
-uint16_t bnx2x_reg_read16(struct bnx2x_softc *sc, size_t offset);
-uint32_t bnx2x_reg_read32(struct bnx2x_softc *sc, size_t offset);
+       if ((offset % 2) != 0)
+               PMD_DRV_LOG(NOTICE, "Unaligned 16-bit write to 0x%08lx",
+                           (unsigned long)offset);
+#endif
+       PMD_DEBUG_PERIODIC_LOG(DEBUG, "offset=0x%08lx val=0x%04x",
+                              (unsigned long)offset, val);
+       *((volatile uint16_t*)
+         ((uintptr_t)sc->bar[BAR0].base_addr + offset)) = val;
+}
 
-void bnx2x_reg_write8(struct bnx2x_softc *sc, size_t offset, uint8_t val);
-void bnx2x_reg_write16(struct bnx2x_softc *sc, size_t offset, uint16_t val);
-void bnx2x_reg_write32(struct bnx2x_softc *sc, size_t offset, uint32_t val);
-#else
-#define bnx2x_reg_write8(sc, offset, val)\
-       *((volatile uint8_t*)((uintptr_t)sc->bar[BAR0].base_addr + offset)) = val
+static inline void
+bnx2x_reg_write32(struct bnx2x_softc *sc, size_t offset, uint32_t val)
+{
+#ifdef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
+       if ((offset % 4) != 0)
+               PMD_DRV_LOG(NOTICE, "Unaligned 32-bit write to 0x%08lx",
+                           (unsigned long)offset);
+#endif
 
-#define bnx2x_reg_write16(sc, offset, val)\
-       *((volatile uint16_t*)((uintptr_t)sc->bar[BAR0].base_addr + offset)) = val
+       PMD_DEBUG_PERIODIC_LOG(DEBUG, "offset=0x%08lx val=0x%08x",
+                              (unsigned long)offset, val);
+       *((volatile uint32_t*)
+         ((uintptr_t)sc->bar[BAR0].base_addr + offset)) = val;
+}
 
-#define bnx2x_reg_write32(sc, offset, val)\
-       *((volatile uint32_t*)((uintptr_t)sc->bar[BAR0].base_addr + offset)) = val
+static inline uint8_t
+bnx2x_reg_read8(struct bnx2x_softc *sc, size_t offset)
+{
+       uint8_t val;
+
+       val = (uint8_t)(*((volatile uint8_t*)
+                         ((uintptr_t)sc->bar[BAR0].base_addr + offset)));
+       PMD_DEBUG_PERIODIC_LOG(DEBUG, "offset=0x%08lx val=0x%02x",
+                              (unsigned long)offset, val);
 
-#define bnx2x_reg_read8(sc, offset)\
-       (*((volatile uint8_t*)((uintptr_t)sc->bar[BAR0].base_addr + offset)))
+       return val;
+}
 
-#define bnx2x_reg_read16(sc, offset)\
-       (*((volatile uint16_t*)((uintptr_t)sc->bar[BAR0].base_addr + offset)))
+static inline uint16_t
+bnx2x_reg_read16(struct bnx2x_softc *sc, size_t offset)
+{
+       uint16_t val;
 
-#define bnx2x_reg_read32(sc, offset)\
-       (*((volatile uint32_t*)((uintptr_t)sc->bar[BAR0].base_addr + offset)))
+#ifdef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
+       if ((offset % 2) != 0)
+               PMD_DRV_LOG(NOTICE, "Unaligned 16-bit read from 0x%08lx",
+                           (unsigned long)offset);
 #endif
 
+       val = (uint16_t)(*((volatile uint16_t*)
+                          ((uintptr_t)sc->bar[BAR0].base_addr + offset)));
+       PMD_DEBUG_PERIODIC_LOG(DEBUG, "offset=0x%08lx val=0x%08x",
+                              (unsigned long)offset, val);
+
+       return val;
+}
+
+static inline uint32_t
+bnx2x_reg_read32(struct bnx2x_softc *sc, size_t offset)
+{
+       uint32_t val;
+
+#ifdef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
+       if ((offset % 4) != 0)
+               PMD_DRV_LOG(NOTICE, "Unaligned 32-bit read from 0x%08lx",
+                           (unsigned long)offset);
+#endif
+
+       val = (uint32_t)(*((volatile uint32_t*)
+                          ((uintptr_t)sc->bar[BAR0].base_addr + offset)));
+       PMD_DEBUG_PERIODIC_LOG(DEBUG, "offset=0x%08lx val=0x%08x",
+                              (unsigned long)offset, val);
+
+       return val;
+}
+
 #define REG_ADDR(sc, offset) (((uint64_t)sc->bar[BAR0].base_addr) + (offset))
 
 #define REG_RD8(sc, offset)  bnx2x_reg_read8(sc, (offset))
@@ -1885,7 +1926,7 @@ int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc);
 int bnx2x_alloc_ilt_mem(struct bnx2x_softc *sc);
 void bnx2x_free_ilt_mem(struct bnx2x_softc *sc);
 void bnx2x_dump_tx_chain(struct bnx2x_fastpath * fp, int bd_prod, int count);
-int bnx2x_tx_encap(struct bnx2x_tx_queue *txq, struct rte_mbuf **m_head, int m_pkts);
+int bnx2x_tx_encap(struct bnx2x_tx_queue *txq, struct rte_mbuf *m0);
 uint8_t bnx2x_txeof(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp);
 void bnx2x_print_adapter_info(struct bnx2x_softc *sc);
 int bnx2x_intr_legacy(struct bnx2x_softc *sc, int scan_fp);
@@ -1902,8 +1943,6 @@ int bnx2x_vf_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
        int leading);
 void bnx2x_free_hsi_mem(struct bnx2x_softc *sc);
 int bnx2x_vf_set_rx_mode(struct bnx2x_softc *sc);
-int bnx2x_fill_accept_flags(struct bnx2x_softc *sc, uint32_t rx_mode,
-       unsigned long *rx_accept_flags, unsigned long *tx_accept_flags);
 int bnx2x_check_bull(struct bnx2x_softc *sc);
 
 //#define BNX2X_PULSE
@@ -1925,14 +1964,6 @@ pci_find_cap(struct bnx2x_softc *sc, uint8_t id, uint8_t type)
        return NULL;
 }
 
-static inline int is_valid_ether_addr(uint8_t *addr)
-{
-       if (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]))
-               return 0;
-       else
-               return 1;
-}
-
 static inline void
 bnx2x_set_rx_mode(struct bnx2x_softc *sc)
 {