172 lines
4.8 KiB
C
172 lines
4.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2023, Jaguar Micro. 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.
|
|
*/
|
|
|
|
#include <linux/pci.h>
|
|
#include <linux/vdpa.h>
|
|
#include "crete_vdpa_dev.h"
|
|
#define CRETE_VDPA_DRV_DESCRIPTION "JaguarMicro/CRETE VDPA VF Device Driver"
|
|
#define CRETE_VDPA_AUX_DEV_NAME "crete_core.vnet"
|
|
#define CRETE_VDPA_DRV_NAME "crete_vnet"
|
|
|
|
static int crete_vdpa_probe(struct auxiliary_device *adev,
|
|
const struct auxiliary_device_id *id)
|
|
{
|
|
struct crete_aux_dev *cadev =
|
|
container_of(adev, struct crete_aux_dev, adev);
|
|
struct crete_core_dev *core_dev = cadev->core_dev;
|
|
struct pci_dev *pdev = core_dev->pdev;
|
|
struct device *dev = &pdev->dev;
|
|
struct crete_vdpa_mgmtdev *cvm;
|
|
int ret;
|
|
#if defined(HAVE_VDPA_MGMTDEV_OPS)
|
|
#else
|
|
struct vdpa_dev_set_config vdsc;
|
|
#endif
|
|
|
|
ret = crete_vdpa_set_device_type(core_dev);
|
|
if (ret) {
|
|
dev_err(dev,
|
|
"Failed to alloc memory for the vDPA management device\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = crete_vdpa_set_hwstatus(core_dev, CRETE_NET_DEV_STARTUP, dev);
|
|
if (ret) {
|
|
dev_err(dev, "set net dev status failed\n");
|
|
return -EINVAL;
|
|
}
|
|
cvm = kzalloc(sizeof(struct crete_vdpa_mgmtdev), GFP_KERNEL);
|
|
if (!cvm)
|
|
return -ENOMEM;
|
|
cvm->cdev = core_dev;
|
|
ret = crete_vdpa_get_mgmt_info(cvm);
|
|
if (ret) {
|
|
dev_err(dev, "Failed to set vDPA management\n");
|
|
goto err;
|
|
}
|
|
dev_set_drvdata(&adev->dev, cvm);
|
|
|
|
#if defined(HAVE_VDPA_MGMTDEV_OPS)
|
|
ret = vdpa_mgmtdev_register(&cvm->mdev);
|
|
if (ret) {
|
|
dev_err(dev,
|
|
"Failed to initialize the management interfaces\n");
|
|
goto err;
|
|
}
|
|
#else
|
|
memset(&vdsc, 0, sizeof(struct vdpa_dev_set_config));
|
|
ret = crete_vdpa_dev_add(&cvm->mdev, "NULL", &vdsc);
|
|
if (ret) {
|
|
dev_err(dev,
|
|
"Failed to add vdpa device ret:%d\n",ret);
|
|
goto err_add;
|
|
}
|
|
#endif
|
|
|
|
//crete_vdpa_debugfs_add_dev(cvm);
|
|
//crete_vdpa_debugfs_add_hcap(cvm);
|
|
return 0;
|
|
err_add:
|
|
dev_set_drvdata(&adev->dev, NULL);
|
|
err:
|
|
kfree(cvm);
|
|
return ret;
|
|
}
|
|
|
|
static void crete_vdpa_remove(struct auxiliary_device *adev)
|
|
{
|
|
struct crete_vdpa_mgmtdev *crete_mgmt_dev;
|
|
struct device *dev = &adev->dev;
|
|
struct crete_adapter *adapter;
|
|
struct vdpa_device *vdpa_dev;
|
|
|
|
crete_mgmt_dev = dev_get_drvdata(&adev->dev);
|
|
|
|
dev_info(dev, "crete vdpa remove\n");
|
|
#if defined(HAVE_VDPA_MGMTDEV_OPS)
|
|
vdpa_mgmtdev_unregister(&crete_mgmt_dev->mdev);
|
|
#else
|
|
adapter = crete_mgmt_dev->adapter;
|
|
vdpa_dev = &adapter->vdpa;
|
|
crete_vdpa_dev_del(&crete_mgmt_dev->mdev, vdpa_dev);
|
|
crete_mgmt_dev->adapter = NULL;
|
|
// crete_vdpa_debugfs_del_vdpadev(crete_mgmt_dev);
|
|
kfree(crete_mgmt_dev);
|
|
dev_set_drvdata(&adev->dev, NULL);
|
|
#endif
|
|
|
|
}
|
|
|
|
static const struct auxiliary_device_id crete_vdpa_id_table[] = {
|
|
{.name = CRETE_VDPA_AUX_DEV_NAME,},
|
|
{},
|
|
};
|
|
|
|
static struct auxiliary_driver crete_vdpa_driver = {
|
|
.name = CRETE_VDPA_DRV_NAME,
|
|
.probe = crete_vdpa_probe,
|
|
.remove = crete_vdpa_remove,
|
|
.id_table = crete_vdpa_id_table,
|
|
};
|
|
|
|
static void __exit crete_vdpa_cleanup(void)
|
|
{
|
|
auxiliary_driver_unregister(&crete_vdpa_driver);
|
|
|
|
// crete_vnet_debugfs_destroy();
|
|
}
|
|
|
|
module_exit(crete_vdpa_cleanup);
|
|
|
|
static int __init crete_vdpa_init(void)
|
|
{
|
|
int err;
|
|
|
|
// crete_vnet_debugfs_create();
|
|
err = auxiliary_driver_register(&crete_vdpa_driver);
|
|
if (err) {
|
|
pr_err("%s: aux driver register failed: %pe\n",
|
|
CRETE_VDPA_DRV_NAME, ERR_PTR(err));
|
|
//crete_vnet_debugfs_destroy();
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
module_init(crete_vdpa_init);
|
|
|
|
MODULE_DESCRIPTION(CRETE_VDPA_DRV_DESCRIPTION);
|
|
MODULE_AUTHOR("jaguarmicro.com");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_VERSION("3.1.1");
|