mic_device.h 7.5 KB

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