]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/misc/mic/scif/scif_main.h
Merge remote-tracking branch 'staging/staging-next'
[karo-tx-linux.git] / drivers / misc / mic / scif / scif_main.h
1 /*
2  * Intel MIC Platform Software Stack (MPSS)
3  *
4  * Copyright(c) 2014 Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 2, as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * Intel SCIF driver.
16  *
17  */
18 #ifndef SCIF_MAIN_H
19 #define SCIF_MAIN_H
20
21 #include <linux/sched.h>
22 #include <linux/pci.h>
23 #include <linux/miscdevice.h>
24 #include <linux/dmaengine.h>
25 #include <linux/file.h>
26 #include <linux/scif.h>
27
28 #include "../common/mic_dev.h"
29
30 #define SCIF_MGMT_NODE 0
31 #define SCIF_DEFAULT_WATCHDOG_TO 30
32 #define SCIF_NODE_ACCEPT_TIMEOUT (3 * HZ)
33 #define SCIF_NODE_ALIVE_TIMEOUT (SCIF_DEFAULT_WATCHDOG_TO * HZ)
34
35 /*
36  * Generic state used for certain node QP message exchanges
37  * like Unregister, Alloc etc.
38  */
39 enum scif_msg_state {
40         OP_IDLE = 1,
41         OP_IN_PROGRESS,
42         OP_COMPLETED,
43         OP_FAILED
44 };
45
46 /*
47  * struct scif_info - Global SCIF information
48  *
49  * @nodeid: Node ID this node is to others
50  * @maxid: Max known node ID
51  * @total: Total number of SCIF nodes
52  * @nr_zombies: number of zombie endpoints
53  * @eplock: Lock to synchronize listening, zombie endpoint lists
54  * @connlock: Lock to synchronize connected and disconnected lists
55  * @nb_connect_lock: Synchronize non blocking connect operations
56  * @port_lock: Synchronize access to SCIF ports
57  * @uaccept: List of user acceptreq waiting for acceptreg
58  * @listen: List of listening end points
59  * @zombie: List of zombie end points with pending RMA's
60  * @connected: List of end points in connected state
61  * @disconnected: List of end points in disconnected state
62  * @nb_connect_list: List for non blocking connections
63  * @misc_work: miscellaneous SCIF tasks
64  * @conflock: Lock to synchronize SCIF node configuration changes
65  * @en_msg_log: Enable debug message logging
66  * @p2p_enable: Enable P2P SCIF network
67  * @mdev: The MISC device
68  * @conn_work: Work for workqueue handling all connections
69  * @exitwq: Wait queue for waiting for an EXIT node QP message response
70  * @loopb_dev: Dummy SCIF device used for loopback
71  * @loopb_wq: Workqueue used for handling loopback messages
72  * @loopb_wqname[16]: Name of loopback workqueue
73  * @loopb_work: Used for submitting work to loopb_wq
74  * @loopb_recv_q: List of messages received on the loopb_wq
75  * @card_initiated_exit: set when the card has initiated the exit
76  */
77 struct scif_info {
78         u8 nodeid;
79         u8 maxid;
80         u8 total;
81         u32 nr_zombies;
82         spinlock_t eplock;
83         struct mutex connlock;
84         spinlock_t nb_connect_lock;
85         spinlock_t port_lock;
86         struct list_head uaccept;
87         struct list_head listen;
88         struct list_head zombie;
89         struct list_head connected;
90         struct list_head disconnected;
91         struct list_head nb_connect_list;
92         struct work_struct misc_work;
93         struct mutex conflock;
94         u8 en_msg_log;
95         u8 p2p_enable;
96         struct miscdevice mdev;
97         struct work_struct conn_work;
98         wait_queue_head_t exitwq;
99         struct scif_dev *loopb_dev;
100         struct workqueue_struct *loopb_wq;
101         char loopb_wqname[16];
102         struct work_struct loopb_work;
103         struct list_head loopb_recv_q;
104         bool card_initiated_exit;
105 };
106
107 /*
108  * struct scif_p2p_info - SCIF mapping information used for P2P
109  *
110  * @ppi_peer_id - SCIF peer node id
111  * @ppi_sg - Scatter list for bar information (One for mmio and one for aper)
112  * @sg_nentries - Number of entries in the scatterlist
113  * @ppi_da: DMA address for MMIO and APER bars
114  * @ppi_len: Length of MMIO and APER bars
115  * @ppi_list: Link in list of mapping information
116  */
117 struct scif_p2p_info {
118         u8 ppi_peer_id;
119         struct scatterlist *ppi_sg[2];
120         u64 sg_nentries[2];
121         dma_addr_t ppi_da[2];
122         u64 ppi_len[2];
123 #define SCIF_PPI_MMIO 0
124 #define SCIF_PPI_APER 1
125         struct list_head ppi_list;
126 };
127
128 /*
129  * struct scif_dev - SCIF remote device specific fields
130  *
131  * @node: Node id
132  * @p2p: List of P2P mapping information
133  * @qpairs: The node queue pair for exchanging control messages
134  * @intr_wq: Workqueue for handling Node QP messages
135  * @intr_wqname: Name of node QP workqueue for handling interrupts
136  * @intr_bh: Used for submitting work to intr_wq
137  * @lock: Lock used for synchronizing access to the scif device
138  * @sdev: SCIF hardware device on the SCIF hardware bus
139  * @db: doorbell the peer will trigger to generate an interrupt on self
140  * @rdb: Doorbell to trigger on the peer to generate an interrupt on the peer
141  * @cookie: Cookie received while registering the interrupt handler
142  * init_msg_work: work scheduled for SCIF_INIT message processing
143  * @p2p_dwork: Delayed work to enable polling for P2P state
144  * @qp_dwork: Delayed work for enabling polling for remote QP information
145  * @p2p_retry: Number of times to retry polling of P2P state
146  * @base_addr: P2P aperture bar base address
147  * @mic_mw mmio: The peer MMIO information used for P2P
148  * @spdev: SCIF peer device on the SCIF peer bus
149  * @node_remove_ack_pending: True if a node_remove_ack is pending
150  * @exit_ack_pending: true if an exit_ack is pending
151  * @disconn_wq: Used while waiting for a node remove response
152  * @disconn_rescnt: Keeps track of number of node remove requests sent
153  * @exit: Status of exit message
154  * @qp_dma_addr: Queue pair DMA address passed to the peer
155 */
156 struct scif_dev {
157         u8 node;
158         struct list_head p2p;
159         struct scif_qp *qpairs;
160         struct workqueue_struct *intr_wq;
161         char intr_wqname[16];
162         struct work_struct intr_bh;
163         struct mutex lock;
164         struct scif_hw_dev *sdev;
165         int db;
166         int rdb;
167         struct mic_irq *cookie;
168         struct work_struct init_msg_work;
169         struct delayed_work p2p_dwork;
170         struct delayed_work qp_dwork;
171         int p2p_retry;
172         dma_addr_t base_addr;
173         struct mic_mw mmio;
174         struct scif_peer_dev __rcu *spdev;
175         bool node_remove_ack_pending;
176         bool exit_ack_pending;
177         wait_queue_head_t disconn_wq;
178         atomic_t disconn_rescnt;
179         enum scif_msg_state exit;
180         dma_addr_t qp_dma_addr;
181 };
182
183 extern struct scif_info scif_info;
184 extern struct idr scif_ports;
185 extern struct scif_dev *scif_dev;
186 extern const struct file_operations scif_fops;
187
188 /* Size of the RB for the Node QP */
189 #define SCIF_NODE_QP_SIZE 0x10000
190
191 #include "scif_nodeqp.h"
192
193 /*
194  * scifdev_self:
195  * @dev: The remote SCIF Device
196  *
197  * Returns true if the SCIF Device passed is the self aka Loopback SCIF device.
198  */
199 static inline int scifdev_self(struct scif_dev *dev)
200 {
201         return dev->node == scif_info.nodeid;
202 }
203
204 static inline bool scif_is_mgmt_node(void)
205 {
206         return !scif_info.nodeid;
207 }
208
209 /*
210  * scifdev_is_p2p:
211  * @dev: The remote SCIF Device
212  *
213  * Returns true if the SCIF Device is a MIC Peer to Peer SCIF device.
214  */
215 static inline bool scifdev_is_p2p(struct scif_dev *dev)
216 {
217         if (scif_is_mgmt_node())
218                 return false;
219         else
220                 return dev != &scif_dev[SCIF_MGMT_NODE] &&
221                         !scifdev_self(dev);
222 }
223
224 /*
225  * scifdev_alive:
226  * @scifdev: The remote SCIF Device
227  *
228  * Returns true if the remote SCIF Device is running or sleeping for
229  * this endpoint.
230  */
231 static inline int _scifdev_alive(struct scif_dev *scifdev)
232 {
233         struct scif_peer_dev *spdev;
234
235         rcu_read_lock();
236         spdev = rcu_dereference(scifdev->spdev);
237         rcu_read_unlock();
238         return !!spdev;
239 }
240
241 #include "scif_epd.h"
242
243 void __init scif_init_debugfs(void);
244 void scif_exit_debugfs(void);
245 int scif_setup_intr_wq(struct scif_dev *scifdev);
246 void scif_destroy_intr_wq(struct scif_dev *scifdev);
247 void scif_cleanup_scifdev(struct scif_dev *dev);
248 void scif_handle_remove_node(int node);
249 void scif_disconnect_node(u32 node_id, bool mgmt_initiated);
250 void scif_free_qp(struct scif_dev *dev);
251 void scif_misc_handler(struct work_struct *work);
252 void scif_stop(struct scif_dev *scifdev);
253 irqreturn_t scif_intr_handler(int irq, void *data);
254 #endif /* SCIF_MAIN_H */