1515#include <linux/mlx5/driver.h>
1616#include <linux/mlx5/fs.h>
1717#include <linux/mlx5/fs_helpers.h>
18- #include <linux/mlx5/accel.h>
1918#include <linux/mlx5/eswitch.h>
2019#include <net/inet_ecn.h>
2120#include "mlx5_ib.h"
@@ -148,16 +147,6 @@ int parse_flow_flow_action(struct mlx5_ib_flow_action *maction,
148147{
149148
150149 switch (maction -> ib_action .type ) {
151- case IB_FLOW_ACTION_ESP :
152- if (action -> action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT |
153- MLX5_FLOW_CONTEXT_ACTION_DECRYPT ))
154- return - EINVAL ;
155- /* Currently only AES_GCM keymat is supported by the driver */
156- action -> esp_id = (uintptr_t )maction -> esp_aes_gcm .ctx ;
157- action -> action |= is_egress ?
158- MLX5_FLOW_CONTEXT_ACTION_ENCRYPT :
159- MLX5_FLOW_CONTEXT_ACTION_DECRYPT ;
160- return 0 ;
161150 case IB_FLOW_ACTION_UNSPECIFIED :
162151 if (maction -> flow_action_raw .sub_type ==
163152 MLX5_IB_FLOW_ACTION_MODIFY_HEADER ) {
@@ -368,14 +357,7 @@ static int parse_flow_attr(struct mlx5_core_dev *mdev,
368357 ib_spec -> type & IB_FLOW_SPEC_INNER );
369358 break ;
370359 case IB_FLOW_SPEC_ESP :
371- if (ib_spec -> esp .mask .seq )
372- return - EOPNOTSUPP ;
373-
374- MLX5_SET (fte_match_set_misc , misc_params_c , outer_esp_spi ,
375- ntohl (ib_spec -> esp .mask .spi ));
376- MLX5_SET (fte_match_set_misc , misc_params_v , outer_esp_spi ,
377- ntohl (ib_spec -> esp .val .spi ));
378- break ;
360+ return - EOPNOTSUPP ;
379361 case IB_FLOW_SPEC_TCP :
380362 if (FIELDS_NOT_SUPPORTED (ib_spec -> tcp_udp .mask ,
381363 LAST_TCP_UDP_FIELD ))
@@ -587,47 +569,6 @@ static bool flow_is_multicast_only(const struct ib_flow_attr *ib_attr)
587569 return false;
588570}
589571
590- enum valid_spec {
591- VALID_SPEC_INVALID ,
592- VALID_SPEC_VALID ,
593- VALID_SPEC_NA ,
594- };
595-
596- static enum valid_spec
597- is_valid_esp_aes_gcm (struct mlx5_core_dev * mdev ,
598- const struct mlx5_flow_spec * spec ,
599- const struct mlx5_flow_act * flow_act ,
600- bool egress )
601- {
602- const u32 * match_c = spec -> match_criteria ;
603- bool is_crypto =
604- (flow_act -> action & (MLX5_FLOW_CONTEXT_ACTION_ENCRYPT |
605- MLX5_FLOW_CONTEXT_ACTION_DECRYPT ));
606- bool is_ipsec = mlx5_fs_is_ipsec_flow (match_c );
607- bool is_drop = flow_act -> action & MLX5_FLOW_CONTEXT_ACTION_DROP ;
608-
609- /*
610- * Currently only crypto is supported in egress, when regular egress
611- * rules would be supported, always return VALID_SPEC_NA.
612- */
613- if (!is_crypto )
614- return VALID_SPEC_NA ;
615-
616- return is_crypto && is_ipsec &&
617- (!egress || (!is_drop &&
618- !(spec -> flow_context .flags & FLOW_CONTEXT_HAS_TAG ))) ?
619- VALID_SPEC_VALID : VALID_SPEC_INVALID ;
620- }
621-
622- static bool is_valid_spec (struct mlx5_core_dev * mdev ,
623- const struct mlx5_flow_spec * spec ,
624- const struct mlx5_flow_act * flow_act ,
625- bool egress )
626- {
627- /* We curretly only support ipsec egress flow */
628- return is_valid_esp_aes_gcm (mdev , spec , flow_act , egress ) != VALID_SPEC_INVALID ;
629- }
630-
631572static bool is_valid_ethertype (struct mlx5_core_dev * mdev ,
632573 const struct ib_flow_attr * flow_attr ,
633574 bool check_inner )
@@ -1154,12 +1095,6 @@ static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev,
11541095
11551096 spec -> match_criteria_enable = get_match_criteria_enable (spec -> match_criteria );
11561097
1157- if (is_egress &&
1158- !is_valid_spec (dev -> mdev , spec , & flow_act , is_egress )) {
1159- err = - EINVAL ;
1160- goto free ;
1161- }
1162-
11631098 if (flow_act .action & MLX5_FLOW_CONTEXT_ACTION_COUNT ) {
11641099 struct mlx5_ib_mcounters * mcounters ;
11651100
@@ -1740,149 +1675,6 @@ static struct mlx5_ib_flow_handler *raw_fs_rule_add(
17401675 return ERR_PTR (err );
17411676}
17421677
1743- static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags (u32 mlx5_flags )
1744- {
1745- u32 flags = 0 ;
1746-
1747- if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA )
1748- flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA ;
1749-
1750- return flags ;
1751- }
1752-
1753- #define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED \
1754- MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA
1755- static struct ib_flow_action *
1756- mlx5_ib_create_flow_action_esp (struct ib_device * device ,
1757- const struct ib_flow_action_attrs_esp * attr ,
1758- struct uverbs_attr_bundle * attrs )
1759- {
1760- struct mlx5_ib_dev * mdev = to_mdev (device );
1761- struct ib_uverbs_flow_action_esp_keymat_aes_gcm * aes_gcm ;
1762- struct mlx5_accel_esp_xfrm_attrs accel_attrs = {};
1763- struct mlx5_ib_flow_action * action ;
1764- u64 action_flags ;
1765- u64 flags ;
1766- int err = 0 ;
1767-
1768- err = uverbs_get_flags64 (
1769- & action_flags , attrs , MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS ,
1770- ((MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1 ) - 1 ));
1771- if (err )
1772- return ERR_PTR (err );
1773-
1774- flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags (action_flags );
1775-
1776- /* We current only support a subset of the standard features. Only a
1777- * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn
1778- * (with overlap). Full offload mode isn't supported.
1779- */
1780- if (!attr -> keymat || attr -> replay || attr -> encap ||
1781- attr -> spi || attr -> seq || attr -> tfc_pad ||
1782- attr -> hard_limit_pkts ||
1783- (attr -> flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED |
1784- IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT )))
1785- return ERR_PTR (- EOPNOTSUPP );
1786-
1787- if (attr -> keymat -> protocol !=
1788- IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM )
1789- return ERR_PTR (- EOPNOTSUPP );
1790-
1791- aes_gcm = & attr -> keymat -> keymat .aes_gcm ;
1792-
1793- if (aes_gcm -> icv_len != 16 ||
1794- aes_gcm -> iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ )
1795- return ERR_PTR (- EOPNOTSUPP );
1796-
1797- action = kmalloc (sizeof (* action ), GFP_KERNEL );
1798- if (!action )
1799- return ERR_PTR (- ENOMEM );
1800-
1801- action -> esp_aes_gcm .ib_flags = attr -> flags ;
1802- memcpy (& accel_attrs .keymat .aes_gcm .aes_key , & aes_gcm -> aes_key ,
1803- sizeof (accel_attrs .keymat .aes_gcm .aes_key ));
1804- accel_attrs .keymat .aes_gcm .key_len = aes_gcm -> key_len * 8 ;
1805- memcpy (& accel_attrs .keymat .aes_gcm .salt , & aes_gcm -> salt ,
1806- sizeof (accel_attrs .keymat .aes_gcm .salt ));
1807- memcpy (& accel_attrs .keymat .aes_gcm .seq_iv , & aes_gcm -> iv ,
1808- sizeof (accel_attrs .keymat .aes_gcm .seq_iv ));
1809- accel_attrs .keymat .aes_gcm .icv_len = aes_gcm -> icv_len * 8 ;
1810- accel_attrs .keymat .aes_gcm .iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ ;
1811- accel_attrs .keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM ;
1812-
1813- accel_attrs .esn = attr -> esn ;
1814- if (attr -> flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED )
1815- accel_attrs .flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED ;
1816- if (attr -> flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW )
1817- accel_attrs .flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP ;
1818-
1819- if (attr -> flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT )
1820- accel_attrs .action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT ;
1821-
1822- action -> esp_aes_gcm .ctx =
1823- mlx5_accel_esp_create_xfrm (mdev -> mdev , & accel_attrs , flags );
1824- if (IS_ERR (action -> esp_aes_gcm .ctx )) {
1825- err = PTR_ERR (action -> esp_aes_gcm .ctx );
1826- goto err_parse ;
1827- }
1828-
1829- action -> esp_aes_gcm .ib_flags = attr -> flags ;
1830-
1831- return & action -> ib_action ;
1832-
1833- err_parse :
1834- kfree (action );
1835- return ERR_PTR (err );
1836- }
1837-
1838- static int
1839- mlx5_ib_modify_flow_action_esp (struct ib_flow_action * action ,
1840- const struct ib_flow_action_attrs_esp * attr ,
1841- struct uverbs_attr_bundle * attrs )
1842- {
1843- struct mlx5_ib_flow_action * maction = to_mflow_act (action );
1844- struct mlx5_accel_esp_xfrm_attrs accel_attrs ;
1845- int err = 0 ;
1846-
1847- if (attr -> keymat || attr -> replay || attr -> encap ||
1848- attr -> spi || attr -> seq || attr -> tfc_pad ||
1849- attr -> hard_limit_pkts ||
1850- (attr -> flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED |
1851- IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS |
1852- IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW )))
1853- return - EOPNOTSUPP ;
1854-
1855- /* Only the ESN value or the MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP can
1856- * be modified.
1857- */
1858- if (!(maction -> esp_aes_gcm .ib_flags &
1859- IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED ) &&
1860- attr -> flags & (IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED |
1861- IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW ))
1862- return - EINVAL ;
1863-
1864- memcpy (& accel_attrs , & maction -> esp_aes_gcm .ctx -> attrs ,
1865- sizeof (accel_attrs ));
1866-
1867- accel_attrs .esn = attr -> esn ;
1868- if (attr -> flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW )
1869- accel_attrs .flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP ;
1870- else
1871- accel_attrs .flags &= ~MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP ;
1872-
1873- err = mlx5_accel_esp_modify_xfrm (maction -> esp_aes_gcm .ctx ,
1874- & accel_attrs );
1875- if (err )
1876- return err ;
1877-
1878- maction -> esp_aes_gcm .ib_flags &=
1879- ~IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW ;
1880- maction -> esp_aes_gcm .ib_flags |=
1881- attr -> flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW ;
1882-
1883- return 0 ;
1884- }
1885-
18861678static void destroy_flow_action_raw (struct mlx5_ib_flow_action * maction )
18871679{
18881680 switch (maction -> flow_action_raw .sub_type ) {
@@ -1906,13 +1698,6 @@ static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action)
19061698 struct mlx5_ib_flow_action * maction = to_mflow_act (action );
19071699
19081700 switch (action -> type ) {
1909- case IB_FLOW_ACTION_ESP :
1910- /*
1911- * We only support aes_gcm by now, so we implicitly know this is
1912- * the underline crypto.
1913- */
1914- mlx5_accel_esp_destroy_xfrm (maction -> esp_aes_gcm .ctx );
1915- break ;
19161701 case IB_FLOW_ACTION_UNSPECIFIED :
19171702 destroy_flow_action_raw (maction );
19181703 break ;
@@ -2709,11 +2494,6 @@ static const struct ib_device_ops flow_ops = {
27092494 .destroy_flow_action = mlx5_ib_destroy_flow_action ,
27102495};
27112496
2712- static const struct ib_device_ops flow_ipsec_ops = {
2713- .create_flow_action_esp = mlx5_ib_create_flow_action_esp ,
2714- .modify_flow_action_esp = mlx5_ib_modify_flow_action_esp ,
2715- };
2716-
27172497int mlx5_ib_fs_init (struct mlx5_ib_dev * dev )
27182498{
27192499 dev -> flow_db = kzalloc (sizeof (* dev -> flow_db ), GFP_KERNEL );
@@ -2724,9 +2504,5 @@ int mlx5_ib_fs_init(struct mlx5_ib_dev *dev)
27242504 mutex_init (& dev -> flow_db -> lock );
27252505
27262506 ib_set_device_ops (& dev -> ib_dev , & flow_ops );
2727- if (mlx5_accel_ipsec_device_caps (dev -> mdev ) &
2728- MLX5_ACCEL_IPSEC_CAP_DEVICE )
2729- ib_set_device_ops (& dev -> ib_dev , & flow_ipsec_ops );
2730-
27312507 return 0 ;
27322508}
0 commit comments