Author: slavash
Date: Wed Dec  5 14:11:20 2018
New Revision: 341572
URL: https://svnweb.freebsd.org/changeset/base/341572

Log:
  mlx5fpga: Initial code import.
  
  Submitted by:   kib@
  Approved by:    hselasky (mentor)
  MFC after:      1 week
  Sponsored by:   Mellanox Technologies

Added:
  head/sys/dev/mlx5/mlx5_accel/
  head/sys/dev/mlx5/mlx5_accel/ipsec.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/
  head/sys/dev/mlx5/mlx5_fpga/cmd.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/conn.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/core.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/ipsec.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5_ifc_fpga.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5fpga_cmd.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5fpga_conn.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5fpga_core.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5fpga_ipsec.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5fpga_sdk.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5fpga_trans.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/mlx5fpga_xfer.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/sdk.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/trans.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_fpga/xfer.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_lib/
  head/sys/dev/mlx5/mlx5_lib/mlx5.h   (contents, props changed)
  head/sys/dev/mlx5/mlx5_lib/mlx5_gid.c   (contents, props changed)
Modified:
  head/sys/dev/mlx5/device.h
  head/sys/dev/mlx5/driver.h
  head/sys/dev/mlx5/mlx5_core/mlx5_core.h
  head/sys/dev/mlx5/mlx5_core/mlx5_main.c
  head/sys/dev/mlx5/mlx5_core/wq.h
  head/sys/dev/mlx5/mlx5_ifc.h
  head/sys/dev/mlx5/mlx5io.h
  head/sys/modules/mlx5/Makefile
  head/sys/modules/mlx5en/Makefile
  head/sys/modules/mlx5ib/Makefile

Modified: head/sys/dev/mlx5/device.h
==============================================================================
--- head/sys/dev/mlx5/device.h  Wed Dec  5 13:49:11 2018        (r341571)
+++ head/sys/dev/mlx5/device.h  Wed Dec  5 14:11:20 2018        (r341572)
@@ -1034,6 +1034,12 @@ enum mlx5_qcam_feature_groups {
 #define        MLX5_CAP_QCAM_FEATURE(mdev, fld) \
        MLX5_GET(qcam_reg, (mdev)->caps.qcam, 
qos_feature_cap_mask.feature_cap.fld)
 
+#define MLX5_CAP_FPGA(mdev, cap) \
+       MLX5_GET(fpga_cap, (mdev)->caps.fpga, cap)
+
+#define MLX5_CAP64_FPGA(mdev, cap) \
+       MLX5_GET64(fpga_cap, (mdev)->caps.fpga, cap)
+
 enum {
        MLX5_CMD_STAT_OK                        = 0x0,
        MLX5_CMD_STAT_INT_ERR                   = 0x1,

Modified: head/sys/dev/mlx5/driver.h
==============================================================================
--- head/sys/dev/mlx5/driver.h  Wed Dec  5 13:49:11 2018        (r341571)
+++ head/sys/dev/mlx5/driver.h  Wed Dec  5 14:11:20 2018        (r341572)
@@ -40,6 +40,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/radix-tree.h>
+#include <linux/idr.h>
 
 #include <dev/mlx5/device.h>
 #include <dev/mlx5/doorbell.h>
@@ -131,6 +132,10 @@ enum {
        MLX5_REG_DCBX_PARAM      = 0x4020,
        MLX5_REG_DCBX_APP        = 0x4021,
        MLX5_REG_PCAP            = 0x5001,
+       MLX5_REG_FPGA_CAP        = 0x4022,
+       MLX5_REG_FPGA_CTRL       = 0x4023,
+       MLX5_REG_FPGA_ACCESS_REG = 0x4024,
+       MLX5_REG_FPGA_SHELL_CNTR = 0x4025,
        MLX5_REG_PMTU            = 0x5003,
        MLX5_REG_PTYS            = 0x5004,
        MLX5_REG_PAOS            = 0x5006,
@@ -404,6 +409,13 @@ struct mlx5_buf {
        u8                      load_done;
 };
 
+struct mlx5_frag_buf {
+       struct mlx5_buf_list    *frags;
+       int                     npages;
+       int                     size;
+       u8                      page_shift;
+};
+
 struct mlx5_eq {
        struct mlx5_core_dev   *dev;
        __be32 __iomem         *doorbell;
@@ -442,6 +454,20 @@ struct mlx5_core_sig_ctx {
        u32                     sigerr_count;
 };
 
+enum {
+       MLX5_MKEY_MR = 1,
+       MLX5_MKEY_MW,
+       MLX5_MKEY_MR_USER,
+};
+
+struct mlx5_core_mkey {
+       u64                     iova;
+       u64                     size;
+       u32                     key;
+       u32                     pd;
+       u32                     type;
+};
+
 struct mlx5_core_mr {
        u64                     iova;
        u64                     size;
@@ -645,6 +671,14 @@ enum mlx5_pci_status {
        MLX5_PCI_STATUS_ENABLED,
 };
 
+#define        MLX5_MAX_RESERVED_GIDS  8
+
+struct mlx5_rsvd_gids {
+       unsigned int start;
+       unsigned int count;
+       struct ida ida;
+};
+
 struct mlx5_special_contexts {
        int resd_lkey;
 };
@@ -663,6 +697,7 @@ struct mlx5_core_dev {
        u32 hca_caps_max[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
        struct {
                u32 qcam[MLX5_ST_SZ_DW(qcam_reg)];
+               u32 fpga[MLX5_ST_SZ_DW(fpga_cap)];
        } caps;
        phys_addr_t             iseg_base;
        struct mlx5_init_seg __iomem *iseg;
@@ -691,6 +726,14 @@ struct mlx5_core_dev {
 
        struct sysctl_ctx_list  sysctl_ctx;
        int                     msix_eqvec;
+
+       struct {
+               struct mlx5_rsvd_gids   reserved_gids;
+               atomic_t                roce_en;
+       } roce;
+#ifdef CONFIG_MLX5_FPGA
+       struct mlx5_fpga_device *fpga;
+#endif
 };
 
 enum {
@@ -1105,6 +1148,11 @@ struct mlx5_interface {
 void *mlx5_get_protocol_dev(struct mlx5_core_dev *mdev, int protocol);
 int mlx5_register_interface(struct mlx5_interface *intf);
 void mlx5_unregister_interface(struct mlx5_interface *intf);
+
+unsigned int mlx5_core_reserved_gids_count(struct mlx5_core_dev *dev);
+int mlx5_core_roce_gid_set(struct mlx5_core_dev *dev, unsigned int index,
+    u8 roce_version, u8 roce_l3_type, const u8 *gid,
+    const u8 *mac, bool vlan, u16 vlan_id);
 
 struct mlx5_profile {
        u64     mask;

Added: head/sys/dev/mlx5/mlx5_accel/ipsec.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_accel/ipsec.h        Wed Dec  5 14:11:20 2018        
(r341572)
@@ -0,0 +1,139 @@
+/*-
+ * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __MLX5_ACCEL_IPSEC_H__
+#define __MLX5_ACCEL_IPSEC_H__
+
+#ifdef CONFIG_MLX5_ACCEL
+
+#include <dev/mlx5/driver.h>
+
+enum {
+       MLX5_ACCEL_IPSEC_DEVICE = BIT(1),
+       MLX5_ACCEL_IPSEC_IPV6 = BIT(2),
+       MLX5_ACCEL_IPSEC_ESP = BIT(3),
+       MLX5_ACCEL_IPSEC_LSO = BIT(4),
+};
+
+#define MLX5_IPSEC_SADB_IP_AH       BIT(7)
+#define MLX5_IPSEC_SADB_IP_ESP      BIT(6)
+#define MLX5_IPSEC_SADB_SA_VALID    BIT(5)
+#define MLX5_IPSEC_SADB_SPI_EN      BIT(4)
+#define MLX5_IPSEC_SADB_DIR_SX      BIT(3)
+#define MLX5_IPSEC_SADB_IPV6        BIT(2)
+
+enum {
+       MLX5_IPSEC_CMD_ADD_SA = 0,
+       MLX5_IPSEC_CMD_DEL_SA = 1,
+};
+
+enum mlx5_accel_ipsec_enc_mode {
+       MLX5_IPSEC_SADB_MODE_NONE = 0,
+       MLX5_IPSEC_SADB_MODE_AES_GCM_128_AUTH_128 = 1,
+       MLX5_IPSEC_SADB_MODE_AES_GCM_256_AUTH_128 = 3,
+};
+
+#define MLX5_IPSEC_DEV(mdev) (mlx5_accel_ipsec_device_caps(mdev) & \
+                             MLX5_ACCEL_IPSEC_DEVICE)
+
+struct mlx5_accel_ipsec_sa {
+       __be32 cmd;
+       u8 key_enc[32];
+       u8 key_auth[32];
+       __be32 sip[4];
+       __be32 dip[4];
+       union {
+               struct {
+                       __be32 reserved;
+                       u8 salt_iv[8];
+                       __be32 salt;
+               } __packed gcm;
+               struct {
+                       u8 salt[16];
+               } __packed cbc;
+       };
+       __be32 spi;
+       __be32 sw_sa_handle;
+       __be16 tfclen;
+       u8 enc_mode;
+       u8 sip_masklen;
+       u8 dip_masklen;
+       u8 flags;
+       u8 reserved[2];
+} __packed;
+
+/**
+ * mlx5_accel_ipsec_sa_cmd_exec - Execute an IPSec SADB command
+ * @mdev: mlx5 device
+ * @cmd: command to execute
+ * May be called from atomic context. Returns context pointer, or error
+ * Caller must eventually call mlx5_accel_ipsec_sa_cmd_wait from non-atomic
+ * context, to cleanup the context pointer
+ */
+void *mlx5_accel_ipsec_sa_cmd_exec(struct mlx5_core_dev *mdev,
+                                  struct mlx5_accel_ipsec_sa *cmd);
+
+/**
+ * mlx5_accel_ipsec_sa_cmd_wait - Wait for command execution completion
+ * @context: Context pointer returned from call to mlx5_accel_ipsec_sa_cmd_exec
+ * Sleeps (killable) until command execution is complete.
+ * Returns the command result, or -EINTR if killed
+ */
+int mlx5_accel_ipsec_sa_cmd_wait(void *context);
+
+u32 mlx5_accel_ipsec_device_caps(struct mlx5_core_dev *mdev);
+
+unsigned int mlx5_accel_ipsec_counters_count(struct mlx5_core_dev *mdev);
+int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
+                                  unsigned int count);
+
+int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev);
+void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev);
+
+#else
+
+#define MLX5_IPSEC_DEV(mdev) false
+
+static inline int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev)
+{
+       return 0;
+}
+
+static inline void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev)
+{
+}
+
+#endif
+
+#endif /* __MLX5_ACCEL_IPSEC_H__ */

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_core.h
==============================================================================
--- head/sys/dev/mlx5/mlx5_core/mlx5_core.h     Wed Dec  5 13:49:11 2018        
(r341571)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_core.h     Wed Dec  5 14:11:20 2018        
(r341572)
@@ -85,6 +85,9 @@ void mlx5_enter_error_state(struct mlx5_core_dev *dev,
 void mlx5_disable_device(struct mlx5_core_dev *dev);
 void mlx5_recover_device(struct mlx5_core_dev *dev);
 
+int mlx5_register_device(struct mlx5_core_dev *dev);
+void mlx5_unregister_device(struct mlx5_core_dev *dev);
+
 void mlx5e_init(void);
 void mlx5e_cleanup(void);
 

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_main.c
==============================================================================
--- head/sys/dev/mlx5/mlx5_core/mlx5_main.c     Wed Dec  5 13:49:11 2018        
(r341571)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_main.c     Wed Dec  5 14:11:20 2018        
(r341572)
@@ -41,6 +41,8 @@
 #include <dev/mlx5/srq.h>
 #include <linux/delay.h>
 #include <dev/mlx5/mlx5_ifc.h>
+#include <dev/mlx5/mlx5_fpga/core.h>
+#include <dev/mlx5/mlx5_lib/mlx5.h>
 #include "mlx5_core.h"
 #include "fs_core.h"
 
@@ -734,7 +736,8 @@ static void mlx5_remove_device(struct mlx5_interface *
                }
 }
 
-static int mlx5_register_device(struct mlx5_core_dev *dev)
+int
+mlx5_register_device(struct mlx5_core_dev *dev)
 {
        struct mlx5_priv *priv = &dev->priv;
        struct mlx5_interface *intf;
@@ -748,7 +751,8 @@ static int mlx5_register_device(struct mlx5_core_dev *
        return 0;
 }
 
-static void mlx5_unregister_device(struct mlx5_core_dev *dev)
+void
+mlx5_unregister_device(struct mlx5_core_dev *dev)
 {
        struct mlx5_priv *priv = &dev->priv;
        struct mlx5_interface *intf;
@@ -912,6 +916,9 @@ static int mlx5_init_once(struct mlx5_core_dev *dev, s
        mlx5_init_srq_table(dev);
        mlx5_init_mr_table(dev);
 
+       mlx5_init_reserved_gids(dev);
+       mlx5_fpga_init(dev);
+
 #ifdef RATELIMIT
        err = mlx5_init_rl_table(dev);
        if (err) {
@@ -941,6 +948,8 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *de
 #ifdef RATELIMIT
        mlx5_cleanup_rl_table(dev);
 #endif
+       mlx5_fpga_cleanup(dev);
+       mlx5_cleanup_reserved_gids(dev);
        mlx5_cleanup_mr_table(dev);
        mlx5_cleanup_srq_table(dev);
        mlx5_cleanup_qp_table(dev);
@@ -1075,6 +1084,12 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, st
                goto err_free_comp_eqs;
        }
 
+       err = mlx5_fpga_device_start(dev);
+       if (err) {
+               dev_err(&pdev->dev, "fpga device start failed %d\n", err);
+               goto err_fpga_start;
+       }
+
        err = mlx5_register_device(dev);
        if (err) {
                dev_err(&pdev->dev, "mlx5_register_device failed %d\n", err);
@@ -1088,6 +1103,7 @@ out:
        mutex_unlock(&dev->intf_state_mutex);
        return 0;
 
+err_fpga_start:
 err_fs:
        mlx5_cleanup_fs(dev);
 
@@ -1152,6 +1168,7 @@ static int mlx5_unload_one(struct mlx5_core_dev *dev, 
 
        mlx5_unregister_device(dev);
 
+       mlx5_fpga_device_stop(dev);
        mlx5_cleanup_fs(dev);
        unmap_bf_area(dev);
        mlx5_wait_for_reclaim_vfs_pages(dev);

Modified: head/sys/dev/mlx5/mlx5_core/wq.h
==============================================================================
--- head/sys/dev/mlx5/mlx5_core/wq.h    Wed Dec  5 13:49:11 2018        
(r341571)
+++ head/sys/dev/mlx5/mlx5_core/wq.h    Wed Dec  5 14:11:20 2018        
(r341572)
@@ -42,11 +42,22 @@ struct mlx5_wq_ctrl {
        struct mlx5_db          db;
 };
 
+struct mlx5_frag_wq_ctrl {
+       struct mlx5_core_dev    *mdev;
+       struct mlx5_frag_buf    frag_buf;
+       struct mlx5_db          db;
+};
+
 struct mlx5_wq_cyc {
        void                    *buf;
        __be32                  *db;
        u16                     sz_m1;
        u8                      log_stride;
+};
+
+struct mlx5_wq_qp {
+       struct mlx5_wq_cyc      rq;
+       struct mlx5_wq_cyc      sq;
 };
 
 struct mlx5_cqwq {

Added: head/sys/dev/mlx5/mlx5_fpga/cmd.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_fpga/cmd.h   Wed Dec  5 14:11:20 2018        
(r341572)
@@ -0,0 +1,82 @@
+/*-
+ * Copyright (c) 2017, Mellanox Technologies, Ltd.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __MLX5_FPGA_H__
+#define __MLX5_FPGA_H__
+
+#include <linux/in6.h>
+#include <dev/mlx5/driver.h>
+#include <dev/mlx5/mlx5io.h>
+
+enum mlx5_fpga_qpc_field_select {
+       MLX5_FPGA_QPC_STATE = BIT(0),
+};
+
+struct mlx5_fpga_qp_counters {
+       u64 rx_ack_packets;
+       u64 rx_send_packets;
+       u64 tx_ack_packets;
+       u64 tx_send_packets;
+       u64 rx_total_drop;
+};
+
+struct mlx5_fpga_shell_counters {
+       u64 ddr_read_requests;
+       u64 ddr_write_requests;
+       u64 ddr_read_bytes;
+       u64 ddr_write_bytes;
+};
+
+int mlx5_fpga_caps(struct mlx5_core_dev *dev);
+int mlx5_fpga_query(struct mlx5_core_dev *dev, struct mlx5_fpga_query *query);
+int mlx5_fpga_ctrl_op(struct mlx5_core_dev *dev, u8 op);
+int mlx5_fpga_access_reg(struct mlx5_core_dev *dev, u8 size, u64 addr,
+                        void *buf, bool write);
+int mlx5_fpga_sbu_caps(struct mlx5_core_dev *dev, void *caps, int size);
+int mlx5_fpga_load(struct mlx5_core_dev *dev, enum mlx5_fpga_image image);
+int mlx5_fpga_image_select(struct mlx5_core_dev *dev,
+                          enum mlx5_fpga_image image);
+int mlx5_fpga_shell_counters(struct mlx5_core_dev *dev, bool clear,
+                            struct mlx5_fpga_shell_counters *data);
+
+int mlx5_fpga_create_qp(struct mlx5_core_dev *dev, void *fpga_qpc,
+                       u32 *fpga_qpn);
+int mlx5_fpga_modify_qp(struct mlx5_core_dev *dev, u32 fpga_qpn,
+                       enum mlx5_fpga_qpc_field_select fields, void *fpga_qpc);
+int mlx5_fpga_query_qp(struct mlx5_core_dev *dev, u32 fpga_qpn, void 
*fpga_qpc);
+int mlx5_fpga_query_qp_counters(struct mlx5_core_dev *dev, u32 fpga_qpn,
+                               bool clear, struct mlx5_fpga_qp_counters *data);
+int mlx5_fpga_destroy_qp(struct mlx5_core_dev *dev, u32 fpga_qpn);
+
+#endif /* __MLX5_FPGA_H__ */

Added: head/sys/dev/mlx5/mlx5_fpga/conn.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_fpga/conn.h  Wed Dec  5 14:11:20 2018        
(r341572)
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __MLX5_FPGA_CONN_H__
+#define __MLX5_FPGA_CONN_H__
+
+#include <dev/mlx5/cq.h>
+#include <dev/mlx5/qp.h>
+#include <dev/mlx5/mlx5_fpga/core.h>
+#include <dev/mlx5/mlx5_fpga/sdk.h>
+#include <dev/mlx5/mlx5_core/wq.h>
+#include <linux/interrupt.h>
+
+struct mlx5_fpga_conn {
+       struct mlx5_fpga_device *fdev;
+
+       void (*recv_cb)(void *cb_arg, struct mlx5_fpga_dma_buf *buf);
+       void *cb_arg;
+
+       /* FPGA QP */
+       u32 fpga_qpc[MLX5_ST_SZ_DW(fpga_qpc)];
+       u32 fpga_qpn;
+
+       /* CQ */
+       struct {
+               struct mlx5_cqwq wq;
+               struct mlx5_frag_wq_ctrl wq_ctrl;
+               struct mlx5_core_cq mcq;
+               struct tasklet_struct tasklet;
+       } cq;
+
+       /* QP */
+       struct {
+               bool active;
+               int sgid_index;
+               struct mlx5_wq_qp wq;
+               struct mlx5_wq_ctrl wq_ctrl;
+               struct mlx5_core_qp mqp;
+               struct {
+                       spinlock_t lock; /* Protects all SQ state */
+                       unsigned int pc;
+                       unsigned int cc;
+                       unsigned int size;
+                       struct mlx5_fpga_dma_buf **bufs;
+                       struct list_head backlog;
+               } sq;
+               struct {
+                       unsigned int pc;
+                       unsigned int cc;
+                       unsigned int size;
+                       struct mlx5_fpga_dma_buf **bufs;
+               } rq;
+       } qp;
+};
+
+int mlx5_fpga_conn_device_init(struct mlx5_fpga_device *fdev);
+void mlx5_fpga_conn_device_cleanup(struct mlx5_fpga_device *fdev);
+struct mlx5_fpga_conn *
+mlx5_fpga_conn_create(struct mlx5_fpga_device *fdev,
+                     struct mlx5_fpga_conn_attr *attr,
+                     enum mlx5_ifc_fpga_qp_type qp_type);
+void mlx5_fpga_conn_destroy(struct mlx5_fpga_conn *conn);
+int mlx5_fpga_conn_send(struct mlx5_fpga_conn *conn,
+                       struct mlx5_fpga_dma_buf *buf);
+
+#endif /* __MLX5_FPGA_CONN_H__ */

Added: head/sys/dev/mlx5/mlx5_fpga/core.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_fpga/core.h  Wed Dec  5 14:11:20 2018        
(r341572)
@@ -0,0 +1,140 @@
+/*-
+ * Copyright (c) 2017, Mellanox Technologies, Ltd.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __MLX5_FPGA_CORE_H__
+#define __MLX5_FPGA_CORE_H__
+
+#ifdef CONFIG_MLX5_FPGA
+
+#include <dev/mlx5/mlx5_fpga/cmd.h>
+#include <dev/mlx5/mlx5_fpga/sdk.h>
+
+/* Represents client-specific and Innova device-specific information */
+struct mlx5_fpga_client_data {
+       struct list_head  list;
+       struct mlx5_fpga_client *client;
+       void *data;
+       bool added;
+};
+
+enum mlx5_fdev_state {
+       MLX5_FDEV_STATE_SUCCESS = 0,
+       MLX5_FDEV_STATE_FAILURE = 1,
+       MLX5_FDEV_STATE_IN_PROGRESS = 2,
+       MLX5_FDEV_STATE_NONE = 0xFFFF,
+};
+
+/* Represents an Innova device */
+struct mlx5_fpga_device {
+       struct mlx5_core_dev *mdev;
+       struct completion load_event;
+       spinlock_t state_lock; /* Protects state transitions */
+       enum mlx5_fdev_state fdev_state;
+       enum mlx5_fpga_status image_status;
+       enum mlx5_fpga_image last_admin_image;
+       enum mlx5_fpga_image last_oper_image;
+
+       /* QP Connection resources */
+       struct {
+               u32 pdn;
+               struct mlx5_core_mkey mkey;
+               struct mlx5_uars_page *uar;
+       } conn_res;
+
+       struct mlx5_fpga_ipsec *ipsec;
+
+       struct list_head list;
+       struct list_head client_data_list;
+
+       /* Shell Transactions state */
+       struct mlx5_fpga_conn *shell_conn;
+       struct mlx5_fpga_trans_device_state *trans;
+};
+
+#define mlx5_fpga_dbg(__adev, format, ...) \
+       dev_dbg(&(__adev)->mdev->pdev->dev, "FPGA: %s:%d:(pid %d): " format, \
+                __func__, __LINE__, current->pid, ##__VA_ARGS__)
+
+#define mlx5_fpga_err(__adev, format, ...) \
+       dev_err(&(__adev)->mdev->pdev->dev, "FPGA: %s:%d:(pid %d): " format, \
+               __func__, __LINE__, current->pid, ##__VA_ARGS__)
+
+#define mlx5_fpga_warn(__adev, format, ...) \
+       dev_warn(&(__adev)->mdev->pdev->dev, "FPGA: %s:%d:(pid %d): " format, \
+               __func__, __LINE__, current->pid, ##__VA_ARGS__)
+
+#define mlx5_fpga_warn_ratelimited(__adev, format, ...) \
+       dev_warn_ratelimited(&(__adev)->mdev->pdev->dev, "FPGA: %s:%d: " \
+               format, __func__, __LINE__, ##__VA_ARGS__)
+
+#define mlx5_fpga_notice(__adev, format, ...) \
+       dev_notice(&(__adev)->mdev->pdev->dev, "FPGA: " format, ##__VA_ARGS__)
+
+#define mlx5_fpga_info(__adev, format, ...) \
+       dev_info(&(__adev)->mdev->pdev->dev, "FPGA: " format, ##__VA_ARGS__)
+
+int mlx5_fpga_init(struct mlx5_core_dev *mdev);
+void mlx5_fpga_cleanup(struct mlx5_core_dev *mdev);
+int mlx5_fpga_device_start(struct mlx5_core_dev *mdev);
+void mlx5_fpga_device_stop(struct mlx5_core_dev *mdev);
+void mlx5_fpga_event(struct mlx5_core_dev *mdev, u8 event, void *data);
+
+#else
+
+static inline int mlx5_fpga_init(struct mlx5_core_dev *mdev)
+{
+       return 0;
+}
+
+static inline void mlx5_fpga_cleanup(struct mlx5_core_dev *mdev)
+{
+}
+
+static inline int mlx5_fpga_device_start(struct mlx5_core_dev *mdev)
+{
+       return 0;
+}
+
+static inline void mlx5_fpga_device_stop(struct mlx5_core_dev *mdev)
+{
+}
+
+static inline void mlx5_fpga_event(struct mlx5_core_dev *mdev, u8 event,
+                                  void *data)
+{
+}
+
+#endif
+
+#endif /* __MLX5_FPGA_CORE_H__ */

Added: head/sys/dev/mlx5/mlx5_fpga/ipsec.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_fpga/ipsec.h Wed Dec  5 14:11:20 2018        
(r341572)
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __MLX5_FPGA_IPSEC_H__
+#define __MLX5_FPGA_IPSEC_H__
+
+#include <dev/mlx5/mlx5_accel/ipsec.h>
+
+#ifdef CONFIG_MLX5_FPGA
+
+void *mlx5_fpga_ipsec_sa_cmd_exec(struct mlx5_core_dev *mdev,
+                                 struct mlx5_accel_ipsec_sa *cmd);
+int mlx5_fpga_ipsec_sa_cmd_wait(void *context);
+
+u32 mlx5_fpga_ipsec_device_caps(struct mlx5_core_dev *mdev);
+unsigned int mlx5_fpga_ipsec_counters_count(struct mlx5_core_dev *mdev);
+int mlx5_fpga_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
+                                 unsigned int counters_count);
+
+int mlx5_fpga_ipsec_init(struct mlx5_core_dev *mdev);
+void mlx5_fpga_ipsec_cleanup(struct mlx5_core_dev *mdev);
+
+#else
+
+static inline void *mlx5_fpga_ipsec_sa_cmd_exec(struct mlx5_core_dev *mdev,
+                                               struct mlx5_accel_ipsec_sa *cmd)
+{
+       return ERR_PTR(-EOPNOTSUPP);
+}
+
+static inline int mlx5_fpga_ipsec_sa_cmd_wait(void *context)
+{
+       return -EOPNOTSUPP;
+}
+
+static inline u32 mlx5_fpga_ipsec_device_caps(struct mlx5_core_dev *mdev)
+{
+       return 0;
+}
+
+static inline unsigned int
+mlx5_fpga_ipsec_counters_count(struct mlx5_core_dev *mdev)
+{
+       return 0;
+}
+
+static inline int mlx5_fpga_ipsec_counters_read(struct mlx5_core_dev *mdev,
+                                               u64 *counters)
+{
+       return 0;
+}
+
+static inline int mlx5_fpga_ipsec_init(struct mlx5_core_dev *mdev)
+{
+       return 0;
+}
+
+static inline void mlx5_fpga_ipsec_cleanup(struct mlx5_core_dev *mdev)
+{
+}
+
+#endif /* CONFIG_MLX5_FPGA */
+
+#endif /* __MLX5_FPGA_SADB_H__ */

Added: head/sys/dev/mlx5/mlx5_fpga/mlx5_ifc_fpga.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_fpga/mlx5_ifc_fpga.h Wed Dec  5 14:11:20 2018        
(r341572)
@@ -0,0 +1,500 @@
+/*-
+ * Copyright (c) 2017, Mellanox Technologies, Ltd.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef MLX5_IFC_FPGA_H
+#define MLX5_IFC_FPGA_H
+
+enum {
+       MLX5_FPGA_CAP_SANDBOX_VENDOR_ID_MLNX = 0x2c9,
+};
+
+enum {
+       MLX5_FPGA_CAP_SANDBOX_PRODUCT_ID_EXAMPLE  = 0x1,
+       MLX5_FPGA_CAP_SANDBOX_PRODUCT_ID_IPSEC    = 0x2,
+       MLX5_FPGA_CAP_SANDBOX_PRODUCT_ID_TLS      = 0x3,
+};
+
+enum {
+       MLX5_FPGA_SHELL_CAPS_QP_TYPE_SHELL_QP    = 0x1,
+       MLX5_FPGA_SHELL_CAPS_QP_TYPE_SANDBOX_QP  = 0x2,
+};
+
+struct mlx5_ifc_fpga_shell_caps_bits {
+       u8         max_num_qps[0x10];
+       u8         reserved_at_10[0x8];
+       u8         total_rcv_credits[0x8];
+
+       u8         reserved_at_20[0xe];
+       u8         qp_type[0x2];
+       u8         reserved_at_30[0x5];
+       u8         rae[0x1];
+       u8         rwe[0x1];
+       u8         rre[0x1];
+       u8         reserved_at_38[0x4];
+       u8         dc[0x1];
+       u8         ud[0x1];
+       u8         uc[0x1];
+       u8         rc[0x1];
+
+       u8         reserved_at_40[0x1a];
+       u8         log_ddr_size[0x6];
+
+       u8         max_fpga_qp_msg_size[0x20];
+
+       u8         reserved_at_80[0x180];
+};
+
+struct mlx5_ifc_fpga_cap_bits {
+       u8         fpga_id[0x8];
+       u8         fpga_device[0x18];
+
+       u8         register_file_ver[0x20];
+
+       u8         fpga_ctrl_modify[0x1];
+       u8         reserved_at_41[0x5];
+       u8         access_reg_query_mode[0x2];
+       u8         reserved_at_48[0x6];
+       u8         access_reg_modify_mode[0x2];
+       u8         reserved_at_50[0x10];
+
+       u8         reserved_at_60[0x20];
+
+       u8         image_version[0x20];
+
+       u8         image_date[0x20];
+
+       u8         image_time[0x20];
+
+       u8         shell_version[0x20];
+
+       u8         reserved_at_100[0x80];
+
+       struct mlx5_ifc_fpga_shell_caps_bits shell_caps;
+
+       u8         reserved_at_380[0x8];
+       u8         ieee_vendor_id[0x18];
+
+       u8         sandbox_product_version[0x10];
+       u8         sandbox_product_id[0x10];
+
+       u8         sandbox_basic_caps[0x20];
+
+       u8         reserved_at_3e0[0x10];
+       u8         sandbox_extended_caps_len[0x10];
+
+       u8         sandbox_extended_caps_addr[0x40];
+
+       u8         fpga_ddr_start_addr[0x40];
+
+       u8         fpga_cr_space_start_addr[0x40];
+
+       u8         fpga_ddr_size[0x20];
+
+       u8         fpga_cr_space_size[0x20];
+
+       u8         reserved_at_500[0x300];
+};
+
+enum {
+       MLX5_FPGA_CTRL_OPERATION_LOAD                = 0x1,
+       MLX5_FPGA_CTRL_OPERATION_RESET               = 0x2,
+       MLX5_FPGA_CTRL_OPERATION_FLASH_SELECT        = 0x3,
+       MLX5_FPGA_CTRL_OPERATION_SANDBOX_BYPASS_ON   = 0x4,
+       MLX5_FPGA_CTRL_OPERATION_SANDBOX_BYPASS_OFF  = 0x5,
+       MLX5_FPGA_CTRL_OPERATION_RESET_SANDBOX       = 0x6,
+};
+
+struct mlx5_ifc_fpga_ctrl_bits {
+       u8         reserved_at_0[0x8];
+       u8         operation[0x8];
+       u8         reserved_at_10[0x8];
+       u8         status[0x8];
+
+       u8         reserved_at_20[0x8];
+       u8         flash_select_admin[0x8];
+       u8         reserved_at_30[0x8];
+       u8         flash_select_oper[0x8];
+
+       u8         reserved_at_40[0x40];
+};
+
+enum {
+       MLX5_FPGA_ERROR_EVENT_SYNDROME_CORRUPTED_DDR        = 0x1,
+       MLX5_FPGA_ERROR_EVENT_SYNDROME_FLASH_TIMEOUT        = 0x2,
+       MLX5_FPGA_ERROR_EVENT_SYNDROME_INTERNAL_LINK_ERROR  = 0x3,
+       MLX5_FPGA_ERROR_EVENT_SYNDROME_WATCHDOG_FAILURE     = 0x4,
+       MLX5_FPGA_ERROR_EVENT_SYNDROME_I2C_FAILURE          = 0x5,
+       MLX5_FPGA_ERROR_EVENT_SYNDROME_IMAGE_CHANGED        = 0x6,
+       MLX5_FPGA_ERROR_EVENT_SYNDROME_TEMPERATURE_CRITICAL = 0x7,
+};
+
+struct mlx5_ifc_fpga_error_event_bits {
+       u8         reserved_at_0[0x40];
+
+       u8         reserved_at_40[0x18];
+       u8         syndrome[0x8];
+
+       u8         reserved_at_60[0x80];
+};
+
+#define MLX5_FPGA_ACCESS_REG_SIZE_MAX 64
+
+struct mlx5_ifc_fpga_access_reg_bits {
+       u8         reserved_at_0[0x20];
+
+       u8         reserved_at_20[0x10];
+       u8         size[0x10];
+
+       u8         address[0x40];
+
+       u8         data[0][0x8];
+};
+
+enum mlx5_ifc_fpga_qp_state {
+       MLX5_FPGA_QPC_STATE_INIT    = 0x0,
+       MLX5_FPGA_QPC_STATE_ACTIVE  = 0x1,
+       MLX5_FPGA_QPC_STATE_ERROR   = 0x2,
+};
+
+enum mlx5_ifc_fpga_qp_type {
+       MLX5_FPGA_QPC_QP_TYPE_SHELL_QP    = 0x0,
+       MLX5_FPGA_QPC_QP_TYPE_SANDBOX_QP  = 0x1,

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to