12656Srgrimes/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
22656Srgrimes/*
32656Srgrimes * Copyright(c) 2017 - 2020 Intel Corporation.
42656Srgrimes */
52656Srgrimes
62656Srgrimes#ifndef _HFI1_VNIC_H
72656Srgrimes#define _HFI1_VNIC_H
82656Srgrimes#include <rdma/opa_vnic.h>
92656Srgrimes#include "hfi.h"
102656Srgrimes#include "sdma.h"
112656Srgrimes
122656Srgrimes#define HFI1_VNIC_MAX_TXQ     16
132656Srgrimes#define HFI1_VNIC_MAX_PAD     12
142656Srgrimes
152656Srgrimes/* L4 header definitions */
162656Srgrimes#define HFI1_VNIC_L4_HDR_OFFSET  OPA_VNIC_L2_HDR_LEN
172656Srgrimes
182656Srgrimes#define HFI1_VNIC_GET_L4_HDR(data)   \
192656Srgrimes	(*((u16 *)((u8 *)(data) + HFI1_VNIC_L4_HDR_OFFSET)))
202656Srgrimes
212656Srgrimes#define HFI1_VNIC_GET_VESWID(data)   \
222656Srgrimes	(HFI1_VNIC_GET_L4_HDR(data) & 0xFFF)
232656Srgrimes
242656Srgrimes/* Service class */
252656Srgrimes#define HFI1_VNIC_SC_OFFSET_LOW 6
262656Srgrimes#define HFI1_VNIC_SC_OFFSET_HI  7
272656Srgrimes#define HFI1_VNIC_SC_SHIFT      4
282656Srgrimes
292656Srgrimes#define HFI1_VNIC_MAX_QUEUE 16
302656Srgrimes#define HFI1_NUM_VNIC_CTXT 8
312656Srgrimes
322656Srgrimes/**
332656Srgrimes * struct hfi1_vnic_sdma - VNIC per Tx ring SDMA information
342656Srgrimes * @dd - device data pointer
352656Srgrimes * @sde - sdma engine
362656Srgrimes * @vinfo - vnic info pointer
372656Srgrimes * @wait - iowait structure
382656Srgrimes * @stx - sdma tx request
392656Srgrimes * @state - vnic Tx ring SDMA state
402656Srgrimes * @q_idx - vnic Tx queue index
412656Srgrimes */
422656Srgrimesstruct hfi1_vnic_sdma {
432656Srgrimes	struct hfi1_devdata *dd;
442656Srgrimes	struct sdma_engine  *sde;
452656Srgrimes	struct hfi1_vnic_vport_info *vinfo;
462656Srgrimes	struct iowait wait;
472656Srgrimes	struct sdma_txreq stx;
482656Srgrimes	unsigned int state;
492656Srgrimes	u8 q_idx;
502656Srgrimes	bool pkts_sent;
512656Srgrimes};
522656Srgrimes
532656Srgrimes/**
542656Srgrimes * struct hfi1_vnic_rx_queue - HFI1 VNIC receive queue
552656Srgrimes * @idx: queue index
562656Srgrimes * @vinfo: pointer to vport information
572656Srgrimes * @netdev: network device
582656Srgrimes * @napi: netdev napi structure
592656Srgrimes * @skbq: queue of received socket buffers
602656Srgrimes */
612656Srgrimesstruct hfi1_vnic_rx_queue {
622656Srgrimes	u8                           idx;
632656Srgrimes	struct hfi1_vnic_vport_info *vinfo;
642656Srgrimes	struct net_device           *netdev;
65	struct napi_struct           napi;
66};
67
68/**
69 * struct hfi1_vnic_vport_info - HFI1 VNIC virtual port information
70 * @dd: device data pointer
71 * @netdev: net device pointer
72 * @flags: state flags
73 * @lock: vport lock
74 * @num_tx_q: number of transmit queues
75 * @num_rx_q: number of receive queues
76 * @vesw_id: virtual switch id
77 * @rxq: Array of receive queues
78 * @stats: per queue stats
79 * @sdma: VNIC SDMA structure per TXQ
80 */
81struct hfi1_vnic_vport_info {
82	struct hfi1_devdata *dd;
83	struct net_device   *netdev;
84	unsigned long        flags;
85
86	/* Lock used around state updates */
87	struct mutex         lock;
88
89	u8  num_tx_q;
90	u8  num_rx_q;
91	u16 vesw_id;
92	struct hfi1_vnic_rx_queue rxq[HFI1_NUM_VNIC_CTXT];
93
94	struct opa_vnic_stats  stats[HFI1_VNIC_MAX_QUEUE];
95	struct hfi1_vnic_sdma  sdma[HFI1_VNIC_MAX_TXQ];
96};
97
98#define v_dbg(format, arg...) \
99	netdev_dbg(vinfo->netdev, format, ## arg)
100#define v_err(format, arg...) \
101	netdev_err(vinfo->netdev, format, ## arg)
102#define v_info(format, arg...) \
103	netdev_info(vinfo->netdev, format, ## arg)
104
105/* vnic hfi1 internal functions */
106void hfi1_vnic_setup(struct hfi1_devdata *dd);
107int hfi1_vnic_txreq_init(struct hfi1_devdata *dd);
108void hfi1_vnic_txreq_deinit(struct hfi1_devdata *dd);
109
110void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet);
111void hfi1_vnic_sdma_init(struct hfi1_vnic_vport_info *vinfo);
112bool hfi1_vnic_sdma_write_avail(struct hfi1_vnic_vport_info *vinfo,
113				u8 q_idx);
114
115/* vnic rdma netdev operations */
116struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
117				      u32 port_num,
118				      enum rdma_netdev_t type,
119				      const char *name,
120				      unsigned char name_assign_type,
121				      void (*setup)(struct net_device *));
122int hfi1_vnic_send_dma(struct hfi1_devdata *dd, u8 q_idx,
123		       struct hfi1_vnic_vport_info *vinfo,
124		       struct sk_buff *skb, u64 pbc, u8 plen);
125
126#endif /* _HFI1_VNIC_H */
127