developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 1 | --- a/drivers/crypto/inside-secure/safexcel.c |
| 2 | +++ b/drivers/crypto/inside-secure/safexcel.c |
| 3 | @@ -304,6 +304,11 @@ |
| 4 | /* Enable access to all IFPP program memories */ |
| 5 | writel(EIP197_PE_ICE_RAM_CTRL_FPP_PROG_EN, |
| 6 | EIP197_PE(priv) + EIP197_PE_ICE_RAM_CTRL(pe)); |
| 7 | + |
| 8 | + /* bypass the OCE, if present */ |
| 9 | + if (priv->flags & EIP197_OCE) |
| 10 | + writel(EIP197_DEBUG_OCE_BYPASS, EIP197_PE(priv) + |
| 11 | + EIP197_PE_DEBUG(pe)); |
| 12 | } |
| 13 | |
| 14 | } |
developer | 720571a | 2022-10-12 14:24:17 +0800 | [diff] [blame] | 15 | @@ -403,13 +408,13 @@ |
| 16 | const struct firmware *fw[FW_NB]; |
| 17 | char fw_path[37], *dir = NULL; |
| 18 | int i, j, ret = 0, pe; |
| 19 | - int ipuesz, ifppsz, minifw = 0; |
| 20 | + int ipuesz, ifppsz, minifw = 1; |
| 21 | |
| 22 | if (priv->version == EIP197D_MRVL) |
developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 23 | dir = "eip197d"; |
| 24 | else if (priv->version == EIP197B_MRVL || |
| 25 | priv->version == EIP197_DEVBRD) |
| 26 | - dir = "eip197b"; |
| 27 | + dir = "eip197_minifw"; |
| 28 | else |
| 29 | return -ENODEV; |
| 30 | |
developer | 2455c2f | 2022-10-28 17:09:32 +0800 | [diff] [blame] | 31 | @@ -442,6 +447,9 @@ |
| 32 | |
| 33 | ipuesz = eip197_write_firmware(priv, fw[FW_IPUE]); |
| 34 | |
| 35 | + for (j = 0; j < i; j++) |
| 36 | + release_firmware(fw[j]); |
| 37 | + |
| 38 | if (eip197_start_firmware(priv, ipuesz, ifppsz, minifw)) { |
| 39 | dev_dbg(priv->dev, "Firmware loaded successfully\n"); |
| 40 | return 0; |
| 41 | @@ -592,6 +600,11 @@ |
developer | 720571a | 2022-10-12 14:24:17 +0800 | [diff] [blame] | 42 | */ |
| 43 | if (priv->flags & SAFEXCEL_HW_EIP197) { |
| 44 | val = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL); |
| 45 | + /* Clear axi_burst_size and rx_burst_size */ |
| 46 | + val &= 0xffffff00; |
| 47 | + /* Set axi_burst_size = 3, rx_burst_size = 3 */ |
| 48 | + val |= EIP197_MST_CTRL_RD_CACHE(3); |
| 49 | + val |= EIP197_MST_CTRL_WD_CACHE(3); |
| 50 | val |= EIP197_MST_CTRL_TX_MAX_CMD(5); |
| 51 | writel(val, EIP197_HIA_AIC(priv) + EIP197_HIA_MST_CTRL); |
| 52 | } |
developer | 2455c2f | 2022-10-28 17:09:32 +0800 | [diff] [blame] | 53 | @@ -792,6 +805,12 @@ |
developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | + /* Allow clocks to be forced on for EIP197 */ |
| 58 | + if (priv->flags & SAFEXCEL_HW_EIP197) { |
| 59 | + writel(0xffffffff, EIP197_HIA_GEN_CFG(priv) + EIP197_FORCE_CLOCK_ON); |
| 60 | + writel(0xffffffff, EIP197_HIA_GEN_CFG(priv) + EIP197_FORCE_CLOCK_ON2); |
| 61 | + } |
| 62 | + |
| 63 | return safexcel_hw_setup_cdesc_rings(priv) ?: |
| 64 | safexcel_hw_setup_rdesc_rings(priv) ?: |
| 65 | 0; |
developer | 2455c2f | 2022-10-28 17:09:32 +0800 | [diff] [blame] | 66 | @@ -1498,6 +1517,9 @@ |
developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 67 | hwopt = readl(EIP197_GLOBAL(priv) + EIP197_OPTIONS); |
| 68 | hiaopt = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_OPTIONS); |
| 69 | |
| 70 | + priv->hwconfig.icever = 0; |
| 71 | + priv->hwconfig.ocever = 0; |
| 72 | + priv->hwconfig.psever = 0; |
| 73 | if (priv->flags & SAFEXCEL_HW_EIP197) { |
| 74 | /* EIP197 */ |
| 75 | peopt = readl(EIP197_PE(priv) + EIP197_PE_OPTIONS(0)); |
developer | 2455c2f | 2022-10-28 17:09:32 +0800 | [diff] [blame] | 76 | @@ -1516,8 +1538,37 @@ |
developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 77 | EIP197_N_RINGS_MASK; |
| 78 | if (hiaopt & EIP197_HIA_OPT_HAS_PE_ARB) |
| 79 | priv->flags |= EIP197_PE_ARB; |
| 80 | - if (EIP206_OPT_ICE_TYPE(peopt) == 1) |
| 81 | + if (EIP206_OPT_ICE_TYPE(peopt) == 1) { |
| 82 | priv->flags |= EIP197_ICE; |
| 83 | + /* Detect ICE EIP207 class. engine and version */ |
| 84 | + version = readl(EIP197_PE(priv) + |
| 85 | + EIP197_PE_ICE_VERSION(0)); |
| 86 | + if (EIP197_REG_LO16(version) != EIP207_VERSION_LE) { |
| 87 | + dev_err(dev, "EIP%d: ICE EIP207 not detected.\n", |
| 88 | + peid); |
| 89 | + return -ENODEV; |
| 90 | + } |
| 91 | + priv->hwconfig.icever = EIP197_VERSION_MASK(version); |
| 92 | + } |
| 93 | + if (EIP206_OPT_OCE_TYPE(peopt) == 1) { |
| 94 | + priv->flags |= EIP197_OCE; |
| 95 | + /* Detect EIP96PP packet stream editor and version */ |
| 96 | + version = readl(EIP197_PE(priv) + EIP197_PE_PSE_VERSION(0)); |
| 97 | + if (EIP197_REG_LO16(version) != EIP96_VERSION_LE) { |
| 98 | + dev_err(dev, "EIP%d: EIP96PP not detected.\n", peid); |
| 99 | + return -ENODEV; |
| 100 | + } |
| 101 | + priv->hwconfig.psever = EIP197_VERSION_MASK(version); |
| 102 | + /* Detect OCE EIP207 class. engine and version */ |
| 103 | + version = readl(EIP197_PE(priv) + |
| 104 | + EIP197_PE_ICE_VERSION(0)); |
| 105 | + if (EIP197_REG_LO16(version) != EIP207_VERSION_LE) { |
| 106 | + dev_err(dev, "EIP%d: OCE EIP207 not detected.\n", |
| 107 | + peid); |
| 108 | + return -ENODEV; |
| 109 | + } |
| 110 | + priv->hwconfig.ocever = EIP197_VERSION_MASK(version); |
| 111 | + } |
| 112 | /* If not a full TRC, then assume simple TRC */ |
| 113 | if (!(hwopt & EIP197_OPT_HAS_TRC)) |
| 114 | priv->flags |= EIP197_SIMPLE_TRC; |
developer | 2455c2f | 2022-10-28 17:09:32 +0800 | [diff] [blame] | 115 | @@ -1555,13 +1606,14 @@ |
developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 116 | EIP197_PE_EIP96_OPTIONS(0)); |
| 117 | |
| 118 | /* Print single info line describing what we just detected */ |
| 119 | - dev_info(priv->dev, "EIP%d:%x(%d,%d,%d,%d)-HIA:%x(%d,%d,%d),PE:%x/%x,alg:%08x\n", |
| 120 | + 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", |
| 121 | peid, priv->hwconfig.hwver, hwctg, priv->hwconfig.hwnumpes, |
| 122 | priv->hwconfig.hwnumrings, priv->hwconfig.hwnumraic, |
| 123 | priv->hwconfig.hiaver, priv->hwconfig.hwdataw, |
| 124 | priv->hwconfig.hwcfsize, priv->hwconfig.hwrfsize, |
| 125 | priv->hwconfig.ppver, priv->hwconfig.pever, |
| 126 | - priv->hwconfig.algo_flags); |
| 127 | + priv->hwconfig.algo_flags, priv->hwconfig.icever, |
| 128 | + priv->hwconfig.ocever, priv->hwconfig.psever); |
| 129 | |
| 130 | safexcel_configure(priv); |
| 131 | |
developer | 2455c2f | 2022-10-28 17:09:32 +0800 | [diff] [blame] | 132 | @@ -1690,6 +1742,7 @@ |
developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 133 | { |
| 134 | struct device *dev = &pdev->dev; |
| 135 | struct safexcel_crypto_priv *priv; |
| 136 | + struct resource *res; |
| 137 | int ret; |
| 138 | |
| 139 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
developer | 2455c2f | 2022-10-28 17:09:32 +0800 | [diff] [blame] | 140 | @@ -1701,7 +1754,11 @@ |
developer | a556978 | 2022-05-06 11:04:59 +0800 | [diff] [blame] | 141 | |
| 142 | platform_set_drvdata(pdev, priv); |
| 143 | |
| 144 | - priv->base = devm_platform_ioremap_resource(pdev, 0); |
| 145 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 146 | + if (!res) |
| 147 | + return -EINVAL; |
| 148 | + |
| 149 | + priv->base = devm_ioremap(dev, res->start, resource_size(res)); |
| 150 | if (IS_ERR(priv->base)) { |
| 151 | dev_err(dev, "failed to get resource\n"); |
| 152 | return PTR_ERR(priv->base); |
| 153 | --- a/drivers/crypto/inside-secure/safexcel.h |
| 154 | +++ b/drivers/crypto/inside-secure/safexcel.h |
| 155 | @@ -22,6 +22,7 @@ |
| 156 | #define EIP96_VERSION_LE 0x9f60 |
| 157 | #define EIP201_VERSION_LE 0x36c9 |
| 158 | #define EIP206_VERSION_LE 0x31ce |
| 159 | +#define EIP207_VERSION_LE 0x30cf |
| 160 | #define EIP197_REG_LO16(reg) (reg & 0xffff) |
| 161 | #define EIP197_REG_HI16(reg) ((reg >> 16) & 0xffff) |
| 162 | #define EIP197_VERSION_MASK(reg) ((reg >> 16) & 0xfff) |
| 163 | @@ -34,6 +35,7 @@ |
| 164 | |
| 165 | /* EIP206 OPTIONS ENCODING */ |
| 166 | #define EIP206_OPT_ICE_TYPE(n) ((n>>8)&3) |
| 167 | +#define EIP206_OPT_OCE_TYPE(n) ((n>>10)&3) |
| 168 | |
| 169 | /* EIP197 OPTIONS ENCODING */ |
| 170 | #define EIP197_OPT_HAS_TRC BIT(31) |
| 171 | @@ -168,6 +170,7 @@ |
| 172 | #define EIP197_PE_ICE_FPP_CTRL(n) (0x0d80 + (0x2000 * (n))) |
| 173 | #define EIP197_PE_ICE_PPTF_CTRL(n) (0x0e00 + (0x2000 * (n))) |
| 174 | #define EIP197_PE_ICE_RAM_CTRL(n) (0x0ff0 + (0x2000 * (n))) |
| 175 | +#define EIP197_PE_ICE_VERSION(n) (0x0ffc + (0x2000 * (n))) |
| 176 | #define EIP197_PE_EIP96_TOKEN_CTRL(n) (0x1000 + (0x2000 * (n))) |
| 177 | #define EIP197_PE_EIP96_FUNCTION_EN(n) (0x1004 + (0x2000 * (n))) |
| 178 | #define EIP197_PE_EIP96_CONTEXT_CTRL(n) (0x1008 + (0x2000 * (n))) |
| 179 | @@ -176,10 +179,15 @@ |
| 180 | #define EIP197_PE_EIP96_FUNCTION2_EN(n) (0x1030 + (0x2000 * (n))) |
| 181 | #define EIP197_PE_EIP96_OPTIONS(n) (0x13f8 + (0x2000 * (n))) |
| 182 | #define EIP197_PE_EIP96_VERSION(n) (0x13fc + (0x2000 * (n))) |
| 183 | +#define EIP197_PE_OCE_VERSION(n) (0x1bfc + (0x2000 * (n))) |
| 184 | #define EIP197_PE_OUT_DBUF_THRES(n) (0x1c00 + (0x2000 * (n))) |
| 185 | #define EIP197_PE_OUT_TBUF_THRES(n) (0x1d00 + (0x2000 * (n))) |
| 186 | +#define EIP197_PE_PSE_VERSION(n) (0x1efc + (0x2000 * (n))) |
| 187 | +#define EIP197_PE_DEBUG(n) (0x1ff4 + (0x2000 * (n))) |
| 188 | #define EIP197_PE_OPTIONS(n) (0x1ff8 + (0x2000 * (n))) |
| 189 | #define EIP197_PE_VERSION(n) (0x1ffc + (0x2000 * (n))) |
| 190 | +#define EIP197_FORCE_CLOCK_ON2 0xffd8 |
| 191 | +#define EIP197_FORCE_CLOCK_ON 0xffe8 |
| 192 | #define EIP197_MST_CTRL 0xfff4 |
| 193 | #define EIP197_OPTIONS 0xfff8 |
| 194 | #define EIP197_VERSION 0xfffc |
| 195 | @@ -353,6 +361,9 @@ |
| 196 | /* EIP197_PE_EIP96_TOKEN_CTRL2 */ |
| 197 | #define EIP197_PE_EIP96_TOKEN_CTRL2_CTX_DONE BIT(3) |
| 198 | |
| 199 | +/* EIP197_PE_DEBUG */ |
| 200 | +#define EIP197_DEBUG_OCE_BYPASS BIT(1) |
| 201 | + |
| 202 | /* EIP197_STRC_CONFIG */ |
| 203 | #define EIP197_STRC_CONFIG_INIT BIT(31) |
| 204 | #define EIP197_STRC_CONFIG_LARGE_REC(s) (s<<8) |
| 205 | @@ -777,6 +788,7 @@ |
| 206 | EIP197_PE_ARB = BIT(2), |
| 207 | EIP197_ICE = BIT(3), |
| 208 | EIP197_SIMPLE_TRC = BIT(4), |
| 209 | + EIP197_OCE = BIT(5), |
| 210 | }; |
| 211 | |
| 212 | struct safexcel_hwconfig { |
| 213 | @@ -784,7 +796,10 @@ |
| 214 | int hwver; |
| 215 | int hiaver; |
| 216 | int ppver; |
| 217 | + int icever; |
| 218 | int pever; |
| 219 | + int ocever; |
| 220 | + int psever; |
| 221 | int hwdataw; |
| 222 | int hwcfsize; |
| 223 | int hwrfsize; |