Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* Copyright(c) 2019 Intel Corporation. All rights rsvd. */ |
| 3 | #include <linux/init.h> |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/slab.h> |
| 7 | #include <linux/pci.h> |
| 8 | #include <linux/interrupt.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/dma-mapping.h> |
| 11 | #include <linux/workqueue.h> |
| 12 | #include <linux/aer.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/io-64-nonatomic-lo-hi.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/idr.h> |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 17 | #include <linux/intel-svm.h> |
| 18 | #include <linux/iommu.h> |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 19 | #include <uapi/linux/idxd.h> |
Dave Jiang | 8f47d1a | 2020-01-21 16:44:23 -0700 | [diff] [blame] | 20 | #include <linux/dmaengine.h> |
| 21 | #include "../dmaengine.h" |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 22 | #include "registers.h" |
| 23 | #include "idxd.h" |
| 24 | |
| 25 | MODULE_VERSION(IDXD_DRIVER_VERSION); |
| 26 | MODULE_LICENSE("GPL v2"); |
| 27 | MODULE_AUTHOR("Intel Corporation"); |
| 28 | |
Dave Jiang | 03d939c | 2021-01-22 11:46:00 -0700 | [diff] [blame] | 29 | static bool sva = true; |
| 30 | module_param(sva, bool, 0644); |
| 31 | MODULE_PARM_DESC(sva, "Toggle SVA support on/off"); |
| 32 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 33 | #define DRV_NAME "idxd" |
| 34 | |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 35 | bool support_enqcmd; |
| 36 | |
Dave Jiang | f7f7739 | 2021-04-15 16:37:27 -0700 | [diff] [blame] | 37 | static struct ida idxd_idas[IDXD_TYPE_MAX]; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 38 | |
| 39 | static struct pci_device_id idxd_pci_tbl[] = { |
| 40 | /* DSA ver 1.0 platforms */ |
| 41 | { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_DSA_SPR0) }, |
Dave Jiang | f25b4638 | 2020-11-17 13:39:14 -0700 | [diff] [blame] | 42 | |
| 43 | /* IAX ver 1.0 platforms */ |
| 44 | { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IAX_SPR0) }, |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 45 | { 0, } |
| 46 | }; |
| 47 | MODULE_DEVICE_TABLE(pci, idxd_pci_tbl); |
| 48 | |
| 49 | static char *idxd_name[] = { |
| 50 | "dsa", |
Dave Jiang | f25b4638 | 2020-11-17 13:39:14 -0700 | [diff] [blame] | 51 | "iax" |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 54 | struct ida *idxd_ida(struct idxd_device *idxd) |
| 55 | { |
| 56 | return &idxd_idas[idxd->type]; |
| 57 | } |
| 58 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 59 | const char *idxd_get_dev_name(struct idxd_device *idxd) |
| 60 | { |
| 61 | return idxd_name[idxd->type]; |
| 62 | } |
| 63 | |
| 64 | static int idxd_setup_interrupts(struct idxd_device *idxd) |
| 65 | { |
| 66 | struct pci_dev *pdev = idxd->pdev; |
| 67 | struct device *dev = &pdev->dev; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 68 | struct idxd_irq_entry *irq_entry; |
| 69 | int i, msixcnt; |
| 70 | int rc = 0; |
| 71 | |
| 72 | msixcnt = pci_msix_vec_count(pdev); |
| 73 | if (msixcnt < 0) { |
| 74 | dev_err(dev, "Not MSI-X interrupt capable.\n"); |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 75 | return -ENOSPC; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 78 | rc = pci_alloc_irq_vectors(pdev, msixcnt, msixcnt, PCI_IRQ_MSIX); |
| 79 | if (rc != msixcnt) { |
| 80 | dev_err(dev, "Failed enabling %d MSIX entries: %d\n", msixcnt, rc); |
| 81 | return -ENOSPC; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 82 | } |
| 83 | dev_dbg(dev, "Enabled %d msix vectors\n", msixcnt); |
| 84 | |
| 85 | /* |
| 86 | * We implement 1 completion list per MSI-X entry except for |
| 87 | * entry 0, which is for errors and others. |
| 88 | */ |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 89 | idxd->irq_entries = kcalloc_node(msixcnt, sizeof(struct idxd_irq_entry), |
| 90 | GFP_KERNEL, dev_to_node(dev)); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 91 | if (!idxd->irq_entries) { |
| 92 | rc = -ENOMEM; |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 93 | goto err_irq_entries; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | for (i = 0; i < msixcnt; i++) { |
| 97 | idxd->irq_entries[i].id = i; |
| 98 | idxd->irq_entries[i].idxd = idxd; |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 99 | idxd->irq_entries[i].vector = pci_irq_vector(pdev, i); |
Dave Jiang | e4f4d8c | 2020-10-27 10:34:40 -0700 | [diff] [blame] | 100 | spin_lock_init(&idxd->irq_entries[i].list_lock); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 103 | irq_entry = &idxd->irq_entries[0]; |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 104 | rc = request_threaded_irq(irq_entry->vector, idxd_irq_handler, idxd_misc_thread, |
| 105 | 0, "idxd-misc", irq_entry); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 106 | if (rc < 0) { |
| 107 | dev_err(dev, "Failed to allocate misc interrupt.\n"); |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 108 | goto err_misc_irq; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 111 | dev_dbg(dev, "Allocated idxd-misc handler on msix vector %d\n", irq_entry->vector); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 112 | |
| 113 | /* first MSI-X entry is not for wq interrupts */ |
| 114 | idxd->num_wq_irqs = msixcnt - 1; |
| 115 | |
| 116 | for (i = 1; i < msixcnt; i++) { |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 117 | irq_entry = &idxd->irq_entries[i]; |
| 118 | |
| 119 | init_llist_head(&idxd->irq_entries[i].pending_llist); |
| 120 | INIT_LIST_HEAD(&idxd->irq_entries[i].work_list); |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 121 | rc = request_threaded_irq(irq_entry->vector, idxd_irq_handler, |
| 122 | idxd_wq_thread, 0, "idxd-portal", irq_entry); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 123 | if (rc < 0) { |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 124 | dev_err(dev, "Failed to allocate irq %d.\n", irq_entry->vector); |
| 125 | goto err_wq_irqs; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 126 | } |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 127 | dev_dbg(dev, "Allocated idxd-msix %d for vector %d\n", i, irq_entry->vector); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | idxd_unmask_error_interrupts(idxd); |
Dave Jiang | 6df0e6c | 2021-04-12 09:23:27 -0700 | [diff] [blame] | 131 | idxd_msix_perm_setup(idxd); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 132 | return 0; |
| 133 | |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 134 | err_wq_irqs: |
| 135 | while (--i >= 0) { |
| 136 | irq_entry = &idxd->irq_entries[i]; |
| 137 | free_irq(irq_entry->vector, irq_entry); |
| 138 | } |
| 139 | err_misc_irq: |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 140 | /* Disable error interrupt generation */ |
| 141 | idxd_mask_error_interrupts(idxd); |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 142 | err_irq_entries: |
| 143 | pci_free_irq_vectors(pdev); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 144 | dev_err(dev, "No usable interrupts\n"); |
| 145 | return rc; |
| 146 | } |
| 147 | |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 148 | static int idxd_setup_wqs(struct idxd_device *idxd) |
| 149 | { |
| 150 | struct device *dev = &idxd->pdev->dev; |
| 151 | struct idxd_wq *wq; |
| 152 | int i, rc; |
| 153 | |
| 154 | idxd->wqs = kcalloc_node(idxd->max_wqs, sizeof(struct idxd_wq *), |
| 155 | GFP_KERNEL, dev_to_node(dev)); |
| 156 | if (!idxd->wqs) |
| 157 | return -ENOMEM; |
| 158 | |
| 159 | for (i = 0; i < idxd->max_wqs; i++) { |
| 160 | wq = kzalloc_node(sizeof(*wq), GFP_KERNEL, dev_to_node(dev)); |
| 161 | if (!wq) { |
| 162 | rc = -ENOMEM; |
| 163 | goto err; |
| 164 | } |
| 165 | |
| 166 | wq->id = i; |
| 167 | wq->idxd = idxd; |
| 168 | device_initialize(&wq->conf_dev); |
| 169 | wq->conf_dev.parent = &idxd->conf_dev; |
| 170 | wq->conf_dev.bus = idxd_get_bus_type(idxd); |
| 171 | wq->conf_dev.type = &idxd_wq_device_type; |
| 172 | rc = dev_set_name(&wq->conf_dev, "wq%d.%d", idxd->id, wq->id); |
| 173 | if (rc < 0) { |
| 174 | put_device(&wq->conf_dev); |
| 175 | goto err; |
| 176 | } |
| 177 | |
| 178 | mutex_init(&wq->wq_lock); |
Dave Jiang | 04922b7 | 2021-04-15 16:37:57 -0700 | [diff] [blame^] | 179 | init_waitqueue_head(&wq->err_queue); |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 180 | wq->max_xfer_bytes = idxd->max_xfer_bytes; |
| 181 | wq->max_batch_size = idxd->max_batch_size; |
| 182 | wq->wqcfg = kzalloc_node(idxd->wqcfg_size, GFP_KERNEL, dev_to_node(dev)); |
| 183 | if (!wq->wqcfg) { |
| 184 | put_device(&wq->conf_dev); |
| 185 | rc = -ENOMEM; |
| 186 | goto err; |
| 187 | } |
| 188 | idxd->wqs[i] = wq; |
| 189 | } |
| 190 | |
| 191 | return 0; |
| 192 | |
| 193 | err: |
| 194 | while (--i >= 0) |
| 195 | put_device(&idxd->wqs[i]->conf_dev); |
| 196 | return rc; |
| 197 | } |
| 198 | |
Dave Jiang | 75b9113 | 2021-04-15 16:37:44 -0700 | [diff] [blame] | 199 | static int idxd_setup_engines(struct idxd_device *idxd) |
| 200 | { |
| 201 | struct idxd_engine *engine; |
| 202 | struct device *dev = &idxd->pdev->dev; |
| 203 | int i, rc; |
| 204 | |
| 205 | idxd->engines = kcalloc_node(idxd->max_engines, sizeof(struct idxd_engine *), |
| 206 | GFP_KERNEL, dev_to_node(dev)); |
| 207 | if (!idxd->engines) |
| 208 | return -ENOMEM; |
| 209 | |
| 210 | for (i = 0; i < idxd->max_engines; i++) { |
| 211 | engine = kzalloc_node(sizeof(*engine), GFP_KERNEL, dev_to_node(dev)); |
| 212 | if (!engine) { |
| 213 | rc = -ENOMEM; |
| 214 | goto err; |
| 215 | } |
| 216 | |
| 217 | engine->id = i; |
| 218 | engine->idxd = idxd; |
| 219 | device_initialize(&engine->conf_dev); |
| 220 | engine->conf_dev.parent = &idxd->conf_dev; |
| 221 | engine->conf_dev.type = &idxd_engine_device_type; |
| 222 | rc = dev_set_name(&engine->conf_dev, "engine%d.%d", idxd->id, engine->id); |
| 223 | if (rc < 0) { |
| 224 | put_device(&engine->conf_dev); |
| 225 | goto err; |
| 226 | } |
| 227 | |
| 228 | idxd->engines[i] = engine; |
| 229 | } |
| 230 | |
| 231 | return 0; |
| 232 | |
| 233 | err: |
| 234 | while (--i >= 0) |
| 235 | put_device(&idxd->engines[i]->conf_dev); |
| 236 | return rc; |
| 237 | } |
| 238 | |
Dave Jiang | defe49f | 2021-04-15 16:37:51 -0700 | [diff] [blame] | 239 | static int idxd_setup_groups(struct idxd_device *idxd) |
| 240 | { |
| 241 | struct device *dev = &idxd->pdev->dev; |
| 242 | struct idxd_group *group; |
| 243 | int i, rc; |
| 244 | |
| 245 | idxd->groups = kcalloc_node(idxd->max_groups, sizeof(struct idxd_group *), |
| 246 | GFP_KERNEL, dev_to_node(dev)); |
| 247 | if (!idxd->groups) |
| 248 | return -ENOMEM; |
| 249 | |
| 250 | for (i = 0; i < idxd->max_groups; i++) { |
| 251 | group = kzalloc_node(sizeof(*group), GFP_KERNEL, dev_to_node(dev)); |
| 252 | if (!group) { |
| 253 | rc = -ENOMEM; |
| 254 | goto err; |
| 255 | } |
| 256 | |
| 257 | group->id = i; |
| 258 | group->idxd = idxd; |
| 259 | device_initialize(&group->conf_dev); |
| 260 | group->conf_dev.parent = &idxd->conf_dev; |
| 261 | group->conf_dev.bus = idxd_get_bus_type(idxd); |
| 262 | group->conf_dev.type = &idxd_group_device_type; |
| 263 | rc = dev_set_name(&group->conf_dev, "group%d.%d", idxd->id, group->id); |
| 264 | if (rc < 0) { |
| 265 | put_device(&group->conf_dev); |
| 266 | goto err; |
| 267 | } |
| 268 | |
| 269 | idxd->groups[i] = group; |
| 270 | group->tc_a = -1; |
| 271 | group->tc_b = -1; |
| 272 | } |
| 273 | |
| 274 | return 0; |
| 275 | |
| 276 | err: |
| 277 | while (--i >= 0) |
| 278 | put_device(&idxd->groups[i]->conf_dev); |
| 279 | return rc; |
| 280 | } |
| 281 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 282 | static int idxd_setup_internals(struct idxd_device *idxd) |
| 283 | { |
| 284 | struct device *dev = &idxd->pdev->dev; |
Dave Jiang | defe49f | 2021-04-15 16:37:51 -0700 | [diff] [blame] | 285 | int rc, i; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 286 | |
Dave Jiang | 0d5c10b | 2020-06-26 11:11:18 -0700 | [diff] [blame] | 287 | init_waitqueue_head(&idxd->cmd_waitq); |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 288 | |
| 289 | rc = idxd_setup_wqs(idxd); |
| 290 | if (rc < 0) |
| 291 | return rc; |
| 292 | |
Dave Jiang | 75b9113 | 2021-04-15 16:37:44 -0700 | [diff] [blame] | 293 | rc = idxd_setup_engines(idxd); |
| 294 | if (rc < 0) |
| 295 | goto err_engine; |
| 296 | |
Dave Jiang | defe49f | 2021-04-15 16:37:51 -0700 | [diff] [blame] | 297 | rc = idxd_setup_groups(idxd); |
| 298 | if (rc < 0) |
| 299 | goto err_group; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 300 | |
Dave Jiang | 0d5c10b | 2020-06-26 11:11:18 -0700 | [diff] [blame] | 301 | idxd->wq = create_workqueue(dev_name(dev)); |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 302 | if (!idxd->wq) { |
| 303 | rc = -ENOMEM; |
Dave Jiang | defe49f | 2021-04-15 16:37:51 -0700 | [diff] [blame] | 304 | goto err_wkq_create; |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 305 | } |
Dave Jiang | 0d5c10b | 2020-06-26 11:11:18 -0700 | [diff] [blame] | 306 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 307 | return 0; |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 308 | |
Dave Jiang | defe49f | 2021-04-15 16:37:51 -0700 | [diff] [blame] | 309 | err_wkq_create: |
| 310 | for (i = 0; i < idxd->max_groups; i++) |
| 311 | put_device(&idxd->groups[i]->conf_dev); |
| 312 | err_group: |
Dave Jiang | 75b9113 | 2021-04-15 16:37:44 -0700 | [diff] [blame] | 313 | for (i = 0; i < idxd->max_engines; i++) |
| 314 | put_device(&idxd->engines[i]->conf_dev); |
| 315 | err_engine: |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 316 | for (i = 0; i < idxd->max_wqs; i++) |
| 317 | put_device(&idxd->wqs[i]->conf_dev); |
| 318 | return rc; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static void idxd_read_table_offsets(struct idxd_device *idxd) |
| 322 | { |
| 323 | union offsets_reg offsets; |
| 324 | struct device *dev = &idxd->pdev->dev; |
| 325 | |
| 326 | offsets.bits[0] = ioread64(idxd->reg_base + IDXD_TABLE_OFFSET); |
Dave Jiang | 2f8417a | 2020-10-30 08:51:56 -0700 | [diff] [blame] | 327 | offsets.bits[1] = ioread64(idxd->reg_base + IDXD_TABLE_OFFSET + sizeof(u64)); |
| 328 | idxd->grpcfg_offset = offsets.grpcfg * IDXD_TABLE_MULT; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 329 | dev_dbg(dev, "IDXD Group Config Offset: %#x\n", idxd->grpcfg_offset); |
Dave Jiang | 2f8417a | 2020-10-30 08:51:56 -0700 | [diff] [blame] | 330 | idxd->wqcfg_offset = offsets.wqcfg * IDXD_TABLE_MULT; |
| 331 | dev_dbg(dev, "IDXD Work Queue Config Offset: %#x\n", idxd->wqcfg_offset); |
| 332 | idxd->msix_perm_offset = offsets.msix_perm * IDXD_TABLE_MULT; |
| 333 | dev_dbg(dev, "IDXD MSIX Permission Offset: %#x\n", idxd->msix_perm_offset); |
| 334 | idxd->perfmon_offset = offsets.perfmon * IDXD_TABLE_MULT; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 335 | dev_dbg(dev, "IDXD Perfmon Offset: %#x\n", idxd->perfmon_offset); |
| 336 | } |
| 337 | |
| 338 | static void idxd_read_caps(struct idxd_device *idxd) |
| 339 | { |
| 340 | struct device *dev = &idxd->pdev->dev; |
| 341 | int i; |
| 342 | |
| 343 | /* reading generic capabilities */ |
| 344 | idxd->hw.gen_cap.bits = ioread64(idxd->reg_base + IDXD_GENCAP_OFFSET); |
| 345 | dev_dbg(dev, "gen_cap: %#llx\n", idxd->hw.gen_cap.bits); |
| 346 | idxd->max_xfer_bytes = 1ULL << idxd->hw.gen_cap.max_xfer_shift; |
| 347 | dev_dbg(dev, "max xfer size: %llu bytes\n", idxd->max_xfer_bytes); |
| 348 | idxd->max_batch_size = 1U << idxd->hw.gen_cap.max_batch_shift; |
| 349 | dev_dbg(dev, "max batch size: %u\n", idxd->max_batch_size); |
| 350 | if (idxd->hw.gen_cap.config_en) |
| 351 | set_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags); |
| 352 | |
| 353 | /* reading group capabilities */ |
| 354 | idxd->hw.group_cap.bits = |
| 355 | ioread64(idxd->reg_base + IDXD_GRPCAP_OFFSET); |
| 356 | dev_dbg(dev, "group_cap: %#llx\n", idxd->hw.group_cap.bits); |
| 357 | idxd->max_groups = idxd->hw.group_cap.num_groups; |
| 358 | dev_dbg(dev, "max groups: %u\n", idxd->max_groups); |
| 359 | idxd->max_tokens = idxd->hw.group_cap.total_tokens; |
| 360 | dev_dbg(dev, "max tokens: %u\n", idxd->max_tokens); |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 361 | idxd->nr_tokens = idxd->max_tokens; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 362 | |
| 363 | /* read engine capabilities */ |
| 364 | idxd->hw.engine_cap.bits = |
| 365 | ioread64(idxd->reg_base + IDXD_ENGCAP_OFFSET); |
| 366 | dev_dbg(dev, "engine_cap: %#llx\n", idxd->hw.engine_cap.bits); |
| 367 | idxd->max_engines = idxd->hw.engine_cap.num_engines; |
| 368 | dev_dbg(dev, "max engines: %u\n", idxd->max_engines); |
| 369 | |
| 370 | /* read workqueue capabilities */ |
| 371 | idxd->hw.wq_cap.bits = ioread64(idxd->reg_base + IDXD_WQCAP_OFFSET); |
| 372 | dev_dbg(dev, "wq_cap: %#llx\n", idxd->hw.wq_cap.bits); |
| 373 | idxd->max_wq_size = idxd->hw.wq_cap.total_wq_size; |
| 374 | dev_dbg(dev, "total workqueue size: %u\n", idxd->max_wq_size); |
| 375 | idxd->max_wqs = idxd->hw.wq_cap.num_wqs; |
| 376 | dev_dbg(dev, "max workqueues: %u\n", idxd->max_wqs); |
Dave Jiang | d98793b | 2020-10-27 14:34:09 -0700 | [diff] [blame] | 377 | idxd->wqcfg_size = 1 << (idxd->hw.wq_cap.wqcfg_size + IDXD_WQCFG_MIN); |
| 378 | dev_dbg(dev, "wqcfg size: %u\n", idxd->wqcfg_size); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 379 | |
| 380 | /* reading operation capabilities */ |
| 381 | for (i = 0; i < 4; i++) { |
| 382 | idxd->hw.opcap.bits[i] = ioread64(idxd->reg_base + |
| 383 | IDXD_OPCAP_OFFSET + i * sizeof(u64)); |
| 384 | dev_dbg(dev, "opcap[%d]: %#llx\n", i, idxd->hw.opcap.bits[i]); |
| 385 | } |
| 386 | } |
| 387 | |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 388 | static inline void idxd_set_type(struct idxd_device *idxd) |
| 389 | { |
| 390 | struct pci_dev *pdev = idxd->pdev; |
| 391 | |
| 392 | if (pdev->device == PCI_DEVICE_ID_INTEL_DSA_SPR0) |
| 393 | idxd->type = IDXD_TYPE_DSA; |
| 394 | else if (pdev->device == PCI_DEVICE_ID_INTEL_IAX_SPR0) |
| 395 | idxd->type = IDXD_TYPE_IAX; |
| 396 | else |
| 397 | idxd->type = IDXD_TYPE_UNKNOWN; |
| 398 | } |
| 399 | |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 400 | static struct idxd_device *idxd_alloc(struct pci_dev *pdev) |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 401 | { |
| 402 | struct device *dev = &pdev->dev; |
| 403 | struct idxd_device *idxd; |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 404 | int rc; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 405 | |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 406 | idxd = kzalloc_node(sizeof(*idxd), GFP_KERNEL, dev_to_node(dev)); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 407 | if (!idxd) |
| 408 | return NULL; |
| 409 | |
| 410 | idxd->pdev = pdev; |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 411 | idxd_set_type(idxd); |
| 412 | idxd->id = ida_alloc(idxd_ida(idxd), GFP_KERNEL); |
| 413 | if (idxd->id < 0) |
| 414 | return NULL; |
| 415 | |
| 416 | device_initialize(&idxd->conf_dev); |
| 417 | idxd->conf_dev.parent = dev; |
| 418 | idxd->conf_dev.bus = idxd_get_bus_type(idxd); |
| 419 | idxd->conf_dev.type = idxd_get_device_type(idxd); |
| 420 | rc = dev_set_name(&idxd->conf_dev, "%s%d", idxd_get_dev_name(idxd), idxd->id); |
| 421 | if (rc < 0) { |
| 422 | put_device(&idxd->conf_dev); |
| 423 | return NULL; |
| 424 | } |
| 425 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 426 | spin_lock_init(&idxd->dev_lock); |
| 427 | |
| 428 | return idxd; |
| 429 | } |
| 430 | |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 431 | static int idxd_enable_system_pasid(struct idxd_device *idxd) |
| 432 | { |
| 433 | int flags; |
| 434 | unsigned int pasid; |
| 435 | struct iommu_sva *sva; |
| 436 | |
| 437 | flags = SVM_FLAG_SUPERVISOR_MODE; |
| 438 | |
| 439 | sva = iommu_sva_bind_device(&idxd->pdev->dev, NULL, &flags); |
| 440 | if (IS_ERR(sva)) { |
| 441 | dev_warn(&idxd->pdev->dev, |
| 442 | "iommu sva bind failed: %ld\n", PTR_ERR(sva)); |
| 443 | return PTR_ERR(sva); |
| 444 | } |
| 445 | |
| 446 | pasid = iommu_sva_get_pasid(sva); |
| 447 | if (pasid == IOMMU_PASID_INVALID) { |
| 448 | iommu_sva_unbind_device(sva); |
| 449 | return -ENODEV; |
| 450 | } |
| 451 | |
| 452 | idxd->sva = sva; |
| 453 | idxd->pasid = pasid; |
| 454 | dev_dbg(&idxd->pdev->dev, "system pasid: %u\n", pasid); |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static void idxd_disable_system_pasid(struct idxd_device *idxd) |
| 459 | { |
| 460 | |
| 461 | iommu_sva_unbind_device(idxd->sva); |
| 462 | idxd->sva = NULL; |
| 463 | } |
| 464 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 465 | static int idxd_probe(struct idxd_device *idxd) |
| 466 | { |
| 467 | struct pci_dev *pdev = idxd->pdev; |
| 468 | struct device *dev = &pdev->dev; |
| 469 | int rc; |
| 470 | |
| 471 | dev_dbg(dev, "%s entered and resetting device\n", __func__); |
Dave Jiang | 89e3bec | 2021-02-01 08:26:14 -0700 | [diff] [blame] | 472 | rc = idxd_device_init_reset(idxd); |
| 473 | if (rc < 0) |
| 474 | return rc; |
| 475 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 476 | dev_dbg(dev, "IDXD reset complete\n"); |
| 477 | |
Dave Jiang | 03d939c | 2021-01-22 11:46:00 -0700 | [diff] [blame] | 478 | if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) && sva) { |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 479 | rc = idxd_enable_system_pasid(idxd); |
| 480 | if (rc < 0) |
| 481 | dev_warn(dev, "Failed to enable PASID. No SVA support: %d\n", rc); |
| 482 | else |
| 483 | set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags); |
Dave Jiang | 03d939c | 2021-01-22 11:46:00 -0700 | [diff] [blame] | 484 | } else if (!sva) { |
| 485 | dev_warn(dev, "User forced SVA off via module param.\n"); |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 488 | idxd_read_caps(idxd); |
| 489 | idxd_read_table_offsets(idxd); |
| 490 | |
| 491 | rc = idxd_setup_internals(idxd); |
| 492 | if (rc) |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 493 | goto err; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 494 | |
| 495 | rc = idxd_setup_interrupts(idxd); |
| 496 | if (rc) |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 497 | goto err; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 498 | |
| 499 | dev_dbg(dev, "IDXD interrupt setup complete.\n"); |
| 500 | |
Dave Jiang | 42d279f | 2020-01-21 16:44:29 -0700 | [diff] [blame] | 501 | idxd->major = idxd_cdev_get_major(idxd); |
| 502 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 503 | dev_dbg(dev, "IDXD device %d probed successfully\n", idxd->id); |
| 504 | return 0; |
| 505 | |
Dave Jiang | 7c5dd23 | 2021-04-15 16:37:39 -0700 | [diff] [blame] | 506 | err: |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 507 | if (device_pasid_enabled(idxd)) |
| 508 | idxd_disable_system_pasid(idxd); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 509 | return rc; |
| 510 | } |
| 511 | |
Dave Jiang | f25b4638 | 2020-11-17 13:39:14 -0700 | [diff] [blame] | 512 | static void idxd_type_init(struct idxd_device *idxd) |
| 513 | { |
| 514 | if (idxd->type == IDXD_TYPE_DSA) |
| 515 | idxd->compl_size = sizeof(struct dsa_completion_record); |
| 516 | else if (idxd->type == IDXD_TYPE_IAX) |
| 517 | idxd->compl_size = sizeof(struct iax_completion_record); |
| 518 | } |
| 519 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 520 | static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 521 | { |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 522 | struct device *dev = &pdev->dev; |
| 523 | struct idxd_device *idxd; |
| 524 | int rc; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 525 | |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 526 | rc = pci_enable_device(pdev); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 527 | if (rc) |
| 528 | return rc; |
| 529 | |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 530 | dev_dbg(dev, "Alloc IDXD context\n"); |
| 531 | idxd = idxd_alloc(pdev); |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 532 | if (!idxd) { |
| 533 | rc = -ENOMEM; |
| 534 | goto err_idxd_alloc; |
| 535 | } |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 536 | |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 537 | dev_dbg(dev, "Mapping BARs\n"); |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 538 | idxd->reg_base = pci_iomap(pdev, IDXD_MMIO_BAR, 0); |
| 539 | if (!idxd->reg_base) { |
| 540 | rc = -ENOMEM; |
| 541 | goto err_iomap; |
| 542 | } |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 543 | |
| 544 | dev_dbg(dev, "Set DMA masks\n"); |
| 545 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
| 546 | if (rc) |
| 547 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 548 | if (rc) |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 549 | goto err; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 550 | |
| 551 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
| 552 | if (rc) |
| 553 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 554 | if (rc) |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 555 | goto err; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 556 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 557 | |
Dave Jiang | f25b4638 | 2020-11-17 13:39:14 -0700 | [diff] [blame] | 558 | idxd_type_init(idxd); |
| 559 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 560 | dev_dbg(dev, "Set PCI master\n"); |
| 561 | pci_set_master(pdev); |
| 562 | pci_set_drvdata(pdev, idxd); |
| 563 | |
| 564 | idxd->hw.version = ioread32(idxd->reg_base + IDXD_VER_OFFSET); |
| 565 | rc = idxd_probe(idxd); |
| 566 | if (rc) { |
| 567 | dev_err(dev, "Intel(R) IDXD DMA Engine init failed\n"); |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 568 | goto err; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 571 | rc = idxd_register_devices(idxd); |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 572 | if (rc) { |
| 573 | dev_err(dev, "IDXD sysfs setup failed\n"); |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 574 | goto err; |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | idxd->state = IDXD_DEV_CONF_READY; |
| 578 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 579 | dev_info(&pdev->dev, "Intel(R) Accelerator Device (v%x)\n", |
| 580 | idxd->hw.version); |
| 581 | |
| 582 | return 0; |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 583 | |
| 584 | err: |
| 585 | pci_iounmap(pdev, idxd->reg_base); |
| 586 | err_iomap: |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 587 | put_device(&idxd->conf_dev); |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 588 | err_idxd_alloc: |
| 589 | pci_disable_device(pdev); |
| 590 | return rc; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Dave Jiang | 8f47d1a | 2020-01-21 16:44:23 -0700 | [diff] [blame] | 593 | static void idxd_flush_pending_llist(struct idxd_irq_entry *ie) |
| 594 | { |
| 595 | struct idxd_desc *desc, *itr; |
| 596 | struct llist_node *head; |
| 597 | |
| 598 | head = llist_del_all(&ie->pending_llist); |
| 599 | if (!head) |
| 600 | return; |
| 601 | |
| 602 | llist_for_each_entry_safe(desc, itr, head, llnode) { |
| 603 | idxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT); |
| 604 | idxd_free_desc(desc->wq, desc); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | static void idxd_flush_work_list(struct idxd_irq_entry *ie) |
| 609 | { |
| 610 | struct idxd_desc *desc, *iter; |
| 611 | |
| 612 | list_for_each_entry_safe(desc, iter, &ie->work_list, list) { |
| 613 | list_del(&desc->list); |
| 614 | idxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT); |
| 615 | idxd_free_desc(desc->wq, desc); |
| 616 | } |
| 617 | } |
| 618 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 619 | static void idxd_shutdown(struct pci_dev *pdev) |
| 620 | { |
| 621 | struct idxd_device *idxd = pci_get_drvdata(pdev); |
| 622 | int rc, i; |
| 623 | struct idxd_irq_entry *irq_entry; |
| 624 | int msixcnt = pci_msix_vec_count(pdev); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 625 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 626 | rc = idxd_device_disable(idxd); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 627 | if (rc) |
| 628 | dev_err(&pdev->dev, "Disabling device failed\n"); |
| 629 | |
| 630 | dev_dbg(&pdev->dev, "%s called\n", __func__); |
| 631 | idxd_mask_msix_vectors(idxd); |
| 632 | idxd_mask_error_interrupts(idxd); |
| 633 | |
| 634 | for (i = 0; i < msixcnt; i++) { |
| 635 | irq_entry = &idxd->irq_entries[i]; |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 636 | synchronize_irq(irq_entry->vector); |
| 637 | free_irq(irq_entry->vector, irq_entry); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 638 | if (i == 0) |
| 639 | continue; |
Dave Jiang | 8f47d1a | 2020-01-21 16:44:23 -0700 | [diff] [blame] | 640 | idxd_flush_pending_llist(irq_entry); |
| 641 | idxd_flush_work_list(irq_entry); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 642 | } |
Dave Jiang | 0d5c10b | 2020-06-26 11:11:18 -0700 | [diff] [blame] | 643 | |
Dave Jiang | 6df0e6c | 2021-04-12 09:23:27 -0700 | [diff] [blame] | 644 | idxd_msix_perm_clear(idxd); |
Dave Jiang | 5fc8e85 | 2021-04-15 16:37:15 -0700 | [diff] [blame] | 645 | pci_free_irq_vectors(pdev); |
Dave Jiang | a39c7cd | 2021-04-15 16:37:21 -0700 | [diff] [blame] | 646 | pci_iounmap(pdev, idxd->reg_base); |
| 647 | pci_disable_device(pdev); |
Dave Jiang | 0d5c10b | 2020-06-26 11:11:18 -0700 | [diff] [blame] | 648 | destroy_workqueue(idxd->wq); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static void idxd_remove(struct pci_dev *pdev) |
| 652 | { |
| 653 | struct idxd_device *idxd = pci_get_drvdata(pdev); |
| 654 | |
| 655 | dev_dbg(&pdev->dev, "%s called\n", __func__); |
| 656 | idxd_shutdown(pdev); |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 657 | if (device_pasid_enabled(idxd)) |
| 658 | idxd_disable_system_pasid(idxd); |
Dave Jiang | 47c16ac | 2021-04-15 16:37:33 -0700 | [diff] [blame] | 659 | idxd_unregister_devices(idxd); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static struct pci_driver idxd_pci_driver = { |
| 663 | .name = DRV_NAME, |
| 664 | .id_table = idxd_pci_tbl, |
| 665 | .probe = idxd_pci_probe, |
| 666 | .remove = idxd_remove, |
| 667 | .shutdown = idxd_shutdown, |
| 668 | }; |
| 669 | |
| 670 | static int __init idxd_init_module(void) |
| 671 | { |
| 672 | int err, i; |
| 673 | |
| 674 | /* |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 675 | * If the CPU does not support MOVDIR64B or ENQCMDS, there's no point in |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 676 | * enumerating the device. We can not utilize it. |
| 677 | */ |
| 678 | if (!boot_cpu_has(X86_FEATURE_MOVDIR64B)) { |
| 679 | pr_warn("idxd driver failed to load without MOVDIR64B.\n"); |
| 680 | return -ENODEV; |
| 681 | } |
| 682 | |
Dave Jiang | 8e50d39 | 2020-10-27 10:34:35 -0700 | [diff] [blame] | 683 | if (!boot_cpu_has(X86_FEATURE_ENQCMD)) |
| 684 | pr_warn("Platform does not have ENQCMD(S) support.\n"); |
| 685 | else |
| 686 | support_enqcmd = true; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 687 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 688 | for (i = 0; i < IDXD_TYPE_MAX; i++) |
Dave Jiang | f7f7739 | 2021-04-15 16:37:27 -0700 | [diff] [blame] | 689 | ida_init(&idxd_idas[i]); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 690 | |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 691 | err = idxd_register_bus_type(); |
| 692 | if (err < 0) |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 693 | return err; |
| 694 | |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 695 | err = idxd_register_driver(); |
| 696 | if (err < 0) |
| 697 | goto err_idxd_driver_register; |
| 698 | |
Dave Jiang | 42d279f | 2020-01-21 16:44:29 -0700 | [diff] [blame] | 699 | err = idxd_cdev_register(); |
| 700 | if (err) |
| 701 | goto err_cdev_register; |
| 702 | |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 703 | err = pci_register_driver(&idxd_pci_driver); |
| 704 | if (err) |
| 705 | goto err_pci_register; |
| 706 | |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 707 | return 0; |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 708 | |
| 709 | err_pci_register: |
Dave Jiang | 42d279f | 2020-01-21 16:44:29 -0700 | [diff] [blame] | 710 | idxd_cdev_remove(); |
| 711 | err_cdev_register: |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 712 | idxd_unregister_driver(); |
| 713 | err_idxd_driver_register: |
| 714 | idxd_unregister_bus_type(); |
| 715 | return err; |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 716 | } |
| 717 | module_init(idxd_init_module); |
| 718 | |
| 719 | static void __exit idxd_exit_module(void) |
| 720 | { |
| 721 | pci_unregister_driver(&idxd_pci_driver); |
Dave Jiang | 42d279f | 2020-01-21 16:44:29 -0700 | [diff] [blame] | 722 | idxd_cdev_remove(); |
Dave Jiang | c52ca47 | 2020-01-21 16:44:05 -0700 | [diff] [blame] | 723 | idxd_unregister_bus_type(); |
Dave Jiang | bfe1d56 | 2020-01-21 16:43:59 -0700 | [diff] [blame] | 724 | } |
| 725 | module_exit(idxd_exit_module); |