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