mic_device.h 6.5 KB

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