2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2014 Intel Corporation.
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.
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.
18 #include "scif_peer_bus.h"
20 #include "scif_main.h"
24 * scif_invalidate_ep() - Set state for all connected endpoints
25 * to disconnected and wake up all send/recv waitqueues
27 static void scif_invalidate_ep(int node)
29 struct scif_endpt *ep;
30 struct list_head *pos, *tmpq;
32 flush_work(&scif_info.conn_work);
33 mutex_lock(&scif_info.connlock);
34 list_for_each_safe(pos, tmpq, &scif_info.disconnected) {
35 ep = list_entry(pos, struct scif_endpt, list);
36 if (ep->remote_dev->node == node) {
38 scif_cleanup_ep_qp(ep);
39 spin_unlock(&ep->lock);
42 list_for_each_safe(pos, tmpq, &scif_info.connected) {
43 ep = list_entry(pos, struct scif_endpt, list);
44 if (ep->remote_dev->node == node) {
47 ep->state = SCIFEP_DISCONNECTED;
48 list_add_tail(&ep->list, &scif_info.disconnected);
49 scif_cleanup_ep_qp(ep);
50 wake_up_interruptible(&ep->sendwq);
51 wake_up_interruptible(&ep->recvwq);
52 spin_unlock(&ep->lock);
55 mutex_unlock(&scif_info.connlock);
58 void scif_free_qp(struct scif_dev *scifdev)
60 struct scif_qp *qp = scifdev->qpairs;
64 scif_free_coherent((void *)qp->inbound_q.rb_base,
65 qp->local_buf, scifdev, qp->inbound_q.size);
66 scif_unmap_single(qp->local_qp, scifdev, sizeof(struct scif_qp));
67 kfree(scifdev->qpairs);
68 scifdev->qpairs = NULL;
71 static void scif_cleanup_qp(struct scif_dev *dev)
73 struct scif_qp *qp = &dev->qpairs[0];
77 scif_iounmap((void *)qp->remote_qp, sizeof(struct scif_qp), dev);
78 scif_iounmap((void *)qp->outbound_q.rb_base,
79 sizeof(struct scif_qp), dev);
82 qp->inbound_q.current_write_offset = 0;
83 qp->inbound_q.current_read_offset = 0;
84 if (scifdev_is_p2p(dev))
88 void scif_send_acks(struct scif_dev *dev)
92 if (dev->node_remove_ack_pending) {
93 msg.uop = SCIF_NODE_REMOVE_ACK;
94 msg.src.node = scif_info.nodeid;
95 msg.dst.node = SCIF_MGMT_NODE;
96 msg.payload[0] = dev->node;
97 scif_nodeqp_send(&scif_dev[SCIF_MGMT_NODE], &msg);
98 dev->node_remove_ack_pending = false;
100 if (dev->exit_ack_pending) {
101 msg.uop = SCIF_EXIT_ACK;
102 msg.src.node = scif_info.nodeid;
103 msg.dst.node = dev->node;
104 scif_nodeqp_send(dev, &msg);
105 dev->exit_ack_pending = false;
110 * scif_cleanup_scifdev
112 * @dev: Remote SCIF device.
113 * Uninitialize SCIF data structures for remote SCIF device.
115 void scif_cleanup_scifdev(struct scif_dev *dev)
117 struct scif_hw_dev *sdev = dev->sdev;
121 if (scifdev_is_p2p(dev)) {
123 sdev->hw_ops->free_irq(sdev, dev->cookie, dev);
126 scif_destroy_intr_wq(dev);
128 scif_destroy_p2p(dev);
129 scif_invalidate_ep(dev->node);
131 if (!dev->node && scif_info.card_initiated_exit) {
133 * Send an SCIF_EXIT message which is the last message from MIC
134 * to the Host and wait for a SCIF_EXIT_ACK
137 scif_info.card_initiated_exit = false;
139 scif_cleanup_qp(dev);
145 * @node: Node to remove
147 void scif_handle_remove_node(int node)
149 struct scif_dev *scifdev = &scif_dev[node];
150 struct scif_peer_dev *spdev;
153 spdev = rcu_dereference(scifdev->spdev);
156 scif_peer_unregister_device(spdev);
158 scif_send_acks(scifdev);
161 static int scif_send_rmnode_msg(int node, int remove_node)
163 struct scifmsg notif_msg;
164 struct scif_dev *dev = &scif_dev[node];
166 notif_msg.uop = SCIF_NODE_REMOVE;
167 notif_msg.src.node = scif_info.nodeid;
168 notif_msg.dst.node = node;
169 notif_msg.payload[0] = remove_node;
170 return scif_nodeqp_send(dev, ¬if_msg);
174 * scif_node_disconnect:
176 * @node_id[in]: source node id.
177 * @mgmt_initiated: Disconnection initiated from the mgmt node
179 * Disconnect a node from the scif network.
181 void scif_disconnect_node(u32 node_id, bool mgmt_initiated)
186 struct scif_dev *scifdev = &scif_dev[node_id];
191 atomic_set(&scifdev->disconn_rescnt, 0);
193 /* Destroy p2p network */
194 for (i = 1; i <= scif_info.maxid; i++) {
197 ret = scif_send_rmnode_msg(i, node_id);
201 /* Wait for the remote nodes to respond with SCIF_NODE_REMOVE_ACK */
202 ret = wait_event_timeout(scifdev->disconn_wq,
203 (atomic_read(&scifdev->disconn_rescnt)
204 == msg_cnt), SCIF_NODE_ALIVE_TIMEOUT);
205 /* Tell the card to clean up */
206 if (mgmt_initiated && _scifdev_alive(scifdev))
208 * Send an SCIF_EXIT message which is the last message from Host
209 * to the MIC and wait for a SCIF_EXIT_ACK
211 scif_send_exit(scifdev);
212 atomic_set(&scifdev->disconn_rescnt, 0);
213 /* Tell the mgmt node to clean up */
214 ret = scif_send_rmnode_msg(SCIF_MGMT_NODE, node_id);
216 /* Wait for mgmt node to respond with SCIF_NODE_REMOVE_ACK */
217 wait_event_timeout(scifdev->disconn_wq,
218 (atomic_read(&scifdev->disconn_rescnt) == 1),
219 SCIF_NODE_ALIVE_TIMEOUT);