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

dmaengine: idxd: remove detection of device type

Move all static data type for per device type to an idxd_driver_data data
structure. The data can be attached to the pci_device_id and provided by
the pci probe function. This removes a lot of unnecessary type detection
and setup code.

Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/161852988924.2203940.2787590808682466398.stgit@djiang5-desk3.ch.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Dave Jiang and committed by
Vinod Koul
435b512d 4b73e4eb

+48 -75
+5 -6
drivers/dma/idxd/cdev.c
··· 45 45 struct idxd_cdev_context *cdev_ctx; 46 46 struct idxd_wq *wq = idxd_cdev->wq; 47 47 48 - cdev_ctx = &ictx[wq->idxd->type]; 48 + cdev_ctx = &ictx[wq->idxd->data->type]; 49 49 ida_simple_remove(&cdev_ctx->minor_ida, idxd_cdev->minor); 50 50 kfree(idxd_cdev); 51 51 } ··· 239 239 240 240 int idxd_cdev_get_major(struct idxd_device *idxd) 241 241 { 242 - return MAJOR(ictx[idxd->type].devt); 242 + return MAJOR(ictx[idxd->data->type].devt); 243 243 } 244 244 245 245 int idxd_wq_add_cdev(struct idxd_wq *wq) ··· 258 258 idxd_cdev->wq = wq; 259 259 cdev = &idxd_cdev->cdev; 260 260 dev = &idxd_cdev->dev; 261 - cdev_ctx = &ictx[wq->idxd->type]; 261 + cdev_ctx = &ictx[wq->idxd->data->type]; 262 262 minor = ida_simple_get(&cdev_ctx->minor_ida, 0, MINORMASK, GFP_KERNEL); 263 263 if (minor < 0) { 264 264 kfree(idxd_cdev); ··· 272 272 dev->type = &idxd_cdev_device_type; 273 273 dev->devt = MKDEV(MAJOR(cdev_ctx->devt), minor); 274 274 275 - rc = dev_set_name(dev, "%s/wq%u.%u", idxd_get_dev_name(idxd), 276 - idxd->id, wq->id); 275 + rc = dev_set_name(dev, "%s/wq%u.%u", idxd->data->name_prefix, idxd->id, wq->id); 277 276 if (rc < 0) 278 277 goto err; 279 278 ··· 297 298 struct idxd_cdev *idxd_cdev; 298 299 struct idxd_cdev_context *cdev_ctx; 299 300 300 - cdev_ctx = &ictx[wq->idxd->type]; 301 + cdev_ctx = &ictx[wq->idxd->data->type]; 301 302 idxd_cdev = wq->idxd_cdev; 302 303 wq->idxd_cdev = NULL; 303 304 cdev_device_del(&idxd_cdev->cdev, &idxd_cdev->dev);
+5 -11
drivers/dma/idxd/device.c
··· 144 144 if (rc < 0) 145 145 return rc; 146 146 147 - if (idxd->type == IDXD_TYPE_DSA) 148 - align = 32; 149 - else if (idxd->type == IDXD_TYPE_IAX) 150 - align = 64; 151 - else 152 - return -ENODEV; 153 - 154 - wq->compls_size = num_descs * idxd->compl_size + align; 147 + align = idxd->data->align; 148 + wq->compls_size = num_descs * idxd->data->compl_size + align; 155 149 wq->compls_raw = dma_alloc_coherent(dev, wq->compls_size, 156 150 &wq->compls_addr_raw, GFP_KERNEL); 157 151 if (!wq->compls_raw) { ··· 172 178 struct idxd_desc *desc = wq->descs[i]; 173 179 174 180 desc->hw = wq->hw_descs[i]; 175 - if (idxd->type == IDXD_TYPE_DSA) 181 + if (idxd->data->type == IDXD_TYPE_DSA) 176 182 desc->completion = &wq->compls[i]; 177 - else if (idxd->type == IDXD_TYPE_IAX) 183 + else if (idxd->data->type == IDXD_TYPE_IAX) 178 184 desc->iax_completion = &wq->iax_compls[i]; 179 - desc->compl_dma = wq->compls_addr + idxd->compl_size * i; 185 + desc->compl_dma = wq->compls_addr + idxd->data->compl_size * i; 180 186 desc->id = i; 181 187 desc->wq = wq; 182 188 desc->cpu = -1;
+9 -4
drivers/dma/idxd/idxd.h
··· 178 178 struct dma_device dma; 179 179 }; 180 180 181 - struct idxd_device { 181 + struct idxd_driver_data { 182 + const char *name_prefix; 182 183 enum idxd_type type; 184 + struct device_type *dev_type; 185 + int compl_size; 186 + int align; 187 + }; 188 + 189 + struct idxd_device { 183 190 struct device conf_dev; 191 + struct idxd_driver_data *data; 184 192 struct list_head list; 185 193 struct idxd_hw hw; 186 194 enum idxd_device_state state; ··· 226 218 int token_limit; 227 219 int nr_tokens; /* non-reserved tokens */ 228 220 unsigned int wqcfg_size; 229 - int compl_size; 230 221 231 222 union sw_err_reg sw_err; 232 223 wait_queue_head_t cmd_waitq; ··· 354 347 return wq->client_count; 355 348 }; 356 349 357 - const char *idxd_get_dev_name(struct idxd_device *idxd); 358 350 int idxd_register_bus_type(void); 359 351 void idxd_unregister_bus_type(void); 360 352 int idxd_register_devices(struct idxd_device *idxd); 361 353 void idxd_unregister_devices(struct idxd_device *idxd); 362 354 int idxd_register_driver(void); 363 355 void idxd_unregister_driver(void); 364 - struct device_type *idxd_get_device_type(struct idxd_device *idxd); 365 356 366 357 /* device interrupt control */ 367 358 void idxd_msix_perm_setup(struct idxd_device *idxd);
+25 -40
drivers/dma/idxd/init.c
··· 35 35 bool support_enqcmd; 36 36 DEFINE_IDA(idxd_ida); 37 37 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 + 38 55 static struct pci_device_id idxd_pci_tbl[] = { 39 56 /* DSA ver 1.0 platforms */ 40 - { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_DSA_SPR0) }, 57 + { PCI_DEVICE_DATA(INTEL, DSA_SPR0, &idxd_driver_data[IDXD_TYPE_DSA]) }, 41 58 42 59 /* IAX ver 1.0 platforms */ 43 - { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IAX_SPR0) }, 60 + { PCI_DEVICE_DATA(INTEL, IAX_SPR0, &idxd_driver_data[IDXD_TYPE_IAX]) }, 44 61 { 0, } 45 62 }; 46 63 MODULE_DEVICE_TABLE(pci, idxd_pci_tbl); 47 - 48 - static char *idxd_name[] = { 49 - "dsa", 50 - "iax" 51 - }; 52 - 53 - const char *idxd_get_dev_name(struct idxd_device *idxd) 54 - { 55 - return idxd_name[idxd->type]; 56 - } 57 64 58 65 static int idxd_setup_interrupts(struct idxd_device *idxd) 59 66 { ··· 386 379 } 387 380 } 388 381 389 - static inline void idxd_set_type(struct idxd_device *idxd) 390 - { 391 - struct pci_dev *pdev = idxd->pdev; 392 - 393 - if (pdev->device == PCI_DEVICE_ID_INTEL_DSA_SPR0) 394 - idxd->type = IDXD_TYPE_DSA; 395 - else if (pdev->device == PCI_DEVICE_ID_INTEL_IAX_SPR0) 396 - idxd->type = IDXD_TYPE_IAX; 397 - else 398 - idxd->type = IDXD_TYPE_UNKNOWN; 399 - } 400 - 401 - static struct idxd_device *idxd_alloc(struct pci_dev *pdev) 382 + static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data) 402 383 { 403 384 struct device *dev = &pdev->dev; 404 385 struct idxd_device *idxd; ··· 397 402 return NULL; 398 403 399 404 idxd->pdev = pdev; 400 - idxd_set_type(idxd); 405 + idxd->data = data; 401 406 idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL); 402 407 if (idxd->id < 0) 403 408 return NULL; ··· 405 410 device_initialize(&idxd->conf_dev); 406 411 idxd->conf_dev.parent = dev; 407 412 idxd->conf_dev.bus = &dsa_bus_type; 408 - idxd->conf_dev.type = idxd_get_device_type(idxd); 409 - rc = dev_set_name(&idxd->conf_dev, "%s%d", idxd_get_dev_name(idxd), idxd->id); 413 + idxd->conf_dev.type = idxd->data->dev_type; 414 + rc = dev_set_name(&idxd->conf_dev, "%s%d", idxd->data->name_prefix, idxd->id); 410 415 if (rc < 0) { 411 416 put_device(&idxd->conf_dev); 412 417 return NULL; ··· 498 503 return rc; 499 504 } 500 505 501 - static void idxd_type_init(struct idxd_device *idxd) 502 - { 503 - if (idxd->type == IDXD_TYPE_DSA) 504 - idxd->compl_size = sizeof(struct dsa_completion_record); 505 - else if (idxd->type == IDXD_TYPE_IAX) 506 - idxd->compl_size = sizeof(struct iax_completion_record); 507 - } 508 - 509 506 static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 510 507 { 511 508 struct device *dev = &pdev->dev; 512 509 struct idxd_device *idxd; 510 + struct idxd_driver_data *data = (struct idxd_driver_data *)id->driver_data; 513 511 int rc; 514 512 515 513 rc = pci_enable_device(pdev); ··· 510 522 return rc; 511 523 512 524 dev_dbg(dev, "Alloc IDXD context\n"); 513 - idxd = idxd_alloc(pdev); 525 + idxd = idxd_alloc(pdev, data); 514 526 if (!idxd) { 515 527 rc = -ENOMEM; 516 528 goto err_idxd_alloc; ··· 535 547 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 536 548 if (rc) 537 549 goto err; 538 - 539 - 540 - idxd_type_init(idxd); 541 550 542 551 dev_dbg(dev, "Set PCI master\n"); 543 552 pci_set_master(pdev);
+1 -1
drivers/dma/idxd/submit.c
··· 15 15 16 16 desc = wq->descs[idx]; 17 17 memset(desc->hw, 0, sizeof(struct dsa_hw_desc)); 18 - memset(desc->completion, 0, idxd->compl_size); 18 + memset(desc->completion, 0, idxd->data->compl_size); 19 19 desc->cpu = cpu; 20 20 21 21 if (device_pasid_enabled(idxd))
+3 -13
drivers/dma/idxd/sysfs.c
··· 310 310 }, 311 311 }; 312 312 313 - struct device_type *idxd_get_device_type(struct idxd_device *idxd) 314 - { 315 - if (idxd->type == IDXD_TYPE_DSA) 316 - return &dsa_device_type; 317 - else if (idxd->type == IDXD_TYPE_IAX) 318 - return &iax_device_type; 319 - else 320 - return NULL; 321 - } 322 - 323 313 /* IDXD generic driver setup */ 324 314 int idxd_register_driver(void) 325 315 { ··· 443 453 if (rc < 0) 444 454 return -EINVAL; 445 455 446 - if (idxd->type == IDXD_TYPE_IAX) 456 + if (idxd->data->type == IDXD_TYPE_IAX) 447 457 return -EOPNOTSUPP; 448 458 449 459 if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) ··· 491 501 if (rc < 0) 492 502 return -EINVAL; 493 503 494 - if (idxd->type == IDXD_TYPE_IAX) 504 + if (idxd->data->type == IDXD_TYPE_IAX) 495 505 return -EOPNOTSUPP; 496 506 497 507 if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) ··· 536 546 if (rc < 0) 537 547 return -EINVAL; 538 548 539 - if (idxd->type == IDXD_TYPE_IAX) 549 + if (idxd->data->type == IDXD_TYPE_IAX) 540 550 return -EOPNOTSUPP; 541 551 542 552 if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))