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 MODULE_DEPEND(mlx5fpga_tools, linuxkpi, 1, 1, 1);
40 MODULE_DEPEND(mlx5fpga_tools, mlx5, 1, 1, 1);
41 MODULE_DEPEND(mlx5fpga_tools, mlx5fpga, 1, 1, 1);
42 MODULE_VERSION(mlx5fpga_tools, 1);
44 static void mlx5_fpga_tools_create(struct mlx5_fpga_device *fdev);
45 static int mlx5_fpga_tools_add(struct mlx5_fpga_device *fdev, u32 vid, u16 pid);
46 static void mlx5_fpga_tools_remove(struct mlx5_fpga_device *fdev);
47 static void mlx5_fpga_tools_destroy(struct mlx5_fpga_device *fdev);
49 struct mlx5_fpga_tools_dev *mlx5_fpga_tools_alloc(struct mlx5_fpga_device *fdev);
50 void mlx5_fpga_tools_free(struct mlx5_fpga_tools_dev *tdev);
52 static struct mlx5_fpga_client mlx5_fpga_tools_client = {
53 .name = MLX5_FPGA_TOOLS_DRIVER_NAME,
54 .create = mlx5_fpga_tools_create,
55 .add = mlx5_fpga_tools_add,
56 .remove = mlx5_fpga_tools_remove,
57 .destroy = mlx5_fpga_tools_destroy,
60 struct mlx5_fpga_tools_dev *mlx5_fpga_tools_alloc(struct mlx5_fpga_device *fdev)
63 struct mlx5_fpga_tools_dev *tdev;
65 tdev = kzalloc(sizeof(*tdev), GFP_KERNEL);
70 sx_init(&tdev->lock, "mlx5fpgat");
71 ret = mlx5_fpga_tools_char_add_one(tdev);
85 void mlx5_fpga_tools_free(struct mlx5_fpga_tools_dev *tdev)
87 mlx5_fpga_tools_char_remove_one(tdev);
91 static void mlx5_fpga_tools_create(struct mlx5_fpga_device *fdev)
93 struct mlx5_fpga_tools_dev *dev = NULL;
95 dev_dbg(mlx5_fpga_dev(fdev), "tools_create\n");
97 dev = mlx5_fpga_tools_alloc(fdev);
101 mlx5_fpga_client_data_set(fdev, &mlx5_fpga_tools_client, dev);
104 static int mlx5_fpga_tools_add(struct mlx5_fpga_device *fdev, u32 vid, u16 pid)
109 static void mlx5_fpga_tools_remove(struct mlx5_fpga_device *fdev)
113 static void mlx5_fpga_tools_destroy(struct mlx5_fpga_device *fdev)
115 struct mlx5_fpga_tools_dev *dev;
117 dev_dbg(mlx5_fpga_dev(fdev), "tools_destroy\n");
119 dev = mlx5_fpga_client_data_get(fdev, &mlx5_fpga_tools_client);
121 mlx5_fpga_tools_free(dev);
124 static int __init mlx5_fpga_tools_init(void)
126 int ret = mlx5_fpga_tools_char_init();
130 mlx5_fpga_client_register(&mlx5_fpga_tools_client);
134 static void __exit mlx5_fpga_tools_exit(void)
136 mlx5_fpga_client_unregister(&mlx5_fpga_tools_client);
137 mlx5_fpga_tools_char_deinit();
140 module_init_order(mlx5_fpga_tools_init, SI_ORDER_SECOND);
141 module_exit_order(mlx5_fpga_tools_exit, SI_ORDER_SECOND);