1 /* QLogic qed NIC Driver 2 * 3 * Copyright (c) 2015 QLogic Corporation 4 * 5 * This software is available under the terms of the GNU General Public License 6 * (GPL) Version 2, available from the file COPYING in the main directory of 7 * this source tree. 8 */ 9 10 #ifndef _QED_LL2_H 11 #define _QED_LL2_H 12 13 #include <linux/types.h> 14 #include <linux/kernel.h> 15 #include <linux/list.h> 16 #include <linux/mutex.h> 17 #include <linux/slab.h> 18 #include <linux/spinlock.h> 19 #include <linux/qed/qed_chain.h> 20 #include <linux/qed/qed_ll2_if.h> 21 #include "qed.h" 22 #include "qed_hsi.h" 23 #include "qed_sp.h" 24 25 #define QED_MAX_NUM_OF_LL2_CONNECTIONS (4) 26 27 enum qed_ll2_roce_flavor_type { 28 QED_LL2_ROCE, 29 QED_LL2_RROCE, 30 MAX_QED_LL2_ROCE_FLAVOR_TYPE 31 }; 32 33 enum qed_ll2_conn_type { 34 QED_LL2_TYPE_RESERVED, 35 QED_LL2_TYPE_ISCSI, 36 QED_LL2_TYPE_TEST, 37 QED_LL2_TYPE_ISCSI_OOO, 38 QED_LL2_TYPE_RESERVED2, 39 QED_LL2_TYPE_ROCE, 40 QED_LL2_TYPE_RESERVED3, 41 MAX_QED_LL2_RX_CONN_TYPE 42 }; 43 44 struct qed_ll2_rx_packet { 45 struct list_head list_entry; 46 struct core_rx_bd_with_buff_len *rxq_bd; 47 dma_addr_t rx_buf_addr; 48 u16 buf_length; 49 void *cookie; 50 u8 placement_offset; 51 u16 parse_flags; 52 u16 packet_length; 53 u16 vlan; 54 u32 opaque_data[2]; 55 }; 56 57 struct qed_ll2_tx_packet { 58 struct list_head list_entry; 59 u16 bd_used; 60 u16 vlan; 61 u16 l4_hdr_offset_w; 62 u8 bd_flags; 63 bool notify_fw; 64 void *cookie; 65 66 struct { 67 struct core_tx_bd *txq_bd; 68 dma_addr_t tx_frag; 69 u16 frag_len; 70 } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET]; 71 }; 72 73 struct qed_ll2_rx_queue { 74 /* Lock protecting the Rx queue manipulation */ 75 spinlock_t lock; 76 struct qed_chain rxq_chain; 77 struct qed_chain rcq_chain; 78 u8 rx_sb_index; 79 bool b_cb_registred; 80 __le16 *p_fw_cons; 81 struct list_head active_descq; 82 struct list_head free_descq; 83 struct list_head posting_descq; 84 struct qed_ll2_rx_packet *descq_array; 85 void __iomem *set_prod_addr; 86 }; 87 88 struct qed_ll2_tx_queue { 89 /* Lock protecting the Tx queue manipulation */ 90 spinlock_t lock; 91 struct qed_chain txq_chain; 92 u8 tx_sb_index; 93 bool b_cb_registred; 94 __le16 *p_fw_cons; 95 struct list_head active_descq; 96 struct list_head free_descq; 97 struct list_head sending_descq; 98 struct qed_ll2_tx_packet *descq_array; 99 struct qed_ll2_tx_packet *cur_send_packet; 100 struct qed_ll2_tx_packet cur_completing_packet; 101 u16 cur_completing_bd_idx; 102 void __iomem *doorbell_addr; 103 u16 bds_idx; 104 u16 cur_send_frag_num; 105 u16 cur_completing_frag_num; 106 bool b_completing_packet; 107 }; 108 109 struct qed_ll2_info { 110 /* Lock protecting the state of LL2 */ 111 struct mutex mutex; 112 enum qed_ll2_conn_type conn_type; 113 u32 cid; 114 u8 my_id; 115 u8 queue_id; 116 u8 tx_stats_id; 117 bool b_active; 118 u16 mtu; 119 u8 rx_drop_ttl0_flg; 120 u8 rx_vlan_removal_en; 121 u8 tx_tc; 122 enum core_tx_dest tx_dest; 123 enum core_error_handle ai_err_packet_too_big; 124 enum core_error_handle ai_err_no_buf; 125 u8 tx_stats_en; 126 struct qed_ll2_rx_queue rx_queue; 127 struct qed_ll2_tx_queue tx_queue; 128 u8 gsi_enable; 129 }; 130 131 /** 132 * @brief qed_ll2_acquire_connection - allocate resources, 133 * starts rx & tx (if relevant) queues pair. Provides 134 * connecion handler as output parameter. 135 * 136 * @param p_hwfn 137 * @param p_params Contain various configuration properties 138 * @param rx_num_desc 139 * @param tx_num_desc 140 * 141 * @param p_connection_handle Output container for LL2 connection's handle 142 * 143 * @return 0 on success, failure otherwise 144 */ 145 int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn, 146 struct qed_ll2_info *p_params, 147 u16 rx_num_desc, 148 u16 tx_num_desc, 149 u8 *p_connection_handle); 150 151 /** 152 * @brief qed_ll2_establish_connection - start previously 153 * allocated LL2 queues pair 154 * 155 * @param p_hwfn 156 * @param p_ptt 157 * @param connection_handle LL2 connection's handle obtained from 158 * qed_ll2_require_connection 159 * 160 * @return 0 on success, failure otherwise 161 */ 162 int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle); 163 164 /** 165 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue. 166 * 167 * @param p_hwfn 168 * @param connection_handle LL2 connection's handle obtained from 169 * qed_ll2_require_connection 170 * @param addr rx (physical address) buffers to submit 171 * @param cookie 172 * @param notify_fw produce corresponding Rx BD immediately 173 * 174 * @return 0 on success, failure otherwise 175 */ 176 int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn, 177 u8 connection_handle, 178 dma_addr_t addr, 179 u16 buf_len, void *cookie, u8 notify_fw); 180 181 /** 182 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD 183 * to prepare Tx packet submission to FW. 184 * 185 * @param p_hwfn 186 * @param connection_handle LL2 connection's handle obtained from 187 * qed_ll2_require_connection 188 * @param num_of_bds a number of requested BD equals a number of 189 * fragments in Tx packet 190 * @param vlan VLAN to insert to packet (if insertion set) 191 * @param bd_flags 192 * @param l4_hdr_offset_w L4 Header Offset from start of packet 193 * (in words). This is needed if both l4_csum 194 * and ipv6_ext are set 195 * @param first_frag 196 * @param first_frag_len 197 * @param cookie 198 * 199 * @param notify_fw 200 * 201 * @return 0 on success, failure otherwise 202 */ 203 int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn, 204 u8 connection_handle, 205 u8 num_of_bds, 206 u16 vlan, 207 u8 bd_flags, 208 u16 l4_hdr_offset_w, 209 enum qed_ll2_roce_flavor_type qed_roce_flavor, 210 dma_addr_t first_frag, 211 u16 first_frag_len, void *cookie, u8 notify_fw); 212 213 /** 214 * @brief qed_ll2_release_connection - releases resources 215 * allocated for LL2 connection 216 * 217 * @param p_hwfn 218 * @param connection_handle LL2 connection's handle obtained from 219 * qed_ll2_require_connection 220 */ 221 void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle); 222 223 /** 224 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill 225 * Tx BD of BDs requested by 226 * qed_ll2_prepare_tx_packet 227 * 228 * @param p_hwfn 229 * @param connection_handle LL2 connection's handle 230 * obtained from 231 * qed_ll2_require_connection 232 * @param addr 233 * @param nbytes 234 * 235 * @return 0 on success, failure otherwise 236 */ 237 int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn, 238 u8 connection_handle, 239 dma_addr_t addr, u16 nbytes); 240 241 /** 242 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues 243 * 244 * 245 * @param p_hwfn 246 * @param connection_handle LL2 connection's handle 247 * obtained from 248 * qed_ll2_require_connection 249 * 250 * @return 0 on success, failure otherwise 251 */ 252 int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle); 253 254 /** 255 * @brief qed_ll2_get_stats - get LL2 queue's statistics 256 * 257 * 258 * @param p_hwfn 259 * @param connection_handle LL2 connection's handle obtained from 260 * qed_ll2_require_connection 261 * @param p_stats 262 * 263 * @return 0 on success, failure otherwise 264 */ 265 int qed_ll2_get_stats(struct qed_hwfn *p_hwfn, 266 u8 connection_handle, struct qed_ll2_stats *p_stats); 267 268 /** 269 * @brief qed_ll2_alloc - Allocates LL2 connections set 270 * 271 * @param p_hwfn 272 * 273 * @return pointer to alocated qed_ll2_info or NULL 274 */ 275 struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn); 276 277 /** 278 * @brief qed_ll2_setup - Inits LL2 connections set 279 * 280 * @param p_hwfn 281 * @param p_ll2_connections 282 * 283 */ 284 void qed_ll2_setup(struct qed_hwfn *p_hwfn, 285 struct qed_ll2_info *p_ll2_connections); 286 287 /** 288 * @brief qed_ll2_free - Releases LL2 connections set 289 * 290 * @param p_hwfn 291 * @param p_ll2_connections 292 * 293 */ 294 void qed_ll2_free(struct qed_hwfn *p_hwfn, 295 struct qed_ll2_info *p_ll2_connections); 296 #endif 297