mic_virtio.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * Intel MIC Host driver.
  19. *
  20. */
  21. #ifndef MIC_VIRTIO_H
  22. #define MIC_VIRTIO_H
  23. #include <linux/virtio_config.h>
  24. #include <linux/mic_ioctl.h>
  25. /*
  26. * Note on endianness.
  27. * 1. Host can be both BE or LE
  28. * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
  29. * rings and ioreadXX/iowriteXX to access used ring.
  30. * 3. Device page exposed by host to guest contains LE values. Guest
  31. * accesses these using ioreadXX/iowriteXX etc. This way in general we
  32. * obey the virtio spec according to which guest works with native
  33. * endianness and host is aware of guest endianness and does all
  34. * required endianness conversion.
  35. * 4. Data provided from user space to guest (in ADD_DEVICE and
  36. * CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
  37. * in guest endianness.
  38. */
  39. /**
  40. * struct mic_vringh - Virtio ring host information.
  41. *
  42. * @vring: The MIC vring used for setting up user space mappings.
  43. * @vrh: The host VRINGH used for accessing the card vrings.
  44. * @riov: The VRINGH read kernel IOV.
  45. * @wiov: The VRINGH write kernel IOV.
  46. * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
  47. * @vr_mutex: Mutex for synchronizing access to the VRING.
  48. * @mvdev: Back pointer to MIC virtio device for vringh_notify(..).
  49. */
  50. struct mic_vringh {
  51. struct mic_vring vring;
  52. struct vringh vrh;
  53. struct vringh_kiov riov;
  54. struct vringh_kiov wiov;
  55. u16 head;
  56. struct mutex vr_mutex;
  57. struct mic_vdev *mvdev;
  58. };
  59. /**
  60. * struct mic_vdev - Host information for a card Virtio device.
  61. *
  62. * @virtio_id - Virtio device id.
  63. * @waitq - Waitqueue to allow ring3 apps to poll.
  64. * @mdev - Back pointer to host MIC device.
  65. * @poll_wake - Used for waking up threads blocked in poll.
  66. * @out_bytes - Debug stats for number of bytes copied from host to card.
  67. * @in_bytes - Debug stats for number of bytes copied from card to host.
  68. * @mvr - Store per VRING data structures.
  69. * @virtio_bh_work - Work struct used to schedule virtio bottom half handling.
  70. * @dd - Virtio device descriptor.
  71. * @dc - Virtio device control fields.
  72. * @list - List of Virtio devices.
  73. * @virtio_db - The doorbell used by the card to interrupt the host.
  74. * @virtio_cookie - The cookie returned while requesting interrupts.
  75. */
  76. struct mic_vdev {
  77. int virtio_id;
  78. wait_queue_head_t waitq;
  79. struct mic_device *mdev;
  80. int poll_wake;
  81. unsigned long out_bytes;
  82. unsigned long in_bytes;
  83. struct mic_vringh mvr[MIC_MAX_VRINGS];
  84. struct work_struct virtio_bh_work;
  85. struct mic_device_desc *dd;
  86. struct mic_device_ctrl *dc;
  87. struct list_head list;
  88. int virtio_db;
  89. struct mic_irq *virtio_cookie;
  90. };
  91. void mic_virtio_uninit(struct mic_device *mdev);
  92. int mic_virtio_add_device(struct mic_vdev *mvdev,
  93. void __user *argp);
  94. void mic_virtio_del_device(struct mic_vdev *mvdev);
  95. int mic_virtio_config_change(struct mic_vdev *mvdev,
  96. void __user *argp);
  97. int mic_virtio_copy_desc(struct mic_vdev *mvdev,
  98. struct mic_copy_desc *request);
  99. void mic_virtio_reset_devices(struct mic_device *mdev);
  100. void mic_bh_handler(struct work_struct *work);
  101. /* Helper API to obtain the MIC PCIe device */
  102. static inline struct device *mic_dev(struct mic_vdev *mvdev)
  103. {
  104. return mvdev->mdev->sdev->parent;
  105. }
  106. /* Helper API to check if a virtio device is initialized */
  107. static inline int mic_vdev_inited(struct mic_vdev *mvdev)
  108. {
  109. /* Device has not been created yet */
  110. if (!mvdev->dd || !mvdev->dd->type) {
  111. dev_err(mic_dev(mvdev), "%s %d err %d\n",
  112. __func__, __LINE__, -EINVAL);
  113. return -EINVAL;
  114. }
  115. /* Device has been removed/deleted */
  116. if (mvdev->dd->type == -1) {
  117. dev_err(mic_dev(mvdev), "%s %d err %d\n",
  118. __func__, __LINE__, -ENODEV);
  119. return -ENODEV;
  120. }
  121. return 0;
  122. }
  123. /* Helper API to check if a virtio device is running */
  124. static inline bool mic_vdevup(struct mic_vdev *mvdev)
  125. {
  126. return !!mvdev->dd->status;
  127. }
  128. #endif