vnic.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef _HFI1_VNIC_H
  2. #define _HFI1_VNIC_H
  3. /*
  4. * Copyright(c) 2017 Intel Corporation.
  5. *
  6. * This file is provided under a dual BSD/GPLv2 license. When using or
  7. * redistributing this file, you may do so under either license.
  8. *
  9. * GPL LICENSE SUMMARY
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * BSD LICENSE
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * - Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * - Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * - Neither the name of Intel Corporation nor the names of its
  33. * contributors may be used to endorse or promote products derived
  34. * from this software without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  43. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  44. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. #include <rdma/opa_vnic.h>
  50. #include "hfi.h"
  51. #include "sdma.h"
  52. #define HFI1_VNIC_MAX_TXQ 16
  53. #define HFI1_VNIC_MAX_PAD 12
  54. /* L4 header definitions */
  55. #define HFI1_VNIC_L4_HDR_OFFSET OPA_VNIC_L2_HDR_LEN
  56. #define HFI1_VNIC_GET_L4_HDR(data) \
  57. (*((u16 *)((u8 *)(data) + HFI1_VNIC_L4_HDR_OFFSET)))
  58. #define HFI1_VNIC_GET_VESWID(data) \
  59. (HFI1_VNIC_GET_L4_HDR(data) & 0xFFF)
  60. /* Service class */
  61. #define HFI1_VNIC_SC_OFFSET_LOW 6
  62. #define HFI1_VNIC_SC_OFFSET_HI 7
  63. #define HFI1_VNIC_SC_SHIFT 4
  64. #define HFI1_VNIC_MAX_QUEUE 16
  65. /**
  66. * struct hfi1_vnic_sdma - VNIC per Tx ring SDMA information
  67. * @dd - device data pointer
  68. * @sde - sdma engine
  69. * @vinfo - vnic info pointer
  70. * @wait - iowait structure
  71. * @stx - sdma tx request
  72. * @state - vnic Tx ring SDMA state
  73. * @q_idx - vnic Tx queue index
  74. */
  75. struct hfi1_vnic_sdma {
  76. struct hfi1_devdata *dd;
  77. struct sdma_engine *sde;
  78. struct hfi1_vnic_vport_info *vinfo;
  79. struct iowait wait;
  80. struct sdma_txreq stx;
  81. unsigned int state;
  82. u8 q_idx;
  83. bool pkts_sent;
  84. };
  85. /**
  86. * struct hfi1_vnic_rx_queue - HFI1 VNIC receive queue
  87. * @idx: queue index
  88. * @vinfo: pointer to vport information
  89. * @netdev: network device
  90. * @napi: netdev napi structure
  91. * @skbq: queue of received socket buffers
  92. */
  93. struct hfi1_vnic_rx_queue {
  94. u8 idx;
  95. struct hfi1_vnic_vport_info *vinfo;
  96. struct net_device *netdev;
  97. struct napi_struct napi;
  98. struct sk_buff_head skbq;
  99. };
  100. /**
  101. * struct hfi1_vnic_vport_info - HFI1 VNIC virtual port information
  102. * @dd: device data pointer
  103. * @netdev: net device pointer
  104. * @flags: state flags
  105. * @lock: vport lock
  106. * @num_tx_q: number of transmit queues
  107. * @num_rx_q: number of receive queues
  108. * @vesw_id: virtual switch id
  109. * @rxq: Array of receive queues
  110. * @stats: per queue stats
  111. * @sdma: VNIC SDMA structure per TXQ
  112. */
  113. struct hfi1_vnic_vport_info {
  114. struct hfi1_devdata *dd;
  115. struct net_device *netdev;
  116. unsigned long flags;
  117. /* Lock used around state updates */
  118. struct mutex lock;
  119. u8 num_tx_q;
  120. u8 num_rx_q;
  121. u16 vesw_id;
  122. struct hfi1_vnic_rx_queue rxq[HFI1_NUM_VNIC_CTXT];
  123. struct opa_vnic_stats stats[HFI1_VNIC_MAX_QUEUE];
  124. struct hfi1_vnic_sdma sdma[HFI1_VNIC_MAX_TXQ];
  125. };
  126. #define v_dbg(format, arg...) \
  127. netdev_dbg(vinfo->netdev, format, ## arg)
  128. #define v_err(format, arg...) \
  129. netdev_err(vinfo->netdev, format, ## arg)
  130. #define v_info(format, arg...) \
  131. netdev_info(vinfo->netdev, format, ## arg)
  132. /* vnic hfi1 internal functions */
  133. void hfi1_vnic_setup(struct hfi1_devdata *dd);
  134. void hfi1_vnic_cleanup(struct hfi1_devdata *dd);
  135. int hfi1_vnic_txreq_init(struct hfi1_devdata *dd);
  136. void hfi1_vnic_txreq_deinit(struct hfi1_devdata *dd);
  137. void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet);
  138. void hfi1_vnic_sdma_init(struct hfi1_vnic_vport_info *vinfo);
  139. bool hfi1_vnic_sdma_write_avail(struct hfi1_vnic_vport_info *vinfo,
  140. u8 q_idx);
  141. /* vnic rdma netdev operations */
  142. struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
  143. u8 port_num,
  144. enum rdma_netdev_t type,
  145. const char *name,
  146. unsigned char name_assign_type,
  147. void (*setup)(struct net_device *));
  148. int hfi1_vnic_send_dma(struct hfi1_devdata *dd, u8 q_idx,
  149. struct hfi1_vnic_vport_info *vinfo,
  150. struct sk_buff *skb, u64 pbc, u8 plen);
  151. #endif /* _HFI1_VNIC_H */