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