[][openwrt][mt7988][crypto][Add multiple ring for DDK look-aside]

[Description]
Add multiple ring for DDK look-aside.

[Release-log]
N/A


Change-Id: I4b27ec566ba3704567224b65c650f0bfb9cb89b5
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9463834
diff --git a/feed/kernel/crypto-eip/src/init.c b/feed/kernel/crypto-eip/src/init.c
index 757f2ec..fc7b868 100644
--- a/feed/kernel/crypto-eip/src/init.c
+++ b/feed/kernel/crypto-eip/src/init.c
@@ -34,7 +34,6 @@
 struct mtk_crypto mcrypto;
 struct device *crypto_dev;
 struct mtk_crypto_priv *priv;
-spinlock_t add_lock;
 
 static struct mtk_crypto_alg_template *mtk_crypto_algs[] = {
 	&mtk_crypto_cbc_aes,
@@ -294,6 +293,7 @@
 static int __init mtk_crypto_lookaside_data_init(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
+	int i;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -301,18 +301,41 @@
 
 	platform_set_drvdata(pdev, priv);
 
-	priv->mtk_eip_queue.work_data.priv = priv;
-	INIT_WORK(&priv->mtk_eip_queue.work_data.work, mtk_crypto_dequeue_work);
-
-	priv->mtk_eip_queue.workqueue = create_singlethread_workqueue("mtk_crypto_work");
-	if (!priv->mtk_eip_queue.workqueue)
+	priv->mtk_eip_ring = devm_kcalloc(dev, PEC_MAX_INTERFACE_NUM,
+							sizeof(*priv->mtk_eip_ring), GFP_KERNEL);
+	if (!priv->mtk_eip_ring)
 		return -ENOMEM;
 
+	for (i = 0; i < PEC_MAX_INTERFACE_NUM; i++) {
+		char wq_name[17] = {0};
+		char irq_name[6] = {0};
+		int irq, cpu;
+
+		// init workqueue for all rings
+		priv->mtk_eip_ring[i].work_data.priv = priv;
+		priv->mtk_eip_ring[i].work_data.ring = i;
+		INIT_WORK(&priv->mtk_eip_ring[i].work_data.work, mtk_crypto_dequeue_work);
+
-	crypto_init_queue(&priv->mtk_eip_queue.queue, EIP197_DEFAULT_RING_SIZE);
+		snprintf(wq_name, 17, "mtk_crypto_work%d", i);
+		priv->mtk_eip_ring[i].workqueue = create_singlethread_workqueue(wq_name);
+		if (!priv->mtk_eip_ring[i].workqueue)
+			return -ENOMEM;
 
-	spin_lock_init(&priv->mtk_eip_queue.lock);
-	spin_lock_init(&priv->mtk_eip_queue.queue_lock);
-	spin_lock_init(&add_lock);
+		crypto_init_queue(&priv->mtk_eip_ring[i].queue, EIP197_DEFAULT_RING_SIZE);
+
+		spin_lock_init(&priv->mtk_eip_ring[i].ring_lock);
+		spin_lock_init(&priv->mtk_eip_ring[i].queue_lock);
+		INIT_LIST_HEAD(&priv->mtk_eip_ring[i].list);
+
+		// setup irq affinity
+		snprintf(irq_name, 6, "ring%d", i);
+		irq = platform_get_irq_byname(pdev,  irq_name);
+		if (irq < 0)
+			return irq;
+
+		cpu = cpumask_local_spread(i, NUMA_NO_NODE);
+		irq_set_affinity_hint(irq, get_cpu_mask(cpu));
+	}
 
 	return 0;
 };