diff options
Diffstat (limited to 'drivers/net/ethernet/mellanox/mlx4/resource_tracker.c')
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c index 561ed2a22a17..9185e2eef8fa 100644 --- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c +++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | |||
@@ -1231,14 +1231,14 @@ static int mpt_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd, | |||
1231 | 1231 | ||
1232 | switch (op) { | 1232 | switch (op) { |
1233 | case RES_OP_RESERVE: | 1233 | case RES_OP_RESERVE: |
1234 | index = __mlx4_mr_reserve(dev); | 1234 | index = __mlx4_mpt_reserve(dev); |
1235 | if (index == -1) | 1235 | if (index == -1) |
1236 | break; | 1236 | break; |
1237 | id = index & mpt_mask(dev); | 1237 | id = index & mpt_mask(dev); |
1238 | 1238 | ||
1239 | err = add_res_range(dev, slave, id, 1, RES_MPT, index); | 1239 | err = add_res_range(dev, slave, id, 1, RES_MPT, index); |
1240 | if (err) { | 1240 | if (err) { |
1241 | __mlx4_mr_release(dev, index); | 1241 | __mlx4_mpt_release(dev, index); |
1242 | break; | 1242 | break; |
1243 | } | 1243 | } |
1244 | set_param_l(out_param, index); | 1244 | set_param_l(out_param, index); |
@@ -1251,7 +1251,7 @@ static int mpt_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd, | |||
1251 | if (err) | 1251 | if (err) |
1252 | return err; | 1252 | return err; |
1253 | 1253 | ||
1254 | err = __mlx4_mr_alloc_icm(dev, mpt->key); | 1254 | err = __mlx4_mpt_alloc_icm(dev, mpt->key); |
1255 | if (err) { | 1255 | if (err) { |
1256 | res_abort_move(dev, slave, RES_MPT, id); | 1256 | res_abort_move(dev, slave, RES_MPT, id); |
1257 | return err; | 1257 | return err; |
@@ -1586,7 +1586,7 @@ static int mpt_free_res(struct mlx4_dev *dev, int slave, int op, int cmd, | |||
1586 | err = rem_res_range(dev, slave, id, 1, RES_MPT, 0); | 1586 | err = rem_res_range(dev, slave, id, 1, RES_MPT, 0); |
1587 | if (err) | 1587 | if (err) |
1588 | break; | 1588 | break; |
1589 | __mlx4_mr_release(dev, index); | 1589 | __mlx4_mpt_release(dev, index); |
1590 | break; | 1590 | break; |
1591 | case RES_OP_MAP_ICM: | 1591 | case RES_OP_MAP_ICM: |
1592 | index = get_param_l(&in_param); | 1592 | index = get_param_l(&in_param); |
@@ -1596,7 +1596,7 @@ static int mpt_free_res(struct mlx4_dev *dev, int slave, int op, int cmd, | |||
1596 | if (err) | 1596 | if (err) |
1597 | return err; | 1597 | return err; |
1598 | 1598 | ||
1599 | __mlx4_mr_free_icm(dev, mpt->key); | 1599 | __mlx4_mpt_free_icm(dev, mpt->key); |
1600 | res_end_move(dev, slave, RES_MPT, id); | 1600 | res_end_move(dev, slave, RES_MPT, id); |
1601 | return err; | 1601 | return err; |
1602 | break; | 1602 | break; |
@@ -1796,6 +1796,26 @@ static int mr_get_mtt_size(struct mlx4_mpt_entry *mpt) | |||
1796 | return be32_to_cpu(mpt->mtt_sz); | 1796 | return be32_to_cpu(mpt->mtt_sz); |
1797 | } | 1797 | } |
1798 | 1798 | ||
1799 | static u32 mr_get_pd(struct mlx4_mpt_entry *mpt) | ||
1800 | { | ||
1801 | return be32_to_cpu(mpt->pd_flags) & 0x00ffffff; | ||
1802 | } | ||
1803 | |||
1804 | static int mr_is_fmr(struct mlx4_mpt_entry *mpt) | ||
1805 | { | ||
1806 | return be32_to_cpu(mpt->pd_flags) & MLX4_MPT_PD_FLAG_FAST_REG; | ||
1807 | } | ||
1808 | |||
1809 | static int mr_is_bind_enabled(struct mlx4_mpt_entry *mpt) | ||
1810 | { | ||
1811 | return be32_to_cpu(mpt->flags) & MLX4_MPT_FLAG_BIND_ENABLE; | ||
1812 | } | ||
1813 | |||
1814 | static int mr_is_region(struct mlx4_mpt_entry *mpt) | ||
1815 | { | ||
1816 | return be32_to_cpu(mpt->flags) & MLX4_MPT_FLAG_REGION; | ||
1817 | } | ||
1818 | |||
1799 | static int qp_get_mtt_addr(struct mlx4_qp_context *qpc) | 1819 | static int qp_get_mtt_addr(struct mlx4_qp_context *qpc) |
1800 | { | 1820 | { |
1801 | return be32_to_cpu(qpc->mtt_base_addr_l) & 0xfffffff8; | 1821 | return be32_to_cpu(qpc->mtt_base_addr_l) & 0xfffffff8; |
@@ -1856,12 +1876,41 @@ int mlx4_SW2HW_MPT_wrapper(struct mlx4_dev *dev, int slave, | |||
1856 | int mtt_base = mr_get_mtt_addr(inbox->buf) / dev->caps.mtt_entry_sz; | 1876 | int mtt_base = mr_get_mtt_addr(inbox->buf) / dev->caps.mtt_entry_sz; |
1857 | int phys; | 1877 | int phys; |
1858 | int id; | 1878 | int id; |
1879 | u32 pd; | ||
1880 | int pd_slave; | ||
1859 | 1881 | ||
1860 | id = index & mpt_mask(dev); | 1882 | id = index & mpt_mask(dev); |
1861 | err = mr_res_start_move_to(dev, slave, id, RES_MPT_HW, &mpt); | 1883 | err = mr_res_start_move_to(dev, slave, id, RES_MPT_HW, &mpt); |
1862 | if (err) | 1884 | if (err) |
1863 | return err; | 1885 | return err; |
1864 | 1886 | ||
1887 | /* Disable memory windows for VFs. */ | ||
1888 | if (!mr_is_region(inbox->buf)) { | ||
1889 | err = -EPERM; | ||
1890 | goto ex_abort; | ||
1891 | } | ||
1892 | |||
1893 | /* Make sure that the PD bits related to the slave id are zeros. */ | ||
1894 | pd = mr_get_pd(inbox->buf); | ||
1895 | pd_slave = (pd >> 17) & 0x7f; | ||
1896 | if (pd_slave != 0 && pd_slave != slave) { | ||
1897 | err = -EPERM; | ||
1898 | goto ex_abort; | ||
1899 | } | ||
1900 | |||
1901 | if (mr_is_fmr(inbox->buf)) { | ||
1902 | /* FMR and Bind Enable are forbidden in slave devices. */ | ||
1903 | if (mr_is_bind_enabled(inbox->buf)) { | ||
1904 | err = -EPERM; | ||
1905 | goto ex_abort; | ||
1906 | } | ||
1907 | /* FMR and Memory Windows are also forbidden. */ | ||
1908 | if (!mr_is_region(inbox->buf)) { | ||
1909 | err = -EPERM; | ||
1910 | goto ex_abort; | ||
1911 | } | ||
1912 | } | ||
1913 | |||
1865 | phys = mr_phys_mpt(inbox->buf); | 1914 | phys = mr_phys_mpt(inbox->buf); |
1866 | if (!phys) { | 1915 | if (!phys) { |
1867 | err = get_res(dev, slave, mtt_base, RES_MTT, &mtt); | 1916 | err = get_res(dev, slave, mtt_base, RES_MTT, &mtt); |
@@ -3480,7 +3529,7 @@ static void rem_slave_mrs(struct mlx4_dev *dev, int slave) | |||
3480 | while (state != 0) { | 3529 | while (state != 0) { |
3481 | switch (state) { | 3530 | switch (state) { |
3482 | case RES_MPT_RESERVED: | 3531 | case RES_MPT_RESERVED: |
3483 | __mlx4_mr_release(dev, mpt->key); | 3532 | __mlx4_mpt_release(dev, mpt->key); |
3484 | spin_lock_irq(mlx4_tlock(dev)); | 3533 | spin_lock_irq(mlx4_tlock(dev)); |
3485 | rb_erase(&mpt->com.node, | 3534 | rb_erase(&mpt->com.node, |
3486 | &tracker->res_tree[RES_MPT]); | 3535 | &tracker->res_tree[RES_MPT]); |
@@ -3491,7 +3540,7 @@ static void rem_slave_mrs(struct mlx4_dev *dev, int slave) | |||
3491 | break; | 3540 | break; |
3492 | 3541 | ||
3493 | case RES_MPT_MAPPED: | 3542 | case RES_MPT_MAPPED: |
3494 | __mlx4_mr_free_icm(dev, mpt->key); | 3543 | __mlx4_mpt_free_icm(dev, mpt->key); |
3495 | state = RES_MPT_RESERVED; | 3544 | state = RES_MPT_RESERVED; |
3496 | break; | 3545 | break; |
3497 | 3546 | ||