xref: /linux/drivers/infiniband/hw/hfi1/netdev.h (revision 53597deca0e38c30e6cd4ba2114fa42d2bcd85bb)
1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /*
3  * Copyright(c) 2020 Intel Corporation.
4  *
5  */
6 
7 #ifndef HFI1_NETDEV_H
8 #define HFI1_NETDEV_H
9 
10 #include "hfi.h"
11 
12 #include <linux/netdevice.h>
13 #include <linux/xarray.h>
14 
15 /**
16  * struct hfi1_netdev_rxq - Receive Queue for HFI
17  * IPoIB netdevices will be working on the rx abstraction.
18  * @napi: napi object
19  * @rx: ptr to netdev_rx
20  * @rcd:  ptr to receive context data
21  */
22 struct hfi1_netdev_rxq {
23 	struct napi_struct napi;
24 	struct hfi1_netdev_rx *rx;
25 	struct hfi1_ctxtdata *rcd;
26 };
27 
28 #define HFI1_MAX_NETDEV_CTXTS   8
29 
30 /* Number of NETDEV RSM entries */
31 #define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS
32 
33 /**
34  * struct hfi1_netdev_rx: data required to setup and run HFI netdev.
35  * @rx_napi:	the dummy netdevice to support "polling" the receive contexts
36  * @dd:		hfi1_devdata
37  * @rxq:	pointer to dummy netdev receive queues.
38  * @num_rx_q:	number of receive queues
39  * @rmt_index:	first free index in RMT Array
40  * @msix_start: first free MSI-X interrupt vector.
41  * @dev_tbl:	netdev table for unique identifier IPoIb VLANs.
42  * @enabled:	atomic counter of netdevs enabling receive queues.
43  *		When 0 NAPI will be disabled.
44  * @netdevs:	atomic counter of netdevs using dummy netdev.
45  *		When 0 receive queues will be freed.
46  */
47 struct hfi1_netdev_rx {
48 	struct net_device *rx_napi;
49 	struct hfi1_devdata *dd;
50 	struct hfi1_netdev_rxq *rxq;
51 	int num_rx_q;
52 	int rmt_start;
53 	struct xarray dev_tbl;
54 	/* count of enabled napi polls */
55 	atomic_t enabled;
56 	/* count of netdevs on top */
57 	atomic_t netdevs;
58 };
59 
60 static inline
61 int hfi1_netdev_ctxt_count(struct hfi1_devdata *dd)
62 {
63 	return dd->netdev_rx->num_rx_q;
64 }
65 
66 static inline
67 struct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
68 {
69 	return dd->netdev_rx->rxq[ctxt].rcd;
70 }
71 
72 static inline
73 int hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata *dd)
74 {
75 	return dd->netdev_rx->rmt_start;
76 }
77 
78 static inline
79 void hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata *dd, int rmt_idx)
80 {
81 	dd->netdev_rx->rmt_start = rmt_idx;
82 }
83 
84 u32 hfi1_num_netdev_contexts(struct hfi1_devdata *dd, u32 available_contexts,
85 			     struct cpumask *cpu_mask);
86 
87 void hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
88 void hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
89 int hfi1_netdev_rx_init(struct hfi1_devdata *dd);
90 int hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
91 int hfi1_alloc_rx(struct hfi1_devdata *dd);
92 void hfi1_free_rx(struct hfi1_devdata *dd);
93 int hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
94 void *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
95 void *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);
96 void *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id);
97 
98 /* chip.c  */
99 int hfi1_netdev_rx_napi(struct napi_struct *napi, int budget);
100 
101 #endif /* HFI1_NETDEV_H */
102