aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel/ice/ice_lib.c
diff options
context:
space:
mode:
authorAnirudh Venkataramanan <anirudh.venkataramanan@intel.com>2018-09-19 20:23:10 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2018-10-01 15:50:30 -0400
commit37bb839012865a4cafc038ec7ee183b873583a7d (patch)
tree6e4aa3fa3db04d1f3698897f50a4f4f2532d4557 /drivers/net/ethernet/intel/ice/ice_lib.c
parentdf0f847915b4311fc107e8e803c69b9f426c4f7b (diff)
ice: Move common functions out of ice_main.c part 7/7
This patch completes the code move out of ice_main.c The following top level functions and related dependency functions) were moved to ice_lib.c: ice_vsi_setup ice_vsi_cfg_tc The following functions were made static again: ice_vsi_setup_vector_base ice_vsi_alloc_q_vectors ice_vsi_get_qs void ice_vsi_map_rings_to_vectors ice_vsi_alloc_rings ice_vsi_set_rss_params ice_vsi_set_num_qs ice_get_free_slot ice_vsi_init ice_vsi_alloc_arrays Signed-off-by: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com> Tested-by: Andrew Bowers <andrewx.bowers@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel/ice/ice_lib.c')
-rw-r--r--drivers/net/ethernet/intel/ice/ice_lib.c253
1 files changed, 243 insertions, 10 deletions
diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
index 232ca06974ea..21e3a3e70329 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -233,7 +233,7 @@ static int ice_vsi_ctrl_rx_rings(struct ice_vsi *vsi, bool ena)
233 * On error: returns error code (negative) 233 * On error: returns error code (negative)
234 * On success: returns 0 234 * On success: returns 0
235 */ 235 */
236int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors) 236static int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors)
237{ 237{
238 struct ice_pf *pf = vsi->back; 238 struct ice_pf *pf = vsi->back;
239 239
@@ -274,7 +274,7 @@ err_txrings:
274 * 274 *
275 * Return 0 on success and a negative value on error 275 * Return 0 on success and a negative value on error
276 */ 276 */
277void ice_vsi_set_num_qs(struct ice_vsi *vsi) 277static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
278{ 278{
279 struct ice_pf *pf = vsi->back; 279 struct ice_pf *pf = vsi->back;
280 280
@@ -301,7 +301,7 @@ void ice_vsi_set_num_qs(struct ice_vsi *vsi)
301 * void * is being used to keep the functionality generic. This lets us use this 301 * void * is being used to keep the functionality generic. This lets us use this
302 * function on any array of pointers. 302 * function on any array of pointers.
303 */ 303 */
304int ice_get_free_slot(void *array, int size, int curr) 304static int ice_get_free_slot(void *array, int size, int curr)
305{ 305{
306 int **tmp_array = (int **)array; 306 int **tmp_array = (int **)array;
307 int next; 307 int next;
@@ -424,6 +424,70 @@ irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
424} 424}
425 425
426/** 426/**
427 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
428 * @pf: board private structure
429 * @type: type of VSI
430 *
431 * returns a pointer to a VSI on success, NULL on failure.
432 */
433static struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type type)
434{
435 struct ice_vsi *vsi = NULL;
436
437 /* Need to protect the allocation of the VSIs at the PF level */
438 mutex_lock(&pf->sw_mutex);
439
440 /* If we have already allocated our maximum number of VSIs,
441 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
442 * is available to be populated
443 */
444 if (pf->next_vsi == ICE_NO_VSI) {
445 dev_dbg(&pf->pdev->dev, "out of VSI slots!\n");
446 goto unlock_pf;
447 }
448
449 vsi = devm_kzalloc(&pf->pdev->dev, sizeof(*vsi), GFP_KERNEL);
450 if (!vsi)
451 goto unlock_pf;
452
453 vsi->type = type;
454 vsi->back = pf;
455 set_bit(__ICE_DOWN, vsi->state);
456 vsi->idx = pf->next_vsi;
457 vsi->work_lmt = ICE_DFLT_IRQ_WORK;
458
459 ice_vsi_set_num_qs(vsi);
460
461 switch (vsi->type) {
462 case ICE_VSI_PF:
463 if (ice_vsi_alloc_arrays(vsi, true))
464 goto err_rings;
465
466 /* Setup default MSIX irq handler for VSI */
467 vsi->irq_handler = ice_msix_clean_rings;
468 break;
469 default:
470 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
471 goto unlock_pf;
472 }
473
474 /* fill VSI slot in the PF struct */
475 pf->vsi[pf->next_vsi] = vsi;
476
477 /* prepare pf->next_vsi for next use */
478 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
479 pf->next_vsi);
480 goto unlock_pf;
481
482err_rings:
483 devm_kfree(&pf->pdev->dev, vsi);
484 vsi = NULL;
485unlock_pf:
486 mutex_unlock(&pf->sw_mutex);
487 return vsi;
488}
489
490/**
427 * ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI 491 * ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
428 * @vsi: the VSI getting queues 492 * @vsi: the VSI getting queues
429 * 493 *
@@ -533,7 +597,7 @@ err_scatter_tx:
533 * 597 *
534 * Returns 0 on success and a negative value on error 598 * Returns 0 on success and a negative value on error
535 */ 599 */
536int ice_vsi_get_qs(struct ice_vsi *vsi) 600static int ice_vsi_get_qs(struct ice_vsi *vsi)
537{ 601{
538 int ret = 0; 602 int ret = 0;
539 603
@@ -602,7 +666,7 @@ static void ice_rss_clean(struct ice_vsi *vsi)
602 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type 666 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
603 * @vsi: the VSI being configured 667 * @vsi: the VSI being configured
604 */ 668 */
605void ice_vsi_set_rss_params(struct ice_vsi *vsi) 669static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
606{ 670{
607 struct ice_hw_common_caps *cap; 671 struct ice_hw_common_caps *cap;
608 struct ice_pf *pf = vsi->back; 672 struct ice_pf *pf = vsi->back;
@@ -793,7 +857,7 @@ static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
793 * This initializes a VSI context depending on the VSI type to be added and 857 * This initializes a VSI context depending on the VSI type to be added and
794 * passes it down to the add_vsi aq command to create a new VSI. 858 * passes it down to the add_vsi aq command to create a new VSI.
795 */ 859 */
796int ice_vsi_init(struct ice_vsi *vsi) 860static int ice_vsi_init(struct ice_vsi *vsi)
797{ 861{
798 struct ice_vsi_ctx ctxt = { 0 }; 862 struct ice_vsi_ctx ctxt = { 0 };
799 struct ice_pf *pf = vsi->back; 863 struct ice_pf *pf = vsi->back;
@@ -922,7 +986,7 @@ static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, int v_idx)
922 * We allocate one q_vector per queue interrupt. If allocation fails we 986 * We allocate one q_vector per queue interrupt. If allocation fails we
923 * return -ENOMEM. 987 * return -ENOMEM.
924 */ 988 */
925int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi) 989static int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
926{ 990{
927 struct ice_pf *pf = vsi->back; 991 struct ice_pf *pf = vsi->back;
928 int v_idx = 0, num_q_vectors; 992 int v_idx = 0, num_q_vectors;
@@ -970,7 +1034,7 @@ err_out:
970 * 1034 *
971 * Returns 0 on success or negative on failure 1035 * Returns 0 on success or negative on failure
972 */ 1036 */
973int ice_vsi_setup_vector_base(struct ice_vsi *vsi) 1037static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
974{ 1038{
975 struct ice_pf *pf = vsi->back; 1039 struct ice_pf *pf = vsi->back;
976 int num_q_vectors = 0; 1040 int num_q_vectors = 0;
@@ -1038,7 +1102,7 @@ static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1038 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI 1102 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1039 * @vsi: VSI which is having rings allocated 1103 * @vsi: VSI which is having rings allocated
1040 */ 1104 */
1041int ice_vsi_alloc_rings(struct ice_vsi *vsi) 1105static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1042{ 1106{
1043 struct ice_pf *pf = vsi->back; 1107 struct ice_pf *pf = vsi->back;
1044 int i; 1108 int i;
@@ -1096,7 +1160,7 @@ err_out:
1096 * through the MSI-X enabling code. On a constrained vector budget, we map Tx 1160 * through the MSI-X enabling code. On a constrained vector budget, we map Tx
1097 * and Rx rings to the vector as "efficiently" as possible. 1161 * and Rx rings to the vector as "efficiently" as possible.
1098 */ 1162 */
1099void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi) 1163static void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1100{ 1164{
1101 int q_vectors = vsi->num_q_vectors; 1165 int q_vectors = vsi->num_q_vectors;
1102 int tx_rings_rem, rx_rings_rem; 1166 int tx_rings_rem, rx_rings_rem;
@@ -1143,6 +1207,69 @@ void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1143} 1207}
1144 1208
1145/** 1209/**
1210 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1211 * @vsi: VSI to be configured
1212 */
1213static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1214{
1215 u8 seed[ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE];
1216 struct ice_aqc_get_set_rss_keys *key;
1217 struct ice_pf *pf = vsi->back;
1218 enum ice_status status;
1219 int err = 0;
1220 u8 *lut;
1221
1222 vsi->rss_size = min_t(int, vsi->rss_size, vsi->num_rxq);
1223
1224 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
1225 if (!lut)
1226 return -ENOMEM;
1227
1228 if (vsi->rss_lut_user)
1229 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1230 else
1231 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1232
1233 status = ice_aq_set_rss_lut(&pf->hw, vsi->vsi_num, vsi->rss_lut_type,
1234 lut, vsi->rss_table_size);
1235
1236 if (status) {
1237 dev_err(&vsi->back->pdev->dev,
1238 "set_rss_lut failed, error %d\n", status);
1239 err = -EIO;
1240 goto ice_vsi_cfg_rss_exit;
1241 }
1242
1243 key = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*key), GFP_KERNEL);
1244 if (!key) {
1245 err = -ENOMEM;
1246 goto ice_vsi_cfg_rss_exit;
1247 }
1248
1249 if (vsi->rss_hkey_user)
1250 memcpy(seed, vsi->rss_hkey_user,
1251 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
1252 else
1253 netdev_rss_key_fill((void *)seed,
1254 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
1255 memcpy(&key->standard_rss_key, seed,
1256 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
1257
1258 status = ice_aq_set_rss_key(&pf->hw, vsi->vsi_num, key);
1259
1260 if (status) {
1261 dev_err(&vsi->back->pdev->dev, "set_rss_key failed, error %d\n",
1262 status);
1263 err = -EIO;
1264 }
1265
1266 devm_kfree(&pf->pdev->dev, key);
1267ice_vsi_cfg_rss_exit:
1268 devm_kfree(&pf->pdev->dev, lut);
1269 return err;
1270}
1271
1272/**
1146 * ice_add_mac_to_list - Add a mac address filter entry to the list 1273 * ice_add_mac_to_list - Add a mac address filter entry to the list
1147 * @vsi: the VSI to be forwarded to 1274 * @vsi: the VSI to be forwarded to
1148 * @add_list: pointer to the list which contains MAC filter entries 1275 * @add_list: pointer to the list which contains MAC filter entries
@@ -1723,6 +1850,112 @@ err_out:
1723} 1850}
1724 1851
1725/** 1852/**
1853 * ice_vsi_setup - Set up a VSI by a given type
1854 * @pf: board private structure
1855 * @pi: pointer to the port_info instance
1856 * @type: VSI type
1857 * @vf_id: defines VF id to which this VSI connects. This field is meant to be
1858 * used only for ICE_VSI_VF VSI type. For other VSI types, should
1859 * fill-in ICE_INVAL_VFID as input.
1860 *
1861 * This allocates the sw VSI structure and its queue resources.
1862 *
1863 * Returns pointer to the successfully allocated and configured VSI sw struct on
1864 * success, NULL on failure.
1865 */
1866struct ice_vsi *
1867ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
1868 enum ice_vsi_type type, u16 __always_unused vf_id)
1869{
1870 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1871 struct device *dev = &pf->pdev->dev;
1872 struct ice_vsi *vsi;
1873 int ret, i;
1874
1875 vsi = ice_vsi_alloc(pf, type);
1876 if (!vsi) {
1877 dev_err(dev, "could not allocate VSI\n");
1878 return NULL;
1879 }
1880
1881 vsi->port_info = pi;
1882 vsi->vsw = pf->first_sw;
1883
1884 if (ice_vsi_get_qs(vsi)) {
1885 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
1886 vsi->idx);
1887 goto unroll_get_qs;
1888 }
1889
1890 /* set RSS capabilities */
1891 ice_vsi_set_rss_params(vsi);
1892
1893 /* create the VSI */
1894 ret = ice_vsi_init(vsi);
1895 if (ret)
1896 goto unroll_get_qs;
1897
1898 switch (vsi->type) {
1899 case ICE_VSI_PF:
1900 ret = ice_vsi_alloc_q_vectors(vsi);
1901 if (ret)
1902 goto unroll_vsi_init;
1903
1904 ret = ice_vsi_setup_vector_base(vsi);
1905 if (ret)
1906 goto unroll_alloc_q_vector;
1907
1908 ret = ice_vsi_alloc_rings(vsi);
1909 if (ret)
1910 goto unroll_vector_base;
1911
1912 ice_vsi_map_rings_to_vectors(vsi);
1913
1914 /* Do not exit if configuring RSS had an issue, at least
1915 * receive traffic on first queue. Hence no need to capture
1916 * return value
1917 */
1918 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1919 ice_vsi_cfg_rss_lut_key(vsi);
1920 break;
1921 default:
1922 /* if VSI type is not recognized, clean up the resources and
1923 * exit
1924 */
1925 goto unroll_vsi_init;
1926 }
1927
1928 ice_vsi_set_tc_cfg(vsi);
1929
1930 /* configure VSI nodes based on number of queues and TC's */
1931 for (i = 0; i < vsi->tc_cfg.numtc; i++)
1932 max_txqs[i] = vsi->num_txq;
1933
1934 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->vsi_num,
1935 vsi->tc_cfg.ena_tc, max_txqs);
1936 if (ret) {
1937 dev_info(&pf->pdev->dev, "Failed VSI lan queue config\n");
1938 goto unroll_vector_base;
1939 }
1940
1941 return vsi;
1942
1943unroll_vector_base:
1944 ice_free_res(vsi->back->irq_tracker, vsi->base_vector, vsi->idx);
1945unroll_alloc_q_vector:
1946 ice_vsi_free_q_vectors(vsi);
1947unroll_vsi_init:
1948 ice_vsi_delete(vsi);
1949unroll_get_qs:
1950 ice_vsi_put_qs(vsi);
1951 pf->q_left_tx += vsi->alloc_txq;
1952 pf->q_left_rx += vsi->alloc_rxq;
1953 ice_vsi_clear(vsi);
1954
1955 return NULL;
1956}
1957
1958/**
1726 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW 1959 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
1727 * @vsi: the VSI being cleaned up 1960 * @vsi: the VSI being cleaned up
1728 */ 1961 */