1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF 0x3725
50#define PCI_DEVICE_ID_INTEL_NTB_PS_JSF 0x3726
51#define PCI_DEVICE_ID_INTEL_NTB_SS_JSF 0x3727
52#define PCI_DEVICE_ID_INTEL_NTB_B2B_SNB 0x3C0D
53#define PCI_DEVICE_ID_INTEL_NTB_PS_SNB 0x3C0E
54#define PCI_DEVICE_ID_INTEL_NTB_SS_SNB 0x3C0F
55#define PCI_DEVICE_ID_INTEL_NTB_B2B_IVT 0x0E0D
56#define PCI_DEVICE_ID_INTEL_NTB_PS_IVT 0x0E0E
57#define PCI_DEVICE_ID_INTEL_NTB_SS_IVT 0x0E0F
58#define PCI_DEVICE_ID_INTEL_NTB_B2B_HSX 0x2F0D
59#define PCI_DEVICE_ID_INTEL_NTB_PS_HSX 0x2F0E
60#define PCI_DEVICE_ID_INTEL_NTB_SS_HSX 0x2F0F
61#define PCI_DEVICE_ID_INTEL_NTB_B2B_BWD 0x0C4E
62
63#define msix_table_size(control) ((control & PCI_MSIX_FLAGS_QSIZE)+1)
64
65#ifndef readq
66static inline u64 readq(void __iomem *addr)
67{
68 return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
69}
70#endif
71
72#ifndef writeq
73static inline void writeq(u64 val, void __iomem *addr)
74{
75 writel(val & 0xffffffff, addr);
76 writel(val >> 32, addr + 4);
77}
78#endif
79
80#define NTB_BAR_MMIO 0
81#define NTB_BAR_23 2
82#define NTB_BAR_45 4
83#define NTB_BAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
84 (1 << NTB_BAR_45))
85
86#define NTB_LINK_DOWN 0
87#define NTB_LINK_UP 1
88
89#define NTB_HB_TIMEOUT msecs_to_jiffies(1000)
90
91#define NTB_MAX_NUM_MW 2
92
93enum ntb_hw_event {
94 NTB_EVENT_SW_EVENT0 = 0,
95 NTB_EVENT_SW_EVENT1,
96 NTB_EVENT_SW_EVENT2,
97 NTB_EVENT_HW_ERROR,
98 NTB_EVENT_HW_LINK_UP,
99 NTB_EVENT_HW_LINK_DOWN,
100};
101
102struct ntb_mw {
103 dma_addr_t phys_addr;
104 void __iomem *vbase;
105 resource_size_t bar_sz;
106};
107
108struct ntb_db_cb {
109 void (*callback) (void *data, int db_num);
110 unsigned int db_num;
111 void *data;
112 struct ntb_device *ndev;
113};
114
115struct ntb_device {
116 struct pci_dev *pdev;
117 struct msix_entry *msix_entries;
118 void __iomem *reg_base;
119 struct ntb_mw mw[NTB_MAX_NUM_MW];
120 struct {
121 unsigned char max_mw;
122 unsigned char max_spads;
123 unsigned char max_db_bits;
124 unsigned char msix_cnt;
125 } limits;
126 struct {
127 void __iomem *ldb;
128 void __iomem *ldb_mask;
129 void __iomem *rdb;
130 void __iomem *bar2_xlat;
131 void __iomem *bar4_xlat;
132 void __iomem *spad_write;
133 void __iomem *spad_read;
134 void __iomem *lnk_cntl;
135 void __iomem *lnk_stat;
136 void __iomem *spci_cmd;
137 } reg_ofs;
138 struct ntb_transport *ntb_transport;
139 void (*event_cb)(void *handle, enum ntb_hw_event event);
140
141 struct ntb_db_cb *db_cb;
142 unsigned char hw_type;
143 unsigned char conn_type;
144 unsigned char dev_type;
145 unsigned char num_msix;
146 unsigned char bits_per_vector;
147 unsigned char max_cbs;
148 unsigned char link_width;
149 unsigned char link_speed;
150 unsigned char link_status;
151
152 struct delayed_work hb_timer;
153 unsigned long last_ts;
154
155 struct delayed_work lr_timer;
156
157 struct dentry *debugfs_dir;
158};
159
160
161
162
163
164
165
166
167
168static inline unsigned char ntb_max_cbs(struct ntb_device *ndev)
169{
170 return ndev->max_cbs;
171}
172
173
174
175
176
177
178
179
180
181static inline unsigned char ntb_max_mw(struct ntb_device *ndev)
182{
183 return ndev->limits.max_mw;
184}
185
186
187
188
189
190
191
192
193
194static inline bool ntb_hw_link_status(struct ntb_device *ndev)
195{
196 return ndev->link_status == NTB_LINK_UP;
197}
198
199
200
201
202
203
204
205
206
207static inline struct pci_dev *ntb_query_pdev(struct ntb_device *ndev)
208{
209 return ndev->pdev;
210}
211
212
213
214
215
216
217
218
219
220
221static inline struct dentry *ntb_query_debugfs(struct ntb_device *ndev)
222{
223 return ndev->debugfs_dir;
224}
225
226struct ntb_device *ntb_register_transport(struct pci_dev *pdev,
227 void *transport);
228void ntb_unregister_transport(struct ntb_device *ndev);
229void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr);
230int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx,
231 void *data, void (*db_cb_func) (void *data,
232 int db_num));
233void ntb_unregister_db_callback(struct ntb_device *ndev, unsigned int idx);
234int ntb_register_event_callback(struct ntb_device *ndev,
235 void (*event_cb_func) (void *handle,
236 enum ntb_hw_event event));
237void ntb_unregister_event_callback(struct ntb_device *ndev);
238int ntb_get_max_spads(struct ntb_device *ndev);
239int ntb_write_local_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
240int ntb_read_local_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
241int ntb_write_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
242int ntb_read_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
243resource_size_t ntb_get_mw_base(struct ntb_device *ndev, unsigned int mw);
244void __iomem *ntb_get_mw_vbase(struct ntb_device *ndev, unsigned int mw);
245u64 ntb_get_mw_size(struct ntb_device *ndev, unsigned int mw);
246void ntb_ring_doorbell(struct ntb_device *ndev, unsigned int idx);
247void *ntb_find_transport(struct pci_dev *pdev);
248
249int ntb_transport_init(struct pci_dev *pdev);
250void ntb_transport_free(void *transport);
251