18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright(c) 2020 Intel Corporation.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef HFI1_NETDEV_H
88c2ecf20Sopenharmony_ci#define HFI1_NETDEV_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include "hfi.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
138c2ecf20Sopenharmony_ci#include <linux/xarray.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/**
168c2ecf20Sopenharmony_ci * struct hfi1_netdev_rxq - Receive Queue for HFI
178c2ecf20Sopenharmony_ci * dummy netdev. Both IPoIB and VNIC netdevices will be working on
188c2ecf20Sopenharmony_ci * top of this device.
198c2ecf20Sopenharmony_ci * @napi: napi object
208c2ecf20Sopenharmony_ci * @priv: ptr to netdev_priv
218c2ecf20Sopenharmony_ci * @rcd:  ptr to receive context data
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_cistruct hfi1_netdev_rxq {
248c2ecf20Sopenharmony_ci	struct napi_struct napi;
258c2ecf20Sopenharmony_ci	struct hfi1_netdev_priv *priv;
268c2ecf20Sopenharmony_ci	struct hfi1_ctxtdata *rcd;
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci * Number of netdev contexts used. Ensure it is less than or equal to
318c2ecf20Sopenharmony_ci * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#define HFI1_MAX_NETDEV_CTXTS   8
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Number of NETDEV RSM entries */
368c2ecf20Sopenharmony_ci#define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/**
398c2ecf20Sopenharmony_ci * struct hfi1_netdev_priv: data required to setup and run HFI netdev.
408c2ecf20Sopenharmony_ci * @dd:		hfi1_devdata
418c2ecf20Sopenharmony_ci * @rxq:	pointer to dummy netdev receive queues.
428c2ecf20Sopenharmony_ci * @num_rx_q:	number of receive queues
438c2ecf20Sopenharmony_ci * @rmt_index:	first free index in RMT Array
448c2ecf20Sopenharmony_ci * @msix_start: first free MSI-X interrupt vector.
458c2ecf20Sopenharmony_ci * @dev_tbl:	netdev table for unique identifier VNIC and IPoIb VLANs.
468c2ecf20Sopenharmony_ci * @enabled:	atomic counter of netdevs enabling receive queues.
478c2ecf20Sopenharmony_ci *		When 0 NAPI will be disabled.
488c2ecf20Sopenharmony_ci * @netdevs:	atomic counter of netdevs using dummy netdev.
498c2ecf20Sopenharmony_ci *		When 0 receive queues will be freed.
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_cistruct hfi1_netdev_priv {
528c2ecf20Sopenharmony_ci	struct hfi1_devdata *dd;
538c2ecf20Sopenharmony_ci	struct hfi1_netdev_rxq *rxq;
548c2ecf20Sopenharmony_ci	int num_rx_q;
558c2ecf20Sopenharmony_ci	int rmt_start;
568c2ecf20Sopenharmony_ci	struct xarray dev_tbl;
578c2ecf20Sopenharmony_ci	/* count of enabled napi polls */
588c2ecf20Sopenharmony_ci	atomic_t enabled;
598c2ecf20Sopenharmony_ci	/* count of netdevs on top */
608c2ecf20Sopenharmony_ci	atomic_t netdevs;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic inline
648c2ecf20Sopenharmony_cistruct hfi1_netdev_priv *hfi1_netdev_priv(struct net_device *dev)
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci	return (struct hfi1_netdev_priv *)&dev[1];
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline
708c2ecf20Sopenharmony_ciint hfi1_netdev_ctxt_count(struct hfi1_devdata *dd)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	return priv->num_rx_q;
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic inline
788c2ecf20Sopenharmony_cistruct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	return priv->rxq[ctxt].rcd;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline
868c2ecf20Sopenharmony_ciint hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata *dd)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	return priv->rmt_start;
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic inline
948c2ecf20Sopenharmony_civoid hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata *dd, int rmt_idx)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	priv->rmt_start = rmt_idx;
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciu32 hfi1_num_netdev_contexts(struct hfi1_devdata *dd, u32 available_contexts,
1028c2ecf20Sopenharmony_ci			     struct cpumask *cpu_mask);
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_civoid hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
1058c2ecf20Sopenharmony_civoid hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
1068c2ecf20Sopenharmony_ciint hfi1_netdev_rx_init(struct hfi1_devdata *dd);
1078c2ecf20Sopenharmony_ciint hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
1088c2ecf20Sopenharmony_ciint hfi1_netdev_alloc(struct hfi1_devdata *dd);
1098c2ecf20Sopenharmony_civoid hfi1_netdev_free(struct hfi1_devdata *dd);
1108c2ecf20Sopenharmony_ciint hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
1118c2ecf20Sopenharmony_civoid *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
1128c2ecf20Sopenharmony_civoid *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);
1138c2ecf20Sopenharmony_civoid *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* chip.c  */
1168c2ecf20Sopenharmony_ciint hfi1_netdev_rx_napi(struct napi_struct *napi, int budget);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#endif /* HFI1_NETDEV_H */
119