1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
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>
41 #include <linux/workqueue.h>
43 #include <linux/bitops.h>
44 #include <linux/delay.h>
45 #include <linux/errno.h>
46 #include <linux/etherdevice.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>
55 #include "qed_dev_api.h"
62 #include "qed_reg_addr.h"
66 #define QED_LL2_RX_REGISTERED(ll2) ((ll2)->rx_queue.b_cb_registered)
67 #define QED_LL2_TX_REGISTERED(ll2) ((ll2)->tx_queue.b_cb_registered)
69 #define QED_LL2_TX_SIZE (256)
70 #define QED_LL2_RX_SIZE (4096)
72 struct qed_cb_ll2_info {
77 /* Lock protecting LL2 buffer lists in sleepless context */
79 struct list_head list;
81 const struct qed_ll2_cb_ops *cbs;
85 struct qed_ll2_buffer {
86 struct list_head list;
91 static void qed_ll2b_complete_tx_packet(void *cxt,
94 dma_addr_t first_frag_addr,
98 struct qed_hwfn *p_hwfn = cxt;
99 struct qed_dev *cdev = p_hwfn->cdev;
100 struct sk_buff *skb = cookie;
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);
106 if (cdev->ll2->cbs && cdev->ll2->cbs->tx_cb)
107 cdev->ll2->cbs->tx_cb(cdev->ll2->cb_cookie, skb,
110 dev_kfree_skb_any(skb);
113 static int qed_ll2_alloc_buffer(struct qed_dev *cdev,
114 u8 **data, dma_addr_t *phys_addr)
116 *data = kmalloc(cdev->ll2->rx_size, GFP_ATOMIC);
118 DP_INFO(cdev, "Failed to allocate LL2 buffer data\n");
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");
134 static int qed_ll2_dealloc_buffer(struct qed_dev *cdev,
135 struct qed_ll2_buffer *buffer)
137 spin_lock_bh(&cdev->ll2->lock);
139 dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
140 cdev->ll2->rx_size, DMA_FROM_DEVICE);
142 list_del(&buffer->list);
145 if (!cdev->ll2->rx_cnt)
146 DP_INFO(cdev, "All LL2 entries were removed\n");
148 spin_unlock_bh(&cdev->ll2->lock);
153 static void qed_ll2_kill_buffers(struct qed_dev *cdev)
155 struct qed_ll2_buffer *buffer, *tmp_buffer;
157 list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list)
158 qed_ll2_dealloc_buffer(cdev, buffer);
161 static void qed_ll2b_complete_rx_packet(void *cxt,
162 struct qed_ll2_comp_rx_data *data)
164 struct qed_hwfn *p_hwfn = cxt;
165 struct qed_ll2_buffer *buffer = data->cookie;
166 struct qed_dev *cdev = p_hwfn->cdev;
167 dma_addr_t new_phys_addr;
174 (NETIF_MSG_RX_STATUS | QED_MSG_STORAGE | NETIF_MSG_PKTDATA),
175 "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",
176 (u64)data->rx_buf_addr,
177 data->u.placement_offset,
178 data->length.packet_length,
180 data->vlan, data->opaque_data_0, data->opaque_data_1);
182 if ((cdev->dp_module & NETIF_MSG_PKTDATA) && buffer->data) {
183 print_hex_dump(KERN_INFO, "",
184 DUMP_PREFIX_OFFSET, 16, 1,
185 buffer->data, data->length.packet_length, false);
188 /* Determine if data is valid */
189 if (data->length.packet_length < ETH_HLEN)
192 /* Allocate a replacement for buffer; Reuse upon failure */
194 rc = qed_ll2_alloc_buffer(p_hwfn->cdev, &new_data,
197 /* If need to reuse or there's no replacement buffer, repost this */
200 dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
201 cdev->ll2->rx_size, DMA_FROM_DEVICE);
203 skb = build_skb(buffer->data, 0);
205 DP_INFO(cdev, "Failed to build SKB\n");
210 data->u.placement_offset += NET_SKB_PAD;
211 skb_reserve(skb, data->u.placement_offset);
212 skb_put(skb, data->length.packet_length);
213 skb_checksum_none_assert(skb);
215 /* Get parital ethernet information instead of eth_type_trans(),
216 * Since we don't have an associated net_device.
218 skb_reset_mac_header(skb);
219 skb->protocol = eth_hdr(skb)->h_proto;
221 /* Pass SKB onward */
222 if (cdev->ll2->cbs && cdev->ll2->cbs->rx_cb) {
224 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
226 cdev->ll2->cbs->rx_cb(cdev->ll2->cb_cookie, skb,
228 data->opaque_data_1);
230 DP_VERBOSE(p_hwfn, (NETIF_MSG_RX_STATUS | NETIF_MSG_PKTDATA |
231 QED_MSG_LL2 | QED_MSG_STORAGE),
232 "Dropping the packet\n");
237 /* Update Buffer information and update FW producer */
238 buffer->data = new_data;
239 buffer->phys_addr = new_phys_addr;
242 rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev), cdev->ll2->handle,
243 buffer->phys_addr, 0, buffer, 1);
246 qed_ll2_dealloc_buffer(cdev, buffer);
249 static struct qed_ll2_info *__qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn,
250 u8 connection_handle,
254 struct qed_ll2_info *p_ll2_conn, *p_ret = NULL;
256 if (connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS)
259 if (!p_hwfn->p_ll2_info)
262 p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle];
266 mutex_lock(&p_ll2_conn->mutex);
267 if (p_ll2_conn->b_active)
270 mutex_unlock(&p_ll2_conn->mutex);
278 static struct qed_ll2_info *qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn,
279 u8 connection_handle)
281 return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, true);
284 static struct qed_ll2_info *qed_ll2_handle_sanity_lock(struct qed_hwfn *p_hwfn,
285 u8 connection_handle)
287 return __qed_ll2_handle_sanity(p_hwfn, connection_handle, true, true);
290 static struct qed_ll2_info *qed_ll2_handle_sanity_inactive(struct qed_hwfn
292 u8 connection_handle)
294 return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, false);
297 static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
299 bool b_last_packet = false, b_last_frag = false;
300 struct qed_ll2_tx_packet *p_pkt = NULL;
301 struct qed_ll2_info *p_ll2_conn;
302 struct qed_ll2_tx_queue *p_tx;
303 unsigned long flags = 0;
306 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
310 p_tx = &p_ll2_conn->tx_queue;
312 spin_lock_irqsave(&p_tx->lock, flags);
313 while (!list_empty(&p_tx->active_descq)) {
314 p_pkt = list_first_entry(&p_tx->active_descq,
315 struct qed_ll2_tx_packet, list_entry);
319 list_del(&p_pkt->list_entry);
320 b_last_packet = list_empty(&p_tx->active_descq);
321 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
322 spin_unlock_irqrestore(&p_tx->lock, flags);
323 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) {
324 struct qed_ooo_buffer *p_buffer;
326 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
327 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
330 p_tx->cur_completing_packet = *p_pkt;
331 p_tx->cur_completing_bd_idx = 1;
333 p_tx->cur_completing_bd_idx == p_pkt->bd_used;
334 tx_frag = p_pkt->bds_set[0].tx_frag;
335 p_ll2_conn->cbs.tx_release_cb(p_ll2_conn->cbs.cookie,
342 spin_lock_irqsave(&p_tx->lock, flags);
344 spin_unlock_irqrestore(&p_tx->lock, flags);
347 static int qed_ll2_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
349 struct qed_ll2_info *p_ll2_conn = p_cookie;
350 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
351 u16 new_idx = 0, num_bds = 0, num_bds_in_packet = 0;
352 struct qed_ll2_tx_packet *p_pkt;
353 bool b_last_frag = false;
357 spin_lock_irqsave(&p_tx->lock, flags);
358 if (p_tx->b_completing_packet) {
363 new_idx = le16_to_cpu(*p_tx->p_fw_cons);
364 num_bds = ((s16)new_idx - (s16)p_tx->bds_idx);
366 if (list_empty(&p_tx->active_descq))
369 p_pkt = list_first_entry(&p_tx->active_descq,
370 struct qed_ll2_tx_packet, list_entry);
374 p_tx->b_completing_packet = true;
375 p_tx->cur_completing_packet = *p_pkt;
376 num_bds_in_packet = p_pkt->bd_used;
377 list_del(&p_pkt->list_entry);
379 if (num_bds < num_bds_in_packet) {
381 "Rest of BDs does not cover whole packet\n");
385 num_bds -= num_bds_in_packet;
386 p_tx->bds_idx += num_bds_in_packet;
387 while (num_bds_in_packet--)
388 qed_chain_consume(&p_tx->txq_chain);
390 p_tx->cur_completing_bd_idx = 1;
391 b_last_frag = p_tx->cur_completing_bd_idx == p_pkt->bd_used;
392 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
394 spin_unlock_irqrestore(&p_tx->lock, flags);
396 p_ll2_conn->cbs.tx_comp_cb(p_ll2_conn->cbs.cookie,
399 p_pkt->bds_set[0].tx_frag,
400 b_last_frag, !num_bds);
402 spin_lock_irqsave(&p_tx->lock, flags);
405 p_tx->b_completing_packet = false;
408 spin_unlock_irqrestore(&p_tx->lock, flags);
412 static void qed_ll2_rxq_parse_gsi(struct qed_hwfn *p_hwfn,
413 union core_rx_cqe_union *p_cqe,
414 struct qed_ll2_comp_rx_data *data)
416 data->parse_flags = le16_to_cpu(p_cqe->rx_cqe_gsi.parse_flags.flags);
417 data->length.data_length = le16_to_cpu(p_cqe->rx_cqe_gsi.data_length);
418 data->vlan = le16_to_cpu(p_cqe->rx_cqe_gsi.vlan);
419 data->opaque_data_0 = le32_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrhi);
420 data->opaque_data_1 = le16_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrlo);
421 data->u.data_length_error = p_cqe->rx_cqe_gsi.data_length_error;
422 data->qp_id = le16_to_cpu(p_cqe->rx_cqe_gsi.qp_id);
424 data->src_qp = le32_to_cpu(p_cqe->rx_cqe_gsi.src_qp);
427 static void qed_ll2_rxq_parse_reg(struct qed_hwfn *p_hwfn,
428 union core_rx_cqe_union *p_cqe,
429 struct qed_ll2_comp_rx_data *data)
431 data->parse_flags = le16_to_cpu(p_cqe->rx_cqe_fp.parse_flags.flags);
432 data->err_flags = le16_to_cpu(p_cqe->rx_cqe_fp.err_flags.flags);
433 data->length.packet_length =
434 le16_to_cpu(p_cqe->rx_cqe_fp.packet_length);
435 data->vlan = le16_to_cpu(p_cqe->rx_cqe_fp.vlan);
436 data->opaque_data_0 = le32_to_cpu(p_cqe->rx_cqe_fp.opaque_data.data[0]);
437 data->opaque_data_1 = le32_to_cpu(p_cqe->rx_cqe_fp.opaque_data.data[1]);
438 data->u.placement_offset = p_cqe->rx_cqe_fp.placement_offset;
442 qed_ll2_handle_slowpath(struct qed_hwfn *p_hwfn,
443 struct qed_ll2_info *p_ll2_conn,
444 union core_rx_cqe_union *p_cqe,
445 unsigned long *p_lock_flags)
447 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
448 struct core_rx_slow_path_cqe *sp_cqe;
450 sp_cqe = &p_cqe->rx_cqe_sp;
451 if (sp_cqe->ramrod_cmd_id != CORE_RAMROD_RX_QUEUE_FLUSH) {
453 "LL2 - unexpected Rx CQE slowpath ramrod_cmd_id:%d\n",
454 sp_cqe->ramrod_cmd_id);
458 if (!p_ll2_conn->cbs.slowpath_cb) {
460 "LL2 - received RX_QUEUE_FLUSH but no callback was provided\n");
464 spin_unlock_irqrestore(&p_rx->lock, *p_lock_flags);
466 p_ll2_conn->cbs.slowpath_cb(p_ll2_conn->cbs.cookie,
468 le32_to_cpu(sp_cqe->opaque_data.data[0]),
469 le32_to_cpu(sp_cqe->opaque_data.data[1]));
471 spin_lock_irqsave(&p_rx->lock, *p_lock_flags);
477 qed_ll2_rxq_handle_completion(struct qed_hwfn *p_hwfn,
478 struct qed_ll2_info *p_ll2_conn,
479 union core_rx_cqe_union *p_cqe,
480 unsigned long *p_lock_flags, bool b_last_cqe)
482 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
483 struct qed_ll2_rx_packet *p_pkt = NULL;
484 struct qed_ll2_comp_rx_data data;
486 if (!list_empty(&p_rx->active_descq))
487 p_pkt = list_first_entry(&p_rx->active_descq,
488 struct qed_ll2_rx_packet, list_entry);
491 "[%d] LL2 Rx completion but active_descq is empty\n",
492 p_ll2_conn->input.conn_type);
496 list_del(&p_pkt->list_entry);
498 if (p_cqe->rx_cqe_sp.type == CORE_RX_CQE_TYPE_REGULAR)
499 qed_ll2_rxq_parse_reg(p_hwfn, p_cqe, &data);
501 qed_ll2_rxq_parse_gsi(p_hwfn, p_cqe, &data);
502 if (qed_chain_consume(&p_rx->rxq_chain) != p_pkt->rxq_bd)
504 "Mismatch between active_descq and the LL2 Rx chain\n");
506 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);
508 data.connection_handle = p_ll2_conn->my_id;
509 data.cookie = p_pkt->cookie;
510 data.rx_buf_addr = p_pkt->rx_buf_addr;
511 data.b_last_packet = b_last_cqe;
513 spin_unlock_irqrestore(&p_rx->lock, *p_lock_flags);
514 p_ll2_conn->cbs.rx_comp_cb(p_ll2_conn->cbs.cookie, &data);
516 spin_lock_irqsave(&p_rx->lock, *p_lock_flags);
521 static int qed_ll2_rxq_completion(struct qed_hwfn *p_hwfn, void *cookie)
523 struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)cookie;
524 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
525 union core_rx_cqe_union *cqe = NULL;
526 u16 cq_new_idx = 0, cq_old_idx = 0;
527 unsigned long flags = 0;
530 spin_lock_irqsave(&p_rx->lock, flags);
531 cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons);
532 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
534 while (cq_new_idx != cq_old_idx) {
535 bool b_last_cqe = (cq_new_idx == cq_old_idx);
538 (union core_rx_cqe_union *)
539 qed_chain_consume(&p_rx->rcq_chain);
540 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
544 "LL2 [sw. cons %04x, fw. at %04x] - Got Packet of type %02x\n",
545 cq_old_idx, cq_new_idx, cqe->rx_cqe_sp.type);
547 switch (cqe->rx_cqe_sp.type) {
548 case CORE_RX_CQE_TYPE_SLOW_PATH:
549 rc = qed_ll2_handle_slowpath(p_hwfn, p_ll2_conn,
552 case CORE_RX_CQE_TYPE_GSI_OFFLOAD:
553 case CORE_RX_CQE_TYPE_REGULAR:
554 rc = qed_ll2_rxq_handle_completion(p_hwfn, p_ll2_conn,
563 spin_unlock_irqrestore(&p_rx->lock, flags);
567 static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
569 struct qed_ll2_info *p_ll2_conn = NULL;
570 struct qed_ll2_rx_packet *p_pkt = NULL;
571 struct qed_ll2_rx_queue *p_rx;
572 unsigned long flags = 0;
574 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
578 p_rx = &p_ll2_conn->rx_queue;
580 spin_lock_irqsave(&p_rx->lock, flags);
581 while (!list_empty(&p_rx->active_descq)) {
582 p_pkt = list_first_entry(&p_rx->active_descq,
583 struct qed_ll2_rx_packet, list_entry);
586 list_move_tail(&p_pkt->list_entry, &p_rx->free_descq);
587 spin_unlock_irqrestore(&p_rx->lock, flags);
589 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) {
590 struct qed_ooo_buffer *p_buffer;
592 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
593 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
596 dma_addr_t rx_buf_addr = p_pkt->rx_buf_addr;
597 void *cookie = p_pkt->cookie;
600 b_last = list_empty(&p_rx->active_descq);
601 p_ll2_conn->cbs.rx_release_cb(p_ll2_conn->cbs.cookie,
604 rx_buf_addr, b_last);
606 spin_lock_irqsave(&p_rx->lock, flags);
608 spin_unlock_irqrestore(&p_rx->lock, flags);
612 qed_ll2_lb_rxq_handler_slowpath(struct qed_hwfn *p_hwfn,
613 struct core_rx_slow_path_cqe *p_cqe)
615 struct ooo_opaque *iscsi_ooo;
618 if (p_cqe->ramrod_cmd_id != CORE_RAMROD_RX_QUEUE_FLUSH)
621 iscsi_ooo = (struct ooo_opaque *)&p_cqe->opaque_data;
622 if (iscsi_ooo->ooo_opcode != TCP_EVENT_DELETE_ISLES)
625 /* Need to make a flush */
626 cid = le32_to_cpu(iscsi_ooo->cid);
627 qed_ooo_release_connection_isles(p_hwfn, p_hwfn->p_ooo_info, cid);
632 static int qed_ll2_lb_rxq_handler(struct qed_hwfn *p_hwfn,
633 struct qed_ll2_info *p_ll2_conn)
635 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
636 u16 packet_length = 0, parse_flags = 0, vlan = 0;
637 struct qed_ll2_rx_packet *p_pkt = NULL;
638 u32 num_ooo_add_to_peninsula = 0, cid;
639 union core_rx_cqe_union *cqe = NULL;
640 u16 cq_new_idx = 0, cq_old_idx = 0;
641 struct qed_ooo_buffer *p_buffer;
642 struct ooo_opaque *iscsi_ooo;
643 u8 placement_offset = 0;
646 cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons);
647 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
648 if (cq_new_idx == cq_old_idx)
651 while (cq_new_idx != cq_old_idx) {
652 struct core_rx_fast_path_cqe *p_cqe_fp;
654 cqe = qed_chain_consume(&p_rx->rcq_chain);
655 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
656 cqe_type = cqe->rx_cqe_sp.type;
658 if (cqe_type == CORE_RX_CQE_TYPE_SLOW_PATH)
659 if (qed_ll2_lb_rxq_handler_slowpath(p_hwfn,
663 if (cqe_type != CORE_RX_CQE_TYPE_REGULAR) {
665 "Got a non-regular LB LL2 completion [type 0x%02x]\n",
669 p_cqe_fp = &cqe->rx_cqe_fp;
671 placement_offset = p_cqe_fp->placement_offset;
672 parse_flags = le16_to_cpu(p_cqe_fp->parse_flags.flags);
673 packet_length = le16_to_cpu(p_cqe_fp->packet_length);
674 vlan = le16_to_cpu(p_cqe_fp->vlan);
675 iscsi_ooo = (struct ooo_opaque *)&p_cqe_fp->opaque_data;
676 qed_ooo_save_history_entry(p_hwfn, p_hwfn->p_ooo_info,
678 cid = le32_to_cpu(iscsi_ooo->cid);
680 /* Process delete isle first */
681 if (iscsi_ooo->drop_size)
682 qed_ooo_delete_isles(p_hwfn, p_hwfn->p_ooo_info, cid,
683 iscsi_ooo->drop_isle,
684 iscsi_ooo->drop_size);
686 if (iscsi_ooo->ooo_opcode == TCP_EVENT_NOP)
689 /* Now process create/add/join isles */
690 if (list_empty(&p_rx->active_descq)) {
692 "LL2 OOO RX chain has no submitted buffers\n"
697 p_pkt = list_first_entry(&p_rx->active_descq,
698 struct qed_ll2_rx_packet, list_entry);
700 if ((iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_NEW_ISLE) ||
701 (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_RIGHT) ||
702 (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_LEFT) ||
703 (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_PEN) ||
704 (iscsi_ooo->ooo_opcode == TCP_EVENT_JOIN)) {
707 "LL2 OOO RX packet is not valid\n");
710 list_del(&p_pkt->list_entry);
711 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
712 p_buffer->packet_length = packet_length;
713 p_buffer->parse_flags = parse_flags;
714 p_buffer->vlan = vlan;
715 p_buffer->placement_offset = placement_offset;
716 qed_chain_consume(&p_rx->rxq_chain);
717 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);
719 switch (iscsi_ooo->ooo_opcode) {
720 case TCP_EVENT_ADD_NEW_ISLE:
721 qed_ooo_add_new_isle(p_hwfn,
727 case TCP_EVENT_ADD_ISLE_RIGHT:
728 qed_ooo_add_new_buffer(p_hwfn,
735 case TCP_EVENT_ADD_ISLE_LEFT:
736 qed_ooo_add_new_buffer(p_hwfn,
744 qed_ooo_add_new_buffer(p_hwfn,
747 iscsi_ooo->ooo_isle +
751 qed_ooo_join_isles(p_hwfn,
753 cid, iscsi_ooo->ooo_isle);
755 case TCP_EVENT_ADD_PEN:
756 num_ooo_add_to_peninsula++;
757 qed_ooo_put_ready_buffer(p_hwfn,
764 "Unexpected event (%d) TX OOO completion\n",
765 iscsi_ooo->ooo_opcode);
773 qed_ooo_submit_tx_buffers(struct qed_hwfn *p_hwfn,
774 struct qed_ll2_info *p_ll2_conn)
776 struct qed_ll2_tx_pkt_info tx_pkt;
777 struct qed_ooo_buffer *p_buffer;
779 dma_addr_t first_frag;
783 /* Submit Tx buffers here */
784 while ((p_buffer = qed_ooo_get_ready_buffer(p_hwfn,
785 p_hwfn->p_ooo_info))) {
789 first_frag = p_buffer->rx_buffer_phys_addr +
790 p_buffer->placement_offset;
791 SET_FIELD(bd_flags, CORE_TX_BD_DATA_FORCE_VLAN_MODE, 1);
792 SET_FIELD(bd_flags, CORE_TX_BD_DATA_L4_PROTOCOL, 1);
794 memset(&tx_pkt, 0, sizeof(tx_pkt));
795 tx_pkt.num_of_bds = 1;
796 tx_pkt.vlan = p_buffer->vlan;
797 tx_pkt.bd_flags = bd_flags;
798 tx_pkt.l4_hdr_offset_w = l4_hdr_offset_w;
799 switch (p_ll2_conn->tx_dest) {
800 case CORE_TX_DEST_NW:
801 tx_pkt.tx_dest = QED_LL2_TX_DEST_NW;
803 case CORE_TX_DEST_LB:
804 tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
806 case CORE_TX_DEST_DROP:
808 tx_pkt.tx_dest = QED_LL2_TX_DEST_DROP;
811 tx_pkt.first_frag = first_frag;
812 tx_pkt.first_frag_len = p_buffer->packet_length;
813 tx_pkt.cookie = p_buffer;
815 rc = qed_ll2_prepare_tx_packet(p_hwfn, p_ll2_conn->my_id,
818 qed_ooo_put_ready_buffer(p_hwfn, p_hwfn->p_ooo_info,
826 qed_ooo_submit_rx_buffers(struct qed_hwfn *p_hwfn,
827 struct qed_ll2_info *p_ll2_conn)
829 struct qed_ooo_buffer *p_buffer;
832 while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn,
833 p_hwfn->p_ooo_info))) {
834 rc = qed_ll2_post_rx_buffer(p_hwfn,
836 p_buffer->rx_buffer_phys_addr,
839 qed_ooo_put_free_buffer(p_hwfn,
840 p_hwfn->p_ooo_info, p_buffer);
846 static int qed_ll2_lb_rxq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
848 struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie;
851 if (!QED_LL2_RX_REGISTERED(p_ll2_conn))
854 rc = qed_ll2_lb_rxq_handler(p_hwfn, p_ll2_conn);
858 qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn);
859 qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn);
864 static int qed_ll2_lb_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
866 struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie;
867 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
868 struct qed_ll2_tx_packet *p_pkt = NULL;
869 struct qed_ooo_buffer *p_buffer;
870 bool b_dont_submit_rx = false;
871 u16 new_idx = 0, num_bds = 0;
874 if (!QED_LL2_TX_REGISTERED(p_ll2_conn))
877 new_idx = le16_to_cpu(*p_tx->p_fw_cons);
878 num_bds = ((s16)new_idx - (s16)p_tx->bds_idx);
884 if (list_empty(&p_tx->active_descq))
887 p_pkt = list_first_entry(&p_tx->active_descq,
888 struct qed_ll2_tx_packet, list_entry);
892 if (p_pkt->bd_used != 1) {
894 "Unexpectedly many BDs(%d) in TX OOO completion\n",
899 list_del(&p_pkt->list_entry);
903 qed_chain_consume(&p_tx->txq_chain);
905 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
906 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
908 if (b_dont_submit_rx) {
909 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
914 rc = qed_ll2_post_rx_buffer(p_hwfn, p_ll2_conn->my_id,
915 p_buffer->rx_buffer_phys_addr, 0,
918 qed_ooo_put_free_buffer(p_hwfn,
919 p_hwfn->p_ooo_info, p_buffer);
920 b_dont_submit_rx = true;
924 qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn);
929 static void qed_ll2_stop_ooo(struct qed_dev *cdev)
931 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
932 u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id;
934 DP_VERBOSE(cdev, QED_MSG_STORAGE, "Stopping LL2 OOO queue [%02x]\n",
937 qed_ll2_terminate_connection(hwfn, *handle);
938 qed_ll2_release_connection(hwfn, *handle);
939 *handle = QED_LL2_UNUSED_HANDLE;
942 static int qed_sp_ll2_rx_queue_start(struct qed_hwfn *p_hwfn,
943 struct qed_ll2_info *p_ll2_conn,
946 enum qed_ll2_conn_type conn_type = p_ll2_conn->input.conn_type;
947 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
948 struct core_rx_start_ramrod_data *p_ramrod = NULL;
949 struct qed_spq_entry *p_ent = NULL;
950 struct qed_sp_init_data init_data;
955 memset(&init_data, 0, sizeof(init_data));
956 init_data.cid = p_ll2_conn->cid;
957 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
958 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
960 rc = qed_sp_init_request(p_hwfn, &p_ent,
961 CORE_RAMROD_RX_QUEUE_START,
962 PROTOCOLID_CORE, &init_data);
966 p_ramrod = &p_ent->ramrod.core_rx_queue_start;
968 p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn));
969 p_ramrod->sb_index = p_rx->rx_sb_index;
970 p_ramrod->complete_event_flg = 1;
972 p_ramrod->mtu = cpu_to_le16(p_ll2_conn->input.mtu);
973 DMA_REGPAIR_LE(p_ramrod->bd_base, p_rx->rxq_chain.p_phys_addr);
974 cqe_pbl_size = (u16)qed_chain_get_page_cnt(&p_rx->rcq_chain);
975 p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
976 DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr,
977 qed_chain_get_pbl_phys(&p_rx->rcq_chain));
979 p_ramrod->drop_ttl0_flg = p_ll2_conn->input.rx_drop_ttl0_flg;
980 p_ramrod->inner_vlan_stripping_en =
981 p_ll2_conn->input.rx_vlan_removal_en;
983 if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) &&
984 p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE)
985 p_ramrod->report_outer_vlan = 1;
986 p_ramrod->queue_id = p_ll2_conn->queue_id;
987 p_ramrod->main_func_queue = p_ll2_conn->main_func_queue ? 1 : 0;
989 if (test_bit(QED_MF_LL2_NON_UNICAST, &p_hwfn->cdev->mf_bits) &&
990 p_ramrod->main_func_queue && conn_type != QED_LL2_TYPE_ROCE &&
991 conn_type != QED_LL2_TYPE_IWARP) {
992 p_ramrod->mf_si_bcast_accept_all = 1;
993 p_ramrod->mf_si_mcast_accept_all = 1;
995 p_ramrod->mf_si_bcast_accept_all = 0;
996 p_ramrod->mf_si_mcast_accept_all = 0;
999 p_ramrod->action_on_error.error_type = action_on_error;
1000 p_ramrod->gsi_offload_flag = p_ll2_conn->input.gsi_enable;
1001 return qed_spq_post(p_hwfn, p_ent, NULL);
1004 static int qed_sp_ll2_tx_queue_start(struct qed_hwfn *p_hwfn,
1005 struct qed_ll2_info *p_ll2_conn)
1007 enum qed_ll2_conn_type conn_type = p_ll2_conn->input.conn_type;
1008 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
1009 struct core_tx_start_ramrod_data *p_ramrod = NULL;
1010 struct qed_spq_entry *p_ent = NULL;
1011 struct qed_sp_init_data init_data;
1012 u16 pq_id = 0, pbl_size;
1015 if (!QED_LL2_TX_REGISTERED(p_ll2_conn))
1018 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO)
1019 p_ll2_conn->tx_stats_en = 0;
1021 p_ll2_conn->tx_stats_en = 1;
1024 memset(&init_data, 0, sizeof(init_data));
1025 init_data.cid = p_ll2_conn->cid;
1026 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1027 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1029 rc = qed_sp_init_request(p_hwfn, &p_ent,
1030 CORE_RAMROD_TX_QUEUE_START,
1031 PROTOCOLID_CORE, &init_data);
1035 p_ramrod = &p_ent->ramrod.core_tx_queue_start;
1037 p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn));
1038 p_ramrod->sb_index = p_tx->tx_sb_index;
1039 p_ramrod->mtu = cpu_to_le16(p_ll2_conn->input.mtu);
1040 p_ramrod->stats_en = p_ll2_conn->tx_stats_en;
1041 p_ramrod->stats_id = p_ll2_conn->tx_stats_id;
1043 DMA_REGPAIR_LE(p_ramrod->pbl_base_addr,
1044 qed_chain_get_pbl_phys(&p_tx->txq_chain));
1045 pbl_size = qed_chain_get_page_cnt(&p_tx->txq_chain);
1046 p_ramrod->pbl_size = cpu_to_le16(pbl_size);
1048 switch (p_ll2_conn->input.tx_tc) {
1050 pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB);
1053 pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OOO);
1056 pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
1060 p_ramrod->qm_pq_id = cpu_to_le16(pq_id);
1062 switch (conn_type) {
1063 case QED_LL2_TYPE_FCOE:
1064 p_ramrod->conn_type = PROTOCOLID_FCOE;
1066 case QED_LL2_TYPE_ISCSI:
1067 p_ramrod->conn_type = PROTOCOLID_ISCSI;
1069 case QED_LL2_TYPE_ROCE:
1070 p_ramrod->conn_type = PROTOCOLID_ROCE;
1072 case QED_LL2_TYPE_IWARP:
1073 p_ramrod->conn_type = PROTOCOLID_IWARP;
1075 case QED_LL2_TYPE_OOO:
1076 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI)
1077 p_ramrod->conn_type = PROTOCOLID_ISCSI;
1079 p_ramrod->conn_type = PROTOCOLID_IWARP;
1082 p_ramrod->conn_type = PROTOCOLID_ETH;
1083 DP_NOTICE(p_hwfn, "Unknown connection type: %d\n", conn_type);
1086 p_ramrod->gsi_offload_flag = p_ll2_conn->input.gsi_enable;
1088 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1092 rc = qed_db_recovery_add(p_hwfn->cdev, p_tx->doorbell_addr,
1093 &p_tx->db_msg, DB_REC_WIDTH_32B,
1098 static int qed_sp_ll2_rx_queue_stop(struct qed_hwfn *p_hwfn,
1099 struct qed_ll2_info *p_ll2_conn)
1101 struct core_rx_stop_ramrod_data *p_ramrod = NULL;
1102 struct qed_spq_entry *p_ent = NULL;
1103 struct qed_sp_init_data init_data;
1107 memset(&init_data, 0, sizeof(init_data));
1108 init_data.cid = p_ll2_conn->cid;
1109 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1110 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1112 rc = qed_sp_init_request(p_hwfn, &p_ent,
1113 CORE_RAMROD_RX_QUEUE_STOP,
1114 PROTOCOLID_CORE, &init_data);
1118 p_ramrod = &p_ent->ramrod.core_rx_queue_stop;
1120 p_ramrod->complete_event_flg = 1;
1121 p_ramrod->queue_id = p_ll2_conn->queue_id;
1123 return qed_spq_post(p_hwfn, p_ent, NULL);
1126 static int qed_sp_ll2_tx_queue_stop(struct qed_hwfn *p_hwfn,
1127 struct qed_ll2_info *p_ll2_conn)
1129 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
1130 struct qed_spq_entry *p_ent = NULL;
1131 struct qed_sp_init_data init_data;
1133 qed_db_recovery_del(p_hwfn->cdev, p_tx->doorbell_addr, &p_tx->db_msg);
1136 memset(&init_data, 0, sizeof(init_data));
1137 init_data.cid = p_ll2_conn->cid;
1138 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1139 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1141 rc = qed_sp_init_request(p_hwfn, &p_ent,
1142 CORE_RAMROD_TX_QUEUE_STOP,
1143 PROTOCOLID_CORE, &init_data);
1147 return qed_spq_post(p_hwfn, p_ent, NULL);
1151 qed_ll2_acquire_connection_rx(struct qed_hwfn *p_hwfn,
1152 struct qed_ll2_info *p_ll2_info)
1154 struct qed_ll2_rx_packet *p_descq;
1158 if (!p_ll2_info->input.rx_num_desc)
1161 rc = qed_chain_alloc(p_hwfn->cdev,
1162 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1163 QED_CHAIN_MODE_NEXT_PTR,
1164 QED_CHAIN_CNT_TYPE_U16,
1165 p_ll2_info->input.rx_num_desc,
1166 sizeof(struct core_rx_bd),
1167 &p_ll2_info->rx_queue.rxq_chain, NULL);
1169 DP_NOTICE(p_hwfn, "Failed to allocate ll2 rxq chain\n");
1173 capacity = qed_chain_get_capacity(&p_ll2_info->rx_queue.rxq_chain);
1174 p_descq = kcalloc(capacity, sizeof(struct qed_ll2_rx_packet),
1178 DP_NOTICE(p_hwfn, "Failed to allocate ll2 Rx desc\n");
1181 p_ll2_info->rx_queue.descq_array = p_descq;
1183 rc = qed_chain_alloc(p_hwfn->cdev,
1184 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1186 QED_CHAIN_CNT_TYPE_U16,
1187 p_ll2_info->input.rx_num_desc,
1188 sizeof(struct core_rx_fast_path_cqe),
1189 &p_ll2_info->rx_queue.rcq_chain, NULL);
1191 DP_NOTICE(p_hwfn, "Failed to allocate ll2 rcq chain\n");
1195 DP_VERBOSE(p_hwfn, QED_MSG_LL2,
1196 "Allocated LL2 Rxq [Type %08x] with 0x%08x buffers\n",
1197 p_ll2_info->input.conn_type, p_ll2_info->input.rx_num_desc);
1203 static int qed_ll2_acquire_connection_tx(struct qed_hwfn *p_hwfn,
1204 struct qed_ll2_info *p_ll2_info)
1206 struct qed_ll2_tx_packet *p_descq;
1211 if (!p_ll2_info->input.tx_num_desc)
1214 rc = qed_chain_alloc(p_hwfn->cdev,
1215 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1217 QED_CHAIN_CNT_TYPE_U16,
1218 p_ll2_info->input.tx_num_desc,
1219 sizeof(struct core_tx_bd),
1220 &p_ll2_info->tx_queue.txq_chain, NULL);
1224 capacity = qed_chain_get_capacity(&p_ll2_info->tx_queue.txq_chain);
1225 /* First element is part of the packet, rest are flexibly added */
1226 desc_size = (sizeof(*p_descq) +
1227 (p_ll2_info->input.tx_max_bds_per_packet - 1) *
1228 sizeof(p_descq->bds_set));
1230 p_descq = kcalloc(capacity, desc_size, GFP_KERNEL);
1235 p_ll2_info->tx_queue.descq_mem = p_descq;
1237 DP_VERBOSE(p_hwfn, QED_MSG_LL2,
1238 "Allocated LL2 Txq [Type %08x] with 0x%08x buffers\n",
1239 p_ll2_info->input.conn_type, p_ll2_info->input.tx_num_desc);
1244 "Can't allocate memory for Tx LL2 with 0x%08x buffers\n",
1245 p_ll2_info->input.tx_num_desc);
1250 qed_ll2_acquire_connection_ooo(struct qed_hwfn *p_hwfn,
1251 struct qed_ll2_info *p_ll2_info, u16 mtu)
1253 struct qed_ooo_buffer *p_buf = NULL;
1258 if (p_ll2_info->input.conn_type != QED_LL2_TYPE_OOO)
1261 /* Correct number of requested OOO buffers if needed */
1262 if (!p_ll2_info->input.rx_num_ooo_buffers) {
1263 u16 num_desc = p_ll2_info->input.rx_num_desc;
1267 p_ll2_info->input.rx_num_ooo_buffers = num_desc * 2;
1270 for (buf_idx = 0; buf_idx < p_ll2_info->input.rx_num_ooo_buffers;
1272 p_buf = kzalloc(sizeof(*p_buf), GFP_KERNEL);
1278 p_buf->rx_buffer_size = mtu + 26 + ETH_CACHE_LINE_SIZE;
1279 p_buf->rx_buffer_size = (p_buf->rx_buffer_size +
1280 ETH_CACHE_LINE_SIZE - 1) &
1281 ~(ETH_CACHE_LINE_SIZE - 1);
1282 p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1283 p_buf->rx_buffer_size,
1284 &p_buf->rx_buffer_phys_addr,
1292 p_buf->rx_buffer_virt_addr = p_virt;
1293 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info, p_buf);
1296 DP_VERBOSE(p_hwfn, QED_MSG_LL2,
1297 "Allocated [%04x] LL2 OOO buffers [each of size 0x%08x]\n",
1298 p_ll2_info->input.rx_num_ooo_buffers, p_buf->rx_buffer_size);
1305 qed_ll2_set_cbs(struct qed_ll2_info *p_ll2_info, const struct qed_ll2_cbs *cbs)
1307 if (!cbs || (!cbs->rx_comp_cb ||
1308 !cbs->rx_release_cb ||
1309 !cbs->tx_comp_cb || !cbs->tx_release_cb || !cbs->cookie))
1312 p_ll2_info->cbs.rx_comp_cb = cbs->rx_comp_cb;
1313 p_ll2_info->cbs.rx_release_cb = cbs->rx_release_cb;
1314 p_ll2_info->cbs.tx_comp_cb = cbs->tx_comp_cb;
1315 p_ll2_info->cbs.tx_release_cb = cbs->tx_release_cb;
1316 p_ll2_info->cbs.slowpath_cb = cbs->slowpath_cb;
1317 p_ll2_info->cbs.cookie = cbs->cookie;
1322 static enum core_error_handle
1323 qed_ll2_get_error_choice(enum qed_ll2_error_handle err)
1326 case QED_LL2_DROP_PACKET:
1327 return LL2_DROP_PACKET;
1328 case QED_LL2_DO_NOTHING:
1329 return LL2_DO_NOTHING;
1330 case QED_LL2_ASSERT:
1333 return LL2_DO_NOTHING;
1337 int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data)
1339 struct qed_hwfn *p_hwfn = cxt;
1340 qed_int_comp_cb_t comp_rx_cb, comp_tx_cb;
1341 struct qed_ll2_info *p_ll2_info = NULL;
1345 if (!data->p_connection_handle || !p_hwfn->p_ll2_info)
1348 /* Find a free connection to be used */
1349 for (i = 0; (i < QED_MAX_NUM_OF_LL2_CONNECTIONS); i++) {
1350 mutex_lock(&p_hwfn->p_ll2_info[i].mutex);
1351 if (p_hwfn->p_ll2_info[i].b_active) {
1352 mutex_unlock(&p_hwfn->p_ll2_info[i].mutex);
1356 p_hwfn->p_ll2_info[i].b_active = true;
1357 p_ll2_info = &p_hwfn->p_ll2_info[i];
1358 mutex_unlock(&p_hwfn->p_ll2_info[i].mutex);
1364 memcpy(&p_ll2_info->input, &data->input, sizeof(p_ll2_info->input));
1366 switch (data->input.tx_dest) {
1367 case QED_LL2_TX_DEST_NW:
1368 p_ll2_info->tx_dest = CORE_TX_DEST_NW;
1370 case QED_LL2_TX_DEST_LB:
1371 p_ll2_info->tx_dest = CORE_TX_DEST_LB;
1373 case QED_LL2_TX_DEST_DROP:
1374 p_ll2_info->tx_dest = CORE_TX_DEST_DROP;
1380 if (data->input.conn_type == QED_LL2_TYPE_OOO ||
1381 data->input.secondary_queue)
1382 p_ll2_info->main_func_queue = false;
1384 p_ll2_info->main_func_queue = true;
1386 /* Correct maximum number of Tx BDs */
1387 p_tx_max = &p_ll2_info->input.tx_max_bds_per_packet;
1389 *p_tx_max = CORE_LL2_TX_MAX_BDS_PER_PACKET;
1391 *p_tx_max = min_t(u8, *p_tx_max,
1392 CORE_LL2_TX_MAX_BDS_PER_PACKET);
1394 rc = qed_ll2_set_cbs(p_ll2_info, data->cbs);
1396 DP_NOTICE(p_hwfn, "Invalid callback functions\n");
1397 goto q_allocate_fail;
1400 rc = qed_ll2_acquire_connection_rx(p_hwfn, p_ll2_info);
1402 goto q_allocate_fail;
1404 rc = qed_ll2_acquire_connection_tx(p_hwfn, p_ll2_info);
1406 goto q_allocate_fail;
1408 rc = qed_ll2_acquire_connection_ooo(p_hwfn, p_ll2_info,
1411 goto q_allocate_fail;
1413 /* Register callbacks for the Rx/Tx queues */
1414 if (data->input.conn_type == QED_LL2_TYPE_OOO) {
1415 comp_rx_cb = qed_ll2_lb_rxq_completion;
1416 comp_tx_cb = qed_ll2_lb_txq_completion;
1418 comp_rx_cb = qed_ll2_rxq_completion;
1419 comp_tx_cb = qed_ll2_txq_completion;
1422 if (data->input.rx_num_desc) {
1423 qed_int_register_cb(p_hwfn, comp_rx_cb,
1424 &p_hwfn->p_ll2_info[i],
1425 &p_ll2_info->rx_queue.rx_sb_index,
1426 &p_ll2_info->rx_queue.p_fw_cons);
1427 p_ll2_info->rx_queue.b_cb_registered = true;
1430 if (data->input.tx_num_desc) {
1431 qed_int_register_cb(p_hwfn,
1433 &p_hwfn->p_ll2_info[i],
1434 &p_ll2_info->tx_queue.tx_sb_index,
1435 &p_ll2_info->tx_queue.p_fw_cons);
1436 p_ll2_info->tx_queue.b_cb_registered = true;
1439 *data->p_connection_handle = i;
1443 qed_ll2_release_connection(p_hwfn, i);
1447 static int qed_ll2_establish_connection_rx(struct qed_hwfn *p_hwfn,
1448 struct qed_ll2_info *p_ll2_conn)
1450 enum qed_ll2_error_handle error_input;
1451 enum core_error_handle error_mode;
1452 u8 action_on_error = 0;
1454 if (!QED_LL2_RX_REGISTERED(p_ll2_conn))
1457 DIRECT_REG_WR(p_ll2_conn->rx_queue.set_prod_addr, 0x0);
1458 error_input = p_ll2_conn->input.ai_err_packet_too_big;
1459 error_mode = qed_ll2_get_error_choice(error_input);
1460 SET_FIELD(action_on_error,
1461 CORE_RX_ACTION_ON_ERROR_PACKET_TOO_BIG, error_mode);
1462 error_input = p_ll2_conn->input.ai_err_no_buf;
1463 error_mode = qed_ll2_get_error_choice(error_input);
1464 SET_FIELD(action_on_error, CORE_RX_ACTION_ON_ERROR_NO_BUFF, error_mode);
1466 return qed_sp_ll2_rx_queue_start(p_hwfn, p_ll2_conn, action_on_error);
1470 qed_ll2_establish_connection_ooo(struct qed_hwfn *p_hwfn,
1471 struct qed_ll2_info *p_ll2_conn)
1473 if (p_ll2_conn->input.conn_type != QED_LL2_TYPE_OOO)
1476 qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
1477 qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn);
1480 int qed_ll2_establish_connection(void *cxt, u8 connection_handle)
1482 struct qed_hwfn *p_hwfn = cxt;
1483 struct qed_ll2_info *p_ll2_conn;
1484 struct qed_ll2_tx_packet *p_pkt;
1485 struct qed_ll2_rx_queue *p_rx;
1486 struct qed_ll2_tx_queue *p_tx;
1487 struct qed_ptt *p_ptt;
1493 p_ptt = qed_ptt_acquire(p_hwfn);
1497 p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle);
1503 p_rx = &p_ll2_conn->rx_queue;
1504 p_tx = &p_ll2_conn->tx_queue;
1506 qed_chain_reset(&p_rx->rxq_chain);
1507 qed_chain_reset(&p_rx->rcq_chain);
1508 INIT_LIST_HEAD(&p_rx->active_descq);
1509 INIT_LIST_HEAD(&p_rx->free_descq);
1510 INIT_LIST_HEAD(&p_rx->posting_descq);
1511 spin_lock_init(&p_rx->lock);
1512 capacity = qed_chain_get_capacity(&p_rx->rxq_chain);
1513 for (i = 0; i < capacity; i++)
1514 list_add_tail(&p_rx->descq_array[i].list_entry,
1516 *p_rx->p_fw_cons = 0;
1518 qed_chain_reset(&p_tx->txq_chain);
1519 INIT_LIST_HEAD(&p_tx->active_descq);
1520 INIT_LIST_HEAD(&p_tx->free_descq);
1521 INIT_LIST_HEAD(&p_tx->sending_descq);
1522 spin_lock_init(&p_tx->lock);
1523 capacity = qed_chain_get_capacity(&p_tx->txq_chain);
1524 /* First element is part of the packet, rest are flexibly added */
1525 desc_size = (sizeof(*p_pkt) +
1526 (p_ll2_conn->input.tx_max_bds_per_packet - 1) *
1527 sizeof(p_pkt->bds_set));
1529 for (i = 0; i < capacity; i++) {
1530 p_pkt = p_tx->descq_mem + desc_size * i;
1531 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
1533 p_tx->cur_completing_bd_idx = 0;
1535 p_tx->b_completing_packet = false;
1536 p_tx->cur_send_packet = NULL;
1537 p_tx->cur_send_frag_num = 0;
1538 p_tx->cur_completing_frag_num = 0;
1539 *p_tx->p_fw_cons = 0;
1541 rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_CORE, &p_ll2_conn->cid);
1545 qid = p_hwfn->hw_info.resc_start[QED_LL2_QUEUE] + connection_handle;
1546 p_ll2_conn->queue_id = qid;
1547 p_ll2_conn->tx_stats_id = qid;
1548 p_rx->set_prod_addr = (u8 __iomem *)p_hwfn->regview +
1549 GTT_BAR0_MAP_REG_TSDM_RAM +
1550 TSTORM_LL2_RX_PRODS_OFFSET(qid);
1551 p_tx->doorbell_addr = (u8 __iomem *)p_hwfn->doorbells +
1552 qed_db_addr(p_ll2_conn->cid,
1554 /* prepare db data */
1555 SET_FIELD(p_tx->db_msg.params, CORE_DB_DATA_DEST, DB_DEST_XCM);
1556 SET_FIELD(p_tx->db_msg.params, CORE_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
1557 SET_FIELD(p_tx->db_msg.params, CORE_DB_DATA_AGG_VAL_SEL,
1558 DQ_XCM_CORE_TX_BD_PROD_CMD);
1559 p_tx->db_msg.agg_flags = DQ_XCM_CORE_DQ_CF_CMD;
1562 rc = qed_ll2_establish_connection_rx(p_hwfn, p_ll2_conn);
1566 rc = qed_sp_ll2_tx_queue_start(p_hwfn, p_ll2_conn);
1570 if (!QED_IS_RDMA_PERSONALITY(p_hwfn))
1571 qed_wr(p_hwfn, p_ptt, PRS_REG_USE_LIGHT_L2, 1);
1573 qed_ll2_establish_connection_ooo(p_hwfn, p_ll2_conn);
1575 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE) {
1576 if (!test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits))
1577 qed_llh_add_protocol_filter(p_hwfn, p_ptt,
1579 QED_LLH_FILTER_ETHERTYPE);
1580 qed_llh_add_protocol_filter(p_hwfn, p_ptt,
1582 QED_LLH_FILTER_ETHERTYPE);
1586 qed_ptt_release(p_hwfn, p_ptt);
1590 static void qed_ll2_post_rx_buffer_notify_fw(struct qed_hwfn *p_hwfn,
1591 struct qed_ll2_rx_queue *p_rx,
1592 struct qed_ll2_rx_packet *p_curp)
1594 struct qed_ll2_rx_packet *p_posting_packet = NULL;
1595 struct core_ll2_rx_prod rx_prod = { 0, 0, 0 };
1596 bool b_notify_fw = false;
1597 u16 bd_prod, cq_prod;
1599 /* This handles the flushing of already posted buffers */
1600 while (!list_empty(&p_rx->posting_descq)) {
1601 p_posting_packet = list_first_entry(&p_rx->posting_descq,
1602 struct qed_ll2_rx_packet,
1604 list_move_tail(&p_posting_packet->list_entry,
1605 &p_rx->active_descq);
1609 /* This handles the supplied packet [if there is one] */
1611 list_add_tail(&p_curp->list_entry, &p_rx->active_descq);
1618 bd_prod = qed_chain_get_prod_idx(&p_rx->rxq_chain);
1619 cq_prod = qed_chain_get_prod_idx(&p_rx->rcq_chain);
1620 rx_prod.bd_prod = cpu_to_le16(bd_prod);
1621 rx_prod.cqe_prod = cpu_to_le16(cq_prod);
1623 /* Make sure chain element is updated before ringing the doorbell */
1626 DIRECT_REG_WR(p_rx->set_prod_addr, *((u32 *)&rx_prod));
1629 int qed_ll2_post_rx_buffer(void *cxt,
1630 u8 connection_handle,
1632 u16 buf_len, void *cookie, u8 notify_fw)
1634 struct qed_hwfn *p_hwfn = cxt;
1635 struct core_rx_bd_with_buff_len *p_curb = NULL;
1636 struct qed_ll2_rx_packet *p_curp = NULL;
1637 struct qed_ll2_info *p_ll2_conn;
1638 struct qed_ll2_rx_queue *p_rx;
1639 unsigned long flags;
1643 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
1646 p_rx = &p_ll2_conn->rx_queue;
1648 spin_lock_irqsave(&p_rx->lock, flags);
1649 if (!list_empty(&p_rx->free_descq))
1650 p_curp = list_first_entry(&p_rx->free_descq,
1651 struct qed_ll2_rx_packet, list_entry);
1653 if (qed_chain_get_elem_left(&p_rx->rxq_chain) &&
1654 qed_chain_get_elem_left(&p_rx->rcq_chain)) {
1655 p_data = qed_chain_produce(&p_rx->rxq_chain);
1656 p_curb = (struct core_rx_bd_with_buff_len *)p_data;
1657 qed_chain_produce(&p_rx->rcq_chain);
1661 /* If we're lacking entires, let's try to flush buffers to FW */
1662 if (!p_curp || !p_curb) {
1668 /* We have an Rx packet we can fill */
1669 DMA_REGPAIR_LE(p_curb->addr, addr);
1670 p_curb->buff_length = cpu_to_le16(buf_len);
1671 p_curp->rx_buf_addr = addr;
1672 p_curp->cookie = cookie;
1673 p_curp->rxq_bd = p_curb;
1674 p_curp->buf_length = buf_len;
1675 list_del(&p_curp->list_entry);
1677 /* Check if we only want to enqueue this packet without informing FW */
1679 list_add_tail(&p_curp->list_entry, &p_rx->posting_descq);
1684 qed_ll2_post_rx_buffer_notify_fw(p_hwfn, p_rx, p_curp);
1686 spin_unlock_irqrestore(&p_rx->lock, flags);
1690 static void qed_ll2_prepare_tx_packet_set(struct qed_hwfn *p_hwfn,
1691 struct qed_ll2_tx_queue *p_tx,
1692 struct qed_ll2_tx_packet *p_curp,
1693 struct qed_ll2_tx_pkt_info *pkt,
1696 list_del(&p_curp->list_entry);
1697 p_curp->cookie = pkt->cookie;
1698 p_curp->bd_used = pkt->num_of_bds;
1699 p_curp->notify_fw = notify_fw;
1700 p_tx->cur_send_packet = p_curp;
1701 p_tx->cur_send_frag_num = 0;
1703 p_curp->bds_set[p_tx->cur_send_frag_num].tx_frag = pkt->first_frag;
1704 p_curp->bds_set[p_tx->cur_send_frag_num].frag_len = pkt->first_frag_len;
1705 p_tx->cur_send_frag_num++;
1709 qed_ll2_prepare_tx_packet_set_bd(struct qed_hwfn *p_hwfn,
1710 struct qed_ll2_info *p_ll2,
1711 struct qed_ll2_tx_packet *p_curp,
1712 struct qed_ll2_tx_pkt_info *pkt)
1714 struct qed_chain *p_tx_chain = &p_ll2->tx_queue.txq_chain;
1715 u16 prod_idx = qed_chain_get_prod_idx(p_tx_chain);
1716 struct core_tx_bd *start_bd = NULL;
1717 enum core_roce_flavor_type roce_flavor;
1718 enum core_tx_dest tx_dest;
1719 u16 bd_data = 0, frag_idx;
1721 roce_flavor = (pkt->qed_roce_flavor == QED_LL2_ROCE) ? CORE_ROCE
1724 switch (pkt->tx_dest) {
1725 case QED_LL2_TX_DEST_NW:
1726 tx_dest = CORE_TX_DEST_NW;
1728 case QED_LL2_TX_DEST_LB:
1729 tx_dest = CORE_TX_DEST_LB;
1731 case QED_LL2_TX_DEST_DROP:
1732 tx_dest = CORE_TX_DEST_DROP;
1735 tx_dest = CORE_TX_DEST_LB;
1739 start_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain);
1740 if (QED_IS_IWARP_PERSONALITY(p_hwfn) &&
1741 p_ll2->input.conn_type == QED_LL2_TYPE_OOO) {
1742 start_bd->nw_vlan_or_lb_echo =
1743 cpu_to_le16(IWARP_LL2_IN_ORDER_TX_QUEUE);
1745 start_bd->nw_vlan_or_lb_echo = cpu_to_le16(pkt->vlan);
1746 if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) &&
1747 p_ll2->input.conn_type == QED_LL2_TYPE_FCOE)
1748 pkt->remove_stag = true;
1751 SET_FIELD(start_bd->bitfield1, CORE_TX_BD_L4_HDR_OFFSET_W,
1752 cpu_to_le16(pkt->l4_hdr_offset_w));
1753 SET_FIELD(start_bd->bitfield1, CORE_TX_BD_TX_DST, tx_dest);
1754 bd_data |= pkt->bd_flags;
1755 SET_FIELD(bd_data, CORE_TX_BD_DATA_START_BD, 0x1);
1756 SET_FIELD(bd_data, CORE_TX_BD_DATA_NBDS, pkt->num_of_bds);
1757 SET_FIELD(bd_data, CORE_TX_BD_DATA_ROCE_FLAV, roce_flavor);
1758 SET_FIELD(bd_data, CORE_TX_BD_DATA_IP_CSUM, !!(pkt->enable_ip_cksum));
1759 SET_FIELD(bd_data, CORE_TX_BD_DATA_L4_CSUM, !!(pkt->enable_l4_cksum));
1760 SET_FIELD(bd_data, CORE_TX_BD_DATA_IP_LEN, !!(pkt->calc_ip_len));
1761 SET_FIELD(bd_data, CORE_TX_BD_DATA_DISABLE_STAG_INSERTION,
1762 !!(pkt->remove_stag));
1764 start_bd->bd_data.as_bitfield = cpu_to_le16(bd_data);
1765 DMA_REGPAIR_LE(start_bd->addr, pkt->first_frag);
1766 start_bd->nbytes = cpu_to_le16(pkt->first_frag_len);
1769 (NETIF_MSG_TX_QUEUED | QED_MSG_LL2),
1770 "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",
1773 p_ll2->input.conn_type,
1775 pkt->first_frag_len,
1777 le32_to_cpu(start_bd->addr.hi),
1778 le32_to_cpu(start_bd->addr.lo));
1780 if (p_ll2->tx_queue.cur_send_frag_num == pkt->num_of_bds)
1783 /* Need to provide the packet with additional BDs for frags */
1784 for (frag_idx = p_ll2->tx_queue.cur_send_frag_num;
1785 frag_idx < pkt->num_of_bds; frag_idx++) {
1786 struct core_tx_bd **p_bd = &p_curp->bds_set[frag_idx].txq_bd;
1788 *p_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain);
1789 (*p_bd)->bd_data.as_bitfield = 0;
1790 (*p_bd)->bitfield1 = 0;
1791 p_curp->bds_set[frag_idx].tx_frag = 0;
1792 p_curp->bds_set[frag_idx].frag_len = 0;
1796 /* This should be called while the Txq spinlock is being held */
1797 static void qed_ll2_tx_packet_notify(struct qed_hwfn *p_hwfn,
1798 struct qed_ll2_info *p_ll2_conn)
1800 bool b_notify = p_ll2_conn->tx_queue.cur_send_packet->notify_fw;
1801 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
1802 struct qed_ll2_tx_packet *p_pkt = NULL;
1805 /* If there are missing BDs, don't do anything now */
1806 if (p_ll2_conn->tx_queue.cur_send_frag_num !=
1807 p_ll2_conn->tx_queue.cur_send_packet->bd_used)
1810 /* Push the current packet to the list and clean after it */
1811 list_add_tail(&p_ll2_conn->tx_queue.cur_send_packet->list_entry,
1812 &p_ll2_conn->tx_queue.sending_descq);
1813 p_ll2_conn->tx_queue.cur_send_packet = NULL;
1814 p_ll2_conn->tx_queue.cur_send_frag_num = 0;
1816 /* Notify FW of packet only if requested to */
1820 bd_prod = qed_chain_get_prod_idx(&p_ll2_conn->tx_queue.txq_chain);
1822 while (!list_empty(&p_tx->sending_descq)) {
1823 p_pkt = list_first_entry(&p_tx->sending_descq,
1824 struct qed_ll2_tx_packet, list_entry);
1828 list_move_tail(&p_pkt->list_entry, &p_tx->active_descq);
1831 p_tx->db_msg.spq_prod = cpu_to_le16(bd_prod);
1833 /* Make sure the BDs data is updated before ringing the doorbell */
1836 DIRECT_REG_WR(p_tx->doorbell_addr, *((u32 *)&p_tx->db_msg));
1839 (NETIF_MSG_TX_QUEUED | QED_MSG_LL2),
1840 "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Doorbelled [producer 0x%04x]\n",
1841 p_ll2_conn->queue_id,
1843 p_ll2_conn->input.conn_type, p_tx->db_msg.spq_prod);
1846 int qed_ll2_prepare_tx_packet(void *cxt,
1847 u8 connection_handle,
1848 struct qed_ll2_tx_pkt_info *pkt,
1851 struct qed_hwfn *p_hwfn = cxt;
1852 struct qed_ll2_tx_packet *p_curp = NULL;
1853 struct qed_ll2_info *p_ll2_conn = NULL;
1854 struct qed_ll2_tx_queue *p_tx;
1855 struct qed_chain *p_tx_chain;
1856 unsigned long flags;
1859 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
1862 p_tx = &p_ll2_conn->tx_queue;
1863 p_tx_chain = &p_tx->txq_chain;
1865 if (pkt->num_of_bds > p_ll2_conn->input.tx_max_bds_per_packet)
1868 spin_lock_irqsave(&p_tx->lock, flags);
1869 if (p_tx->cur_send_packet) {
1874 /* Get entry, but only if we have tx elements for it */
1875 if (!list_empty(&p_tx->free_descq))
1876 p_curp = list_first_entry(&p_tx->free_descq,
1877 struct qed_ll2_tx_packet, list_entry);
1878 if (p_curp && qed_chain_get_elem_left(p_tx_chain) < pkt->num_of_bds)
1886 /* Prepare packet and BD, and perhaps send a doorbell to FW */
1887 qed_ll2_prepare_tx_packet_set(p_hwfn, p_tx, p_curp, pkt, notify_fw);
1889 qed_ll2_prepare_tx_packet_set_bd(p_hwfn, p_ll2_conn, p_curp, pkt);
1891 qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn);
1894 spin_unlock_irqrestore(&p_tx->lock, flags);
1898 int qed_ll2_set_fragment_of_tx_packet(void *cxt,
1899 u8 connection_handle,
1900 dma_addr_t addr, u16 nbytes)
1902 struct qed_ll2_tx_packet *p_cur_send_packet = NULL;
1903 struct qed_hwfn *p_hwfn = cxt;
1904 struct qed_ll2_info *p_ll2_conn = NULL;
1905 u16 cur_send_frag_num = 0;
1906 struct core_tx_bd *p_bd;
1907 unsigned long flags;
1909 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
1913 if (!p_ll2_conn->tx_queue.cur_send_packet)
1916 p_cur_send_packet = p_ll2_conn->tx_queue.cur_send_packet;
1917 cur_send_frag_num = p_ll2_conn->tx_queue.cur_send_frag_num;
1919 if (cur_send_frag_num >= p_cur_send_packet->bd_used)
1922 /* Fill the BD information, and possibly notify FW */
1923 p_bd = p_cur_send_packet->bds_set[cur_send_frag_num].txq_bd;
1924 DMA_REGPAIR_LE(p_bd->addr, addr);
1925 p_bd->nbytes = cpu_to_le16(nbytes);
1926 p_cur_send_packet->bds_set[cur_send_frag_num].tx_frag = addr;
1927 p_cur_send_packet->bds_set[cur_send_frag_num].frag_len = nbytes;
1929 p_ll2_conn->tx_queue.cur_send_frag_num++;
1931 spin_lock_irqsave(&p_ll2_conn->tx_queue.lock, flags);
1932 qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn);
1933 spin_unlock_irqrestore(&p_ll2_conn->tx_queue.lock, flags);
1938 int qed_ll2_terminate_connection(void *cxt, u8 connection_handle)
1940 struct qed_hwfn *p_hwfn = cxt;
1941 struct qed_ll2_info *p_ll2_conn = NULL;
1943 struct qed_ptt *p_ptt;
1945 p_ptt = qed_ptt_acquire(p_hwfn);
1949 p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle);
1955 /* Stop Tx & Rx of connection, if needed */
1956 if (QED_LL2_TX_REGISTERED(p_ll2_conn)) {
1957 p_ll2_conn->tx_queue.b_cb_registered = false;
1958 smp_wmb(); /* Make sure this is seen by ll2_lb_rxq_completion */
1959 rc = qed_sp_ll2_tx_queue_stop(p_hwfn, p_ll2_conn);
1963 qed_ll2_txq_flush(p_hwfn, connection_handle);
1964 qed_int_unregister_cb(p_hwfn, p_ll2_conn->tx_queue.tx_sb_index);
1967 if (QED_LL2_RX_REGISTERED(p_ll2_conn)) {
1968 p_ll2_conn->rx_queue.b_cb_registered = false;
1969 smp_wmb(); /* Make sure this is seen by ll2_lb_rxq_completion */
1970 rc = qed_sp_ll2_rx_queue_stop(p_hwfn, p_ll2_conn);
1974 qed_ll2_rxq_flush(p_hwfn, connection_handle);
1975 qed_int_unregister_cb(p_hwfn, p_ll2_conn->rx_queue.rx_sb_index);
1978 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO)
1979 qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
1981 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE) {
1982 if (!test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits))
1983 qed_llh_remove_protocol_filter(p_hwfn, p_ptt,
1985 QED_LLH_FILTER_ETHERTYPE);
1986 qed_llh_remove_protocol_filter(p_hwfn, p_ptt,
1988 QED_LLH_FILTER_ETHERTYPE);
1992 qed_ptt_release(p_hwfn, p_ptt);
1996 static void qed_ll2_release_connection_ooo(struct qed_hwfn *p_hwfn,
1997 struct qed_ll2_info *p_ll2_conn)
1999 struct qed_ooo_buffer *p_buffer;
2001 if (p_ll2_conn->input.conn_type != QED_LL2_TYPE_OOO)
2004 qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
2005 while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn,
2006 p_hwfn->p_ooo_info))) {
2007 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
2008 p_buffer->rx_buffer_size,
2009 p_buffer->rx_buffer_virt_addr,
2010 p_buffer->rx_buffer_phys_addr);
2015 void qed_ll2_release_connection(void *cxt, u8 connection_handle)
2017 struct qed_hwfn *p_hwfn = cxt;
2018 struct qed_ll2_info *p_ll2_conn = NULL;
2020 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
2024 kfree(p_ll2_conn->tx_queue.descq_mem);
2025 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->tx_queue.txq_chain);
2027 kfree(p_ll2_conn->rx_queue.descq_array);
2028 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rxq_chain);
2029 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rcq_chain);
2031 qed_cxt_release_cid(p_hwfn, p_ll2_conn->cid);
2033 qed_ll2_release_connection_ooo(p_hwfn, p_ll2_conn);
2035 mutex_lock(&p_ll2_conn->mutex);
2036 p_ll2_conn->b_active = false;
2037 mutex_unlock(&p_ll2_conn->mutex);
2040 int qed_ll2_alloc(struct qed_hwfn *p_hwfn)
2042 struct qed_ll2_info *p_ll2_connections;
2045 /* Allocate LL2's set struct */
2046 p_ll2_connections = kcalloc(QED_MAX_NUM_OF_LL2_CONNECTIONS,
2047 sizeof(struct qed_ll2_info), GFP_KERNEL);
2048 if (!p_ll2_connections) {
2049 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_ll2'\n");
2053 for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++)
2054 p_ll2_connections[i].my_id = i;
2056 p_hwfn->p_ll2_info = p_ll2_connections;
2060 void qed_ll2_setup(struct qed_hwfn *p_hwfn)
2064 for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++)
2065 mutex_init(&p_hwfn->p_ll2_info[i].mutex);
2068 void qed_ll2_free(struct qed_hwfn *p_hwfn)
2070 if (!p_hwfn->p_ll2_info)
2073 kfree(p_hwfn->p_ll2_info);
2074 p_hwfn->p_ll2_info = NULL;
2077 static void _qed_ll2_get_port_stats(struct qed_hwfn *p_hwfn,
2078 struct qed_ptt *p_ptt,
2079 struct qed_ll2_stats *p_stats)
2081 struct core_ll2_port_stats port_stats;
2083 memset(&port_stats, 0, sizeof(port_stats));
2084 qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
2085 BAR0_MAP_REG_TSDM_RAM +
2086 TSTORM_LL2_PORT_STAT_OFFSET(MFW_PORT(p_hwfn)),
2087 sizeof(port_stats));
2089 p_stats->gsi_invalid_hdr = HILO_64_REGPAIR(port_stats.gsi_invalid_hdr);
2090 p_stats->gsi_invalid_pkt_length =
2091 HILO_64_REGPAIR(port_stats.gsi_invalid_pkt_length);
2092 p_stats->gsi_unsupported_pkt_typ =
2093 HILO_64_REGPAIR(port_stats.gsi_unsupported_pkt_typ);
2094 p_stats->gsi_crcchksm_error =
2095 HILO_64_REGPAIR(port_stats.gsi_crcchksm_error);
2098 static void _qed_ll2_get_tstats(struct qed_hwfn *p_hwfn,
2099 struct qed_ptt *p_ptt,
2100 struct qed_ll2_info *p_ll2_conn,
2101 struct qed_ll2_stats *p_stats)
2103 struct core_ll2_tstorm_per_queue_stat tstats;
2104 u8 qid = p_ll2_conn->queue_id;
2107 memset(&tstats, 0, sizeof(tstats));
2108 tstats_addr = BAR0_MAP_REG_TSDM_RAM +
2109 CORE_LL2_TSTORM_PER_QUEUE_STAT_OFFSET(qid);
2110 qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, sizeof(tstats));
2112 p_stats->packet_too_big_discard =
2113 HILO_64_REGPAIR(tstats.packet_too_big_discard);
2114 p_stats->no_buff_discard = HILO_64_REGPAIR(tstats.no_buff_discard);
2117 static void _qed_ll2_get_ustats(struct qed_hwfn *p_hwfn,
2118 struct qed_ptt *p_ptt,
2119 struct qed_ll2_info *p_ll2_conn,
2120 struct qed_ll2_stats *p_stats)
2122 struct core_ll2_ustorm_per_queue_stat ustats;
2123 u8 qid = p_ll2_conn->queue_id;
2126 memset(&ustats, 0, sizeof(ustats));
2127 ustats_addr = BAR0_MAP_REG_USDM_RAM +
2128 CORE_LL2_USTORM_PER_QUEUE_STAT_OFFSET(qid);
2129 qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, sizeof(ustats));
2131 p_stats->rcv_ucast_bytes = HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
2132 p_stats->rcv_mcast_bytes = HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
2133 p_stats->rcv_bcast_bytes = HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
2134 p_stats->rcv_ucast_pkts = HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
2135 p_stats->rcv_mcast_pkts = HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
2136 p_stats->rcv_bcast_pkts = HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
2139 static void _qed_ll2_get_pstats(struct qed_hwfn *p_hwfn,
2140 struct qed_ptt *p_ptt,
2141 struct qed_ll2_info *p_ll2_conn,
2142 struct qed_ll2_stats *p_stats)
2144 struct core_ll2_pstorm_per_queue_stat pstats;
2145 u8 stats_id = p_ll2_conn->tx_stats_id;
2148 memset(&pstats, 0, sizeof(pstats));
2149 pstats_addr = BAR0_MAP_REG_PSDM_RAM +
2150 CORE_LL2_PSTORM_PER_QUEUE_STAT_OFFSET(stats_id);
2151 qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, sizeof(pstats));
2153 p_stats->sent_ucast_bytes = HILO_64_REGPAIR(pstats.sent_ucast_bytes);
2154 p_stats->sent_mcast_bytes = HILO_64_REGPAIR(pstats.sent_mcast_bytes);
2155 p_stats->sent_bcast_bytes = HILO_64_REGPAIR(pstats.sent_bcast_bytes);
2156 p_stats->sent_ucast_pkts = HILO_64_REGPAIR(pstats.sent_ucast_pkts);
2157 p_stats->sent_mcast_pkts = HILO_64_REGPAIR(pstats.sent_mcast_pkts);
2158 p_stats->sent_bcast_pkts = HILO_64_REGPAIR(pstats.sent_bcast_pkts);
2161 int qed_ll2_get_stats(void *cxt,
2162 u8 connection_handle, struct qed_ll2_stats *p_stats)
2164 struct qed_hwfn *p_hwfn = cxt;
2165 struct qed_ll2_info *p_ll2_conn = NULL;
2166 struct qed_ptt *p_ptt;
2168 memset(p_stats, 0, sizeof(*p_stats));
2170 if ((connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS) ||
2171 !p_hwfn->p_ll2_info)
2174 p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle];
2176 p_ptt = qed_ptt_acquire(p_hwfn);
2178 DP_ERR(p_hwfn, "Failed to acquire ptt\n");
2182 if (p_ll2_conn->input.gsi_enable)
2183 _qed_ll2_get_port_stats(p_hwfn, p_ptt, p_stats);
2184 _qed_ll2_get_tstats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
2185 _qed_ll2_get_ustats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
2186 if (p_ll2_conn->tx_stats_en)
2187 _qed_ll2_get_pstats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
2189 qed_ptt_release(p_hwfn, p_ptt);
2193 static void qed_ll2b_release_rx_packet(void *cxt,
2194 u8 connection_handle,
2196 dma_addr_t rx_buf_addr,
2199 struct qed_hwfn *p_hwfn = cxt;
2201 qed_ll2_dealloc_buffer(p_hwfn->cdev, cookie);
2204 static void qed_ll2_register_cb_ops(struct qed_dev *cdev,
2205 const struct qed_ll2_cb_ops *ops,
2208 cdev->ll2->cbs = ops;
2209 cdev->ll2->cb_cookie = cookie;
2212 struct qed_ll2_cbs ll2_cbs = {
2213 .rx_comp_cb = &qed_ll2b_complete_rx_packet,
2214 .rx_release_cb = &qed_ll2b_release_rx_packet,
2215 .tx_comp_cb = &qed_ll2b_complete_tx_packet,
2216 .tx_release_cb = &qed_ll2b_complete_tx_packet,
2219 static void qed_ll2_set_conn_data(struct qed_dev *cdev,
2220 struct qed_ll2_acquire_data *data,
2221 struct qed_ll2_params *params,
2222 enum qed_ll2_conn_type conn_type,
2223 u8 *handle, bool lb)
2225 memset(data, 0, sizeof(*data));
2227 data->input.conn_type = conn_type;
2228 data->input.mtu = params->mtu;
2229 data->input.rx_num_desc = QED_LL2_RX_SIZE;
2230 data->input.rx_drop_ttl0_flg = params->drop_ttl0_packets;
2231 data->input.rx_vlan_removal_en = params->rx_vlan_stripping;
2232 data->input.tx_num_desc = QED_LL2_TX_SIZE;
2233 data->p_connection_handle = handle;
2234 data->cbs = &ll2_cbs;
2235 ll2_cbs.cookie = QED_LEADING_HWFN(cdev);
2238 data->input.tx_tc = PKT_LB_TC;
2239 data->input.tx_dest = QED_LL2_TX_DEST_LB;
2241 data->input.tx_tc = 0;
2242 data->input.tx_dest = QED_LL2_TX_DEST_NW;
2246 static int qed_ll2_start_ooo(struct qed_dev *cdev,
2247 struct qed_ll2_params *params)
2249 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2250 u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id;
2251 struct qed_ll2_acquire_data data;
2254 qed_ll2_set_conn_data(cdev, &data, params,
2255 QED_LL2_TYPE_OOO, handle, true);
2257 rc = qed_ll2_acquire_connection(hwfn, &data);
2259 DP_INFO(cdev, "Failed to acquire LL2 OOO connection\n");
2263 rc = qed_ll2_establish_connection(hwfn, *handle);
2265 DP_INFO(cdev, "Failed to establist LL2 OOO connection\n");
2272 qed_ll2_release_connection(hwfn, *handle);
2274 *handle = QED_LL2_UNUSED_HANDLE;
2278 static int qed_ll2_start(struct qed_dev *cdev, struct qed_ll2_params *params)
2280 struct qed_ll2_buffer *buffer, *tmp_buffer;
2281 enum qed_ll2_conn_type conn_type;
2282 struct qed_ll2_acquire_data data;
2283 struct qed_ptt *p_ptt;
2287 /* Initialize LL2 locks & lists */
2288 INIT_LIST_HEAD(&cdev->ll2->list);
2289 spin_lock_init(&cdev->ll2->lock);
2290 cdev->ll2->rx_size = NET_SKB_PAD + ETH_HLEN +
2291 L1_CACHE_BYTES + params->mtu;
2293 /*Allocate memory for LL2 */
2294 DP_INFO(cdev, "Allocating LL2 buffers of size %08x bytes\n",
2295 cdev->ll2->rx_size);
2296 for (i = 0; i < QED_LL2_RX_SIZE; i++) {
2297 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
2299 DP_INFO(cdev, "Failed to allocate LL2 buffers\n");
2303 rc = qed_ll2_alloc_buffer(cdev, (u8 **)&buffer->data,
2304 &buffer->phys_addr);
2310 list_add_tail(&buffer->list, &cdev->ll2->list);
2313 switch (QED_LEADING_HWFN(cdev)->hw_info.personality) {
2315 conn_type = QED_LL2_TYPE_FCOE;
2318 conn_type = QED_LL2_TYPE_ISCSI;
2320 case QED_PCI_ETH_ROCE:
2321 conn_type = QED_LL2_TYPE_ROCE;
2324 conn_type = QED_LL2_TYPE_TEST;
2327 qed_ll2_set_conn_data(cdev, &data, params, conn_type,
2328 &cdev->ll2->handle, false);
2330 rc = qed_ll2_acquire_connection(QED_LEADING_HWFN(cdev), &data);
2332 DP_INFO(cdev, "Failed to acquire LL2 connection\n");
2336 rc = qed_ll2_establish_connection(QED_LEADING_HWFN(cdev),
2339 DP_INFO(cdev, "Failed to establish LL2 connection\n");
2343 /* Post all Rx buffers to FW */
2344 spin_lock_bh(&cdev->ll2->lock);
2345 list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list) {
2346 rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev),
2348 buffer->phys_addr, 0, buffer, 1);
2351 "Failed to post an Rx buffer; Deleting it\n");
2352 dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
2353 cdev->ll2->rx_size, DMA_FROM_DEVICE);
2354 kfree(buffer->data);
2355 list_del(&buffer->list);
2358 cdev->ll2->rx_cnt++;
2361 spin_unlock_bh(&cdev->ll2->lock);
2363 if (!cdev->ll2->rx_cnt) {
2364 DP_INFO(cdev, "Failed passing even a single Rx buffer\n");
2365 goto release_terminate;
2368 if (!is_valid_ether_addr(params->ll2_mac_address)) {
2369 DP_INFO(cdev, "Invalid Ethernet address\n");
2370 goto release_terminate;
2373 if (QED_LEADING_HWFN(cdev)->hw_info.personality == QED_PCI_ISCSI) {
2374 DP_VERBOSE(cdev, QED_MSG_STORAGE, "Starting OOO LL2 queue\n");
2375 rc = qed_ll2_start_ooo(cdev, params);
2378 "Failed to initialize the OOO LL2 queue\n");
2379 goto release_terminate;
2383 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
2385 DP_INFO(cdev, "Failed to acquire PTT\n");
2386 goto release_terminate;
2389 rc = qed_llh_add_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
2390 params->ll2_mac_address);
2391 qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
2393 DP_ERR(cdev, "Failed to allocate LLH filter\n");
2394 goto release_terminate_all;
2397 ether_addr_copy(cdev->ll2_mac_address, params->ll2_mac_address);
2400 release_terminate_all:
2403 qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
2405 qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
2407 qed_ll2_kill_buffers(cdev);
2408 cdev->ll2->handle = QED_LL2_UNUSED_HANDLE;
2412 static int qed_ll2_stop(struct qed_dev *cdev)
2414 struct qed_ptt *p_ptt;
2417 if (cdev->ll2->handle == QED_LL2_UNUSED_HANDLE)
2420 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
2422 DP_INFO(cdev, "Failed to acquire PTT\n");
2426 qed_llh_remove_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
2427 cdev->ll2_mac_address);
2428 qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
2429 eth_zero_addr(cdev->ll2_mac_address);
2431 if (QED_LEADING_HWFN(cdev)->hw_info.personality == QED_PCI_ISCSI)
2432 qed_ll2_stop_ooo(cdev);
2434 rc = qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev),
2437 DP_INFO(cdev, "Failed to terminate LL2 connection\n");
2439 qed_ll2_kill_buffers(cdev);
2441 qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
2442 cdev->ll2->handle = QED_LL2_UNUSED_HANDLE;
2449 static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb,
2450 unsigned long xmit_flags)
2452 struct qed_ll2_tx_pkt_info pkt;
2453 const skb_frag_t *frag;
2454 u8 flags = 0, nr_frags;
2455 int rc = -EINVAL, i;
2459 if (unlikely(skb->ip_summed != CHECKSUM_NONE)) {
2460 DP_INFO(cdev, "Cannot transmit a checksummed packet\n");
2464 /* Cache number of fragments from SKB since SKB may be freed by
2465 * the completion routine after calling qed_ll2_prepare_tx_packet()
2467 nr_frags = skb_shinfo(skb)->nr_frags;
2469 if (1 + nr_frags > CORE_LL2_TX_MAX_BDS_PER_PACKET) {
2470 DP_ERR(cdev, "Cannot transmit a packet with %d fragments\n",
2475 mapping = dma_map_single(&cdev->pdev->dev, skb->data,
2476 skb->len, DMA_TO_DEVICE);
2477 if (unlikely(dma_mapping_error(&cdev->pdev->dev, mapping))) {
2478 DP_NOTICE(cdev, "SKB mapping failed\n");
2482 /* Request HW to calculate IP csum */
2483 if (!((vlan_get_protocol(skb) == htons(ETH_P_IPV6)) &&
2484 ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
2485 flags |= BIT(CORE_TX_BD_DATA_IP_CSUM_SHIFT);
2487 if (skb_vlan_tag_present(skb)) {
2488 vlan = skb_vlan_tag_get(skb);
2489 flags |= BIT(CORE_TX_BD_DATA_VLAN_INSERTION_SHIFT);
2492 memset(&pkt, 0, sizeof(pkt));
2493 pkt.num_of_bds = 1 + nr_frags;
2495 pkt.bd_flags = flags;
2496 pkt.tx_dest = QED_LL2_TX_DEST_NW;
2497 pkt.first_frag = mapping;
2498 pkt.first_frag_len = skb->len;
2500 if (test_bit(QED_MF_UFP_SPECIFIC, &cdev->mf_bits) &&
2501 test_bit(QED_LL2_XMIT_FLAGS_FIP_DISCOVERY, &xmit_flags))
2502 pkt.remove_stag = true;
2504 /* qed_ll2_prepare_tx_packet() may actually send the packet if
2505 * there are no fragments in the skb and subsequently the completion
2506 * routine may run and free the SKB, so no dereferencing the SKB
2507 * beyond this point unless skb has any fragments.
2509 rc = qed_ll2_prepare_tx_packet(&cdev->hwfns[0], cdev->ll2->handle,
2514 for (i = 0; i < nr_frags; i++) {
2515 frag = &skb_shinfo(skb)->frags[i];
2517 mapping = skb_frag_dma_map(&cdev->pdev->dev, frag, 0,
2518 skb_frag_size(frag), DMA_TO_DEVICE);
2520 if (unlikely(dma_mapping_error(&cdev->pdev->dev, mapping))) {
2522 "Unable to map frag - dropping packet\n");
2527 rc = qed_ll2_set_fragment_of_tx_packet(QED_LEADING_HWFN(cdev),
2530 skb_frag_size(frag));
2532 /* if failed not much to do here, partial packet has been posted
2533 * we can't free memory, will need to wait for completion.
2542 dma_unmap_single(&cdev->pdev->dev, mapping, skb->len, DMA_TO_DEVICE);
2548 static int qed_ll2_stats(struct qed_dev *cdev, struct qed_ll2_stats *stats)
2553 return qed_ll2_get_stats(QED_LEADING_HWFN(cdev),
2554 cdev->ll2->handle, stats);
2557 const struct qed_ll2_ops qed_ll2_ops_pass = {
2558 .start = &qed_ll2_start,
2559 .stop = &qed_ll2_stop,
2560 .start_xmit = &qed_ll2_start_xmit,
2561 .register_cb_ops = &qed_ll2_register_cb_ops,
2562 .get_stats = &qed_ll2_stats,
2565 int qed_ll2_alloc_if(struct qed_dev *cdev)
2567 cdev->ll2 = kzalloc(sizeof(*cdev->ll2), GFP_KERNEL);
2568 return cdev->ll2 ? 0 : -ENOMEM;
2571 void qed_ll2_dealloc_if(struct qed_dev *cdev)