Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1 | /* |
| 2 | * talitos - Freescale Integrated Security Engine (SEC) device driver |
| 3 | * |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 4 | * Copyright (c) 2008-2011 Freescale Semiconductor, Inc. |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 5 | * |
| 6 | * Scatterlist Crypto API glue code copied from files with the following: |
| 7 | * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au> |
| 8 | * |
| 9 | * Crypto algorithm registration code copied from hifn driver: |
| 10 | * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru> |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/mod_devicetable.h> |
| 31 | #include <linux/device.h> |
| 32 | #include <linux/interrupt.h> |
| 33 | #include <linux/crypto.h> |
| 34 | #include <linux/hw_random.h> |
Rob Herring | 5af5073 | 2013-09-17 14:28:33 -0500 | [diff] [blame] | 35 | #include <linux/of_address.h> |
| 36 | #include <linux/of_irq.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 37 | #include <linux/of_platform.h> |
| 38 | #include <linux/dma-mapping.h> |
| 39 | #include <linux/io.h> |
| 40 | #include <linux/spinlock.h> |
| 41 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 43 | |
| 44 | #include <crypto/algapi.h> |
| 45 | #include <crypto/aes.h> |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 46 | #include <crypto/des.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 47 | #include <crypto/sha.h> |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 48 | #include <crypto/md5.h> |
Herbert Xu | e98014a | 2015-05-11 17:47:48 +0800 | [diff] [blame] | 49 | #include <crypto/internal/aead.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 50 | #include <crypto/authenc.h> |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 51 | #include <crypto/skcipher.h> |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 52 | #include <crypto/hash.h> |
| 53 | #include <crypto/internal/hash.h> |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 54 | #include <crypto/scatterwalk.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 55 | |
| 56 | #include "talitos.h" |
| 57 | |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 58 | static void to_talitos_ptr(struct talitos_ptr *ptr, dma_addr_t dma_addr, |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 59 | unsigned int len, bool is_sec1) |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 60 | { |
LEROY Christophe | edc6bd6 | 2015-04-17 16:31:53 +0200 | [diff] [blame] | 61 | ptr->ptr = cpu_to_be32(lower_32_bits(dma_addr)); |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 62 | if (is_sec1) { |
| 63 | ptr->len1 = cpu_to_be16(len); |
| 64 | } else { |
| 65 | ptr->len = cpu_to_be16(len); |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 66 | ptr->eptr = upper_32_bits(dma_addr); |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 67 | } |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 68 | } |
| 69 | |
Horia Geant? | 340ff60 | 2016-04-19 20:33:48 +0300 | [diff] [blame] | 70 | static void copy_talitos_ptr(struct talitos_ptr *dst_ptr, |
| 71 | struct talitos_ptr *src_ptr, bool is_sec1) |
| 72 | { |
| 73 | dst_ptr->ptr = src_ptr->ptr; |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 74 | if (is_sec1) { |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 75 | dst_ptr->len1 = src_ptr->len1; |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 76 | } else { |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 77 | dst_ptr->len = src_ptr->len; |
| 78 | dst_ptr->eptr = src_ptr->eptr; |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 79 | } |
LEROY Christophe | 538caf8 | 2015-04-17 16:31:59 +0200 | [diff] [blame] | 80 | } |
| 81 | |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 82 | static unsigned short from_talitos_ptr_len(struct talitos_ptr *ptr, |
| 83 | bool is_sec1) |
LEROY Christophe | 538caf8 | 2015-04-17 16:31:59 +0200 | [diff] [blame] | 84 | { |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 85 | if (is_sec1) |
| 86 | return be16_to_cpu(ptr->len1); |
| 87 | else |
| 88 | return be16_to_cpu(ptr->len); |
LEROY Christophe | 538caf8 | 2015-04-17 16:31:59 +0200 | [diff] [blame] | 89 | } |
| 90 | |
LEROY Christophe | b096b54 | 2016-06-06 13:20:34 +0200 | [diff] [blame] | 91 | static void to_talitos_ptr_ext_set(struct talitos_ptr *ptr, u8 val, |
| 92 | bool is_sec1) |
LEROY Christophe | 185eb79 | 2015-04-17 16:31:55 +0200 | [diff] [blame] | 93 | { |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 94 | if (!is_sec1) |
LEROY Christophe | b096b54 | 2016-06-06 13:20:34 +0200 | [diff] [blame] | 95 | ptr->j_extent = val; |
| 96 | } |
| 97 | |
| 98 | static void to_talitos_ptr_ext_or(struct talitos_ptr *ptr, u8 val, bool is_sec1) |
| 99 | { |
| 100 | if (!is_sec1) |
| 101 | ptr->j_extent |= val; |
LEROY Christophe | 185eb79 | 2015-04-17 16:31:55 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 104 | /* |
| 105 | * map virtual single (contiguous) pointer to h/w descriptor pointer |
| 106 | */ |
| 107 | static void map_single_talitos_ptr(struct device *dev, |
LEROY Christophe | edc6bd6 | 2015-04-17 16:31:53 +0200 | [diff] [blame] | 108 | struct talitos_ptr *ptr, |
Horia Geant? | 42e8b0d | 2015-05-11 20:04:56 +0300 | [diff] [blame] | 109 | unsigned int len, void *data, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 110 | enum dma_data_direction dir) |
| 111 | { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 112 | dma_addr_t dma_addr = dma_map_single(dev, data, len, dir); |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 113 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 114 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 115 | |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 116 | to_talitos_ptr(ptr, dma_addr, len, is_sec1); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* |
| 120 | * unmap bus single (contiguous) h/w descriptor pointer |
| 121 | */ |
| 122 | static void unmap_single_talitos_ptr(struct device *dev, |
LEROY Christophe | edc6bd6 | 2015-04-17 16:31:53 +0200 | [diff] [blame] | 123 | struct talitos_ptr *ptr, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 124 | enum dma_data_direction dir) |
| 125 | { |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 126 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 127 | bool is_sec1 = has_ftr_sec1(priv); |
| 128 | |
LEROY Christophe | edc6bd6 | 2015-04-17 16:31:53 +0200 | [diff] [blame] | 129 | dma_unmap_single(dev, be32_to_cpu(ptr->ptr), |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 130 | from_talitos_ptr_len(ptr, is_sec1), dir); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static int reset_channel(struct device *dev, int ch) |
| 134 | { |
| 135 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 136 | unsigned int timeout = TALITOS_TIMEOUT; |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 137 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 138 | |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 139 | if (is_sec1) { |
| 140 | setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO, |
| 141 | TALITOS1_CCCR_LO_RESET); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 142 | |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 143 | while ((in_be32(priv->chan[ch].reg + TALITOS_CCCR_LO) & |
| 144 | TALITOS1_CCCR_LO_RESET) && --timeout) |
| 145 | cpu_relax(); |
| 146 | } else { |
| 147 | setbits32(priv->chan[ch].reg + TALITOS_CCCR, |
| 148 | TALITOS2_CCCR_RESET); |
| 149 | |
| 150 | while ((in_be32(priv->chan[ch].reg + TALITOS_CCCR) & |
| 151 | TALITOS2_CCCR_RESET) && --timeout) |
| 152 | cpu_relax(); |
| 153 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 154 | |
| 155 | if (timeout == 0) { |
| 156 | dev_err(dev, "failed to reset channel %d\n", ch); |
| 157 | return -EIO; |
| 158 | } |
| 159 | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 160 | /* set 36-bit addressing, done writeback enable and done IRQ enable */ |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 161 | setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO, TALITOS_CCCR_LO_EAE | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 162 | TALITOS_CCCR_LO_CDWE | TALITOS_CCCR_LO_CDIE); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 163 | /* enable chaining descriptors */ |
| 164 | if (is_sec1) |
| 165 | setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO, |
| 166 | TALITOS_CCCR_LO_NE); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 167 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 168 | /* and ICCR writeback, if available */ |
| 169 | if (priv->features & TALITOS_FTR_HW_AUTH_CHECK) |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 170 | setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO, |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 171 | TALITOS_CCCR_LO_IWSE); |
| 172 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static int reset_device(struct device *dev) |
| 177 | { |
| 178 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 179 | unsigned int timeout = TALITOS_TIMEOUT; |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 180 | bool is_sec1 = has_ftr_sec1(priv); |
| 181 | u32 mcr = is_sec1 ? TALITOS1_MCR_SWR : TALITOS2_MCR_SWR; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 182 | |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 183 | setbits32(priv->reg + TALITOS_MCR, mcr); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 184 | |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 185 | while ((in_be32(priv->reg + TALITOS_MCR) & mcr) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 186 | && --timeout) |
| 187 | cpu_relax(); |
| 188 | |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 189 | if (priv->irq[1]) { |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 190 | mcr = TALITOS_MCR_RCA1 | TALITOS_MCR_RCA3; |
| 191 | setbits32(priv->reg + TALITOS_MCR, mcr); |
| 192 | } |
| 193 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 194 | if (timeout == 0) { |
| 195 | dev_err(dev, "failed to reset device\n"); |
| 196 | return -EIO; |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * Reset and initialize the device |
| 204 | */ |
| 205 | static int init_device(struct device *dev) |
| 206 | { |
| 207 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 208 | int ch, err; |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 209 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * Master reset |
| 213 | * errata documentation: warning: certain SEC interrupts |
| 214 | * are not fully cleared by writing the MCR:SWR bit, |
| 215 | * set bit twice to completely reset |
| 216 | */ |
| 217 | err = reset_device(dev); |
| 218 | if (err) |
| 219 | return err; |
| 220 | |
| 221 | err = reset_device(dev); |
| 222 | if (err) |
| 223 | return err; |
| 224 | |
| 225 | /* reset channels */ |
| 226 | for (ch = 0; ch < priv->num_channels; ch++) { |
| 227 | err = reset_channel(dev, ch); |
| 228 | if (err) |
| 229 | return err; |
| 230 | } |
| 231 | |
| 232 | /* enable channel done and error interrupts */ |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 233 | if (is_sec1) { |
| 234 | clrbits32(priv->reg + TALITOS_IMR, TALITOS1_IMR_INIT); |
| 235 | clrbits32(priv->reg + TALITOS_IMR_LO, TALITOS1_IMR_LO_INIT); |
| 236 | /* disable parity error check in DEU (erroneous? test vect.) */ |
| 237 | setbits32(priv->reg_deu + TALITOS_EUICR, TALITOS1_DEUICR_KPE); |
| 238 | } else { |
| 239 | setbits32(priv->reg + TALITOS_IMR, TALITOS2_IMR_INIT); |
| 240 | setbits32(priv->reg + TALITOS_IMR_LO, TALITOS2_IMR_LO_INIT); |
| 241 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 242 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 243 | /* disable integrity check error interrupts (use writeback instead) */ |
| 244 | if (priv->features & TALITOS_FTR_HW_AUTH_CHECK) |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 245 | setbits32(priv->reg_mdeu + TALITOS_EUICR_LO, |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 246 | TALITOS_MDEUICR_LO_ICE); |
| 247 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * talitos_submit - submits a descriptor to the device for processing |
| 253 | * @dev: the SEC device to be used |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 254 | * @ch: the SEC device channel to be used |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 255 | * @desc: the descriptor to be processed by the device |
| 256 | * @callback: whom to call when processing is complete |
| 257 | * @context: a handle for use by caller (optional) |
| 258 | * |
| 259 | * desc must contain valid dma-mapped (bus physical) address pointers. |
| 260 | * callback must check err and feedback in descriptor header |
| 261 | * for device processing status. |
| 262 | */ |
Horia Geanta | 865d506 | 2012-07-03 19:16:52 +0300 | [diff] [blame] | 263 | int talitos_submit(struct device *dev, int ch, struct talitos_desc *desc, |
| 264 | void (*callback)(struct device *dev, |
| 265 | struct talitos_desc *desc, |
| 266 | void *context, int error), |
| 267 | void *context) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 268 | { |
| 269 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 270 | struct talitos_request *request; |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 271 | unsigned long flags; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 272 | int head; |
LEROY Christophe | 7d607c6a | 2015-04-17 16:32:09 +0200 | [diff] [blame] | 273 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 274 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 275 | spin_lock_irqsave(&priv->chan[ch].head_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 276 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 277 | if (!atomic_inc_not_zero(&priv->chan[ch].submit_count)) { |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 278 | /* h/w fifo is full */ |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 279 | spin_unlock_irqrestore(&priv->chan[ch].head_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 280 | return -EAGAIN; |
| 281 | } |
| 282 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 283 | head = priv->chan[ch].head; |
| 284 | request = &priv->chan[ch].fifo[head]; |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 285 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 286 | /* map descriptor and save caller data */ |
LEROY Christophe | 7d607c6a | 2015-04-17 16:32:09 +0200 | [diff] [blame] | 287 | if (is_sec1) { |
| 288 | desc->hdr1 = desc->hdr; |
LEROY Christophe | 7d607c6a | 2015-04-17 16:32:09 +0200 | [diff] [blame] | 289 | request->dma_desc = dma_map_single(dev, &desc->hdr1, |
| 290 | TALITOS_DESC_SIZE, |
| 291 | DMA_BIDIRECTIONAL); |
| 292 | } else { |
| 293 | request->dma_desc = dma_map_single(dev, desc, |
| 294 | TALITOS_DESC_SIZE, |
| 295 | DMA_BIDIRECTIONAL); |
| 296 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 297 | request->callback = callback; |
| 298 | request->context = context; |
| 299 | |
| 300 | /* increment fifo head */ |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 301 | priv->chan[ch].head = (priv->chan[ch].head + 1) & (priv->fifo_len - 1); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 302 | |
| 303 | smp_wmb(); |
| 304 | request->desc = desc; |
| 305 | |
| 306 | /* GO! */ |
| 307 | wmb(); |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 308 | out_be32(priv->chan[ch].reg + TALITOS_FF, |
| 309 | upper_32_bits(request->dma_desc)); |
| 310 | out_be32(priv->chan[ch].reg + TALITOS_FF_LO, |
Kim Phillips | a752447 | 2010-09-23 15:56:38 +0800 | [diff] [blame] | 311 | lower_32_bits(request->dma_desc)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 312 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 313 | spin_unlock_irqrestore(&priv->chan[ch].head_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 314 | |
| 315 | return -EINPROGRESS; |
| 316 | } |
Horia Geanta | 865d506 | 2012-07-03 19:16:52 +0300 | [diff] [blame] | 317 | EXPORT_SYMBOL(talitos_submit); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 318 | |
| 319 | /* |
| 320 | * process what was done, notify callback of error if not |
| 321 | */ |
| 322 | static void flush_channel(struct device *dev, int ch, int error, int reset_ch) |
| 323 | { |
| 324 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 325 | struct talitos_request *request, saved_req; |
| 326 | unsigned long flags; |
| 327 | int tail, status; |
LEROY Christophe | 7d607c6a | 2015-04-17 16:32:09 +0200 | [diff] [blame] | 328 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 329 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 330 | spin_lock_irqsave(&priv->chan[ch].tail_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 331 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 332 | tail = priv->chan[ch].tail; |
| 333 | while (priv->chan[ch].fifo[tail].desc) { |
LEROY Christophe | 7d607c6a | 2015-04-17 16:32:09 +0200 | [diff] [blame] | 334 | __be32 hdr; |
| 335 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 336 | request = &priv->chan[ch].fifo[tail]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 337 | |
| 338 | /* descriptors with their done bits set don't get the error */ |
| 339 | rmb(); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 340 | if (!is_sec1) |
| 341 | hdr = request->desc->hdr; |
| 342 | else if (request->desc->next_desc) |
| 343 | hdr = (request->desc + 1)->hdr1; |
| 344 | else |
| 345 | hdr = request->desc->hdr1; |
LEROY Christophe | 7d607c6a | 2015-04-17 16:32:09 +0200 | [diff] [blame] | 346 | |
| 347 | if ((hdr & DESC_HDR_DONE) == DESC_HDR_DONE) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 348 | status = 0; |
Lee Nipper | ca38a81 | 2008-12-20 17:09:25 +1100 | [diff] [blame] | 349 | else |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 350 | if (!error) |
| 351 | break; |
| 352 | else |
| 353 | status = error; |
| 354 | |
| 355 | dma_unmap_single(dev, request->dma_desc, |
LEROY Christophe | 7d607c6a | 2015-04-17 16:32:09 +0200 | [diff] [blame] | 356 | TALITOS_DESC_SIZE, |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 357 | DMA_BIDIRECTIONAL); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 358 | |
| 359 | /* copy entries so we can call callback outside lock */ |
| 360 | saved_req.desc = request->desc; |
| 361 | saved_req.callback = request->callback; |
| 362 | saved_req.context = request->context; |
| 363 | |
| 364 | /* release request entry in fifo */ |
| 365 | smp_wmb(); |
| 366 | request->desc = NULL; |
| 367 | |
| 368 | /* increment fifo tail */ |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 369 | priv->chan[ch].tail = (tail + 1) & (priv->fifo_len - 1); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 370 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 371 | spin_unlock_irqrestore(&priv->chan[ch].tail_lock, flags); |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 372 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 373 | atomic_dec(&priv->chan[ch].submit_count); |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 374 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 375 | saved_req.callback(dev, saved_req.desc, saved_req.context, |
| 376 | status); |
| 377 | /* channel may resume processing in single desc error case */ |
| 378 | if (error && !reset_ch && status == error) |
| 379 | return; |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 380 | spin_lock_irqsave(&priv->chan[ch].tail_lock, flags); |
| 381 | tail = priv->chan[ch].tail; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 382 | } |
| 383 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 384 | spin_unlock_irqrestore(&priv->chan[ch].tail_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* |
| 388 | * process completed requests for channels that have done status |
| 389 | */ |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 390 | #define DEF_TALITOS1_DONE(name, ch_done_mask) \ |
| 391 | static void talitos1_done_##name(unsigned long data) \ |
| 392 | { \ |
| 393 | struct device *dev = (struct device *)data; \ |
| 394 | struct talitos_private *priv = dev_get_drvdata(dev); \ |
| 395 | unsigned long flags; \ |
| 396 | \ |
| 397 | if (ch_done_mask & 0x10000000) \ |
| 398 | flush_channel(dev, 0, 0, 0); \ |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 399 | if (ch_done_mask & 0x40000000) \ |
| 400 | flush_channel(dev, 1, 0, 0); \ |
| 401 | if (ch_done_mask & 0x00010000) \ |
| 402 | flush_channel(dev, 2, 0, 0); \ |
| 403 | if (ch_done_mask & 0x00040000) \ |
| 404 | flush_channel(dev, 3, 0, 0); \ |
| 405 | \ |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 406 | /* At this point, all completed channels have been processed */ \ |
| 407 | /* Unmask done interrupts for channels completed later on. */ \ |
| 408 | spin_lock_irqsave(&priv->reg_lock, flags); \ |
| 409 | clrbits32(priv->reg + TALITOS_IMR, ch_done_mask); \ |
| 410 | clrbits32(priv->reg + TALITOS_IMR_LO, TALITOS1_IMR_LO_INIT); \ |
| 411 | spin_unlock_irqrestore(&priv->reg_lock, flags); \ |
| 412 | } |
| 413 | |
| 414 | DEF_TALITOS1_DONE(4ch, TALITOS1_ISR_4CHDONE) |
LEROY Christophe | 9c02e28 | 2017-10-06 15:04:55 +0200 | [diff] [blame] | 415 | DEF_TALITOS1_DONE(ch0, TALITOS1_ISR_CH_0_DONE) |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 416 | |
| 417 | #define DEF_TALITOS2_DONE(name, ch_done_mask) \ |
| 418 | static void talitos2_done_##name(unsigned long data) \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 419 | { \ |
| 420 | struct device *dev = (struct device *)data; \ |
| 421 | struct talitos_private *priv = dev_get_drvdata(dev); \ |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 422 | unsigned long flags; \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 423 | \ |
| 424 | if (ch_done_mask & 1) \ |
| 425 | flush_channel(dev, 0, 0, 0); \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 426 | if (ch_done_mask & (1 << 2)) \ |
| 427 | flush_channel(dev, 1, 0, 0); \ |
| 428 | if (ch_done_mask & (1 << 4)) \ |
| 429 | flush_channel(dev, 2, 0, 0); \ |
| 430 | if (ch_done_mask & (1 << 6)) \ |
| 431 | flush_channel(dev, 3, 0, 0); \ |
| 432 | \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 433 | /* At this point, all completed channels have been processed */ \ |
| 434 | /* Unmask done interrupts for channels completed later on. */ \ |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 435 | spin_lock_irqsave(&priv->reg_lock, flags); \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 436 | setbits32(priv->reg + TALITOS_IMR, ch_done_mask); \ |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 437 | setbits32(priv->reg + TALITOS_IMR_LO, TALITOS2_IMR_LO_INIT); \ |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 438 | spin_unlock_irqrestore(&priv->reg_lock, flags); \ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 439 | } |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 440 | |
| 441 | DEF_TALITOS2_DONE(4ch, TALITOS2_ISR_4CHDONE) |
LEROY Christophe | 9c02e28 | 2017-10-06 15:04:55 +0200 | [diff] [blame] | 442 | DEF_TALITOS2_DONE(ch0, TALITOS2_ISR_CH_0_DONE) |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 443 | DEF_TALITOS2_DONE(ch0_2, TALITOS2_ISR_CH_0_2_DONE) |
| 444 | DEF_TALITOS2_DONE(ch1_3, TALITOS2_ISR_CH_1_3_DONE) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * locate current (offending) descriptor |
| 448 | */ |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 449 | static u32 current_desc_hdr(struct device *dev, int ch) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 450 | { |
| 451 | struct talitos_private *priv = dev_get_drvdata(dev); |
Horia Geanta | b62ffd8 | 2013-11-13 12:20:37 +0200 | [diff] [blame] | 452 | int tail, iter; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 453 | dma_addr_t cur_desc; |
| 454 | |
Horia Geanta | b62ffd8 | 2013-11-13 12:20:37 +0200 | [diff] [blame] | 455 | cur_desc = ((u64)in_be32(priv->chan[ch].reg + TALITOS_CDPR)) << 32; |
| 456 | cur_desc |= in_be32(priv->chan[ch].reg + TALITOS_CDPR_LO); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 457 | |
Horia Geanta | b62ffd8 | 2013-11-13 12:20:37 +0200 | [diff] [blame] | 458 | if (!cur_desc) { |
| 459 | dev_err(dev, "CDPR is NULL, giving up search for offending descriptor\n"); |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | tail = priv->chan[ch].tail; |
| 464 | |
| 465 | iter = tail; |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 466 | while (priv->chan[ch].fifo[iter].dma_desc != cur_desc && |
| 467 | priv->chan[ch].fifo[iter].desc->next_desc != cur_desc) { |
Horia Geanta | b62ffd8 | 2013-11-13 12:20:37 +0200 | [diff] [blame] | 468 | iter = (iter + 1) & (priv->fifo_len - 1); |
| 469 | if (iter == tail) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 470 | dev_err(dev, "couldn't locate current descriptor\n"); |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 471 | return 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 475 | if (priv->chan[ch].fifo[iter].desc->next_desc == cur_desc) |
| 476 | return (priv->chan[ch].fifo[iter].desc + 1)->hdr; |
| 477 | |
Horia Geanta | b62ffd8 | 2013-11-13 12:20:37 +0200 | [diff] [blame] | 478 | return priv->chan[ch].fifo[iter].desc->hdr; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /* |
| 482 | * user diagnostics; report root cause of error based on execution unit status |
| 483 | */ |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 484 | static void report_eu_error(struct device *dev, int ch, u32 desc_hdr) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 485 | { |
| 486 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 487 | int i; |
| 488 | |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 489 | if (!desc_hdr) |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 490 | desc_hdr = in_be32(priv->chan[ch].reg + TALITOS_DESCBUF); |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 491 | |
| 492 | switch (desc_hdr & DESC_HDR_SEL0_MASK) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 493 | case DESC_HDR_SEL0_AFEU: |
| 494 | dev_err(dev, "AFEUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 495 | in_be32(priv->reg_afeu + TALITOS_EUISR), |
| 496 | in_be32(priv->reg_afeu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 497 | break; |
| 498 | case DESC_HDR_SEL0_DEU: |
| 499 | dev_err(dev, "DEUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 500 | in_be32(priv->reg_deu + TALITOS_EUISR), |
| 501 | in_be32(priv->reg_deu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 502 | break; |
| 503 | case DESC_HDR_SEL0_MDEUA: |
| 504 | case DESC_HDR_SEL0_MDEUB: |
| 505 | dev_err(dev, "MDEUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 506 | in_be32(priv->reg_mdeu + TALITOS_EUISR), |
| 507 | in_be32(priv->reg_mdeu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 508 | break; |
| 509 | case DESC_HDR_SEL0_RNG: |
| 510 | dev_err(dev, "RNGUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 511 | in_be32(priv->reg_rngu + TALITOS_ISR), |
| 512 | in_be32(priv->reg_rngu + TALITOS_ISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 513 | break; |
| 514 | case DESC_HDR_SEL0_PKEU: |
| 515 | dev_err(dev, "PKEUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 516 | in_be32(priv->reg_pkeu + TALITOS_EUISR), |
| 517 | in_be32(priv->reg_pkeu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 518 | break; |
| 519 | case DESC_HDR_SEL0_AESU: |
| 520 | dev_err(dev, "AESUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 521 | in_be32(priv->reg_aesu + TALITOS_EUISR), |
| 522 | in_be32(priv->reg_aesu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 523 | break; |
| 524 | case DESC_HDR_SEL0_CRCU: |
| 525 | dev_err(dev, "CRCUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 526 | in_be32(priv->reg_crcu + TALITOS_EUISR), |
| 527 | in_be32(priv->reg_crcu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 528 | break; |
| 529 | case DESC_HDR_SEL0_KEU: |
| 530 | dev_err(dev, "KEUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 531 | in_be32(priv->reg_pkeu + TALITOS_EUISR), |
| 532 | in_be32(priv->reg_pkeu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 533 | break; |
| 534 | } |
| 535 | |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 536 | switch (desc_hdr & DESC_HDR_SEL1_MASK) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 537 | case DESC_HDR_SEL1_MDEUA: |
| 538 | case DESC_HDR_SEL1_MDEUB: |
| 539 | dev_err(dev, "MDEUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 540 | in_be32(priv->reg_mdeu + TALITOS_EUISR), |
| 541 | in_be32(priv->reg_mdeu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 542 | break; |
| 543 | case DESC_HDR_SEL1_CRCU: |
| 544 | dev_err(dev, "CRCUISR 0x%08x_%08x\n", |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 545 | in_be32(priv->reg_crcu + TALITOS_EUISR), |
| 546 | in_be32(priv->reg_crcu + TALITOS_EUISR_LO)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 547 | break; |
| 548 | } |
| 549 | |
| 550 | for (i = 0; i < 8; i++) |
| 551 | dev_err(dev, "DESCBUF 0x%08x_%08x\n", |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 552 | in_be32(priv->chan[ch].reg + TALITOS_DESCBUF + 8*i), |
| 553 | in_be32(priv->chan[ch].reg + TALITOS_DESCBUF_LO + 8*i)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /* |
| 557 | * recover from error interrupts |
| 558 | */ |
Kim Phillips | 5e718a0 | 2011-12-12 14:59:12 -0600 | [diff] [blame] | 559 | static void talitos_error(struct device *dev, u32 isr, u32 isr_lo) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 560 | { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 561 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 562 | unsigned int timeout = TALITOS_TIMEOUT; |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 563 | int ch, error, reset_dev = 0; |
Horia Geant? | 42e8b0d | 2015-05-11 20:04:56 +0300 | [diff] [blame] | 564 | u32 v_lo; |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 565 | bool is_sec1 = has_ftr_sec1(priv); |
| 566 | int reset_ch = is_sec1 ? 1 : 0; /* only SEC2 supports continuation */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 567 | |
| 568 | for (ch = 0; ch < priv->num_channels; ch++) { |
| 569 | /* skip channels without errors */ |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 570 | if (is_sec1) { |
| 571 | /* bits 29, 31, 17, 19 */ |
| 572 | if (!(isr & (1 << (29 + (ch & 1) * 2 - (ch & 2) * 6)))) |
| 573 | continue; |
| 574 | } else { |
| 575 | if (!(isr & (1 << (ch * 2 + 1)))) |
| 576 | continue; |
| 577 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 578 | |
| 579 | error = -EINVAL; |
| 580 | |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 581 | v_lo = in_be32(priv->chan[ch].reg + TALITOS_CCPSR_LO); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 582 | |
| 583 | if (v_lo & TALITOS_CCPSR_LO_DOF) { |
| 584 | dev_err(dev, "double fetch fifo overflow error\n"); |
| 585 | error = -EAGAIN; |
| 586 | reset_ch = 1; |
| 587 | } |
| 588 | if (v_lo & TALITOS_CCPSR_LO_SOF) { |
| 589 | /* h/w dropped descriptor */ |
| 590 | dev_err(dev, "single fetch fifo overflow error\n"); |
| 591 | error = -EAGAIN; |
| 592 | } |
| 593 | if (v_lo & TALITOS_CCPSR_LO_MDTE) |
| 594 | dev_err(dev, "master data transfer error\n"); |
| 595 | if (v_lo & TALITOS_CCPSR_LO_SGDLZ) |
Colin Ian King | 4d9b3a5 | 2016-11-01 20:14:04 -0600 | [diff] [blame] | 596 | dev_err(dev, is_sec1 ? "pointer not complete error\n" |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 597 | : "s/g data length zero error\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 598 | if (v_lo & TALITOS_CCPSR_LO_FPZ) |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 599 | dev_err(dev, is_sec1 ? "parity error\n" |
| 600 | : "fetch pointer zero error\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 601 | if (v_lo & TALITOS_CCPSR_LO_IDH) |
| 602 | dev_err(dev, "illegal descriptor header error\n"); |
| 603 | if (v_lo & TALITOS_CCPSR_LO_IEU) |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 604 | dev_err(dev, is_sec1 ? "static assignment error\n" |
| 605 | : "invalid exec unit error\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 606 | if (v_lo & TALITOS_CCPSR_LO_EU) |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 607 | report_eu_error(dev, ch, current_desc_hdr(dev, ch)); |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 608 | if (!is_sec1) { |
| 609 | if (v_lo & TALITOS_CCPSR_LO_GB) |
| 610 | dev_err(dev, "gather boundary error\n"); |
| 611 | if (v_lo & TALITOS_CCPSR_LO_GRL) |
| 612 | dev_err(dev, "gather return/length error\n"); |
| 613 | if (v_lo & TALITOS_CCPSR_LO_SB) |
| 614 | dev_err(dev, "scatter boundary error\n"); |
| 615 | if (v_lo & TALITOS_CCPSR_LO_SRL) |
| 616 | dev_err(dev, "scatter return/length error\n"); |
| 617 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 618 | |
| 619 | flush_channel(dev, ch, error, reset_ch); |
| 620 | |
| 621 | if (reset_ch) { |
| 622 | reset_channel(dev, ch); |
| 623 | } else { |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 624 | setbits32(priv->chan[ch].reg + TALITOS_CCCR, |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 625 | TALITOS2_CCCR_CONT); |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 626 | setbits32(priv->chan[ch].reg + TALITOS_CCCR_LO, 0); |
| 627 | while ((in_be32(priv->chan[ch].reg + TALITOS_CCCR) & |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 628 | TALITOS2_CCCR_CONT) && --timeout) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 629 | cpu_relax(); |
| 630 | if (timeout == 0) { |
| 631 | dev_err(dev, "failed to restart channel %d\n", |
| 632 | ch); |
| 633 | reset_dev = 1; |
| 634 | } |
| 635 | } |
| 636 | } |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 637 | if (reset_dev || (is_sec1 && isr & ~TALITOS1_ISR_4CHERR) || |
| 638 | (!is_sec1 && isr & ~TALITOS2_ISR_4CHERR) || isr_lo) { |
| 639 | if (is_sec1 && (isr_lo & TALITOS1_ISR_TEA_ERR)) |
| 640 | dev_err(dev, "TEA error: ISR 0x%08x_%08x\n", |
| 641 | isr, isr_lo); |
| 642 | else |
| 643 | dev_err(dev, "done overflow, internal time out, or " |
| 644 | "rngu error: ISR 0x%08x_%08x\n", isr, isr_lo); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 645 | |
| 646 | /* purge request queues */ |
| 647 | for (ch = 0; ch < priv->num_channels; ch++) |
| 648 | flush_channel(dev, ch, -EIO, 1); |
| 649 | |
| 650 | /* reset and reinitialize the device */ |
| 651 | init_device(dev); |
| 652 | } |
| 653 | } |
| 654 | |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 655 | #define DEF_TALITOS1_INTERRUPT(name, ch_done_mask, ch_err_mask, tlet) \ |
| 656 | static irqreturn_t talitos1_interrupt_##name(int irq, void *data) \ |
| 657 | { \ |
| 658 | struct device *dev = data; \ |
| 659 | struct talitos_private *priv = dev_get_drvdata(dev); \ |
| 660 | u32 isr, isr_lo; \ |
| 661 | unsigned long flags; \ |
| 662 | \ |
| 663 | spin_lock_irqsave(&priv->reg_lock, flags); \ |
| 664 | isr = in_be32(priv->reg + TALITOS_ISR); \ |
| 665 | isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); \ |
| 666 | /* Acknowledge interrupt */ \ |
| 667 | out_be32(priv->reg + TALITOS_ICR, isr & (ch_done_mask | ch_err_mask)); \ |
| 668 | out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); \ |
| 669 | \ |
| 670 | if (unlikely(isr & ch_err_mask || isr_lo & TALITOS1_IMR_LO_INIT)) { \ |
| 671 | spin_unlock_irqrestore(&priv->reg_lock, flags); \ |
| 672 | talitos_error(dev, isr & ch_err_mask, isr_lo); \ |
| 673 | } \ |
| 674 | else { \ |
| 675 | if (likely(isr & ch_done_mask)) { \ |
| 676 | /* mask further done interrupts. */ \ |
| 677 | setbits32(priv->reg + TALITOS_IMR, ch_done_mask); \ |
| 678 | /* done_task will unmask done interrupts at exit */ \ |
| 679 | tasklet_schedule(&priv->done_task[tlet]); \ |
| 680 | } \ |
| 681 | spin_unlock_irqrestore(&priv->reg_lock, flags); \ |
| 682 | } \ |
| 683 | \ |
| 684 | return (isr & (ch_done_mask | ch_err_mask) || isr_lo) ? IRQ_HANDLED : \ |
| 685 | IRQ_NONE; \ |
| 686 | } |
| 687 | |
| 688 | DEF_TALITOS1_INTERRUPT(4ch, TALITOS1_ISR_4CHDONE, TALITOS1_ISR_4CHERR, 0) |
| 689 | |
| 690 | #define DEF_TALITOS2_INTERRUPT(name, ch_done_mask, ch_err_mask, tlet) \ |
| 691 | static irqreturn_t talitos2_interrupt_##name(int irq, void *data) \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 692 | { \ |
| 693 | struct device *dev = data; \ |
| 694 | struct talitos_private *priv = dev_get_drvdata(dev); \ |
| 695 | u32 isr, isr_lo; \ |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 696 | unsigned long flags; \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 697 | \ |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 698 | spin_lock_irqsave(&priv->reg_lock, flags); \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 699 | isr = in_be32(priv->reg + TALITOS_ISR); \ |
| 700 | isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); \ |
| 701 | /* Acknowledge interrupt */ \ |
| 702 | out_be32(priv->reg + TALITOS_ICR, isr & (ch_done_mask | ch_err_mask)); \ |
| 703 | out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); \ |
| 704 | \ |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 705 | if (unlikely(isr & ch_err_mask || isr_lo)) { \ |
| 706 | spin_unlock_irqrestore(&priv->reg_lock, flags); \ |
| 707 | talitos_error(dev, isr & ch_err_mask, isr_lo); \ |
| 708 | } \ |
| 709 | else { \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 710 | if (likely(isr & ch_done_mask)) { \ |
| 711 | /* mask further done interrupts. */ \ |
| 712 | clrbits32(priv->reg + TALITOS_IMR, ch_done_mask); \ |
| 713 | /* done_task will unmask done interrupts at exit */ \ |
| 714 | tasklet_schedule(&priv->done_task[tlet]); \ |
| 715 | } \ |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 716 | spin_unlock_irqrestore(&priv->reg_lock, flags); \ |
| 717 | } \ |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 718 | \ |
| 719 | return (isr & (ch_done_mask | ch_err_mask) || isr_lo) ? IRQ_HANDLED : \ |
| 720 | IRQ_NONE; \ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 721 | } |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 722 | |
| 723 | DEF_TALITOS2_INTERRUPT(4ch, TALITOS2_ISR_4CHDONE, TALITOS2_ISR_4CHERR, 0) |
| 724 | DEF_TALITOS2_INTERRUPT(ch0_2, TALITOS2_ISR_CH_0_2_DONE, TALITOS2_ISR_CH_0_2_ERR, |
| 725 | 0) |
| 726 | DEF_TALITOS2_INTERRUPT(ch1_3, TALITOS2_ISR_CH_1_3_DONE, TALITOS2_ISR_CH_1_3_ERR, |
| 727 | 1) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 728 | |
| 729 | /* |
| 730 | * hwrng |
| 731 | */ |
| 732 | static int talitos_rng_data_present(struct hwrng *rng, int wait) |
| 733 | { |
| 734 | struct device *dev = (struct device *)rng->priv; |
| 735 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 736 | u32 ofl; |
| 737 | int i; |
| 738 | |
| 739 | for (i = 0; i < 20; i++) { |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 740 | ofl = in_be32(priv->reg_rngu + TALITOS_EUSR_LO) & |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 741 | TALITOS_RNGUSR_LO_OFL; |
| 742 | if (ofl || !wait) |
| 743 | break; |
| 744 | udelay(10); |
| 745 | } |
| 746 | |
| 747 | return !!ofl; |
| 748 | } |
| 749 | |
| 750 | static int talitos_rng_data_read(struct hwrng *rng, u32 *data) |
| 751 | { |
| 752 | struct device *dev = (struct device *)rng->priv; |
| 753 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 754 | |
| 755 | /* rng fifo requires 64-bit accesses */ |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 756 | *data = in_be32(priv->reg_rngu + TALITOS_EU_FIFO); |
| 757 | *data = in_be32(priv->reg_rngu + TALITOS_EU_FIFO_LO); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 758 | |
| 759 | return sizeof(u32); |
| 760 | } |
| 761 | |
| 762 | static int talitos_rng_init(struct hwrng *rng) |
| 763 | { |
| 764 | struct device *dev = (struct device *)rng->priv; |
| 765 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 766 | unsigned int timeout = TALITOS_TIMEOUT; |
| 767 | |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 768 | setbits32(priv->reg_rngu + TALITOS_EURCR_LO, TALITOS_RNGURCR_LO_SR); |
| 769 | while (!(in_be32(priv->reg_rngu + TALITOS_EUSR_LO) |
| 770 | & TALITOS_RNGUSR_LO_RD) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 771 | && --timeout) |
| 772 | cpu_relax(); |
| 773 | if (timeout == 0) { |
| 774 | dev_err(dev, "failed to reset rng hw\n"); |
| 775 | return -ENODEV; |
| 776 | } |
| 777 | |
| 778 | /* start generating */ |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 779 | setbits32(priv->reg_rngu + TALITOS_EUDSR_LO, 0); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 780 | |
| 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | static int talitos_register_rng(struct device *dev) |
| 785 | { |
| 786 | struct talitos_private *priv = dev_get_drvdata(dev); |
Aaron Sierra | 35a3bb3 | 2015-08-05 16:52:08 -0500 | [diff] [blame] | 787 | int err; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 788 | |
| 789 | priv->rng.name = dev_driver_string(dev), |
| 790 | priv->rng.init = talitos_rng_init, |
| 791 | priv->rng.data_present = talitos_rng_data_present, |
| 792 | priv->rng.data_read = talitos_rng_data_read, |
| 793 | priv->rng.priv = (unsigned long)dev; |
| 794 | |
Aaron Sierra | 35a3bb3 | 2015-08-05 16:52:08 -0500 | [diff] [blame] | 795 | err = hwrng_register(&priv->rng); |
| 796 | if (!err) |
| 797 | priv->rng_registered = true; |
| 798 | |
| 799 | return err; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | static void talitos_unregister_rng(struct device *dev) |
| 803 | { |
| 804 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 805 | |
Aaron Sierra | 35a3bb3 | 2015-08-05 16:52:08 -0500 | [diff] [blame] | 806 | if (!priv->rng_registered) |
| 807 | return; |
| 808 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 809 | hwrng_unregister(&priv->rng); |
Aaron Sierra | 35a3bb3 | 2015-08-05 16:52:08 -0500 | [diff] [blame] | 810 | priv->rng_registered = false; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /* |
| 814 | * crypto alg |
| 815 | */ |
| 816 | #define TALITOS_CRA_PRIORITY 3000 |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 817 | /* |
| 818 | * Defines a priority for doing AEAD with descriptors type |
| 819 | * HMAC_SNOOP_NO_AFEA (HSNA) instead of type IPSEC_ESP |
| 820 | */ |
| 821 | #define TALITOS_CRA_PRIORITY_AEAD_HSNA (TALITOS_CRA_PRIORITY - 1) |
Martin Hicks | 03d2c51 | 2017-05-02 09:38:35 -0400 | [diff] [blame] | 822 | #define TALITOS_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + SHA512_BLOCK_SIZE) |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 823 | #define TALITOS_MAX_IV_LENGTH 16 /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */ |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 824 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 825 | struct talitos_ctx { |
| 826 | struct device *dev; |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 827 | int ch; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 828 | __be32 desc_hdr_template; |
| 829 | u8 key[TALITOS_MAX_KEY_SIZE]; |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 830 | u8 iv[TALITOS_MAX_IV_LENGTH]; |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 831 | dma_addr_t dma_key; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 832 | unsigned int keylen; |
| 833 | unsigned int enckeylen; |
| 834 | unsigned int authkeylen; |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 835 | dma_addr_t dma_buf; |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 836 | dma_addr_t dma_hw_context; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 837 | }; |
| 838 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 839 | #define HASH_MAX_BLOCK_SIZE SHA512_BLOCK_SIZE |
| 840 | #define TALITOS_MDEU_MAX_CONTEXT_SIZE TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 |
| 841 | |
| 842 | struct talitos_ahash_req_ctx { |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 843 | u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof(u32)]; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 844 | unsigned int hw_context_size; |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 845 | u8 buf[2][HASH_MAX_BLOCK_SIZE]; |
| 846 | int buf_idx; |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 847 | unsigned int swinit; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 848 | unsigned int first; |
| 849 | unsigned int last; |
| 850 | unsigned int to_hash_later; |
Horia Geant? | 42e8b0d | 2015-05-11 20:04:56 +0300 | [diff] [blame] | 851 | unsigned int nbuf; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 852 | struct scatterlist bufsl[2]; |
| 853 | struct scatterlist *psrc; |
| 854 | }; |
| 855 | |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 856 | struct talitos_export_state { |
| 857 | u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof(u32)]; |
| 858 | u8 buf[HASH_MAX_BLOCK_SIZE]; |
| 859 | unsigned int swinit; |
| 860 | unsigned int first; |
| 861 | unsigned int last; |
| 862 | unsigned int to_hash_later; |
| 863 | unsigned int nbuf; |
| 864 | }; |
| 865 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 866 | static int aead_setkey(struct crypto_aead *authenc, |
| 867 | const u8 *key, unsigned int keylen) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 868 | { |
| 869 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 870 | struct device *dev = ctx->dev; |
Mathias Krause | c306a98 | 2013-10-15 13:49:34 +0200 | [diff] [blame] | 871 | struct crypto_authenc_keys keys; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 872 | |
Mathias Krause | c306a98 | 2013-10-15 13:49:34 +0200 | [diff] [blame] | 873 | if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 874 | goto badkey; |
| 875 | |
Mathias Krause | c306a98 | 2013-10-15 13:49:34 +0200 | [diff] [blame] | 876 | if (keys.authkeylen + keys.enckeylen > TALITOS_MAX_KEY_SIZE) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 877 | goto badkey; |
| 878 | |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 879 | if (ctx->keylen) |
| 880 | dma_unmap_single(dev, ctx->dma_key, ctx->keylen, DMA_TO_DEVICE); |
| 881 | |
Mathias Krause | c306a98 | 2013-10-15 13:49:34 +0200 | [diff] [blame] | 882 | memcpy(ctx->key, keys.authkey, keys.authkeylen); |
| 883 | memcpy(&ctx->key[keys.authkeylen], keys.enckey, keys.enckeylen); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 884 | |
Mathias Krause | c306a98 | 2013-10-15 13:49:34 +0200 | [diff] [blame] | 885 | ctx->keylen = keys.authkeylen + keys.enckeylen; |
| 886 | ctx->enckeylen = keys.enckeylen; |
| 887 | ctx->authkeylen = keys.authkeylen; |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 888 | ctx->dma_key = dma_map_single(dev, ctx->key, ctx->keylen, |
| 889 | DMA_TO_DEVICE); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 890 | |
| 891 | return 0; |
| 892 | |
| 893 | badkey: |
| 894 | crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 895 | return -EINVAL; |
| 896 | } |
| 897 | |
| 898 | /* |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 899 | * talitos_edesc - s/w-extended descriptor |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 900 | * @src_nents: number of segments in input scatterlist |
| 901 | * @dst_nents: number of segments in output scatterlist |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 902 | * @icv_ool: whether ICV is out-of-line |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 903 | * @iv_dma: dma address of iv for checking continuity and link table |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 904 | * @dma_len: length of dma mapped link_tbl space |
LEROY Christophe | 6f65f6a | 2015-04-17 16:32:15 +0200 | [diff] [blame] | 905 | * @dma_link_tbl: bus physical address of link_tbl/buf |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 906 | * @desc: h/w descriptor |
LEROY Christophe | 6f65f6a | 2015-04-17 16:32:15 +0200 | [diff] [blame] | 907 | * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (SEC2) |
| 908 | * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 909 | * |
| 910 | * if decrypting (with authcheck), or either one of src_nents or dst_nents |
| 911 | * is greater than 1, an integrity check value is concatenated to the end |
| 912 | * of link_tbl data |
| 913 | */ |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 914 | struct talitos_edesc { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 915 | int src_nents; |
| 916 | int dst_nents; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 917 | bool icv_ool; |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 918 | dma_addr_t iv_dma; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 919 | int dma_len; |
| 920 | dma_addr_t dma_link_tbl; |
| 921 | struct talitos_desc desc; |
LEROY Christophe | 6f65f6a | 2015-04-17 16:32:15 +0200 | [diff] [blame] | 922 | union { |
| 923 | struct talitos_ptr link_tbl[0]; |
| 924 | u8 buf[0]; |
| 925 | }; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 926 | }; |
| 927 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 928 | static void talitos_sg_unmap(struct device *dev, |
| 929 | struct talitos_edesc *edesc, |
| 930 | struct scatterlist *src, |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 931 | struct scatterlist *dst, |
| 932 | unsigned int len, unsigned int offset) |
LEROY Christophe | 246a87c | 2016-06-06 13:20:36 +0200 | [diff] [blame] | 933 | { |
| 934 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 935 | bool is_sec1 = has_ftr_sec1(priv); |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 936 | unsigned int src_nents = edesc->src_nents ? : 1; |
| 937 | unsigned int dst_nents = edesc->dst_nents ? : 1; |
LEROY Christophe | 246a87c | 2016-06-06 13:20:36 +0200 | [diff] [blame] | 938 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 939 | if (is_sec1 && dst && dst_nents > 1) { |
| 940 | dma_sync_single_for_device(dev, edesc->dma_link_tbl + offset, |
| 941 | len, DMA_FROM_DEVICE); |
| 942 | sg_pcopy_from_buffer(dst, dst_nents, edesc->buf + offset, len, |
| 943 | offset); |
| 944 | } |
| 945 | if (src != dst) { |
| 946 | if (src_nents == 1 || !is_sec1) |
| 947 | dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE); |
| 948 | |
| 949 | if (dst && (dst_nents == 1 || !is_sec1)) |
| 950 | dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE); |
| 951 | } else if (src_nents == 1 || !is_sec1) { |
| 952 | dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL); |
LEROY Christophe | 246a87c | 2016-06-06 13:20:36 +0200 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 956 | static void ipsec_esp_unmap(struct device *dev, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 957 | struct talitos_edesc *edesc, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 958 | struct aead_request *areq) |
| 959 | { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 960 | struct crypto_aead *aead = crypto_aead_reqtfm(areq); |
| 961 | struct talitos_ctx *ctx = crypto_aead_ctx(aead); |
| 962 | unsigned int ivsize = crypto_aead_ivsize(aead); |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 963 | bool is_ipsec_esp = edesc->desc.hdr & DESC_HDR_TYPE_IPSEC_ESP; |
| 964 | struct talitos_ptr *civ_ptr = &edesc->desc.ptr[is_ipsec_esp ? 2 : 3]; |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 965 | |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 966 | if (is_ipsec_esp) |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 967 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[6], |
| 968 | DMA_FROM_DEVICE); |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 969 | unmap_single_talitos_ptr(dev, civ_ptr, DMA_TO_DEVICE); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 970 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 971 | talitos_sg_unmap(dev, edesc, areq->src, areq->dst, areq->cryptlen, |
| 972 | areq->assoclen); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 973 | |
| 974 | if (edesc->dma_len) |
| 975 | dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, |
| 976 | DMA_BIDIRECTIONAL); |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 977 | |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 978 | if (!is_ipsec_esp) { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 979 | unsigned int dst_nents = edesc->dst_nents ? : 1; |
| 980 | |
| 981 | sg_pcopy_to_buffer(areq->dst, dst_nents, ctx->iv, ivsize, |
| 982 | areq->assoclen + areq->cryptlen - ivsize); |
| 983 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /* |
| 987 | * ipsec_esp descriptor callbacks |
| 988 | */ |
| 989 | static void ipsec_esp_encrypt_done(struct device *dev, |
| 990 | struct talitos_desc *desc, void *context, |
| 991 | int err) |
| 992 | { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 993 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 994 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 995 | struct aead_request *areq = context; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 996 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 997 | unsigned int authsize = crypto_aead_authsize(authenc); |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 998 | unsigned int ivsize = crypto_aead_ivsize(authenc); |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 999 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1000 | struct scatterlist *sg; |
| 1001 | void *icvdata; |
| 1002 | |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 1003 | edesc = container_of(desc, struct talitos_edesc, desc); |
| 1004 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1005 | ipsec_esp_unmap(dev, edesc, areq); |
| 1006 | |
| 1007 | /* copy the generated ICV to dst */ |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1008 | if (edesc->icv_ool) { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1009 | if (is_sec1) |
| 1010 | icvdata = edesc->buf + areq->assoclen + areq->cryptlen; |
| 1011 | else |
| 1012 | icvdata = &edesc->link_tbl[edesc->src_nents + |
| 1013 | edesc->dst_nents + 2]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1014 | sg = sg_last(areq->dst, edesc->dst_nents); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1015 | memcpy((char *)sg_virt(sg) + sg->length - authsize, |
| 1016 | icvdata, authsize); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1017 | } |
| 1018 | |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1019 | dma_unmap_single(dev, edesc->iv_dma, ivsize, DMA_TO_DEVICE); |
| 1020 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1021 | kfree(edesc); |
| 1022 | |
| 1023 | aead_request_complete(areq, err); |
| 1024 | } |
| 1025 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1026 | static void ipsec_esp_decrypt_swauth_done(struct device *dev, |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1027 | struct talitos_desc *desc, |
| 1028 | void *context, int err) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1029 | { |
| 1030 | struct aead_request *req = context; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1031 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1032 | unsigned int authsize = crypto_aead_authsize(authenc); |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 1033 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1034 | struct scatterlist *sg; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1035 | char *oicv, *icv; |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1036 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1037 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1038 | |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 1039 | edesc = container_of(desc, struct talitos_edesc, desc); |
| 1040 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1041 | ipsec_esp_unmap(dev, edesc, req); |
| 1042 | |
| 1043 | if (!err) { |
| 1044 | /* auth check */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1045 | sg = sg_last(req->dst, edesc->dst_nents ? : 1); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1046 | icv = (char *)sg_virt(sg) + sg->length - authsize; |
| 1047 | |
| 1048 | if (edesc->dma_len) { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1049 | if (is_sec1) |
| 1050 | oicv = (char *)&edesc->dma_link_tbl + |
| 1051 | req->assoclen + req->cryptlen; |
| 1052 | else |
| 1053 | oicv = (char *) |
| 1054 | &edesc->link_tbl[edesc->src_nents + |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1055 | edesc->dst_nents + 2]; |
| 1056 | if (edesc->icv_ool) |
| 1057 | icv = oicv + authsize; |
| 1058 | } else |
| 1059 | oicv = (char *)&edesc->link_tbl[0]; |
| 1060 | |
David Gstir | 7996094 | 2015-11-15 17:14:42 +0100 | [diff] [blame] | 1061 | err = crypto_memneq(oicv, icv, authsize) ? -EBADMSG : 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | kfree(edesc); |
| 1065 | |
| 1066 | aead_request_complete(req, err); |
| 1067 | } |
| 1068 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1069 | static void ipsec_esp_decrypt_hwauth_done(struct device *dev, |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1070 | struct talitos_desc *desc, |
| 1071 | void *context, int err) |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1072 | { |
| 1073 | struct aead_request *req = context; |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 1074 | struct talitos_edesc *edesc; |
| 1075 | |
| 1076 | edesc = container_of(desc, struct talitos_edesc, desc); |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1077 | |
| 1078 | ipsec_esp_unmap(dev, edesc, req); |
| 1079 | |
| 1080 | /* check ICV auth status */ |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1081 | if (!err && ((desc->hdr_lo & DESC_HDR_LO_ICCR1_MASK) != |
| 1082 | DESC_HDR_LO_ICCR1_PASS)) |
| 1083 | err = -EBADMSG; |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1084 | |
| 1085 | kfree(edesc); |
| 1086 | |
| 1087 | aead_request_complete(req, err); |
| 1088 | } |
| 1089 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1090 | /* |
| 1091 | * convert scatterlist to SEC h/w link table format |
| 1092 | * stop at cryptlen bytes |
| 1093 | */ |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1094 | static int sg_to_link_tbl_offset(struct scatterlist *sg, int sg_count, |
| 1095 | unsigned int offset, int cryptlen, |
| 1096 | struct talitos_ptr *link_tbl_ptr) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1097 | { |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1098 | int n_sg = sg_count; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1099 | int count = 0; |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1100 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1101 | while (cryptlen && sg && n_sg--) { |
| 1102 | unsigned int len = sg_dma_len(sg); |
| 1103 | |
| 1104 | if (offset >= len) { |
| 1105 | offset -= len; |
| 1106 | goto next; |
| 1107 | } |
| 1108 | |
| 1109 | len -= offset; |
| 1110 | |
| 1111 | if (len > cryptlen) |
| 1112 | len = cryptlen; |
| 1113 | |
| 1114 | to_talitos_ptr(link_tbl_ptr + count, |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 1115 | sg_dma_address(sg) + offset, len, 0); |
LEROY Christophe | b096b54 | 2016-06-06 13:20:34 +0200 | [diff] [blame] | 1116 | to_talitos_ptr_ext_set(link_tbl_ptr + count, 0, 0); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1117 | count++; |
| 1118 | cryptlen -= len; |
| 1119 | offset = 0; |
| 1120 | |
| 1121 | next: |
Cristian Stoica | 5be4d4c | 2015-01-20 10:06:16 +0200 | [diff] [blame] | 1122 | sg = sg_next(sg); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1123 | } |
| 1124 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1125 | /* tag end of link table */ |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1126 | if (count > 0) |
LEROY Christophe | b096b54 | 2016-06-06 13:20:34 +0200 | [diff] [blame] | 1127 | to_talitos_ptr_ext_set(link_tbl_ptr + count - 1, |
| 1128 | DESC_PTR_LNKTBL_RETURN, 0); |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1129 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1130 | return count; |
| 1131 | } |
| 1132 | |
LEROY Christophe | 5b2cf26 | 2017-10-06 15:04:47 +0200 | [diff] [blame] | 1133 | static int talitos_sg_map(struct device *dev, struct scatterlist *src, |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1134 | unsigned int len, struct talitos_edesc *edesc, |
| 1135 | struct talitos_ptr *ptr, |
| 1136 | int sg_count, unsigned int offset, int tbl_off) |
LEROY Christophe | 246a87c | 2016-06-06 13:20:36 +0200 | [diff] [blame] | 1137 | { |
LEROY Christophe | 246a87c | 2016-06-06 13:20:36 +0200 | [diff] [blame] | 1138 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1139 | bool is_sec1 = has_ftr_sec1(priv); |
| 1140 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1141 | if (sg_count == 1) { |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 1142 | to_talitos_ptr(ptr, sg_dma_address(src) + offset, len, is_sec1); |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1143 | return sg_count; |
LEROY Christophe | 246a87c | 2016-06-06 13:20:36 +0200 | [diff] [blame] | 1144 | } |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1145 | if (is_sec1) { |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 1146 | to_talitos_ptr(ptr, edesc->dma_link_tbl + offset, len, is_sec1); |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1147 | return sg_count; |
| 1148 | } |
| 1149 | sg_count = sg_to_link_tbl_offset(src, sg_count, offset, len, |
| 1150 | &edesc->link_tbl[tbl_off]); |
| 1151 | if (sg_count == 1) { |
| 1152 | /* Only one segment now, so no link tbl needed*/ |
| 1153 | copy_talitos_ptr(ptr, &edesc->link_tbl[tbl_off], is_sec1); |
| 1154 | return sg_count; |
| 1155 | } |
| 1156 | to_talitos_ptr(ptr, edesc->dma_link_tbl + |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 1157 | tbl_off * sizeof(struct talitos_ptr), len, is_sec1); |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1158 | to_talitos_ptr_ext_or(ptr, DESC_PTR_LNKTBL_JUMP, is_sec1); |
| 1159 | |
LEROY Christophe | 246a87c | 2016-06-06 13:20:36 +0200 | [diff] [blame] | 1160 | return sg_count; |
| 1161 | } |
| 1162 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1163 | /* |
| 1164 | * fill in and submit ipsec_esp descriptor |
| 1165 | */ |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1166 | static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1167 | void (*callback)(struct device *dev, |
| 1168 | struct talitos_desc *desc, |
| 1169 | void *context, int error)) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1170 | { |
| 1171 | struct crypto_aead *aead = crypto_aead_reqtfm(areq); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1172 | unsigned int authsize = crypto_aead_authsize(aead); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1173 | struct talitos_ctx *ctx = crypto_aead_ctx(aead); |
| 1174 | struct device *dev = ctx->dev; |
| 1175 | struct talitos_desc *desc = &edesc->desc; |
| 1176 | unsigned int cryptlen = areq->cryptlen; |
Kim Phillips | e41256f | 2009-08-13 11:49:06 +1000 | [diff] [blame] | 1177 | unsigned int ivsize = crypto_aead_ivsize(aead); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1178 | int tbl_off = 0; |
Kim Phillips | fa86a26 | 2008-07-17 20:20:06 +0800 | [diff] [blame] | 1179 | int sg_count, ret; |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1180 | int sg_link_tbl_len; |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1181 | bool sync_needed = false; |
| 1182 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1183 | bool is_sec1 = has_ftr_sec1(priv); |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1184 | bool is_ipsec_esp = desc->hdr & DESC_HDR_TYPE_IPSEC_ESP; |
| 1185 | struct talitos_ptr *civ_ptr = &desc->ptr[is_ipsec_esp ? 2 : 3]; |
| 1186 | struct talitos_ptr *ckey_ptr = &desc->ptr[is_ipsec_esp ? 3 : 2]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1187 | |
| 1188 | /* hmac key */ |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1189 | to_talitos_ptr(&desc->ptr[0], ctx->dma_key, ctx->authkeylen, is_sec1); |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1190 | |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1191 | sg_count = edesc->src_nents ?: 1; |
| 1192 | if (is_sec1 && sg_count > 1) |
| 1193 | sg_copy_to_buffer(areq->src, sg_count, edesc->buf, |
| 1194 | areq->assoclen + cryptlen); |
| 1195 | else |
| 1196 | sg_count = dma_map_sg(dev, areq->src, sg_count, |
| 1197 | (areq->src == areq->dst) ? |
| 1198 | DMA_BIDIRECTIONAL : DMA_TO_DEVICE); |
| 1199 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1200 | /* hmac data */ |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1201 | ret = talitos_sg_map(dev, areq->src, areq->assoclen, edesc, |
| 1202 | &desc->ptr[1], sg_count, 0, tbl_off); |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1203 | |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1204 | if (ret > 1) { |
Horia Geant? | 340ff60 | 2016-04-19 20:33:48 +0300 | [diff] [blame] | 1205 | tbl_off += ret; |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1206 | sync_needed = true; |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1207 | } |
| 1208 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1209 | /* cipher iv */ |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1210 | to_talitos_ptr(civ_ptr, edesc->iv_dma, ivsize, is_sec1); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1211 | |
| 1212 | /* cipher key */ |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1213 | to_talitos_ptr(ckey_ptr, ctx->dma_key + ctx->authkeylen, |
| 1214 | ctx->enckeylen, is_sec1); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1215 | |
| 1216 | /* |
| 1217 | * cipher in |
| 1218 | * map and adjust cipher len to aead request cryptlen. |
| 1219 | * extent is bytes of HMAC postpended to ciphertext, |
| 1220 | * typically 12 for ipsec |
| 1221 | */ |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1222 | sg_link_tbl_len = cryptlen; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1223 | |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1224 | if (is_ipsec_esp) { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1225 | to_talitos_ptr_ext_set(&desc->ptr[4], authsize, is_sec1); |
| 1226 | |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1227 | if (desc->hdr & DESC_HDR_MODE1_MDEU_CICV) |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1228 | sg_link_tbl_len += authsize; |
| 1229 | } |
| 1230 | |
LEROY Christophe | fbb2213 | 2017-10-06 15:04:41 +0200 | [diff] [blame] | 1231 | ret = talitos_sg_map(dev, areq->src, sg_link_tbl_len, edesc, |
| 1232 | &desc->ptr[4], sg_count, areq->assoclen, tbl_off); |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1233 | |
LEROY Christophe | ec8c7d1 | 2017-10-06 15:04:33 +0200 | [diff] [blame] | 1234 | if (ret > 1) { |
| 1235 | tbl_off += ret; |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1236 | sync_needed = true; |
Horia Geant? | 340ff60 | 2016-04-19 20:33:48 +0300 | [diff] [blame] | 1237 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1238 | |
| 1239 | /* cipher out */ |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1240 | if (areq->src != areq->dst) { |
| 1241 | sg_count = edesc->dst_nents ? : 1; |
| 1242 | if (!is_sec1 || sg_count == 1) |
| 1243 | dma_map_sg(dev, areq->dst, sg_count, DMA_FROM_DEVICE); |
| 1244 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1245 | |
LEROY Christophe | e04a61b | 2017-10-06 15:04:35 +0200 | [diff] [blame] | 1246 | ret = talitos_sg_map(dev, areq->dst, cryptlen, edesc, &desc->ptr[5], |
| 1247 | sg_count, areq->assoclen, tbl_off); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1248 | |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1249 | if (is_ipsec_esp) |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1250 | to_talitos_ptr_ext_or(&desc->ptr[5], authsize, is_sec1); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1251 | |
LEROY Christophe | e04a61b | 2017-10-06 15:04:35 +0200 | [diff] [blame] | 1252 | /* ICV data */ |
| 1253 | if (ret > 1) { |
| 1254 | tbl_off += ret; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1255 | edesc->icv_ool = true; |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1256 | sync_needed = true; |
| 1257 | |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1258 | if (is_ipsec_esp) { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1259 | struct talitos_ptr *tbl_ptr = &edesc->link_tbl[tbl_off]; |
| 1260 | int offset = (edesc->src_nents + edesc->dst_nents + 2) * |
| 1261 | sizeof(struct talitos_ptr) + authsize; |
| 1262 | |
| 1263 | /* Add an entry to the link table for ICV data */ |
LEROY Christophe | e04a61b | 2017-10-06 15:04:35 +0200 | [diff] [blame] | 1264 | to_talitos_ptr_ext_set(tbl_ptr - 1, 0, is_sec1); |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1265 | to_talitos_ptr_ext_set(tbl_ptr, DESC_PTR_LNKTBL_RETURN, |
| 1266 | is_sec1); |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1267 | |
| 1268 | /* icv data follows link tables */ |
| 1269 | to_talitos_ptr(tbl_ptr, edesc->dma_link_tbl + offset, |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 1270 | authsize, is_sec1); |
LEROY Christophe | e04a61b | 2017-10-06 15:04:35 +0200 | [diff] [blame] | 1271 | } else { |
| 1272 | dma_addr_t addr = edesc->dma_link_tbl; |
| 1273 | |
| 1274 | if (is_sec1) |
| 1275 | addr += areq->assoclen + cryptlen; |
| 1276 | else |
| 1277 | addr += sizeof(struct talitos_ptr) * tbl_off; |
| 1278 | |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 1279 | to_talitos_ptr(&desc->ptr[6], addr, authsize, is_sec1); |
LEROY Christophe | e04a61b | 2017-10-06 15:04:35 +0200 | [diff] [blame] | 1280 | } |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1281 | } else if (!is_ipsec_esp) { |
LEROY Christophe | e04a61b | 2017-10-06 15:04:35 +0200 | [diff] [blame] | 1282 | ret = talitos_sg_map(dev, areq->dst, authsize, edesc, |
| 1283 | &desc->ptr[6], sg_count, areq->assoclen + |
| 1284 | cryptlen, |
| 1285 | tbl_off); |
| 1286 | if (ret > 1) { |
| 1287 | tbl_off += ret; |
| 1288 | edesc->icv_ool = true; |
| 1289 | sync_needed = true; |
| 1290 | } else { |
| 1291 | edesc->icv_ool = false; |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1292 | } |
Horia Geant? | 340ff60 | 2016-04-19 20:33:48 +0300 | [diff] [blame] | 1293 | } else { |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1294 | edesc->icv_ool = false; |
| 1295 | } |
| 1296 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1297 | /* iv out */ |
LEROY Christophe | 9a65560 | 2017-10-06 15:04:59 +0200 | [diff] [blame] | 1298 | if (is_ipsec_esp) |
LEROY Christophe | 549bd8b | 2016-06-06 13:20:40 +0200 | [diff] [blame] | 1299 | map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, |
| 1300 | DMA_FROM_DEVICE); |
| 1301 | |
| 1302 | if (sync_needed) |
| 1303 | dma_sync_single_for_device(dev, edesc->dma_link_tbl, |
| 1304 | edesc->dma_len, |
| 1305 | DMA_BIDIRECTIONAL); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1306 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 1307 | ret = talitos_submit(dev, ctx->ch, desc, callback, areq); |
Kim Phillips | fa86a26 | 2008-07-17 20:20:06 +0800 | [diff] [blame] | 1308 | if (ret != -EINPROGRESS) { |
| 1309 | ipsec_esp_unmap(dev, edesc, areq); |
| 1310 | kfree(edesc); |
| 1311 | } |
| 1312 | return ret; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1313 | } |
| 1314 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1315 | /* |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1316 | * allocate and map the extended descriptor |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1317 | */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1318 | static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, |
| 1319 | struct scatterlist *src, |
| 1320 | struct scatterlist *dst, |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1321 | u8 *iv, |
| 1322 | unsigned int assoclen, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1323 | unsigned int cryptlen, |
| 1324 | unsigned int authsize, |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1325 | unsigned int ivsize, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1326 | int icv_stashing, |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1327 | u32 cryptoflags, |
| 1328 | bool encrypt) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1329 | { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1330 | struct talitos_edesc *edesc; |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1331 | int src_nents, dst_nents, alloc_len, dma_len, src_len, dst_len; |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1332 | dma_addr_t iv_dma = 0; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1333 | gfp_t flags = cryptoflags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : |
Kim Phillips | 586725f | 2008-07-17 20:19:18 +0800 | [diff] [blame] | 1334 | GFP_ATOMIC; |
LEROY Christophe | 6f65f6a | 2015-04-17 16:32:15 +0200 | [diff] [blame] | 1335 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1336 | bool is_sec1 = has_ftr_sec1(priv); |
| 1337 | int max_len = is_sec1 ? TALITOS1_MAX_DATA_LEN : TALITOS2_MAX_DATA_LEN; |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1338 | void *err; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1339 | |
LEROY Christophe | 6f65f6a | 2015-04-17 16:32:15 +0200 | [diff] [blame] | 1340 | if (cryptlen + authsize > max_len) { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1341 | dev_err(dev, "length exceeds h/w max limit\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1342 | return ERR_PTR(-EINVAL); |
| 1343 | } |
| 1344 | |
Horia Geanta | 935e99a | 2013-11-19 14:57:49 +0200 | [diff] [blame] | 1345 | if (ivsize) |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1346 | iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE); |
| 1347 | |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1348 | if (!dst || dst == src) { |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1349 | src_len = assoclen + cryptlen + authsize; |
| 1350 | src_nents = sg_nents_for_len(src, src_len); |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1351 | if (src_nents < 0) { |
| 1352 | dev_err(dev, "Invalid number of src SG.\n"); |
| 1353 | err = ERR_PTR(-EINVAL); |
| 1354 | goto error_sg; |
| 1355 | } |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1356 | src_nents = (src_nents == 1) ? 0 : src_nents; |
| 1357 | dst_nents = dst ? src_nents : 0; |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1358 | dst_len = 0; |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1359 | } else { /* dst && dst != src*/ |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1360 | src_len = assoclen + cryptlen + (encrypt ? 0 : authsize); |
| 1361 | src_nents = sg_nents_for_len(src, src_len); |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1362 | if (src_nents < 0) { |
| 1363 | dev_err(dev, "Invalid number of src SG.\n"); |
| 1364 | err = ERR_PTR(-EINVAL); |
| 1365 | goto error_sg; |
| 1366 | } |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1367 | src_nents = (src_nents == 1) ? 0 : src_nents; |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1368 | dst_len = assoclen + cryptlen + (encrypt ? authsize : 0); |
| 1369 | dst_nents = sg_nents_for_len(dst, dst_len); |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1370 | if (dst_nents < 0) { |
| 1371 | dev_err(dev, "Invalid number of dst SG.\n"); |
| 1372 | err = ERR_PTR(-EINVAL); |
| 1373 | goto error_sg; |
| 1374 | } |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1375 | dst_nents = (dst_nents == 1) ? 0 : dst_nents; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | * allocate space for base edesc plus the link tables, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1380 | * allowing for two separate entries for AD and generated ICV (+ 2), |
| 1381 | * and space for two sets of ICVs (stashed and generated) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1382 | */ |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1383 | alloc_len = sizeof(struct talitos_edesc); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1384 | if (src_nents || dst_nents) { |
LEROY Christophe | 6f65f6a | 2015-04-17 16:32:15 +0200 | [diff] [blame] | 1385 | if (is_sec1) |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1386 | dma_len = (src_nents ? src_len : 0) + |
| 1387 | (dst_nents ? dst_len : 0); |
LEROY Christophe | 6f65f6a | 2015-04-17 16:32:15 +0200 | [diff] [blame] | 1388 | else |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1389 | dma_len = (src_nents + dst_nents + 2) * |
| 1390 | sizeof(struct talitos_ptr) + authsize * 2; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1391 | alloc_len += dma_len; |
| 1392 | } else { |
| 1393 | dma_len = 0; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1394 | alloc_len += icv_stashing ? authsize : 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1395 | } |
| 1396 | |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1397 | /* if its a ahash, add space for a second desc next to the first one */ |
| 1398 | if (is_sec1 && !dst) |
| 1399 | alloc_len += sizeof(struct talitos_desc); |
| 1400 | |
Kim Phillips | 586725f | 2008-07-17 20:19:18 +0800 | [diff] [blame] | 1401 | edesc = kmalloc(alloc_len, GFP_DMA | flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1402 | if (!edesc) { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1403 | dev_err(dev, "could not allocate edescriptor\n"); |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1404 | err = ERR_PTR(-ENOMEM); |
| 1405 | goto error_sg; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1406 | } |
LEROY Christophe | e4a647c | 2017-10-06 15:04:45 +0200 | [diff] [blame] | 1407 | memset(&edesc->desc, 0, sizeof(edesc->desc)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1408 | |
| 1409 | edesc->src_nents = src_nents; |
| 1410 | edesc->dst_nents = dst_nents; |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1411 | edesc->iv_dma = iv_dma; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1412 | edesc->dma_len = dma_len; |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1413 | if (dma_len) { |
| 1414 | void *addr = &edesc->link_tbl[0]; |
| 1415 | |
| 1416 | if (is_sec1 && !dst) |
| 1417 | addr += sizeof(struct talitos_desc); |
| 1418 | edesc->dma_link_tbl = dma_map_single(dev, addr, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1419 | edesc->dma_len, |
| 1420 | DMA_BIDIRECTIONAL); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1421 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1422 | return edesc; |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1423 | error_sg: |
| 1424 | if (iv_dma) |
| 1425 | dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE); |
| 1426 | return err; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1427 | } |
| 1428 | |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1429 | static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq, u8 *iv, |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1430 | int icv_stashing, bool encrypt) |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1431 | { |
| 1432 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1433 | unsigned int authsize = crypto_aead_authsize(authenc); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1434 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1435 | unsigned int ivsize = crypto_aead_ivsize(authenc); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1436 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1437 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1438 | iv, areq->assoclen, areq->cryptlen, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1439 | authsize, ivsize, icv_stashing, |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1440 | areq->base.flags, encrypt); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1441 | } |
| 1442 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1443 | static int aead_encrypt(struct aead_request *req) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1444 | { |
| 1445 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
| 1446 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1447 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1448 | |
| 1449 | /* allocate extended descriptor */ |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1450 | edesc = aead_edesc_alloc(req, req->iv, 0, true); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1451 | if (IS_ERR(edesc)) |
| 1452 | return PTR_ERR(edesc); |
| 1453 | |
| 1454 | /* set encrypt */ |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1455 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1456 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1457 | return ipsec_esp(edesc, req, ipsec_esp_encrypt_done); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1458 | } |
| 1459 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1460 | static int aead_decrypt(struct aead_request *req) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1461 | { |
| 1462 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1463 | unsigned int authsize = crypto_aead_authsize(authenc); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1464 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1465 | struct talitos_private *priv = dev_get_drvdata(ctx->dev); |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1466 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1467 | struct scatterlist *sg; |
| 1468 | void *icvdata; |
| 1469 | |
| 1470 | req->cryptlen -= authsize; |
| 1471 | |
| 1472 | /* allocate extended descriptor */ |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1473 | edesc = aead_edesc_alloc(req, req->iv, 1, false); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1474 | if (IS_ERR(edesc)) |
| 1475 | return PTR_ERR(edesc); |
| 1476 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1477 | if ((priv->features & TALITOS_FTR_HW_AUTH_CHECK) && |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1478 | ((!edesc->src_nents && !edesc->dst_nents) || |
| 1479 | priv->features & TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT)) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1480 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1481 | /* decrypt and check the ICV */ |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1482 | edesc->desc.hdr = ctx->desc_hdr_template | |
| 1483 | DESC_HDR_DIR_INBOUND | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1484 | DESC_HDR_MODE1_MDEU_CICV; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1485 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1486 | /* reset integrity check result bits */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1487 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1488 | return ipsec_esp(edesc, req, ipsec_esp_decrypt_hwauth_done); |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1489 | } |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1490 | |
| 1491 | /* Have to check the ICV with software */ |
| 1492 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND; |
| 1493 | |
| 1494 | /* stash incoming ICV for later cmp with ICV generated by the h/w */ |
| 1495 | if (edesc->dma_len) |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1496 | icvdata = (char *)&edesc->link_tbl[edesc->src_nents + |
| 1497 | edesc->dst_nents + 2]; |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1498 | else |
| 1499 | icvdata = &edesc->link_tbl[0]; |
| 1500 | |
| 1501 | sg = sg_last(req->src, edesc->src_nents ? : 1); |
| 1502 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1503 | memcpy(icvdata, (char *)sg_virt(sg) + sg->length - authsize, authsize); |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1504 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1505 | return ipsec_esp(edesc, req, ipsec_esp_decrypt_swauth_done); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1506 | } |
| 1507 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1508 | static int ablkcipher_setkey(struct crypto_ablkcipher *cipher, |
| 1509 | const u8 *key, unsigned int keylen) |
| 1510 | { |
| 1511 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1512 | struct device *dev = ctx->dev; |
LEROY Christophe | f384cdc | 2017-10-06 15:04:37 +0200 | [diff] [blame] | 1513 | u32 tmp[DES_EXPKEY_WORDS]; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1514 | |
Martin Hicks | 03d2c51 | 2017-05-02 09:38:35 -0400 | [diff] [blame] | 1515 | if (keylen > TALITOS_MAX_KEY_SIZE) { |
| 1516 | crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 1517 | return -EINVAL; |
| 1518 | } |
| 1519 | |
LEROY Christophe | f384cdc | 2017-10-06 15:04:37 +0200 | [diff] [blame] | 1520 | if (unlikely(crypto_ablkcipher_get_flags(cipher) & |
| 1521 | CRYPTO_TFM_REQ_WEAK_KEY) && |
| 1522 | !des_ekey(tmp, key)) { |
| 1523 | crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_WEAK_KEY); |
| 1524 | return -EINVAL; |
| 1525 | } |
| 1526 | |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1527 | if (ctx->keylen) |
| 1528 | dma_unmap_single(dev, ctx->dma_key, ctx->keylen, DMA_TO_DEVICE); |
| 1529 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1530 | memcpy(&ctx->key, key, keylen); |
| 1531 | ctx->keylen = keylen; |
| 1532 | |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1533 | ctx->dma_key = dma_map_single(dev, ctx->key, keylen, DMA_TO_DEVICE); |
| 1534 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1535 | return 0; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void common_nonsnoop_unmap(struct device *dev, |
| 1539 | struct talitos_edesc *edesc, |
| 1540 | struct ablkcipher_request *areq) |
| 1541 | { |
| 1542 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE); |
LEROY Christophe | 032d197 | 2015-04-17 16:31:51 +0200 | [diff] [blame] | 1543 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1544 | talitos_sg_unmap(dev, edesc, areq->src, areq->dst, areq->nbytes, 0); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1545 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1], DMA_TO_DEVICE); |
| 1546 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1547 | if (edesc->dma_len) |
| 1548 | dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, |
| 1549 | DMA_BIDIRECTIONAL); |
| 1550 | } |
| 1551 | |
| 1552 | static void ablkcipher_done(struct device *dev, |
| 1553 | struct talitos_desc *desc, void *context, |
| 1554 | int err) |
| 1555 | { |
| 1556 | struct ablkcipher_request *areq = context; |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 1557 | struct talitos_edesc *edesc; |
| 1558 | |
| 1559 | edesc = container_of(desc, struct talitos_edesc, desc); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1560 | |
| 1561 | common_nonsnoop_unmap(dev, edesc, areq); |
| 1562 | |
| 1563 | kfree(edesc); |
| 1564 | |
| 1565 | areq->base.complete(&areq->base, err); |
| 1566 | } |
| 1567 | |
| 1568 | static int common_nonsnoop(struct talitos_edesc *edesc, |
| 1569 | struct ablkcipher_request *areq, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1570 | void (*callback) (struct device *dev, |
| 1571 | struct talitos_desc *desc, |
| 1572 | void *context, int error)) |
| 1573 | { |
| 1574 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1575 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
| 1576 | struct device *dev = ctx->dev; |
| 1577 | struct talitos_desc *desc = &edesc->desc; |
| 1578 | unsigned int cryptlen = areq->nbytes; |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1579 | unsigned int ivsize = crypto_ablkcipher_ivsize(cipher); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1580 | int sg_count, ret; |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1581 | bool sync_needed = false; |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 1582 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1583 | bool is_sec1 = has_ftr_sec1(priv); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1584 | |
| 1585 | /* first DWORD empty */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1586 | |
| 1587 | /* cipher iv */ |
LEROY Christophe | da9de14 | 2017-10-06 15:04:57 +0200 | [diff] [blame] | 1588 | to_talitos_ptr(&desc->ptr[1], edesc->iv_dma, ivsize, is_sec1); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1589 | |
| 1590 | /* cipher key */ |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1591 | to_talitos_ptr(&desc->ptr[2], ctx->dma_key, ctx->keylen, is_sec1); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1592 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1593 | sg_count = edesc->src_nents ?: 1; |
| 1594 | if (is_sec1 && sg_count > 1) |
| 1595 | sg_copy_to_buffer(areq->src, sg_count, edesc->buf, |
| 1596 | cryptlen); |
| 1597 | else |
| 1598 | sg_count = dma_map_sg(dev, areq->src, sg_count, |
| 1599 | (areq->src == areq->dst) ? |
| 1600 | DMA_BIDIRECTIONAL : DMA_TO_DEVICE); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1601 | /* |
| 1602 | * cipher in |
| 1603 | */ |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1604 | sg_count = talitos_sg_map(dev, areq->src, cryptlen, edesc, |
| 1605 | &desc->ptr[3], sg_count, 0, 0); |
| 1606 | if (sg_count > 1) |
| 1607 | sync_needed = true; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1608 | |
| 1609 | /* cipher out */ |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1610 | if (areq->src != areq->dst) { |
| 1611 | sg_count = edesc->dst_nents ? : 1; |
| 1612 | if (!is_sec1 || sg_count == 1) |
| 1613 | dma_map_sg(dev, areq->dst, sg_count, DMA_FROM_DEVICE); |
| 1614 | } |
| 1615 | |
| 1616 | ret = talitos_sg_map(dev, areq->dst, cryptlen, edesc, &desc->ptr[4], |
| 1617 | sg_count, 0, (edesc->src_nents + 1)); |
| 1618 | if (ret > 1) |
| 1619 | sync_needed = true; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1620 | |
| 1621 | /* iv out */ |
LEROY Christophe | a2b35aa | 2015-04-17 16:31:57 +0200 | [diff] [blame] | 1622 | map_single_talitos_ptr(dev, &desc->ptr[5], ivsize, ctx->iv, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1623 | DMA_FROM_DEVICE); |
| 1624 | |
| 1625 | /* last DWORD empty */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1626 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1627 | if (sync_needed) |
| 1628 | dma_sync_single_for_device(dev, edesc->dma_link_tbl, |
| 1629 | edesc->dma_len, DMA_BIDIRECTIONAL); |
| 1630 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 1631 | ret = talitos_submit(dev, ctx->ch, desc, callback, areq); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1632 | if (ret != -EINPROGRESS) { |
| 1633 | common_nonsnoop_unmap(dev, edesc, areq); |
| 1634 | kfree(edesc); |
| 1635 | } |
| 1636 | return ret; |
| 1637 | } |
| 1638 | |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1639 | static struct talitos_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request * |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1640 | areq, bool encrypt) |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1641 | { |
| 1642 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1643 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1644 | unsigned int ivsize = crypto_ablkcipher_ivsize(cipher); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1645 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1646 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, |
Horia Geanta | 79fd31d | 2012-08-02 17:16:40 +0300 | [diff] [blame] | 1647 | areq->info, 0, areq->nbytes, 0, ivsize, 0, |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1648 | areq->base.flags, encrypt); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | static int ablkcipher_encrypt(struct ablkcipher_request *areq) |
| 1652 | { |
| 1653 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1654 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
| 1655 | struct talitos_edesc *edesc; |
| 1656 | |
| 1657 | /* allocate extended descriptor */ |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1658 | edesc = ablkcipher_edesc_alloc(areq, true); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1659 | if (IS_ERR(edesc)) |
| 1660 | return PTR_ERR(edesc); |
| 1661 | |
| 1662 | /* set encrypt */ |
| 1663 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT; |
| 1664 | |
Kim Phillips | febec54 | 2011-07-15 11:21:39 +0800 | [diff] [blame] | 1665 | return common_nonsnoop(edesc, areq, ablkcipher_done); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | static int ablkcipher_decrypt(struct ablkcipher_request *areq) |
| 1669 | { |
| 1670 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1671 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
| 1672 | struct talitos_edesc *edesc; |
| 1673 | |
| 1674 | /* allocate extended descriptor */ |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1675 | edesc = ablkcipher_edesc_alloc(areq, false); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1676 | if (IS_ERR(edesc)) |
| 1677 | return PTR_ERR(edesc); |
| 1678 | |
| 1679 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND; |
| 1680 | |
Kim Phillips | febec54 | 2011-07-15 11:21:39 +0800 | [diff] [blame] | 1681 | return common_nonsnoop(edesc, areq, ablkcipher_done); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1682 | } |
| 1683 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1684 | static void common_nonsnoop_hash_unmap(struct device *dev, |
| 1685 | struct talitos_edesc *edesc, |
| 1686 | struct ahash_request *areq) |
| 1687 | { |
| 1688 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1689 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1690 | talitos_sg_unmap(dev, edesc, req_ctx->psrc, NULL, 0, 0); |
LEROY Christophe | 032d197 | 2015-04-17 16:31:51 +0200 | [diff] [blame] | 1691 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1692 | if (edesc->dma_len) |
| 1693 | dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, |
| 1694 | DMA_BIDIRECTIONAL); |
| 1695 | |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1696 | if (edesc->desc.next_desc) |
| 1697 | dma_unmap_single(dev, be32_to_cpu(edesc->desc.next_desc), |
| 1698 | TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | static void ahash_done(struct device *dev, |
| 1702 | struct talitos_desc *desc, void *context, |
| 1703 | int err) |
| 1704 | { |
| 1705 | struct ahash_request *areq = context; |
| 1706 | struct talitos_edesc *edesc = |
| 1707 | container_of(desc, struct talitos_edesc, desc); |
| 1708 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1709 | |
| 1710 | if (!req_ctx->last && req_ctx->to_hash_later) { |
| 1711 | /* Position any partial block for next update/final/finup */ |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 1712 | req_ctx->buf_idx = (req_ctx->buf_idx + 1) & 1; |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1713 | req_ctx->nbuf = req_ctx->to_hash_later; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1714 | } |
| 1715 | common_nonsnoop_hash_unmap(dev, edesc, areq); |
| 1716 | |
| 1717 | kfree(edesc); |
| 1718 | |
| 1719 | areq->base.complete(&areq->base, err); |
| 1720 | } |
| 1721 | |
LEROY Christophe | 2d02905 | 2015-04-17 16:32:18 +0200 | [diff] [blame] | 1722 | /* |
| 1723 | * SEC1 doesn't like hashing of 0 sized message, so we do the padding |
| 1724 | * ourself and submit a padded block |
| 1725 | */ |
LEROY Christophe | 5b2cf26 | 2017-10-06 15:04:47 +0200 | [diff] [blame] | 1726 | static void talitos_handle_buggy_hash(struct talitos_ctx *ctx, |
LEROY Christophe | 2d02905 | 2015-04-17 16:32:18 +0200 | [diff] [blame] | 1727 | struct talitos_edesc *edesc, |
| 1728 | struct talitos_ptr *ptr) |
| 1729 | { |
| 1730 | static u8 padded_hash[64] = { |
| 1731 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1732 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1733 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1734 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1735 | }; |
| 1736 | |
| 1737 | pr_err_once("Bug in SEC1, padding ourself\n"); |
| 1738 | edesc->desc.hdr &= ~DESC_HDR_MODE0_MDEU_PAD; |
| 1739 | map_single_talitos_ptr(ctx->dev, ptr, sizeof(padded_hash), |
| 1740 | (char *)padded_hash, DMA_TO_DEVICE); |
| 1741 | } |
| 1742 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1743 | static int common_nonsnoop_hash(struct talitos_edesc *edesc, |
| 1744 | struct ahash_request *areq, unsigned int length, |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1745 | unsigned int offset, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1746 | void (*callback) (struct device *dev, |
| 1747 | struct talitos_desc *desc, |
| 1748 | void *context, int error)) |
| 1749 | { |
| 1750 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1751 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1752 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1753 | struct device *dev = ctx->dev; |
| 1754 | struct talitos_desc *desc = &edesc->desc; |
LEROY Christophe | 032d197 | 2015-04-17 16:31:51 +0200 | [diff] [blame] | 1755 | int ret; |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1756 | bool sync_needed = false; |
LEROY Christophe | 922f9dc | 2015-04-17 16:32:07 +0200 | [diff] [blame] | 1757 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1758 | bool is_sec1 = has_ftr_sec1(priv); |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1759 | int sg_count; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1760 | |
| 1761 | /* first DWORD empty */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1762 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1763 | /* hash context in */ |
| 1764 | if (!req_ctx->first || req_ctx->swinit) { |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1765 | to_talitos_ptr(&desc->ptr[1], ctx->dma_hw_context, |
| 1766 | req_ctx->hw_context_size, is_sec1); |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1767 | req_ctx->swinit = 0; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1768 | } |
LEROY Christophe | afd62fa | 2017-09-13 12:44:51 +0200 | [diff] [blame] | 1769 | /* Indicate next op is not the first. */ |
| 1770 | req_ctx->first = 0; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1771 | |
| 1772 | /* HMAC key */ |
| 1773 | if (ctx->keylen) |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 1774 | to_talitos_ptr(&desc->ptr[2], ctx->dma_key, ctx->keylen, |
| 1775 | is_sec1); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1776 | |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1777 | if (is_sec1 && req_ctx->nbuf) |
| 1778 | length -= req_ctx->nbuf; |
| 1779 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1780 | sg_count = edesc->src_nents ?: 1; |
| 1781 | if (is_sec1 && sg_count > 1) |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1782 | sg_pcopy_to_buffer(req_ctx->psrc, sg_count, |
| 1783 | edesc->buf + sizeof(struct talitos_desc), |
| 1784 | length, req_ctx->nbuf); |
| 1785 | else if (length) |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1786 | sg_count = dma_map_sg(dev, req_ctx->psrc, sg_count, |
| 1787 | DMA_TO_DEVICE); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1788 | /* |
| 1789 | * data in |
| 1790 | */ |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1791 | if (is_sec1 && req_ctx->nbuf) { |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 1792 | dma_addr_t dma_buf = ctx->dma_buf + req_ctx->buf_idx * |
| 1793 | HASH_MAX_BLOCK_SIZE; |
| 1794 | |
| 1795 | to_talitos_ptr(&desc->ptr[3], dma_buf, req_ctx->nbuf, is_sec1); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1796 | } else { |
| 1797 | sg_count = talitos_sg_map(dev, req_ctx->psrc, length, edesc, |
| 1798 | &desc->ptr[3], sg_count, offset, 0); |
| 1799 | if (sg_count > 1) |
| 1800 | sync_needed = true; |
| 1801 | } |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1802 | |
| 1803 | /* fifth DWORD empty */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1804 | |
| 1805 | /* hash/HMAC out -or- hash context out */ |
| 1806 | if (req_ctx->last) |
| 1807 | map_single_talitos_ptr(dev, &desc->ptr[5], |
| 1808 | crypto_ahash_digestsize(tfm), |
LEROY Christophe | a2b35aa | 2015-04-17 16:31:57 +0200 | [diff] [blame] | 1809 | areq->result, DMA_FROM_DEVICE); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1810 | else |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1811 | to_talitos_ptr(&desc->ptr[5], ctx->dma_hw_context, |
| 1812 | req_ctx->hw_context_size, is_sec1); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1813 | |
| 1814 | /* last DWORD empty */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1815 | |
LEROY Christophe | 2d02905 | 2015-04-17 16:32:18 +0200 | [diff] [blame] | 1816 | if (is_sec1 && from_talitos_ptr_len(&desc->ptr[3], true) == 0) |
| 1817 | talitos_handle_buggy_hash(ctx, edesc, &desc->ptr[3]); |
| 1818 | |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1819 | if (is_sec1 && req_ctx->nbuf && length) { |
| 1820 | struct talitos_desc *desc2 = desc + 1; |
| 1821 | dma_addr_t next_desc; |
| 1822 | |
| 1823 | memset(desc2, 0, sizeof(*desc2)); |
| 1824 | desc2->hdr = desc->hdr; |
| 1825 | desc2->hdr &= ~DESC_HDR_MODE0_MDEU_INIT; |
| 1826 | desc2->hdr1 = desc2->hdr; |
| 1827 | desc->hdr &= ~DESC_HDR_MODE0_MDEU_PAD; |
| 1828 | desc->hdr |= DESC_HDR_MODE0_MDEU_CONT; |
| 1829 | desc->hdr &= ~DESC_HDR_DONE_NOTIFY; |
| 1830 | |
| 1831 | to_talitos_ptr(&desc2->ptr[1], ctx->dma_hw_context, |
| 1832 | req_ctx->hw_context_size, is_sec1); |
| 1833 | |
| 1834 | copy_talitos_ptr(&desc2->ptr[2], &desc->ptr[2], is_sec1); |
| 1835 | sg_count = talitos_sg_map(dev, req_ctx->psrc, length, edesc, |
| 1836 | &desc2->ptr[3], sg_count, offset, 0); |
| 1837 | if (sg_count > 1) |
| 1838 | sync_needed = true; |
| 1839 | copy_talitos_ptr(&desc2->ptr[5], &desc->ptr[5], is_sec1); |
| 1840 | if (req_ctx->last) |
| 1841 | to_talitos_ptr(&desc->ptr[5], ctx->dma_hw_context, |
| 1842 | req_ctx->hw_context_size, is_sec1); |
| 1843 | |
| 1844 | next_desc = dma_map_single(dev, &desc2->hdr1, TALITOS_DESC_SIZE, |
| 1845 | DMA_BIDIRECTIONAL); |
| 1846 | desc->next_desc = cpu_to_be32(next_desc); |
| 1847 | } |
| 1848 | |
LEROY Christophe | 6a1e8d1 | 2016-06-06 13:20:38 +0200 | [diff] [blame] | 1849 | if (sync_needed) |
| 1850 | dma_sync_single_for_device(dev, edesc->dma_link_tbl, |
| 1851 | edesc->dma_len, DMA_BIDIRECTIONAL); |
| 1852 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 1853 | ret = talitos_submit(dev, ctx->ch, desc, callback, areq); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1854 | if (ret != -EINPROGRESS) { |
| 1855 | common_nonsnoop_hash_unmap(dev, edesc, areq); |
| 1856 | kfree(edesc); |
| 1857 | } |
| 1858 | return ret; |
| 1859 | } |
| 1860 | |
| 1861 | static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, |
| 1862 | unsigned int nbytes) |
| 1863 | { |
| 1864 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1865 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1866 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1867 | struct talitos_private *priv = dev_get_drvdata(ctx->dev); |
| 1868 | bool is_sec1 = has_ftr_sec1(priv); |
| 1869 | |
| 1870 | if (is_sec1) |
| 1871 | nbytes -= req_ctx->nbuf; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1872 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 1873 | return talitos_edesc_alloc(ctx->dev, req_ctx->psrc, NULL, NULL, 0, |
Horia Geanta | 62293a3 | 2013-11-28 15:11:17 +0200 | [diff] [blame] | 1874 | nbytes, 0, 0, 0, areq->base.flags, false); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | static int ahash_init(struct ahash_request *areq) |
| 1878 | { |
| 1879 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1880 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1881 | struct device *dev = ctx->dev; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1882 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1883 | unsigned int size; |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1884 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1885 | bool is_sec1 = has_ftr_sec1(priv); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1886 | |
| 1887 | /* Initialize the context */ |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 1888 | req_ctx->buf_idx = 0; |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1889 | req_ctx->nbuf = 0; |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1890 | req_ctx->first = 1; /* first indicates h/w must init its context */ |
| 1891 | req_ctx->swinit = 0; /* assume h/w init of context */ |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1892 | size = (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE) |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1893 | ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 |
| 1894 | : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1895 | req_ctx->hw_context_size = size; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1896 | |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1897 | if (ctx->dma_hw_context) |
| 1898 | dma_unmap_single(dev, ctx->dma_hw_context, size, |
| 1899 | DMA_BIDIRECTIONAL); |
| 1900 | ctx->dma_hw_context = dma_map_single(dev, req_ctx->hw_context, size, |
| 1901 | DMA_BIDIRECTIONAL); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1902 | if (ctx->dma_buf) |
| 1903 | dma_unmap_single(dev, ctx->dma_buf, sizeof(req_ctx->buf), |
| 1904 | DMA_TO_DEVICE); |
| 1905 | if (is_sec1) |
| 1906 | ctx->dma_buf = dma_map_single(dev, req_ctx->buf, |
| 1907 | sizeof(req_ctx->buf), |
| 1908 | DMA_TO_DEVICE); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1909 | return 0; |
| 1910 | } |
| 1911 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1912 | /* |
| 1913 | * on h/w without explicit sha224 support, we initialize h/w context |
| 1914 | * manually with sha224 constants, and tell it to run sha256. |
| 1915 | */ |
| 1916 | static int ahash_init_sha224_swinit(struct ahash_request *areq) |
| 1917 | { |
| 1918 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1919 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1920 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1921 | struct device *dev = ctx->dev; |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1922 | |
| 1923 | ahash_init(areq); |
| 1924 | req_ctx->swinit = 1;/* prevent h/w initting context with sha256 values*/ |
| 1925 | |
Kim Phillips | a752447 | 2010-09-23 15:56:38 +0800 | [diff] [blame] | 1926 | req_ctx->hw_context[0] = SHA224_H0; |
| 1927 | req_ctx->hw_context[1] = SHA224_H1; |
| 1928 | req_ctx->hw_context[2] = SHA224_H2; |
| 1929 | req_ctx->hw_context[3] = SHA224_H3; |
| 1930 | req_ctx->hw_context[4] = SHA224_H4; |
| 1931 | req_ctx->hw_context[5] = SHA224_H5; |
| 1932 | req_ctx->hw_context[6] = SHA224_H6; |
| 1933 | req_ctx->hw_context[7] = SHA224_H7; |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1934 | |
| 1935 | /* init 64-bit count */ |
| 1936 | req_ctx->hw_context[8] = 0; |
| 1937 | req_ctx->hw_context[9] = 0; |
| 1938 | |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 1939 | dma_sync_single_for_device(dev, ctx->dma_hw_context, |
| 1940 | req_ctx->hw_context_size, DMA_TO_DEVICE); |
| 1941 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1942 | return 0; |
| 1943 | } |
| 1944 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1945 | static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) |
| 1946 | { |
| 1947 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1948 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1949 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1950 | struct talitos_edesc *edesc; |
| 1951 | unsigned int blocksize = |
| 1952 | crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); |
| 1953 | unsigned int nbytes_to_hash; |
| 1954 | unsigned int to_hash_later; |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1955 | unsigned int nsg; |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1956 | int nents; |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1957 | struct device *dev = ctx->dev; |
| 1958 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 1959 | bool is_sec1 = has_ftr_sec1(priv); |
| 1960 | int offset = 0; |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 1961 | u8 *ctx_buf = req_ctx->buf[req_ctx->buf_idx]; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1962 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1963 | if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) { |
| 1964 | /* Buffer up to one whole block */ |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 1965 | nents = sg_nents_for_len(areq->src, nbytes); |
| 1966 | if (nents < 0) { |
| 1967 | dev_err(ctx->dev, "Invalid number of src SG.\n"); |
| 1968 | return nents; |
| 1969 | } |
| 1970 | sg_copy_to_buffer(areq->src, nents, |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 1971 | ctx_buf + req_ctx->nbuf, nbytes); |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1972 | req_ctx->nbuf += nbytes; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1973 | return 0; |
| 1974 | } |
| 1975 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1976 | /* At least (blocksize + 1) bytes are available to hash */ |
| 1977 | nbytes_to_hash = nbytes + req_ctx->nbuf; |
| 1978 | to_hash_later = nbytes_to_hash & (blocksize - 1); |
| 1979 | |
| 1980 | if (req_ctx->last) |
| 1981 | to_hash_later = 0; |
| 1982 | else if (to_hash_later) |
| 1983 | /* There is a partial block. Hash the full block(s) now */ |
| 1984 | nbytes_to_hash -= to_hash_later; |
| 1985 | else { |
| 1986 | /* Keep one block buffered */ |
| 1987 | nbytes_to_hash -= blocksize; |
| 1988 | to_hash_later = blocksize; |
| 1989 | } |
| 1990 | |
| 1991 | /* Chain in any previously buffered data */ |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1992 | if (!is_sec1 && req_ctx->nbuf) { |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1993 | nsg = (req_ctx->nbuf < nbytes_to_hash) ? 2 : 1; |
| 1994 | sg_init_table(req_ctx->bufsl, nsg); |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 1995 | sg_set_buf(req_ctx->bufsl, ctx_buf, req_ctx->nbuf); |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1996 | if (nsg > 1) |
Dan Williams | c56f6d1 | 2015-08-07 18:15:13 +0200 | [diff] [blame] | 1997 | sg_chain(req_ctx->bufsl, 2, areq->src); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1998 | req_ctx->psrc = req_ctx->bufsl; |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 1999 | } else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) { |
| 2000 | if (nbytes_to_hash > blocksize) |
| 2001 | offset = blocksize - req_ctx->nbuf; |
| 2002 | else |
| 2003 | offset = nbytes_to_hash - req_ctx->nbuf; |
| 2004 | nents = sg_nents_for_len(areq->src, offset); |
| 2005 | if (nents < 0) { |
| 2006 | dev_err(ctx->dev, "Invalid number of src SG.\n"); |
| 2007 | return nents; |
| 2008 | } |
| 2009 | sg_copy_to_buffer(areq->src, nents, |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 2010 | ctx_buf + req_ctx->nbuf, offset); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 2011 | req_ctx->nbuf += offset; |
| 2012 | req_ctx->psrc = areq->src; |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 2013 | } else |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2014 | req_ctx->psrc = areq->src; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2015 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 2016 | if (to_hash_later) { |
LABBE Corentin | 8e409fe | 2015-11-04 21:13:34 +0100 | [diff] [blame] | 2017 | nents = sg_nents_for_len(areq->src, nbytes); |
| 2018 | if (nents < 0) { |
| 2019 | dev_err(ctx->dev, "Invalid number of src SG.\n"); |
| 2020 | return nents; |
| 2021 | } |
Akinobu Mita | d052572 | 2013-07-08 16:01:55 -0700 | [diff] [blame] | 2022 | sg_pcopy_to_buffer(areq->src, nents, |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 2023 | req_ctx->buf[(req_ctx->buf_idx + 1) & 1], |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 2024 | to_hash_later, |
| 2025 | nbytes - to_hash_later); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2026 | } |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 2027 | req_ctx->to_hash_later = to_hash_later; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2028 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 2029 | /* Allocate extended descriptor */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2030 | edesc = ahash_edesc_alloc(areq, nbytes_to_hash); |
| 2031 | if (IS_ERR(edesc)) |
| 2032 | return PTR_ERR(edesc); |
| 2033 | |
| 2034 | edesc->desc.hdr = ctx->desc_hdr_template; |
| 2035 | |
| 2036 | /* On last one, request SEC to pad; otherwise continue */ |
| 2037 | if (req_ctx->last) |
| 2038 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_PAD; |
| 2039 | else |
| 2040 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_CONT; |
| 2041 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2042 | /* request SEC to INIT hash. */ |
| 2043 | if (req_ctx->first && !req_ctx->swinit) |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2044 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_INIT; |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 2045 | if (is_sec1) { |
| 2046 | dma_addr_t dma_buf = ctx->dma_buf + req_ctx->buf_idx * |
| 2047 | HASH_MAX_BLOCK_SIZE; |
| 2048 | |
| 2049 | dma_sync_single_for_device(dev, dma_buf, |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 2050 | req_ctx->nbuf, DMA_TO_DEVICE); |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 2051 | } |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2052 | |
| 2053 | /* When the tfm context has a keylen, it's an HMAC. |
| 2054 | * A first or last (ie. not middle) descriptor must request HMAC. |
| 2055 | */ |
| 2056 | if (ctx->keylen && (req_ctx->first || req_ctx->last)) |
| 2057 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_HMAC; |
| 2058 | |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 2059 | return common_nonsnoop_hash(edesc, areq, nbytes_to_hash, offset, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2060 | ahash_done); |
| 2061 | } |
| 2062 | |
| 2063 | static int ahash_update(struct ahash_request *areq) |
| 2064 | { |
| 2065 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 2066 | |
| 2067 | req_ctx->last = 0; |
| 2068 | |
| 2069 | return ahash_process_req(areq, areq->nbytes); |
| 2070 | } |
| 2071 | |
| 2072 | static int ahash_final(struct ahash_request *areq) |
| 2073 | { |
| 2074 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 2075 | |
| 2076 | req_ctx->last = 1; |
| 2077 | |
| 2078 | return ahash_process_req(areq, 0); |
| 2079 | } |
| 2080 | |
| 2081 | static int ahash_finup(struct ahash_request *areq) |
| 2082 | { |
| 2083 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 2084 | |
| 2085 | req_ctx->last = 1; |
| 2086 | |
| 2087 | return ahash_process_req(areq, areq->nbytes); |
| 2088 | } |
| 2089 | |
| 2090 | static int ahash_digest(struct ahash_request *areq) |
| 2091 | { |
| 2092 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2093 | struct crypto_ahash *ahash = crypto_ahash_reqtfm(areq); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2094 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2095 | ahash->init(areq); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2096 | req_ctx->last = 1; |
| 2097 | |
| 2098 | return ahash_process_req(areq, areq->nbytes); |
| 2099 | } |
| 2100 | |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2101 | static int ahash_export(struct ahash_request *areq, void *out) |
| 2102 | { |
| 2103 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 2104 | struct talitos_export_state *export = out; |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 2105 | struct crypto_ahash *ahash = crypto_ahash_reqtfm(areq); |
| 2106 | struct talitos_ctx *ctx = crypto_ahash_ctx(ahash); |
| 2107 | struct device *dev = ctx->dev; |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2108 | |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 2109 | dma_sync_single_for_cpu(dev, ctx->dma_hw_context, |
| 2110 | req_ctx->hw_context_size, DMA_FROM_DEVICE); |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2111 | memcpy(export->hw_context, req_ctx->hw_context, |
| 2112 | req_ctx->hw_context_size); |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 2113 | memcpy(export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2114 | export->swinit = req_ctx->swinit; |
| 2115 | export->first = req_ctx->first; |
| 2116 | export->last = req_ctx->last; |
| 2117 | export->to_hash_later = req_ctx->to_hash_later; |
| 2118 | export->nbuf = req_ctx->nbuf; |
| 2119 | |
| 2120 | return 0; |
| 2121 | } |
| 2122 | |
| 2123 | static int ahash_import(struct ahash_request *areq, const void *in) |
| 2124 | { |
| 2125 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 2126 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 2127 | const struct talitos_export_state *export = in; |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 2128 | unsigned int size; |
| 2129 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 2130 | struct device *dev = ctx->dev; |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 2131 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 2132 | bool is_sec1 = has_ftr_sec1(priv); |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2133 | |
| 2134 | memset(req_ctx, 0, sizeof(*req_ctx)); |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 2135 | size = (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE) |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2136 | ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 |
| 2137 | : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 2138 | req_ctx->hw_context_size = size; |
| 2139 | if (ctx->dma_hw_context) |
| 2140 | dma_unmap_single(dev, ctx->dma_hw_context, size, |
| 2141 | DMA_BIDIRECTIONAL); |
| 2142 | |
| 2143 | memcpy(req_ctx->hw_context, export->hw_context, size); |
| 2144 | ctx->dma_hw_context = dma_map_single(dev, req_ctx->hw_context, size, |
| 2145 | DMA_BIDIRECTIONAL); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 2146 | if (ctx->dma_buf) |
| 2147 | dma_unmap_single(dev, ctx->dma_buf, sizeof(req_ctx->buf), |
| 2148 | DMA_TO_DEVICE); |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 2149 | memcpy(req_ctx->buf[0], export->buf, export->nbuf); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 2150 | if (is_sec1) |
| 2151 | ctx->dma_buf = dma_map_single(dev, req_ctx->buf, |
| 2152 | sizeof(req_ctx->buf), |
| 2153 | DMA_TO_DEVICE); |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2154 | req_ctx->swinit = export->swinit; |
| 2155 | req_ctx->first = export->first; |
| 2156 | req_ctx->last = export->last; |
| 2157 | req_ctx->to_hash_later = export->to_hash_later; |
| 2158 | req_ctx->nbuf = export->nbuf; |
| 2159 | |
| 2160 | return 0; |
| 2161 | } |
| 2162 | |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2163 | struct keyhash_result { |
| 2164 | struct completion completion; |
| 2165 | int err; |
| 2166 | }; |
| 2167 | |
| 2168 | static void keyhash_complete(struct crypto_async_request *req, int err) |
| 2169 | { |
| 2170 | struct keyhash_result *res = req->data; |
| 2171 | |
| 2172 | if (err == -EINPROGRESS) |
| 2173 | return; |
| 2174 | |
| 2175 | res->err = err; |
| 2176 | complete(&res->completion); |
| 2177 | } |
| 2178 | |
| 2179 | static int keyhash(struct crypto_ahash *tfm, const u8 *key, unsigned int keylen, |
| 2180 | u8 *hash) |
| 2181 | { |
| 2182 | struct talitos_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
| 2183 | |
| 2184 | struct scatterlist sg[1]; |
| 2185 | struct ahash_request *req; |
| 2186 | struct keyhash_result hresult; |
| 2187 | int ret; |
| 2188 | |
| 2189 | init_completion(&hresult.completion); |
| 2190 | |
| 2191 | req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 2192 | if (!req) |
| 2193 | return -ENOMEM; |
| 2194 | |
| 2195 | /* Keep tfm keylen == 0 during hash of the long key */ |
| 2196 | ctx->keylen = 0; |
| 2197 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 2198 | keyhash_complete, &hresult); |
| 2199 | |
| 2200 | sg_init_one(&sg[0], key, keylen); |
| 2201 | |
| 2202 | ahash_request_set_crypt(req, sg, hash, keylen); |
| 2203 | ret = crypto_ahash_digest(req); |
| 2204 | switch (ret) { |
| 2205 | case 0: |
| 2206 | break; |
| 2207 | case -EINPROGRESS: |
| 2208 | case -EBUSY: |
| 2209 | ret = wait_for_completion_interruptible( |
| 2210 | &hresult.completion); |
| 2211 | if (!ret) |
| 2212 | ret = hresult.err; |
| 2213 | break; |
| 2214 | default: |
| 2215 | break; |
| 2216 | } |
| 2217 | ahash_request_free(req); |
| 2218 | |
| 2219 | return ret; |
| 2220 | } |
| 2221 | |
| 2222 | static int ahash_setkey(struct crypto_ahash *tfm, const u8 *key, |
| 2223 | unsigned int keylen) |
| 2224 | { |
| 2225 | struct talitos_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 2226 | struct device *dev = ctx->dev; |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2227 | unsigned int blocksize = |
| 2228 | crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); |
| 2229 | unsigned int digestsize = crypto_ahash_digestsize(tfm); |
| 2230 | unsigned int keysize = keylen; |
| 2231 | u8 hash[SHA512_DIGEST_SIZE]; |
| 2232 | int ret; |
| 2233 | |
| 2234 | if (keylen <= blocksize) |
| 2235 | memcpy(ctx->key, key, keysize); |
| 2236 | else { |
| 2237 | /* Must get the hash of the long key */ |
| 2238 | ret = keyhash(tfm, key, keylen, hash); |
| 2239 | |
| 2240 | if (ret) { |
| 2241 | crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 2242 | return -EINVAL; |
| 2243 | } |
| 2244 | |
| 2245 | keysize = digestsize; |
| 2246 | memcpy(ctx->key, hash, digestsize); |
| 2247 | } |
| 2248 | |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 2249 | if (ctx->keylen) |
| 2250 | dma_unmap_single(dev, ctx->dma_key, ctx->keylen, DMA_TO_DEVICE); |
| 2251 | |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2252 | ctx->keylen = keysize; |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 2253 | ctx->dma_key = dma_map_single(dev, ctx->key, keysize, DMA_TO_DEVICE); |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2254 | |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
| 2258 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2259 | struct talitos_alg_template { |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2260 | u32 type; |
LEROY Christophe | b005776 | 2016-06-06 13:20:44 +0200 | [diff] [blame] | 2261 | u32 priority; |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2262 | union { |
| 2263 | struct crypto_alg crypto; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2264 | struct ahash_alg hash; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2265 | struct aead_alg aead; |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2266 | } alg; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2267 | __be32 desc_hdr_template; |
| 2268 | }; |
| 2269 | |
| 2270 | static struct talitos_alg_template driver_algs[] = { |
Horia Geanta | 991155b | 2013-03-20 16:31:38 +0200 | [diff] [blame] | 2271 | /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */ |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2272 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2273 | .alg.aead = { |
| 2274 | .base = { |
| 2275 | .cra_name = "authenc(hmac(sha1),cbc(aes))", |
| 2276 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2277 | "cbc-aes-talitos", |
| 2278 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2279 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2280 | }, |
| 2281 | .ivsize = AES_BLOCK_SIZE, |
| 2282 | .maxauthsize = SHA1_DIGEST_SIZE, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2283 | }, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2284 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2285 | DESC_HDR_SEL0_AESU | |
| 2286 | DESC_HDR_MODE0_AESU_CBC | |
| 2287 | DESC_HDR_SEL1_MDEUA | |
| 2288 | DESC_HDR_MODE1_MDEU_INIT | |
| 2289 | DESC_HDR_MODE1_MDEU_PAD | |
| 2290 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 2291 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2292 | { .type = CRYPTO_ALG_TYPE_AEAD, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2293 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2294 | .alg.aead = { |
| 2295 | .base = { |
| 2296 | .cra_name = "authenc(hmac(sha1),cbc(aes))", |
| 2297 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2298 | "cbc-aes-talitos", |
| 2299 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2300 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2301 | }, |
| 2302 | .ivsize = AES_BLOCK_SIZE, |
| 2303 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2304 | }, |
| 2305 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2306 | DESC_HDR_SEL0_AESU | |
| 2307 | DESC_HDR_MODE0_AESU_CBC | |
| 2308 | DESC_HDR_SEL1_MDEUA | |
| 2309 | DESC_HDR_MODE1_MDEU_INIT | |
| 2310 | DESC_HDR_MODE1_MDEU_PAD | |
| 2311 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
| 2312 | }, |
| 2313 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2314 | .alg.aead = { |
| 2315 | .base = { |
| 2316 | .cra_name = "authenc(hmac(sha1)," |
| 2317 | "cbc(des3_ede))", |
| 2318 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2319 | "cbc-3des-talitos", |
| 2320 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2321 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2322 | }, |
| 2323 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2324 | .maxauthsize = SHA1_DIGEST_SIZE, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2325 | }, |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 2326 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2327 | DESC_HDR_SEL0_DEU | |
| 2328 | DESC_HDR_MODE0_DEU_CBC | |
| 2329 | DESC_HDR_MODE0_DEU_3DES | |
| 2330 | DESC_HDR_SEL1_MDEUA | |
| 2331 | DESC_HDR_MODE1_MDEU_INIT | |
| 2332 | DESC_HDR_MODE1_MDEU_PAD | |
| 2333 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2334 | }, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2335 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2336 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2337 | .alg.aead = { |
| 2338 | .base = { |
| 2339 | .cra_name = "authenc(hmac(sha1)," |
| 2340 | "cbc(des3_ede))", |
| 2341 | .cra_driver_name = "authenc-hmac-sha1-" |
| 2342 | "cbc-3des-talitos", |
| 2343 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2344 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2345 | }, |
| 2346 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2347 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2348 | }, |
| 2349 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2350 | DESC_HDR_SEL0_DEU | |
| 2351 | DESC_HDR_MODE0_DEU_CBC | |
| 2352 | DESC_HDR_MODE0_DEU_3DES | |
| 2353 | DESC_HDR_SEL1_MDEUA | |
| 2354 | DESC_HDR_MODE1_MDEU_INIT | |
| 2355 | DESC_HDR_MODE1_MDEU_PAD | |
| 2356 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
| 2357 | }, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2358 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2359 | .alg.aead = { |
| 2360 | .base = { |
| 2361 | .cra_name = "authenc(hmac(sha224),cbc(aes))", |
| 2362 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2363 | "cbc-aes-talitos", |
| 2364 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2365 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2366 | }, |
| 2367 | .ivsize = AES_BLOCK_SIZE, |
| 2368 | .maxauthsize = SHA224_DIGEST_SIZE, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2369 | }, |
| 2370 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2371 | DESC_HDR_SEL0_AESU | |
| 2372 | DESC_HDR_MODE0_AESU_CBC | |
| 2373 | DESC_HDR_SEL1_MDEUA | |
| 2374 | DESC_HDR_MODE1_MDEU_INIT | |
| 2375 | DESC_HDR_MODE1_MDEU_PAD | |
| 2376 | DESC_HDR_MODE1_MDEU_SHA224_HMAC, |
| 2377 | }, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2378 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2379 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2380 | .alg.aead = { |
| 2381 | .base = { |
| 2382 | .cra_name = "authenc(hmac(sha224),cbc(aes))", |
| 2383 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2384 | "cbc-aes-talitos", |
| 2385 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2386 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2387 | }, |
| 2388 | .ivsize = AES_BLOCK_SIZE, |
| 2389 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2390 | }, |
| 2391 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2392 | DESC_HDR_SEL0_AESU | |
| 2393 | DESC_HDR_MODE0_AESU_CBC | |
| 2394 | DESC_HDR_SEL1_MDEUA | |
| 2395 | DESC_HDR_MODE1_MDEU_INIT | |
| 2396 | DESC_HDR_MODE1_MDEU_PAD | |
| 2397 | DESC_HDR_MODE1_MDEU_SHA224_HMAC, |
| 2398 | }, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2399 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2400 | .alg.aead = { |
| 2401 | .base = { |
| 2402 | .cra_name = "authenc(hmac(sha224)," |
| 2403 | "cbc(des3_ede))", |
| 2404 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2405 | "cbc-3des-talitos", |
| 2406 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2407 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2408 | }, |
| 2409 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2410 | .maxauthsize = SHA224_DIGEST_SIZE, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2411 | }, |
| 2412 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2413 | DESC_HDR_SEL0_DEU | |
| 2414 | DESC_HDR_MODE0_DEU_CBC | |
| 2415 | DESC_HDR_MODE0_DEU_3DES | |
| 2416 | DESC_HDR_SEL1_MDEUA | |
| 2417 | DESC_HDR_MODE1_MDEU_INIT | |
| 2418 | DESC_HDR_MODE1_MDEU_PAD | |
| 2419 | DESC_HDR_MODE1_MDEU_SHA224_HMAC, |
| 2420 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2421 | { .type = CRYPTO_ALG_TYPE_AEAD, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2422 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2423 | .alg.aead = { |
| 2424 | .base = { |
| 2425 | .cra_name = "authenc(hmac(sha224)," |
| 2426 | "cbc(des3_ede))", |
| 2427 | .cra_driver_name = "authenc-hmac-sha224-" |
| 2428 | "cbc-3des-talitos", |
| 2429 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2430 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2431 | }, |
| 2432 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2433 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2434 | }, |
| 2435 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2436 | DESC_HDR_SEL0_DEU | |
| 2437 | DESC_HDR_MODE0_DEU_CBC | |
| 2438 | DESC_HDR_MODE0_DEU_3DES | |
| 2439 | DESC_HDR_SEL1_MDEUA | |
| 2440 | DESC_HDR_MODE1_MDEU_INIT | |
| 2441 | DESC_HDR_MODE1_MDEU_PAD | |
| 2442 | DESC_HDR_MODE1_MDEU_SHA224_HMAC, |
| 2443 | }, |
| 2444 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2445 | .alg.aead = { |
| 2446 | .base = { |
| 2447 | .cra_name = "authenc(hmac(sha256),cbc(aes))", |
| 2448 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2449 | "cbc-aes-talitos", |
| 2450 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2451 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2452 | }, |
| 2453 | .ivsize = AES_BLOCK_SIZE, |
| 2454 | .maxauthsize = SHA256_DIGEST_SIZE, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2455 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2456 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2457 | DESC_HDR_SEL0_AESU | |
| 2458 | DESC_HDR_MODE0_AESU_CBC | |
| 2459 | DESC_HDR_SEL1_MDEUA | |
| 2460 | DESC_HDR_MODE1_MDEU_INIT | |
| 2461 | DESC_HDR_MODE1_MDEU_PAD | |
| 2462 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
| 2463 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2464 | { .type = CRYPTO_ALG_TYPE_AEAD, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2465 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2466 | .alg.aead = { |
| 2467 | .base = { |
| 2468 | .cra_name = "authenc(hmac(sha256),cbc(aes))", |
| 2469 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2470 | "cbc-aes-talitos", |
| 2471 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2472 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2473 | }, |
| 2474 | .ivsize = AES_BLOCK_SIZE, |
| 2475 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2476 | }, |
| 2477 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2478 | DESC_HDR_SEL0_AESU | |
| 2479 | DESC_HDR_MODE0_AESU_CBC | |
| 2480 | DESC_HDR_SEL1_MDEUA | |
| 2481 | DESC_HDR_MODE1_MDEU_INIT | |
| 2482 | DESC_HDR_MODE1_MDEU_PAD | |
| 2483 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
| 2484 | }, |
| 2485 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2486 | .alg.aead = { |
| 2487 | .base = { |
| 2488 | .cra_name = "authenc(hmac(sha256)," |
| 2489 | "cbc(des3_ede))", |
| 2490 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2491 | "cbc-3des-talitos", |
| 2492 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2493 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2494 | }, |
| 2495 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2496 | .maxauthsize = SHA256_DIGEST_SIZE, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2497 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2498 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2499 | DESC_HDR_SEL0_DEU | |
| 2500 | DESC_HDR_MODE0_DEU_CBC | |
| 2501 | DESC_HDR_MODE0_DEU_3DES | |
| 2502 | DESC_HDR_SEL1_MDEUA | |
| 2503 | DESC_HDR_MODE1_MDEU_INIT | |
| 2504 | DESC_HDR_MODE1_MDEU_PAD | |
| 2505 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
| 2506 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2507 | { .type = CRYPTO_ALG_TYPE_AEAD, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2508 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2509 | .alg.aead = { |
| 2510 | .base = { |
| 2511 | .cra_name = "authenc(hmac(sha256)," |
| 2512 | "cbc(des3_ede))", |
| 2513 | .cra_driver_name = "authenc-hmac-sha256-" |
| 2514 | "cbc-3des-talitos", |
| 2515 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2516 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2517 | }, |
| 2518 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2519 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2520 | }, |
| 2521 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2522 | DESC_HDR_SEL0_DEU | |
| 2523 | DESC_HDR_MODE0_DEU_CBC | |
| 2524 | DESC_HDR_MODE0_DEU_3DES | |
| 2525 | DESC_HDR_SEL1_MDEUA | |
| 2526 | DESC_HDR_MODE1_MDEU_INIT | |
| 2527 | DESC_HDR_MODE1_MDEU_PAD | |
| 2528 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
| 2529 | }, |
| 2530 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2531 | .alg.aead = { |
| 2532 | .base = { |
| 2533 | .cra_name = "authenc(hmac(sha384),cbc(aes))", |
| 2534 | .cra_driver_name = "authenc-hmac-sha384-" |
| 2535 | "cbc-aes-talitos", |
| 2536 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2537 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2538 | }, |
| 2539 | .ivsize = AES_BLOCK_SIZE, |
| 2540 | .maxauthsize = SHA384_DIGEST_SIZE, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2541 | }, |
| 2542 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2543 | DESC_HDR_SEL0_AESU | |
| 2544 | DESC_HDR_MODE0_AESU_CBC | |
| 2545 | DESC_HDR_SEL1_MDEUB | |
| 2546 | DESC_HDR_MODE1_MDEU_INIT | |
| 2547 | DESC_HDR_MODE1_MDEU_PAD | |
| 2548 | DESC_HDR_MODE1_MDEUB_SHA384_HMAC, |
| 2549 | }, |
| 2550 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2551 | .alg.aead = { |
| 2552 | .base = { |
| 2553 | .cra_name = "authenc(hmac(sha384)," |
| 2554 | "cbc(des3_ede))", |
| 2555 | .cra_driver_name = "authenc-hmac-sha384-" |
| 2556 | "cbc-3des-talitos", |
| 2557 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2558 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2559 | }, |
| 2560 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2561 | .maxauthsize = SHA384_DIGEST_SIZE, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2562 | }, |
| 2563 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2564 | DESC_HDR_SEL0_DEU | |
| 2565 | DESC_HDR_MODE0_DEU_CBC | |
| 2566 | DESC_HDR_MODE0_DEU_3DES | |
| 2567 | DESC_HDR_SEL1_MDEUB | |
| 2568 | DESC_HDR_MODE1_MDEU_INIT | |
| 2569 | DESC_HDR_MODE1_MDEU_PAD | |
| 2570 | DESC_HDR_MODE1_MDEUB_SHA384_HMAC, |
| 2571 | }, |
| 2572 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2573 | .alg.aead = { |
| 2574 | .base = { |
| 2575 | .cra_name = "authenc(hmac(sha512),cbc(aes))", |
| 2576 | .cra_driver_name = "authenc-hmac-sha512-" |
| 2577 | "cbc-aes-talitos", |
| 2578 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2579 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2580 | }, |
| 2581 | .ivsize = AES_BLOCK_SIZE, |
| 2582 | .maxauthsize = SHA512_DIGEST_SIZE, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2583 | }, |
| 2584 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2585 | DESC_HDR_SEL0_AESU | |
| 2586 | DESC_HDR_MODE0_AESU_CBC | |
| 2587 | DESC_HDR_SEL1_MDEUB | |
| 2588 | DESC_HDR_MODE1_MDEU_INIT | |
| 2589 | DESC_HDR_MODE1_MDEU_PAD | |
| 2590 | DESC_HDR_MODE1_MDEUB_SHA512_HMAC, |
| 2591 | }, |
| 2592 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2593 | .alg.aead = { |
| 2594 | .base = { |
| 2595 | .cra_name = "authenc(hmac(sha512)," |
| 2596 | "cbc(des3_ede))", |
| 2597 | .cra_driver_name = "authenc-hmac-sha512-" |
| 2598 | "cbc-3des-talitos", |
| 2599 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2600 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2601 | }, |
| 2602 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2603 | .maxauthsize = SHA512_DIGEST_SIZE, |
Horia Geanta | 357fb60 | 2012-07-03 19:16:53 +0300 | [diff] [blame] | 2604 | }, |
| 2605 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2606 | DESC_HDR_SEL0_DEU | |
| 2607 | DESC_HDR_MODE0_DEU_CBC | |
| 2608 | DESC_HDR_MODE0_DEU_3DES | |
| 2609 | DESC_HDR_SEL1_MDEUB | |
| 2610 | DESC_HDR_MODE1_MDEU_INIT | |
| 2611 | DESC_HDR_MODE1_MDEU_PAD | |
| 2612 | DESC_HDR_MODE1_MDEUB_SHA512_HMAC, |
| 2613 | }, |
| 2614 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2615 | .alg.aead = { |
| 2616 | .base = { |
| 2617 | .cra_name = "authenc(hmac(md5),cbc(aes))", |
| 2618 | .cra_driver_name = "authenc-hmac-md5-" |
| 2619 | "cbc-aes-talitos", |
| 2620 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2621 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2622 | }, |
| 2623 | .ivsize = AES_BLOCK_SIZE, |
| 2624 | .maxauthsize = MD5_DIGEST_SIZE, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2625 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2626 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2627 | DESC_HDR_SEL0_AESU | |
| 2628 | DESC_HDR_MODE0_AESU_CBC | |
| 2629 | DESC_HDR_SEL1_MDEUA | |
| 2630 | DESC_HDR_MODE1_MDEU_INIT | |
| 2631 | DESC_HDR_MODE1_MDEU_PAD | |
| 2632 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
| 2633 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2634 | { .type = CRYPTO_ALG_TYPE_AEAD, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2635 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2636 | .alg.aead = { |
| 2637 | .base = { |
| 2638 | .cra_name = "authenc(hmac(md5),cbc(aes))", |
| 2639 | .cra_driver_name = "authenc-hmac-md5-" |
| 2640 | "cbc-aes-talitos", |
| 2641 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2642 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2643 | }, |
| 2644 | .ivsize = AES_BLOCK_SIZE, |
| 2645 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2646 | }, |
| 2647 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2648 | DESC_HDR_SEL0_AESU | |
| 2649 | DESC_HDR_MODE0_AESU_CBC | |
| 2650 | DESC_HDR_SEL1_MDEUA | |
| 2651 | DESC_HDR_MODE1_MDEU_INIT | |
| 2652 | DESC_HDR_MODE1_MDEU_PAD | |
| 2653 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
| 2654 | }, |
| 2655 | { .type = CRYPTO_ALG_TYPE_AEAD, |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 2656 | .alg.aead = { |
| 2657 | .base = { |
| 2658 | .cra_name = "authenc(hmac(md5),cbc(des3_ede))", |
| 2659 | .cra_driver_name = "authenc-hmac-md5-" |
| 2660 | "cbc-3des-talitos", |
| 2661 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2662 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2663 | }, |
| 2664 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2665 | .maxauthsize = MD5_DIGEST_SIZE, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2666 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2667 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2668 | DESC_HDR_SEL0_DEU | |
| 2669 | DESC_HDR_MODE0_DEU_CBC | |
| 2670 | DESC_HDR_MODE0_DEU_3DES | |
| 2671 | DESC_HDR_SEL1_MDEUA | |
| 2672 | DESC_HDR_MODE1_MDEU_INIT | |
| 2673 | DESC_HDR_MODE1_MDEU_PAD | |
| 2674 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2675 | }, |
LEROY Christophe | 7405c8d | 2016-06-06 13:20:46 +0200 | [diff] [blame] | 2676 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2677 | .priority = TALITOS_CRA_PRIORITY_AEAD_HSNA, |
| 2678 | .alg.aead = { |
| 2679 | .base = { |
| 2680 | .cra_name = "authenc(hmac(md5),cbc(des3_ede))", |
| 2681 | .cra_driver_name = "authenc-hmac-md5-" |
| 2682 | "cbc-3des-talitos", |
| 2683 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2684 | .cra_flags = CRYPTO_ALG_ASYNC, |
| 2685 | }, |
| 2686 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2687 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2688 | }, |
| 2689 | .desc_hdr_template = DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU | |
| 2690 | DESC_HDR_SEL0_DEU | |
| 2691 | DESC_HDR_MODE0_DEU_CBC | |
| 2692 | DESC_HDR_MODE0_DEU_3DES | |
| 2693 | DESC_HDR_SEL1_MDEUA | |
| 2694 | DESC_HDR_MODE1_MDEU_INIT | |
| 2695 | DESC_HDR_MODE1_MDEU_PAD | |
| 2696 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
| 2697 | }, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2698 | /* ABLKCIPHER algorithms. */ |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2699 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2700 | .alg.crypto = { |
LEROY Christophe | 5e75ae1 | 2015-12-01 12:44:15 +0100 | [diff] [blame] | 2701 | .cra_name = "ecb(aes)", |
| 2702 | .cra_driver_name = "ecb-aes-talitos", |
| 2703 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2704 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2705 | CRYPTO_ALG_ASYNC, |
| 2706 | .cra_ablkcipher = { |
| 2707 | .min_keysize = AES_MIN_KEY_SIZE, |
| 2708 | .max_keysize = AES_MAX_KEY_SIZE, |
| 2709 | .ivsize = AES_BLOCK_SIZE, |
| 2710 | } |
| 2711 | }, |
| 2712 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2713 | DESC_HDR_SEL0_AESU, |
| 2714 | }, |
| 2715 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2716 | .alg.crypto = { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2717 | .cra_name = "cbc(aes)", |
| 2718 | .cra_driver_name = "cbc-aes-talitos", |
| 2719 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2720 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2721 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2722 | .cra_ablkcipher = { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2723 | .min_keysize = AES_MIN_KEY_SIZE, |
| 2724 | .max_keysize = AES_MAX_KEY_SIZE, |
| 2725 | .ivsize = AES_BLOCK_SIZE, |
| 2726 | } |
| 2727 | }, |
| 2728 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2729 | DESC_HDR_SEL0_AESU | |
| 2730 | DESC_HDR_MODE0_AESU_CBC, |
| 2731 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2732 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2733 | .alg.crypto = { |
LEROY Christophe | 5e75ae1 | 2015-12-01 12:44:15 +0100 | [diff] [blame] | 2734 | .cra_name = "ctr(aes)", |
| 2735 | .cra_driver_name = "ctr-aes-talitos", |
| 2736 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2737 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2738 | CRYPTO_ALG_ASYNC, |
| 2739 | .cra_ablkcipher = { |
| 2740 | .min_keysize = AES_MIN_KEY_SIZE, |
| 2741 | .max_keysize = AES_MAX_KEY_SIZE, |
| 2742 | .ivsize = AES_BLOCK_SIZE, |
| 2743 | } |
| 2744 | }, |
LEROY Christophe | 70d355c | 2017-10-06 15:04:43 +0200 | [diff] [blame] | 2745 | .desc_hdr_template = DESC_HDR_TYPE_AESU_CTR_NONSNOOP | |
LEROY Christophe | 5e75ae1 | 2015-12-01 12:44:15 +0100 | [diff] [blame] | 2746 | DESC_HDR_SEL0_AESU | |
| 2747 | DESC_HDR_MODE0_AESU_CTR, |
| 2748 | }, |
| 2749 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2750 | .alg.crypto = { |
| 2751 | .cra_name = "ecb(des)", |
| 2752 | .cra_driver_name = "ecb-des-talitos", |
| 2753 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2754 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2755 | CRYPTO_ALG_ASYNC, |
| 2756 | .cra_ablkcipher = { |
| 2757 | .min_keysize = DES_KEY_SIZE, |
| 2758 | .max_keysize = DES_KEY_SIZE, |
| 2759 | .ivsize = DES_BLOCK_SIZE, |
| 2760 | } |
| 2761 | }, |
| 2762 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2763 | DESC_HDR_SEL0_DEU, |
| 2764 | }, |
| 2765 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2766 | .alg.crypto = { |
| 2767 | .cra_name = "cbc(des)", |
| 2768 | .cra_driver_name = "cbc-des-talitos", |
| 2769 | .cra_blocksize = DES_BLOCK_SIZE, |
| 2770 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2771 | CRYPTO_ALG_ASYNC, |
| 2772 | .cra_ablkcipher = { |
| 2773 | .min_keysize = DES_KEY_SIZE, |
| 2774 | .max_keysize = DES_KEY_SIZE, |
| 2775 | .ivsize = DES_BLOCK_SIZE, |
| 2776 | } |
| 2777 | }, |
| 2778 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2779 | DESC_HDR_SEL0_DEU | |
| 2780 | DESC_HDR_MODE0_DEU_CBC, |
| 2781 | }, |
| 2782 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2783 | .alg.crypto = { |
| 2784 | .cra_name = "ecb(des3_ede)", |
| 2785 | .cra_driver_name = "ecb-3des-talitos", |
| 2786 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2787 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2788 | CRYPTO_ALG_ASYNC, |
| 2789 | .cra_ablkcipher = { |
| 2790 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 2791 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 2792 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2793 | } |
| 2794 | }, |
| 2795 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2796 | DESC_HDR_SEL0_DEU | |
| 2797 | DESC_HDR_MODE0_DEU_3DES, |
| 2798 | }, |
| 2799 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2800 | .alg.crypto = { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2801 | .cra_name = "cbc(des3_ede)", |
| 2802 | .cra_driver_name = "cbc-3des-talitos", |
| 2803 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2804 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2805 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2806 | .cra_ablkcipher = { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2807 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 2808 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 2809 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2810 | } |
| 2811 | }, |
| 2812 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2813 | DESC_HDR_SEL0_DEU | |
| 2814 | DESC_HDR_MODE0_DEU_CBC | |
| 2815 | DESC_HDR_MODE0_DEU_3DES, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2816 | }, |
| 2817 | /* AHASH algorithms. */ |
| 2818 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2819 | .alg.hash = { |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2820 | .halg.digestsize = MD5_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2821 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2822 | .halg.base = { |
| 2823 | .cra_name = "md5", |
| 2824 | .cra_driver_name = "md5-talitos", |
Martin Hicks | b398861 | 2015-03-03 08:21:34 -0500 | [diff] [blame] | 2825 | .cra_blocksize = MD5_HMAC_BLOCK_SIZE, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2826 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2827 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2828 | } |
| 2829 | }, |
| 2830 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2831 | DESC_HDR_SEL0_MDEUA | |
| 2832 | DESC_HDR_MODE0_MDEU_MD5, |
| 2833 | }, |
| 2834 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2835 | .alg.hash = { |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2836 | .halg.digestsize = SHA1_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2837 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2838 | .halg.base = { |
| 2839 | .cra_name = "sha1", |
| 2840 | .cra_driver_name = "sha1-talitos", |
| 2841 | .cra_blocksize = SHA1_BLOCK_SIZE, |
| 2842 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2843 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2844 | } |
| 2845 | }, |
| 2846 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2847 | DESC_HDR_SEL0_MDEUA | |
| 2848 | DESC_HDR_MODE0_MDEU_SHA1, |
| 2849 | }, |
| 2850 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2851 | .alg.hash = { |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2852 | .halg.digestsize = SHA224_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2853 | .halg.statesize = sizeof(struct talitos_export_state), |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2854 | .halg.base = { |
| 2855 | .cra_name = "sha224", |
| 2856 | .cra_driver_name = "sha224-talitos", |
| 2857 | .cra_blocksize = SHA224_BLOCK_SIZE, |
| 2858 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2859 | CRYPTO_ALG_ASYNC, |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2860 | } |
| 2861 | }, |
| 2862 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2863 | DESC_HDR_SEL0_MDEUA | |
| 2864 | DESC_HDR_MODE0_MDEU_SHA224, |
| 2865 | }, |
| 2866 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2867 | .alg.hash = { |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2868 | .halg.digestsize = SHA256_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2869 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2870 | .halg.base = { |
| 2871 | .cra_name = "sha256", |
| 2872 | .cra_driver_name = "sha256-talitos", |
| 2873 | .cra_blocksize = SHA256_BLOCK_SIZE, |
| 2874 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2875 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2876 | } |
| 2877 | }, |
| 2878 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2879 | DESC_HDR_SEL0_MDEUA | |
| 2880 | DESC_HDR_MODE0_MDEU_SHA256, |
| 2881 | }, |
| 2882 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2883 | .alg.hash = { |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2884 | .halg.digestsize = SHA384_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2885 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2886 | .halg.base = { |
| 2887 | .cra_name = "sha384", |
| 2888 | .cra_driver_name = "sha384-talitos", |
| 2889 | .cra_blocksize = SHA384_BLOCK_SIZE, |
| 2890 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2891 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2892 | } |
| 2893 | }, |
| 2894 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2895 | DESC_HDR_SEL0_MDEUB | |
| 2896 | DESC_HDR_MODE0_MDEUB_SHA384, |
| 2897 | }, |
| 2898 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2899 | .alg.hash = { |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2900 | .halg.digestsize = SHA512_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2901 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2902 | .halg.base = { |
| 2903 | .cra_name = "sha512", |
| 2904 | .cra_driver_name = "sha512-talitos", |
| 2905 | .cra_blocksize = SHA512_BLOCK_SIZE, |
| 2906 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2907 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2908 | } |
| 2909 | }, |
| 2910 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2911 | DESC_HDR_SEL0_MDEUB | |
| 2912 | DESC_HDR_MODE0_MDEUB_SHA512, |
| 2913 | }, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2914 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2915 | .alg.hash = { |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2916 | .halg.digestsize = MD5_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2917 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2918 | .halg.base = { |
| 2919 | .cra_name = "hmac(md5)", |
| 2920 | .cra_driver_name = "hmac-md5-talitos", |
Martin Hicks | b398861 | 2015-03-03 08:21:34 -0500 | [diff] [blame] | 2921 | .cra_blocksize = MD5_HMAC_BLOCK_SIZE, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2922 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2923 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2924 | } |
| 2925 | }, |
| 2926 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2927 | DESC_HDR_SEL0_MDEUA | |
| 2928 | DESC_HDR_MODE0_MDEU_MD5, |
| 2929 | }, |
| 2930 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2931 | .alg.hash = { |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2932 | .halg.digestsize = SHA1_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2933 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2934 | .halg.base = { |
| 2935 | .cra_name = "hmac(sha1)", |
| 2936 | .cra_driver_name = "hmac-sha1-talitos", |
| 2937 | .cra_blocksize = SHA1_BLOCK_SIZE, |
| 2938 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2939 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2940 | } |
| 2941 | }, |
| 2942 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2943 | DESC_HDR_SEL0_MDEUA | |
| 2944 | DESC_HDR_MODE0_MDEU_SHA1, |
| 2945 | }, |
| 2946 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2947 | .alg.hash = { |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2948 | .halg.digestsize = SHA224_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2949 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2950 | .halg.base = { |
| 2951 | .cra_name = "hmac(sha224)", |
| 2952 | .cra_driver_name = "hmac-sha224-talitos", |
| 2953 | .cra_blocksize = SHA224_BLOCK_SIZE, |
| 2954 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2955 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2956 | } |
| 2957 | }, |
| 2958 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2959 | DESC_HDR_SEL0_MDEUA | |
| 2960 | DESC_HDR_MODE0_MDEU_SHA224, |
| 2961 | }, |
| 2962 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2963 | .alg.hash = { |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2964 | .halg.digestsize = SHA256_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2965 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2966 | .halg.base = { |
| 2967 | .cra_name = "hmac(sha256)", |
| 2968 | .cra_driver_name = "hmac-sha256-talitos", |
| 2969 | .cra_blocksize = SHA256_BLOCK_SIZE, |
| 2970 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2971 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2972 | } |
| 2973 | }, |
| 2974 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2975 | DESC_HDR_SEL0_MDEUA | |
| 2976 | DESC_HDR_MODE0_MDEU_SHA256, |
| 2977 | }, |
| 2978 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2979 | .alg.hash = { |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2980 | .halg.digestsize = SHA384_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2981 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2982 | .halg.base = { |
| 2983 | .cra_name = "hmac(sha384)", |
| 2984 | .cra_driver_name = "hmac-sha384-talitos", |
| 2985 | .cra_blocksize = SHA384_BLOCK_SIZE, |
| 2986 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2987 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2988 | } |
| 2989 | }, |
| 2990 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2991 | DESC_HDR_SEL0_MDEUB | |
| 2992 | DESC_HDR_MODE0_MDEUB_SHA384, |
| 2993 | }, |
| 2994 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2995 | .alg.hash = { |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2996 | .halg.digestsize = SHA512_DIGEST_SIZE, |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 2997 | .halg.statesize = sizeof(struct talitos_export_state), |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2998 | .halg.base = { |
| 2999 | .cra_name = "hmac(sha512)", |
| 3000 | .cra_driver_name = "hmac-sha512-talitos", |
| 3001 | .cra_blocksize = SHA512_BLOCK_SIZE, |
| 3002 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 3003 | CRYPTO_ALG_ASYNC, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 3004 | } |
| 3005 | }, |
| 3006 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 3007 | DESC_HDR_SEL0_MDEUB | |
| 3008 | DESC_HDR_MODE0_MDEUB_SHA512, |
| 3009 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3010 | }; |
| 3011 | |
| 3012 | struct talitos_crypto_alg { |
| 3013 | struct list_head entry; |
| 3014 | struct device *dev; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3015 | struct talitos_alg_template algt; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3016 | }; |
| 3017 | |
Jonas Eymann | 89d124c | 2016-04-19 20:33:47 +0300 | [diff] [blame] | 3018 | static int talitos_init_common(struct talitos_ctx *ctx, |
| 3019 | struct talitos_crypto_alg *talitos_alg) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3020 | { |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 3021 | struct talitos_private *priv; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3022 | |
| 3023 | /* update context with ptr to dev */ |
| 3024 | ctx->dev = talitos_alg->dev; |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 3025 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 3026 | /* assign SEC channel to tfm in round-robin fashion */ |
| 3027 | priv = dev_get_drvdata(ctx->dev); |
| 3028 | ctx->ch = atomic_inc_return(&priv->last_chan) & |
| 3029 | (priv->num_channels - 1); |
| 3030 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3031 | /* copy descriptor header template value */ |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3032 | ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3033 | |
Kim Phillips | 602dba5 | 2011-07-15 11:21:39 +0800 | [diff] [blame] | 3034 | /* select done notification */ |
| 3035 | ctx->desc_hdr_template |= DESC_HDR_DONE_NOTIFY; |
| 3036 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 3037 | return 0; |
| 3038 | } |
| 3039 | |
Jonas Eymann | 89d124c | 2016-04-19 20:33:47 +0300 | [diff] [blame] | 3040 | static int talitos_cra_init(struct crypto_tfm *tfm) |
| 3041 | { |
| 3042 | struct crypto_alg *alg = tfm->__crt_alg; |
| 3043 | struct talitos_crypto_alg *talitos_alg; |
| 3044 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
| 3045 | |
| 3046 | if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH) |
| 3047 | talitos_alg = container_of(__crypto_ahash_alg(alg), |
| 3048 | struct talitos_crypto_alg, |
| 3049 | algt.alg.hash); |
| 3050 | else |
| 3051 | talitos_alg = container_of(alg, struct talitos_crypto_alg, |
| 3052 | algt.alg.crypto); |
| 3053 | |
| 3054 | return talitos_init_common(ctx, talitos_alg); |
| 3055 | } |
| 3056 | |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3057 | static int talitos_cra_init_aead(struct crypto_aead *tfm) |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 3058 | { |
Jonas Eymann | 89d124c | 2016-04-19 20:33:47 +0300 | [diff] [blame] | 3059 | struct aead_alg *alg = crypto_aead_alg(tfm); |
| 3060 | struct talitos_crypto_alg *talitos_alg; |
| 3061 | struct talitos_ctx *ctx = crypto_aead_ctx(tfm); |
| 3062 | |
| 3063 | talitos_alg = container_of(alg, struct talitos_crypto_alg, |
| 3064 | algt.alg.aead); |
| 3065 | |
| 3066 | return talitos_init_common(ctx, talitos_alg); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3067 | } |
| 3068 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 3069 | static int talitos_cra_init_ahash(struct crypto_tfm *tfm) |
| 3070 | { |
| 3071 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
| 3072 | |
| 3073 | talitos_cra_init(tfm); |
| 3074 | |
| 3075 | ctx->keylen = 0; |
| 3076 | crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), |
| 3077 | sizeof(struct talitos_ahash_req_ctx)); |
| 3078 | |
| 3079 | return 0; |
| 3080 | } |
| 3081 | |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 3082 | static void talitos_cra_exit(struct crypto_tfm *tfm) |
| 3083 | { |
| 3084 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
| 3085 | struct device *dev = ctx->dev; |
| 3086 | |
| 3087 | if (ctx->keylen) |
| 3088 | dma_unmap_single(dev, ctx->dma_key, ctx->keylen, DMA_TO_DEVICE); |
| 3089 | } |
| 3090 | |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 3091 | static void talitos_cra_exit_ahash(struct crypto_tfm *tfm) |
| 3092 | { |
| 3093 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
| 3094 | struct device *dev = ctx->dev; |
| 3095 | unsigned int size; |
| 3096 | |
| 3097 | talitos_cra_exit(tfm); |
| 3098 | |
| 3099 | size = (crypto_ahash_digestsize(__crypto_ahash_cast(tfm)) <= |
| 3100 | SHA256_DIGEST_SIZE) |
| 3101 | ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 |
| 3102 | : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; |
| 3103 | |
| 3104 | if (ctx->dma_hw_context) |
| 3105 | dma_unmap_single(dev, ctx->dma_hw_context, size, |
| 3106 | DMA_BIDIRECTIONAL); |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 3107 | if (ctx->dma_buf) |
LEROY Christophe | 3c0dd19 | 2017-10-06 15:05:08 +0200 | [diff] [blame^] | 3108 | dma_unmap_single(dev, ctx->dma_buf, HASH_MAX_BLOCK_SIZE * 2, |
LEROY Christophe | 37b5e88 | 2017-10-06 15:05:06 +0200 | [diff] [blame] | 3109 | DMA_TO_DEVICE); |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 3110 | } |
| 3111 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3112 | /* |
| 3113 | * given the alg's descriptor header template, determine whether descriptor |
| 3114 | * type and primary/secondary execution units required match the hw |
| 3115 | * capabilities description provided in the device tree node. |
| 3116 | */ |
| 3117 | static int hw_supports(struct device *dev, __be32 desc_hdr_template) |
| 3118 | { |
| 3119 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 3120 | int ret; |
| 3121 | |
| 3122 | ret = (1 << DESC_TYPE(desc_hdr_template) & priv->desc_types) && |
| 3123 | (1 << PRIMARY_EU(desc_hdr_template) & priv->exec_units); |
| 3124 | |
| 3125 | if (SECONDARY_EU(desc_hdr_template)) |
| 3126 | ret = ret && (1 << SECONDARY_EU(desc_hdr_template) |
| 3127 | & priv->exec_units); |
| 3128 | |
| 3129 | return ret; |
| 3130 | } |
| 3131 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 3132 | static int talitos_remove(struct platform_device *ofdev) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3133 | { |
| 3134 | struct device *dev = &ofdev->dev; |
| 3135 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 3136 | struct talitos_crypto_alg *t_alg, *n; |
| 3137 | int i; |
| 3138 | |
| 3139 | list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3140 | switch (t_alg->algt.type) { |
| 3141 | case CRYPTO_ALG_TYPE_ABLKCIPHER: |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3142 | break; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3143 | case CRYPTO_ALG_TYPE_AEAD: |
| 3144 | crypto_unregister_aead(&t_alg->algt.alg.aead); |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3145 | case CRYPTO_ALG_TYPE_AHASH: |
| 3146 | crypto_unregister_ahash(&t_alg->algt.alg.hash); |
| 3147 | break; |
| 3148 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3149 | list_del(&t_alg->entry); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | if (hw_supports(dev, DESC_HDR_SEL0_RNG)) |
| 3153 | talitos_unregister_rng(dev); |
| 3154 | |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3155 | for (i = 0; i < 2; i++) |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 3156 | if (priv->irq[i]) { |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3157 | free_irq(priv->irq[i], dev); |
| 3158 | irq_dispose_mapping(priv->irq[i]); |
| 3159 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3160 | |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3161 | tasklet_kill(&priv->done_task[0]); |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 3162 | if (priv->irq[1]) |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3163 | tasklet_kill(&priv->done_task[1]); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3164 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3165 | return 0; |
| 3166 | } |
| 3167 | |
| 3168 | static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, |
| 3169 | struct talitos_alg_template |
| 3170 | *template) |
| 3171 | { |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 3172 | struct talitos_private *priv = dev_get_drvdata(dev); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3173 | struct talitos_crypto_alg *t_alg; |
| 3174 | struct crypto_alg *alg; |
| 3175 | |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3176 | t_alg = devm_kzalloc(dev, sizeof(struct talitos_crypto_alg), |
| 3177 | GFP_KERNEL); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3178 | if (!t_alg) |
| 3179 | return ERR_PTR(-ENOMEM); |
| 3180 | |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3181 | t_alg->algt = *template; |
| 3182 | |
| 3183 | switch (t_alg->algt.type) { |
| 3184 | case CRYPTO_ALG_TYPE_ABLKCIPHER: |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 3185 | alg = &t_alg->algt.alg.crypto; |
| 3186 | alg->cra_init = talitos_cra_init; |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 3187 | alg->cra_exit = talitos_cra_exit; |
Kim Phillips | d4cd328 | 2012-08-08 20:32:00 -0500 | [diff] [blame] | 3188 | alg->cra_type = &crypto_ablkcipher_type; |
Kim Phillips | b286e00 | 2012-08-08 20:33:34 -0500 | [diff] [blame] | 3189 | alg->cra_ablkcipher.setkey = ablkcipher_setkey; |
| 3190 | alg->cra_ablkcipher.encrypt = ablkcipher_encrypt; |
| 3191 | alg->cra_ablkcipher.decrypt = ablkcipher_decrypt; |
| 3192 | alg->cra_ablkcipher.geniv = "eseqiv"; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 3193 | break; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3194 | case CRYPTO_ALG_TYPE_AEAD: |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3195 | alg = &t_alg->algt.alg.aead.base; |
LEROY Christophe | 2e13ce0 | 2017-10-06 15:05:02 +0200 | [diff] [blame] | 3196 | alg->cra_exit = talitos_cra_exit; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3197 | t_alg->algt.alg.aead.init = talitos_cra_init_aead; |
| 3198 | t_alg->algt.alg.aead.setkey = aead_setkey; |
| 3199 | t_alg->algt.alg.aead.encrypt = aead_encrypt; |
| 3200 | t_alg->algt.alg.aead.decrypt = aead_decrypt; |
LEROY Christophe | 6cda075 | 2017-10-06 15:04:39 +0200 | [diff] [blame] | 3201 | if (!(priv->features & TALITOS_FTR_SHA224_HWINIT) && |
| 3202 | !strncmp(alg->cra_name, "authenc(hmac(sha224)", 20)) { |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3203 | devm_kfree(dev, t_alg); |
LEROY Christophe | 6cda075 | 2017-10-06 15:04:39 +0200 | [diff] [blame] | 3204 | return ERR_PTR(-ENOTSUPP); |
| 3205 | } |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3206 | break; |
| 3207 | case CRYPTO_ALG_TYPE_AHASH: |
| 3208 | alg = &t_alg->algt.alg.hash.halg.base; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 3209 | alg->cra_init = talitos_cra_init_ahash; |
LEROY Christophe | 49f9783 | 2017-10-06 15:05:04 +0200 | [diff] [blame] | 3210 | alg->cra_exit = talitos_cra_exit_ahash; |
Kim Phillips | d4cd328 | 2012-08-08 20:32:00 -0500 | [diff] [blame] | 3211 | alg->cra_type = &crypto_ahash_type; |
Kim Phillips | b286e00 | 2012-08-08 20:33:34 -0500 | [diff] [blame] | 3212 | t_alg->algt.alg.hash.init = ahash_init; |
| 3213 | t_alg->algt.alg.hash.update = ahash_update; |
| 3214 | t_alg->algt.alg.hash.final = ahash_final; |
| 3215 | t_alg->algt.alg.hash.finup = ahash_finup; |
| 3216 | t_alg->algt.alg.hash.digest = ahash_digest; |
LEROY Christophe | 5613663 | 2017-09-12 11:03:39 +0200 | [diff] [blame] | 3217 | if (!strncmp(alg->cra_name, "hmac", 4)) |
| 3218 | t_alg->algt.alg.hash.setkey = ahash_setkey; |
Horia Geant? | 3639ca8 | 2016-04-21 19:24:55 +0300 | [diff] [blame] | 3219 | t_alg->algt.alg.hash.import = ahash_import; |
| 3220 | t_alg->algt.alg.hash.export = ahash_export; |
Kim Phillips | b286e00 | 2012-08-08 20:33:34 -0500 | [diff] [blame] | 3221 | |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 3222 | if (!(priv->features & TALITOS_FTR_HMAC_OK) && |
Kim Phillips | 0b2730d | 2011-12-12 14:59:10 -0600 | [diff] [blame] | 3223 | !strncmp(alg->cra_name, "hmac", 4)) { |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3224 | devm_kfree(dev, t_alg); |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 3225 | return ERR_PTR(-ENOTSUPP); |
Kim Phillips | 0b2730d | 2011-12-12 14:59:10 -0600 | [diff] [blame] | 3226 | } |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 3227 | if (!(priv->features & TALITOS_FTR_SHA224_HWINIT) && |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 3228 | (!strcmp(alg->cra_name, "sha224") || |
| 3229 | !strcmp(alg->cra_name, "hmac(sha224)"))) { |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 3230 | t_alg->algt.alg.hash.init = ahash_init_sha224_swinit; |
| 3231 | t_alg->algt.desc_hdr_template = |
| 3232 | DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 3233 | DESC_HDR_SEL0_MDEUA | |
| 3234 | DESC_HDR_MODE0_MDEU_SHA256; |
| 3235 | } |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 3236 | break; |
Kim Phillips | 1d11911 | 2010-09-23 15:55:27 +0800 | [diff] [blame] | 3237 | default: |
| 3238 | dev_err(dev, "unknown algorithm type %d\n", t_alg->algt.type); |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3239 | devm_kfree(dev, t_alg); |
Kim Phillips | 1d11911 | 2010-09-23 15:55:27 +0800 | [diff] [blame] | 3240 | return ERR_PTR(-EINVAL); |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3241 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3242 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3243 | alg->cra_module = THIS_MODULE; |
LEROY Christophe | b005776 | 2016-06-06 13:20:44 +0200 | [diff] [blame] | 3244 | if (t_alg->algt.priority) |
| 3245 | alg->cra_priority = t_alg->algt.priority; |
| 3246 | else |
| 3247 | alg->cra_priority = TALITOS_CRA_PRIORITY; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3248 | alg->cra_alignmask = 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3249 | alg->cra_ctxsize = sizeof(struct talitos_ctx); |
Nikos Mavrogiannopoulos | d912bb7 | 2011-11-01 13:39:56 +0100 | [diff] [blame] | 3250 | alg->cra_flags |= CRYPTO_ALG_KERN_DRIVER_ONLY; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3251 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3252 | t_alg->dev = dev; |
| 3253 | |
| 3254 | return t_alg; |
| 3255 | } |
| 3256 | |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3257 | static int talitos_probe_irq(struct platform_device *ofdev) |
| 3258 | { |
| 3259 | struct device *dev = &ofdev->dev; |
| 3260 | struct device_node *np = ofdev->dev.of_node; |
| 3261 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 3262 | int err; |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3263 | bool is_sec1 = has_ftr_sec1(priv); |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3264 | |
| 3265 | priv->irq[0] = irq_of_parse_and_map(np, 0); |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 3266 | if (!priv->irq[0]) { |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3267 | dev_err(dev, "failed to map irq\n"); |
| 3268 | return -EINVAL; |
| 3269 | } |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3270 | if (is_sec1) { |
| 3271 | err = request_irq(priv->irq[0], talitos1_interrupt_4ch, 0, |
| 3272 | dev_driver_string(dev), dev); |
| 3273 | goto primary_out; |
| 3274 | } |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3275 | |
| 3276 | priv->irq[1] = irq_of_parse_and_map(np, 1); |
| 3277 | |
| 3278 | /* get the primary irq line */ |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 3279 | if (!priv->irq[1]) { |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3280 | err = request_irq(priv->irq[0], talitos2_interrupt_4ch, 0, |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3281 | dev_driver_string(dev), dev); |
| 3282 | goto primary_out; |
| 3283 | } |
| 3284 | |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3285 | err = request_irq(priv->irq[0], talitos2_interrupt_ch0_2, 0, |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3286 | dev_driver_string(dev), dev); |
| 3287 | if (err) |
| 3288 | goto primary_out; |
| 3289 | |
| 3290 | /* get the secondary irq line */ |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3291 | err = request_irq(priv->irq[1], talitos2_interrupt_ch1_3, 0, |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3292 | dev_driver_string(dev), dev); |
| 3293 | if (err) { |
| 3294 | dev_err(dev, "failed to request secondary irq\n"); |
| 3295 | irq_dispose_mapping(priv->irq[1]); |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 3296 | priv->irq[1] = 0; |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | return err; |
| 3300 | |
| 3301 | primary_out: |
| 3302 | if (err) { |
| 3303 | dev_err(dev, "failed to request primary irq\n"); |
| 3304 | irq_dispose_mapping(priv->irq[0]); |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 3305 | priv->irq[0] = 0; |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | return err; |
| 3309 | } |
| 3310 | |
Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 3311 | static int talitos_probe(struct platform_device *ofdev) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3312 | { |
| 3313 | struct device *dev = &ofdev->dev; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 3314 | struct device_node *np = ofdev->dev.of_node; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3315 | struct talitos_private *priv; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3316 | int i, err; |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 3317 | int stride; |
LEROY Christophe | fd5ea7f | 2017-10-06 15:04:53 +0200 | [diff] [blame] | 3318 | struct resource *res; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3319 | |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3320 | priv = devm_kzalloc(dev, sizeof(struct talitos_private), GFP_KERNEL); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3321 | if (!priv) |
| 3322 | return -ENOMEM; |
| 3323 | |
Kevin Hao | f3de9cb | 2014-01-28 20:17:23 +0800 | [diff] [blame] | 3324 | INIT_LIST_HEAD(&priv->alg_list); |
| 3325 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3326 | dev_set_drvdata(dev, priv); |
| 3327 | |
| 3328 | priv->ofdev = ofdev; |
| 3329 | |
Horia Geanta | 511d63c | 2012-03-30 17:49:53 +0300 | [diff] [blame] | 3330 | spin_lock_init(&priv->reg_lock); |
| 3331 | |
LEROY Christophe | fd5ea7f | 2017-10-06 15:04:53 +0200 | [diff] [blame] | 3332 | res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); |
| 3333 | if (!res) |
| 3334 | return -ENXIO; |
| 3335 | priv->reg = devm_ioremap(dev, res->start, resource_size(res)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3336 | if (!priv->reg) { |
| 3337 | dev_err(dev, "failed to of_iomap\n"); |
| 3338 | err = -ENOMEM; |
| 3339 | goto err_out; |
| 3340 | } |
| 3341 | |
| 3342 | /* get SEC version capabilities from device tree */ |
LEROY Christophe | fa14c6c | 2017-10-06 15:04:51 +0200 | [diff] [blame] | 3343 | of_property_read_u32(np, "fsl,num-channels", &priv->num_channels); |
| 3344 | of_property_read_u32(np, "fsl,channel-fifo-len", &priv->chfifo_len); |
| 3345 | of_property_read_u32(np, "fsl,exec-units-mask", &priv->exec_units); |
| 3346 | of_property_read_u32(np, "fsl,descriptor-types-mask", |
| 3347 | &priv->desc_types); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3348 | |
| 3349 | if (!is_power_of_2(priv->num_channels) || !priv->chfifo_len || |
| 3350 | !priv->exec_units || !priv->desc_types) { |
| 3351 | dev_err(dev, "invalid property data in device tree node\n"); |
| 3352 | err = -EINVAL; |
| 3353 | goto err_out; |
| 3354 | } |
| 3355 | |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 3356 | if (of_device_is_compatible(np, "fsl,sec3.0")) |
| 3357 | priv->features |= TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT; |
| 3358 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 3359 | if (of_device_is_compatible(np, "fsl,sec2.1")) |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 3360 | priv->features |= TALITOS_FTR_HW_AUTH_CHECK | |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 3361 | TALITOS_FTR_SHA224_HWINIT | |
| 3362 | TALITOS_FTR_HMAC_OK; |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 3363 | |
LEROY Christophe | 2159088 | 2015-04-17 16:32:05 +0200 | [diff] [blame] | 3364 | if (of_device_is_compatible(np, "fsl,sec1.0")) |
| 3365 | priv->features |= TALITOS_FTR_SEC1; |
| 3366 | |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 3367 | if (of_device_is_compatible(np, "fsl,sec1.2")) { |
| 3368 | priv->reg_deu = priv->reg + TALITOS12_DEU; |
| 3369 | priv->reg_aesu = priv->reg + TALITOS12_AESU; |
| 3370 | priv->reg_mdeu = priv->reg + TALITOS12_MDEU; |
| 3371 | stride = TALITOS1_CH_STRIDE; |
| 3372 | } else if (of_device_is_compatible(np, "fsl,sec1.0")) { |
| 3373 | priv->reg_deu = priv->reg + TALITOS10_DEU; |
| 3374 | priv->reg_aesu = priv->reg + TALITOS10_AESU; |
| 3375 | priv->reg_mdeu = priv->reg + TALITOS10_MDEU; |
| 3376 | priv->reg_afeu = priv->reg + TALITOS10_AFEU; |
| 3377 | priv->reg_rngu = priv->reg + TALITOS10_RNGU; |
| 3378 | priv->reg_pkeu = priv->reg + TALITOS10_PKEU; |
| 3379 | stride = TALITOS1_CH_STRIDE; |
| 3380 | } else { |
| 3381 | priv->reg_deu = priv->reg + TALITOS2_DEU; |
| 3382 | priv->reg_aesu = priv->reg + TALITOS2_AESU; |
| 3383 | priv->reg_mdeu = priv->reg + TALITOS2_MDEU; |
| 3384 | priv->reg_afeu = priv->reg + TALITOS2_AFEU; |
| 3385 | priv->reg_rngu = priv->reg + TALITOS2_RNGU; |
| 3386 | priv->reg_pkeu = priv->reg + TALITOS2_PKEU; |
| 3387 | priv->reg_keu = priv->reg + TALITOS2_KEU; |
| 3388 | priv->reg_crcu = priv->reg + TALITOS2_CRCU; |
| 3389 | stride = TALITOS2_CH_STRIDE; |
| 3390 | } |
| 3391 | |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3392 | err = talitos_probe_irq(ofdev); |
| 3393 | if (err) |
| 3394 | goto err_out; |
| 3395 | |
| 3396 | if (of_device_is_compatible(np, "fsl,sec1.0")) { |
LEROY Christophe | 9c02e28 | 2017-10-06 15:04:55 +0200 | [diff] [blame] | 3397 | if (priv->num_channels == 1) |
| 3398 | tasklet_init(&priv->done_task[0], talitos1_done_ch0, |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3399 | (unsigned long)dev); |
LEROY Christophe | 9c02e28 | 2017-10-06 15:04:55 +0200 | [diff] [blame] | 3400 | else |
| 3401 | tasklet_init(&priv->done_task[0], talitos1_done_4ch, |
| 3402 | (unsigned long)dev); |
| 3403 | } else { |
| 3404 | if (priv->irq[1]) { |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3405 | tasklet_init(&priv->done_task[0], talitos2_done_ch0_2, |
| 3406 | (unsigned long)dev); |
| 3407 | tasklet_init(&priv->done_task[1], talitos2_done_ch1_3, |
| 3408 | (unsigned long)dev); |
LEROY Christophe | 9c02e28 | 2017-10-06 15:04:55 +0200 | [diff] [blame] | 3409 | } else if (priv->num_channels == 1) { |
| 3410 | tasklet_init(&priv->done_task[0], talitos2_done_ch0, |
| 3411 | (unsigned long)dev); |
| 3412 | } else { |
| 3413 | tasklet_init(&priv->done_task[0], talitos2_done_4ch, |
| 3414 | (unsigned long)dev); |
LEROY Christophe | dd3c098 | 2015-04-17 16:32:13 +0200 | [diff] [blame] | 3415 | } |
| 3416 | } |
| 3417 | |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3418 | priv->chan = devm_kzalloc(dev, sizeof(struct talitos_channel) * |
| 3419 | priv->num_channels, GFP_KERNEL); |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 3420 | if (!priv->chan) { |
| 3421 | dev_err(dev, "failed to allocate channel management space\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3422 | err = -ENOMEM; |
| 3423 | goto err_out; |
| 3424 | } |
| 3425 | |
Martin Hicks | f641ddd | 2015-03-03 08:21:33 -0500 | [diff] [blame] | 3426 | priv->fifo_len = roundup_pow_of_two(priv->chfifo_len); |
| 3427 | |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3428 | for (i = 0; i < priv->num_channels; i++) { |
LEROY Christophe | 5fa7fa1 | 2015-04-17 16:32:11 +0200 | [diff] [blame] | 3429 | priv->chan[i].reg = priv->reg + stride * (i + 1); |
Kim Phillips | 2cdba3c | 2011-12-12 14:59:11 -0600 | [diff] [blame] | 3430 | if (!priv->irq[1] || !(i & 1)) |
Kim Phillips | c3e337f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3431 | priv->chan[i].reg += TALITOS_CH_BASE_OFFSET; |
Kim Phillips | ad42d5f | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 3432 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 3433 | spin_lock_init(&priv->chan[i].head_lock); |
| 3434 | spin_lock_init(&priv->chan[i].tail_lock); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3435 | |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3436 | priv->chan[i].fifo = devm_kzalloc(dev, |
| 3437 | sizeof(struct talitos_request) * |
| 3438 | priv->fifo_len, GFP_KERNEL); |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 3439 | if (!priv->chan[i].fifo) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3440 | dev_err(dev, "failed to allocate request fifo %d\n", i); |
| 3441 | err = -ENOMEM; |
| 3442 | goto err_out; |
| 3443 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3444 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 3445 | atomic_set(&priv->chan[i].submit_count, |
| 3446 | -(priv->chfifo_len - 1)); |
Martin Hicks | f641ddd | 2015-03-03 08:21:33 -0500 | [diff] [blame] | 3447 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3448 | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 3449 | dma_set_mask(dev, DMA_BIT_MASK(36)); |
| 3450 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3451 | /* reset and initialize the h/w */ |
| 3452 | err = init_device(dev); |
| 3453 | if (err) { |
| 3454 | dev_err(dev, "failed to initialize device\n"); |
| 3455 | goto err_out; |
| 3456 | } |
| 3457 | |
| 3458 | /* register the RNG, if available */ |
| 3459 | if (hw_supports(dev, DESC_HDR_SEL0_RNG)) { |
| 3460 | err = talitos_register_rng(dev); |
| 3461 | if (err) { |
| 3462 | dev_err(dev, "failed to register hwrng: %d\n", err); |
| 3463 | goto err_out; |
| 3464 | } else |
| 3465 | dev_info(dev, "hwrng\n"); |
| 3466 | } |
| 3467 | |
| 3468 | /* register crypto algorithms the device supports */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3469 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
| 3470 | if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { |
| 3471 | struct talitos_crypto_alg *t_alg; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3472 | struct crypto_alg *alg = NULL; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3473 | |
| 3474 | t_alg = talitos_alg_alloc(dev, &driver_algs[i]); |
| 3475 | if (IS_ERR(t_alg)) { |
| 3476 | err = PTR_ERR(t_alg); |
Kim Phillips | 0b2730d | 2011-12-12 14:59:10 -0600 | [diff] [blame] | 3477 | if (err == -ENOTSUPP) |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 3478 | continue; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3479 | goto err_out; |
| 3480 | } |
| 3481 | |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3482 | switch (t_alg->algt.type) { |
| 3483 | case CRYPTO_ALG_TYPE_ABLKCIPHER: |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3484 | err = crypto_register_alg( |
| 3485 | &t_alg->algt.alg.crypto); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3486 | alg = &t_alg->algt.alg.crypto; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3487 | break; |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3488 | |
| 3489 | case CRYPTO_ALG_TYPE_AEAD: |
| 3490 | err = crypto_register_aead( |
| 3491 | &t_alg->algt.alg.aead); |
| 3492 | alg = &t_alg->algt.alg.aead.base; |
| 3493 | break; |
| 3494 | |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3495 | case CRYPTO_ALG_TYPE_AHASH: |
| 3496 | err = crypto_register_ahash( |
| 3497 | &t_alg->algt.alg.hash); |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3498 | alg = &t_alg->algt.alg.hash.halg.base; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 3499 | break; |
| 3500 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3501 | if (err) { |
| 3502 | dev_err(dev, "%s alg registration failed\n", |
Herbert Xu | aeb4c13 | 2015-07-30 17:53:22 +0800 | [diff] [blame] | 3503 | alg->cra_driver_name); |
LEROY Christophe | 24b92ff | 2017-10-06 15:04:49 +0200 | [diff] [blame] | 3504 | devm_kfree(dev, t_alg); |
Horia Geanta | 991155b | 2013-03-20 16:31:38 +0200 | [diff] [blame] | 3505 | } else |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3506 | list_add_tail(&t_alg->entry, &priv->alg_list); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3507 | } |
| 3508 | } |
Kim Phillips | 5b859b6e | 2011-11-21 16:13:26 +0800 | [diff] [blame] | 3509 | if (!list_empty(&priv->alg_list)) |
| 3510 | dev_info(dev, "%s algorithms registered in /proc/crypto\n", |
| 3511 | (char *)of_get_property(np, "compatible", NULL)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3512 | |
| 3513 | return 0; |
| 3514 | |
| 3515 | err_out: |
| 3516 | talitos_remove(ofdev); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3517 | |
| 3518 | return err; |
| 3519 | } |
| 3520 | |
Márton Németh | 6c3f975 | 2010-01-17 21:54:01 +1100 | [diff] [blame] | 3521 | static const struct of_device_id talitos_match[] = { |
LEROY Christophe | 0635b7d | 2015-04-17 16:32:20 +0200 | [diff] [blame] | 3522 | #ifdef CONFIG_CRYPTO_DEV_TALITOS1 |
| 3523 | { |
| 3524 | .compatible = "fsl,sec1.0", |
| 3525 | }, |
| 3526 | #endif |
| 3527 | #ifdef CONFIG_CRYPTO_DEV_TALITOS2 |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3528 | { |
| 3529 | .compatible = "fsl,sec2.0", |
| 3530 | }, |
LEROY Christophe | 0635b7d | 2015-04-17 16:32:20 +0200 | [diff] [blame] | 3531 | #endif |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3532 | {}, |
| 3533 | }; |
| 3534 | MODULE_DEVICE_TABLE(of, talitos_match); |
| 3535 | |
Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 3536 | static struct platform_driver talitos_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 3537 | .driver = { |
| 3538 | .name = "talitos", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 3539 | .of_match_table = talitos_match, |
| 3540 | }, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3541 | .probe = talitos_probe, |
Al Viro | 596f103 | 2008-11-22 17:34:24 +0000 | [diff] [blame] | 3542 | .remove = talitos_remove, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3543 | }; |
| 3544 | |
Axel Lin | 741e8c2 | 2011-11-26 21:26:19 +0800 | [diff] [blame] | 3545 | module_platform_driver(talitos_driver); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 3546 | |
| 3547 | MODULE_LICENSE("GPL"); |
| 3548 | MODULE_AUTHOR("Kim Phillips <kim.phillips@freescale.com>"); |
| 3549 | MODULE_DESCRIPTION("Freescale integrated security engine (SEC) driver"); |