Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2017 QLogic Corporation |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 3 | * |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 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: |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 9 | * |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 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. |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 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 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 50 | struct qed_ll2_rx_packet { |
| 51 | struct list_head list_entry; |
| 52 | struct core_rx_bd_with_buff_len *rxq_bd; |
| 53 | dma_addr_t rx_buf_addr; |
| 54 | u16 buf_length; |
| 55 | void *cookie; |
| 56 | u8 placement_offset; |
| 57 | u16 parse_flags; |
| 58 | u16 packet_length; |
| 59 | u16 vlan; |
| 60 | u32 opaque_data[2]; |
| 61 | }; |
| 62 | |
| 63 | struct qed_ll2_tx_packet { |
| 64 | struct list_head list_entry; |
| 65 | u16 bd_used; |
| 66 | u16 vlan; |
| 67 | u16 l4_hdr_offset_w; |
| 68 | u8 bd_flags; |
| 69 | bool notify_fw; |
| 70 | void *cookie; |
| 71 | |
| 72 | struct { |
| 73 | struct core_tx_bd *txq_bd; |
| 74 | dma_addr_t tx_frag; |
| 75 | u16 frag_len; |
| 76 | } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET]; |
| 77 | }; |
| 78 | |
| 79 | struct qed_ll2_rx_queue { |
| 80 | /* Lock protecting the Rx queue manipulation */ |
| 81 | spinlock_t lock; |
| 82 | struct qed_chain rxq_chain; |
| 83 | struct qed_chain rcq_chain; |
| 84 | u8 rx_sb_index; |
| 85 | bool b_cb_registred; |
| 86 | __le16 *p_fw_cons; |
| 87 | struct list_head active_descq; |
| 88 | struct list_head free_descq; |
| 89 | struct list_head posting_descq; |
| 90 | struct qed_ll2_rx_packet *descq_array; |
| 91 | void __iomem *set_prod_addr; |
| 92 | }; |
| 93 | |
| 94 | struct qed_ll2_tx_queue { |
| 95 | /* Lock protecting the Tx queue manipulation */ |
| 96 | spinlock_t lock; |
| 97 | struct qed_chain txq_chain; |
| 98 | u8 tx_sb_index; |
| 99 | bool b_cb_registred; |
| 100 | __le16 *p_fw_cons; |
| 101 | struct list_head active_descq; |
| 102 | struct list_head free_descq; |
| 103 | struct list_head sending_descq; |
| 104 | struct qed_ll2_tx_packet *descq_array; |
| 105 | struct qed_ll2_tx_packet *cur_send_packet; |
| 106 | struct qed_ll2_tx_packet cur_completing_packet; |
| 107 | u16 cur_completing_bd_idx; |
| 108 | void __iomem *doorbell_addr; |
| 109 | u16 bds_idx; |
| 110 | u16 cur_send_frag_num; |
| 111 | u16 cur_completing_frag_num; |
| 112 | bool b_completing_packet; |
| 113 | }; |
| 114 | |
Arnd Bergmann | 0629a33 | 2017-01-18 15:52:52 +0100 | [diff] [blame] | 115 | struct qed_ll2_info { |
| 116 | /* Lock protecting the state of LL2 */ |
| 117 | struct mutex mutex; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame^] | 118 | |
| 119 | struct qed_ll2_acquire_data_inputs input; |
Arnd Bergmann | 0629a33 | 2017-01-18 15:52:52 +0100 | [diff] [blame] | 120 | u32 cid; |
| 121 | u8 my_id; |
| 122 | u8 queue_id; |
| 123 | u8 tx_stats_id; |
| 124 | bool b_active; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame^] | 125 | enum core_tx_dest tx_dest; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 126 | u8 tx_stats_en; |
| 127 | struct qed_ll2_rx_queue rx_queue; |
| 128 | struct qed_ll2_tx_queue tx_queue; |
| 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 | * |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame^] | 136 | * |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 137 | * @param p_hwfn |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame^] | 138 | * @param data - describes connection parameters |
| 139 | * @return int |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 140 | */ |
| 141 | int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame^] | 142 | struct qed_ll2_acquire_data *data); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * @brief qed_ll2_establish_connection - start previously |
| 146 | * allocated LL2 queues pair |
| 147 | * |
| 148 | * @param p_hwfn |
| 149 | * @param p_ptt |
| 150 | * @param connection_handle LL2 connection's handle obtained from |
| 151 | * qed_ll2_require_connection |
| 152 | * |
| 153 | * @return 0 on success, failure otherwise |
| 154 | */ |
| 155 | int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle); |
| 156 | |
| 157 | /** |
| 158 | * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue. |
| 159 | * |
| 160 | * @param p_hwfn |
| 161 | * @param connection_handle LL2 connection's handle obtained from |
| 162 | * qed_ll2_require_connection |
| 163 | * @param addr rx (physical address) buffers to submit |
| 164 | * @param cookie |
| 165 | * @param notify_fw produce corresponding Rx BD immediately |
| 166 | * |
| 167 | * @return 0 on success, failure otherwise |
| 168 | */ |
| 169 | int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn, |
| 170 | u8 connection_handle, |
| 171 | dma_addr_t addr, |
| 172 | u16 buf_len, void *cookie, u8 notify_fw); |
| 173 | |
| 174 | /** |
| 175 | * @brief qed_ll2_prepare_tx_packet - request for start Tx BD |
| 176 | * to prepare Tx packet submission to FW. |
| 177 | * |
| 178 | * @param p_hwfn |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 179 | * @param connection_handle |
| 180 | * @param pkt - info regarding the tx packet |
| 181 | * @param notify_fw - issue doorbell to fw for this packet |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 182 | * |
| 183 | * @return 0 on success, failure otherwise |
| 184 | */ |
| 185 | int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn, |
| 186 | u8 connection_handle, |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 187 | struct qed_ll2_tx_pkt_info *pkt, |
| 188 | bool notify_fw); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * @brief qed_ll2_release_connection - releases resources |
| 192 | * allocated for LL2 connection |
| 193 | * |
| 194 | * @param p_hwfn |
| 195 | * @param connection_handle LL2 connection's handle obtained from |
| 196 | * qed_ll2_require_connection |
| 197 | */ |
| 198 | void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle); |
| 199 | |
| 200 | /** |
| 201 | * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill |
| 202 | * Tx BD of BDs requested by |
| 203 | * qed_ll2_prepare_tx_packet |
| 204 | * |
| 205 | * @param p_hwfn |
| 206 | * @param connection_handle LL2 connection's handle |
| 207 | * obtained from |
| 208 | * qed_ll2_require_connection |
| 209 | * @param addr |
| 210 | * @param nbytes |
| 211 | * |
| 212 | * @return 0 on success, failure otherwise |
| 213 | */ |
| 214 | int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn, |
| 215 | u8 connection_handle, |
| 216 | dma_addr_t addr, u16 nbytes); |
| 217 | |
| 218 | /** |
| 219 | * @brief qed_ll2_terminate_connection - stops Tx/Rx queues |
| 220 | * |
| 221 | * |
| 222 | * @param p_hwfn |
| 223 | * @param connection_handle LL2 connection's handle |
| 224 | * obtained from |
| 225 | * qed_ll2_require_connection |
| 226 | * |
| 227 | * @return 0 on success, failure otherwise |
| 228 | */ |
| 229 | int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle); |
| 230 | |
| 231 | /** |
| 232 | * @brief qed_ll2_get_stats - get LL2 queue's statistics |
| 233 | * |
| 234 | * |
| 235 | * @param p_hwfn |
| 236 | * @param connection_handle LL2 connection's handle obtained from |
| 237 | * qed_ll2_require_connection |
| 238 | * @param p_stats |
| 239 | * |
| 240 | * @return 0 on success, failure otherwise |
| 241 | */ |
| 242 | int qed_ll2_get_stats(struct qed_hwfn *p_hwfn, |
| 243 | u8 connection_handle, struct qed_ll2_stats *p_stats); |
| 244 | |
| 245 | /** |
| 246 | * @brief qed_ll2_alloc - Allocates LL2 connections set |
| 247 | * |
| 248 | * @param p_hwfn |
| 249 | * |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 250 | * @return int |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 251 | */ |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 252 | int qed_ll2_alloc(struct qed_hwfn *p_hwfn); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 253 | |
| 254 | /** |
| 255 | * @brief qed_ll2_setup - Inits LL2 connections set |
| 256 | * |
| 257 | * @param p_hwfn |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 258 | * |
| 259 | */ |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 260 | void qed_ll2_setup(struct qed_hwfn *p_hwfn); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 261 | |
| 262 | /** |
| 263 | * @brief qed_ll2_free - Releases LL2 connections set |
| 264 | * |
| 265 | * @param p_hwfn |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 266 | * |
| 267 | */ |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 268 | void qed_ll2_free(struct qed_hwfn *p_hwfn); |
| 269 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 270 | #endif |