diff options
author | Sathya Perla <sathya.perla@emulex.com> | 2011-03-21 16:49:25 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-03-31 00:39:19 -0400 |
commit | ac6a0c4aab16070d7d55f49a52de33f716ae1d3d (patch) | |
tree | 4b61658c9c3cbe141e18d667cc715c20992430b8 /drivers/net | |
parent | 311fddc7569d7a3340d61de262cff11685060f74 (diff) |
be2net: refactor code that decides adapter->num_rx_queues
The code has been refactored to not set num_rx_qs inside be_enable_msix().
num_rx_qs is now set at the time of queue creation based on the number of
available msix vectors.
Signed-off-by: Sathya Perla <sathya.perla@emulex.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/benet/be.h | 8 | ||||
-rw-r--r-- | drivers/net/benet/be_main.c | 66 |
2 files changed, 39 insertions, 35 deletions
diff --git a/drivers/net/benet/be.h b/drivers/net/benet/be.h index f803c58b941d..3937bca3d431 100644 --- a/drivers/net/benet/be.h +++ b/drivers/net/benet/be.h | |||
@@ -84,7 +84,8 @@ static inline char *nic_name(struct pci_dev *pdev) | |||
84 | #define MCC_CQ_LEN 256 | 84 | #define MCC_CQ_LEN 256 |
85 | 85 | ||
86 | #define MAX_RSS_QS 4 /* BE limit is 4 queues/port */ | 86 | #define MAX_RSS_QS 4 /* BE limit is 4 queues/port */ |
87 | #define BE_MAX_MSIX_VECTORS (MAX_RSS_QS + 1 + 1)/* RSS qs + 1 def Rx + Tx */ | 87 | #define MAX_RX_QS (MAX_RSS_QS + 1) /* RSS qs + 1 def Rx */ |
88 | #define BE_MAX_MSIX_VECTORS (MAX_RX_QS + 1)/* RX + TX */ | ||
88 | #define BE_NAPI_WEIGHT 64 | 89 | #define BE_NAPI_WEIGHT 64 |
89 | #define MAX_RX_POST BE_NAPI_WEIGHT /* Frags posted at a time */ | 90 | #define MAX_RX_POST BE_NAPI_WEIGHT /* Frags posted at a time */ |
90 | #define RX_FRAGS_REFILL_WM (RX_Q_LEN - MAX_RX_POST) | 91 | #define RX_FRAGS_REFILL_WM (RX_Q_LEN - MAX_RX_POST) |
@@ -276,7 +277,7 @@ struct be_adapter { | |||
276 | spinlock_t mcc_cq_lock; | 277 | spinlock_t mcc_cq_lock; |
277 | 278 | ||
278 | struct msix_entry msix_entries[BE_MAX_MSIX_VECTORS]; | 279 | struct msix_entry msix_entries[BE_MAX_MSIX_VECTORS]; |
279 | bool msix_enabled; | 280 | u32 num_msix_vec; |
280 | bool isr_registered; | 281 | bool isr_registered; |
281 | 282 | ||
282 | /* TX Rings */ | 283 | /* TX Rings */ |
@@ -287,7 +288,7 @@ struct be_adapter { | |||
287 | u32 cache_line_break[8]; | 288 | u32 cache_line_break[8]; |
288 | 289 | ||
289 | /* Rx rings */ | 290 | /* Rx rings */ |
290 | struct be_rx_obj rx_obj[MAX_RSS_QS + 1]; /* one default non-rss Q */ | 291 | struct be_rx_obj rx_obj[MAX_RX_QS]; |
291 | u32 num_rx_qs; | 292 | u32 num_rx_qs; |
292 | u32 big_page_size; /* Compounded page size shared by rx wrbs */ | 293 | u32 big_page_size; /* Compounded page size shared by rx wrbs */ |
293 | 294 | ||
@@ -351,6 +352,7 @@ struct be_adapter { | |||
351 | 352 | ||
352 | extern const struct ethtool_ops be_ethtool_ops; | 353 | extern const struct ethtool_ops be_ethtool_ops; |
353 | 354 | ||
355 | #define msix_enabled(adapter) (adapter->num_msix_vec > 0) | ||
354 | #define tx_stats(adapter) (&adapter->tx_stats) | 356 | #define tx_stats(adapter) (&adapter->tx_stats) |
355 | #define rx_stats(rxo) (&rxo->stats) | 357 | #define rx_stats(rxo) (&rxo->stats) |
356 | 358 | ||
diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c index a71163f1e34b..7a5d6a308051 100644 --- a/drivers/net/benet/be_main.c +++ b/drivers/net/benet/be_main.c | |||
@@ -1567,12 +1567,31 @@ static void be_rx_queues_destroy(struct be_adapter *adapter) | |||
1567 | } | 1567 | } |
1568 | } | 1568 | } |
1569 | 1569 | ||
1570 | static u32 be_num_rxqs_want(struct be_adapter *adapter) | ||
1571 | { | ||
1572 | if (multi_rxq && (adapter->function_caps & BE_FUNCTION_CAPS_RSS) && | ||
1573 | !adapter->sriov_enabled && !(adapter->function_mode & 0x400)) { | ||
1574 | return 1 + MAX_RSS_QS; /* one default non-RSS queue */ | ||
1575 | } else { | ||
1576 | dev_warn(&adapter->pdev->dev, | ||
1577 | "No support for multiple RX queues\n"); | ||
1578 | return 1; | ||
1579 | } | ||
1580 | } | ||
1581 | |||
1570 | static int be_rx_queues_create(struct be_adapter *adapter) | 1582 | static int be_rx_queues_create(struct be_adapter *adapter) |
1571 | { | 1583 | { |
1572 | struct be_queue_info *eq, *q, *cq; | 1584 | struct be_queue_info *eq, *q, *cq; |
1573 | struct be_rx_obj *rxo; | 1585 | struct be_rx_obj *rxo; |
1574 | int rc, i; | 1586 | int rc, i; |
1575 | 1587 | ||
1588 | adapter->num_rx_qs = min(be_num_rxqs_want(adapter), | ||
1589 | msix_enabled(adapter) ? | ||
1590 | adapter->num_msix_vec - 1 : 1); | ||
1591 | if (adapter->num_rx_qs != MAX_RX_QS) | ||
1592 | dev_warn(&adapter->pdev->dev, | ||
1593 | "Can create only %d RX queues", adapter->num_rx_qs); | ||
1594 | |||
1576 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; | 1595 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
1577 | for_all_rx_queues(adapter, rxo, i) { | 1596 | for_all_rx_queues(adapter, rxo, i) { |
1578 | rxo->adapter = adapter; | 1597 | rxo->adapter = adapter; |
@@ -1878,51 +1897,35 @@ reschedule: | |||
1878 | 1897 | ||
1879 | static void be_msix_disable(struct be_adapter *adapter) | 1898 | static void be_msix_disable(struct be_adapter *adapter) |
1880 | { | 1899 | { |
1881 | if (adapter->msix_enabled) { | 1900 | if (msix_enabled(adapter)) { |
1882 | pci_disable_msix(adapter->pdev); | 1901 | pci_disable_msix(adapter->pdev); |
1883 | adapter->msix_enabled = false; | 1902 | adapter->num_msix_vec = 0; |
1884 | } | ||
1885 | } | ||
1886 | |||
1887 | static int be_num_rxqs_get(struct be_adapter *adapter) | ||
1888 | { | ||
1889 | if (multi_rxq && (adapter->function_caps & BE_FUNCTION_CAPS_RSS) && | ||
1890 | !adapter->sriov_enabled && !(adapter->function_mode & 0x400)) { | ||
1891 | return 1 + MAX_RSS_QS; /* one default non-RSS queue */ | ||
1892 | } else { | ||
1893 | dev_warn(&adapter->pdev->dev, | ||
1894 | "No support for multiple RX queues\n"); | ||
1895 | return 1; | ||
1896 | } | 1903 | } |
1897 | } | 1904 | } |
1898 | 1905 | ||
1899 | static void be_msix_enable(struct be_adapter *adapter) | 1906 | static void be_msix_enable(struct be_adapter *adapter) |
1900 | { | 1907 | { |
1901 | #define BE_MIN_MSIX_VECTORS (1 + 1) /* Rx + Tx */ | 1908 | #define BE_MIN_MSIX_VECTORS (1 + 1) /* Rx + Tx */ |
1902 | int i, status; | 1909 | int i, status, num_vec; |
1903 | 1910 | ||
1904 | adapter->num_rx_qs = be_num_rxqs_get(adapter); | 1911 | num_vec = be_num_rxqs_want(adapter) + 1; |
1905 | 1912 | ||
1906 | for (i = 0; i < (adapter->num_rx_qs + 1); i++) | 1913 | for (i = 0; i < num_vec; i++) |
1907 | adapter->msix_entries[i].entry = i; | 1914 | adapter->msix_entries[i].entry = i; |
1908 | 1915 | ||
1909 | status = pci_enable_msix(adapter->pdev, adapter->msix_entries, | 1916 | status = pci_enable_msix(adapter->pdev, adapter->msix_entries, num_vec); |
1910 | adapter->num_rx_qs + 1); | ||
1911 | if (status == 0) { | 1917 | if (status == 0) { |
1912 | goto done; | 1918 | goto done; |
1913 | } else if (status >= BE_MIN_MSIX_VECTORS) { | 1919 | } else if (status >= BE_MIN_MSIX_VECTORS) { |
1920 | num_vec = status; | ||
1914 | if (pci_enable_msix(adapter->pdev, adapter->msix_entries, | 1921 | if (pci_enable_msix(adapter->pdev, adapter->msix_entries, |
1915 | status) == 0) { | 1922 | num_vec) == 0) |
1916 | adapter->num_rx_qs = status - 1; | ||
1917 | dev_warn(&adapter->pdev->dev, | ||
1918 | "Could alloc only %d MSIx vectors. " | ||
1919 | "Using %d RX Qs\n", status, adapter->num_rx_qs); | ||
1920 | goto done; | 1923 | goto done; |
1921 | } | ||
1922 | } | 1924 | } |
1923 | return; | 1925 | return; |
1924 | done: | 1926 | done: |
1925 | adapter->msix_enabled = true; | 1927 | adapter->num_msix_vec = num_vec; |
1928 | return; | ||
1926 | } | 1929 | } |
1927 | 1930 | ||
1928 | static void be_sriov_enable(struct be_adapter *adapter) | 1931 | static void be_sriov_enable(struct be_adapter *adapter) |
@@ -2003,8 +2006,7 @@ err_msix: | |||
2003 | err: | 2006 | err: |
2004 | dev_warn(&adapter->pdev->dev, | 2007 | dev_warn(&adapter->pdev->dev, |
2005 | "MSIX Request IRQ failed - err %d\n", status); | 2008 | "MSIX Request IRQ failed - err %d\n", status); |
2006 | pci_disable_msix(adapter->pdev); | 2009 | be_msix_disable(adapter); |
2007 | adapter->msix_enabled = false; | ||
2008 | return status; | 2010 | return status; |
2009 | } | 2011 | } |
2010 | 2012 | ||
@@ -2013,7 +2015,7 @@ static int be_irq_register(struct be_adapter *adapter) | |||
2013 | struct net_device *netdev = adapter->netdev; | 2015 | struct net_device *netdev = adapter->netdev; |
2014 | int status; | 2016 | int status; |
2015 | 2017 | ||
2016 | if (adapter->msix_enabled) { | 2018 | if (msix_enabled(adapter)) { |
2017 | status = be_msix_register(adapter); | 2019 | status = be_msix_register(adapter); |
2018 | if (status == 0) | 2020 | if (status == 0) |
2019 | goto done; | 2021 | goto done; |
@@ -2046,7 +2048,7 @@ static void be_irq_unregister(struct be_adapter *adapter) | |||
2046 | return; | 2048 | return; |
2047 | 2049 | ||
2048 | /* INTx */ | 2050 | /* INTx */ |
2049 | if (!adapter->msix_enabled) { | 2051 | if (!msix_enabled(adapter)) { |
2050 | free_irq(netdev->irq, adapter); | 2052 | free_irq(netdev->irq, adapter); |
2051 | goto done; | 2053 | goto done; |
2052 | } | 2054 | } |
@@ -2088,7 +2090,7 @@ static int be_close(struct net_device *netdev) | |||
2088 | be_cq_notify(adapter, rxo->cq.id, false, 0); | 2090 | be_cq_notify(adapter, rxo->cq.id, false, 0); |
2089 | } | 2091 | } |
2090 | 2092 | ||
2091 | if (adapter->msix_enabled) { | 2093 | if (msix_enabled(adapter)) { |
2092 | vec = be_msix_vec_get(adapter, tx_eq); | 2094 | vec = be_msix_vec_get(adapter, tx_eq); |
2093 | synchronize_irq(vec); | 2095 | synchronize_irq(vec); |
2094 | 2096 | ||
@@ -2261,7 +2263,7 @@ static int be_setup(struct be_adapter *adapter) | |||
2261 | BE_IF_FLAGS_PASS_L3L4_ERRORS; | 2263 | BE_IF_FLAGS_PASS_L3L4_ERRORS; |
2262 | en_flags |= BE_IF_FLAGS_PASS_L3L4_ERRORS; | 2264 | en_flags |= BE_IF_FLAGS_PASS_L3L4_ERRORS; |
2263 | 2265 | ||
2264 | if (be_multi_rxq(adapter)) { | 2266 | if (adapter->function_caps & BE_FUNCTION_CAPS_RSS) { |
2265 | cap_flags |= BE_IF_FLAGS_RSS; | 2267 | cap_flags |= BE_IF_FLAGS_RSS; |
2266 | en_flags |= BE_IF_FLAGS_RSS; | 2268 | en_flags |= BE_IF_FLAGS_RSS; |
2267 | } | 2269 | } |