forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/crypto/cavium/nitrox/nitrox_req.h
....@@ -7,6 +7,11 @@
77
88 #include "nitrox_dev.h"
99
10
+#define PENDING_SIG 0xFFFFFFFFFFFFFFFFUL
11
+#define PRIO 4001
12
+
13
+typedef void (*sereq_completion_t)(void *req, int err);
14
+
1015 /**
1116 * struct gphdr - General purpose Header
1217 * @param0: first parameter.
....@@ -46,13 +51,6 @@
4651 } s;
4752 };
4853
49
-struct nitrox_sglist {
50
- u16 len;
51
- u16 raz0;
52
- u32 raz1;
53
- dma_addr_t dma;
54
-};
55
-
5654 #define MAX_IV_LEN 16
5755
5856 /**
....@@ -62,8 +60,10 @@
6260 * @ctx_handle: Crypto context handle.
6361 * @gph: GP Header
6462 * @ctrl: Request Information.
65
- * @in: Input sglist
66
- * @out: Output sglist
63
+ * @orh: ORH address
64
+ * @comp: completion address
65
+ * @src: Input sglist
66
+ * @dst: Output sglist
6767 */
6868 struct se_crypto_request {
6969 u8 opcode;
....@@ -73,9 +73,8 @@
7373
7474 struct gphdr gph;
7575 union se_req_ctrl ctrl;
76
-
77
- u8 iv[MAX_IV_LEN];
78
- u16 ivsize;
76
+ u64 *orh;
77
+ u64 *comp;
7978
8079 struct scatterlist *src;
8180 struct scatterlist *dst;
....@@ -110,6 +109,18 @@
110109 CIPHER_INVALID
111110 };
112111
112
+enum flexi_auth {
113
+ AUTH_NULL = 0,
114
+ AUTH_MD5,
115
+ AUTH_SHA1,
116
+ AUTH_SHA2_SHA224,
117
+ AUTH_SHA2_SHA256,
118
+ AUTH_SHA2_SHA384,
119
+ AUTH_SHA2_SHA512,
120
+ AUTH_GMAC,
121
+ AUTH_INVALID
122
+};
123
+
113124 /**
114125 * struct crypto_keys - Crypto keys
115126 * @key: Encryption key or KEY1 for AES-XTS
....@@ -136,6 +147,32 @@
136147 u8 opad[64];
137148 };
138149
150
+union fc_ctx_flags {
151
+ __be64 f;
152
+ struct {
153
+#if defined(__BIG_ENDIAN_BITFIELD)
154
+ u64 cipher_type : 4;
155
+ u64 reserved_59 : 1;
156
+ u64 aes_keylen : 2;
157
+ u64 iv_source : 1;
158
+ u64 hash_type : 4;
159
+ u64 reserved_49_51 : 3;
160
+ u64 auth_input_type: 1;
161
+ u64 mac_len : 8;
162
+ u64 reserved_0_39 : 40;
163
+#else
164
+ u64 reserved_0_39 : 40;
165
+ u64 mac_len : 8;
166
+ u64 auth_input_type: 1;
167
+ u64 reserved_49_51 : 3;
168
+ u64 hash_type : 4;
169
+ u64 iv_source : 1;
170
+ u64 aes_keylen : 2;
171
+ u64 reserved_59 : 1;
172
+ u64 cipher_type : 4;
173
+#endif
174
+ } w0;
175
+};
139176 /**
140177 * struct flexi_crypto_context - Crypto context
141178 * @cipher_type: Encryption cipher type
....@@ -150,33 +187,7 @@
150187 * @auth: Authentication keys
151188 */
152189 struct flexi_crypto_context {
153
- union {
154
- __be64 flags;
155
- struct {
156
-#if defined(__BIG_ENDIAN_BITFIELD)
157
- u64 cipher_type : 4;
158
- u64 reserved_59 : 1;
159
- u64 aes_keylen : 2;
160
- u64 iv_source : 1;
161
- u64 hash_type : 4;
162
- u64 reserved_49_51 : 3;
163
- u64 auth_input_type: 1;
164
- u64 mac_len : 8;
165
- u64 reserved_0_39 : 40;
166
-#else
167
- u64 reserved_0_39 : 40;
168
- u64 mac_len : 8;
169
- u64 auth_input_type: 1;
170
- u64 reserved_49_51 : 3;
171
- u64 hash_type : 4;
172
- u64 iv_source : 1;
173
- u64 aes_keylen : 2;
174
- u64 reserved_59 : 1;
175
- u64 cipher_type : 4;
176
-#endif
177
- } w0;
178
- };
179
-
190
+ union fc_ctx_flags flags;
180191 struct crypto_keys crypto;
181192 struct auth_keys auth;
182193 };
....@@ -194,12 +205,58 @@
194205 struct flexi_crypto_context *fctx;
195206 } u;
196207 struct crypto_ctx_hdr *chdr;
208
+ sereq_completion_t callback;
197209 };
198210
199211 struct nitrox_kcrypt_request {
200212 struct se_crypto_request creq;
201
- struct nitrox_crypto_ctx *nctx;
202
- struct skcipher_request *skreq;
213
+ u8 *src;
214
+ u8 *dst;
215
+ u8 *iv_out;
216
+};
217
+
218
+/**
219
+ * struct nitrox_aead_rctx - AEAD request context
220
+ * @nkreq: Base request context
221
+ * @cryptlen: Encryption/Decryption data length
222
+ * @assoclen: AAD length
223
+ * @srclen: Input buffer length
224
+ * @dstlen: Output buffer length
225
+ * @iv: IV data
226
+ * @ivsize: IV data length
227
+ * @flags: AEAD req flags
228
+ * @ctx_handle: Device context handle
229
+ * @src: Source sglist
230
+ * @dst: Destination sglist
231
+ * @ctrl_arg: Identifies the request type (ENCRYPT/DECRYPT)
232
+ */
233
+struct nitrox_aead_rctx {
234
+ struct nitrox_kcrypt_request nkreq;
235
+ unsigned int cryptlen;
236
+ unsigned int assoclen;
237
+ unsigned int srclen;
238
+ unsigned int dstlen;
239
+ u8 *iv;
240
+ int ivsize;
241
+ u32 flags;
242
+ u64 ctx_handle;
243
+ struct scatterlist *src;
244
+ struct scatterlist *dst;
245
+ u8 ctrl_arg;
246
+};
247
+
248
+/**
249
+ * struct nitrox_rfc4106_rctx - rfc4106 cipher request context
250
+ * @base: AEAD request context
251
+ * @src: Source sglist
252
+ * @dst: Destination sglist
253
+ * @assoc: AAD
254
+ */
255
+struct nitrox_rfc4106_rctx {
256
+ struct nitrox_aead_rctx base;
257
+ struct scatterlist src[3];
258
+ struct scatterlist dst[3];
259
+ u8 assoc[20];
203260 };
204261
205262 /**
....@@ -347,6 +404,36 @@
347404 };
348405
349406 /**
407
+ * struct aqmq_command_s - The 32 byte command for AE processing.
408
+ * @opcode: Request opcode
409
+ * @param1: Request control parameter 1
410
+ * @param2: Request control parameter 2
411
+ * @dlen: Input length
412
+ * @dptr: Input pointer points to buffer in remote host
413
+ * @rptr: Result pointer points to buffer in remote host
414
+ * @grp: AQM Group (0..7)
415
+ * @cptr: Context pointer
416
+ */
417
+struct aqmq_command_s {
418
+ __be16 opcode;
419
+ __be16 param1;
420
+ __be16 param2;
421
+ __be16 dlen;
422
+ __be64 dptr;
423
+ __be64 rptr;
424
+ union {
425
+ __be64 word3;
426
+#if defined(__BIG_ENDIAN_BITFIELD)
427
+ u64 grp : 3;
428
+ u64 cptr : 61;
429
+#else
430
+ u64 cptr : 61;
431
+ u64 grp : 3;
432
+#endif
433
+ };
434
+};
435
+
436
+/**
350437 * struct ctx_hdr - Book keeping data about the crypto context
351438 * @pool: Pool used to allocate crypto context
352439 * @dma: Base DMA address of the cypto context
....@@ -376,26 +463,19 @@
376463
377464 /*
378465 * strutct nitrox_sgtable - SG list information
379
- * @map_cnt: Number of buffers mapped
380
- * @nr_comp: Number of sglist components
466
+ * @sgmap_cnt: Number of buffers mapped
381467 * @total_bytes: Total bytes in sglist.
382
- * @len: Total sglist components length.
383
- * @dma: DMA address of sglist component.
384
- * @dir: DMA direction.
385
- * @buf: crypto request buffer.
386
- * @sglist: SG list of input/output buffers.
468
+ * @sgcomp_len: Total sglist components length.
469
+ * @sgcomp_dma: DMA address of sglist component.
470
+ * @sg: crypto request buffer.
387471 * @sgcomp: sglist component for NITROX.
388472 */
389473 struct nitrox_sgtable {
390
- u8 map_bufs_cnt;
391
- u8 nr_sgcomp;
474
+ u8 sgmap_cnt;
392475 u16 total_bytes;
393
- u32 len;
394
- dma_addr_t dma;
395
- enum dma_data_direction dir;
396
-
397
- struct scatterlist *buf;
398
- struct nitrox_sglist *sglist;
476
+ u32 sgcomp_len;
477
+ dma_addr_t sgcomp_dma;
478
+ struct scatterlist *sg;
399479 struct nitrox_sgcomp *sgcomp;
400480 };
401481
....@@ -405,13 +485,11 @@
405485 #define COMP_HLEN 8
406486
407487 struct resp_hdr {
408
- u64 orh;
409
- dma_addr_t orh_dma;
410
- u64 completion;
411
- dma_addr_t completion_dma;
488
+ u64 *orh;
489
+ u64 *completion;
412490 };
413491
414
-typedef void (*completion_t)(struct skcipher_request *skreq, int err);
492
+typedef void (*completion_t)(void *arg, int err);
415493
416494 /**
417495 * struct nitrox_softreq - Represents the NIROX Request.
....@@ -434,7 +512,6 @@
434512 u32 flags;
435513 gfp_t gfp;
436514 atomic_t status;
437
- bool inplace;
438515
439516 struct nitrox_device *ndev;
440517 struct nitrox_cmdq *cmdq;
....@@ -447,7 +524,201 @@
447524 unsigned long tstamp;
448525
449526 completion_t callback;
450
- struct skcipher_request *skreq;
527
+ void *cb_arg;
451528 };
452529
530
+static inline int flexi_aes_keylen(int keylen)
531
+{
532
+ int aes_keylen;
533
+
534
+ switch (keylen) {
535
+ case AES_KEYSIZE_128:
536
+ aes_keylen = 1;
537
+ break;
538
+ case AES_KEYSIZE_192:
539
+ aes_keylen = 2;
540
+ break;
541
+ case AES_KEYSIZE_256:
542
+ aes_keylen = 3;
543
+ break;
544
+ default:
545
+ aes_keylen = -EINVAL;
546
+ break;
547
+ }
548
+ return aes_keylen;
549
+}
550
+
551
+static inline void *alloc_req_buf(int nents, int extralen, gfp_t gfp)
552
+{
553
+ size_t size;
554
+
555
+ size = sizeof(struct scatterlist) * nents;
556
+ size += extralen;
557
+
558
+ return kzalloc(size, gfp);
559
+}
560
+
561
+/**
562
+ * create_single_sg - Point SG entry to the data
563
+ * @sg: Destination SG list
564
+ * @buf: Data
565
+ * @buflen: Data length
566
+ *
567
+ * Returns next free entry in the destination SG list
568
+ **/
569
+static inline struct scatterlist *create_single_sg(struct scatterlist *sg,
570
+ void *buf, int buflen)
571
+{
572
+ sg_set_buf(sg, buf, buflen);
573
+ sg++;
574
+ return sg;
575
+}
576
+
577
+/**
578
+ * create_multi_sg - Create multiple sg entries with buflen data length from
579
+ * source sglist
580
+ * @to_sg: Destination SG list
581
+ * @from_sg: Source SG list
582
+ * @buflen: Data length
583
+ *
584
+ * Returns next free entry in the destination SG list
585
+ **/
586
+static inline struct scatterlist *create_multi_sg(struct scatterlist *to_sg,
587
+ struct scatterlist *from_sg,
588
+ int buflen)
589
+{
590
+ struct scatterlist *sg = to_sg;
591
+ unsigned int sglen;
592
+
593
+ for (; buflen && from_sg; buflen -= sglen) {
594
+ sglen = from_sg->length;
595
+ if (sglen > buflen)
596
+ sglen = buflen;
597
+
598
+ sg_set_buf(sg, sg_virt(from_sg), sglen);
599
+ from_sg = sg_next(from_sg);
600
+ sg++;
601
+ }
602
+
603
+ return sg;
604
+}
605
+
606
+static inline void set_orh_value(u64 *orh)
607
+{
608
+ WRITE_ONCE(*orh, PENDING_SIG);
609
+}
610
+
611
+static inline void set_comp_value(u64 *comp)
612
+{
613
+ WRITE_ONCE(*comp, PENDING_SIG);
614
+}
615
+
616
+static inline int alloc_src_req_buf(struct nitrox_kcrypt_request *nkreq,
617
+ int nents, int ivsize)
618
+{
619
+ struct se_crypto_request *creq = &nkreq->creq;
620
+
621
+ nkreq->src = alloc_req_buf(nents, ivsize, creq->gfp);
622
+ if (!nkreq->src)
623
+ return -ENOMEM;
624
+
625
+ return 0;
626
+}
627
+
628
+static inline void nitrox_creq_copy_iv(char *dst, char *src, int size)
629
+{
630
+ memcpy(dst, src, size);
631
+}
632
+
633
+static inline struct scatterlist *nitrox_creq_src_sg(char *iv, int ivsize)
634
+{
635
+ return (struct scatterlist *)(iv + ivsize);
636
+}
637
+
638
+static inline void nitrox_creq_set_src_sg(struct nitrox_kcrypt_request *nkreq,
639
+ int nents, int ivsize,
640
+ struct scatterlist *src, int buflen)
641
+{
642
+ char *iv = nkreq->src;
643
+ struct scatterlist *sg;
644
+ struct se_crypto_request *creq = &nkreq->creq;
645
+
646
+ creq->src = nitrox_creq_src_sg(iv, ivsize);
647
+ sg = creq->src;
648
+ sg_init_table(sg, nents);
649
+
650
+ /* Input format:
651
+ * +----+----------------+
652
+ * | IV | SRC sg entries |
653
+ * +----+----------------+
654
+ */
655
+
656
+ /* IV */
657
+ sg = create_single_sg(sg, iv, ivsize);
658
+ /* SRC entries */
659
+ create_multi_sg(sg, src, buflen);
660
+}
661
+
662
+static inline int alloc_dst_req_buf(struct nitrox_kcrypt_request *nkreq,
663
+ int nents)
664
+{
665
+ int extralen = ORH_HLEN + COMP_HLEN;
666
+ struct se_crypto_request *creq = &nkreq->creq;
667
+
668
+ nkreq->dst = alloc_req_buf(nents, extralen, creq->gfp);
669
+ if (!nkreq->dst)
670
+ return -ENOMEM;
671
+
672
+ return 0;
673
+}
674
+
675
+static inline void nitrox_creq_set_orh(struct nitrox_kcrypt_request *nkreq)
676
+{
677
+ struct se_crypto_request *creq = &nkreq->creq;
678
+
679
+ creq->orh = (u64 *)(nkreq->dst);
680
+ set_orh_value(creq->orh);
681
+}
682
+
683
+static inline void nitrox_creq_set_comp(struct nitrox_kcrypt_request *nkreq)
684
+{
685
+ struct se_crypto_request *creq = &nkreq->creq;
686
+
687
+ creq->comp = (u64 *)(nkreq->dst + ORH_HLEN);
688
+ set_comp_value(creq->comp);
689
+}
690
+
691
+static inline struct scatterlist *nitrox_creq_dst_sg(char *dst)
692
+{
693
+ return (struct scatterlist *)(dst + ORH_HLEN + COMP_HLEN);
694
+}
695
+
696
+static inline void nitrox_creq_set_dst_sg(struct nitrox_kcrypt_request *nkreq,
697
+ int nents, int ivsize,
698
+ struct scatterlist *dst, int buflen)
699
+{
700
+ struct se_crypto_request *creq = &nkreq->creq;
701
+ struct scatterlist *sg;
702
+ char *iv = nkreq->src;
703
+
704
+ creq->dst = nitrox_creq_dst_sg(nkreq->dst);
705
+ sg = creq->dst;
706
+ sg_init_table(sg, nents);
707
+
708
+ /* Output format:
709
+ * +-----+----+----------------+-----------------+
710
+ * | ORH | IV | DST sg entries | COMPLETION Bytes|
711
+ * +-----+----+----------------+-----------------+
712
+ */
713
+
714
+ /* ORH */
715
+ sg = create_single_sg(sg, creq->orh, ORH_HLEN);
716
+ /* IV */
717
+ sg = create_single_sg(sg, iv, ivsize);
718
+ /* DST entries */
719
+ sg = create_multi_sg(sg, dst, buflen);
720
+ /* COMPLETION Bytes */
721
+ create_single_sg(sg, creq->comp, COMP_HLEN);
722
+}
723
+
453724 #endif /* __NITROX_REQ_H */