18c2ecf20Sopenharmony_ci#ifndef _HFI1_VNIC_H
28c2ecf20Sopenharmony_ci#define _HFI1_VNIC_H
38c2ecf20Sopenharmony_ci/*
48c2ecf20Sopenharmony_ci * Copyright(c) 2017 - 2020 Intel Corporation.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
78c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
128c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
138c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
168c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
178c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
188c2ecf20Sopenharmony_ci * General Public License for more details.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * BSD LICENSE
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
238c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
248c2ecf20Sopenharmony_ci * are met:
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *  - Redistributions of source code must retain the above copyright
278c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
288c2ecf20Sopenharmony_ci *  - Redistributions in binary form must reproduce the above copyright
298c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
308c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
318c2ecf20Sopenharmony_ci *    distribution.
328c2ecf20Sopenharmony_ci *  - Neither the name of Intel Corporation nor the names of its
338c2ecf20Sopenharmony_ci *    contributors may be used to endorse or promote products derived
348c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
378c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
388c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
398c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
408c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
418c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
428c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
438c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
448c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
458c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
468c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#include <rdma/opa_vnic.h>
518c2ecf20Sopenharmony_ci#include "hfi.h"
528c2ecf20Sopenharmony_ci#include "sdma.h"
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define HFI1_VNIC_MAX_TXQ     16
558c2ecf20Sopenharmony_ci#define HFI1_VNIC_MAX_PAD     12
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* L4 header definitions */
588c2ecf20Sopenharmony_ci#define HFI1_VNIC_L4_HDR_OFFSET  OPA_VNIC_L2_HDR_LEN
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define HFI1_VNIC_GET_L4_HDR(data)   \
618c2ecf20Sopenharmony_ci	(*((u16 *)((u8 *)(data) + HFI1_VNIC_L4_HDR_OFFSET)))
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define HFI1_VNIC_GET_VESWID(data)   \
648c2ecf20Sopenharmony_ci	(HFI1_VNIC_GET_L4_HDR(data) & 0xFFF)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/* Service class */
678c2ecf20Sopenharmony_ci#define HFI1_VNIC_SC_OFFSET_LOW 6
688c2ecf20Sopenharmony_ci#define HFI1_VNIC_SC_OFFSET_HI  7
698c2ecf20Sopenharmony_ci#define HFI1_VNIC_SC_SHIFT      4
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define HFI1_VNIC_MAX_QUEUE 16
728c2ecf20Sopenharmony_ci#define HFI1_NUM_VNIC_CTXT 8
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/**
758c2ecf20Sopenharmony_ci * struct hfi1_vnic_sdma - VNIC per Tx ring SDMA information
768c2ecf20Sopenharmony_ci * @dd - device data pointer
778c2ecf20Sopenharmony_ci * @sde - sdma engine
788c2ecf20Sopenharmony_ci * @vinfo - vnic info pointer
798c2ecf20Sopenharmony_ci * @wait - iowait structure
808c2ecf20Sopenharmony_ci * @stx - sdma tx request
818c2ecf20Sopenharmony_ci * @state - vnic Tx ring SDMA state
828c2ecf20Sopenharmony_ci * @q_idx - vnic Tx queue index
838c2ecf20Sopenharmony_ci */
848c2ecf20Sopenharmony_cistruct hfi1_vnic_sdma {
858c2ecf20Sopenharmony_ci	struct hfi1_devdata *dd;
868c2ecf20Sopenharmony_ci	struct sdma_engine  *sde;
878c2ecf20Sopenharmony_ci	struct hfi1_vnic_vport_info *vinfo;
888c2ecf20Sopenharmony_ci	struct iowait wait;
898c2ecf20Sopenharmony_ci	struct sdma_txreq stx;
908c2ecf20Sopenharmony_ci	unsigned int state;
918c2ecf20Sopenharmony_ci	u8 q_idx;
928c2ecf20Sopenharmony_ci	bool pkts_sent;
938c2ecf20Sopenharmony_ci};
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/**
968c2ecf20Sopenharmony_ci * struct hfi1_vnic_rx_queue - HFI1 VNIC receive queue
978c2ecf20Sopenharmony_ci * @idx: queue index
988c2ecf20Sopenharmony_ci * @vinfo: pointer to vport information
998c2ecf20Sopenharmony_ci * @netdev: network device
1008c2ecf20Sopenharmony_ci * @napi: netdev napi structure
1018c2ecf20Sopenharmony_ci * @skbq: queue of received socket buffers
1028c2ecf20Sopenharmony_ci */
1038c2ecf20Sopenharmony_cistruct hfi1_vnic_rx_queue {
1048c2ecf20Sopenharmony_ci	u8                           idx;
1058c2ecf20Sopenharmony_ci	struct hfi1_vnic_vport_info *vinfo;
1068c2ecf20Sopenharmony_ci	struct net_device           *netdev;
1078c2ecf20Sopenharmony_ci	struct napi_struct           napi;
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/**
1118c2ecf20Sopenharmony_ci * struct hfi1_vnic_vport_info - HFI1 VNIC virtual port information
1128c2ecf20Sopenharmony_ci * @dd: device data pointer
1138c2ecf20Sopenharmony_ci * @netdev: net device pointer
1148c2ecf20Sopenharmony_ci * @flags: state flags
1158c2ecf20Sopenharmony_ci * @lock: vport lock
1168c2ecf20Sopenharmony_ci * @num_tx_q: number of transmit queues
1178c2ecf20Sopenharmony_ci * @num_rx_q: number of receive queues
1188c2ecf20Sopenharmony_ci * @vesw_id: virtual switch id
1198c2ecf20Sopenharmony_ci * @rxq: Array of receive queues
1208c2ecf20Sopenharmony_ci * @stats: per queue stats
1218c2ecf20Sopenharmony_ci * @sdma: VNIC SDMA structure per TXQ
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_cistruct hfi1_vnic_vport_info {
1248c2ecf20Sopenharmony_ci	struct hfi1_devdata *dd;
1258c2ecf20Sopenharmony_ci	struct net_device   *netdev;
1268c2ecf20Sopenharmony_ci	unsigned long        flags;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	/* Lock used around state updates */
1298c2ecf20Sopenharmony_ci	struct mutex         lock;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	u8  num_tx_q;
1328c2ecf20Sopenharmony_ci	u8  num_rx_q;
1338c2ecf20Sopenharmony_ci	u16 vesw_id;
1348c2ecf20Sopenharmony_ci	struct hfi1_vnic_rx_queue rxq[HFI1_NUM_VNIC_CTXT];
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	struct opa_vnic_stats  stats[HFI1_VNIC_MAX_QUEUE];
1378c2ecf20Sopenharmony_ci	struct hfi1_vnic_sdma  sdma[HFI1_VNIC_MAX_TXQ];
1388c2ecf20Sopenharmony_ci};
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci#define v_dbg(format, arg...) \
1418c2ecf20Sopenharmony_ci	netdev_dbg(vinfo->netdev, format, ## arg)
1428c2ecf20Sopenharmony_ci#define v_err(format, arg...) \
1438c2ecf20Sopenharmony_ci	netdev_err(vinfo->netdev, format, ## arg)
1448c2ecf20Sopenharmony_ci#define v_info(format, arg...) \
1458c2ecf20Sopenharmony_ci	netdev_info(vinfo->netdev, format, ## arg)
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* vnic hfi1 internal functions */
1488c2ecf20Sopenharmony_civoid hfi1_vnic_setup(struct hfi1_devdata *dd);
1498c2ecf20Sopenharmony_ciint hfi1_vnic_txreq_init(struct hfi1_devdata *dd);
1508c2ecf20Sopenharmony_civoid hfi1_vnic_txreq_deinit(struct hfi1_devdata *dd);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_civoid hfi1_vnic_bypass_rcv(struct hfi1_packet *packet);
1538c2ecf20Sopenharmony_civoid hfi1_vnic_sdma_init(struct hfi1_vnic_vport_info *vinfo);
1548c2ecf20Sopenharmony_cibool hfi1_vnic_sdma_write_avail(struct hfi1_vnic_vport_info *vinfo,
1558c2ecf20Sopenharmony_ci				u8 q_idx);
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/* vnic rdma netdev operations */
1588c2ecf20Sopenharmony_cistruct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
1598c2ecf20Sopenharmony_ci				      u8 port_num,
1608c2ecf20Sopenharmony_ci				      enum rdma_netdev_t type,
1618c2ecf20Sopenharmony_ci				      const char *name,
1628c2ecf20Sopenharmony_ci				      unsigned char name_assign_type,
1638c2ecf20Sopenharmony_ci				      void (*setup)(struct net_device *));
1648c2ecf20Sopenharmony_ciint hfi1_vnic_send_dma(struct hfi1_devdata *dd, u8 q_idx,
1658c2ecf20Sopenharmony_ci		       struct hfi1_vnic_vport_info *vinfo,
1668c2ecf20Sopenharmony_ci		       struct sk_buff *skb, u64 pbc, u8 plen);
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci#endif /* _HFI1_VNIC_H */
169