cosm_bus.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2015 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 COSM Bus Driver
  19. */
  20. #ifndef _COSM_BUS_H_
  21. #define _COSM_BUS_H_
  22. #include <linux/scif.h>
  23. #include <linux/mic_common.h>
  24. #include "../common/mic_dev.h"
  25. /**
  26. * cosm_device - representation of a cosm device
  27. *
  28. * @attr_group: Pointer to list of sysfs attribute groups.
  29. * @sdev: Device for sysfs entries.
  30. * @state: MIC state.
  31. * @prev_state: MIC state previous to MIC_RESETTING
  32. * @shutdown_status: MIC status reported by card for shutdown/crashes.
  33. * @shutdown_status_int: Internal shutdown status maintained by the driver
  34. * @cosm_mutex: Mutex for synchronizing access to data structures.
  35. * @reset_trigger_work: Work for triggering reset requests.
  36. * @scif_work: Work for handling per device SCIF connections
  37. * @cmdline: Kernel command line.
  38. * @firmware: Firmware file name.
  39. * @ramdisk: Ramdisk file name.
  40. * @bootmode: Boot mode i.e. "linux" or "elf" for flash updates.
  41. * @log_buf_addr: Log buffer address for MIC.
  42. * @log_buf_len: Log buffer length address for MIC.
  43. * @state_sysfs: Sysfs dirent for notifying ring 3 about MIC state changes.
  44. * @hw_ops: the hardware bus ops for this device.
  45. * @dev: underlying device.
  46. * @index: unique position on the cosm bus
  47. * @dbg_dir: debug fs directory
  48. * @newepd: new endpoint from scif accept to be assigned to this cdev
  49. * @epd: SCIF endpoint for this cdev
  50. * @heartbeat_watchdog_enable: if heartbeat watchdog is enabled for this cdev
  51. * @sysfs_heartbeat_enable: sysfs setting for disabling heartbeat notification
  52. */
  53. struct cosm_device {
  54. const struct attribute_group **attr_group;
  55. struct device *sdev;
  56. u8 state;
  57. u8 prev_state;
  58. u8 shutdown_status;
  59. u8 shutdown_status_int;
  60. struct mutex cosm_mutex;
  61. struct work_struct reset_trigger_work;
  62. struct work_struct scif_work;
  63. char *cmdline;
  64. char *firmware;
  65. char *ramdisk;
  66. char *bootmode;
  67. void *log_buf_addr;
  68. int *log_buf_len;
  69. struct kernfs_node *state_sysfs;
  70. struct cosm_hw_ops *hw_ops;
  71. struct device dev;
  72. int index;
  73. struct dentry *dbg_dir;
  74. scif_epd_t newepd;
  75. scif_epd_t epd;
  76. bool heartbeat_watchdog_enable;
  77. bool sysfs_heartbeat_enable;
  78. };
  79. /**
  80. * cosm_driver - operations for a cosm driver
  81. *
  82. * @driver: underlying device driver (populate name and owner).
  83. * @probe: the function to call when a device is found. Returns 0 or -errno.
  84. * @remove: the function to call when a device is removed.
  85. */
  86. struct cosm_driver {
  87. struct device_driver driver;
  88. int (*probe)(struct cosm_device *dev);
  89. void (*remove)(struct cosm_device *dev);
  90. };
  91. /**
  92. * cosm_hw_ops - cosm bus ops
  93. *
  94. * @reset: trigger MIC reset
  95. * @force_reset: force MIC reset
  96. * @post_reset: inform MIC reset is complete
  97. * @ready: is MIC ready for OS download
  98. * @start: boot MIC
  99. * @stop: prepare MIC for reset
  100. * @family: return MIC HW family string
  101. * @stepping: return MIC HW stepping string
  102. * @aper: return MIC PCIe aperture
  103. */
  104. struct cosm_hw_ops {
  105. void (*reset)(struct cosm_device *cdev);
  106. void (*force_reset)(struct cosm_device *cdev);
  107. void (*post_reset)(struct cosm_device *cdev, enum mic_states state);
  108. bool (*ready)(struct cosm_device *cdev);
  109. int (*start)(struct cosm_device *cdev, int id);
  110. void (*stop)(struct cosm_device *cdev, bool force);
  111. ssize_t (*family)(struct cosm_device *cdev, char *buf);
  112. ssize_t (*stepping)(struct cosm_device *cdev, char *buf);
  113. struct mic_mw *(*aper)(struct cosm_device *cdev);
  114. };
  115. struct cosm_device *
  116. cosm_register_device(struct device *pdev, struct cosm_hw_ops *hw_ops);
  117. void cosm_unregister_device(struct cosm_device *dev);
  118. int cosm_register_driver(struct cosm_driver *drv);
  119. void cosm_unregister_driver(struct cosm_driver *drv);
  120. struct cosm_device *cosm_find_cdev_by_id(int id);
  121. static inline struct cosm_device *dev_to_cosm(struct device *dev)
  122. {
  123. return container_of(dev, struct cosm_device, dev);
  124. }
  125. static inline struct cosm_driver *drv_to_cosm(struct device_driver *drv)
  126. {
  127. return container_of(drv, struct cosm_driver, driver);
  128. }
  129. #endif /* _COSM_BUS_H */