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.
7 * Copyright(c) 2012 Intel Corporation. All rights reserved.
8 * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
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.
16 * Copyright(c) 2012 Intel Corporation. All rights reserved.
17 * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
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
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.
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.
45 * Intel PCIe NTB Linux driver
47 * Contact Information:
48 * Jon Mason <jon.mason@intel.com>
51 #include <linux/debugfs.h>
52 #include <linux/delay.h>
53 #include <linux/init.h>
54 #include <linux/interrupt.h>
55 #include <linux/module.h>
56 #include <linux/pci.h>
57 #include <linux/random.h>
58 #include <linux/slab.h>
59 #include <linux/ntb.h>
61 #include "ntb_hw_intel.h"
63 #define NTB_NAME "ntb_hw_intel"
64 #define NTB_DESC "Intel(R) PCI-E Non-Transparent Bridge Driver"
67 MODULE_DESCRIPTION(NTB_DESC
);
68 MODULE_VERSION(NTB_VER
);
69 MODULE_LICENSE("Dual BSD/GPL");
70 MODULE_AUTHOR("Intel Corporation");
72 #define bar0_off(base, bar) ((base) + ((bar) << 2))
73 #define bar2_off(base, bar) bar0_off(base, (bar) - 2)
75 static const struct intel_ntb_reg atom_reg
;
76 static const struct intel_ntb_alt_reg atom_pri_reg
;
77 static const struct intel_ntb_alt_reg atom_sec_reg
;
78 static const struct intel_ntb_alt_reg atom_b2b_reg
;
79 static const struct intel_ntb_xlat_reg atom_pri_xlat
;
80 static const struct intel_ntb_xlat_reg atom_sec_xlat
;
81 static const struct intel_ntb_reg xeon_reg
;
82 static const struct intel_ntb_alt_reg xeon_pri_reg
;
83 static const struct intel_ntb_alt_reg xeon_sec_reg
;
84 static const struct intel_ntb_alt_reg xeon_b2b_reg
;
85 static const struct intel_ntb_xlat_reg xeon_pri_xlat
;
86 static const struct intel_ntb_xlat_reg xeon_sec_xlat
;
87 static struct intel_b2b_addr xeon_b2b_usd_addr
;
88 static struct intel_b2b_addr xeon_b2b_dsd_addr
;
89 static const struct ntb_dev_ops intel_ntb_ops
;
91 static const struct file_operations intel_ntb_debugfs_info
;
92 static struct dentry
*debugfs_dir
;
94 static int b2b_mw_idx
= -1;
95 module_param(b2b_mw_idx
, int, 0644);
96 MODULE_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!");
101 static unsigned int b2b_mw_share
;
102 module_param(b2b_mw_share
, uint
, 0644);
103 MODULE_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!");
108 module_param_named(xeon_b2b_usd_bar2_addr64
,
109 xeon_b2b_usd_addr
.bar2_addr64
, ullong
, 0644);
110 MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64
,
111 "XEON B2B USD BAR 2 64-bit address");
113 module_param_named(xeon_b2b_usd_bar4_addr64
,
114 xeon_b2b_usd_addr
.bar4_addr64
, ullong
, 0644);
115 MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64
,
116 "XEON B2B USD BAR 4 64-bit address");
118 module_param_named(xeon_b2b_usd_bar4_addr32
,
119 xeon_b2b_usd_addr
.bar4_addr32
, ullong
, 0644);
120 MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64
,
121 "XEON B2B USD split-BAR 4 32-bit address");
123 module_param_named(xeon_b2b_usd_bar5_addr32
,
124 xeon_b2b_usd_addr
.bar5_addr32
, ullong
, 0644);
125 MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64
,
126 "XEON B2B USD split-BAR 5 32-bit address");
128 module_param_named(xeon_b2b_dsd_bar2_addr64
,
129 xeon_b2b_dsd_addr
.bar2_addr64
, ullong
, 0644);
130 MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64
,
131 "XEON B2B DSD BAR 2 64-bit address");
133 module_param_named(xeon_b2b_dsd_bar4_addr64
,
134 xeon_b2b_dsd_addr
.bar4_addr64
, ullong
, 0644);
135 MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64
,
136 "XEON B2B DSD BAR 4 64-bit address");
138 module_param_named(xeon_b2b_dsd_bar4_addr32
,
139 xeon_b2b_dsd_addr
.bar4_addr32
, ullong
, 0644);
140 MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64
,
141 "XEON B2B DSD split-BAR 4 32-bit address");
143 module_param_named(xeon_b2b_dsd_bar5_addr32
,
144 xeon_b2b_dsd_addr
.bar5_addr32
, ullong
, 0644);
145 MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64
,
146 "XEON B2B DSD split-BAR 5 32-bit address");
150 #define ioread64 readq
152 #define ioread64 _ioread64
153 static inline u64
_ioread64(void __iomem
*mmio
)
157 low
= ioread32(mmio
);
158 high
= ioread32(mmio
+ sizeof(u32
));
159 return low
| (high
<< 32);
166 #define iowrite64 writeq
168 #define iowrite64 _iowrite64
169 static inline void _iowrite64(u64 val
, void __iomem
*mmio
)
171 iowrite32(val
, mmio
);
172 iowrite32(val
>> 32, mmio
+ sizeof(u32
));
177 static inline int pdev_is_atom(struct pci_dev
*pdev
)
179 switch (pdev
->device
) {
180 case PCI_DEVICE_ID_INTEL_NTB_B2B_BWD
:
186 static inline int pdev_is_xeon(struct pci_dev
*pdev
)
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
:
206 static inline void ndev_reset_unsafe_flags(struct intel_ntb_dev
*ndev
)
208 ndev
->unsafe_flags
= 0;
209 ndev
->unsafe_flags_ignore
= 0;
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
;
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
;
223 static inline int ndev_is_unsafe(struct intel_ntb_dev
*ndev
,
226 return !!(flag
& ndev
->unsafe_flags
& ~ndev
->unsafe_flags_ignore
);
229 static inline int ndev_ignore_unsafe(struct intel_ntb_dev
*ndev
,
232 flag
&= ndev
->unsafe_flags
;
233 ndev
->unsafe_flags_ignore
|= flag
;
238 static int ndev_mw_to_bar(struct intel_ntb_dev
*ndev
, int idx
)
240 if (idx
< 0 || idx
> ndev
->mw_count
)
242 return ndev
->reg
->mw_bar
[idx
];
245 static 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
)
249 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_DB
))
250 pr_warn_once("%s: NTB unsafe doorbell access", __func__
);
253 *db_addr
= reg_addr
+ reg
;
254 dev_dbg(ndev_dev(ndev
), "Peer db addr %llx\n", *db_addr
);
258 *db_size
= ndev
->reg
->db_size
;
259 dev_dbg(ndev_dev(ndev
), "Peer db size %llx\n", *db_size
);
265 static inline u64
ndev_db_read(struct intel_ntb_dev
*ndev
,
268 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_DB
))
269 pr_warn_once("%s: NTB unsafe doorbell access", __func__
);
271 return ndev
->reg
->db_ioread(mmio
);
274 static inline int ndev_db_write(struct intel_ntb_dev
*ndev
, u64 db_bits
,
277 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_DB
))
278 pr_warn_once("%s: NTB unsafe doorbell access", __func__
);
280 if (db_bits
& ~ndev
->db_valid_mask
)
283 ndev
->reg
->db_iowrite(db_bits
, mmio
);
288 static inline int ndev_db_set_mask(struct intel_ntb_dev
*ndev
, u64 db_bits
,
291 unsigned long irqflags
;
293 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_DB
))
294 pr_warn_once("%s: NTB unsafe doorbell access", __func__
);
296 if (db_bits
& ~ndev
->db_valid_mask
)
299 spin_lock_irqsave(&ndev
->db_mask_lock
, irqflags
);
301 ndev
->db_mask
|= db_bits
;
302 ndev
->reg
->db_iowrite(ndev
->db_mask
, mmio
);
304 spin_unlock_irqrestore(&ndev
->db_mask_lock
, irqflags
);
309 static inline int ndev_db_clear_mask(struct intel_ntb_dev
*ndev
, u64 db_bits
,
312 unsigned long irqflags
;
314 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_DB
))
315 pr_warn_once("%s: NTB unsafe doorbell access", __func__
);
317 if (db_bits
& ~ndev
->db_valid_mask
)
320 spin_lock_irqsave(&ndev
->db_mask_lock
, irqflags
);
322 ndev
->db_mask
&= ~db_bits
;
323 ndev
->reg
->db_iowrite(ndev
->db_mask
, mmio
);
325 spin_unlock_irqrestore(&ndev
->db_mask_lock
, irqflags
);
330 static inline int ndev_vec_mask(struct intel_ntb_dev
*ndev
, int db_vector
)
334 shift
= ndev
->db_vec_shift
;
335 mask
= BIT_ULL(shift
) - 1;
337 return mask
<< (shift
* db_vector
);
340 static inline int ndev_spad_addr(struct intel_ntb_dev
*ndev
, int idx
,
341 phys_addr_t
*spad_addr
, phys_addr_t reg_addr
,
344 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_SPAD
))
345 pr_warn_once("%s: NTB unsafe scratchpad access", __func__
);
347 if (idx
< 0 || idx
>= ndev
->spad_count
)
351 *spad_addr
= reg_addr
+ reg
+ (idx
<< 2);
352 dev_dbg(ndev_dev(ndev
), "Peer spad addr %llx\n", *spad_addr
);
358 static inline u32
ndev_spad_read(struct intel_ntb_dev
*ndev
, int idx
,
361 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_SPAD
))
362 pr_warn_once("%s: NTB unsafe scratchpad access", __func__
);
364 if (idx
< 0 || idx
>= ndev
->spad_count
)
367 return ioread32(mmio
+ (idx
<< 2));
370 static inline int ndev_spad_write(struct intel_ntb_dev
*ndev
, int idx
, u32 val
,
373 if (ndev_is_unsafe(ndev
, NTB_UNSAFE_SPAD
))
374 pr_warn_once("%s: NTB unsafe scratchpad access", __func__
);
376 if (idx
< 0 || idx
>= ndev
->spad_count
)
379 iowrite32(val
, mmio
+ (idx
<< 2));
384 static irqreturn_t
ndev_interrupt(struct intel_ntb_dev
*ndev
, int vec
)
388 vec_mask
= ndev_vec_mask(ndev
, vec
);
390 dev_dbg(ndev_dev(ndev
), "vec %d vec_mask %llx\n", vec
, vec_mask
);
392 ndev
->last_ts
= jiffies
;
394 if (vec_mask
& ndev
->db_link_mask
) {
395 if (ndev
->reg
->poll_link(ndev
))
396 ntb_link_event(&ndev
->ntb
);
399 if (vec_mask
& ndev
->db_valid_mask
)
400 ntb_db_event(&ndev
->ntb
, vec
);
405 static irqreturn_t
ndev_vec_isr(int irq
, void *dev
)
407 struct intel_ntb_vec
*nvec
= dev
;
409 return ndev_interrupt(nvec
->ndev
, nvec
->num
);
412 static irqreturn_t
ndev_irq_isr(int irq
, void *dev
)
414 struct intel_ntb_dev
*ndev
= dev
;
416 return ndev_interrupt(ndev
, irq
- ndev_pdev(ndev
)->irq
);
419 static int ndev_init_isr(struct intel_ntb_dev
*ndev
,
420 int msix_min
, int msix_max
,
421 int msix_shift
, int total_shift
)
423 struct pci_dev
*pdev
;
424 int rc
, i
, msix_count
, node
;
426 pdev
= ndev_pdev(ndev
);
428 node
= dev_to_node(&pdev
->dev
);
430 /* Mask all doorbell interrupts */
431 ndev
->db_mask
= ndev
->db_valid_mask
;
432 ndev
->reg
->db_iowrite(ndev
->db_mask
,
434 ndev
->self_reg
->db_mask
);
436 /* Try to set up msix irq */
438 ndev
->vec
= kzalloc_node(msix_max
* sizeof(*ndev
->vec
),
441 goto err_msix_vec_alloc
;
443 ndev
->msix
= kzalloc_node(msix_max
* sizeof(*ndev
->msix
),
448 for (i
= 0; i
< msix_max
; ++i
)
449 ndev
->msix
[i
].entry
= i
;
451 msix_count
= pci_enable_msix_range(pdev
, ndev
->msix
,
454 goto err_msix_enable
;
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
]);
462 goto err_msix_request
;
465 dev_dbg(ndev_dev(ndev
), "Using msix interrupts\n");
466 ndev
->db_vec_count
= msix_count
;
467 ndev
->db_vec_shift
= msix_shift
;
472 free_irq(ndev
->msix
[i
].vector
, ndev
);
473 pci_disable_msix(pdev
);
482 /* Try to set up msi irq */
484 rc
= pci_enable_msi(pdev
);
488 rc
= request_irq(pdev
->irq
, ndev_irq_isr
, 0,
489 "ndev_irq_isr", ndev
);
491 goto err_msi_request
;
493 dev_dbg(ndev_dev(ndev
), "Using msi interrupts\n");
494 ndev
->db_vec_count
= 1;
495 ndev
->db_vec_shift
= total_shift
;
499 pci_disable_msi(pdev
);
502 /* Try to set up intx irq */
506 rc
= request_irq(pdev
->irq
, ndev_irq_isr
, IRQF_SHARED
,
507 "ndev_irq_isr", ndev
);
509 goto err_intx_request
;
511 dev_dbg(ndev_dev(ndev
), "Using intx interrupts\n");
512 ndev
->db_vec_count
= 1;
513 ndev
->db_vec_shift
= total_shift
;
520 static void ndev_deinit_isr(struct intel_ntb_dev
*ndev
)
522 struct pci_dev
*pdev
;
525 pdev
= ndev_pdev(ndev
);
527 /* Mask all doorbell interrupts */
528 ndev
->db_mask
= ndev
->db_valid_mask
;
529 ndev
->reg
->db_iowrite(ndev
->db_mask
,
531 ndev
->self_reg
->db_mask
);
534 i
= ndev
->db_vec_count
;
536 free_irq(ndev
->msix
[i
].vector
, &ndev
->vec
[i
]);
537 pci_disable_msix(pdev
);
541 free_irq(pdev
->irq
, ndev
);
542 if (pci_dev_msi_enabled(pdev
))
543 pci_disable_msi(pdev
);
547 static ssize_t
ndev_debugfs_read(struct file
*filp
, char __user
*ubuf
,
548 size_t count
, loff_t
*offp
)
550 struct intel_ntb_dev
*ndev
;
555 union { u64 v64
; u32 v32
; u16 v16
; } u
;
557 ndev
= filp
->private_data
;
558 mmio
= ndev
->self_mmio
;
560 buf_size
= min(count
, 0x800ul
);
562 buf
= kmalloc(buf_size
, GFP_KERNEL
);
568 off
+= scnprintf(buf
+ off
, buf_size
- off
,
569 "NTB Device Information:\n");
571 off
+= scnprintf(buf
+ off
, buf_size
- off
,
572 "Connection Topology -\t%s\n",
573 ntb_topo_string(ndev
->ntb
.topo
));
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");
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
);
588 if (!ndev
->reg
->link_is_up(ndev
)) {
589 off
+= scnprintf(buf
+ off
, buf_size
- off
,
590 "Link Status -\t\tDown\n");
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
));
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
);
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
);
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
);
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
);
628 off
+= scnprintf(buf
+ off
, buf_size
- off
,
629 "\nNTB Incoming XLAT:\n");
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
);
635 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
);
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
);
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
);
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
);
653 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
);
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
);
666 if (pdev_is_xeon(ndev
->ntb
.pdev
)) {
667 if (ntb_topo_is_b2b(ndev
->ntb
.topo
)) {
668 off
+= scnprintf(buf
+ off
, buf_size
- off
,
669 "\nNTB Outgoing B2B XLAT:\n");
671 u
.v64
= ioread64(mmio
+ XEON_PBAR23XLAT_OFFSET
);
672 off
+= scnprintf(buf
+ off
, buf_size
- off
,
673 "B2B XLAT23 -\t\t%#018llx\n", u
.v64
);
675 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",
680 u
.v32
= ioread32(mmio
+ XEON_PBAR5XLAT_OFFSET
);
681 off
+= scnprintf(buf
+ off
, buf_size
- off
,
682 "B2B XLAT5 -\t\t%#06x\n",
685 u
.v64
= ioread64(mmio
+ XEON_PBAR45XLAT_OFFSET
);
686 off
+= scnprintf(buf
+ off
, buf_size
- off
,
687 "B2B XLAT45 -\t\t%#018llx\n",
691 u
.v64
= ioread64(mmio
+ XEON_PBAR23LMT_OFFSET
);
692 off
+= scnprintf(buf
+ off
, buf_size
- off
,
693 "B2B LMT23 -\t\t%#018llx\n", u
.v64
);
695 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",
700 u
.v32
= ioread32(mmio
+ XEON_PBAR5LMT_OFFSET
);
701 off
+= scnprintf(buf
+ off
, buf_size
- off
,
702 "B2B LMT5 -\t\t%#06x\n",
705 u
.v64
= ioread64(mmio
+ XEON_PBAR45LMT_OFFSET
);
706 off
+= scnprintf(buf
+ off
, buf_size
- off
,
707 "B2B LMT45 -\t\t%#018llx\n",
711 off
+= scnprintf(buf
+ off
, buf_size
- off
,
712 "\nNTB Secondary BAR:\n");
714 u
.v64
= ioread64(mmio
+ XEON_SBAR0BASE_OFFSET
);
715 off
+= scnprintf(buf
+ off
, buf_size
- off
,
716 "SBAR01 -\t\t%#018llx\n", u
.v64
);
718 u
.v64
= ioread64(mmio
+ XEON_SBAR23BASE_OFFSET
);
719 off
+= scnprintf(buf
+ off
, buf_size
- off
,
720 "SBAR23 -\t\t%#018llx\n", u
.v64
);
722 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
);
730 u
.v64
= ioread64(mmio
+ XEON_SBAR45BASE_OFFSET
);
731 off
+= scnprintf(buf
+ off
, buf_size
- off
,
732 "SBAR45 -\t\t%#018llx\n",
737 off
+= scnprintf(buf
+ off
, buf_size
- off
,
738 "\nXEON NTB Statistics:\n");
740 u
.v16
= ioread16(mmio
+ XEON_USMEMMISS_OFFSET
);
741 off
+= scnprintf(buf
+ off
, buf_size
- off
,
742 "Upstream Memory Miss -\t%u\n", u
.v16
);
744 off
+= scnprintf(buf
+ off
, buf_size
- off
,
745 "\nXEON NTB Hardware Errors:\n");
747 if (!pci_read_config_word(ndev
->ntb
.pdev
,
748 XEON_DEVSTS_OFFSET
, &u
.v16
))
749 off
+= scnprintf(buf
+ off
, buf_size
- off
,
750 "DEVSTS -\t\t%#06x\n", u
.v16
);
752 if (!pci_read_config_word(ndev
->ntb
.pdev
,
753 XEON_LINK_STATUS_OFFSET
, &u
.v16
))
754 off
+= scnprintf(buf
+ off
, buf_size
- off
,
755 "LNKSTS -\t\t%#06x\n", u
.v16
);
757 if (!pci_read_config_dword(ndev
->ntb
.pdev
,
758 XEON_UNCERRSTS_OFFSET
, &u
.v32
))
759 off
+= scnprintf(buf
+ off
, buf_size
- off
,
760 "UNCERRSTS -\t\t%#06x\n", u
.v32
);
762 if (!pci_read_config_dword(ndev
->ntb
.pdev
,
763 XEON_CORERRSTS_OFFSET
, &u
.v32
))
764 off
+= scnprintf(buf
+ off
, buf_size
- off
,
765 "CORERRSTS -\t\t%#06x\n", u
.v32
);
768 ret
= simple_read_from_buffer(ubuf
, count
, offp
, buf
, off
);
773 static void ndev_init_debugfs(struct intel_ntb_dev
*ndev
)
776 ndev
->debugfs_dir
= NULL
;
777 ndev
->debugfs_info
= NULL
;
780 debugfs_create_dir(ndev_name(ndev
), debugfs_dir
);
781 if (!ndev
->debugfs_dir
)
782 ndev
->debugfs_info
= NULL
;
785 debugfs_create_file("info", S_IRUSR
,
786 ndev
->debugfs_dir
, ndev
,
787 &intel_ntb_debugfs_info
);
791 static void ndev_deinit_debugfs(struct intel_ntb_dev
*ndev
)
793 debugfs_remove_recursive(ndev
->debugfs_dir
);
796 static int intel_ntb_mw_count(struct ntb_dev
*ntb
)
798 return ntb_ndev(ntb
)->mw_count
;
801 static int intel_ntb_mw_get_range(struct ntb_dev
*ntb
, int idx
,
803 resource_size_t
*size
,
804 resource_size_t
*align
,
805 resource_size_t
*align_size
)
807 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
810 if (idx
>= ndev
->b2b_idx
&& !ndev
->b2b_off
)
813 bar
= ndev_mw_to_bar(ndev
, idx
);
818 *base
= pci_resource_start(ndev
->ntb
.pdev
, bar
) +
819 (idx
== ndev
->b2b_idx
? ndev
->b2b_off
: 0);
822 *size
= pci_resource_len(ndev
->ntb
.pdev
, bar
) -
823 (idx
== ndev
->b2b_idx
? ndev
->b2b_off
: 0);
826 *align
= pci_resource_len(ndev
->ntb
.pdev
, bar
);
834 static int intel_ntb_mw_set_trans(struct ntb_dev
*ntb
, int idx
,
835 dma_addr_t addr
, resource_size_t size
)
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
;
841 u64 base
, limit
, reg_val
;
844 if (idx
>= ndev
->b2b_idx
&& !ndev
->b2b_off
)
847 bar
= ndev_mw_to_bar(ndev
, idx
);
851 bar_size
= pci_resource_len(ndev
->ntb
.pdev
, bar
);
853 if (idx
== ndev
->b2b_idx
)
854 mw_size
= bar_size
- ndev
->b2b_off
;
858 /* hardware requires that addr is aligned to bar size */
859 if (addr
& (bar_size
- 1))
862 /* make sure the range fits in the usable mw size */
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
);
871 if (bar
< 4 || !ndev
->bar4_split
) {
872 base
= ioread64(mmio
+ base_reg
);
874 /* Set the limit if supported, if size is not mw_size */
875 if (limit_reg
&& size
!= mw_size
)
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
);
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
);
897 /* split bar addr range must all be 32 bit */
898 if (addr
& (~0ull << 32))
900 if ((addr
+ size
) & (~0ull << 32))
903 base
= ioread32(mmio
+ base_reg
);
905 /* Set the limit if supported, if size is not mw_size */
906 if (limit_reg
&& size
!= mw_size
)
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
);
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
);
932 static int intel_ntb_link_is_up(struct ntb_dev
*ntb
,
933 enum ntb_speed
*speed
,
934 enum ntb_width
*width
)
936 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
938 if (ndev
->reg
->link_is_up(ndev
)) {
940 *speed
= NTB_LNK_STA_SPEED(ndev
->lnk_sta
);
942 *width
= NTB_LNK_STA_WIDTH(ndev
->lnk_sta
);
945 /* TODO MAYBE: is it possible to observe the link speed and
946 * width while link is training? */
948 *speed
= NTB_SPEED_NONE
;
950 *width
= NTB_WIDTH_NONE
;
955 static int intel_ntb_link_enable(struct ntb_dev
*ntb
,
956 enum ntb_speed max_speed
,
957 enum ntb_width max_width
)
959 struct intel_ntb_dev
*ndev
;
962 ndev
= container_of(ntb
, struct intel_ntb_dev
, ntb
);
964 if (ndev
->ntb
.topo
== NTB_TOPO_SEC
)
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
);
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
);
986 static int intel_ntb_link_disable(struct ntb_dev
*ntb
)
988 struct intel_ntb_dev
*ndev
;
991 ndev
= container_of(ntb
, struct intel_ntb_dev
, ntb
);
993 if (ndev
->ntb
.topo
== NTB_TOPO_SEC
)
996 dev_dbg(ndev_dev(ndev
), "Disabling link\n");
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
);
1010 static int intel_ntb_db_is_unsafe(struct ntb_dev
*ntb
)
1012 return ndev_ignore_unsafe(ntb_ndev(ntb
), NTB_UNSAFE_DB
);
1015 static u64
intel_ntb_db_valid_mask(struct ntb_dev
*ntb
)
1017 return ntb_ndev(ntb
)->db_valid_mask
;
1020 static int intel_ntb_db_vector_count(struct ntb_dev
*ntb
)
1022 struct intel_ntb_dev
*ndev
;
1024 ndev
= container_of(ntb
, struct intel_ntb_dev
, ntb
);
1026 return ndev
->db_vec_count
;
1029 static u64
intel_ntb_db_vector_mask(struct ntb_dev
*ntb
, int db_vector
)
1031 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1033 if (db_vector
< 0 || db_vector
> ndev
->db_vec_count
)
1036 return ndev
->db_valid_mask
& ndev_vec_mask(ndev
, db_vector
);
1039 static u64
intel_ntb_db_read(struct ntb_dev
*ntb
)
1041 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1043 return ndev_db_read(ndev
,
1045 ndev
->self_reg
->db_bell
);
1048 static int intel_ntb_db_clear(struct ntb_dev
*ntb
, u64 db_bits
)
1050 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1052 return ndev_db_write(ndev
, db_bits
,
1054 ndev
->self_reg
->db_bell
);
1057 static int intel_ntb_db_set_mask(struct ntb_dev
*ntb
, u64 db_bits
)
1059 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1061 return ndev_db_set_mask(ndev
, db_bits
,
1063 ndev
->self_reg
->db_mask
);
1066 static int intel_ntb_db_clear_mask(struct ntb_dev
*ntb
, u64 db_bits
)
1068 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1070 return ndev_db_clear_mask(ndev
, db_bits
,
1072 ndev
->self_reg
->db_mask
);
1075 static int intel_ntb_peer_db_addr(struct ntb_dev
*ntb
,
1076 phys_addr_t
*db_addr
,
1077 resource_size_t
*db_size
)
1079 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1081 return ndev_db_addr(ndev
, db_addr
, db_size
, ndev
->peer_addr
,
1082 ndev
->peer_reg
->db_bell
);
1085 static int intel_ntb_peer_db_set(struct ntb_dev
*ntb
, u64 db_bits
)
1087 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1089 return ndev_db_write(ndev
, db_bits
,
1091 ndev
->peer_reg
->db_bell
);
1094 static int intel_ntb_spad_is_unsafe(struct ntb_dev
*ntb
)
1096 return ndev_ignore_unsafe(ntb_ndev(ntb
), NTB_UNSAFE_SPAD
);
1099 static int intel_ntb_spad_count(struct ntb_dev
*ntb
)
1101 struct intel_ntb_dev
*ndev
;
1103 ndev
= container_of(ntb
, struct intel_ntb_dev
, ntb
);
1105 return ndev
->spad_count
;
1108 static u32
intel_ntb_spad_read(struct ntb_dev
*ntb
, int idx
)
1110 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1112 return ndev_spad_read(ndev
, idx
,
1114 ndev
->self_reg
->spad
);
1117 static int intel_ntb_spad_write(struct ntb_dev
*ntb
,
1120 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1122 return ndev_spad_write(ndev
, idx
, val
,
1124 ndev
->self_reg
->spad
);
1127 static int intel_ntb_peer_spad_addr(struct ntb_dev
*ntb
, int idx
,
1128 phys_addr_t
*spad_addr
)
1130 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1132 return ndev_spad_addr(ndev
, idx
, spad_addr
, ndev
->peer_addr
,
1133 ndev
->peer_reg
->spad
);
1136 static u32
intel_ntb_peer_spad_read(struct ntb_dev
*ntb
, int idx
)
1138 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1140 return ndev_spad_read(ndev
, idx
,
1142 ndev
->peer_reg
->spad
);
1145 static int intel_ntb_peer_spad_write(struct ntb_dev
*ntb
,
1148 struct intel_ntb_dev
*ndev
= ntb_ndev(ntb
);
1150 return ndev_spad_write(ndev
, idx
, val
,
1152 ndev
->peer_reg
->spad
);
1157 static u64
atom_db_ioread(void __iomem
*mmio
)
1159 return ioread64(mmio
);
1162 static void atom_db_iowrite(u64 bits
, void __iomem
*mmio
)
1164 iowrite64(bits
, mmio
);
1167 static int atom_poll_link(struct intel_ntb_dev
*ndev
)
1171 ntb_ctl
= ioread32(ndev
->self_mmio
+ ATOM_NTBCNTL_OFFSET
);
1173 if (ntb_ctl
== ndev
->ntb_ctl
)
1176 ndev
->ntb_ctl
= ntb_ctl
;
1178 ndev
->lnk_sta
= ioread32(ndev
->self_mmio
+ ATOM_LINK_STATUS_OFFSET
);
1183 static int atom_link_is_up(struct intel_ntb_dev
*ndev
)
1185 return ATOM_NTB_CTL_ACTIVE(ndev
->ntb_ctl
);
1188 static int atom_link_is_err(struct intel_ntb_dev
*ndev
)
1190 if (ioread32(ndev
->self_mmio
+ ATOM_LTSSMSTATEJMP_OFFSET
)
1191 & ATOM_LTSSMSTATEJMP_FORCEDETECT
)
1194 if (ioread32(ndev
->self_mmio
+ ATOM_IBSTERRRCRVSTS0_OFFSET
)
1195 & ATOM_IBIST_ERR_OFLOW
)
1201 static inline enum ntb_topo
atom_ppd_topo(struct intel_ntb_dev
*ndev
, u32 ppd
)
1203 switch (ppd
& ATOM_PPD_TOPO_MASK
) {
1204 case ATOM_PPD_TOPO_B2B_USD
:
1205 dev_dbg(ndev_dev(ndev
), "PPD %d B2B USD\n", ppd
);
1206 return NTB_TOPO_B2B_USD
;
1208 case ATOM_PPD_TOPO_B2B_DSD
:
1209 dev_dbg(ndev_dev(ndev
), "PPD %d B2B DSD\n", ppd
);
1210 return NTB_TOPO_B2B_DSD
;
1212 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 */
1216 dev_dbg(ndev_dev(ndev
), "PPD %d non B2B disabled\n", ppd
);
1217 return NTB_TOPO_NONE
;
1220 dev_dbg(ndev_dev(ndev
), "PPD %d invalid\n", ppd
);
1221 return NTB_TOPO_NONE
;
1224 static void atom_link_hb(struct work_struct
*work
)
1226 struct intel_ntb_dev
*ndev
= hb_ndev(work
);
1227 unsigned long poll_ts
;
1231 poll_ts
= ndev
->last_ts
+ ATOM_LINK_HB_TIMEOUT
;
1233 /* Delay polling the link status if an interrupt was received,
1234 * unless the cached link status says the link is down.
1236 if (time_after(poll_ts
, jiffies
) && atom_link_is_up(ndev
)) {
1237 schedule_delayed_work(&ndev
->hb_timer
, poll_ts
- jiffies
);
1241 if (atom_poll_link(ndev
))
1242 ntb_link_event(&ndev
->ntb
);
1244 if (atom_link_is_up(ndev
) || !atom_link_is_err(ndev
)) {
1245 schedule_delayed_work(&ndev
->hb_timer
, ATOM_LINK_HB_TIMEOUT
);
1249 /* Link is down with error: recover the link! */
1251 mmio
= ndev
->self_mmio
;
1253 /* Driver resets the NTB ModPhy lanes - magic! */
1254 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
);
1259 /* Driver waits 100ms to allow the NTB ModPhy to settle */
1262 /* Clear AER Errors, write to clear */
1263 status32
= ioread32(mmio
+ ATOM_ERRCORSTS_OFFSET
);
1264 dev_dbg(ndev_dev(ndev
), "ERRCORSTS = %x\n", status32
);
1265 status32
&= PCI_ERR_COR_REP_ROLL
;
1266 iowrite32(status32
, mmio
+ ATOM_ERRCORSTS_OFFSET
);
1268 /* Clear unexpected electrical idle event in LTSSM, write to clear */
1269 status32
= ioread32(mmio
+ ATOM_LTSSMERRSTS0_OFFSET
);
1270 dev_dbg(ndev_dev(ndev
), "LTSSMERRSTS0 = %x\n", status32
);
1271 status32
|= ATOM_LTSSMERRSTS0_UNEXPECTEDEI
;
1272 iowrite32(status32
, mmio
+ ATOM_LTSSMERRSTS0_OFFSET
);
1274 /* Clear DeSkew Buffer error, write to clear */
1275 status32
= ioread32(mmio
+ ATOM_DESKEWSTS_OFFSET
);
1276 dev_dbg(ndev_dev(ndev
), "DESKEWSTS = %x\n", status32
);
1277 status32
|= ATOM_DESKEWSTS_DBERR
;
1278 iowrite32(status32
, mmio
+ ATOM_DESKEWSTS_OFFSET
);
1280 status32
= ioread32(mmio
+ ATOM_IBSTERRRCRVSTS0_OFFSET
);
1281 dev_dbg(ndev_dev(ndev
), "IBSTERRRCRVSTS0 = %x\n", status32
);
1282 status32
&= ATOM_IBIST_ERR_OFLOW
;
1283 iowrite32(status32
, mmio
+ ATOM_IBSTERRRCRVSTS0_OFFSET
);
1285 /* Releases the NTB state machine to allow the link to retrain */
1286 status32
= ioread32(mmio
+ ATOM_LTSSMSTATEJMP_OFFSET
);
1287 dev_dbg(ndev_dev(ndev
), "LTSSMSTATEJMP = %x\n", status32
);
1288 status32
&= ~ATOM_LTSSMSTATEJMP_FORCEDETECT
;
1289 iowrite32(status32
, mmio
+ ATOM_LTSSMSTATEJMP_OFFSET
);
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.
1296 schedule_delayed_work(&ndev
->hb_timer
, ATOM_LINK_RECOVERY_TIME
1297 + prandom_u32() % ATOM_LINK_RECOVERY_TIME
);
1300 static int atom_init_isr(struct intel_ntb_dev
*ndev
)
1304 rc
= ndev_init_isr(ndev
, 1, ATOM_DB_MSIX_VECTOR_COUNT
,
1305 ATOM_DB_MSIX_VECTOR_SHIFT
, ATOM_DB_TOTAL_SHIFT
);
1309 /* ATOM doesn't have link status interrupt, poll on that platform */
1310 ndev
->last_ts
= jiffies
;
1311 INIT_DELAYED_WORK(&ndev
->hb_timer
, atom_link_hb
);
1312 schedule_delayed_work(&ndev
->hb_timer
, ATOM_LINK_HB_TIMEOUT
);
1317 static void atom_deinit_isr(struct intel_ntb_dev
*ndev
)
1319 cancel_delayed_work_sync(&ndev
->hb_timer
);
1320 ndev_deinit_isr(ndev
);
1323 static int atom_init_ntb(struct intel_ntb_dev
*ndev
)
1325 ndev
->mw_count
= ATOM_MW_COUNT
;
1326 ndev
->spad_count
= ATOM_SPAD_COUNT
;
1327 ndev
->db_count
= ATOM_DB_COUNT
;
1329 switch (ndev
->ntb
.topo
) {
1330 case NTB_TOPO_B2B_USD
:
1331 case NTB_TOPO_B2B_DSD
:
1332 ndev
->self_reg
= &atom_pri_reg
;
1333 ndev
->peer_reg
= &atom_b2b_reg
;
1334 ndev
->xlat_reg
= &atom_sec_xlat
;
1336 /* Enable Bus Master and Memory Space on the secondary side */
1337 iowrite16(PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
,
1338 ndev
->self_mmio
+ ATOM_SPCICMD_OFFSET
);
1346 ndev
->db_valid_mask
= BIT_ULL(ndev
->db_count
) - 1;
1351 static int atom_init_dev(struct intel_ntb_dev
*ndev
)
1356 rc
= pci_read_config_dword(ndev
->ntb
.pdev
, ATOM_PPD_OFFSET
, &ppd
);
1360 ndev
->ntb
.topo
= atom_ppd_topo(ndev
, ppd
);
1361 if (ndev
->ntb
.topo
== NTB_TOPO_NONE
)
1364 rc
= atom_init_ntb(ndev
);
1368 rc
= atom_init_isr(ndev
);
1372 if (ndev
->ntb
.topo
!= NTB_TOPO_SEC
) {
1373 /* Initiate PCI-E link training */
1374 rc
= pci_write_config_dword(ndev
->ntb
.pdev
, ATOM_PPD_OFFSET
,
1375 ppd
| ATOM_PPD_INIT_LINK
);
1383 static void atom_deinit_dev(struct intel_ntb_dev
*ndev
)
1385 atom_deinit_isr(ndev
);
1390 static u64
xeon_db_ioread(void __iomem
*mmio
)
1392 return (u64
)ioread16(mmio
);
1395 static void xeon_db_iowrite(u64 bits
, void __iomem
*mmio
)
1397 iowrite16((u16
)bits
, mmio
);
1400 static int xeon_poll_link(struct intel_ntb_dev
*ndev
)
1405 ndev
->reg
->db_iowrite(ndev
->db_link_mask
,
1407 ndev
->self_reg
->db_bell
);
1409 rc
= pci_read_config_word(ndev
->ntb
.pdev
,
1410 XEON_LINK_STATUS_OFFSET
, ®_val
);
1414 if (reg_val
== ndev
->lnk_sta
)
1417 ndev
->lnk_sta
= reg_val
;
1422 static int xeon_link_is_up(struct intel_ntb_dev
*ndev
)
1424 if (ndev
->ntb
.topo
== NTB_TOPO_SEC
)
1427 return NTB_LNK_STA_ACTIVE(ndev
->lnk_sta
);
1430 static inline enum ntb_topo
xeon_ppd_topo(struct intel_ntb_dev
*ndev
, u8 ppd
)
1432 switch (ppd
& XEON_PPD_TOPO_MASK
) {
1433 case XEON_PPD_TOPO_B2B_USD
:
1434 return NTB_TOPO_B2B_USD
;
1436 case XEON_PPD_TOPO_B2B_DSD
:
1437 return NTB_TOPO_B2B_DSD
;
1439 case XEON_PPD_TOPO_PRI_USD
:
1440 case XEON_PPD_TOPO_PRI_DSD
: /* accept bogus PRI_DSD */
1441 return NTB_TOPO_PRI
;
1443 case XEON_PPD_TOPO_SEC_USD
:
1444 case XEON_PPD_TOPO_SEC_DSD
: /* accept bogus SEC_DSD */
1445 return NTB_TOPO_SEC
;
1448 return NTB_TOPO_NONE
;
1451 static inline int xeon_ppd_bar4_split(struct intel_ntb_dev
*ndev
, u8 ppd
)
1453 if (ppd
& XEON_PPD_SPLIT_BAR_MASK
) {
1454 dev_dbg(ndev_dev(ndev
), "PPD %d split bar\n", ppd
);
1460 static int xeon_init_isr(struct intel_ntb_dev
*ndev
)
1462 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
);
1468 static void xeon_deinit_isr(struct intel_ntb_dev
*ndev
)
1470 ndev_deinit_isr(ndev
);
1473 static 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
)
1477 struct pci_dev
*pdev
;
1479 resource_size_t bar_size
;
1480 phys_addr_t bar_addr
;
1484 pdev
= ndev_pdev(ndev
);
1485 mmio
= ndev
->self_mmio
;
1487 if (ndev
->b2b_idx
>= ndev
->mw_count
) {
1488 dev_dbg(ndev_dev(ndev
), "not using b2b mw\n");
1492 b2b_bar
= ndev_mw_to_bar(ndev
, ndev
->b2b_idx
);
1496 dev_dbg(ndev_dev(ndev
), "using b2b mw bar %d\n", b2b_bar
);
1498 bar_size
= pci_resource_len(ndev
->ntb
.pdev
, b2b_bar
);
1500 dev_dbg(ndev_dev(ndev
), "b2b bar size %#llx\n", bar_size
);
1502 if (b2b_mw_share
&& XEON_B2B_MIN_SIZE
<= bar_size
>> 1) {
1503 dev_dbg(ndev_dev(ndev
),
1504 "b2b using first half of bar\n");
1505 ndev
->b2b_off
= bar_size
>> 1;
1506 } else if (XEON_B2B_MIN_SIZE
<= bar_size
) {
1507 dev_dbg(ndev_dev(ndev
),
1508 "b2b using whole bar\n");
1512 dev_dbg(ndev_dev(ndev
),
1513 "b2b bar size is too small\n");
1518 /* Reset the secondary bar sizes to match the primary bar sizes,
1519 * except disable or halve the size of the b2b secondary bar.
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).
1524 pci_read_config_byte(pdev
, XEON_PBAR23SZ_OFFSET
, &bar_sz
);
1525 dev_dbg(ndev_dev(ndev
), "PBAR23SZ %#x\n", bar_sz
);
1532 pci_write_config_byte(pdev
, XEON_SBAR23SZ_OFFSET
, bar_sz
);
1533 pci_read_config_byte(pdev
, XEON_SBAR23SZ_OFFSET
, &bar_sz
);
1534 dev_dbg(ndev_dev(ndev
), "SBAR23SZ %#x\n", bar_sz
);
1536 if (!ndev
->bar4_split
) {
1537 pci_read_config_byte(pdev
, XEON_PBAR45SZ_OFFSET
, &bar_sz
);
1538 dev_dbg(ndev_dev(ndev
), "PBAR45SZ %#x\n", bar_sz
);
1545 pci_write_config_byte(pdev
, XEON_SBAR45SZ_OFFSET
, bar_sz
);
1546 pci_read_config_byte(pdev
, XEON_SBAR45SZ_OFFSET
, &bar_sz
);
1547 dev_dbg(ndev_dev(ndev
), "SBAR45SZ %#x\n", bar_sz
);
1549 pci_read_config_byte(pdev
, XEON_PBAR4SZ_OFFSET
, &bar_sz
);
1550 dev_dbg(ndev_dev(ndev
), "PBAR4SZ %#x\n", bar_sz
);
1557 pci_write_config_byte(pdev
, XEON_SBAR4SZ_OFFSET
, bar_sz
);
1558 pci_read_config_byte(pdev
, XEON_SBAR4SZ_OFFSET
, &bar_sz
);
1559 dev_dbg(ndev_dev(ndev
), "SBAR4SZ %#x\n", bar_sz
);
1561 pci_read_config_byte(pdev
, XEON_PBAR5SZ_OFFSET
, &bar_sz
);
1562 dev_dbg(ndev_dev(ndev
), "PBAR5SZ %#x\n", bar_sz
);
1569 pci_write_config_byte(pdev
, XEON_SBAR5SZ_OFFSET
, bar_sz
);
1570 pci_read_config_byte(pdev
, XEON_SBAR5SZ_OFFSET
, &bar_sz
);
1571 dev_dbg(ndev_dev(ndev
), "SBAR5SZ %#x\n", bar_sz
);
1574 /* SBAR01 hit by first part of the b2b bar */
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
;
1588 dev_dbg(ndev_dev(ndev
), "SBAR01 %#018llx\n", bar_addr
);
1589 iowrite64(bar_addr
, mmio
+ XEON_SBAR0BASE_OFFSET
);
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.
1596 bar_addr
= addr
->bar2_addr64
+ (b2b_bar
== 2 ? ndev
->b2b_off
: 0);
1597 iowrite64(bar_addr
, mmio
+ XEON_SBAR23BASE_OFFSET
);
1598 bar_addr
= ioread64(mmio
+ XEON_SBAR23BASE_OFFSET
);
1599 dev_dbg(ndev_dev(ndev
), "SBAR23 %#018llx\n", bar_addr
);
1601 if (!ndev
->bar4_split
) {
1602 bar_addr
= addr
->bar4_addr64
+
1603 (b2b_bar
== 4 ? ndev
->b2b_off
: 0);
1604 iowrite64(bar_addr
, mmio
+ XEON_SBAR45BASE_OFFSET
);
1605 bar_addr
= ioread64(mmio
+ XEON_SBAR45BASE_OFFSET
);
1606 dev_dbg(ndev_dev(ndev
), "SBAR45 %#018llx\n", bar_addr
);
1608 bar_addr
= addr
->bar4_addr32
+
1609 (b2b_bar
== 4 ? ndev
->b2b_off
: 0);
1610 iowrite32(bar_addr
, mmio
+ XEON_SBAR4BASE_OFFSET
);
1611 bar_addr
= ioread32(mmio
+ XEON_SBAR4BASE_OFFSET
);
1612 dev_dbg(ndev_dev(ndev
), "SBAR4 %#010llx\n", bar_addr
);
1614 bar_addr
= addr
->bar5_addr32
+
1615 (b2b_bar
== 5 ? ndev
->b2b_off
: 0);
1616 iowrite32(bar_addr
, mmio
+ XEON_SBAR5BASE_OFFSET
);
1617 bar_addr
= ioread32(mmio
+ XEON_SBAR5BASE_OFFSET
);
1618 dev_dbg(ndev_dev(ndev
), "SBAR5 %#010llx\n", bar_addr
);
1621 /* setup incoming bar limits == base addrs (zero length windows) */
1623 bar_addr
= addr
->bar2_addr64
+ (b2b_bar
== 2 ? ndev
->b2b_off
: 0);
1624 iowrite64(bar_addr
, mmio
+ XEON_SBAR23LMT_OFFSET
);
1625 bar_addr
= ioread64(mmio
+ XEON_SBAR23LMT_OFFSET
);
1626 dev_dbg(ndev_dev(ndev
), "SBAR23LMT %#018llx\n", bar_addr
);
1628 if (!ndev
->bar4_split
) {
1629 bar_addr
= addr
->bar4_addr64
+
1630 (b2b_bar
== 4 ? ndev
->b2b_off
: 0);
1631 iowrite64(bar_addr
, mmio
+ XEON_SBAR45LMT_OFFSET
);
1632 bar_addr
= ioread64(mmio
+ XEON_SBAR45LMT_OFFSET
);
1633 dev_dbg(ndev_dev(ndev
), "SBAR45LMT %#018llx\n", bar_addr
);
1635 bar_addr
= addr
->bar4_addr32
+
1636 (b2b_bar
== 4 ? ndev
->b2b_off
: 0);
1637 iowrite32(bar_addr
, mmio
+ XEON_SBAR4LMT_OFFSET
);
1638 bar_addr
= ioread32(mmio
+ XEON_SBAR4LMT_OFFSET
);
1639 dev_dbg(ndev_dev(ndev
), "SBAR4LMT %#010llx\n", bar_addr
);
1641 bar_addr
= addr
->bar5_addr32
+
1642 (b2b_bar
== 5 ? ndev
->b2b_off
: 0);
1643 iowrite32(bar_addr
, mmio
+ XEON_SBAR5LMT_OFFSET
);
1644 bar_addr
= ioread32(mmio
+ XEON_SBAR5LMT_OFFSET
);
1645 dev_dbg(ndev_dev(ndev
), "SBAR5LMT %#05llx\n", bar_addr
);
1648 /* zero incoming translation addrs */
1649 iowrite64(0, mmio
+ XEON_SBAR23XLAT_OFFSET
);
1651 if (!ndev
->bar4_split
) {
1652 iowrite64(0, mmio
+ XEON_SBAR45XLAT_OFFSET
);
1654 iowrite32(0, mmio
+ XEON_SBAR4XLAT_OFFSET
);
1655 iowrite32(0, mmio
+ XEON_SBAR5XLAT_OFFSET
);
1658 /* zero outgoing translation limits (whole bar size windows) */
1659 iowrite64(0, mmio
+ XEON_PBAR23LMT_OFFSET
);
1660 if (!ndev
->bar4_split
) {
1661 iowrite64(0, mmio
+ XEON_PBAR45LMT_OFFSET
);
1663 iowrite32(0, mmio
+ XEON_PBAR4LMT_OFFSET
);
1664 iowrite32(0, mmio
+ XEON_PBAR5LMT_OFFSET
);
1667 /* set outgoing translation offsets */
1668 bar_addr
= peer_addr
->bar2_addr64
;
1669 iowrite64(bar_addr
, mmio
+ XEON_PBAR23XLAT_OFFSET
);
1670 bar_addr
= ioread64(mmio
+ XEON_PBAR23XLAT_OFFSET
);
1671 dev_dbg(ndev_dev(ndev
), "PBAR23XLAT %#018llx\n", bar_addr
);
1673 if (!ndev
->bar4_split
) {
1674 bar_addr
= peer_addr
->bar4_addr64
;
1675 iowrite64(bar_addr
, mmio
+ XEON_PBAR45XLAT_OFFSET
);
1676 bar_addr
= ioread64(mmio
+ XEON_PBAR45XLAT_OFFSET
);
1677 dev_dbg(ndev_dev(ndev
), "PBAR45XLAT %#018llx\n", bar_addr
);
1679 bar_addr
= peer_addr
->bar4_addr32
;
1680 iowrite32(bar_addr
, mmio
+ XEON_PBAR4XLAT_OFFSET
);
1681 bar_addr
= ioread32(mmio
+ XEON_PBAR4XLAT_OFFSET
);
1682 dev_dbg(ndev_dev(ndev
), "PBAR4XLAT %#010llx\n", bar_addr
);
1684 bar_addr
= peer_addr
->bar5_addr32
;
1685 iowrite32(bar_addr
, mmio
+ XEON_PBAR5XLAT_OFFSET
);
1686 bar_addr
= ioread32(mmio
+ XEON_PBAR5XLAT_OFFSET
);
1687 dev_dbg(ndev_dev(ndev
), "PBAR5XLAT %#010llx\n", bar_addr
);
1690 /* set the translation offset for b2b registers */
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
;
1704 /* B2B_XLAT_OFFSET is 64bit, but can only take 32bit writes */
1705 dev_dbg(ndev_dev(ndev
), "B2BXLAT %#018llx\n", bar_addr
);
1706 iowrite32(bar_addr
, mmio
+ XEON_B2B_XLAT_OFFSETL
);
1707 iowrite32(bar_addr
>> 32, mmio
+ XEON_B2B_XLAT_OFFSETU
);
1710 /* map peer ntb mmio config space registers */
1711 ndev
->peer_mmio
= pci_iomap(pdev
, b2b_bar
,
1713 if (!ndev
->peer_mmio
)
1720 static int xeon_init_ntb(struct intel_ntb_dev
*ndev
)
1725 if (ndev
->bar4_split
)
1726 ndev
->mw_count
= HSX_SPLIT_BAR_MW_COUNT
;
1728 ndev
->mw_count
= XEON_MW_COUNT
;
1730 ndev
->spad_count
= XEON_SPAD_COUNT
;
1731 ndev
->db_count
= XEON_DB_COUNT
;
1732 ndev
->db_link_mask
= XEON_DB_LINK_BIT
;
1734 switch (ndev
->ntb
.topo
) {
1736 if (ndev
->hwerr_flags
& NTB_HWERR_SDOORBELL_LOCKUP
) {
1737 dev_err(ndev_dev(ndev
), "NTB Primary config disabled\n");
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
);
1746 /* use half the spads for the peer */
1747 ndev
->spad_count
>>= 1;
1748 ndev
->self_reg
= &xeon_pri_reg
;
1749 ndev
->peer_reg
= &xeon_sec_reg
;
1750 ndev
->xlat_reg
= &xeon_sec_xlat
;
1754 if (ndev
->hwerr_flags
& NTB_HWERR_SDOORBELL_LOCKUP
) {
1755 dev_err(ndev_dev(ndev
), "NTB Secondary config disabled\n");
1758 /* use half the spads for the peer */
1759 ndev
->spad_count
>>= 1;
1760 ndev
->self_reg
= &xeon_sec_reg
;
1761 ndev
->peer_reg
= &xeon_pri_reg
;
1762 ndev
->xlat_reg
= &xeon_pri_xlat
;
1765 case NTB_TOPO_B2B_USD
:
1766 case NTB_TOPO_B2B_DSD
:
1767 ndev
->self_reg
= &xeon_pri_reg
;
1768 ndev
->peer_reg
= &xeon_b2b_reg
;
1769 ndev
->xlat_reg
= &xeon_sec_xlat
;
1771 if (ndev
->hwerr_flags
& NTB_HWERR_SDOORBELL_LOCKUP
) {
1772 ndev
->peer_reg
= &xeon_pri_reg
;
1775 ndev
->b2b_idx
= b2b_mw_idx
+ ndev
->mw_count
;
1777 ndev
->b2b_idx
= b2b_mw_idx
;
1779 dev_dbg(ndev_dev(ndev
),
1780 "setting up b2b mw idx %d means %d\n",
1781 b2b_mw_idx
, ndev
->b2b_idx
);
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;
1788 if (ndev
->ntb
.topo
== NTB_TOPO_B2B_USD
) {
1789 rc
= xeon_setup_b2b_mw(ndev
,
1791 &xeon_b2b_usd_addr
);
1793 rc
= xeon_setup_b2b_mw(ndev
,
1795 &xeon_b2b_dsd_addr
);
1800 /* Enable Bus Master and Memory Space on the secondary side */
1801 iowrite16(PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
,
1802 ndev
->self_mmio
+ XEON_SPCICMD_OFFSET
);
1810 ndev
->db_valid_mask
= BIT_ULL(ndev
->db_count
) - 1;
1812 ndev
->reg
->db_iowrite(ndev
->db_valid_mask
,
1814 ndev
->self_reg
->db_mask
);
1819 static int xeon_init_dev(struct intel_ntb_dev
*ndev
)
1821 struct pci_dev
*pdev
;
1825 pdev
= ndev_pdev(ndev
);
1827 switch (pdev
->device
) {
1828 /* 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
1834 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
;
1850 switch (pdev
->device
) {
1851 /* There is a hardware errata related to accessing any register in
1852 * SB01BASE in the presence of bidirectional traffic crossing the NTB.
1854 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
;
1864 switch (pdev
->device
) {
1865 /* 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.
1869 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
;
1885 ndev
->reg
= &xeon_reg
;
1887 rc
= pci_read_config_byte(pdev
, XEON_PPD_OFFSET
, &ppd
);
1891 ndev
->ntb
.topo
= xeon_ppd_topo(ndev
, ppd
);
1892 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
)
1897 if (ndev
->ntb
.topo
!= NTB_TOPO_SEC
) {
1898 ndev
->bar4_split
= xeon_ppd_bar4_split(ndev
, ppd
);
1899 dev_dbg(ndev_dev(ndev
), "ppd %#x bar4_split %d\n",
1900 ppd
, ndev
->bar4_split
);
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.
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
);
1913 rc
= xeon_init_ntb(ndev
);
1917 return xeon_init_isr(ndev
);
1920 static void xeon_deinit_dev(struct intel_ntb_dev
*ndev
)
1922 xeon_deinit_isr(ndev
);
1925 static int intel_ntb_init_pci(struct intel_ntb_dev
*ndev
, struct pci_dev
*pdev
)
1929 pci_set_drvdata(pdev
, ndev
);
1931 rc
= pci_enable_device(pdev
);
1933 goto err_pci_enable
;
1935 rc
= pci_request_regions(pdev
, NTB_NAME
);
1937 goto err_pci_regions
;
1939 pci_set_master(pdev
);
1941 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
1943 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1946 dev_warn(ndev_dev(ndev
), "Cannot DMA highmem\n");
1949 rc
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64));
1951 rc
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
1954 dev_warn(ndev_dev(ndev
), "Cannot DMA consistent highmem\n");
1957 ndev
->self_mmio
= pci_iomap(pdev
, 0, 0);
1958 if (!ndev
->self_mmio
) {
1962 ndev
->peer_mmio
= ndev
->self_mmio
;
1968 pci_clear_master(pdev
);
1969 pci_release_regions(pdev
);
1971 pci_disable_device(pdev
);
1973 pci_set_drvdata(pdev
, NULL
);
1977 static void intel_ntb_deinit_pci(struct intel_ntb_dev
*ndev
)
1979 struct pci_dev
*pdev
= ndev_pdev(ndev
);
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
);
1985 pci_clear_master(pdev
);
1986 pci_release_regions(pdev
);
1987 pci_disable_device(pdev
);
1988 pci_set_drvdata(pdev
, NULL
);
1991 static inline void ndev_init_struct(struct intel_ntb_dev
*ndev
,
1992 struct pci_dev
*pdev
)
1994 ndev
->ntb
.pdev
= pdev
;
1995 ndev
->ntb
.topo
= NTB_TOPO_NONE
;
1996 ndev
->ntb
.ops
= &intel_ntb_ops
;
1999 ndev
->b2b_idx
= INT_MAX
;
2001 ndev
->bar4_split
= 0;
2004 ndev
->spad_count
= 0;
2006 ndev
->db_vec_count
= 0;
2007 ndev
->db_vec_shift
= 0;
2012 ndev
->db_valid_mask
= 0;
2013 ndev
->db_link_mask
= 0;
2016 spin_lock_init(&ndev
->db_mask_lock
);
2019 static int intel_ntb_pci_probe(struct pci_dev
*pdev
,
2020 const struct pci_device_id
*id
)
2022 struct intel_ntb_dev
*ndev
;
2025 node
= dev_to_node(&pdev
->dev
);
2027 if (pdev_is_atom(pdev
)) {
2028 ndev
= kzalloc_node(sizeof(*ndev
), GFP_KERNEL
, node
);
2034 ndev_init_struct(ndev
, pdev
);
2036 rc
= intel_ntb_init_pci(ndev
, pdev
);
2040 rc
= atom_init_dev(ndev
);
2044 } else if (pdev_is_xeon(pdev
)) {
2045 ndev
= kzalloc_node(sizeof(*ndev
), GFP_KERNEL
, node
);
2051 ndev_init_struct(ndev
, pdev
);
2053 rc
= intel_ntb_init_pci(ndev
, pdev
);
2057 rc
= xeon_init_dev(ndev
);
2066 ndev_reset_unsafe_flags(ndev
);
2068 ndev
->reg
->poll_link(ndev
);
2070 ndev_init_debugfs(ndev
);
2072 rc
= ntb_register_device(&ndev
->ntb
);
2076 dev_info(&pdev
->dev
, "NTB device registered.\n");
2081 ndev_deinit_debugfs(ndev
);
2082 if (pdev_is_atom(pdev
))
2083 atom_deinit_dev(ndev
);
2084 else if (pdev_is_xeon(pdev
))
2085 xeon_deinit_dev(ndev
);
2087 intel_ntb_deinit_pci(ndev
);
2094 static void intel_ntb_pci_remove(struct pci_dev
*pdev
)
2096 struct intel_ntb_dev
*ndev
= pci_get_drvdata(pdev
);
2098 ntb_unregister_device(&ndev
->ntb
);
2099 ndev_deinit_debugfs(ndev
);
2100 if (pdev_is_atom(pdev
))
2101 atom_deinit_dev(ndev
);
2102 else if (pdev_is_xeon(pdev
))
2103 xeon_deinit_dev(ndev
);
2104 intel_ntb_deinit_pci(ndev
);
2108 static 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
,
2113 .db_size
= sizeof(u64
),
2114 .ntb_ctl
= ATOM_NTBCNTL_OFFSET
,
2118 static 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
,
2124 static const struct intel_ntb_alt_reg atom_b2b_reg
= {
2125 .db_bell
= ATOM_B2B_DOORBELL_OFFSET
,
2126 .spad
= ATOM_B2B_SPAD_OFFSET
,
2129 static 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
,
2135 static 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
,
2140 .db_size
= sizeof(u32
),
2141 .ntb_ctl
= XEON_NTBCNTL_OFFSET
,
2142 .mw_bar
= {2, 4, 5},
2145 static 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
,
2151 static const struct intel_ntb_alt_reg xeon_sec_reg
= {
2152 .db_bell
= XEON_SDOORBELL_OFFSET
,
2153 .db_mask
= XEON_SDBMSK_OFFSET
,
2154 /* second half of the scratchpads */
2155 .spad
= XEON_SPAD_OFFSET
+ (XEON_SPAD_COUNT
<< 1),
2158 static const struct intel_ntb_alt_reg xeon_b2b_reg
= {
2159 .db_bell
= XEON_B2B_DOORBELL_OFFSET
,
2160 .spad
= XEON_B2B_SPAD_OFFSET
,
2163 static const struct intel_ntb_xlat_reg xeon_pri_xlat
= {
2164 /* Note: no primary .bar0_base visible to the secondary side.
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.
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.
2174 .bar2_limit
= XEON_PBAR23LMT_OFFSET
,
2175 .bar2_xlat
= XEON_PBAR23XLAT_OFFSET
,
2178 static 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
,
2184 static 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
,
2191 static 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
,
2198 /* operations for primary side of local ntb */
2199 static 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
,
2225 static const struct file_operations intel_ntb_debugfs_info
= {
2226 .owner
= THIS_MODULE
,
2227 .open
= simple_open
,
2228 .read
= ndev_debugfs_read
,
2231 static const struct pci_device_id intel_ntb_pci_tbl
[] = {
2232 {PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_NTB_B2B_BWD
)},
2233 {PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_NTB_B2B_JSF
)},
2234 {PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_NTB_B2B_SNB
)},
2235 {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
)},
2247 MODULE_DEVICE_TABLE(pci
, intel_ntb_pci_tbl
);
2249 static 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
,
2256 static int __init
intel_ntb_pci_driver_init(void)
2258 pr_info("%s %s\n", NTB_DESC
, NTB_VER
);
2260 if (debugfs_initialized())
2261 debugfs_dir
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
2263 return pci_register_driver(&intel_ntb_pci_driver
);
2265 module_init(intel_ntb_pci_driver_init
);
2267 static void __exit
intel_ntb_pci_driver_exit(void)
2269 pci_unregister_driver(&intel_ntb_pci_driver
);
2271 debugfs_remove_recursive(debugfs_dir
);
2273 module_exit(intel_ntb_pci_driver_exit
);