Sudeep Dutt | 40cb594 | 2015-04-29 05:32:34 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Intel MIC Platform Software Stack (MPSS) |
| 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
| 9 | * Copyright(c) 2014 Intel Corporation. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * BSD LICENSE |
| 21 | * |
| 22 | * Copyright(c) 2014 Intel Corporation. |
| 23 | * |
| 24 | * Redistribution and use in source and binary forms, with or without |
| 25 | * modification, are permitted provided that the following conditions |
| 26 | * are met: |
| 27 | * |
| 28 | * * Redistributions of source code must retain the above copyright |
| 29 | * notice, this list of conditions and the following disclaimer. |
| 30 | * * Redistributions in binary form must reproduce the above copyright |
| 31 | * notice, this list of conditions and the following disclaimer in |
| 32 | * the documentation and/or other materials provided with the |
| 33 | * distribution. |
| 34 | * * Neither the name of Intel Corporation nor the names of its |
| 35 | * contributors may be used to endorse or promote products derived |
| 36 | * from this software without specific prior written permission. |
| 37 | * |
| 38 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 39 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 40 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 41 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 42 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 44 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 45 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 46 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 47 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 48 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 49 | * |
| 50 | * Intel SCIF driver. |
| 51 | * |
| 52 | */ |
| 53 | #ifndef SCIF_NODEQP |
| 54 | #define SCIF_NODEQP |
| 55 | |
| 56 | #include "scif_rb.h" |
| 57 | #include "scif_peer_bus.h" |
| 58 | |
| 59 | #define SCIF_INIT 1 /* First message sent to the peer node for discovery */ |
| 60 | #define SCIF_EXIT 2 /* Last message from the peer informing intent to exit */ |
| 61 | #define SCIF_EXIT_ACK 3 /* Response to SCIF_EXIT message */ |
| 62 | #define SCIF_NODE_ADD 4 /* Tell Online nodes a new node exits */ |
| 63 | #define SCIF_NODE_ADD_ACK 5 /* Confirm to mgmt node sequence is finished */ |
| 64 | #define SCIF_NODE_ADD_NACK 6 /* SCIF_NODE_ADD failed */ |
| 65 | #define SCIF_NODE_REMOVE 7 /* Request to deactivate a SCIF node */ |
| 66 | #define SCIF_NODE_REMOVE_ACK 8 /* Response to a SCIF_NODE_REMOVE message */ |
| 67 | #define SCIF_MAX_MSG SCIF_NODE_REMOVE_ACK |
| 68 | |
| 69 | /* |
| 70 | * struct scifmsg - Node QP message format |
| 71 | * |
| 72 | * @src: Source information |
| 73 | * @dst: Destination information |
| 74 | * @uop: The message opcode |
| 75 | * @payload: Unique payload format for each message |
| 76 | */ |
| 77 | struct scifmsg { |
| 78 | struct scif_port_id src; |
| 79 | struct scif_port_id dst; |
| 80 | u32 uop; |
| 81 | u64 payload[4]; |
| 82 | } __packed; |
| 83 | |
| 84 | /* |
| 85 | * struct scif_qp - Node Queue Pair |
| 86 | * |
| 87 | * Interesting structure -- a little difficult because we can only |
| 88 | * write across the PCIe, so any r/w pointer we need to read is |
| 89 | * local. We only need to read the read pointer on the inbound_q |
| 90 | * and read the write pointer in the outbound_q |
| 91 | * |
| 92 | * @magic: Magic value to ensure the peer sees the QP correctly |
| 93 | * @outbound_q: The outbound ring buffer for sending messages |
| 94 | * @inbound_q: The inbound ring buffer for receiving messages |
| 95 | * @local_write: Local write index |
| 96 | * @local_read: Local read index |
| 97 | * @remote_qp: The remote queue pair |
| 98 | * @local_buf: DMA address of local ring buffer |
| 99 | * @local_qp: DMA address of the local queue pair data structure |
| 100 | * @remote_buf: DMA address of remote ring buffer |
| 101 | * @qp_state: QP state i.e. online or offline used for P2P |
| 102 | * @send_lock: synchronize access to outbound queue |
| 103 | * @recv_lock: Synchronize access to inbound queue |
| 104 | */ |
| 105 | struct scif_qp { |
| 106 | u64 magic; |
| 107 | #define SCIFEP_MAGIC 0x5c1f000000005c1fULL |
| 108 | struct scif_rb outbound_q; |
| 109 | struct scif_rb inbound_q; |
| 110 | |
| 111 | u32 local_write __aligned(64); |
| 112 | u32 local_read __aligned(64); |
| 113 | struct scif_qp *remote_qp; |
| 114 | dma_addr_t local_buf; |
| 115 | dma_addr_t local_qp; |
| 116 | dma_addr_t remote_buf; |
| 117 | u32 qp_state; |
| 118 | #define SCIF_QP_OFFLINE 0xdead |
| 119 | #define SCIF_QP_ONLINE 0xc0de |
| 120 | spinlock_t send_lock; |
| 121 | spinlock_t recv_lock; |
| 122 | }; |
| 123 | |
| 124 | /* |
| 125 | * struct scif_loopb_msg - An element in the loopback Node QP message list. |
| 126 | * |
| 127 | * @msg - The SCIF node QP message |
| 128 | * @list - link in the list of messages |
| 129 | */ |
| 130 | struct scif_loopb_msg { |
| 131 | struct scifmsg msg; |
| 132 | struct list_head list; |
| 133 | }; |
| 134 | |
| 135 | int scif_nodeqp_send(struct scif_dev *scifdev, struct scifmsg *msg); |
| 136 | int _scif_nodeqp_send(struct scif_dev *scifdev, struct scifmsg *msg); |
| 137 | void scif_nodeqp_intrhandler(struct scif_dev *scifdev, struct scif_qp *qp); |
| 138 | int scif_loopb_msg_handler(struct scif_dev *scifdev, struct scif_qp *qp); |
| 139 | int scif_setup_qp(struct scif_dev *scifdev); |
| 140 | int scif_qp_response(phys_addr_t phys, struct scif_dev *dev); |
| 141 | int scif_setup_qp_connect(struct scif_qp *qp, dma_addr_t *qp_offset, |
| 142 | int local_size, struct scif_dev *scifdev); |
| 143 | int scif_setup_qp_accept(struct scif_qp *qp, dma_addr_t *qp_offset, |
| 144 | dma_addr_t phys, int local_size, |
| 145 | struct scif_dev *scifdev); |
| 146 | int scif_setup_qp_connect_response(struct scif_dev *scifdev, |
| 147 | struct scif_qp *qp, u64 payload); |
| 148 | int scif_setup_loopback_qp(struct scif_dev *scifdev); |
| 149 | int scif_destroy_loopback_qp(struct scif_dev *scifdev); |
| 150 | void scif_poll_qp_state(struct work_struct *work); |
| 151 | void scif_qp_response_ack(struct work_struct *work); |
| 152 | void scif_destroy_p2p(struct scif_dev *scifdev); |
| 153 | void scif_send_exit(struct scif_dev *scifdev); |
| 154 | static inline struct device *scif_get_peer_dev(struct scif_dev *scifdev) |
| 155 | { |
| 156 | struct scif_peer_dev *spdev; |
| 157 | struct device *spdev_ret; |
| 158 | |
| 159 | rcu_read_lock(); |
| 160 | spdev = rcu_dereference(scifdev->spdev); |
| 161 | if (spdev) |
| 162 | spdev_ret = get_device(&spdev->dev); |
| 163 | else |
| 164 | spdev_ret = ERR_PTR(-ENODEV); |
| 165 | rcu_read_unlock(); |
| 166 | return spdev_ret; |
| 167 | } |
| 168 | |
| 169 | static inline void scif_put_peer_dev(struct device *dev) |
| 170 | { |
| 171 | put_device(dev); |
| 172 | } |
| 173 | #endif /* SCIF_NODEQP */ |