mic_device.h 6.1 KB

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