forked from Minki/linux
crypto: hisilicon/hpre - Optimize finding hpre device process
Optimize finding hpre device process according to priority of numa distance. Signed-off-by: Hui Tang <tanghui20@huawei.com> Signed-off-by: Shukun Tan <tanshukun1@huawei.com> Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com> Reviewed-by: Zaibo Xu <xuzaibo@huawei.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
18f1ab3f74
commit
0f4146fadc
@ -46,7 +46,6 @@ struct hpre_debug {
|
|||||||
|
|
||||||
struct hpre {
|
struct hpre {
|
||||||
struct hisi_qm qm;
|
struct hisi_qm qm;
|
||||||
struct list_head list;
|
|
||||||
struct hpre_debug debug;
|
struct hpre_debug debug;
|
||||||
u32 num_vfs;
|
u32 num_vfs;
|
||||||
unsigned long status;
|
unsigned long status;
|
||||||
@ -76,7 +75,7 @@ struct hpre_sqe {
|
|||||||
__le32 rsvd1[_HPRE_SQE_ALIGN_EXT];
|
__le32 rsvd1[_HPRE_SQE_ALIGN_EXT];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hpre *hpre_find_device(int node);
|
struct hisi_qp *hpre_create_qp(void);
|
||||||
int hpre_algs_register(void);
|
int hpre_algs_register(void);
|
||||||
void hpre_algs_unregister(void);
|
void hpre_algs_unregister(void);
|
||||||
|
|
||||||
|
@ -147,26 +147,18 @@ static void hpre_rm_req_from_ctx(struct hpre_asym_request *hpre_req)
|
|||||||
static struct hisi_qp *hpre_get_qp_and_start(void)
|
static struct hisi_qp *hpre_get_qp_and_start(void)
|
||||||
{
|
{
|
||||||
struct hisi_qp *qp;
|
struct hisi_qp *qp;
|
||||||
struct hpre *hpre;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* find the proper hpre device, which is near the current CPU core */
|
qp = hpre_create_qp();
|
||||||
hpre = hpre_find_device(cpu_to_node(smp_processor_id()));
|
if (!qp) {
|
||||||
if (!hpre) {
|
pr_err("Can not create hpre qp!\n");
|
||||||
pr_err("Can not find proper hpre device!\n");
|
|
||||||
return ERR_PTR(-ENODEV);
|
|
||||||
}
|
|
||||||
|
|
||||||
qp = hisi_qm_create_qp(&hpre->qm, 0);
|
|
||||||
if (IS_ERR(qp)) {
|
|
||||||
pci_err(hpre->qm.pdev, "Can not create qp!\n");
|
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = hisi_qm_start_qp(qp, 0);
|
ret = hisi_qm_start_qp(qp, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
hisi_qm_release_qp(qp);
|
hisi_qm_free_qps(&qp, 1);
|
||||||
pci_err(hpre->qm.pdev, "Can not start qp!\n");
|
pci_err(qp->qm->pdev, "Can not start qp!\n");
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +330,7 @@ static void hpre_ctx_clear(struct hpre_ctx *ctx, bool is_clear_all)
|
|||||||
if (is_clear_all) {
|
if (is_clear_all) {
|
||||||
idr_destroy(&ctx->req_idr);
|
idr_destroy(&ctx->req_idr);
|
||||||
kfree(ctx->req_list);
|
kfree(ctx->req_list);
|
||||||
hisi_qm_release_qp(ctx->qp);
|
hisi_qm_free_qps(&ctx->qp, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->crt_g2_mode = false;
|
ctx->crt_g2_mode = false;
|
||||||
|
@ -82,8 +82,7 @@
|
|||||||
|
|
||||||
#define HPRE_VIA_MSI_DSM 1
|
#define HPRE_VIA_MSI_DSM 1
|
||||||
|
|
||||||
static LIST_HEAD(hpre_list);
|
static struct hisi_qm_list hpre_devices;
|
||||||
static DEFINE_MUTEX(hpre_list_lock);
|
|
||||||
static const char hpre_name[] = "hisi_hpre";
|
static const char hpre_name[] = "hisi_hpre";
|
||||||
static struct dentry *hpre_debugfs_root;
|
static struct dentry *hpre_debugfs_root;
|
||||||
static const struct pci_device_id hpre_dev_ids[] = {
|
static const struct pci_device_id hpre_dev_ids[] = {
|
||||||
@ -196,43 +195,17 @@ static u32 hpre_pf_q_num = HPRE_PF_DEF_Q_NUM;
|
|||||||
module_param_cb(hpre_pf_q_num, &hpre_pf_q_num_ops, &hpre_pf_q_num, 0444);
|
module_param_cb(hpre_pf_q_num, &hpre_pf_q_num_ops, &hpre_pf_q_num, 0444);
|
||||||
MODULE_PARM_DESC(hpre_pf_q_num, "Number of queues in PF of CS(1-1024)");
|
MODULE_PARM_DESC(hpre_pf_q_num, "Number of queues in PF of CS(1-1024)");
|
||||||
|
|
||||||
static inline void hpre_add_to_list(struct hpre *hpre)
|
struct hisi_qp *hpre_create_qp(void)
|
||||||
{
|
{
|
||||||
mutex_lock(&hpre_list_lock);
|
int node = cpu_to_node(smp_processor_id());
|
||||||
list_add_tail(&hpre->list, &hpre_list);
|
struct hisi_qp *qp = NULL;
|
||||||
mutex_unlock(&hpre_list_lock);
|
int ret;
|
||||||
}
|
|
||||||
|
|
||||||
static inline void hpre_remove_from_list(struct hpre *hpre)
|
ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, 0, node, &qp);
|
||||||
{
|
if (!ret)
|
||||||
mutex_lock(&hpre_list_lock);
|
return qp;
|
||||||
list_del(&hpre->list);
|
|
||||||
mutex_unlock(&hpre_list_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct hpre *hpre_find_device(int node)
|
return NULL;
|
||||||
{
|
|
||||||
struct hpre *hpre, *ret = NULL;
|
|
||||||
int min_distance = INT_MAX;
|
|
||||||
struct device *dev;
|
|
||||||
int dev_node = 0;
|
|
||||||
|
|
||||||
mutex_lock(&hpre_list_lock);
|
|
||||||
list_for_each_entry(hpre, &hpre_list, list) {
|
|
||||||
dev = &hpre->qm.pdev->dev;
|
|
||||||
#ifdef CONFIG_NUMA
|
|
||||||
dev_node = dev->numa_node;
|
|
||||||
if (dev_node < 0)
|
|
||||||
dev_node = 0;
|
|
||||||
#endif
|
|
||||||
if (node_distance(dev_node, node) < min_distance) {
|
|
||||||
ret = hpre;
|
|
||||||
min_distance = node_distance(dev_node, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mutex_unlock(&hpre_list_lock);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hpre_cfg_by_dsm(struct hisi_qm *qm)
|
static int hpre_cfg_by_dsm(struct hisi_qm *qm)
|
||||||
@ -799,17 +772,17 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|||||||
if (ret)
|
if (ret)
|
||||||
dev_warn(&pdev->dev, "init debugfs fail!\n");
|
dev_warn(&pdev->dev, "init debugfs fail!\n");
|
||||||
|
|
||||||
hpre_add_to_list(hpre);
|
hisi_qm_add_to_list(qm, &hpre_devices);
|
||||||
|
|
||||||
ret = hpre_algs_register();
|
ret = hpre_algs_register();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
hpre_remove_from_list(hpre);
|
|
||||||
pci_err(pdev, "fail to register algs to crypto!\n");
|
pci_err(pdev, "fail to register algs to crypto!\n");
|
||||||
goto err_with_qm_start;
|
goto err_with_qm_start;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_with_qm_start:
|
err_with_qm_start:
|
||||||
|
hisi_qm_del_from_list(qm, &hpre_devices);
|
||||||
hisi_qm_stop(qm);
|
hisi_qm_stop(qm);
|
||||||
|
|
||||||
err_with_err_init:
|
err_with_err_init:
|
||||||
@ -929,7 +902,7 @@ static void hpre_remove(struct pci_dev *pdev)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
hpre_algs_unregister();
|
hpre_algs_unregister();
|
||||||
hpre_remove_from_list(hpre);
|
hisi_qm_del_from_list(qm, &hpre_devices);
|
||||||
if (qm->fun_type == QM_HW_PF && hpre->num_vfs != 0) {
|
if (qm->fun_type == QM_HW_PF && hpre->num_vfs != 0) {
|
||||||
ret = hpre_sriov_disable(pdev);
|
ret = hpre_sriov_disable(pdev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -979,6 +952,7 @@ static int __init hpre_init(void)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
hisi_qm_init_list(&hpre_devices);
|
||||||
hpre_register_debugfs();
|
hpre_register_debugfs();
|
||||||
|
|
||||||
ret = pci_register_driver(&hpre_pci_driver);
|
ret = pci_register_driver(&hpre_pci_driver);
|
||||||
|
Loading…
Reference in New Issue
Block a user