Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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