]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/ntb/ntb_hw.h
Merge tag 'ftracetest-3.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-bionic-kernel.git] / drivers / ntb / ntb_hw.h
CommitLineData
fce8a7bb
JM
1/*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2012 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * BSD LICENSE
14 *
15 * Copyright(c) 2012 Intel Corporation. All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 *
21 * * Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * * Redistributions in binary form must reproduce the above copy
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 * * Neither the name of Intel Corporation nor the names of its
28 * contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 * Intel PCIe NTB Linux driver
44 *
45 * Contact Information:
46 * Jon Mason <jon.mason@intel.com>
47 */
403c63cb 48#include <linux/ntb.h>
fce8a7bb
JM
49
50#define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF 0x3725
be4dac0f
JM
51#define PCI_DEVICE_ID_INTEL_NTB_PS_JSF 0x3726
52#define PCI_DEVICE_ID_INTEL_NTB_SS_JSF 0x3727
fce8a7bb 53#define PCI_DEVICE_ID_INTEL_NTB_B2B_SNB 0x3C0D
be4dac0f
JM
54#define PCI_DEVICE_ID_INTEL_NTB_PS_SNB 0x3C0E
55#define PCI_DEVICE_ID_INTEL_NTB_SS_SNB 0x3C0F
56#define PCI_DEVICE_ID_INTEL_NTB_B2B_IVT 0x0E0D
57#define PCI_DEVICE_ID_INTEL_NTB_PS_IVT 0x0E0E
58#define PCI_DEVICE_ID_INTEL_NTB_SS_IVT 0x0E0F
59#define PCI_DEVICE_ID_INTEL_NTB_B2B_HSX 0x2F0D
60#define PCI_DEVICE_ID_INTEL_NTB_PS_HSX 0x2F0E
61#define PCI_DEVICE_ID_INTEL_NTB_SS_HSX 0x2F0F
fce8a7bb
JM
62#define PCI_DEVICE_ID_INTEL_NTB_B2B_BWD 0x0C4E
63
ac477afb
JM
64#ifndef readq
65static inline u64 readq(void __iomem *addr)
66{
67 return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
68}
69#endif
70
71#ifndef writeq
72static inline void writeq(u64 val, void __iomem *addr)
73{
74 writel(val & 0xffffffff, addr);
75 writel(val >> 32, addr + 4);
76}
77#endif
78
fce8a7bb
JM
79#define NTB_BAR_MMIO 0
80#define NTB_BAR_23 2
ab760a0c
DJ
81#define NTB_BAR_4 4
82#define NTB_BAR_5 5
83
fce8a7bb 84#define NTB_BAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
ab760a0c
DJ
85 (1 << NTB_BAR_4))
86#define NTB_SPLITBAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
87 (1 << NTB_BAR_4) | (1 << NTB_BAR_5))
fce8a7bb 88
fce8a7bb
JM
89#define NTB_HB_TIMEOUT msecs_to_jiffies(1000)
90
fce8a7bb
JM
91enum ntb_hw_event {
92 NTB_EVENT_SW_EVENT0 = 0,
93 NTB_EVENT_SW_EVENT1,
94 NTB_EVENT_SW_EVENT2,
95 NTB_EVENT_HW_ERROR,
96 NTB_EVENT_HW_LINK_UP,
97 NTB_EVENT_HW_LINK_DOWN,
98};
99
100struct ntb_mw {
101 dma_addr_t phys_addr;
102 void __iomem *vbase;
103 resource_size_t bar_sz;
104};
105
106struct ntb_db_cb {
e8aeb60c 107 int (*callback)(void *data, int db_num);
fce8a7bb
JM
108 unsigned int db_num;
109 void *data;
110 struct ntb_device *ndev;
e8aeb60c 111 struct tasklet_struct irq_work;
fce8a7bb
JM
112};
113
069684e8
DJ
114#define WA_SNB_ERR 0x00000001
115
fce8a7bb
JM
116struct ntb_device {
117 struct pci_dev *pdev;
118 struct msix_entry *msix_entries;
119 void __iomem *reg_base;
ab760a0c 120 struct ntb_mw *mw;
fce8a7bb 121 struct {
948d3a65
JM
122 unsigned char max_mw;
123 unsigned char max_spads;
124 unsigned char max_db_bits;
125 unsigned char msix_cnt;
fce8a7bb
JM
126 } limits;
127 struct {
49793889
JM
128 void __iomem *ldb;
129 void __iomem *ldb_mask;
130 void __iomem *rdb;
131 void __iomem *bar2_xlat;
132 void __iomem *bar4_xlat;
ab760a0c 133 void __iomem *bar5_xlat;
fce8a7bb
JM
134 void __iomem *spad_write;
135 void __iomem *spad_read;
136 void __iomem *lnk_cntl;
137 void __iomem *lnk_stat;
138 void __iomem *spci_cmd;
139 } reg_ofs;
140 struct ntb_transport *ntb_transport;
141 void (*event_cb)(void *handle, enum ntb_hw_event event);
142
143 struct ntb_db_cb *db_cb;
144 unsigned char hw_type;
145 unsigned char conn_type;
146 unsigned char dev_type;
147 unsigned char num_msix;
148 unsigned char bits_per_vector;
149 unsigned char max_cbs;
113bf1c9
JM
150 unsigned char link_width;
151 unsigned char link_speed;
fce8a7bb 152 unsigned char link_status;
ab760a0c 153 unsigned char split_bar;
113bf1c9 154
fce8a7bb
JM
155 struct delayed_work hb_timer;
156 unsigned long last_ts;
1517a3f2 157
113bf1c9
JM
158 struct delayed_work lr_timer;
159
1517a3f2 160 struct dentry *debugfs_dir;
6465d02e 161 struct dentry *debugfs_info;
069684e8
DJ
162
163 unsigned int wa_flags;
fce8a7bb
JM
164};
165
948d3a65
JM
166/**
167 * ntb_max_cbs() - return the max callbacks
168 * @ndev: pointer to ntb_device instance
169 *
170 * Given the ntb pointer, return the maximum number of callbacks
171 *
172 * RETURNS: the maximum number of callbacks
173 */
174static inline unsigned char ntb_max_cbs(struct ntb_device *ndev)
175{
176 return ndev->max_cbs;
177}
178
179/**
180 * ntb_max_mw() - return the max number of memory windows
181 * @ndev: pointer to ntb_device instance
182 *
183 * Given the ntb pointer, return the maximum number of memory windows
184 *
185 * RETURNS: the maximum number of memory windows
186 */
187static inline unsigned char ntb_max_mw(struct ntb_device *ndev)
188{
189 return ndev->limits.max_mw;
190}
191
fce8a7bb
JM
192/**
193 * ntb_hw_link_status() - return the hardware link status
194 * @ndev: pointer to ntb_device instance
195 *
196 * Returns true if the hardware is connected to the remote system
197 *
198 * RETURNS: true or false based on the hardware link state
199 */
200static inline bool ntb_hw_link_status(struct ntb_device *ndev)
201{
202 return ndev->link_status == NTB_LINK_UP;
203}
204
205/**
206 * ntb_query_pdev() - return the pci_dev pointer
207 * @ndev: pointer to ntb_device instance
208 *
948d3a65 209 * Given the ntb pointer, return the pci_dev pointer for the NTB hardware device
fce8a7bb
JM
210 *
211 * RETURNS: a pointer to the ntb pci_dev
212 */
213static inline struct pci_dev *ntb_query_pdev(struct ntb_device *ndev)
214{
215 return ndev->pdev;
216}
217
1517a3f2
JM
218/**
219 * ntb_query_debugfs() - return the debugfs pointer
220 * @ndev: pointer to ntb_device instance
221 *
222 * Given the ntb pointer, return the debugfs directory pointer for the NTB
223 * hardware device
224 *
225 * RETURNS: a pointer to the debugfs directory
226 */
227static inline struct dentry *ntb_query_debugfs(struct ntb_device *ndev)
228{
229 return ndev->debugfs_dir;
230}
231
fce8a7bb
JM
232struct ntb_device *ntb_register_transport(struct pci_dev *pdev,
233 void *transport);
234void ntb_unregister_transport(struct ntb_device *ndev);
235void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr);
236int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx,
e8aeb60c
JM
237 void *data, int (*db_cb_func)(void *data,
238 int db_num));
fce8a7bb
JM
239void ntb_unregister_db_callback(struct ntb_device *ndev, unsigned int idx);
240int ntb_register_event_callback(struct ntb_device *ndev,
53ca4fea 241 void (*event_cb_func)(void *handle,
74465645 242 enum ntb_hw_event event));
fce8a7bb
JM
243void ntb_unregister_event_callback(struct ntb_device *ndev);
244int ntb_get_max_spads(struct ntb_device *ndev);
245int ntb_write_local_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
246int ntb_read_local_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
247int ntb_write_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
248int ntb_read_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
282a2fee 249resource_size_t ntb_get_mw_base(struct ntb_device *ndev, unsigned int mw);
74465645 250void __iomem *ntb_get_mw_vbase(struct ntb_device *ndev, unsigned int mw);
ac477afb 251u64 ntb_get_mw_size(struct ntb_device *ndev, unsigned int mw);
49793889 252void ntb_ring_doorbell(struct ntb_device *ndev, unsigned int idx);
fce8a7bb
JM
253void *ntb_find_transport(struct pci_dev *pdev);
254
255int ntb_transport_init(struct pci_dev *pdev);
256void ntb_transport_free(void *transport);