blob: a144c364ea4c5b5e3b6b06be2b63ebb6ef89d6c4 [file] [log] [blame]
developer5d148cb2023-06-02 13:08:11 +08001From 7baac266ec5e64236ff94447286a9cc74815d259 Mon Sep 17 00:00:00 2001
2From: Sam Shih <sam.shih@mediatek.com>
3Date: Fri, 2 Jun 2023 13:06:28 +0800
4Subject: [PATCH]
5 [networking][999-2706-crypto-add-eip197-inside-secure-support.patch]
6
7---
8 drivers/crypto/inside-secure/safexcel.c | 69 ++++++++++++++++++++++---
9 drivers/crypto/inside-secure/safexcel.h | 15 ++++++
10 2 files changed, 78 insertions(+), 6 deletions(-)
11
12diff --git a/drivers/crypto/inside-secure/safexcel.c b/drivers/crypto/inside-secure/safexcel.c
13index 647c5a0c1..6f4fc15b7 100644
developera5569782022-05-06 11:04:59 +080014--- a/drivers/crypto/inside-secure/safexcel.c
15+++ b/drivers/crypto/inside-secure/safexcel.c
developer5d148cb2023-06-02 13:08:11 +080016@@ -304,6 +304,11 @@ static void eip197_init_firmware(struct safexcel_crypto_priv *priv)
developera5569782022-05-06 11:04:59 +080017 /* Enable access to all IFPP program memories */
18 writel(EIP197_PE_ICE_RAM_CTRL_FPP_PROG_EN,
19 EIP197_PE(priv) + EIP197_PE_ICE_RAM_CTRL(pe));
20+
21+ /* bypass the OCE, if present */
22+ if (priv->flags & EIP197_OCE)
23+ writel(EIP197_DEBUG_OCE_BYPASS, EIP197_PE(priv) +
24+ EIP197_PE_DEBUG(pe));
25 }
26
27 }
developer5d148cb2023-06-02 13:08:11 +080028@@ -403,13 +408,13 @@ static int eip197_load_firmwares(struct safexcel_crypto_priv *priv)
developer720571a2022-10-12 14:24:17 +080029 const struct firmware *fw[FW_NB];
30 char fw_path[37], *dir = NULL;
31 int i, j, ret = 0, pe;
32- int ipuesz, ifppsz, minifw = 0;
33+ int ipuesz, ifppsz, minifw = 1;
34
35 if (priv->version == EIP197D_MRVL)
developera5569782022-05-06 11:04:59 +080036 dir = "eip197d";
37 else if (priv->version == EIP197B_MRVL ||
38 priv->version == EIP197_DEVBRD)
39- dir = "eip197b";
40+ dir = "eip197_minifw";
41 else
42 return -ENODEV;
43
developer5d148cb2023-06-02 13:08:11 +080044@@ -442,6 +447,9 @@ retry_fw:
developer2455c2f2022-10-28 17:09:32 +080045
46 ipuesz = eip197_write_firmware(priv, fw[FW_IPUE]);
47
48+ for (j = 0; j < i; j++)
49+ release_firmware(fw[j]);
50+
51 if (eip197_start_firmware(priv, ipuesz, ifppsz, minifw)) {
52 dev_dbg(priv->dev, "Firmware loaded successfully\n");
53 return 0;
developer5d148cb2023-06-02 13:08:11 +080054@@ -592,6 +600,11 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
developer720571a2022-10-12 14:24:17 +080055 */
56 if (priv->flags & SAFEXCEL_HW_EIP197) {
57 val = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL);
58+ /* Clear axi_burst_size and rx_burst_size */
59+ val &= 0xffffff00;
60+ /* Set axi_burst_size = 3, rx_burst_size = 3 */
61+ val |= EIP197_MST_CTRL_RD_CACHE(3);
62+ val |= EIP197_MST_CTRL_WD_CACHE(3);
63 val |= EIP197_MST_CTRL_TX_MAX_CMD(5);
64 writel(val, EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL);
65 }
developer5d148cb2023-06-02 13:08:11 +080066@@ -792,6 +805,12 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
developera5569782022-05-06 11:04:59 +080067 return ret;
68 }
69
70+ /* Allow clocks to be forced on for EIP197 */
71+ if (priv->flags & SAFEXCEL_HW_EIP197) {
72+ writel(0xffffffff, EIP197_HIA_GEN_CFG(priv) + EIP197_FORCE_CLOCK_ON);
73+ writel(0xffffffff, EIP197_HIA_GEN_CFG(priv) + EIP197_FORCE_CLOCK_ON2);
74+ }
75+
76 return safexcel_hw_setup_cdesc_rings(priv) ?:
77 safexcel_hw_setup_rdesc_rings(priv) ?:
78 0;
developer5d148cb2023-06-02 13:08:11 +080079@@ -1498,6 +1517,9 @@ static int safexcel_probe_generic(void *pdev,
developera5569782022-05-06 11:04:59 +080080 hwopt = readl(EIP197_GLOBAL(priv) + EIP197_OPTIONS);
81 hiaopt = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_OPTIONS);
82
83+ priv->hwconfig.icever = 0;
84+ priv->hwconfig.ocever = 0;
85+ priv->hwconfig.psever = 0;
86 if (priv->flags & SAFEXCEL_HW_EIP197) {
87 /* EIP197 */
88 peopt = readl(EIP197_PE(priv) + EIP197_PE_OPTIONS(0));
developer5d148cb2023-06-02 13:08:11 +080089@@ -1516,8 +1538,37 @@ static int safexcel_probe_generic(void *pdev,
developera5569782022-05-06 11:04:59 +080090 EIP197_N_RINGS_MASK;
91 if (hiaopt & EIP197_HIA_OPT_HAS_PE_ARB)
92 priv->flags |= EIP197_PE_ARB;
93- if (EIP206_OPT_ICE_TYPE(peopt) == 1)
94+ if (EIP206_OPT_ICE_TYPE(peopt) == 1) {
95 priv->flags |= EIP197_ICE;
96+ /* Detect ICE EIP207 class. engine and version */
97+ version = readl(EIP197_PE(priv) +
98+ EIP197_PE_ICE_VERSION(0));
99+ if (EIP197_REG_LO16(version) != EIP207_VERSION_LE) {
100+ dev_err(dev, "EIP%d: ICE EIP207 not detected.\n",
101+ peid);
102+ return -ENODEV;
103+ }
104+ priv->hwconfig.icever = EIP197_VERSION_MASK(version);
105+ }
106+ if (EIP206_OPT_OCE_TYPE(peopt) == 1) {
107+ priv->flags |= EIP197_OCE;
108+ /* Detect EIP96PP packet stream editor and version */
109+ version = readl(EIP197_PE(priv) + EIP197_PE_PSE_VERSION(0));
110+ if (EIP197_REG_LO16(version) != EIP96_VERSION_LE) {
111+ dev_err(dev, "EIP%d: EIP96PP not detected.\n", peid);
112+ return -ENODEV;
113+ }
114+ priv->hwconfig.psever = EIP197_VERSION_MASK(version);
115+ /* Detect OCE EIP207 class. engine and version */
116+ version = readl(EIP197_PE(priv) +
117+ EIP197_PE_ICE_VERSION(0));
118+ if (EIP197_REG_LO16(version) != EIP207_VERSION_LE) {
119+ dev_err(dev, "EIP%d: OCE EIP207 not detected.\n",
120+ peid);
121+ return -ENODEV;
122+ }
123+ priv->hwconfig.ocever = EIP197_VERSION_MASK(version);
124+ }
125 /* If not a full TRC, then assume simple TRC */
126 if (!(hwopt & EIP197_OPT_HAS_TRC))
127 priv->flags |= EIP197_SIMPLE_TRC;
developer5d148cb2023-06-02 13:08:11 +0800128@@ -1555,13 +1606,14 @@ static int safexcel_probe_generic(void *pdev,
developera5569782022-05-06 11:04:59 +0800129 EIP197_PE_EIP96_OPTIONS(0));
130
131 /* Print single info line describing what we just detected */
132- dev_info(priv->dev, "EIP%d:%x(%d,%d,%d,%d)-HIA:%x(%d,%d,%d),PE:%x/%x,alg:%08x\n",
133+ dev_info(priv->dev, "EIP%d:%x(%d,%d,%d,%d)-HIA:%x(%d,%d,%d),PE:%x/%x(alg:%08x)/%x/%x/%x\n",
134 peid, priv->hwconfig.hwver, hwctg, priv->hwconfig.hwnumpes,
135 priv->hwconfig.hwnumrings, priv->hwconfig.hwnumraic,
136 priv->hwconfig.hiaver, priv->hwconfig.hwdataw,
137 priv->hwconfig.hwcfsize, priv->hwconfig.hwrfsize,
138 priv->hwconfig.ppver, priv->hwconfig.pever,
139- priv->hwconfig.algo_flags);
140+ priv->hwconfig.algo_flags, priv->hwconfig.icever,
141+ priv->hwconfig.ocever, priv->hwconfig.psever);
142
143 safexcel_configure(priv);
144
developer5d148cb2023-06-02 13:08:11 +0800145@@ -1690,6 +1742,7 @@ static int safexcel_probe(struct platform_device *pdev)
developera5569782022-05-06 11:04:59 +0800146 {
147 struct device *dev = &pdev->dev;
148 struct safexcel_crypto_priv *priv;
149+ struct resource *res;
150 int ret;
151
152 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
developer5d148cb2023-06-02 13:08:11 +0800153@@ -1701,7 +1754,11 @@ static int safexcel_probe(struct platform_device *pdev)
developera5569782022-05-06 11:04:59 +0800154
155 platform_set_drvdata(pdev, priv);
156
157- priv->base = devm_platform_ioremap_resource(pdev, 0);
158+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
159+ if (!res)
160+ return -EINVAL;
161+
162+ priv->base = devm_ioremap(dev, res->start, resource_size(res));
163 if (IS_ERR(priv->base)) {
164 dev_err(dev, "failed to get resource\n");
165 return PTR_ERR(priv->base);
developer5d148cb2023-06-02 13:08:11 +0800166diff --git a/drivers/crypto/inside-secure/safexcel.h b/drivers/crypto/inside-secure/safexcel.h
167index c031c197e..e9909c336 100644
developera5569782022-05-06 11:04:59 +0800168--- a/drivers/crypto/inside-secure/safexcel.h
169+++ b/drivers/crypto/inside-secure/safexcel.h
170@@ -22,6 +22,7 @@
171 #define EIP96_VERSION_LE 0x9f60
172 #define EIP201_VERSION_LE 0x36c9
173 #define EIP206_VERSION_LE 0x31ce
174+#define EIP207_VERSION_LE 0x30cf
175 #define EIP197_REG_LO16(reg) (reg & 0xffff)
176 #define EIP197_REG_HI16(reg) ((reg >> 16) & 0xffff)
177 #define EIP197_VERSION_MASK(reg) ((reg >> 16) & 0xfff)
178@@ -34,6 +35,7 @@
179
180 /* EIP206 OPTIONS ENCODING */
181 #define EIP206_OPT_ICE_TYPE(n) ((n>>8)&3)
182+#define EIP206_OPT_OCE_TYPE(n) ((n>>10)&3)
183
184 /* EIP197 OPTIONS ENCODING */
185 #define EIP197_OPT_HAS_TRC BIT(31)
186@@ -168,6 +170,7 @@
187 #define EIP197_PE_ICE_FPP_CTRL(n) (0x0d80 + (0x2000 * (n)))
188 #define EIP197_PE_ICE_PPTF_CTRL(n) (0x0e00 + (0x2000 * (n)))
189 #define EIP197_PE_ICE_RAM_CTRL(n) (0x0ff0 + (0x2000 * (n)))
190+#define EIP197_PE_ICE_VERSION(n) (0x0ffc + (0x2000 * (n)))
191 #define EIP197_PE_EIP96_TOKEN_CTRL(n) (0x1000 + (0x2000 * (n)))
192 #define EIP197_PE_EIP96_FUNCTION_EN(n) (0x1004 + (0x2000 * (n)))
193 #define EIP197_PE_EIP96_CONTEXT_CTRL(n) (0x1008 + (0x2000 * (n)))
194@@ -176,10 +179,15 @@
195 #define EIP197_PE_EIP96_FUNCTION2_EN(n) (0x1030 + (0x2000 * (n)))
196 #define EIP197_PE_EIP96_OPTIONS(n) (0x13f8 + (0x2000 * (n)))
197 #define EIP197_PE_EIP96_VERSION(n) (0x13fc + (0x2000 * (n)))
198+#define EIP197_PE_OCE_VERSION(n) (0x1bfc + (0x2000 * (n)))
199 #define EIP197_PE_OUT_DBUF_THRES(n) (0x1c00 + (0x2000 * (n)))
200 #define EIP197_PE_OUT_TBUF_THRES(n) (0x1d00 + (0x2000 * (n)))
201+#define EIP197_PE_PSE_VERSION(n) (0x1efc + (0x2000 * (n)))
202+#define EIP197_PE_DEBUG(n) (0x1ff4 + (0x2000 * (n)))
203 #define EIP197_PE_OPTIONS(n) (0x1ff8 + (0x2000 * (n)))
204 #define EIP197_PE_VERSION(n) (0x1ffc + (0x2000 * (n)))
205+#define EIP197_FORCE_CLOCK_ON2 0xffd8
206+#define EIP197_FORCE_CLOCK_ON 0xffe8
207 #define EIP197_MST_CTRL 0xfff4
208 #define EIP197_OPTIONS 0xfff8
209 #define EIP197_VERSION 0xfffc
210@@ -353,6 +361,9 @@
211 /* EIP197_PE_EIP96_TOKEN_CTRL2 */
212 #define EIP197_PE_EIP96_TOKEN_CTRL2_CTX_DONE BIT(3)
213
214+/* EIP197_PE_DEBUG */
215+#define EIP197_DEBUG_OCE_BYPASS BIT(1)
216+
217 /* EIP197_STRC_CONFIG */
218 #define EIP197_STRC_CONFIG_INIT BIT(31)
219 #define EIP197_STRC_CONFIG_LARGE_REC(s) (s<<8)
developer5d148cb2023-06-02 13:08:11 +0800220@@ -777,6 +788,7 @@ enum safexcel_flags {
developera5569782022-05-06 11:04:59 +0800221 EIP197_PE_ARB = BIT(2),
222 EIP197_ICE = BIT(3),
223 EIP197_SIMPLE_TRC = BIT(4),
224+ EIP197_OCE = BIT(5),
225 };
226
227 struct safexcel_hwconfig {
developer5d148cb2023-06-02 13:08:11 +0800228@@ -784,7 +796,10 @@ struct safexcel_hwconfig {
developera5569782022-05-06 11:04:59 +0800229 int hwver;
230 int hiaver;
231 int ppver;
232+ int icever;
233 int pever;
234+ int ocever;
235+ int psever;
236 int hwdataw;
237 int hwcfsize;
238 int hwrfsize;
developer5d148cb2023-06-02 13:08:11 +0800239--
2402.34.1
241