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