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