virtio_pci_common.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * Virtio PCI driver - common functionality for all device versions
  3. *
  4. * This module allows virtio devices to be used over a virtual PCI device.
  5. * This can be used with QEMU based VMMs like KVM or Xen.
  6. *
  7. * Copyright IBM Corp. 2007
  8. * Copyright Red Hat, Inc. 2014
  9. *
  10. * Authors:
  11. * Anthony Liguori <aliguori@us.ibm.com>
  12. * Rusty Russell <rusty@rustcorp.com.au>
  13. * Michael S. Tsirkin <mst@redhat.com>
  14. *
  15. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  16. * See the COPYING file in the top-level directory.
  17. *
  18. */
  19. #include "virtio_pci_common.h"
  20. static bool force_legacy = false;
  21. #if IS_ENABLED(CONFIG_VIRTIO_PCI_LEGACY)
  22. module_param(force_legacy, bool, 0444);
  23. MODULE_PARM_DESC(force_legacy,
  24. "Force legacy mode for transitional virtio 1 devices");
  25. #endif
  26. /* wait for pending irq handlers */
  27. void vp_synchronize_vectors(struct virtio_device *vdev)
  28. {
  29. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  30. int i;
  31. if (vp_dev->intx_enabled)
  32. synchronize_irq(vp_dev->pci_dev->irq);
  33. for (i = 0; i < vp_dev->msix_vectors; ++i)
  34. synchronize_irq(pci_irq_vector(vp_dev->pci_dev, i));
  35. }
  36. /* the notify function used when creating a virt queue */
  37. bool vp_notify(struct virtqueue *vq)
  38. {
  39. /* we write the queue's selector into the notification register to
  40. * signal the other end */
  41. iowrite16(vq->index, (void __iomem *)vq->priv);
  42. return true;
  43. }
  44. /* Handle a configuration change: Tell driver if it wants to know. */
  45. static irqreturn_t vp_config_changed(int irq, void *opaque)
  46. {
  47. struct virtio_pci_device *vp_dev = opaque;
  48. virtio_config_changed(&vp_dev->vdev);
  49. return IRQ_HANDLED;
  50. }
  51. /* Notify all virtqueues on an interrupt. */
  52. static irqreturn_t vp_vring_interrupt(int irq, void *opaque)
  53. {
  54. struct virtio_pci_device *vp_dev = opaque;
  55. struct virtio_pci_vq_info *info;
  56. irqreturn_t ret = IRQ_NONE;
  57. unsigned long flags;
  58. spin_lock_irqsave(&vp_dev->lock, flags);
  59. list_for_each_entry(info, &vp_dev->virtqueues, node) {
  60. if (vring_interrupt(irq, info->vq) == IRQ_HANDLED)
  61. ret = IRQ_HANDLED;
  62. }
  63. spin_unlock_irqrestore(&vp_dev->lock, flags);
  64. return ret;
  65. }
  66. /* A small wrapper to also acknowledge the interrupt when it's handled.
  67. * I really need an EIO hook for the vring so I can ack the interrupt once we
  68. * know that we'll be handling the IRQ but before we invoke the callback since
  69. * the callback may notify the host which results in the host attempting to
  70. * raise an interrupt that we would then mask once we acknowledged the
  71. * interrupt. */
  72. static irqreturn_t vp_interrupt(int irq, void *opaque)
  73. {
  74. struct virtio_pci_device *vp_dev = opaque;
  75. u8 isr;
  76. /* reading the ISR has the effect of also clearing it so it's very
  77. * important to save off the value. */
  78. isr = ioread8(vp_dev->isr);
  79. /* It's definitely not us if the ISR was not high */
  80. if (!isr)
  81. return IRQ_NONE;
  82. /* Configuration change? Tell driver if it wants to know. */
  83. if (isr & VIRTIO_PCI_ISR_CONFIG)
  84. vp_config_changed(irq, opaque);
  85. return vp_vring_interrupt(irq, opaque);
  86. }
  87. static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
  88. bool per_vq_vectors, struct irq_affinity *desc)
  89. {
  90. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  91. const char *name = dev_name(&vp_dev->vdev.dev);
  92. unsigned flags = PCI_IRQ_MSIX;
  93. unsigned i, v;
  94. int err = -ENOMEM;
  95. vp_dev->msix_vectors = nvectors;
  96. vp_dev->msix_names = kmalloc_array(nvectors,
  97. sizeof(*vp_dev->msix_names),
  98. GFP_KERNEL);
  99. if (!vp_dev->msix_names)
  100. goto error;
  101. vp_dev->msix_affinity_masks
  102. = kcalloc(nvectors, sizeof(*vp_dev->msix_affinity_masks),
  103. GFP_KERNEL);
  104. if (!vp_dev->msix_affinity_masks)
  105. goto error;
  106. for (i = 0; i < nvectors; ++i)
  107. if (!alloc_cpumask_var(&vp_dev->msix_affinity_masks[i],
  108. GFP_KERNEL))
  109. goto error;
  110. if (desc) {
  111. flags |= PCI_IRQ_AFFINITY;
  112. desc->pre_vectors++; /* virtio config vector */
  113. }
  114. err = pci_alloc_irq_vectors_affinity(vp_dev->pci_dev, nvectors,
  115. nvectors, flags, desc);
  116. if (err < 0)
  117. goto error;
  118. vp_dev->msix_enabled = 1;
  119. /* Set the vector used for configuration */
  120. v = vp_dev->msix_used_vectors;
  121. snprintf(vp_dev->msix_names[v], sizeof *vp_dev->msix_names,
  122. "%s-config", name);
  123. err = request_irq(pci_irq_vector(vp_dev->pci_dev, v),
  124. vp_config_changed, 0, vp_dev->msix_names[v],
  125. vp_dev);
  126. if (err)
  127. goto error;
  128. ++vp_dev->msix_used_vectors;
  129. v = vp_dev->config_vector(vp_dev, v);
  130. /* Verify we had enough resources to assign the vector */
  131. if (v == VIRTIO_MSI_NO_VECTOR) {
  132. err = -EBUSY;
  133. goto error;
  134. }
  135. if (!per_vq_vectors) {
  136. /* Shared vector for all VQs */
  137. v = vp_dev->msix_used_vectors;
  138. snprintf(vp_dev->msix_names[v], sizeof *vp_dev->msix_names,
  139. "%s-virtqueues", name);
  140. err = request_irq(pci_irq_vector(vp_dev->pci_dev, v),
  141. vp_vring_interrupt, 0, vp_dev->msix_names[v],
  142. vp_dev);
  143. if (err)
  144. goto error;
  145. ++vp_dev->msix_used_vectors;
  146. }
  147. return 0;
  148. error:
  149. return err;
  150. }
  151. static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned index,
  152. void (*callback)(struct virtqueue *vq),
  153. const char *name,
  154. bool ctx,
  155. u16 msix_vec)
  156. {
  157. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  158. struct virtio_pci_vq_info *info = kmalloc(sizeof *info, GFP_KERNEL);
  159. struct virtqueue *vq;
  160. unsigned long flags;
  161. /* fill out our structure that represents an active queue */
  162. if (!info)
  163. return ERR_PTR(-ENOMEM);
  164. vq = vp_dev->setup_vq(vp_dev, info, index, callback, name, ctx,
  165. msix_vec);
  166. if (IS_ERR(vq))
  167. goto out_info;
  168. info->vq = vq;
  169. if (callback) {
  170. spin_lock_irqsave(&vp_dev->lock, flags);
  171. list_add(&info->node, &vp_dev->virtqueues);
  172. spin_unlock_irqrestore(&vp_dev->lock, flags);
  173. } else {
  174. INIT_LIST_HEAD(&info->node);
  175. }
  176. vp_dev->vqs[index] = info;
  177. return vq;
  178. out_info:
  179. kfree(info);
  180. return vq;
  181. }
  182. static void vp_del_vq(struct virtqueue *vq)
  183. {
  184. struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
  185. struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];
  186. unsigned long flags;
  187. spin_lock_irqsave(&vp_dev->lock, flags);
  188. list_del(&info->node);
  189. spin_unlock_irqrestore(&vp_dev->lock, flags);
  190. vp_dev->del_vq(info);
  191. kfree(info);
  192. }
  193. /* the config->del_vqs() implementation */
  194. void vp_del_vqs(struct virtio_device *vdev)
  195. {
  196. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  197. struct virtqueue *vq, *n;
  198. int i;
  199. list_for_each_entry_safe(vq, n, &vdev->vqs, list) {
  200. if (vp_dev->per_vq_vectors) {
  201. int v = vp_dev->vqs[vq->index]->msix_vector;
  202. if (v != VIRTIO_MSI_NO_VECTOR) {
  203. int irq = pci_irq_vector(vp_dev->pci_dev, v);
  204. irq_set_affinity_hint(irq, NULL);
  205. free_irq(irq, vq);
  206. }
  207. }
  208. vp_del_vq(vq);
  209. }
  210. vp_dev->per_vq_vectors = false;
  211. if (vp_dev->intx_enabled) {
  212. free_irq(vp_dev->pci_dev->irq, vp_dev);
  213. vp_dev->intx_enabled = 0;
  214. }
  215. for (i = 0; i < vp_dev->msix_used_vectors; ++i)
  216. free_irq(pci_irq_vector(vp_dev->pci_dev, i), vp_dev);
  217. if (vp_dev->msix_affinity_masks) {
  218. for (i = 0; i < vp_dev->msix_vectors; i++)
  219. if (vp_dev->msix_affinity_masks[i])
  220. free_cpumask_var(vp_dev->msix_affinity_masks[i]);
  221. }
  222. if (vp_dev->msix_enabled) {
  223. /* Disable the vector used for configuration */
  224. vp_dev->config_vector(vp_dev, VIRTIO_MSI_NO_VECTOR);
  225. pci_free_irq_vectors(vp_dev->pci_dev);
  226. vp_dev->msix_enabled = 0;
  227. }
  228. vp_dev->msix_vectors = 0;
  229. vp_dev->msix_used_vectors = 0;
  230. kfree(vp_dev->msix_names);
  231. vp_dev->msix_names = NULL;
  232. kfree(vp_dev->msix_affinity_masks);
  233. vp_dev->msix_affinity_masks = NULL;
  234. kfree(vp_dev->vqs);
  235. vp_dev->vqs = NULL;
  236. }
  237. static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
  238. struct virtqueue *vqs[], vq_callback_t *callbacks[],
  239. const char * const names[], bool per_vq_vectors,
  240. const bool *ctx,
  241. struct irq_affinity *desc)
  242. {
  243. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  244. u16 msix_vec;
  245. int i, err, nvectors, allocated_vectors;
  246. vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
  247. if (!vp_dev->vqs)
  248. return -ENOMEM;
  249. if (per_vq_vectors) {
  250. /* Best option: one for change interrupt, one per vq. */
  251. nvectors = 1;
  252. for (i = 0; i < nvqs; ++i)
  253. if (callbacks[i])
  254. ++nvectors;
  255. } else {
  256. /* Second best: one for change, shared for all vqs. */
  257. nvectors = 2;
  258. }
  259. err = vp_request_msix_vectors(vdev, nvectors, per_vq_vectors,
  260. per_vq_vectors ? desc : NULL);
  261. if (err)
  262. goto error_find;
  263. vp_dev->per_vq_vectors = per_vq_vectors;
  264. allocated_vectors = vp_dev->msix_used_vectors;
  265. for (i = 0; i < nvqs; ++i) {
  266. if (!names[i]) {
  267. vqs[i] = NULL;
  268. continue;
  269. }
  270. if (!callbacks[i])
  271. msix_vec = VIRTIO_MSI_NO_VECTOR;
  272. else if (vp_dev->per_vq_vectors)
  273. msix_vec = allocated_vectors++;
  274. else
  275. msix_vec = VP_MSIX_VQ_VECTOR;
  276. vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i],
  277. ctx ? ctx[i] : false,
  278. msix_vec);
  279. if (IS_ERR(vqs[i])) {
  280. err = PTR_ERR(vqs[i]);
  281. goto error_find;
  282. }
  283. if (!vp_dev->per_vq_vectors || msix_vec == VIRTIO_MSI_NO_VECTOR)
  284. continue;
  285. /* allocate per-vq irq if available and necessary */
  286. snprintf(vp_dev->msix_names[msix_vec],
  287. sizeof *vp_dev->msix_names,
  288. "%s-%s",
  289. dev_name(&vp_dev->vdev.dev), names[i]);
  290. err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec),
  291. vring_interrupt, 0,
  292. vp_dev->msix_names[msix_vec],
  293. vqs[i]);
  294. if (err)
  295. goto error_find;
  296. }
  297. return 0;
  298. error_find:
  299. vp_del_vqs(vdev);
  300. return err;
  301. }
  302. static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
  303. struct virtqueue *vqs[], vq_callback_t *callbacks[],
  304. const char * const names[], const bool *ctx)
  305. {
  306. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  307. int i, err;
  308. vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
  309. if (!vp_dev->vqs)
  310. return -ENOMEM;
  311. err = request_irq(vp_dev->pci_dev->irq, vp_interrupt, IRQF_SHARED,
  312. dev_name(&vdev->dev), vp_dev);
  313. if (err)
  314. goto out_del_vqs;
  315. vp_dev->intx_enabled = 1;
  316. vp_dev->per_vq_vectors = false;
  317. for (i = 0; i < nvqs; ++i) {
  318. if (!names[i]) {
  319. vqs[i] = NULL;
  320. continue;
  321. }
  322. vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i],
  323. ctx ? ctx[i] : false,
  324. VIRTIO_MSI_NO_VECTOR);
  325. if (IS_ERR(vqs[i])) {
  326. err = PTR_ERR(vqs[i]);
  327. goto out_del_vqs;
  328. }
  329. }
  330. return 0;
  331. out_del_vqs:
  332. vp_del_vqs(vdev);
  333. return err;
  334. }
  335. /* the config->find_vqs() implementation */
  336. int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
  337. struct virtqueue *vqs[], vq_callback_t *callbacks[],
  338. const char * const names[], const bool *ctx,
  339. struct irq_affinity *desc)
  340. {
  341. int err;
  342. /* Try MSI-X with one vector per queue. */
  343. err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, true, ctx, desc);
  344. if (!err)
  345. return 0;
  346. /* Fallback: MSI-X with one vector for config, one shared for queues. */
  347. err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, false, ctx, desc);
  348. if (!err)
  349. return 0;
  350. /* Finally fall back to regular interrupts. */
  351. return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, ctx);
  352. }
  353. const char *vp_bus_name(struct virtio_device *vdev)
  354. {
  355. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  356. return pci_name(vp_dev->pci_dev);
  357. }
  358. /* Setup the affinity for a virtqueue:
  359. * - force the affinity for per vq vector
  360. * - OR over all affinities for shared MSI
  361. * - ignore the affinity request if we're using INTX
  362. */
  363. int vp_set_vq_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask)
  364. {
  365. struct virtio_device *vdev = vq->vdev;
  366. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  367. struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];
  368. struct cpumask *mask;
  369. unsigned int irq;
  370. if (!vq->callback)
  371. return -EINVAL;
  372. if (vp_dev->msix_enabled) {
  373. mask = vp_dev->msix_affinity_masks[info->msix_vector];
  374. irq = pci_irq_vector(vp_dev->pci_dev, info->msix_vector);
  375. if (!cpu_mask)
  376. irq_set_affinity_hint(irq, NULL);
  377. else {
  378. cpumask_copy(mask, cpu_mask);
  379. irq_set_affinity_hint(irq, mask);
  380. }
  381. }
  382. return 0;
  383. }
  384. const struct cpumask *vp_get_vq_affinity(struct virtio_device *vdev, int index)
  385. {
  386. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  387. if (!vp_dev->per_vq_vectors ||
  388. vp_dev->vqs[index]->msix_vector == VIRTIO_MSI_NO_VECTOR)
  389. return NULL;
  390. return pci_irq_get_affinity(vp_dev->pci_dev,
  391. vp_dev->vqs[index]->msix_vector);
  392. }
  393. #ifdef CONFIG_PM_SLEEP
  394. static int virtio_pci_freeze(struct device *dev)
  395. {
  396. struct pci_dev *pci_dev = to_pci_dev(dev);
  397. struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
  398. int ret;
  399. ret = virtio_device_freeze(&vp_dev->vdev);
  400. if (!ret)
  401. pci_disable_device(pci_dev);
  402. return ret;
  403. }
  404. static int virtio_pci_restore(struct device *dev)
  405. {
  406. struct pci_dev *pci_dev = to_pci_dev(dev);
  407. struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
  408. int ret;
  409. ret = pci_enable_device(pci_dev);
  410. if (ret)
  411. return ret;
  412. pci_set_master(pci_dev);
  413. return virtio_device_restore(&vp_dev->vdev);
  414. }
  415. static const struct dev_pm_ops virtio_pci_pm_ops = {
  416. SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore)
  417. };
  418. #endif
  419. /* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */
  420. static const struct pci_device_id virtio_pci_id_table[] = {
  421. { PCI_DEVICE(PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_ANY_ID) },
  422. { 0 }
  423. };
  424. MODULE_DEVICE_TABLE(pci, virtio_pci_id_table);
  425. static void virtio_pci_release_dev(struct device *_d)
  426. {
  427. struct virtio_device *vdev = dev_to_virtio(_d);
  428. struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  429. /* As struct device is a kobject, it's not safe to
  430. * free the memory (including the reference counter itself)
  431. * until it's release callback. */
  432. kfree(vp_dev);
  433. }
  434. static int virtio_pci_probe(struct pci_dev *pci_dev,
  435. const struct pci_device_id *id)
  436. {
  437. struct virtio_pci_device *vp_dev, *reg_dev = NULL;
  438. int rc;
  439. /* allocate our structure and fill it out */
  440. vp_dev = kzalloc(sizeof(struct virtio_pci_device), GFP_KERNEL);
  441. if (!vp_dev)
  442. return -ENOMEM;
  443. pci_set_drvdata(pci_dev, vp_dev);
  444. vp_dev->vdev.dev.parent = &pci_dev->dev;
  445. vp_dev->vdev.dev.release = virtio_pci_release_dev;
  446. vp_dev->pci_dev = pci_dev;
  447. INIT_LIST_HEAD(&vp_dev->virtqueues);
  448. spin_lock_init(&vp_dev->lock);
  449. /* enable the device */
  450. rc = pci_enable_device(pci_dev);
  451. if (rc)
  452. goto err_enable_device;
  453. if (force_legacy) {
  454. rc = virtio_pci_legacy_probe(vp_dev);
  455. /* Also try modern mode if we can't map BAR0 (no IO space). */
  456. if (rc == -ENODEV || rc == -ENOMEM)
  457. rc = virtio_pci_modern_probe(vp_dev);
  458. if (rc)
  459. goto err_probe;
  460. } else {
  461. rc = virtio_pci_modern_probe(vp_dev);
  462. if (rc == -ENODEV)
  463. rc = virtio_pci_legacy_probe(vp_dev);
  464. if (rc)
  465. goto err_probe;
  466. }
  467. pci_set_master(pci_dev);
  468. rc = register_virtio_device(&vp_dev->vdev);
  469. reg_dev = vp_dev;
  470. if (rc)
  471. goto err_register;
  472. return 0;
  473. err_register:
  474. if (vp_dev->ioaddr)
  475. virtio_pci_legacy_remove(vp_dev);
  476. else
  477. virtio_pci_modern_remove(vp_dev);
  478. err_probe:
  479. pci_disable_device(pci_dev);
  480. err_enable_device:
  481. if (reg_dev)
  482. put_device(&vp_dev->vdev.dev);
  483. else
  484. kfree(vp_dev);
  485. return rc;
  486. }
  487. static void virtio_pci_remove(struct pci_dev *pci_dev)
  488. {
  489. struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
  490. struct device *dev = get_device(&vp_dev->vdev.dev);
  491. pci_disable_sriov(pci_dev);
  492. unregister_virtio_device(&vp_dev->vdev);
  493. if (vp_dev->ioaddr)
  494. virtio_pci_legacy_remove(vp_dev);
  495. else
  496. virtio_pci_modern_remove(vp_dev);
  497. pci_disable_device(pci_dev);
  498. put_device(dev);
  499. }
  500. static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
  501. {
  502. struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
  503. struct virtio_device *vdev = &vp_dev->vdev;
  504. int ret;
  505. if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK))
  506. return -EBUSY;
  507. if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV))
  508. return -EINVAL;
  509. if (pci_vfs_assigned(pci_dev))
  510. return -EPERM;
  511. if (num_vfs == 0) {
  512. pci_disable_sriov(pci_dev);
  513. return 0;
  514. }
  515. ret = pci_enable_sriov(pci_dev, num_vfs);
  516. if (ret < 0)
  517. return ret;
  518. return num_vfs;
  519. }
  520. static struct pci_driver virtio_pci_driver = {
  521. .name = "virtio-pci",
  522. .id_table = virtio_pci_id_table,
  523. .probe = virtio_pci_probe,
  524. .remove = virtio_pci_remove,
  525. #ifdef CONFIG_PM_SLEEP
  526. .driver.pm = &virtio_pci_pm_ops,
  527. #endif
  528. .sriov_configure = virtio_pci_sriov_configure,
  529. };
  530. module_pci_driver(virtio_pci_driver);
  531. MODULE_AUTHOR("Anthony Liguori <aliguori@us.ibm.com>");
  532. MODULE_DESCRIPTION("virtio-pci");
  533. MODULE_LICENSE("GPL");
  534. MODULE_VERSION("1");