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