hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/crypto/qat/qat_common/adf_transport.c
....@@ -1,49 +1,5 @@
1
-/*
2
- This file is provided under a dual BSD/GPLv2 license. When using or
3
- redistributing this file, you may do so under either license.
4
-
5
- GPL LICENSE SUMMARY
6
- Copyright(c) 2014 Intel Corporation.
7
- This program is free software; you can redistribute it and/or modify
8
- it under the terms of version 2 of the GNU General Public License as
9
- published by the Free Software Foundation.
10
-
11
- This program is distributed in the hope that it will be useful, but
12
- WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- General Public License for more details.
15
-
16
- Contact Information:
17
- qat-linux@intel.com
18
-
19
- BSD LICENSE
20
- Copyright(c) 2014 Intel Corporation.
21
- Redistribution and use in source and binary forms, with or without
22
- modification, are permitted provided that the following conditions
23
- are met:
24
-
25
- * Redistributions of source code must retain the above copyright
26
- notice, this list of conditions and the following disclaimer.
27
- * Redistributions in binary form must reproduce the above copyright
28
- notice, this list of conditions and the following disclaimer in
29
- the documentation and/or other materials provided with the
30
- distribution.
31
- * Neither the name of Intel Corporation nor the names of its
32
- contributors may be used to endorse or promote products derived
33
- from this software without specific prior written permission.
34
-
35
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
-*/
1
+// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
2
+/* Copyright(c) 2014 - 2020 Intel Corporation */
473 #include <linux/delay.h>
484 #include "adf_accel_devices.h"
495 #include "adf_transport_internal.h"
....@@ -51,22 +7,22 @@
517 #include "adf_cfg.h"
528 #include "adf_common_drv.h"
539
54
-static inline uint32_t adf_modulo(uint32_t data, uint32_t shift)
10
+static inline u32 adf_modulo(u32 data, u32 shift)
5511 {
56
- uint32_t div = data >> shift;
57
- uint32_t mult = div << shift;
12
+ u32 div = data >> shift;
13
+ u32 mult = div << shift;
5814
5915 return data - mult;
6016 }
6117
62
-static inline int adf_check_ring_alignment(uint64_t addr, uint64_t size)
18
+static inline int adf_check_ring_alignment(u64 addr, u64 size)
6319 {
6420 if (((size - 1) & addr) != 0)
6521 return -EFAULT;
6622 return 0;
6723 }
6824
69
-static int adf_verify_ring_size(uint32_t msg_size, uint32_t msg_num)
25
+static int adf_verify_ring_size(u32 msg_size, u32 msg_num)
7026 {
7127 int i = ADF_MIN_RING_SIZE;
7228
....@@ -77,7 +33,7 @@
7733 return ADF_DEFAULT_RING_SIZE;
7834 }
7935
80
-static int adf_reserve_ring(struct adf_etr_bank_data *bank, uint32_t ring)
36
+static int adf_reserve_ring(struct adf_etr_bank_data *bank, u32 ring)
8137 {
8238 spin_lock(&bank->lock);
8339 if (bank->ring_mask & (1 << ring)) {
....@@ -89,14 +45,14 @@
8945 return 0;
9046 }
9147
92
-static void adf_unreserve_ring(struct adf_etr_bank_data *bank, uint32_t ring)
48
+static void adf_unreserve_ring(struct adf_etr_bank_data *bank, u32 ring)
9349 {
9450 spin_lock(&bank->lock);
9551 bank->ring_mask &= ~(1 << ring);
9652 spin_unlock(&bank->lock);
9753 }
9854
99
-static void adf_enable_ring_irq(struct adf_etr_bank_data *bank, uint32_t ring)
55
+static void adf_enable_ring_irq(struct adf_etr_bank_data *bank, u32 ring)
10056 {
10157 spin_lock_bh(&bank->lock);
10258 bank->irq_mask |= (1 << ring);
....@@ -106,7 +62,7 @@
10662 bank->irq_coalesc_timer);
10763 }
10864
109
-static void adf_disable_ring_irq(struct adf_etr_bank_data *bank, uint32_t ring)
65
+static void adf_disable_ring_irq(struct adf_etr_bank_data *bank, u32 ring)
11066 {
11167 spin_lock_bh(&bank->lock);
11268 bank->irq_mask &= ~(1 << ring);
....@@ -114,7 +70,7 @@
11470 WRITE_CSR_INT_COL_EN(bank->csr_addr, bank->bank_number, bank->irq_mask);
11571 }
11672
117
-int adf_send_message(struct adf_etr_ring_data *ring, uint32_t *msg)
73
+int adf_send_message(struct adf_etr_ring_data *ring, u32 *msg)
11874 {
11975 if (atomic_add_return(1, ring->inflights) >
12076 ADF_MAX_INFLIGHTS(ring->ring_size, ring->msg_size)) {
....@@ -136,18 +92,18 @@
13692
13793 static int adf_handle_response(struct adf_etr_ring_data *ring)
13894 {
139
- uint32_t msg_counter = 0;
140
- uint32_t *msg = (uint32_t *)((uintptr_t)ring->base_addr + ring->head);
95
+ u32 msg_counter = 0;
96
+ u32 *msg = (u32 *)((uintptr_t)ring->base_addr + ring->head);
14197
14298 while (*msg != ADF_RING_EMPTY_SIG) {
143
- ring->callback((uint32_t *)msg);
99
+ ring->callback((u32 *)msg);
144100 atomic_dec(ring->inflights);
145101 *msg = ADF_RING_EMPTY_SIG;
146102 ring->head = adf_modulo(ring->head +
147103 ADF_MSG_SIZE_TO_BYTES(ring->msg_size),
148104 ADF_RING_SIZE_MODULO(ring->ring_size));
149105 msg_counter++;
150
- msg = (uint32_t *)((uintptr_t)ring->base_addr + ring->head);
106
+ msg = (u32 *)((uintptr_t)ring->base_addr + ring->head);
151107 }
152108 if (msg_counter > 0)
153109 WRITE_CSR_RING_HEAD(ring->bank->csr_addr,
....@@ -158,7 +114,7 @@
158114
159115 static void adf_configure_tx_ring(struct adf_etr_ring_data *ring)
160116 {
161
- uint32_t ring_config = BUILD_RING_CONFIG(ring->ring_size);
117
+ u32 ring_config = BUILD_RING_CONFIG(ring->ring_size);
162118
163119 WRITE_CSR_RING_CONFIG(ring->bank->csr_addr, ring->bank->bank_number,
164120 ring->ring_number, ring_config);
....@@ -166,7 +122,7 @@
166122
167123 static void adf_configure_rx_ring(struct adf_etr_ring_data *ring)
168124 {
169
- uint32_t ring_config =
125
+ u32 ring_config =
170126 BUILD_RESP_RING_CONFIG(ring->ring_size,
171127 ADF_RING_NEAR_WATERMARK_512,
172128 ADF_RING_NEAR_WATERMARK_0);
....@@ -180,8 +136,8 @@
180136 struct adf_etr_bank_data *bank = ring->bank;
181137 struct adf_accel_dev *accel_dev = bank->accel_dev;
182138 struct adf_hw_device_data *hw_data = accel_dev->hw_device;
183
- uint64_t ring_base;
184
- uint32_t ring_size_bytes =
139
+ u64 ring_base;
140
+ u32 ring_size_bytes =
185141 ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size);
186142
187143 ring_size_bytes = ADF_RING_SIZE_BYTES_MIN(ring_size_bytes);
....@@ -216,7 +172,7 @@
216172
217173 static void adf_cleanup_ring(struct adf_etr_ring_data *ring)
218174 {
219
- uint32_t ring_size_bytes =
175
+ u32 ring_size_bytes =
220176 ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size);
221177 ring_size_bytes = ADF_RING_SIZE_BYTES_MIN(ring_size_bytes);
222178
....@@ -229,8 +185,8 @@
229185 }
230186
231187 int adf_create_ring(struct adf_accel_dev *accel_dev, const char *section,
232
- uint32_t bank_num, uint32_t num_msgs,
233
- uint32_t msg_size, const char *ring_name,
188
+ u32 bank_num, u32 num_msgs,
189
+ u32 msg_size, const char *ring_name,
234190 adf_callback_fn callback, int poll_mode,
235191 struct adf_etr_ring_data **ring_ptr)
236192 {
....@@ -238,7 +194,7 @@
238194 struct adf_etr_bank_data *bank;
239195 struct adf_etr_ring_data *ring;
240196 char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
241
- uint32_t ring_num;
197
+ u32 ring_num;
242198 int ret;
243199
244200 if (bank_num >= GET_MAX_BANKS(accel_dev)) {
....@@ -331,7 +287,7 @@
331287
332288 static void adf_ring_response_handler(struct adf_etr_bank_data *bank)
333289 {
334
- uint32_t empty_rings, i;
290
+ u32 empty_rings, i;
335291
336292 empty_rings = READ_CSR_E_STAT(bank->csr_addr, bank->bank_number);
337293 empty_rings = ~empty_rings & bank->irq_mask;
....@@ -354,7 +310,7 @@
354310
355311 static inline int adf_get_cfg_int(struct adf_accel_dev *accel_dev,
356312 const char *section, const char *format,
357
- uint32_t key, uint32_t *value)
313
+ u32 key, u32 *value)
358314 {
359315 char key_buf[ADF_CFG_MAX_KEY_LEN_IN_BYTES];
360316 char val_buf[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
....@@ -371,7 +327,7 @@
371327
372328 static void adf_get_coalesc_timer(struct adf_etr_bank_data *bank,
373329 const char *section,
374
- uint32_t bank_num_in_accel)
330
+ u32 bank_num_in_accel)
375331 {
376332 if (adf_get_cfg_int(bank->accel_dev, section,
377333 ADF_ETRMGR_COALESCE_TIMER_FORMAT,
....@@ -385,12 +341,12 @@
385341
386342 static int adf_init_bank(struct adf_accel_dev *accel_dev,
387343 struct adf_etr_bank_data *bank,
388
- uint32_t bank_num, void __iomem *csr_addr)
344
+ u32 bank_num, void __iomem *csr_addr)
389345 {
390346 struct adf_hw_device_data *hw_data = accel_dev->hw_device;
391347 struct adf_etr_ring_data *ring;
392348 struct adf_etr_ring_data *tx_ring;
393
- uint32_t i, coalesc_enabled = 0;
349
+ u32 i, coalesc_enabled = 0;
394350
395351 memset(bank, 0, sizeof(*bank));
396352 bank->bank_number = bank_num;
....@@ -462,8 +418,8 @@
462418 struct adf_etr_data *etr_data;
463419 struct adf_hw_device_data *hw_data = accel_dev->hw_device;
464420 void __iomem *csr_addr;
465
- uint32_t size;
466
- uint32_t num_banks = 0;
421
+ u32 size;
422
+ u32 num_banks = 0;
467423 int i, ret;
468424
469425 etr_data = kzalloc_node(sizeof(*etr_data), GFP_KERNEL,
....@@ -487,12 +443,6 @@
487443 /* accel_dev->debugfs_dir should always be non-NULL here */
488444 etr_data->debug = debugfs_create_dir("transport",
489445 accel_dev->debugfs_dir);
490
- if (!etr_data->debug) {
491
- dev_err(&GET_DEV(accel_dev),
492
- "Unable to create transport debugfs entry\n");
493
- ret = -ENOENT;
494
- goto err_bank_debug;
495
- }
496446
497447 for (i = 0; i < num_banks; i++) {
498448 ret = adf_init_bank(accel_dev, &etr_data->banks[i], i,
....@@ -505,7 +455,6 @@
505455
506456 err_bank_all:
507457 debugfs_remove(etr_data->debug);
508
-err_bank_debug:
509458 kfree(etr_data->banks);
510459 err_bank:
511460 kfree(etr_data);
....@@ -516,7 +465,7 @@
516465
517466 static void cleanup_bank(struct adf_etr_bank_data *bank)
518467 {
519
- uint32_t i;
468
+ u32 i;
520469
521470 for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) {
522471 struct adf_accel_dev *accel_dev = bank->accel_dev;
....@@ -536,7 +485,7 @@
536485 static void adf_cleanup_etr_handles(struct adf_accel_dev *accel_dev)
537486 {
538487 struct adf_etr_data *etr_data = accel_dev->transport;
539
- uint32_t i, num_banks = GET_MAX_BANKS(accel_dev);
488
+ u32 i, num_banks = GET_MAX_BANKS(accel_dev);
540489
541490 for (i = 0; i < num_banks; i++)
542491 cleanup_bank(&etr_data->banks[i]);