Loading...
Note: File does not exist in v3.1.
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Intel MIC Platform Software Stack (MPSS)
4 *
5 * Copyright(c) 2014 Intel Corporation.
6 *
7 * Intel SCIF driver.
8 */
9#include "scif_peer_bus.h"
10
11#include "scif_main.h"
12#include "scif_map.h"
13
14/**
15 * scif_invalidate_ep() - Set state for all connected endpoints
16 * to disconnected and wake up all send/recv waitqueues
17 *
18 * @node: Node to invalidate
19 */
20static void scif_invalidate_ep(int node)
21{
22 struct scif_endpt *ep;
23 struct list_head *pos, *tmpq;
24
25 flush_work(&scif_info.conn_work);
26 mutex_lock(&scif_info.connlock);
27 list_for_each_safe(pos, tmpq, &scif_info.disconnected) {
28 ep = list_entry(pos, struct scif_endpt, list);
29 if (ep->remote_dev->node == node) {
30 scif_unmap_all_windows(ep);
31 spin_lock(&ep->lock);
32 scif_cleanup_ep_qp(ep);
33 spin_unlock(&ep->lock);
34 }
35 }
36 list_for_each_safe(pos, tmpq, &scif_info.connected) {
37 ep = list_entry(pos, struct scif_endpt, list);
38 if (ep->remote_dev->node == node) {
39 list_del(pos);
40 spin_lock(&ep->lock);
41 ep->state = SCIFEP_DISCONNECTED;
42 list_add_tail(&ep->list, &scif_info.disconnected);
43 scif_cleanup_ep_qp(ep);
44 wake_up_interruptible(&ep->sendwq);
45 wake_up_interruptible(&ep->recvwq);
46 spin_unlock(&ep->lock);
47 scif_unmap_all_windows(ep);
48 }
49 }
50 mutex_unlock(&scif_info.connlock);
51}
52
53void scif_free_qp(struct scif_dev *scifdev)
54{
55 struct scif_qp *qp = scifdev->qpairs;
56
57 if (!qp)
58 return;
59 scif_unmap_single(qp->local_buf, scifdev, qp->inbound_q.size);
60 kfree(qp->inbound_q.rb_base);
61 scif_unmap_single(qp->local_qp, scifdev, sizeof(struct scif_qp));
62 kfree(scifdev->qpairs);
63 scifdev->qpairs = NULL;
64}
65
66static void scif_cleanup_qp(struct scif_dev *dev)
67{
68 struct scif_qp *qp = &dev->qpairs[0];
69
70 if (!qp)
71 return;
72 scif_iounmap((void *)qp->remote_qp, sizeof(struct scif_qp), dev);
73 scif_iounmap((void *)qp->outbound_q.rb_base,
74 sizeof(struct scif_qp), dev);
75 qp->remote_qp = NULL;
76 qp->local_write = 0;
77 qp->inbound_q.current_write_offset = 0;
78 qp->inbound_q.current_read_offset = 0;
79 if (scifdev_is_p2p(dev))
80 scif_free_qp(dev);
81}
82
83void scif_send_acks(struct scif_dev *dev)
84{
85 struct scifmsg msg;
86
87 if (dev->node_remove_ack_pending) {
88 msg.uop = SCIF_NODE_REMOVE_ACK;
89 msg.src.node = scif_info.nodeid;
90 msg.dst.node = SCIF_MGMT_NODE;
91 msg.payload[0] = dev->node;
92 scif_nodeqp_send(&scif_dev[SCIF_MGMT_NODE], &msg);
93 dev->node_remove_ack_pending = false;
94 }
95 if (dev->exit_ack_pending) {
96 msg.uop = SCIF_EXIT_ACK;
97 msg.src.node = scif_info.nodeid;
98 msg.dst.node = dev->node;
99 scif_nodeqp_send(dev, &msg);
100 dev->exit_ack_pending = false;
101 }
102}
103
104/**
105 * scif_cleanup_scifdev - Uninitialize SCIF data structures for remote
106 * SCIF device.
107 * @dev: Remote SCIF device.
108 */
109void scif_cleanup_scifdev(struct scif_dev *dev)
110{
111 struct scif_hw_dev *sdev = dev->sdev;
112
113 if (!dev->sdev)
114 return;
115 if (scifdev_is_p2p(dev)) {
116 if (dev->cookie) {
117 sdev->hw_ops->free_irq(sdev, dev->cookie, dev);
118 dev->cookie = NULL;
119 }
120 scif_destroy_intr_wq(dev);
121 }
122 flush_work(&scif_info.misc_work);
123 scif_destroy_p2p(dev);
124 scif_invalidate_ep(dev->node);
125 scif_zap_mmaps(dev->node);
126 scif_cleanup_rma_for_zombies(dev->node);
127 flush_work(&scif_info.misc_work);
128 scif_send_acks(dev);
129 if (!dev->node && scif_info.card_initiated_exit) {
130 /*
131 * Send an SCIF_EXIT message which is the last message from MIC
132 * to the Host and wait for a SCIF_EXIT_ACK
133 */
134 scif_send_exit(dev);
135 scif_info.card_initiated_exit = false;
136 }
137 scif_cleanup_qp(dev);
138}
139
140/**
141 * scif_remove_node
142 *
143 * @node: Node to remove
144 */
145void scif_handle_remove_node(int node)
146{
147 struct scif_dev *scifdev = &scif_dev[node];
148
149 if (scif_peer_unregister_device(scifdev))
150 scif_send_acks(scifdev);
151}
152
153static int scif_send_rmnode_msg(int node, int remove_node)
154{
155 struct scifmsg notif_msg;
156 struct scif_dev *dev = &scif_dev[node];
157
158 notif_msg.uop = SCIF_NODE_REMOVE;
159 notif_msg.src.node = scif_info.nodeid;
160 notif_msg.dst.node = node;
161 notif_msg.payload[0] = remove_node;
162 return scif_nodeqp_send(dev, ¬if_msg);
163}
164
165/**
166 * scif_node_disconnect
167 *
168 * @node_id: source node id [in]
169 * @mgmt_initiated: Disconnection initiated from the mgmt node
170 *
171 * Disconnect a node from the scif network.
172 */
173void scif_disconnect_node(u32 node_id, bool mgmt_initiated)
174{
175 int ret;
176 int msg_cnt = 0;
177 u32 i = 0;
178 struct scif_dev *scifdev = &scif_dev[node_id];
179
180 if (!node_id)
181 return;
182
183 atomic_set(&scifdev->disconn_rescnt, 0);
184
185 /* Destroy p2p network */
186 for (i = 1; i <= scif_info.maxid; i++) {
187 if (i == node_id)
188 continue;
189 ret = scif_send_rmnode_msg(i, node_id);
190 if (!ret)
191 msg_cnt++;
192 }
193 /* Wait for the remote nodes to respond with SCIF_NODE_REMOVE_ACK */
194 ret = wait_event_timeout(scifdev->disconn_wq,
195 (atomic_read(&scifdev->disconn_rescnt)
196 == msg_cnt), SCIF_NODE_ALIVE_TIMEOUT);
197 /* Tell the card to clean up */
198 if (mgmt_initiated && _scifdev_alive(scifdev))
199 /*
200 * Send an SCIF_EXIT message which is the last message from Host
201 * to the MIC and wait for a SCIF_EXIT_ACK
202 */
203 scif_send_exit(scifdev);
204 atomic_set(&scifdev->disconn_rescnt, 0);
205 /* Tell the mgmt node to clean up */
206 ret = scif_send_rmnode_msg(SCIF_MGMT_NODE, node_id);
207 if (!ret)
208 /* Wait for mgmt node to respond with SCIF_NODE_REMOVE_ACK */
209 wait_event_timeout(scifdev->disconn_wq,
210 (atomic_read(&scifdev->disconn_rescnt) == 1),
211 SCIF_NODE_ALIVE_TIMEOUT);
212}
213
214void scif_get_node_info(void)
215{
216 struct scifmsg msg;
217 DECLARE_COMPLETION_ONSTACK(node_info);
218
219 msg.uop = SCIF_GET_NODE_INFO;
220 msg.src.node = scif_info.nodeid;
221 msg.dst.node = SCIF_MGMT_NODE;
222 msg.payload[3] = (u64)&node_info;
223
224 if ((scif_nodeqp_send(&scif_dev[SCIF_MGMT_NODE], &msg)))
225 return;
226
227 /* Wait for a response with SCIF_GET_NODE_INFO */
228 wait_for_completion(&node_info);
229}