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