netdev.h 2.9 KB

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