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