blob: c70775fd3ce2266b3b2805b8c1cb440217a55b6f [file] [log] [blame]
Kim Phillips9c4a7962008-06-23 19:50:15 +08001/*
2 * talitos - Freescale Integrated Security Engine (SEC) device driver
3 *
4 * Copyright (c) 2008 Freescale Semiconductor, Inc.
5 *
6 * Scatterlist Crypto API glue code copied from files with the following:
7 * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au>
8 *
9 * Crypto algorithm registration code copied from hifn driver:
10 * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/mod_devicetable.h>
31#include <linux/device.h>
32#include <linux/interrupt.h>
33#include <linux/crypto.h>
34#include <linux/hw_random.h>
35#include <linux/of_platform.h>
36#include <linux/dma-mapping.h>
37#include <linux/io.h>
38#include <linux/spinlock.h>
39#include <linux/rtnetlink.h>
40
41#include <crypto/algapi.h>
42#include <crypto/aes.h>
Lee Nipper3952f172008-07-10 18:29:18 +080043#include <crypto/des.h>
Kim Phillips9c4a7962008-06-23 19:50:15 +080044#include <crypto/sha.h>
45#include <crypto/aead.h>
46#include <crypto/authenc.h>
Lee Nipper4de9d0b2009-03-29 15:52:32 +080047#include <crypto/skcipher.h>
48#include <crypto/scatterwalk.h>
Kim Phillips9c4a7962008-06-23 19:50:15 +080049
50#include "talitos.h"
51
52#define TALITOS_TIMEOUT 100000
53#define TALITOS_MAX_DATA_LEN 65535
54
55#define DESC_TYPE(desc_hdr) ((be32_to_cpu(desc_hdr) >> 3) & 0x1f)
56#define PRIMARY_EU(desc_hdr) ((be32_to_cpu(desc_hdr) >> 28) & 0xf)
57#define SECONDARY_EU(desc_hdr) ((be32_to_cpu(desc_hdr) >> 16) & 0xf)
58
59/* descriptor pointer entry */
60struct talitos_ptr {
61 __be16 len; /* length */
62 u8 j_extent; /* jump to sg link table and/or extent */
63 u8 eptr; /* extended address */
64 __be32 ptr; /* address */
65};
66
67/* descriptor */
68struct talitos_desc {
69 __be32 hdr; /* header high bits */
70 __be32 hdr_lo; /* header low bits */
71 struct talitos_ptr ptr[7]; /* ptr/len pair array */
72};
73
74/**
75 * talitos_request - descriptor submission request
76 * @desc: descriptor pointer (kernel virtual)
77 * @dma_desc: descriptor's physical bus address
78 * @callback: whom to call when descriptor processing is done
79 * @context: caller context (optional)
80 */
81struct talitos_request {
82 struct talitos_desc *desc;
83 dma_addr_t dma_desc;
84 void (*callback) (struct device *dev, struct talitos_desc *desc,
85 void *context, int error);
86 void *context;
87};
88
89struct talitos_private {
90 struct device *dev;
91 struct of_device *ofdev;
92 void __iomem *reg;
93 int irq;
94
95 /* SEC version geometry (from device tree node) */
96 unsigned int num_channels;
97 unsigned int chfifo_len;
98 unsigned int exec_units;
99 unsigned int desc_types;
100
Lee Nipperf3c85bc2008-07-30 16:26:57 +0800101 /* SEC Compatibility info */
102 unsigned long features;
103
Kim Phillips9c4a7962008-06-23 19:50:15 +0800104 /* next channel to be assigned next incoming descriptor */
105 atomic_t last_chan;
106
Kim Phillipsec6644d2008-07-17 20:16:40 +0800107 /* per-channel number of requests pending in channel h/w fifo */
108 atomic_t *submit_count;
109
Kim Phillips9c4a7962008-06-23 19:50:15 +0800110 /* per-channel request fifo */
111 struct talitos_request **fifo;
112
113 /*
114 * length of the request fifo
115 * fifo_len is chfifo_len rounded up to next power of 2
116 * so we can use bitwise ops to wrap
117 */
118 unsigned int fifo_len;
119
120 /* per-channel index to next free descriptor request */
121 int *head;
122
123 /* per-channel index to next in-progress/done descriptor request */
124 int *tail;
125
126 /* per-channel request submission (head) and release (tail) locks */
127 spinlock_t *head_lock;
128 spinlock_t *tail_lock;
129
130 /* request callback tasklet */
131 struct tasklet_struct done_task;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800132
133 /* list of registered algorithms */
134 struct list_head alg_list;
135
136 /* hwrng device */
137 struct hwrng rng;
138};
139
Lee Nipperf3c85bc2008-07-30 16:26:57 +0800140/* .features flag */
141#define TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT 0x00000001
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800142#define TALITOS_FTR_HW_AUTH_CHECK 0x00000002
Lee Nipperf3c85bc2008-07-30 16:26:57 +0800143
Kim Phillips9c4a7962008-06-23 19:50:15 +0800144/*
145 * map virtual single (contiguous) pointer to h/w descriptor pointer
146 */
147static void map_single_talitos_ptr(struct device *dev,
148 struct talitos_ptr *talitos_ptr,
149 unsigned short len, void *data,
150 unsigned char extent,
151 enum dma_data_direction dir)
152{
153 talitos_ptr->len = cpu_to_be16(len);
154 talitos_ptr->ptr = cpu_to_be32(dma_map_single(dev, data, len, dir));
155 talitos_ptr->j_extent = extent;
156}
157
158/*
159 * unmap bus single (contiguous) h/w descriptor pointer
160 */
161static void unmap_single_talitos_ptr(struct device *dev,
162 struct talitos_ptr *talitos_ptr,
163 enum dma_data_direction dir)
164{
165 dma_unmap_single(dev, be32_to_cpu(talitos_ptr->ptr),
166 be16_to_cpu(talitos_ptr->len), dir);
167}
168
169static int reset_channel(struct device *dev, int ch)
170{
171 struct talitos_private *priv = dev_get_drvdata(dev);
172 unsigned int timeout = TALITOS_TIMEOUT;
173
174 setbits32(priv->reg + TALITOS_CCCR(ch), TALITOS_CCCR_RESET);
175
176 while ((in_be32(priv->reg + TALITOS_CCCR(ch)) & TALITOS_CCCR_RESET)
177 && --timeout)
178 cpu_relax();
179
180 if (timeout == 0) {
181 dev_err(dev, "failed to reset channel %d\n", ch);
182 return -EIO;
183 }
184
185 /* set done writeback and IRQ */
186 setbits32(priv->reg + TALITOS_CCCR_LO(ch), TALITOS_CCCR_LO_CDWE |
187 TALITOS_CCCR_LO_CDIE);
188
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800189 /* and ICCR writeback, if available */
190 if (priv->features & TALITOS_FTR_HW_AUTH_CHECK)
191 setbits32(priv->reg + TALITOS_CCCR_LO(ch),
192 TALITOS_CCCR_LO_IWSE);
193
Kim Phillips9c4a7962008-06-23 19:50:15 +0800194 return 0;
195}
196
197static int reset_device(struct device *dev)
198{
199 struct talitos_private *priv = dev_get_drvdata(dev);
200 unsigned int timeout = TALITOS_TIMEOUT;
201
202 setbits32(priv->reg + TALITOS_MCR, TALITOS_MCR_SWR);
203
204 while ((in_be32(priv->reg + TALITOS_MCR) & TALITOS_MCR_SWR)
205 && --timeout)
206 cpu_relax();
207
208 if (timeout == 0) {
209 dev_err(dev, "failed to reset device\n");
210 return -EIO;
211 }
212
213 return 0;
214}
215
216/*
217 * Reset and initialize the device
218 */
219static int init_device(struct device *dev)
220{
221 struct talitos_private *priv = dev_get_drvdata(dev);
222 int ch, err;
223
224 /*
225 * Master reset
226 * errata documentation: warning: certain SEC interrupts
227 * are not fully cleared by writing the MCR:SWR bit,
228 * set bit twice to completely reset
229 */
230 err = reset_device(dev);
231 if (err)
232 return err;
233
234 err = reset_device(dev);
235 if (err)
236 return err;
237
238 /* reset channels */
239 for (ch = 0; ch < priv->num_channels; ch++) {
240 err = reset_channel(dev, ch);
241 if (err)
242 return err;
243 }
244
245 /* enable channel done and error interrupts */
246 setbits32(priv->reg + TALITOS_IMR, TALITOS_IMR_INIT);
247 setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT);
248
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800249 /* disable integrity check error interrupts (use writeback instead) */
250 if (priv->features & TALITOS_FTR_HW_AUTH_CHECK)
251 setbits32(priv->reg + TALITOS_MDEUICR_LO,
252 TALITOS_MDEUICR_LO_ICE);
253
Kim Phillips9c4a7962008-06-23 19:50:15 +0800254 return 0;
255}
256
257/**
258 * talitos_submit - submits a descriptor to the device for processing
259 * @dev: the SEC device to be used
260 * @desc: the descriptor to be processed by the device
261 * @callback: whom to call when processing is complete
262 * @context: a handle for use by caller (optional)
263 *
264 * desc must contain valid dma-mapped (bus physical) address pointers.
265 * callback must check err and feedback in descriptor header
266 * for device processing status.
267 */
268static int talitos_submit(struct device *dev, struct talitos_desc *desc,
269 void (*callback)(struct device *dev,
270 struct talitos_desc *desc,
271 void *context, int error),
272 void *context)
273{
274 struct talitos_private *priv = dev_get_drvdata(dev);
275 struct talitos_request *request;
276 unsigned long flags, ch;
277 int head;
278
279 /* select done notification */
280 desc->hdr |= DESC_HDR_DONE_NOTIFY;
281
282 /* emulate SEC's round-robin channel fifo polling scheme */
283 ch = atomic_inc_return(&priv->last_chan) & (priv->num_channels - 1);
284
285 spin_lock_irqsave(&priv->head_lock[ch], flags);
286
Kim Phillipsec6644d2008-07-17 20:16:40 +0800287 if (!atomic_inc_not_zero(&priv->submit_count[ch])) {
288 /* h/w fifo is full */
Kim Phillips9c4a7962008-06-23 19:50:15 +0800289 spin_unlock_irqrestore(&priv->head_lock[ch], flags);
290 return -EAGAIN;
291 }
292
Kim Phillipsec6644d2008-07-17 20:16:40 +0800293 head = priv->head[ch];
294 request = &priv->fifo[ch][head];
295
Kim Phillips9c4a7962008-06-23 19:50:15 +0800296 /* map descriptor and save caller data */
297 request->dma_desc = dma_map_single(dev, desc, sizeof(*desc),
298 DMA_BIDIRECTIONAL);
299 request->callback = callback;
300 request->context = context;
301
302 /* increment fifo head */
303 priv->head[ch] = (priv->head[ch] + 1) & (priv->fifo_len - 1);
304
305 smp_wmb();
306 request->desc = desc;
307
308 /* GO! */
309 wmb();
310 out_be32(priv->reg + TALITOS_FF_LO(ch), request->dma_desc);
311
312 spin_unlock_irqrestore(&priv->head_lock[ch], flags);
313
314 return -EINPROGRESS;
315}
316
317/*
318 * process what was done, notify callback of error if not
319 */
320static void flush_channel(struct device *dev, int ch, int error, int reset_ch)
321{
322 struct talitos_private *priv = dev_get_drvdata(dev);
323 struct talitos_request *request, saved_req;
324 unsigned long flags;
325 int tail, status;
326
327 spin_lock_irqsave(&priv->tail_lock[ch], flags);
328
329 tail = priv->tail[ch];
330 while (priv->fifo[ch][tail].desc) {
331 request = &priv->fifo[ch][tail];
332
333 /* descriptors with their done bits set don't get the error */
334 rmb();
Lee Nipperca38a812008-12-20 17:09:25 +1100335 if ((request->desc->hdr & DESC_HDR_DONE) == DESC_HDR_DONE)
Kim Phillips9c4a7962008-06-23 19:50:15 +0800336 status = 0;
Lee Nipperca38a812008-12-20 17:09:25 +1100337 else
Kim Phillips9c4a7962008-06-23 19:50:15 +0800338 if (!error)
339 break;
340 else
341 status = error;
342
343 dma_unmap_single(dev, request->dma_desc,
Kim Phillipse938e462009-03-29 15:53:23 +0800344 sizeof(struct talitos_desc),
345 DMA_BIDIRECTIONAL);
Kim Phillips9c4a7962008-06-23 19:50:15 +0800346
347 /* copy entries so we can call callback outside lock */
348 saved_req.desc = request->desc;
349 saved_req.callback = request->callback;
350 saved_req.context = request->context;
351
352 /* release request entry in fifo */
353 smp_wmb();
354 request->desc = NULL;
355
356 /* increment fifo tail */
357 priv->tail[ch] = (tail + 1) & (priv->fifo_len - 1);
358
359 spin_unlock_irqrestore(&priv->tail_lock[ch], flags);
Kim Phillipsec6644d2008-07-17 20:16:40 +0800360
361 atomic_dec(&priv->submit_count[ch]);
362
Kim Phillips9c4a7962008-06-23 19:50:15 +0800363 saved_req.callback(dev, saved_req.desc, saved_req.context,
364 status);
365 /* channel may resume processing in single desc error case */
366 if (error && !reset_ch && status == error)
367 return;
368 spin_lock_irqsave(&priv->tail_lock[ch], flags);
369 tail = priv->tail[ch];
370 }
371
372 spin_unlock_irqrestore(&priv->tail_lock[ch], flags);
373}
374
375/*
376 * process completed requests for channels that have done status
377 */
378static void talitos_done(unsigned long data)
379{
380 struct device *dev = (struct device *)data;
381 struct talitos_private *priv = dev_get_drvdata(dev);
382 int ch;
383
384 for (ch = 0; ch < priv->num_channels; ch++)
385 flush_channel(dev, ch, 0, 0);
Lee Nipper1c2e8812008-10-12 20:29:34 +0800386
387 /* At this point, all completed channels have been processed.
388 * Unmask done interrupts for channels completed later on.
389 */
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800390 setbits32(priv->reg + TALITOS_IMR, TALITOS_IMR_INIT);
391 setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT);
Kim Phillips9c4a7962008-06-23 19:50:15 +0800392}
393
394/*
395 * locate current (offending) descriptor
396 */
397static struct talitos_desc *current_desc(struct device *dev, int ch)
398{
399 struct talitos_private *priv = dev_get_drvdata(dev);
400 int tail = priv->tail[ch];
401 dma_addr_t cur_desc;
402
403 cur_desc = in_be32(priv->reg + TALITOS_CDPR_LO(ch));
404
405 while (priv->fifo[ch][tail].dma_desc != cur_desc) {
406 tail = (tail + 1) & (priv->fifo_len - 1);
407 if (tail == priv->tail[ch]) {
408 dev_err(dev, "couldn't locate current descriptor\n");
409 return NULL;
410 }
411 }
412
413 return priv->fifo[ch][tail].desc;
414}
415
416/*
417 * user diagnostics; report root cause of error based on execution unit status
418 */
Kim Phillipse938e462009-03-29 15:53:23 +0800419static void report_eu_error(struct device *dev, int ch,
420 struct talitos_desc *desc)
Kim Phillips9c4a7962008-06-23 19:50:15 +0800421{
422 struct talitos_private *priv = dev_get_drvdata(dev);
423 int i;
424
425 switch (desc->hdr & DESC_HDR_SEL0_MASK) {
426 case DESC_HDR_SEL0_AFEU:
427 dev_err(dev, "AFEUISR 0x%08x_%08x\n",
428 in_be32(priv->reg + TALITOS_AFEUISR),
429 in_be32(priv->reg + TALITOS_AFEUISR_LO));
430 break;
431 case DESC_HDR_SEL0_DEU:
432 dev_err(dev, "DEUISR 0x%08x_%08x\n",
433 in_be32(priv->reg + TALITOS_DEUISR),
434 in_be32(priv->reg + TALITOS_DEUISR_LO));
435 break;
436 case DESC_HDR_SEL0_MDEUA:
437 case DESC_HDR_SEL0_MDEUB:
438 dev_err(dev, "MDEUISR 0x%08x_%08x\n",
439 in_be32(priv->reg + TALITOS_MDEUISR),
440 in_be32(priv->reg + TALITOS_MDEUISR_LO));
441 break;
442 case DESC_HDR_SEL0_RNG:
443 dev_err(dev, "RNGUISR 0x%08x_%08x\n",
444 in_be32(priv->reg + TALITOS_RNGUISR),
445 in_be32(priv->reg + TALITOS_RNGUISR_LO));
446 break;
447 case DESC_HDR_SEL0_PKEU:
448 dev_err(dev, "PKEUISR 0x%08x_%08x\n",
449 in_be32(priv->reg + TALITOS_PKEUISR),
450 in_be32(priv->reg + TALITOS_PKEUISR_LO));
451 break;
452 case DESC_HDR_SEL0_AESU:
453 dev_err(dev, "AESUISR 0x%08x_%08x\n",
454 in_be32(priv->reg + TALITOS_AESUISR),
455 in_be32(priv->reg + TALITOS_AESUISR_LO));
456 break;
457 case DESC_HDR_SEL0_CRCU:
458 dev_err(dev, "CRCUISR 0x%08x_%08x\n",
459 in_be32(priv->reg + TALITOS_CRCUISR),
460 in_be32(priv->reg + TALITOS_CRCUISR_LO));
461 break;
462 case DESC_HDR_SEL0_KEU:
463 dev_err(dev, "KEUISR 0x%08x_%08x\n",
464 in_be32(priv->reg + TALITOS_KEUISR),
465 in_be32(priv->reg + TALITOS_KEUISR_LO));
466 break;
467 }
468
469 switch (desc->hdr & DESC_HDR_SEL1_MASK) {
470 case DESC_HDR_SEL1_MDEUA:
471 case DESC_HDR_SEL1_MDEUB:
472 dev_err(dev, "MDEUISR 0x%08x_%08x\n",
473 in_be32(priv->reg + TALITOS_MDEUISR),
474 in_be32(priv->reg + TALITOS_MDEUISR_LO));
475 break;
476 case DESC_HDR_SEL1_CRCU:
477 dev_err(dev, "CRCUISR 0x%08x_%08x\n",
478 in_be32(priv->reg + TALITOS_CRCUISR),
479 in_be32(priv->reg + TALITOS_CRCUISR_LO));
480 break;
481 }
482
483 for (i = 0; i < 8; i++)
484 dev_err(dev, "DESCBUF 0x%08x_%08x\n",
485 in_be32(priv->reg + TALITOS_DESCBUF(ch) + 8*i),
486 in_be32(priv->reg + TALITOS_DESCBUF_LO(ch) + 8*i));
487}
488
489/*
490 * recover from error interrupts
491 */
Kim Phillips40405f12008-10-12 20:19:35 +0800492static void talitos_error(unsigned long data, u32 isr, u32 isr_lo)
Kim Phillips9c4a7962008-06-23 19:50:15 +0800493{
494 struct device *dev = (struct device *)data;
495 struct talitos_private *priv = dev_get_drvdata(dev);
496 unsigned int timeout = TALITOS_TIMEOUT;
497 int ch, error, reset_dev = 0, reset_ch = 0;
Kim Phillips40405f12008-10-12 20:19:35 +0800498 u32 v, v_lo;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800499
500 for (ch = 0; ch < priv->num_channels; ch++) {
501 /* skip channels without errors */
502 if (!(isr & (1 << (ch * 2 + 1))))
503 continue;
504
505 error = -EINVAL;
506
507 v = in_be32(priv->reg + TALITOS_CCPSR(ch));
508 v_lo = in_be32(priv->reg + TALITOS_CCPSR_LO(ch));
509
510 if (v_lo & TALITOS_CCPSR_LO_DOF) {
511 dev_err(dev, "double fetch fifo overflow error\n");
512 error = -EAGAIN;
513 reset_ch = 1;
514 }
515 if (v_lo & TALITOS_CCPSR_LO_SOF) {
516 /* h/w dropped descriptor */
517 dev_err(dev, "single fetch fifo overflow error\n");
518 error = -EAGAIN;
519 }
520 if (v_lo & TALITOS_CCPSR_LO_MDTE)
521 dev_err(dev, "master data transfer error\n");
522 if (v_lo & TALITOS_CCPSR_LO_SGDLZ)
523 dev_err(dev, "s/g data length zero error\n");
524 if (v_lo & TALITOS_CCPSR_LO_FPZ)
525 dev_err(dev, "fetch pointer zero error\n");
526 if (v_lo & TALITOS_CCPSR_LO_IDH)
527 dev_err(dev, "illegal descriptor header error\n");
528 if (v_lo & TALITOS_CCPSR_LO_IEU)
529 dev_err(dev, "invalid execution unit error\n");
530 if (v_lo & TALITOS_CCPSR_LO_EU)
531 report_eu_error(dev, ch, current_desc(dev, ch));
532 if (v_lo & TALITOS_CCPSR_LO_GB)
533 dev_err(dev, "gather boundary error\n");
534 if (v_lo & TALITOS_CCPSR_LO_GRL)
535 dev_err(dev, "gather return/length error\n");
536 if (v_lo & TALITOS_CCPSR_LO_SB)
537 dev_err(dev, "scatter boundary error\n");
538 if (v_lo & TALITOS_CCPSR_LO_SRL)
539 dev_err(dev, "scatter return/length error\n");
540
541 flush_channel(dev, ch, error, reset_ch);
542
543 if (reset_ch) {
544 reset_channel(dev, ch);
545 } else {
546 setbits32(priv->reg + TALITOS_CCCR(ch),
547 TALITOS_CCCR_CONT);
548 setbits32(priv->reg + TALITOS_CCCR_LO(ch), 0);
549 while ((in_be32(priv->reg + TALITOS_CCCR(ch)) &
550 TALITOS_CCCR_CONT) && --timeout)
551 cpu_relax();
552 if (timeout == 0) {
553 dev_err(dev, "failed to restart channel %d\n",
554 ch);
555 reset_dev = 1;
556 }
557 }
558 }
559 if (reset_dev || isr & ~TALITOS_ISR_CHERR || isr_lo) {
560 dev_err(dev, "done overflow, internal time out, or rngu error: "
561 "ISR 0x%08x_%08x\n", isr, isr_lo);
562
563 /* purge request queues */
564 for (ch = 0; ch < priv->num_channels; ch++)
565 flush_channel(dev, ch, -EIO, 1);
566
567 /* reset and reinitialize the device */
568 init_device(dev);
569 }
570}
571
572static irqreturn_t talitos_interrupt(int irq, void *data)
573{
574 struct device *dev = data;
575 struct talitos_private *priv = dev_get_drvdata(dev);
576 u32 isr, isr_lo;
577
578 isr = in_be32(priv->reg + TALITOS_ISR);
579 isr_lo = in_be32(priv->reg + TALITOS_ISR_LO);
Lee Nipperca38a812008-12-20 17:09:25 +1100580 /* Acknowledge interrupt */
581 out_be32(priv->reg + TALITOS_ICR, isr);
582 out_be32(priv->reg + TALITOS_ICR_LO, isr_lo);
Kim Phillips9c4a7962008-06-23 19:50:15 +0800583
Lee Nipperca38a812008-12-20 17:09:25 +1100584 if (unlikely((isr & ~TALITOS_ISR_CHDONE) || isr_lo))
Kim Phillips40405f12008-10-12 20:19:35 +0800585 talitos_error((unsigned long)data, isr, isr_lo);
Lee Nipperca38a812008-12-20 17:09:25 +1100586 else
Lee Nipper1c2e8812008-10-12 20:29:34 +0800587 if (likely(isr & TALITOS_ISR_CHDONE)) {
588 /* mask further done interrupts. */
589 clrbits32(priv->reg + TALITOS_IMR, TALITOS_IMR_DONE);
590 /* done_task will unmask done interrupts at exit */
Kim Phillips9c4a7962008-06-23 19:50:15 +0800591 tasklet_schedule(&priv->done_task);
Lee Nipper1c2e8812008-10-12 20:29:34 +0800592 }
Kim Phillips9c4a7962008-06-23 19:50:15 +0800593
594 return (isr || isr_lo) ? IRQ_HANDLED : IRQ_NONE;
595}
596
597/*
598 * hwrng
599 */
600static int talitos_rng_data_present(struct hwrng *rng, int wait)
601{
602 struct device *dev = (struct device *)rng->priv;
603 struct talitos_private *priv = dev_get_drvdata(dev);
604 u32 ofl;
605 int i;
606
607 for (i = 0; i < 20; i++) {
608 ofl = in_be32(priv->reg + TALITOS_RNGUSR_LO) &
609 TALITOS_RNGUSR_LO_OFL;
610 if (ofl || !wait)
611 break;
612 udelay(10);
613 }
614
615 return !!ofl;
616}
617
618static int talitos_rng_data_read(struct hwrng *rng, u32 *data)
619{
620 struct device *dev = (struct device *)rng->priv;
621 struct talitos_private *priv = dev_get_drvdata(dev);
622
623 /* rng fifo requires 64-bit accesses */
624 *data = in_be32(priv->reg + TALITOS_RNGU_FIFO);
625 *data = in_be32(priv->reg + TALITOS_RNGU_FIFO_LO);
626
627 return sizeof(u32);
628}
629
630static int talitos_rng_init(struct hwrng *rng)
631{
632 struct device *dev = (struct device *)rng->priv;
633 struct talitos_private *priv = dev_get_drvdata(dev);
634 unsigned int timeout = TALITOS_TIMEOUT;
635
636 setbits32(priv->reg + TALITOS_RNGURCR_LO, TALITOS_RNGURCR_LO_SR);
637 while (!(in_be32(priv->reg + TALITOS_RNGUSR_LO) & TALITOS_RNGUSR_LO_RD)
638 && --timeout)
639 cpu_relax();
640 if (timeout == 0) {
641 dev_err(dev, "failed to reset rng hw\n");
642 return -ENODEV;
643 }
644
645 /* start generating */
646 setbits32(priv->reg + TALITOS_RNGUDSR_LO, 0);
647
648 return 0;
649}
650
651static int talitos_register_rng(struct device *dev)
652{
653 struct talitos_private *priv = dev_get_drvdata(dev);
654
655 priv->rng.name = dev_driver_string(dev),
656 priv->rng.init = talitos_rng_init,
657 priv->rng.data_present = talitos_rng_data_present,
658 priv->rng.data_read = talitos_rng_data_read,
659 priv->rng.priv = (unsigned long)dev;
660
661 return hwrng_register(&priv->rng);
662}
663
664static void talitos_unregister_rng(struct device *dev)
665{
666 struct talitos_private *priv = dev_get_drvdata(dev);
667
668 hwrng_unregister(&priv->rng);
669}
670
671/*
672 * crypto alg
673 */
674#define TALITOS_CRA_PRIORITY 3000
675#define TALITOS_MAX_KEY_SIZE 64
Lee Nipper3952f172008-07-10 18:29:18 +0800676#define TALITOS_MAX_IV_LENGTH 16 /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
Lee Nipper70bcaca2008-07-03 19:08:46 +0800677
Lee Nipper3952f172008-07-10 18:29:18 +0800678#define MD5_DIGEST_SIZE 16
Kim Phillips9c4a7962008-06-23 19:50:15 +0800679
680struct talitos_ctx {
681 struct device *dev;
682 __be32 desc_hdr_template;
683 u8 key[TALITOS_MAX_KEY_SIZE];
Lee Nipper70bcaca2008-07-03 19:08:46 +0800684 u8 iv[TALITOS_MAX_IV_LENGTH];
Kim Phillips9c4a7962008-06-23 19:50:15 +0800685 unsigned int keylen;
686 unsigned int enckeylen;
687 unsigned int authkeylen;
688 unsigned int authsize;
689};
690
Lee Nipper56af8cd2009-03-29 15:50:50 +0800691static int aead_setauthsize(struct crypto_aead *authenc,
692 unsigned int authsize)
Kim Phillips9c4a7962008-06-23 19:50:15 +0800693{
694 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
695
696 ctx->authsize = authsize;
697
698 return 0;
699}
700
Lee Nipper56af8cd2009-03-29 15:50:50 +0800701static int aead_setkey(struct crypto_aead *authenc,
702 const u8 *key, unsigned int keylen)
Kim Phillips9c4a7962008-06-23 19:50:15 +0800703{
704 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
705 struct rtattr *rta = (void *)key;
706 struct crypto_authenc_key_param *param;
707 unsigned int authkeylen;
708 unsigned int enckeylen;
709
710 if (!RTA_OK(rta, keylen))
711 goto badkey;
712
713 if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
714 goto badkey;
715
716 if (RTA_PAYLOAD(rta) < sizeof(*param))
717 goto badkey;
718
719 param = RTA_DATA(rta);
720 enckeylen = be32_to_cpu(param->enckeylen);
721
722 key += RTA_ALIGN(rta->rta_len);
723 keylen -= RTA_ALIGN(rta->rta_len);
724
725 if (keylen < enckeylen)
726 goto badkey;
727
728 authkeylen = keylen - enckeylen;
729
730 if (keylen > TALITOS_MAX_KEY_SIZE)
731 goto badkey;
732
733 memcpy(&ctx->key, key, keylen);
734
735 ctx->keylen = keylen;
736 ctx->enckeylen = enckeylen;
737 ctx->authkeylen = authkeylen;
738
739 return 0;
740
741badkey:
742 crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
743 return -EINVAL;
744}
745
746/*
Lee Nipper56af8cd2009-03-29 15:50:50 +0800747 * talitos_edesc - s/w-extended descriptor
Kim Phillips9c4a7962008-06-23 19:50:15 +0800748 * @src_nents: number of segments in input scatterlist
749 * @dst_nents: number of segments in output scatterlist
750 * @dma_len: length of dma mapped link_tbl space
751 * @dma_link_tbl: bus physical address of link_tbl
752 * @desc: h/w descriptor
753 * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1)
754 *
755 * if decrypting (with authcheck), or either one of src_nents or dst_nents
756 * is greater than 1, an integrity check value is concatenated to the end
757 * of link_tbl data
758 */
Lee Nipper56af8cd2009-03-29 15:50:50 +0800759struct talitos_edesc {
Kim Phillips9c4a7962008-06-23 19:50:15 +0800760 int src_nents;
761 int dst_nents;
Lee Nipper4de9d0b2009-03-29 15:52:32 +0800762 int src_is_chained;
763 int dst_is_chained;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800764 int dma_len;
765 dma_addr_t dma_link_tbl;
766 struct talitos_desc desc;
767 struct talitos_ptr link_tbl[0];
768};
769
Lee Nipper4de9d0b2009-03-29 15:52:32 +0800770static int talitos_map_sg(struct device *dev, struct scatterlist *sg,
771 unsigned int nents, enum dma_data_direction dir,
772 int chained)
773{
774 if (unlikely(chained))
775 while (sg) {
776 dma_map_sg(dev, sg, 1, dir);
777 sg = scatterwalk_sg_next(sg);
778 }
779 else
780 dma_map_sg(dev, sg, nents, dir);
781 return nents;
782}
783
784static void talitos_unmap_sg_chain(struct device *dev, struct scatterlist *sg,
785 enum dma_data_direction dir)
786{
787 while (sg) {
788 dma_unmap_sg(dev, sg, 1, dir);
789 sg = scatterwalk_sg_next(sg);
790 }
791}
792
793static void talitos_sg_unmap(struct device *dev,
794 struct talitos_edesc *edesc,
795 struct scatterlist *src,
796 struct scatterlist *dst)
797{
798 unsigned int src_nents = edesc->src_nents ? : 1;
799 unsigned int dst_nents = edesc->dst_nents ? : 1;
800
801 if (src != dst) {
802 if (edesc->src_is_chained)
803 talitos_unmap_sg_chain(dev, src, DMA_TO_DEVICE);
804 else
805 dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
806
807 if (edesc->dst_is_chained)
808 talitos_unmap_sg_chain(dev, dst, DMA_FROM_DEVICE);
809 else
810 dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
811 } else
812 if (edesc->src_is_chained)
813 talitos_unmap_sg_chain(dev, src, DMA_BIDIRECTIONAL);
814 else
815 dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
816}
817
Kim Phillips9c4a7962008-06-23 19:50:15 +0800818static void ipsec_esp_unmap(struct device *dev,
Lee Nipper56af8cd2009-03-29 15:50:50 +0800819 struct talitos_edesc *edesc,
Kim Phillips9c4a7962008-06-23 19:50:15 +0800820 struct aead_request *areq)
821{
822 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[6], DMA_FROM_DEVICE);
823 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[3], DMA_TO_DEVICE);
824 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE);
825 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[0], DMA_TO_DEVICE);
826
827 dma_unmap_sg(dev, areq->assoc, 1, DMA_TO_DEVICE);
828
Lee Nipper4de9d0b2009-03-29 15:52:32 +0800829 talitos_sg_unmap(dev, edesc, areq->src, areq->dst);
Kim Phillips9c4a7962008-06-23 19:50:15 +0800830
831 if (edesc->dma_len)
832 dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
833 DMA_BIDIRECTIONAL);
834}
835
836/*
837 * ipsec_esp descriptor callbacks
838 */
839static void ipsec_esp_encrypt_done(struct device *dev,
840 struct talitos_desc *desc, void *context,
841 int err)
842{
843 struct aead_request *areq = context;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800844 struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
845 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
Kim Phillips19bbbc62009-03-29 15:53:59 +0800846 struct talitos_edesc *edesc;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800847 struct scatterlist *sg;
848 void *icvdata;
849
Kim Phillips19bbbc62009-03-29 15:53:59 +0800850 edesc = container_of(desc, struct talitos_edesc, desc);
851
Kim Phillips9c4a7962008-06-23 19:50:15 +0800852 ipsec_esp_unmap(dev, edesc, areq);
853
854 /* copy the generated ICV to dst */
855 if (edesc->dma_len) {
856 icvdata = &edesc->link_tbl[edesc->src_nents +
Lee Nipperf3c85bc2008-07-30 16:26:57 +0800857 edesc->dst_nents + 2];
Kim Phillips9c4a7962008-06-23 19:50:15 +0800858 sg = sg_last(areq->dst, edesc->dst_nents);
859 memcpy((char *)sg_virt(sg) + sg->length - ctx->authsize,
860 icvdata, ctx->authsize);
861 }
862
863 kfree(edesc);
864
865 aead_request_complete(areq, err);
866}
867
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800868static void ipsec_esp_decrypt_swauth_done(struct device *dev,
Kim Phillipse938e462009-03-29 15:53:23 +0800869 struct talitos_desc *desc,
870 void *context, int err)
Kim Phillips9c4a7962008-06-23 19:50:15 +0800871{
872 struct aead_request *req = context;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800873 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
874 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
Kim Phillips19bbbc62009-03-29 15:53:59 +0800875 struct talitos_edesc *edesc;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800876 struct scatterlist *sg;
877 void *icvdata;
878
Kim Phillips19bbbc62009-03-29 15:53:59 +0800879 edesc = container_of(desc, struct talitos_edesc, desc);
880
Kim Phillips9c4a7962008-06-23 19:50:15 +0800881 ipsec_esp_unmap(dev, edesc, req);
882
883 if (!err) {
884 /* auth check */
885 if (edesc->dma_len)
886 icvdata = &edesc->link_tbl[edesc->src_nents +
Lee Nipperf3c85bc2008-07-30 16:26:57 +0800887 edesc->dst_nents + 2];
Kim Phillips9c4a7962008-06-23 19:50:15 +0800888 else
889 icvdata = &edesc->link_tbl[0];
890
891 sg = sg_last(req->dst, edesc->dst_nents ? : 1);
892 err = memcmp(icvdata, (char *)sg_virt(sg) + sg->length -
893 ctx->authsize, ctx->authsize) ? -EBADMSG : 0;
894 }
895
896 kfree(edesc);
897
898 aead_request_complete(req, err);
899}
900
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800901static void ipsec_esp_decrypt_hwauth_done(struct device *dev,
Kim Phillipse938e462009-03-29 15:53:23 +0800902 struct talitos_desc *desc,
903 void *context, int err)
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800904{
905 struct aead_request *req = context;
Kim Phillips19bbbc62009-03-29 15:53:59 +0800906 struct talitos_edesc *edesc;
907
908 edesc = container_of(desc, struct talitos_edesc, desc);
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800909
910 ipsec_esp_unmap(dev, edesc, req);
911
912 /* check ICV auth status */
Kim Phillipse938e462009-03-29 15:53:23 +0800913 if (!err && ((desc->hdr_lo & DESC_HDR_LO_ICCR1_MASK) !=
914 DESC_HDR_LO_ICCR1_PASS))
915 err = -EBADMSG;
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800916
917 kfree(edesc);
918
919 aead_request_complete(req, err);
920}
921
Kim Phillips9c4a7962008-06-23 19:50:15 +0800922/*
923 * convert scatterlist to SEC h/w link table format
924 * stop at cryptlen bytes
925 */
Lee Nipper70bcaca2008-07-03 19:08:46 +0800926static int sg_to_link_tbl(struct scatterlist *sg, int sg_count,
Kim Phillips9c4a7962008-06-23 19:50:15 +0800927 int cryptlen, struct talitos_ptr *link_tbl_ptr)
928{
Lee Nipper70bcaca2008-07-03 19:08:46 +0800929 int n_sg = sg_count;
930
931 while (n_sg--) {
Kim Phillips9c4a7962008-06-23 19:50:15 +0800932 link_tbl_ptr->ptr = cpu_to_be32(sg_dma_address(sg));
933 link_tbl_ptr->len = cpu_to_be16(sg_dma_len(sg));
934 link_tbl_ptr->j_extent = 0;
935 link_tbl_ptr++;
936 cryptlen -= sg_dma_len(sg);
Lee Nipper4de9d0b2009-03-29 15:52:32 +0800937 sg = scatterwalk_sg_next(sg);
Kim Phillips9c4a7962008-06-23 19:50:15 +0800938 }
939
Lee Nipper70bcaca2008-07-03 19:08:46 +0800940 /* adjust (decrease) last one (or two) entry's len to cryptlen */
Kim Phillips9c4a7962008-06-23 19:50:15 +0800941 link_tbl_ptr--;
Kim Phillipsc0e741d2008-07-17 20:20:59 +0800942 while (be16_to_cpu(link_tbl_ptr->len) <= (-cryptlen)) {
Lee Nipper70bcaca2008-07-03 19:08:46 +0800943 /* Empty this entry, and move to previous one */
944 cryptlen += be16_to_cpu(link_tbl_ptr->len);
945 link_tbl_ptr->len = 0;
946 sg_count--;
947 link_tbl_ptr--;
948 }
Kim Phillips9c4a7962008-06-23 19:50:15 +0800949 link_tbl_ptr->len = cpu_to_be16(be16_to_cpu(link_tbl_ptr->len)
950 + cryptlen);
951
952 /* tag end of link table */
953 link_tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN;
Lee Nipper70bcaca2008-07-03 19:08:46 +0800954
955 return sg_count;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800956}
957
958/*
959 * fill in and submit ipsec_esp descriptor
960 */
Lee Nipper56af8cd2009-03-29 15:50:50 +0800961static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
Kim Phillips9c4a7962008-06-23 19:50:15 +0800962 u8 *giv, u64 seq,
963 void (*callback) (struct device *dev,
964 struct talitos_desc *desc,
965 void *context, int error))
966{
967 struct crypto_aead *aead = crypto_aead_reqtfm(areq);
968 struct talitos_ctx *ctx = crypto_aead_ctx(aead);
969 struct device *dev = ctx->dev;
970 struct talitos_desc *desc = &edesc->desc;
971 unsigned int cryptlen = areq->cryptlen;
972 unsigned int authsize = ctx->authsize;
973 unsigned int ivsize;
Kim Phillipsfa86a262008-07-17 20:20:06 +0800974 int sg_count, ret;
Kim Phillipsfe5720e2008-10-12 20:33:14 +0800975 int sg_link_tbl_len;
Kim Phillips9c4a7962008-06-23 19:50:15 +0800976
977 /* hmac key */
978 map_single_talitos_ptr(dev, &desc->ptr[0], ctx->authkeylen, &ctx->key,
979 0, DMA_TO_DEVICE);
980 /* hmac data */
981 map_single_talitos_ptr(dev, &desc->ptr[1], sg_virt(areq->src) -
982 sg_virt(areq->assoc), sg_virt(areq->assoc), 0,
983 DMA_TO_DEVICE);
984 /* cipher iv */
985 ivsize = crypto_aead_ivsize(aead);
986 map_single_talitos_ptr(dev, &desc->ptr[2], ivsize, giv ?: areq->iv, 0,
987 DMA_TO_DEVICE);
988
989 /* cipher key */
990 map_single_talitos_ptr(dev, &desc->ptr[3], ctx->enckeylen,
991 (char *)&ctx->key + ctx->authkeylen, 0,
992 DMA_TO_DEVICE);
993
994 /*
995 * cipher in
996 * map and adjust cipher len to aead request cryptlen.
997 * extent is bytes of HMAC postpended to ciphertext,
998 * typically 12 for ipsec
999 */
1000 desc->ptr[4].len = cpu_to_be16(cryptlen);
1001 desc->ptr[4].j_extent = authsize;
1002
Kim Phillipse938e462009-03-29 15:53:23 +08001003 sg_count = talitos_map_sg(dev, areq->src, edesc->src_nents ? : 1,
1004 (areq->src == areq->dst) ? DMA_BIDIRECTIONAL
1005 : DMA_TO_DEVICE,
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001006 edesc->src_is_chained);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001007
1008 if (sg_count == 1) {
1009 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->src));
1010 } else {
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001011 sg_link_tbl_len = cryptlen;
1012
Kim Phillips962a9c92009-03-29 15:54:30 +08001013 if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV)
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001014 sg_link_tbl_len = cryptlen + authsize;
Kim Phillipse938e462009-03-29 15:53:23 +08001015
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001016 sg_count = sg_to_link_tbl(areq->src, sg_count, sg_link_tbl_len,
Lee Nipper70bcaca2008-07-03 19:08:46 +08001017 &edesc->link_tbl[0]);
1018 if (sg_count > 1) {
1019 desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP;
1020 desc->ptr[4].ptr = cpu_to_be32(edesc->dma_link_tbl);
Kim Phillipse938e462009-03-29 15:53:23 +08001021 dma_sync_single_for_device(dev, edesc->dma_link_tbl,
1022 edesc->dma_len,
1023 DMA_BIDIRECTIONAL);
Lee Nipper70bcaca2008-07-03 19:08:46 +08001024 } else {
1025 /* Only one segment now, so no link tbl needed */
Kim Phillipse938e462009-03-29 15:53:23 +08001026 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->
1027 src));
Lee Nipper70bcaca2008-07-03 19:08:46 +08001028 }
Kim Phillips9c4a7962008-06-23 19:50:15 +08001029 }
1030
1031 /* cipher out */
1032 desc->ptr[5].len = cpu_to_be16(cryptlen);
1033 desc->ptr[5].j_extent = authsize;
1034
Kim Phillipse938e462009-03-29 15:53:23 +08001035 if (areq->src != areq->dst)
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001036 sg_count = talitos_map_sg(dev, areq->dst,
1037 edesc->dst_nents ? : 1,
1038 DMA_FROM_DEVICE,
1039 edesc->dst_is_chained);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001040
1041 if (sg_count == 1) {
1042 desc->ptr[5].ptr = cpu_to_be32(sg_dma_address(areq->dst));
1043 } else {
1044 struct talitos_ptr *link_tbl_ptr =
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001045 &edesc->link_tbl[edesc->src_nents + 1];
Kim Phillips9c4a7962008-06-23 19:50:15 +08001046
1047 desc->ptr[5].ptr = cpu_to_be32((struct talitos_ptr *)
1048 edesc->dma_link_tbl +
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001049 edesc->src_nents + 1);
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001050 sg_count = sg_to_link_tbl(areq->dst, sg_count, cryptlen,
1051 link_tbl_ptr);
1052
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001053 /* Add an entry to the link table for ICV data */
Kim Phillips9c4a7962008-06-23 19:50:15 +08001054 link_tbl_ptr += sg_count - 1;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001055 link_tbl_ptr->j_extent = 0;
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001056 sg_count++;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001057 link_tbl_ptr++;
1058 link_tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN;
1059 link_tbl_ptr->len = cpu_to_be16(authsize);
1060
1061 /* icv data follows link tables */
1062 link_tbl_ptr->ptr = cpu_to_be32((struct talitos_ptr *)
1063 edesc->dma_link_tbl +
1064 edesc->src_nents +
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001065 edesc->dst_nents + 2);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001066
1067 desc->ptr[5].j_extent |= DESC_PTR_LNKTBL_JUMP;
1068 dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl,
1069 edesc->dma_len, DMA_BIDIRECTIONAL);
1070 }
1071
1072 /* iv out */
1073 map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, 0,
1074 DMA_FROM_DEVICE);
1075
Kim Phillipsfa86a262008-07-17 20:20:06 +08001076 ret = talitos_submit(dev, desc, callback, areq);
1077 if (ret != -EINPROGRESS) {
1078 ipsec_esp_unmap(dev, edesc, areq);
1079 kfree(edesc);
1080 }
1081 return ret;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001082}
1083
Kim Phillips9c4a7962008-06-23 19:50:15 +08001084/*
1085 * derive number of elements in scatterlist
1086 */
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001087static int sg_count(struct scatterlist *sg_list, int nbytes, int *chained)
Kim Phillips9c4a7962008-06-23 19:50:15 +08001088{
1089 struct scatterlist *sg = sg_list;
1090 int sg_nents = 0;
1091
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001092 *chained = 0;
1093 while (nbytes > 0) {
Kim Phillips9c4a7962008-06-23 19:50:15 +08001094 sg_nents++;
1095 nbytes -= sg->length;
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001096 if (!sg_is_last(sg) && (sg + 1)->length == 0)
1097 *chained = 1;
1098 sg = scatterwalk_sg_next(sg);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001099 }
1100
1101 return sg_nents;
1102}
1103
1104/*
Lee Nipper56af8cd2009-03-29 15:50:50 +08001105 * allocate and map the extended descriptor
Kim Phillips9c4a7962008-06-23 19:50:15 +08001106 */
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001107static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
1108 struct scatterlist *src,
1109 struct scatterlist *dst,
1110 unsigned int cryptlen,
1111 unsigned int authsize,
1112 int icv_stashing,
1113 u32 cryptoflags)
Kim Phillips9c4a7962008-06-23 19:50:15 +08001114{
Lee Nipper56af8cd2009-03-29 15:50:50 +08001115 struct talitos_edesc *edesc;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001116 int src_nents, dst_nents, alloc_len, dma_len;
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001117 int src_chained, dst_chained = 0;
1118 gfp_t flags = cryptoflags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
Kim Phillips586725f2008-07-17 20:19:18 +08001119 GFP_ATOMIC;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001120
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001121 if (cryptlen + authsize > TALITOS_MAX_DATA_LEN) {
1122 dev_err(dev, "length exceeds h/w max limit\n");
Kim Phillips9c4a7962008-06-23 19:50:15 +08001123 return ERR_PTR(-EINVAL);
1124 }
1125
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001126 src_nents = sg_count(src, cryptlen + authsize, &src_chained);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001127 src_nents = (src_nents == 1) ? 0 : src_nents;
1128
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001129 if (dst == src) {
Kim Phillips9c4a7962008-06-23 19:50:15 +08001130 dst_nents = src_nents;
1131 } else {
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001132 dst_nents = sg_count(dst, cryptlen + authsize, &dst_chained);
Lee Nipper695ad582008-07-17 16:22:30 +08001133 dst_nents = (dst_nents == 1) ? 0 : dst_nents;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001134 }
1135
1136 /*
1137 * allocate space for base edesc plus the link tables,
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001138 * allowing for two separate entries for ICV and generated ICV (+ 2),
Kim Phillips9c4a7962008-06-23 19:50:15 +08001139 * and the ICV data itself
1140 */
Lee Nipper56af8cd2009-03-29 15:50:50 +08001141 alloc_len = sizeof(struct talitos_edesc);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001142 if (src_nents || dst_nents) {
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001143 dma_len = (src_nents + dst_nents + 2) *
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001144 sizeof(struct talitos_ptr) + authsize;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001145 alloc_len += dma_len;
1146 } else {
1147 dma_len = 0;
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001148 alloc_len += icv_stashing ? authsize : 0;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001149 }
1150
Kim Phillips586725f2008-07-17 20:19:18 +08001151 edesc = kmalloc(alloc_len, GFP_DMA | flags);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001152 if (!edesc) {
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001153 dev_err(dev, "could not allocate edescriptor\n");
Kim Phillips9c4a7962008-06-23 19:50:15 +08001154 return ERR_PTR(-ENOMEM);
1155 }
1156
1157 edesc->src_nents = src_nents;
1158 edesc->dst_nents = dst_nents;
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001159 edesc->src_is_chained = src_chained;
1160 edesc->dst_is_chained = dst_chained;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001161 edesc->dma_len = dma_len;
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001162 edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0],
Kim Phillips9c4a7962008-06-23 19:50:15 +08001163 edesc->dma_len, DMA_BIDIRECTIONAL);
1164
1165 return edesc;
1166}
1167
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001168static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq,
1169 int icv_stashing)
1170{
1171 struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
1172 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1173
1174 return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst,
1175 areq->cryptlen, ctx->authsize, icv_stashing,
1176 areq->base.flags);
1177}
1178
Lee Nipper56af8cd2009-03-29 15:50:50 +08001179static int aead_encrypt(struct aead_request *req)
Kim Phillips9c4a7962008-06-23 19:50:15 +08001180{
1181 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
1182 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
Lee Nipper56af8cd2009-03-29 15:50:50 +08001183 struct talitos_edesc *edesc;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001184
1185 /* allocate extended descriptor */
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001186 edesc = aead_edesc_alloc(req, 0);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001187 if (IS_ERR(edesc))
1188 return PTR_ERR(edesc);
1189
1190 /* set encrypt */
Lee Nipper70bcaca2008-07-03 19:08:46 +08001191 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001192
1193 return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_encrypt_done);
1194}
1195
Lee Nipper56af8cd2009-03-29 15:50:50 +08001196static int aead_decrypt(struct aead_request *req)
Kim Phillips9c4a7962008-06-23 19:50:15 +08001197{
1198 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
1199 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1200 unsigned int authsize = ctx->authsize;
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001201 struct talitos_private *priv = dev_get_drvdata(ctx->dev);
Lee Nipper56af8cd2009-03-29 15:50:50 +08001202 struct talitos_edesc *edesc;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001203 struct scatterlist *sg;
1204 void *icvdata;
1205
1206 req->cryptlen -= authsize;
1207
1208 /* allocate extended descriptor */
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001209 edesc = aead_edesc_alloc(req, 1);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001210 if (IS_ERR(edesc))
1211 return PTR_ERR(edesc);
1212
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001213 if ((priv->features & TALITOS_FTR_HW_AUTH_CHECK) &&
Kim Phillipse938e462009-03-29 15:53:23 +08001214 ((!edesc->src_nents && !edesc->dst_nents) ||
1215 priv->features & TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT)) {
Kim Phillips9c4a7962008-06-23 19:50:15 +08001216
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001217 /* decrypt and check the ICV */
Kim Phillipse938e462009-03-29 15:53:23 +08001218 edesc->desc.hdr = ctx->desc_hdr_template |
1219 DESC_HDR_DIR_INBOUND |
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001220 DESC_HDR_MODE1_MDEU_CICV;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001221
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001222 /* reset integrity check result bits */
1223 edesc->desc.hdr_lo = 0;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001224
Kim Phillipse938e462009-03-29 15:53:23 +08001225 return ipsec_esp(edesc, req, NULL, 0,
1226 ipsec_esp_decrypt_hwauth_done);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001227
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001228 }
Kim Phillipse938e462009-03-29 15:53:23 +08001229
1230 /* Have to check the ICV with software */
1231 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND;
1232
1233 /* stash incoming ICV for later cmp with ICV generated by the h/w */
1234 if (edesc->dma_len)
1235 icvdata = &edesc->link_tbl[edesc->src_nents +
1236 edesc->dst_nents + 2];
1237 else
1238 icvdata = &edesc->link_tbl[0];
1239
1240 sg = sg_last(req->src, edesc->src_nents ? : 1);
1241
1242 memcpy(icvdata, (char *)sg_virt(sg) + sg->length - ctx->authsize,
1243 ctx->authsize);
1244
1245 return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_decrypt_swauth_done);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001246}
1247
Lee Nipper56af8cd2009-03-29 15:50:50 +08001248static int aead_givencrypt(struct aead_givcrypt_request *req)
Kim Phillips9c4a7962008-06-23 19:50:15 +08001249{
1250 struct aead_request *areq = &req->areq;
1251 struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
1252 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
Lee Nipper56af8cd2009-03-29 15:50:50 +08001253 struct talitos_edesc *edesc;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001254
1255 /* allocate extended descriptor */
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001256 edesc = aead_edesc_alloc(areq, 0);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001257 if (IS_ERR(edesc))
1258 return PTR_ERR(edesc);
1259
1260 /* set encrypt */
Lee Nipper70bcaca2008-07-03 19:08:46 +08001261 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001262
1263 memcpy(req->giv, ctx->iv, crypto_aead_ivsize(authenc));
Kim Phillipsba954872008-09-14 13:41:19 -07001264 /* avoid consecutive packets going out with same IV */
1265 *(__be64 *)req->giv ^= cpu_to_be64(req->seq);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001266
1267 return ipsec_esp(edesc, areq, req->giv, req->seq,
1268 ipsec_esp_encrypt_done);
1269}
1270
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001271static int ablkcipher_setkey(struct crypto_ablkcipher *cipher,
1272 const u8 *key, unsigned int keylen)
1273{
1274 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1275 struct ablkcipher_alg *alg = crypto_ablkcipher_alg(cipher);
1276
1277 if (keylen > TALITOS_MAX_KEY_SIZE)
1278 goto badkey;
1279
1280 if (keylen < alg->min_keysize || keylen > alg->max_keysize)
1281 goto badkey;
1282
1283 memcpy(&ctx->key, key, keylen);
1284 ctx->keylen = keylen;
1285
1286 return 0;
1287
1288badkey:
1289 crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
1290 return -EINVAL;
1291}
1292
1293static void common_nonsnoop_unmap(struct device *dev,
1294 struct talitos_edesc *edesc,
1295 struct ablkcipher_request *areq)
1296{
1297 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE);
1298 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE);
1299 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1], DMA_TO_DEVICE);
1300
1301 talitos_sg_unmap(dev, edesc, areq->src, areq->dst);
1302
1303 if (edesc->dma_len)
1304 dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
1305 DMA_BIDIRECTIONAL);
1306}
1307
1308static void ablkcipher_done(struct device *dev,
1309 struct talitos_desc *desc, void *context,
1310 int err)
1311{
1312 struct ablkcipher_request *areq = context;
Kim Phillips19bbbc62009-03-29 15:53:59 +08001313 struct talitos_edesc *edesc;
1314
1315 edesc = container_of(desc, struct talitos_edesc, desc);
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001316
1317 common_nonsnoop_unmap(dev, edesc, areq);
1318
1319 kfree(edesc);
1320
1321 areq->base.complete(&areq->base, err);
1322}
1323
1324static int common_nonsnoop(struct talitos_edesc *edesc,
1325 struct ablkcipher_request *areq,
1326 u8 *giv,
1327 void (*callback) (struct device *dev,
1328 struct talitos_desc *desc,
1329 void *context, int error))
1330{
1331 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1332 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1333 struct device *dev = ctx->dev;
1334 struct talitos_desc *desc = &edesc->desc;
1335 unsigned int cryptlen = areq->nbytes;
1336 unsigned int ivsize;
1337 int sg_count, ret;
1338
1339 /* first DWORD empty */
1340 desc->ptr[0].len = 0;
1341 desc->ptr[0].ptr = 0;
1342 desc->ptr[0].j_extent = 0;
1343
1344 /* cipher iv */
1345 ivsize = crypto_ablkcipher_ivsize(cipher);
1346 map_single_talitos_ptr(dev, &desc->ptr[1], ivsize, giv ?: areq->info, 0,
1347 DMA_TO_DEVICE);
1348
1349 /* cipher key */
1350 map_single_talitos_ptr(dev, &desc->ptr[2], ctx->keylen,
1351 (char *)&ctx->key, 0, DMA_TO_DEVICE);
1352
1353 /*
1354 * cipher in
1355 */
1356 desc->ptr[3].len = cpu_to_be16(cryptlen);
1357 desc->ptr[3].j_extent = 0;
1358
1359 sg_count = talitos_map_sg(dev, areq->src, edesc->src_nents ? : 1,
1360 (areq->src == areq->dst) ? DMA_BIDIRECTIONAL
1361 : DMA_TO_DEVICE,
1362 edesc->src_is_chained);
1363
1364 if (sg_count == 1) {
1365 desc->ptr[3].ptr = cpu_to_be32(sg_dma_address(areq->src));
1366 } else {
1367 sg_count = sg_to_link_tbl(areq->src, sg_count, cryptlen,
1368 &edesc->link_tbl[0]);
1369 if (sg_count > 1) {
1370 desc->ptr[3].j_extent |= DESC_PTR_LNKTBL_JUMP;
1371 desc->ptr[3].ptr = cpu_to_be32(edesc->dma_link_tbl);
Kim Phillipse938e462009-03-29 15:53:23 +08001372 dma_sync_single_for_device(dev, edesc->dma_link_tbl,
1373 edesc->dma_len,
1374 DMA_BIDIRECTIONAL);
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001375 } else {
1376 /* Only one segment now, so no link tbl needed */
Kim Phillipse938e462009-03-29 15:53:23 +08001377 desc->ptr[3].ptr = cpu_to_be32(sg_dma_address(areq->
1378 src));
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001379 }
1380 }
1381
1382 /* cipher out */
1383 desc->ptr[4].len = cpu_to_be16(cryptlen);
1384 desc->ptr[4].j_extent = 0;
1385
1386 if (areq->src != areq->dst)
1387 sg_count = talitos_map_sg(dev, areq->dst,
1388 edesc->dst_nents ? : 1,
1389 DMA_FROM_DEVICE,
1390 edesc->dst_is_chained);
1391
1392 if (sg_count == 1) {
1393 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->dst));
1394 } else {
1395 struct talitos_ptr *link_tbl_ptr =
1396 &edesc->link_tbl[edesc->src_nents + 1];
1397
1398 desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP;
1399 desc->ptr[4].ptr = cpu_to_be32((struct talitos_ptr *)
1400 edesc->dma_link_tbl +
1401 edesc->src_nents + 1);
1402 sg_count = sg_to_link_tbl(areq->dst, sg_count, cryptlen,
1403 link_tbl_ptr);
1404 dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl,
1405 edesc->dma_len, DMA_BIDIRECTIONAL);
1406 }
1407
1408 /* iv out */
1409 map_single_talitos_ptr(dev, &desc->ptr[5], ivsize, ctx->iv, 0,
1410 DMA_FROM_DEVICE);
1411
1412 /* last DWORD empty */
1413 desc->ptr[6].len = 0;
1414 desc->ptr[6].ptr = 0;
1415 desc->ptr[6].j_extent = 0;
1416
1417 ret = talitos_submit(dev, desc, callback, areq);
1418 if (ret != -EINPROGRESS) {
1419 common_nonsnoop_unmap(dev, edesc, areq);
1420 kfree(edesc);
1421 }
1422 return ret;
1423}
1424
Kim Phillipse938e462009-03-29 15:53:23 +08001425static struct talitos_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request *
1426 areq)
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001427{
1428 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1429 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1430
1431 return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, areq->nbytes,
1432 0, 0, areq->base.flags);
1433}
1434
1435static int ablkcipher_encrypt(struct ablkcipher_request *areq)
1436{
1437 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1438 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1439 struct talitos_edesc *edesc;
1440
1441 /* allocate extended descriptor */
1442 edesc = ablkcipher_edesc_alloc(areq);
1443 if (IS_ERR(edesc))
1444 return PTR_ERR(edesc);
1445
1446 /* set encrypt */
1447 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
1448
1449 return common_nonsnoop(edesc, areq, NULL, ablkcipher_done);
1450}
1451
1452static int ablkcipher_decrypt(struct ablkcipher_request *areq)
1453{
1454 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1455 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1456 struct talitos_edesc *edesc;
1457
1458 /* allocate extended descriptor */
1459 edesc = ablkcipher_edesc_alloc(areq);
1460 if (IS_ERR(edesc))
1461 return PTR_ERR(edesc);
1462
1463 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND;
1464
1465 return common_nonsnoop(edesc, areq, NULL, ablkcipher_done);
1466}
1467
Kim Phillips9c4a7962008-06-23 19:50:15 +08001468struct talitos_alg_template {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001469 struct crypto_alg alg;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001470 __be32 desc_hdr_template;
1471};
1472
1473static struct talitos_alg_template driver_algs[] = {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001474 /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */
Kim Phillips9c4a7962008-06-23 19:50:15 +08001475 {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001476 .alg = {
1477 .cra_name = "authenc(hmac(sha1),cbc(aes))",
1478 .cra_driver_name = "authenc-hmac-sha1-cbc-aes-talitos",
1479 .cra_blocksize = AES_BLOCK_SIZE,
1480 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1481 .cra_type = &crypto_aead_type,
1482 .cra_aead = {
1483 .setkey = aead_setkey,
1484 .setauthsize = aead_setauthsize,
1485 .encrypt = aead_encrypt,
1486 .decrypt = aead_decrypt,
1487 .givencrypt = aead_givencrypt,
1488 .geniv = "<built-in>",
1489 .ivsize = AES_BLOCK_SIZE,
1490 .maxauthsize = SHA1_DIGEST_SIZE,
1491 }
1492 },
Kim Phillips9c4a7962008-06-23 19:50:15 +08001493 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1494 DESC_HDR_SEL0_AESU |
1495 DESC_HDR_MODE0_AESU_CBC |
1496 DESC_HDR_SEL1_MDEUA |
1497 DESC_HDR_MODE1_MDEU_INIT |
1498 DESC_HDR_MODE1_MDEU_PAD |
1499 DESC_HDR_MODE1_MDEU_SHA1_HMAC,
Lee Nipper70bcaca2008-07-03 19:08:46 +08001500 },
1501 {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001502 .alg = {
1503 .cra_name = "authenc(hmac(sha1),cbc(des3_ede))",
1504 .cra_driver_name = "authenc-hmac-sha1-cbc-3des-talitos",
1505 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1506 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1507 .cra_type = &crypto_aead_type,
1508 .cra_aead = {
1509 .setkey = aead_setkey,
1510 .setauthsize = aead_setauthsize,
1511 .encrypt = aead_encrypt,
1512 .decrypt = aead_decrypt,
1513 .givencrypt = aead_givencrypt,
1514 .geniv = "<built-in>",
1515 .ivsize = DES3_EDE_BLOCK_SIZE,
1516 .maxauthsize = SHA1_DIGEST_SIZE,
1517 }
1518 },
Lee Nipper70bcaca2008-07-03 19:08:46 +08001519 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1520 DESC_HDR_SEL0_DEU |
1521 DESC_HDR_MODE0_DEU_CBC |
1522 DESC_HDR_MODE0_DEU_3DES |
1523 DESC_HDR_SEL1_MDEUA |
1524 DESC_HDR_MODE1_MDEU_INIT |
1525 DESC_HDR_MODE1_MDEU_PAD |
1526 DESC_HDR_MODE1_MDEU_SHA1_HMAC,
Lee Nipper3952f172008-07-10 18:29:18 +08001527 },
1528 {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001529 .alg = {
1530 .cra_name = "authenc(hmac(sha256),cbc(aes))",
1531 .cra_driver_name = "authenc-hmac-sha256-cbc-aes-talitos",
1532 .cra_blocksize = AES_BLOCK_SIZE,
1533 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1534 .cra_type = &crypto_aead_type,
1535 .cra_aead = {
1536 .setkey = aead_setkey,
1537 .setauthsize = aead_setauthsize,
1538 .encrypt = aead_encrypt,
1539 .decrypt = aead_decrypt,
1540 .givencrypt = aead_givencrypt,
1541 .geniv = "<built-in>",
1542 .ivsize = AES_BLOCK_SIZE,
1543 .maxauthsize = SHA256_DIGEST_SIZE,
1544 }
1545 },
Lee Nipper3952f172008-07-10 18:29:18 +08001546 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1547 DESC_HDR_SEL0_AESU |
1548 DESC_HDR_MODE0_AESU_CBC |
1549 DESC_HDR_SEL1_MDEUA |
1550 DESC_HDR_MODE1_MDEU_INIT |
1551 DESC_HDR_MODE1_MDEU_PAD |
1552 DESC_HDR_MODE1_MDEU_SHA256_HMAC,
1553 },
1554 {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001555 .alg = {
1556 .cra_name = "authenc(hmac(sha256),cbc(des3_ede))",
1557 .cra_driver_name = "authenc-hmac-sha256-cbc-3des-talitos",
1558 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1559 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1560 .cra_type = &crypto_aead_type,
1561 .cra_aead = {
1562 .setkey = aead_setkey,
1563 .setauthsize = aead_setauthsize,
1564 .encrypt = aead_encrypt,
1565 .decrypt = aead_decrypt,
1566 .givencrypt = aead_givencrypt,
1567 .geniv = "<built-in>",
1568 .ivsize = DES3_EDE_BLOCK_SIZE,
1569 .maxauthsize = SHA256_DIGEST_SIZE,
1570 }
1571 },
Lee Nipper3952f172008-07-10 18:29:18 +08001572 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1573 DESC_HDR_SEL0_DEU |
1574 DESC_HDR_MODE0_DEU_CBC |
1575 DESC_HDR_MODE0_DEU_3DES |
1576 DESC_HDR_SEL1_MDEUA |
1577 DESC_HDR_MODE1_MDEU_INIT |
1578 DESC_HDR_MODE1_MDEU_PAD |
1579 DESC_HDR_MODE1_MDEU_SHA256_HMAC,
1580 },
1581 {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001582 .alg = {
1583 .cra_name = "authenc(hmac(md5),cbc(aes))",
1584 .cra_driver_name = "authenc-hmac-md5-cbc-aes-talitos",
1585 .cra_blocksize = AES_BLOCK_SIZE,
1586 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1587 .cra_type = &crypto_aead_type,
1588 .cra_aead = {
1589 .setkey = aead_setkey,
1590 .setauthsize = aead_setauthsize,
1591 .encrypt = aead_encrypt,
1592 .decrypt = aead_decrypt,
1593 .givencrypt = aead_givencrypt,
1594 .geniv = "<built-in>",
1595 .ivsize = AES_BLOCK_SIZE,
1596 .maxauthsize = MD5_DIGEST_SIZE,
1597 }
1598 },
Lee Nipper3952f172008-07-10 18:29:18 +08001599 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1600 DESC_HDR_SEL0_AESU |
1601 DESC_HDR_MODE0_AESU_CBC |
1602 DESC_HDR_SEL1_MDEUA |
1603 DESC_HDR_MODE1_MDEU_INIT |
1604 DESC_HDR_MODE1_MDEU_PAD |
1605 DESC_HDR_MODE1_MDEU_MD5_HMAC,
1606 },
1607 {
Lee Nipper56af8cd2009-03-29 15:50:50 +08001608 .alg = {
1609 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
1610 .cra_driver_name = "authenc-hmac-md5-cbc-3des-talitos",
1611 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1612 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1613 .cra_type = &crypto_aead_type,
1614 .cra_aead = {
1615 .setkey = aead_setkey,
1616 .setauthsize = aead_setauthsize,
1617 .encrypt = aead_encrypt,
1618 .decrypt = aead_decrypt,
1619 .givencrypt = aead_givencrypt,
1620 .geniv = "<built-in>",
1621 .ivsize = DES3_EDE_BLOCK_SIZE,
1622 .maxauthsize = MD5_DIGEST_SIZE,
1623 }
1624 },
Lee Nipper3952f172008-07-10 18:29:18 +08001625 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1626 DESC_HDR_SEL0_DEU |
1627 DESC_HDR_MODE0_DEU_CBC |
1628 DESC_HDR_MODE0_DEU_3DES |
1629 DESC_HDR_SEL1_MDEUA |
1630 DESC_HDR_MODE1_MDEU_INIT |
1631 DESC_HDR_MODE1_MDEU_PAD |
1632 DESC_HDR_MODE1_MDEU_MD5_HMAC,
Lee Nipper4de9d0b2009-03-29 15:52:32 +08001633 },
1634 /* ABLKCIPHER algorithms. */
1635 {
1636 .alg = {
1637 .cra_name = "cbc(aes)",
1638 .cra_driver_name = "cbc-aes-talitos",
1639 .cra_blocksize = AES_BLOCK_SIZE,
1640 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1641 CRYPTO_ALG_ASYNC,
1642 .cra_type = &crypto_ablkcipher_type,
1643 .cra_ablkcipher = {
1644 .setkey = ablkcipher_setkey,
1645 .encrypt = ablkcipher_encrypt,
1646 .decrypt = ablkcipher_decrypt,
1647 .geniv = "eseqiv",
1648 .min_keysize = AES_MIN_KEY_SIZE,
1649 .max_keysize = AES_MAX_KEY_SIZE,
1650 .ivsize = AES_BLOCK_SIZE,
1651 }
1652 },
1653 .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
1654 DESC_HDR_SEL0_AESU |
1655 DESC_HDR_MODE0_AESU_CBC,
1656 },
1657 {
1658 .alg = {
1659 .cra_name = "cbc(des3_ede)",
1660 .cra_driver_name = "cbc-3des-talitos",
1661 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1662 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1663 CRYPTO_ALG_ASYNC,
1664 .cra_type = &crypto_ablkcipher_type,
1665 .cra_ablkcipher = {
1666 .setkey = ablkcipher_setkey,
1667 .encrypt = ablkcipher_encrypt,
1668 .decrypt = ablkcipher_decrypt,
1669 .geniv = "eseqiv",
1670 .min_keysize = DES3_EDE_KEY_SIZE,
1671 .max_keysize = DES3_EDE_KEY_SIZE,
1672 .ivsize = DES3_EDE_BLOCK_SIZE,
1673 }
1674 },
1675 .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
1676 DESC_HDR_SEL0_DEU |
1677 DESC_HDR_MODE0_DEU_CBC |
1678 DESC_HDR_MODE0_DEU_3DES,
Kim Phillips9c4a7962008-06-23 19:50:15 +08001679 }
1680};
1681
1682struct talitos_crypto_alg {
1683 struct list_head entry;
1684 struct device *dev;
1685 __be32 desc_hdr_template;
1686 struct crypto_alg crypto_alg;
1687};
1688
1689static int talitos_cra_init(struct crypto_tfm *tfm)
1690{
1691 struct crypto_alg *alg = tfm->__crt_alg;
Kim Phillips19bbbc62009-03-29 15:53:59 +08001692 struct talitos_crypto_alg *talitos_alg;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001693 struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
1694
Kim Phillips19bbbc62009-03-29 15:53:59 +08001695 talitos_alg = container_of(alg, struct talitos_crypto_alg, crypto_alg);
1696
Kim Phillips9c4a7962008-06-23 19:50:15 +08001697 /* update context with ptr to dev */
1698 ctx->dev = talitos_alg->dev;
Kim Phillips19bbbc62009-03-29 15:53:59 +08001699
Kim Phillips9c4a7962008-06-23 19:50:15 +08001700 /* copy descriptor header template value */
1701 ctx->desc_hdr_template = talitos_alg->desc_hdr_template;
1702
1703 /* random first IV */
Lee Nipper70bcaca2008-07-03 19:08:46 +08001704 get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001705
1706 return 0;
1707}
1708
1709/*
1710 * given the alg's descriptor header template, determine whether descriptor
1711 * type and primary/secondary execution units required match the hw
1712 * capabilities description provided in the device tree node.
1713 */
1714static int hw_supports(struct device *dev, __be32 desc_hdr_template)
1715{
1716 struct talitos_private *priv = dev_get_drvdata(dev);
1717 int ret;
1718
1719 ret = (1 << DESC_TYPE(desc_hdr_template) & priv->desc_types) &&
1720 (1 << PRIMARY_EU(desc_hdr_template) & priv->exec_units);
1721
1722 if (SECONDARY_EU(desc_hdr_template))
1723 ret = ret && (1 << SECONDARY_EU(desc_hdr_template)
1724 & priv->exec_units);
1725
1726 return ret;
1727}
1728
Al Viro596f1032008-11-22 17:34:24 +00001729static int talitos_remove(struct of_device *ofdev)
Kim Phillips9c4a7962008-06-23 19:50:15 +08001730{
1731 struct device *dev = &ofdev->dev;
1732 struct talitos_private *priv = dev_get_drvdata(dev);
1733 struct talitos_crypto_alg *t_alg, *n;
1734 int i;
1735
1736 list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) {
1737 crypto_unregister_alg(&t_alg->crypto_alg);
1738 list_del(&t_alg->entry);
1739 kfree(t_alg);
1740 }
1741
1742 if (hw_supports(dev, DESC_HDR_SEL0_RNG))
1743 talitos_unregister_rng(dev);
1744
Kim Phillipsec6644d2008-07-17 20:16:40 +08001745 kfree(priv->submit_count);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001746 kfree(priv->tail);
1747 kfree(priv->head);
1748
1749 if (priv->fifo)
1750 for (i = 0; i < priv->num_channels; i++)
1751 kfree(priv->fifo[i]);
1752
1753 kfree(priv->fifo);
1754 kfree(priv->head_lock);
1755 kfree(priv->tail_lock);
1756
1757 if (priv->irq != NO_IRQ) {
1758 free_irq(priv->irq, dev);
1759 irq_dispose_mapping(priv->irq);
1760 }
1761
1762 tasklet_kill(&priv->done_task);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001763
1764 iounmap(priv->reg);
1765
1766 dev_set_drvdata(dev, NULL);
1767
1768 kfree(priv);
1769
1770 return 0;
1771}
1772
1773static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
1774 struct talitos_alg_template
1775 *template)
1776{
1777 struct talitos_crypto_alg *t_alg;
1778 struct crypto_alg *alg;
1779
1780 t_alg = kzalloc(sizeof(struct talitos_crypto_alg), GFP_KERNEL);
1781 if (!t_alg)
1782 return ERR_PTR(-ENOMEM);
1783
1784 alg = &t_alg->crypto_alg;
Lee Nipper56af8cd2009-03-29 15:50:50 +08001785 *alg = template->alg;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001786
Kim Phillips9c4a7962008-06-23 19:50:15 +08001787 alg->cra_module = THIS_MODULE;
1788 alg->cra_init = talitos_cra_init;
1789 alg->cra_priority = TALITOS_CRA_PRIORITY;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001790 alg->cra_alignmask = 0;
Kim Phillips9c4a7962008-06-23 19:50:15 +08001791 alg->cra_ctxsize = sizeof(struct talitos_ctx);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001792
1793 t_alg->desc_hdr_template = template->desc_hdr_template;
1794 t_alg->dev = dev;
1795
1796 return t_alg;
1797}
1798
1799static int talitos_probe(struct of_device *ofdev,
1800 const struct of_device_id *match)
1801{
1802 struct device *dev = &ofdev->dev;
1803 struct device_node *np = ofdev->node;
1804 struct talitos_private *priv;
1805 const unsigned int *prop;
1806 int i, err;
1807
1808 priv = kzalloc(sizeof(struct talitos_private), GFP_KERNEL);
1809 if (!priv)
1810 return -ENOMEM;
1811
1812 dev_set_drvdata(dev, priv);
1813
1814 priv->ofdev = ofdev;
1815
1816 tasklet_init(&priv->done_task, talitos_done, (unsigned long)dev);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001817
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001818 INIT_LIST_HEAD(&priv->alg_list);
1819
Kim Phillips9c4a7962008-06-23 19:50:15 +08001820 priv->irq = irq_of_parse_and_map(np, 0);
1821
1822 if (priv->irq == NO_IRQ) {
1823 dev_err(dev, "failed to map irq\n");
1824 err = -EINVAL;
1825 goto err_out;
1826 }
1827
1828 /* get the irq line */
1829 err = request_irq(priv->irq, talitos_interrupt, 0,
1830 dev_driver_string(dev), dev);
1831 if (err) {
1832 dev_err(dev, "failed to request irq %d\n", priv->irq);
1833 irq_dispose_mapping(priv->irq);
1834 priv->irq = NO_IRQ;
1835 goto err_out;
1836 }
1837
1838 priv->reg = of_iomap(np, 0);
1839 if (!priv->reg) {
1840 dev_err(dev, "failed to of_iomap\n");
1841 err = -ENOMEM;
1842 goto err_out;
1843 }
1844
1845 /* get SEC version capabilities from device tree */
1846 prop = of_get_property(np, "fsl,num-channels", NULL);
1847 if (prop)
1848 priv->num_channels = *prop;
1849
1850 prop = of_get_property(np, "fsl,channel-fifo-len", NULL);
1851 if (prop)
1852 priv->chfifo_len = *prop;
1853
1854 prop = of_get_property(np, "fsl,exec-units-mask", NULL);
1855 if (prop)
1856 priv->exec_units = *prop;
1857
1858 prop = of_get_property(np, "fsl,descriptor-types-mask", NULL);
1859 if (prop)
1860 priv->desc_types = *prop;
1861
1862 if (!is_power_of_2(priv->num_channels) || !priv->chfifo_len ||
1863 !priv->exec_units || !priv->desc_types) {
1864 dev_err(dev, "invalid property data in device tree node\n");
1865 err = -EINVAL;
1866 goto err_out;
1867 }
1868
Lee Nipperf3c85bc2008-07-30 16:26:57 +08001869 if (of_device_is_compatible(np, "fsl,sec3.0"))
1870 priv->features |= TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT;
1871
Kim Phillipsfe5720e2008-10-12 20:33:14 +08001872 if (of_device_is_compatible(np, "fsl,sec2.1"))
1873 priv->features |= TALITOS_FTR_HW_AUTH_CHECK;
1874
Kim Phillips9c4a7962008-06-23 19:50:15 +08001875 priv->head_lock = kmalloc(sizeof(spinlock_t) * priv->num_channels,
1876 GFP_KERNEL);
1877 priv->tail_lock = kmalloc(sizeof(spinlock_t) * priv->num_channels,
1878 GFP_KERNEL);
1879 if (!priv->head_lock || !priv->tail_lock) {
1880 dev_err(dev, "failed to allocate fifo locks\n");
1881 err = -ENOMEM;
1882 goto err_out;
1883 }
1884
1885 for (i = 0; i < priv->num_channels; i++) {
1886 spin_lock_init(&priv->head_lock[i]);
1887 spin_lock_init(&priv->tail_lock[i]);
1888 }
1889
1890 priv->fifo = kmalloc(sizeof(struct talitos_request *) *
1891 priv->num_channels, GFP_KERNEL);
1892 if (!priv->fifo) {
1893 dev_err(dev, "failed to allocate request fifo\n");
1894 err = -ENOMEM;
1895 goto err_out;
1896 }
1897
1898 priv->fifo_len = roundup_pow_of_two(priv->chfifo_len);
1899
1900 for (i = 0; i < priv->num_channels; i++) {
1901 priv->fifo[i] = kzalloc(sizeof(struct talitos_request) *
1902 priv->fifo_len, GFP_KERNEL);
1903 if (!priv->fifo[i]) {
1904 dev_err(dev, "failed to allocate request fifo %d\n", i);
1905 err = -ENOMEM;
1906 goto err_out;
1907 }
1908 }
1909
Kim Phillips586725f2008-07-17 20:19:18 +08001910 priv->submit_count = kmalloc(sizeof(atomic_t) * priv->num_channels,
Kim Phillipsec6644d2008-07-17 20:16:40 +08001911 GFP_KERNEL);
1912 if (!priv->submit_count) {
1913 dev_err(dev, "failed to allocate fifo submit count space\n");
1914 err = -ENOMEM;
1915 goto err_out;
1916 }
1917 for (i = 0; i < priv->num_channels; i++)
Vishnu Suresh4b24ea92008-10-20 21:06:18 +08001918 atomic_set(&priv->submit_count[i], -(priv->chfifo_len - 1));
Kim Phillipsec6644d2008-07-17 20:16:40 +08001919
Kim Phillips9c4a7962008-06-23 19:50:15 +08001920 priv->head = kzalloc(sizeof(int) * priv->num_channels, GFP_KERNEL);
1921 priv->tail = kzalloc(sizeof(int) * priv->num_channels, GFP_KERNEL);
1922 if (!priv->head || !priv->tail) {
1923 dev_err(dev, "failed to allocate request index space\n");
1924 err = -ENOMEM;
1925 goto err_out;
1926 }
1927
1928 /* reset and initialize the h/w */
1929 err = init_device(dev);
1930 if (err) {
1931 dev_err(dev, "failed to initialize device\n");
1932 goto err_out;
1933 }
1934
1935 /* register the RNG, if available */
1936 if (hw_supports(dev, DESC_HDR_SEL0_RNG)) {
1937 err = talitos_register_rng(dev);
1938 if (err) {
1939 dev_err(dev, "failed to register hwrng: %d\n", err);
1940 goto err_out;
1941 } else
1942 dev_info(dev, "hwrng\n");
1943 }
1944
1945 /* register crypto algorithms the device supports */
Kim Phillips9c4a7962008-06-23 19:50:15 +08001946 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
1947 if (hw_supports(dev, driver_algs[i].desc_hdr_template)) {
1948 struct talitos_crypto_alg *t_alg;
1949
1950 t_alg = talitos_alg_alloc(dev, &driver_algs[i]);
1951 if (IS_ERR(t_alg)) {
1952 err = PTR_ERR(t_alg);
1953 goto err_out;
1954 }
1955
1956 err = crypto_register_alg(&t_alg->crypto_alg);
1957 if (err) {
1958 dev_err(dev, "%s alg registration failed\n",
1959 t_alg->crypto_alg.cra_driver_name);
1960 kfree(t_alg);
1961 } else {
1962 list_add_tail(&t_alg->entry, &priv->alg_list);
1963 dev_info(dev, "%s\n",
1964 t_alg->crypto_alg.cra_driver_name);
1965 }
1966 }
1967 }
1968
1969 return 0;
1970
1971err_out:
1972 talitos_remove(ofdev);
Kim Phillips9c4a7962008-06-23 19:50:15 +08001973
1974 return err;
1975}
1976
1977static struct of_device_id talitos_match[] = {
1978 {
1979 .compatible = "fsl,sec2.0",
1980 },
1981 {},
1982};
1983MODULE_DEVICE_TABLE(of, talitos_match);
1984
1985static struct of_platform_driver talitos_driver = {
1986 .name = "talitos",
1987 .match_table = talitos_match,
1988 .probe = talitos_probe,
Al Viro596f1032008-11-22 17:34:24 +00001989 .remove = talitos_remove,
Kim Phillips9c4a7962008-06-23 19:50:15 +08001990};
1991
1992static int __init talitos_init(void)
1993{
1994 return of_register_platform_driver(&talitos_driver);
1995}
1996module_init(talitos_init);
1997
1998static void __exit talitos_exit(void)
1999{
2000 of_unregister_platform_driver(&talitos_driver);
2001}
2002module_exit(talitos_exit);
2003
2004MODULE_LICENSE("GPL");
2005MODULE_AUTHOR("Kim Phillips <kim.phillips@freescale.com>");
2006MODULE_DESCRIPTION("Freescale integrated security engine (SEC) driver");