2 * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <linux/module.h>
36 #include <dev/mlx5/mlx5_fpga_tools/tools.h>
37 #include <dev/mlx5/mlx5_fpga_tools/tools_char.h>
39 #if (__FreeBSD_version >= 1100000)
40 MODULE_DEPEND(mlx5fpga_tools, linuxkpi, 1, 1, 1);
42 MODULE_DEPEND(mlx5fpga_tools, mlx5, 1, 1, 1);
43 MODULE_DEPEND(mlx5fpga_tools, mlx5fpga, 1, 1, 1);
44 MODULE_VERSION(mlx5fpga_tools, 1);
46 static void mlx5_fpga_tools_create(struct mlx5_fpga_device *fdev);
47 static int mlx5_fpga_tools_add(struct mlx5_fpga_device *fdev, u32 vid, u16 pid);
48 static void mlx5_fpga_tools_remove(struct mlx5_fpga_device *fdev);
49 static void mlx5_fpga_tools_destroy(struct mlx5_fpga_device *fdev);
51 struct mlx5_fpga_tools_dev *mlx5_fpga_tools_alloc(struct mlx5_fpga_device *fdev);
52 void mlx5_fpga_tools_free(struct mlx5_fpga_tools_dev *tdev);
54 static struct mlx5_fpga_client mlx5_fpga_tools_client = {
55 .name = MLX5_FPGA_TOOLS_DRIVER_NAME,
56 .create = mlx5_fpga_tools_create,
57 .add = mlx5_fpga_tools_add,
58 .remove = mlx5_fpga_tools_remove,
59 .destroy = mlx5_fpga_tools_destroy,
62 struct mlx5_fpga_tools_dev *mlx5_fpga_tools_alloc(struct mlx5_fpga_device *fdev)
65 struct mlx5_fpga_tools_dev *tdev;
67 tdev = kzalloc(sizeof(*tdev), GFP_KERNEL);
72 sx_init(&tdev->lock, "mlx5fpgat");
73 ret = mlx5_fpga_tools_char_add_one(tdev);
87 void mlx5_fpga_tools_free(struct mlx5_fpga_tools_dev *tdev)
89 mlx5_fpga_tools_char_remove_one(tdev);
93 static void mlx5_fpga_tools_create(struct mlx5_fpga_device *fdev)
95 struct mlx5_fpga_tools_dev *dev = NULL;
97 dev_dbg(mlx5_fpga_dev(fdev), "tools_create\n");
99 dev = mlx5_fpga_tools_alloc(fdev);
103 mlx5_fpga_client_data_set(fdev, &mlx5_fpga_tools_client, dev);
106 static int mlx5_fpga_tools_add(struct mlx5_fpga_device *fdev, u32 vid, u16 pid)
111 static void mlx5_fpga_tools_remove(struct mlx5_fpga_device *fdev)
115 static void mlx5_fpga_tools_destroy(struct mlx5_fpga_device *fdev)
117 struct mlx5_fpga_tools_dev *dev;
119 dev_dbg(mlx5_fpga_dev(fdev), "tools_destroy\n");
121 dev = mlx5_fpga_client_data_get(fdev, &mlx5_fpga_tools_client);
123 mlx5_fpga_tools_free(dev);
126 static int __init mlx5_fpga_tools_init(void)
128 int ret = mlx5_fpga_tools_char_init();
132 mlx5_fpga_client_register(&mlx5_fpga_tools_client);
136 static void __exit mlx5_fpga_tools_exit(void)
138 mlx5_fpga_client_unregister(&mlx5_fpga_tools_client);
139 mlx5_fpga_tools_char_deinit();
142 module_init(mlx5_fpga_tools_init);
143 module_exit(mlx5_fpga_tools_exit);