1 /*- 2 * Copyright (c) 2023 NVIDIA corporation & affiliates. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 * 25 */ 26 27 #include <sys/mbuf.h> 28 #include <sys/socket.h> 29 #include <netinet/in.h> 30 #include <netipsec/keydb.h> 31 #include <netipsec/ipsec_offload.h> 32 #include <dev/mlx5/qp.h> 33 #include <dev/mlx5/mlx5_en/en.h> 34 #include <dev/mlx5/mlx5_accel/ipsec.h> 35 36 #define MLX5_IPSEC_METADATA_HANDLE(ipsec_metadata) (ipsec_metadata & 0xFFFFFF) 37 38 int mlx5_accel_ipsec_rx_tag_add(if_t ifp, struct mbuf *mb) 39 { 40 struct mlx5e_priv *priv; 41 struct ipsec_accel_in_tag *tag; 42 struct m_tag *mtag; 43 44 priv = if_getsoftc(ifp); 45 if (priv->ipsec == NULL) 46 return (0); 47 48 mtag = m_tag_get(PACKET_TAG_IPSEC_ACCEL_IN, sizeof(*tag), M_NOWAIT); 49 if (mtag == NULL) 50 return -ENOMEM; 51 52 m_tag_prepend(mb, mtag); 53 return 0; 54 } 55 56 int mlx5e_accel_ipsec_handle_rx_cqe(struct mbuf *mb, struct mlx5_cqe64 *cqe) 57 { 58 struct ipsec_accel_in_tag *tag; 59 u32 drv_spi; 60 61 drv_spi = MLX5_IPSEC_METADATA_HANDLE(be32_to_cpu(cqe->ft_metadata)); 62 tag = (struct ipsec_accel_in_tag *) m_tag_find(mb, PACKET_TAG_IPSEC_ACCEL_IN, NULL); 63 WARN_ON(tag == NULL); 64 if (tag) 65 tag->drv_spi = drv_spi; 66 67 return 0; 68 } 69 70 void 71 mlx5e_accel_ipsec_handle_tx_wqe(struct mbuf *mb, struct mlx5e_tx_wqe *wqe, 72 struct ipsec_accel_out_tag *tag) 73 { 74 wqe->eth.flow_table_metadata = cpu_to_be32( 75 mlx5e_accel_ipsec_get_metadata(tag->drv_spi)); 76 } 77