aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshutosh Dixit <ashutosh.dixit@intel.com>2015-09-29 21:12:03 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-10-04 07:46:06 -0400
commita3283d831a71d53234fcc279e0d9ed262cef94d5 (patch)
treeef96662b886b471af5fe1478800562116d32a19c
parentd3d912eb7386b7512f131b34407978cecccb3703 (diff)
misc: mic: MIC COSM bus
The MIC COSM bus allows the co-processor state management (COSM) functionality to be shared between multiple generations of Intel MIC products. The COSM driver registers itself on the COSM bus. The base PCIe drivers implement the bus ops and register COSM devices on the bus, resulting in the COSM driver being probed with the COSM devices. COSM bus ops, e.g. start, stop, ready, reset, therefore abstract out common functionality from its specific implementation for individual generations of MIC products. Reviewed-by: Nikhil Rao <nikhil.rao@intel.com> Reviewed-by: Sudeep Dutt <sudeep.dutt@intel.com> Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/mic/Kconfig22
-rw-r--r--drivers/misc/mic/bus/Makefile1
-rw-r--r--drivers/misc/mic/bus/cosm_bus.c141
-rw-r--r--drivers/misc/mic/bus/cosm_bus.h134
4 files changed, 296 insertions, 2 deletions
diff --git a/drivers/misc/mic/Kconfig b/drivers/misc/mic/Kconfig
index e9f2f56c370d..1488232317c5 100644
--- a/drivers/misc/mic/Kconfig
+++ b/drivers/misc/mic/Kconfig
@@ -36,7 +36,7 @@ comment "Intel MIC Host Driver"
36 36
37config INTEL_MIC_HOST 37config INTEL_MIC_HOST
38 tristate "Intel MIC Host Driver" 38 tristate "Intel MIC Host Driver"
39 depends on 64BIT && PCI && X86 && INTEL_MIC_BUS && SCIF_BUS 39 depends on 64BIT && PCI && X86 && INTEL_MIC_BUS && SCIF_BUS && MIC_COSM
40 select VHOST_RING 40 select VHOST_RING
41 help 41 help
42 This enables Host Driver support for the Intel Many Integrated 42 This enables Host Driver support for the Intel Many Integrated
@@ -56,7 +56,7 @@ comment "Intel MIC Card Driver"
56 56
57config INTEL_MIC_CARD 57config INTEL_MIC_CARD
58 tristate "Intel MIC Card Driver" 58 tristate "Intel MIC Card Driver"
59 depends on 64BIT && X86 && INTEL_MIC_BUS && SCIF_BUS 59 depends on 64BIT && X86 && INTEL_MIC_BUS && SCIF_BUS && MIC_COSM
60 select VIRTIO 60 select VIRTIO
61 help 61 help
62 This enables card driver support for the Intel Many Integrated 62 This enables card driver support for the Intel Many Integrated
@@ -88,3 +88,21 @@ config SCIF
88 More information about the Intel MIC family as well as the Linux 88 More information about the Intel MIC family as well as the Linux
89 OS and tools for MIC to use with this driver are available from 89 OS and tools for MIC to use with this driver are available from
90 <http://software.intel.com/en-us/mic-developer>. 90 <http://software.intel.com/en-us/mic-developer>.
91
92comment "Intel MIC Coprocessor State Management (COSM) Drivers"
93
94config MIC_COSM
95 tristate "Intel MIC Coprocessor State Management (COSM) Drivers"
96 depends on 64BIT && PCI && X86 && SCIF
97 help
98 This enables COSM driver support for the Intel Many
99 Integrated Core (MIC) family of PCIe form factor coprocessor
100 devices. COSM drivers implement functions such as boot,
101 shutdown, reset and reboot of MIC devices.
102
103 If you are building a host kernel with an Intel MIC device then
104 say M (recommended) or Y, else say N. If unsure say N.
105
106 More information about the Intel MIC family as well as the Linux
107 OS and tools for MIC to use with this driver are available from
108 <http://software.intel.com/en-us/mic-developer>.
diff --git a/drivers/misc/mic/bus/Makefile b/drivers/misc/mic/bus/Makefile
index 1ed37e234c96..761842b0d0bb 100644
--- a/drivers/misc/mic/bus/Makefile
+++ b/drivers/misc/mic/bus/Makefile
@@ -4,3 +4,4 @@
4# 4#
5obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o 5obj-$(CONFIG_INTEL_MIC_BUS) += mic_bus.o
6obj-$(CONFIG_SCIF_BUS) += scif_bus.o 6obj-$(CONFIG_SCIF_BUS) += scif_bus.o
7obj-$(CONFIG_MIC_COSM) += cosm_bus.o
diff --git a/drivers/misc/mic/bus/cosm_bus.c b/drivers/misc/mic/bus/cosm_bus.c
new file mode 100644
index 000000000000..1e36830f1a4e
--- /dev/null
+++ b/drivers/misc/mic/bus/cosm_bus.c
@@ -0,0 +1,141 @@
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#include <linux/slab.h>
21#include <linux/module.h>
22#include <linux/idr.h>
23#include "cosm_bus.h"
24
25/* Unique numbering for cosm devices. */
26static DEFINE_IDA(cosm_index_ida);
27
28static int cosm_dev_probe(struct device *d)
29{
30 struct cosm_device *dev = dev_to_cosm(d);
31 struct cosm_driver *drv = drv_to_cosm(dev->dev.driver);
32
33 return drv->probe(dev);
34}
35
36static int cosm_dev_remove(struct device *d)
37{
38 struct cosm_device *dev = dev_to_cosm(d);
39 struct cosm_driver *drv = drv_to_cosm(dev->dev.driver);
40
41 drv->remove(dev);
42 return 0;
43}
44
45static struct bus_type cosm_bus = {
46 .name = "cosm_bus",
47 .probe = cosm_dev_probe,
48 .remove = cosm_dev_remove,
49};
50
51int cosm_register_driver(struct cosm_driver *driver)
52{
53 driver->driver.bus = &cosm_bus;
54 return driver_register(&driver->driver);
55}
56EXPORT_SYMBOL_GPL(cosm_register_driver);
57
58void cosm_unregister_driver(struct cosm_driver *driver)
59{
60 driver_unregister(&driver->driver);
61}
62EXPORT_SYMBOL_GPL(cosm_unregister_driver);
63
64static inline void cosm_release_dev(struct device *d)
65{
66 struct cosm_device *cdev = dev_to_cosm(d);
67
68 kfree(cdev);
69}
70
71struct cosm_device *
72cosm_register_device(struct device *pdev, struct cosm_hw_ops *hw_ops)
73{
74 struct cosm_device *cdev;
75 int ret;
76
77 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
78 if (!cdev)
79 return ERR_PTR(-ENOMEM);
80
81 cdev->dev.parent = pdev;
82 cdev->dev.release = cosm_release_dev;
83 cdev->hw_ops = hw_ops;
84 dev_set_drvdata(&cdev->dev, cdev);
85 cdev->dev.bus = &cosm_bus;
86
87 /* Assign a unique device index and hence name */
88 ret = ida_simple_get(&cosm_index_ida, 0, 0, GFP_KERNEL);
89 if (ret < 0)
90 goto free_cdev;
91
92 cdev->index = ret;
93 cdev->dev.id = ret;
94 dev_set_name(&cdev->dev, "cosm-dev%u", cdev->index);
95
96 ret = device_register(&cdev->dev);
97 if (ret)
98 goto ida_remove;
99 return cdev;
100ida_remove:
101 ida_simple_remove(&cosm_index_ida, cdev->index);
102free_cdev:
103 kfree(cdev);
104 return ERR_PTR(ret);
105}
106EXPORT_SYMBOL_GPL(cosm_register_device);
107
108void cosm_unregister_device(struct cosm_device *dev)
109{
110 int index = dev->index; /* save for after device release */
111
112 device_unregister(&dev->dev);
113 ida_simple_remove(&cosm_index_ida, index);
114}
115EXPORT_SYMBOL_GPL(cosm_unregister_device);
116
117struct cosm_device *cosm_find_cdev_by_id(int id)
118{
119 struct device *dev = subsys_find_device_by_id(&cosm_bus, id, NULL);
120
121 return dev ? container_of(dev, struct cosm_device, dev) : NULL;
122}
123EXPORT_SYMBOL_GPL(cosm_find_cdev_by_id);
124
125static int __init cosm_init(void)
126{
127 return bus_register(&cosm_bus);
128}
129
130static void __exit cosm_exit(void)
131{
132 bus_unregister(&cosm_bus);
133 ida_destroy(&cosm_index_ida);
134}
135
136core_initcall(cosm_init);
137module_exit(cosm_exit);
138
139MODULE_AUTHOR("Intel Corporation");
140MODULE_DESCRIPTION("Intel(R) MIC card OS state management bus driver");
141MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/mic/bus/cosm_bus.h b/drivers/misc/mic/bus/cosm_bus.h
new file mode 100644
index 000000000000..f7c57f266916
--- /dev/null
+++ b/drivers/misc/mic/bus/cosm_bus.h
@@ -0,0 +1,134 @@
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 */