162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright(c) 2020 Intel Corporation.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef HFI1_NETDEV_H
862306a36Sopenharmony_ci#define HFI1_NETDEV_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include "hfi.h"
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/netdevice.h>
1362306a36Sopenharmony_ci#include <linux/xarray.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/**
1662306a36Sopenharmony_ci * struct hfi1_netdev_rxq - Receive Queue for HFI
1762306a36Sopenharmony_ci * Both IPoIB and VNIC netdevices will be working on the rx abstraction.
1862306a36Sopenharmony_ci * @napi: napi object
1962306a36Sopenharmony_ci * @rx: ptr to netdev_rx
2062306a36Sopenharmony_ci * @rcd:  ptr to receive context data
2162306a36Sopenharmony_ci */
2262306a36Sopenharmony_cistruct hfi1_netdev_rxq {
2362306a36Sopenharmony_ci	struct napi_struct napi;
2462306a36Sopenharmony_ci	struct hfi1_netdev_rx *rx;
2562306a36Sopenharmony_ci	struct hfi1_ctxtdata *rcd;
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * Number of netdev contexts used. Ensure it is less than or equal to
3062306a36Sopenharmony_ci * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ci#define HFI1_MAX_NETDEV_CTXTS   8
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* Number of NETDEV RSM entries */
3562306a36Sopenharmony_ci#define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci/**
3862306a36Sopenharmony_ci * struct hfi1_netdev_rx: data required to setup and run HFI netdev.
3962306a36Sopenharmony_ci * @rx_napi:	the dummy netdevice to support "polling" the receive contexts
4062306a36Sopenharmony_ci * @dd:		hfi1_devdata
4162306a36Sopenharmony_ci * @rxq:	pointer to dummy netdev receive queues.
4262306a36Sopenharmony_ci * @num_rx_q:	number of receive queues
4362306a36Sopenharmony_ci * @rmt_index:	first free index in RMT Array
4462306a36Sopenharmony_ci * @msix_start: first free MSI-X interrupt vector.
4562306a36Sopenharmony_ci * @dev_tbl:	netdev table for unique identifier VNIC and IPoIb VLANs.
4662306a36Sopenharmony_ci * @enabled:	atomic counter of netdevs enabling receive queues.
4762306a36Sopenharmony_ci *		When 0 NAPI will be disabled.
4862306a36Sopenharmony_ci * @netdevs:	atomic counter of netdevs using dummy netdev.
4962306a36Sopenharmony_ci *		When 0 receive queues will be freed.
5062306a36Sopenharmony_ci */
5162306a36Sopenharmony_cistruct hfi1_netdev_rx {
5262306a36Sopenharmony_ci	struct net_device rx_napi;
5362306a36Sopenharmony_ci	struct hfi1_devdata *dd;
5462306a36Sopenharmony_ci	struct hfi1_netdev_rxq *rxq;
5562306a36Sopenharmony_ci	int num_rx_q;
5662306a36Sopenharmony_ci	int rmt_start;
5762306a36Sopenharmony_ci	struct xarray dev_tbl;
5862306a36Sopenharmony_ci	/* count of enabled napi polls */
5962306a36Sopenharmony_ci	atomic_t enabled;
6062306a36Sopenharmony_ci	/* count of netdevs on top */
6162306a36Sopenharmony_ci	atomic_t netdevs;
6262306a36Sopenharmony_ci};
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_cistatic inline
6562306a36Sopenharmony_ciint hfi1_netdev_ctxt_count(struct hfi1_devdata *dd)
6662306a36Sopenharmony_ci{
6762306a36Sopenharmony_ci	return dd->netdev_rx->num_rx_q;
6862306a36Sopenharmony_ci}
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistatic inline
7162306a36Sopenharmony_cistruct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
7262306a36Sopenharmony_ci{
7362306a36Sopenharmony_ci	return dd->netdev_rx->rxq[ctxt].rcd;
7462306a36Sopenharmony_ci}
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cistatic inline
7762306a36Sopenharmony_ciint hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata *dd)
7862306a36Sopenharmony_ci{
7962306a36Sopenharmony_ci	return dd->netdev_rx->rmt_start;
8062306a36Sopenharmony_ci}
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistatic inline
8362306a36Sopenharmony_civoid hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata *dd, int rmt_idx)
8462306a36Sopenharmony_ci{
8562306a36Sopenharmony_ci	dd->netdev_rx->rmt_start = rmt_idx;
8662306a36Sopenharmony_ci}
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ciu32 hfi1_num_netdev_contexts(struct hfi1_devdata *dd, u32 available_contexts,
8962306a36Sopenharmony_ci			     struct cpumask *cpu_mask);
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_civoid hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
9262306a36Sopenharmony_civoid hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
9362306a36Sopenharmony_ciint hfi1_netdev_rx_init(struct hfi1_devdata *dd);
9462306a36Sopenharmony_ciint hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
9562306a36Sopenharmony_ciint hfi1_alloc_rx(struct hfi1_devdata *dd);
9662306a36Sopenharmony_civoid hfi1_free_rx(struct hfi1_devdata *dd);
9762306a36Sopenharmony_ciint hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
9862306a36Sopenharmony_civoid *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
9962306a36Sopenharmony_civoid *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);
10062306a36Sopenharmony_civoid *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id);
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/* chip.c  */
10362306a36Sopenharmony_ciint hfi1_netdev_rx_napi(struct napi_struct *napi, int budget);
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#endif /* HFI1_NETDEV_H */
106