ipoib.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
  2. /*
  3. * Copyright(c) 2020 Intel Corporation.
  4. *
  5. */
  6. /*
  7. * This file contains HFI1 support for IPOIB functionality
  8. */
  9. #ifndef HFI1_IPOIB_H
  10. #define HFI1_IPOIB_H
  11. #include <linux/types.h>
  12. #include <linux/stddef.h>
  13. #include <linux/atomic.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/slab.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/list.h>
  18. #include <linux/if_infiniband.h>
  19. #include "hfi.h"
  20. #include "iowait.h"
  21. #include "netdev.h"
  22. #include <rdma/ib_verbs.h>
  23. #define HFI1_IPOIB_ENTROPY_SHIFT 24
  24. #define HFI1_IPOIB_TXREQ_NAME_LEN 32
  25. #define HFI1_IPOIB_PSEUDO_LEN 20
  26. #define HFI1_IPOIB_ENCAP_LEN 4
  27. struct hfi1_ipoib_dev_priv;
  28. union hfi1_ipoib_flow {
  29. u16 as_int;
  30. struct {
  31. u8 tx_queue;
  32. u8 sc5;
  33. } __attribute__((__packed__));
  34. };
  35. /**
  36. * struct ipoib_txreq - IPOIB transmit descriptor
  37. * @txreq: sdma transmit request
  38. * @sdma_hdr: 9b ib headers
  39. * @sdma_status: status returned by sdma engine
  40. * @complete: non-zero implies complete
  41. * @priv: ipoib netdev private data
  42. * @txq: txq on which skb was output
  43. * @skb: skb to send
  44. */
  45. struct ipoib_txreq {
  46. struct sdma_txreq txreq;
  47. struct hfi1_sdma_header *sdma_hdr;
  48. int sdma_status;
  49. int complete;
  50. struct hfi1_ipoib_dev_priv *priv;
  51. struct hfi1_ipoib_txq *txq;
  52. struct sk_buff *skb;
  53. };
  54. /**
  55. * struct hfi1_ipoib_circ_buf - List of items to be processed
  56. * @items: ring of items each a power of two size
  57. * @max_items: max items + 1 that the ring can contain
  58. * @shift: log2 of size for getting txreq
  59. * @sent_txreqs: count of txreqs posted to sdma
  60. * @tail: ring tail
  61. * @stops: count of stops of queue
  62. * @ring_full: ring has been filled
  63. * @no_desc: descriptor shortage seen
  64. * @complete_txreqs: count of txreqs completed by sdma
  65. * @head: ring head
  66. */
  67. struct hfi1_ipoib_circ_buf {
  68. void *items;
  69. u32 max_items;
  70. u32 shift;
  71. /* consumer cache line */
  72. u64 ____cacheline_aligned_in_smp sent_txreqs;
  73. u32 avail;
  74. u32 tail;
  75. atomic_t stops;
  76. atomic_t ring_full;
  77. atomic_t no_desc;
  78. /* producer cache line */
  79. u64 ____cacheline_aligned_in_smp complete_txreqs;
  80. u32 head;
  81. };
  82. /**
  83. * struct hfi1_ipoib_txq - IPOIB per Tx queue information
  84. * @priv: private pointer
  85. * @sde: sdma engine
  86. * @tx_list: tx request list
  87. * @sent_txreqs: count of txreqs posted to sdma
  88. * @flow: tracks when list needs to be flushed for a flow change
  89. * @q_idx: ipoib Tx queue index
  90. * @pkts_sent: indicator packets have been sent from this queue
  91. * @wait: iowait structure
  92. * @napi: pointer to tx napi interface
  93. * @tx_ring: ring of ipoib txreqs to be reaped by napi callback
  94. */
  95. struct hfi1_ipoib_txq {
  96. struct napi_struct napi;
  97. struct hfi1_ipoib_dev_priv *priv;
  98. struct sdma_engine *sde;
  99. struct list_head tx_list;
  100. union hfi1_ipoib_flow flow;
  101. u8 q_idx;
  102. bool pkts_sent;
  103. struct iowait wait;
  104. struct hfi1_ipoib_circ_buf ____cacheline_aligned_in_smp tx_ring;
  105. };
  106. struct hfi1_ipoib_dev_priv {
  107. struct hfi1_devdata *dd;
  108. struct net_device *netdev;
  109. struct ib_device *device;
  110. struct hfi1_ipoib_txq *txqs;
  111. const struct net_device_ops *netdev_ops;
  112. struct rvt_qp *qp;
  113. u32 qkey;
  114. u16 pkey;
  115. u16 pkey_index;
  116. u8 port_num;
  117. };
  118. /* hfi1 ipoib rdma netdev's private data structure */
  119. struct hfi1_ipoib_rdma_netdev {
  120. struct rdma_netdev rn; /* keep this first */
  121. /* followed by device private data */
  122. struct hfi1_ipoib_dev_priv dev_priv;
  123. };
  124. static inline struct hfi1_ipoib_dev_priv *
  125. hfi1_ipoib_priv(const struct net_device *dev)
  126. {
  127. return &((struct hfi1_ipoib_rdma_netdev *)netdev_priv(dev))->dev_priv;
  128. }
  129. int hfi1_ipoib_send(struct net_device *dev,
  130. struct sk_buff *skb,
  131. struct ib_ah *address,
  132. u32 dqpn);
  133. int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv);
  134. void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv);
  135. int hfi1_ipoib_rxq_init(struct net_device *dev);
  136. void hfi1_ipoib_rxq_deinit(struct net_device *dev);
  137. void hfi1_ipoib_napi_tx_enable(struct net_device *dev);
  138. void hfi1_ipoib_napi_tx_disable(struct net_device *dev);
  139. struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq,
  140. int size, void *data);
  141. int hfi1_ipoib_rn_get_params(struct ib_device *device,
  142. u32 port_num,
  143. enum rdma_netdev_t type,
  144. struct rdma_netdev_alloc_params *params);
  145. void hfi1_ipoib_tx_timeout(struct net_device *dev, unsigned int q);
  146. #endif /* _IPOIB_H */