bnx2x: Add run-time CNIC support
PATCH 1/1 bnx2x: Add run-time CNIC support
This patch replaces the BCM_CNIC compilation flag with a run-time flag. This is mainly important for the SR-IOV driver, as this driver will share the same code with the PF/hypervisor driver. Since storage is not supported in SR-IOV (while is usually enabled in the non-SR-IOV driver), we don't want to waste resources on it.
In addition this change makes the code prettier.
---
Hi Dave,
Please consider applying this patch to net-next.
Thanks,
Merav
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h | 74 +-- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 179 +++--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h | 17 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c | 9 +- .../net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | 4 +- .../net/ethernet/broadcom/bnx2x/bnx2x_init_ops.h | 2 - drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 579 ++++++++++---------- 7 files changed, 396 insertions(+), 468 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h +24 -50
@@ -34,18 +34,10 @@#include "bnx2x_hsi.h" -#if defined(CONFIG_CNIC ) || defined(CONFIG_CNIC_MODULE ) -#define BCM_CNIC 1#include "../cnic_if.h" -#endif -#ifdef BCM_CNIC -#define BNX2X_MIN_MSIX_VEC_CNT 3 -#define BNX2X_MSIX_VEC_FP_START 2 -#else -#define BNX2X_MIN_MSIX_VEC_CNT 2 -#define BNX2X_MSIX_VEC_FP_START 1 -#endif + +#define BNX2X_MIN_MSIX_VEC_CNT (bp) ((bp)->min_msix_vec_cnt)#include <linux/mdio.h>
@@ -251,20 +243,13 @@ enum {#define BNX2X_CNIC_START_ETH_CID (bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) *\ (bp)->max_cos) +/* iSCSI L2 */ #define BNX2X_ISCSI_ETH_CID (bp) (BNX2X_CNIC_START_ETH_CID(bp))/* FCoE L2 */ #define BNX2X_FCOE_ETH_CID (bp) (BNX2X_CNIC_START_ETH_CID(bp) + 1) -/** Additional rings budgeting */ -#ifdef BCM_CNIC -#define CNIC_PRESENT 1 -#define FCOE_PRESENT 1 -#else -#define CNIC_PRESENT 0 -#define FCOE_PRESENT 0 -#endif /* BCM_CNIC */ -#define NON_ETH_CONTEXT_USE (FCOE_PRESENT) +#define CNIC_ENABLED (bp) ((bp)->cnic_enabled)#define AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR \ AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
@@ -297,9 +282,7 @@ enum { OOO_TXQ_IDX_OFFSET, };#define MAX_ETH_TXQ_IDX (bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) * (bp)->max_cos) -#ifdef BCM_CNIC #define FCOE_TXQ_IDX (bp) (MAX_ETH_TXQ_IDX(bp) + FCOE_TXQ_IDX_OFFSET) -#endif /* fast path */ /*
@@ -584,15 +567,10 @@ struct bnx2x_fastpath { ->var) -#define IS_ETH_FP (fp) (fp->index < \ - BNX2X_NUM_ETH_QUEUES(fp->bp)) -#ifdef BCM_CNIC -#define IS_FCOE_FP (fp) (fp->index == FCOE_IDX(fp->bp)) -#define IS_FCOE_IDX (idx) ((idx) == FCOE_IDX(bp)) -#else -#define IS_FCOE_FP (fp) false -#define IS_FCOE_IDX (idx) false -#endif +#define IS_ETH_FP (fp) ((fp)->index < BNX2X_NUM_ETH_QUEUES((fp)->bp)) +#define IS_FCOE_FP (fp) ((fp)->index == FCOE_IDX((fp)->bp) && \ + CNIC_ENABLED((fp)->bp)) +#define IS_FCOE_IDX (idx) (CNIC_ENABLED(bp) && ((idx) == FCOE_IDX(bp)))/* MC hsi */
@@ -979,18 +957,15 @@ union cdu_context {#define CDU_ILT_PAGE_SZ (8192 << CDU_ILT_PAGE_SZ_HW)/* 32K */ #define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context)) -#ifdef BCM_CNIC #define CNIC_ISCSI_CID_MAX 256#define CNIC_FCOE_CID_MAX 2048#define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)#define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS) -#endif #define QM_ILT_PAGE_SZ_HW 0#define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW)/* 4K */ #define QM_CID_ROUND 1024 -#ifdef BCM_CNIC /* TM (timers) host DB constants */ #define TM_ILT_PAGE_SZ_HW 0#define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW)/* 4K */
@@ -1008,8 +983,6 @@ union cdu_context {#define SRC_T2_SZ SRC_ILT_SZ#define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ) -#endif -#define MAX_DMAE_C 8/* DMA memory not used in fastpath */
@@ -1203,7 +1176,6 @@ struct bnx2x {struct bnx2x_sp_objs *sp_objs;struct bnx2x_fp_stats *fp_stats;struct bnx2x_fp_txdata *bnx2x_txq; -int bnx2x_txq_size;void __iomem *regview;void __iomem *doorbells;u16 db_size;
@@ -1326,6 +1298,8 @@ struct bnx2x {#define NO_ISCSI_OOO (bp) ((bp)->flags & NO_ISCSI_OOO_FLAG)#define NO_FCOE (bp) ((bp)->flags & NO_FCOE_FLAG) +int cnic_enabled; +int pm_cap;int mrrs;
@@ -1396,6 +1370,9 @@ struct bnx2x {#define BNX2X_MAX_COS 3#define BNX2X_MAX_TX_COS 2int num_queues; +uint num_ethernet_queues; +uint num_cnic_queues; +/* The number of queues to whom MSI-X vector and napi was allocated */ int num_napi_queues;int disable_tpa;
@@ -1409,6 +1386,7 @@ struct bnx2x {u8 igu_dsb_id;u8 igu_base_sb;u8 igu_sb_cnt; +u8 min_msix_vec_cnt;dma_addr_t def_status_blk_mapping;
@@ -1454,16 +1432,16 @@ struct bnx2x {* Maximum supported number of RSS queues: number of IGU SBs minus one that goes * to CNIC. */ -#define BNX2X_MAX_RSS_COUNT (bp) ((bp)->igu_sb_cnt - CNIC_PRESENT) +#define BNX2X_MAX_RSS_COUNT (bp) ((bp)->igu_sb_cnt - CNIC_ENABLED(bp))/* * Maximum CID count that might be required by the bnx2x: * Max RSS * Max_Tx_Multi_Cos + FCoE + iSCSI */ #define BNX2X_L2_CID_COUNT (bp) (BNX2X_NUM_ETH_QUEUES(bp) * BNX2X_MULTI_TX_COS \ - + NON_ETH_CONTEXT_USE + CNIC_PRESENT) + + 2 * CNIC_ENABLED(bp))#define BNX2X_L2_MAX_CID (bp) (BNX2X_MAX_RSS_COUNT(bp) * BNX2X_MULTI_TX_COS \ - + NON_ETH_CONTEXT_USE + CNIC_PRESENT) + + 2 * CNIC_ENABLED(bp))#define L2_ILT_LINES (bp) (DIV_ROUND_UP(BNX2X_L2_CID_COUNT(bp),\ ILT_PAGE_CIDS))
@@ -1471,9 +1449,6 @@ struct bnx2x {int dropless_fc; -#ifdef BCM_CNIC -u32 cnic_flags; -#define BNX2X_CNIC_FLAG_MAC_SET 1void *t2;dma_addr_t t2_mapping;struct cnic_ops __rcu *cnic_ops;
@@ -1494,7 +1469,6 @@ struct bnx2x {/* Start index of the "special" (CNIC related) L2 cleints */ u8 cnic_base_cl_id; -#endif int dmae_ready;/* used to synchronize dmae accesses */
@@ -1623,9 +1597,10 @@ struct bnx2x {/* Tx queues may be less or equal to Rx queues */ extern int num_queues;#define BNX2X_NUM_QUEUES (bp) (bp->num_queues) -#define BNX2X_NUM_ETH_QUEUES (bp) (BNX2X_NUM_QUEUES(bp) - NON_ETH_CONTEXT_USE) +#define BNX2X_INIT_NUM_QUEUES (bp) ((bp)->init_num_queues) +#define BNX2X_NUM_ETH_QUEUES (bp) ((bp)->num_ethernet_queues)#define BNX2X_NUM_NON_CNIC_QUEUES (bp) (BNX2X_NUM_QUEUES(bp) - \ - NON_ETH_CONTEXT_USE) + (bp)->num_cnic_queues)#define BNX2X_NUM_RX_QUEUES (bp) BNX2X_NUM_QUEUES(bp)#define is_multi (bp) (BNX2X_NUM_QUEUES(bp) > 1)
@@ -2167,7 +2142,6 @@ void bnx2x_notify_link_changed(struct bnx2x *bp);#define BNX2X_MF_SD_PROTOCOL (bp) \ ((bp)->mf_config[BP_VN(bp)] & FUNC_MF_CFG_PROTOCOL_MASK) -#ifdef BCM_CNIC #define BNX2X_IS_MF_SD_PROTOCOL_ISCSI (bp) \ (BNX2X_MF_SD_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_ISCSI)
@@ -2180,13 +2154,13 @@ void bnx2x_notify_link_changed(struct bnx2x *bp);#define BNX2X_MF_EXT_PROTOCOL_FCOE (bp) ((bp)->mf_ext_config & \ MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) -#define IS_MF_FCOE_AFEX (bp) (IS_MF_AFEX(bp) && BNX2X_MF_EXT_PROTOCOL_FCOE(bp)) +#define IS_MF_FCOE_AFEX (bp) (IS_MF_AFEX(bp) && \ + BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && CNIC_ENABLED(bp)) +#define IS_MF_STORAGE_SD (bp) (IS_MF_SD(bp) && \ (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp) || \ BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) -#else -#define IS_MF_FCOE_AFEX (bp) false -#endif +#endif /* bnx2x.h */
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +79 -100
418 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h +4 -13
@@ -229,7 +229,6 @@ irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance);* @dev_instance: private instance */ irqreturn_t bnx2x_interrupt (int irq,void *dev_instance); -#ifdef BCM_CNIC /** * bnx2x_cnic_notify - send command to cnic driver
@@ -253,8 +252,6 @@ void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);*/ void bnx2x_setup_cnic_info (struct bnx2x *bp); -#endif -/** * bnx2x_int_enable - enable HW interrupts. *
@@ -537,7 +534,7 @@ void bnx2x_free_mem_bp(struct bnx2x *bp);*/ int bnx2x_change_mtu (struct net_device *dev,int new_mtu); -#if defined(NETDEV_FCOE_WWNN ) && defined(BCM_CNIC ) +#ifdef NETDEV_FCOE_WWNN /** * bnx2x_fcoe_get_wwn - return the requested WWN value for this port *
@@ -971,11 +968,9 @@ static inline u8 bnx2x_stats_id(struct bnx2x_fastpath *fp) {struct bnx2x *bp = fp->bp;if (!CHIP_IS_E1x (bp)) { -#ifdef BCM_CNIC /* there are special statistics counters for FCoE 136..140 */ if (IS_FCOE_FP (fp))return bp->cnic_base_cl_id + (bp->pf_num >>1 ); -#endif return fp->cl_id; }return fp->cl_id +BP_PORT (bp) * FP_SB_MAX_E1x;
@@ -1093,7 +1088,6 @@ static inline void bnx2x_init_txdata(struct bnx2x *bp, txdata->cid, txdata->txq_index); } -#ifdef BCM_CNIC static inline u8 bnx2x_cnic_eth_cl_id (struct bnx2x *bp,u8 cl_idx) { return bp->cnic_base_cl_id + cl_idx +
@@ -1153,7 +1147,6 @@ static inline void bnx2x_init_fcoe_fp(struct bnx2x *bp) fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id, fp->igu_sb_id); } -#endif static inline int bnx2x_clean_tx_queue (struct bnx2x *bp,struct bnx2x_fp_txdata *txdata)
@@ -1271,7 +1264,7 @@ static inline bool bnx2x_mtu_allows_gro(int mtu)*/ return mtu <=SGE_PAGE_SIZE && (U_ETH_SGL_SIZE * fpp) <=MAX_SKB_FRAGS ; } -#ifdef BCM_CNIC +/** * bnx2x_get_iscsi_info - update iSCSI params according to licensing info. *
@@ -1279,7 +1272,6 @@ static inline bool bnx2x_mtu_allows_gro(int mtu)* */ void bnx2x_get_iscsi_info (struct bnx2x *bp); -#endif /** * bnx2x_link_sync_notify - send notification to other functions.
@@ -1333,11 +1325,10 @@ static inline bool bnx2x_is_valid_ether_addr(struct bnx2x *bp, u8 *addr) {if (is_valid_ether_addr (addr))return true; -#ifdef BCM_CNIC -if (is_zero_ether_addr (addr) && +if (CNIC_ENABLED (bp) &&is_zero_ether_addr (addr) && (IS_MF_STORAGE_SD (bp) ||IS_MF_FCOE_AFEX (bp)))return true; -#endif +return false; }
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +5 -4
@@ -1912,10 +1912,11 @@ static void bnx2x_dcbnl_get_perm_hw_addr(struct net_device *netdev,/* first the HW mac address */ memcpy (perm_addr, netdev->dev_addr, netdev->addr_len); -#ifdef BCM_CNIC -/* second SAN address */ -memcpy (perm_addr+netdev->addr_len, bp->fip_mac, netdev->addr_len); -#endif + +if (CNIC_ENABLED (bp)) +/* second SAN address */ +memcpy (perm_addr+netdev->addr_len, bp->fip_mac, + netdev->addr_len); } static void bnx2x_dcbnl_set_pg_tccfg_tx(struct net_device *netdev, int prio,
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +3 -1
@@ -2890,7 +2890,9 @@ static void bnx2x_change_num_queues(struct bnx2x *bp, int num_rss) {bnx2x_del_all_napi (bp);bnx2x_disable_msi (bp); -BNX2X_NUM_QUEUES (bp) = num_rss +NON_ETH_CONTEXT_USE ; + bp->num_ethernet_queues = num_rss; + bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues; +BNX2X_DEV_INFO ("set number of queues to %d\n" , bp->num_queues);bnx2x_set_int_mode (bp);bnx2x_add_all_napi (bp); }
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init_ops.h +0 -2
@@ -890,7 +890,6 @@ static void bnx2x_qm_init_ptr_table(struct bnx2x *bp, int qm_cid_count,/**************************************************************************** * SRC initializations ****************************************************************************/ -#ifdef BCM_CNIC /* called during init func stage */ static void bnx2x_src_init_t2 (struct bnx2x *bp,struct src_ent *t2,dma_addr_t t2_mapping,int src_cid_count)
@@ -915,5 +914,4 @@ static void bnx2x_src_init_t2(struct bnx2x *bp, struct src_ent *t2,U64_HI ((u64 )t2_mapping + (src_cid_count-1) * sizeof(struct src_ent))); } -#endif #endif /* BNX2X_INIT_OPS_H */
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +281 -298
1,147 lines not on this page · raw message
--
1.7.10
David Miller
maintainerFrom: "Merav Sicron" <[email protected]>
Date: Sun, 8 Jul 2012 12:48:34 +0300
Quoted 6 lines
This patch replaces the
BCM_CNICcompilation flag with a run-time flag. This is mainly important for the SR-IOV driver, as this driver will share the same code with the PF/hypervisor driver. Since storage is not supported in SR-IOV (while is usually enabled in the non-SR-IOV driver), we don't want to waste resources on it.
In addition this change makes the code prettier.
...
Quoted 2 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +1
-1-static const struct net_device_ops bnx2x_netdev_ops = { +static struct net_device_ops bnx2x_netdev_ops = {
...
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c static int __devinit bnx2x_init_dev(struct pci_dev *pdev, · line 11397
Quoted 7 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +6
-0+if (CNIC_ENABLED (bp)) + bnx2x_netdev_ops.ndo_select_queue = bnx2x_select_queue; +#if defined(NETDEV_FCOE_WWNN ) +if (CNIC_ENABLED (bp)) + bnx2x_netdev_ops.ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn; +#endif
...
+static int set_is_cnic_enabled(void)
+{
+#if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
+ return 1;
+#else
+ return 0;
+#endif
+}
This is basically a joke.
You're losing const'ness of net_device_ops and other nice things for what is still, in the end, set by kconfig options.
I'm not applying crap like this, sorry.
Quoted 30 lines · David Miller
From: "Merav Sicron" <[email protected]>
Date: Sun, 8 Jul 2012 12:48:34 +0300Quoted 6 lines
This patch replaces the
BCM_CNICcompilation flag with a run-time flag. This is mainly important for the SR-IOV driver, as this driver will share the same code with the PF/hypervisor driver. Since storage is not supported in SR-IOV (while is usually enabled in the non-SR-IOV driver), we don't want to waste resources on it.
In addition this change makes the code prettier....
Quoted 2 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +1
-1-static const struct net_device_ops bnx2x_netdev_ops = { +static struct net_device_ops bnx2x_netdev_ops = {...
Quoted 7 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +6
-0+if (CNIC_ENABLED (bp)) + bnx2x_netdev_ops.ndo_select_queue = bnx2x_select_queue; +#if defined(NETDEV_FCOE_WWNN ) +if (CNIC_ENABLED (bp)) + bnx2x_netdev_ops.ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn; +#endif ...
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +8
-0+static int set_is_cnic_enabled (void ) +{ +#if defined(CONFIG_CNIC ) || defined(CONFIG_CNIC_MODULE ) +return 1 ; +#else +return 0 ; +#endif +}
Quoted 7 lines
This is basically a joke.
You're losing const'ness of
net_device_opsand other nice things for what is still, in the end, set by kconfig options.I'm not applying crap like this, sorry.
It seems that I didn't explain our motivation well enough... This feature is indeed not useful for the current bnx2x functionality. However we are adding support for a VF driver to be used in SR-IOV, and we will have single-binary bnx2x which will be used in both PF/Hypervisor and VF (hopefully will send a patch on it in a couple of weeks).
Since we want CNIC in the PF/Hypervisor but don't want CNIC in the VF, and since it is a single binary, we can't use a compilation flag but should rather use a run-time flag.
The set_is_cnic_enabled function will eventually look something like this:
static int set_is_cnic_enabled(bool is_vf)
{
if (is_vf)
return 0;
#if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
return 1;
#else
return 0;#endif
}
Thanks,
Merav
Quoted 10 lines · Merav Sicron
static int
set_is_cnic_enabled(bool is_vf){ if (is_vf) return 0; #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE) return 1; #else return 0;#endif
}
Small note : this should use booleans and can use
if (is_vf)
return false;
return IS_ENABLED(CONFIG_CNIC);
David Miller
maintainerFrom: "Merav Sicron" <[email protected]>
Date: Sun, 8 Jul 2012 14:00:39 +0300
Quoted 10 lines
static int
set_is_cnic_enabled(bool is_vf){ if (is_vf) return 0; #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE) return 1; #else return 0;#endif
}
I still think this is beyond ugly.
This ifdef just wants to die completely. It serves no real purpose as every distribution vendor that turns on your driver will turn CNIC on as well.
And you have to address the lost of const'ness of the netdevice ops. If you absolutely must have runtime method choices, you must use multiple instances of netdevice ops and assign the appropriate one.