blob: 52b12b22f4aea2477f516475c33990f774a5bb91 [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>
Siva Yerramreddyd4ef0982014-07-11 14:04:23 -070028#include <linux/dmaengine.h>
Ashutosh Dixit1da2b3e2015-09-29 18:13:26 -070029#include <linux/miscdevice.h>
Siva Yerramreddyd4ef0982014-07-11 14:04:23 -070030#include <linux/mic_bus.h>
Sudeep Dutt74321d42015-04-29 05:32:38 -070031#include "../bus/scif_bus.h"
Sudeep Duttc74c9312016-02-08 15:48:18 -080032#include "../bus/vop_bus.h"
Ashutosh Dixit1da2b3e2015-09-29 18:13:26 -070033#include "../bus/cosm_bus.h"
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -070034#include "mic_intr.h"
35
Sudeep Duttb170d8c2013-09-05 16:41:31 -070036/**
37 * enum mic_stepping - MIC stepping ids.
38 */
39enum mic_stepping {
40 MIC_A0_STEP = 0x0,
41 MIC_B0_STEP = 0x10,
42 MIC_B1_STEP = 0x11,
43 MIC_C0_STEP = 0x20,
44};
45
Ashutosh Dixit1da2b3e2015-09-29 18:13:26 -070046extern struct cosm_hw_ops cosm_hw_ops;
47
Sudeep Duttb170d8c2013-09-05 16:41:31 -070048/**
49 * struct mic_device - MIC device information for each card.
50 *
51 * @mmio: MMIO bar information.
52 * @aper: Aperture bar information.
53 * @family: The MIC family to which this device belongs.
54 * @ops: MIC HW specific operations.
55 * @id: The unique device id for this MIC device.
56 * @stepping: Stepping ID.
Ashutosh Dixit1da2b3e2015-09-29 18:13:26 -070057 * @pdev: Underlying PCI device.
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -070058 * @mic_mutex: Mutex for synchronizing access to mic_device.
59 * @intr_ops: HW specific interrupt operations.
60 * @smpt_ops: Hardware specific SMPT operations.
61 * @smpt: MIC SMPT information.
62 * @intr_info: H/W specific interrupt information.
63 * @irq_info: The OS specific irq information
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070064 * @dbg_dir: debugfs directory of this MIC device.
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070065 * @bootaddr: MIC boot address.
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070066 * @dp: virtio device page
67 * @dp_dma_addr: virtio device page DMA address.
Siva Yerramreddyd4ef0982014-07-11 14:04:23 -070068 * @dma_mbdev: MIC BUS DMA device.
Sudeep Dutt74321d42015-04-29 05:32:38 -070069 * @dma_ch - Array of DMA channels
70 * @num_dma_ch - Number of DMA channels available
71 * @scdev: SCIF device on the SCIF virtual bus.
Sudeep Duttc74c9312016-02-08 15:48:18 -080072 * @vpdev: Virtio over PCIe device on the VOP virtual bus.
Ashutosh Dixit1da2b3e2015-09-29 18:13:26 -070073 * @cosm_dev: COSM device
Sudeep Duttb170d8c2013-09-05 16:41:31 -070074 */
75struct mic_device {
76 struct mic_mw mmio;
77 struct mic_mw aper;
78 enum mic_hw_family family;
79 struct mic_hw_ops *ops;
80 int id;
81 enum mic_stepping stepping;
Ashutosh Dixit1da2b3e2015-09-29 18:13:26 -070082 struct pci_dev *pdev;
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -070083 struct mutex mic_mutex;
84 struct mic_hw_intr_ops *intr_ops;
85 struct mic_smpt_ops *smpt_ops;
86 struct mic_smpt_info *smpt;
87 struct mic_intr_info *intr_info;
88 struct mic_irq_info irq_info;
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070089 struct dentry *dbg_dir;
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070090 u32 bootaddr;
Sudeep Dutt3a6a9202013-09-05 16:41:55 -070091 void *dp;
92 dma_addr_t dp_dma_addr;
Siva Yerramreddyd4ef0982014-07-11 14:04:23 -070093 struct mbus_device *dma_mbdev;
Sudeep Dutt74321d42015-04-29 05:32:38 -070094 struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN];
95 int num_dma_ch;
96 struct scif_hw_dev *scdev;
Sudeep Duttc74c9312016-02-08 15:48:18 -080097 struct vop_device *vpdev;
Ashutosh Dixit1da2b3e2015-09-29 18:13:26 -070098 struct cosm_device *cosm_dev;
Sudeep Duttb170d8c2013-09-05 16:41:31 -070099};
100
101/**
102 * struct mic_hw_ops - MIC HW specific operations.
103 * @aper_bar: Aperture bar resource number.
104 * @mmio_bar: MMIO bar resource number.
105 * @read_spad: Read from scratch pad register.
106 * @write_spad: Write to scratch pad register.
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -0700107 * @send_intr: Send an interrupt for a particular doorbell on the card.
108 * @ack_interrupt: Hardware specific operations to ack the h/w on
109 * receipt of an interrupt.
Dasaratharaman Chandramoulidf5e4e82013-12-10 09:51:12 -0800110 * @intr_workarounds: Hardware specific workarounds needed after
111 * handling an interrupt.
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700112 * @reset: Reset the remote processor.
113 * @reset_fw_ready: Reset firmware ready field.
114 * @is_fw_ready: Check if firmware is ready for OS download.
115 * @send_firmware_intr: Send an interrupt to the card firmware.
116 * @load_mic_fw: Load firmware segments required to boot the card
117 * into card memory. This includes the kernel, command line, ramdisk etc.
118 * @get_postcode: Get post code status from firmware.
Siva Yerramreddyd4ef0982014-07-11 14:04:23 -0700119 * @dma_filter: DMA filter function to be used.
Sudeep Duttb170d8c2013-09-05 16:41:31 -0700120 */
121struct mic_hw_ops {
122 u8 aper_bar;
123 u8 mmio_bar;
124 u32 (*read_spad)(struct mic_device *mdev, unsigned int idx);
125 void (*write_spad)(struct mic_device *mdev, unsigned int idx, u32 val);
Dasaratharaman Chandramoulia01e28f2013-09-05 16:41:41 -0700126 void (*send_intr)(struct mic_device *mdev, int doorbell);
127 u32 (*ack_interrupt)(struct mic_device *mdev);
Dasaratharaman Chandramoulidf5e4e82013-12-10 09:51:12 -0800128 void (*intr_workarounds)(struct mic_device *mdev);
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700129 void (*reset)(struct mic_device *mdev);
130 void (*reset_fw_ready)(struct mic_device *mdev);
131 bool (*is_fw_ready)(struct mic_device *mdev);
132 void (*send_firmware_intr)(struct mic_device *mdev);
133 int (*load_mic_fw)(struct mic_device *mdev, const char *buf);
134 u32 (*get_postcode)(struct mic_device *mdev);
Siva Yerramreddyd4ef0982014-07-11 14:04:23 -0700135 bool (*dma_filter)(struct dma_chan *chan, void *param);
Sudeep Duttb170d8c2013-09-05 16:41:31 -0700136};
137
138/**
139 * mic_mmio_read - read from an MMIO register.
140 * @mw: MMIO register base virtual address.
141 * @offset: register offset.
142 *
143 * RETURNS: register value.
144 */
145static inline u32 mic_mmio_read(struct mic_mw *mw, u32 offset)
146{
147 return ioread32(mw->va + offset);
148}
149
150/**
151 * mic_mmio_write - write to an MMIO register.
152 * @mw: MMIO register base virtual address.
153 * @val: the data value to put into the register
154 * @offset: register offset.
155 *
156 * RETURNS: none.
157 */
158static inline void
159mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset)
160{
161 iowrite32(val, mw->va + offset);
162}
163
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700164void mic_bootparam_init(struct mic_device *mdev);
Sudeep Dutt3a6a9202013-09-05 16:41:55 -0700165void mic_create_debug_dir(struct mic_device *dev);
166void mic_delete_debug_dir(struct mic_device *dev);
167void __init mic_init_debugfs(void);
168void mic_exit_debugfs(void);
Sudeep Duttb170d8c2013-09-05 16:41:31 -0700169#endif