blob: 1639f3b2aa58f798aa20fb081df5dcea4fe16b60 [file] [log] [blame]
Dave Jiangbfe1d562020-01-21 16:43:59 -07001// 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 Jiang8e50d392020-10-27 10:34:35 -070017#include <linux/intel-svm.h>
18#include <linux/iommu.h>
Dave Jiangbfe1d562020-01-21 16:43:59 -070019#include <uapi/linux/idxd.h>
Dave Jiang8f47d1a2020-01-21 16:44:23 -070020#include <linux/dmaengine.h>
21#include "../dmaengine.h"
Dave Jiangbfe1d562020-01-21 16:43:59 -070022#include "registers.h"
23#include "idxd.h"
24
25MODULE_VERSION(IDXD_DRIVER_VERSION);
26MODULE_LICENSE("GPL v2");
27MODULE_AUTHOR("Intel Corporation");
28
29#define DRV_NAME "idxd"
30
Dave Jiang8e50d392020-10-27 10:34:35 -070031bool support_enqcmd;
32
Dave Jiangbfe1d562020-01-21 16:43:59 -070033static struct idr idxd_idrs[IDXD_TYPE_MAX];
34static struct mutex idxd_idr_lock;
35
36static struct pci_device_id idxd_pci_tbl[] = {
37 /* DSA ver 1.0 platforms */
38 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_DSA_SPR0) },
39 { 0, }
40};
41MODULE_DEVICE_TABLE(pci, idxd_pci_tbl);
42
43static char *idxd_name[] = {
44 "dsa",
45};
46
47const char *idxd_get_dev_name(struct idxd_device *idxd)
48{
49 return idxd_name[idxd->type];
50}
51
52static int idxd_setup_interrupts(struct idxd_device *idxd)
53{
54 struct pci_dev *pdev = idxd->pdev;
55 struct device *dev = &pdev->dev;
56 struct msix_entry *msix;
57 struct idxd_irq_entry *irq_entry;
58 int i, msixcnt;
59 int rc = 0;
Dave Jiang8e50d392020-10-27 10:34:35 -070060 union msix_perm mperm;
Dave Jiangbfe1d562020-01-21 16:43:59 -070061
62 msixcnt = pci_msix_vec_count(pdev);
63 if (msixcnt < 0) {
64 dev_err(dev, "Not MSI-X interrupt capable.\n");
65 goto err_no_irq;
66 }
67
68 idxd->msix_entries = devm_kzalloc(dev, sizeof(struct msix_entry) *
69 msixcnt, GFP_KERNEL);
70 if (!idxd->msix_entries) {
71 rc = -ENOMEM;
72 goto err_no_irq;
73 }
74
75 for (i = 0; i < msixcnt; i++)
76 idxd->msix_entries[i].entry = i;
77
78 rc = pci_enable_msix_exact(pdev, idxd->msix_entries, msixcnt);
79 if (rc) {
80 dev_err(dev, "Failed enabling %d MSIX entries.\n", msixcnt);
81 goto err_no_irq;
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 */
89 idxd->irq_entries = devm_kcalloc(dev, msixcnt,
90 sizeof(struct idxd_irq_entry),
91 GFP_KERNEL);
92 if (!idxd->irq_entries) {
93 rc = -ENOMEM;
94 goto err_no_irq;
95 }
96
97 for (i = 0; i < msixcnt; i++) {
98 idxd->irq_entries[i].id = i;
99 idxd->irq_entries[i].idxd = idxd;
100 }
101
102 msix = &idxd->msix_entries[0];
103 irq_entry = &idxd->irq_entries[0];
104 rc = devm_request_threaded_irq(dev, msix->vector, idxd_irq_handler,
105 idxd_misc_thread, 0, "idxd-misc",
106 irq_entry);
107 if (rc < 0) {
108 dev_err(dev, "Failed to allocate misc interrupt.\n");
109 goto err_no_irq;
110 }
111
112 dev_dbg(dev, "Allocated idxd-misc handler on msix vector %d\n",
113 msix->vector);
114
115 /* first MSI-X entry is not for wq interrupts */
116 idxd->num_wq_irqs = msixcnt - 1;
117
118 for (i = 1; i < msixcnt; i++) {
119 msix = &idxd->msix_entries[i];
120 irq_entry = &idxd->irq_entries[i];
121
122 init_llist_head(&idxd->irq_entries[i].pending_llist);
123 INIT_LIST_HEAD(&idxd->irq_entries[i].work_list);
124 rc = devm_request_threaded_irq(dev, msix->vector,
125 idxd_irq_handler,
126 idxd_wq_thread, 0,
127 "idxd-portal", irq_entry);
128 if (rc < 0) {
129 dev_err(dev, "Failed to allocate irq %d.\n",
130 msix->vector);
131 goto err_no_irq;
132 }
133 dev_dbg(dev, "Allocated idxd-msix %d for vector %d\n",
134 i, msix->vector);
135 }
136
137 idxd_unmask_error_interrupts(idxd);
138
Dave Jiang8e50d392020-10-27 10:34:35 -0700139 /* Setup MSIX permission table */
140 mperm.bits = 0;
141 mperm.pasid = idxd->pasid;
142 mperm.pasid_en = device_pasid_enabled(idxd);
143 for (i = 1; i < msixcnt; i++)
144 iowrite32(mperm.bits, idxd->reg_base + idxd->msix_perm_offset + i * 8);
145
Dave Jiangbfe1d562020-01-21 16:43:59 -0700146 return 0;
147
148 err_no_irq:
149 /* Disable error interrupt generation */
150 idxd_mask_error_interrupts(idxd);
151 pci_disable_msix(pdev);
152 dev_err(dev, "No usable interrupts\n");
153 return rc;
154}
155
Dave Jiangbfe1d562020-01-21 16:43:59 -0700156static int idxd_setup_internals(struct idxd_device *idxd)
157{
158 struct device *dev = &idxd->pdev->dev;
159 int i;
160
Dave Jiang0d5c10b2020-06-26 11:11:18 -0700161 init_waitqueue_head(&idxd->cmd_waitq);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700162 idxd->groups = devm_kcalloc(dev, idxd->max_groups,
163 sizeof(struct idxd_group), GFP_KERNEL);
164 if (!idxd->groups)
165 return -ENOMEM;
166
167 for (i = 0; i < idxd->max_groups; i++) {
168 idxd->groups[i].idxd = idxd;
169 idxd->groups[i].id = i;
170 idxd->groups[i].tc_a = -1;
171 idxd->groups[i].tc_b = -1;
172 }
173
174 idxd->wqs = devm_kcalloc(dev, idxd->max_wqs, sizeof(struct idxd_wq),
175 GFP_KERNEL);
176 if (!idxd->wqs)
177 return -ENOMEM;
178
179 idxd->engines = devm_kcalloc(dev, idxd->max_engines,
180 sizeof(struct idxd_engine), GFP_KERNEL);
181 if (!idxd->engines)
182 return -ENOMEM;
183
184 for (i = 0; i < idxd->max_wqs; i++) {
185 struct idxd_wq *wq = &idxd->wqs[i];
Dave Jiangbfe1d562020-01-21 16:43:59 -0700186
187 wq->id = i;
188 wq->idxd = idxd;
189 mutex_init(&wq->wq_lock);
Dave Jiang42d279f2020-01-21 16:44:29 -0700190 wq->idxd_cdev.minor = -1;
Dave Jiangd7aad552020-08-28 15:12:10 -0700191 wq->max_xfer_bytes = idxd->max_xfer_bytes;
Dave Jiange7184b12020-08-28 15:12:50 -0700192 wq->max_batch_size = idxd->max_batch_size;
Dave Jiangd98793b2020-10-27 14:34:09 -0700193 wq->wqcfg = devm_kzalloc(dev, idxd->wqcfg_size, GFP_KERNEL);
194 if (!wq->wqcfg)
195 return -ENOMEM;
Dave Jiangbfe1d562020-01-21 16:43:59 -0700196 }
197
198 for (i = 0; i < idxd->max_engines; i++) {
199 idxd->engines[i].idxd = idxd;
200 idxd->engines[i].id = i;
201 }
202
Dave Jiang0d5c10b2020-06-26 11:11:18 -0700203 idxd->wq = create_workqueue(dev_name(dev));
204 if (!idxd->wq)
205 return -ENOMEM;
206
Dave Jiangbfe1d562020-01-21 16:43:59 -0700207 return 0;
208}
209
210static void idxd_read_table_offsets(struct idxd_device *idxd)
211{
212 union offsets_reg offsets;
213 struct device *dev = &idxd->pdev->dev;
214
215 offsets.bits[0] = ioread64(idxd->reg_base + IDXD_TABLE_OFFSET);
216 offsets.bits[1] = ioread64(idxd->reg_base + IDXD_TABLE_OFFSET
217 + sizeof(u64));
218 idxd->grpcfg_offset = offsets.grpcfg * 0x100;
219 dev_dbg(dev, "IDXD Group Config Offset: %#x\n", idxd->grpcfg_offset);
220 idxd->wqcfg_offset = offsets.wqcfg * 0x100;
221 dev_dbg(dev, "IDXD Work Queue Config Offset: %#x\n",
222 idxd->wqcfg_offset);
223 idxd->msix_perm_offset = offsets.msix_perm * 0x100;
224 dev_dbg(dev, "IDXD MSIX Permission Offset: %#x\n",
225 idxd->msix_perm_offset);
226 idxd->perfmon_offset = offsets.perfmon * 0x100;
227 dev_dbg(dev, "IDXD Perfmon Offset: %#x\n", idxd->perfmon_offset);
228}
229
230static void idxd_read_caps(struct idxd_device *idxd)
231{
232 struct device *dev = &idxd->pdev->dev;
233 int i;
234
235 /* reading generic capabilities */
236 idxd->hw.gen_cap.bits = ioread64(idxd->reg_base + IDXD_GENCAP_OFFSET);
237 dev_dbg(dev, "gen_cap: %#llx\n", idxd->hw.gen_cap.bits);
238 idxd->max_xfer_bytes = 1ULL << idxd->hw.gen_cap.max_xfer_shift;
239 dev_dbg(dev, "max xfer size: %llu bytes\n", idxd->max_xfer_bytes);
240 idxd->max_batch_size = 1U << idxd->hw.gen_cap.max_batch_shift;
241 dev_dbg(dev, "max batch size: %u\n", idxd->max_batch_size);
242 if (idxd->hw.gen_cap.config_en)
243 set_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags);
244
245 /* reading group capabilities */
246 idxd->hw.group_cap.bits =
247 ioread64(idxd->reg_base + IDXD_GRPCAP_OFFSET);
248 dev_dbg(dev, "group_cap: %#llx\n", idxd->hw.group_cap.bits);
249 idxd->max_groups = idxd->hw.group_cap.num_groups;
250 dev_dbg(dev, "max groups: %u\n", idxd->max_groups);
251 idxd->max_tokens = idxd->hw.group_cap.total_tokens;
252 dev_dbg(dev, "max tokens: %u\n", idxd->max_tokens);
Dave Jiangc52ca472020-01-21 16:44:05 -0700253 idxd->nr_tokens = idxd->max_tokens;
Dave Jiangbfe1d562020-01-21 16:43:59 -0700254
255 /* read engine capabilities */
256 idxd->hw.engine_cap.bits =
257 ioread64(idxd->reg_base + IDXD_ENGCAP_OFFSET);
258 dev_dbg(dev, "engine_cap: %#llx\n", idxd->hw.engine_cap.bits);
259 idxd->max_engines = idxd->hw.engine_cap.num_engines;
260 dev_dbg(dev, "max engines: %u\n", idxd->max_engines);
261
262 /* read workqueue capabilities */
263 idxd->hw.wq_cap.bits = ioread64(idxd->reg_base + IDXD_WQCAP_OFFSET);
264 dev_dbg(dev, "wq_cap: %#llx\n", idxd->hw.wq_cap.bits);
265 idxd->max_wq_size = idxd->hw.wq_cap.total_wq_size;
266 dev_dbg(dev, "total workqueue size: %u\n", idxd->max_wq_size);
267 idxd->max_wqs = idxd->hw.wq_cap.num_wqs;
268 dev_dbg(dev, "max workqueues: %u\n", idxd->max_wqs);
Dave Jiangd98793b2020-10-27 14:34:09 -0700269 idxd->wqcfg_size = 1 << (idxd->hw.wq_cap.wqcfg_size + IDXD_WQCFG_MIN);
270 dev_dbg(dev, "wqcfg size: %u\n", idxd->wqcfg_size);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700271
272 /* reading operation capabilities */
273 for (i = 0; i < 4; i++) {
274 idxd->hw.opcap.bits[i] = ioread64(idxd->reg_base +
275 IDXD_OPCAP_OFFSET + i * sizeof(u64));
276 dev_dbg(dev, "opcap[%d]: %#llx\n", i, idxd->hw.opcap.bits[i]);
277 }
278}
279
Dave Jiang8e50d392020-10-27 10:34:35 -0700280static struct idxd_device *idxd_alloc(struct pci_dev *pdev)
Dave Jiangbfe1d562020-01-21 16:43:59 -0700281{
282 struct device *dev = &pdev->dev;
283 struct idxd_device *idxd;
284
285 idxd = devm_kzalloc(dev, sizeof(struct idxd_device), GFP_KERNEL);
286 if (!idxd)
287 return NULL;
288
289 idxd->pdev = pdev;
Dave Jiangbfe1d562020-01-21 16:43:59 -0700290 spin_lock_init(&idxd->dev_lock);
291
292 return idxd;
293}
294
Dave Jiang8e50d392020-10-27 10:34:35 -0700295static int idxd_enable_system_pasid(struct idxd_device *idxd)
296{
297 int flags;
298 unsigned int pasid;
299 struct iommu_sva *sva;
300
301 flags = SVM_FLAG_SUPERVISOR_MODE;
302
303 sva = iommu_sva_bind_device(&idxd->pdev->dev, NULL, &flags);
304 if (IS_ERR(sva)) {
305 dev_warn(&idxd->pdev->dev,
306 "iommu sva bind failed: %ld\n", PTR_ERR(sva));
307 return PTR_ERR(sva);
308 }
309
310 pasid = iommu_sva_get_pasid(sva);
311 if (pasid == IOMMU_PASID_INVALID) {
312 iommu_sva_unbind_device(sva);
313 return -ENODEV;
314 }
315
316 idxd->sva = sva;
317 idxd->pasid = pasid;
318 dev_dbg(&idxd->pdev->dev, "system pasid: %u\n", pasid);
319 return 0;
320}
321
322static void idxd_disable_system_pasid(struct idxd_device *idxd)
323{
324
325 iommu_sva_unbind_device(idxd->sva);
326 idxd->sva = NULL;
327}
328
Dave Jiangbfe1d562020-01-21 16:43:59 -0700329static int idxd_probe(struct idxd_device *idxd)
330{
331 struct pci_dev *pdev = idxd->pdev;
332 struct device *dev = &pdev->dev;
333 int rc;
334
335 dev_dbg(dev, "%s entered and resetting device\n", __func__);
Dave Jiang0d5c10b2020-06-26 11:11:18 -0700336 idxd_device_init_reset(idxd);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700337 dev_dbg(dev, "IDXD reset complete\n");
338
Dave Jiang8e50d392020-10-27 10:34:35 -0700339 if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM)) {
340 rc = idxd_enable_system_pasid(idxd);
341 if (rc < 0)
342 dev_warn(dev, "Failed to enable PASID. No SVA support: %d\n", rc);
343 else
344 set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags);
345 }
346
Dave Jiangbfe1d562020-01-21 16:43:59 -0700347 idxd_read_caps(idxd);
348 idxd_read_table_offsets(idxd);
349
350 rc = idxd_setup_internals(idxd);
351 if (rc)
352 goto err_setup;
353
354 rc = idxd_setup_interrupts(idxd);
355 if (rc)
356 goto err_setup;
357
358 dev_dbg(dev, "IDXD interrupt setup complete.\n");
359
360 mutex_lock(&idxd_idr_lock);
361 idxd->id = idr_alloc(&idxd_idrs[idxd->type], idxd, 0, 0, GFP_KERNEL);
362 mutex_unlock(&idxd_idr_lock);
363 if (idxd->id < 0) {
364 rc = -ENOMEM;
365 goto err_idr_fail;
366 }
367
Dave Jiang42d279f2020-01-21 16:44:29 -0700368 idxd->major = idxd_cdev_get_major(idxd);
369
Dave Jiangbfe1d562020-01-21 16:43:59 -0700370 dev_dbg(dev, "IDXD device %d probed successfully\n", idxd->id);
371 return 0;
372
373 err_idr_fail:
374 idxd_mask_error_interrupts(idxd);
375 idxd_mask_msix_vectors(idxd);
376 err_setup:
Dave Jiang8e50d392020-10-27 10:34:35 -0700377 if (device_pasid_enabled(idxd))
378 idxd_disable_system_pasid(idxd);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700379 return rc;
380}
381
382static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
383{
Dave Jiangbfe1d562020-01-21 16:43:59 -0700384 struct device *dev = &pdev->dev;
385 struct idxd_device *idxd;
386 int rc;
Dave Jiangbfe1d562020-01-21 16:43:59 -0700387
388 rc = pcim_enable_device(pdev);
389 if (rc)
390 return rc;
391
Dave Jiang8e50d392020-10-27 10:34:35 -0700392 dev_dbg(dev, "Alloc IDXD context\n");
393 idxd = idxd_alloc(pdev);
394 if (!idxd)
395 return -ENOMEM;
Dave Jiangbfe1d562020-01-21 16:43:59 -0700396
Dave Jiang8e50d392020-10-27 10:34:35 -0700397 dev_dbg(dev, "Mapping BARs\n");
398 idxd->reg_base = pcim_iomap(pdev, IDXD_MMIO_BAR, 0);
399 if (!idxd->reg_base)
Dave Jiangbfe1d562020-01-21 16:43:59 -0700400 return -ENOMEM;
401
402 dev_dbg(dev, "Set DMA masks\n");
403 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
404 if (rc)
405 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
406 if (rc)
407 return rc;
408
409 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
410 if (rc)
411 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
412 if (rc)
413 return rc;
414
Dave Jiangbfe1d562020-01-21 16:43:59 -0700415 idxd_set_type(idxd);
416
417 dev_dbg(dev, "Set PCI master\n");
418 pci_set_master(pdev);
419 pci_set_drvdata(pdev, idxd);
420
421 idxd->hw.version = ioread32(idxd->reg_base + IDXD_VER_OFFSET);
422 rc = idxd_probe(idxd);
423 if (rc) {
424 dev_err(dev, "Intel(R) IDXD DMA Engine init failed\n");
425 return -ENODEV;
426 }
427
Dave Jiangc52ca472020-01-21 16:44:05 -0700428 rc = idxd_setup_sysfs(idxd);
429 if (rc) {
430 dev_err(dev, "IDXD sysfs setup failed\n");
431 return -ENODEV;
432 }
433
434 idxd->state = IDXD_DEV_CONF_READY;
435
Dave Jiangbfe1d562020-01-21 16:43:59 -0700436 dev_info(&pdev->dev, "Intel(R) Accelerator Device (v%x)\n",
437 idxd->hw.version);
438
439 return 0;
440}
441
Dave Jiang8f47d1a2020-01-21 16:44:23 -0700442static void idxd_flush_pending_llist(struct idxd_irq_entry *ie)
443{
444 struct idxd_desc *desc, *itr;
445 struct llist_node *head;
446
447 head = llist_del_all(&ie->pending_llist);
448 if (!head)
449 return;
450
451 llist_for_each_entry_safe(desc, itr, head, llnode) {
452 idxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT);
453 idxd_free_desc(desc->wq, desc);
454 }
455}
456
457static void idxd_flush_work_list(struct idxd_irq_entry *ie)
458{
459 struct idxd_desc *desc, *iter;
460
461 list_for_each_entry_safe(desc, iter, &ie->work_list, list) {
462 list_del(&desc->list);
463 idxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT);
464 idxd_free_desc(desc->wq, desc);
465 }
466}
467
Dave Jiangbfe1d562020-01-21 16:43:59 -0700468static void idxd_shutdown(struct pci_dev *pdev)
469{
470 struct idxd_device *idxd = pci_get_drvdata(pdev);
471 int rc, i;
472 struct idxd_irq_entry *irq_entry;
473 int msixcnt = pci_msix_vec_count(pdev);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700474
Dave Jiangbfe1d562020-01-21 16:43:59 -0700475 rc = idxd_device_disable(idxd);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700476 if (rc)
477 dev_err(&pdev->dev, "Disabling device failed\n");
478
479 dev_dbg(&pdev->dev, "%s called\n", __func__);
480 idxd_mask_msix_vectors(idxd);
481 idxd_mask_error_interrupts(idxd);
482
483 for (i = 0; i < msixcnt; i++) {
484 irq_entry = &idxd->irq_entries[i];
485 synchronize_irq(idxd->msix_entries[i].vector);
486 if (i == 0)
487 continue;
Dave Jiang8f47d1a2020-01-21 16:44:23 -0700488 idxd_flush_pending_llist(irq_entry);
489 idxd_flush_work_list(irq_entry);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700490 }
Dave Jiang0d5c10b2020-06-26 11:11:18 -0700491
492 destroy_workqueue(idxd->wq);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700493}
494
495static void idxd_remove(struct pci_dev *pdev)
496{
497 struct idxd_device *idxd = pci_get_drvdata(pdev);
498
499 dev_dbg(&pdev->dev, "%s called\n", __func__);
Dave Jiangc52ca472020-01-21 16:44:05 -0700500 idxd_cleanup_sysfs(idxd);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700501 idxd_shutdown(pdev);
Dave Jiang8e50d392020-10-27 10:34:35 -0700502 if (device_pasid_enabled(idxd))
503 idxd_disable_system_pasid(idxd);
Dave Jiangbfe1d562020-01-21 16:43:59 -0700504 mutex_lock(&idxd_idr_lock);
505 idr_remove(&idxd_idrs[idxd->type], idxd->id);
506 mutex_unlock(&idxd_idr_lock);
507}
508
509static struct pci_driver idxd_pci_driver = {
510 .name = DRV_NAME,
511 .id_table = idxd_pci_tbl,
512 .probe = idxd_pci_probe,
513 .remove = idxd_remove,
514 .shutdown = idxd_shutdown,
515};
516
517static int __init idxd_init_module(void)
518{
519 int err, i;
520
521 /*
Dave Jiang8e50d392020-10-27 10:34:35 -0700522 * If the CPU does not support MOVDIR64B or ENQCMDS, there's no point in
Dave Jiangbfe1d562020-01-21 16:43:59 -0700523 * enumerating the device. We can not utilize it.
524 */
525 if (!boot_cpu_has(X86_FEATURE_MOVDIR64B)) {
526 pr_warn("idxd driver failed to load without MOVDIR64B.\n");
527 return -ENODEV;
528 }
529
Dave Jiang8e50d392020-10-27 10:34:35 -0700530 if (!boot_cpu_has(X86_FEATURE_ENQCMD))
531 pr_warn("Platform does not have ENQCMD(S) support.\n");
532 else
533 support_enqcmd = true;
Dave Jiangbfe1d562020-01-21 16:43:59 -0700534
535 mutex_init(&idxd_idr_lock);
536 for (i = 0; i < IDXD_TYPE_MAX; i++)
537 idr_init(&idxd_idrs[i]);
538
Dave Jiangc52ca472020-01-21 16:44:05 -0700539 err = idxd_register_bus_type();
540 if (err < 0)
Dave Jiangbfe1d562020-01-21 16:43:59 -0700541 return err;
542
Dave Jiangc52ca472020-01-21 16:44:05 -0700543 err = idxd_register_driver();
544 if (err < 0)
545 goto err_idxd_driver_register;
546
Dave Jiang42d279f2020-01-21 16:44:29 -0700547 err = idxd_cdev_register();
548 if (err)
549 goto err_cdev_register;
550
Dave Jiangc52ca472020-01-21 16:44:05 -0700551 err = pci_register_driver(&idxd_pci_driver);
552 if (err)
553 goto err_pci_register;
554
Dave Jiangbfe1d562020-01-21 16:43:59 -0700555 return 0;
Dave Jiangc52ca472020-01-21 16:44:05 -0700556
557err_pci_register:
Dave Jiang42d279f2020-01-21 16:44:29 -0700558 idxd_cdev_remove();
559err_cdev_register:
Dave Jiangc52ca472020-01-21 16:44:05 -0700560 idxd_unregister_driver();
561err_idxd_driver_register:
562 idxd_unregister_bus_type();
563 return err;
Dave Jiangbfe1d562020-01-21 16:43:59 -0700564}
565module_init(idxd_init_module);
566
567static void __exit idxd_exit_module(void)
568{
569 pci_unregister_driver(&idxd_pci_driver);
Dave Jiang42d279f2020-01-21 16:44:29 -0700570 idxd_cdev_remove();
Dave Jiangc52ca472020-01-21 16:44:05 -0700571 idxd_unregister_bus_type();
Dave Jiangbfe1d562020-01-21 16:43:59 -0700572}
573module_exit(idxd_exit_module);