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