Skip to content

Commit 9166c44

Browse files
raveenpherbertx
authored andcommitted
crypto: brcm - Support more FlexRM rings than SPU engines.
Enhance code to generically support cases where DMA rings are greater than or equal to number of SPU engines. New hardware has underlying DMA engine-FlexRM with 32 rings which can be used to communicate to any of the available 10 SPU engines. Signed-off-by: Raveendra Padasalagi <[email protected]> Reviewed-by: Scott Branden <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 6d2bce6 commit 9166c44

File tree

2 files changed

+56
-66
lines changed

2 files changed

+56
-66
lines changed

drivers/crypto/bcm/cipher.c

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ static int aead_pri = 150;
9090
module_param(aead_pri, int, 0644);
9191
MODULE_PARM_DESC(aead_pri, "Priority for AEAD algos");
9292

93-
#define MAX_SPUS 16
94-
9593
/* A type 3 BCM header, expected to precede the SPU header for SPU-M.
9694
* Bits 3 and 4 in the first byte encode the channel number (the dma ringset).
9795
* 0x60 - ring 0
@@ -120,7 +118,7 @@ static u8 select_channel(void)
120118
{
121119
u8 chan_idx = atomic_inc_return(&iproc_priv.next_chan);
122120

123-
return chan_idx % iproc_priv.spu.num_spu;
121+
return chan_idx % iproc_priv.spu.num_chan;
124122
}
125123

126124
/**
@@ -4528,8 +4526,13 @@ static void spu_functions_register(struct device *dev,
45284526
*/
45294527
static int spu_mb_init(struct device *dev)
45304528
{
4531-
struct mbox_client *mcl = &iproc_priv.mcl[iproc_priv.spu.num_spu];
4532-
int err;
4529+
struct mbox_client *mcl = &iproc_priv.mcl;
4530+
int err, i;
4531+
4532+
iproc_priv.mbox = devm_kcalloc(dev, iproc_priv.spu.num_chan,
4533+
sizeof(struct mbox_chan *), GFP_KERNEL);
4534+
if (!iproc_priv.mbox)
4535+
return -ENOMEM;
45334536

45344537
mcl->dev = dev;
45354538
mcl->tx_block = false;
@@ -4538,25 +4541,33 @@ static int spu_mb_init(struct device *dev)
45384541
mcl->rx_callback = spu_rx_callback;
45394542
mcl->tx_done = NULL;
45404543

4541-
iproc_priv.mbox[iproc_priv.spu.num_spu] =
4542-
mbox_request_channel(mcl, 0);
4543-
if (IS_ERR(iproc_priv.mbox[iproc_priv.spu.num_spu])) {
4544-
err = (int)PTR_ERR(iproc_priv.mbox[iproc_priv.spu.num_spu]);
4545-
dev_err(dev,
4546-
"Mbox channel %d request failed with err %d",
4547-
iproc_priv.spu.num_spu, err);
4548-
iproc_priv.mbox[iproc_priv.spu.num_spu] = NULL;
4549-
return err;
4544+
for (i = 0; i < iproc_priv.spu.num_chan; i++) {
4545+
iproc_priv.mbox[i] = mbox_request_channel(mcl, i);
4546+
if (IS_ERR(iproc_priv.mbox[i])) {
4547+
err = (int)PTR_ERR(iproc_priv.mbox[i]);
4548+
dev_err(dev,
4549+
"Mbox channel %d request failed with err %d",
4550+
i, err);
4551+
iproc_priv.mbox[i] = NULL;
4552+
goto free_channels;
4553+
}
45504554
}
45514555

45524556
return 0;
4557+
free_channels:
4558+
for (i = 0; i < iproc_priv.spu.num_chan; i++) {
4559+
if (iproc_priv.mbox[i])
4560+
mbox_free_channel(iproc_priv.mbox[i]);
4561+
}
4562+
4563+
return err;
45534564
}
45544565

45554566
static void spu_mb_release(struct platform_device *pdev)
45564567
{
45574568
int i;
45584569

4559-
for (i = 0; i < iproc_priv.spu.num_spu; i++)
4570+
for (i = 0; i < iproc_priv.spu.num_chan; i++)
45604571
mbox_free_channel(iproc_priv.mbox[i]);
45614572
}
45624573

@@ -4567,7 +4578,7 @@ static void spu_counters_init(void)
45674578

45684579
atomic_set(&iproc_priv.session_count, 0);
45694580
atomic_set(&iproc_priv.stream_count, 0);
4570-
atomic_set(&iproc_priv.next_chan, (int)iproc_priv.spu.num_spu);
4581+
atomic_set(&iproc_priv.next_chan, (int)iproc_priv.spu.num_chan);
45714582
atomic64_set(&iproc_priv.bytes_in, 0);
45724583
atomic64_set(&iproc_priv.bytes_out, 0);
45734584
for (i = 0; i < SPU_OP_NUM; i++) {
@@ -4809,8 +4820,11 @@ static int spu_dt_read(struct platform_device *pdev)
48094820
struct resource *spu_ctrl_regs;
48104821
const struct of_device_id *match;
48114822
const struct spu_type_subtype *matched_spu_type;
4812-
void __iomem *spu_reg_vbase[MAX_SPUS];
4813-
int err;
4823+
struct device_node *dn = pdev->dev.of_node;
4824+
int err, i;
4825+
4826+
/* Count number of mailbox channels */
4827+
spu->num_chan = of_count_phandle_with_args(dn, "mboxes", "#mbox-cells");
48144828

48154829
match = of_match_device(of_match_ptr(bcm_spu_dt_ids), dev);
48164830
if (!match) {
@@ -4820,41 +4834,24 @@ static int spu_dt_read(struct platform_device *pdev)
48204834

48214835
matched_spu_type = match->data;
48224836

4823-
if (iproc_priv.spu.num_spu > 1) {
4824-
/* If this is 2nd or later SPU, make sure it's same type */
4825-
if ((spu->spu_type != matched_spu_type->type) ||
4826-
(spu->spu_subtype != matched_spu_type->subtype)) {
4827-
err = -EINVAL;
4828-
dev_err(&pdev->dev, "Multiple SPU types not allowed");
4829-
return err;
4830-
}
4831-
} else {
4832-
/* Record type of first SPU */
4833-
spu->spu_type = matched_spu_type->type;
4834-
spu->spu_subtype = matched_spu_type->subtype;
4835-
}
4837+
spu->spu_type = matched_spu_type->type;
4838+
spu->spu_subtype = matched_spu_type->subtype;
48364839

4837-
/* Get and map SPU registers */
4838-
spu_ctrl_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4839-
if (!spu_ctrl_regs) {
4840-
err = -EINVAL;
4841-
dev_err(&pdev->dev, "Invalid/missing registers for SPU\n");
4842-
return err;
4843-
}
4840+
i = 0;
4841+
for (i = 0; (i < MAX_SPUS) && ((spu_ctrl_regs =
4842+
platform_get_resource(pdev, IORESOURCE_MEM, i)) != NULL); i++) {
48444843

4845-
spu_reg_vbase[iproc_priv.spu.num_spu] =
4846-
devm_ioremap_resource(dev, spu_ctrl_regs);
4847-
if (IS_ERR(spu_reg_vbase[iproc_priv.spu.num_spu])) {
4848-
err = PTR_ERR(spu_reg_vbase[iproc_priv.spu.num_spu]);
4849-
dev_err(&pdev->dev, "Failed to map registers: %d\n",
4850-
err);
4851-
spu_reg_vbase[iproc_priv.spu.num_spu] = NULL;
4852-
return err;
4844+
spu->reg_vbase[i] = devm_ioremap_resource(dev, spu_ctrl_regs);
4845+
if (IS_ERR(spu->reg_vbase[i])) {
4846+
err = PTR_ERR(spu->reg_vbase[i]);
4847+
dev_err(&pdev->dev, "Failed to map registers: %d\n",
4848+
err);
4849+
spu->reg_vbase[i] = NULL;
4850+
return err;
4851+
}
48534852
}
4854-
4855-
dev_dbg(dev, "SPU %d detected.", iproc_priv.spu.num_spu);
4856-
4857-
spu->reg_vbase[iproc_priv.spu.num_spu] = spu_reg_vbase;
4853+
spu->num_spu = i;
4854+
dev_dbg(dev, "Device has %d SPUs", spu->num_spu);
48584855

48594856
return 0;
48604857
}
@@ -4865,8 +4862,8 @@ int bcm_spu_probe(struct platform_device *pdev)
48654862
struct spu_hw *spu = &iproc_priv.spu;
48664863
int err = 0;
48674864

4868-
iproc_priv.pdev[iproc_priv.spu.num_spu] = pdev;
4869-
platform_set_drvdata(iproc_priv.pdev[iproc_priv.spu.num_spu],
4865+
iproc_priv.pdev = pdev;
4866+
platform_set_drvdata(iproc_priv.pdev,
48704867
&iproc_priv);
48714868

48724869
err = spu_dt_read(pdev);
@@ -4877,12 +4874,6 @@ int bcm_spu_probe(struct platform_device *pdev)
48774874
if (err < 0)
48784875
goto failure;
48794876

4880-
iproc_priv.spu.num_spu++;
4881-
4882-
/* If already initialized, we've just added another SPU and are done */
4883-
if (iproc_priv.inited)
4884-
return 0;
4885-
48864877
if (spu->spu_type == SPU_TYPE_SPUM)
48874878
iproc_priv.bcm_hdr_len = 8;
48884879
else if (spu->spu_type == SPU_TYPE_SPU2)
@@ -4898,8 +4889,6 @@ int bcm_spu_probe(struct platform_device *pdev)
48984889
if (err < 0)
48994890
goto fail_reg;
49004891

4901-
iproc_priv.inited = true;
4902-
49034892
return 0;
49044893

49054894
fail_reg:

drivers/crypto/bcm/cipher.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,13 @@ struct spu_hw {
427427

428428
/* The number of SPUs on this platform */
429429
u32 num_spu;
430+
431+
/* The number of SPU channels on this platform */
432+
u32 num_chan;
430433
};
431434

432435
struct device_private {
433-
struct platform_device *pdev[MAX_SPUS];
436+
struct platform_device *pdev;
434437

435438
struct spu_hw spu;
436439

@@ -470,12 +473,10 @@ struct device_private {
470473
/* Number of ICV check failures for AEAD messages */
471474
atomic_t bad_icv;
472475

473-
struct mbox_client mcl[MAX_SPUS];
474-
/* Array of mailbox channel pointers, one for each channel */
475-
struct mbox_chan *mbox[MAX_SPUS];
476+
struct mbox_client mcl;
476477

477-
/* Driver initialized */
478-
bool inited;
478+
/* Array of mailbox channel pointers, one for each channel */
479+
struct mbox_chan **mbox;
479480
};
480481

481482
extern struct device_private iproc_priv;

0 commit comments

Comments
 (0)