Commit c6dc0609 authored by Herbert Xu's avatar Herbert Xu

Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

Merge the crypto tree to resolve conflict between caam changes.
parents 796b40c6 40c98cb5
...@@ -12,7 +12,8 @@ Required properties: ...@@ -12,7 +12,8 @@ Required properties:
- reg : Offset and length of the register set for the module - reg : Offset and length of the register set for the module
- interrupts : the interrupt number for the RNG module. - interrupts : the interrupt number for the RNG module.
Used for "ti,omap4-rng" and "inside-secure,safexcel-eip76" Used for "ti,omap4-rng" and "inside-secure,safexcel-eip76"
- clocks: the trng clock source - clocks: the trng clock source. Only mandatory for the
"inside-secure,safexcel-eip76" compatible.
Example: Example:
/* AM335x */ /* AM335x */
......
...@@ -286,8 +286,11 @@ static int init_crypt(struct skcipher_request *req, crypto_completion_t done) ...@@ -286,8 +286,11 @@ static int init_crypt(struct skcipher_request *req, crypto_completion_t done)
subreq->cryptlen = LRW_BUFFER_SIZE; subreq->cryptlen = LRW_BUFFER_SIZE;
if (req->cryptlen > LRW_BUFFER_SIZE) { if (req->cryptlen > LRW_BUFFER_SIZE) {
subreq->cryptlen = min(req->cryptlen, (unsigned)PAGE_SIZE); unsigned int n = min(req->cryptlen, (unsigned int)PAGE_SIZE);
rctx->ext = kmalloc(subreq->cryptlen, gfp);
rctx->ext = kmalloc(n, gfp);
if (rctx->ext)
subreq->cryptlen = n;
} }
rctx->src = req->src; rctx->src = req->src;
......
...@@ -230,8 +230,11 @@ static int init_crypt(struct skcipher_request *req, crypto_completion_t done) ...@@ -230,8 +230,11 @@ static int init_crypt(struct skcipher_request *req, crypto_completion_t done)
subreq->cryptlen = XTS_BUFFER_SIZE; subreq->cryptlen = XTS_BUFFER_SIZE;
if (req->cryptlen > XTS_BUFFER_SIZE) { if (req->cryptlen > XTS_BUFFER_SIZE) {
subreq->cryptlen = min(req->cryptlen, (unsigned)PAGE_SIZE); unsigned int n = min(req->cryptlen, (unsigned int)PAGE_SIZE);
rctx->ext = kmalloc(subreq->cryptlen, gfp);
rctx->ext = kmalloc(n, gfp);
if (rctx->ext)
subreq->cryptlen = n;
} }
rctx->src = req->src; rctx->src = req->src;
......
...@@ -55,6 +55,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl); ...@@ -55,6 +55,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
struct amd768_priv { struct amd768_priv {
void __iomem *iobase; void __iomem *iobase;
struct pci_dev *pcidev; struct pci_dev *pcidev;
u32 pmbase;
}; };
static int amd_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) static int amd_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
...@@ -148,33 +149,58 @@ static int __init mod_init(void) ...@@ -148,33 +149,58 @@ static int __init mod_init(void)
if (pmbase == 0) if (pmbase == 0)
return -EIO; return -EIO;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
if (!devm_request_region(&pdev->dev, pmbase + PMBASE_OFFSET, if (!request_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE, DRV_NAME)) {
PMBASE_SIZE, DRV_NAME)) {
dev_err(&pdev->dev, DRV_NAME " region 0x%x already in use!\n", dev_err(&pdev->dev, DRV_NAME " region 0x%x already in use!\n",
pmbase + 0xF0); pmbase + 0xF0);
return -EBUSY; err = -EBUSY;
goto out;
} }
priv->iobase = devm_ioport_map(&pdev->dev, pmbase + PMBASE_OFFSET, priv->iobase = ioport_map(pmbase + PMBASE_OFFSET, PMBASE_SIZE);
PMBASE_SIZE);
if (!priv->iobase) { if (!priv->iobase) {
pr_err(DRV_NAME "Cannot map ioport\n"); pr_err(DRV_NAME "Cannot map ioport\n");
return -ENOMEM; err = -EINVAL;
goto err_iomap;
} }
amd_rng.priv = (unsigned long)priv; amd_rng.priv = (unsigned long)priv;
priv->pmbase = pmbase;
priv->pcidev = pdev; priv->pcidev = pdev;
pr_info(DRV_NAME " detected\n"); pr_info(DRV_NAME " detected\n");
return devm_hwrng_register(&pdev->dev, &amd_rng); err = hwrng_register(&amd_rng);
if (err) {
pr_err(DRV_NAME " registering failed (%d)\n", err);
goto err_hwrng;
}
return 0;
err_hwrng:
ioport_unmap(priv->iobase);
err_iomap:
release_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE);
out:
kfree(priv);
return err;
} }
static void __exit mod_exit(void) static void __exit mod_exit(void)
{ {
struct amd768_priv *priv;
priv = (struct amd768_priv *)amd_rng.priv;
hwrng_unregister(&amd_rng);
ioport_unmap(priv->iobase);
release_region(priv->pmbase + PMBASE_OFFSET, PMBASE_SIZE);
kfree(priv);
} }
module_init(mod_init); module_init(mod_init);
......
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h> #include <linux/pci.h>
#define PFX KBUILD_MODNAME ": "
#define GEODE_RNG_DATA_REG 0x50 #define GEODE_RNG_DATA_REG 0x50
#define GEODE_RNG_STATUS_REG 0x54 #define GEODE_RNG_STATUS_REG 0x54
...@@ -82,6 +85,7 @@ static struct hwrng geode_rng = { ...@@ -82,6 +85,7 @@ static struct hwrng geode_rng = {
static int __init mod_init(void) static int __init mod_init(void)
{ {
int err = -ENODEV;
struct pci_dev *pdev = NULL; struct pci_dev *pdev = NULL;
const struct pci_device_id *ent; const struct pci_device_id *ent;
void __iomem *mem; void __iomem *mem;
...@@ -89,27 +93,43 @@ static int __init mod_init(void) ...@@ -89,27 +93,43 @@ static int __init mod_init(void)
for_each_pci_dev(pdev) { for_each_pci_dev(pdev) {
ent = pci_match_id(pci_tbl, pdev); ent = pci_match_id(pci_tbl, pdev);
if (ent) { if (ent)
goto found;
}
/* Device not found. */
goto out;
found:
rng_base = pci_resource_start(pdev, 0); rng_base = pci_resource_start(pdev, 0);
if (rng_base == 0) if (rng_base == 0)
return -ENODEV; goto out;
err = -ENOMEM;
mem = devm_ioremap(&pdev->dev, rng_base, 0x58); mem = ioremap(rng_base, 0x58);
if (!mem) if (!mem)
return -ENOMEM; goto out;
geode_rng.priv = (unsigned long)mem; geode_rng.priv = (unsigned long)mem;
pr_info("AMD Geode RNG detected\n"); pr_info("AMD Geode RNG detected\n");
return devm_hwrng_register(&pdev->dev, &geode_rng); err = hwrng_register(&geode_rng);
} if (err) {
pr_err(PFX "RNG registering failed (%d)\n",
err);
goto err_unmap;
} }
out:
return err;
/* Device not found. */ err_unmap:
return -ENODEV; iounmap(mem);
goto out;
} }
static void __exit mod_exit(void) static void __exit mod_exit(void)
{ {
void __iomem *mem = (void __iomem *)geode_rng.priv;
hwrng_unregister(&geode_rng);
iounmap(mem);
} }
module_init(mod_init); module_init(mod_init);
......
...@@ -506,7 +506,7 @@ static int caam_rsa_init_tfm(struct crypto_akcipher *tfm) ...@@ -506,7 +506,7 @@ static int caam_rsa_init_tfm(struct crypto_akcipher *tfm)
ctx->dev = caam_jr_alloc(); ctx->dev = caam_jr_alloc();
if (IS_ERR(ctx->dev)) { if (IS_ERR(ctx->dev)) {
dev_err(ctx->dev, "Job Ring Device allocation for transform failed\n"); pr_err("Job Ring Device allocation for transform failed\n");
return PTR_ERR(ctx->dev); return PTR_ERR(ctx->dev);
} }
......
...@@ -285,7 +285,8 @@ static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask) ...@@ -285,7 +285,8 @@ static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask)
/* Try to run it through DECO0 */ /* Try to run it through DECO0 */
ret = run_descriptor_deco0(ctrldev, desc, &status); ret = run_descriptor_deco0(ctrldev, desc, &status);
if (ret || status) { if (ret ||
(status && status != JRSTA_SSRC_JUMP_HALT_CC)) {
dev_err(ctrldev, dev_err(ctrldev,
"Failed to deinstantiate RNG4 SH%d\n", "Failed to deinstantiate RNG4 SH%d\n",
sh_idx); sh_idx);
...@@ -305,15 +306,13 @@ static int caam_remove(struct platform_device *pdev) ...@@ -305,15 +306,13 @@ static int caam_remove(struct platform_device *pdev)
struct device *ctrldev; struct device *ctrldev;
struct caam_drv_private *ctrlpriv; struct caam_drv_private *ctrlpriv;
struct caam_ctrl __iomem *ctrl; struct caam_ctrl __iomem *ctrl;
int ring;
ctrldev = &pdev->dev; ctrldev = &pdev->dev;
ctrlpriv = dev_get_drvdata(ctrldev); ctrlpriv = dev_get_drvdata(ctrldev);
ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl; ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
/* Remove platform devices for JobRs */ /* Remove platform devices under the crypto node */
for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) of_platform_depopulate(ctrldev);
of_device_unregister(ctrlpriv->jrpdev[ring]);
#ifdef CONFIG_CAAM_QI #ifdef CONFIG_CAAM_QI
if (ctrlpriv->qidev) if (ctrlpriv->qidev)
...@@ -410,10 +409,21 @@ int caam_get_era(void) ...@@ -410,10 +409,21 @@ int caam_get_era(void)
} }
EXPORT_SYMBOL(caam_get_era); EXPORT_SYMBOL(caam_get_era);
static const struct of_device_id caam_match[] = {
{
.compatible = "fsl,sec-v4.0",
},
{
.compatible = "fsl,sec4.0",
},
{},
};
MODULE_DEVICE_TABLE(of, caam_match);
/* Probe routine for CAAM top (controller) level */ /* Probe routine for CAAM top (controller) level */
static int caam_probe(struct platform_device *pdev) static int caam_probe(struct platform_device *pdev)
{ {
int ret, ring, ridx, rspec, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN; int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
u64 caam_id; u64 caam_id;
struct device *dev; struct device *dev;
struct device_node *nprop, *np; struct device_node *nprop, *np;
...@@ -589,21 +599,9 @@ static int caam_probe(struct platform_device *pdev) ...@@ -589,21 +599,9 @@ static int caam_probe(struct platform_device *pdev)
goto iounmap_ctrl; goto iounmap_ctrl;
} }
/* ret = of_platform_populate(nprop, caam_match, NULL, dev);
* Detect and enable JobRs if (ret) {
* First, find out how many ring spec'ed, allocate references dev_err(dev, "JR platform devices creation error\n");
* for all, then go probe each one.
*/
rspec = 0;
for_each_available_child_of_node(nprop, np)
if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
rspec++;
ctrlpriv->jrpdev = devm_kcalloc(&pdev->dev, rspec,
sizeof(*ctrlpriv->jrpdev), GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
ret = -ENOMEM;
goto iounmap_ctrl; goto iounmap_ctrl;
} }
...@@ -618,28 +616,18 @@ static int caam_probe(struct platform_device *pdev) ...@@ -618,28 +616,18 @@ static int caam_probe(struct platform_device *pdev)
ctrlpriv->dfs_root = debugfs_create_dir(dev_name(dev), NULL); ctrlpriv->dfs_root = debugfs_create_dir(dev_name(dev), NULL);
ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root); ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);
#endif #endif
ring = 0; ring = 0;
ridx = 0;
ctrlpriv->total_jobrs = 0;
for_each_available_child_of_node(nprop, np) for_each_available_child_of_node(nprop, np)
if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") || if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
of_device_is_compatible(np, "fsl,sec4.0-job-ring")) { of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
ctrlpriv->jrpdev[ring] =
of_platform_device_create(np, NULL, dev);
if (!ctrlpriv->jrpdev[ring]) {
pr_warn("JR physical index %d: Platform device creation error\n",
ridx);
ridx++;
continue;
}
ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *) ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
((__force uint8_t *)ctrl + ((__force uint8_t *)ctrl +
(ridx + JR_BLOCK_NUMBER) * (ring + JR_BLOCK_NUMBER) *
BLOCK_OFFSET BLOCK_OFFSET
); );
ctrlpriv->total_jobrs++; ctrlpriv->total_jobrs++;
ring++; ring++;
ridx++;
} }
/* Check to see if QI present. If so, enable */ /* Check to see if QI present. If so, enable */
...@@ -849,17 +837,6 @@ static int caam_probe(struct platform_device *pdev) ...@@ -849,17 +837,6 @@ static int caam_probe(struct platform_device *pdev)
return ret; return ret;
} }
static struct of_device_id caam_match[] = {
{
.compatible = "fsl,sec-v4.0",
},
{
.compatible = "fsl,sec4.0",
},
{},
};
MODULE_DEVICE_TABLE(of, caam_match);
static struct platform_driver caam_driver = { static struct platform_driver caam_driver = {
.driver = { .driver = {
.name = "caam", .name = "caam",
......
...@@ -66,7 +66,6 @@ struct caam_drv_private_jr { ...@@ -66,7 +66,6 @@ struct caam_drv_private_jr {
struct caam_drv_private { struct caam_drv_private {
struct device *dev; struct device *dev;
struct platform_device **jrpdev; /* Alloc'ed array per sub-device */
#ifdef CONFIG_CAAM_QI #ifdef CONFIG_CAAM_QI
struct device *qidev; struct device *qidev;
#endif #endif
......
...@@ -1069,6 +1069,7 @@ const struct ccp_vdata ccpv5a = { ...@@ -1069,6 +1069,7 @@ const struct ccp_vdata ccpv5a = {
const struct ccp_vdata ccpv5b = { const struct ccp_vdata ccpv5b = {
.version = CCP_VERSION(5, 0), .version = CCP_VERSION(5, 0),
.dma_chan_attr = DMA_PRIVATE,
.setup = ccp5other_config, .setup = ccp5other_config,
.perform = &ccp5_actions, .perform = &ccp5_actions,
.bar = 2, .bar = 2,
......
...@@ -283,11 +283,14 @@ EXPORT_SYMBOL_GPL(ccp_version); ...@@ -283,11 +283,14 @@ EXPORT_SYMBOL_GPL(ccp_version);
*/ */
int ccp_enqueue_cmd(struct ccp_cmd *cmd) int ccp_enqueue_cmd(struct ccp_cmd *cmd)
{ {
struct ccp_device *ccp = ccp_get_device(); struct ccp_device *ccp;
unsigned long flags; unsigned long flags;
unsigned int i; unsigned int i;
int ret; int ret;
/* Some commands might need to be sent to a specific device */
ccp = cmd->ccp ? cmd->ccp : ccp_get_device();
if (!ccp) if (!ccp)
return -ENODEV; return -ENODEV;
......
...@@ -179,6 +179,10 @@ ...@@ -179,6 +179,10 @@
/* ------------------------ General CCP Defines ------------------------ */ /* ------------------------ General CCP Defines ------------------------ */
#define CCP_DMA_DFLT 0x0
#define CCP_DMA_PRIV 0x1
#define CCP_DMA_PUB 0x2
#define CCP_DMAPOOL_MAX_SIZE 64 #define CCP_DMAPOOL_MAX_SIZE 64
#define CCP_DMAPOOL_ALIGN BIT(5) #define CCP_DMAPOOL_ALIGN BIT(5)
...@@ -646,6 +650,7 @@ struct ccp_actions { ...@@ -646,6 +650,7 @@ struct ccp_actions {
/* Structure to hold CCP version-specific values */ /* Structure to hold CCP version-specific values */
struct ccp_vdata { struct ccp_vdata {
const unsigned int version; const unsigned int version;
const unsigned int dma_chan_attr;
void (*setup)(struct ccp_device *); void (*setup)(struct ccp_device *);
const struct ccp_actions *perform; const struct ccp_actions *perform;
const unsigned int bar; const unsigned int bar;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
* published by the Free Software Foundation. * published by the Free Software Foundation.
*/ */
#include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/dmaengine.h> #include <linux/dmaengine.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
...@@ -25,6 +26,37 @@ ...@@ -25,6 +26,37 @@
(mask == 0) ? 64 : fls64(mask); \ (mask == 0) ? 64 : fls64(mask); \
}) })
/* The CCP as a DMA provider can be configured for public or private
* channels. Default is specified in the vdata for the device (PCI ID).
* This module parameter will override for all channels on all devices:
* dma_chan_attr = 0x2 to force all channels public
* = 0x1 to force all channels private
* = 0x0 to defer to the vdata setting
* = any other value: warning, revert to 0x0
*/
static unsigned int dma_chan_attr = CCP_DMA_DFLT;
module_param(dma_chan_attr, uint, 0444);
MODULE_PARM_DESC(dma_chan_attr, "Set DMA channel visibility: 0 (default) = device defaults, 1 = make private, 2 = make public");
unsigned int ccp_get_dma_chan_attr(struct ccp_device *ccp)
{
switch (dma_chan_attr) {
case CCP_DMA_DFLT:
return ccp->vdata->dma_chan_attr;
case CCP_DMA_PRIV:
return DMA_PRIVATE;
case CCP_DMA_PUB:
return 0;
default:
dev_info_once(ccp->dev, "Invalid value for dma_chan_attr: %d\n",
dma_chan_attr);
return ccp->vdata->dma_chan_attr;
}
}
static void ccp_free_cmd_resources(struct ccp_device *ccp, static void ccp_free_cmd_resources(struct ccp_device *ccp,
struct list_head *list) struct list_head *list)
{ {
...@@ -390,6 +422,7 @@ static struct ccp_dma_desc *ccp_create_desc(struct dma_chan *dma_chan, ...@@ -390,6 +422,7 @@ static struct ccp_dma_desc *ccp_create_desc(struct dma_chan *dma_chan,
goto err; goto err;
ccp_cmd = &cmd->ccp_cmd; ccp_cmd = &cmd->ccp_cmd;
ccp_cmd->ccp = chan->ccp;
ccp_pt = &ccp_cmd->u.passthru_nomap; ccp_pt = &ccp_cmd->u.passthru_nomap;
ccp_cmd->flags = CCP_CMD_MAY_BACKLOG; ccp_cmd->flags = CCP_CMD_MAY_BACKLOG;
ccp_cmd->flags |= CCP_CMD_PASSTHRU_NO_DMA_MAP; ccp_cmd->flags |= CCP_CMD_PASSTHRU_NO_DMA_MAP;
...@@ -674,6 +707,15 @@ int ccp_dmaengine_register(struct ccp_device *ccp) ...@@ -674,6 +707,15 @@ int ccp_dmaengine_register(struct ccp_device *ccp)
dma_cap_set(DMA_SG, dma_dev->cap_mask); dma_cap_set(DMA_SG, dma_dev->cap_mask);
dma_cap_set(DMA_INTERRUPT, dma_dev->cap_mask); dma_cap_set(DMA_INTERRUPT, dma_dev->cap_mask);
/* The DMA channels for this device can be set to public or private,
* and overridden by the module parameter dma_chan_attr.
* Default: according to the value in vdata (dma_chan_attr=0)
* dma_chan_attr=0x1: all channels private (override vdata)
* dma_chan_attr=0x2: all channels public (override vdata)
*/
if (ccp_get_dma_chan_attr(ccp) == DMA_PRIVATE)
dma_cap_set(DMA_PRIVATE, dma_dev->cap_mask);
INIT_LIST_HEAD(&dma_dev->channels); INIT_LIST_HEAD(&dma_dev->channels);
for (i = 0; i < ccp->cmd_q_count; i++) { for (i = 0; i < ccp->cmd_q_count; i++) {
chan = ccp->ccp_dma_chan + i; chan = ccp->ccp_dma_chan + i;
......
...@@ -621,7 +621,7 @@ enum ccp_engine { ...@@ -621,7 +621,7 @@ enum ccp_engine {
* struct ccp_cmd - CCP operation request * struct ccp_cmd - CCP operation request
* @entry: list element (ccp driver use only) * @entry: list element (ccp driver use only)
* @work: work element used for callbacks (ccp driver use only) * @work: work element used for callbacks (ccp driver use only)
* @ccp: CCP device to be run on (ccp driver use only) * @ccp: CCP device to be run on
* @ret: operation return code (ccp driver use only) * @ret: operation return code (ccp driver use only)
* @flags: cmd processing flags * @flags: cmd processing flags
* @engine: CCP operation to perform * @engine: CCP operation to perform
......
...@@ -186,19 +186,20 @@ static struct padata_priv *padata_get_next(struct parallel_data *pd) ...@@ -186,19 +186,20 @@ static struct padata_priv *padata_get_next(struct parallel_data *pd)
reorder = &next_queue->reorder; reorder = &next_queue->reorder;
spin_lock(&reorder->lock);
if (!list_empty(&reorder->list)) { if (!list_empty(&reorder->list)) {
padata = list_entry(reorder->list.next, padata = list_entry(reorder->list.next,
struct padata_priv, list); struct padata_priv, list);
spin_lock(&reorder->lock);
list_del_init(&padata->list); list_del_init(&padata->list);
atomic_dec(&pd->reorder_objects); atomic_dec(&pd->reorder_objects);
spin_unlock(&reorder->lock);
pd->processed++; pd->processed++;
spin_unlock(&reorder->lock);
goto out; goto out;
} }
spin_unlock(&reorder->lock);
if (__this_cpu_read(pd->pqueue->cpu_index) == next_queue->cpu_index) { if (__this_cpu_read(pd->pqueue->cpu_index) == next_queue->cpu_index) {
padata = ERR_PTR(-ENODATA); padata = ERR_PTR(-ENODATA);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment