blob: 3a3038ca83e6d4451c910bcbc7cdf48a1fd00213 [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.
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_CLASSIC_JSF 0x3726
51#define PCI_DEVICE_ID_INTEL_NTB_RP_JSF 0x3727
52#define PCI_DEVICE_ID_INTEL_NTB_RP_SNB 0x3C08
53#define PCI_DEVICE_ID_INTEL_NTB_B2B_SNB 0x3C0D
54#define PCI_DEVICE_ID_INTEL_NTB_CLASSIC_SNB 0x3C0E
55#define PCI_DEVICE_ID_INTEL_NTB_2ND_SNB 0x3C0F
56#define PCI_DEVICE_ID_INTEL_NTB_B2B_BWD 0x0C4E
57
58#define msix_table_size(control) ((control & PCI_MSIX_FLAGS_QSIZE)+1)
59
60#define NTB_BAR_MMIO 0
61#define NTB_BAR_23 2
62#define NTB_BAR_45 4
63#define NTB_BAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
64 (1 << NTB_BAR_45))
65
66#define NTB_LINK_DOWN 0
67#define NTB_LINK_UP 1
68
69#define NTB_HB_TIMEOUT msecs_to_jiffies(1000)
70
71#define NTB_NUM_MW 2
72
73enum ntb_hw_event {
74 NTB_EVENT_SW_EVENT0 = 0,
75 NTB_EVENT_SW_EVENT1,
76 NTB_EVENT_SW_EVENT2,
77 NTB_EVENT_HW_ERROR,
78 NTB_EVENT_HW_LINK_UP,
79 NTB_EVENT_HW_LINK_DOWN,
80};
81
82struct ntb_mw {
83 dma_addr_t phys_addr;
84 void __iomem *vbase;
85 resource_size_t bar_sz;
86};
87
88struct ntb_db_cb {
89 void (*callback) (void *data, int db_num);
90 unsigned int db_num;
91 void *data;
92 struct ntb_device *ndev;
93};
94
95struct ntb_device {
96 struct pci_dev *pdev;
97 struct msix_entry *msix_entries;
98 void __iomem *reg_base;
99 struct ntb_mw mw[NTB_NUM_MW];
100 struct {
101 unsigned int max_spads;
102 unsigned int max_db_bits;
103 unsigned int msix_cnt;
104 } limits;
105 struct {
106 void __iomem *pdb;
107 void __iomem *pdb_mask;
108 void __iomem *sdb;
109 void __iomem *sbar2_xlat;
110 void __iomem *sbar4_xlat;
111 void __iomem *spad_write;
112 void __iomem *spad_read;
113 void __iomem *lnk_cntl;
114 void __iomem *lnk_stat;
115 void __iomem *spci_cmd;
116 } reg_ofs;
117 struct ntb_transport *ntb_transport;
118 void (*event_cb)(void *handle, enum ntb_hw_event event);
119
120 struct ntb_db_cb *db_cb;
121 unsigned char hw_type;
122 unsigned char conn_type;
123 unsigned char dev_type;
124 unsigned char num_msix;
125 unsigned char bits_per_vector;
126 unsigned char max_cbs;
127 unsigned char link_status;
128 struct delayed_work hb_timer;
129 unsigned long last_ts;
130};
131
132/**
133 * ntb_hw_link_status() - return the hardware link status
134 * @ndev: pointer to ntb_device instance
135 *
136 * Returns true if the hardware is connected to the remote system
137 *
138 * RETURNS: true or false based on the hardware link state
139 */
140static inline bool ntb_hw_link_status(struct ntb_device *ndev)
141{
142 return ndev->link_status == NTB_LINK_UP;
143}
144
145/**
146 * ntb_query_pdev() - return the pci_dev pointer
147 * @ndev: pointer to ntb_device instance
148 *
149 * Given the ntb pointer return the pci_dev pointerfor the NTB hardware device
150 *
151 * RETURNS: a pointer to the ntb pci_dev
152 */
153static inline struct pci_dev *ntb_query_pdev(struct ntb_device *ndev)
154{
155 return ndev->pdev;
156}
157
158struct ntb_device *ntb_register_transport(struct pci_dev *pdev,
159 void *transport);
160void ntb_unregister_transport(struct ntb_device *ndev);
161void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr);
162int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx,
163 void *data, void (*db_cb_func) (void *data,
164 int db_num));
165void ntb_unregister_db_callback(struct ntb_device *ndev, unsigned int idx);
166int ntb_register_event_callback(struct ntb_device *ndev,
167 void (*event_cb_func) (void *handle,
Jon Mason74465642013-01-21 15:28:52 -0700168 enum ntb_hw_event event));
Jon Masonfce8a7b2012-11-16 19:27:12 -0700169void ntb_unregister_event_callback(struct ntb_device *ndev);
170int ntb_get_max_spads(struct ntb_device *ndev);
171int ntb_write_local_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
172int ntb_read_local_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
173int ntb_write_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
174int ntb_read_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
Jon Mason74465642013-01-21 15:28:52 -0700175void __iomem *ntb_get_mw_vbase(struct ntb_device *ndev, unsigned int mw);
Jon Masonfce8a7b2012-11-16 19:27:12 -0700176resource_size_t ntb_get_mw_size(struct ntb_device *ndev, unsigned int mw);
177void ntb_ring_sdb(struct ntb_device *ndev, unsigned int idx);
178void *ntb_find_transport(struct pci_dev *pdev);
179
180int ntb_transport_init(struct pci_dev *pdev);
181void ntb_transport_free(void *transport);