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> |
| 35 | #include <linux/of_platform.h> |
| 36 | #include <linux/dma-mapping.h> |
| 37 | #include <linux/io.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 41 | |
| 42 | #include <crypto/algapi.h> |
| 43 | #include <crypto/aes.h> |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 44 | #include <crypto/des.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 45 | #include <crypto/sha.h> |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 46 | #include <crypto/md5.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 47 | #include <crypto/aead.h> |
| 48 | #include <crypto/authenc.h> |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 49 | #include <crypto/skcipher.h> |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 50 | #include <crypto/hash.h> |
| 51 | #include <crypto/internal/hash.h> |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 52 | #include <crypto/scatterwalk.h> |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 53 | |
| 54 | #include "talitos.h" |
| 55 | |
| 56 | #define TALITOS_TIMEOUT 100000 |
| 57 | #define TALITOS_MAX_DATA_LEN 65535 |
| 58 | |
| 59 | #define DESC_TYPE(desc_hdr) ((be32_to_cpu(desc_hdr) >> 3) & 0x1f) |
| 60 | #define PRIMARY_EU(desc_hdr) ((be32_to_cpu(desc_hdr) >> 28) & 0xf) |
| 61 | #define SECONDARY_EU(desc_hdr) ((be32_to_cpu(desc_hdr) >> 16) & 0xf) |
| 62 | |
| 63 | /* descriptor pointer entry */ |
| 64 | struct talitos_ptr { |
| 65 | __be16 len; /* length */ |
| 66 | u8 j_extent; /* jump to sg link table and/or extent */ |
| 67 | u8 eptr; /* extended address */ |
| 68 | __be32 ptr; /* address */ |
| 69 | }; |
| 70 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 71 | static const struct talitos_ptr zero_entry = { |
| 72 | .len = 0, |
| 73 | .j_extent = 0, |
| 74 | .eptr = 0, |
| 75 | .ptr = 0 |
| 76 | }; |
| 77 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 78 | /* descriptor */ |
| 79 | struct talitos_desc { |
| 80 | __be32 hdr; /* header high bits */ |
| 81 | __be32 hdr_lo; /* header low bits */ |
| 82 | struct talitos_ptr ptr[7]; /* ptr/len pair array */ |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * talitos_request - descriptor submission request |
| 87 | * @desc: descriptor pointer (kernel virtual) |
| 88 | * @dma_desc: descriptor's physical bus address |
| 89 | * @callback: whom to call when descriptor processing is done |
| 90 | * @context: caller context (optional) |
| 91 | */ |
| 92 | struct talitos_request { |
| 93 | struct talitos_desc *desc; |
| 94 | dma_addr_t dma_desc; |
| 95 | void (*callback) (struct device *dev, struct talitos_desc *desc, |
| 96 | void *context, int error); |
| 97 | void *context; |
| 98 | }; |
| 99 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 100 | /* per-channel fifo management */ |
| 101 | struct talitos_channel { |
| 102 | /* request fifo */ |
| 103 | struct talitos_request *fifo; |
| 104 | |
| 105 | /* number of requests pending in channel h/w fifo */ |
| 106 | atomic_t submit_count ____cacheline_aligned; |
| 107 | |
| 108 | /* request submission (head) lock */ |
| 109 | spinlock_t head_lock ____cacheline_aligned; |
| 110 | /* index to next free descriptor request */ |
| 111 | int head; |
| 112 | |
| 113 | /* request release (tail) lock */ |
| 114 | spinlock_t tail_lock ____cacheline_aligned; |
| 115 | /* index to next in-progress/done descriptor request */ |
| 116 | int tail; |
| 117 | }; |
| 118 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 119 | struct talitos_private { |
| 120 | struct device *dev; |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 121 | struct platform_device *ofdev; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 122 | void __iomem *reg; |
| 123 | int irq; |
| 124 | |
| 125 | /* SEC version geometry (from device tree node) */ |
| 126 | unsigned int num_channels; |
| 127 | unsigned int chfifo_len; |
| 128 | unsigned int exec_units; |
| 129 | unsigned int desc_types; |
| 130 | |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 131 | /* SEC Compatibility info */ |
| 132 | unsigned long features; |
| 133 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 134 | /* |
| 135 | * length of the request fifo |
| 136 | * fifo_len is chfifo_len rounded up to next power of 2 |
| 137 | * so we can use bitwise ops to wrap |
| 138 | */ |
| 139 | unsigned int fifo_len; |
| 140 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 141 | struct talitos_channel *chan; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 142 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 143 | /* next channel to be assigned next incoming descriptor */ |
| 144 | atomic_t last_chan ____cacheline_aligned; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 145 | |
| 146 | /* request callback tasklet */ |
| 147 | struct tasklet_struct done_task; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 148 | |
| 149 | /* list of registered algorithms */ |
| 150 | struct list_head alg_list; |
| 151 | |
| 152 | /* hwrng device */ |
| 153 | struct hwrng rng; |
| 154 | }; |
| 155 | |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 156 | /* .features flag */ |
| 157 | #define TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT 0x00000001 |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 158 | #define TALITOS_FTR_HW_AUTH_CHECK 0x00000002 |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 159 | #define TALITOS_FTR_SHA224_HWINIT 0x00000004 |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 160 | #define TALITOS_FTR_HMAC_OK 0x00000008 |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 161 | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 162 | static void to_talitos_ptr(struct talitos_ptr *talitos_ptr, dma_addr_t dma_addr) |
| 163 | { |
| 164 | talitos_ptr->ptr = cpu_to_be32(lower_32_bits(dma_addr)); |
Kim Phillips | a752447 | 2010-09-23 15:56:38 +0800 | [diff] [blame] | 165 | talitos_ptr->eptr = upper_32_bits(dma_addr); |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 166 | } |
| 167 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 168 | /* |
| 169 | * map virtual single (contiguous) pointer to h/w descriptor pointer |
| 170 | */ |
| 171 | static void map_single_talitos_ptr(struct device *dev, |
| 172 | struct talitos_ptr *talitos_ptr, |
| 173 | unsigned short len, void *data, |
| 174 | unsigned char extent, |
| 175 | enum dma_data_direction dir) |
| 176 | { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 177 | dma_addr_t dma_addr = dma_map_single(dev, data, len, dir); |
| 178 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 179 | talitos_ptr->len = cpu_to_be16(len); |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 180 | to_talitos_ptr(talitos_ptr, dma_addr); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 181 | talitos_ptr->j_extent = extent; |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * unmap bus single (contiguous) h/w descriptor pointer |
| 186 | */ |
| 187 | static void unmap_single_talitos_ptr(struct device *dev, |
| 188 | struct talitos_ptr *talitos_ptr, |
| 189 | enum dma_data_direction dir) |
| 190 | { |
| 191 | dma_unmap_single(dev, be32_to_cpu(talitos_ptr->ptr), |
| 192 | be16_to_cpu(talitos_ptr->len), dir); |
| 193 | } |
| 194 | |
| 195 | static int reset_channel(struct device *dev, int ch) |
| 196 | { |
| 197 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 198 | unsigned int timeout = TALITOS_TIMEOUT; |
| 199 | |
| 200 | setbits32(priv->reg + TALITOS_CCCR(ch), TALITOS_CCCR_RESET); |
| 201 | |
| 202 | while ((in_be32(priv->reg + TALITOS_CCCR(ch)) & TALITOS_CCCR_RESET) |
| 203 | && --timeout) |
| 204 | cpu_relax(); |
| 205 | |
| 206 | if (timeout == 0) { |
| 207 | dev_err(dev, "failed to reset channel %d\n", ch); |
| 208 | return -EIO; |
| 209 | } |
| 210 | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 211 | /* set 36-bit addressing, done writeback enable and done IRQ enable */ |
| 212 | setbits32(priv->reg + TALITOS_CCCR_LO(ch), TALITOS_CCCR_LO_EAE | |
| 213 | TALITOS_CCCR_LO_CDWE | TALITOS_CCCR_LO_CDIE); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 214 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 215 | /* and ICCR writeback, if available */ |
| 216 | if (priv->features & TALITOS_FTR_HW_AUTH_CHECK) |
| 217 | setbits32(priv->reg + TALITOS_CCCR_LO(ch), |
| 218 | TALITOS_CCCR_LO_IWSE); |
| 219 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | static int reset_device(struct device *dev) |
| 224 | { |
| 225 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 226 | unsigned int timeout = TALITOS_TIMEOUT; |
| 227 | |
| 228 | setbits32(priv->reg + TALITOS_MCR, TALITOS_MCR_SWR); |
| 229 | |
| 230 | while ((in_be32(priv->reg + TALITOS_MCR) & TALITOS_MCR_SWR) |
| 231 | && --timeout) |
| 232 | cpu_relax(); |
| 233 | |
| 234 | if (timeout == 0) { |
| 235 | dev_err(dev, "failed to reset device\n"); |
| 236 | return -EIO; |
| 237 | } |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * Reset and initialize the device |
| 244 | */ |
| 245 | static int init_device(struct device *dev) |
| 246 | { |
| 247 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 248 | int ch, err; |
| 249 | |
| 250 | /* |
| 251 | * Master reset |
| 252 | * errata documentation: warning: certain SEC interrupts |
| 253 | * are not fully cleared by writing the MCR:SWR bit, |
| 254 | * set bit twice to completely reset |
| 255 | */ |
| 256 | err = reset_device(dev); |
| 257 | if (err) |
| 258 | return err; |
| 259 | |
| 260 | err = reset_device(dev); |
| 261 | if (err) |
| 262 | return err; |
| 263 | |
| 264 | /* reset channels */ |
| 265 | for (ch = 0; ch < priv->num_channels; ch++) { |
| 266 | err = reset_channel(dev, ch); |
| 267 | if (err) |
| 268 | return err; |
| 269 | } |
| 270 | |
| 271 | /* enable channel done and error interrupts */ |
| 272 | setbits32(priv->reg + TALITOS_IMR, TALITOS_IMR_INIT); |
| 273 | setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT); |
| 274 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 275 | /* disable integrity check error interrupts (use writeback instead) */ |
| 276 | if (priv->features & TALITOS_FTR_HW_AUTH_CHECK) |
| 277 | setbits32(priv->reg + TALITOS_MDEUICR_LO, |
| 278 | TALITOS_MDEUICR_LO_ICE); |
| 279 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * talitos_submit - submits a descriptor to the device for processing |
| 285 | * @dev: the SEC device to be used |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 286 | * @ch: the SEC device channel to be used |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 287 | * @desc: the descriptor to be processed by the device |
| 288 | * @callback: whom to call when processing is complete |
| 289 | * @context: a handle for use by caller (optional) |
| 290 | * |
| 291 | * desc must contain valid dma-mapped (bus physical) address pointers. |
| 292 | * callback must check err and feedback in descriptor header |
| 293 | * for device processing status. |
| 294 | */ |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 295 | static int talitos_submit(struct device *dev, int ch, struct talitos_desc *desc, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 296 | void (*callback)(struct device *dev, |
| 297 | struct talitos_desc *desc, |
| 298 | void *context, int error), |
| 299 | void *context) |
| 300 | { |
| 301 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 302 | struct talitos_request *request; |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 303 | unsigned long flags; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 304 | int head; |
| 305 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 306 | spin_lock_irqsave(&priv->chan[ch].head_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 307 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 308 | if (!atomic_inc_not_zero(&priv->chan[ch].submit_count)) { |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 309 | /* h/w fifo is full */ |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 310 | spin_unlock_irqrestore(&priv->chan[ch].head_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 311 | return -EAGAIN; |
| 312 | } |
| 313 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 314 | head = priv->chan[ch].head; |
| 315 | request = &priv->chan[ch].fifo[head]; |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 316 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 317 | /* map descriptor and save caller data */ |
| 318 | request->dma_desc = dma_map_single(dev, desc, sizeof(*desc), |
| 319 | DMA_BIDIRECTIONAL); |
| 320 | request->callback = callback; |
| 321 | request->context = context; |
| 322 | |
| 323 | /* increment fifo head */ |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 324 | 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] | 325 | |
| 326 | smp_wmb(); |
| 327 | request->desc = desc; |
| 328 | |
| 329 | /* GO! */ |
| 330 | wmb(); |
Kim Phillips | a752447 | 2010-09-23 15:56:38 +0800 | [diff] [blame] | 331 | out_be32(priv->reg + TALITOS_FF(ch), upper_32_bits(request->dma_desc)); |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 332 | out_be32(priv->reg + TALITOS_FF_LO(ch), |
Kim Phillips | a752447 | 2010-09-23 15:56:38 +0800 | [diff] [blame] | 333 | lower_32_bits(request->dma_desc)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 334 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 335 | spin_unlock_irqrestore(&priv->chan[ch].head_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 336 | |
| 337 | return -EINPROGRESS; |
| 338 | } |
| 339 | |
| 340 | /* |
| 341 | * process what was done, notify callback of error if not |
| 342 | */ |
| 343 | static void flush_channel(struct device *dev, int ch, int error, int reset_ch) |
| 344 | { |
| 345 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 346 | struct talitos_request *request, saved_req; |
| 347 | unsigned long flags; |
| 348 | int tail, status; |
| 349 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 350 | spin_lock_irqsave(&priv->chan[ch].tail_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 351 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 352 | tail = priv->chan[ch].tail; |
| 353 | while (priv->chan[ch].fifo[tail].desc) { |
| 354 | request = &priv->chan[ch].fifo[tail]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 355 | |
| 356 | /* descriptors with their done bits set don't get the error */ |
| 357 | rmb(); |
Lee Nipper | ca38a81 | 2008-12-20 17:09:25 +1100 | [diff] [blame] | 358 | if ((request->desc->hdr & DESC_HDR_DONE) == DESC_HDR_DONE) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 359 | status = 0; |
Lee Nipper | ca38a81 | 2008-12-20 17:09:25 +1100 | [diff] [blame] | 360 | else |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 361 | if (!error) |
| 362 | break; |
| 363 | else |
| 364 | status = error; |
| 365 | |
| 366 | dma_unmap_single(dev, request->dma_desc, |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 367 | sizeof(struct talitos_desc), |
| 368 | DMA_BIDIRECTIONAL); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 369 | |
| 370 | /* copy entries so we can call callback outside lock */ |
| 371 | saved_req.desc = request->desc; |
| 372 | saved_req.callback = request->callback; |
| 373 | saved_req.context = request->context; |
| 374 | |
| 375 | /* release request entry in fifo */ |
| 376 | smp_wmb(); |
| 377 | request->desc = NULL; |
| 378 | |
| 379 | /* increment fifo tail */ |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 380 | priv->chan[ch].tail = (tail + 1) & (priv->fifo_len - 1); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 381 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 382 | spin_unlock_irqrestore(&priv->chan[ch].tail_lock, flags); |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 383 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 384 | atomic_dec(&priv->chan[ch].submit_count); |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 385 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 386 | saved_req.callback(dev, saved_req.desc, saved_req.context, |
| 387 | status); |
| 388 | /* channel may resume processing in single desc error case */ |
| 389 | if (error && !reset_ch && status == error) |
| 390 | return; |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 391 | spin_lock_irqsave(&priv->chan[ch].tail_lock, flags); |
| 392 | tail = priv->chan[ch].tail; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 393 | } |
| 394 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 395 | spin_unlock_irqrestore(&priv->chan[ch].tail_lock, flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* |
| 399 | * process completed requests for channels that have done status |
| 400 | */ |
| 401 | static void talitos_done(unsigned long data) |
| 402 | { |
| 403 | struct device *dev = (struct device *)data; |
| 404 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 405 | int ch; |
| 406 | |
| 407 | for (ch = 0; ch < priv->num_channels; ch++) |
| 408 | flush_channel(dev, ch, 0, 0); |
Lee Nipper | 1c2e881 | 2008-10-12 20:29:34 +0800 | [diff] [blame] | 409 | |
| 410 | /* At this point, all completed channels have been processed. |
| 411 | * Unmask done interrupts for channels completed later on. |
| 412 | */ |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 413 | setbits32(priv->reg + TALITOS_IMR, TALITOS_IMR_INIT); |
| 414 | setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* |
| 418 | * locate current (offending) descriptor |
| 419 | */ |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 420 | static u32 current_desc_hdr(struct device *dev, int ch) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 421 | { |
| 422 | struct talitos_private *priv = dev_get_drvdata(dev); |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 423 | int tail = priv->chan[ch].tail; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 424 | dma_addr_t cur_desc; |
| 425 | |
| 426 | cur_desc = in_be32(priv->reg + TALITOS_CDPR_LO(ch)); |
| 427 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 428 | while (priv->chan[ch].fifo[tail].dma_desc != cur_desc) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 429 | tail = (tail + 1) & (priv->fifo_len - 1); |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 430 | if (tail == priv->chan[ch].tail) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 431 | dev_err(dev, "couldn't locate current descriptor\n"); |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 432 | return 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 436 | return priv->chan[ch].fifo[tail].desc->hdr; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* |
| 440 | * user diagnostics; report root cause of error based on execution unit status |
| 441 | */ |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 442 | 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] | 443 | { |
| 444 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 445 | int i; |
| 446 | |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 447 | if (!desc_hdr) |
| 448 | desc_hdr = in_be32(priv->reg + TALITOS_DESCBUF(ch)); |
| 449 | |
| 450 | switch (desc_hdr & DESC_HDR_SEL0_MASK) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 451 | case DESC_HDR_SEL0_AFEU: |
| 452 | dev_err(dev, "AFEUISR 0x%08x_%08x\n", |
| 453 | in_be32(priv->reg + TALITOS_AFEUISR), |
| 454 | in_be32(priv->reg + TALITOS_AFEUISR_LO)); |
| 455 | break; |
| 456 | case DESC_HDR_SEL0_DEU: |
| 457 | dev_err(dev, "DEUISR 0x%08x_%08x\n", |
| 458 | in_be32(priv->reg + TALITOS_DEUISR), |
| 459 | in_be32(priv->reg + TALITOS_DEUISR_LO)); |
| 460 | break; |
| 461 | case DESC_HDR_SEL0_MDEUA: |
| 462 | case DESC_HDR_SEL0_MDEUB: |
| 463 | dev_err(dev, "MDEUISR 0x%08x_%08x\n", |
| 464 | in_be32(priv->reg + TALITOS_MDEUISR), |
| 465 | in_be32(priv->reg + TALITOS_MDEUISR_LO)); |
| 466 | break; |
| 467 | case DESC_HDR_SEL0_RNG: |
| 468 | dev_err(dev, "RNGUISR 0x%08x_%08x\n", |
| 469 | in_be32(priv->reg + TALITOS_RNGUISR), |
| 470 | in_be32(priv->reg + TALITOS_RNGUISR_LO)); |
| 471 | break; |
| 472 | case DESC_HDR_SEL0_PKEU: |
| 473 | dev_err(dev, "PKEUISR 0x%08x_%08x\n", |
| 474 | in_be32(priv->reg + TALITOS_PKEUISR), |
| 475 | in_be32(priv->reg + TALITOS_PKEUISR_LO)); |
| 476 | break; |
| 477 | case DESC_HDR_SEL0_AESU: |
| 478 | dev_err(dev, "AESUISR 0x%08x_%08x\n", |
| 479 | in_be32(priv->reg + TALITOS_AESUISR), |
| 480 | in_be32(priv->reg + TALITOS_AESUISR_LO)); |
| 481 | break; |
| 482 | case DESC_HDR_SEL0_CRCU: |
| 483 | dev_err(dev, "CRCUISR 0x%08x_%08x\n", |
| 484 | in_be32(priv->reg + TALITOS_CRCUISR), |
| 485 | in_be32(priv->reg + TALITOS_CRCUISR_LO)); |
| 486 | break; |
| 487 | case DESC_HDR_SEL0_KEU: |
| 488 | dev_err(dev, "KEUISR 0x%08x_%08x\n", |
| 489 | in_be32(priv->reg + TALITOS_KEUISR), |
| 490 | in_be32(priv->reg + TALITOS_KEUISR_LO)); |
| 491 | break; |
| 492 | } |
| 493 | |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 494 | switch (desc_hdr & DESC_HDR_SEL1_MASK) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 495 | case DESC_HDR_SEL1_MDEUA: |
| 496 | case DESC_HDR_SEL1_MDEUB: |
| 497 | dev_err(dev, "MDEUISR 0x%08x_%08x\n", |
| 498 | in_be32(priv->reg + TALITOS_MDEUISR), |
| 499 | in_be32(priv->reg + TALITOS_MDEUISR_LO)); |
| 500 | break; |
| 501 | case DESC_HDR_SEL1_CRCU: |
| 502 | dev_err(dev, "CRCUISR 0x%08x_%08x\n", |
| 503 | in_be32(priv->reg + TALITOS_CRCUISR), |
| 504 | in_be32(priv->reg + TALITOS_CRCUISR_LO)); |
| 505 | break; |
| 506 | } |
| 507 | |
| 508 | for (i = 0; i < 8; i++) |
| 509 | dev_err(dev, "DESCBUF 0x%08x_%08x\n", |
| 510 | in_be32(priv->reg + TALITOS_DESCBUF(ch) + 8*i), |
| 511 | in_be32(priv->reg + TALITOS_DESCBUF_LO(ch) + 8*i)); |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * recover from error interrupts |
| 516 | */ |
Kim Phillips | 40405f1 | 2008-10-12 20:19:35 +0800 | [diff] [blame] | 517 | static void talitos_error(unsigned long data, u32 isr, u32 isr_lo) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 518 | { |
| 519 | struct device *dev = (struct device *)data; |
| 520 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 521 | unsigned int timeout = TALITOS_TIMEOUT; |
| 522 | int ch, error, reset_dev = 0, reset_ch = 0; |
Kim Phillips | 40405f1 | 2008-10-12 20:19:35 +0800 | [diff] [blame] | 523 | u32 v, v_lo; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 524 | |
| 525 | for (ch = 0; ch < priv->num_channels; ch++) { |
| 526 | /* skip channels without errors */ |
| 527 | if (!(isr & (1 << (ch * 2 + 1)))) |
| 528 | continue; |
| 529 | |
| 530 | error = -EINVAL; |
| 531 | |
| 532 | v = in_be32(priv->reg + TALITOS_CCPSR(ch)); |
| 533 | v_lo = in_be32(priv->reg + TALITOS_CCPSR_LO(ch)); |
| 534 | |
| 535 | if (v_lo & TALITOS_CCPSR_LO_DOF) { |
| 536 | dev_err(dev, "double fetch fifo overflow error\n"); |
| 537 | error = -EAGAIN; |
| 538 | reset_ch = 1; |
| 539 | } |
| 540 | if (v_lo & TALITOS_CCPSR_LO_SOF) { |
| 541 | /* h/w dropped descriptor */ |
| 542 | dev_err(dev, "single fetch fifo overflow error\n"); |
| 543 | error = -EAGAIN; |
| 544 | } |
| 545 | if (v_lo & TALITOS_CCPSR_LO_MDTE) |
| 546 | dev_err(dev, "master data transfer error\n"); |
| 547 | if (v_lo & TALITOS_CCPSR_LO_SGDLZ) |
| 548 | dev_err(dev, "s/g data length zero error\n"); |
| 549 | if (v_lo & TALITOS_CCPSR_LO_FPZ) |
| 550 | dev_err(dev, "fetch pointer zero error\n"); |
| 551 | if (v_lo & TALITOS_CCPSR_LO_IDH) |
| 552 | dev_err(dev, "illegal descriptor header error\n"); |
| 553 | if (v_lo & TALITOS_CCPSR_LO_IEU) |
| 554 | dev_err(dev, "invalid execution unit error\n"); |
| 555 | if (v_lo & TALITOS_CCPSR_LO_EU) |
Kim Phillips | 3e721ae | 2011-10-21 15:20:28 +0200 | [diff] [blame] | 556 | report_eu_error(dev, ch, current_desc_hdr(dev, ch)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 557 | if (v_lo & TALITOS_CCPSR_LO_GB) |
| 558 | dev_err(dev, "gather boundary error\n"); |
| 559 | if (v_lo & TALITOS_CCPSR_LO_GRL) |
| 560 | dev_err(dev, "gather return/length error\n"); |
| 561 | if (v_lo & TALITOS_CCPSR_LO_SB) |
| 562 | dev_err(dev, "scatter boundary error\n"); |
| 563 | if (v_lo & TALITOS_CCPSR_LO_SRL) |
| 564 | dev_err(dev, "scatter return/length error\n"); |
| 565 | |
| 566 | flush_channel(dev, ch, error, reset_ch); |
| 567 | |
| 568 | if (reset_ch) { |
| 569 | reset_channel(dev, ch); |
| 570 | } else { |
| 571 | setbits32(priv->reg + TALITOS_CCCR(ch), |
| 572 | TALITOS_CCCR_CONT); |
| 573 | setbits32(priv->reg + TALITOS_CCCR_LO(ch), 0); |
| 574 | while ((in_be32(priv->reg + TALITOS_CCCR(ch)) & |
| 575 | TALITOS_CCCR_CONT) && --timeout) |
| 576 | cpu_relax(); |
| 577 | if (timeout == 0) { |
| 578 | dev_err(dev, "failed to restart channel %d\n", |
| 579 | ch); |
| 580 | reset_dev = 1; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | if (reset_dev || isr & ~TALITOS_ISR_CHERR || isr_lo) { |
| 585 | dev_err(dev, "done overflow, internal time out, or rngu error: " |
| 586 | "ISR 0x%08x_%08x\n", isr, isr_lo); |
| 587 | |
| 588 | /* purge request queues */ |
| 589 | for (ch = 0; ch < priv->num_channels; ch++) |
| 590 | flush_channel(dev, ch, -EIO, 1); |
| 591 | |
| 592 | /* reset and reinitialize the device */ |
| 593 | init_device(dev); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | static irqreturn_t talitos_interrupt(int irq, void *data) |
| 598 | { |
| 599 | struct device *dev = data; |
| 600 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 601 | u32 isr, isr_lo; |
| 602 | |
| 603 | isr = in_be32(priv->reg + TALITOS_ISR); |
| 604 | isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); |
Lee Nipper | ca38a81 | 2008-12-20 17:09:25 +1100 | [diff] [blame] | 605 | /* Acknowledge interrupt */ |
| 606 | out_be32(priv->reg + TALITOS_ICR, isr); |
| 607 | out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 608 | |
Lee Nipper | ca38a81 | 2008-12-20 17:09:25 +1100 | [diff] [blame] | 609 | if (unlikely((isr & ~TALITOS_ISR_CHDONE) || isr_lo)) |
Kim Phillips | 40405f1 | 2008-10-12 20:19:35 +0800 | [diff] [blame] | 610 | talitos_error((unsigned long)data, isr, isr_lo); |
Lee Nipper | ca38a81 | 2008-12-20 17:09:25 +1100 | [diff] [blame] | 611 | else |
Lee Nipper | 1c2e881 | 2008-10-12 20:29:34 +0800 | [diff] [blame] | 612 | if (likely(isr & TALITOS_ISR_CHDONE)) { |
| 613 | /* mask further done interrupts. */ |
| 614 | clrbits32(priv->reg + TALITOS_IMR, TALITOS_IMR_DONE); |
| 615 | /* done_task will unmask done interrupts at exit */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 616 | tasklet_schedule(&priv->done_task); |
Lee Nipper | 1c2e881 | 2008-10-12 20:29:34 +0800 | [diff] [blame] | 617 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 618 | |
| 619 | return (isr || isr_lo) ? IRQ_HANDLED : IRQ_NONE; |
| 620 | } |
| 621 | |
| 622 | /* |
| 623 | * hwrng |
| 624 | */ |
| 625 | static int talitos_rng_data_present(struct hwrng *rng, int wait) |
| 626 | { |
| 627 | struct device *dev = (struct device *)rng->priv; |
| 628 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 629 | u32 ofl; |
| 630 | int i; |
| 631 | |
| 632 | for (i = 0; i < 20; i++) { |
| 633 | ofl = in_be32(priv->reg + TALITOS_RNGUSR_LO) & |
| 634 | TALITOS_RNGUSR_LO_OFL; |
| 635 | if (ofl || !wait) |
| 636 | break; |
| 637 | udelay(10); |
| 638 | } |
| 639 | |
| 640 | return !!ofl; |
| 641 | } |
| 642 | |
| 643 | static int talitos_rng_data_read(struct hwrng *rng, u32 *data) |
| 644 | { |
| 645 | struct device *dev = (struct device *)rng->priv; |
| 646 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 647 | |
| 648 | /* rng fifo requires 64-bit accesses */ |
| 649 | *data = in_be32(priv->reg + TALITOS_RNGU_FIFO); |
| 650 | *data = in_be32(priv->reg + TALITOS_RNGU_FIFO_LO); |
| 651 | |
| 652 | return sizeof(u32); |
| 653 | } |
| 654 | |
| 655 | static int talitos_rng_init(struct hwrng *rng) |
| 656 | { |
| 657 | struct device *dev = (struct device *)rng->priv; |
| 658 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 659 | unsigned int timeout = TALITOS_TIMEOUT; |
| 660 | |
| 661 | setbits32(priv->reg + TALITOS_RNGURCR_LO, TALITOS_RNGURCR_LO_SR); |
| 662 | while (!(in_be32(priv->reg + TALITOS_RNGUSR_LO) & TALITOS_RNGUSR_LO_RD) |
| 663 | && --timeout) |
| 664 | cpu_relax(); |
| 665 | if (timeout == 0) { |
| 666 | dev_err(dev, "failed to reset rng hw\n"); |
| 667 | return -ENODEV; |
| 668 | } |
| 669 | |
| 670 | /* start generating */ |
| 671 | setbits32(priv->reg + TALITOS_RNGUDSR_LO, 0); |
| 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | static int talitos_register_rng(struct device *dev) |
| 677 | { |
| 678 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 679 | |
| 680 | priv->rng.name = dev_driver_string(dev), |
| 681 | priv->rng.init = talitos_rng_init, |
| 682 | priv->rng.data_present = talitos_rng_data_present, |
| 683 | priv->rng.data_read = talitos_rng_data_read, |
| 684 | priv->rng.priv = (unsigned long)dev; |
| 685 | |
| 686 | return hwrng_register(&priv->rng); |
| 687 | } |
| 688 | |
| 689 | static void talitos_unregister_rng(struct device *dev) |
| 690 | { |
| 691 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 692 | |
| 693 | hwrng_unregister(&priv->rng); |
| 694 | } |
| 695 | |
| 696 | /* |
| 697 | * crypto alg |
| 698 | */ |
| 699 | #define TALITOS_CRA_PRIORITY 3000 |
| 700 | #define TALITOS_MAX_KEY_SIZE 64 |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 701 | #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] | 702 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 703 | #define MD5_BLOCK_SIZE 64 |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 704 | |
| 705 | struct talitos_ctx { |
| 706 | struct device *dev; |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 707 | int ch; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 708 | __be32 desc_hdr_template; |
| 709 | u8 key[TALITOS_MAX_KEY_SIZE]; |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 710 | u8 iv[TALITOS_MAX_IV_LENGTH]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 711 | unsigned int keylen; |
| 712 | unsigned int enckeylen; |
| 713 | unsigned int authkeylen; |
| 714 | unsigned int authsize; |
| 715 | }; |
| 716 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 717 | #define HASH_MAX_BLOCK_SIZE SHA512_BLOCK_SIZE |
| 718 | #define TALITOS_MDEU_MAX_CONTEXT_SIZE TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512 |
| 719 | |
| 720 | struct talitos_ahash_req_ctx { |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 721 | u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof(u32)]; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 722 | unsigned int hw_context_size; |
| 723 | u8 buf[HASH_MAX_BLOCK_SIZE]; |
| 724 | u8 bufnext[HASH_MAX_BLOCK_SIZE]; |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 725 | unsigned int swinit; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 726 | unsigned int first; |
| 727 | unsigned int last; |
| 728 | unsigned int to_hash_later; |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 729 | u64 nbuf; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 730 | struct scatterlist bufsl[2]; |
| 731 | struct scatterlist *psrc; |
| 732 | }; |
| 733 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 734 | static int aead_setauthsize(struct crypto_aead *authenc, |
| 735 | unsigned int authsize) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 736 | { |
| 737 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
| 738 | |
| 739 | ctx->authsize = authsize; |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 744 | static int aead_setkey(struct crypto_aead *authenc, |
| 745 | const u8 *key, unsigned int keylen) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 746 | { |
| 747 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
| 748 | struct rtattr *rta = (void *)key; |
| 749 | struct crypto_authenc_key_param *param; |
| 750 | unsigned int authkeylen; |
| 751 | unsigned int enckeylen; |
| 752 | |
| 753 | if (!RTA_OK(rta, keylen)) |
| 754 | goto badkey; |
| 755 | |
| 756 | if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM) |
| 757 | goto badkey; |
| 758 | |
| 759 | if (RTA_PAYLOAD(rta) < sizeof(*param)) |
| 760 | goto badkey; |
| 761 | |
| 762 | param = RTA_DATA(rta); |
| 763 | enckeylen = be32_to_cpu(param->enckeylen); |
| 764 | |
| 765 | key += RTA_ALIGN(rta->rta_len); |
| 766 | keylen -= RTA_ALIGN(rta->rta_len); |
| 767 | |
| 768 | if (keylen < enckeylen) |
| 769 | goto badkey; |
| 770 | |
| 771 | authkeylen = keylen - enckeylen; |
| 772 | |
| 773 | if (keylen > TALITOS_MAX_KEY_SIZE) |
| 774 | goto badkey; |
| 775 | |
| 776 | memcpy(&ctx->key, key, keylen); |
| 777 | |
| 778 | ctx->keylen = keylen; |
| 779 | ctx->enckeylen = enckeylen; |
| 780 | ctx->authkeylen = authkeylen; |
| 781 | |
| 782 | return 0; |
| 783 | |
| 784 | badkey: |
| 785 | crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | |
| 789 | /* |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 790 | * talitos_edesc - s/w-extended descriptor |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 791 | * @src_nents: number of segments in input scatterlist |
| 792 | * @dst_nents: number of segments in output scatterlist |
| 793 | * @dma_len: length of dma mapped link_tbl space |
| 794 | * @dma_link_tbl: bus physical address of link_tbl |
| 795 | * @desc: h/w descriptor |
| 796 | * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) |
| 797 | * |
| 798 | * if decrypting (with authcheck), or either one of src_nents or dst_nents |
| 799 | * is greater than 1, an integrity check value is concatenated to the end |
| 800 | * of link_tbl data |
| 801 | */ |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 802 | struct talitos_edesc { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 803 | int src_nents; |
| 804 | int dst_nents; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 805 | int src_is_chained; |
| 806 | int dst_is_chained; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 807 | int dma_len; |
| 808 | dma_addr_t dma_link_tbl; |
| 809 | struct talitos_desc desc; |
| 810 | struct talitos_ptr link_tbl[0]; |
| 811 | }; |
| 812 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 813 | static int talitos_map_sg(struct device *dev, struct scatterlist *sg, |
| 814 | unsigned int nents, enum dma_data_direction dir, |
| 815 | int chained) |
| 816 | { |
| 817 | if (unlikely(chained)) |
| 818 | while (sg) { |
| 819 | dma_map_sg(dev, sg, 1, dir); |
| 820 | sg = scatterwalk_sg_next(sg); |
| 821 | } |
| 822 | else |
| 823 | dma_map_sg(dev, sg, nents, dir); |
| 824 | return nents; |
| 825 | } |
| 826 | |
| 827 | static void talitos_unmap_sg_chain(struct device *dev, struct scatterlist *sg, |
| 828 | enum dma_data_direction dir) |
| 829 | { |
| 830 | while (sg) { |
| 831 | dma_unmap_sg(dev, sg, 1, dir); |
| 832 | sg = scatterwalk_sg_next(sg); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | static void talitos_sg_unmap(struct device *dev, |
| 837 | struct talitos_edesc *edesc, |
| 838 | struct scatterlist *src, |
| 839 | struct scatterlist *dst) |
| 840 | { |
| 841 | unsigned int src_nents = edesc->src_nents ? : 1; |
| 842 | unsigned int dst_nents = edesc->dst_nents ? : 1; |
| 843 | |
| 844 | if (src != dst) { |
| 845 | if (edesc->src_is_chained) |
| 846 | talitos_unmap_sg_chain(dev, src, DMA_TO_DEVICE); |
| 847 | else |
| 848 | dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE); |
| 849 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 850 | if (dst) { |
| 851 | if (edesc->dst_is_chained) |
| 852 | talitos_unmap_sg_chain(dev, dst, |
| 853 | DMA_FROM_DEVICE); |
| 854 | else |
| 855 | dma_unmap_sg(dev, dst, dst_nents, |
| 856 | DMA_FROM_DEVICE); |
| 857 | } |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 858 | } else |
| 859 | if (edesc->src_is_chained) |
| 860 | talitos_unmap_sg_chain(dev, src, DMA_BIDIRECTIONAL); |
| 861 | else |
| 862 | dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL); |
| 863 | } |
| 864 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 865 | static void ipsec_esp_unmap(struct device *dev, |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 866 | struct talitos_edesc *edesc, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 867 | struct aead_request *areq) |
| 868 | { |
| 869 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[6], DMA_FROM_DEVICE); |
| 870 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[3], DMA_TO_DEVICE); |
| 871 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE); |
| 872 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[0], DMA_TO_DEVICE); |
| 873 | |
| 874 | dma_unmap_sg(dev, areq->assoc, 1, DMA_TO_DEVICE); |
| 875 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 876 | talitos_sg_unmap(dev, edesc, areq->src, areq->dst); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 877 | |
| 878 | if (edesc->dma_len) |
| 879 | dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, |
| 880 | DMA_BIDIRECTIONAL); |
| 881 | } |
| 882 | |
| 883 | /* |
| 884 | * ipsec_esp descriptor callbacks |
| 885 | */ |
| 886 | static void ipsec_esp_encrypt_done(struct device *dev, |
| 887 | struct talitos_desc *desc, void *context, |
| 888 | int err) |
| 889 | { |
| 890 | struct aead_request *areq = context; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 891 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); |
| 892 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 893 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 894 | struct scatterlist *sg; |
| 895 | void *icvdata; |
| 896 | |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 897 | edesc = container_of(desc, struct talitos_edesc, desc); |
| 898 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 899 | ipsec_esp_unmap(dev, edesc, areq); |
| 900 | |
| 901 | /* copy the generated ICV to dst */ |
| 902 | if (edesc->dma_len) { |
| 903 | icvdata = &edesc->link_tbl[edesc->src_nents + |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 904 | edesc->dst_nents + 2]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 905 | sg = sg_last(areq->dst, edesc->dst_nents); |
| 906 | memcpy((char *)sg_virt(sg) + sg->length - ctx->authsize, |
| 907 | icvdata, ctx->authsize); |
| 908 | } |
| 909 | |
| 910 | kfree(edesc); |
| 911 | |
| 912 | aead_request_complete(areq, err); |
| 913 | } |
| 914 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 915 | static void ipsec_esp_decrypt_swauth_done(struct device *dev, |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 916 | struct talitos_desc *desc, |
| 917 | void *context, int err) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 918 | { |
| 919 | struct aead_request *req = context; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 920 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
| 921 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 922 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 923 | struct scatterlist *sg; |
| 924 | void *icvdata; |
| 925 | |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 926 | edesc = container_of(desc, struct talitos_edesc, desc); |
| 927 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 928 | ipsec_esp_unmap(dev, edesc, req); |
| 929 | |
| 930 | if (!err) { |
| 931 | /* auth check */ |
| 932 | if (edesc->dma_len) |
| 933 | icvdata = &edesc->link_tbl[edesc->src_nents + |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 934 | edesc->dst_nents + 2]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 935 | else |
| 936 | icvdata = &edesc->link_tbl[0]; |
| 937 | |
| 938 | sg = sg_last(req->dst, edesc->dst_nents ? : 1); |
| 939 | err = memcmp(icvdata, (char *)sg_virt(sg) + sg->length - |
| 940 | ctx->authsize, ctx->authsize) ? -EBADMSG : 0; |
| 941 | } |
| 942 | |
| 943 | kfree(edesc); |
| 944 | |
| 945 | aead_request_complete(req, err); |
| 946 | } |
| 947 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 948 | static void ipsec_esp_decrypt_hwauth_done(struct device *dev, |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 949 | struct talitos_desc *desc, |
| 950 | void *context, int err) |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 951 | { |
| 952 | struct aead_request *req = context; |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 953 | struct talitos_edesc *edesc; |
| 954 | |
| 955 | edesc = container_of(desc, struct talitos_edesc, desc); |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 956 | |
| 957 | ipsec_esp_unmap(dev, edesc, req); |
| 958 | |
| 959 | /* check ICV auth status */ |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 960 | if (!err && ((desc->hdr_lo & DESC_HDR_LO_ICCR1_MASK) != |
| 961 | DESC_HDR_LO_ICCR1_PASS)) |
| 962 | err = -EBADMSG; |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 963 | |
| 964 | kfree(edesc); |
| 965 | |
| 966 | aead_request_complete(req, err); |
| 967 | } |
| 968 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 969 | /* |
| 970 | * convert scatterlist to SEC h/w link table format |
| 971 | * stop at cryptlen bytes |
| 972 | */ |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 973 | static int sg_to_link_tbl(struct scatterlist *sg, int sg_count, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 974 | int cryptlen, struct talitos_ptr *link_tbl_ptr) |
| 975 | { |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 976 | int n_sg = sg_count; |
| 977 | |
| 978 | while (n_sg--) { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 979 | to_talitos_ptr(link_tbl_ptr, sg_dma_address(sg)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 980 | link_tbl_ptr->len = cpu_to_be16(sg_dma_len(sg)); |
| 981 | link_tbl_ptr->j_extent = 0; |
| 982 | link_tbl_ptr++; |
| 983 | cryptlen -= sg_dma_len(sg); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 984 | sg = scatterwalk_sg_next(sg); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 985 | } |
| 986 | |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 987 | /* adjust (decrease) last one (or two) entry's len to cryptlen */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 988 | link_tbl_ptr--; |
Kim Phillips | c0e741d | 2008-07-17 20:20:59 +0800 | [diff] [blame] | 989 | while (be16_to_cpu(link_tbl_ptr->len) <= (-cryptlen)) { |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 990 | /* Empty this entry, and move to previous one */ |
| 991 | cryptlen += be16_to_cpu(link_tbl_ptr->len); |
| 992 | link_tbl_ptr->len = 0; |
| 993 | sg_count--; |
| 994 | link_tbl_ptr--; |
| 995 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 996 | link_tbl_ptr->len = cpu_to_be16(be16_to_cpu(link_tbl_ptr->len) |
| 997 | + cryptlen); |
| 998 | |
| 999 | /* tag end of link table */ |
| 1000 | link_tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN; |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1001 | |
| 1002 | return sg_count; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /* |
| 1006 | * fill in and submit ipsec_esp descriptor |
| 1007 | */ |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1008 | static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1009 | u8 *giv, u64 seq, |
| 1010 | void (*callback) (struct device *dev, |
| 1011 | struct talitos_desc *desc, |
| 1012 | void *context, int error)) |
| 1013 | { |
| 1014 | struct crypto_aead *aead = crypto_aead_reqtfm(areq); |
| 1015 | struct talitos_ctx *ctx = crypto_aead_ctx(aead); |
| 1016 | struct device *dev = ctx->dev; |
| 1017 | struct talitos_desc *desc = &edesc->desc; |
| 1018 | unsigned int cryptlen = areq->cryptlen; |
| 1019 | unsigned int authsize = ctx->authsize; |
Kim Phillips | e41256f | 2009-08-13 11:49:06 +1000 | [diff] [blame] | 1020 | unsigned int ivsize = crypto_aead_ivsize(aead); |
Kim Phillips | fa86a26 | 2008-07-17 20:20:06 +0800 | [diff] [blame] | 1021 | int sg_count, ret; |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1022 | int sg_link_tbl_len; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1023 | |
| 1024 | /* hmac key */ |
| 1025 | map_single_talitos_ptr(dev, &desc->ptr[0], ctx->authkeylen, &ctx->key, |
| 1026 | 0, DMA_TO_DEVICE); |
| 1027 | /* hmac data */ |
Kim Phillips | e41256f | 2009-08-13 11:49:06 +1000 | [diff] [blame] | 1028 | map_single_talitos_ptr(dev, &desc->ptr[1], areq->assoclen + ivsize, |
| 1029 | sg_virt(areq->assoc), 0, DMA_TO_DEVICE); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1030 | /* cipher iv */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1031 | map_single_talitos_ptr(dev, &desc->ptr[2], ivsize, giv ?: areq->iv, 0, |
| 1032 | DMA_TO_DEVICE); |
| 1033 | |
| 1034 | /* cipher key */ |
| 1035 | map_single_talitos_ptr(dev, &desc->ptr[3], ctx->enckeylen, |
| 1036 | (char *)&ctx->key + ctx->authkeylen, 0, |
| 1037 | DMA_TO_DEVICE); |
| 1038 | |
| 1039 | /* |
| 1040 | * cipher in |
| 1041 | * map and adjust cipher len to aead request cryptlen. |
| 1042 | * extent is bytes of HMAC postpended to ciphertext, |
| 1043 | * typically 12 for ipsec |
| 1044 | */ |
| 1045 | desc->ptr[4].len = cpu_to_be16(cryptlen); |
| 1046 | desc->ptr[4].j_extent = authsize; |
| 1047 | |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1048 | sg_count = talitos_map_sg(dev, areq->src, edesc->src_nents ? : 1, |
| 1049 | (areq->src == areq->dst) ? DMA_BIDIRECTIONAL |
| 1050 | : DMA_TO_DEVICE, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1051 | edesc->src_is_chained); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1052 | |
| 1053 | if (sg_count == 1) { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1054 | to_talitos_ptr(&desc->ptr[4], sg_dma_address(areq->src)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1055 | } else { |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1056 | sg_link_tbl_len = cryptlen; |
| 1057 | |
Kim Phillips | 962a9c9 | 2009-03-29 15:54:30 +0800 | [diff] [blame] | 1058 | if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV) |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1059 | sg_link_tbl_len = cryptlen + authsize; |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1060 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1061 | sg_count = sg_to_link_tbl(areq->src, sg_count, sg_link_tbl_len, |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1062 | &edesc->link_tbl[0]); |
| 1063 | if (sg_count > 1) { |
| 1064 | desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP; |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1065 | to_talitos_ptr(&desc->ptr[4], edesc->dma_link_tbl); |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1066 | dma_sync_single_for_device(dev, edesc->dma_link_tbl, |
| 1067 | edesc->dma_len, |
| 1068 | DMA_BIDIRECTIONAL); |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1069 | } else { |
| 1070 | /* Only one segment now, so no link tbl needed */ |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1071 | to_talitos_ptr(&desc->ptr[4], |
| 1072 | sg_dma_address(areq->src)); |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1073 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | /* cipher out */ |
| 1077 | desc->ptr[5].len = cpu_to_be16(cryptlen); |
| 1078 | desc->ptr[5].j_extent = authsize; |
| 1079 | |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1080 | if (areq->src != areq->dst) |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1081 | sg_count = talitos_map_sg(dev, areq->dst, |
| 1082 | edesc->dst_nents ? : 1, |
| 1083 | DMA_FROM_DEVICE, |
| 1084 | edesc->dst_is_chained); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1085 | |
| 1086 | if (sg_count == 1) { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1087 | to_talitos_ptr(&desc->ptr[5], sg_dma_address(areq->dst)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1088 | } else { |
| 1089 | struct talitos_ptr *link_tbl_ptr = |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 1090 | &edesc->link_tbl[edesc->src_nents + 1]; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1091 | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1092 | to_talitos_ptr(&desc->ptr[5], edesc->dma_link_tbl + |
| 1093 | (edesc->src_nents + 1) * |
| 1094 | sizeof(struct talitos_ptr)); |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1095 | sg_count = sg_to_link_tbl(areq->dst, sg_count, cryptlen, |
| 1096 | link_tbl_ptr); |
| 1097 | |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 1098 | /* Add an entry to the link table for ICV data */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1099 | link_tbl_ptr += sg_count - 1; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1100 | link_tbl_ptr->j_extent = 0; |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 1101 | sg_count++; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1102 | link_tbl_ptr++; |
| 1103 | link_tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN; |
| 1104 | link_tbl_ptr->len = cpu_to_be16(authsize); |
| 1105 | |
| 1106 | /* icv data follows link tables */ |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1107 | to_talitos_ptr(link_tbl_ptr, edesc->dma_link_tbl + |
| 1108 | (edesc->src_nents + edesc->dst_nents + 2) * |
| 1109 | sizeof(struct talitos_ptr)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1110 | desc->ptr[5].j_extent |= DESC_PTR_LNKTBL_JUMP; |
| 1111 | dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl, |
| 1112 | edesc->dma_len, DMA_BIDIRECTIONAL); |
| 1113 | } |
| 1114 | |
| 1115 | /* iv out */ |
| 1116 | map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, 0, |
| 1117 | DMA_FROM_DEVICE); |
| 1118 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 1119 | ret = talitos_submit(dev, ctx->ch, desc, callback, areq); |
Kim Phillips | fa86a26 | 2008-07-17 20:20:06 +0800 | [diff] [blame] | 1120 | if (ret != -EINPROGRESS) { |
| 1121 | ipsec_esp_unmap(dev, edesc, areq); |
| 1122 | kfree(edesc); |
| 1123 | } |
| 1124 | return ret; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1125 | } |
| 1126 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1127 | /* |
| 1128 | * derive number of elements in scatterlist |
| 1129 | */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1130 | static int sg_count(struct scatterlist *sg_list, int nbytes, int *chained) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1131 | { |
| 1132 | struct scatterlist *sg = sg_list; |
| 1133 | int sg_nents = 0; |
| 1134 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1135 | *chained = 0; |
| 1136 | while (nbytes > 0) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1137 | sg_nents++; |
| 1138 | nbytes -= sg->length; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1139 | if (!sg_is_last(sg) && (sg + 1)->length == 0) |
| 1140 | *chained = 1; |
| 1141 | sg = scatterwalk_sg_next(sg); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | return sg_nents; |
| 1145 | } |
| 1146 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1147 | /** |
| 1148 | * sg_copy_end_to_buffer - Copy end data from SG list to a linear buffer |
| 1149 | * @sgl: The SG list |
| 1150 | * @nents: Number of SG entries |
| 1151 | * @buf: Where to copy to |
| 1152 | * @buflen: The number of bytes to copy |
| 1153 | * @skip: The number of bytes to skip before copying. |
| 1154 | * Note: skip + buflen should equal SG total size. |
| 1155 | * |
| 1156 | * Returns the number of copied bytes. |
| 1157 | * |
| 1158 | **/ |
| 1159 | static size_t sg_copy_end_to_buffer(struct scatterlist *sgl, unsigned int nents, |
| 1160 | void *buf, size_t buflen, unsigned int skip) |
| 1161 | { |
| 1162 | unsigned int offset = 0; |
| 1163 | unsigned int boffset = 0; |
| 1164 | struct sg_mapping_iter miter; |
| 1165 | unsigned long flags; |
| 1166 | unsigned int sg_flags = SG_MITER_ATOMIC; |
| 1167 | size_t total_buffer = buflen + skip; |
| 1168 | |
| 1169 | sg_flags |= SG_MITER_FROM_SG; |
| 1170 | |
| 1171 | sg_miter_start(&miter, sgl, nents, sg_flags); |
| 1172 | |
| 1173 | local_irq_save(flags); |
| 1174 | |
| 1175 | while (sg_miter_next(&miter) && offset < total_buffer) { |
| 1176 | unsigned int len; |
| 1177 | unsigned int ignore; |
| 1178 | |
| 1179 | if ((offset + miter.length) > skip) { |
| 1180 | if (offset < skip) { |
| 1181 | /* Copy part of this segment */ |
| 1182 | ignore = skip - offset; |
| 1183 | len = miter.length - ignore; |
Lee Nipper | 7260042 | 2010-07-19 14:11:24 +0800 | [diff] [blame] | 1184 | if (boffset + len > buflen) |
| 1185 | len = buflen - boffset; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1186 | memcpy(buf + boffset, miter.addr + ignore, len); |
| 1187 | } else { |
Lee Nipper | 7260042 | 2010-07-19 14:11:24 +0800 | [diff] [blame] | 1188 | /* Copy all of this segment (up to buflen) */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1189 | len = miter.length; |
Lee Nipper | 7260042 | 2010-07-19 14:11:24 +0800 | [diff] [blame] | 1190 | if (boffset + len > buflen) |
| 1191 | len = buflen - boffset; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1192 | memcpy(buf + boffset, miter.addr, len); |
| 1193 | } |
| 1194 | boffset += len; |
| 1195 | } |
| 1196 | offset += miter.length; |
| 1197 | } |
| 1198 | |
| 1199 | sg_miter_stop(&miter); |
| 1200 | |
| 1201 | local_irq_restore(flags); |
| 1202 | return boffset; |
| 1203 | } |
| 1204 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1205 | /* |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1206 | * allocate and map the extended descriptor |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1207 | */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1208 | static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, |
| 1209 | struct scatterlist *src, |
| 1210 | struct scatterlist *dst, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1211 | int hash_result, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1212 | unsigned int cryptlen, |
| 1213 | unsigned int authsize, |
| 1214 | int icv_stashing, |
| 1215 | u32 cryptoflags) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1216 | { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1217 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1218 | int src_nents, dst_nents, alloc_len, dma_len; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1219 | int src_chained, dst_chained = 0; |
| 1220 | gfp_t flags = cryptoflags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : |
Kim Phillips | 586725f | 2008-07-17 20:19:18 +0800 | [diff] [blame] | 1221 | GFP_ATOMIC; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1222 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1223 | if (cryptlen + authsize > TALITOS_MAX_DATA_LEN) { |
| 1224 | dev_err(dev, "length exceeds h/w max limit\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1225 | return ERR_PTR(-EINVAL); |
| 1226 | } |
| 1227 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1228 | src_nents = sg_count(src, cryptlen + authsize, &src_chained); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1229 | src_nents = (src_nents == 1) ? 0 : src_nents; |
| 1230 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1231 | if (hash_result) { |
| 1232 | dst_nents = 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1233 | } else { |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1234 | if (dst == src) { |
| 1235 | dst_nents = src_nents; |
| 1236 | } else { |
| 1237 | dst_nents = sg_count(dst, cryptlen + authsize, |
| 1238 | &dst_chained); |
| 1239 | dst_nents = (dst_nents == 1) ? 0 : dst_nents; |
| 1240 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | /* |
| 1244 | * allocate space for base edesc plus the link tables, |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 1245 | * allowing for two separate entries for ICV and generated ICV (+ 2), |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1246 | * and the ICV data itself |
| 1247 | */ |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1248 | alloc_len = sizeof(struct talitos_edesc); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1249 | if (src_nents || dst_nents) { |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 1250 | dma_len = (src_nents + dst_nents + 2) * |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1251 | sizeof(struct talitos_ptr) + authsize; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1252 | alloc_len += dma_len; |
| 1253 | } else { |
| 1254 | dma_len = 0; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1255 | alloc_len += icv_stashing ? authsize : 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Kim Phillips | 586725f | 2008-07-17 20:19:18 +0800 | [diff] [blame] | 1258 | edesc = kmalloc(alloc_len, GFP_DMA | flags); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1259 | if (!edesc) { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1260 | dev_err(dev, "could not allocate edescriptor\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1261 | return ERR_PTR(-ENOMEM); |
| 1262 | } |
| 1263 | |
| 1264 | edesc->src_nents = src_nents; |
| 1265 | edesc->dst_nents = dst_nents; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1266 | edesc->src_is_chained = src_chained; |
| 1267 | edesc->dst_is_chained = dst_chained; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1268 | edesc->dma_len = dma_len; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1269 | if (dma_len) |
| 1270 | edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0], |
| 1271 | edesc->dma_len, |
| 1272 | DMA_BIDIRECTIONAL); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1273 | |
| 1274 | return edesc; |
| 1275 | } |
| 1276 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1277 | static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq, |
| 1278 | int icv_stashing) |
| 1279 | { |
| 1280 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); |
| 1281 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
| 1282 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1283 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, 0, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1284 | areq->cryptlen, ctx->authsize, icv_stashing, |
| 1285 | areq->base.flags); |
| 1286 | } |
| 1287 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1288 | static int aead_encrypt(struct aead_request *req) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1289 | { |
| 1290 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
| 1291 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1292 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1293 | |
| 1294 | /* allocate extended descriptor */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1295 | edesc = aead_edesc_alloc(req, 0); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1296 | if (IS_ERR(edesc)) |
| 1297 | return PTR_ERR(edesc); |
| 1298 | |
| 1299 | /* set encrypt */ |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1300 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1301 | |
| 1302 | return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_encrypt_done); |
| 1303 | } |
| 1304 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1305 | static int aead_decrypt(struct aead_request *req) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1306 | { |
| 1307 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
| 1308 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
| 1309 | unsigned int authsize = ctx->authsize; |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1310 | struct talitos_private *priv = dev_get_drvdata(ctx->dev); |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1311 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1312 | struct scatterlist *sg; |
| 1313 | void *icvdata; |
| 1314 | |
| 1315 | req->cryptlen -= authsize; |
| 1316 | |
| 1317 | /* allocate extended descriptor */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1318 | edesc = aead_edesc_alloc(req, 1); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1319 | if (IS_ERR(edesc)) |
| 1320 | return PTR_ERR(edesc); |
| 1321 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1322 | if ((priv->features & TALITOS_FTR_HW_AUTH_CHECK) && |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1323 | ((!edesc->src_nents && !edesc->dst_nents) || |
| 1324 | priv->features & TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT)) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1325 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1326 | /* decrypt and check the ICV */ |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1327 | edesc->desc.hdr = ctx->desc_hdr_template | |
| 1328 | DESC_HDR_DIR_INBOUND | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1329 | DESC_HDR_MODE1_MDEU_CICV; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1330 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1331 | /* reset integrity check result bits */ |
| 1332 | edesc->desc.hdr_lo = 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1333 | |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1334 | return ipsec_esp(edesc, req, NULL, 0, |
| 1335 | ipsec_esp_decrypt_hwauth_done); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1336 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 1337 | } |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1338 | |
| 1339 | /* Have to check the ICV with software */ |
| 1340 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND; |
| 1341 | |
| 1342 | /* stash incoming ICV for later cmp with ICV generated by the h/w */ |
| 1343 | if (edesc->dma_len) |
| 1344 | icvdata = &edesc->link_tbl[edesc->src_nents + |
| 1345 | edesc->dst_nents + 2]; |
| 1346 | else |
| 1347 | icvdata = &edesc->link_tbl[0]; |
| 1348 | |
| 1349 | sg = sg_last(req->src, edesc->src_nents ? : 1); |
| 1350 | |
| 1351 | memcpy(icvdata, (char *)sg_virt(sg) + sg->length - ctx->authsize, |
| 1352 | ctx->authsize); |
| 1353 | |
| 1354 | return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_decrypt_swauth_done); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1355 | } |
| 1356 | |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1357 | static int aead_givencrypt(struct aead_givcrypt_request *req) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1358 | { |
| 1359 | struct aead_request *areq = &req->areq; |
| 1360 | struct crypto_aead *authenc = crypto_aead_reqtfm(areq); |
| 1361 | struct talitos_ctx *ctx = crypto_aead_ctx(authenc); |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1362 | struct talitos_edesc *edesc; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1363 | |
| 1364 | /* allocate extended descriptor */ |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1365 | edesc = aead_edesc_alloc(areq, 0); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1366 | if (IS_ERR(edesc)) |
| 1367 | return PTR_ERR(edesc); |
| 1368 | |
| 1369 | /* set encrypt */ |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 1370 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1371 | |
| 1372 | memcpy(req->giv, ctx->iv, crypto_aead_ivsize(authenc)); |
Kim Phillips | ba95487 | 2008-09-14 13:41:19 -0700 | [diff] [blame] | 1373 | /* avoid consecutive packets going out with same IV */ |
| 1374 | *(__be64 *)req->giv ^= cpu_to_be64(req->seq); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1375 | |
| 1376 | return ipsec_esp(edesc, areq, req->giv, req->seq, |
| 1377 | ipsec_esp_encrypt_done); |
| 1378 | } |
| 1379 | |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1380 | static int ablkcipher_setkey(struct crypto_ablkcipher *cipher, |
| 1381 | const u8 *key, unsigned int keylen) |
| 1382 | { |
| 1383 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1384 | |
| 1385 | memcpy(&ctx->key, key, keylen); |
| 1386 | ctx->keylen = keylen; |
| 1387 | |
| 1388 | return 0; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | static void common_nonsnoop_unmap(struct device *dev, |
| 1392 | struct talitos_edesc *edesc, |
| 1393 | struct ablkcipher_request *areq) |
| 1394 | { |
| 1395 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE); |
| 1396 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE); |
| 1397 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1], DMA_TO_DEVICE); |
| 1398 | |
| 1399 | talitos_sg_unmap(dev, edesc, areq->src, areq->dst); |
| 1400 | |
| 1401 | if (edesc->dma_len) |
| 1402 | dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, |
| 1403 | DMA_BIDIRECTIONAL); |
| 1404 | } |
| 1405 | |
| 1406 | static void ablkcipher_done(struct device *dev, |
| 1407 | struct talitos_desc *desc, void *context, |
| 1408 | int err) |
| 1409 | { |
| 1410 | struct ablkcipher_request *areq = context; |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 1411 | struct talitos_edesc *edesc; |
| 1412 | |
| 1413 | edesc = container_of(desc, struct talitos_edesc, desc); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1414 | |
| 1415 | common_nonsnoop_unmap(dev, edesc, areq); |
| 1416 | |
| 1417 | kfree(edesc); |
| 1418 | |
| 1419 | areq->base.complete(&areq->base, err); |
| 1420 | } |
| 1421 | |
| 1422 | static int common_nonsnoop(struct talitos_edesc *edesc, |
| 1423 | struct ablkcipher_request *areq, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1424 | void (*callback) (struct device *dev, |
| 1425 | struct talitos_desc *desc, |
| 1426 | void *context, int error)) |
| 1427 | { |
| 1428 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1429 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
| 1430 | struct device *dev = ctx->dev; |
| 1431 | struct talitos_desc *desc = &edesc->desc; |
| 1432 | unsigned int cryptlen = areq->nbytes; |
| 1433 | unsigned int ivsize; |
| 1434 | int sg_count, ret; |
| 1435 | |
| 1436 | /* first DWORD empty */ |
| 1437 | desc->ptr[0].len = 0; |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1438 | to_talitos_ptr(&desc->ptr[0], 0); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1439 | desc->ptr[0].j_extent = 0; |
| 1440 | |
| 1441 | /* cipher iv */ |
| 1442 | ivsize = crypto_ablkcipher_ivsize(cipher); |
Kim Phillips | febec54 | 2011-07-15 11:21:39 +0800 | [diff] [blame] | 1443 | map_single_talitos_ptr(dev, &desc->ptr[1], ivsize, areq->info, 0, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1444 | DMA_TO_DEVICE); |
| 1445 | |
| 1446 | /* cipher key */ |
| 1447 | map_single_talitos_ptr(dev, &desc->ptr[2], ctx->keylen, |
| 1448 | (char *)&ctx->key, 0, DMA_TO_DEVICE); |
| 1449 | |
| 1450 | /* |
| 1451 | * cipher in |
| 1452 | */ |
| 1453 | desc->ptr[3].len = cpu_to_be16(cryptlen); |
| 1454 | desc->ptr[3].j_extent = 0; |
| 1455 | |
| 1456 | sg_count = talitos_map_sg(dev, areq->src, edesc->src_nents ? : 1, |
| 1457 | (areq->src == areq->dst) ? DMA_BIDIRECTIONAL |
| 1458 | : DMA_TO_DEVICE, |
| 1459 | edesc->src_is_chained); |
| 1460 | |
| 1461 | if (sg_count == 1) { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1462 | to_talitos_ptr(&desc->ptr[3], sg_dma_address(areq->src)); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1463 | } else { |
| 1464 | sg_count = sg_to_link_tbl(areq->src, sg_count, cryptlen, |
| 1465 | &edesc->link_tbl[0]); |
| 1466 | if (sg_count > 1) { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1467 | to_talitos_ptr(&desc->ptr[3], edesc->dma_link_tbl); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1468 | desc->ptr[3].j_extent |= DESC_PTR_LNKTBL_JUMP; |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1469 | dma_sync_single_for_device(dev, edesc->dma_link_tbl, |
| 1470 | edesc->dma_len, |
| 1471 | DMA_BIDIRECTIONAL); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1472 | } else { |
| 1473 | /* Only one segment now, so no link tbl needed */ |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1474 | to_talitos_ptr(&desc->ptr[3], |
| 1475 | sg_dma_address(areq->src)); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | /* cipher out */ |
| 1480 | desc->ptr[4].len = cpu_to_be16(cryptlen); |
| 1481 | desc->ptr[4].j_extent = 0; |
| 1482 | |
| 1483 | if (areq->src != areq->dst) |
| 1484 | sg_count = talitos_map_sg(dev, areq->dst, |
| 1485 | edesc->dst_nents ? : 1, |
| 1486 | DMA_FROM_DEVICE, |
| 1487 | edesc->dst_is_chained); |
| 1488 | |
| 1489 | if (sg_count == 1) { |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1490 | to_talitos_ptr(&desc->ptr[4], sg_dma_address(areq->dst)); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1491 | } else { |
| 1492 | struct talitos_ptr *link_tbl_ptr = |
| 1493 | &edesc->link_tbl[edesc->src_nents + 1]; |
| 1494 | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1495 | to_talitos_ptr(&desc->ptr[4], edesc->dma_link_tbl + |
| 1496 | (edesc->src_nents + 1) * |
| 1497 | sizeof(struct talitos_ptr)); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1498 | desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP; |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1499 | sg_count = sg_to_link_tbl(areq->dst, sg_count, cryptlen, |
| 1500 | link_tbl_ptr); |
| 1501 | dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl, |
| 1502 | edesc->dma_len, DMA_BIDIRECTIONAL); |
| 1503 | } |
| 1504 | |
| 1505 | /* iv out */ |
| 1506 | map_single_talitos_ptr(dev, &desc->ptr[5], ivsize, ctx->iv, 0, |
| 1507 | DMA_FROM_DEVICE); |
| 1508 | |
| 1509 | /* last DWORD empty */ |
| 1510 | desc->ptr[6].len = 0; |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 1511 | to_talitos_ptr(&desc->ptr[6], 0); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1512 | desc->ptr[6].j_extent = 0; |
| 1513 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 1514 | ret = talitos_submit(dev, ctx->ch, desc, callback, areq); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1515 | if (ret != -EINPROGRESS) { |
| 1516 | common_nonsnoop_unmap(dev, edesc, areq); |
| 1517 | kfree(edesc); |
| 1518 | } |
| 1519 | return ret; |
| 1520 | } |
| 1521 | |
Kim Phillips | e938e46 | 2009-03-29 15:53:23 +0800 | [diff] [blame] | 1522 | static struct talitos_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request * |
| 1523 | areq) |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1524 | { |
| 1525 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1526 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
| 1527 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1528 | return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, 0, |
| 1529 | areq->nbytes, 0, 0, areq->base.flags); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | static int ablkcipher_encrypt(struct ablkcipher_request *areq) |
| 1533 | { |
| 1534 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1535 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
| 1536 | struct talitos_edesc *edesc; |
| 1537 | |
| 1538 | /* allocate extended descriptor */ |
| 1539 | edesc = ablkcipher_edesc_alloc(areq); |
| 1540 | if (IS_ERR(edesc)) |
| 1541 | return PTR_ERR(edesc); |
| 1542 | |
| 1543 | /* set encrypt */ |
| 1544 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT; |
| 1545 | |
Kim Phillips | febec54 | 2011-07-15 11:21:39 +0800 | [diff] [blame] | 1546 | return common_nonsnoop(edesc, areq, ablkcipher_done); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | static int ablkcipher_decrypt(struct ablkcipher_request *areq) |
| 1550 | { |
| 1551 | struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq); |
| 1552 | struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher); |
| 1553 | struct talitos_edesc *edesc; |
| 1554 | |
| 1555 | /* allocate extended descriptor */ |
| 1556 | edesc = ablkcipher_edesc_alloc(areq); |
| 1557 | if (IS_ERR(edesc)) |
| 1558 | return PTR_ERR(edesc); |
| 1559 | |
| 1560 | edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND; |
| 1561 | |
Kim Phillips | febec54 | 2011-07-15 11:21:39 +0800 | [diff] [blame] | 1562 | return common_nonsnoop(edesc, areq, ablkcipher_done); |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 1563 | } |
| 1564 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1565 | static void common_nonsnoop_hash_unmap(struct device *dev, |
| 1566 | struct talitos_edesc *edesc, |
| 1567 | struct ahash_request *areq) |
| 1568 | { |
| 1569 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1570 | |
| 1571 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE); |
| 1572 | |
| 1573 | /* When using hashctx-in, must unmap it. */ |
| 1574 | if (edesc->desc.ptr[1].len) |
| 1575 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1], |
| 1576 | DMA_TO_DEVICE); |
| 1577 | |
| 1578 | if (edesc->desc.ptr[2].len) |
| 1579 | unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], |
| 1580 | DMA_TO_DEVICE); |
| 1581 | |
| 1582 | talitos_sg_unmap(dev, edesc, req_ctx->psrc, NULL); |
| 1583 | |
| 1584 | if (edesc->dma_len) |
| 1585 | dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, |
| 1586 | DMA_BIDIRECTIONAL); |
| 1587 | |
| 1588 | } |
| 1589 | |
| 1590 | static void ahash_done(struct device *dev, |
| 1591 | struct talitos_desc *desc, void *context, |
| 1592 | int err) |
| 1593 | { |
| 1594 | struct ahash_request *areq = context; |
| 1595 | struct talitos_edesc *edesc = |
| 1596 | container_of(desc, struct talitos_edesc, desc); |
| 1597 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1598 | |
| 1599 | if (!req_ctx->last && req_ctx->to_hash_later) { |
| 1600 | /* Position any partial block for next update/final/finup */ |
| 1601 | memcpy(req_ctx->buf, req_ctx->bufnext, req_ctx->to_hash_later); |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1602 | req_ctx->nbuf = req_ctx->to_hash_later; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1603 | } |
| 1604 | common_nonsnoop_hash_unmap(dev, edesc, areq); |
| 1605 | |
| 1606 | kfree(edesc); |
| 1607 | |
| 1608 | areq->base.complete(&areq->base, err); |
| 1609 | } |
| 1610 | |
| 1611 | static int common_nonsnoop_hash(struct talitos_edesc *edesc, |
| 1612 | struct ahash_request *areq, unsigned int length, |
| 1613 | void (*callback) (struct device *dev, |
| 1614 | struct talitos_desc *desc, |
| 1615 | void *context, int error)) |
| 1616 | { |
| 1617 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1618 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1619 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1620 | struct device *dev = ctx->dev; |
| 1621 | struct talitos_desc *desc = &edesc->desc; |
| 1622 | int sg_count, ret; |
| 1623 | |
| 1624 | /* first DWORD empty */ |
| 1625 | desc->ptr[0] = zero_entry; |
| 1626 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1627 | /* hash context in */ |
| 1628 | if (!req_ctx->first || req_ctx->swinit) { |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1629 | map_single_talitos_ptr(dev, &desc->ptr[1], |
| 1630 | req_ctx->hw_context_size, |
| 1631 | (char *)req_ctx->hw_context, 0, |
| 1632 | DMA_TO_DEVICE); |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1633 | req_ctx->swinit = 0; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1634 | } else { |
| 1635 | desc->ptr[1] = zero_entry; |
| 1636 | /* Indicate next op is not the first. */ |
| 1637 | req_ctx->first = 0; |
| 1638 | } |
| 1639 | |
| 1640 | /* HMAC key */ |
| 1641 | if (ctx->keylen) |
| 1642 | map_single_talitos_ptr(dev, &desc->ptr[2], ctx->keylen, |
| 1643 | (char *)&ctx->key, 0, DMA_TO_DEVICE); |
| 1644 | else |
| 1645 | desc->ptr[2] = zero_entry; |
| 1646 | |
| 1647 | /* |
| 1648 | * data in |
| 1649 | */ |
| 1650 | desc->ptr[3].len = cpu_to_be16(length); |
| 1651 | desc->ptr[3].j_extent = 0; |
| 1652 | |
| 1653 | sg_count = talitos_map_sg(dev, req_ctx->psrc, |
| 1654 | edesc->src_nents ? : 1, |
| 1655 | DMA_TO_DEVICE, |
| 1656 | edesc->src_is_chained); |
| 1657 | |
| 1658 | if (sg_count == 1) { |
| 1659 | to_talitos_ptr(&desc->ptr[3], sg_dma_address(req_ctx->psrc)); |
| 1660 | } else { |
| 1661 | sg_count = sg_to_link_tbl(req_ctx->psrc, sg_count, length, |
| 1662 | &edesc->link_tbl[0]); |
| 1663 | if (sg_count > 1) { |
| 1664 | desc->ptr[3].j_extent |= DESC_PTR_LNKTBL_JUMP; |
| 1665 | to_talitos_ptr(&desc->ptr[3], edesc->dma_link_tbl); |
| 1666 | dma_sync_single_for_device(ctx->dev, |
| 1667 | edesc->dma_link_tbl, |
| 1668 | edesc->dma_len, |
| 1669 | DMA_BIDIRECTIONAL); |
| 1670 | } else { |
| 1671 | /* Only one segment now, so no link tbl needed */ |
| 1672 | to_talitos_ptr(&desc->ptr[3], |
| 1673 | sg_dma_address(req_ctx->psrc)); |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | /* fifth DWORD empty */ |
| 1678 | desc->ptr[4] = zero_entry; |
| 1679 | |
| 1680 | /* hash/HMAC out -or- hash context out */ |
| 1681 | if (req_ctx->last) |
| 1682 | map_single_talitos_ptr(dev, &desc->ptr[5], |
| 1683 | crypto_ahash_digestsize(tfm), |
| 1684 | areq->result, 0, DMA_FROM_DEVICE); |
| 1685 | else |
| 1686 | map_single_talitos_ptr(dev, &desc->ptr[5], |
| 1687 | req_ctx->hw_context_size, |
| 1688 | req_ctx->hw_context, 0, DMA_FROM_DEVICE); |
| 1689 | |
| 1690 | /* last DWORD empty */ |
| 1691 | desc->ptr[6] = zero_entry; |
| 1692 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 1693 | ret = talitos_submit(dev, ctx->ch, desc, callback, areq); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1694 | if (ret != -EINPROGRESS) { |
| 1695 | common_nonsnoop_hash_unmap(dev, edesc, areq); |
| 1696 | kfree(edesc); |
| 1697 | } |
| 1698 | return ret; |
| 1699 | } |
| 1700 | |
| 1701 | static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, |
| 1702 | unsigned int nbytes) |
| 1703 | { |
| 1704 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1705 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1706 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1707 | |
| 1708 | return talitos_edesc_alloc(ctx->dev, req_ctx->psrc, NULL, 1, |
| 1709 | nbytes, 0, 0, areq->base.flags); |
| 1710 | } |
| 1711 | |
| 1712 | static int ahash_init(struct ahash_request *areq) |
| 1713 | { |
| 1714 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1715 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1716 | |
| 1717 | /* Initialize the context */ |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1718 | req_ctx->nbuf = 0; |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1719 | req_ctx->first = 1; /* first indicates h/w must init its context */ |
| 1720 | req_ctx->swinit = 0; /* assume h/w init of context */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1721 | req_ctx->hw_context_size = |
| 1722 | (crypto_ahash_digestsize(tfm) <= SHA256_DIGEST_SIZE) |
| 1723 | ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 |
| 1724 | : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; |
| 1725 | |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1729 | /* |
| 1730 | * on h/w without explicit sha224 support, we initialize h/w context |
| 1731 | * manually with sha224 constants, and tell it to run sha256. |
| 1732 | */ |
| 1733 | static int ahash_init_sha224_swinit(struct ahash_request *areq) |
| 1734 | { |
| 1735 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1736 | |
| 1737 | ahash_init(areq); |
| 1738 | req_ctx->swinit = 1;/* prevent h/w initting context with sha256 values*/ |
| 1739 | |
Kim Phillips | a752447 | 2010-09-23 15:56:38 +0800 | [diff] [blame] | 1740 | req_ctx->hw_context[0] = SHA224_H0; |
| 1741 | req_ctx->hw_context[1] = SHA224_H1; |
| 1742 | req_ctx->hw_context[2] = SHA224_H2; |
| 1743 | req_ctx->hw_context[3] = SHA224_H3; |
| 1744 | req_ctx->hw_context[4] = SHA224_H4; |
| 1745 | req_ctx->hw_context[5] = SHA224_H5; |
| 1746 | req_ctx->hw_context[6] = SHA224_H6; |
| 1747 | req_ctx->hw_context[7] = SHA224_H7; |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1748 | |
| 1749 | /* init 64-bit count */ |
| 1750 | req_ctx->hw_context[8] = 0; |
| 1751 | req_ctx->hw_context[9] = 0; |
| 1752 | |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1756 | static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes) |
| 1757 | { |
| 1758 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); |
| 1759 | struct talitos_ctx *ctx = crypto_ahash_ctx(tfm); |
| 1760 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1761 | struct talitos_edesc *edesc; |
| 1762 | unsigned int blocksize = |
| 1763 | crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); |
| 1764 | unsigned int nbytes_to_hash; |
| 1765 | unsigned int to_hash_later; |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1766 | unsigned int nsg; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1767 | int chained; |
| 1768 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1769 | if (!req_ctx->last && (nbytes + req_ctx->nbuf <= blocksize)) { |
| 1770 | /* Buffer up to one whole block */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1771 | sg_copy_to_buffer(areq->src, |
| 1772 | sg_count(areq->src, nbytes, &chained), |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1773 | req_ctx->buf + req_ctx->nbuf, nbytes); |
| 1774 | req_ctx->nbuf += nbytes; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1775 | return 0; |
| 1776 | } |
| 1777 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1778 | /* At least (blocksize + 1) bytes are available to hash */ |
| 1779 | nbytes_to_hash = nbytes + req_ctx->nbuf; |
| 1780 | to_hash_later = nbytes_to_hash & (blocksize - 1); |
| 1781 | |
| 1782 | if (req_ctx->last) |
| 1783 | to_hash_later = 0; |
| 1784 | else if (to_hash_later) |
| 1785 | /* There is a partial block. Hash the full block(s) now */ |
| 1786 | nbytes_to_hash -= to_hash_later; |
| 1787 | else { |
| 1788 | /* Keep one block buffered */ |
| 1789 | nbytes_to_hash -= blocksize; |
| 1790 | to_hash_later = blocksize; |
| 1791 | } |
| 1792 | |
| 1793 | /* Chain in any previously buffered data */ |
| 1794 | if (req_ctx->nbuf) { |
| 1795 | nsg = (req_ctx->nbuf < nbytes_to_hash) ? 2 : 1; |
| 1796 | sg_init_table(req_ctx->bufsl, nsg); |
| 1797 | sg_set_buf(req_ctx->bufsl, req_ctx->buf, req_ctx->nbuf); |
| 1798 | if (nsg > 1) |
| 1799 | scatterwalk_sg_chain(req_ctx->bufsl, 2, areq->src); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1800 | req_ctx->psrc = req_ctx->bufsl; |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1801 | } else |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1802 | req_ctx->psrc = areq->src; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1803 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1804 | if (to_hash_later) { |
| 1805 | int nents = sg_count(areq->src, nbytes, &chained); |
| 1806 | sg_copy_end_to_buffer(areq->src, nents, |
| 1807 | req_ctx->bufnext, |
| 1808 | to_hash_later, |
| 1809 | nbytes - to_hash_later); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1810 | } |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1811 | req_ctx->to_hash_later = to_hash_later; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1812 | |
Lee Nipper | 5e833bc | 2010-06-16 15:29:15 +1000 | [diff] [blame] | 1813 | /* Allocate extended descriptor */ |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1814 | edesc = ahash_edesc_alloc(areq, nbytes_to_hash); |
| 1815 | if (IS_ERR(edesc)) |
| 1816 | return PTR_ERR(edesc); |
| 1817 | |
| 1818 | edesc->desc.hdr = ctx->desc_hdr_template; |
| 1819 | |
| 1820 | /* On last one, request SEC to pad; otherwise continue */ |
| 1821 | if (req_ctx->last) |
| 1822 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_PAD; |
| 1823 | else |
| 1824 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_CONT; |
| 1825 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1826 | /* request SEC to INIT hash. */ |
| 1827 | if (req_ctx->first && !req_ctx->swinit) |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1828 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_INIT; |
| 1829 | |
| 1830 | /* When the tfm context has a keylen, it's an HMAC. |
| 1831 | * A first or last (ie. not middle) descriptor must request HMAC. |
| 1832 | */ |
| 1833 | if (ctx->keylen && (req_ctx->first || req_ctx->last)) |
| 1834 | edesc->desc.hdr |= DESC_HDR_MODE0_MDEU_HMAC; |
| 1835 | |
| 1836 | return common_nonsnoop_hash(edesc, areq, nbytes_to_hash, |
| 1837 | ahash_done); |
| 1838 | } |
| 1839 | |
| 1840 | static int ahash_update(struct ahash_request *areq) |
| 1841 | { |
| 1842 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1843 | |
| 1844 | req_ctx->last = 0; |
| 1845 | |
| 1846 | return ahash_process_req(areq, areq->nbytes); |
| 1847 | } |
| 1848 | |
| 1849 | static int ahash_final(struct ahash_request *areq) |
| 1850 | { |
| 1851 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1852 | |
| 1853 | req_ctx->last = 1; |
| 1854 | |
| 1855 | return ahash_process_req(areq, 0); |
| 1856 | } |
| 1857 | |
| 1858 | static int ahash_finup(struct ahash_request *areq) |
| 1859 | { |
| 1860 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
| 1861 | |
| 1862 | req_ctx->last = 1; |
| 1863 | |
| 1864 | return ahash_process_req(areq, areq->nbytes); |
| 1865 | } |
| 1866 | |
| 1867 | static int ahash_digest(struct ahash_request *areq) |
| 1868 | { |
| 1869 | struct talitos_ahash_req_ctx *req_ctx = ahash_request_ctx(areq); |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1870 | struct crypto_ahash *ahash = crypto_ahash_reqtfm(areq); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1871 | |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 1872 | ahash->init(areq); |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 1873 | req_ctx->last = 1; |
| 1874 | |
| 1875 | return ahash_process_req(areq, areq->nbytes); |
| 1876 | } |
| 1877 | |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 1878 | struct keyhash_result { |
| 1879 | struct completion completion; |
| 1880 | int err; |
| 1881 | }; |
| 1882 | |
| 1883 | static void keyhash_complete(struct crypto_async_request *req, int err) |
| 1884 | { |
| 1885 | struct keyhash_result *res = req->data; |
| 1886 | |
| 1887 | if (err == -EINPROGRESS) |
| 1888 | return; |
| 1889 | |
| 1890 | res->err = err; |
| 1891 | complete(&res->completion); |
| 1892 | } |
| 1893 | |
| 1894 | static int keyhash(struct crypto_ahash *tfm, const u8 *key, unsigned int keylen, |
| 1895 | u8 *hash) |
| 1896 | { |
| 1897 | struct talitos_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
| 1898 | |
| 1899 | struct scatterlist sg[1]; |
| 1900 | struct ahash_request *req; |
| 1901 | struct keyhash_result hresult; |
| 1902 | int ret; |
| 1903 | |
| 1904 | init_completion(&hresult.completion); |
| 1905 | |
| 1906 | req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 1907 | if (!req) |
| 1908 | return -ENOMEM; |
| 1909 | |
| 1910 | /* Keep tfm keylen == 0 during hash of the long key */ |
| 1911 | ctx->keylen = 0; |
| 1912 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 1913 | keyhash_complete, &hresult); |
| 1914 | |
| 1915 | sg_init_one(&sg[0], key, keylen); |
| 1916 | |
| 1917 | ahash_request_set_crypt(req, sg, hash, keylen); |
| 1918 | ret = crypto_ahash_digest(req); |
| 1919 | switch (ret) { |
| 1920 | case 0: |
| 1921 | break; |
| 1922 | case -EINPROGRESS: |
| 1923 | case -EBUSY: |
| 1924 | ret = wait_for_completion_interruptible( |
| 1925 | &hresult.completion); |
| 1926 | if (!ret) |
| 1927 | ret = hresult.err; |
| 1928 | break; |
| 1929 | default: |
| 1930 | break; |
| 1931 | } |
| 1932 | ahash_request_free(req); |
| 1933 | |
| 1934 | return ret; |
| 1935 | } |
| 1936 | |
| 1937 | static int ahash_setkey(struct crypto_ahash *tfm, const u8 *key, |
| 1938 | unsigned int keylen) |
| 1939 | { |
| 1940 | struct talitos_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
| 1941 | unsigned int blocksize = |
| 1942 | crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); |
| 1943 | unsigned int digestsize = crypto_ahash_digestsize(tfm); |
| 1944 | unsigned int keysize = keylen; |
| 1945 | u8 hash[SHA512_DIGEST_SIZE]; |
| 1946 | int ret; |
| 1947 | |
| 1948 | if (keylen <= blocksize) |
| 1949 | memcpy(ctx->key, key, keysize); |
| 1950 | else { |
| 1951 | /* Must get the hash of the long key */ |
| 1952 | ret = keyhash(tfm, key, keylen, hash); |
| 1953 | |
| 1954 | if (ret) { |
| 1955 | crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 1956 | return -EINVAL; |
| 1957 | } |
| 1958 | |
| 1959 | keysize = digestsize; |
| 1960 | memcpy(ctx->key, hash, digestsize); |
| 1961 | } |
| 1962 | |
| 1963 | ctx->keylen = keysize; |
| 1964 | |
| 1965 | return 0; |
| 1966 | } |
| 1967 | |
| 1968 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1969 | struct talitos_alg_template { |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 1970 | u32 type; |
| 1971 | union { |
| 1972 | struct crypto_alg crypto; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 1973 | struct ahash_alg hash; |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 1974 | } alg; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1975 | __be32 desc_hdr_template; |
| 1976 | }; |
| 1977 | |
| 1978 | static struct talitos_alg_template driver_algs[] = { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1979 | /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */ |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 1980 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 1981 | .alg.crypto = { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 1982 | .cra_name = "authenc(hmac(sha1),cbc(aes))", |
| 1983 | .cra_driver_name = "authenc-hmac-sha1-cbc-aes-talitos", |
| 1984 | .cra_blocksize = AES_BLOCK_SIZE, |
| 1985 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
| 1986 | .cra_type = &crypto_aead_type, |
| 1987 | .cra_aead = { |
| 1988 | .setkey = aead_setkey, |
| 1989 | .setauthsize = aead_setauthsize, |
| 1990 | .encrypt = aead_encrypt, |
| 1991 | .decrypt = aead_decrypt, |
| 1992 | .givencrypt = aead_givencrypt, |
| 1993 | .geniv = "<built-in>", |
| 1994 | .ivsize = AES_BLOCK_SIZE, |
| 1995 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 1996 | } |
| 1997 | }, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 1998 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 1999 | DESC_HDR_SEL0_AESU | |
| 2000 | DESC_HDR_MODE0_AESU_CBC | |
| 2001 | DESC_HDR_SEL1_MDEUA | |
| 2002 | DESC_HDR_MODE1_MDEU_INIT | |
| 2003 | DESC_HDR_MODE1_MDEU_PAD | |
| 2004 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 2005 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2006 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2007 | .alg.crypto = { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2008 | .cra_name = "authenc(hmac(sha1),cbc(des3_ede))", |
| 2009 | .cra_driver_name = "authenc-hmac-sha1-cbc-3des-talitos", |
| 2010 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2011 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
| 2012 | .cra_type = &crypto_aead_type, |
| 2013 | .cra_aead = { |
| 2014 | .setkey = aead_setkey, |
| 2015 | .setauthsize = aead_setauthsize, |
| 2016 | .encrypt = aead_encrypt, |
| 2017 | .decrypt = aead_decrypt, |
| 2018 | .givencrypt = aead_givencrypt, |
| 2019 | .geniv = "<built-in>", |
| 2020 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2021 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2022 | } |
| 2023 | }, |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 2024 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2025 | DESC_HDR_SEL0_DEU | |
| 2026 | DESC_HDR_MODE0_DEU_CBC | |
| 2027 | DESC_HDR_MODE0_DEU_3DES | |
| 2028 | DESC_HDR_SEL1_MDEUA | |
| 2029 | DESC_HDR_MODE1_MDEU_INIT | |
| 2030 | DESC_HDR_MODE1_MDEU_PAD | |
| 2031 | DESC_HDR_MODE1_MDEU_SHA1_HMAC, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2032 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2033 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2034 | .alg.crypto = { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2035 | .cra_name = "authenc(hmac(sha256),cbc(aes))", |
| 2036 | .cra_driver_name = "authenc-hmac-sha256-cbc-aes-talitos", |
| 2037 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2038 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
| 2039 | .cra_type = &crypto_aead_type, |
| 2040 | .cra_aead = { |
| 2041 | .setkey = aead_setkey, |
| 2042 | .setauthsize = aead_setauthsize, |
| 2043 | .encrypt = aead_encrypt, |
| 2044 | .decrypt = aead_decrypt, |
| 2045 | .givencrypt = aead_givencrypt, |
| 2046 | .geniv = "<built-in>", |
| 2047 | .ivsize = AES_BLOCK_SIZE, |
| 2048 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2049 | } |
| 2050 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2051 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2052 | DESC_HDR_SEL0_AESU | |
| 2053 | DESC_HDR_MODE0_AESU_CBC | |
| 2054 | DESC_HDR_SEL1_MDEUA | |
| 2055 | DESC_HDR_MODE1_MDEU_INIT | |
| 2056 | DESC_HDR_MODE1_MDEU_PAD | |
| 2057 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
| 2058 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2059 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2060 | .alg.crypto = { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2061 | .cra_name = "authenc(hmac(sha256),cbc(des3_ede))", |
| 2062 | .cra_driver_name = "authenc-hmac-sha256-cbc-3des-talitos", |
| 2063 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2064 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
| 2065 | .cra_type = &crypto_aead_type, |
| 2066 | .cra_aead = { |
| 2067 | .setkey = aead_setkey, |
| 2068 | .setauthsize = aead_setauthsize, |
| 2069 | .encrypt = aead_encrypt, |
| 2070 | .decrypt = aead_decrypt, |
| 2071 | .givencrypt = aead_givencrypt, |
| 2072 | .geniv = "<built-in>", |
| 2073 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2074 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2075 | } |
| 2076 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2077 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2078 | DESC_HDR_SEL0_DEU | |
| 2079 | DESC_HDR_MODE0_DEU_CBC | |
| 2080 | DESC_HDR_MODE0_DEU_3DES | |
| 2081 | DESC_HDR_SEL1_MDEUA | |
| 2082 | DESC_HDR_MODE1_MDEU_INIT | |
| 2083 | DESC_HDR_MODE1_MDEU_PAD | |
| 2084 | DESC_HDR_MODE1_MDEU_SHA256_HMAC, |
| 2085 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2086 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2087 | .alg.crypto = { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2088 | .cra_name = "authenc(hmac(md5),cbc(aes))", |
| 2089 | .cra_driver_name = "authenc-hmac-md5-cbc-aes-talitos", |
| 2090 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2091 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
| 2092 | .cra_type = &crypto_aead_type, |
| 2093 | .cra_aead = { |
| 2094 | .setkey = aead_setkey, |
| 2095 | .setauthsize = aead_setauthsize, |
| 2096 | .encrypt = aead_encrypt, |
| 2097 | .decrypt = aead_decrypt, |
| 2098 | .givencrypt = aead_givencrypt, |
| 2099 | .geniv = "<built-in>", |
| 2100 | .ivsize = AES_BLOCK_SIZE, |
| 2101 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2102 | } |
| 2103 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2104 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2105 | DESC_HDR_SEL0_AESU | |
| 2106 | DESC_HDR_MODE0_AESU_CBC | |
| 2107 | DESC_HDR_SEL1_MDEUA | |
| 2108 | DESC_HDR_MODE1_MDEU_INIT | |
| 2109 | DESC_HDR_MODE1_MDEU_PAD | |
| 2110 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
| 2111 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2112 | { .type = CRYPTO_ALG_TYPE_AEAD, |
| 2113 | .alg.crypto = { |
Lee Nipper | 56af8cd | 2009-03-29 15:50:50 +0800 | [diff] [blame] | 2114 | .cra_name = "authenc(hmac(md5),cbc(des3_ede))", |
| 2115 | .cra_driver_name = "authenc-hmac-md5-cbc-3des-talitos", |
| 2116 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2117 | .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC, |
| 2118 | .cra_type = &crypto_aead_type, |
| 2119 | .cra_aead = { |
| 2120 | .setkey = aead_setkey, |
| 2121 | .setauthsize = aead_setauthsize, |
| 2122 | .encrypt = aead_encrypt, |
| 2123 | .decrypt = aead_decrypt, |
| 2124 | .givencrypt = aead_givencrypt, |
| 2125 | .geniv = "<built-in>", |
| 2126 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2127 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2128 | } |
| 2129 | }, |
Lee Nipper | 3952f17 | 2008-07-10 18:29:18 +0800 | [diff] [blame] | 2130 | .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | |
| 2131 | DESC_HDR_SEL0_DEU | |
| 2132 | DESC_HDR_MODE0_DEU_CBC | |
| 2133 | DESC_HDR_MODE0_DEU_3DES | |
| 2134 | DESC_HDR_SEL1_MDEUA | |
| 2135 | DESC_HDR_MODE1_MDEU_INIT | |
| 2136 | DESC_HDR_MODE1_MDEU_PAD | |
| 2137 | DESC_HDR_MODE1_MDEU_MD5_HMAC, |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2138 | }, |
| 2139 | /* ABLKCIPHER algorithms. */ |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2140 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2141 | .alg.crypto = { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2142 | .cra_name = "cbc(aes)", |
| 2143 | .cra_driver_name = "cbc-aes-talitos", |
| 2144 | .cra_blocksize = AES_BLOCK_SIZE, |
| 2145 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2146 | CRYPTO_ALG_ASYNC, |
| 2147 | .cra_type = &crypto_ablkcipher_type, |
| 2148 | .cra_ablkcipher = { |
| 2149 | .setkey = ablkcipher_setkey, |
| 2150 | .encrypt = ablkcipher_encrypt, |
| 2151 | .decrypt = ablkcipher_decrypt, |
| 2152 | .geniv = "eseqiv", |
| 2153 | .min_keysize = AES_MIN_KEY_SIZE, |
| 2154 | .max_keysize = AES_MAX_KEY_SIZE, |
| 2155 | .ivsize = AES_BLOCK_SIZE, |
| 2156 | } |
| 2157 | }, |
| 2158 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2159 | DESC_HDR_SEL0_AESU | |
| 2160 | DESC_HDR_MODE0_AESU_CBC, |
| 2161 | }, |
Lee Nipper | d5e4aae | 2010-05-19 19:18:38 +1000 | [diff] [blame] | 2162 | { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2163 | .alg.crypto = { |
Lee Nipper | 4de9d0b | 2009-03-29 15:52:32 +0800 | [diff] [blame] | 2164 | .cra_name = "cbc(des3_ede)", |
| 2165 | .cra_driver_name = "cbc-3des-talitos", |
| 2166 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 2167 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 2168 | CRYPTO_ALG_ASYNC, |
| 2169 | .cra_type = &crypto_ablkcipher_type, |
| 2170 | .cra_ablkcipher = { |
| 2171 | .setkey = ablkcipher_setkey, |
| 2172 | .encrypt = ablkcipher_encrypt, |
| 2173 | .decrypt = ablkcipher_decrypt, |
| 2174 | .geniv = "eseqiv", |
| 2175 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 2176 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 2177 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2178 | } |
| 2179 | }, |
| 2180 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2181 | DESC_HDR_SEL0_DEU | |
| 2182 | DESC_HDR_MODE0_DEU_CBC | |
| 2183 | DESC_HDR_MODE0_DEU_3DES, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2184 | }, |
| 2185 | /* AHASH algorithms. */ |
| 2186 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2187 | .alg.hash = { |
| 2188 | .init = ahash_init, |
| 2189 | .update = ahash_update, |
| 2190 | .final = ahash_final, |
| 2191 | .finup = ahash_finup, |
| 2192 | .digest = ahash_digest, |
| 2193 | .halg.digestsize = MD5_DIGEST_SIZE, |
| 2194 | .halg.base = { |
| 2195 | .cra_name = "md5", |
| 2196 | .cra_driver_name = "md5-talitos", |
| 2197 | .cra_blocksize = MD5_BLOCK_SIZE, |
| 2198 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2199 | CRYPTO_ALG_ASYNC, |
| 2200 | .cra_type = &crypto_ahash_type |
| 2201 | } |
| 2202 | }, |
| 2203 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2204 | DESC_HDR_SEL0_MDEUA | |
| 2205 | DESC_HDR_MODE0_MDEU_MD5, |
| 2206 | }, |
| 2207 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2208 | .alg.hash = { |
| 2209 | .init = ahash_init, |
| 2210 | .update = ahash_update, |
| 2211 | .final = ahash_final, |
| 2212 | .finup = ahash_finup, |
| 2213 | .digest = ahash_digest, |
| 2214 | .halg.digestsize = SHA1_DIGEST_SIZE, |
| 2215 | .halg.base = { |
| 2216 | .cra_name = "sha1", |
| 2217 | .cra_driver_name = "sha1-talitos", |
| 2218 | .cra_blocksize = SHA1_BLOCK_SIZE, |
| 2219 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2220 | CRYPTO_ALG_ASYNC, |
| 2221 | .cra_type = &crypto_ahash_type |
| 2222 | } |
| 2223 | }, |
| 2224 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2225 | DESC_HDR_SEL0_MDEUA | |
| 2226 | DESC_HDR_MODE0_MDEU_SHA1, |
| 2227 | }, |
| 2228 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2229 | .alg.hash = { |
| 2230 | .init = ahash_init, |
| 2231 | .update = ahash_update, |
| 2232 | .final = ahash_final, |
| 2233 | .finup = ahash_finup, |
| 2234 | .digest = ahash_digest, |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2235 | .halg.digestsize = SHA224_DIGEST_SIZE, |
| 2236 | .halg.base = { |
| 2237 | .cra_name = "sha224", |
| 2238 | .cra_driver_name = "sha224-talitos", |
| 2239 | .cra_blocksize = SHA224_BLOCK_SIZE, |
| 2240 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2241 | CRYPTO_ALG_ASYNC, |
| 2242 | .cra_type = &crypto_ahash_type |
| 2243 | } |
| 2244 | }, |
| 2245 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2246 | DESC_HDR_SEL0_MDEUA | |
| 2247 | DESC_HDR_MODE0_MDEU_SHA224, |
| 2248 | }, |
| 2249 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2250 | .alg.hash = { |
| 2251 | .init = ahash_init, |
| 2252 | .update = ahash_update, |
| 2253 | .final = ahash_final, |
| 2254 | .finup = ahash_finup, |
| 2255 | .digest = ahash_digest, |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2256 | .halg.digestsize = SHA256_DIGEST_SIZE, |
| 2257 | .halg.base = { |
| 2258 | .cra_name = "sha256", |
| 2259 | .cra_driver_name = "sha256-talitos", |
| 2260 | .cra_blocksize = SHA256_BLOCK_SIZE, |
| 2261 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2262 | CRYPTO_ALG_ASYNC, |
| 2263 | .cra_type = &crypto_ahash_type |
| 2264 | } |
| 2265 | }, |
| 2266 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2267 | DESC_HDR_SEL0_MDEUA | |
| 2268 | DESC_HDR_MODE0_MDEU_SHA256, |
| 2269 | }, |
| 2270 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2271 | .alg.hash = { |
| 2272 | .init = ahash_init, |
| 2273 | .update = ahash_update, |
| 2274 | .final = ahash_final, |
| 2275 | .finup = ahash_finup, |
| 2276 | .digest = ahash_digest, |
| 2277 | .halg.digestsize = SHA384_DIGEST_SIZE, |
| 2278 | .halg.base = { |
| 2279 | .cra_name = "sha384", |
| 2280 | .cra_driver_name = "sha384-talitos", |
| 2281 | .cra_blocksize = SHA384_BLOCK_SIZE, |
| 2282 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2283 | CRYPTO_ALG_ASYNC, |
| 2284 | .cra_type = &crypto_ahash_type |
| 2285 | } |
| 2286 | }, |
| 2287 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2288 | DESC_HDR_SEL0_MDEUB | |
| 2289 | DESC_HDR_MODE0_MDEUB_SHA384, |
| 2290 | }, |
| 2291 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2292 | .alg.hash = { |
| 2293 | .init = ahash_init, |
| 2294 | .update = ahash_update, |
| 2295 | .final = ahash_final, |
| 2296 | .finup = ahash_finup, |
| 2297 | .digest = ahash_digest, |
| 2298 | .halg.digestsize = SHA512_DIGEST_SIZE, |
| 2299 | .halg.base = { |
| 2300 | .cra_name = "sha512", |
| 2301 | .cra_driver_name = "sha512-talitos", |
| 2302 | .cra_blocksize = SHA512_BLOCK_SIZE, |
| 2303 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2304 | CRYPTO_ALG_ASYNC, |
| 2305 | .cra_type = &crypto_ahash_type |
| 2306 | } |
| 2307 | }, |
| 2308 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2309 | DESC_HDR_SEL0_MDEUB | |
| 2310 | DESC_HDR_MODE0_MDEUB_SHA512, |
| 2311 | }, |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2312 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2313 | .alg.hash = { |
| 2314 | .init = ahash_init, |
| 2315 | .update = ahash_update, |
| 2316 | .final = ahash_final, |
| 2317 | .finup = ahash_finup, |
| 2318 | .digest = ahash_digest, |
| 2319 | .setkey = ahash_setkey, |
| 2320 | .halg.digestsize = MD5_DIGEST_SIZE, |
| 2321 | .halg.base = { |
| 2322 | .cra_name = "hmac(md5)", |
| 2323 | .cra_driver_name = "hmac-md5-talitos", |
| 2324 | .cra_blocksize = MD5_BLOCK_SIZE, |
| 2325 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2326 | CRYPTO_ALG_ASYNC, |
| 2327 | .cra_type = &crypto_ahash_type |
| 2328 | } |
| 2329 | }, |
| 2330 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2331 | DESC_HDR_SEL0_MDEUA | |
| 2332 | DESC_HDR_MODE0_MDEU_MD5, |
| 2333 | }, |
| 2334 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2335 | .alg.hash = { |
| 2336 | .init = ahash_init, |
| 2337 | .update = ahash_update, |
| 2338 | .final = ahash_final, |
| 2339 | .finup = ahash_finup, |
| 2340 | .digest = ahash_digest, |
| 2341 | .setkey = ahash_setkey, |
| 2342 | .halg.digestsize = SHA1_DIGEST_SIZE, |
| 2343 | .halg.base = { |
| 2344 | .cra_name = "hmac(sha1)", |
| 2345 | .cra_driver_name = "hmac-sha1-talitos", |
| 2346 | .cra_blocksize = SHA1_BLOCK_SIZE, |
| 2347 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2348 | CRYPTO_ALG_ASYNC, |
| 2349 | .cra_type = &crypto_ahash_type |
| 2350 | } |
| 2351 | }, |
| 2352 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2353 | DESC_HDR_SEL0_MDEUA | |
| 2354 | DESC_HDR_MODE0_MDEU_SHA1, |
| 2355 | }, |
| 2356 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2357 | .alg.hash = { |
| 2358 | .init = ahash_init, |
| 2359 | .update = ahash_update, |
| 2360 | .final = ahash_final, |
| 2361 | .finup = ahash_finup, |
| 2362 | .digest = ahash_digest, |
| 2363 | .setkey = ahash_setkey, |
| 2364 | .halg.digestsize = SHA224_DIGEST_SIZE, |
| 2365 | .halg.base = { |
| 2366 | .cra_name = "hmac(sha224)", |
| 2367 | .cra_driver_name = "hmac-sha224-talitos", |
| 2368 | .cra_blocksize = SHA224_BLOCK_SIZE, |
| 2369 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2370 | CRYPTO_ALG_ASYNC, |
| 2371 | .cra_type = &crypto_ahash_type |
| 2372 | } |
| 2373 | }, |
| 2374 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2375 | DESC_HDR_SEL0_MDEUA | |
| 2376 | DESC_HDR_MODE0_MDEU_SHA224, |
| 2377 | }, |
| 2378 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2379 | .alg.hash = { |
| 2380 | .init = ahash_init, |
| 2381 | .update = ahash_update, |
| 2382 | .final = ahash_final, |
| 2383 | .finup = ahash_finup, |
| 2384 | .digest = ahash_digest, |
| 2385 | .setkey = ahash_setkey, |
| 2386 | .halg.digestsize = SHA256_DIGEST_SIZE, |
| 2387 | .halg.base = { |
| 2388 | .cra_name = "hmac(sha256)", |
| 2389 | .cra_driver_name = "hmac-sha256-talitos", |
| 2390 | .cra_blocksize = SHA256_BLOCK_SIZE, |
| 2391 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2392 | CRYPTO_ALG_ASYNC, |
| 2393 | .cra_type = &crypto_ahash_type |
| 2394 | } |
| 2395 | }, |
| 2396 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2397 | DESC_HDR_SEL0_MDEUA | |
| 2398 | DESC_HDR_MODE0_MDEU_SHA256, |
| 2399 | }, |
| 2400 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2401 | .alg.hash = { |
| 2402 | .init = ahash_init, |
| 2403 | .update = ahash_update, |
| 2404 | .final = ahash_final, |
| 2405 | .finup = ahash_finup, |
| 2406 | .digest = ahash_digest, |
| 2407 | .setkey = ahash_setkey, |
| 2408 | .halg.digestsize = SHA384_DIGEST_SIZE, |
| 2409 | .halg.base = { |
| 2410 | .cra_name = "hmac(sha384)", |
| 2411 | .cra_driver_name = "hmac-sha384-talitos", |
| 2412 | .cra_blocksize = SHA384_BLOCK_SIZE, |
| 2413 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2414 | CRYPTO_ALG_ASYNC, |
| 2415 | .cra_type = &crypto_ahash_type |
| 2416 | } |
| 2417 | }, |
| 2418 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2419 | DESC_HDR_SEL0_MDEUB | |
| 2420 | DESC_HDR_MODE0_MDEUB_SHA384, |
| 2421 | }, |
| 2422 | { .type = CRYPTO_ALG_TYPE_AHASH, |
| 2423 | .alg.hash = { |
| 2424 | .init = ahash_init, |
| 2425 | .update = ahash_update, |
| 2426 | .final = ahash_final, |
| 2427 | .finup = ahash_finup, |
| 2428 | .digest = ahash_digest, |
| 2429 | .setkey = ahash_setkey, |
| 2430 | .halg.digestsize = SHA512_DIGEST_SIZE, |
| 2431 | .halg.base = { |
| 2432 | .cra_name = "hmac(sha512)", |
| 2433 | .cra_driver_name = "hmac-sha512-talitos", |
| 2434 | .cra_blocksize = SHA512_BLOCK_SIZE, |
| 2435 | .cra_flags = CRYPTO_ALG_TYPE_AHASH | |
| 2436 | CRYPTO_ALG_ASYNC, |
| 2437 | .cra_type = &crypto_ahash_type |
| 2438 | } |
| 2439 | }, |
| 2440 | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2441 | DESC_HDR_SEL0_MDEUB | |
| 2442 | DESC_HDR_MODE0_MDEUB_SHA512, |
| 2443 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2444 | }; |
| 2445 | |
| 2446 | struct talitos_crypto_alg { |
| 2447 | struct list_head entry; |
| 2448 | struct device *dev; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2449 | struct talitos_alg_template algt; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2450 | }; |
| 2451 | |
| 2452 | static int talitos_cra_init(struct crypto_tfm *tfm) |
| 2453 | { |
| 2454 | struct crypto_alg *alg = tfm->__crt_alg; |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 2455 | struct talitos_crypto_alg *talitos_alg; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2456 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 2457 | struct talitos_private *priv; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2458 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2459 | if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH) |
| 2460 | talitos_alg = container_of(__crypto_ahash_alg(alg), |
| 2461 | struct talitos_crypto_alg, |
| 2462 | algt.alg.hash); |
| 2463 | else |
| 2464 | talitos_alg = container_of(alg, struct talitos_crypto_alg, |
| 2465 | algt.alg.crypto); |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 2466 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2467 | /* update context with ptr to dev */ |
| 2468 | ctx->dev = talitos_alg->dev; |
Kim Phillips | 19bbbc6 | 2009-03-29 15:53:59 +0800 | [diff] [blame] | 2469 | |
Kim Phillips | 5228f0f | 2011-07-15 11:21:38 +0800 | [diff] [blame] | 2470 | /* assign SEC channel to tfm in round-robin fashion */ |
| 2471 | priv = dev_get_drvdata(ctx->dev); |
| 2472 | ctx->ch = atomic_inc_return(&priv->last_chan) & |
| 2473 | (priv->num_channels - 1); |
| 2474 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2475 | /* copy descriptor header template value */ |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2476 | ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2477 | |
Kim Phillips | 602dba5 | 2011-07-15 11:21:39 +0800 | [diff] [blame] | 2478 | /* select done notification */ |
| 2479 | ctx->desc_hdr_template |= DESC_HDR_DONE_NOTIFY; |
| 2480 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2481 | return 0; |
| 2482 | } |
| 2483 | |
| 2484 | static int talitos_cra_init_aead(struct crypto_tfm *tfm) |
| 2485 | { |
| 2486 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
| 2487 | |
| 2488 | talitos_cra_init(tfm); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2489 | |
| 2490 | /* random first IV */ |
Lee Nipper | 70bcaca | 2008-07-03 19:08:46 +0800 | [diff] [blame] | 2491 | get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2492 | |
| 2493 | return 0; |
| 2494 | } |
| 2495 | |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2496 | static int talitos_cra_init_ahash(struct crypto_tfm *tfm) |
| 2497 | { |
| 2498 | struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); |
| 2499 | |
| 2500 | talitos_cra_init(tfm); |
| 2501 | |
| 2502 | ctx->keylen = 0; |
| 2503 | crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), |
| 2504 | sizeof(struct talitos_ahash_req_ctx)); |
| 2505 | |
| 2506 | return 0; |
| 2507 | } |
| 2508 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2509 | /* |
| 2510 | * given the alg's descriptor header template, determine whether descriptor |
| 2511 | * type and primary/secondary execution units required match the hw |
| 2512 | * capabilities description provided in the device tree node. |
| 2513 | */ |
| 2514 | static int hw_supports(struct device *dev, __be32 desc_hdr_template) |
| 2515 | { |
| 2516 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 2517 | int ret; |
| 2518 | |
| 2519 | ret = (1 << DESC_TYPE(desc_hdr_template) & priv->desc_types) && |
| 2520 | (1 << PRIMARY_EU(desc_hdr_template) & priv->exec_units); |
| 2521 | |
| 2522 | if (SECONDARY_EU(desc_hdr_template)) |
| 2523 | ret = ret && (1 << SECONDARY_EU(desc_hdr_template) |
| 2524 | & priv->exec_units); |
| 2525 | |
| 2526 | return ret; |
| 2527 | } |
| 2528 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 2529 | static int talitos_remove(struct platform_device *ofdev) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2530 | { |
| 2531 | struct device *dev = &ofdev->dev; |
| 2532 | struct talitos_private *priv = dev_get_drvdata(dev); |
| 2533 | struct talitos_crypto_alg *t_alg, *n; |
| 2534 | int i; |
| 2535 | |
| 2536 | list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) { |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2537 | switch (t_alg->algt.type) { |
| 2538 | case CRYPTO_ALG_TYPE_ABLKCIPHER: |
| 2539 | case CRYPTO_ALG_TYPE_AEAD: |
| 2540 | crypto_unregister_alg(&t_alg->algt.alg.crypto); |
| 2541 | break; |
| 2542 | case CRYPTO_ALG_TYPE_AHASH: |
| 2543 | crypto_unregister_ahash(&t_alg->algt.alg.hash); |
| 2544 | break; |
| 2545 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2546 | list_del(&t_alg->entry); |
| 2547 | kfree(t_alg); |
| 2548 | } |
| 2549 | |
| 2550 | if (hw_supports(dev, DESC_HDR_SEL0_RNG)) |
| 2551 | talitos_unregister_rng(dev); |
| 2552 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 2553 | for (i = 0; i < priv->num_channels; i++) |
Kim Phillips | 0b79824 | 2010-09-23 15:56:08 +0800 | [diff] [blame] | 2554 | kfree(priv->chan[i].fifo); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2555 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 2556 | kfree(priv->chan); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2557 | |
| 2558 | if (priv->irq != NO_IRQ) { |
| 2559 | free_irq(priv->irq, dev); |
| 2560 | irq_dispose_mapping(priv->irq); |
| 2561 | } |
| 2562 | |
| 2563 | tasklet_kill(&priv->done_task); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2564 | |
| 2565 | iounmap(priv->reg); |
| 2566 | |
| 2567 | dev_set_drvdata(dev, NULL); |
| 2568 | |
| 2569 | kfree(priv); |
| 2570 | |
| 2571 | return 0; |
| 2572 | } |
| 2573 | |
| 2574 | static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev, |
| 2575 | struct talitos_alg_template |
| 2576 | *template) |
| 2577 | { |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2578 | struct talitos_private *priv = dev_get_drvdata(dev); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2579 | struct talitos_crypto_alg *t_alg; |
| 2580 | struct crypto_alg *alg; |
| 2581 | |
| 2582 | t_alg = kzalloc(sizeof(struct talitos_crypto_alg), GFP_KERNEL); |
| 2583 | if (!t_alg) |
| 2584 | return ERR_PTR(-ENOMEM); |
| 2585 | |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2586 | t_alg->algt = *template; |
| 2587 | |
| 2588 | switch (t_alg->algt.type) { |
| 2589 | case CRYPTO_ALG_TYPE_ABLKCIPHER: |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2590 | alg = &t_alg->algt.alg.crypto; |
| 2591 | alg->cra_init = talitos_cra_init; |
| 2592 | break; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2593 | case CRYPTO_ALG_TYPE_AEAD: |
| 2594 | alg = &t_alg->algt.alg.crypto; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2595 | alg->cra_init = talitos_cra_init_aead; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2596 | break; |
| 2597 | case CRYPTO_ALG_TYPE_AHASH: |
| 2598 | alg = &t_alg->algt.alg.hash.halg.base; |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2599 | alg->cra_init = talitos_cra_init_ahash; |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2600 | if (!(priv->features & TALITOS_FTR_HMAC_OK) && |
| 2601 | !strncmp(alg->cra_name, "hmac", 4)) |
| 2602 | return ERR_PTR(-ENOTSUPP); |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2603 | if (!(priv->features & TALITOS_FTR_SHA224_HWINIT) && |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2604 | (!strcmp(alg->cra_name, "sha224") || |
| 2605 | !strcmp(alg->cra_name, "hmac(sha224)"))) { |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2606 | t_alg->algt.alg.hash.init = ahash_init_sha224_swinit; |
| 2607 | t_alg->algt.desc_hdr_template = |
| 2608 | DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | |
| 2609 | DESC_HDR_SEL0_MDEUA | |
| 2610 | DESC_HDR_MODE0_MDEU_SHA256; |
| 2611 | } |
Lee Nipper | 497f2e6 | 2010-05-19 19:20:36 +1000 | [diff] [blame] | 2612 | break; |
Kim Phillips | 1d11911 | 2010-09-23 15:55:27 +0800 | [diff] [blame] | 2613 | default: |
| 2614 | dev_err(dev, "unknown algorithm type %d\n", t_alg->algt.type); |
| 2615 | return ERR_PTR(-EINVAL); |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2616 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2617 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2618 | alg->cra_module = THIS_MODULE; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2619 | alg->cra_priority = TALITOS_CRA_PRIORITY; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2620 | alg->cra_alignmask = 0; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2621 | alg->cra_ctxsize = sizeof(struct talitos_ctx); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2622 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2623 | t_alg->dev = dev; |
| 2624 | |
| 2625 | return t_alg; |
| 2626 | } |
| 2627 | |
Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 2628 | static int talitos_probe(struct platform_device *ofdev) |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2629 | { |
| 2630 | struct device *dev = &ofdev->dev; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 2631 | struct device_node *np = ofdev->dev.of_node; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2632 | struct talitos_private *priv; |
| 2633 | const unsigned int *prop; |
| 2634 | int i, err; |
| 2635 | |
| 2636 | priv = kzalloc(sizeof(struct talitos_private), GFP_KERNEL); |
| 2637 | if (!priv) |
| 2638 | return -ENOMEM; |
| 2639 | |
| 2640 | dev_set_drvdata(dev, priv); |
| 2641 | |
| 2642 | priv->ofdev = ofdev; |
| 2643 | |
| 2644 | tasklet_init(&priv->done_task, talitos_done, (unsigned long)dev); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2645 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 2646 | INIT_LIST_HEAD(&priv->alg_list); |
| 2647 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2648 | priv->irq = irq_of_parse_and_map(np, 0); |
| 2649 | |
| 2650 | if (priv->irq == NO_IRQ) { |
| 2651 | dev_err(dev, "failed to map irq\n"); |
| 2652 | err = -EINVAL; |
| 2653 | goto err_out; |
| 2654 | } |
| 2655 | |
| 2656 | /* get the irq line */ |
| 2657 | err = request_irq(priv->irq, talitos_interrupt, 0, |
| 2658 | dev_driver_string(dev), dev); |
| 2659 | if (err) { |
| 2660 | dev_err(dev, "failed to request irq %d\n", priv->irq); |
| 2661 | irq_dispose_mapping(priv->irq); |
| 2662 | priv->irq = NO_IRQ; |
| 2663 | goto err_out; |
| 2664 | } |
| 2665 | |
| 2666 | priv->reg = of_iomap(np, 0); |
| 2667 | if (!priv->reg) { |
| 2668 | dev_err(dev, "failed to of_iomap\n"); |
| 2669 | err = -ENOMEM; |
| 2670 | goto err_out; |
| 2671 | } |
| 2672 | |
| 2673 | /* get SEC version capabilities from device tree */ |
| 2674 | prop = of_get_property(np, "fsl,num-channels", NULL); |
| 2675 | if (prop) |
| 2676 | priv->num_channels = *prop; |
| 2677 | |
| 2678 | prop = of_get_property(np, "fsl,channel-fifo-len", NULL); |
| 2679 | if (prop) |
| 2680 | priv->chfifo_len = *prop; |
| 2681 | |
| 2682 | prop = of_get_property(np, "fsl,exec-units-mask", NULL); |
| 2683 | if (prop) |
| 2684 | priv->exec_units = *prop; |
| 2685 | |
| 2686 | prop = of_get_property(np, "fsl,descriptor-types-mask", NULL); |
| 2687 | if (prop) |
| 2688 | priv->desc_types = *prop; |
| 2689 | |
| 2690 | if (!is_power_of_2(priv->num_channels) || !priv->chfifo_len || |
| 2691 | !priv->exec_units || !priv->desc_types) { |
| 2692 | dev_err(dev, "invalid property data in device tree node\n"); |
| 2693 | err = -EINVAL; |
| 2694 | goto err_out; |
| 2695 | } |
| 2696 | |
Lee Nipper | f3c85bc | 2008-07-30 16:26:57 +0800 | [diff] [blame] | 2697 | if (of_device_is_compatible(np, "fsl,sec3.0")) |
| 2698 | priv->features |= TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT; |
| 2699 | |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 2700 | if (of_device_is_compatible(np, "fsl,sec2.1")) |
Kim Phillips | 60f208d | 2010-05-19 19:21:53 +1000 | [diff] [blame] | 2701 | priv->features |= TALITOS_FTR_HW_AUTH_CHECK | |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2702 | TALITOS_FTR_SHA224_HWINIT | |
| 2703 | TALITOS_FTR_HMAC_OK; |
Kim Phillips | fe5720e | 2008-10-12 20:33:14 +0800 | [diff] [blame] | 2704 | |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 2705 | priv->chan = kzalloc(sizeof(struct talitos_channel) * |
| 2706 | priv->num_channels, GFP_KERNEL); |
| 2707 | if (!priv->chan) { |
| 2708 | dev_err(dev, "failed to allocate channel management space\n"); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2709 | err = -ENOMEM; |
| 2710 | goto err_out; |
| 2711 | } |
| 2712 | |
| 2713 | for (i = 0; i < priv->num_channels; i++) { |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 2714 | spin_lock_init(&priv->chan[i].head_lock); |
| 2715 | spin_lock_init(&priv->chan[i].tail_lock); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | priv->fifo_len = roundup_pow_of_two(priv->chfifo_len); |
| 2719 | |
| 2720 | for (i = 0; i < priv->num_channels; i++) { |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 2721 | priv->chan[i].fifo = kzalloc(sizeof(struct talitos_request) * |
| 2722 | priv->fifo_len, GFP_KERNEL); |
| 2723 | if (!priv->chan[i].fifo) { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2724 | dev_err(dev, "failed to allocate request fifo %d\n", i); |
| 2725 | err = -ENOMEM; |
| 2726 | goto err_out; |
| 2727 | } |
| 2728 | } |
| 2729 | |
Kim Phillips | ec6644d | 2008-07-17 20:16:40 +0800 | [diff] [blame] | 2730 | for (i = 0; i < priv->num_channels; i++) |
Kim Phillips | 4b992628 | 2009-08-13 11:50:38 +1000 | [diff] [blame] | 2731 | atomic_set(&priv->chan[i].submit_count, |
| 2732 | -(priv->chfifo_len - 1)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2733 | |
Kim Phillips | 81eb024 | 2009-08-13 11:51:51 +1000 | [diff] [blame] | 2734 | dma_set_mask(dev, DMA_BIT_MASK(36)); |
| 2735 | |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2736 | /* reset and initialize the h/w */ |
| 2737 | err = init_device(dev); |
| 2738 | if (err) { |
| 2739 | dev_err(dev, "failed to initialize device\n"); |
| 2740 | goto err_out; |
| 2741 | } |
| 2742 | |
| 2743 | /* register the RNG, if available */ |
| 2744 | if (hw_supports(dev, DESC_HDR_SEL0_RNG)) { |
| 2745 | err = talitos_register_rng(dev); |
| 2746 | if (err) { |
| 2747 | dev_err(dev, "failed to register hwrng: %d\n", err); |
| 2748 | goto err_out; |
| 2749 | } else |
| 2750 | dev_info(dev, "hwrng\n"); |
| 2751 | } |
| 2752 | |
| 2753 | /* register crypto algorithms the device supports */ |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2754 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
| 2755 | if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { |
| 2756 | struct talitos_crypto_alg *t_alg; |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2757 | char *name = NULL; |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2758 | |
| 2759 | t_alg = talitos_alg_alloc(dev, &driver_algs[i]); |
| 2760 | if (IS_ERR(t_alg)) { |
| 2761 | err = PTR_ERR(t_alg); |
Lee Nipper | 79b3a41 | 2011-11-21 16:13:25 +0800 | [diff] [blame] | 2762 | if (err == -ENOTSUPP) { |
| 2763 | kfree(t_alg); |
| 2764 | continue; |
| 2765 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2766 | goto err_out; |
| 2767 | } |
| 2768 | |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2769 | switch (t_alg->algt.type) { |
| 2770 | case CRYPTO_ALG_TYPE_ABLKCIPHER: |
| 2771 | case CRYPTO_ALG_TYPE_AEAD: |
| 2772 | err = crypto_register_alg( |
| 2773 | &t_alg->algt.alg.crypto); |
| 2774 | name = t_alg->algt.alg.crypto.cra_driver_name; |
| 2775 | break; |
| 2776 | case CRYPTO_ALG_TYPE_AHASH: |
| 2777 | err = crypto_register_ahash( |
| 2778 | &t_alg->algt.alg.hash); |
| 2779 | name = |
| 2780 | t_alg->algt.alg.hash.halg.base.cra_driver_name; |
| 2781 | break; |
| 2782 | } |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2783 | if (err) { |
| 2784 | dev_err(dev, "%s alg registration failed\n", |
Lee Nipper | acbf7c62 | 2010-05-19 19:19:33 +1000 | [diff] [blame] | 2785 | name); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2786 | kfree(t_alg); |
Kim Phillips | 5b859b6e | 2011-11-21 16:13:26 +0800 | [diff] [blame^] | 2787 | } else |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2788 | list_add_tail(&t_alg->entry, &priv->alg_list); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2789 | } |
| 2790 | } |
Kim Phillips | 5b859b6e | 2011-11-21 16:13:26 +0800 | [diff] [blame^] | 2791 | if (!list_empty(&priv->alg_list)) |
| 2792 | dev_info(dev, "%s algorithms registered in /proc/crypto\n", |
| 2793 | (char *)of_get_property(np, "compatible", NULL)); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2794 | |
| 2795 | return 0; |
| 2796 | |
| 2797 | err_out: |
| 2798 | talitos_remove(ofdev); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2799 | |
| 2800 | return err; |
| 2801 | } |
| 2802 | |
Márton Németh | 6c3f975 | 2010-01-17 21:54:01 +1100 | [diff] [blame] | 2803 | static const struct of_device_id talitos_match[] = { |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2804 | { |
| 2805 | .compatible = "fsl,sec2.0", |
| 2806 | }, |
| 2807 | {}, |
| 2808 | }; |
| 2809 | MODULE_DEVICE_TABLE(of, talitos_match); |
| 2810 | |
Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 2811 | static struct platform_driver talitos_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 2812 | .driver = { |
| 2813 | .name = "talitos", |
| 2814 | .owner = THIS_MODULE, |
| 2815 | .of_match_table = talitos_match, |
| 2816 | }, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2817 | .probe = talitos_probe, |
Al Viro | 596f103 | 2008-11-22 17:34:24 +0000 | [diff] [blame] | 2818 | .remove = talitos_remove, |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2819 | }; |
| 2820 | |
| 2821 | static int __init talitos_init(void) |
| 2822 | { |
Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 2823 | return platform_driver_register(&talitos_driver); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2824 | } |
| 2825 | module_init(talitos_init); |
| 2826 | |
| 2827 | static void __exit talitos_exit(void) |
| 2828 | { |
Grant Likely | 1c48a5c | 2011-02-17 02:43:24 -0700 | [diff] [blame] | 2829 | platform_driver_unregister(&talitos_driver); |
Kim Phillips | 9c4a796 | 2008-06-23 19:50:15 +0800 | [diff] [blame] | 2830 | } |
| 2831 | module_exit(talitos_exit); |
| 2832 | |
| 2833 | MODULE_LICENSE("GPL"); |
| 2834 | MODULE_AUTHOR("Kim Phillips <kim.phillips@freescale.com>"); |
| 2835 | MODULE_DESCRIPTION("Freescale integrated security engine (SEC) driver"); |