qed_ll2_if.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
  2. /* QLogic qed NIC Driver
  3. * Copyright (c) 2015-2017 QLogic Corporation
  4. * Copyright (c) 2019-2020 Marvell International Ltd.
  5. */
  6. #ifndef _QED_LL2_IF_H
  7. #define _QED_LL2_IF_H
  8. #include <linux/types.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/pci.h>
  12. #include <linux/skbuff.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/qed/qed_if.h>
  16. enum qed_ll2_conn_type {
  17. QED_LL2_TYPE_FCOE,
  18. QED_LL2_TYPE_TCP_ULP,
  19. QED_LL2_TYPE_TEST,
  20. QED_LL2_TYPE_OOO,
  21. QED_LL2_TYPE_RESERVED2,
  22. QED_LL2_TYPE_ROCE,
  23. QED_LL2_TYPE_IWARP,
  24. QED_LL2_TYPE_RESERVED3,
  25. MAX_QED_LL2_CONN_TYPE
  26. };
  27. enum qed_ll2_rx_conn_type {
  28. QED_LL2_RX_TYPE_LEGACY,
  29. QED_LL2_RX_TYPE_CTX,
  30. MAX_QED_LL2_RX_CONN_TYPE
  31. };
  32. enum qed_ll2_roce_flavor_type {
  33. QED_LL2_ROCE,
  34. QED_LL2_RROCE,
  35. MAX_QED_LL2_ROCE_FLAVOR_TYPE
  36. };
  37. enum qed_ll2_tx_dest {
  38. QED_LL2_TX_DEST_NW, /* Light L2 TX Destination to the Network */
  39. QED_LL2_TX_DEST_LB, /* Light L2 TX Destination to the Loopback */
  40. QED_LL2_TX_DEST_DROP, /* Light L2 Drop the TX packet */
  41. QED_LL2_TX_DEST_MAX
  42. };
  43. enum qed_ll2_error_handle {
  44. QED_LL2_DROP_PACKET,
  45. QED_LL2_DO_NOTHING,
  46. QED_LL2_ASSERT,
  47. };
  48. struct qed_ll2_stats {
  49. u64 gsi_invalid_hdr;
  50. u64 gsi_invalid_pkt_length;
  51. u64 gsi_unsupported_pkt_typ;
  52. u64 gsi_crcchksm_error;
  53. u64 packet_too_big_discard;
  54. u64 no_buff_discard;
  55. u64 rcv_ucast_bytes;
  56. u64 rcv_mcast_bytes;
  57. u64 rcv_bcast_bytes;
  58. u64 rcv_ucast_pkts;
  59. u64 rcv_mcast_pkts;
  60. u64 rcv_bcast_pkts;
  61. u64 sent_ucast_bytes;
  62. u64 sent_mcast_bytes;
  63. u64 sent_bcast_bytes;
  64. u64 sent_ucast_pkts;
  65. u64 sent_mcast_pkts;
  66. u64 sent_bcast_pkts;
  67. };
  68. struct qed_ll2_comp_rx_data {
  69. void *cookie;
  70. dma_addr_t rx_buf_addr;
  71. u16 parse_flags;
  72. u16 err_flags;
  73. u16 vlan;
  74. bool b_last_packet;
  75. u8 connection_handle;
  76. union {
  77. u16 packet_length;
  78. u16 data_length;
  79. } length;
  80. u32 opaque_data_0;
  81. u32 opaque_data_1;
  82. /* GSI only */
  83. u32 src_qp;
  84. u16 qp_id;
  85. union {
  86. u8 placement_offset;
  87. u8 data_length_error;
  88. } u;
  89. };
  90. typedef
  91. void (*qed_ll2_complete_rx_packet_cb)(void *cxt,
  92. struct qed_ll2_comp_rx_data *data);
  93. typedef
  94. void (*qed_ll2_release_rx_packet_cb)(void *cxt,
  95. u8 connection_handle,
  96. void *cookie,
  97. dma_addr_t rx_buf_addr,
  98. bool b_last_packet);
  99. typedef
  100. void (*qed_ll2_complete_tx_packet_cb)(void *cxt,
  101. u8 connection_handle,
  102. void *cookie,
  103. dma_addr_t first_frag_addr,
  104. bool b_last_fragment,
  105. bool b_last_packet);
  106. typedef
  107. void (*qed_ll2_release_tx_packet_cb)(void *cxt,
  108. u8 connection_handle,
  109. void *cookie,
  110. dma_addr_t first_frag_addr,
  111. bool b_last_fragment, bool b_last_packet);
  112. typedef
  113. void (*qed_ll2_slowpath_cb)(void *cxt, u8 connection_handle,
  114. u32 opaque_data_0, u32 opaque_data_1);
  115. struct qed_ll2_cbs {
  116. qed_ll2_complete_rx_packet_cb rx_comp_cb;
  117. qed_ll2_release_rx_packet_cb rx_release_cb;
  118. qed_ll2_complete_tx_packet_cb tx_comp_cb;
  119. qed_ll2_release_tx_packet_cb tx_release_cb;
  120. qed_ll2_slowpath_cb slowpath_cb;
  121. void *cookie;
  122. };
  123. struct qed_ll2_acquire_data_inputs {
  124. enum qed_ll2_rx_conn_type rx_conn_type;
  125. enum qed_ll2_conn_type conn_type;
  126. u16 mtu;
  127. u16 rx_num_desc;
  128. u16 rx_num_ooo_buffers;
  129. u8 rx_drop_ttl0_flg;
  130. u8 rx_vlan_removal_en;
  131. u16 tx_num_desc;
  132. u8 tx_max_bds_per_packet;
  133. u8 tx_tc;
  134. enum qed_ll2_tx_dest tx_dest;
  135. enum qed_ll2_error_handle ai_err_packet_too_big;
  136. enum qed_ll2_error_handle ai_err_no_buf;
  137. bool secondary_queue;
  138. u8 gsi_enable;
  139. };
  140. struct qed_ll2_acquire_data {
  141. struct qed_ll2_acquire_data_inputs input;
  142. const struct qed_ll2_cbs *cbs;
  143. /* Output container for LL2 connection's handle */
  144. u8 *p_connection_handle;
  145. };
  146. struct qed_ll2_tx_pkt_info {
  147. void *cookie;
  148. dma_addr_t first_frag;
  149. enum qed_ll2_tx_dest tx_dest;
  150. enum qed_ll2_roce_flavor_type qed_roce_flavor;
  151. u16 vlan;
  152. u16 l4_hdr_offset_w; /* from start of packet */
  153. u16 first_frag_len;
  154. u8 num_of_bds;
  155. u8 bd_flags;
  156. bool enable_ip_cksum;
  157. bool enable_l4_cksum;
  158. bool calc_ip_len;
  159. bool remove_stag;
  160. };
  161. #define QED_LL2_UNUSED_HANDLE (0xff)
  162. struct qed_ll2_cb_ops {
  163. int (*rx_cb)(void *, struct sk_buff *, u32, u32);
  164. int (*tx_cb)(void *, struct sk_buff *, bool);
  165. };
  166. struct qed_ll2_params {
  167. u16 mtu;
  168. bool drop_ttl0_packets;
  169. bool rx_vlan_stripping;
  170. u8 tx_tc;
  171. bool frags_mapped;
  172. u8 ll2_mac_address[ETH_ALEN];
  173. };
  174. enum qed_ll2_xmit_flags {
  175. /* FIP discovery packet */
  176. QED_LL2_XMIT_FLAGS_FIP_DISCOVERY
  177. };
  178. struct qed_ll2_ops {
  179. /**
  180. * start(): Initializes ll2.
  181. *
  182. * @cdev: Qed dev pointer.
  183. * @params: Protocol driver configuration for the ll2.
  184. *
  185. * Return: 0 on success, otherwise error value.
  186. */
  187. int (*start)(struct qed_dev *cdev, struct qed_ll2_params *params);
  188. /**
  189. * stop(): Stops the ll2
  190. *
  191. * @cdev: Qed dev pointer.
  192. *
  193. * Return: 0 on success, otherwise error value.
  194. */
  195. int (*stop)(struct qed_dev *cdev);
  196. /**
  197. * start_xmit(): Transmits an skb over the ll2 interface
  198. *
  199. * @cdev: Qed dev pointer.
  200. * @skb: SKB.
  201. * @xmit_flags: Transmit options defined by the enum qed_ll2_xmit_flags.
  202. *
  203. * Return: 0 on success, otherwise error value.
  204. */
  205. int (*start_xmit)(struct qed_dev *cdev, struct sk_buff *skb,
  206. unsigned long xmit_flags);
  207. /**
  208. * register_cb_ops(): Protocol driver register the callback for Rx/Tx
  209. * packets. Should be called before `start'.
  210. *
  211. * @cdev: Qed dev pointer.
  212. * @cookie: to be passed to the callback functions.
  213. * @ops: the callback functions to register for Rx / Tx.
  214. *
  215. * Return: 0 on success, otherwise error value.
  216. */
  217. void (*register_cb_ops)(struct qed_dev *cdev,
  218. const struct qed_ll2_cb_ops *ops,
  219. void *cookie);
  220. /**
  221. * get_stats(): Get LL2 related statistics.
  222. *
  223. * @cdev: Qed dev pointer.
  224. * @stats: Pointer to struct that would be filled with stats.
  225. *
  226. * Return: 0 on success, error otherwise.
  227. */
  228. int (*get_stats)(struct qed_dev *cdev, struct qed_ll2_stats *stats);
  229. };
  230. #ifdef CONFIG_QED_LL2
  231. int qed_ll2_alloc_if(struct qed_dev *);
  232. void qed_ll2_dealloc_if(struct qed_dev *);
  233. #else
  234. static const struct qed_ll2_ops qed_ll2_ops_pass = {
  235. .start = NULL,
  236. .stop = NULL,
  237. .start_xmit = NULL,
  238. .register_cb_ops = NULL,
  239. .get_stats = NULL,
  240. };
  241. static inline int qed_ll2_alloc_if(struct qed_dev *cdev)
  242. {
  243. return 0;
  244. }
  245. static inline void qed_ll2_dealloc_if(struct qed_dev *cdev)
  246. {
  247. }
  248. #endif
  249. #endif