mic_device.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_DEVICE_H_
  22. #define _MIC_DEVICE_H_
  23. #include <linux/cdev.h>
  24. #include <linux/idr.h>
  25. #include <linux/notifier.h>
  26. #include <linux/irqreturn.h>
  27. #include <linux/dmaengine.h>
  28. #include <linux/mic_bus.h>
  29. #include "mic_intr.h"
  30. /* The maximum number of MIC devices supported in a single host system. */
  31. #define MIC_MAX_NUM_DEVS 256
  32. /**
  33. * enum mic_hw_family - The hardware family to which a device belongs.
  34. */
  35. enum mic_hw_family {
  36. MIC_FAMILY_X100 = 0,
  37. MIC_FAMILY_UNKNOWN
  38. };
  39. /**
  40. * enum mic_stepping - MIC stepping ids.
  41. */
  42. enum mic_stepping {
  43. MIC_A0_STEP = 0x0,
  44. MIC_B0_STEP = 0x10,
  45. MIC_B1_STEP = 0x11,
  46. MIC_C0_STEP = 0x20,
  47. };
  48. /**
  49. * struct mic_device - MIC device information for each card.
  50. *
  51. * @mmio: MMIO bar information.
  52. * @aper: Aperture bar information.
  53. * @family: The MIC family to which this device belongs.
  54. * @ops: MIC HW specific operations.
  55. * @id: The unique device id for this MIC device.
  56. * @stepping: Stepping ID.
  57. * @attr_group: Pointer to list of sysfs attribute groups.
  58. * @sdev: Device for sysfs entries.
  59. * @mic_mutex: Mutex for synchronizing access to mic_device.
  60. * @intr_ops: HW specific interrupt operations.
  61. * @smpt_ops: Hardware specific SMPT operations.
  62. * @smpt: MIC SMPT information.
  63. * @intr_info: H/W specific interrupt information.
  64. * @irq_info: The OS specific irq information
  65. * @dbg_dir: debugfs directory of this MIC device.
  66. * @cmdline: Kernel command line.
  67. * @firmware: Firmware file name.
  68. * @ramdisk: Ramdisk file name.
  69. * @bootmode: Boot mode i.e. "linux" or "elf" for flash updates.
  70. * @bootaddr: MIC boot address.
  71. * @reset_trigger_work: Work for triggering reset requests.
  72. * @shutdown_work: Work for handling shutdown interrupts.
  73. * @state: MIC state.
  74. * @shutdown_status: MIC status reported by card for shutdown/crashes.
  75. * @state_sysfs: Sysfs dirent for notifying ring 3 about MIC state changes.
  76. * @reset_wait: Waitqueue for sleeping while reset completes.
  77. * @log_buf_addr: Log buffer address for MIC.
  78. * @log_buf_len: Log buffer length address for MIC.
  79. * @dp: virtio device page
  80. * @dp_dma_addr: virtio device page DMA address.
  81. * @shutdown_db: shutdown doorbell.
  82. * @shutdown_cookie: shutdown cookie.
  83. * @cdev: Character device for MIC.
  84. * @vdev_list: list of virtio devices.
  85. * @pm_notifier: Handles PM notifications from the OS.
  86. * @dma_mbdev: MIC BUS DMA device.
  87. * @dma_ch: DMA channel reserved by this driver for use by virtio devices.
  88. */
  89. struct mic_device {
  90. struct mic_mw mmio;
  91. struct mic_mw aper;
  92. enum mic_hw_family family;
  93. struct mic_hw_ops *ops;
  94. int id;
  95. enum mic_stepping stepping;
  96. const struct attribute_group **attr_group;
  97. struct device *sdev;
  98. struct mutex mic_mutex;
  99. struct mic_hw_intr_ops *intr_ops;
  100. struct mic_smpt_ops *smpt_ops;
  101. struct mic_smpt_info *smpt;
  102. struct mic_intr_info *intr_info;
  103. struct mic_irq_info irq_info;
  104. struct dentry *dbg_dir;
  105. char *cmdline;
  106. char *firmware;
  107. char *ramdisk;
  108. char *bootmode;
  109. u32 bootaddr;
  110. struct work_struct reset_trigger_work;
  111. struct work_struct shutdown_work;
  112. u8 state;
  113. u8 shutdown_status;
  114. struct kernfs_node *state_sysfs;
  115. struct completion reset_wait;
  116. void *log_buf_addr;
  117. int *log_buf_len;
  118. void *dp;
  119. dma_addr_t dp_dma_addr;
  120. int shutdown_db;
  121. struct mic_irq *shutdown_cookie;
  122. struct cdev cdev;
  123. struct list_head vdev_list;
  124. struct notifier_block pm_notifier;
  125. struct mbus_device *dma_mbdev;
  126. struct dma_chan *dma_ch;
  127. };
  128. /**
  129. * struct mic_hw_ops - MIC HW specific operations.
  130. * @aper_bar: Aperture bar resource number.
  131. * @mmio_bar: MMIO bar resource number.
  132. * @read_spad: Read from scratch pad register.
  133. * @write_spad: Write to scratch pad register.
  134. * @send_intr: Send an interrupt for a particular doorbell on the card.
  135. * @ack_interrupt: Hardware specific operations to ack the h/w on
  136. * receipt of an interrupt.
  137. * @intr_workarounds: Hardware specific workarounds needed after
  138. * handling an interrupt.
  139. * @reset: Reset the remote processor.
  140. * @reset_fw_ready: Reset firmware ready field.
  141. * @is_fw_ready: Check if firmware is ready for OS download.
  142. * @send_firmware_intr: Send an interrupt to the card firmware.
  143. * @load_mic_fw: Load firmware segments required to boot the card
  144. * into card memory. This includes the kernel, command line, ramdisk etc.
  145. * @get_postcode: Get post code status from firmware.
  146. * @dma_filter: DMA filter function to be used.
  147. */
  148. struct mic_hw_ops {
  149. u8 aper_bar;
  150. u8 mmio_bar;
  151. u32 (*read_spad)(struct mic_device *mdev, unsigned int idx);
  152. void (*write_spad)(struct mic_device *mdev, unsigned int idx, u32 val);
  153. void (*send_intr)(struct mic_device *mdev, int doorbell);
  154. u32 (*ack_interrupt)(struct mic_device *mdev);
  155. void (*intr_workarounds)(struct mic_device *mdev);
  156. void (*reset)(struct mic_device *mdev);
  157. void (*reset_fw_ready)(struct mic_device *mdev);
  158. bool (*is_fw_ready)(struct mic_device *mdev);
  159. void (*send_firmware_intr)(struct mic_device *mdev);
  160. int (*load_mic_fw)(struct mic_device *mdev, const char *buf);
  161. u32 (*get_postcode)(struct mic_device *mdev);
  162. bool (*dma_filter)(struct dma_chan *chan, void *param);
  163. };
  164. /**
  165. * mic_mmio_read - read from an MMIO register.
  166. * @mw: MMIO register base virtual address.
  167. * @offset: register offset.
  168. *
  169. * RETURNS: register value.
  170. */
  171. static inline u32 mic_mmio_read(struct mic_mw *mw, u32 offset)
  172. {
  173. return ioread32(mw->va + offset);
  174. }
  175. /**
  176. * mic_mmio_write - write to an MMIO register.
  177. * @mw: MMIO register base virtual address.
  178. * @val: the data value to put into the register
  179. * @offset: register offset.
  180. *
  181. * RETURNS: none.
  182. */
  183. static inline void
  184. mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset)
  185. {
  186. iowrite32(val, mw->va + offset);
  187. }
  188. static inline struct dma_chan *mic_request_dma_chan(struct mic_device *mdev)
  189. {
  190. dma_cap_mask_t mask;
  191. struct dma_chan *chan;
  192. dma_cap_zero(mask);
  193. dma_cap_set(DMA_MEMCPY, mask);
  194. chan = dma_request_channel(mask, mdev->ops->dma_filter,
  195. mdev->sdev->parent);
  196. if (chan)
  197. return chan;
  198. dev_err(mdev->sdev->parent, "%s %d unable to acquire channel\n",
  199. __func__, __LINE__);
  200. return NULL;
  201. }
  202. void mic_sysfs_init(struct mic_device *mdev);
  203. int mic_start(struct mic_device *mdev, const char *buf);
  204. void mic_stop(struct mic_device *mdev, bool force);
  205. void mic_shutdown(struct mic_device *mdev);
  206. void mic_reset_delayed_work(struct work_struct *work);
  207. void mic_reset_trigger_work(struct work_struct *work);
  208. void mic_shutdown_work(struct work_struct *work);
  209. void mic_bootparam_init(struct mic_device *mdev);
  210. void mic_set_state(struct mic_device *mdev, u8 state);
  211. void mic_set_shutdown_status(struct mic_device *mdev, u8 status);
  212. void mic_create_debug_dir(struct mic_device *dev);
  213. void mic_delete_debug_dir(struct mic_device *dev);
  214. void __init mic_init_debugfs(void);
  215. void mic_exit_debugfs(void);
  216. void mic_prepare_suspend(struct mic_device *mdev);
  217. void mic_complete_resume(struct mic_device *mdev);
  218. void mic_suspend(struct mic_device *mdev);
  219. #endif