mic_virtio.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Disclaimer: The codes contained in these modules may be specific to
  19. * the Intel Software Development Platform codenamed: Knights Ferry, and
  20. * the Intel product codenamed: Knights Corner, and are not backward
  21. * compatible with other Intel products. Additionally, Intel will NOT
  22. * support the codes or instruction set in future products.
  23. *
  24. * Adapted from:
  25. *
  26. * virtio for kvm on s390
  27. *
  28. * Copyright IBM Corp. 2008
  29. *
  30. * This program is free software; you can redistribute it and/or modify
  31. * it under the terms of the GNU General Public License (version 2 only)
  32. * as published by the Free Software Foundation.
  33. *
  34. * Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
  35. *
  36. * Intel MIC Card driver.
  37. *
  38. */
  39. #include <linux/delay.h>
  40. #include <linux/slab.h>
  41. #include <linux/virtio_config.h>
  42. #include "../common/mic_dev.h"
  43. #include "mic_virtio.h"
  44. #define VIRTIO_SUBCODE_64 0x0D00
  45. #define MIC_MAX_VRINGS 4
  46. struct mic_vdev {
  47. struct virtio_device vdev;
  48. struct mic_device_desc __iomem *desc;
  49. struct mic_device_ctrl __iomem *dc;
  50. struct mic_device *mdev;
  51. void __iomem *vr[MIC_MAX_VRINGS];
  52. int used_size[MIC_MAX_VRINGS];
  53. struct completion reset_done;
  54. struct mic_irq *virtio_cookie;
  55. int c2h_vdev_db;
  56. };
  57. static struct mic_irq *virtio_config_cookie;
  58. #define to_micvdev(vd) container_of(vd, struct mic_vdev, vdev)
  59. /* Helper API to obtain the parent of the virtio device */
  60. static inline struct device *mic_dev(struct mic_vdev *mvdev)
  61. {
  62. return mvdev->vdev.dev.parent;
  63. }
  64. /* This gets the device's feature bits. */
  65. static u64 mic_get_features(struct virtio_device *vdev)
  66. {
  67. unsigned int i, bits;
  68. u32 features = 0;
  69. struct mic_device_desc __iomem *desc = to_micvdev(vdev)->desc;
  70. u8 __iomem *in_features = mic_vq_features(desc);
  71. int feature_len = ioread8(&desc->feature_len);
  72. bits = min_t(unsigned, feature_len, sizeof(features)) * 8;
  73. for (i = 0; i < bits; i++)
  74. if (ioread8(&in_features[i / 8]) & (BIT(i % 8)))
  75. features |= BIT(i);
  76. return features;
  77. }
  78. static int mic_finalize_features(struct virtio_device *vdev)
  79. {
  80. unsigned int i, bits;
  81. struct mic_device_desc __iomem *desc = to_micvdev(vdev)->desc;
  82. u8 feature_len = ioread8(&desc->feature_len);
  83. /* Second half of bitmap is features we accept. */
  84. u8 __iomem *out_features =
  85. mic_vq_features(desc) + feature_len;
  86. /* Give virtio_ring a chance to accept features. */
  87. vring_transport_features(vdev);
  88. /* Make sure we don't have any features > 32 bits! */
  89. BUG_ON((u32)vdev->features != vdev->features);
  90. memset_io(out_features, 0, feature_len);
  91. bits = min_t(unsigned, feature_len,
  92. sizeof(vdev->features)) * 8;
  93. for (i = 0; i < bits; i++) {
  94. if (__virtio_test_bit(vdev, i))
  95. iowrite8(ioread8(&out_features[i / 8]) | (1 << (i % 8)),
  96. &out_features[i / 8]);
  97. }
  98. return 0;
  99. }
  100. /*
  101. * Reading and writing elements in config space
  102. */
  103. static void mic_get(struct virtio_device *vdev, unsigned int offset,
  104. void *buf, unsigned len)
  105. {
  106. struct mic_device_desc __iomem *desc = to_micvdev(vdev)->desc;
  107. if (offset + len > ioread8(&desc->config_len))
  108. return;
  109. memcpy_fromio(buf, mic_vq_configspace(desc) + offset, len);
  110. }
  111. static void mic_set(struct virtio_device *vdev, unsigned int offset,
  112. const void *buf, unsigned len)
  113. {
  114. struct mic_device_desc __iomem *desc = to_micvdev(vdev)->desc;
  115. if (offset + len > ioread8(&desc->config_len))
  116. return;
  117. memcpy_toio(mic_vq_configspace(desc) + offset, buf, len);
  118. }
  119. /*
  120. * The operations to get and set the status word just access the status
  121. * field of the device descriptor. set_status also interrupts the host
  122. * to tell about status changes.
  123. */
  124. static u8 mic_get_status(struct virtio_device *vdev)
  125. {
  126. return ioread8(&to_micvdev(vdev)->desc->status);
  127. }
  128. static void mic_set_status(struct virtio_device *vdev, u8 status)
  129. {
  130. struct mic_vdev *mvdev = to_micvdev(vdev);
  131. if (!status)
  132. return;
  133. iowrite8(status, &mvdev->desc->status);
  134. mic_send_intr(mvdev->mdev, mvdev->c2h_vdev_db);
  135. }
  136. /* Inform host on a virtio device reset and wait for ack from host */
  137. static void mic_reset_inform_host(struct virtio_device *vdev)
  138. {
  139. struct mic_vdev *mvdev = to_micvdev(vdev);
  140. struct mic_device_ctrl __iomem *dc = mvdev->dc;
  141. int retry;
  142. iowrite8(0, &dc->host_ack);
  143. iowrite8(1, &dc->vdev_reset);
  144. mic_send_intr(mvdev->mdev, mvdev->c2h_vdev_db);
  145. /* Wait till host completes all card accesses and acks the reset */
  146. for (retry = 100; retry--;) {
  147. if (ioread8(&dc->host_ack))
  148. break;
  149. msleep(100);
  150. };
  151. dev_dbg(mic_dev(mvdev), "%s: retry: %d\n", __func__, retry);
  152. /* Reset status to 0 in case we timed out */
  153. iowrite8(0, &mvdev->desc->status);
  154. }
  155. static void mic_reset(struct virtio_device *vdev)
  156. {
  157. struct mic_vdev *mvdev = to_micvdev(vdev);
  158. dev_dbg(mic_dev(mvdev), "%s: virtio id %d\n",
  159. __func__, vdev->id.device);
  160. mic_reset_inform_host(vdev);
  161. complete_all(&mvdev->reset_done);
  162. }
  163. /*
  164. * The virtio_ring code calls this API when it wants to notify the Host.
  165. */
  166. static bool mic_notify(struct virtqueue *vq)
  167. {
  168. struct mic_vdev *mvdev = vq->priv;
  169. mic_send_intr(mvdev->mdev, mvdev->c2h_vdev_db);
  170. return true;
  171. }
  172. static void mic_del_vq(struct virtqueue *vq, int n)
  173. {
  174. struct mic_vdev *mvdev = to_micvdev(vq->vdev);
  175. struct vring *vr = (struct vring *)(vq + 1);
  176. free_pages((unsigned long) vr->used, get_order(mvdev->used_size[n]));
  177. vring_del_virtqueue(vq);
  178. mic_card_unmap(mvdev->mdev, mvdev->vr[n]);
  179. mvdev->vr[n] = NULL;
  180. }
  181. static void mic_del_vqs(struct virtio_device *vdev)
  182. {
  183. struct mic_vdev *mvdev = to_micvdev(vdev);
  184. struct virtqueue *vq, *n;
  185. int idx = 0;
  186. dev_dbg(mic_dev(mvdev), "%s\n", __func__);
  187. list_for_each_entry_safe(vq, n, &vdev->vqs, list)
  188. mic_del_vq(vq, idx++);
  189. }
  190. /*
  191. * This routine will assign vring's allocated in host/io memory. Code in
  192. * virtio_ring.c however continues to access this io memory as if it were local
  193. * memory without io accessors.
  194. */
  195. static struct virtqueue *mic_find_vq(struct virtio_device *vdev,
  196. unsigned index,
  197. void (*callback)(struct virtqueue *vq),
  198. const char *name)
  199. {
  200. struct mic_vdev *mvdev = to_micvdev(vdev);
  201. struct mic_vqconfig __iomem *vqconfig;
  202. struct mic_vqconfig config;
  203. struct virtqueue *vq;
  204. void __iomem *va;
  205. struct _mic_vring_info __iomem *info;
  206. void *used;
  207. int vr_size, _vr_size, err, magic;
  208. struct vring *vr;
  209. u8 type = ioread8(&mvdev->desc->type);
  210. if (index >= ioread8(&mvdev->desc->num_vq))
  211. return ERR_PTR(-ENOENT);
  212. if (!name)
  213. return ERR_PTR(-ENOENT);
  214. /* First assign the vring's allocated in host memory */
  215. vqconfig = mic_vq_config(mvdev->desc) + index;
  216. memcpy_fromio(&config, vqconfig, sizeof(config));
  217. _vr_size = vring_size(le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN);
  218. vr_size = PAGE_ALIGN(_vr_size + sizeof(struct _mic_vring_info));
  219. va = mic_card_map(mvdev->mdev, le64_to_cpu(config.address), vr_size);
  220. if (!va)
  221. return ERR_PTR(-ENOMEM);
  222. mvdev->vr[index] = va;
  223. memset_io(va, 0x0, _vr_size);
  224. vq = vring_new_virtqueue(index, le16_to_cpu(config.num),
  225. MIC_VIRTIO_RING_ALIGN, vdev, false,
  226. (void __force *)va, mic_notify, callback,
  227. name);
  228. if (!vq) {
  229. err = -ENOMEM;
  230. goto unmap;
  231. }
  232. info = va + _vr_size;
  233. magic = ioread32(&info->magic);
  234. if (WARN(magic != MIC_MAGIC + type + index, "magic mismatch")) {
  235. err = -EIO;
  236. goto unmap;
  237. }
  238. /* Allocate and reassign used ring now */
  239. mvdev->used_size[index] = PAGE_ALIGN(sizeof(__u16) * 3 +
  240. sizeof(struct vring_used_elem) *
  241. le16_to_cpu(config.num));
  242. used = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
  243. get_order(mvdev->used_size[index]));
  244. if (!used) {
  245. err = -ENOMEM;
  246. dev_err(mic_dev(mvdev), "%s %d err %d\n",
  247. __func__, __LINE__, err);
  248. goto del_vq;
  249. }
  250. iowrite64(virt_to_phys(used), &vqconfig->used_address);
  251. /*
  252. * To reassign the used ring here we are directly accessing
  253. * struct vring_virtqueue which is a private data structure
  254. * in virtio_ring.c. At the minimum, a BUILD_BUG_ON() in
  255. * vring_new_virtqueue() would ensure that
  256. * (&vq->vring == (struct vring *) (&vq->vq + 1));
  257. */
  258. vr = (struct vring *)(vq + 1);
  259. vr->used = used;
  260. vq->priv = mvdev;
  261. return vq;
  262. del_vq:
  263. vring_del_virtqueue(vq);
  264. unmap:
  265. mic_card_unmap(mvdev->mdev, mvdev->vr[index]);
  266. return ERR_PTR(err);
  267. }
  268. static int mic_find_vqs(struct virtio_device *vdev, unsigned nvqs,
  269. struct virtqueue *vqs[],
  270. vq_callback_t *callbacks[],
  271. const char *names[])
  272. {
  273. struct mic_vdev *mvdev = to_micvdev(vdev);
  274. struct mic_device_ctrl __iomem *dc = mvdev->dc;
  275. int i, err, retry;
  276. /* We must have this many virtqueues. */
  277. if (nvqs > ioread8(&mvdev->desc->num_vq))
  278. return -ENOENT;
  279. for (i = 0; i < nvqs; ++i) {
  280. dev_dbg(mic_dev(mvdev), "%s: %d: %s\n",
  281. __func__, i, names[i]);
  282. vqs[i] = mic_find_vq(vdev, i, callbacks[i], names[i]);
  283. if (IS_ERR(vqs[i])) {
  284. err = PTR_ERR(vqs[i]);
  285. goto error;
  286. }
  287. }
  288. iowrite8(1, &dc->used_address_updated);
  289. /*
  290. * Send an interrupt to the host to inform it that used
  291. * rings have been re-assigned.
  292. */
  293. mic_send_intr(mvdev->mdev, mvdev->c2h_vdev_db);
  294. for (retry = 100; retry--;) {
  295. if (!ioread8(&dc->used_address_updated))
  296. break;
  297. msleep(100);
  298. };
  299. dev_dbg(mic_dev(mvdev), "%s: retry: %d\n", __func__, retry);
  300. if (!retry) {
  301. err = -ENODEV;
  302. goto error;
  303. }
  304. return 0;
  305. error:
  306. mic_del_vqs(vdev);
  307. return err;
  308. }
  309. /*
  310. * The config ops structure as defined by virtio config
  311. */
  312. static struct virtio_config_ops mic_vq_config_ops = {
  313. .get_features = mic_get_features,
  314. .finalize_features = mic_finalize_features,
  315. .get = mic_get,
  316. .set = mic_set,
  317. .get_status = mic_get_status,
  318. .set_status = mic_set_status,
  319. .reset = mic_reset,
  320. .find_vqs = mic_find_vqs,
  321. .del_vqs = mic_del_vqs,
  322. };
  323. static irqreturn_t
  324. mic_virtio_intr_handler(int irq, void *data)
  325. {
  326. struct mic_vdev *mvdev = data;
  327. struct virtqueue *vq;
  328. mic_ack_interrupt(mvdev->mdev);
  329. list_for_each_entry(vq, &mvdev->vdev.vqs, list)
  330. vring_interrupt(0, vq);
  331. return IRQ_HANDLED;
  332. }
  333. static void mic_virtio_release_dev(struct device *_d)
  334. {
  335. /*
  336. * No need for a release method similar to virtio PCI.
  337. * Provide an empty one to avoid getting a warning from core.
  338. */
  339. }
  340. /*
  341. * adds a new device and register it with virtio
  342. * appropriate drivers are loaded by the device model
  343. */
  344. static int mic_add_device(struct mic_device_desc __iomem *d,
  345. unsigned int offset, struct mic_driver *mdrv)
  346. {
  347. struct mic_vdev *mvdev;
  348. int ret;
  349. int virtio_db;
  350. u8 type = ioread8(&d->type);
  351. mvdev = kzalloc(sizeof(*mvdev), GFP_KERNEL);
  352. if (!mvdev) {
  353. dev_err(mdrv->dev, "Cannot allocate mic dev %u type %u\n",
  354. offset, type);
  355. return -ENOMEM;
  356. }
  357. mvdev->mdev = &mdrv->mdev;
  358. mvdev->vdev.dev.parent = mdrv->dev;
  359. mvdev->vdev.dev.release = mic_virtio_release_dev;
  360. mvdev->vdev.id.device = type;
  361. mvdev->vdev.config = &mic_vq_config_ops;
  362. mvdev->desc = d;
  363. mvdev->dc = (void __iomem *)d + mic_aligned_desc_size(d);
  364. init_completion(&mvdev->reset_done);
  365. virtio_db = mic_next_card_db();
  366. mvdev->virtio_cookie = mic_request_card_irq(mic_virtio_intr_handler,
  367. NULL, "virtio intr", mvdev, virtio_db);
  368. if (IS_ERR(mvdev->virtio_cookie)) {
  369. ret = PTR_ERR(mvdev->virtio_cookie);
  370. goto kfree;
  371. }
  372. iowrite8((u8)virtio_db, &mvdev->dc->h2c_vdev_db);
  373. mvdev->c2h_vdev_db = ioread8(&mvdev->dc->c2h_vdev_db);
  374. ret = register_virtio_device(&mvdev->vdev);
  375. if (ret) {
  376. dev_err(mic_dev(mvdev),
  377. "Failed to register mic device %u type %u\n",
  378. offset, type);
  379. goto free_irq;
  380. }
  381. iowrite64((u64)mvdev, &mvdev->dc->vdev);
  382. dev_dbg(mic_dev(mvdev), "%s: registered mic device %u type %u mvdev %p\n",
  383. __func__, offset, type, mvdev);
  384. return 0;
  385. free_irq:
  386. mic_free_card_irq(mvdev->virtio_cookie, mvdev);
  387. kfree:
  388. kfree(mvdev);
  389. return ret;
  390. }
  391. /*
  392. * match for a mic device with a specific desc pointer
  393. */
  394. static int mic_match_desc(struct device *dev, void *data)
  395. {
  396. struct virtio_device *vdev = dev_to_virtio(dev);
  397. struct mic_vdev *mvdev = to_micvdev(vdev);
  398. return mvdev->desc == (void __iomem *)data;
  399. }
  400. static void mic_handle_config_change(struct mic_device_desc __iomem *d,
  401. unsigned int offset, struct mic_driver *mdrv)
  402. {
  403. struct mic_device_ctrl __iomem *dc
  404. = (void __iomem *)d + mic_aligned_desc_size(d);
  405. struct mic_vdev *mvdev = (struct mic_vdev *)ioread64(&dc->vdev);
  406. if (ioread8(&dc->config_change) != MIC_VIRTIO_PARAM_CONFIG_CHANGED)
  407. return;
  408. dev_dbg(mdrv->dev, "%s %d\n", __func__, __LINE__);
  409. virtio_config_changed(&mvdev->vdev);
  410. iowrite8(1, &dc->guest_ack);
  411. }
  412. /*
  413. * removes a virtio device if a hot remove event has been
  414. * requested by the host.
  415. */
  416. static int mic_remove_device(struct mic_device_desc __iomem *d,
  417. unsigned int offset, struct mic_driver *mdrv)
  418. {
  419. struct mic_device_ctrl __iomem *dc
  420. = (void __iomem *)d + mic_aligned_desc_size(d);
  421. struct mic_vdev *mvdev = (struct mic_vdev *)ioread64(&dc->vdev);
  422. u8 status;
  423. int ret = -1;
  424. if (ioread8(&dc->config_change) == MIC_VIRTIO_PARAM_DEV_REMOVE) {
  425. dev_dbg(mdrv->dev,
  426. "%s %d config_change %d type %d mvdev %p\n",
  427. __func__, __LINE__,
  428. ioread8(&dc->config_change), ioread8(&d->type), mvdev);
  429. status = ioread8(&d->status);
  430. reinit_completion(&mvdev->reset_done);
  431. unregister_virtio_device(&mvdev->vdev);
  432. mic_free_card_irq(mvdev->virtio_cookie, mvdev);
  433. if (status & VIRTIO_CONFIG_S_DRIVER_OK)
  434. wait_for_completion(&mvdev->reset_done);
  435. kfree(mvdev);
  436. iowrite8(1, &dc->guest_ack);
  437. dev_dbg(mdrv->dev, "%s %d guest_ack %d\n",
  438. __func__, __LINE__, ioread8(&dc->guest_ack));
  439. ret = 0;
  440. }
  441. return ret;
  442. }
  443. #define REMOVE_DEVICES true
  444. static void mic_scan_devices(struct mic_driver *mdrv, bool remove)
  445. {
  446. s8 type;
  447. unsigned int i;
  448. struct mic_device_desc __iomem *d;
  449. struct mic_device_ctrl __iomem *dc;
  450. struct device *dev;
  451. int ret;
  452. for (i = sizeof(struct mic_bootparam); i < MIC_DP_SIZE;
  453. i += mic_total_desc_size(d)) {
  454. d = mdrv->dp + i;
  455. dc = (void __iomem *)d + mic_aligned_desc_size(d);
  456. /*
  457. * This read barrier is paired with the corresponding write
  458. * barrier on the host which is inserted before adding or
  459. * removing a virtio device descriptor, by updating the type.
  460. */
  461. rmb();
  462. type = ioread8(&d->type);
  463. /* end of list */
  464. if (type == 0)
  465. break;
  466. if (type == -1)
  467. continue;
  468. /* device already exists */
  469. dev = device_find_child(mdrv->dev, (void __force *)d,
  470. mic_match_desc);
  471. if (dev) {
  472. if (remove)
  473. iowrite8(MIC_VIRTIO_PARAM_DEV_REMOVE,
  474. &dc->config_change);
  475. put_device(dev);
  476. mic_handle_config_change(d, i, mdrv);
  477. ret = mic_remove_device(d, i, mdrv);
  478. if (!ret && !remove)
  479. iowrite8(-1, &d->type);
  480. if (remove) {
  481. iowrite8(0, &dc->config_change);
  482. iowrite8(0, &dc->guest_ack);
  483. }
  484. continue;
  485. }
  486. /* new device */
  487. dev_dbg(mdrv->dev, "%s %d Adding new virtio device %p\n",
  488. __func__, __LINE__, d);
  489. if (!remove)
  490. mic_add_device(d, i, mdrv);
  491. }
  492. }
  493. /*
  494. * mic_hotplug_device tries to find changes in the device page.
  495. */
  496. static void mic_hotplug_devices(struct work_struct *work)
  497. {
  498. struct mic_driver *mdrv = container_of(work,
  499. struct mic_driver, hotplug_work);
  500. mic_scan_devices(mdrv, !REMOVE_DEVICES);
  501. }
  502. /*
  503. * Interrupt handler for hot plug/config changes etc.
  504. */
  505. static irqreturn_t
  506. mic_extint_handler(int irq, void *data)
  507. {
  508. struct mic_driver *mdrv = (struct mic_driver *)data;
  509. dev_dbg(mdrv->dev, "%s %d hotplug work\n",
  510. __func__, __LINE__);
  511. mic_ack_interrupt(&mdrv->mdev);
  512. schedule_work(&mdrv->hotplug_work);
  513. return IRQ_HANDLED;
  514. }
  515. /*
  516. * Init function for virtio
  517. */
  518. int mic_devices_init(struct mic_driver *mdrv)
  519. {
  520. int rc;
  521. struct mic_bootparam __iomem *bootparam;
  522. int config_db;
  523. INIT_WORK(&mdrv->hotplug_work, mic_hotplug_devices);
  524. mic_scan_devices(mdrv, !REMOVE_DEVICES);
  525. config_db = mic_next_card_db();
  526. virtio_config_cookie = mic_request_card_irq(mic_extint_handler, NULL,
  527. "virtio_config_intr", mdrv,
  528. config_db);
  529. if (IS_ERR(virtio_config_cookie)) {
  530. rc = PTR_ERR(virtio_config_cookie);
  531. goto exit;
  532. }
  533. bootparam = mdrv->dp;
  534. iowrite8(config_db, &bootparam->h2c_config_db);
  535. return 0;
  536. exit:
  537. return rc;
  538. }
  539. /*
  540. * Uninit function for virtio
  541. */
  542. void mic_devices_uninit(struct mic_driver *mdrv)
  543. {
  544. struct mic_bootparam __iomem *bootparam = mdrv->dp;
  545. iowrite8(-1, &bootparam->h2c_config_db);
  546. mic_free_card_irq(virtio_config_cookie, mdrv);
  547. flush_work(&mdrv->hotplug_work);
  548. mic_scan_devices(mdrv, REMOVE_DEVICES);
  549. }