| 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> |
| Bjorn Helgaas | 7ef3691 | 2014-02-14 14:05:18 -0700 | [diff] [blame] | 27 | #include <linux/irqreturn.h> |
| Siva Yerramreddy | d4ef098 | 2014-07-11 14:04:23 -0700 | [diff] [blame] | 28 | #include <linux/dmaengine.h> |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 29 | #include <linux/miscdevice.h> |
| Siva Yerramreddy | d4ef098 | 2014-07-11 14:04:23 -0700 | [diff] [blame] | 30 | #include <linux/mic_bus.h> |
| Sudeep Dutt | 74321d4 | 2015-04-29 05:32:38 -0700 | [diff] [blame] | 31 | #include "../bus/scif_bus.h" |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 32 | #include "../bus/cosm_bus.h" |
| Dasaratharaman Chandramouli | a01e28f | 2013-09-05 16:41:41 -0700 | [diff] [blame] | 33 | #include "mic_intr.h" |
| 34 | |
| Sudeep Dutt | b170d8c | 2013-09-05 16:41:31 -0700 | [diff] [blame] | 35 | /** |
| 36 | * enum mic_stepping - MIC stepping ids. |
| 37 | */ |
| 38 | enum mic_stepping { |
| 39 | MIC_A0_STEP = 0x0, |
| 40 | MIC_B0_STEP = 0x10, |
| 41 | MIC_B1_STEP = 0x11, |
| 42 | MIC_C0_STEP = 0x20, |
| 43 | }; |
| 44 | |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 45 | extern struct cosm_hw_ops cosm_hw_ops; |
| 46 | |
| Sudeep Dutt | b170d8c | 2013-09-05 16:41:31 -0700 | [diff] [blame] | 47 | /** |
| 48 | * struct mic_device - MIC device information for each card. |
| 49 | * |
| 50 | * @mmio: MMIO bar information. |
| 51 | * @aper: Aperture bar information. |
| 52 | * @family: The MIC family to which this device belongs. |
| 53 | * @ops: MIC HW specific operations. |
| 54 | * @id: The unique device id for this MIC device. |
| 55 | * @stepping: Stepping ID. |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 56 | * @pdev: Underlying PCI device. |
| Dasaratharaman Chandramouli | a01e28f | 2013-09-05 16:41:41 -0700 | [diff] [blame] | 57 | * @mic_mutex: Mutex for synchronizing access to mic_device. |
| 58 | * @intr_ops: HW specific interrupt operations. |
| 59 | * @smpt_ops: Hardware specific SMPT operations. |
| 60 | * @smpt: MIC SMPT information. |
| 61 | * @intr_info: H/W specific interrupt information. |
| 62 | * @irq_info: The OS specific irq information |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 63 | * @dbg_dir: debugfs directory of this MIC device. |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 64 | * @bootaddr: MIC boot address. |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 65 | * @dp: virtio device page |
| 66 | * @dp_dma_addr: virtio device page DMA address. |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 67 | * @name: name for the misc char device |
| 68 | * @miscdev: registered misc char device |
| Ashutosh Dixit | f69bcbf | 2013-09-05 16:42:18 -0700 | [diff] [blame] | 69 | * @vdev_list: list of virtio devices. |
| Siva Yerramreddy | d4ef098 | 2014-07-11 14:04:23 -0700 | [diff] [blame] | 70 | * @dma_mbdev: MIC BUS DMA device. |
| Sudeep Dutt | 74321d4 | 2015-04-29 05:32:38 -0700 | [diff] [blame] | 71 | * @dma_ch - Array of DMA channels |
| 72 | * @num_dma_ch - Number of DMA channels available |
| 73 | * @scdev: SCIF device on the SCIF virtual bus. |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 74 | * @cosm_dev: COSM device |
| Sudeep Dutt | b170d8c | 2013-09-05 16:41:31 -0700 | [diff] [blame] | 75 | */ |
| 76 | struct mic_device { |
| 77 | struct mic_mw mmio; |
| 78 | struct mic_mw aper; |
| 79 | enum mic_hw_family family; |
| 80 | struct mic_hw_ops *ops; |
| 81 | int id; |
| 82 | enum mic_stepping stepping; |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 83 | struct pci_dev *pdev; |
| Dasaratharaman Chandramouli | a01e28f | 2013-09-05 16:41:41 -0700 | [diff] [blame] | 84 | struct mutex mic_mutex; |
| 85 | struct mic_hw_intr_ops *intr_ops; |
| 86 | struct mic_smpt_ops *smpt_ops; |
| 87 | struct mic_smpt_info *smpt; |
| 88 | struct mic_intr_info *intr_info; |
| 89 | struct mic_irq_info irq_info; |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 90 | struct dentry *dbg_dir; |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 91 | u32 bootaddr; |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 92 | void *dp; |
| 93 | dma_addr_t dp_dma_addr; |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 94 | char name[16]; |
| 95 | struct miscdevice miscdev; |
| Ashutosh Dixit | f69bcbf | 2013-09-05 16:42:18 -0700 | [diff] [blame] | 96 | struct list_head vdev_list; |
| Siva Yerramreddy | d4ef098 | 2014-07-11 14:04:23 -0700 | [diff] [blame] | 97 | struct mbus_device *dma_mbdev; |
| Sudeep Dutt | 74321d4 | 2015-04-29 05:32:38 -0700 | [diff] [blame] | 98 | struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN]; |
| 99 | int num_dma_ch; |
| 100 | struct scif_hw_dev *scdev; |
| Ashutosh Dixit | 1da2b3e | 2015-09-29 18:13:26 -0700 | [diff] [blame] | 101 | struct cosm_device *cosm_dev; |
| Sudeep Dutt | b170d8c | 2013-09-05 16:41:31 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * struct mic_hw_ops - MIC HW specific operations. |
| 106 | * @aper_bar: Aperture bar resource number. |
| 107 | * @mmio_bar: MMIO bar resource number. |
| 108 | * @read_spad: Read from scratch pad register. |
| 109 | * @write_spad: Write to scratch pad register. |
| Dasaratharaman Chandramouli | a01e28f | 2013-09-05 16:41:41 -0700 | [diff] [blame] | 110 | * @send_intr: Send an interrupt for a particular doorbell on the card. |
| 111 | * @ack_interrupt: Hardware specific operations to ack the h/w on |
| 112 | * receipt of an interrupt. |
| Dasaratharaman Chandramouli | df5e4e8 | 2013-12-10 09:51:12 -0800 | [diff] [blame] | 113 | * @intr_workarounds: Hardware specific workarounds needed after |
| 114 | * handling an interrupt. |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 115 | * @reset: Reset the remote processor. |
| 116 | * @reset_fw_ready: Reset firmware ready field. |
| 117 | * @is_fw_ready: Check if firmware is ready for OS download. |
| 118 | * @send_firmware_intr: Send an interrupt to the card firmware. |
| 119 | * @load_mic_fw: Load firmware segments required to boot the card |
| 120 | * into card memory. This includes the kernel, command line, ramdisk etc. |
| 121 | * @get_postcode: Get post code status from firmware. |
| Siva Yerramreddy | d4ef098 | 2014-07-11 14:04:23 -0700 | [diff] [blame] | 122 | * @dma_filter: DMA filter function to be used. |
| Sudeep Dutt | b170d8c | 2013-09-05 16:41:31 -0700 | [diff] [blame] | 123 | */ |
| 124 | struct mic_hw_ops { |
| 125 | u8 aper_bar; |
| 126 | u8 mmio_bar; |
| 127 | u32 (*read_spad)(struct mic_device *mdev, unsigned int idx); |
| 128 | void (*write_spad)(struct mic_device *mdev, unsigned int idx, u32 val); |
| Dasaratharaman Chandramouli | a01e28f | 2013-09-05 16:41:41 -0700 | [diff] [blame] | 129 | void (*send_intr)(struct mic_device *mdev, int doorbell); |
| 130 | u32 (*ack_interrupt)(struct mic_device *mdev); |
| Dasaratharaman Chandramouli | df5e4e8 | 2013-12-10 09:51:12 -0800 | [diff] [blame] | 131 | void (*intr_workarounds)(struct mic_device *mdev); |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 132 | void (*reset)(struct mic_device *mdev); |
| 133 | void (*reset_fw_ready)(struct mic_device *mdev); |
| 134 | bool (*is_fw_ready)(struct mic_device *mdev); |
| 135 | void (*send_firmware_intr)(struct mic_device *mdev); |
| 136 | int (*load_mic_fw)(struct mic_device *mdev, const char *buf); |
| 137 | u32 (*get_postcode)(struct mic_device *mdev); |
| Siva Yerramreddy | d4ef098 | 2014-07-11 14:04:23 -0700 | [diff] [blame] | 138 | bool (*dma_filter)(struct dma_chan *chan, void *param); |
| Sudeep Dutt | b170d8c | 2013-09-05 16:41:31 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | /** |
| 142 | * mic_mmio_read - read from an MMIO register. |
| 143 | * @mw: MMIO register base virtual address. |
| 144 | * @offset: register offset. |
| 145 | * |
| 146 | * RETURNS: register value. |
| 147 | */ |
| 148 | static inline u32 mic_mmio_read(struct mic_mw *mw, u32 offset) |
| 149 | { |
| 150 | return ioread32(mw->va + offset); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * mic_mmio_write - write to an MMIO register. |
| 155 | * @mw: MMIO register base virtual address. |
| 156 | * @val: the data value to put into the register |
| 157 | * @offset: register offset. |
| 158 | * |
| 159 | * RETURNS: none. |
| 160 | */ |
| 161 | static inline void |
| 162 | mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset) |
| 163 | { |
| 164 | iowrite32(val, mw->va + offset); |
| 165 | } |
| 166 | |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 167 | void mic_bootparam_init(struct mic_device *mdev); |
| Sudeep Dutt | 3a6a920 | 2013-09-05 16:41:55 -0700 | [diff] [blame] | 168 | void mic_create_debug_dir(struct mic_device *dev); |
| 169 | void mic_delete_debug_dir(struct mic_device *dev); |
| 170 | void __init mic_init_debugfs(void); |
| 171 | void mic_exit_debugfs(void); |
| Sudeep Dutt | b170d8c | 2013-09-05 16:41:31 -0700 | [diff] [blame] | 172 | #endif |