|
| 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 | + |
| 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_ACCEL_DEVICES_H_ |
| 48 | +#define ADF_ACCEL_DEVICES_H_ |
| 49 | +#include <linux/module.h> |
| 50 | +#include <linux/atomic.h> |
| 51 | +#include <linux/list.h> |
| 52 | +#include <linux/proc_fs.h> |
| 53 | +#include "adf_cfg_common.h" |
| 54 | + |
| 55 | +#define PCI_VENDOR_ID_INTEL 0x8086 |
| 56 | +#define ADF_DH895XCC_DEVICE_NAME "dh895xcc" |
| 57 | +#define ADF_DH895XCC_PCI_DEVICE_ID 0x435 |
| 58 | +#define ADF_DH895XCC_PMISC_BAR 1 |
| 59 | +#define ADF_DH895XCC_ETR_BAR 2 |
| 60 | +#define ADF_PCI_MAX_BARS 3 |
| 61 | +#define ADF_DEVICE_NAME_LENGTH 32 |
| 62 | +#define ADF_ETR_MAX_RINGS_PER_BANK 16 |
| 63 | +#define ADF_MAX_MSIX_VECTOR_NAME 16 |
| 64 | +#define ADF_DEVICE_NAME_PREFIX "qat_" |
| 65 | + |
| 66 | +enum adf_accel_capabilities { |
| 67 | + ADF_ACCEL_CAPABILITIES_NULL = 0, |
| 68 | + ADF_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC = 1, |
| 69 | + ADF_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC = 2, |
| 70 | + ADF_ACCEL_CAPABILITIES_CIPHER = 4, |
| 71 | + ADF_ACCEL_CAPABILITIES_AUTHENTICATION = 8, |
| 72 | + ADF_ACCEL_CAPABILITIES_COMPRESSION = 32, |
| 73 | + ADF_ACCEL_CAPABILITIES_LZS_COMPRESSION = 64, |
| 74 | + ADF_ACCEL_CAPABILITIES_RANDOM_NUMBER = 128 |
| 75 | +}; |
| 76 | + |
| 77 | +struct adf_bar { |
| 78 | + resource_size_t base_addr; |
| 79 | + void __iomem *virt_addr; |
| 80 | + resource_size_t size; |
| 81 | +} __packed; |
| 82 | + |
| 83 | +struct adf_accel_msix { |
| 84 | + struct msix_entry *entries; |
| 85 | + char **names; |
| 86 | +} __packed; |
| 87 | + |
| 88 | +struct adf_accel_pci { |
| 89 | + struct pci_dev *pci_dev; |
| 90 | + struct adf_accel_msix msix_entries; |
| 91 | + struct adf_bar pci_bars[ADF_PCI_MAX_BARS]; |
| 92 | + uint8_t revid; |
| 93 | + uint8_t sku; |
| 94 | +} __packed; |
| 95 | + |
| 96 | +enum dev_state { |
| 97 | + DEV_DOWN = 0, |
| 98 | + DEV_UP |
| 99 | +}; |
| 100 | + |
| 101 | +enum dev_sku_info { |
| 102 | + DEV_SKU_1 = 0, |
| 103 | + DEV_SKU_2, |
| 104 | + DEV_SKU_3, |
| 105 | + DEV_SKU_4, |
| 106 | + DEV_SKU_UNKNOWN, |
| 107 | +}; |
| 108 | + |
| 109 | +static inline const char *get_sku_info(enum dev_sku_info info) |
| 110 | +{ |
| 111 | + switch (info) { |
| 112 | + case DEV_SKU_1: |
| 113 | + return "SKU1"; |
| 114 | + case DEV_SKU_2: |
| 115 | + return "SKU2"; |
| 116 | + case DEV_SKU_3: |
| 117 | + return "SKU3"; |
| 118 | + case DEV_SKU_4: |
| 119 | + return "SKU4"; |
| 120 | + case DEV_SKU_UNKNOWN: |
| 121 | + default: |
| 122 | + break; |
| 123 | + } |
| 124 | + return "Unknown SKU"; |
| 125 | +} |
| 126 | + |
| 127 | +struct adf_hw_device_class { |
| 128 | + const char *name; |
| 129 | + const enum adf_device_type type; |
| 130 | + uint32_t instances; |
| 131 | +} __packed; |
| 132 | + |
| 133 | +struct adf_cfg_device_data; |
| 134 | +struct adf_accel_dev; |
| 135 | +struct adf_etr_data; |
| 136 | +struct adf_etr_ring_data; |
| 137 | + |
| 138 | +struct adf_hw_device_data { |
| 139 | + struct adf_hw_device_class *dev_class; |
| 140 | + uint32_t (*get_accel_mask)(uint32_t fuse); |
| 141 | + uint32_t (*get_ae_mask)(uint32_t fuse); |
| 142 | + uint32_t (*get_misc_bar_id)(struct adf_hw_device_data *self); |
| 143 | + uint32_t (*get_etr_bar_id)(struct adf_hw_device_data *self); |
| 144 | + uint32_t (*get_num_aes)(struct adf_hw_device_data *self); |
| 145 | + uint32_t (*get_num_accels)(struct adf_hw_device_data *self); |
| 146 | + enum dev_sku_info (*get_sku)(struct adf_hw_device_data *self); |
| 147 | + void (*hw_arb_ring_enable)(struct adf_etr_ring_data *ring); |
| 148 | + void (*hw_arb_ring_disable)(struct adf_etr_ring_data *ring); |
| 149 | + int (*alloc_irq)(struct adf_accel_dev *accel_dev); |
| 150 | + void (*free_irq)(struct adf_accel_dev *accel_dev); |
| 151 | + void (*enable_error_correction)(struct adf_accel_dev *accel_dev); |
| 152 | + const char *fw_name; |
| 153 | + uint32_t pci_dev_id; |
| 154 | + uint32_t fuses; |
| 155 | + uint32_t accel_capabilities_mask; |
| 156 | + uint16_t accel_mask; |
| 157 | + uint16_t ae_mask; |
| 158 | + uint16_t tx_rings_mask; |
| 159 | + uint8_t tx_rx_gap; |
| 160 | + uint8_t instance_id; |
| 161 | + uint8_t num_banks; |
| 162 | + uint8_t num_accel; |
| 163 | + uint8_t num_logical_accel; |
| 164 | + uint8_t num_engines; |
| 165 | +} __packed; |
| 166 | + |
| 167 | +/* CSR write macro */ |
| 168 | +#define ADF_CSR_WR(csr_base, csr_offset, val) \ |
| 169 | + __raw_writel(val, csr_base + csr_offset) |
| 170 | + |
| 171 | +/* CSR read macro */ |
| 172 | +#define ADF_CSR_RD(csr_base, csr_offset) __raw_readl(csr_base + csr_offset) |
| 173 | + |
| 174 | +#define GET_DEV(accel_dev) ((accel_dev)->accel_pci_dev.pci_dev->dev) |
| 175 | +#define GET_BARS(accel_dev) ((accel_dev)->accel_pci_dev.pci_bars) |
| 176 | +#define GET_HW_DATA(accel_dev) (accel_dev->hw_device) |
| 177 | +#define GET_MAX_BANKS(accel_dev) (GET_HW_DATA(accel_dev)->num_banks) |
| 178 | +#define GET_MAX_ACCELENGINES(accel_dev) (GET_HW_DATA(accel_dev)->num_engines) |
| 179 | +#define accel_to_pci_dev(accel_ptr) accel_ptr->accel_pci_dev.pci_dev |
| 180 | + |
| 181 | +struct adf_admin_comms; |
| 182 | +struct icp_qat_fw_loader_handle; |
| 183 | +struct adf_fw_loader_data { |
| 184 | + struct icp_qat_fw_loader_handle *fw_loader; |
| 185 | + const struct firmware *uof_fw; |
| 186 | +}; |
| 187 | + |
| 188 | +struct adf_accel_dev { |
| 189 | + struct adf_etr_data *transport; |
| 190 | + struct adf_hw_device_data *hw_device; |
| 191 | + struct adf_cfg_device_data *cfg; |
| 192 | + struct adf_fw_loader_data *fw_loader; |
| 193 | + struct adf_admin_comms *admin; |
| 194 | + struct list_head crypto_list; |
| 195 | + unsigned long status; |
| 196 | + atomic_t ref_count; |
| 197 | + struct dentry *debugfs_dir; |
| 198 | + struct list_head list; |
| 199 | + struct module *owner; |
| 200 | + uint8_t accel_id; |
| 201 | + uint8_t numa_node; |
| 202 | + struct adf_accel_pci accel_pci_dev; |
| 203 | +} __packed; |
| 204 | +#endif |
0 commit comments