blob: 87751cfd6f4faa4f1ac69b5255bdeb3aae69cda1 [file] [log] [blame]
Jon Masonfce8a7b2012-11-16 19:27:12 -07001/*
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.
Allen Hubbee26a5842015-04-09 10:33:20 -04008 * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
Jon Masonfce8a7b2012-11-16 19:27:12 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * BSD LICENSE
15 *
16 * Copyright(c) 2012 Intel Corporation. All rights reserved.
Allen Hubbee26a5842015-04-09 10:33:20 -040017 * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
Jon Masonfce8a7b2012-11-16 19:27:12 -070018 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 *
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above copy
26 * notice, this list of conditions and the following disclaimer in
27 * the documentation and/or other materials provided with the
28 * distribution.
29 * * Neither the name of Intel Corporation nor the names of its
30 * contributors may be used to endorse or promote products derived
31 * from this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 *
45 * Intel PCIe NTB Linux driver
46 *
47 * Contact Information:
48 * Jon Mason <jon.mason@intel.com>
49 */
Allen Hubbee26a5842015-04-09 10:33:20 -040050
Jon Masonfce8a7b2012-11-16 19:27:12 -070051#include <linux/debugfs.h>
Jon Mason113bf1c2012-11-16 18:52:57 -070052#include <linux/delay.h>
Jon Masonfce8a7b2012-11-16 19:27:12 -070053#include <linux/init.h>
54#include <linux/interrupt.h>
55#include <linux/module.h>
56#include <linux/pci.h>
Jon Mason113bf1c2012-11-16 18:52:57 -070057#include <linux/random.h>
Jon Masonfce8a7b2012-11-16 19:27:12 -070058#include <linux/slab.h>
Allen Hubbee26a5842015-04-09 10:33:20 -040059#include <linux/ntb.h>
60
Allen Hubbeec110bc2015-05-07 06:45:21 -040061#include "ntb_hw_intel.h"
Jon Masonfce8a7b2012-11-16 19:27:12 -070062
Allen Hubbee26a5842015-04-09 10:33:20 -040063#define NTB_NAME "ntb_hw_intel"
64#define NTB_DESC "Intel(R) PCI-E Non-Transparent Bridge Driver"
65#define NTB_VER "2.0"
Jon Masonfce8a7b2012-11-16 19:27:12 -070066
Allen Hubbee26a5842015-04-09 10:33:20 -040067MODULE_DESCRIPTION(NTB_DESC);
Jon Masonfce8a7b2012-11-16 19:27:12 -070068MODULE_VERSION(NTB_VER);
69MODULE_LICENSE("Dual BSD/GPL");
70MODULE_AUTHOR("Intel Corporation");
71
Allen Hubbee26a5842015-04-09 10:33:20 -040072#define bar0_off(base, bar) ((base) + ((bar) << 2))
73#define bar2_off(base, bar) bar0_off(base, (bar) - 2)
Jon Masonfce8a7b2012-11-16 19:27:12 -070074
Dave Jiang2f887b92015-05-20 12:55:47 -040075static const struct intel_ntb_reg atom_reg;
76static const struct intel_ntb_alt_reg atom_pri_reg;
77static const struct intel_ntb_alt_reg atom_sec_reg;
78static const struct intel_ntb_alt_reg atom_b2b_reg;
79static const struct intel_ntb_xlat_reg atom_pri_xlat;
80static const struct intel_ntb_xlat_reg atom_sec_xlat;
81static const struct intel_ntb_reg xeon_reg;
82static const struct intel_ntb_alt_reg xeon_pri_reg;
83static const struct intel_ntb_alt_reg xeon_sec_reg;
84static const struct intel_ntb_alt_reg xeon_b2b_reg;
85static const struct intel_ntb_xlat_reg xeon_pri_xlat;
86static const struct intel_ntb_xlat_reg xeon_sec_xlat;
87static struct intel_b2b_addr xeon_b2b_usd_addr;
88static struct intel_b2b_addr xeon_b2b_dsd_addr;
Allen Hubbe42fefc82015-05-11 05:45:30 -040089static const struct ntb_dev_ops intel_ntb_ops;
90
91static const struct file_operations intel_ntb_debugfs_info;
92static struct dentry *debugfs_dir;
93
Allen Hubbee26a5842015-04-09 10:33:20 -040094static int b2b_mw_idx = -1;
95module_param(b2b_mw_idx, int, 0644);
96MODULE_PARM_DESC(b2b_mw_idx, "Use this mw idx to access the peer ntb. A "
97 "value of zero or positive starts from first mw idx, and a "
98 "negative value starts from last mw idx. Both sides MUST "
99 "set the same value here!");
Jon Masonfce8a7b2012-11-16 19:27:12 -0700100
Allen Hubbee26a5842015-04-09 10:33:20 -0400101static unsigned int b2b_mw_share;
102module_param(b2b_mw_share, uint, 0644);
103MODULE_PARM_DESC(b2b_mw_share, "If the b2b mw is large enough, configure the "
104 "ntb so that the peer ntb only occupies the first half of "
105 "the mw, so the second half can still be used as a mw. Both "
106 "sides MUST set the same value here!");
Jon Masonfce8a7b2012-11-16 19:27:12 -0700107
Dave Jiang2f887b92015-05-20 12:55:47 -0400108module_param_named(xeon_b2b_usd_bar2_addr64,
109 xeon_b2b_usd_addr.bar2_addr64, ullong, 0644);
110MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64,
111 "XEON B2B USD BAR 2 64-bit address");
Allen Hubbee26a5842015-04-09 10:33:20 -0400112
Dave Jiang2f887b92015-05-20 12:55:47 -0400113module_param_named(xeon_b2b_usd_bar4_addr64,
114 xeon_b2b_usd_addr.bar4_addr64, ullong, 0644);
115MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64,
116 "XEON B2B USD BAR 4 64-bit address");
Allen Hubbee26a5842015-04-09 10:33:20 -0400117
Dave Jiang2f887b92015-05-20 12:55:47 -0400118module_param_named(xeon_b2b_usd_bar4_addr32,
119 xeon_b2b_usd_addr.bar4_addr32, ullong, 0644);
120MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64,
121 "XEON B2B USD split-BAR 4 32-bit address");
Allen Hubbe42fefc82015-05-11 05:45:30 -0400122
Dave Jiang2f887b92015-05-20 12:55:47 -0400123module_param_named(xeon_b2b_usd_bar5_addr32,
124 xeon_b2b_usd_addr.bar5_addr32, ullong, 0644);
125MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64,
126 "XEON B2B USD split-BAR 5 32-bit address");
Allen Hubbe42fefc82015-05-11 05:45:30 -0400127
Dave Jiang2f887b92015-05-20 12:55:47 -0400128module_param_named(xeon_b2b_dsd_bar2_addr64,
129 xeon_b2b_dsd_addr.bar2_addr64, ullong, 0644);
130MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64,
131 "XEON B2B DSD BAR 2 64-bit address");
Allen Hubbe42fefc82015-05-11 05:45:30 -0400132
Dave Jiang2f887b92015-05-20 12:55:47 -0400133module_param_named(xeon_b2b_dsd_bar4_addr64,
134 xeon_b2b_dsd_addr.bar4_addr64, ullong, 0644);
135MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64,
136 "XEON B2B DSD BAR 4 64-bit address");
Allen Hubbe42fefc82015-05-11 05:45:30 -0400137
Dave Jiang2f887b92015-05-20 12:55:47 -0400138module_param_named(xeon_b2b_dsd_bar4_addr32,
139 xeon_b2b_dsd_addr.bar4_addr32, ullong, 0644);
140MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64,
141 "XEON B2B DSD split-BAR 4 32-bit address");
Allen Hubbe42fefc82015-05-11 05:45:30 -0400142
Dave Jiang2f887b92015-05-20 12:55:47 -0400143module_param_named(xeon_b2b_dsd_bar5_addr32,
144 xeon_b2b_dsd_addr.bar5_addr32, ullong, 0644);
145MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64,
146 "XEON B2B DSD split-BAR 5 32-bit address");
Jon Mason1517a3f2013-07-30 15:58:49 -0700147
Allen Hubbee26a5842015-04-09 10:33:20 -0400148#ifndef ioread64
149#ifdef readq
150#define ioread64 readq
151#else
152#define ioread64 _ioread64
153static inline u64 _ioread64(void __iomem *mmio)
154{
155 u64 low, high;
Jon Mason113bf1c2012-11-16 18:52:57 -0700156
Allen Hubbee26a5842015-04-09 10:33:20 -0400157 low = ioread32(mmio);
158 high = ioread32(mmio + sizeof(u32));
159 return low | (high << 32);
160}
161#endif
162#endif
Jon Masonfce8a7b2012-11-16 19:27:12 -0700163
Allen Hubbee26a5842015-04-09 10:33:20 -0400164#ifndef iowrite64
165#ifdef writeq
166#define iowrite64 writeq
167#else
168#define iowrite64 _iowrite64
169static inline void _iowrite64(u64 val, void __iomem *mmio)
170{
171 iowrite32(val, mmio);
172 iowrite32(val >> 32, mmio + sizeof(u32));
173}
174#endif
175#endif
176
Dave Jiang2f887b92015-05-20 12:55:47 -0400177static inline int pdev_is_atom(struct pci_dev *pdev)
Allen Hubbee26a5842015-04-09 10:33:20 -0400178{
179 switch (pdev->device) {
180 case PCI_DEVICE_ID_INTEL_NTB_B2B_BWD:
181 return 1;
182 }
183 return 0;
184}
185
Dave Jiang2f887b92015-05-20 12:55:47 -0400186static inline int pdev_is_xeon(struct pci_dev *pdev)
Allen Hubbee26a5842015-04-09 10:33:20 -0400187{
188 switch (pdev->device) {
189 case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
190 case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
191 case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
192 case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
193 case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
194 case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
195 case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
196 case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
197 case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
198 case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
199 case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
200 case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
201 return 1;
202 }
203 return 0;
204}
205
206static inline void ndev_reset_unsafe_flags(struct intel_ntb_dev *ndev)
207{
208 ndev->unsafe_flags = 0;
209 ndev->unsafe_flags_ignore = 0;
210
211 /* Only B2B has a workaround to avoid SDOORBELL */
212 if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP)
213 if (!ntb_topo_is_b2b(ndev->ntb.topo))
214 ndev->unsafe_flags |= NTB_UNSAFE_DB;
215
216 /* No low level workaround to avoid SB01BASE */
217 if (ndev->hwerr_flags & NTB_HWERR_SB01BASE_LOCKUP) {
218 ndev->unsafe_flags |= NTB_UNSAFE_DB;
219 ndev->unsafe_flags |= NTB_UNSAFE_SPAD;
220 }
221}
222
223static inline int ndev_is_unsafe(struct intel_ntb_dev *ndev,
224 unsigned long flag)
225{
226 return !!(flag & ndev->unsafe_flags & ~ndev->unsafe_flags_ignore);
227}
228
229static inline int ndev_ignore_unsafe(struct intel_ntb_dev *ndev,
230 unsigned long flag)
231{
232 flag &= ndev->unsafe_flags;
233 ndev->unsafe_flags_ignore |= flag;
234
235 return !!flag;
236}
237
238static int ndev_mw_to_bar(struct intel_ntb_dev *ndev, int idx)
239{
240 if (idx < 0 || idx > ndev->mw_count)
241 return -EINVAL;
242 return ndev->reg->mw_bar[idx];
243}
244
245static inline int ndev_db_addr(struct intel_ntb_dev *ndev,
246 phys_addr_t *db_addr, resource_size_t *db_size,
247 phys_addr_t reg_addr, unsigned long reg)
248{
Dave Jiangfd839bf2015-06-15 08:22:30 -0400249 if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
250 pr_warn_once("%s: NTB unsafe doorbell access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400251
252 if (db_addr) {
253 *db_addr = reg_addr + reg;
254 dev_dbg(ndev_dev(ndev), "Peer db addr %llx\n", *db_addr);
255 }
256
257 if (db_size) {
258 *db_size = ndev->reg->db_size;
259 dev_dbg(ndev_dev(ndev), "Peer db size %llx\n", *db_size);
260 }
261
262 return 0;
263}
264
265static inline u64 ndev_db_read(struct intel_ntb_dev *ndev,
266 void __iomem *mmio)
267{
Dave Jiangfd839bf2015-06-15 08:22:30 -0400268 if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
269 pr_warn_once("%s: NTB unsafe doorbell access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400270
271 return ndev->reg->db_ioread(mmio);
272}
273
274static inline int ndev_db_write(struct intel_ntb_dev *ndev, u64 db_bits,
275 void __iomem *mmio)
276{
Dave Jiangfd839bf2015-06-15 08:22:30 -0400277 if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
278 pr_warn_once("%s: NTB unsafe doorbell access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400279
280 if (db_bits & ~ndev->db_valid_mask)
281 return -EINVAL;
282
283 ndev->reg->db_iowrite(db_bits, mmio);
284
285 return 0;
286}
287
288static inline int ndev_db_set_mask(struct intel_ntb_dev *ndev, u64 db_bits,
289 void __iomem *mmio)
290{
291 unsigned long irqflags;
292
Dave Jiangfd839bf2015-06-15 08:22:30 -0400293 if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
294 pr_warn_once("%s: NTB unsafe doorbell access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400295
296 if (db_bits & ~ndev->db_valid_mask)
297 return -EINVAL;
298
299 spin_lock_irqsave(&ndev->db_mask_lock, irqflags);
300 {
301 ndev->db_mask |= db_bits;
302 ndev->reg->db_iowrite(ndev->db_mask, mmio);
303 }
304 spin_unlock_irqrestore(&ndev->db_mask_lock, irqflags);
305
306 return 0;
307}
308
309static inline int ndev_db_clear_mask(struct intel_ntb_dev *ndev, u64 db_bits,
310 void __iomem *mmio)
311{
312 unsigned long irqflags;
313
Dave Jiangfd839bf2015-06-15 08:22:30 -0400314 if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
315 pr_warn_once("%s: NTB unsafe doorbell access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400316
317 if (db_bits & ~ndev->db_valid_mask)
318 return -EINVAL;
319
320 spin_lock_irqsave(&ndev->db_mask_lock, irqflags);
321 {
322 ndev->db_mask &= ~db_bits;
323 ndev->reg->db_iowrite(ndev->db_mask, mmio);
324 }
325 spin_unlock_irqrestore(&ndev->db_mask_lock, irqflags);
326
327 return 0;
328}
329
330static inline int ndev_vec_mask(struct intel_ntb_dev *ndev, int db_vector)
331{
332 u64 shift, mask;
333
334 shift = ndev->db_vec_shift;
335 mask = BIT_ULL(shift) - 1;
336
337 return mask << (shift * db_vector);
338}
339
340static inline int ndev_spad_addr(struct intel_ntb_dev *ndev, int idx,
341 phys_addr_t *spad_addr, phys_addr_t reg_addr,
342 unsigned long reg)
343{
Dave Jiangfd839bf2015-06-15 08:22:30 -0400344 if (ndev_is_unsafe(ndev, NTB_UNSAFE_SPAD))
345 pr_warn_once("%s: NTB unsafe scratchpad access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400346
347 if (idx < 0 || idx >= ndev->spad_count)
348 return -EINVAL;
349
350 if (spad_addr) {
351 *spad_addr = reg_addr + reg + (idx << 2);
352 dev_dbg(ndev_dev(ndev), "Peer spad addr %llx\n", *spad_addr);
353 }
354
355 return 0;
356}
357
358static inline u32 ndev_spad_read(struct intel_ntb_dev *ndev, int idx,
359 void __iomem *mmio)
360{
Dave Jiangfd839bf2015-06-15 08:22:30 -0400361 if (ndev_is_unsafe(ndev, NTB_UNSAFE_SPAD))
362 pr_warn_once("%s: NTB unsafe scratchpad access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400363
364 if (idx < 0 || idx >= ndev->spad_count)
365 return 0;
366
367 return ioread32(mmio + (idx << 2));
368}
369
370static inline int ndev_spad_write(struct intel_ntb_dev *ndev, int idx, u32 val,
371 void __iomem *mmio)
372{
Dave Jiangfd839bf2015-06-15 08:22:30 -0400373 if (ndev_is_unsafe(ndev, NTB_UNSAFE_SPAD))
374 pr_warn_once("%s: NTB unsafe scratchpad access", __func__);
Allen Hubbee26a5842015-04-09 10:33:20 -0400375
376 if (idx < 0 || idx >= ndev->spad_count)
377 return -EINVAL;
378
379 iowrite32(val, mmio + (idx << 2));
380
381 return 0;
382}
383
384static irqreturn_t ndev_interrupt(struct intel_ntb_dev *ndev, int vec)
385{
386 u64 vec_mask;
387
388 vec_mask = ndev_vec_mask(ndev, vec);
389
390 dev_dbg(ndev_dev(ndev), "vec %d vec_mask %llx\n", vec, vec_mask);
391
392 ndev->last_ts = jiffies;
393
394 if (vec_mask & ndev->db_link_mask) {
395 if (ndev->reg->poll_link(ndev))
396 ntb_link_event(&ndev->ntb);
397 }
398
399 if (vec_mask & ndev->db_valid_mask)
400 ntb_db_event(&ndev->ntb, vec);
401
402 return IRQ_HANDLED;
403}
404
405static irqreturn_t ndev_vec_isr(int irq, void *dev)
406{
407 struct intel_ntb_vec *nvec = dev;
408
409 return ndev_interrupt(nvec->ndev, nvec->num);
410}
411
412static irqreturn_t ndev_irq_isr(int irq, void *dev)
413{
414 struct intel_ntb_dev *ndev = dev;
415
416 return ndev_interrupt(ndev, irq - ndev_pdev(ndev)->irq);
417}
418
419static int ndev_init_isr(struct intel_ntb_dev *ndev,
420 int msix_min, int msix_max,
421 int msix_shift, int total_shift)
422{
423 struct pci_dev *pdev;
Allen Hubbe0e041fb2015-05-19 12:04:52 -0400424 int rc, i, msix_count, node;
Allen Hubbee26a5842015-04-09 10:33:20 -0400425
426 pdev = ndev_pdev(ndev);
427
Allen Hubbe0e041fb2015-05-19 12:04:52 -0400428 node = dev_to_node(&pdev->dev);
429
Allen Hubbee26a5842015-04-09 10:33:20 -0400430 /* Mask all doorbell interrupts */
431 ndev->db_mask = ndev->db_valid_mask;
432 ndev->reg->db_iowrite(ndev->db_mask,
433 ndev->self_mmio +
434 ndev->self_reg->db_mask);
435
436 /* Try to set up msix irq */
437
Allen Hubbe0e041fb2015-05-19 12:04:52 -0400438 ndev->vec = kzalloc_node(msix_max * sizeof(*ndev->vec),
439 GFP_KERNEL, node);
Allen Hubbee26a5842015-04-09 10:33:20 -0400440 if (!ndev->vec)
441 goto err_msix_vec_alloc;
442
Allen Hubbe0e041fb2015-05-19 12:04:52 -0400443 ndev->msix = kzalloc_node(msix_max * sizeof(*ndev->msix),
444 GFP_KERNEL, node);
Allen Hubbee26a5842015-04-09 10:33:20 -0400445 if (!ndev->msix)
446 goto err_msix_alloc;
447
448 for (i = 0; i < msix_max; ++i)
449 ndev->msix[i].entry = i;
450
451 msix_count = pci_enable_msix_range(pdev, ndev->msix,
452 msix_min, msix_max);
453 if (msix_count < 0)
454 goto err_msix_enable;
455
456 for (i = 0; i < msix_count; ++i) {
457 ndev->vec[i].ndev = ndev;
458 ndev->vec[i].num = i;
459 rc = request_irq(ndev->msix[i].vector, ndev_vec_isr, 0,
460 "ndev_vec_isr", &ndev->vec[i]);
461 if (rc)
462 goto err_msix_request;
463 }
464
465 dev_dbg(ndev_dev(ndev), "Using msix interrupts\n");
466 ndev->db_vec_count = msix_count;
467 ndev->db_vec_shift = msix_shift;
468 return 0;
469
470err_msix_request:
471 while (i-- > 0)
472 free_irq(ndev->msix[i].vector, ndev);
473 pci_disable_msix(pdev);
474err_msix_enable:
475 kfree(ndev->msix);
476err_msix_alloc:
477 kfree(ndev->vec);
478err_msix_vec_alloc:
479 ndev->msix = NULL;
480 ndev->vec = NULL;
481
482 /* Try to set up msi irq */
483
484 rc = pci_enable_msi(pdev);
485 if (rc)
486 goto err_msi_enable;
487
488 rc = request_irq(pdev->irq, ndev_irq_isr, 0,
489 "ndev_irq_isr", ndev);
490 if (rc)
491 goto err_msi_request;
492
493 dev_dbg(ndev_dev(ndev), "Using msi interrupts\n");
494 ndev->db_vec_count = 1;
495 ndev->db_vec_shift = total_shift;
496 return 0;
497
498err_msi_request:
499 pci_disable_msi(pdev);
500err_msi_enable:
501
502 /* Try to set up intx irq */
503
504 pci_intx(pdev, 1);
505
506 rc = request_irq(pdev->irq, ndev_irq_isr, IRQF_SHARED,
507 "ndev_irq_isr", ndev);
508 if (rc)
509 goto err_intx_request;
510
511 dev_dbg(ndev_dev(ndev), "Using intx interrupts\n");
512 ndev->db_vec_count = 1;
513 ndev->db_vec_shift = total_shift;
514 return 0;
515
516err_intx_request:
517 return rc;
518}
519
520static void ndev_deinit_isr(struct intel_ntb_dev *ndev)
521{
522 struct pci_dev *pdev;
523 int i;
524
525 pdev = ndev_pdev(ndev);
526
527 /* Mask all doorbell interrupts */
528 ndev->db_mask = ndev->db_valid_mask;
529 ndev->reg->db_iowrite(ndev->db_mask,
530 ndev->self_mmio +
531 ndev->self_reg->db_mask);
532
533 if (ndev->msix) {
534 i = ndev->db_vec_count;
535 while (i--)
536 free_irq(ndev->msix[i].vector, &ndev->vec[i]);
537 pci_disable_msix(pdev);
538 kfree(ndev->msix);
539 kfree(ndev->vec);
540 } else {
541 free_irq(pdev->irq, ndev);
542 if (pci_dev_msi_enabled(pdev))
543 pci_disable_msi(pdev);
544 }
545}
546
547static ssize_t ndev_debugfs_read(struct file *filp, char __user *ubuf,
548 size_t count, loff_t *offp)
549{
550 struct intel_ntb_dev *ndev;
551 void __iomem *mmio;
552 char *buf;
553 size_t buf_size;
554 ssize_t ret, off;
555 union { u64 v64; u32 v32; u16 v16; } u;
556
557 ndev = filp->private_data;
558 mmio = ndev->self_mmio;
559
560 buf_size = min(count, 0x800ul);
561
562 buf = kmalloc(buf_size, GFP_KERNEL);
563 if (!buf)
564 return -ENOMEM;
565
566 off = 0;
567
568 off += scnprintf(buf + off, buf_size - off,
569 "NTB Device Information:\n");
570
571 off += scnprintf(buf + off, buf_size - off,
572 "Connection Topology -\t%s\n",
573 ntb_topo_string(ndev->ntb.topo));
574
575 off += scnprintf(buf + off, buf_size - off,
576 "B2B Offset -\t\t%#lx\n", ndev->b2b_off);
577 off += scnprintf(buf + off, buf_size - off,
578 "B2B MW Idx -\t\t%d\n", ndev->b2b_idx);
579 off += scnprintf(buf + off, buf_size - off,
580 "BAR4 Split -\t\t%s\n",
581 ndev->bar4_split ? "yes" : "no");
582
583 off += scnprintf(buf + off, buf_size - off,
584 "NTB CTL -\t\t%#06x\n", ndev->ntb_ctl);
585 off += scnprintf(buf + off, buf_size - off,
586 "LNK STA -\t\t%#06x\n", ndev->lnk_sta);
587
588 if (!ndev->reg->link_is_up(ndev)) {
589 off += scnprintf(buf + off, buf_size - off,
590 "Link Status -\t\tDown\n");
591 } else {
592 off += scnprintf(buf + off, buf_size - off,
593 "Link Status -\t\tUp\n");
594 off += scnprintf(buf + off, buf_size - off,
595 "Link Speed -\t\tPCI-E Gen %u\n",
596 NTB_LNK_STA_SPEED(ndev->lnk_sta));
597 off += scnprintf(buf + off, buf_size - off,
598 "Link Width -\t\tx%u\n",
599 NTB_LNK_STA_WIDTH(ndev->lnk_sta));
600 }
601
602 off += scnprintf(buf + off, buf_size - off,
603 "Memory Window Count -\t%u\n", ndev->mw_count);
604 off += scnprintf(buf + off, buf_size - off,
605 "Scratchpad Count -\t%u\n", ndev->spad_count);
606 off += scnprintf(buf + off, buf_size - off,
607 "Doorbell Count -\t%u\n", ndev->db_count);
608 off += scnprintf(buf + off, buf_size - off,
609 "Doorbell Vector Count -\t%u\n", ndev->db_vec_count);
610 off += scnprintf(buf + off, buf_size - off,
611 "Doorbell Vector Shift -\t%u\n", ndev->db_vec_shift);
612
613 off += scnprintf(buf + off, buf_size - off,
614 "Doorbell Valid Mask -\t%#llx\n", ndev->db_valid_mask);
615 off += scnprintf(buf + off, buf_size - off,
616 "Doorbell Link Mask -\t%#llx\n", ndev->db_link_mask);
617 off += scnprintf(buf + off, buf_size - off,
618 "Doorbell Mask Cached -\t%#llx\n", ndev->db_mask);
619
620 u.v64 = ndev_db_read(ndev, mmio + ndev->self_reg->db_mask);
621 off += scnprintf(buf + off, buf_size - off,
622 "Doorbell Mask -\t\t%#llx\n", u.v64);
623
624 u.v64 = ndev_db_read(ndev, mmio + ndev->self_reg->db_bell);
625 off += scnprintf(buf + off, buf_size - off,
626 "Doorbell Bell -\t\t%#llx\n", u.v64);
627
628 off += scnprintf(buf + off, buf_size - off,
629 "\nNTB Incoming XLAT:\n");
630
631 u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 2));
632 off += scnprintf(buf + off, buf_size - off,
633 "XLAT23 -\t\t%#018llx\n", u.v64);
634
Dave Jiangbf44fe42015-06-18 05:17:30 -0400635 if (ndev->bar4_split) {
636 u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 4));
637 off += scnprintf(buf + off, buf_size - off,
638 "XLAT4 -\t\t\t%#06x\n", u.v32);
639
640 u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 5));
641 off += scnprintf(buf + off, buf_size - off,
642 "XLAT5 -\t\t\t%#06x\n", u.v32);
643 } else {
644 u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 4));
645 off += scnprintf(buf + off, buf_size - off,
646 "XLAT45 -\t\t%#018llx\n", u.v64);
647 }
Allen Hubbee26a5842015-04-09 10:33:20 -0400648
649 u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 2));
650 off += scnprintf(buf + off, buf_size - off,
651 "LMT23 -\t\t\t%#018llx\n", u.v64);
652
Dave Jiangbf44fe42015-06-18 05:17:30 -0400653 if (ndev->bar4_split) {
654 u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 4));
655 off += scnprintf(buf + off, buf_size - off,
656 "LMT4 -\t\t\t%#06x\n", u.v32);
657 u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 5));
658 off += scnprintf(buf + off, buf_size - off,
659 "LMT5 -\t\t\t%#06x\n", u.v32);
660 } else {
661 u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 4));
662 off += scnprintf(buf + off, buf_size - off,
663 "LMT45 -\t\t\t%#018llx\n", u.v64);
664 }
Allen Hubbee26a5842015-04-09 10:33:20 -0400665
Dave Jiang2f887b92015-05-20 12:55:47 -0400666 if (pdev_is_xeon(ndev->ntb.pdev)) {
Allen Hubbee26a5842015-04-09 10:33:20 -0400667 if (ntb_topo_is_b2b(ndev->ntb.topo)) {
668 off += scnprintf(buf + off, buf_size - off,
669 "\nNTB Outgoing B2B XLAT:\n");
670
Dave Jiang2f887b92015-05-20 12:55:47 -0400671 u.v64 = ioread64(mmio + XEON_PBAR23XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -0400672 off += scnprintf(buf + off, buf_size - off,
673 "B2B XLAT23 -\t\t%#018llx\n", u.v64);
674
Dave Jiangbf44fe42015-06-18 05:17:30 -0400675 if (ndev->bar4_split) {
676 u.v32 = ioread32(mmio + XEON_PBAR4XLAT_OFFSET);
677 off += scnprintf(buf + off, buf_size - off,
678 "B2B XLAT4 -\t\t%#06x\n",
679 u.v32);
680 u.v32 = ioread32(mmio + XEON_PBAR5XLAT_OFFSET);
681 off += scnprintf(buf + off, buf_size - off,
682 "B2B XLAT5 -\t\t%#06x\n",
683 u.v32);
684 } else {
685 u.v64 = ioread64(mmio + XEON_PBAR45XLAT_OFFSET);
686 off += scnprintf(buf + off, buf_size - off,
687 "B2B XLAT45 -\t\t%#018llx\n",
688 u.v64);
689 }
Allen Hubbee26a5842015-04-09 10:33:20 -0400690
Dave Jiang2f887b92015-05-20 12:55:47 -0400691 u.v64 = ioread64(mmio + XEON_PBAR23LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -0400692 off += scnprintf(buf + off, buf_size - off,
693 "B2B LMT23 -\t\t%#018llx\n", u.v64);
694
Dave Jiangbf44fe42015-06-18 05:17:30 -0400695 if (ndev->bar4_split) {
696 u.v32 = ioread32(mmio + XEON_PBAR4LMT_OFFSET);
697 off += scnprintf(buf + off, buf_size - off,
698 "B2B LMT4 -\t\t%#06x\n",
699 u.v32);
700 u.v32 = ioread32(mmio + XEON_PBAR5LMT_OFFSET);
701 off += scnprintf(buf + off, buf_size - off,
702 "B2B LMT5 -\t\t%#06x\n",
703 u.v32);
704 } else {
705 u.v64 = ioread64(mmio + XEON_PBAR45LMT_OFFSET);
706 off += scnprintf(buf + off, buf_size - off,
707 "B2B LMT45 -\t\t%#018llx\n",
708 u.v64);
709 }
Allen Hubbee26a5842015-04-09 10:33:20 -0400710
711 off += scnprintf(buf + off, buf_size - off,
712 "\nNTB Secondary BAR:\n");
713
Dave Jiang2f887b92015-05-20 12:55:47 -0400714 u.v64 = ioread64(mmio + XEON_SBAR0BASE_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -0400715 off += scnprintf(buf + off, buf_size - off,
716 "SBAR01 -\t\t%#018llx\n", u.v64);
717
Dave Jiang2f887b92015-05-20 12:55:47 -0400718 u.v64 = ioread64(mmio + XEON_SBAR23BASE_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -0400719 off += scnprintf(buf + off, buf_size - off,
720 "SBAR23 -\t\t%#018llx\n", u.v64);
721
Dave Jiangbf44fe42015-06-18 05:17:30 -0400722 if (ndev->bar4_split) {
723 u.v32 = ioread32(mmio + XEON_SBAR4BASE_OFFSET);
724 off += scnprintf(buf + off, buf_size - off,
725 "SBAR4 -\t\t\t%#06x\n", u.v32);
726 u.v32 = ioread32(mmio + XEON_SBAR5BASE_OFFSET);
727 off += scnprintf(buf + off, buf_size - off,
728 "SBAR5 -\t\t\t%#06x\n", u.v32);
729 } else {
730 u.v64 = ioread64(mmio + XEON_SBAR45BASE_OFFSET);
731 off += scnprintf(buf + off, buf_size - off,
732 "SBAR45 -\t\t%#018llx\n",
733 u.v64);
734 }
Allen Hubbee26a5842015-04-09 10:33:20 -0400735 }
736
737 off += scnprintf(buf + off, buf_size - off,
Dave Jiang2f887b92015-05-20 12:55:47 -0400738 "\nXEON NTB Statistics:\n");
Allen Hubbee26a5842015-04-09 10:33:20 -0400739
Dave Jiang2f887b92015-05-20 12:55:47 -0400740 u.v16 = ioread16(mmio + XEON_USMEMMISS_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -0400741 off += scnprintf(buf + off, buf_size - off,
742 "Upstream Memory Miss -\t%u\n", u.v16);
743
744 off += scnprintf(buf + off, buf_size - off,
Dave Jiang2f887b92015-05-20 12:55:47 -0400745 "\nXEON NTB Hardware Errors:\n");
Allen Hubbee26a5842015-04-09 10:33:20 -0400746
747 if (!pci_read_config_word(ndev->ntb.pdev,
Dave Jiang2f887b92015-05-20 12:55:47 -0400748 XEON_DEVSTS_OFFSET, &u.v16))
Allen Hubbee26a5842015-04-09 10:33:20 -0400749 off += scnprintf(buf + off, buf_size - off,
750 "DEVSTS -\t\t%#06x\n", u.v16);
751
752 if (!pci_read_config_word(ndev->ntb.pdev,
Dave Jiang2f887b92015-05-20 12:55:47 -0400753 XEON_LINK_STATUS_OFFSET, &u.v16))
Allen Hubbee26a5842015-04-09 10:33:20 -0400754 off += scnprintf(buf + off, buf_size - off,
755 "LNKSTS -\t\t%#06x\n", u.v16);
756
757 if (!pci_read_config_dword(ndev->ntb.pdev,
Dave Jiang2f887b92015-05-20 12:55:47 -0400758 XEON_UNCERRSTS_OFFSET, &u.v32))
Allen Hubbee26a5842015-04-09 10:33:20 -0400759 off += scnprintf(buf + off, buf_size - off,
760 "UNCERRSTS -\t\t%#06x\n", u.v32);
761
762 if (!pci_read_config_dword(ndev->ntb.pdev,
Dave Jiang2f887b92015-05-20 12:55:47 -0400763 XEON_CORERRSTS_OFFSET, &u.v32))
Allen Hubbee26a5842015-04-09 10:33:20 -0400764 off += scnprintf(buf + off, buf_size - off,
765 "CORERRSTS -\t\t%#06x\n", u.v32);
766 }
767
768 ret = simple_read_from_buffer(ubuf, count, offp, buf, off);
769 kfree(buf);
770 return ret;
771}
772
773static void ndev_init_debugfs(struct intel_ntb_dev *ndev)
774{
775 if (!debugfs_dir) {
776 ndev->debugfs_dir = NULL;
777 ndev->debugfs_info = NULL;
778 } else {
779 ndev->debugfs_dir =
780 debugfs_create_dir(ndev_name(ndev), debugfs_dir);
781 if (!ndev->debugfs_dir)
782 ndev->debugfs_info = NULL;
783 else
784 ndev->debugfs_info =
785 debugfs_create_file("info", S_IRUSR,
786 ndev->debugfs_dir, ndev,
787 &intel_ntb_debugfs_info);
788 }
789}
790
791static void ndev_deinit_debugfs(struct intel_ntb_dev *ndev)
792{
793 debugfs_remove_recursive(ndev->debugfs_dir);
794}
795
796static int intel_ntb_mw_count(struct ntb_dev *ntb)
797{
798 return ntb_ndev(ntb)->mw_count;
799}
800
801static int intel_ntb_mw_get_range(struct ntb_dev *ntb, int idx,
802 phys_addr_t *base,
803 resource_size_t *size,
804 resource_size_t *align,
805 resource_size_t *align_size)
806{
807 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
808 int bar;
809
810 if (idx >= ndev->b2b_idx && !ndev->b2b_off)
811 idx += 1;
812
813 bar = ndev_mw_to_bar(ndev, idx);
814 if (bar < 0)
815 return bar;
816
817 if (base)
818 *base = pci_resource_start(ndev->ntb.pdev, bar) +
819 (idx == ndev->b2b_idx ? ndev->b2b_off : 0);
820
821 if (size)
822 *size = pci_resource_len(ndev->ntb.pdev, bar) -
823 (idx == ndev->b2b_idx ? ndev->b2b_off : 0);
824
825 if (align)
826 *align = pci_resource_len(ndev->ntb.pdev, bar);
827
828 if (align_size)
829 *align_size = 1;
830
831 return 0;
832}
833
834static int intel_ntb_mw_set_trans(struct ntb_dev *ntb, int idx,
835 dma_addr_t addr, resource_size_t size)
836{
837 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
838 unsigned long base_reg, xlat_reg, limit_reg;
839 resource_size_t bar_size, mw_size;
840 void __iomem *mmio;
841 u64 base, limit, reg_val;
842 int bar;
843
844 if (idx >= ndev->b2b_idx && !ndev->b2b_off)
845 idx += 1;
846
847 bar = ndev_mw_to_bar(ndev, idx);
848 if (bar < 0)
849 return bar;
850
851 bar_size = pci_resource_len(ndev->ntb.pdev, bar);
852
853 if (idx == ndev->b2b_idx)
854 mw_size = bar_size - ndev->b2b_off;
855 else
856 mw_size = bar_size;
857
858 /* hardware requires that addr is aligned to bar size */
859 if (addr & (bar_size - 1))
860 return -EINVAL;
861
862 /* make sure the range fits in the usable mw size */
863 if (size > mw_size)
864 return -EINVAL;
865
866 mmio = ndev->self_mmio;
867 base_reg = bar0_off(ndev->xlat_reg->bar0_base, bar);
868 xlat_reg = bar2_off(ndev->xlat_reg->bar2_xlat, bar);
869 limit_reg = bar2_off(ndev->xlat_reg->bar2_limit, bar);
870
871 if (bar < 4 || !ndev->bar4_split) {
872 base = ioread64(mmio + base_reg);
873
874 /* Set the limit if supported, if size is not mw_size */
875 if (limit_reg && size != mw_size)
876 limit = base + size;
877 else
878 limit = 0;
879
880 /* set and verify setting the translation address */
881 iowrite64(addr, mmio + xlat_reg);
882 reg_val = ioread64(mmio + xlat_reg);
883 if (reg_val != addr) {
884 iowrite64(0, mmio + xlat_reg);
885 return -EIO;
886 }
887
888 /* set and verify setting the limit */
889 iowrite64(limit, mmio + limit_reg);
890 reg_val = ioread64(mmio + limit_reg);
891 if (reg_val != limit) {
892 iowrite64(base, mmio + limit_reg);
893 iowrite64(0, mmio + xlat_reg);
894 return -EIO;
895 }
896 } else {
897 /* split bar addr range must all be 32 bit */
898 if (addr & (~0ull << 32))
899 return -EINVAL;
900 if ((addr + size) & (~0ull << 32))
901 return -EINVAL;
902
903 base = ioread32(mmio + base_reg);
904
905 /* Set the limit if supported, if size is not mw_size */
906 if (limit_reg && size != mw_size)
907 limit = base + size;
908 else
909 limit = 0;
910
911 /* set and verify setting the translation address */
912 iowrite32(addr, mmio + xlat_reg);
913 reg_val = ioread32(mmio + xlat_reg);
914 if (reg_val != addr) {
915 iowrite32(0, mmio + xlat_reg);
916 return -EIO;
917 }
918
919 /* set and verify setting the limit */
920 iowrite32(limit, mmio + limit_reg);
921 reg_val = ioread32(mmio + limit_reg);
922 if (reg_val != limit) {
923 iowrite32(base, mmio + limit_reg);
924 iowrite32(0, mmio + xlat_reg);
925 return -EIO;
926 }
927 }
928
929 return 0;
930}
931
932static int intel_ntb_link_is_up(struct ntb_dev *ntb,
933 enum ntb_speed *speed,
934 enum ntb_width *width)
935{
936 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
937
938 if (ndev->reg->link_is_up(ndev)) {
939 if (speed)
940 *speed = NTB_LNK_STA_SPEED(ndev->lnk_sta);
941 if (width)
942 *width = NTB_LNK_STA_WIDTH(ndev->lnk_sta);
943 return 1;
944 } else {
945 /* TODO MAYBE: is it possible to observe the link speed and
946 * width while link is training? */
947 if (speed)
948 *speed = NTB_SPEED_NONE;
949 if (width)
950 *width = NTB_WIDTH_NONE;
951 return 0;
952 }
953}
954
955static int intel_ntb_link_enable(struct ntb_dev *ntb,
956 enum ntb_speed max_speed,
957 enum ntb_width max_width)
958{
959 struct intel_ntb_dev *ndev;
960 u32 ntb_ctl;
961
962 ndev = container_of(ntb, struct intel_ntb_dev, ntb);
963
964 if (ndev->ntb.topo == NTB_TOPO_SEC)
965 return -EINVAL;
966
967 dev_dbg(ndev_dev(ndev),
968 "Enabling link with max_speed %d max_width %d\n",
969 max_speed, max_width);
970 if (max_speed != NTB_SPEED_AUTO)
971 dev_dbg(ndev_dev(ndev), "ignoring max_speed %d\n", max_speed);
972 if (max_width != NTB_WIDTH_AUTO)
973 dev_dbg(ndev_dev(ndev), "ignoring max_width %d\n", max_width);
974
975 ntb_ctl = ioread32(ndev->self_mmio + ndev->reg->ntb_ctl);
976 ntb_ctl &= ~(NTB_CTL_DISABLE | NTB_CTL_CFG_LOCK);
977 ntb_ctl |= NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP;
978 ntb_ctl |= NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP;
979 if (ndev->bar4_split)
980 ntb_ctl |= NTB_CTL_P2S_BAR5_SNOOP | NTB_CTL_S2P_BAR5_SNOOP;
981 iowrite32(ntb_ctl, ndev->self_mmio + ndev->reg->ntb_ctl);
982
983 return 0;
984}
985
986static int intel_ntb_link_disable(struct ntb_dev *ntb)
987{
988 struct intel_ntb_dev *ndev;
989 u32 ntb_cntl;
990
991 ndev = container_of(ntb, struct intel_ntb_dev, ntb);
992
993 if (ndev->ntb.topo == NTB_TOPO_SEC)
994 return -EINVAL;
995
996 dev_dbg(ndev_dev(ndev), "Disabling link\n");
997
998 /* Bring NTB link down */
999 ntb_cntl = ioread32(ndev->self_mmio + ndev->reg->ntb_ctl);
1000 ntb_cntl &= ~(NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP);
1001 ntb_cntl &= ~(NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP);
1002 if (ndev->bar4_split)
1003 ntb_cntl &= ~(NTB_CTL_P2S_BAR5_SNOOP | NTB_CTL_S2P_BAR5_SNOOP);
1004 ntb_cntl |= NTB_CTL_DISABLE | NTB_CTL_CFG_LOCK;
1005 iowrite32(ntb_cntl, ndev->self_mmio + ndev->reg->ntb_ctl);
1006
1007 return 0;
1008}
1009
1010static int intel_ntb_db_is_unsafe(struct ntb_dev *ntb)
1011{
1012 return ndev_ignore_unsafe(ntb_ndev(ntb), NTB_UNSAFE_DB);
1013}
1014
1015static u64 intel_ntb_db_valid_mask(struct ntb_dev *ntb)
1016{
1017 return ntb_ndev(ntb)->db_valid_mask;
1018}
1019
1020static int intel_ntb_db_vector_count(struct ntb_dev *ntb)
1021{
1022 struct intel_ntb_dev *ndev;
1023
1024 ndev = container_of(ntb, struct intel_ntb_dev, ntb);
1025
1026 return ndev->db_vec_count;
1027}
1028
1029static u64 intel_ntb_db_vector_mask(struct ntb_dev *ntb, int db_vector)
1030{
1031 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1032
1033 if (db_vector < 0 || db_vector > ndev->db_vec_count)
1034 return 0;
1035
1036 return ndev->db_valid_mask & ndev_vec_mask(ndev, db_vector);
1037}
1038
1039static u64 intel_ntb_db_read(struct ntb_dev *ntb)
1040{
1041 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1042
1043 return ndev_db_read(ndev,
1044 ndev->self_mmio +
1045 ndev->self_reg->db_bell);
1046}
1047
1048static int intel_ntb_db_clear(struct ntb_dev *ntb, u64 db_bits)
1049{
1050 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1051
1052 return ndev_db_write(ndev, db_bits,
1053 ndev->self_mmio +
1054 ndev->self_reg->db_bell);
1055}
1056
1057static int intel_ntb_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
1058{
1059 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1060
1061 return ndev_db_set_mask(ndev, db_bits,
1062 ndev->self_mmio +
1063 ndev->self_reg->db_mask);
1064}
1065
1066static int intel_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
1067{
1068 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1069
1070 return ndev_db_clear_mask(ndev, db_bits,
1071 ndev->self_mmio +
1072 ndev->self_reg->db_mask);
1073}
1074
1075static int intel_ntb_peer_db_addr(struct ntb_dev *ntb,
1076 phys_addr_t *db_addr,
1077 resource_size_t *db_size)
1078{
1079 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1080
1081 return ndev_db_addr(ndev, db_addr, db_size, ndev->peer_addr,
1082 ndev->peer_reg->db_bell);
1083}
1084
1085static int intel_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
1086{
1087 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1088
1089 return ndev_db_write(ndev, db_bits,
1090 ndev->peer_mmio +
1091 ndev->peer_reg->db_bell);
1092}
1093
1094static int intel_ntb_spad_is_unsafe(struct ntb_dev *ntb)
1095{
1096 return ndev_ignore_unsafe(ntb_ndev(ntb), NTB_UNSAFE_SPAD);
1097}
1098
1099static int intel_ntb_spad_count(struct ntb_dev *ntb)
1100{
1101 struct intel_ntb_dev *ndev;
1102
1103 ndev = container_of(ntb, struct intel_ntb_dev, ntb);
1104
1105 return ndev->spad_count;
1106}
1107
1108static u32 intel_ntb_spad_read(struct ntb_dev *ntb, int idx)
1109{
1110 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1111
1112 return ndev_spad_read(ndev, idx,
1113 ndev->self_mmio +
1114 ndev->self_reg->spad);
1115}
1116
1117static int intel_ntb_spad_write(struct ntb_dev *ntb,
1118 int idx, u32 val)
1119{
1120 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1121
1122 return ndev_spad_write(ndev, idx, val,
1123 ndev->self_mmio +
1124 ndev->self_reg->spad);
1125}
1126
1127static int intel_ntb_peer_spad_addr(struct ntb_dev *ntb, int idx,
1128 phys_addr_t *spad_addr)
1129{
1130 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1131
1132 return ndev_spad_addr(ndev, idx, spad_addr, ndev->peer_addr,
1133 ndev->peer_reg->spad);
1134}
1135
1136static u32 intel_ntb_peer_spad_read(struct ntb_dev *ntb, int idx)
1137{
1138 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1139
1140 return ndev_spad_read(ndev, idx,
1141 ndev->peer_mmio +
1142 ndev->peer_reg->spad);
1143}
1144
1145static int intel_ntb_peer_spad_write(struct ntb_dev *ntb,
1146 int idx, u32 val)
1147{
1148 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1149
1150 return ndev_spad_write(ndev, idx, val,
1151 ndev->peer_mmio +
1152 ndev->peer_reg->spad);
1153}
1154
Dave Jiang2f887b92015-05-20 12:55:47 -04001155/* ATOM */
Allen Hubbee26a5842015-04-09 10:33:20 -04001156
Dave Jiang2f887b92015-05-20 12:55:47 -04001157static u64 atom_db_ioread(void __iomem *mmio)
Allen Hubbee26a5842015-04-09 10:33:20 -04001158{
1159 return ioread64(mmio);
1160}
1161
Dave Jiang2f887b92015-05-20 12:55:47 -04001162static void atom_db_iowrite(u64 bits, void __iomem *mmio)
Allen Hubbee26a5842015-04-09 10:33:20 -04001163{
1164 iowrite64(bits, mmio);
1165}
1166
Dave Jiang2f887b92015-05-20 12:55:47 -04001167static int atom_poll_link(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001168{
1169 u32 ntb_ctl;
1170
Dave Jiang2f887b92015-05-20 12:55:47 -04001171 ntb_ctl = ioread32(ndev->self_mmio + ATOM_NTBCNTL_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001172
1173 if (ntb_ctl == ndev->ntb_ctl)
1174 return 0;
1175
1176 ndev->ntb_ctl = ntb_ctl;
1177
Dave Jiang2f887b92015-05-20 12:55:47 -04001178 ndev->lnk_sta = ioread32(ndev->self_mmio + ATOM_LINK_STATUS_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001179
1180 return 1;
1181}
1182
Dave Jiang2f887b92015-05-20 12:55:47 -04001183static int atom_link_is_up(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001184{
Dave Jiang2f887b92015-05-20 12:55:47 -04001185 return ATOM_NTB_CTL_ACTIVE(ndev->ntb_ctl);
Allen Hubbee26a5842015-04-09 10:33:20 -04001186}
1187
Dave Jiang2f887b92015-05-20 12:55:47 -04001188static int atom_link_is_err(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001189{
Dave Jiang2f887b92015-05-20 12:55:47 -04001190 if (ioread32(ndev->self_mmio + ATOM_LTSSMSTATEJMP_OFFSET)
1191 & ATOM_LTSSMSTATEJMP_FORCEDETECT)
Allen Hubbee26a5842015-04-09 10:33:20 -04001192 return 1;
1193
Dave Jiang2f887b92015-05-20 12:55:47 -04001194 if (ioread32(ndev->self_mmio + ATOM_IBSTERRRCRVSTS0_OFFSET)
1195 & ATOM_IBIST_ERR_OFLOW)
Allen Hubbee26a5842015-04-09 10:33:20 -04001196 return 1;
1197
1198 return 0;
1199}
1200
Dave Jiang2f887b92015-05-20 12:55:47 -04001201static inline enum ntb_topo atom_ppd_topo(struct intel_ntb_dev *ndev, u32 ppd)
Allen Hubbee26a5842015-04-09 10:33:20 -04001202{
Dave Jiang2f887b92015-05-20 12:55:47 -04001203 switch (ppd & ATOM_PPD_TOPO_MASK) {
1204 case ATOM_PPD_TOPO_B2B_USD:
Allen Hubbee26a5842015-04-09 10:33:20 -04001205 dev_dbg(ndev_dev(ndev), "PPD %d B2B USD\n", ppd);
1206 return NTB_TOPO_B2B_USD;
1207
Dave Jiang2f887b92015-05-20 12:55:47 -04001208 case ATOM_PPD_TOPO_B2B_DSD:
Allen Hubbee26a5842015-04-09 10:33:20 -04001209 dev_dbg(ndev_dev(ndev), "PPD %d B2B DSD\n", ppd);
1210 return NTB_TOPO_B2B_DSD;
1211
Dave Jiang2f887b92015-05-20 12:55:47 -04001212 case ATOM_PPD_TOPO_PRI_USD:
1213 case ATOM_PPD_TOPO_PRI_DSD: /* accept bogus PRI_DSD */
1214 case ATOM_PPD_TOPO_SEC_USD:
1215 case ATOM_PPD_TOPO_SEC_DSD: /* accept bogus SEC_DSD */
Allen Hubbee26a5842015-04-09 10:33:20 -04001216 dev_dbg(ndev_dev(ndev), "PPD %d non B2B disabled\n", ppd);
1217 return NTB_TOPO_NONE;
1218 }
1219
1220 dev_dbg(ndev_dev(ndev), "PPD %d invalid\n", ppd);
1221 return NTB_TOPO_NONE;
1222}
1223
Dave Jiang2f887b92015-05-20 12:55:47 -04001224static void atom_link_hb(struct work_struct *work)
Allen Hubbee26a5842015-04-09 10:33:20 -04001225{
1226 struct intel_ntb_dev *ndev = hb_ndev(work);
1227 unsigned long poll_ts;
1228 void __iomem *mmio;
1229 u32 status32;
1230
Dave Jiang2f887b92015-05-20 12:55:47 -04001231 poll_ts = ndev->last_ts + ATOM_LINK_HB_TIMEOUT;
Allen Hubbee26a5842015-04-09 10:33:20 -04001232
1233 /* Delay polling the link status if an interrupt was received,
1234 * unless the cached link status says the link is down.
1235 */
Dave Jiang2f887b92015-05-20 12:55:47 -04001236 if (time_after(poll_ts, jiffies) && atom_link_is_up(ndev)) {
Allen Hubbee26a5842015-04-09 10:33:20 -04001237 schedule_delayed_work(&ndev->hb_timer, poll_ts - jiffies);
1238 return;
1239 }
1240
Dave Jiang2f887b92015-05-20 12:55:47 -04001241 if (atom_poll_link(ndev))
Allen Hubbee26a5842015-04-09 10:33:20 -04001242 ntb_link_event(&ndev->ntb);
1243
Dave Jiang2f887b92015-05-20 12:55:47 -04001244 if (atom_link_is_up(ndev) || !atom_link_is_err(ndev)) {
1245 schedule_delayed_work(&ndev->hb_timer, ATOM_LINK_HB_TIMEOUT);
Allen Hubbee26a5842015-04-09 10:33:20 -04001246 return;
1247 }
1248
1249 /* Link is down with error: recover the link! */
1250
1251 mmio = ndev->self_mmio;
1252
1253 /* Driver resets the NTB ModPhy lanes - magic! */
Dave Jiang2f887b92015-05-20 12:55:47 -04001254 iowrite8(0xe0, mmio + ATOM_MODPHY_PCSREG6);
1255 iowrite8(0x40, mmio + ATOM_MODPHY_PCSREG4);
1256 iowrite8(0x60, mmio + ATOM_MODPHY_PCSREG4);
1257 iowrite8(0x60, mmio + ATOM_MODPHY_PCSREG6);
Allen Hubbee26a5842015-04-09 10:33:20 -04001258
1259 /* Driver waits 100ms to allow the NTB ModPhy to settle */
1260 msleep(100);
1261
1262 /* Clear AER Errors, write to clear */
Dave Jiang2f887b92015-05-20 12:55:47 -04001263 status32 = ioread32(mmio + ATOM_ERRCORSTS_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001264 dev_dbg(ndev_dev(ndev), "ERRCORSTS = %x\n", status32);
1265 status32 &= PCI_ERR_COR_REP_ROLL;
Dave Jiang2f887b92015-05-20 12:55:47 -04001266 iowrite32(status32, mmio + ATOM_ERRCORSTS_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001267
1268 /* Clear unexpected electrical idle event in LTSSM, write to clear */
Dave Jiang2f887b92015-05-20 12:55:47 -04001269 status32 = ioread32(mmio + ATOM_LTSSMERRSTS0_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001270 dev_dbg(ndev_dev(ndev), "LTSSMERRSTS0 = %x\n", status32);
Dave Jiang2f887b92015-05-20 12:55:47 -04001271 status32 |= ATOM_LTSSMERRSTS0_UNEXPECTEDEI;
1272 iowrite32(status32, mmio + ATOM_LTSSMERRSTS0_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001273
1274 /* Clear DeSkew Buffer error, write to clear */
Dave Jiang2f887b92015-05-20 12:55:47 -04001275 status32 = ioread32(mmio + ATOM_DESKEWSTS_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001276 dev_dbg(ndev_dev(ndev), "DESKEWSTS = %x\n", status32);
Dave Jiang2f887b92015-05-20 12:55:47 -04001277 status32 |= ATOM_DESKEWSTS_DBERR;
1278 iowrite32(status32, mmio + ATOM_DESKEWSTS_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001279
Dave Jiang2f887b92015-05-20 12:55:47 -04001280 status32 = ioread32(mmio + ATOM_IBSTERRRCRVSTS0_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001281 dev_dbg(ndev_dev(ndev), "IBSTERRRCRVSTS0 = %x\n", status32);
Dave Jiang2f887b92015-05-20 12:55:47 -04001282 status32 &= ATOM_IBIST_ERR_OFLOW;
1283 iowrite32(status32, mmio + ATOM_IBSTERRRCRVSTS0_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001284
1285 /* Releases the NTB state machine to allow the link to retrain */
Dave Jiang2f887b92015-05-20 12:55:47 -04001286 status32 = ioread32(mmio + ATOM_LTSSMSTATEJMP_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001287 dev_dbg(ndev_dev(ndev), "LTSSMSTATEJMP = %x\n", status32);
Dave Jiang2f887b92015-05-20 12:55:47 -04001288 status32 &= ~ATOM_LTSSMSTATEJMP_FORCEDETECT;
1289 iowrite32(status32, mmio + ATOM_LTSSMSTATEJMP_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001290
1291 /* There is a potential race between the 2 NTB devices recovering at the
1292 * same time. If the times are the same, the link will not recover and
1293 * the driver will be stuck in this loop forever. Add a random interval
1294 * to the recovery time to prevent this race.
1295 */
Dave Jiang2f887b92015-05-20 12:55:47 -04001296 schedule_delayed_work(&ndev->hb_timer, ATOM_LINK_RECOVERY_TIME
1297 + prandom_u32() % ATOM_LINK_RECOVERY_TIME);
Allen Hubbee26a5842015-04-09 10:33:20 -04001298}
1299
Dave Jiang2f887b92015-05-20 12:55:47 -04001300static int atom_init_isr(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001301{
1302 int rc;
1303
Dave Jiang2f887b92015-05-20 12:55:47 -04001304 rc = ndev_init_isr(ndev, 1, ATOM_DB_MSIX_VECTOR_COUNT,
1305 ATOM_DB_MSIX_VECTOR_SHIFT, ATOM_DB_TOTAL_SHIFT);
Allen Hubbee26a5842015-04-09 10:33:20 -04001306 if (rc)
1307 return rc;
1308
Dave Jiang2f887b92015-05-20 12:55:47 -04001309 /* ATOM doesn't have link status interrupt, poll on that platform */
Allen Hubbee26a5842015-04-09 10:33:20 -04001310 ndev->last_ts = jiffies;
Dave Jiang2f887b92015-05-20 12:55:47 -04001311 INIT_DELAYED_WORK(&ndev->hb_timer, atom_link_hb);
1312 schedule_delayed_work(&ndev->hb_timer, ATOM_LINK_HB_TIMEOUT);
Allen Hubbee26a5842015-04-09 10:33:20 -04001313
1314 return 0;
1315}
1316
Dave Jiang2f887b92015-05-20 12:55:47 -04001317static void atom_deinit_isr(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001318{
1319 cancel_delayed_work_sync(&ndev->hb_timer);
1320 ndev_deinit_isr(ndev);
1321}
1322
Dave Jiang2f887b92015-05-20 12:55:47 -04001323static int atom_init_ntb(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001324{
Dave Jiang2f887b92015-05-20 12:55:47 -04001325 ndev->mw_count = ATOM_MW_COUNT;
1326 ndev->spad_count = ATOM_SPAD_COUNT;
1327 ndev->db_count = ATOM_DB_COUNT;
Allen Hubbee26a5842015-04-09 10:33:20 -04001328
1329 switch (ndev->ntb.topo) {
1330 case NTB_TOPO_B2B_USD:
1331 case NTB_TOPO_B2B_DSD:
Dave Jiang2f887b92015-05-20 12:55:47 -04001332 ndev->self_reg = &atom_pri_reg;
1333 ndev->peer_reg = &atom_b2b_reg;
1334 ndev->xlat_reg = &atom_sec_xlat;
Allen Hubbee26a5842015-04-09 10:33:20 -04001335
1336 /* Enable Bus Master and Memory Space on the secondary side */
1337 iowrite16(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER,
Dave Jiang2f887b92015-05-20 12:55:47 -04001338 ndev->self_mmio + ATOM_SPCICMD_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001339
1340 break;
1341
1342 default:
1343 return -EINVAL;
1344 }
1345
1346 ndev->db_valid_mask = BIT_ULL(ndev->db_count) - 1;
1347
1348 return 0;
1349}
1350
Dave Jiang2f887b92015-05-20 12:55:47 -04001351static int atom_init_dev(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001352{
1353 u32 ppd;
1354 int rc;
1355
Dave Jiang2f887b92015-05-20 12:55:47 -04001356 rc = pci_read_config_dword(ndev->ntb.pdev, ATOM_PPD_OFFSET, &ppd);
Allen Hubbee26a5842015-04-09 10:33:20 -04001357 if (rc)
1358 return -EIO;
1359
Dave Jiang2f887b92015-05-20 12:55:47 -04001360 ndev->ntb.topo = atom_ppd_topo(ndev, ppd);
Allen Hubbee26a5842015-04-09 10:33:20 -04001361 if (ndev->ntb.topo == NTB_TOPO_NONE)
1362 return -EINVAL;
1363
Dave Jiang2f887b92015-05-20 12:55:47 -04001364 rc = atom_init_ntb(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04001365 if (rc)
1366 return rc;
1367
Dave Jiang2f887b92015-05-20 12:55:47 -04001368 rc = atom_init_isr(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04001369 if (rc)
1370 return rc;
1371
1372 if (ndev->ntb.topo != NTB_TOPO_SEC) {
1373 /* Initiate PCI-E link training */
Dave Jiang2f887b92015-05-20 12:55:47 -04001374 rc = pci_write_config_dword(ndev->ntb.pdev, ATOM_PPD_OFFSET,
1375 ppd | ATOM_PPD_INIT_LINK);
Allen Hubbee26a5842015-04-09 10:33:20 -04001376 if (rc)
1377 return rc;
1378 }
1379
1380 return 0;
1381}
1382
Dave Jiang2f887b92015-05-20 12:55:47 -04001383static void atom_deinit_dev(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001384{
Dave Jiang2f887b92015-05-20 12:55:47 -04001385 atom_deinit_isr(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04001386}
1387
Dave Jiang2f887b92015-05-20 12:55:47 -04001388/* XEON */
Allen Hubbee26a5842015-04-09 10:33:20 -04001389
Dave Jiang2f887b92015-05-20 12:55:47 -04001390static u64 xeon_db_ioread(void __iomem *mmio)
Allen Hubbee26a5842015-04-09 10:33:20 -04001391{
1392 return (u64)ioread16(mmio);
1393}
1394
Dave Jiang2f887b92015-05-20 12:55:47 -04001395static void xeon_db_iowrite(u64 bits, void __iomem *mmio)
Allen Hubbee26a5842015-04-09 10:33:20 -04001396{
1397 iowrite16((u16)bits, mmio);
1398}
1399
Dave Jiang2f887b92015-05-20 12:55:47 -04001400static int xeon_poll_link(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001401{
1402 u16 reg_val;
1403 int rc;
1404
1405 ndev->reg->db_iowrite(ndev->db_link_mask,
1406 ndev->self_mmio +
1407 ndev->self_reg->db_bell);
1408
1409 rc = pci_read_config_word(ndev->ntb.pdev,
Dave Jiang2f887b92015-05-20 12:55:47 -04001410 XEON_LINK_STATUS_OFFSET, &reg_val);
Allen Hubbee26a5842015-04-09 10:33:20 -04001411 if (rc)
1412 return 0;
1413
1414 if (reg_val == ndev->lnk_sta)
1415 return 0;
1416
1417 ndev->lnk_sta = reg_val;
1418
1419 return 1;
1420}
1421
Dave Jiang2f887b92015-05-20 12:55:47 -04001422static int xeon_link_is_up(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001423{
Dave Jiang5ae0beb2015-05-19 16:59:34 -04001424 if (ndev->ntb.topo == NTB_TOPO_SEC)
1425 return 1;
1426
Allen Hubbee26a5842015-04-09 10:33:20 -04001427 return NTB_LNK_STA_ACTIVE(ndev->lnk_sta);
1428}
1429
Dave Jiang2f887b92015-05-20 12:55:47 -04001430static inline enum ntb_topo xeon_ppd_topo(struct intel_ntb_dev *ndev, u8 ppd)
Allen Hubbee26a5842015-04-09 10:33:20 -04001431{
Dave Jiang2f887b92015-05-20 12:55:47 -04001432 switch (ppd & XEON_PPD_TOPO_MASK) {
1433 case XEON_PPD_TOPO_B2B_USD:
Allen Hubbee26a5842015-04-09 10:33:20 -04001434 return NTB_TOPO_B2B_USD;
1435
Dave Jiang2f887b92015-05-20 12:55:47 -04001436 case XEON_PPD_TOPO_B2B_DSD:
Allen Hubbee26a5842015-04-09 10:33:20 -04001437 return NTB_TOPO_B2B_DSD;
1438
Dave Jiang2f887b92015-05-20 12:55:47 -04001439 case XEON_PPD_TOPO_PRI_USD:
1440 case XEON_PPD_TOPO_PRI_DSD: /* accept bogus PRI_DSD */
Allen Hubbee26a5842015-04-09 10:33:20 -04001441 return NTB_TOPO_PRI;
1442
Dave Jiang2f887b92015-05-20 12:55:47 -04001443 case XEON_PPD_TOPO_SEC_USD:
1444 case XEON_PPD_TOPO_SEC_DSD: /* accept bogus SEC_DSD */
Allen Hubbee26a5842015-04-09 10:33:20 -04001445 return NTB_TOPO_SEC;
1446 }
1447
1448 return NTB_TOPO_NONE;
1449}
1450
Dave Jiang2f887b92015-05-20 12:55:47 -04001451static inline int xeon_ppd_bar4_split(struct intel_ntb_dev *ndev, u8 ppd)
Allen Hubbee26a5842015-04-09 10:33:20 -04001452{
Dave Jiang2f887b92015-05-20 12:55:47 -04001453 if (ppd & XEON_PPD_SPLIT_BAR_MASK) {
Allen Hubbee26a5842015-04-09 10:33:20 -04001454 dev_dbg(ndev_dev(ndev), "PPD %d split bar\n", ppd);
1455 return 1;
1456 }
1457 return 0;
1458}
1459
Dave Jiang2f887b92015-05-20 12:55:47 -04001460static int xeon_init_isr(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001461{
Dave Jiang2f887b92015-05-20 12:55:47 -04001462 return ndev_init_isr(ndev, XEON_DB_MSIX_VECTOR_COUNT,
1463 XEON_DB_MSIX_VECTOR_COUNT,
1464 XEON_DB_MSIX_VECTOR_SHIFT,
1465 XEON_DB_TOTAL_SHIFT);
Allen Hubbee26a5842015-04-09 10:33:20 -04001466}
1467
Dave Jiang2f887b92015-05-20 12:55:47 -04001468static void xeon_deinit_isr(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001469{
1470 ndev_deinit_isr(ndev);
1471}
1472
Dave Jiang2f887b92015-05-20 12:55:47 -04001473static int xeon_setup_b2b_mw(struct intel_ntb_dev *ndev,
1474 const struct intel_b2b_addr *addr,
1475 const struct intel_b2b_addr *peer_addr)
Allen Hubbee26a5842015-04-09 10:33:20 -04001476{
1477 struct pci_dev *pdev;
1478 void __iomem *mmio;
1479 resource_size_t bar_size;
1480 phys_addr_t bar_addr;
1481 int b2b_bar;
1482 u8 bar_sz;
1483
1484 pdev = ndev_pdev(ndev);
1485 mmio = ndev->self_mmio;
1486
1487 if (ndev->b2b_idx >= ndev->mw_count) {
1488 dev_dbg(ndev_dev(ndev), "not using b2b mw\n");
1489 b2b_bar = 0;
1490 ndev->b2b_off = 0;
1491 } else {
1492 b2b_bar = ndev_mw_to_bar(ndev, ndev->b2b_idx);
1493 if (b2b_bar < 0)
1494 return -EIO;
1495
1496 dev_dbg(ndev_dev(ndev), "using b2b mw bar %d\n", b2b_bar);
1497
1498 bar_size = pci_resource_len(ndev->ntb.pdev, b2b_bar);
1499
1500 dev_dbg(ndev_dev(ndev), "b2b bar size %#llx\n", bar_size);
1501
Dave Jiang2f887b92015-05-20 12:55:47 -04001502 if (b2b_mw_share && XEON_B2B_MIN_SIZE <= bar_size >> 1) {
Allen Hubbee26a5842015-04-09 10:33:20 -04001503 dev_dbg(ndev_dev(ndev),
1504 "b2b using first half of bar\n");
1505 ndev->b2b_off = bar_size >> 1;
Dave Jiang2f887b92015-05-20 12:55:47 -04001506 } else if (XEON_B2B_MIN_SIZE <= bar_size) {
Allen Hubbee26a5842015-04-09 10:33:20 -04001507 dev_dbg(ndev_dev(ndev),
1508 "b2b using whole bar\n");
1509 ndev->b2b_off = 0;
1510 --ndev->mw_count;
1511 } else {
1512 dev_dbg(ndev_dev(ndev),
1513 "b2b bar size is too small\n");
1514 return -EIO;
1515 }
1516 }
1517
1518 /* Reset the secondary bar sizes to match the primary bar sizes,
1519 * except disable or halve the size of the b2b secondary bar.
1520 *
1521 * Note: code for each specific bar size register, because the register
1522 * offsets are not in a consistent order (bar5sz comes after ppd, odd).
1523 */
Dave Jiang2f887b92015-05-20 12:55:47 -04001524 pci_read_config_byte(pdev, XEON_PBAR23SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001525 dev_dbg(ndev_dev(ndev), "PBAR23SZ %#x\n", bar_sz);
1526 if (b2b_bar == 2) {
1527 if (ndev->b2b_off)
1528 bar_sz -= 1;
1529 else
1530 bar_sz = 0;
1531 }
Dave Jiang2f887b92015-05-20 12:55:47 -04001532 pci_write_config_byte(pdev, XEON_SBAR23SZ_OFFSET, bar_sz);
1533 pci_read_config_byte(pdev, XEON_SBAR23SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001534 dev_dbg(ndev_dev(ndev), "SBAR23SZ %#x\n", bar_sz);
1535
1536 if (!ndev->bar4_split) {
Dave Jiang2f887b92015-05-20 12:55:47 -04001537 pci_read_config_byte(pdev, XEON_PBAR45SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001538 dev_dbg(ndev_dev(ndev), "PBAR45SZ %#x\n", bar_sz);
1539 if (b2b_bar == 4) {
1540 if (ndev->b2b_off)
1541 bar_sz -= 1;
1542 else
1543 bar_sz = 0;
1544 }
Dave Jiang2f887b92015-05-20 12:55:47 -04001545 pci_write_config_byte(pdev, XEON_SBAR45SZ_OFFSET, bar_sz);
1546 pci_read_config_byte(pdev, XEON_SBAR45SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001547 dev_dbg(ndev_dev(ndev), "SBAR45SZ %#x\n", bar_sz);
1548 } else {
Dave Jiang2f887b92015-05-20 12:55:47 -04001549 pci_read_config_byte(pdev, XEON_PBAR4SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001550 dev_dbg(ndev_dev(ndev), "PBAR4SZ %#x\n", bar_sz);
1551 if (b2b_bar == 4) {
1552 if (ndev->b2b_off)
1553 bar_sz -= 1;
1554 else
1555 bar_sz = 0;
1556 }
Dave Jiang2f887b92015-05-20 12:55:47 -04001557 pci_write_config_byte(pdev, XEON_SBAR4SZ_OFFSET, bar_sz);
1558 pci_read_config_byte(pdev, XEON_SBAR4SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001559 dev_dbg(ndev_dev(ndev), "SBAR4SZ %#x\n", bar_sz);
1560
Dave Jiang2f887b92015-05-20 12:55:47 -04001561 pci_read_config_byte(pdev, XEON_PBAR5SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001562 dev_dbg(ndev_dev(ndev), "PBAR5SZ %#x\n", bar_sz);
1563 if (b2b_bar == 5) {
1564 if (ndev->b2b_off)
1565 bar_sz -= 1;
1566 else
1567 bar_sz = 0;
1568 }
Dave Jiang2f887b92015-05-20 12:55:47 -04001569 pci_write_config_byte(pdev, XEON_SBAR5SZ_OFFSET, bar_sz);
1570 pci_read_config_byte(pdev, XEON_SBAR5SZ_OFFSET, &bar_sz);
Allen Hubbee26a5842015-04-09 10:33:20 -04001571 dev_dbg(ndev_dev(ndev), "SBAR5SZ %#x\n", bar_sz);
1572 }
1573
1574 /* SBAR01 hit by first part of the b2b bar */
1575 if (b2b_bar == 0)
1576 bar_addr = addr->bar0_addr;
1577 else if (b2b_bar == 2)
1578 bar_addr = addr->bar2_addr64;
1579 else if (b2b_bar == 4 && !ndev->bar4_split)
1580 bar_addr = addr->bar4_addr64;
1581 else if (b2b_bar == 4)
1582 bar_addr = addr->bar4_addr32;
1583 else if (b2b_bar == 5)
1584 bar_addr = addr->bar5_addr32;
1585 else
1586 return -EIO;
1587
1588 dev_dbg(ndev_dev(ndev), "SBAR01 %#018llx\n", bar_addr);
Dave Jiang2f887b92015-05-20 12:55:47 -04001589 iowrite64(bar_addr, mmio + XEON_SBAR0BASE_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001590
1591 /* Other SBAR are normally hit by the PBAR xlat, except for b2b bar.
1592 * The b2b bar is either disabled above, or configured half-size, and
1593 * it starts at the PBAR xlat + offset.
1594 */
1595
1596 bar_addr = addr->bar2_addr64 + (b2b_bar == 2 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001597 iowrite64(bar_addr, mmio + XEON_SBAR23BASE_OFFSET);
1598 bar_addr = ioread64(mmio + XEON_SBAR23BASE_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001599 dev_dbg(ndev_dev(ndev), "SBAR23 %#018llx\n", bar_addr);
1600
1601 if (!ndev->bar4_split) {
1602 bar_addr = addr->bar4_addr64 +
1603 (b2b_bar == 4 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001604 iowrite64(bar_addr, mmio + XEON_SBAR45BASE_OFFSET);
1605 bar_addr = ioread64(mmio + XEON_SBAR45BASE_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001606 dev_dbg(ndev_dev(ndev), "SBAR45 %#018llx\n", bar_addr);
1607 } else {
1608 bar_addr = addr->bar4_addr32 +
1609 (b2b_bar == 4 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001610 iowrite32(bar_addr, mmio + XEON_SBAR4BASE_OFFSET);
1611 bar_addr = ioread32(mmio + XEON_SBAR4BASE_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001612 dev_dbg(ndev_dev(ndev), "SBAR4 %#010llx\n", bar_addr);
1613
1614 bar_addr = addr->bar5_addr32 +
1615 (b2b_bar == 5 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001616 iowrite32(bar_addr, mmio + XEON_SBAR5BASE_OFFSET);
1617 bar_addr = ioread32(mmio + XEON_SBAR5BASE_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001618 dev_dbg(ndev_dev(ndev), "SBAR5 %#010llx\n", bar_addr);
1619 }
1620
1621 /* setup incoming bar limits == base addrs (zero length windows) */
1622
1623 bar_addr = addr->bar2_addr64 + (b2b_bar == 2 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001624 iowrite64(bar_addr, mmio + XEON_SBAR23LMT_OFFSET);
1625 bar_addr = ioread64(mmio + XEON_SBAR23LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001626 dev_dbg(ndev_dev(ndev), "SBAR23LMT %#018llx\n", bar_addr);
1627
1628 if (!ndev->bar4_split) {
1629 bar_addr = addr->bar4_addr64 +
1630 (b2b_bar == 4 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001631 iowrite64(bar_addr, mmio + XEON_SBAR45LMT_OFFSET);
1632 bar_addr = ioread64(mmio + XEON_SBAR45LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001633 dev_dbg(ndev_dev(ndev), "SBAR45LMT %#018llx\n", bar_addr);
1634 } else {
1635 bar_addr = addr->bar4_addr32 +
1636 (b2b_bar == 4 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001637 iowrite32(bar_addr, mmio + XEON_SBAR4LMT_OFFSET);
1638 bar_addr = ioread32(mmio + XEON_SBAR4LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001639 dev_dbg(ndev_dev(ndev), "SBAR4LMT %#010llx\n", bar_addr);
1640
1641 bar_addr = addr->bar5_addr32 +
1642 (b2b_bar == 5 ? ndev->b2b_off : 0);
Dave Jiang2f887b92015-05-20 12:55:47 -04001643 iowrite32(bar_addr, mmio + XEON_SBAR5LMT_OFFSET);
1644 bar_addr = ioread32(mmio + XEON_SBAR5LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001645 dev_dbg(ndev_dev(ndev), "SBAR5LMT %#05llx\n", bar_addr);
1646 }
1647
1648 /* zero incoming translation addrs */
Dave Jiang2f887b92015-05-20 12:55:47 -04001649 iowrite64(0, mmio + XEON_SBAR23XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001650
1651 if (!ndev->bar4_split) {
Dave Jiang2f887b92015-05-20 12:55:47 -04001652 iowrite64(0, mmio + XEON_SBAR45XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001653 } else {
Dave Jiang2f887b92015-05-20 12:55:47 -04001654 iowrite32(0, mmio + XEON_SBAR4XLAT_OFFSET);
1655 iowrite32(0, mmio + XEON_SBAR5XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001656 }
1657
1658 /* zero outgoing translation limits (whole bar size windows) */
Dave Jiang2f887b92015-05-20 12:55:47 -04001659 iowrite64(0, mmio + XEON_PBAR23LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001660 if (!ndev->bar4_split) {
Dave Jiang2f887b92015-05-20 12:55:47 -04001661 iowrite64(0, mmio + XEON_PBAR45LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001662 } else {
Dave Jiang2f887b92015-05-20 12:55:47 -04001663 iowrite32(0, mmio + XEON_PBAR4LMT_OFFSET);
1664 iowrite32(0, mmio + XEON_PBAR5LMT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001665 }
1666
1667 /* set outgoing translation offsets */
1668 bar_addr = peer_addr->bar2_addr64;
Dave Jiang2f887b92015-05-20 12:55:47 -04001669 iowrite64(bar_addr, mmio + XEON_PBAR23XLAT_OFFSET);
1670 bar_addr = ioread64(mmio + XEON_PBAR23XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001671 dev_dbg(ndev_dev(ndev), "PBAR23XLAT %#018llx\n", bar_addr);
1672
1673 if (!ndev->bar4_split) {
1674 bar_addr = peer_addr->bar4_addr64;
Dave Jiang2f887b92015-05-20 12:55:47 -04001675 iowrite64(bar_addr, mmio + XEON_PBAR45XLAT_OFFSET);
1676 bar_addr = ioread64(mmio + XEON_PBAR45XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001677 dev_dbg(ndev_dev(ndev), "PBAR45XLAT %#018llx\n", bar_addr);
1678 } else {
1679 bar_addr = peer_addr->bar4_addr32;
Dave Jiang2f887b92015-05-20 12:55:47 -04001680 iowrite32(bar_addr, mmio + XEON_PBAR4XLAT_OFFSET);
1681 bar_addr = ioread32(mmio + XEON_PBAR4XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001682 dev_dbg(ndev_dev(ndev), "PBAR4XLAT %#010llx\n", bar_addr);
1683
1684 bar_addr = peer_addr->bar5_addr32;
Dave Jiang2f887b92015-05-20 12:55:47 -04001685 iowrite32(bar_addr, mmio + XEON_PBAR5XLAT_OFFSET);
1686 bar_addr = ioread32(mmio + XEON_PBAR5XLAT_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001687 dev_dbg(ndev_dev(ndev), "PBAR5XLAT %#010llx\n", bar_addr);
1688 }
1689
1690 /* set the translation offset for b2b registers */
1691 if (b2b_bar == 0)
1692 bar_addr = peer_addr->bar0_addr;
1693 else if (b2b_bar == 2)
1694 bar_addr = peer_addr->bar2_addr64;
1695 else if (b2b_bar == 4 && !ndev->bar4_split)
1696 bar_addr = peer_addr->bar4_addr64;
1697 else if (b2b_bar == 4)
1698 bar_addr = peer_addr->bar4_addr32;
1699 else if (b2b_bar == 5)
1700 bar_addr = peer_addr->bar5_addr32;
1701 else
1702 return -EIO;
1703
1704 /* B2B_XLAT_OFFSET is 64bit, but can only take 32bit writes */
1705 dev_dbg(ndev_dev(ndev), "B2BXLAT %#018llx\n", bar_addr);
Dave Jiang2f887b92015-05-20 12:55:47 -04001706 iowrite32(bar_addr, mmio + XEON_B2B_XLAT_OFFSETL);
1707 iowrite32(bar_addr >> 32, mmio + XEON_B2B_XLAT_OFFSETU);
Allen Hubbee26a5842015-04-09 10:33:20 -04001708
1709 if (b2b_bar) {
1710 /* map peer ntb mmio config space registers */
1711 ndev->peer_mmio = pci_iomap(pdev, b2b_bar,
Dave Jiang2f887b92015-05-20 12:55:47 -04001712 XEON_B2B_MIN_SIZE);
Allen Hubbee26a5842015-04-09 10:33:20 -04001713 if (!ndev->peer_mmio)
1714 return -EIO;
1715 }
1716
1717 return 0;
1718}
1719
Dave Jiang2f887b92015-05-20 12:55:47 -04001720static int xeon_init_ntb(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001721{
1722 int rc;
Dave Jiang5ae0beb2015-05-19 16:59:34 -04001723 u32 ntb_ctl;
Allen Hubbee26a5842015-04-09 10:33:20 -04001724
1725 if (ndev->bar4_split)
1726 ndev->mw_count = HSX_SPLIT_BAR_MW_COUNT;
1727 else
Dave Jiang2f887b92015-05-20 12:55:47 -04001728 ndev->mw_count = XEON_MW_COUNT;
Allen Hubbee26a5842015-04-09 10:33:20 -04001729
Dave Jiang2f887b92015-05-20 12:55:47 -04001730 ndev->spad_count = XEON_SPAD_COUNT;
1731 ndev->db_count = XEON_DB_COUNT;
1732 ndev->db_link_mask = XEON_DB_LINK_BIT;
Allen Hubbee26a5842015-04-09 10:33:20 -04001733
1734 switch (ndev->ntb.topo) {
1735 case NTB_TOPO_PRI:
1736 if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP) {
1737 dev_err(ndev_dev(ndev), "NTB Primary config disabled\n");
1738 return -EINVAL;
1739 }
Dave Jiang5ae0beb2015-05-19 16:59:34 -04001740
1741 /* enable link to allow secondary side device to appear */
1742 ntb_ctl = ioread32(ndev->self_mmio + ndev->reg->ntb_ctl);
1743 ntb_ctl &= ~NTB_CTL_DISABLE;
1744 iowrite32(ntb_ctl, ndev->self_mmio + ndev->reg->ntb_ctl);
1745
Allen Hubbee26a5842015-04-09 10:33:20 -04001746 /* use half the spads for the peer */
1747 ndev->spad_count >>= 1;
Dave Jiang2f887b92015-05-20 12:55:47 -04001748 ndev->self_reg = &xeon_pri_reg;
1749 ndev->peer_reg = &xeon_sec_reg;
1750 ndev->xlat_reg = &xeon_sec_xlat;
Allen Hubbee26a5842015-04-09 10:33:20 -04001751 break;
1752
1753 case NTB_TOPO_SEC:
1754 if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP) {
1755 dev_err(ndev_dev(ndev), "NTB Secondary config disabled\n");
1756 return -EINVAL;
1757 }
1758 /* use half the spads for the peer */
1759 ndev->spad_count >>= 1;
Dave Jiang2f887b92015-05-20 12:55:47 -04001760 ndev->self_reg = &xeon_sec_reg;
1761 ndev->peer_reg = &xeon_pri_reg;
1762 ndev->xlat_reg = &xeon_pri_xlat;
Allen Hubbee26a5842015-04-09 10:33:20 -04001763 break;
1764
1765 case NTB_TOPO_B2B_USD:
1766 case NTB_TOPO_B2B_DSD:
Dave Jiang2f887b92015-05-20 12:55:47 -04001767 ndev->self_reg = &xeon_pri_reg;
1768 ndev->peer_reg = &xeon_b2b_reg;
1769 ndev->xlat_reg = &xeon_sec_xlat;
Allen Hubbee26a5842015-04-09 10:33:20 -04001770
1771 if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP) {
Dave Jiang2f887b92015-05-20 12:55:47 -04001772 ndev->peer_reg = &xeon_pri_reg;
Allen Hubbee26a5842015-04-09 10:33:20 -04001773
1774 if (b2b_mw_idx < 0)
1775 ndev->b2b_idx = b2b_mw_idx + ndev->mw_count;
1776 else
1777 ndev->b2b_idx = b2b_mw_idx;
1778
1779 dev_dbg(ndev_dev(ndev),
1780 "setting up b2b mw idx %d means %d\n",
1781 b2b_mw_idx, ndev->b2b_idx);
1782
1783 } else if (ndev->hwerr_flags & NTB_HWERR_B2BDOORBELL_BIT14) {
1784 dev_warn(ndev_dev(ndev), "Reduce doorbell count by 1\n");
1785 ndev->db_count -= 1;
1786 }
1787
1788 if (ndev->ntb.topo == NTB_TOPO_B2B_USD) {
Dave Jiang2f887b92015-05-20 12:55:47 -04001789 rc = xeon_setup_b2b_mw(ndev,
1790 &xeon_b2b_dsd_addr,
1791 &xeon_b2b_usd_addr);
Allen Hubbee26a5842015-04-09 10:33:20 -04001792 } else {
Dave Jiang2f887b92015-05-20 12:55:47 -04001793 rc = xeon_setup_b2b_mw(ndev,
1794 &xeon_b2b_usd_addr,
1795 &xeon_b2b_dsd_addr);
Allen Hubbee26a5842015-04-09 10:33:20 -04001796 }
1797 if (rc)
1798 return rc;
1799
1800 /* Enable Bus Master and Memory Space on the secondary side */
1801 iowrite16(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER,
Dave Jiang2f887b92015-05-20 12:55:47 -04001802 ndev->self_mmio + XEON_SPCICMD_OFFSET);
Allen Hubbee26a5842015-04-09 10:33:20 -04001803
1804 break;
1805
1806 default:
1807 return -EINVAL;
1808 }
1809
1810 ndev->db_valid_mask = BIT_ULL(ndev->db_count) - 1;
1811
1812 ndev->reg->db_iowrite(ndev->db_valid_mask,
1813 ndev->self_mmio +
1814 ndev->self_reg->db_mask);
1815
1816 return 0;
1817}
1818
Dave Jiang2f887b92015-05-20 12:55:47 -04001819static int xeon_init_dev(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001820{
1821 struct pci_dev *pdev;
1822 u8 ppd;
1823 int rc, mem;
1824
Dave Jiangdd5d4d82015-05-08 12:24:40 -04001825 pdev = ndev_pdev(ndev);
1826
1827 switch (pdev->device) {
Allen Hubbee26a5842015-04-09 10:33:20 -04001828 /* There is a Xeon hardware errata related to writes to SDOORBELL or
1829 * B2BDOORBELL in conjunction with inbound access to NTB MMIO Space,
1830 * which may hang the system. To workaround this use the second memory
1831 * window to access the interrupt and scratch pad registers on the
1832 * remote system.
1833 */
Dave Jiangdd5d4d82015-05-08 12:24:40 -04001834 case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
1835 case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
1836 case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
1837 case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
1838 case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
1839 case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
1840 case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
1841 case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
1842 case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
1843 case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
1844 case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
1845 case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
1846 ndev->hwerr_flags |= NTB_HWERR_SDOORBELL_LOCKUP;
1847 break;
1848 }
Allen Hubbee26a5842015-04-09 10:33:20 -04001849
Dave Jiangdd5d4d82015-05-08 12:24:40 -04001850 switch (pdev->device) {
Allen Hubbee26a5842015-04-09 10:33:20 -04001851 /* There is a hardware errata related to accessing any register in
1852 * SB01BASE in the presence of bidirectional traffic crossing the NTB.
1853 */
Dave Jiangdd5d4d82015-05-08 12:24:40 -04001854 case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
1855 case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
1856 case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
1857 case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
1858 case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
1859 case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
1860 ndev->hwerr_flags |= NTB_HWERR_SB01BASE_LOCKUP;
1861 break;
1862 }
Allen Hubbee26a5842015-04-09 10:33:20 -04001863
Dave Jiangdd5d4d82015-05-08 12:24:40 -04001864 switch (pdev->device) {
Allen Hubbee26a5842015-04-09 10:33:20 -04001865 /* HW Errata on bit 14 of b2bdoorbell register. Writes will not be
1866 * mirrored to the remote system. Shrink the number of bits by one,
1867 * since bit 14 is the last bit.
1868 */
Dave Jiangdd5d4d82015-05-08 12:24:40 -04001869 case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
1870 case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
1871 case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
1872 case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
1873 case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
1874 case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
1875 case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
1876 case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
1877 case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
1878 case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
1879 case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
1880 case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
1881 ndev->hwerr_flags |= NTB_HWERR_B2BDOORBELL_BIT14;
1882 break;
1883 }
Allen Hubbee26a5842015-04-09 10:33:20 -04001884
Dave Jiang2f887b92015-05-20 12:55:47 -04001885 ndev->reg = &xeon_reg;
Allen Hubbee26a5842015-04-09 10:33:20 -04001886
Dave Jiang2f887b92015-05-20 12:55:47 -04001887 rc = pci_read_config_byte(pdev, XEON_PPD_OFFSET, &ppd);
Allen Hubbee26a5842015-04-09 10:33:20 -04001888 if (rc)
1889 return -EIO;
1890
Dave Jiang2f887b92015-05-20 12:55:47 -04001891 ndev->ntb.topo = xeon_ppd_topo(ndev, ppd);
Allen Hubbee26a5842015-04-09 10:33:20 -04001892 dev_dbg(ndev_dev(ndev), "ppd %#x topo %s\n", ppd,
1893 ntb_topo_string(ndev->ntb.topo));
1894 if (ndev->ntb.topo == NTB_TOPO_NONE)
1895 return -EINVAL;
1896
1897 if (ndev->ntb.topo != NTB_TOPO_SEC) {
Dave Jiang2f887b92015-05-20 12:55:47 -04001898 ndev->bar4_split = xeon_ppd_bar4_split(ndev, ppd);
Allen Hubbee26a5842015-04-09 10:33:20 -04001899 dev_dbg(ndev_dev(ndev), "ppd %#x bar4_split %d\n",
1900 ppd, ndev->bar4_split);
1901 } else {
1902 /* This is a way for transparent BAR to figure out if we are
1903 * doing split BAR or not. There is no way for the hw on the
1904 * transparent side to know and set the PPD.
1905 */
1906 mem = pci_select_bars(pdev, IORESOURCE_MEM);
1907 ndev->bar4_split = hweight32(mem) ==
1908 HSX_SPLIT_BAR_MW_COUNT + 1;
1909 dev_dbg(ndev_dev(ndev), "mem %#x bar4_split %d\n",
1910 mem, ndev->bar4_split);
1911 }
1912
Dave Jiang2f887b92015-05-20 12:55:47 -04001913 rc = xeon_init_ntb(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04001914 if (rc)
1915 return rc;
1916
Dave Jiang2f887b92015-05-20 12:55:47 -04001917 return xeon_init_isr(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04001918}
1919
Dave Jiang2f887b92015-05-20 12:55:47 -04001920static void xeon_deinit_dev(struct intel_ntb_dev *ndev)
Allen Hubbee26a5842015-04-09 10:33:20 -04001921{
Dave Jiang2f887b92015-05-20 12:55:47 -04001922 xeon_deinit_isr(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04001923}
1924
1925static int intel_ntb_init_pci(struct intel_ntb_dev *ndev, struct pci_dev *pdev)
1926{
1927 int rc;
1928
1929 pci_set_drvdata(pdev, ndev);
1930
1931 rc = pci_enable_device(pdev);
1932 if (rc)
1933 goto err_pci_enable;
1934
1935 rc = pci_request_regions(pdev, NTB_NAME);
1936 if (rc)
1937 goto err_pci_regions;
1938
1939 pci_set_master(pdev);
1940
1941 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
1942 if (rc) {
1943 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1944 if (rc)
1945 goto err_dma_mask;
1946 dev_warn(ndev_dev(ndev), "Cannot DMA highmem\n");
1947 }
1948
1949 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
1950 if (rc) {
1951 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
1952 if (rc)
1953 goto err_dma_mask;
1954 dev_warn(ndev_dev(ndev), "Cannot DMA consistent highmem\n");
1955 }
1956
1957 ndev->self_mmio = pci_iomap(pdev, 0, 0);
1958 if (!ndev->self_mmio) {
1959 rc = -EIO;
1960 goto err_mmio;
1961 }
1962 ndev->peer_mmio = ndev->self_mmio;
1963
1964 return 0;
1965
1966err_mmio:
1967err_dma_mask:
1968 pci_clear_master(pdev);
1969 pci_release_regions(pdev);
1970err_pci_regions:
1971 pci_disable_device(pdev);
1972err_pci_enable:
1973 pci_set_drvdata(pdev, NULL);
1974 return rc;
1975}
1976
1977static void intel_ntb_deinit_pci(struct intel_ntb_dev *ndev)
1978{
1979 struct pci_dev *pdev = ndev_pdev(ndev);
1980
1981 if (ndev->peer_mmio && ndev->peer_mmio != ndev->self_mmio)
1982 pci_iounmap(pdev, ndev->peer_mmio);
1983 pci_iounmap(pdev, ndev->self_mmio);
1984
1985 pci_clear_master(pdev);
1986 pci_release_regions(pdev);
1987 pci_disable_device(pdev);
1988 pci_set_drvdata(pdev, NULL);
1989}
1990
1991static inline void ndev_init_struct(struct intel_ntb_dev *ndev,
1992 struct pci_dev *pdev)
1993{
1994 ndev->ntb.pdev = pdev;
1995 ndev->ntb.topo = NTB_TOPO_NONE;
1996 ndev->ntb.ops = &intel_ntb_ops;
1997
1998 ndev->b2b_off = 0;
1999 ndev->b2b_idx = INT_MAX;
2000
2001 ndev->bar4_split = 0;
2002
2003 ndev->mw_count = 0;
2004 ndev->spad_count = 0;
2005 ndev->db_count = 0;
2006 ndev->db_vec_count = 0;
2007 ndev->db_vec_shift = 0;
2008
2009 ndev->ntb_ctl = 0;
2010 ndev->lnk_sta = 0;
2011
2012 ndev->db_valid_mask = 0;
2013 ndev->db_link_mask = 0;
2014 ndev->db_mask = 0;
2015
2016 spin_lock_init(&ndev->db_mask_lock);
2017}
2018
2019static int intel_ntb_pci_probe(struct pci_dev *pdev,
2020 const struct pci_device_id *id)
2021{
2022 struct intel_ntb_dev *ndev;
Allen Hubbe0e041fb2015-05-19 12:04:52 -04002023 int rc, node;
2024
2025 node = dev_to_node(&pdev->dev);
Allen Hubbee26a5842015-04-09 10:33:20 -04002026
Dave Jiang2f887b92015-05-20 12:55:47 -04002027 if (pdev_is_atom(pdev)) {
Allen Hubbe0e041fb2015-05-19 12:04:52 -04002028 ndev = kzalloc_node(sizeof(*ndev), GFP_KERNEL, node);
Allen Hubbee26a5842015-04-09 10:33:20 -04002029 if (!ndev) {
2030 rc = -ENOMEM;
2031 goto err_ndev;
2032 }
2033
2034 ndev_init_struct(ndev, pdev);
2035
2036 rc = intel_ntb_init_pci(ndev, pdev);
2037 if (rc)
2038 goto err_init_pci;
2039
Dave Jiang2f887b92015-05-20 12:55:47 -04002040 rc = atom_init_dev(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04002041 if (rc)
2042 goto err_init_dev;
2043
Dave Jiang2f887b92015-05-20 12:55:47 -04002044 } else if (pdev_is_xeon(pdev)) {
Allen Hubbe0e041fb2015-05-19 12:04:52 -04002045 ndev = kzalloc_node(sizeof(*ndev), GFP_KERNEL, node);
Allen Hubbee26a5842015-04-09 10:33:20 -04002046 if (!ndev) {
2047 rc = -ENOMEM;
2048 goto err_ndev;
2049 }
2050
2051 ndev_init_struct(ndev, pdev);
2052
2053 rc = intel_ntb_init_pci(ndev, pdev);
2054 if (rc)
2055 goto err_init_pci;
2056
Dave Jiang2f887b92015-05-20 12:55:47 -04002057 rc = xeon_init_dev(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04002058 if (rc)
2059 goto err_init_dev;
2060
2061 } else {
2062 rc = -EINVAL;
2063 goto err_ndev;
2064 }
2065
2066 ndev_reset_unsafe_flags(ndev);
2067
2068 ndev->reg->poll_link(ndev);
2069
2070 ndev_init_debugfs(ndev);
2071
2072 rc = ntb_register_device(&ndev->ntb);
2073 if (rc)
2074 goto err_register;
2075
Dave Jiang7eb38782015-06-15 08:21:33 -04002076 dev_info(&pdev->dev, "NTB device registered.\n");
2077
Allen Hubbee26a5842015-04-09 10:33:20 -04002078 return 0;
2079
2080err_register:
2081 ndev_deinit_debugfs(ndev);
Dave Jiang2f887b92015-05-20 12:55:47 -04002082 if (pdev_is_atom(pdev))
2083 atom_deinit_dev(ndev);
2084 else if (pdev_is_xeon(pdev))
2085 xeon_deinit_dev(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04002086err_init_dev:
2087 intel_ntb_deinit_pci(ndev);
2088err_init_pci:
2089 kfree(ndev);
2090err_ndev:
2091 return rc;
2092}
2093
2094static void intel_ntb_pci_remove(struct pci_dev *pdev)
2095{
2096 struct intel_ntb_dev *ndev = pci_get_drvdata(pdev);
2097
2098 ntb_unregister_device(&ndev->ntb);
2099 ndev_deinit_debugfs(ndev);
Dave Jiang2f887b92015-05-20 12:55:47 -04002100 if (pdev_is_atom(pdev))
2101 atom_deinit_dev(ndev);
2102 else if (pdev_is_xeon(pdev))
2103 xeon_deinit_dev(ndev);
Allen Hubbee26a5842015-04-09 10:33:20 -04002104 intel_ntb_deinit_pci(ndev);
2105 kfree(ndev);
2106}
2107
Dave Jiang2f887b92015-05-20 12:55:47 -04002108static const struct intel_ntb_reg atom_reg = {
2109 .poll_link = atom_poll_link,
2110 .link_is_up = atom_link_is_up,
2111 .db_ioread = atom_db_ioread,
2112 .db_iowrite = atom_db_iowrite,
Allen Hubbee26a5842015-04-09 10:33:20 -04002113 .db_size = sizeof(u64),
Dave Jiang2f887b92015-05-20 12:55:47 -04002114 .ntb_ctl = ATOM_NTBCNTL_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002115 .mw_bar = {2, 4},
2116};
2117
Dave Jiang2f887b92015-05-20 12:55:47 -04002118static const struct intel_ntb_alt_reg atom_pri_reg = {
2119 .db_bell = ATOM_PDOORBELL_OFFSET,
2120 .db_mask = ATOM_PDBMSK_OFFSET,
2121 .spad = ATOM_SPAD_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002122};
2123
Dave Jiang2f887b92015-05-20 12:55:47 -04002124static const struct intel_ntb_alt_reg atom_b2b_reg = {
2125 .db_bell = ATOM_B2B_DOORBELL_OFFSET,
2126 .spad = ATOM_B2B_SPAD_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002127};
2128
Dave Jiang2f887b92015-05-20 12:55:47 -04002129static const struct intel_ntb_xlat_reg atom_sec_xlat = {
2130 /* FIXME : .bar0_base = ATOM_SBAR0BASE_OFFSET, */
2131 /* FIXME : .bar2_limit = ATOM_SBAR2LMT_OFFSET, */
2132 .bar2_xlat = ATOM_SBAR2XLAT_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002133};
2134
Dave Jiang2f887b92015-05-20 12:55:47 -04002135static const struct intel_ntb_reg xeon_reg = {
2136 .poll_link = xeon_poll_link,
2137 .link_is_up = xeon_link_is_up,
2138 .db_ioread = xeon_db_ioread,
2139 .db_iowrite = xeon_db_iowrite,
Allen Hubbee26a5842015-04-09 10:33:20 -04002140 .db_size = sizeof(u32),
Dave Jiang2f887b92015-05-20 12:55:47 -04002141 .ntb_ctl = XEON_NTBCNTL_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002142 .mw_bar = {2, 4, 5},
2143};
2144
Dave Jiang2f887b92015-05-20 12:55:47 -04002145static const struct intel_ntb_alt_reg xeon_pri_reg = {
2146 .db_bell = XEON_PDOORBELL_OFFSET,
2147 .db_mask = XEON_PDBMSK_OFFSET,
2148 .spad = XEON_SPAD_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002149};
2150
Dave Jiang2f887b92015-05-20 12:55:47 -04002151static const struct intel_ntb_alt_reg xeon_sec_reg = {
2152 .db_bell = XEON_SDOORBELL_OFFSET,
2153 .db_mask = XEON_SDBMSK_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002154 /* second half of the scratchpads */
Dave Jiang2f887b92015-05-20 12:55:47 -04002155 .spad = XEON_SPAD_OFFSET + (XEON_SPAD_COUNT << 1),
Allen Hubbee26a5842015-04-09 10:33:20 -04002156};
2157
Dave Jiang2f887b92015-05-20 12:55:47 -04002158static const struct intel_ntb_alt_reg xeon_b2b_reg = {
2159 .db_bell = XEON_B2B_DOORBELL_OFFSET,
2160 .spad = XEON_B2B_SPAD_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002161};
2162
Dave Jiang2f887b92015-05-20 12:55:47 -04002163static const struct intel_ntb_xlat_reg xeon_pri_xlat = {
Allen Hubbee26a5842015-04-09 10:33:20 -04002164 /* Note: no primary .bar0_base visible to the secondary side.
2165 *
2166 * The secondary side cannot get the base address stored in primary
2167 * bars. The base address is necessary to set the limit register to
2168 * any value other than zero, or unlimited.
2169 *
2170 * WITHOUT THE BASE ADDRESS, THE SECONDARY SIDE CANNOT DISABLE the
2171 * window by setting the limit equal to base, nor can it limit the size
2172 * of the memory window by setting the limit to base + size.
2173 */
Dave Jiang2f887b92015-05-20 12:55:47 -04002174 .bar2_limit = XEON_PBAR23LMT_OFFSET,
2175 .bar2_xlat = XEON_PBAR23XLAT_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002176};
2177
Dave Jiang2f887b92015-05-20 12:55:47 -04002178static const struct intel_ntb_xlat_reg xeon_sec_xlat = {
2179 .bar0_base = XEON_SBAR0BASE_OFFSET,
2180 .bar2_limit = XEON_SBAR23LMT_OFFSET,
2181 .bar2_xlat = XEON_SBAR23XLAT_OFFSET,
Allen Hubbee26a5842015-04-09 10:33:20 -04002182};
2183
Dave Jiang2f887b92015-05-20 12:55:47 -04002184static struct intel_b2b_addr xeon_b2b_usd_addr = {
2185 .bar2_addr64 = XEON_B2B_BAR2_USD_ADDR64,
2186 .bar4_addr64 = XEON_B2B_BAR4_USD_ADDR64,
2187 .bar4_addr32 = XEON_B2B_BAR4_USD_ADDR32,
2188 .bar5_addr32 = XEON_B2B_BAR5_USD_ADDR32,
Allen Hubbee26a5842015-04-09 10:33:20 -04002189};
2190
Dave Jiang2f887b92015-05-20 12:55:47 -04002191static struct intel_b2b_addr xeon_b2b_dsd_addr = {
2192 .bar2_addr64 = XEON_B2B_BAR2_DSD_ADDR64,
2193 .bar4_addr64 = XEON_B2B_BAR4_DSD_ADDR64,
2194 .bar4_addr32 = XEON_B2B_BAR4_DSD_ADDR32,
2195 .bar5_addr32 = XEON_B2B_BAR5_DSD_ADDR32,
Allen Hubbee26a5842015-04-09 10:33:20 -04002196};
2197
2198/* operations for primary side of local ntb */
2199static const struct ntb_dev_ops intel_ntb_ops = {
2200 .mw_count = intel_ntb_mw_count,
2201 .mw_get_range = intel_ntb_mw_get_range,
2202 .mw_set_trans = intel_ntb_mw_set_trans,
2203 .link_is_up = intel_ntb_link_is_up,
2204 .link_enable = intel_ntb_link_enable,
2205 .link_disable = intel_ntb_link_disable,
2206 .db_is_unsafe = intel_ntb_db_is_unsafe,
2207 .db_valid_mask = intel_ntb_db_valid_mask,
2208 .db_vector_count = intel_ntb_db_vector_count,
2209 .db_vector_mask = intel_ntb_db_vector_mask,
2210 .db_read = intel_ntb_db_read,
2211 .db_clear = intel_ntb_db_clear,
2212 .db_set_mask = intel_ntb_db_set_mask,
2213 .db_clear_mask = intel_ntb_db_clear_mask,
2214 .peer_db_addr = intel_ntb_peer_db_addr,
2215 .peer_db_set = intel_ntb_peer_db_set,
2216 .spad_is_unsafe = intel_ntb_spad_is_unsafe,
2217 .spad_count = intel_ntb_spad_count,
2218 .spad_read = intel_ntb_spad_read,
2219 .spad_write = intel_ntb_spad_write,
2220 .peer_spad_addr = intel_ntb_peer_spad_addr,
2221 .peer_spad_read = intel_ntb_peer_spad_read,
2222 .peer_spad_write = intel_ntb_peer_spad_write,
2223};
2224
2225static const struct file_operations intel_ntb_debugfs_info = {
2226 .owner = THIS_MODULE,
2227 .open = simple_open,
2228 .read = ndev_debugfs_read,
2229};
2230
2231static const struct pci_device_id intel_ntb_pci_tbl[] = {
Jon Masonfce8a7b2012-11-16 19:27:12 -07002232 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_BWD)},
2233 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_JSF)},
Jon Masonfce8a7b2012-11-16 19:27:12 -07002234 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_SNB)},
Jon Masonbe4dac02012-09-28 11:38:48 -07002235 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_IVT)},
2236 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_HSX)},
2237 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_JSF)},
2238 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_SNB)},
2239 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_IVT)},
2240 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_HSX)},
2241 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_JSF)},
2242 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_SNB)},
2243 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_IVT)},
2244 {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_HSX)},
Jon Masonfce8a7b2012-11-16 19:27:12 -07002245 {0}
2246};
Allen Hubbee26a5842015-04-09 10:33:20 -04002247MODULE_DEVICE_TABLE(pci, intel_ntb_pci_tbl);
Jon Masonfce8a7b2012-11-16 19:27:12 -07002248
Allen Hubbee26a5842015-04-09 10:33:20 -04002249static struct pci_driver intel_ntb_pci_driver = {
2250 .name = KBUILD_MODNAME,
2251 .id_table = intel_ntb_pci_tbl,
2252 .probe = intel_ntb_pci_probe,
2253 .remove = intel_ntb_pci_remove,
Jon Mason6465d022014-04-07 10:55:47 -07002254};
2255
Allen Hubbee26a5842015-04-09 10:33:20 -04002256static int __init intel_ntb_pci_driver_init(void)
Jon Mason1517a3f2013-07-30 15:58:49 -07002257{
Dave Jiang7eb38782015-06-15 08:21:33 -04002258 pr_info("%s %s\n", NTB_DESC, NTB_VER);
2259
Allen Hubbee26a5842015-04-09 10:33:20 -04002260 if (debugfs_initialized())
Jon Mason1517a3f2013-07-30 15:58:49 -07002261 debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
2262
Allen Hubbee26a5842015-04-09 10:33:20 -04002263 return pci_register_driver(&intel_ntb_pci_driver);
Jon Mason1517a3f2013-07-30 15:58:49 -07002264}
Allen Hubbee26a5842015-04-09 10:33:20 -04002265module_init(intel_ntb_pci_driver_init);
Jon Mason1517a3f2013-07-30 15:58:49 -07002266
Allen Hubbee26a5842015-04-09 10:33:20 -04002267static void __exit intel_ntb_pci_driver_exit(void)
Jon Mason1517a3f2013-07-30 15:58:49 -07002268{
Allen Hubbee26a5842015-04-09 10:33:20 -04002269 pci_unregister_driver(&intel_ntb_pci_driver);
Jon Mason1517a3f2013-07-30 15:58:49 -07002270
Allen Hubbee26a5842015-04-09 10:33:20 -04002271 debugfs_remove_recursive(debugfs_dir);
Jon Mason1517a3f2013-07-30 15:58:49 -07002272}
Allen Hubbee26a5842015-04-09 10:33:20 -04002273module_exit(intel_ntb_pci_driver_exit);
Jon Mason1517a3f2013-07-30 15:58:49 -07002274