Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
0002 /*
0003  * Copyright(c) 2020 Intel Corporation.
0004  *
0005  */
0006 
0007 #ifndef HFI1_NETDEV_H
0008 #define HFI1_NETDEV_H
0009 
0010 #include "hfi.h"
0011 
0012 #include <linux/netdevice.h>
0013 #include <linux/xarray.h>
0014 
0015 /**
0016  * struct hfi1_netdev_rxq - Receive Queue for HFI
0017  * Both IPoIB and VNIC netdevices will be working on the rx abstraction.
0018  * @napi: napi object
0019  * @rx: ptr to netdev_rx
0020  * @rcd:  ptr to receive context data
0021  */
0022 struct hfi1_netdev_rxq {
0023     struct napi_struct napi;
0024     struct hfi1_netdev_rx *rx;
0025     struct hfi1_ctxtdata *rcd;
0026 };
0027 
0028 /*
0029  * Number of netdev contexts used. Ensure it is less than or equal to
0030  * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
0031  */
0032 #define HFI1_MAX_NETDEV_CTXTS   8
0033 
0034 /* Number of NETDEV RSM entries */
0035 #define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS
0036 
0037 /**
0038  * struct hfi1_netdev_rx: data required to setup and run HFI netdev.
0039  * @rx_napi:    the dummy netdevice to support "polling" the receive contexts
0040  * @dd:     hfi1_devdata
0041  * @rxq:    pointer to dummy netdev receive queues.
0042  * @num_rx_q:   number of receive queues
0043  * @rmt_index:  first free index in RMT Array
0044  * @msix_start: first free MSI-X interrupt vector.
0045  * @dev_tbl:    netdev table for unique identifier VNIC and IPoIb VLANs.
0046  * @enabled:    atomic counter of netdevs enabling receive queues.
0047  *      When 0 NAPI will be disabled.
0048  * @netdevs:    atomic counter of netdevs using dummy netdev.
0049  *      When 0 receive queues will be freed.
0050  */
0051 struct hfi1_netdev_rx {
0052     struct net_device rx_napi;
0053     struct hfi1_devdata *dd;
0054     struct hfi1_netdev_rxq *rxq;
0055     int num_rx_q;
0056     int rmt_start;
0057     struct xarray dev_tbl;
0058     /* count of enabled napi polls */
0059     atomic_t enabled;
0060     /* count of netdevs on top */
0061     atomic_t netdevs;
0062 };
0063 
0064 static inline
0065 int hfi1_netdev_ctxt_count(struct hfi1_devdata *dd)
0066 {
0067     return dd->netdev_rx->num_rx_q;
0068 }
0069 
0070 static inline
0071 struct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
0072 {
0073     return dd->netdev_rx->rxq[ctxt].rcd;
0074 }
0075 
0076 static inline
0077 int hfi1_netdev_get_free_rmt_idx(struct hfi1_devdata *dd)
0078 {
0079     return dd->netdev_rx->rmt_start;
0080 }
0081 
0082 static inline
0083 void hfi1_netdev_set_free_rmt_idx(struct hfi1_devdata *dd, int rmt_idx)
0084 {
0085     dd->netdev_rx->rmt_start = rmt_idx;
0086 }
0087 
0088 u32 hfi1_num_netdev_contexts(struct hfi1_devdata *dd, u32 available_contexts,
0089                  struct cpumask *cpu_mask);
0090 
0091 void hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
0092 void hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
0093 int hfi1_netdev_rx_init(struct hfi1_devdata *dd);
0094 int hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
0095 int hfi1_alloc_rx(struct hfi1_devdata *dd);
0096 void hfi1_free_rx(struct hfi1_devdata *dd);
0097 int hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
0098 void *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
0099 void *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);
0100 void *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id);
0101 
0102 /* chip.c  */
0103 int hfi1_netdev_rx_napi(struct napi_struct *napi, int budget);
0104 
0105 #endif /* HFI1_NETDEV_H */