blob: 0398c696d25758fa9fe36d1a15fd97cad75b27da [file] [log] [blame]
Sudeep Duttb170d8c2013-09-05 16:41:31 -07001/*
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
Ashutosh Dixitf69bcbf2013-09-05 16:42:18 -070024#include <linux/cdev.h>
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -070025#include <linux/idr.h>
Dasaratharaman Chandramouliaf190492013-10-03 18:06:23 -070026#include <linux/notifier.h>
Bjorn Helgaas7ef36912014-02-14 14:05:18 -070027#include <linux/irqreturn.h>
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -070028
29#include "mic_intr.h"
30
Sudeep Duttb170d8c2013-09-05 16:41:31 -070031/* The maximum number of MIC devices supported in a single host system. */
32#define MIC_MAX_NUM_DEVS 256
33
34/**
35 * enum mic_hw_family - The hardware family to which a device belongs.
36 */
37enum mic_hw_family {
38 MIC_FAMILY_X100 = 0,
39 MIC_FAMILY_UNKNOWN
40};
41
42/**
43 * enum mic_stepping - MIC stepping ids.
44 */
45enum mic_stepping {
46 MIC_A0_STEP = 0x0,
47 MIC_B0_STEP = 0x10,
48 MIC_B1_STEP = 0x11,
49 MIC_C0_STEP = 0x20,
50};
51
52/**
53 * struct mic_device - MIC device information for each card.
54 *
55 * @mmio: MMIO bar information.
56 * @aper: Aperture bar information.
57 * @family: The MIC family to which this device belongs.
58 * @ops: MIC HW specific operations.
59 * @id: The unique device id for this MIC device.
60 * @stepping: Stepping ID.
61 * @attr_group: Pointer to list of sysfs attribute groups.
62 * @sdev: Device for sysfs entries.
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -070063 * @mic_mutex: Mutex for synchronizing access to mic_device.
64 * @intr_ops: HW specific interrupt operations.
65 * @smpt_ops: Hardware specific SMPT operations.
66 * @smpt: MIC SMPT information.
67 * @intr_info: H/W specific interrupt information.
68 * @irq_info: The OS specific irq information
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070069 * @dbg_dir: debugfs directory of this MIC device.
70 * @cmdline: Kernel command line.
71 * @firmware: Firmware file name.
72 * @ramdisk: Ramdisk file name.
73 * @bootmode: Boot mode i.e. "linux" or "elf" for flash updates.
74 * @bootaddr: MIC boot address.
75 * @reset_trigger_work: Work for triggering reset requests.
76 * @shutdown_work: Work for handling shutdown interrupts.
77 * @state: MIC state.
78 * @shutdown_status: MIC status reported by card for shutdown/crashes.
79 * @state_sysfs: Sysfs dirent for notifying ring 3 about MIC state changes.
Dasaratharaman Chandramouliaf190492013-10-03 18:06:23 -070080 * @reset_wait: Waitqueue for sleeping while reset completes.
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070081 * @log_buf_addr: Log buffer address for MIC.
82 * @log_buf_len: Log buffer length address for MIC.
83 * @dp: virtio device page
84 * @dp_dma_addr: virtio device page DMA address.
85 * @shutdown_db: shutdown doorbell.
86 * @shutdown_cookie: shutdown cookie.
Ashutosh Dixitf69bcbf2013-09-05 16:42:18 -070087 * @cdev: Character device for MIC.
88 * @vdev_list: list of virtio devices.
Dasaratharaman Chandramouliaf190492013-10-03 18:06:23 -070089 * @pm_notifier: Handles PM notifications from the OS.
Sudeep Duttb170d8c2013-09-05 16:41:31 -070090 */
91struct mic_device {
92 struct mic_mw mmio;
93 struct mic_mw aper;
94 enum mic_hw_family family;
95 struct mic_hw_ops *ops;
96 int id;
97 enum mic_stepping stepping;
98 const struct attribute_group **attr_group;
99 struct device *sdev;
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -0700100 struct mutex mic_mutex;
101 struct mic_hw_intr_ops *intr_ops;
102 struct mic_smpt_ops *smpt_ops;
103 struct mic_smpt_info *smpt;
104 struct mic_intr_info *intr_info;
105 struct mic_irq_info irq_info;
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700106 struct dentry *dbg_dir;
107 char *cmdline;
108 char *firmware;
109 char *ramdisk;
110 char *bootmode;
111 u32 bootaddr;
112 struct work_struct reset_trigger_work;
113 struct work_struct shutdown_work;
114 u8 state;
115 u8 shutdown_status;
Tejun Heo324a56e2013-12-11 14:11:53 -0500116 struct kernfs_node *state_sysfs;
Dasaratharaman Chandramouliaf190492013-10-03 18:06:23 -0700117 struct completion reset_wait;
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700118 void *log_buf_addr;
119 int *log_buf_len;
120 void *dp;
121 dma_addr_t dp_dma_addr;
122 int shutdown_db;
123 struct mic_irq *shutdown_cookie;
Ashutosh Dixitf69bcbf2013-09-05 16:42:18 -0700124 struct cdev cdev;
125 struct list_head vdev_list;
Dasaratharaman Chandramouliaf190492013-10-03 18:06:23 -0700126 struct notifier_block pm_notifier;
Sudeep Duttb170d8c2013-09-05 16:41:31 -0700127};
128
129/**
130 * struct mic_hw_ops - MIC HW specific operations.
131 * @aper_bar: Aperture bar resource number.
132 * @mmio_bar: MMIO bar resource number.
133 * @read_spad: Read from scratch pad register.
134 * @write_spad: Write to scratch pad register.
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -0700135 * @send_intr: Send an interrupt for a particular doorbell on the card.
136 * @ack_interrupt: Hardware specific operations to ack the h/w on
137 * receipt of an interrupt.
Dasaratharaman Chandramoulidf5e4e82013-12-10 09:51:12 -0800138 * @intr_workarounds: Hardware specific workarounds needed after
139 * handling an interrupt.
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700140 * @reset: Reset the remote processor.
141 * @reset_fw_ready: Reset firmware ready field.
142 * @is_fw_ready: Check if firmware is ready for OS download.
143 * @send_firmware_intr: Send an interrupt to the card firmware.
144 * @load_mic_fw: Load firmware segments required to boot the card
145 * into card memory. This includes the kernel, command line, ramdisk etc.
146 * @get_postcode: Get post code status from firmware.
Sudeep Duttb170d8c2013-09-05 16:41:31 -0700147 */
148struct mic_hw_ops {
149 u8 aper_bar;
150 u8 mmio_bar;
151 u32 (*read_spad)(struct mic_device *mdev, unsigned int idx);
152 void (*write_spad)(struct mic_device *mdev, unsigned int idx, u32 val);
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -0700153 void (*send_intr)(struct mic_device *mdev, int doorbell);
154 u32 (*ack_interrupt)(struct mic_device *mdev);
Dasaratharaman Chandramoulidf5e4e82013-12-10 09:51:12 -0800155 void (*intr_workarounds)(struct mic_device *mdev);
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700156 void (*reset)(struct mic_device *mdev);
157 void (*reset_fw_ready)(struct mic_device *mdev);
158 bool (*is_fw_ready)(struct mic_device *mdev);
159 void (*send_firmware_intr)(struct mic_device *mdev);
160 int (*load_mic_fw)(struct mic_device *mdev, const char *buf);
161 u32 (*get_postcode)(struct mic_device *mdev);
Sudeep Duttb170d8c2013-09-05 16:41:31 -0700162};
163
164/**
165 * mic_mmio_read - read from an MMIO register.
166 * @mw: MMIO register base virtual address.
167 * @offset: register offset.
168 *
169 * RETURNS: register value.
170 */
171static inline u32 mic_mmio_read(struct mic_mw *mw, u32 offset)
172{
173 return ioread32(mw->va + offset);
174}
175
176/**
177 * mic_mmio_write - write to an MMIO register.
178 * @mw: MMIO register base virtual address.
179 * @val: the data value to put into the register
180 * @offset: register offset.
181 *
182 * RETURNS: none.
183 */
184static inline void
185mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset)
186{
187 iowrite32(val, mw->va + offset);
188}
189
190void mic_sysfs_init(struct mic_device *mdev);
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700191int mic_start(struct mic_device *mdev, const char *buf);
192void mic_stop(struct mic_device *mdev, bool force);
193void mic_shutdown(struct mic_device *mdev);
194void mic_reset_delayed_work(struct work_struct *work);
195void mic_reset_trigger_work(struct work_struct *work);
196void mic_shutdown_work(struct work_struct *work);
197void mic_bootparam_init(struct mic_device *mdev);
198void mic_set_state(struct mic_device *mdev, u8 state);
199void mic_set_shutdown_status(struct mic_device *mdev, u8 status);
200void mic_create_debug_dir(struct mic_device *dev);
201void mic_delete_debug_dir(struct mic_device *dev);
202void __init mic_init_debugfs(void);
203void mic_exit_debugfs(void);
Dasaratharaman Chandramouliaf190492013-10-03 18:06:23 -0700204void mic_prepare_suspend(struct mic_device *mdev);
205void mic_complete_resume(struct mic_device *mdev);
206void mic_suspend(struct mic_device *mdev);
Sudeep Duttb170d8c2013-09-05 16:41:31 -0700207#endif