xref: /openbmc/linux/drivers/infiniband/hw/hfi1/netdev.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
16991abcbSKaike Wan /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
26991abcbSKaike Wan /*
36991abcbSKaike Wan  * Copyright(c) 2020 Intel Corporation.
46991abcbSKaike Wan  *
56991abcbSKaike Wan  */
66991abcbSKaike Wan 
76991abcbSKaike Wan #ifndef HFI1_NETDEV_H
86991abcbSKaike Wan #define HFI1_NETDEV_H
96991abcbSKaike Wan 
106991abcbSKaike Wan #include "hfi.h"
116991abcbSKaike Wan 
126991abcbSKaike Wan #include <linux/netdevice.h>
136991abcbSKaike Wan #include <linux/xarray.h>
146991abcbSKaike Wan 
156991abcbSKaike Wan /**
166991abcbSKaike Wan  * struct hfi1_netdev_rxq - Receive Queue for HFI
17*780278c2SMike Marciniszyn  * Both IPoIB and VNIC netdevices will be working on the rx abstraction.
186991abcbSKaike Wan  * @napi: napi object
19*780278c2SMike Marciniszyn  * @rx: ptr to netdev_rx
206991abcbSKaike Wan  * @rcd:  ptr to receive context data
216991abcbSKaike Wan  */
226991abcbSKaike Wan struct hfi1_netdev_rxq {
236991abcbSKaike Wan 	struct napi_struct napi;
24*780278c2SMike Marciniszyn 	struct hfi1_netdev_rx *rx;
256991abcbSKaike Wan 	struct hfi1_ctxtdata *rcd;
266991abcbSKaike Wan };
276991abcbSKaike Wan 
286991abcbSKaike Wan /*
296991abcbSKaike Wan  * Number of netdev contexts used. Ensure it is less than or equal to
306991abcbSKaike Wan  * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
316991abcbSKaike Wan  */
326991abcbSKaike Wan #define HFI1_MAX_NETDEV_CTXTS   8
336991abcbSKaike Wan 
346991abcbSKaike Wan /* Number of NETDEV RSM entries */
356991abcbSKaike Wan #define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS
366991abcbSKaike Wan 
376991abcbSKaike Wan /**
38*780278c2SMike Marciniszyn  * struct hfi1_netdev_rx: data required to setup and run HFI netdev.
39*780278c2SMike Marciniszyn  * @rx_napi:	the dummy netdevice to support "polling" the receive contexts
406991abcbSKaike Wan  * @dd:		hfi1_devdata
416991abcbSKaike Wan  * @rxq:	pointer to dummy netdev receive queues.
426991abcbSKaike Wan  * @num_rx_q:	number of receive queues
436991abcbSKaike Wan  * @rmt_index:	first free index in RMT Array
446991abcbSKaike Wan  * @msix_start: first free MSI-X interrupt vector.
456991abcbSKaike Wan  * @dev_tbl:	netdev table for unique identifier VNIC and IPoIb VLANs.
466991abcbSKaike Wan  * @enabled:	atomic counter of netdevs enabling receive queues.
476991abcbSKaike Wan  *		When 0 NAPI will be disabled.
486991abcbSKaike Wan  * @netdevs:	atomic counter of netdevs using dummy netdev.
496991abcbSKaike Wan  *		When 0 receive queues will be freed.
506991abcbSKaike Wan  */
51*780278c2SMike Marciniszyn struct hfi1_netdev_rx {
52*780278c2SMike Marciniszyn 	struct net_device rx_napi;
536991abcbSKaike Wan 	struct hfi1_devdata *dd;
546991abcbSKaike Wan 	struct hfi1_netdev_rxq *rxq;
556991abcbSKaike Wan 	int num_rx_q;
566991abcbSKaike Wan 	int rmt_start;
576991abcbSKaike Wan 	struct xarray dev_tbl;
586991abcbSKaike Wan 	/* count of enabled napi polls */
596991abcbSKaike Wan 	atomic_t enabled;
606991abcbSKaike Wan 	/* count of netdevs on top */
616991abcbSKaike Wan 	atomic_t netdevs;
626991abcbSKaike Wan };
636991abcbSKaike Wan 
646991abcbSKaike Wan static inline
hfi1_netdev_ctxt_count(struct hfi1_devdata * dd)656991abcbSKaike Wan int hfi1_netdev_ctxt_count(struct hfi1_devdata *dd)
666991abcbSKaike Wan {
67*780278c2SMike Marciniszyn 	return dd->netdev_rx->num_rx_q;
686991abcbSKaike Wan }
696991abcbSKaike Wan 
706991abcbSKaike Wan static inline
hfi1_netdev_get_ctxt(struct hfi1_devdata * dd,int ctxt)716991abcbSKaike Wan struct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
726991abcbSKaike Wan {
73*780278c2SMike Marciniszyn 	return dd->netdev_rx->rxq[ctxt].rcd;
746991abcbSKaike Wan }
756991abcbSKaike Wan 
764730f4a6SGrzegorz Andrejczuk static inline
hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata * dd)774730f4a6SGrzegorz Andrejczuk int hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata *dd)
784730f4a6SGrzegorz Andrejczuk {
79*780278c2SMike Marciniszyn 	return dd->netdev_rx->rmt_start;
804730f4a6SGrzegorz Andrejczuk }
814730f4a6SGrzegorz Andrejczuk 
824730f4a6SGrzegorz Andrejczuk static inline
hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata * dd,int rmt_idx)834730f4a6SGrzegorz Andrejczuk void hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata *dd, int rmt_idx)
844730f4a6SGrzegorz Andrejczuk {
85*780278c2SMike Marciniszyn 	dd->netdev_rx->rmt_start = rmt_idx;
864730f4a6SGrzegorz Andrejczuk }
874730f4a6SGrzegorz Andrejczuk 
884730f4a6SGrzegorz Andrejczuk u32 hfi1_num_netdev_contexts(struct hfi1_devdata *dd, u32 available_contexts,
894730f4a6SGrzegorz Andrejczuk 			     struct cpumask *cpu_mask);
904730f4a6SGrzegorz Andrejczuk 
91370caa5bSGrzegorz Andrejczuk void hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
92370caa5bSGrzegorz Andrejczuk void hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
93370caa5bSGrzegorz Andrejczuk int hfi1_netdev_rx_init(struct hfi1_devdata *dd);
94370caa5bSGrzegorz Andrejczuk int hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
95*780278c2SMike Marciniszyn int hfi1_alloc_rx(struct hfi1_devdata *dd);
96*780278c2SMike Marciniszyn void hfi1_free_rx(struct hfi1_devdata *dd);
976991abcbSKaike Wan int hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
986991abcbSKaike Wan void *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
996991abcbSKaike Wan void *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);
1006991abcbSKaike Wan void *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id);
1016991abcbSKaike Wan 
1020bae02d5SGrzegorz Andrejczuk /* chip.c  */
1030bae02d5SGrzegorz Andrejczuk int hfi1_netdev_rx_napi(struct napi_struct *napi, int budget);
1040bae02d5SGrzegorz Andrejczuk 
1056991abcbSKaike Wan #endif /* HFI1_NETDEV_H */
106