Loading drivers/crypto/msm/compat_qcedev.h +13 −0 Original line number Diff line number Diff line /* * Copyright (c) 2014, 2017 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #ifndef _UAPI_COMPAT_QCEDEV__H #define _UAPI_COMPAT_QCEDEV__H Loading drivers/crypto/msm/qce.h +6 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,12 @@ /* Maximum Nonce bytes */ #define MAX_NONCE 16 /* Crypto clock control flags */ #define QCE_CLK_ENABLE_FIRST 1 #define QCE_BW_REQUEST_FIRST 2 #define QCE_CLK_DISABLE_FIRST 3 #define QCE_BW_REQUEST_RESET_FIRST 4 typedef void (*qce_comp_func_ptr_t)(void *areq, unsigned char *icv, unsigned char *iv, int ret); Loading drivers/crypto/msm/qcedev.c +139 −94 Original line number Diff line number Diff line Loading @@ -58,55 +58,120 @@ static uint8_t _std_init_vector_sha256_uint8[] = { static DEFINE_MUTEX(send_cmd_lock); static DEFINE_MUTEX(qcedev_sent_bw_req); static void qcedev_ce_high_bw_req(struct qcedev_control *podev, bool high_bw_req) static int qcedev_control_clocks(struct qcedev_control *podev, bool enable) { unsigned int control_flag; int ret = 0; mutex_lock(&qcedev_sent_bw_req); if (high_bw_req) { if (podev->high_bw_req_count == 0) { if (podev->ce_support.req_bw_before_clk) { if (enable) control_flag = QCE_BW_REQUEST_FIRST; else control_flag = QCE_CLK_DISABLE_FIRST; } else { if (enable) control_flag = QCE_CLK_ENABLE_FIRST; else control_flag = QCE_BW_REQUEST_RESET_FIRST; } switch (control_flag) { case QCE_CLK_ENABLE_FIRST: ret = qce_enable_clk(podev->qce); if (ret) { pr_err("%s Unable enable clk\n", __func__); mutex_unlock(&qcedev_sent_bw_req); return; return ret; } ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) { pr_err("%s Unable to set to high bandwidth\n", __func__); pr_err("%s Unable to set high bw\n", __func__); ret = qce_disable_clk(podev->qce); mutex_unlock(&qcedev_sent_bw_req); return; if (ret) pr_err("%s Unable disable clk\n", __func__); return ret; } break; case QCE_BW_REQUEST_FIRST: ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) { pr_err("%s Unable to set high bw\n", __func__); return ret; } podev->high_bw_req_count++; } else { if (podev->high_bw_req_count == 1) { ret = qce_enable_clk(podev->qce); if (ret) { pr_err("%s Unable enable clk\n", __func__); ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) pr_err("%s Unable to set low bw\n", __func__); return ret; } break; case QCE_CLK_DISABLE_FIRST: ret = qce_disable_clk(podev->qce); if (ret) { pr_err("%s Unable to set to low bandwidth\n", __func__); mutex_unlock(&qcedev_sent_bw_req); return; pr_err("%s Unable to disable clk\n", __func__); return ret; } ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) { pr_err("%s Unable to set low bw\n", __func__); ret = qce_enable_clk(podev->qce); if (ret) pr_err("%s Unable enable clk\n", __func__); return ret; } break; case QCE_BW_REQUEST_RESET_FIRST: ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) { pr_err("%s Unable to set low bw\n", __func__); return ret; } ret = qce_disable_clk(podev->qce); if (ret) { pr_err("%s Unable disable clk\n", __func__); pr_err("%s Unable to disable clk\n", __func__); ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) pr_err("%s Unable to set to high bandwidth\n", __func__); mutex_unlock(&qcedev_sent_bw_req); return; pr_err("%s Unable to set high bw\n", __func__); return ret; } break; default: return -ENOENT; } return 0; } static void qcedev_ce_high_bw_req(struct qcedev_control *podev, bool high_bw_req) { int ret = 0; mutex_lock(&qcedev_sent_bw_req); if (high_bw_req) { if (podev->high_bw_req_count == 0) { ret = qcedev_control_clocks(podev, true); if (ret) goto exit_unlock_mutex; } podev->high_bw_req_count++; } else { if (podev->high_bw_req_count == 1) { ret = qcedev_control_clocks(podev, false); if (ret) goto exit_unlock_mutex; } podev->high_bw_req_count--; } exit_unlock_mutex: mutex_unlock(&qcedev_sent_bw_req); } Loading Loading @@ -1767,32 +1832,47 @@ static int qcedev_probe(struct platform_device *pdev) tasklet_init(&podev->done_tasklet, req_done, (unsigned long)podev); /* open qce */ podev->platform_support.bus_scale_table = (struct msm_bus_scale_pdata *) msm_bus_cl_get_pdata(pdev); if (!podev->platform_support.bus_scale_table) { pr_err("bus_scale_table is NULL\n"); return -ENODATA; } podev->bus_scale_handle = msm_bus_scale_register_client( (struct msm_bus_scale_pdata *) podev->platform_support.bus_scale_table); if (!podev->bus_scale_handle) { pr_err("%s not able to get bus scale\n", __func__); return -ENOMEM; } rc = msm_bus_scale_client_update_request(podev->bus_scale_handle, 1); if (rc) { pr_err("%s Unable to set to high bandwidth\n", __func__); goto exit_unregister_bus_scale; } handle = qce_open(pdev, &rc); if (handle == NULL) { platform_set_drvdata(pdev, NULL); return rc; rc = -ENODEV; goto exit_scale_busbandwidth; } rc = msm_bus_scale_client_update_request(podev->bus_scale_handle, 0); if (rc) { pr_err("%s Unable to set to low bandwidth\n", __func__); goto exit_qce_close; } podev->qce = handle; podev->pdev = pdev; platform_set_drvdata(pdev, podev); rc = misc_register(&podev->miscdevice); qce_hw_support(podev->qce, &podev->ce_support); if (podev->ce_support.bam) { podev->platform_support.ce_shared = 0; podev->platform_support.shared_ce_resource = 0; podev->platform_support.hw_key_support = podev->ce_support.hw_key; podev->platform_support.bus_scale_table = NULL; podev->platform_support.sha_hmac = 1; podev->platform_support.bus_scale_table = (struct msm_bus_scale_pdata *) msm_bus_cl_get_pdata(pdev); if (!podev->platform_support.bus_scale_table) pr_err("bus_scale_table is NULL\n"); } else { platform_support = (struct msm_ce_hw_support *)pdev->dev.platform_data; Loading @@ -1801,35 +1881,27 @@ static int qcedev_probe(struct platform_device *pdev) platform_support->shared_ce_resource; podev->platform_support.hw_key_support = platform_support->hw_key_support; podev->platform_support.bus_scale_table = platform_support->bus_scale_table; podev->platform_support.sha_hmac = platform_support->sha_hmac; } if (podev->platform_support.bus_scale_table != NULL) { podev->bus_scale_handle = msm_bus_scale_register_client( (struct msm_bus_scale_pdata *) podev->platform_support.bus_scale_table); if (!podev->bus_scale_handle) { pr_err("%s not able to get bus scale\n", __func__); rc = -ENOMEM; goto err; } } rc = misc_register(&podev->miscdevice); if (rc >= 0) return 0; if (podev->platform_support.bus_scale_table != NULL) msm_bus_scale_unregister_client(podev->bus_scale_handle); err: misc_deregister(&podev->miscdevice); exit_qce_close: if (handle) qce_close(handle); exit_scale_busbandwidth: msm_bus_scale_client_update_request(podev->bus_scale_handle, 0); exit_unregister_bus_scale: if (podev->platform_support.bus_scale_table != NULL) msm_bus_scale_unregister_client(podev->bus_scale_handle); platform_set_drvdata(pdev, NULL); podev->qce = NULL; podev->pdev = NULL; podev->qce = NULL; return rc; }; Loading Loading @@ -1864,24 +1936,10 @@ static int qcedev_suspend(struct platform_device *pdev, pm_message_t state) mutex_lock(&qcedev_sent_bw_req); if (podev->high_bw_req_count) { ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) { pr_err("%s Unable to set to low bandwidth\n", __func__); goto suspend_exit; } ret = qce_disable_clk(podev->qce); if (ret) { pr_err("%s Unable disable clk\n", __func__); ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); ret = qcedev_control_clocks(podev, false); if (ret) pr_err("%s Unable to set to high bandwidth\n", __func__); goto suspend_exit; } } suspend_exit: mutex_unlock(&qcedev_sent_bw_req); Loading @@ -1900,23 +1958,10 @@ static int qcedev_resume(struct platform_device *pdev) mutex_lock(&qcedev_sent_bw_req); if (podev->high_bw_req_count) { ret = qce_enable_clk(podev->qce); if (ret) { pr_err("%s Unable enable clk\n", __func__); goto resume_exit; } ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) { pr_err("%s Unable to set to high bandwidth\n", __func__); ret = qce_disable_clk(podev->qce); ret = qcedev_control_clocks(podev, true); if (ret) pr_err("%s Unable enable clk\n", __func__); goto resume_exit; } } resume_exit: mutex_unlock(&qcedev_sent_bw_req); Loading Loading
drivers/crypto/msm/compat_qcedev.h +13 −0 Original line number Diff line number Diff line /* * Copyright (c) 2014, 2017 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #ifndef _UAPI_COMPAT_QCEDEV__H #define _UAPI_COMPAT_QCEDEV__H Loading
drivers/crypto/msm/qce.h +6 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,12 @@ /* Maximum Nonce bytes */ #define MAX_NONCE 16 /* Crypto clock control flags */ #define QCE_CLK_ENABLE_FIRST 1 #define QCE_BW_REQUEST_FIRST 2 #define QCE_CLK_DISABLE_FIRST 3 #define QCE_BW_REQUEST_RESET_FIRST 4 typedef void (*qce_comp_func_ptr_t)(void *areq, unsigned char *icv, unsigned char *iv, int ret); Loading
drivers/crypto/msm/qcedev.c +139 −94 Original line number Diff line number Diff line Loading @@ -58,55 +58,120 @@ static uint8_t _std_init_vector_sha256_uint8[] = { static DEFINE_MUTEX(send_cmd_lock); static DEFINE_MUTEX(qcedev_sent_bw_req); static void qcedev_ce_high_bw_req(struct qcedev_control *podev, bool high_bw_req) static int qcedev_control_clocks(struct qcedev_control *podev, bool enable) { unsigned int control_flag; int ret = 0; mutex_lock(&qcedev_sent_bw_req); if (high_bw_req) { if (podev->high_bw_req_count == 0) { if (podev->ce_support.req_bw_before_clk) { if (enable) control_flag = QCE_BW_REQUEST_FIRST; else control_flag = QCE_CLK_DISABLE_FIRST; } else { if (enable) control_flag = QCE_CLK_ENABLE_FIRST; else control_flag = QCE_BW_REQUEST_RESET_FIRST; } switch (control_flag) { case QCE_CLK_ENABLE_FIRST: ret = qce_enable_clk(podev->qce); if (ret) { pr_err("%s Unable enable clk\n", __func__); mutex_unlock(&qcedev_sent_bw_req); return; return ret; } ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) { pr_err("%s Unable to set to high bandwidth\n", __func__); pr_err("%s Unable to set high bw\n", __func__); ret = qce_disable_clk(podev->qce); mutex_unlock(&qcedev_sent_bw_req); return; if (ret) pr_err("%s Unable disable clk\n", __func__); return ret; } break; case QCE_BW_REQUEST_FIRST: ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) { pr_err("%s Unable to set high bw\n", __func__); return ret; } podev->high_bw_req_count++; } else { if (podev->high_bw_req_count == 1) { ret = qce_enable_clk(podev->qce); if (ret) { pr_err("%s Unable enable clk\n", __func__); ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) pr_err("%s Unable to set low bw\n", __func__); return ret; } break; case QCE_CLK_DISABLE_FIRST: ret = qce_disable_clk(podev->qce); if (ret) { pr_err("%s Unable to set to low bandwidth\n", __func__); mutex_unlock(&qcedev_sent_bw_req); return; pr_err("%s Unable to disable clk\n", __func__); return ret; } ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) { pr_err("%s Unable to set low bw\n", __func__); ret = qce_enable_clk(podev->qce); if (ret) pr_err("%s Unable enable clk\n", __func__); return ret; } break; case QCE_BW_REQUEST_RESET_FIRST: ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) { pr_err("%s Unable to set low bw\n", __func__); return ret; } ret = qce_disable_clk(podev->qce); if (ret) { pr_err("%s Unable disable clk\n", __func__); pr_err("%s Unable to disable clk\n", __func__); ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) pr_err("%s Unable to set to high bandwidth\n", __func__); mutex_unlock(&qcedev_sent_bw_req); return; pr_err("%s Unable to set high bw\n", __func__); return ret; } break; default: return -ENOENT; } return 0; } static void qcedev_ce_high_bw_req(struct qcedev_control *podev, bool high_bw_req) { int ret = 0; mutex_lock(&qcedev_sent_bw_req); if (high_bw_req) { if (podev->high_bw_req_count == 0) { ret = qcedev_control_clocks(podev, true); if (ret) goto exit_unlock_mutex; } podev->high_bw_req_count++; } else { if (podev->high_bw_req_count == 1) { ret = qcedev_control_clocks(podev, false); if (ret) goto exit_unlock_mutex; } podev->high_bw_req_count--; } exit_unlock_mutex: mutex_unlock(&qcedev_sent_bw_req); } Loading Loading @@ -1767,32 +1832,47 @@ static int qcedev_probe(struct platform_device *pdev) tasklet_init(&podev->done_tasklet, req_done, (unsigned long)podev); /* open qce */ podev->platform_support.bus_scale_table = (struct msm_bus_scale_pdata *) msm_bus_cl_get_pdata(pdev); if (!podev->platform_support.bus_scale_table) { pr_err("bus_scale_table is NULL\n"); return -ENODATA; } podev->bus_scale_handle = msm_bus_scale_register_client( (struct msm_bus_scale_pdata *) podev->platform_support.bus_scale_table); if (!podev->bus_scale_handle) { pr_err("%s not able to get bus scale\n", __func__); return -ENOMEM; } rc = msm_bus_scale_client_update_request(podev->bus_scale_handle, 1); if (rc) { pr_err("%s Unable to set to high bandwidth\n", __func__); goto exit_unregister_bus_scale; } handle = qce_open(pdev, &rc); if (handle == NULL) { platform_set_drvdata(pdev, NULL); return rc; rc = -ENODEV; goto exit_scale_busbandwidth; } rc = msm_bus_scale_client_update_request(podev->bus_scale_handle, 0); if (rc) { pr_err("%s Unable to set to low bandwidth\n", __func__); goto exit_qce_close; } podev->qce = handle; podev->pdev = pdev; platform_set_drvdata(pdev, podev); rc = misc_register(&podev->miscdevice); qce_hw_support(podev->qce, &podev->ce_support); if (podev->ce_support.bam) { podev->platform_support.ce_shared = 0; podev->platform_support.shared_ce_resource = 0; podev->platform_support.hw_key_support = podev->ce_support.hw_key; podev->platform_support.bus_scale_table = NULL; podev->platform_support.sha_hmac = 1; podev->platform_support.bus_scale_table = (struct msm_bus_scale_pdata *) msm_bus_cl_get_pdata(pdev); if (!podev->platform_support.bus_scale_table) pr_err("bus_scale_table is NULL\n"); } else { platform_support = (struct msm_ce_hw_support *)pdev->dev.platform_data; Loading @@ -1801,35 +1881,27 @@ static int qcedev_probe(struct platform_device *pdev) platform_support->shared_ce_resource; podev->platform_support.hw_key_support = platform_support->hw_key_support; podev->platform_support.bus_scale_table = platform_support->bus_scale_table; podev->platform_support.sha_hmac = platform_support->sha_hmac; } if (podev->platform_support.bus_scale_table != NULL) { podev->bus_scale_handle = msm_bus_scale_register_client( (struct msm_bus_scale_pdata *) podev->platform_support.bus_scale_table); if (!podev->bus_scale_handle) { pr_err("%s not able to get bus scale\n", __func__); rc = -ENOMEM; goto err; } } rc = misc_register(&podev->miscdevice); if (rc >= 0) return 0; if (podev->platform_support.bus_scale_table != NULL) msm_bus_scale_unregister_client(podev->bus_scale_handle); err: misc_deregister(&podev->miscdevice); exit_qce_close: if (handle) qce_close(handle); exit_scale_busbandwidth: msm_bus_scale_client_update_request(podev->bus_scale_handle, 0); exit_unregister_bus_scale: if (podev->platform_support.bus_scale_table != NULL) msm_bus_scale_unregister_client(podev->bus_scale_handle); platform_set_drvdata(pdev, NULL); podev->qce = NULL; podev->pdev = NULL; podev->qce = NULL; return rc; }; Loading Loading @@ -1864,24 +1936,10 @@ static int qcedev_suspend(struct platform_device *pdev, pm_message_t state) mutex_lock(&qcedev_sent_bw_req); if (podev->high_bw_req_count) { ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 0); if (ret) { pr_err("%s Unable to set to low bandwidth\n", __func__); goto suspend_exit; } ret = qce_disable_clk(podev->qce); if (ret) { pr_err("%s Unable disable clk\n", __func__); ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); ret = qcedev_control_clocks(podev, false); if (ret) pr_err("%s Unable to set to high bandwidth\n", __func__); goto suspend_exit; } } suspend_exit: mutex_unlock(&qcedev_sent_bw_req); Loading @@ -1900,23 +1958,10 @@ static int qcedev_resume(struct platform_device *pdev) mutex_lock(&qcedev_sent_bw_req); if (podev->high_bw_req_count) { ret = qce_enable_clk(podev->qce); if (ret) { pr_err("%s Unable enable clk\n", __func__); goto resume_exit; } ret = msm_bus_scale_client_update_request( podev->bus_scale_handle, 1); if (ret) { pr_err("%s Unable to set to high bandwidth\n", __func__); ret = qce_disable_clk(podev->qce); ret = qcedev_control_clocks(podev, true); if (ret) pr_err("%s Unable enable clk\n", __func__); goto resume_exit; } } resume_exit: mutex_unlock(&qcedev_sent_bw_req); Loading