Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: qat - Intel(R) QAT transport code

This patch adds a code that implements communication channel between the
driver and the firmware.

Acked-by: John Griffin <john.griffin@intel.com>
Reviewed-by: Bruce W. Allan <bruce.w.allan@intel.com>
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Tadeusz Struk and committed by
Herbert Xu
a672a9dc d8cba25d

+1204
+565
drivers/crypto/qat/qat_common/adf_transport.c
··· 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 + */ 47 + #include <linux/delay.h> 48 + #include "adf_accel_devices.h" 49 + #include "adf_transport_internal.h" 50 + #include "adf_transport_access_macros.h" 51 + #include "adf_cfg.h" 52 + #include "adf_common_drv.h" 53 + 54 + static inline uint32_t adf_modulo(uint32_t data, uint32_t shift) 55 + { 56 + uint32_t div = data >> shift; 57 + uint32_t mult = div << shift; 58 + return data - mult; 59 + } 60 + 61 + static inline int adf_check_ring_alignment(uint64_t addr, uint64_t size) 62 + { 63 + if (((size - 1) & addr) != 0) 64 + return -EFAULT; 65 + return 0; 66 + } 67 + 68 + static int adf_verify_ring_size(uint32_t msg_size, uint32_t msg_num) 69 + { 70 + int i = ADF_MIN_RING_SIZE; 71 + for (; i <= ADF_MAX_RING_SIZE; i++) 72 + if ((msg_size * msg_num) == ADF_SIZE_TO_RING_SIZE_IN_BYTES(i)) 73 + return i; 74 + 75 + return ADF_DEFAULT_RING_SIZE; 76 + } 77 + 78 + static int adf_reserve_ring(struct adf_etr_bank_data *bank, uint32_t ring) 79 + { 80 + spin_lock(&bank->lock); 81 + if (bank->ring_mask & (1 << ring)) { 82 + spin_unlock(&bank->lock); 83 + return -EFAULT; 84 + } 85 + bank->ring_mask |= (1 << ring); 86 + spin_unlock(&bank->lock); 87 + return 0; 88 + } 89 + 90 + static void adf_unreserve_ring(struct adf_etr_bank_data *bank, uint32_t ring) 91 + { 92 + spin_lock(&bank->lock); 93 + bank->ring_mask &= ~(1 << ring); 94 + spin_unlock(&bank->lock); 95 + } 96 + 97 + static void adf_enable_ring_irq(struct adf_etr_bank_data *bank, uint32_t ring) 98 + { 99 + spin_lock_bh(&bank->lock); 100 + bank->irq_mask |= (1 << ring); 101 + spin_unlock_bh(&bank->lock); 102 + WRITE_CSR_INT_COL_EN(bank->csr_addr, bank->bank_number, bank->irq_mask); 103 + WRITE_CSR_INT_COL_CTL(bank->csr_addr, bank->bank_number, 104 + bank->irq_coalesc_timer); 105 + } 106 + 107 + static void adf_disable_ring_irq(struct adf_etr_bank_data *bank, uint32_t ring) 108 + { 109 + spin_lock_bh(&bank->lock); 110 + bank->irq_mask &= ~(1 << ring); 111 + spin_unlock_bh(&bank->lock); 112 + WRITE_CSR_INT_COL_EN(bank->csr_addr, bank->bank_number, bank->irq_mask); 113 + } 114 + 115 + int adf_send_message(struct adf_etr_ring_data *ring, uint32_t *msg) 116 + { 117 + if (atomic_add_return(1, ring->inflights) > 118 + ADF_MAX_INFLIGHTS(ring->ring_size, ring->msg_size)) { 119 + atomic_dec(ring->inflights); 120 + return -EAGAIN; 121 + } 122 + spin_lock_bh(&ring->lock); 123 + memcpy(ring->base_addr + ring->tail, msg, 124 + ADF_MSG_SIZE_TO_BYTES(ring->msg_size)); 125 + 126 + ring->tail = adf_modulo(ring->tail + 127 + ADF_MSG_SIZE_TO_BYTES(ring->msg_size), 128 + ADF_RING_SIZE_MODULO(ring->ring_size)); 129 + WRITE_CSR_RING_TAIL(ring->bank->csr_addr, ring->bank->bank_number, 130 + ring->ring_number, ring->tail); 131 + spin_unlock_bh(&ring->lock); 132 + return 0; 133 + } 134 + 135 + static int adf_handle_response(struct adf_etr_ring_data *ring) 136 + { 137 + uint32_t msg_counter = 0; 138 + uint32_t *msg = (uint32_t *)(ring->base_addr + ring->head); 139 + 140 + while (*msg != ADF_RING_EMPTY_SIG) { 141 + ring->callback((uint32_t *)msg); 142 + *msg = ADF_RING_EMPTY_SIG; 143 + ring->head = adf_modulo(ring->head + 144 + ADF_MSG_SIZE_TO_BYTES(ring->msg_size), 145 + ADF_RING_SIZE_MODULO(ring->ring_size)); 146 + msg_counter++; 147 + msg = (uint32_t *)(ring->base_addr + ring->head); 148 + } 149 + if (msg_counter > 0) { 150 + WRITE_CSR_RING_HEAD(ring->bank->csr_addr, 151 + ring->bank->bank_number, 152 + ring->ring_number, ring->head); 153 + atomic_sub(msg_counter, ring->inflights); 154 + } 155 + return 0; 156 + } 157 + 158 + static void adf_configure_tx_ring(struct adf_etr_ring_data *ring) 159 + { 160 + uint32_t ring_config = BUILD_RING_CONFIG(ring->ring_size); 161 + 162 + WRITE_CSR_RING_CONFIG(ring->bank->csr_addr, ring->bank->bank_number, 163 + ring->ring_number, ring_config); 164 + } 165 + 166 + static void adf_configure_rx_ring(struct adf_etr_ring_data *ring) 167 + { 168 + uint32_t ring_config = 169 + BUILD_RESP_RING_CONFIG(ring->ring_size, 170 + ADF_RING_NEAR_WATERMARK_512, 171 + ADF_RING_NEAR_WATERMARK_0); 172 + 173 + WRITE_CSR_RING_CONFIG(ring->bank->csr_addr, ring->bank->bank_number, 174 + ring->ring_number, ring_config); 175 + } 176 + 177 + static int adf_init_ring(struct adf_etr_ring_data *ring) 178 + { 179 + struct adf_etr_bank_data *bank = ring->bank; 180 + struct adf_accel_dev *accel_dev = bank->accel_dev; 181 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 182 + uint64_t ring_base; 183 + uint32_t ring_size_bytes = 184 + ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size); 185 + 186 + ring_size_bytes = ADF_RING_SIZE_BYTES_MIN(ring_size_bytes); 187 + ring->base_addr = dma_alloc_coherent(&GET_DEV(accel_dev), 188 + ring_size_bytes, &ring->dma_addr, 189 + GFP_KERNEL); 190 + if (!ring->base_addr) 191 + return -ENOMEM; 192 + 193 + memset(ring->base_addr, 0x7F, ring_size_bytes); 194 + /* The base_addr has to be aligned to the size of the buffer */ 195 + if (adf_check_ring_alignment(ring->dma_addr, ring_size_bytes)) { 196 + pr_err("QAT: Ring address not aligned\n"); 197 + dma_free_coherent(&GET_DEV(accel_dev), ring_size_bytes, 198 + ring->base_addr, ring->dma_addr); 199 + return -EFAULT; 200 + } 201 + 202 + if (hw_data->tx_rings_mask & (1 << ring->ring_number)) 203 + adf_configure_tx_ring(ring); 204 + 205 + else 206 + adf_configure_rx_ring(ring); 207 + 208 + ring_base = BUILD_RING_BASE_ADDR(ring->dma_addr, ring->ring_size); 209 + WRITE_CSR_RING_BASE(ring->bank->csr_addr, ring->bank->bank_number, 210 + ring->ring_number, ring_base); 211 + spin_lock_init(&ring->lock); 212 + return 0; 213 + } 214 + 215 + static void adf_cleanup_ring(struct adf_etr_ring_data *ring) 216 + { 217 + uint32_t ring_size_bytes = 218 + ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size); 219 + ring_size_bytes = ADF_RING_SIZE_BYTES_MIN(ring_size_bytes); 220 + 221 + if (ring->base_addr) { 222 + memset(ring->base_addr, 0x7F, ring_size_bytes); 223 + dma_free_coherent(&GET_DEV(ring->bank->accel_dev), 224 + ring_size_bytes, ring->base_addr, 225 + ring->dma_addr); 226 + } 227 + } 228 + 229 + int adf_create_ring(struct adf_accel_dev *accel_dev, const char *section, 230 + uint32_t bank_num, uint32_t num_msgs, 231 + uint32_t msg_size, const char *ring_name, 232 + adf_callback_fn callback, int poll_mode, 233 + struct adf_etr_ring_data **ring_ptr) 234 + { 235 + struct adf_etr_data *transport_data = accel_dev->transport; 236 + struct adf_etr_bank_data *bank; 237 + struct adf_etr_ring_data *ring; 238 + char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES]; 239 + uint32_t ring_num; 240 + int ret; 241 + 242 + if (bank_num >= GET_MAX_BANKS(accel_dev)) { 243 + pr_err("QAT: Invalid bank number\n"); 244 + return -EFAULT; 245 + } 246 + if (msg_size > ADF_MSG_SIZE_TO_BYTES(ADF_MAX_MSG_SIZE)) { 247 + pr_err("QAT: Invalid msg size\n"); 248 + return -EFAULT; 249 + } 250 + if (ADF_MAX_INFLIGHTS(adf_verify_ring_size(msg_size, num_msgs), 251 + ADF_BYTES_TO_MSG_SIZE(msg_size)) < 2) { 252 + pr_err("QAT: Invalid ring size for given msg size\n"); 253 + return -EFAULT; 254 + } 255 + if (adf_cfg_get_param_value(accel_dev, section, ring_name, val)) { 256 + pr_err("QAT: Section %s, no such entry : %s\n", 257 + section, ring_name); 258 + return -EFAULT; 259 + } 260 + if (kstrtouint(val, 10, &ring_num)) { 261 + pr_err("QAT: Can't get ring number\n"); 262 + return -EFAULT; 263 + } 264 + 265 + bank = &transport_data->banks[bank_num]; 266 + if (adf_reserve_ring(bank, ring_num)) { 267 + pr_err("QAT: Ring %d, %s already exists.\n", 268 + ring_num, ring_name); 269 + return -EFAULT; 270 + } 271 + ring = &bank->rings[ring_num]; 272 + ring->ring_number = ring_num; 273 + ring->bank = bank; 274 + ring->callback = callback; 275 + ring->msg_size = ADF_BYTES_TO_MSG_SIZE(msg_size); 276 + ring->ring_size = adf_verify_ring_size(msg_size, num_msgs); 277 + ring->head = 0; 278 + ring->tail = 0; 279 + atomic_set(ring->inflights, 0); 280 + ret = adf_init_ring(ring); 281 + if (ret) 282 + goto err; 283 + 284 + /* Enable HW arbitration for the given ring */ 285 + accel_dev->hw_device->hw_arb_ring_enable(ring); 286 + 287 + if (adf_ring_debugfs_add(ring, ring_name)) { 288 + pr_err("QAT: Couldn't add ring debugfs entry\n"); 289 + ret = -EFAULT; 290 + goto err; 291 + } 292 + 293 + /* Enable interrupts if needed */ 294 + if (callback && (!poll_mode)) 295 + adf_enable_ring_irq(bank, ring->ring_number); 296 + *ring_ptr = ring; 297 + return 0; 298 + err: 299 + adf_cleanup_ring(ring); 300 + adf_unreserve_ring(bank, ring_num); 301 + accel_dev->hw_device->hw_arb_ring_disable(ring); 302 + return ret; 303 + } 304 + 305 + void adf_remove_ring(struct adf_etr_ring_data *ring) 306 + { 307 + struct adf_etr_bank_data *bank = ring->bank; 308 + struct adf_accel_dev *accel_dev = bank->accel_dev; 309 + 310 + /* Disable interrupts for the given ring */ 311 + adf_disable_ring_irq(bank, ring->ring_number); 312 + 313 + /* Clear PCI config space */ 314 + WRITE_CSR_RING_CONFIG(bank->csr_addr, bank->bank_number, 315 + ring->ring_number, 0); 316 + WRITE_CSR_RING_BASE(bank->csr_addr, bank->bank_number, 317 + ring->ring_number, 0); 318 + adf_ring_debugfs_rm(ring); 319 + adf_unreserve_ring(bank, ring->ring_number); 320 + /* Disable HW arbitration for the given ring */ 321 + accel_dev->hw_device->hw_arb_ring_disable(ring); 322 + adf_cleanup_ring(ring); 323 + } 324 + 325 + static void adf_ring_response_handler(struct adf_etr_bank_data *bank) 326 + { 327 + uint32_t empty_rings, i; 328 + 329 + empty_rings = READ_CSR_E_STAT(bank->csr_addr, bank->bank_number); 330 + empty_rings = ~empty_rings & bank->irq_mask; 331 + 332 + for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; ++i) { 333 + if (empty_rings & (1 << i)) 334 + adf_handle_response(&bank->rings[i]); 335 + } 336 + } 337 + 338 + /** 339 + * adf_response_handler() - Bottom half handler response handler 340 + * @bank_addr: Address of a ring bank for with the BH was scheduled. 341 + * 342 + * Function is the bottom half handler for the response from acceleration 343 + * device. There is one handler for every ring bank. Function checks all 344 + * communication rings in the bank. 345 + * To be used by QAT device specific drivers. 346 + * 347 + * Return: void 348 + */ 349 + void adf_response_handler(unsigned long bank_addr) 350 + { 351 + struct adf_etr_bank_data *bank = (void *)bank_addr; 352 + 353 + /* Handle all the responses nad reenable IRQs */ 354 + adf_ring_response_handler(bank); 355 + WRITE_CSR_INT_FLAG_AND_COL(bank->csr_addr, bank->bank_number, 356 + bank->irq_mask); 357 + } 358 + EXPORT_SYMBOL_GPL(adf_response_handler); 359 + 360 + static inline int adf_get_cfg_int(struct adf_accel_dev *accel_dev, 361 + const char *section, const char *format, 362 + uint32_t key, uint32_t *value) 363 + { 364 + char key_buf[ADF_CFG_MAX_KEY_LEN_IN_BYTES]; 365 + char val_buf[ADF_CFG_MAX_VAL_LEN_IN_BYTES]; 366 + 367 + snprintf(key_buf, ADF_CFG_MAX_KEY_LEN_IN_BYTES, format, key); 368 + 369 + if (adf_cfg_get_param_value(accel_dev, section, key_buf, val_buf)) 370 + return -EFAULT; 371 + 372 + if (kstrtouint(val_buf, 10, value)) 373 + return -EFAULT; 374 + return 0; 375 + } 376 + 377 + static void adf_enable_coalesc(struct adf_etr_bank_data *bank, 378 + const char *section, uint32_t bank_num_in_accel) 379 + { 380 + if (adf_get_cfg_int(bank->accel_dev, section, 381 + ADF_ETRMGR_COALESCE_TIMER_FORMAT, 382 + bank_num_in_accel, &bank->irq_coalesc_timer)) 383 + bank->irq_coalesc_timer = ADF_COALESCING_DEF_TIME; 384 + 385 + if (ADF_COALESCING_MAX_TIME < bank->irq_coalesc_timer || 386 + ADF_COALESCING_MIN_TIME > bank->irq_coalesc_timer) 387 + bank->irq_coalesc_timer = ADF_COALESCING_DEF_TIME; 388 + } 389 + 390 + static int adf_init_bank(struct adf_accel_dev *accel_dev, 391 + struct adf_etr_bank_data *bank, 392 + uint32_t bank_num, void __iomem *csr_addr) 393 + { 394 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 395 + struct adf_etr_ring_data *ring; 396 + struct adf_etr_ring_data *tx_ring; 397 + uint32_t i, coalesc_enabled; 398 + 399 + memset(bank, 0, sizeof(*bank)); 400 + bank->bank_number = bank_num; 401 + bank->csr_addr = csr_addr; 402 + bank->accel_dev = accel_dev; 403 + spin_lock_init(&bank->lock); 404 + 405 + /* Enable IRQ coalescing always. This will allow to use 406 + * the optimised flag and coalesc register. 407 + * If it is disabled in the config file just use min time value */ 408 + if (adf_get_cfg_int(accel_dev, "Accelerator0", 409 + ADF_ETRMGR_COALESCING_ENABLED_FORMAT, 410 + bank_num, &coalesc_enabled) && coalesc_enabled) 411 + adf_enable_coalesc(bank, "Accelerator0", bank_num); 412 + else 413 + bank->irq_coalesc_timer = ADF_COALESCING_MIN_TIME; 414 + 415 + for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) { 416 + WRITE_CSR_RING_CONFIG(csr_addr, bank_num, i, 0); 417 + WRITE_CSR_RING_BASE(csr_addr, bank_num, i, 0); 418 + ring = &bank->rings[i]; 419 + if (hw_data->tx_rings_mask & (1 << i)) { 420 + ring->inflights = kzalloc_node(sizeof(atomic_t), 421 + GFP_KERNEL, 422 + accel_dev->numa_node); 423 + if (!ring->inflights) 424 + goto err; 425 + } else { 426 + if (i < hw_data->tx_rx_gap) { 427 + pr_err("QAT: Invalid tx rings mask config\n"); 428 + goto err; 429 + } 430 + tx_ring = &bank->rings[i - hw_data->tx_rx_gap]; 431 + ring->inflights = tx_ring->inflights; 432 + } 433 + } 434 + if (adf_bank_debugfs_add(bank)) { 435 + pr_err("QAT: Failed to add bank debugfs entry\n"); 436 + goto err; 437 + } 438 + 439 + WRITE_CSR_INT_SRCSEL(csr_addr, bank_num); 440 + return 0; 441 + err: 442 + for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) { 443 + ring = &bank->rings[i]; 444 + if (hw_data->tx_rings_mask & (1 << i) && ring->inflights) 445 + kfree(ring->inflights); 446 + } 447 + return -ENOMEM; 448 + } 449 + 450 + /** 451 + * adf_init_etr_data() - Initialize transport rings for acceleration device 452 + * @accel_dev: Pointer to acceleration device. 453 + * 454 + * Function is the initializes the communications channels (rings) to the 455 + * acceleration device accel_dev. 456 + * To be used by QAT device specific drivers. 457 + * 458 + * Return: 0 on success, error code othewise. 459 + */ 460 + int adf_init_etr_data(struct adf_accel_dev *accel_dev) 461 + { 462 + struct adf_etr_data *etr_data; 463 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 464 + void __iomem *csr_addr; 465 + uint32_t size; 466 + uint32_t num_banks = 0; 467 + int i, ret; 468 + 469 + etr_data = kzalloc_node(sizeof(*etr_data), GFP_KERNEL, 470 + accel_dev->numa_node); 471 + if (!etr_data) 472 + return -ENOMEM; 473 + 474 + num_banks = GET_MAX_BANKS(accel_dev); 475 + size = num_banks * sizeof(struct adf_etr_bank_data); 476 + etr_data->banks = kzalloc_node(size, GFP_KERNEL, accel_dev->numa_node); 477 + if (!etr_data->banks) { 478 + ret = -ENOMEM; 479 + goto err_bank; 480 + } 481 + 482 + accel_dev->transport = etr_data; 483 + i = hw_data->get_etr_bar_id(hw_data); 484 + csr_addr = accel_dev->accel_pci_dev.pci_bars[i].virt_addr; 485 + 486 + /* accel_dev->debugfs_dir should always be non-NULL here */ 487 + etr_data->debug = debugfs_create_dir("transport", 488 + accel_dev->debugfs_dir); 489 + if (!etr_data->debug) { 490 + pr_err("QAT: Unable to create transport debugfs entry\n"); 491 + ret = -ENOENT; 492 + goto err_bank_debug; 493 + } 494 + 495 + for (i = 0; i < num_banks; i++) { 496 + ret = adf_init_bank(accel_dev, &etr_data->banks[i], i, 497 + csr_addr); 498 + if (ret) 499 + goto err_bank_all; 500 + } 501 + 502 + return 0; 503 + 504 + err_bank_all: 505 + debugfs_remove(etr_data->debug); 506 + err_bank_debug: 507 + kfree(etr_data->banks); 508 + err_bank: 509 + kfree(etr_data); 510 + accel_dev->transport = NULL; 511 + return ret; 512 + } 513 + EXPORT_SYMBOL_GPL(adf_init_etr_data); 514 + 515 + static void cleanup_bank(struct adf_etr_bank_data *bank) 516 + { 517 + uint32_t i; 518 + 519 + for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) { 520 + struct adf_accel_dev *accel_dev = bank->accel_dev; 521 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 522 + struct adf_etr_ring_data *ring = &bank->rings[i]; 523 + 524 + if (bank->ring_mask & (1 << i)) 525 + adf_cleanup_ring(ring); 526 + 527 + if (hw_data->tx_rings_mask & (1 << i)) 528 + kfree(ring->inflights); 529 + } 530 + adf_bank_debugfs_rm(bank); 531 + memset(bank, 0, sizeof(*bank)); 532 + } 533 + 534 + static void adf_cleanup_etr_handles(struct adf_accel_dev *accel_dev) 535 + { 536 + struct adf_etr_data *etr_data = accel_dev->transport; 537 + uint32_t i, num_banks = GET_MAX_BANKS(accel_dev); 538 + 539 + for (i = 0; i < num_banks; i++) 540 + cleanup_bank(&etr_data->banks[i]); 541 + } 542 + 543 + /** 544 + * adf_cleanup_etr_data() - Clear transport rings for acceleration device 545 + * @accel_dev: Pointer to acceleration device. 546 + * 547 + * Function is the clears the communications channels (rings) of the 548 + * acceleration device accel_dev. 549 + * To be used by QAT device specific drivers. 550 + * 551 + * Return: void 552 + */ 553 + void adf_cleanup_etr_data(struct adf_accel_dev *accel_dev) 554 + { 555 + struct adf_etr_data *etr_data = accel_dev->transport; 556 + 557 + if (etr_data) { 558 + adf_cleanup_etr_handles(accel_dev); 559 + debugfs_remove(etr_data->debug); 560 + kfree(etr_data->banks); 561 + kfree(etr_data); 562 + accel_dev->transport = NULL; 563 + } 564 + } 565 + EXPORT_SYMBOL_GPL(adf_cleanup_etr_data);
+63
drivers/crypto/qat/qat_common/adf_transport.h
··· 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 + */ 47 + #ifndef ADF_TRANSPORT_H 48 + #define ADF_TRANSPORT_H 49 + 50 + #include "adf_accel_devices.h" 51 + 52 + struct adf_etr_ring_data; 53 + 54 + typedef void (*adf_callback_fn)(void *resp_msg); 55 + 56 + int adf_create_ring(struct adf_accel_dev *accel_dev, const char *section, 57 + uint32_t bank_num, uint32_t num_mgs, uint32_t msg_size, 58 + const char *ring_name, adf_callback_fn callback, 59 + int poll_mode, struct adf_etr_ring_data **ring_ptr); 60 + 61 + int adf_send_message(struct adf_etr_ring_data *ring, uint32_t *msg); 62 + void adf_remove_ring(struct adf_etr_ring_data *ring); 63 + #endif
+160
drivers/crypto/qat/qat_common/adf_transport_access_macros.h
··· 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 + */ 47 + #ifndef ADF_TRANSPORT_ACCESS_MACROS_H 48 + #define ADF_TRANSPORT_ACCESS_MACROS_H 49 + 50 + #include "adf_accel_devices.h" 51 + #define ADF_BANK_INT_SRC_SEL_MASK_0 0x4444444CUL 52 + #define ADF_BANK_INT_SRC_SEL_MASK_X 0x44444444UL 53 + #define ADF_RING_CSR_RING_CONFIG 0x000 54 + #define ADF_RING_CSR_RING_LBASE 0x040 55 + #define ADF_RING_CSR_RING_UBASE 0x080 56 + #define ADF_RING_CSR_RING_HEAD 0x0C0 57 + #define ADF_RING_CSR_RING_TAIL 0x100 58 + #define ADF_RING_CSR_E_STAT 0x14C 59 + #define ADF_RING_CSR_INT_SRCSEL 0x174 60 + #define ADF_RING_CSR_INT_SRCSEL_2 0x178 61 + #define ADF_RING_CSR_INT_COL_EN 0x17C 62 + #define ADF_RING_CSR_INT_COL_CTL 0x180 63 + #define ADF_RING_CSR_INT_FLAG_AND_COL 0x184 64 + #define ADF_RING_CSR_INT_COL_CTL_ENABLE 0x80000000 65 + #define ADF_RING_BUNDLE_SIZE 0x1000 66 + #define ADF_RING_CONFIG_NEAR_FULL_WM 0x0A 67 + #define ADF_RING_CONFIG_NEAR_EMPTY_WM 0x05 68 + #define ADF_COALESCING_MIN_TIME 0x1FF 69 + #define ADF_COALESCING_MAX_TIME 0xFFFFF 70 + #define ADF_COALESCING_DEF_TIME 0x27FF 71 + #define ADF_RING_NEAR_WATERMARK_512 0x08 72 + #define ADF_RING_NEAR_WATERMARK_0 0x00 73 + #define ADF_RING_EMPTY_SIG 0x7F7F7F7F 74 + 75 + /* Valid internal ring size values */ 76 + #define ADF_RING_SIZE_128 0x01 77 + #define ADF_RING_SIZE_256 0x02 78 + #define ADF_RING_SIZE_512 0x03 79 + #define ADF_RING_SIZE_4K 0x06 80 + #define ADF_RING_SIZE_16K 0x08 81 + #define ADF_RING_SIZE_4M 0x10 82 + #define ADF_MIN_RING_SIZE ADF_RING_SIZE_128 83 + #define ADF_MAX_RING_SIZE ADF_RING_SIZE_4M 84 + #define ADF_DEFAULT_RING_SIZE ADF_RING_SIZE_16K 85 + 86 + /* Valid internal msg size values internal */ 87 + #define ADF_MSG_SIZE_32 0x01 88 + #define ADF_MSG_SIZE_64 0x02 89 + #define ADF_MSG_SIZE_128 0x04 90 + #define ADF_MIN_MSG_SIZE ADF_MSG_SIZE_32 91 + #define ADF_MAX_MSG_SIZE ADF_MSG_SIZE_128 92 + 93 + /* Size to bytes conversion macros for ring and msg values */ 94 + #define ADF_MSG_SIZE_TO_BYTES(SIZE) (SIZE << 5) 95 + #define ADF_BYTES_TO_MSG_SIZE(SIZE) (SIZE >> 5) 96 + #define ADF_SIZE_TO_RING_SIZE_IN_BYTES(SIZE) ((1 << (SIZE - 1)) << 7) 97 + #define ADF_RING_SIZE_IN_BYTES_TO_SIZE(SIZE) ((1 << (SIZE - 1)) >> 7) 98 + 99 + /* Minimum ring bufer size for memory allocation */ 100 + #define ADF_RING_SIZE_BYTES_MIN(SIZE) ((SIZE < ADF_RING_SIZE_4K) ? \ 101 + ADF_RING_SIZE_4K : SIZE) 102 + #define ADF_RING_SIZE_MODULO(SIZE) (SIZE + 0x6) 103 + #define ADF_MAX_INFLIGHTS(RING_SIZE, MSG_SIZE) \ 104 + ((((1 << (RING_SIZE - 1)) << 4) >> MSG_SIZE) - 1) 105 + #define BUILD_RING_CONFIG(size) \ 106 + ((ADF_RING_NEAR_WATERMARK_0 << ADF_RING_CONFIG_NEAR_FULL_WM) \ 107 + | (ADF_RING_NEAR_WATERMARK_0 << ADF_RING_CONFIG_NEAR_EMPTY_WM) \ 108 + | size) 109 + #define BUILD_RESP_RING_CONFIG(size, watermark_nf, watermark_ne) \ 110 + ((watermark_nf << ADF_RING_CONFIG_NEAR_FULL_WM) \ 111 + | (watermark_ne << ADF_RING_CONFIG_NEAR_EMPTY_WM) \ 112 + | size) 113 + #define BUILD_RING_BASE_ADDR(addr, size) \ 114 + ((addr >> 6) & (0xFFFFFFFFFFFFFFFFULL << size)) 115 + #define READ_CSR_RING_HEAD(csr_base_addr, bank, ring) \ 116 + ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 117 + ADF_RING_CSR_RING_HEAD + (ring << 2)) 118 + #define READ_CSR_RING_TAIL(csr_base_addr, bank, ring) \ 119 + ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 120 + ADF_RING_CSR_RING_TAIL + (ring << 2)) 121 + #define READ_CSR_E_STAT(csr_base_addr, bank) \ 122 + ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 123 + ADF_RING_CSR_E_STAT) 124 + #define WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value) \ 125 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 126 + ADF_RING_CSR_RING_CONFIG + (ring << 2), value) 127 + #define WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, value) \ 128 + do { \ 129 + uint32_t l_base = 0, u_base = 0; \ 130 + l_base = (uint32_t)(value & 0xFFFFFFFF); \ 131 + u_base = (uint32_t)((value & 0xFFFFFFFF00000000ULL) >> 32); \ 132 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 133 + ADF_RING_CSR_RING_LBASE + (ring << 2), l_base); \ 134 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 135 + ADF_RING_CSR_RING_UBASE + (ring << 2), u_base); \ 136 + } while (0) 137 + #define WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value) \ 138 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 139 + ADF_RING_CSR_RING_HEAD + (ring << 2), value) 140 + #define WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value) \ 141 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 142 + ADF_RING_CSR_RING_TAIL + (ring << 2), value) 143 + #define WRITE_CSR_INT_SRCSEL(csr_base_addr, bank) \ 144 + do { \ 145 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 146 + ADF_RING_CSR_INT_SRCSEL, ADF_BANK_INT_SRC_SEL_MASK_0); \ 147 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 148 + ADF_RING_CSR_INT_SRCSEL_2, ADF_BANK_INT_SRC_SEL_MASK_X); \ 149 + } while (0) 150 + #define WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value) \ 151 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 152 + ADF_RING_CSR_INT_COL_EN, value) 153 + #define WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value) \ 154 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 155 + ADF_RING_CSR_INT_COL_CTL, \ 156 + ADF_RING_CSR_INT_COL_CTL_ENABLE | value) 157 + #define WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value) \ 158 + ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \ 159 + ADF_RING_CSR_INT_FLAG_AND_COL, value) 160 + #endif
+301
drivers/crypto/qat/qat_common/adf_transport_debug.c
··· 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 + */ 47 + #include <linux/mutex.h> 48 + #include <linux/slab.h> 49 + #include <linux/seq_file.h> 50 + #include "adf_accel_devices.h" 51 + #include "adf_transport_internal.h" 52 + #include "adf_transport_access_macros.h" 53 + 54 + static DEFINE_MUTEX(ring_read_lock); 55 + static DEFINE_MUTEX(bank_read_lock); 56 + 57 + static void *adf_ring_start(struct seq_file *sfile, loff_t *pos) 58 + { 59 + struct adf_etr_ring_data *ring = sfile->private; 60 + mutex_lock(&ring_read_lock); 61 + if (*pos == 0) 62 + return SEQ_START_TOKEN; 63 + 64 + if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) / 65 + ADF_MSG_SIZE_TO_BYTES(ring->msg_size))) 66 + return NULL; 67 + 68 + return ring->base_addr + 69 + (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++); 70 + } 71 + 72 + static void *adf_ring_next(struct seq_file *sfile, void *v, loff_t *pos) 73 + { 74 + struct adf_etr_ring_data *ring = sfile->private; 75 + 76 + if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) / 77 + ADF_MSG_SIZE_TO_BYTES(ring->msg_size))) 78 + return NULL; 79 + 80 + return ring->base_addr + 81 + (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++); 82 + } 83 + 84 + static int adf_ring_show(struct seq_file *sfile, void *v) 85 + { 86 + struct adf_etr_ring_data *ring = sfile->private; 87 + struct adf_etr_bank_data *bank = ring->bank; 88 + uint32_t *msg = v; 89 + void __iomem *csr = ring->bank->csr_addr; 90 + int i, x; 91 + 92 + if (v == SEQ_START_TOKEN) { 93 + int head, tail, empty; 94 + 95 + head = READ_CSR_RING_HEAD(csr, bank->bank_number, 96 + ring->ring_number); 97 + tail = READ_CSR_RING_TAIL(csr, bank->bank_number, 98 + ring->ring_number); 99 + empty = READ_CSR_E_STAT(csr, bank->bank_number); 100 + 101 + seq_puts(sfile, "------- Ring configuration -------\n"); 102 + seq_printf(sfile, "ring num %d, bank num %d\n", 103 + ring->ring_number, ring->bank->bank_number); 104 + seq_printf(sfile, "head %x, tail %x, empty: %d\n", 105 + head, tail, (empty & 1 << ring->ring_number) 106 + >> ring->ring_number); 107 + seq_printf(sfile, "ring size %d, msg size %d\n", 108 + ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size), 109 + ADF_MSG_SIZE_TO_BYTES(ring->msg_size)); 110 + seq_puts(sfile, "----------- Ring data ------------\n"); 111 + return 0; 112 + } 113 + seq_printf(sfile, "%p:", msg); 114 + x = 0; 115 + i = 0; 116 + for (; i < (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) >> 2); i++) { 117 + seq_printf(sfile, " %08X", *(msg + i)); 118 + if ((ADF_MSG_SIZE_TO_BYTES(ring->msg_size) >> 2) != i + 1 && 119 + (++x == 8)) { 120 + seq_printf(sfile, "\n%p:", msg + i + 1); 121 + x = 0; 122 + } 123 + } 124 + seq_puts(sfile, "\n"); 125 + return 0; 126 + } 127 + 128 + static void adf_ring_stop(struct seq_file *sfile, void *v) 129 + { 130 + mutex_unlock(&ring_read_lock); 131 + } 132 + 133 + static const struct seq_operations adf_ring_sops = { 134 + .start = adf_ring_start, 135 + .next = adf_ring_next, 136 + .stop = adf_ring_stop, 137 + .show = adf_ring_show 138 + }; 139 + 140 + static int adf_ring_open(struct inode *inode, struct file *file) 141 + { 142 + int ret = seq_open(file, &adf_ring_sops); 143 + 144 + if (!ret) { 145 + struct seq_file *seq_f = file->private_data; 146 + seq_f->private = inode->i_private; 147 + } 148 + return ret; 149 + } 150 + 151 + static const struct file_operations adf_ring_debug_fops = { 152 + .open = adf_ring_open, 153 + .read = seq_read, 154 + .llseek = seq_lseek, 155 + .release = seq_release 156 + }; 157 + 158 + int adf_ring_debugfs_add(struct adf_etr_ring_data *ring, const char *name) 159 + { 160 + struct adf_etr_ring_debug_entry *ring_debug; 161 + char entry_name[8]; 162 + 163 + ring_debug = kzalloc(sizeof(*ring_debug), GFP_KERNEL); 164 + if (!ring_debug) 165 + return -ENOMEM; 166 + 167 + strlcpy(ring_debug->ring_name, name, sizeof(ring_debug->ring_name)); 168 + snprintf(entry_name, sizeof(entry_name), "ring_%02d", 169 + ring->ring_number); 170 + 171 + ring_debug->debug = debugfs_create_file(entry_name, S_IRUSR, 172 + ring->bank->bank_debug_dir, 173 + ring, &adf_ring_debug_fops); 174 + if (!ring_debug->debug) { 175 + pr_err("QAT: Failed to create ring debug entry.\n"); 176 + kfree(ring_debug); 177 + return -EFAULT; 178 + } 179 + ring->ring_debug = ring_debug; 180 + return 0; 181 + } 182 + 183 + void adf_ring_debugfs_rm(struct adf_etr_ring_data *ring) 184 + { 185 + if (ring->ring_debug) { 186 + debugfs_remove(ring->ring_debug->debug); 187 + kfree(ring->ring_debug); 188 + ring->ring_debug = NULL; 189 + } 190 + } 191 + 192 + static void *adf_bank_start(struct seq_file *sfile, loff_t *pos) 193 + { 194 + mutex_lock(&bank_read_lock); 195 + if (*pos == 0) 196 + return SEQ_START_TOKEN; 197 + 198 + if (*pos >= ADF_ETR_MAX_RINGS_PER_BANK) 199 + return NULL; 200 + 201 + return pos; 202 + } 203 + 204 + static void *adf_bank_next(struct seq_file *sfile, void *v, loff_t *pos) 205 + { 206 + if (++(*pos) >= ADF_ETR_MAX_RINGS_PER_BANK) 207 + return NULL; 208 + 209 + return pos; 210 + } 211 + 212 + static int adf_bank_show(struct seq_file *sfile, void *v) 213 + { 214 + struct adf_etr_bank_data *bank = sfile->private; 215 + 216 + if (v == SEQ_START_TOKEN) { 217 + seq_printf(sfile, "------- Bank %d configuration -------\n", 218 + bank->bank_number); 219 + } else { 220 + int ring_id = *((int *)v) - 1; 221 + struct adf_etr_ring_data *ring = &bank->rings[ring_id]; 222 + void __iomem *csr = bank->csr_addr; 223 + int head, tail, empty; 224 + 225 + if (!(bank->ring_mask & 1 << ring_id)) 226 + return 0; 227 + 228 + head = READ_CSR_RING_HEAD(csr, bank->bank_number, 229 + ring->ring_number); 230 + tail = READ_CSR_RING_TAIL(csr, bank->bank_number, 231 + ring->ring_number); 232 + empty = READ_CSR_E_STAT(csr, bank->bank_number); 233 + 234 + seq_printf(sfile, 235 + "ring num %02d, head %04x, tail %04x, empty: %d\n", 236 + ring->ring_number, head, tail, 237 + (empty & 1 << ring->ring_number) >> 238 + ring->ring_number); 239 + } 240 + return 0; 241 + } 242 + 243 + static void adf_bank_stop(struct seq_file *sfile, void *v) 244 + { 245 + mutex_unlock(&bank_read_lock); 246 + } 247 + 248 + static const struct seq_operations adf_bank_sops = { 249 + .start = adf_bank_start, 250 + .next = adf_bank_next, 251 + .stop = adf_bank_stop, 252 + .show = adf_bank_show 253 + }; 254 + 255 + static int adf_bank_open(struct inode *inode, struct file *file) 256 + { 257 + int ret = seq_open(file, &adf_bank_sops); 258 + 259 + if (!ret) { 260 + struct seq_file *seq_f = file->private_data; 261 + seq_f->private = inode->i_private; 262 + } 263 + return ret; 264 + } 265 + 266 + static const struct file_operations adf_bank_debug_fops = { 267 + .open = adf_bank_open, 268 + .read = seq_read, 269 + .llseek = seq_lseek, 270 + .release = seq_release 271 + }; 272 + 273 + int adf_bank_debugfs_add(struct adf_etr_bank_data *bank) 274 + { 275 + struct adf_accel_dev *accel_dev = bank->accel_dev; 276 + struct dentry *parent = accel_dev->transport->debug; 277 + char name[8]; 278 + 279 + snprintf(name, sizeof(name), "bank_%02d", bank->bank_number); 280 + bank->bank_debug_dir = debugfs_create_dir(name, parent); 281 + if (!bank->bank_debug_dir) { 282 + pr_err("QAT: Failed to create bank debug dir.\n"); 283 + return -EFAULT; 284 + } 285 + 286 + bank->bank_debug_cfg = debugfs_create_file("config", S_IRUSR, 287 + bank->bank_debug_dir, bank, 288 + &adf_bank_debug_fops); 289 + if (!bank->bank_debug_cfg) { 290 + pr_err("QAT: Failed to create bank debug entry.\n"); 291 + debugfs_remove(bank->bank_debug_dir); 292 + return -EFAULT; 293 + } 294 + return 0; 295 + } 296 + 297 + void adf_bank_debugfs_rm(struct adf_etr_bank_data *bank) 298 + { 299 + debugfs_remove(bank->bank_debug_cfg); 300 + debugfs_remove(bank->bank_debug_dir); 301 + }
+115
drivers/crypto/qat/qat_common/adf_transport_internal.h
··· 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 + */ 47 + #ifndef ADF_TRANSPORT_INTRN_H 48 + #define ADF_TRANSPORT_INTRN_H 49 + 50 + #include <linux/interrupt.h> 51 + #include <linux/atomic.h> 52 + #include <linux/spinlock_types.h> 53 + #include "adf_transport.h" 54 + 55 + struct adf_etr_ring_debug_entry { 56 + char ring_name[ADF_CFG_MAX_KEY_LEN_IN_BYTES]; 57 + struct dentry *debug; 58 + }; 59 + 60 + struct adf_etr_ring_data { 61 + void *base_addr; 62 + atomic_t *inflights; 63 + spinlock_t lock; /* protects ring data struct */ 64 + adf_callback_fn callback; 65 + struct adf_etr_bank_data *bank; 66 + dma_addr_t dma_addr; 67 + uint16_t head; 68 + uint16_t tail; 69 + uint8_t ring_number; 70 + uint8_t ring_size; 71 + uint8_t msg_size; 72 + uint8_t reserved; 73 + struct adf_etr_ring_debug_entry *ring_debug; 74 + } __packed; 75 + 76 + struct adf_etr_bank_data { 77 + struct adf_etr_ring_data rings[ADF_ETR_MAX_RINGS_PER_BANK]; 78 + struct tasklet_struct resp_hanlder; 79 + void __iomem *csr_addr; 80 + struct adf_accel_dev *accel_dev; 81 + uint32_t irq_coalesc_timer; 82 + uint16_t ring_mask; 83 + uint16_t irq_mask; 84 + spinlock_t lock; /* protects bank data struct */ 85 + struct dentry *bank_debug_dir; 86 + struct dentry *bank_debug_cfg; 87 + uint32_t bank_number; 88 + } __packed; 89 + 90 + struct adf_etr_data { 91 + struct adf_etr_bank_data *banks; 92 + struct dentry *debug; 93 + }; 94 + 95 + void adf_response_handler(unsigned long bank_addr); 96 + #ifdef CONFIG_DEBUG_FS 97 + #include <linux/debugfs.h> 98 + int adf_bank_debugfs_add(struct adf_etr_bank_data *bank); 99 + void adf_bank_debugfs_rm(struct adf_etr_bank_data *bank); 100 + int adf_ring_debugfs_add(struct adf_etr_ring_data *ring, const char *name); 101 + void adf_ring_debugfs_rm(struct adf_etr_ring_data *ring); 102 + #else 103 + static inline int adf_bank_debugfs_add(struct adf_etr_bank_data *bank) 104 + { 105 + return 0; 106 + } 107 + #define adf_bank_debugfs_rm(bank) do {} while (0) 108 + static inline int adf_ring_debugfs_add(struct adf_etr_ring_data *ring, 109 + const char *name) 110 + { 111 + return 0; 112 + } 113 + #define adf_ring_debugfs_rm(ring) do {} while (0) 114 + #endif 115 + #endif