aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSathya Perla <sathya.perla@emulex.com>2013-08-27 07:27:32 -0400
committerDavid S. Miller <davem@davemloft.net>2013-08-27 15:57:04 -0400
commit92bf14abf7a064936b5e6baab30661da86a86e52 (patch)
treed8268f13c45c47725994a1eeaa8ab94563101322 /drivers
parent150d58c7094ee02e5e3e876e288a95e254c5e830 (diff)
be2net: refactor be_get_resources() code
1) use be_resources{} struct to query/store HW resource limits 2) The HW queue/resource limits for BE2/BE3 chips are mostly called out in driver as constants. Code to handle this is scattered across various places in be_setup(). Consolidate this code into BEx_get_resources(). For Lancer-R, Skyhawk-R, these limits are queried from FW. Signed-off-by: Sathya Perla <sathya.perla@emulex.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/ethernet/emulex/benet/be.h60
-rw-r--r--drivers/net/ethernet/emulex/benet/be_cmds.c51
-rw-r--r--drivers/net/ethernet/emulex/benet/be_cmds.h8
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c293
-rw-r--r--drivers/net/ethernet/emulex/benet/be_roce.c2
-rw-r--r--drivers/net/ethernet/emulex/benet/be_roce.h4
6 files changed, 229 insertions, 189 deletions
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index 7c5f9f2c5e03..8b416355879f 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -101,12 +101,15 @@ static inline char *nic_name(struct pci_dev *pdev)
101 101
102#define BE3_MAX_RSS_QS 8 102#define BE3_MAX_RSS_QS 8
103#define BE2_MAX_RSS_QS 4 103#define BE2_MAX_RSS_QS 4
104#define BE3_MAX_TX_QS 8
104#define MAX_RSS_QS BE3_MAX_RSS_QS 105#define MAX_RSS_QS BE3_MAX_RSS_QS
105#define MAX_RX_QS (MAX_RSS_QS + 1) /* RSS qs + 1 def Rx */ 106#define MAX_RX_QS (MAX_RSS_QS + 1) /* RSS qs + 1 def Rx */
107#define MAX_EVT_QS MAX_RSS_QS
106 108
107#define MAX_TX_QS 8 109#define MAX_TX_QS 8
108#define MAX_ROCE_EQS 5 110#define MAX_ROCE_EQS 5
109#define MAX_MSIX_VECTORS (MAX_RSS_QS + MAX_ROCE_EQS) /* RSS qs + RoCE */ 111#define MAX_MSIX_VECTORS (MAX_RSS_QS + MAX_ROCE_EQS) /* RSS qs + RoCE */
112#define MIN_MSIX_VECTORS 1
110#define BE_TX_BUDGET 256 113#define BE_TX_BUDGET 256
111#define BE_NAPI_WEIGHT 64 114#define BE_NAPI_WEIGHT 64
112#define MAX_RX_POST BE_NAPI_WEIGHT /* Frags posted at a time */ 115#define MAX_RX_POST BE_NAPI_WEIGHT /* Frags posted at a time */
@@ -353,6 +356,18 @@ struct phy_info {
353 u32 supported; 356 u32 supported;
354}; 357};
355 358
359struct be_resources {
360 u16 max_vfs; /* Total VFs "really" supported by FW/HW */
361 u16 max_mcast_mac;
362 u16 max_tx_qs;
363 u16 max_rss_qs;
364 u16 max_rx_qs;
365 u16 max_uc_mac; /* Max UC MACs programmable */
366 u16 max_vlans; /* Number of vlans supported */
367 u16 max_evt_qs;
368 u32 if_cap_flags;
369};
370
356struct be_adapter { 371struct be_adapter {
357 struct pci_dev *pdev; 372 struct pci_dev *pdev;
358 struct net_device *netdev; 373 struct net_device *netdev;
@@ -370,18 +385,19 @@ struct be_adapter {
370 spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */ 385 spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */
371 spinlock_t mcc_cq_lock; 386 spinlock_t mcc_cq_lock;
372 387
373 u32 num_msix_vec; 388 u16 cfg_num_qs; /* configured via set-channels */
374 u32 num_evt_qs; 389 u16 num_evt_qs;
375 struct be_eq_obj eq_obj[MAX_MSIX_VECTORS]; 390 u16 num_msix_vec;
391 struct be_eq_obj eq_obj[MAX_EVT_QS];
376 struct msix_entry msix_entries[MAX_MSIX_VECTORS]; 392 struct msix_entry msix_entries[MAX_MSIX_VECTORS];
377 bool isr_registered; 393 bool isr_registered;
378 394
379 /* TX Rings */ 395 /* TX Rings */
380 u32 num_tx_qs; 396 u16 num_tx_qs;
381 struct be_tx_obj tx_obj[MAX_TX_QS]; 397 struct be_tx_obj tx_obj[MAX_TX_QS];
382 398
383 /* Rx rings */ 399 /* Rx rings */
384 u32 num_rx_qs; 400 u16 num_rx_qs;
385 struct be_rx_obj rx_obj[MAX_RX_QS]; 401 struct be_rx_obj rx_obj[MAX_RX_QS];
386 u32 big_page_size; /* Compounded page size shared by rx wrbs */ 402 u32 big_page_size; /* Compounded page size shared by rx wrbs */
387 403
@@ -431,8 +447,8 @@ struct be_adapter {
431 u32 flash_status; 447 u32 flash_status;
432 struct completion flash_compl; 448 struct completion flash_compl;
433 449
434 u32 num_vfs; /* Number of VFs provisioned by PF driver */ 450 struct be_resources res; /* resources available for the func */
435 u32 dev_num_vfs; /* Number of VFs supported by HW */ 451 u16 num_vfs; /* Number of VFs provisioned by PF */
436 u8 virtfn; 452 u8 virtfn;
437 struct be_vf_cfg *vf_cfg; 453 struct be_vf_cfg *vf_cfg;
438 bool be3_native; 454 bool be3_native;
@@ -447,21 +463,13 @@ struct be_adapter {
447 u16 qnq_vid; 463 u16 qnq_vid;
448 u32 msg_enable; 464 u32 msg_enable;
449 int be_get_temp_freq; 465 int be_get_temp_freq;
450 u16 max_mcast_mac;
451 u16 max_tx_queues;
452 u16 max_rss_queues;
453 u16 max_rx_queues;
454 u16 max_pmac_cnt;
455 u16 max_vlans;
456 u16 max_event_queues;
457 u32 if_cap_flags;
458 u8 pf_number; 466 u8 pf_number;
459 u64 rss_flags; 467 u64 rss_flags;
460}; 468};
461 469
462#define be_physfn(adapter) (!adapter->virtfn) 470#define be_physfn(adapter) (!adapter->virtfn)
463#define sriov_enabled(adapter) (adapter->num_vfs > 0) 471#define sriov_enabled(adapter) (adapter->num_vfs > 0)
464#define sriov_want(adapter) (adapter->dev_num_vfs && num_vfs && \ 472#define sriov_want(adapter) (be_max_vfs(adapter) && num_vfs && \
465 be_physfn(adapter)) 473 be_physfn(adapter))
466#define for_all_vfs(adapter, vf_cfg, i) \ 474#define for_all_vfs(adapter, vf_cfg, i) \
467 for (i = 0, vf_cfg = &adapter->vf_cfg[i]; i < adapter->num_vfs; \ 475 for (i = 0, vf_cfg = &adapter->vf_cfg[i]; i < adapter->num_vfs; \
@@ -470,6 +478,26 @@ struct be_adapter {
470#define ON 1 478#define ON 1
471#define OFF 0 479#define OFF 0
472 480
481#define be_max_vlans(adapter) (adapter->res.max_vlans)
482#define be_max_uc(adapter) (adapter->res.max_uc_mac)
483#define be_max_mc(adapter) (adapter->res.max_mcast_mac)
484#define be_max_vfs(adapter) (adapter->res.max_vfs)
485#define be_max_rss(adapter) (adapter->res.max_rss_qs)
486#define be_max_txqs(adapter) (adapter->res.max_tx_qs)
487#define be_max_prio_txqs(adapter) (adapter->res.max_prio_tx_qs)
488#define be_max_rxqs(adapter) (adapter->res.max_rx_qs)
489#define be_max_eqs(adapter) (adapter->res.max_evt_qs)
490#define be_if_cap_flags(adapter) (adapter->res.if_cap_flags)
491
492static inline u16 be_max_qs(struct be_adapter *adapter)
493{
494 /* If no RSS, need atleast the one def RXQ */
495 u16 num = max_t(u16, be_max_rss(adapter), 1);
496
497 num = min(num, be_max_eqs(adapter));
498 return min_t(u16, num, num_online_cpus());
499}
500
473#define lancer_chip(adapter) (adapter->pdev->device == OC_DEVICE_ID3 || \ 501#define lancer_chip(adapter) (adapter->pdev->device == OC_DEVICE_ID3 || \
474 adapter->pdev->device == OC_DEVICE_ID4) 502 adapter->pdev->device == OC_DEVICE_ID4)
475 503
diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c
index bc6f95814998..5458a4357ae0 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -1776,8 +1776,7 @@ int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
1776 */ 1776 */
1777 req->if_flags_mask |= 1777 req->if_flags_mask |=
1778 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS & 1778 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
1779 adapter->if_cap_flags); 1779 be_if_cap_flags(adapter));
1780
1781 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev)); 1780 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
1782 netdev_for_each_mc_addr(ha, adapter->netdev) 1781 netdev_for_each_mc_addr(ha, adapter->netdev)
1783 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN); 1782 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
@@ -3103,8 +3102,26 @@ static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf,
3103 return NULL; 3102 return NULL;
3104} 3103}
3105 3104
3105static void be_copy_nic_desc(struct be_resources *res,
3106 struct be_nic_res_desc *desc)
3107{
3108 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
3109 res->max_vlans = le16_to_cpu(desc->vlan_count);
3110 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3111 res->max_tx_qs = le16_to_cpu(desc->txq_count);
3112 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
3113 res->max_rx_qs = le16_to_cpu(desc->rq_count);
3114 res->max_evt_qs = le16_to_cpu(desc->eq_count);
3115 /* Clear flags that driver is not interested in */
3116 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
3117 BE_IF_CAP_FLAGS_WANT;
3118 /* Need 1 RXQ as the default RXQ */
3119 if (res->max_rss_qs && res->max_rss_qs == res->max_rx_qs)
3120 res->max_rss_qs -= 1;
3121}
3122
3106/* Uses Mbox */ 3123/* Uses Mbox */
3107int be_cmd_get_func_config(struct be_adapter *adapter) 3124int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
3108{ 3125{
3109 struct be_mcc_wrb *wrb; 3126 struct be_mcc_wrb *wrb;
3110 struct be_cmd_req_get_func_config *req; 3127 struct be_cmd_req_get_func_config *req;
@@ -3152,18 +3169,7 @@ int be_cmd_get_func_config(struct be_adapter *adapter)
3152 } 3169 }
3153 3170
3154 adapter->pf_number = desc->pf_num; 3171 adapter->pf_number = desc->pf_num;
3155 adapter->max_pmac_cnt = le16_to_cpu(desc->unicast_mac_count); 3172 be_copy_nic_desc(res, desc);
3156 adapter->max_vlans = le16_to_cpu(desc->vlan_count);
3157 adapter->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3158 adapter->max_tx_queues = le16_to_cpu(desc->txq_count);
3159 adapter->max_rss_queues = le16_to_cpu(desc->rssq_count);
3160 adapter->max_rx_queues = le16_to_cpu(desc->rq_count);
3161
3162 adapter->max_event_queues = le16_to_cpu(desc->eq_count);
3163 adapter->if_cap_flags = le32_to_cpu(desc->cap_flags);
3164
3165 /* Clear flags that driver is not interested in */
3166 adapter->if_cap_flags &= BE_IF_CAP_FLAGS_WANT;
3167 } 3173 }
3168err: 3174err:
3169 mutex_unlock(&adapter->mbox_lock); 3175 mutex_unlock(&adapter->mbox_lock);
@@ -3234,8 +3240,8 @@ err:
3234} 3240}
3235 3241
3236/* Uses sync mcc, if MCCQ is already created otherwise mbox */ 3242/* Uses sync mcc, if MCCQ is already created otherwise mbox */
3237int be_cmd_get_profile_config(struct be_adapter *adapter, u32 *cap_flags, 3243int be_cmd_get_profile_config(struct be_adapter *adapter,
3238 u16 *txq_count, u8 domain) 3244 struct be_resources *res, u8 domain)
3239{ 3245{
3240 struct be_cmd_resp_get_profile_config *resp; 3246 struct be_cmd_resp_get_profile_config *resp;
3241 struct be_pcie_res_desc *pcie; 3247 struct be_pcie_res_desc *pcie;
@@ -3264,15 +3270,12 @@ int be_cmd_get_profile_config(struct be_adapter *adapter, u32 *cap_flags,
3264 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param, 3270 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param,
3265 desc_count); 3271 desc_count);
3266 if (pcie) 3272 if (pcie)
3267 adapter->dev_num_vfs = le16_to_cpu(pcie->num_vfs); 3273 res->max_vfs = le16_to_cpu(pcie->num_vfs);
3268 3274
3269 nic = be_get_nic_desc(resp->func_param, desc_count); 3275 nic = be_get_nic_desc(resp->func_param, desc_count);
3270 if (nic) { 3276 if (nic)
3271 if (cap_flags) 3277 be_copy_nic_desc(res, nic);
3272 *cap_flags = le32_to_cpu(nic->cap_flags); 3278
3273 if (txq_count)
3274 *txq_count = le16_to_cpu(nic->txq_count);
3275 }
3276err: 3279err:
3277 if (cmd.va) 3280 if (cmd.va)
3278 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma); 3281 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.h b/drivers/net/ethernet/emulex/benet/be_cmds.h
index 8ebed17b57f1..52f3d4ca0056 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.h
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.h
@@ -1980,10 +1980,10 @@ extern int lancer_initiate_dump(struct be_adapter *adapter);
1980extern bool dump_present(struct be_adapter *adapter); 1980extern bool dump_present(struct be_adapter *adapter);
1981extern int lancer_test_and_set_rdy_state(struct be_adapter *adapter); 1981extern int lancer_test_and_set_rdy_state(struct be_adapter *adapter);
1982extern int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name); 1982extern int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name);
1983extern int be_cmd_get_func_config(struct be_adapter *adapter); 1983int be_cmd_get_func_config(struct be_adapter *adapter,
1984extern int be_cmd_get_profile_config(struct be_adapter *adapter, u32 *cap_flags, 1984 struct be_resources *res);
1985 u16 *txq_count, u8 domain); 1985int be_cmd_get_profile_config(struct be_adapter *adapter,
1986 1986 struct be_resources *res, u8 domain);
1987extern int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps, 1987extern int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps,
1988 u8 domain); 1988 u8 domain);
1989extern int be_cmd_get_if_id(struct be_adapter *adapter, 1989extern int be_cmd_get_if_id(struct be_adapter *adapter,
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 6f040d851eb2..d34ea98ea2c4 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -1001,7 +1001,7 @@ static int be_vid_config(struct be_adapter *adapter)
1001 if (adapter->promiscuous) 1001 if (adapter->promiscuous)
1002 return 0; 1002 return 0;
1003 1003
1004 if (adapter->vlans_added > adapter->max_vlans) 1004 if (adapter->vlans_added > be_max_vlans(adapter))
1005 goto set_vlan_promisc; 1005 goto set_vlan_promisc;
1006 1006
1007 /* Construct VLAN Table to give to HW */ 1007 /* Construct VLAN Table to give to HW */
@@ -1042,7 +1042,7 @@ static int be_vlan_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
1042 goto ret; 1042 goto ret;
1043 1043
1044 adapter->vlan_tag[vid] = 1; 1044 adapter->vlan_tag[vid] = 1;
1045 if (adapter->vlans_added <= (adapter->max_vlans + 1)) 1045 if (adapter->vlans_added <= (be_max_vlans(adapter) + 1))
1046 status = be_vid_config(adapter); 1046 status = be_vid_config(adapter);
1047 1047
1048 if (!status) 1048 if (!status)
@@ -1068,7 +1068,7 @@ static int be_vlan_rem_vid(struct net_device *netdev, __be16 proto, u16 vid)
1068 goto ret; 1068 goto ret;
1069 1069
1070 adapter->vlan_tag[vid] = 0; 1070 adapter->vlan_tag[vid] = 0;
1071 if (adapter->vlans_added <= adapter->max_vlans) 1071 if (adapter->vlans_added <= be_max_vlans(adapter))
1072 status = be_vid_config(adapter); 1072 status = be_vid_config(adapter);
1073 1073
1074 if (!status) 1074 if (!status)
@@ -1101,7 +1101,7 @@ static void be_set_rx_mode(struct net_device *netdev)
1101 1101
1102 /* Enable multicast promisc if num configured exceeds what we support */ 1102 /* Enable multicast promisc if num configured exceeds what we support */
1103 if (netdev->flags & IFF_ALLMULTI || 1103 if (netdev->flags & IFF_ALLMULTI ||
1104 netdev_mc_count(netdev) > adapter->max_mcast_mac) { 1104 netdev_mc_count(netdev) > be_max_mc(adapter)) {
1105 be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON); 1105 be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON);
1106 goto done; 1106 goto done;
1107 } 1107 }
@@ -1115,7 +1115,7 @@ static void be_set_rx_mode(struct net_device *netdev)
1115 adapter->pmac_id[i], 0); 1115 adapter->pmac_id[i], 0);
1116 } 1116 }
1117 1117
1118 if (netdev_uc_count(netdev) > adapter->max_pmac_cnt) { 1118 if (netdev_uc_count(netdev) > be_max_uc(adapter)) {
1119 be_cmd_rx_filter(adapter, IFF_PROMISC, ON); 1119 be_cmd_rx_filter(adapter, IFF_PROMISC, ON);
1120 adapter->promiscuous = true; 1120 adapter->promiscuous = true;
1121 goto done; 1121 goto done;
@@ -1924,7 +1924,8 @@ static int be_evt_queues_create(struct be_adapter *adapter)
1924 struct be_eq_obj *eqo; 1924 struct be_eq_obj *eqo;
1925 int i, rc; 1925 int i, rc;
1926 1926
1927 adapter->num_evt_qs = num_irqs(adapter); 1927 adapter->num_evt_qs = min_t(u16, num_irqs(adapter),
1928 adapter->cfg_num_qs);
1928 1929
1929 for_all_evt_queues(adapter, eqo, i) { 1930 for_all_evt_queues(adapter, eqo, i) {
1930 eqo->adapter = adapter; 1931 eqo->adapter = adapter;
@@ -2013,25 +2014,13 @@ static void be_tx_queues_destroy(struct be_adapter *adapter)
2013 } 2014 }
2014} 2015}
2015 2016
2016static int be_num_txqs_want(struct be_adapter *adapter)
2017{
2018 if ((!lancer_chip(adapter) && sriov_want(adapter)) ||
2019 be_is_mc(adapter) ||
2020 (!lancer_chip(adapter) && !be_physfn(adapter)) ||
2021 BE2_chip(adapter))
2022 return 1;
2023 else
2024 return adapter->max_tx_queues;
2025}
2026
2027static int be_tx_cqs_create(struct be_adapter *adapter) 2017static int be_tx_cqs_create(struct be_adapter *adapter)
2028{ 2018{
2029 struct be_queue_info *cq, *eq; 2019 struct be_queue_info *cq, *eq;
2030 int status;
2031 struct be_tx_obj *txo; 2020 struct be_tx_obj *txo;
2032 u8 i; 2021 int status, i;
2033 2022
2034 adapter->num_tx_qs = be_num_txqs_want(adapter); 2023 adapter->num_tx_qs = min(adapter->num_evt_qs, be_max_txqs(adapter));
2035 if (adapter->num_tx_qs != MAX_TX_QS) { 2024 if (adapter->num_tx_qs != MAX_TX_QS) {
2036 rtnl_lock(); 2025 rtnl_lock();
2037 netif_set_real_num_tx_queues(adapter->netdev, 2026 netif_set_real_num_tx_queues(adapter->netdev,
@@ -2098,11 +2087,15 @@ static int be_rx_cqs_create(struct be_adapter *adapter)
2098 struct be_rx_obj *rxo; 2087 struct be_rx_obj *rxo;
2099 int rc, i; 2088 int rc, i;
2100 2089
2101 /* We'll create as many RSS rings as there are irqs. 2090 /* We can create as many RSS rings as there are EQs. */
2102 * But when there's only one irq there's no use creating RSS rings 2091 adapter->num_rx_qs = adapter->num_evt_qs;
2092
2093 /* We'll use RSS only if atleast 2 RSS rings are supported.
2094 * When RSS is used, we'll need a default RXQ for non-IP traffic.
2103 */ 2095 */
2104 adapter->num_rx_qs = (num_irqs(adapter) > 1) ? 2096 if (adapter->num_rx_qs > 1)
2105 num_irqs(adapter) + 1 : 1; 2097 adapter->num_rx_qs++;
2098
2106 if (adapter->num_rx_qs != MAX_RX_QS) { 2099 if (adapter->num_rx_qs != MAX_RX_QS) {
2107 rtnl_lock(); 2100 rtnl_lock();
2108 netif_set_real_num_rx_queues(adapter->netdev, 2101 netif_set_real_num_rx_queues(adapter->netdev,
@@ -2375,35 +2368,20 @@ static void be_msix_disable(struct be_adapter *adapter)
2375 } 2368 }
2376} 2369}
2377 2370
2378static uint be_num_rss_want(struct be_adapter *adapter)
2379{
2380 u32 num = 0;
2381
2382 if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) &&
2383 (lancer_chip(adapter) ||
2384 (!sriov_want(adapter) && be_physfn(adapter)))) {
2385 num = adapter->max_rss_queues;
2386 num = min_t(u32, num, (u32)netif_get_num_default_rss_queues());
2387 }
2388 return num;
2389}
2390
2391static int be_msix_enable(struct be_adapter *adapter) 2371static int be_msix_enable(struct be_adapter *adapter)
2392{ 2372{
2393#define BE_MIN_MSIX_VECTORS 1 2373 int i, status, num_vec;
2394 int i, status, num_vec, num_roce_vec = 0;
2395 struct device *dev = &adapter->pdev->dev; 2374 struct device *dev = &adapter->pdev->dev;
2396 2375
2397 /* If RSS queues are not used, need a vec for default RX Q */ 2376 /* If RoCE is supported, program the max number of NIC vectors that
2398 num_vec = min(be_num_rss_want(adapter), num_online_cpus()); 2377 * may be configured via set-channels, along with vectors needed for
2399 if (be_roce_supported(adapter)) { 2378 * RoCe. Else, just program the number we'll use initially.
2400 num_roce_vec = min_t(u32, MAX_ROCE_MSIX_VECTORS, 2379 */
2401 (num_online_cpus() + 1)); 2380 if (be_roce_supported(adapter))
2402 num_roce_vec = min(num_roce_vec, MAX_ROCE_EQS); 2381 num_vec = min_t(int, 2 * be_max_eqs(adapter),
2403 num_vec += num_roce_vec; 2382 2 * num_online_cpus());
2404 num_vec = min(num_vec, MAX_MSIX_VECTORS); 2383 else
2405 } 2384 num_vec = adapter->cfg_num_qs;
2406 num_vec = max(num_vec, BE_MIN_MSIX_VECTORS);
2407 2385
2408 for (i = 0; i < num_vec; i++) 2386 for (i = 0; i < num_vec; i++)
2409 adapter->msix_entries[i].entry = i; 2387 adapter->msix_entries[i].entry = i;
@@ -2411,7 +2389,7 @@ static int be_msix_enable(struct be_adapter *adapter)
2411 status = pci_enable_msix(adapter->pdev, adapter->msix_entries, num_vec); 2389 status = pci_enable_msix(adapter->pdev, adapter->msix_entries, num_vec);
2412 if (status == 0) { 2390 if (status == 0) {
2413 goto done; 2391 goto done;
2414 } else if (status >= BE_MIN_MSIX_VECTORS) { 2392 } else if (status >= MIN_MSIX_VECTORS) {
2415 num_vec = status; 2393 num_vec = status;
2416 status = pci_enable_msix(adapter->pdev, adapter->msix_entries, 2394 status = pci_enable_msix(adapter->pdev, adapter->msix_entries,
2417 num_vec); 2395 num_vec);
@@ -2420,23 +2398,22 @@ static int be_msix_enable(struct be_adapter *adapter)
2420 } 2398 }
2421 2399
2422 dev_warn(dev, "MSIx enable failed\n"); 2400 dev_warn(dev, "MSIx enable failed\n");
2401
2423 /* INTx is not supported in VFs, so fail probe if enable_msix fails */ 2402 /* INTx is not supported in VFs, so fail probe if enable_msix fails */
2424 if (!be_physfn(adapter)) 2403 if (!be_physfn(adapter))
2425 return status; 2404 return status;
2426 return 0; 2405 return 0;
2427done: 2406done:
2428 if (be_roce_supported(adapter)) { 2407 if (be_roce_supported(adapter) && num_vec > MIN_MSIX_VECTORS) {
2429 if (num_vec > num_roce_vec) { 2408 adapter->num_msix_roce_vec = num_vec / 2;
2430 adapter->num_msix_vec = num_vec - num_roce_vec; 2409 dev_info(dev, "enabled %d MSI-x vector(s) for RoCE\n",
2431 adapter->num_msix_roce_vec = 2410 adapter->num_msix_roce_vec);
2432 num_vec - adapter->num_msix_vec; 2411 }
2433 } else { 2412
2434 adapter->num_msix_vec = num_vec; 2413 adapter->num_msix_vec = num_vec - adapter->num_msix_roce_vec;
2435 adapter->num_msix_roce_vec = 0; 2414
2436 } 2415 dev_info(dev, "enabled %d MSI-x vector(s) for NIC\n",
2437 } else 2416 adapter->num_msix_vec);
2438 adapter->num_msix_vec = num_vec;
2439 dev_info(dev, "enabled %d MSI-x vector(s)\n", adapter->num_msix_vec);
2440 return 0; 2417 return 0;
2441} 2418}
2442 2419
@@ -2829,6 +2806,7 @@ static int be_clear(struct be_adapter *adapter)
2829 2806
2830static int be_vfs_if_create(struct be_adapter *adapter) 2807static int be_vfs_if_create(struct be_adapter *adapter)
2831{ 2808{
2809 struct be_resources res = {0};
2832 struct be_vf_cfg *vf_cfg; 2810 struct be_vf_cfg *vf_cfg;
2833 u32 cap_flags, en_flags, vf; 2811 u32 cap_flags, en_flags, vf;
2834 int status; 2812 int status;
@@ -2837,9 +2815,12 @@ static int be_vfs_if_create(struct be_adapter *adapter)
2837 BE_IF_FLAGS_MULTICAST; 2815 BE_IF_FLAGS_MULTICAST;
2838 2816
2839 for_all_vfs(adapter, vf_cfg, vf) { 2817 for_all_vfs(adapter, vf_cfg, vf) {
2840 if (!BE3_chip(adapter)) 2818 if (!BE3_chip(adapter)) {
2841 be_cmd_get_profile_config(adapter, &cap_flags, 2819 status = be_cmd_get_profile_config(adapter, &res,
2842 NULL, vf + 1); 2820 vf + 1);
2821 if (!status)
2822 cap_flags = res.if_cap_flags;
2823 }
2843 2824
2844 /* If a FW profile exists, then cap_flags are updated */ 2825 /* If a FW profile exists, then cap_flags are updated */
2845 en_flags = cap_flags & (BE_IF_FLAGS_UNTAGGED | 2826 en_flags = cap_flags & (BE_IF_FLAGS_UNTAGGED |
@@ -2885,10 +2866,10 @@ static int be_vf_setup(struct be_adapter *adapter)
2885 dev_warn(dev, "Ignoring num_vfs=%d setting\n", num_vfs); 2866 dev_warn(dev, "Ignoring num_vfs=%d setting\n", num_vfs);
2886 adapter->num_vfs = old_vfs; 2867 adapter->num_vfs = old_vfs;
2887 } else { 2868 } else {
2888 if (num_vfs > adapter->dev_num_vfs) 2869 if (num_vfs > be_max_vfs(adapter))
2889 dev_info(dev, "Device supports %d VFs and not %d\n", 2870 dev_info(dev, "Device supports %d VFs and not %d\n",
2890 adapter->dev_num_vfs, num_vfs); 2871 be_max_vfs(adapter), num_vfs);
2891 adapter->num_vfs = min_t(u16, num_vfs, adapter->dev_num_vfs); 2872 adapter->num_vfs = min_t(u16, num_vfs, be_max_vfs(adapter));
2892 if (!adapter->num_vfs) 2873 if (!adapter->num_vfs)
2893 return 0; 2874 return 0;
2894 } 2875 }
@@ -2967,6 +2948,51 @@ err:
2967 return status; 2948 return status;
2968} 2949}
2969 2950
2951/* On BE2/BE3 FW does not suggest the supported limits */
2952static void BEx_get_resources(struct be_adapter *adapter,
2953 struct be_resources *res)
2954{
2955 struct pci_dev *pdev = adapter->pdev;
2956 bool use_sriov = false;
2957
2958 if (BE3_chip(adapter) && be_physfn(adapter)) {
2959 int max_vfs;
2960
2961 max_vfs = pci_sriov_get_totalvfs(pdev);
2962 res->max_vfs = max_vfs > 0 ? min(MAX_VFS, max_vfs) : 0;
2963 use_sriov = res->max_vfs && num_vfs;
2964 }
2965
2966 if (be_physfn(adapter))
2967 res->max_uc_mac = BE_UC_PMAC_COUNT;
2968 else
2969 res->max_uc_mac = BE_VF_UC_PMAC_COUNT;
2970
2971 if (adapter->function_mode & FLEX10_MODE)
2972 res->max_vlans = BE_NUM_VLANS_SUPPORTED/8;
2973 else
2974 res->max_vlans = BE_NUM_VLANS_SUPPORTED;
2975 res->max_mcast_mac = BE_MAX_MC;
2976
2977 if (BE2_chip(adapter) || use_sriov || be_is_mc(adapter) ||
2978 !be_physfn(adapter))
2979 res->max_tx_qs = 1;
2980 else
2981 res->max_tx_qs = BE3_MAX_TX_QS;
2982
2983 if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) &&
2984 !use_sriov && be_physfn(adapter))
2985 res->max_rss_qs = (adapter->be3_native) ?
2986 BE3_MAX_RSS_QS : BE2_MAX_RSS_QS;
2987 res->max_rx_qs = res->max_rss_qs + 1;
2988
2989 res->max_evt_qs = be_physfn(adapter) ? MAX_EVT_QS : 1;
2990
2991 res->if_cap_flags = BE_IF_CAP_FLAGS_WANT;
2992 if (!(adapter->function_caps & BE_FUNCTION_CAPS_RSS))
2993 res->if_cap_flags &= ~BE_IF_FLAGS_RSS;
2994}
2995
2970static void be_setup_init(struct be_adapter *adapter) 2996static void be_setup_init(struct be_adapter *adapter)
2971{ 2997{
2972 adapter->vlan_prio_bmap = 0xff; 2998 adapter->vlan_prio_bmap = 0xff;
@@ -2980,76 +3006,56 @@ static void be_setup_init(struct be_adapter *adapter)
2980 adapter->cmd_privileges = MIN_PRIVILEGES; 3006 adapter->cmd_privileges = MIN_PRIVILEGES;
2981} 3007}
2982 3008
2983static void be_get_resources(struct be_adapter *adapter) 3009static int be_get_resources(struct be_adapter *adapter)
2984{ 3010{
2985 u16 dev_num_vfs; 3011 struct device *dev = &adapter->pdev->dev;
2986 int pos, status; 3012 struct be_resources res = {0};
2987 bool profile_present = false; 3013 int status;
2988 u16 txq_count = 0;
2989 3014
2990 if (!BEx_chip(adapter)) { 3015 if (BEx_chip(adapter)) {
2991 status = be_cmd_get_func_config(adapter); 3016 BEx_get_resources(adapter, &res);
2992 if (!status) 3017 adapter->res = res;
2993 profile_present = true;
2994 } else if (BE3_chip(adapter) && be_physfn(adapter)) {
2995 be_cmd_get_profile_config(adapter, NULL, &txq_count, 0);
2996 } 3018 }
2997 3019
2998 if (profile_present) { 3020 /* For BE3 only check if FW suggests a different max-txqs value */
2999 adapter->max_tx_queues = min_t(u16, adapter->max_tx_queues, 3021 if (BE3_chip(adapter)) {
3000 MAX_TX_QS); 3022 status = be_cmd_get_profile_config(adapter, &res, 0);
3001 adapter->max_rss_queues = min_t(u16, adapter->max_rss_queues, 3023 if (!status && res.max_tx_qs)
3002 BE3_MAX_RSS_QS); 3024 adapter->res.max_tx_qs =
3003 adapter->max_event_queues = min_t(u16, 3025 min(adapter->res.max_tx_qs, res.max_tx_qs);
3004 adapter->max_event_queues, 3026 }
3005 BE3_MAX_RSS_QS);
3006
3007 if (adapter->max_rss_queues &&
3008 adapter->max_rss_queues == adapter->max_rx_queues)
3009 adapter->max_rss_queues -= 1;
3010
3011 if (adapter->max_event_queues < adapter->max_rss_queues)
3012 adapter->max_rss_queues = adapter->max_event_queues;
3013
3014 } else {
3015 if (be_physfn(adapter))
3016 adapter->max_pmac_cnt = BE_UC_PMAC_COUNT;
3017 else
3018 adapter->max_pmac_cnt = BE_VF_UC_PMAC_COUNT;
3019 3027
3020 if (adapter->function_mode & FLEX10_MODE) 3028 /* For Lancer, SH etc read per-function resource limits from FW.
3021 adapter->max_vlans = BE_NUM_VLANS_SUPPORTED/8; 3029 * GET_FUNC_CONFIG returns per function guaranteed limits.
3022 else 3030 * GET_PROFILE_CONFIG returns PCI-E related limits PF-pool limits
3023 adapter->max_vlans = BE_NUM_VLANS_SUPPORTED; 3031 */
3032 if (!BEx_chip(adapter)) {
3033 status = be_cmd_get_func_config(adapter, &res);
3034 if (status)
3035 return status;
3024 3036
3025 adapter->max_mcast_mac = BE_MAX_MC; 3037 /* If RoCE may be enabled stash away half the EQs for RoCE */
3026 adapter->max_tx_queues = txq_count ? txq_count : MAX_TX_QS; 3038 if (be_roce_supported(adapter))
3027 adapter->max_tx_queues = min_t(u16, adapter->max_tx_queues, 3039 res.max_evt_qs /= 2;
3028 MAX_TX_QS); 3040 adapter->res = res;
3029 adapter->max_rss_queues = (adapter->be3_native) ?
3030 BE3_MAX_RSS_QS : BE2_MAX_RSS_QS;
3031 adapter->max_event_queues = BE3_MAX_RSS_QS;
3032 3041
3033 adapter->if_cap_flags = BE_IF_FLAGS_UNTAGGED | 3042 if (be_physfn(adapter)) {
3034 BE_IF_FLAGS_BROADCAST | 3043 status = be_cmd_get_profile_config(adapter, &res, 0);
3035 BE_IF_FLAGS_MULTICAST | 3044 if (status)
3036 BE_IF_FLAGS_PASS_L3L4_ERRORS | 3045 return status;
3037 BE_IF_FLAGS_MCAST_PROMISCUOUS | 3046 adapter->res.max_vfs = res.max_vfs;
3038 BE_IF_FLAGS_VLAN_PROMISCUOUS | 3047 }
3039 BE_IF_FLAGS_PROMISCUOUS;
3040 3048
3041 if (adapter->function_caps & BE_FUNCTION_CAPS_RSS) 3049 dev_info(dev, "Max: txqs %d, rxqs %d, rss %d, eqs %d, vfs %d\n",
3042 adapter->if_cap_flags |= BE_IF_FLAGS_RSS; 3050 be_max_txqs(adapter), be_max_rxqs(adapter),
3051 be_max_rss(adapter), be_max_eqs(adapter),
3052 be_max_vfs(adapter));
3053 dev_info(dev, "Max: uc-macs %d, mc-macs %d, vlans %d\n",
3054 be_max_uc(adapter), be_max_mc(adapter),
3055 be_max_vlans(adapter));
3043 } 3056 }
3044 3057
3045 pos = pci_find_ext_capability(adapter->pdev, PCI_EXT_CAP_ID_SRIOV); 3058 return 0;
3046 if (pos) {
3047 pci_read_config_word(adapter->pdev, pos + PCI_SRIOV_TOTAL_VF,
3048 &dev_num_vfs);
3049 if (BE3_chip(adapter))
3050 dev_num_vfs = min_t(u16, dev_num_vfs, MAX_VFS);
3051 adapter->dev_num_vfs = dev_num_vfs;
3052 }
3053} 3059}
3054 3060
3055/* Routine to query per function resource limits */ 3061/* Routine to query per function resource limits */
@@ -3062,20 +3068,22 @@ static int be_get_config(struct be_adapter *adapter)
3062 &adapter->function_caps, 3068 &adapter->function_caps,
3063 &adapter->asic_rev); 3069 &adapter->asic_rev);
3064 if (status) 3070 if (status)
3065 goto err; 3071 return status;
3066 3072
3067 be_get_resources(adapter); 3073 status = be_get_resources(adapter);
3074 if (status)
3075 return status;
3068 3076
3069 /* primary mac needs 1 pmac entry */ 3077 /* primary mac needs 1 pmac entry */
3070 adapter->pmac_id = kcalloc(adapter->max_pmac_cnt + 1, 3078 adapter->pmac_id = kcalloc(be_max_uc(adapter) + 1, sizeof(u32),
3071 sizeof(u32), GFP_KERNEL); 3079 GFP_KERNEL);
3072 if (!adapter->pmac_id) { 3080 if (!adapter->pmac_id)
3073 status = -ENOMEM; 3081 return -ENOMEM;
3074 goto err;
3075 }
3076 3082
3077err: 3083 /* Sanitize cfg_num_qs based on HW and platform limits */
3078 return status; 3084 adapter->cfg_num_qs = min(adapter->cfg_num_qs, be_max_qs(adapter));
3085
3086 return 0;
3079} 3087}
3080 3088
3081static int be_mac_setup(struct be_adapter *adapter) 3089static int be_mac_setup(struct be_adapter *adapter)
@@ -3151,8 +3159,8 @@ static int be_setup(struct be_adapter *adapter)
3151 BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS; 3159 BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS;
3152 if (adapter->function_caps & BE_FUNCTION_CAPS_RSS) 3160 if (adapter->function_caps & BE_FUNCTION_CAPS_RSS)
3153 en_flags |= BE_IF_FLAGS_RSS; 3161 en_flags |= BE_IF_FLAGS_RSS;
3154 en_flags = en_flags & adapter->if_cap_flags; 3162 en_flags = en_flags & be_if_cap_flags(adapter);
3155 status = be_cmd_if_create(adapter, adapter->if_cap_flags, en_flags, 3163 status = be_cmd_if_create(adapter, be_if_cap_flags(adapter), en_flags,
3156 &adapter->if_handle, 0); 3164 &adapter->if_handle, 0);
3157 if (status != 0) 3165 if (status != 0)
3158 goto err; 3166 goto err;
@@ -3178,8 +3186,8 @@ static int be_setup(struct be_adapter *adapter)
3178 be_cmd_set_flow_control(adapter, adapter->tx_fc, 3186 be_cmd_set_flow_control(adapter, adapter->tx_fc,
3179 adapter->rx_fc); 3187 adapter->rx_fc);
3180 3188
3181 if (be_physfn(adapter)) { 3189 if (be_physfn(adapter) && num_vfs) {
3182 if (adapter->dev_num_vfs) 3190 if (be_max_vfs(adapter))
3183 be_vf_setup(adapter); 3191 be_vf_setup(adapter);
3184 else 3192 else
3185 dev_warn(dev, "device doesn't support SRIOV\n"); 3193 dev_warn(dev, "device doesn't support SRIOV\n");
@@ -4045,6 +4053,7 @@ static int be_get_initial_config(struct be_adapter *adapter)
4045 level = be_get_fw_log_level(adapter); 4053 level = be_get_fw_log_level(adapter);
4046 adapter->msg_enable = level <= FW_LOG_LEVEL_DEFAULT ? NETIF_MSG_HW : 0; 4054 adapter->msg_enable = level <= FW_LOG_LEVEL_DEFAULT ? NETIF_MSG_HW : 0;
4047 4055
4056 adapter->cfg_num_qs = netif_get_num_default_rss_queues();
4048 return 0; 4057 return 0;
4049} 4058}
4050 4059
diff --git a/drivers/net/ethernet/emulex/benet/be_roce.c b/drivers/net/ethernet/emulex/benet/be_roce.c
index 645e846daa5c..9cd5415fe017 100644
--- a/drivers/net/ethernet/emulex/benet/be_roce.c
+++ b/drivers/net/ethernet/emulex/benet/be_roce.c
@@ -60,7 +60,7 @@ static void _be_roce_dev_add(struct be_adapter *adapter)
60 */ 60 */
61 num_vec = adapter->num_msix_vec + adapter->num_msix_roce_vec; 61 num_vec = adapter->num_msix_vec + adapter->num_msix_roce_vec;
62 dev_info.intr_mode = BE_INTERRUPT_MODE_MSIX; 62 dev_info.intr_mode = BE_INTERRUPT_MODE_MSIX;
63 dev_info.msix.num_vectors = min(num_vec, MAX_ROCE_MSIX_VECTORS); 63 dev_info.msix.num_vectors = min(num_vec, MAX_MSIX_VECTORS);
64 /* provide start index of the vector, 64 /* provide start index of the vector,
65 * so in case of linear usage, 65 * so in case of linear usage,
66 * it can use the base as starting point. 66 * it can use the base as starting point.
diff --git a/drivers/net/ethernet/emulex/benet/be_roce.h b/drivers/net/ethernet/emulex/benet/be_roce.h
index 276572998463..2cd1129e19af 100644
--- a/drivers/net/ethernet/emulex/benet/be_roce.h
+++ b/drivers/net/ethernet/emulex/benet/be_roce.h
@@ -29,7 +29,7 @@ enum be_interrupt_mode {
29 BE_INTERRUPT_MODE_MSI = 2, 29 BE_INTERRUPT_MODE_MSI = 2,
30}; 30};
31 31
32#define MAX_ROCE_MSIX_VECTORS 16 32#define MAX_MSIX_VECTORS 32
33struct be_dev_info { 33struct be_dev_info {
34 u8 __iomem *db; 34 u8 __iomem *db;
35 u64 unmapped_db; 35 u64 unmapped_db;
@@ -45,7 +45,7 @@ struct be_dev_info {
45 struct { 45 struct {
46 int num_vectors; 46 int num_vectors;
47 int start_vector; 47 int start_vector;
48 u32 vector_list[MAX_ROCE_MSIX_VECTORS]; 48 u32 vector_list[MAX_MSIX_VECTORS];
49 } msix; 49 } msix;
50}; 50};
51 51