1 #ifndef _HFI1_VNIC_H 2 #define _HFI1_VNIC_H 3 /* 4 * Copyright(c) 2017 Intel Corporation. 5 * 6 * This file is provided under a dual BSD/GPLv2 license. When using or 7 * redistributing this file, you may do so under either license. 8 * 9 * GPL LICENSE SUMMARY 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 * Redistribution and use in source and binary forms, with or without 23 * modification, are permitted provided that the following conditions 24 * are met: 25 * 26 * - Redistributions of source code must retain the above copyright 27 * notice, this list of conditions and the following disclaimer. 28 * - Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in 30 * the documentation and/or other materials provided with the 31 * distribution. 32 * - Neither the name of Intel Corporation nor the names of its 33 * contributors may be used to endorse or promote products derived 34 * from this software without specific prior written permission. 35 * 36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 * 48 */ 49 50 #include <rdma/opa_vnic.h> 51 #include "hfi.h" 52 #include "sdma.h" 53 54 #define HFI1_VNIC_MAX_TXQ 16 55 #define HFI1_VNIC_MAX_PAD 12 56 57 /* L2 header definitions */ 58 #define HFI1_L2_TYPE_OFFSET 0x7 59 #define HFI1_L2_TYPE_SHFT 0x5 60 #define HFI1_L2_TYPE_MASK 0x3 61 62 #define HFI1_GET_L2_TYPE(hdr) \ 63 ((*((u8 *)(hdr) + HFI1_L2_TYPE_OFFSET) >> HFI1_L2_TYPE_SHFT) & \ 64 HFI1_L2_TYPE_MASK) 65 66 /* L4 type definitions */ 67 #define HFI1_L4_TYPE_OFFSET 8 68 69 #define HFI1_GET_L4_TYPE(data) \ 70 (*((u8 *)(data) + HFI1_L4_TYPE_OFFSET)) 71 72 /* L4 header definitions */ 73 #define HFI1_VNIC_L4_HDR_OFFSET OPA_VNIC_L2_HDR_LEN 74 75 #define HFI1_VNIC_GET_L4_HDR(data) \ 76 (*((u16 *)((u8 *)(data) + HFI1_VNIC_L4_HDR_OFFSET))) 77 78 #define HFI1_VNIC_GET_VESWID(data) \ 79 (HFI1_VNIC_GET_L4_HDR(data) & 0xFFF) 80 81 /* Service class */ 82 #define HFI1_VNIC_SC_OFFSET_LOW 6 83 #define HFI1_VNIC_SC_OFFSET_HI 7 84 #define HFI1_VNIC_SC_SHIFT 4 85 86 #define HFI1_VNIC_MAX_QUEUE 16 87 88 /** 89 * struct hfi1_vnic_sdma - VNIC per Tx ring SDMA information 90 * @dd - device data pointer 91 * @sde - sdma engine 92 * @vinfo - vnic info pointer 93 * @wait - iowait structure 94 * @stx - sdma tx request 95 * @state - vnic Tx ring SDMA state 96 * @q_idx - vnic Tx queue index 97 */ 98 struct hfi1_vnic_sdma { 99 struct hfi1_devdata *dd; 100 struct sdma_engine *sde; 101 struct hfi1_vnic_vport_info *vinfo; 102 struct iowait wait; 103 struct sdma_txreq stx; 104 unsigned int state; 105 u8 q_idx; 106 }; 107 108 /** 109 * struct hfi1_vnic_rx_queue - HFI1 VNIC receive queue 110 * @idx: queue index 111 * @vinfo: pointer to vport information 112 * @netdev: network device 113 * @napi: netdev napi structure 114 * @skbq: queue of received socket buffers 115 */ 116 struct hfi1_vnic_rx_queue { 117 u8 idx; 118 struct hfi1_vnic_vport_info *vinfo; 119 struct net_device *netdev; 120 struct napi_struct napi; 121 struct sk_buff_head skbq; 122 }; 123 124 /** 125 * struct hfi1_vnic_vport_info - HFI1 VNIC virtual port information 126 * @dd: device data pointer 127 * @netdev: net device pointer 128 * @flags: state flags 129 * @lock: vport lock 130 * @num_tx_q: number of transmit queues 131 * @num_rx_q: number of receive queues 132 * @vesw_id: virtual switch id 133 * @rxq: Array of receive queues 134 * @stats: per queue stats 135 * @sdma: VNIC SDMA structure per TXQ 136 */ 137 struct hfi1_vnic_vport_info { 138 struct hfi1_devdata *dd; 139 struct net_device *netdev; 140 unsigned long flags; 141 142 /* Lock used around state updates */ 143 struct mutex lock; 144 145 u8 num_tx_q; 146 u8 num_rx_q; 147 u16 vesw_id; 148 struct hfi1_vnic_rx_queue rxq[HFI1_NUM_VNIC_CTXT]; 149 150 struct opa_vnic_stats stats[HFI1_VNIC_MAX_QUEUE]; 151 struct hfi1_vnic_sdma sdma[HFI1_VNIC_MAX_TXQ]; 152 }; 153 154 #define v_dbg(format, arg...) \ 155 netdev_dbg(vinfo->netdev, format, ## arg) 156 #define v_err(format, arg...) \ 157 netdev_err(vinfo->netdev, format, ## arg) 158 #define v_info(format, arg...) \ 159 netdev_info(vinfo->netdev, format, ## arg) 160 161 /* vnic hfi1 internal functions */ 162 void hfi1_vnic_setup(struct hfi1_devdata *dd); 163 void hfi1_vnic_cleanup(struct hfi1_devdata *dd); 164 int hfi1_vnic_txreq_init(struct hfi1_devdata *dd); 165 void hfi1_vnic_txreq_deinit(struct hfi1_devdata *dd); 166 167 void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet); 168 void hfi1_vnic_sdma_init(struct hfi1_vnic_vport_info *vinfo); 169 bool hfi1_vnic_sdma_write_avail(struct hfi1_vnic_vport_info *vinfo, 170 u8 q_idx); 171 172 /* vnic rdma netdev operations */ 173 struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device, 174 u8 port_num, 175 enum rdma_netdev_t type, 176 const char *name, 177 unsigned char name_assign_type, 178 void (*setup)(struct net_device *)); 179 int hfi1_vnic_send_dma(struct hfi1_devdata *dd, u8 q_idx, 180 struct hfi1_vnic_vport_info *vinfo, 181 struct sk_buff *skb, u64 pbc, u8 plen); 182 183 #endif /* _HFI1_VNIC_H */ 184