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 | #include <linux/types.h> |
| 34 | #include <asm/byteorder.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/if_vlan.h> |
| 37 | #include <linux/kernel.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/slab.h> |
| 40 | #include <linux/stddef.h> |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 41 | #include <linux/workqueue.h> |
| 42 | #include <net/ipv6.h> |
| 43 | #include <linux/bitops.h> |
| 44 | #include <linux/delay.h> |
| 45 | #include <linux/errno.h> |
| 46 | #include <linux/etherdevice.h> |
| 47 | #include <linux/io.h> |
| 48 | #include <linux/list.h> |
| 49 | #include <linux/mutex.h> |
| 50 | #include <linux/spinlock.h> |
| 51 | #include <linux/string.h> |
| 52 | #include <linux/qed/qed_ll2_if.h> |
| 53 | #include "qed.h" |
| 54 | #include "qed_cxt.h" |
| 55 | #include "qed_dev_api.h" |
| 56 | #include "qed_hsi.h" |
| 57 | #include "qed_hw.h" |
| 58 | #include "qed_int.h" |
| 59 | #include "qed_ll2.h" |
| 60 | #include "qed_mcp.h" |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 61 | #include "qed_ooo.h" |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 62 | #include "qed_reg_addr.h" |
| 63 | #include "qed_sp.h" |
Kalderon, Michal | b71b9af | 2017-06-21 16:22:45 +0300 | [diff] [blame] | 64 | #include "qed_rdma.h" |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 65 | |
| 66 | #define QED_LL2_RX_REGISTERED(ll2) ((ll2)->rx_queue.b_cb_registred) |
| 67 | #define QED_LL2_TX_REGISTERED(ll2) ((ll2)->tx_queue.b_cb_registred) |
| 68 | |
| 69 | #define QED_LL2_TX_SIZE (256) |
| 70 | #define QED_LL2_RX_SIZE (4096) |
| 71 | |
| 72 | struct qed_cb_ll2_info { |
| 73 | int rx_cnt; |
| 74 | u32 rx_size; |
| 75 | u8 handle; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 76 | |
| 77 | /* Lock protecting LL2 buffer lists in sleepless context */ |
| 78 | spinlock_t lock; |
| 79 | struct list_head list; |
| 80 | |
| 81 | const struct qed_ll2_cb_ops *cbs; |
| 82 | void *cb_cookie; |
| 83 | }; |
| 84 | |
| 85 | struct qed_ll2_buffer { |
| 86 | struct list_head list; |
| 87 | void *data; |
| 88 | dma_addr_t phys_addr; |
| 89 | }; |
| 90 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 91 | static void qed_ll2b_complete_tx_packet(void *cxt, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 92 | u8 connection_handle, |
| 93 | void *cookie, |
| 94 | dma_addr_t first_frag_addr, |
| 95 | bool b_last_fragment, |
| 96 | bool b_last_packet) |
| 97 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 98 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 99 | struct qed_dev *cdev = p_hwfn->cdev; |
| 100 | struct sk_buff *skb = cookie; |
| 101 | |
| 102 | /* All we need to do is release the mapping */ |
| 103 | dma_unmap_single(&p_hwfn->cdev->pdev->dev, first_frag_addr, |
| 104 | skb_headlen(skb), DMA_TO_DEVICE); |
| 105 | |
| 106 | if (cdev->ll2->cbs && cdev->ll2->cbs->tx_cb) |
| 107 | cdev->ll2->cbs->tx_cb(cdev->ll2->cb_cookie, skb, |
| 108 | b_last_fragment); |
| 109 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 110 | dev_kfree_skb_any(skb); |
| 111 | } |
| 112 | |
| 113 | static int qed_ll2_alloc_buffer(struct qed_dev *cdev, |
| 114 | u8 **data, dma_addr_t *phys_addr) |
| 115 | { |
| 116 | *data = kmalloc(cdev->ll2->rx_size, GFP_ATOMIC); |
| 117 | if (!(*data)) { |
| 118 | DP_INFO(cdev, "Failed to allocate LL2 buffer data\n"); |
| 119 | return -ENOMEM; |
| 120 | } |
| 121 | |
| 122 | *phys_addr = dma_map_single(&cdev->pdev->dev, |
| 123 | ((*data) + NET_SKB_PAD), |
| 124 | cdev->ll2->rx_size, DMA_FROM_DEVICE); |
| 125 | if (dma_mapping_error(&cdev->pdev->dev, *phys_addr)) { |
| 126 | DP_INFO(cdev, "Failed to map LL2 buffer data\n"); |
| 127 | kfree((*data)); |
| 128 | return -ENOMEM; |
| 129 | } |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static int qed_ll2_dealloc_buffer(struct qed_dev *cdev, |
| 135 | struct qed_ll2_buffer *buffer) |
| 136 | { |
| 137 | spin_lock_bh(&cdev->ll2->lock); |
| 138 | |
| 139 | dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr, |
| 140 | cdev->ll2->rx_size, DMA_FROM_DEVICE); |
| 141 | kfree(buffer->data); |
| 142 | list_del(&buffer->list); |
| 143 | |
| 144 | cdev->ll2->rx_cnt--; |
| 145 | if (!cdev->ll2->rx_cnt) |
| 146 | DP_INFO(cdev, "All LL2 entries were removed\n"); |
| 147 | |
| 148 | spin_unlock_bh(&cdev->ll2->lock); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static void qed_ll2_kill_buffers(struct qed_dev *cdev) |
| 154 | { |
| 155 | struct qed_ll2_buffer *buffer, *tmp_buffer; |
| 156 | |
| 157 | list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list) |
| 158 | qed_ll2_dealloc_buffer(cdev, buffer); |
| 159 | } |
| 160 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 161 | void qed_ll2b_complete_rx_packet(void *cxt, struct qed_ll2_comp_rx_data *data) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 162 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 163 | struct qed_hwfn *p_hwfn = cxt; |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 164 | struct qed_ll2_buffer *buffer = data->cookie; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 165 | struct qed_dev *cdev = p_hwfn->cdev; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 166 | dma_addr_t new_phys_addr; |
| 167 | struct sk_buff *skb; |
| 168 | bool reuse = false; |
| 169 | int rc = -EINVAL; |
| 170 | u8 *new_data; |
| 171 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 172 | DP_VERBOSE(p_hwfn, |
| 173 | (NETIF_MSG_RX_STATUS | QED_MSG_STORAGE | NETIF_MSG_PKTDATA), |
| 174 | "Got an LL2 Rx completion: [Buffer at phys 0x%llx, offset 0x%02x] Length 0x%04x Parse_flags 0x%04x vlan 0x%04x Opaque data [0x%08x:0x%08x]\n", |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 175 | (u64)data->rx_buf_addr, |
| 176 | data->u.placement_offset, |
| 177 | data->length.packet_length, |
| 178 | data->parse_flags, |
| 179 | data->vlan, data->opaque_data_0, data->opaque_data_1); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 180 | |
| 181 | if ((cdev->dp_module & NETIF_MSG_PKTDATA) && buffer->data) { |
| 182 | print_hex_dump(KERN_INFO, "", |
| 183 | DUMP_PREFIX_OFFSET, 16, 1, |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 184 | buffer->data, data->length.packet_length, false); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* Determine if data is valid */ |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 188 | if (data->length.packet_length < ETH_HLEN) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 189 | reuse = true; |
| 190 | |
| 191 | /* Allocate a replacement for buffer; Reuse upon failure */ |
| 192 | if (!reuse) |
| 193 | rc = qed_ll2_alloc_buffer(p_hwfn->cdev, &new_data, |
| 194 | &new_phys_addr); |
| 195 | |
| 196 | /* If need to reuse or there's no replacement buffer, repost this */ |
| 197 | if (rc) |
| 198 | goto out_post; |
Mintz, Yuval | 752ecb2 | 2017-03-14 15:26:00 +0200 | [diff] [blame] | 199 | dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr, |
| 200 | cdev->ll2->rx_size, DMA_FROM_DEVICE); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 201 | |
| 202 | skb = build_skb(buffer->data, 0); |
| 203 | if (!skb) { |
| 204 | rc = -ENOMEM; |
| 205 | goto out_post; |
| 206 | } |
| 207 | |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 208 | data->u.placement_offset += NET_SKB_PAD; |
| 209 | skb_reserve(skb, data->u.placement_offset); |
| 210 | skb_put(skb, data->length.packet_length); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 211 | skb_checksum_none_assert(skb); |
| 212 | |
| 213 | /* Get parital ethernet information instead of eth_type_trans(), |
| 214 | * Since we don't have an associated net_device. |
| 215 | */ |
| 216 | skb_reset_mac_header(skb); |
| 217 | skb->protocol = eth_hdr(skb)->h_proto; |
| 218 | |
| 219 | /* Pass SKB onward */ |
| 220 | if (cdev->ll2->cbs && cdev->ll2->cbs->rx_cb) { |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 221 | if (data->vlan) |
| 222 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 223 | data->vlan); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 224 | cdev->ll2->cbs->rx_cb(cdev->ll2->cb_cookie, skb, |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 225 | data->opaque_data_0, |
| 226 | data->opaque_data_1); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* Update Buffer information and update FW producer */ |
| 230 | buffer->data = new_data; |
| 231 | buffer->phys_addr = new_phys_addr; |
| 232 | |
| 233 | out_post: |
| 234 | rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev), cdev->ll2->handle, |
| 235 | buffer->phys_addr, 0, buffer, 1); |
| 236 | |
| 237 | if (rc) |
| 238 | qed_ll2_dealloc_buffer(cdev, buffer); |
| 239 | } |
| 240 | |
| 241 | static struct qed_ll2_info *__qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn, |
| 242 | u8 connection_handle, |
| 243 | bool b_lock, |
| 244 | bool b_only_active) |
| 245 | { |
| 246 | struct qed_ll2_info *p_ll2_conn, *p_ret = NULL; |
| 247 | |
| 248 | if (connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS) |
| 249 | return NULL; |
| 250 | |
| 251 | if (!p_hwfn->p_ll2_info) |
| 252 | return NULL; |
| 253 | |
| 254 | p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle]; |
| 255 | |
| 256 | if (b_only_active) { |
| 257 | if (b_lock) |
| 258 | mutex_lock(&p_ll2_conn->mutex); |
| 259 | if (p_ll2_conn->b_active) |
| 260 | p_ret = p_ll2_conn; |
| 261 | if (b_lock) |
| 262 | mutex_unlock(&p_ll2_conn->mutex); |
| 263 | } else { |
| 264 | p_ret = p_ll2_conn; |
| 265 | } |
| 266 | |
| 267 | return p_ret; |
| 268 | } |
| 269 | |
| 270 | static struct qed_ll2_info *qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn, |
| 271 | u8 connection_handle) |
| 272 | { |
| 273 | return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, true); |
| 274 | } |
| 275 | |
| 276 | static struct qed_ll2_info *qed_ll2_handle_sanity_lock(struct qed_hwfn *p_hwfn, |
| 277 | u8 connection_handle) |
| 278 | { |
| 279 | return __qed_ll2_handle_sanity(p_hwfn, connection_handle, true, true); |
| 280 | } |
| 281 | |
| 282 | static struct qed_ll2_info *qed_ll2_handle_sanity_inactive(struct qed_hwfn |
| 283 | *p_hwfn, |
| 284 | u8 connection_handle) |
| 285 | { |
| 286 | return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, false); |
| 287 | } |
| 288 | |
| 289 | static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle) |
| 290 | { |
| 291 | bool b_last_packet = false, b_last_frag = false; |
| 292 | struct qed_ll2_tx_packet *p_pkt = NULL; |
| 293 | struct qed_ll2_info *p_ll2_conn; |
| 294 | struct qed_ll2_tx_queue *p_tx; |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 295 | dma_addr_t tx_frag; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 296 | |
| 297 | p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle); |
| 298 | if (!p_ll2_conn) |
| 299 | return; |
| 300 | |
| 301 | p_tx = &p_ll2_conn->tx_queue; |
| 302 | |
| 303 | while (!list_empty(&p_tx->active_descq)) { |
| 304 | p_pkt = list_first_entry(&p_tx->active_descq, |
| 305 | struct qed_ll2_tx_packet, list_entry); |
| 306 | if (!p_pkt) |
| 307 | break; |
| 308 | |
| 309 | list_del(&p_pkt->list_entry); |
| 310 | b_last_packet = list_empty(&p_tx->active_descq); |
| 311 | list_add_tail(&p_pkt->list_entry, &p_tx->free_descq); |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 312 | if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) { |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 313 | struct qed_ooo_buffer *p_buffer; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 314 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 315 | p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie; |
| 316 | qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info, |
| 317 | p_buffer); |
| 318 | } else { |
| 319 | p_tx->cur_completing_packet = *p_pkt; |
| 320 | p_tx->cur_completing_bd_idx = 1; |
| 321 | b_last_frag = |
| 322 | p_tx->cur_completing_bd_idx == p_pkt->bd_used; |
| 323 | tx_frag = p_pkt->bds_set[0].tx_frag; |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 324 | p_ll2_conn->cbs.tx_release_cb(p_ll2_conn->cbs.cookie, |
| 325 | p_ll2_conn->my_id, |
| 326 | p_pkt->cookie, |
| 327 | tx_frag, |
| 328 | b_last_frag, |
| 329 | b_last_packet); |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 330 | } |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
| 334 | static int qed_ll2_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie) |
| 335 | { |
| 336 | struct qed_ll2_info *p_ll2_conn = p_cookie; |
| 337 | struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue; |
| 338 | u16 new_idx = 0, num_bds = 0, num_bds_in_packet = 0; |
| 339 | struct qed_ll2_tx_packet *p_pkt; |
| 340 | bool b_last_frag = false; |
| 341 | unsigned long flags; |
| 342 | int rc = -EINVAL; |
| 343 | |
| 344 | spin_lock_irqsave(&p_tx->lock, flags); |
| 345 | if (p_tx->b_completing_packet) { |
| 346 | rc = -EBUSY; |
| 347 | goto out; |
| 348 | } |
| 349 | |
| 350 | new_idx = le16_to_cpu(*p_tx->p_fw_cons); |
| 351 | num_bds = ((s16)new_idx - (s16)p_tx->bds_idx); |
| 352 | while (num_bds) { |
| 353 | if (list_empty(&p_tx->active_descq)) |
| 354 | goto out; |
| 355 | |
| 356 | p_pkt = list_first_entry(&p_tx->active_descq, |
| 357 | struct qed_ll2_tx_packet, list_entry); |
| 358 | if (!p_pkt) |
| 359 | goto out; |
| 360 | |
| 361 | p_tx->b_completing_packet = true; |
| 362 | p_tx->cur_completing_packet = *p_pkt; |
| 363 | num_bds_in_packet = p_pkt->bd_used; |
| 364 | list_del(&p_pkt->list_entry); |
| 365 | |
| 366 | if (num_bds < num_bds_in_packet) { |
| 367 | DP_NOTICE(p_hwfn, |
| 368 | "Rest of BDs does not cover whole packet\n"); |
| 369 | goto out; |
| 370 | } |
| 371 | |
| 372 | num_bds -= num_bds_in_packet; |
| 373 | p_tx->bds_idx += num_bds_in_packet; |
| 374 | while (num_bds_in_packet--) |
| 375 | qed_chain_consume(&p_tx->txq_chain); |
| 376 | |
| 377 | p_tx->cur_completing_bd_idx = 1; |
| 378 | b_last_frag = p_tx->cur_completing_bd_idx == p_pkt->bd_used; |
| 379 | list_add_tail(&p_pkt->list_entry, &p_tx->free_descq); |
| 380 | |
| 381 | spin_unlock_irqrestore(&p_tx->lock, flags); |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 382 | |
| 383 | p_ll2_conn->cbs.tx_comp_cb(p_ll2_conn->cbs.cookie, |
| 384 | p_ll2_conn->my_id, |
| 385 | p_pkt->cookie, |
| 386 | p_pkt->bds_set[0].tx_frag, |
| 387 | b_last_frag, !num_bds); |
| 388 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 389 | spin_lock_irqsave(&p_tx->lock, flags); |
| 390 | } |
| 391 | |
| 392 | p_tx->b_completing_packet = false; |
| 393 | rc = 0; |
| 394 | out: |
| 395 | spin_unlock_irqrestore(&p_tx->lock, flags); |
| 396 | return rc; |
| 397 | } |
| 398 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 399 | static void qed_ll2_rxq_parse_gsi(struct qed_hwfn *p_hwfn, |
| 400 | union core_rx_cqe_union *p_cqe, |
| 401 | struct qed_ll2_comp_rx_data *data) |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 402 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 403 | data->parse_flags = le16_to_cpu(p_cqe->rx_cqe_gsi.parse_flags.flags); |
| 404 | data->length.data_length = le16_to_cpu(p_cqe->rx_cqe_gsi.data_length); |
| 405 | data->vlan = le16_to_cpu(p_cqe->rx_cqe_gsi.vlan); |
| 406 | data->opaque_data_0 = le32_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrhi); |
| 407 | data->opaque_data_1 = le16_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrlo); |
| 408 | data->u.data_length_error = p_cqe->rx_cqe_gsi.data_length_error; |
Tomer Tayar | da09091 | 2017-12-27 19:30:07 +0200 | [diff] [blame] | 409 | data->qp_id = le16_to_cpu(p_cqe->rx_cqe_gsi.qp_id); |
| 410 | |
| 411 | data->src_qp = le32_to_cpu(p_cqe->rx_cqe_gsi.src_qp); |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 412 | } |
| 413 | |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 414 | static void qed_ll2_rxq_parse_reg(struct qed_hwfn *p_hwfn, |
| 415 | union core_rx_cqe_union *p_cqe, |
| 416 | struct qed_ll2_comp_rx_data *data) |
| 417 | { |
| 418 | data->parse_flags = le16_to_cpu(p_cqe->rx_cqe_fp.parse_flags.flags); |
Michal Kalderon | 1e99c49 | 2017-09-24 12:09:45 +0300 | [diff] [blame] | 419 | data->err_flags = le16_to_cpu(p_cqe->rx_cqe_fp.err_flags.flags); |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 420 | data->length.packet_length = |
| 421 | le16_to_cpu(p_cqe->rx_cqe_fp.packet_length); |
| 422 | data->vlan = le16_to_cpu(p_cqe->rx_cqe_fp.vlan); |
| 423 | data->opaque_data_0 = le32_to_cpu(p_cqe->rx_cqe_fp.opaque_data.data[0]); |
| 424 | data->opaque_data_1 = le32_to_cpu(p_cqe->rx_cqe_fp.opaque_data.data[1]); |
| 425 | data->u.placement_offset = p_cqe->rx_cqe_fp.placement_offset; |
| 426 | } |
| 427 | |
| 428 | static int |
Michal Kalderon | 6f34a28 | 2017-10-09 12:37:48 +0300 | [diff] [blame] | 429 | qed_ll2_handle_slowpath(struct qed_hwfn *p_hwfn, |
| 430 | struct qed_ll2_info *p_ll2_conn, |
| 431 | union core_rx_cqe_union *p_cqe, |
| 432 | unsigned long *p_lock_flags) |
| 433 | { |
| 434 | struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue; |
| 435 | struct core_rx_slow_path_cqe *sp_cqe; |
| 436 | |
| 437 | sp_cqe = &p_cqe->rx_cqe_sp; |
| 438 | if (sp_cqe->ramrod_cmd_id != CORE_RAMROD_RX_QUEUE_FLUSH) { |
| 439 | DP_NOTICE(p_hwfn, |
| 440 | "LL2 - unexpected Rx CQE slowpath ramrod_cmd_id:%d\n", |
| 441 | sp_cqe->ramrod_cmd_id); |
| 442 | return -EINVAL; |
| 443 | } |
| 444 | |
| 445 | if (!p_ll2_conn->cbs.slowpath_cb) { |
| 446 | DP_NOTICE(p_hwfn, |
| 447 | "LL2 - received RX_QUEUE_FLUSH but no callback was provided\n"); |
| 448 | return -EINVAL; |
| 449 | } |
| 450 | |
| 451 | spin_unlock_irqrestore(&p_rx->lock, *p_lock_flags); |
| 452 | |
| 453 | p_ll2_conn->cbs.slowpath_cb(p_ll2_conn->cbs.cookie, |
| 454 | p_ll2_conn->my_id, |
| 455 | le32_to_cpu(sp_cqe->opaque_data.data[0]), |
| 456 | le32_to_cpu(sp_cqe->opaque_data.data[1])); |
| 457 | |
| 458 | spin_lock_irqsave(&p_rx->lock, *p_lock_flags); |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static int |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 464 | qed_ll2_rxq_handle_completion(struct qed_hwfn *p_hwfn, |
| 465 | struct qed_ll2_info *p_ll2_conn, |
| 466 | union core_rx_cqe_union *p_cqe, |
| 467 | unsigned long *p_lock_flags, bool b_last_cqe) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 468 | { |
| 469 | struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue; |
| 470 | struct qed_ll2_rx_packet *p_pkt = NULL; |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 471 | struct qed_ll2_comp_rx_data data; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 472 | |
| 473 | if (!list_empty(&p_rx->active_descq)) |
| 474 | p_pkt = list_first_entry(&p_rx->active_descq, |
| 475 | struct qed_ll2_rx_packet, list_entry); |
| 476 | if (!p_pkt) { |
| 477 | DP_NOTICE(p_hwfn, |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 478 | "[%d] LL2 Rx completion but active_descq is empty\n", |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 479 | p_ll2_conn->input.conn_type); |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 480 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 481 | return -EIO; |
| 482 | } |
| 483 | list_del(&p_pkt->list_entry); |
| 484 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 485 | if (p_cqe->rx_cqe_sp.type == CORE_RX_CQE_TYPE_REGULAR) |
| 486 | qed_ll2_rxq_parse_reg(p_hwfn, p_cqe, &data); |
| 487 | else |
| 488 | qed_ll2_rxq_parse_gsi(p_hwfn, p_cqe, &data); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 489 | if (qed_chain_consume(&p_rx->rxq_chain) != p_pkt->rxq_bd) |
| 490 | DP_NOTICE(p_hwfn, |
| 491 | "Mismatch between active_descq and the LL2 Rx chain\n"); |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 492 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 493 | list_add_tail(&p_pkt->list_entry, &p_rx->free_descq); |
| 494 | |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 495 | data.connection_handle = p_ll2_conn->my_id; |
| 496 | data.cookie = p_pkt->cookie; |
| 497 | data.rx_buf_addr = p_pkt->rx_buf_addr; |
| 498 | data.b_last_packet = b_last_cqe; |
| 499 | |
Ram Amrani | 1df2ade | 2017-03-14 15:26:02 +0200 | [diff] [blame] | 500 | spin_unlock_irqrestore(&p_rx->lock, *p_lock_flags); |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 501 | p_ll2_conn->cbs.rx_comp_cb(p_ll2_conn->cbs.cookie, &data); |
| 502 | |
Ram Amrani | 1df2ade | 2017-03-14 15:26:02 +0200 | [diff] [blame] | 503 | spin_lock_irqsave(&p_rx->lock, *p_lock_flags); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static int qed_ll2_rxq_completion(struct qed_hwfn *p_hwfn, void *cookie) |
| 509 | { |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 510 | struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)cookie; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 511 | struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue; |
| 512 | union core_rx_cqe_union *cqe = NULL; |
| 513 | u16 cq_new_idx = 0, cq_old_idx = 0; |
| 514 | unsigned long flags = 0; |
| 515 | int rc = 0; |
| 516 | |
| 517 | spin_lock_irqsave(&p_rx->lock, flags); |
| 518 | cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons); |
| 519 | cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain); |
| 520 | |
| 521 | while (cq_new_idx != cq_old_idx) { |
| 522 | bool b_last_cqe = (cq_new_idx == cq_old_idx); |
| 523 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 524 | cqe = |
| 525 | (union core_rx_cqe_union *) |
| 526 | qed_chain_consume(&p_rx->rcq_chain); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 527 | cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain); |
| 528 | |
| 529 | DP_VERBOSE(p_hwfn, |
| 530 | QED_MSG_LL2, |
| 531 | "LL2 [sw. cons %04x, fw. at %04x] - Got Packet of type %02x\n", |
| 532 | cq_old_idx, cq_new_idx, cqe->rx_cqe_sp.type); |
| 533 | |
| 534 | switch (cqe->rx_cqe_sp.type) { |
| 535 | case CORE_RX_CQE_TYPE_SLOW_PATH: |
Michal Kalderon | 6f34a28 | 2017-10-09 12:37:48 +0300 | [diff] [blame] | 536 | rc = qed_ll2_handle_slowpath(p_hwfn, p_ll2_conn, |
| 537 | cqe, &flags); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 538 | break; |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 539 | case CORE_RX_CQE_TYPE_GSI_OFFLOAD: |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 540 | case CORE_RX_CQE_TYPE_REGULAR: |
Mintz, Yuval | 68be910 | 2017-06-09 17:13:19 +0300 | [diff] [blame] | 541 | rc = qed_ll2_rxq_handle_completion(p_hwfn, p_ll2_conn, |
| 542 | cqe, &flags, |
| 543 | b_last_cqe); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 544 | break; |
| 545 | default: |
| 546 | rc = -EIO; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | spin_unlock_irqrestore(&p_rx->lock, flags); |
| 551 | return rc; |
| 552 | } |
| 553 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 554 | static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 555 | { |
| 556 | struct qed_ll2_info *p_ll2_conn = NULL; |
| 557 | struct qed_ll2_rx_packet *p_pkt = NULL; |
| 558 | struct qed_ll2_rx_queue *p_rx; |
| 559 | |
| 560 | p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle); |
| 561 | if (!p_ll2_conn) |
| 562 | return; |
| 563 | |
| 564 | p_rx = &p_ll2_conn->rx_queue; |
| 565 | |
| 566 | while (!list_empty(&p_rx->active_descq)) { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 567 | p_pkt = list_first_entry(&p_rx->active_descq, |
| 568 | struct qed_ll2_rx_packet, list_entry); |
| 569 | if (!p_pkt) |
| 570 | break; |
| 571 | |
Wei Yongjun | b4f0fd4 | 2016-10-17 15:17:51 +0000 | [diff] [blame] | 572 | list_move_tail(&p_pkt->list_entry, &p_rx->free_descq); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 573 | |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 574 | if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) { |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 575 | struct qed_ooo_buffer *p_buffer; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 576 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 577 | p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie; |
| 578 | qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info, |
| 579 | p_buffer); |
| 580 | } else { |
Mintz, Yuval | 54f19f0 | 2017-06-09 17:13:24 +0300 | [diff] [blame] | 581 | dma_addr_t rx_buf_addr = p_pkt->rx_buf_addr; |
| 582 | void *cookie = p_pkt->cookie; |
| 583 | bool b_last; |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 584 | |
| 585 | b_last = list_empty(&p_rx->active_descq); |
Mintz, Yuval | 54f19f0 | 2017-06-09 17:13:24 +0300 | [diff] [blame] | 586 | p_ll2_conn->cbs.rx_release_cb(p_ll2_conn->cbs.cookie, |
| 587 | p_ll2_conn->my_id, |
| 588 | cookie, |
| 589 | rx_buf_addr, b_last); |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 590 | } |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Michal Kalderon | 974f6c0 | 2018-05-16 14:44:38 +0300 | [diff] [blame^] | 594 | static bool |
| 595 | qed_ll2_lb_rxq_handler_slowpath(struct qed_hwfn *p_hwfn, |
| 596 | struct core_rx_slow_path_cqe *p_cqe) |
| 597 | { |
| 598 | struct ooo_opaque *iscsi_ooo; |
| 599 | u32 cid; |
| 600 | |
| 601 | if (p_cqe->ramrod_cmd_id != CORE_RAMROD_RX_QUEUE_FLUSH) |
| 602 | return false; |
| 603 | |
| 604 | iscsi_ooo = (struct ooo_opaque *)&p_cqe->opaque_data; |
| 605 | if (iscsi_ooo->ooo_opcode != TCP_EVENT_DELETE_ISLES) |
| 606 | return false; |
| 607 | |
| 608 | /* Need to make a flush */ |
| 609 | cid = le32_to_cpu(iscsi_ooo->cid); |
| 610 | qed_ooo_release_connection_isles(p_hwfn, p_hwfn->p_ooo_info, cid); |
| 611 | |
| 612 | return true; |
| 613 | } |
| 614 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 615 | static int qed_ll2_lb_rxq_handler(struct qed_hwfn *p_hwfn, |
| 616 | struct qed_ll2_info *p_ll2_conn) |
| 617 | { |
| 618 | struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue; |
| 619 | u16 packet_length = 0, parse_flags = 0, vlan = 0; |
| 620 | struct qed_ll2_rx_packet *p_pkt = NULL; |
| 621 | u32 num_ooo_add_to_peninsula = 0, cid; |
| 622 | union core_rx_cqe_union *cqe = NULL; |
| 623 | u16 cq_new_idx = 0, cq_old_idx = 0; |
| 624 | struct qed_ooo_buffer *p_buffer; |
| 625 | struct ooo_opaque *iscsi_ooo; |
| 626 | u8 placement_offset = 0; |
| 627 | u8 cqe_type; |
| 628 | |
| 629 | cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons); |
| 630 | cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain); |
| 631 | if (cq_new_idx == cq_old_idx) |
| 632 | return 0; |
| 633 | |
| 634 | while (cq_new_idx != cq_old_idx) { |
| 635 | struct core_rx_fast_path_cqe *p_cqe_fp; |
| 636 | |
| 637 | cqe = qed_chain_consume(&p_rx->rcq_chain); |
| 638 | cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain); |
| 639 | cqe_type = cqe->rx_cqe_sp.type; |
| 640 | |
Michal Kalderon | 974f6c0 | 2018-05-16 14:44:38 +0300 | [diff] [blame^] | 641 | if (cqe_type == CORE_RX_CQE_TYPE_SLOW_PATH) |
| 642 | if (qed_ll2_lb_rxq_handler_slowpath(p_hwfn, |
| 643 | &cqe->rx_cqe_sp)) |
| 644 | continue; |
| 645 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 646 | if (cqe_type != CORE_RX_CQE_TYPE_REGULAR) { |
| 647 | DP_NOTICE(p_hwfn, |
| 648 | "Got a non-regular LB LL2 completion [type 0x%02x]\n", |
| 649 | cqe_type); |
| 650 | return -EINVAL; |
| 651 | } |
| 652 | p_cqe_fp = &cqe->rx_cqe_fp; |
| 653 | |
| 654 | placement_offset = p_cqe_fp->placement_offset; |
| 655 | parse_flags = le16_to_cpu(p_cqe_fp->parse_flags.flags); |
| 656 | packet_length = le16_to_cpu(p_cqe_fp->packet_length); |
| 657 | vlan = le16_to_cpu(p_cqe_fp->vlan); |
| 658 | iscsi_ooo = (struct ooo_opaque *)&p_cqe_fp->opaque_data; |
| 659 | qed_ooo_save_history_entry(p_hwfn, p_hwfn->p_ooo_info, |
| 660 | iscsi_ooo); |
| 661 | cid = le32_to_cpu(iscsi_ooo->cid); |
| 662 | |
| 663 | /* Process delete isle first */ |
| 664 | if (iscsi_ooo->drop_size) |
| 665 | qed_ooo_delete_isles(p_hwfn, p_hwfn->p_ooo_info, cid, |
| 666 | iscsi_ooo->drop_isle, |
| 667 | iscsi_ooo->drop_size); |
| 668 | |
| 669 | if (iscsi_ooo->ooo_opcode == TCP_EVENT_NOP) |
| 670 | continue; |
| 671 | |
| 672 | /* Now process create/add/join isles */ |
| 673 | if (list_empty(&p_rx->active_descq)) { |
| 674 | DP_NOTICE(p_hwfn, |
| 675 | "LL2 OOO RX chain has no submitted buffers\n" |
| 676 | ); |
| 677 | return -EIO; |
| 678 | } |
| 679 | |
| 680 | p_pkt = list_first_entry(&p_rx->active_descq, |
| 681 | struct qed_ll2_rx_packet, list_entry); |
| 682 | |
| 683 | if ((iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_NEW_ISLE) || |
| 684 | (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_RIGHT) || |
| 685 | (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_LEFT) || |
| 686 | (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_PEN) || |
| 687 | (iscsi_ooo->ooo_opcode == TCP_EVENT_JOIN)) { |
| 688 | if (!p_pkt) { |
| 689 | DP_NOTICE(p_hwfn, |
| 690 | "LL2 OOO RX packet is not valid\n"); |
| 691 | return -EIO; |
| 692 | } |
| 693 | list_del(&p_pkt->list_entry); |
| 694 | p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie; |
| 695 | p_buffer->packet_length = packet_length; |
| 696 | p_buffer->parse_flags = parse_flags; |
| 697 | p_buffer->vlan = vlan; |
| 698 | p_buffer->placement_offset = placement_offset; |
| 699 | qed_chain_consume(&p_rx->rxq_chain); |
| 700 | list_add_tail(&p_pkt->list_entry, &p_rx->free_descq); |
| 701 | |
| 702 | switch (iscsi_ooo->ooo_opcode) { |
| 703 | case TCP_EVENT_ADD_NEW_ISLE: |
| 704 | qed_ooo_add_new_isle(p_hwfn, |
| 705 | p_hwfn->p_ooo_info, |
| 706 | cid, |
| 707 | iscsi_ooo->ooo_isle, |
| 708 | p_buffer); |
| 709 | break; |
| 710 | case TCP_EVENT_ADD_ISLE_RIGHT: |
| 711 | qed_ooo_add_new_buffer(p_hwfn, |
| 712 | p_hwfn->p_ooo_info, |
| 713 | cid, |
| 714 | iscsi_ooo->ooo_isle, |
| 715 | p_buffer, |
| 716 | QED_OOO_RIGHT_BUF); |
| 717 | break; |
| 718 | case TCP_EVENT_ADD_ISLE_LEFT: |
| 719 | qed_ooo_add_new_buffer(p_hwfn, |
| 720 | p_hwfn->p_ooo_info, |
| 721 | cid, |
| 722 | iscsi_ooo->ooo_isle, |
| 723 | p_buffer, |
| 724 | QED_OOO_LEFT_BUF); |
| 725 | break; |
| 726 | case TCP_EVENT_JOIN: |
| 727 | qed_ooo_add_new_buffer(p_hwfn, |
| 728 | p_hwfn->p_ooo_info, |
| 729 | cid, |
| 730 | iscsi_ooo->ooo_isle + |
| 731 | 1, |
| 732 | p_buffer, |
| 733 | QED_OOO_LEFT_BUF); |
| 734 | qed_ooo_join_isles(p_hwfn, |
| 735 | p_hwfn->p_ooo_info, |
| 736 | cid, iscsi_ooo->ooo_isle); |
| 737 | break; |
| 738 | case TCP_EVENT_ADD_PEN: |
| 739 | num_ooo_add_to_peninsula++; |
| 740 | qed_ooo_put_ready_buffer(p_hwfn, |
| 741 | p_hwfn->p_ooo_info, |
| 742 | p_buffer, true); |
| 743 | break; |
| 744 | } |
| 745 | } else { |
| 746 | DP_NOTICE(p_hwfn, |
| 747 | "Unexpected event (%d) TX OOO completion\n", |
| 748 | iscsi_ooo->ooo_opcode); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | static void |
| 756 | qed_ooo_submit_tx_buffers(struct qed_hwfn *p_hwfn, |
| 757 | struct qed_ll2_info *p_ll2_conn) |
| 758 | { |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 759 | struct qed_ll2_tx_pkt_info tx_pkt; |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 760 | struct qed_ooo_buffer *p_buffer; |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 761 | u16 l4_hdr_offset_w; |
| 762 | dma_addr_t first_frag; |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 763 | u8 bd_flags; |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 764 | int rc; |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 765 | |
| 766 | /* Submit Tx buffers here */ |
| 767 | while ((p_buffer = qed_ooo_get_ready_buffer(p_hwfn, |
| 768 | p_hwfn->p_ooo_info))) { |
| 769 | l4_hdr_offset_w = 0; |
| 770 | bd_flags = 0; |
| 771 | |
| 772 | first_frag = p_buffer->rx_buffer_phys_addr + |
| 773 | p_buffer->placement_offset; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 774 | SET_FIELD(bd_flags, CORE_TX_BD_DATA_FORCE_VLAN_MODE, 1); |
| 775 | SET_FIELD(bd_flags, CORE_TX_BD_DATA_L4_PROTOCOL, 1); |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 776 | |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 777 | memset(&tx_pkt, 0, sizeof(tx_pkt)); |
| 778 | tx_pkt.num_of_bds = 1; |
| 779 | tx_pkt.vlan = p_buffer->vlan; |
| 780 | tx_pkt.bd_flags = bd_flags; |
| 781 | tx_pkt.l4_hdr_offset_w = l4_hdr_offset_w; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 782 | tx_pkt.tx_dest = p_ll2_conn->tx_dest; |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 783 | tx_pkt.first_frag = first_frag; |
| 784 | tx_pkt.first_frag_len = p_buffer->packet_length; |
| 785 | tx_pkt.cookie = p_buffer; |
| 786 | |
| 787 | rc = qed_ll2_prepare_tx_packet(p_hwfn, p_ll2_conn->my_id, |
| 788 | &tx_pkt, true); |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 789 | if (rc) { |
| 790 | qed_ooo_put_ready_buffer(p_hwfn, p_hwfn->p_ooo_info, |
| 791 | p_buffer, false); |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | static void |
| 798 | qed_ooo_submit_rx_buffers(struct qed_hwfn *p_hwfn, |
| 799 | struct qed_ll2_info *p_ll2_conn) |
| 800 | { |
| 801 | struct qed_ooo_buffer *p_buffer; |
| 802 | int rc; |
| 803 | |
| 804 | while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn, |
| 805 | p_hwfn->p_ooo_info))) { |
| 806 | rc = qed_ll2_post_rx_buffer(p_hwfn, |
| 807 | p_ll2_conn->my_id, |
| 808 | p_buffer->rx_buffer_phys_addr, |
| 809 | 0, p_buffer, true); |
| 810 | if (rc) { |
| 811 | qed_ooo_put_free_buffer(p_hwfn, |
| 812 | p_hwfn->p_ooo_info, p_buffer); |
| 813 | break; |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | static int qed_ll2_lb_rxq_completion(struct qed_hwfn *p_hwfn, void *p_cookie) |
| 819 | { |
| 820 | struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie; |
| 821 | int rc; |
| 822 | |
| 823 | rc = qed_ll2_lb_rxq_handler(p_hwfn, p_ll2_conn); |
| 824 | if (rc) |
| 825 | return rc; |
| 826 | |
| 827 | qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn); |
| 828 | qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn); |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | static int qed_ll2_lb_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie) |
| 834 | { |
| 835 | struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie; |
| 836 | struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue; |
| 837 | struct qed_ll2_tx_packet *p_pkt = NULL; |
| 838 | struct qed_ooo_buffer *p_buffer; |
| 839 | bool b_dont_submit_rx = false; |
| 840 | u16 new_idx = 0, num_bds = 0; |
| 841 | int rc; |
| 842 | |
| 843 | new_idx = le16_to_cpu(*p_tx->p_fw_cons); |
| 844 | num_bds = ((s16)new_idx - (s16)p_tx->bds_idx); |
| 845 | |
| 846 | if (!num_bds) |
| 847 | return 0; |
| 848 | |
| 849 | while (num_bds) { |
| 850 | if (list_empty(&p_tx->active_descq)) |
| 851 | return -EINVAL; |
| 852 | |
| 853 | p_pkt = list_first_entry(&p_tx->active_descq, |
| 854 | struct qed_ll2_tx_packet, list_entry); |
| 855 | if (!p_pkt) |
| 856 | return -EINVAL; |
| 857 | |
| 858 | if (p_pkt->bd_used != 1) { |
| 859 | DP_NOTICE(p_hwfn, |
| 860 | "Unexpectedly many BDs(%d) in TX OOO completion\n", |
| 861 | p_pkt->bd_used); |
| 862 | return -EINVAL; |
| 863 | } |
| 864 | |
| 865 | list_del(&p_pkt->list_entry); |
| 866 | |
| 867 | num_bds--; |
| 868 | p_tx->bds_idx++; |
| 869 | qed_chain_consume(&p_tx->txq_chain); |
| 870 | |
| 871 | p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie; |
| 872 | list_add_tail(&p_pkt->list_entry, &p_tx->free_descq); |
| 873 | |
| 874 | if (b_dont_submit_rx) { |
| 875 | qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info, |
| 876 | p_buffer); |
| 877 | continue; |
| 878 | } |
| 879 | |
| 880 | rc = qed_ll2_post_rx_buffer(p_hwfn, p_ll2_conn->my_id, |
| 881 | p_buffer->rx_buffer_phys_addr, 0, |
| 882 | p_buffer, true); |
| 883 | if (rc != 0) { |
| 884 | qed_ooo_put_free_buffer(p_hwfn, |
| 885 | p_hwfn->p_ooo_info, p_buffer); |
| 886 | b_dont_submit_rx = true; |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn); |
| 891 | |
| 892 | return 0; |
| 893 | } |
| 894 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 895 | static void qed_ll2_stop_ooo(struct qed_dev *cdev) |
| 896 | { |
| 897 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 898 | u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id; |
| 899 | |
| 900 | DP_VERBOSE(cdev, QED_MSG_STORAGE, "Stopping LL2 OOO queue [%02x]\n", |
| 901 | *handle); |
| 902 | |
| 903 | qed_ll2_terminate_connection(hwfn, *handle); |
| 904 | qed_ll2_release_connection(hwfn, *handle); |
| 905 | *handle = QED_LL2_UNUSED_HANDLE; |
| 906 | } |
| 907 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 908 | static int qed_sp_ll2_rx_queue_start(struct qed_hwfn *p_hwfn, |
| 909 | struct qed_ll2_info *p_ll2_conn, |
| 910 | u8 action_on_error) |
| 911 | { |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 912 | enum qed_ll2_conn_type conn_type = p_ll2_conn->input.conn_type; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 913 | struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue; |
| 914 | struct core_rx_start_ramrod_data *p_ramrod = NULL; |
| 915 | struct qed_spq_entry *p_ent = NULL; |
| 916 | struct qed_sp_init_data init_data; |
| 917 | u16 cqe_pbl_size; |
| 918 | int rc = 0; |
| 919 | |
| 920 | /* Get SPQ entry */ |
| 921 | memset(&init_data, 0, sizeof(init_data)); |
| 922 | init_data.cid = p_ll2_conn->cid; |
| 923 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 924 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 925 | |
| 926 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 927 | CORE_RAMROD_RX_QUEUE_START, |
| 928 | PROTOCOLID_CORE, &init_data); |
| 929 | if (rc) |
| 930 | return rc; |
| 931 | |
| 932 | p_ramrod = &p_ent->ramrod.core_rx_queue_start; |
| 933 | |
| 934 | p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn)); |
| 935 | p_ramrod->sb_index = p_rx->rx_sb_index; |
| 936 | p_ramrod->complete_event_flg = 1; |
| 937 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 938 | p_ramrod->mtu = cpu_to_le16(p_ll2_conn->input.mtu); |
| 939 | DMA_REGPAIR_LE(p_ramrod->bd_base, p_rx->rxq_chain.p_phys_addr); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 940 | cqe_pbl_size = (u16)qed_chain_get_page_cnt(&p_rx->rcq_chain); |
| 941 | p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size); |
| 942 | DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr, |
| 943 | qed_chain_get_pbl_phys(&p_rx->rcq_chain)); |
| 944 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 945 | p_ramrod->drop_ttl0_flg = p_ll2_conn->input.rx_drop_ttl0_flg; |
Tomer Tayar | da09091 | 2017-12-27 19:30:07 +0200 | [diff] [blame] | 946 | p_ramrod->inner_vlan_stripping_en = |
| 947 | p_ll2_conn->input.rx_vlan_removal_en; |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 948 | |
| 949 | if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) && |
| 950 | p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE) |
| 951 | p_ramrod->report_outer_vlan = 1; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 952 | p_ramrod->queue_id = p_ll2_conn->queue_id; |
Michal Kalderon | ed468eb | 2017-10-09 12:37:44 +0300 | [diff] [blame] | 953 | p_ramrod->main_func_queue = p_ll2_conn->main_func_queue ? 1 : 0; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 954 | |
Sudarsana Reddy Kalluru | 0bc5fe8 | 2018-05-05 18:42:59 -0700 | [diff] [blame] | 955 | if (test_bit(QED_MF_LL2_NON_UNICAST, &p_hwfn->cdev->mf_bits) && |
| 956 | p_ramrod->main_func_queue && conn_type != QED_LL2_TYPE_ROCE && |
| 957 | conn_type != QED_LL2_TYPE_IWARP) { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 958 | p_ramrod->mf_si_bcast_accept_all = 1; |
| 959 | p_ramrod->mf_si_mcast_accept_all = 1; |
| 960 | } else { |
| 961 | p_ramrod->mf_si_bcast_accept_all = 0; |
| 962 | p_ramrod->mf_si_mcast_accept_all = 0; |
| 963 | } |
| 964 | |
| 965 | p_ramrod->action_on_error.error_type = action_on_error; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 966 | p_ramrod->gsi_offload_flag = p_ll2_conn->input.gsi_enable; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 967 | return qed_spq_post(p_hwfn, p_ent, NULL); |
| 968 | } |
| 969 | |
| 970 | static int qed_sp_ll2_tx_queue_start(struct qed_hwfn *p_hwfn, |
| 971 | struct qed_ll2_info *p_ll2_conn) |
| 972 | { |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 973 | enum qed_ll2_conn_type conn_type = p_ll2_conn->input.conn_type; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 974 | struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue; |
| 975 | struct core_tx_start_ramrod_data *p_ramrod = NULL; |
| 976 | struct qed_spq_entry *p_ent = NULL; |
| 977 | struct qed_sp_init_data init_data; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 978 | u16 pq_id = 0, pbl_size; |
| 979 | int rc = -EINVAL; |
| 980 | |
| 981 | if (!QED_LL2_TX_REGISTERED(p_ll2_conn)) |
| 982 | return 0; |
| 983 | |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 984 | if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 985 | p_ll2_conn->tx_stats_en = 0; |
| 986 | else |
| 987 | p_ll2_conn->tx_stats_en = 1; |
| 988 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 989 | /* Get SPQ entry */ |
| 990 | memset(&init_data, 0, sizeof(init_data)); |
| 991 | init_data.cid = p_ll2_conn->cid; |
| 992 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 993 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 994 | |
| 995 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 996 | CORE_RAMROD_TX_QUEUE_START, |
| 997 | PROTOCOLID_CORE, &init_data); |
| 998 | if (rc) |
| 999 | return rc; |
| 1000 | |
| 1001 | p_ramrod = &p_ent->ramrod.core_tx_queue_start; |
| 1002 | |
| 1003 | p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn)); |
| 1004 | p_ramrod->sb_index = p_tx->tx_sb_index; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1005 | p_ramrod->mtu = cpu_to_le16(p_ll2_conn->input.mtu); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1006 | p_ramrod->stats_en = p_ll2_conn->tx_stats_en; |
| 1007 | p_ramrod->stats_id = p_ll2_conn->tx_stats_id; |
| 1008 | |
| 1009 | DMA_REGPAIR_LE(p_ramrod->pbl_base_addr, |
| 1010 | qed_chain_get_pbl_phys(&p_tx->txq_chain)); |
| 1011 | pbl_size = qed_chain_get_page_cnt(&p_tx->txq_chain); |
| 1012 | p_ramrod->pbl_size = cpu_to_le16(pbl_size); |
| 1013 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1014 | switch (p_ll2_conn->input.tx_tc) { |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 1015 | case PURE_LB_TC: |
Ariel Elior | b5a9ee7 | 2017-04-03 12:21:09 +0300 | [diff] [blame] | 1016 | pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB); |
| 1017 | break; |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 1018 | case PKT_LB_TC: |
Ariel Elior | b5a9ee7 | 2017-04-03 12:21:09 +0300 | [diff] [blame] | 1019 | pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OOO); |
Colin Ian King | 827d240 | 2017-04-05 13:35:44 +0100 | [diff] [blame] | 1020 | break; |
Ariel Elior | b5a9ee7 | 2017-04-03 12:21:09 +0300 | [diff] [blame] | 1021 | default: |
| 1022 | pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD); |
| 1023 | break; |
| 1024 | } |
| 1025 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1026 | p_ramrod->qm_pq_id = cpu_to_le16(pq_id); |
| 1027 | |
| 1028 | switch (conn_type) { |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1029 | case QED_LL2_TYPE_FCOE: |
| 1030 | p_ramrod->conn_type = PROTOCOLID_FCOE; |
| 1031 | break; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1032 | case QED_LL2_TYPE_ISCSI: |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1033 | p_ramrod->conn_type = PROTOCOLID_ISCSI; |
| 1034 | break; |
| 1035 | case QED_LL2_TYPE_ROCE: |
| 1036 | p_ramrod->conn_type = PROTOCOLID_ROCE; |
| 1037 | break; |
Kalderon, Michal | cc4ad32 | 2017-07-02 10:29:24 +0300 | [diff] [blame] | 1038 | case QED_LL2_TYPE_IWARP: |
| 1039 | p_ramrod->conn_type = PROTOCOLID_IWARP; |
| 1040 | break; |
| 1041 | case QED_LL2_TYPE_OOO: |
| 1042 | if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) |
| 1043 | p_ramrod->conn_type = PROTOCOLID_ISCSI; |
| 1044 | else |
| 1045 | p_ramrod->conn_type = PROTOCOLID_IWARP; |
| 1046 | break; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1047 | default: |
| 1048 | p_ramrod->conn_type = PROTOCOLID_ETH; |
| 1049 | DP_NOTICE(p_hwfn, "Unknown connection type: %d\n", conn_type); |
| 1050 | } |
| 1051 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1052 | p_ramrod->gsi_offload_flag = p_ll2_conn->input.gsi_enable; |
| 1053 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1054 | return qed_spq_post(p_hwfn, p_ent, NULL); |
| 1055 | } |
| 1056 | |
| 1057 | static int qed_sp_ll2_rx_queue_stop(struct qed_hwfn *p_hwfn, |
| 1058 | struct qed_ll2_info *p_ll2_conn) |
| 1059 | { |
| 1060 | struct core_rx_stop_ramrod_data *p_ramrod = NULL; |
| 1061 | struct qed_spq_entry *p_ent = NULL; |
| 1062 | struct qed_sp_init_data init_data; |
| 1063 | int rc = -EINVAL; |
| 1064 | |
| 1065 | /* Get SPQ entry */ |
| 1066 | memset(&init_data, 0, sizeof(init_data)); |
| 1067 | init_data.cid = p_ll2_conn->cid; |
| 1068 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1069 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1070 | |
| 1071 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1072 | CORE_RAMROD_RX_QUEUE_STOP, |
| 1073 | PROTOCOLID_CORE, &init_data); |
| 1074 | if (rc) |
| 1075 | return rc; |
| 1076 | |
| 1077 | p_ramrod = &p_ent->ramrod.core_rx_queue_stop; |
| 1078 | |
| 1079 | p_ramrod->complete_event_flg = 1; |
| 1080 | p_ramrod->queue_id = p_ll2_conn->queue_id; |
| 1081 | |
| 1082 | return qed_spq_post(p_hwfn, p_ent, NULL); |
| 1083 | } |
| 1084 | |
| 1085 | static int qed_sp_ll2_tx_queue_stop(struct qed_hwfn *p_hwfn, |
| 1086 | struct qed_ll2_info *p_ll2_conn) |
| 1087 | { |
| 1088 | struct qed_spq_entry *p_ent = NULL; |
| 1089 | struct qed_sp_init_data init_data; |
| 1090 | int rc = -EINVAL; |
| 1091 | |
| 1092 | /* Get SPQ entry */ |
| 1093 | memset(&init_data, 0, sizeof(init_data)); |
| 1094 | init_data.cid = p_ll2_conn->cid; |
| 1095 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1096 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1097 | |
| 1098 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1099 | CORE_RAMROD_TX_QUEUE_STOP, |
| 1100 | PROTOCOLID_CORE, &init_data); |
| 1101 | if (rc) |
| 1102 | return rc; |
| 1103 | |
| 1104 | return qed_spq_post(p_hwfn, p_ent, NULL); |
| 1105 | } |
| 1106 | |
| 1107 | static int |
| 1108 | qed_ll2_acquire_connection_rx(struct qed_hwfn *p_hwfn, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1109 | struct qed_ll2_info *p_ll2_info) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1110 | { |
| 1111 | struct qed_ll2_rx_packet *p_descq; |
| 1112 | u32 capacity; |
| 1113 | int rc = 0; |
| 1114 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1115 | if (!p_ll2_info->input.rx_num_desc) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1116 | goto out; |
| 1117 | |
| 1118 | rc = qed_chain_alloc(p_hwfn->cdev, |
| 1119 | QED_CHAIN_USE_TO_CONSUME_PRODUCE, |
| 1120 | QED_CHAIN_MODE_NEXT_PTR, |
| 1121 | QED_CHAIN_CNT_TYPE_U16, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1122 | p_ll2_info->input.rx_num_desc, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1123 | sizeof(struct core_rx_bd), |
Mintz, Yuval | 1a4a697 | 2017-06-20 16:00:00 +0300 | [diff] [blame] | 1124 | &p_ll2_info->rx_queue.rxq_chain, NULL); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1125 | if (rc) { |
| 1126 | DP_NOTICE(p_hwfn, "Failed to allocate ll2 rxq chain\n"); |
| 1127 | goto out; |
| 1128 | } |
| 1129 | |
| 1130 | capacity = qed_chain_get_capacity(&p_ll2_info->rx_queue.rxq_chain); |
| 1131 | p_descq = kcalloc(capacity, sizeof(struct qed_ll2_rx_packet), |
| 1132 | GFP_KERNEL); |
| 1133 | if (!p_descq) { |
| 1134 | rc = -ENOMEM; |
| 1135 | DP_NOTICE(p_hwfn, "Failed to allocate ll2 Rx desc\n"); |
| 1136 | goto out; |
| 1137 | } |
| 1138 | p_ll2_info->rx_queue.descq_array = p_descq; |
| 1139 | |
| 1140 | rc = qed_chain_alloc(p_hwfn->cdev, |
| 1141 | QED_CHAIN_USE_TO_CONSUME_PRODUCE, |
| 1142 | QED_CHAIN_MODE_PBL, |
| 1143 | QED_CHAIN_CNT_TYPE_U16, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1144 | p_ll2_info->input.rx_num_desc, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1145 | sizeof(struct core_rx_fast_path_cqe), |
Mintz, Yuval | 1a4a697 | 2017-06-20 16:00:00 +0300 | [diff] [blame] | 1146 | &p_ll2_info->rx_queue.rcq_chain, NULL); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1147 | if (rc) { |
| 1148 | DP_NOTICE(p_hwfn, "Failed to allocate ll2 rcq chain\n"); |
| 1149 | goto out; |
| 1150 | } |
| 1151 | |
| 1152 | DP_VERBOSE(p_hwfn, QED_MSG_LL2, |
| 1153 | "Allocated LL2 Rxq [Type %08x] with 0x%08x buffers\n", |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1154 | p_ll2_info->input.conn_type, p_ll2_info->input.rx_num_desc); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1155 | |
| 1156 | out: |
| 1157 | return rc; |
| 1158 | } |
| 1159 | |
| 1160 | static int qed_ll2_acquire_connection_tx(struct qed_hwfn *p_hwfn, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1161 | struct qed_ll2_info *p_ll2_info) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1162 | { |
| 1163 | struct qed_ll2_tx_packet *p_descq; |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1164 | u32 desc_size; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1165 | u32 capacity; |
| 1166 | int rc = 0; |
| 1167 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1168 | if (!p_ll2_info->input.tx_num_desc) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1169 | goto out; |
| 1170 | |
| 1171 | rc = qed_chain_alloc(p_hwfn->cdev, |
| 1172 | QED_CHAIN_USE_TO_CONSUME_PRODUCE, |
| 1173 | QED_CHAIN_MODE_PBL, |
| 1174 | QED_CHAIN_CNT_TYPE_U16, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1175 | p_ll2_info->input.tx_num_desc, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1176 | sizeof(struct core_tx_bd), |
Mintz, Yuval | 1a4a697 | 2017-06-20 16:00:00 +0300 | [diff] [blame] | 1177 | &p_ll2_info->tx_queue.txq_chain, NULL); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1178 | if (rc) |
| 1179 | goto out; |
| 1180 | |
| 1181 | capacity = qed_chain_get_capacity(&p_ll2_info->tx_queue.txq_chain); |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1182 | /* First element is part of the packet, rest are flexibly added */ |
| 1183 | desc_size = (sizeof(*p_descq) + |
| 1184 | (p_ll2_info->input.tx_max_bds_per_packet - 1) * |
| 1185 | sizeof(p_descq->bds_set)); |
| 1186 | |
| 1187 | p_descq = kcalloc(capacity, desc_size, GFP_KERNEL); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1188 | if (!p_descq) { |
| 1189 | rc = -ENOMEM; |
| 1190 | goto out; |
| 1191 | } |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1192 | p_ll2_info->tx_queue.descq_mem = p_descq; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1193 | |
| 1194 | DP_VERBOSE(p_hwfn, QED_MSG_LL2, |
| 1195 | "Allocated LL2 Txq [Type %08x] with 0x%08x buffers\n", |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1196 | p_ll2_info->input.conn_type, p_ll2_info->input.tx_num_desc); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1197 | |
| 1198 | out: |
| 1199 | if (rc) |
| 1200 | DP_NOTICE(p_hwfn, |
| 1201 | "Can't allocate memory for Tx LL2 with 0x%08x buffers\n", |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1202 | p_ll2_info->input.tx_num_desc); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1203 | return rc; |
| 1204 | } |
| 1205 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1206 | static int |
| 1207 | qed_ll2_acquire_connection_ooo(struct qed_hwfn *p_hwfn, |
| 1208 | struct qed_ll2_info *p_ll2_info, u16 mtu) |
| 1209 | { |
| 1210 | struct qed_ooo_buffer *p_buf = NULL; |
| 1211 | void *p_virt; |
| 1212 | u16 buf_idx; |
| 1213 | int rc = 0; |
| 1214 | |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 1215 | if (p_ll2_info->input.conn_type != QED_LL2_TYPE_OOO) |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1216 | return rc; |
| 1217 | |
| 1218 | /* Correct number of requested OOO buffers if needed */ |
| 1219 | if (!p_ll2_info->input.rx_num_ooo_buffers) { |
| 1220 | u16 num_desc = p_ll2_info->input.rx_num_desc; |
| 1221 | |
| 1222 | if (!num_desc) |
| 1223 | return -EINVAL; |
| 1224 | p_ll2_info->input.rx_num_ooo_buffers = num_desc * 2; |
| 1225 | } |
| 1226 | |
| 1227 | for (buf_idx = 0; buf_idx < p_ll2_info->input.rx_num_ooo_buffers; |
| 1228 | buf_idx++) { |
| 1229 | p_buf = kzalloc(sizeof(*p_buf), GFP_KERNEL); |
| 1230 | if (!p_buf) { |
| 1231 | rc = -ENOMEM; |
| 1232 | goto out; |
| 1233 | } |
| 1234 | |
| 1235 | p_buf->rx_buffer_size = mtu + 26 + ETH_CACHE_LINE_SIZE; |
| 1236 | p_buf->rx_buffer_size = (p_buf->rx_buffer_size + |
| 1237 | ETH_CACHE_LINE_SIZE - 1) & |
| 1238 | ~(ETH_CACHE_LINE_SIZE - 1); |
| 1239 | p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1240 | p_buf->rx_buffer_size, |
| 1241 | &p_buf->rx_buffer_phys_addr, |
| 1242 | GFP_KERNEL); |
| 1243 | if (!p_virt) { |
| 1244 | kfree(p_buf); |
| 1245 | rc = -ENOMEM; |
| 1246 | goto out; |
| 1247 | } |
| 1248 | |
| 1249 | p_buf->rx_buffer_virt_addr = p_virt; |
| 1250 | qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info, p_buf); |
| 1251 | } |
| 1252 | |
| 1253 | DP_VERBOSE(p_hwfn, QED_MSG_LL2, |
| 1254 | "Allocated [%04x] LL2 OOO buffers [each of size 0x%08x]\n", |
| 1255 | p_ll2_info->input.rx_num_ooo_buffers, p_buf->rx_buffer_size); |
| 1256 | |
| 1257 | out: |
| 1258 | return rc; |
| 1259 | } |
| 1260 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1261 | static int |
| 1262 | qed_ll2_set_cbs(struct qed_ll2_info *p_ll2_info, const struct qed_ll2_cbs *cbs) |
| 1263 | { |
| 1264 | if (!cbs || (!cbs->rx_comp_cb || |
| 1265 | !cbs->rx_release_cb || |
| 1266 | !cbs->tx_comp_cb || !cbs->tx_release_cb || !cbs->cookie)) |
| 1267 | return -EINVAL; |
| 1268 | |
| 1269 | p_ll2_info->cbs.rx_comp_cb = cbs->rx_comp_cb; |
| 1270 | p_ll2_info->cbs.rx_release_cb = cbs->rx_release_cb; |
| 1271 | p_ll2_info->cbs.tx_comp_cb = cbs->tx_comp_cb; |
| 1272 | p_ll2_info->cbs.tx_release_cb = cbs->tx_release_cb; |
Michal Kalderon | 6f34a28 | 2017-10-09 12:37:48 +0300 | [diff] [blame] | 1273 | p_ll2_info->cbs.slowpath_cb = cbs->slowpath_cb; |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1274 | p_ll2_info->cbs.cookie = cbs->cookie; |
| 1275 | |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1279 | static enum core_error_handle |
| 1280 | qed_ll2_get_error_choice(enum qed_ll2_error_handle err) |
| 1281 | { |
| 1282 | switch (err) { |
| 1283 | case QED_LL2_DROP_PACKET: |
| 1284 | return LL2_DROP_PACKET; |
| 1285 | case QED_LL2_DO_NOTHING: |
| 1286 | return LL2_DO_NOTHING; |
| 1287 | case QED_LL2_ASSERT: |
| 1288 | return LL2_ASSERT; |
| 1289 | default: |
| 1290 | return LL2_DO_NOTHING; |
| 1291 | } |
| 1292 | } |
| 1293 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1294 | int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1295 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1296 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1297 | qed_int_comp_cb_t comp_rx_cb, comp_tx_cb; |
| 1298 | struct qed_ll2_info *p_ll2_info = NULL; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1299 | u8 i, *p_tx_max; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1300 | int rc; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1301 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1302 | if (!data->p_connection_handle || !p_hwfn->p_ll2_info) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1303 | return -EINVAL; |
| 1304 | |
| 1305 | /* Find a free connection to be used */ |
| 1306 | for (i = 0; (i < QED_MAX_NUM_OF_LL2_CONNECTIONS); i++) { |
| 1307 | mutex_lock(&p_hwfn->p_ll2_info[i].mutex); |
| 1308 | if (p_hwfn->p_ll2_info[i].b_active) { |
| 1309 | mutex_unlock(&p_hwfn->p_ll2_info[i].mutex); |
| 1310 | continue; |
| 1311 | } |
| 1312 | |
| 1313 | p_hwfn->p_ll2_info[i].b_active = true; |
| 1314 | p_ll2_info = &p_hwfn->p_ll2_info[i]; |
| 1315 | mutex_unlock(&p_hwfn->p_ll2_info[i].mutex); |
| 1316 | break; |
| 1317 | } |
| 1318 | if (!p_ll2_info) |
| 1319 | return -EBUSY; |
| 1320 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1321 | memcpy(&p_ll2_info->input, &data->input, sizeof(p_ll2_info->input)); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1322 | |
Tomer Tayar | da09091 | 2017-12-27 19:30:07 +0200 | [diff] [blame] | 1323 | switch (data->input.tx_dest) { |
| 1324 | case QED_LL2_TX_DEST_NW: |
| 1325 | p_ll2_info->tx_dest = CORE_TX_DEST_NW; |
| 1326 | break; |
| 1327 | case QED_LL2_TX_DEST_LB: |
| 1328 | p_ll2_info->tx_dest = CORE_TX_DEST_LB; |
| 1329 | break; |
| 1330 | case QED_LL2_TX_DEST_DROP: |
| 1331 | p_ll2_info->tx_dest = CORE_TX_DEST_DROP; |
| 1332 | break; |
| 1333 | default: |
| 1334 | return -EINVAL; |
| 1335 | } |
| 1336 | |
Michal Kalderon | ed468eb | 2017-10-09 12:37:44 +0300 | [diff] [blame] | 1337 | if (data->input.conn_type == QED_LL2_TYPE_OOO || |
| 1338 | data->input.secondary_queue) |
| 1339 | p_ll2_info->main_func_queue = false; |
| 1340 | else |
| 1341 | p_ll2_info->main_func_queue = true; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1342 | |
| 1343 | /* Correct maximum number of Tx BDs */ |
| 1344 | p_tx_max = &p_ll2_info->input.tx_max_bds_per_packet; |
| 1345 | if (*p_tx_max == 0) |
| 1346 | *p_tx_max = CORE_LL2_TX_MAX_BDS_PER_PACKET; |
| 1347 | else |
| 1348 | *p_tx_max = min_t(u8, *p_tx_max, |
| 1349 | CORE_LL2_TX_MAX_BDS_PER_PACKET); |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1350 | |
| 1351 | rc = qed_ll2_set_cbs(p_ll2_info, data->cbs); |
| 1352 | if (rc) { |
| 1353 | DP_NOTICE(p_hwfn, "Invalid callback functions\n"); |
| 1354 | goto q_allocate_fail; |
| 1355 | } |
| 1356 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1357 | rc = qed_ll2_acquire_connection_rx(p_hwfn, p_ll2_info); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1358 | if (rc) |
| 1359 | goto q_allocate_fail; |
| 1360 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1361 | rc = qed_ll2_acquire_connection_tx(p_hwfn, p_ll2_info); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1362 | if (rc) |
| 1363 | goto q_allocate_fail; |
| 1364 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 1365 | rc = qed_ll2_acquire_connection_ooo(p_hwfn, p_ll2_info, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1366 | data->input.mtu); |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 1367 | if (rc) |
| 1368 | goto q_allocate_fail; |
| 1369 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1370 | /* Register callbacks for the Rx/Tx queues */ |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 1371 | if (data->input.conn_type == QED_LL2_TYPE_OOO) { |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 1372 | comp_rx_cb = qed_ll2_lb_rxq_completion; |
| 1373 | comp_tx_cb = qed_ll2_lb_txq_completion; |
| 1374 | } else { |
| 1375 | comp_rx_cb = qed_ll2_rxq_completion; |
| 1376 | comp_tx_cb = qed_ll2_txq_completion; |
| 1377 | } |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1378 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1379 | if (data->input.rx_num_desc) { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1380 | qed_int_register_cb(p_hwfn, comp_rx_cb, |
| 1381 | &p_hwfn->p_ll2_info[i], |
| 1382 | &p_ll2_info->rx_queue.rx_sb_index, |
| 1383 | &p_ll2_info->rx_queue.p_fw_cons); |
| 1384 | p_ll2_info->rx_queue.b_cb_registred = true; |
| 1385 | } |
| 1386 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1387 | if (data->input.tx_num_desc) { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1388 | qed_int_register_cb(p_hwfn, |
| 1389 | comp_tx_cb, |
| 1390 | &p_hwfn->p_ll2_info[i], |
| 1391 | &p_ll2_info->tx_queue.tx_sb_index, |
| 1392 | &p_ll2_info->tx_queue.p_fw_cons); |
| 1393 | p_ll2_info->tx_queue.b_cb_registred = true; |
| 1394 | } |
| 1395 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1396 | *data->p_connection_handle = i; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1397 | return rc; |
| 1398 | |
| 1399 | q_allocate_fail: |
| 1400 | qed_ll2_release_connection(p_hwfn, i); |
| 1401 | return -ENOMEM; |
| 1402 | } |
| 1403 | |
| 1404 | static int qed_ll2_establish_connection_rx(struct qed_hwfn *p_hwfn, |
| 1405 | struct qed_ll2_info *p_ll2_conn) |
| 1406 | { |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1407 | enum qed_ll2_error_handle error_input; |
| 1408 | enum core_error_handle error_mode; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1409 | u8 action_on_error = 0; |
| 1410 | |
| 1411 | if (!QED_LL2_RX_REGISTERED(p_ll2_conn)) |
| 1412 | return 0; |
| 1413 | |
| 1414 | DIRECT_REG_WR(p_ll2_conn->rx_queue.set_prod_addr, 0x0); |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1415 | error_input = p_ll2_conn->input.ai_err_packet_too_big; |
| 1416 | error_mode = qed_ll2_get_error_choice(error_input); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1417 | SET_FIELD(action_on_error, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1418 | CORE_RX_ACTION_ON_ERROR_PACKET_TOO_BIG, error_mode); |
| 1419 | error_input = p_ll2_conn->input.ai_err_no_buf; |
| 1420 | error_mode = qed_ll2_get_error_choice(error_input); |
| 1421 | SET_FIELD(action_on_error, CORE_RX_ACTION_ON_ERROR_NO_BUFF, error_mode); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1422 | |
| 1423 | return qed_sp_ll2_rx_queue_start(p_hwfn, p_ll2_conn, action_on_error); |
| 1424 | } |
| 1425 | |
Mintz, Yuval | 58de289 | 2017-06-09 17:13:21 +0300 | [diff] [blame] | 1426 | static void |
| 1427 | qed_ll2_establish_connection_ooo(struct qed_hwfn *p_hwfn, |
| 1428 | struct qed_ll2_info *p_ll2_conn) |
| 1429 | { |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 1430 | if (p_ll2_conn->input.conn_type != QED_LL2_TYPE_OOO) |
Mintz, Yuval | 58de289 | 2017-06-09 17:13:21 +0300 | [diff] [blame] | 1431 | return; |
| 1432 | |
| 1433 | qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info); |
| 1434 | qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn); |
| 1435 | } |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1436 | |
| 1437 | int qed_ll2_establish_connection(void *cxt, u8 connection_handle) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1438 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1439 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1440 | struct qed_ll2_info *p_ll2_conn; |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1441 | struct qed_ll2_tx_packet *p_pkt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1442 | struct qed_ll2_rx_queue *p_rx; |
| 1443 | struct qed_ll2_tx_queue *p_tx; |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1444 | struct qed_ptt *p_ptt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1445 | int rc = -EINVAL; |
| 1446 | u32 i, capacity; |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1447 | u32 desc_size; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1448 | u8 qid; |
| 1449 | |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1450 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 1451 | if (!p_ptt) |
| 1452 | return -EAGAIN; |
| 1453 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1454 | p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle); |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1455 | if (!p_ll2_conn) { |
| 1456 | rc = -EINVAL; |
| 1457 | goto out; |
| 1458 | } |
| 1459 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1460 | p_rx = &p_ll2_conn->rx_queue; |
| 1461 | p_tx = &p_ll2_conn->tx_queue; |
| 1462 | |
| 1463 | qed_chain_reset(&p_rx->rxq_chain); |
| 1464 | qed_chain_reset(&p_rx->rcq_chain); |
| 1465 | INIT_LIST_HEAD(&p_rx->active_descq); |
| 1466 | INIT_LIST_HEAD(&p_rx->free_descq); |
| 1467 | INIT_LIST_HEAD(&p_rx->posting_descq); |
| 1468 | spin_lock_init(&p_rx->lock); |
| 1469 | capacity = qed_chain_get_capacity(&p_rx->rxq_chain); |
| 1470 | for (i = 0; i < capacity; i++) |
| 1471 | list_add_tail(&p_rx->descq_array[i].list_entry, |
| 1472 | &p_rx->free_descq); |
| 1473 | *p_rx->p_fw_cons = 0; |
| 1474 | |
| 1475 | qed_chain_reset(&p_tx->txq_chain); |
| 1476 | INIT_LIST_HEAD(&p_tx->active_descq); |
| 1477 | INIT_LIST_HEAD(&p_tx->free_descq); |
| 1478 | INIT_LIST_HEAD(&p_tx->sending_descq); |
| 1479 | spin_lock_init(&p_tx->lock); |
| 1480 | capacity = qed_chain_get_capacity(&p_tx->txq_chain); |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1481 | /* First element is part of the packet, rest are flexibly added */ |
| 1482 | desc_size = (sizeof(*p_pkt) + |
| 1483 | (p_ll2_conn->input.tx_max_bds_per_packet - 1) * |
| 1484 | sizeof(p_pkt->bds_set)); |
| 1485 | |
| 1486 | for (i = 0; i < capacity; i++) { |
| 1487 | p_pkt = p_tx->descq_mem + desc_size * i; |
| 1488 | list_add_tail(&p_pkt->list_entry, &p_tx->free_descq); |
| 1489 | } |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1490 | p_tx->cur_completing_bd_idx = 0; |
| 1491 | p_tx->bds_idx = 0; |
| 1492 | p_tx->b_completing_packet = false; |
| 1493 | p_tx->cur_send_packet = NULL; |
| 1494 | p_tx->cur_send_frag_num = 0; |
| 1495 | p_tx->cur_completing_frag_num = 0; |
| 1496 | *p_tx->p_fw_cons = 0; |
| 1497 | |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1498 | rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_CORE, &p_ll2_conn->cid); |
| 1499 | if (rc) |
| 1500 | goto out; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1501 | |
| 1502 | qid = p_hwfn->hw_info.resc_start[QED_LL2_QUEUE] + connection_handle; |
| 1503 | p_ll2_conn->queue_id = qid; |
| 1504 | p_ll2_conn->tx_stats_id = qid; |
| 1505 | p_rx->set_prod_addr = (u8 __iomem *)p_hwfn->regview + |
| 1506 | GTT_BAR0_MAP_REG_TSDM_RAM + |
| 1507 | TSTORM_LL2_RX_PRODS_OFFSET(qid); |
| 1508 | p_tx->doorbell_addr = (u8 __iomem *)p_hwfn->doorbells + |
| 1509 | qed_db_addr(p_ll2_conn->cid, |
| 1510 | DQ_DEMS_LEGACY); |
| 1511 | |
| 1512 | rc = qed_ll2_establish_connection_rx(p_hwfn, p_ll2_conn); |
| 1513 | if (rc) |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1514 | goto out; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1515 | |
| 1516 | rc = qed_sp_ll2_tx_queue_start(p_hwfn, p_ll2_conn); |
| 1517 | if (rc) |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1518 | goto out; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1519 | |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 1520 | if (!QED_IS_RDMA_PERSONALITY(p_hwfn)) |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1521 | qed_wr(p_hwfn, p_ptt, PRS_REG_USE_LIGHT_L2, 1); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1522 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 1523 | qed_ll2_establish_connection_ooo(p_hwfn, p_ll2_conn); |
| 1524 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1525 | if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE) { |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1526 | if (!test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits)) |
| 1527 | qed_llh_add_protocol_filter(p_hwfn, p_ptt, |
| 1528 | ETH_P_FCOE, 0, |
| 1529 | QED_LLH_FILTER_ETHERTYPE); |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1530 | qed_llh_add_protocol_filter(p_hwfn, p_ptt, |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1531 | ETH_P_FIP, 0, |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1532 | QED_LLH_FILTER_ETHERTYPE); |
| 1533 | } |
| 1534 | |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1535 | out: |
| 1536 | qed_ptt_release(p_hwfn, p_ptt); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1537 | return rc; |
| 1538 | } |
| 1539 | |
| 1540 | static void qed_ll2_post_rx_buffer_notify_fw(struct qed_hwfn *p_hwfn, |
| 1541 | struct qed_ll2_rx_queue *p_rx, |
| 1542 | struct qed_ll2_rx_packet *p_curp) |
| 1543 | { |
| 1544 | struct qed_ll2_rx_packet *p_posting_packet = NULL; |
| 1545 | struct core_ll2_rx_prod rx_prod = { 0, 0, 0 }; |
| 1546 | bool b_notify_fw = false; |
| 1547 | u16 bd_prod, cq_prod; |
| 1548 | |
| 1549 | /* This handles the flushing of already posted buffers */ |
| 1550 | while (!list_empty(&p_rx->posting_descq)) { |
| 1551 | p_posting_packet = list_first_entry(&p_rx->posting_descq, |
| 1552 | struct qed_ll2_rx_packet, |
| 1553 | list_entry); |
Wei Yongjun | b4f0fd4 | 2016-10-17 15:17:51 +0000 | [diff] [blame] | 1554 | list_move_tail(&p_posting_packet->list_entry, |
| 1555 | &p_rx->active_descq); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1556 | b_notify_fw = true; |
| 1557 | } |
| 1558 | |
| 1559 | /* This handles the supplied packet [if there is one] */ |
| 1560 | if (p_curp) { |
| 1561 | list_add_tail(&p_curp->list_entry, &p_rx->active_descq); |
| 1562 | b_notify_fw = true; |
| 1563 | } |
| 1564 | |
| 1565 | if (!b_notify_fw) |
| 1566 | return; |
| 1567 | |
| 1568 | bd_prod = qed_chain_get_prod_idx(&p_rx->rxq_chain); |
| 1569 | cq_prod = qed_chain_get_prod_idx(&p_rx->rcq_chain); |
| 1570 | rx_prod.bd_prod = cpu_to_le16(bd_prod); |
| 1571 | rx_prod.cqe_prod = cpu_to_le16(cq_prod); |
| 1572 | DIRECT_REG_WR(p_rx->set_prod_addr, *((u32 *)&rx_prod)); |
| 1573 | } |
| 1574 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1575 | int qed_ll2_post_rx_buffer(void *cxt, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1576 | u8 connection_handle, |
| 1577 | dma_addr_t addr, |
| 1578 | u16 buf_len, void *cookie, u8 notify_fw) |
| 1579 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1580 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1581 | struct core_rx_bd_with_buff_len *p_curb = NULL; |
| 1582 | struct qed_ll2_rx_packet *p_curp = NULL; |
| 1583 | struct qed_ll2_info *p_ll2_conn; |
| 1584 | struct qed_ll2_rx_queue *p_rx; |
| 1585 | unsigned long flags; |
| 1586 | void *p_data; |
| 1587 | int rc = 0; |
| 1588 | |
| 1589 | p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle); |
| 1590 | if (!p_ll2_conn) |
| 1591 | return -EINVAL; |
| 1592 | p_rx = &p_ll2_conn->rx_queue; |
| 1593 | |
| 1594 | spin_lock_irqsave(&p_rx->lock, flags); |
| 1595 | if (!list_empty(&p_rx->free_descq)) |
| 1596 | p_curp = list_first_entry(&p_rx->free_descq, |
| 1597 | struct qed_ll2_rx_packet, list_entry); |
| 1598 | if (p_curp) { |
| 1599 | if (qed_chain_get_elem_left(&p_rx->rxq_chain) && |
| 1600 | qed_chain_get_elem_left(&p_rx->rcq_chain)) { |
| 1601 | p_data = qed_chain_produce(&p_rx->rxq_chain); |
| 1602 | p_curb = (struct core_rx_bd_with_buff_len *)p_data; |
| 1603 | qed_chain_produce(&p_rx->rcq_chain); |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | /* If we're lacking entires, let's try to flush buffers to FW */ |
| 1608 | if (!p_curp || !p_curb) { |
| 1609 | rc = -EBUSY; |
| 1610 | p_curp = NULL; |
| 1611 | goto out_notify; |
| 1612 | } |
| 1613 | |
| 1614 | /* We have an Rx packet we can fill */ |
| 1615 | DMA_REGPAIR_LE(p_curb->addr, addr); |
| 1616 | p_curb->buff_length = cpu_to_le16(buf_len); |
| 1617 | p_curp->rx_buf_addr = addr; |
| 1618 | p_curp->cookie = cookie; |
| 1619 | p_curp->rxq_bd = p_curb; |
| 1620 | p_curp->buf_length = buf_len; |
| 1621 | list_del(&p_curp->list_entry); |
| 1622 | |
| 1623 | /* Check if we only want to enqueue this packet without informing FW */ |
| 1624 | if (!notify_fw) { |
| 1625 | list_add_tail(&p_curp->list_entry, &p_rx->posting_descq); |
| 1626 | goto out; |
| 1627 | } |
| 1628 | |
| 1629 | out_notify: |
| 1630 | qed_ll2_post_rx_buffer_notify_fw(p_hwfn, p_rx, p_curp); |
| 1631 | out: |
| 1632 | spin_unlock_irqrestore(&p_rx->lock, flags); |
| 1633 | return rc; |
| 1634 | } |
| 1635 | |
| 1636 | static void qed_ll2_prepare_tx_packet_set(struct qed_hwfn *p_hwfn, |
| 1637 | struct qed_ll2_tx_queue *p_tx, |
| 1638 | struct qed_ll2_tx_packet *p_curp, |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1639 | struct qed_ll2_tx_pkt_info *pkt, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1640 | u8 notify_fw) |
| 1641 | { |
| 1642 | list_del(&p_curp->list_entry); |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1643 | p_curp->cookie = pkt->cookie; |
| 1644 | p_curp->bd_used = pkt->num_of_bds; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1645 | p_curp->notify_fw = notify_fw; |
| 1646 | p_tx->cur_send_packet = p_curp; |
| 1647 | p_tx->cur_send_frag_num = 0; |
| 1648 | |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1649 | p_curp->bds_set[p_tx->cur_send_frag_num].tx_frag = pkt->first_frag; |
| 1650 | p_curp->bds_set[p_tx->cur_send_frag_num].frag_len = pkt->first_frag_len; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1651 | p_tx->cur_send_frag_num++; |
| 1652 | } |
| 1653 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1654 | static void |
| 1655 | qed_ll2_prepare_tx_packet_set_bd(struct qed_hwfn *p_hwfn, |
| 1656 | struct qed_ll2_info *p_ll2, |
| 1657 | struct qed_ll2_tx_packet *p_curp, |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1658 | struct qed_ll2_tx_pkt_info *pkt) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1659 | { |
| 1660 | struct qed_chain *p_tx_chain = &p_ll2->tx_queue.txq_chain; |
| 1661 | u16 prod_idx = qed_chain_get_prod_idx(p_tx_chain); |
| 1662 | struct core_tx_bd *start_bd = NULL; |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1663 | enum core_roce_flavor_type roce_flavor; |
| 1664 | enum core_tx_dest tx_dest; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1665 | u16 bd_data = 0, frag_idx; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1666 | |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1667 | roce_flavor = (pkt->qed_roce_flavor == QED_LL2_ROCE) ? CORE_ROCE |
| 1668 | : CORE_RROCE; |
| 1669 | |
Michal Kalderon | 77caa79 | 2017-10-09 12:37:45 +0300 | [diff] [blame] | 1670 | switch (pkt->tx_dest) { |
| 1671 | case QED_LL2_TX_DEST_NW: |
| 1672 | tx_dest = CORE_TX_DEST_NW; |
| 1673 | break; |
| 1674 | case QED_LL2_TX_DEST_LB: |
| 1675 | tx_dest = CORE_TX_DEST_LB; |
| 1676 | break; |
| 1677 | case QED_LL2_TX_DEST_DROP: |
| 1678 | tx_dest = CORE_TX_DEST_DROP; |
| 1679 | break; |
| 1680 | default: |
| 1681 | tx_dest = CORE_TX_DEST_LB; |
| 1682 | break; |
| 1683 | } |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1684 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1685 | start_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain); |
Michal Kalderon | 89d6511 | 2017-10-09 12:37:47 +0300 | [diff] [blame] | 1686 | if (QED_IS_IWARP_PERSONALITY(p_hwfn) && |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1687 | p_ll2->input.conn_type == QED_LL2_TYPE_OOO) { |
Michal Kalderon | 89d6511 | 2017-10-09 12:37:47 +0300 | [diff] [blame] | 1688 | start_bd->nw_vlan_or_lb_echo = |
| 1689 | cpu_to_le16(IWARP_LL2_IN_ORDER_TX_QUEUE); |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1690 | } else { |
Michal Kalderon | 89d6511 | 2017-10-09 12:37:47 +0300 | [diff] [blame] | 1691 | start_bd->nw_vlan_or_lb_echo = cpu_to_le16(pkt->vlan); |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1692 | if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) && |
| 1693 | p_ll2->input.conn_type == QED_LL2_TYPE_FCOE) |
| 1694 | pkt->remove_stag = true; |
| 1695 | } |
| 1696 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1697 | SET_FIELD(start_bd->bitfield1, CORE_TX_BD_L4_HDR_OFFSET_W, |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1698 | cpu_to_le16(pkt->l4_hdr_offset_w)); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1699 | SET_FIELD(start_bd->bitfield1, CORE_TX_BD_TX_DST, tx_dest); |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1700 | bd_data |= pkt->bd_flags; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1701 | SET_FIELD(bd_data, CORE_TX_BD_DATA_START_BD, 0x1); |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1702 | SET_FIELD(bd_data, CORE_TX_BD_DATA_NBDS, pkt->num_of_bds); |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1703 | SET_FIELD(bd_data, CORE_TX_BD_DATA_ROCE_FLAV, roce_flavor); |
Michal Kalderon | 6df60fe | 2017-10-09 12:37:46 +0300 | [diff] [blame] | 1704 | SET_FIELD(bd_data, CORE_TX_BD_DATA_IP_CSUM, !!(pkt->enable_ip_cksum)); |
| 1705 | SET_FIELD(bd_data, CORE_TX_BD_DATA_L4_CSUM, !!(pkt->enable_l4_cksum)); |
| 1706 | SET_FIELD(bd_data, CORE_TX_BD_DATA_IP_LEN, !!(pkt->calc_ip_len)); |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1707 | SET_FIELD(bd_data, CORE_TX_BD_DATA_DISABLE_STAG_INSERTION, |
| 1708 | !!(pkt->remove_stag)); |
| 1709 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1710 | start_bd->bd_data.as_bitfield = cpu_to_le16(bd_data); |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1711 | DMA_REGPAIR_LE(start_bd->addr, pkt->first_frag); |
| 1712 | start_bd->nbytes = cpu_to_le16(pkt->first_frag_len); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1713 | |
| 1714 | DP_VERBOSE(p_hwfn, |
| 1715 | (NETIF_MSG_TX_QUEUED | QED_MSG_LL2), |
| 1716 | "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Tx Producer at [0x%04x] - set with a %04x bytes %02x BDs buffer at %08x:%08x\n", |
| 1717 | p_ll2->queue_id, |
| 1718 | p_ll2->cid, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1719 | p_ll2->input.conn_type, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1720 | prod_idx, |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1721 | pkt->first_frag_len, |
| 1722 | pkt->num_of_bds, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1723 | le32_to_cpu(start_bd->addr.hi), |
| 1724 | le32_to_cpu(start_bd->addr.lo)); |
| 1725 | |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1726 | if (p_ll2->tx_queue.cur_send_frag_num == pkt->num_of_bds) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1727 | return; |
| 1728 | |
| 1729 | /* Need to provide the packet with additional BDs for frags */ |
| 1730 | for (frag_idx = p_ll2->tx_queue.cur_send_frag_num; |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1731 | frag_idx < pkt->num_of_bds; frag_idx++) { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1732 | struct core_tx_bd **p_bd = &p_curp->bds_set[frag_idx].txq_bd; |
| 1733 | |
| 1734 | *p_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain); |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1735 | (*p_bd)->bd_data.as_bitfield = 0; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1736 | (*p_bd)->bitfield1 = 0; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1737 | p_curp->bds_set[frag_idx].tx_frag = 0; |
| 1738 | p_curp->bds_set[frag_idx].frag_len = 0; |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | /* This should be called while the Txq spinlock is being held */ |
| 1743 | static void qed_ll2_tx_packet_notify(struct qed_hwfn *p_hwfn, |
| 1744 | struct qed_ll2_info *p_ll2_conn) |
| 1745 | { |
| 1746 | bool b_notify = p_ll2_conn->tx_queue.cur_send_packet->notify_fw; |
| 1747 | struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue; |
| 1748 | struct qed_ll2_tx_packet *p_pkt = NULL; |
| 1749 | struct core_db_data db_msg = { 0, 0, 0 }; |
| 1750 | u16 bd_prod; |
| 1751 | |
| 1752 | /* If there are missing BDs, don't do anything now */ |
| 1753 | if (p_ll2_conn->tx_queue.cur_send_frag_num != |
| 1754 | p_ll2_conn->tx_queue.cur_send_packet->bd_used) |
| 1755 | return; |
| 1756 | |
| 1757 | /* Push the current packet to the list and clean after it */ |
| 1758 | list_add_tail(&p_ll2_conn->tx_queue.cur_send_packet->list_entry, |
| 1759 | &p_ll2_conn->tx_queue.sending_descq); |
| 1760 | p_ll2_conn->tx_queue.cur_send_packet = NULL; |
| 1761 | p_ll2_conn->tx_queue.cur_send_frag_num = 0; |
| 1762 | |
| 1763 | /* Notify FW of packet only if requested to */ |
| 1764 | if (!b_notify) |
| 1765 | return; |
| 1766 | |
| 1767 | bd_prod = qed_chain_get_prod_idx(&p_ll2_conn->tx_queue.txq_chain); |
| 1768 | |
| 1769 | while (!list_empty(&p_tx->sending_descq)) { |
| 1770 | p_pkt = list_first_entry(&p_tx->sending_descq, |
| 1771 | struct qed_ll2_tx_packet, list_entry); |
| 1772 | if (!p_pkt) |
| 1773 | break; |
| 1774 | |
Wei Yongjun | b4f0fd4 | 2016-10-17 15:17:51 +0000 | [diff] [blame] | 1775 | list_move_tail(&p_pkt->list_entry, &p_tx->active_descq); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | SET_FIELD(db_msg.params, CORE_DB_DATA_DEST, DB_DEST_XCM); |
| 1779 | SET_FIELD(db_msg.params, CORE_DB_DATA_AGG_CMD, DB_AGG_CMD_SET); |
| 1780 | SET_FIELD(db_msg.params, CORE_DB_DATA_AGG_VAL_SEL, |
| 1781 | DQ_XCM_CORE_TX_BD_PROD_CMD); |
| 1782 | db_msg.agg_flags = DQ_XCM_CORE_DQ_CF_CMD; |
| 1783 | db_msg.spq_prod = cpu_to_le16(bd_prod); |
| 1784 | |
| 1785 | /* Make sure the BDs data is updated before ringing the doorbell */ |
| 1786 | wmb(); |
| 1787 | |
| 1788 | DIRECT_REG_WR(p_tx->doorbell_addr, *((u32 *)&db_msg)); |
| 1789 | |
| 1790 | DP_VERBOSE(p_hwfn, |
| 1791 | (NETIF_MSG_TX_QUEUED | QED_MSG_LL2), |
| 1792 | "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Doorbelled [producer 0x%04x]\n", |
| 1793 | p_ll2_conn->queue_id, |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1794 | p_ll2_conn->cid, |
| 1795 | p_ll2_conn->input.conn_type, db_msg.spq_prod); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1796 | } |
| 1797 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1798 | int qed_ll2_prepare_tx_packet(void *cxt, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1799 | u8 connection_handle, |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1800 | struct qed_ll2_tx_pkt_info *pkt, |
| 1801 | bool notify_fw) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1802 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1803 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1804 | struct qed_ll2_tx_packet *p_curp = NULL; |
| 1805 | struct qed_ll2_info *p_ll2_conn = NULL; |
| 1806 | struct qed_ll2_tx_queue *p_tx; |
| 1807 | struct qed_chain *p_tx_chain; |
| 1808 | unsigned long flags; |
| 1809 | int rc = 0; |
| 1810 | |
| 1811 | p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle); |
| 1812 | if (!p_ll2_conn) |
| 1813 | return -EINVAL; |
| 1814 | p_tx = &p_ll2_conn->tx_queue; |
| 1815 | p_tx_chain = &p_tx->txq_chain; |
| 1816 | |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1817 | if (pkt->num_of_bds > p_ll2_conn->input.tx_max_bds_per_packet) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1818 | return -EIO; |
| 1819 | |
| 1820 | spin_lock_irqsave(&p_tx->lock, flags); |
| 1821 | if (p_tx->cur_send_packet) { |
| 1822 | rc = -EEXIST; |
| 1823 | goto out; |
| 1824 | } |
| 1825 | |
| 1826 | /* Get entry, but only if we have tx elements for it */ |
| 1827 | if (!list_empty(&p_tx->free_descq)) |
| 1828 | p_curp = list_first_entry(&p_tx->free_descq, |
| 1829 | struct qed_ll2_tx_packet, list_entry); |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1830 | if (p_curp && qed_chain_get_elem_left(p_tx_chain) < pkt->num_of_bds) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1831 | p_curp = NULL; |
| 1832 | |
| 1833 | if (!p_curp) { |
| 1834 | rc = -EBUSY; |
| 1835 | goto out; |
| 1836 | } |
| 1837 | |
| 1838 | /* Prepare packet and BD, and perhaps send a doorbell to FW */ |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 1839 | qed_ll2_prepare_tx_packet_set(p_hwfn, p_tx, p_curp, pkt, notify_fw); |
| 1840 | |
| 1841 | qed_ll2_prepare_tx_packet_set_bd(p_hwfn, p_ll2_conn, p_curp, pkt); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1842 | |
| 1843 | qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn); |
| 1844 | |
| 1845 | out: |
| 1846 | spin_unlock_irqrestore(&p_tx->lock, flags); |
| 1847 | return rc; |
| 1848 | } |
| 1849 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1850 | int qed_ll2_set_fragment_of_tx_packet(void *cxt, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1851 | u8 connection_handle, |
| 1852 | dma_addr_t addr, u16 nbytes) |
| 1853 | { |
| 1854 | struct qed_ll2_tx_packet *p_cur_send_packet = NULL; |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1855 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1856 | struct qed_ll2_info *p_ll2_conn = NULL; |
| 1857 | u16 cur_send_frag_num = 0; |
| 1858 | struct core_tx_bd *p_bd; |
| 1859 | unsigned long flags; |
| 1860 | |
| 1861 | p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle); |
| 1862 | if (!p_ll2_conn) |
| 1863 | return -EINVAL; |
| 1864 | |
| 1865 | if (!p_ll2_conn->tx_queue.cur_send_packet) |
| 1866 | return -EINVAL; |
| 1867 | |
| 1868 | p_cur_send_packet = p_ll2_conn->tx_queue.cur_send_packet; |
| 1869 | cur_send_frag_num = p_ll2_conn->tx_queue.cur_send_frag_num; |
| 1870 | |
| 1871 | if (cur_send_frag_num >= p_cur_send_packet->bd_used) |
| 1872 | return -EINVAL; |
| 1873 | |
| 1874 | /* Fill the BD information, and possibly notify FW */ |
| 1875 | p_bd = p_cur_send_packet->bds_set[cur_send_frag_num].txq_bd; |
| 1876 | DMA_REGPAIR_LE(p_bd->addr, addr); |
| 1877 | p_bd->nbytes = cpu_to_le16(nbytes); |
| 1878 | p_cur_send_packet->bds_set[cur_send_frag_num].tx_frag = addr; |
| 1879 | p_cur_send_packet->bds_set[cur_send_frag_num].frag_len = nbytes; |
| 1880 | |
| 1881 | p_ll2_conn->tx_queue.cur_send_frag_num++; |
| 1882 | |
| 1883 | spin_lock_irqsave(&p_ll2_conn->tx_queue.lock, flags); |
| 1884 | qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn); |
| 1885 | spin_unlock_irqrestore(&p_ll2_conn->tx_queue.lock, flags); |
| 1886 | |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1890 | int qed_ll2_terminate_connection(void *cxt, u8 connection_handle) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1891 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1892 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1893 | struct qed_ll2_info *p_ll2_conn = NULL; |
| 1894 | int rc = -EINVAL; |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1895 | struct qed_ptt *p_ptt; |
| 1896 | |
| 1897 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 1898 | if (!p_ptt) |
| 1899 | return -EAGAIN; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1900 | |
| 1901 | p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle); |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1902 | if (!p_ll2_conn) { |
| 1903 | rc = -EINVAL; |
| 1904 | goto out; |
| 1905 | } |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1906 | |
| 1907 | /* Stop Tx & Rx of connection, if needed */ |
| 1908 | if (QED_LL2_TX_REGISTERED(p_ll2_conn)) { |
| 1909 | rc = qed_sp_ll2_tx_queue_stop(p_hwfn, p_ll2_conn); |
| 1910 | if (rc) |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1911 | goto out; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1912 | qed_ll2_txq_flush(p_hwfn, connection_handle); |
| 1913 | } |
| 1914 | |
| 1915 | if (QED_LL2_RX_REGISTERED(p_ll2_conn)) { |
| 1916 | rc = qed_sp_ll2_rx_queue_stop(p_hwfn, p_ll2_conn); |
| 1917 | if (rc) |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1918 | goto out; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1919 | qed_ll2_rxq_flush(p_hwfn, connection_handle); |
| 1920 | } |
| 1921 | |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 1922 | if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 1923 | qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info); |
| 1924 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 1925 | if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE) { |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1926 | if (!test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits)) |
| 1927 | qed_llh_remove_protocol_filter(p_hwfn, p_ptt, |
| 1928 | ETH_P_FCOE, 0, |
| 1929 | QED_LLH_FILTER_ETHERTYPE); |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1930 | qed_llh_remove_protocol_filter(p_hwfn, p_ptt, |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 1931 | ETH_P_FIP, 0, |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1932 | QED_LLH_FILTER_ETHERTYPE); |
| 1933 | } |
| 1934 | |
Rahul Verma | 1558296 | 2017-04-06 15:58:29 +0300 | [diff] [blame] | 1935 | out: |
| 1936 | qed_ptt_release(p_hwfn, p_ptt); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1937 | return rc; |
| 1938 | } |
| 1939 | |
Mintz, Yuval | 58de289 | 2017-06-09 17:13:21 +0300 | [diff] [blame] | 1940 | static void qed_ll2_release_connection_ooo(struct qed_hwfn *p_hwfn, |
| 1941 | struct qed_ll2_info *p_ll2_conn) |
| 1942 | { |
| 1943 | struct qed_ooo_buffer *p_buffer; |
| 1944 | |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 1945 | if (p_ll2_conn->input.conn_type != QED_LL2_TYPE_OOO) |
Mintz, Yuval | 58de289 | 2017-06-09 17:13:21 +0300 | [diff] [blame] | 1946 | return; |
| 1947 | |
| 1948 | qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info); |
| 1949 | while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn, |
| 1950 | p_hwfn->p_ooo_info))) { |
| 1951 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1952 | p_buffer->rx_buffer_size, |
| 1953 | p_buffer->rx_buffer_virt_addr, |
| 1954 | p_buffer->rx_buffer_phys_addr); |
| 1955 | kfree(p_buffer); |
| 1956 | } |
| 1957 | } |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1958 | |
| 1959 | void qed_ll2_release_connection(void *cxt, u8 connection_handle) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1960 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 1961 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1962 | struct qed_ll2_info *p_ll2_conn = NULL; |
| 1963 | |
| 1964 | p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle); |
| 1965 | if (!p_ll2_conn) |
| 1966 | return; |
| 1967 | |
| 1968 | if (QED_LL2_RX_REGISTERED(p_ll2_conn)) { |
| 1969 | p_ll2_conn->rx_queue.b_cb_registred = false; |
| 1970 | qed_int_unregister_cb(p_hwfn, p_ll2_conn->rx_queue.rx_sb_index); |
| 1971 | } |
| 1972 | |
| 1973 | if (QED_LL2_TX_REGISTERED(p_ll2_conn)) { |
| 1974 | p_ll2_conn->tx_queue.b_cb_registred = false; |
| 1975 | qed_int_unregister_cb(p_hwfn, p_ll2_conn->tx_queue.tx_sb_index); |
| 1976 | } |
| 1977 | |
Michal Kalderon | f5823fe | 2017-10-09 12:37:43 +0300 | [diff] [blame] | 1978 | kfree(p_ll2_conn->tx_queue.descq_mem); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1979 | qed_chain_free(p_hwfn->cdev, &p_ll2_conn->tx_queue.txq_chain); |
| 1980 | |
| 1981 | kfree(p_ll2_conn->rx_queue.descq_array); |
| 1982 | qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rxq_chain); |
| 1983 | qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rcq_chain); |
| 1984 | |
| 1985 | qed_cxt_release_cid(p_hwfn, p_ll2_conn->cid); |
| 1986 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 1987 | qed_ll2_release_connection_ooo(p_hwfn, p_ll2_conn); |
| 1988 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1989 | mutex_lock(&p_ll2_conn->mutex); |
| 1990 | p_ll2_conn->b_active = false; |
| 1991 | mutex_unlock(&p_ll2_conn->mutex); |
| 1992 | } |
| 1993 | |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 1994 | int qed_ll2_alloc(struct qed_hwfn *p_hwfn) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1995 | { |
| 1996 | struct qed_ll2_info *p_ll2_connections; |
| 1997 | u8 i; |
| 1998 | |
| 1999 | /* Allocate LL2's set struct */ |
| 2000 | p_ll2_connections = kcalloc(QED_MAX_NUM_OF_LL2_CONNECTIONS, |
| 2001 | sizeof(struct qed_ll2_info), GFP_KERNEL); |
| 2002 | if (!p_ll2_connections) { |
| 2003 | DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_ll2'\n"); |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 2004 | return -ENOMEM; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++) |
| 2008 | p_ll2_connections[i].my_id = i; |
| 2009 | |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 2010 | p_hwfn->p_ll2_info = p_ll2_connections; |
| 2011 | return 0; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2012 | } |
| 2013 | |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 2014 | void qed_ll2_setup(struct qed_hwfn *p_hwfn) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2015 | { |
| 2016 | int i; |
| 2017 | |
| 2018 | for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++) |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 2019 | mutex_init(&p_hwfn->p_ll2_info[i].mutex); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2020 | } |
| 2021 | |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 2022 | void qed_ll2_free(struct qed_hwfn *p_hwfn) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2023 | { |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 2024 | if (!p_hwfn->p_ll2_info) |
| 2025 | return; |
| 2026 | |
| 2027 | kfree(p_hwfn->p_ll2_info); |
| 2028 | p_hwfn->p_ll2_info = NULL; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2029 | } |
| 2030 | |
Mintz, Yuval | fef1c3f | 2017-06-09 17:13:25 +0300 | [diff] [blame] | 2031 | static void _qed_ll2_get_port_stats(struct qed_hwfn *p_hwfn, |
| 2032 | struct qed_ptt *p_ptt, |
| 2033 | struct qed_ll2_stats *p_stats) |
| 2034 | { |
| 2035 | struct core_ll2_port_stats port_stats; |
| 2036 | |
| 2037 | memset(&port_stats, 0, sizeof(port_stats)); |
| 2038 | qed_memcpy_from(p_hwfn, p_ptt, &port_stats, |
| 2039 | BAR0_MAP_REG_TSDM_RAM + |
| 2040 | TSTORM_LL2_PORT_STAT_OFFSET(MFW_PORT(p_hwfn)), |
| 2041 | sizeof(port_stats)); |
| 2042 | |
| 2043 | p_stats->gsi_invalid_hdr = HILO_64_REGPAIR(port_stats.gsi_invalid_hdr); |
| 2044 | p_stats->gsi_invalid_pkt_length = |
| 2045 | HILO_64_REGPAIR(port_stats.gsi_invalid_pkt_length); |
| 2046 | p_stats->gsi_unsupported_pkt_typ = |
| 2047 | HILO_64_REGPAIR(port_stats.gsi_unsupported_pkt_typ); |
| 2048 | p_stats->gsi_crcchksm_error = |
| 2049 | HILO_64_REGPAIR(port_stats.gsi_crcchksm_error); |
| 2050 | } |
| 2051 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2052 | static void _qed_ll2_get_tstats(struct qed_hwfn *p_hwfn, |
| 2053 | struct qed_ptt *p_ptt, |
| 2054 | struct qed_ll2_info *p_ll2_conn, |
| 2055 | struct qed_ll2_stats *p_stats) |
| 2056 | { |
| 2057 | struct core_ll2_tstorm_per_queue_stat tstats; |
| 2058 | u8 qid = p_ll2_conn->queue_id; |
| 2059 | u32 tstats_addr; |
| 2060 | |
| 2061 | memset(&tstats, 0, sizeof(tstats)); |
| 2062 | tstats_addr = BAR0_MAP_REG_TSDM_RAM + |
| 2063 | CORE_LL2_TSTORM_PER_QUEUE_STAT_OFFSET(qid); |
| 2064 | qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, sizeof(tstats)); |
| 2065 | |
| 2066 | p_stats->packet_too_big_discard = |
| 2067 | HILO_64_REGPAIR(tstats.packet_too_big_discard); |
| 2068 | p_stats->no_buff_discard = HILO_64_REGPAIR(tstats.no_buff_discard); |
| 2069 | } |
| 2070 | |
| 2071 | static void _qed_ll2_get_ustats(struct qed_hwfn *p_hwfn, |
| 2072 | struct qed_ptt *p_ptt, |
| 2073 | struct qed_ll2_info *p_ll2_conn, |
| 2074 | struct qed_ll2_stats *p_stats) |
| 2075 | { |
| 2076 | struct core_ll2_ustorm_per_queue_stat ustats; |
| 2077 | u8 qid = p_ll2_conn->queue_id; |
| 2078 | u32 ustats_addr; |
| 2079 | |
| 2080 | memset(&ustats, 0, sizeof(ustats)); |
| 2081 | ustats_addr = BAR0_MAP_REG_USDM_RAM + |
| 2082 | CORE_LL2_USTORM_PER_QUEUE_STAT_OFFSET(qid); |
| 2083 | qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, sizeof(ustats)); |
| 2084 | |
| 2085 | p_stats->rcv_ucast_bytes = HILO_64_REGPAIR(ustats.rcv_ucast_bytes); |
| 2086 | p_stats->rcv_mcast_bytes = HILO_64_REGPAIR(ustats.rcv_mcast_bytes); |
| 2087 | p_stats->rcv_bcast_bytes = HILO_64_REGPAIR(ustats.rcv_bcast_bytes); |
| 2088 | p_stats->rcv_ucast_pkts = HILO_64_REGPAIR(ustats.rcv_ucast_pkts); |
| 2089 | p_stats->rcv_mcast_pkts = HILO_64_REGPAIR(ustats.rcv_mcast_pkts); |
| 2090 | p_stats->rcv_bcast_pkts = HILO_64_REGPAIR(ustats.rcv_bcast_pkts); |
| 2091 | } |
| 2092 | |
| 2093 | static void _qed_ll2_get_pstats(struct qed_hwfn *p_hwfn, |
| 2094 | struct qed_ptt *p_ptt, |
| 2095 | struct qed_ll2_info *p_ll2_conn, |
| 2096 | struct qed_ll2_stats *p_stats) |
| 2097 | { |
| 2098 | struct core_ll2_pstorm_per_queue_stat pstats; |
| 2099 | u8 stats_id = p_ll2_conn->tx_stats_id; |
| 2100 | u32 pstats_addr; |
| 2101 | |
| 2102 | memset(&pstats, 0, sizeof(pstats)); |
| 2103 | pstats_addr = BAR0_MAP_REG_PSDM_RAM + |
| 2104 | CORE_LL2_PSTORM_PER_QUEUE_STAT_OFFSET(stats_id); |
| 2105 | qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, sizeof(pstats)); |
| 2106 | |
| 2107 | p_stats->sent_ucast_bytes = HILO_64_REGPAIR(pstats.sent_ucast_bytes); |
| 2108 | p_stats->sent_mcast_bytes = HILO_64_REGPAIR(pstats.sent_mcast_bytes); |
| 2109 | p_stats->sent_bcast_bytes = HILO_64_REGPAIR(pstats.sent_bcast_bytes); |
| 2110 | p_stats->sent_ucast_pkts = HILO_64_REGPAIR(pstats.sent_ucast_pkts); |
| 2111 | p_stats->sent_mcast_pkts = HILO_64_REGPAIR(pstats.sent_mcast_pkts); |
| 2112 | p_stats->sent_bcast_pkts = HILO_64_REGPAIR(pstats.sent_bcast_pkts); |
| 2113 | } |
| 2114 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2115 | int qed_ll2_get_stats(void *cxt, |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2116 | u8 connection_handle, struct qed_ll2_stats *p_stats) |
| 2117 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2118 | struct qed_hwfn *p_hwfn = cxt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2119 | struct qed_ll2_info *p_ll2_conn = NULL; |
| 2120 | struct qed_ptt *p_ptt; |
| 2121 | |
| 2122 | memset(p_stats, 0, sizeof(*p_stats)); |
| 2123 | |
| 2124 | if ((connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS) || |
| 2125 | !p_hwfn->p_ll2_info) |
| 2126 | return -EINVAL; |
| 2127 | |
| 2128 | p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle]; |
| 2129 | |
| 2130 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 2131 | if (!p_ptt) { |
| 2132 | DP_ERR(p_hwfn, "Failed to acquire ptt\n"); |
| 2133 | return -EINVAL; |
| 2134 | } |
| 2135 | |
Mintz, Yuval | fef1c3f | 2017-06-09 17:13:25 +0300 | [diff] [blame] | 2136 | if (p_ll2_conn->input.gsi_enable) |
| 2137 | _qed_ll2_get_port_stats(p_hwfn, p_ptt, p_stats); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2138 | _qed_ll2_get_tstats(p_hwfn, p_ptt, p_ll2_conn, p_stats); |
| 2139 | _qed_ll2_get_ustats(p_hwfn, p_ptt, p_ll2_conn, p_stats); |
| 2140 | if (p_ll2_conn->tx_stats_en) |
| 2141 | _qed_ll2_get_pstats(p_hwfn, p_ptt, p_ll2_conn, p_stats); |
| 2142 | |
| 2143 | qed_ptt_release(p_hwfn, p_ptt); |
| 2144 | return 0; |
| 2145 | } |
| 2146 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2147 | static void qed_ll2b_release_rx_packet(void *cxt, |
| 2148 | u8 connection_handle, |
| 2149 | void *cookie, |
| 2150 | dma_addr_t rx_buf_addr, |
| 2151 | bool b_last_packet) |
| 2152 | { |
| 2153 | struct qed_hwfn *p_hwfn = cxt; |
| 2154 | |
| 2155 | qed_ll2_dealloc_buffer(p_hwfn->cdev, cookie); |
| 2156 | } |
| 2157 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2158 | static void qed_ll2_register_cb_ops(struct qed_dev *cdev, |
| 2159 | const struct qed_ll2_cb_ops *ops, |
| 2160 | void *cookie) |
| 2161 | { |
| 2162 | cdev->ll2->cbs = ops; |
| 2163 | cdev->ll2->cb_cookie = cookie; |
| 2164 | } |
| 2165 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2166 | struct qed_ll2_cbs ll2_cbs = { |
| 2167 | .rx_comp_cb = &qed_ll2b_complete_rx_packet, |
| 2168 | .rx_release_cb = &qed_ll2b_release_rx_packet, |
| 2169 | .tx_comp_cb = &qed_ll2b_complete_tx_packet, |
| 2170 | .tx_release_cb = &qed_ll2b_complete_tx_packet, |
| 2171 | }; |
| 2172 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2173 | static void qed_ll2_set_conn_data(struct qed_dev *cdev, |
| 2174 | struct qed_ll2_acquire_data *data, |
| 2175 | struct qed_ll2_params *params, |
| 2176 | enum qed_ll2_conn_type conn_type, |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2177 | u8 *handle, bool lb) |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2178 | { |
| 2179 | memset(data, 0, sizeof(*data)); |
| 2180 | |
| 2181 | data->input.conn_type = conn_type; |
| 2182 | data->input.mtu = params->mtu; |
| 2183 | data->input.rx_num_desc = QED_LL2_RX_SIZE; |
| 2184 | data->input.rx_drop_ttl0_flg = params->drop_ttl0_packets; |
| 2185 | data->input.rx_vlan_removal_en = params->rx_vlan_stripping; |
| 2186 | data->input.tx_num_desc = QED_LL2_TX_SIZE; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2187 | data->p_connection_handle = handle; |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2188 | data->cbs = &ll2_cbs; |
| 2189 | ll2_cbs.cookie = QED_LEADING_HWFN(cdev); |
| 2190 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2191 | if (lb) { |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 2192 | data->input.tx_tc = PKT_LB_TC; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2193 | data->input.tx_dest = QED_LL2_TX_DEST_LB; |
| 2194 | } else { |
| 2195 | data->input.tx_tc = 0; |
| 2196 | data->input.tx_dest = QED_LL2_TX_DEST_NW; |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | static int qed_ll2_start_ooo(struct qed_dev *cdev, |
| 2201 | struct qed_ll2_params *params) |
| 2202 | { |
| 2203 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 2204 | u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id; |
| 2205 | struct qed_ll2_acquire_data data; |
| 2206 | int rc; |
| 2207 | |
| 2208 | qed_ll2_set_conn_data(cdev, &data, params, |
Kalderon, Michal | 526d1d0 | 2017-07-02 10:29:23 +0300 | [diff] [blame] | 2209 | QED_LL2_TYPE_OOO, handle, true); |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2210 | |
| 2211 | rc = qed_ll2_acquire_connection(hwfn, &data); |
| 2212 | if (rc) { |
| 2213 | DP_INFO(cdev, "Failed to acquire LL2 OOO connection\n"); |
| 2214 | goto out; |
| 2215 | } |
| 2216 | |
| 2217 | rc = qed_ll2_establish_connection(hwfn, *handle); |
| 2218 | if (rc) { |
| 2219 | DP_INFO(cdev, "Failed to establist LL2 OOO connection\n"); |
| 2220 | goto fail; |
| 2221 | } |
| 2222 | |
| 2223 | return 0; |
| 2224 | |
| 2225 | fail: |
| 2226 | qed_ll2_release_connection(hwfn, *handle); |
| 2227 | out: |
| 2228 | *handle = QED_LL2_UNUSED_HANDLE; |
| 2229 | return rc; |
| 2230 | } |
| 2231 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2232 | static int qed_ll2_start(struct qed_dev *cdev, struct qed_ll2_params *params) |
| 2233 | { |
Wei Yongjun | 88a2428 | 2016-10-10 14:08:28 +0000 | [diff] [blame] | 2234 | struct qed_ll2_buffer *buffer, *tmp_buffer; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2235 | enum qed_ll2_conn_type conn_type; |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2236 | struct qed_ll2_acquire_data data; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2237 | struct qed_ptt *p_ptt; |
| 2238 | int rc, i; |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2239 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2240 | |
| 2241 | /* Initialize LL2 locks & lists */ |
| 2242 | INIT_LIST_HEAD(&cdev->ll2->list); |
| 2243 | spin_lock_init(&cdev->ll2->lock); |
| 2244 | cdev->ll2->rx_size = NET_SKB_PAD + ETH_HLEN + |
| 2245 | L1_CACHE_BYTES + params->mtu; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2246 | |
| 2247 | /*Allocate memory for LL2 */ |
| 2248 | DP_INFO(cdev, "Allocating LL2 buffers of size %08x bytes\n", |
| 2249 | cdev->ll2->rx_size); |
| 2250 | for (i = 0; i < QED_LL2_RX_SIZE; i++) { |
| 2251 | buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); |
| 2252 | if (!buffer) { |
| 2253 | DP_INFO(cdev, "Failed to allocate LL2 buffers\n"); |
| 2254 | goto fail; |
| 2255 | } |
| 2256 | |
| 2257 | rc = qed_ll2_alloc_buffer(cdev, (u8 **)&buffer->data, |
| 2258 | &buffer->phys_addr); |
| 2259 | if (rc) { |
| 2260 | kfree(buffer); |
| 2261 | goto fail; |
| 2262 | } |
| 2263 | |
| 2264 | list_add_tail(&buffer->list, &cdev->ll2->list); |
| 2265 | } |
| 2266 | |
| 2267 | switch (QED_LEADING_HWFN(cdev)->hw_info.personality) { |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 2268 | case QED_PCI_FCOE: |
| 2269 | conn_type = QED_LL2_TYPE_FCOE; |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 2270 | break; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2271 | case QED_PCI_ISCSI: |
| 2272 | conn_type = QED_LL2_TYPE_ISCSI; |
| 2273 | break; |
| 2274 | case QED_PCI_ETH_ROCE: |
| 2275 | conn_type = QED_LL2_TYPE_ROCE; |
| 2276 | break; |
| 2277 | default: |
| 2278 | conn_type = QED_LL2_TYPE_TEST; |
| 2279 | } |
| 2280 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2281 | qed_ll2_set_conn_data(cdev, &data, params, conn_type, |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2282 | &cdev->ll2->handle, false); |
Arnd Bergmann | 0629a33 | 2017-01-18 15:52:52 +0100 | [diff] [blame] | 2283 | |
Mintz, Yuval | 13c5477 | 2017-06-09 17:13:20 +0300 | [diff] [blame] | 2284 | rc = qed_ll2_acquire_connection(QED_LEADING_HWFN(cdev), &data); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2285 | if (rc) { |
| 2286 | DP_INFO(cdev, "Failed to acquire LL2 connection\n"); |
| 2287 | goto fail; |
| 2288 | } |
| 2289 | |
| 2290 | rc = qed_ll2_establish_connection(QED_LEADING_HWFN(cdev), |
| 2291 | cdev->ll2->handle); |
| 2292 | if (rc) { |
| 2293 | DP_INFO(cdev, "Failed to establish LL2 connection\n"); |
| 2294 | goto release_fail; |
| 2295 | } |
| 2296 | |
| 2297 | /* Post all Rx buffers to FW */ |
| 2298 | spin_lock_bh(&cdev->ll2->lock); |
Wei Yongjun | 88a2428 | 2016-10-10 14:08:28 +0000 | [diff] [blame] | 2299 | list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list) { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2300 | rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev), |
| 2301 | cdev->ll2->handle, |
| 2302 | buffer->phys_addr, 0, buffer, 1); |
| 2303 | if (rc) { |
| 2304 | DP_INFO(cdev, |
| 2305 | "Failed to post an Rx buffer; Deleting it\n"); |
| 2306 | dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr, |
| 2307 | cdev->ll2->rx_size, DMA_FROM_DEVICE); |
| 2308 | kfree(buffer->data); |
| 2309 | list_del(&buffer->list); |
| 2310 | kfree(buffer); |
| 2311 | } else { |
| 2312 | cdev->ll2->rx_cnt++; |
| 2313 | } |
| 2314 | } |
| 2315 | spin_unlock_bh(&cdev->ll2->lock); |
| 2316 | |
| 2317 | if (!cdev->ll2->rx_cnt) { |
| 2318 | DP_INFO(cdev, "Failed passing even a single Rx buffer\n"); |
| 2319 | goto release_terminate; |
| 2320 | } |
| 2321 | |
| 2322 | if (!is_valid_ether_addr(params->ll2_mac_address)) { |
| 2323 | DP_INFO(cdev, "Invalid Ethernet address\n"); |
| 2324 | goto release_terminate; |
| 2325 | } |
| 2326 | |
Tomer Tayar | da09091 | 2017-12-27 19:30:07 +0200 | [diff] [blame] | 2327 | if (QED_LEADING_HWFN(cdev)->hw_info.personality == QED_PCI_ISCSI) { |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 2328 | DP_VERBOSE(cdev, QED_MSG_STORAGE, "Starting OOO LL2 queue\n"); |
| 2329 | rc = qed_ll2_start_ooo(cdev, params); |
| 2330 | if (rc) { |
| 2331 | DP_INFO(cdev, |
| 2332 | "Failed to initialize the OOO LL2 queue\n"); |
| 2333 | goto release_terminate; |
| 2334 | } |
| 2335 | } |
| 2336 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2337 | p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev)); |
| 2338 | if (!p_ptt) { |
| 2339 | DP_INFO(cdev, "Failed to acquire PTT\n"); |
| 2340 | goto release_terminate; |
| 2341 | } |
| 2342 | |
| 2343 | rc = qed_llh_add_mac_filter(QED_LEADING_HWFN(cdev), p_ptt, |
| 2344 | params->ll2_mac_address); |
| 2345 | qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt); |
| 2346 | if (rc) { |
| 2347 | DP_ERR(cdev, "Failed to allocate LLH filter\n"); |
| 2348 | goto release_terminate_all; |
| 2349 | } |
| 2350 | |
| 2351 | ether_addr_copy(cdev->ll2_mac_address, params->ll2_mac_address); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2352 | return 0; |
| 2353 | |
| 2354 | release_terminate_all: |
| 2355 | |
| 2356 | release_terminate: |
| 2357 | qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle); |
| 2358 | release_fail: |
| 2359 | qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle); |
| 2360 | fail: |
| 2361 | qed_ll2_kill_buffers(cdev); |
| 2362 | cdev->ll2->handle = QED_LL2_UNUSED_HANDLE; |
| 2363 | return -EINVAL; |
| 2364 | } |
| 2365 | |
| 2366 | static int qed_ll2_stop(struct qed_dev *cdev) |
| 2367 | { |
| 2368 | struct qed_ptt *p_ptt; |
| 2369 | int rc; |
| 2370 | |
| 2371 | if (cdev->ll2->handle == QED_LL2_UNUSED_HANDLE) |
| 2372 | return 0; |
| 2373 | |
| 2374 | p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev)); |
| 2375 | if (!p_ptt) { |
| 2376 | DP_INFO(cdev, "Failed to acquire PTT\n"); |
| 2377 | goto fail; |
| 2378 | } |
| 2379 | |
| 2380 | qed_llh_remove_mac_filter(QED_LEADING_HWFN(cdev), p_ptt, |
| 2381 | cdev->ll2_mac_address); |
| 2382 | qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt); |
| 2383 | eth_zero_addr(cdev->ll2_mac_address); |
| 2384 | |
Tomer Tayar | da09091 | 2017-12-27 19:30:07 +0200 | [diff] [blame] | 2385 | if (QED_LEADING_HWFN(cdev)->hw_info.personality == QED_PCI_ISCSI) |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 2386 | qed_ll2_stop_ooo(cdev); |
| 2387 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2388 | rc = qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev), |
| 2389 | cdev->ll2->handle); |
| 2390 | if (rc) |
| 2391 | DP_INFO(cdev, "Failed to terminate LL2 connection\n"); |
| 2392 | |
| 2393 | qed_ll2_kill_buffers(cdev); |
| 2394 | |
| 2395 | qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle); |
| 2396 | cdev->ll2->handle = QED_LL2_UNUSED_HANDLE; |
| 2397 | |
| 2398 | return rc; |
| 2399 | fail: |
| 2400 | return -EINVAL; |
| 2401 | } |
| 2402 | |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 2403 | static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb, |
| 2404 | unsigned long xmit_flags) |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2405 | { |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 2406 | struct qed_ll2_tx_pkt_info pkt; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2407 | const skb_frag_t *frag; |
| 2408 | int rc = -EINVAL, i; |
| 2409 | dma_addr_t mapping; |
| 2410 | u16 vlan = 0; |
| 2411 | u8 flags = 0; |
| 2412 | |
| 2413 | if (unlikely(skb->ip_summed != CHECKSUM_NONE)) { |
Colin Ian King | ff81de7 | 2018-04-28 10:43:20 +0100 | [diff] [blame] | 2414 | DP_INFO(cdev, "Cannot transmit a checksummed packet\n"); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2415 | return -EINVAL; |
| 2416 | } |
| 2417 | |
| 2418 | if (1 + skb_shinfo(skb)->nr_frags > CORE_LL2_TX_MAX_BDS_PER_PACKET) { |
| 2419 | DP_ERR(cdev, "Cannot transmit a packet with %d fragments\n", |
| 2420 | 1 + skb_shinfo(skb)->nr_frags); |
| 2421 | return -EINVAL; |
| 2422 | } |
| 2423 | |
| 2424 | mapping = dma_map_single(&cdev->pdev->dev, skb->data, |
| 2425 | skb->len, DMA_TO_DEVICE); |
| 2426 | if (unlikely(dma_mapping_error(&cdev->pdev->dev, mapping))) { |
| 2427 | DP_NOTICE(cdev, "SKB mapping failed\n"); |
| 2428 | return -EINVAL; |
| 2429 | } |
| 2430 | |
| 2431 | /* Request HW to calculate IP csum */ |
| 2432 | if (!((vlan_get_protocol(skb) == htons(ETH_P_IPV6)) && |
| 2433 | ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6)) |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2434 | flags |= BIT(CORE_TX_BD_DATA_IP_CSUM_SHIFT); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2435 | |
| 2436 | if (skb_vlan_tag_present(skb)) { |
| 2437 | vlan = skb_vlan_tag_get(skb); |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2438 | flags |= BIT(CORE_TX_BD_DATA_VLAN_INSERTION_SHIFT); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2439 | } |
| 2440 | |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 2441 | memset(&pkt, 0, sizeof(pkt)); |
| 2442 | pkt.num_of_bds = 1 + skb_shinfo(skb)->nr_frags; |
| 2443 | pkt.vlan = vlan; |
| 2444 | pkt.bd_flags = flags; |
| 2445 | pkt.tx_dest = QED_LL2_TX_DEST_NW; |
| 2446 | pkt.first_frag = mapping; |
| 2447 | pkt.first_frag_len = skb->len; |
| 2448 | pkt.cookie = skb; |
Sudarsana Reddy Kalluru | cac6f69 | 2018-05-05 18:43:02 -0700 | [diff] [blame] | 2449 | if (test_bit(QED_MF_UFP_SPECIFIC, &cdev->mf_bits) && |
| 2450 | test_bit(QED_LL2_XMIT_FLAGS_FIP_DISCOVERY, &xmit_flags)) |
| 2451 | pkt.remove_stag = true; |
Mintz, Yuval | 7c7973b | 2017-06-09 17:13:18 +0300 | [diff] [blame] | 2452 | |
| 2453 | rc = qed_ll2_prepare_tx_packet(&cdev->hwfns[0], cdev->ll2->handle, |
| 2454 | &pkt, 1); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2455 | if (rc) |
| 2456 | goto err; |
| 2457 | |
| 2458 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 2459 | frag = &skb_shinfo(skb)->frags[i]; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2460 | |
Mintz, Yuval | d2201a2 | 2017-06-09 17:13:23 +0300 | [diff] [blame] | 2461 | mapping = skb_frag_dma_map(&cdev->pdev->dev, frag, 0, |
| 2462 | skb_frag_size(frag), DMA_TO_DEVICE); |
| 2463 | |
| 2464 | if (unlikely(dma_mapping_error(&cdev->pdev->dev, mapping))) { |
| 2465 | DP_NOTICE(cdev, |
| 2466 | "Unable to map frag - dropping packet\n"); |
| 2467 | goto err; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | rc = qed_ll2_set_fragment_of_tx_packet(QED_LEADING_HWFN(cdev), |
| 2471 | cdev->ll2->handle, |
| 2472 | mapping, |
| 2473 | skb_frag_size(frag)); |
| 2474 | |
| 2475 | /* if failed not much to do here, partial packet has been posted |
| 2476 | * we can't free memory, will need to wait for completion. |
| 2477 | */ |
| 2478 | if (rc) |
| 2479 | goto err2; |
| 2480 | } |
| 2481 | |
| 2482 | return 0; |
| 2483 | |
| 2484 | err: |
| 2485 | dma_unmap_single(&cdev->pdev->dev, mapping, skb->len, DMA_TO_DEVICE); |
| 2486 | |
| 2487 | err2: |
| 2488 | return rc; |
| 2489 | } |
| 2490 | |
| 2491 | static int qed_ll2_stats(struct qed_dev *cdev, struct qed_ll2_stats *stats) |
| 2492 | { |
| 2493 | if (!cdev->ll2) |
| 2494 | return -EINVAL; |
| 2495 | |
| 2496 | return qed_ll2_get_stats(QED_LEADING_HWFN(cdev), |
| 2497 | cdev->ll2->handle, stats); |
| 2498 | } |
| 2499 | |
| 2500 | const struct qed_ll2_ops qed_ll2_ops_pass = { |
| 2501 | .start = &qed_ll2_start, |
| 2502 | .stop = &qed_ll2_stop, |
| 2503 | .start_xmit = &qed_ll2_start_xmit, |
| 2504 | .register_cb_ops = &qed_ll2_register_cb_ops, |
| 2505 | .get_stats = &qed_ll2_stats, |
| 2506 | }; |
| 2507 | |
| 2508 | int qed_ll2_alloc_if(struct qed_dev *cdev) |
| 2509 | { |
| 2510 | cdev->ll2 = kzalloc(sizeof(*cdev->ll2), GFP_KERNEL); |
| 2511 | return cdev->ll2 ? 0 : -ENOMEM; |
| 2512 | } |
| 2513 | |
| 2514 | void qed_ll2_dealloc_if(struct qed_dev *cdev) |
| 2515 | { |
| 2516 | kfree(cdev->ll2); |
| 2517 | cdev->ll2 = NULL; |
| 2518 | } |