qed_ll2_if.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef _QED_LL2_IF_H
  33. #define _QED_LL2_IF_H
  34. #include <linux/types.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/pci.h>
  38. #include <linux/skbuff.h>
  39. #include <linux/version.h>
  40. #include <linux/kernel.h>
  41. #include <linux/slab.h>
  42. #include <linux/qed/qed_if.h>
  43. enum qed_ll2_conn_type {
  44. QED_LL2_TYPE_FCOE,
  45. QED_LL2_TYPE_ISCSI,
  46. QED_LL2_TYPE_TEST,
  47. QED_LL2_TYPE_OOO,
  48. QED_LL2_TYPE_RESERVED2,
  49. QED_LL2_TYPE_ROCE,
  50. QED_LL2_TYPE_IWARP,
  51. QED_LL2_TYPE_RESERVED3,
  52. MAX_QED_LL2_RX_CONN_TYPE
  53. };
  54. enum qed_ll2_roce_flavor_type {
  55. QED_LL2_ROCE,
  56. QED_LL2_RROCE,
  57. MAX_QED_LL2_ROCE_FLAVOR_TYPE
  58. };
  59. enum qed_ll2_tx_dest {
  60. QED_LL2_TX_DEST_NW, /* Light L2 TX Destination to the Network */
  61. QED_LL2_TX_DEST_LB, /* Light L2 TX Destination to the Loopback */
  62. QED_LL2_TX_DEST_DROP, /* Light L2 Drop the TX packet */
  63. QED_LL2_TX_DEST_MAX
  64. };
  65. enum qed_ll2_error_handle {
  66. QED_LL2_DROP_PACKET,
  67. QED_LL2_DO_NOTHING,
  68. QED_LL2_ASSERT,
  69. };
  70. struct qed_ll2_stats {
  71. u64 gsi_invalid_hdr;
  72. u64 gsi_invalid_pkt_length;
  73. u64 gsi_unsupported_pkt_typ;
  74. u64 gsi_crcchksm_error;
  75. u64 packet_too_big_discard;
  76. u64 no_buff_discard;
  77. u64 rcv_ucast_bytes;
  78. u64 rcv_mcast_bytes;
  79. u64 rcv_bcast_bytes;
  80. u64 rcv_ucast_pkts;
  81. u64 rcv_mcast_pkts;
  82. u64 rcv_bcast_pkts;
  83. u64 sent_ucast_bytes;
  84. u64 sent_mcast_bytes;
  85. u64 sent_bcast_bytes;
  86. u64 sent_ucast_pkts;
  87. u64 sent_mcast_pkts;
  88. u64 sent_bcast_pkts;
  89. };
  90. struct qed_ll2_comp_rx_data {
  91. void *cookie;
  92. dma_addr_t rx_buf_addr;
  93. u16 parse_flags;
  94. u16 err_flags;
  95. u16 vlan;
  96. bool b_last_packet;
  97. u8 connection_handle;
  98. union {
  99. u16 packet_length;
  100. u16 data_length;
  101. } length;
  102. u32 opaque_data_0;
  103. u32 opaque_data_1;
  104. /* GSI only */
  105. u32 src_qp;
  106. u16 qp_id;
  107. union {
  108. u8 placement_offset;
  109. u8 data_length_error;
  110. } u;
  111. };
  112. typedef
  113. void (*qed_ll2_complete_rx_packet_cb)(void *cxt,
  114. struct qed_ll2_comp_rx_data *data);
  115. typedef
  116. void (*qed_ll2_release_rx_packet_cb)(void *cxt,
  117. u8 connection_handle,
  118. void *cookie,
  119. dma_addr_t rx_buf_addr,
  120. bool b_last_packet);
  121. typedef
  122. void (*qed_ll2_complete_tx_packet_cb)(void *cxt,
  123. u8 connection_handle,
  124. void *cookie,
  125. dma_addr_t first_frag_addr,
  126. bool b_last_fragment,
  127. bool b_last_packet);
  128. typedef
  129. void (*qed_ll2_release_tx_packet_cb)(void *cxt,
  130. u8 connection_handle,
  131. void *cookie,
  132. dma_addr_t first_frag_addr,
  133. bool b_last_fragment, bool b_last_packet);
  134. typedef
  135. void (*qed_ll2_slowpath_cb)(void *cxt, u8 connection_handle,
  136. u32 opaque_data_0, u32 opaque_data_1);
  137. struct qed_ll2_cbs {
  138. qed_ll2_complete_rx_packet_cb rx_comp_cb;
  139. qed_ll2_release_rx_packet_cb rx_release_cb;
  140. qed_ll2_complete_tx_packet_cb tx_comp_cb;
  141. qed_ll2_release_tx_packet_cb tx_release_cb;
  142. qed_ll2_slowpath_cb slowpath_cb;
  143. void *cookie;
  144. };
  145. struct qed_ll2_acquire_data_inputs {
  146. enum qed_ll2_conn_type conn_type;
  147. u16 mtu;
  148. u16 rx_num_desc;
  149. u16 rx_num_ooo_buffers;
  150. u8 rx_drop_ttl0_flg;
  151. u8 rx_vlan_removal_en;
  152. u16 tx_num_desc;
  153. u8 tx_max_bds_per_packet;
  154. u8 tx_tc;
  155. enum qed_ll2_tx_dest tx_dest;
  156. enum qed_ll2_error_handle ai_err_packet_too_big;
  157. enum qed_ll2_error_handle ai_err_no_buf;
  158. bool secondary_queue;
  159. u8 gsi_enable;
  160. };
  161. struct qed_ll2_acquire_data {
  162. struct qed_ll2_acquire_data_inputs input;
  163. const struct qed_ll2_cbs *cbs;
  164. /* Output container for LL2 connection's handle */
  165. u8 *p_connection_handle;
  166. };
  167. struct qed_ll2_tx_pkt_info {
  168. void *cookie;
  169. dma_addr_t first_frag;
  170. enum qed_ll2_tx_dest tx_dest;
  171. enum qed_ll2_roce_flavor_type qed_roce_flavor;
  172. u16 vlan;
  173. u16 l4_hdr_offset_w; /* from start of packet */
  174. u16 first_frag_len;
  175. u8 num_of_bds;
  176. u8 bd_flags;
  177. bool enable_ip_cksum;
  178. bool enable_l4_cksum;
  179. bool calc_ip_len;
  180. bool remove_stag;
  181. };
  182. #define QED_LL2_UNUSED_HANDLE (0xff)
  183. struct qed_ll2_cb_ops {
  184. int (*rx_cb)(void *, struct sk_buff *, u32, u32);
  185. int (*tx_cb)(void *, struct sk_buff *, bool);
  186. };
  187. struct qed_ll2_params {
  188. u16 mtu;
  189. bool drop_ttl0_packets;
  190. bool rx_vlan_stripping;
  191. u8 tx_tc;
  192. bool frags_mapped;
  193. u8 ll2_mac_address[ETH_ALEN];
  194. };
  195. enum qed_ll2_xmit_flags {
  196. /* FIP discovery packet */
  197. QED_LL2_XMIT_FLAGS_FIP_DISCOVERY
  198. };
  199. struct qed_ll2_ops {
  200. /**
  201. * @brief start - initializes ll2
  202. *
  203. * @param cdev
  204. * @param params - protocol driver configuration for the ll2.
  205. *
  206. * @return 0 on success, otherwise error value.
  207. */
  208. int (*start)(struct qed_dev *cdev, struct qed_ll2_params *params);
  209. /**
  210. * @brief stop - stops the ll2
  211. *
  212. * @param cdev
  213. *
  214. * @return 0 on success, otherwise error value.
  215. */
  216. int (*stop)(struct qed_dev *cdev);
  217. /**
  218. * @brief start_xmit - transmits an skb over the ll2 interface
  219. *
  220. * @param cdev
  221. * @param skb
  222. * @param xmit_flags - Transmit options defined by the enum qed_ll2_xmit_flags.
  223. *
  224. * @return 0 on success, otherwise error value.
  225. */
  226. int (*start_xmit)(struct qed_dev *cdev, struct sk_buff *skb,
  227. unsigned long xmit_flags);
  228. /**
  229. * @brief register_cb_ops - protocol driver register the callback for Rx/Tx
  230. * packets. Should be called before `start'.
  231. *
  232. * @param cdev
  233. * @param cookie - to be passed to the callback functions.
  234. * @param ops - the callback functions to register for Rx / Tx.
  235. *
  236. * @return 0 on success, otherwise error value.
  237. */
  238. void (*register_cb_ops)(struct qed_dev *cdev,
  239. const struct qed_ll2_cb_ops *ops,
  240. void *cookie);
  241. /**
  242. * @brief get LL2 related statistics
  243. *
  244. * @param cdev
  245. * @param stats - pointer to struct that would be filled with stats
  246. *
  247. * @return 0 on success, error otherwise.
  248. */
  249. int (*get_stats)(struct qed_dev *cdev, struct qed_ll2_stats *stats);
  250. };
  251. #ifdef CONFIG_QED_LL2
  252. int qed_ll2_alloc_if(struct qed_dev *);
  253. void qed_ll2_dealloc_if(struct qed_dev *);
  254. #else
  255. static const struct qed_ll2_ops qed_ll2_ops_pass = {
  256. .start = NULL,
  257. .stop = NULL,
  258. .start_xmit = NULL,
  259. .register_cb_ops = NULL,
  260. .get_stats = NULL,
  261. };
  262. static inline int qed_ll2_alloc_if(struct qed_dev *cdev)
  263. {
  264. return 0;
  265. }
  266. static inline void qed_ll2_dealloc_if(struct qed_dev *cdev)
  267. {
  268. }
  269. #endif
  270. #endif