Loading...
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 * Both IPoIB and VNIC 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 */
22struct hfi1_netdev_rxq {
23 struct napi_struct napi;
24 struct hfi1_netdev_rx *rx;
25 struct hfi1_ctxtdata *rcd;
26};
27
28/*
29 * Number of netdev contexts used. Ensure it is less than or equal to
30 * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
31 */
32#define HFI1_MAX_NETDEV_CTXTS 8
33
34/* Number of NETDEV RSM entries */
35#define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS
36
37/**
38 * struct hfi1_netdev_rx: data required to setup and run HFI netdev.
39 * @rx_napi: the dummy netdevice to support "polling" the receive contexts
40 * @dd: hfi1_devdata
41 * @rxq: pointer to dummy netdev receive queues.
42 * @num_rx_q: number of receive queues
43 * @rmt_index: first free index in RMT Array
44 * @msix_start: first free MSI-X interrupt vector.
45 * @dev_tbl: netdev table for unique identifier VNIC and IPoIb VLANs.
46 * @enabled: atomic counter of netdevs enabling receive queues.
47 * When 0 NAPI will be disabled.
48 * @netdevs: atomic counter of netdevs using dummy netdev.
49 * When 0 receive queues will be freed.
50 */
51struct hfi1_netdev_rx {
52 struct net_device rx_napi;
53 struct hfi1_devdata *dd;
54 struct hfi1_netdev_rxq *rxq;
55 int num_rx_q;
56 int rmt_start;
57 struct xarray dev_tbl;
58 /* count of enabled napi polls */
59 atomic_t enabled;
60 /* count of netdevs on top */
61 atomic_t netdevs;
62};
63
64static inline
65int hfi1_netdev_ctxt_count(struct hfi1_devdata *dd)
66{
67 return dd->netdev_rx->num_rx_q;
68}
69
70static inline
71struct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
72{
73 return dd->netdev_rx->rxq[ctxt].rcd;
74}
75
76static inline
77int hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata *dd)
78{
79 return dd->netdev_rx->rmt_start;
80}
81
82static inline
83void hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata *dd, int rmt_idx)
84{
85 dd->netdev_rx->rmt_start = rmt_idx;
86}
87
88u32 hfi1_num_netdev_contexts(struct hfi1_devdata *dd, u32 available_contexts,
89 struct cpumask *cpu_mask);
90
91void hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
92void hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
93int hfi1_netdev_rx_init(struct hfi1_devdata *dd);
94int hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
95int hfi1_alloc_rx(struct hfi1_devdata *dd);
96void hfi1_free_rx(struct hfi1_devdata *dd);
97int hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
98void *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
99void *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);
100void *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id);
101
102/* chip.c */
103int hfi1_netdev_rx_napi(struct napi_struct *napi, int budget);
104
105#endif /* HFI1_NETDEV_H */
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 * dummy netdev. Both IPoIB and VNIC netdevices will be working on
18 * top of this device.
19 * @napi: napi object
20 * @priv: ptr to netdev_priv
21 * @rcd: ptr to receive context data
22 */
23struct hfi1_netdev_rxq {
24 struct napi_struct napi;
25 struct hfi1_netdev_priv *priv;
26 struct hfi1_ctxtdata *rcd;
27};
28
29/*
30 * Number of netdev contexts used. Ensure it is less than or equal to
31 * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
32 */
33#define HFI1_MAX_NETDEV_CTXTS 8
34
35/* Number of NETDEV RSM entries */
36#define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS
37
38/**
39 * struct hfi1_netdev_priv: data required to setup and run HFI netdev.
40 * @dd: hfi1_devdata
41 * @rxq: pointer to dummy netdev receive queues.
42 * @num_rx_q: number of receive queues
43 * @rmt_index: first free index in RMT Array
44 * @msix_start: first free MSI-X interrupt vector.
45 * @dev_tbl: netdev table for unique identifier VNIC and IPoIb VLANs.
46 * @enabled: atomic counter of netdevs enabling receive queues.
47 * When 0 NAPI will be disabled.
48 * @netdevs: atomic counter of netdevs using dummy netdev.
49 * When 0 receive queues will be freed.
50 */
51struct hfi1_netdev_priv {
52 struct hfi1_devdata *dd;
53 struct hfi1_netdev_rxq *rxq;
54 int num_rx_q;
55 int rmt_start;
56 struct xarray dev_tbl;
57 /* count of enabled napi polls */
58 atomic_t enabled;
59 /* count of netdevs on top */
60 atomic_t netdevs;
61};
62
63static inline
64struct hfi1_netdev_priv *hfi1_netdev_priv(struct net_device *dev)
65{
66 return (struct hfi1_netdev_priv *)&dev[1];
67}
68
69static inline
70int hfi1_netdev_ctxt_count(struct hfi1_devdata *dd)
71{
72 struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
73
74 return priv->num_rx_q;
75}
76
77static inline
78struct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
79{
80 struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
81
82 return priv->rxq[ctxt].rcd;
83}
84
85static inline
86int hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata *dd)
87{
88 struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
89
90 return priv->rmt_start;
91}
92
93static inline
94void hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata *dd, int rmt_idx)
95{
96 struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev);
97
98 priv->rmt_start = rmt_idx;
99}
100
101u32 hfi1_num_netdev_contexts(struct hfi1_devdata *dd, u32 available_contexts,
102 struct cpumask *cpu_mask);
103
104void hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
105void hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
106int hfi1_netdev_rx_init(struct hfi1_devdata *dd);
107int hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
108int hfi1_netdev_alloc(struct hfi1_devdata *dd);
109void hfi1_netdev_free(struct hfi1_devdata *dd);
110int hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
111void *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
112void *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);
113void *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id);
114
115/* chip.c */
116int hfi1_netdev_rx_napi(struct napi_struct *napi, int budget);
117
118#endif /* HFI1_NETDEV_H */