1 /* QLogic qed NIC Driver
3 * Copyright (c) 2015 QLogic Corporation
5 * This software is available under the terms of the GNU General Public License
6 * (GPL) Version 2, available from the file COPYING in the main directory of
10 #include <linux/types.h>
11 #include <asm/byteorder.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/if_vlan.h>
14 #include <linux/kernel.h>
15 #include <linux/pci.h>
16 #include <linux/slab.h>
17 #include <linux/stddef.h>
18 #include <linux/version.h>
19 #include <linux/workqueue.h>
21 #include <linux/bitops.h>
22 #include <linux/delay.h>
23 #include <linux/errno.h>
24 #include <linux/etherdevice.h>
26 #include <linux/list.h>
27 #include <linux/mutex.h>
28 #include <linux/spinlock.h>
29 #include <linux/string.h>
30 #include <linux/qed/qed_ll2_if.h>
33 #include "qed_dev_api.h"
40 #include "qed_reg_addr.h"
44 #define QED_LL2_RX_REGISTERED(ll2) ((ll2)->rx_queue.b_cb_registred)
45 #define QED_LL2_TX_REGISTERED(ll2) ((ll2)->tx_queue.b_cb_registred)
47 #define QED_LL2_TX_SIZE (256)
48 #define QED_LL2_RX_SIZE (4096)
50 struct qed_cb_ll2_info {
56 /* Lock protecting LL2 buffer lists in sleepless context */
58 struct list_head list;
60 const struct qed_ll2_cb_ops *cbs;
64 struct qed_ll2_buffer {
65 struct list_head list;
70 static void qed_ll2b_complete_tx_packet(struct qed_hwfn *p_hwfn,
73 dma_addr_t first_frag_addr,
77 struct qed_dev *cdev = p_hwfn->cdev;
78 struct sk_buff *skb = cookie;
80 /* All we need to do is release the mapping */
81 dma_unmap_single(&p_hwfn->cdev->pdev->dev, first_frag_addr,
82 skb_headlen(skb), DMA_TO_DEVICE);
84 if (cdev->ll2->cbs && cdev->ll2->cbs->tx_cb)
85 cdev->ll2->cbs->tx_cb(cdev->ll2->cb_cookie, skb,
88 if (cdev->ll2->frags_mapped)
89 /* Case where mapped frags were received, need to
90 * free skb with nr_frags marked as 0
92 skb_shinfo(skb)->nr_frags = 0;
94 dev_kfree_skb_any(skb);
97 static int qed_ll2_alloc_buffer(struct qed_dev *cdev,
98 u8 **data, dma_addr_t *phys_addr)
100 *data = kmalloc(cdev->ll2->rx_size, GFP_ATOMIC);
102 DP_INFO(cdev, "Failed to allocate LL2 buffer data\n");
106 *phys_addr = dma_map_single(&cdev->pdev->dev,
107 ((*data) + NET_SKB_PAD),
108 cdev->ll2->rx_size, DMA_FROM_DEVICE);
109 if (dma_mapping_error(&cdev->pdev->dev, *phys_addr)) {
110 DP_INFO(cdev, "Failed to map LL2 buffer data\n");
118 static int qed_ll2_dealloc_buffer(struct qed_dev *cdev,
119 struct qed_ll2_buffer *buffer)
121 spin_lock_bh(&cdev->ll2->lock);
123 dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
124 cdev->ll2->rx_size, DMA_FROM_DEVICE);
126 list_del(&buffer->list);
129 if (!cdev->ll2->rx_cnt)
130 DP_INFO(cdev, "All LL2 entries were removed\n");
132 spin_unlock_bh(&cdev->ll2->lock);
137 static void qed_ll2_kill_buffers(struct qed_dev *cdev)
139 struct qed_ll2_buffer *buffer, *tmp_buffer;
141 list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list)
142 qed_ll2_dealloc_buffer(cdev, buffer);
145 static void qed_ll2b_complete_rx_packet(struct qed_hwfn *p_hwfn,
146 u8 connection_handle,
147 struct qed_ll2_rx_packet *p_pkt,
148 struct core_rx_fast_path_cqe *p_cqe,
151 u16 packet_length = le16_to_cpu(p_cqe->packet_length);
152 struct qed_ll2_buffer *buffer = p_pkt->cookie;
153 struct qed_dev *cdev = p_hwfn->cdev;
154 u16 vlan = le16_to_cpu(p_cqe->vlan);
155 u32 opaque_data_0, opaque_data_1;
156 u8 pad = p_cqe->placement_offset;
157 dma_addr_t new_phys_addr;
163 opaque_data_0 = le32_to_cpu(p_cqe->opaque_data.data[0]);
164 opaque_data_1 = le32_to_cpu(p_cqe->opaque_data.data[1]);
167 (NETIF_MSG_RX_STATUS | QED_MSG_STORAGE | NETIF_MSG_PKTDATA),
168 "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",
169 (u64)p_pkt->rx_buf_addr, pad, packet_length,
170 le16_to_cpu(p_cqe->parse_flags.flags), vlan,
171 opaque_data_0, opaque_data_1);
173 if ((cdev->dp_module & NETIF_MSG_PKTDATA) && buffer->data) {
174 print_hex_dump(KERN_INFO, "",
175 DUMP_PREFIX_OFFSET, 16, 1,
176 buffer->data, packet_length, false);
179 /* Determine if data is valid */
180 if (packet_length < ETH_HLEN)
183 /* Allocate a replacement for buffer; Reuse upon failure */
185 rc = qed_ll2_alloc_buffer(p_hwfn->cdev, &new_data,
188 /* If need to reuse or there's no replacement buffer, repost this */
192 skb = build_skb(buffer->data, 0);
199 skb_reserve(skb, pad);
200 skb_put(skb, packet_length);
201 skb_checksum_none_assert(skb);
203 /* Get parital ethernet information instead of eth_type_trans(),
204 * Since we don't have an associated net_device.
206 skb_reset_mac_header(skb);
207 skb->protocol = eth_hdr(skb)->h_proto;
209 /* Pass SKB onward */
210 if (cdev->ll2->cbs && cdev->ll2->cbs->rx_cb) {
212 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan);
213 cdev->ll2->cbs->rx_cb(cdev->ll2->cb_cookie, skb,
214 opaque_data_0, opaque_data_1);
217 /* Update Buffer information and update FW producer */
218 buffer->data = new_data;
219 buffer->phys_addr = new_phys_addr;
222 rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev), cdev->ll2->handle,
223 buffer->phys_addr, 0, buffer, 1);
226 qed_ll2_dealloc_buffer(cdev, buffer);
229 static struct qed_ll2_info *__qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn,
230 u8 connection_handle,
234 struct qed_ll2_info *p_ll2_conn, *p_ret = NULL;
236 if (connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS)
239 if (!p_hwfn->p_ll2_info)
242 p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle];
246 mutex_lock(&p_ll2_conn->mutex);
247 if (p_ll2_conn->b_active)
250 mutex_unlock(&p_ll2_conn->mutex);
258 static struct qed_ll2_info *qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn,
259 u8 connection_handle)
261 return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, true);
264 static struct qed_ll2_info *qed_ll2_handle_sanity_lock(struct qed_hwfn *p_hwfn,
265 u8 connection_handle)
267 return __qed_ll2_handle_sanity(p_hwfn, connection_handle, true, true);
270 static struct qed_ll2_info *qed_ll2_handle_sanity_inactive(struct qed_hwfn
272 u8 connection_handle)
274 return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, false);
277 static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
279 bool b_last_packet = false, b_last_frag = false;
280 struct qed_ll2_tx_packet *p_pkt = NULL;
281 struct qed_ll2_info *p_ll2_conn;
282 struct qed_ll2_tx_queue *p_tx;
285 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
289 p_tx = &p_ll2_conn->tx_queue;
291 while (!list_empty(&p_tx->active_descq)) {
292 p_pkt = list_first_entry(&p_tx->active_descq,
293 struct qed_ll2_tx_packet, list_entry);
297 list_del(&p_pkt->list_entry);
298 b_last_packet = list_empty(&p_tx->active_descq);
299 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
300 if (p_ll2_conn->conn.conn_type == QED_LL2_TYPE_ISCSI_OOO) {
301 struct qed_ooo_buffer *p_buffer;
303 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
304 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
307 p_tx->cur_completing_packet = *p_pkt;
308 p_tx->cur_completing_bd_idx = 1;
310 p_tx->cur_completing_bd_idx == p_pkt->bd_used;
311 tx_frag = p_pkt->bds_set[0].tx_frag;
312 if (p_ll2_conn->conn.gsi_enable)
313 qed_ll2b_release_tx_gsi_packet(p_hwfn,
321 qed_ll2b_complete_tx_packet(p_hwfn,
331 static int qed_ll2_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
333 struct qed_ll2_info *p_ll2_conn = p_cookie;
334 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
335 u16 new_idx = 0, num_bds = 0, num_bds_in_packet = 0;
336 struct qed_ll2_tx_packet *p_pkt;
337 bool b_last_frag = false;
342 spin_lock_irqsave(&p_tx->lock, flags);
343 if (p_tx->b_completing_packet) {
348 new_idx = le16_to_cpu(*p_tx->p_fw_cons);
349 num_bds = ((s16)new_idx - (s16)p_tx->bds_idx);
351 if (list_empty(&p_tx->active_descq))
354 p_pkt = list_first_entry(&p_tx->active_descq,
355 struct qed_ll2_tx_packet, list_entry);
359 p_tx->b_completing_packet = true;
360 p_tx->cur_completing_packet = *p_pkt;
361 num_bds_in_packet = p_pkt->bd_used;
362 list_del(&p_pkt->list_entry);
364 if (num_bds < num_bds_in_packet) {
366 "Rest of BDs does not cover whole packet\n");
370 num_bds -= num_bds_in_packet;
371 p_tx->bds_idx += num_bds_in_packet;
372 while (num_bds_in_packet--)
373 qed_chain_consume(&p_tx->txq_chain);
375 p_tx->cur_completing_bd_idx = 1;
376 b_last_frag = p_tx->cur_completing_bd_idx == p_pkt->bd_used;
377 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
379 spin_unlock_irqrestore(&p_tx->lock, flags);
380 tx_frag = p_pkt->bds_set[0].tx_frag;
381 if (p_ll2_conn->conn.gsi_enable)
382 qed_ll2b_complete_tx_gsi_packet(p_hwfn,
386 b_last_frag, !num_bds);
388 qed_ll2b_complete_tx_packet(p_hwfn,
392 b_last_frag, !num_bds);
393 spin_lock_irqsave(&p_tx->lock, flags);
396 p_tx->b_completing_packet = false;
399 spin_unlock_irqrestore(&p_tx->lock, flags);
404 qed_ll2_rxq_completion_gsi(struct qed_hwfn *p_hwfn,
405 struct qed_ll2_info *p_ll2_info,
406 union core_rx_cqe_union *p_cqe,
407 unsigned long lock_flags, bool b_last_cqe)
409 struct qed_ll2_rx_queue *p_rx = &p_ll2_info->rx_queue;
410 struct qed_ll2_rx_packet *p_pkt = NULL;
411 u16 packet_length, parse_flags, vlan;
415 if (!list_empty(&p_rx->active_descq))
416 p_pkt = list_first_entry(&p_rx->active_descq,
417 struct qed_ll2_rx_packet, list_entry);
420 "GSI Rx completion but active_descq is empty\n");
424 list_del(&p_pkt->list_entry);
425 parse_flags = le16_to_cpu(p_cqe->rx_cqe_gsi.parse_flags.flags);
426 packet_length = le16_to_cpu(p_cqe->rx_cqe_gsi.data_length);
427 vlan = le16_to_cpu(p_cqe->rx_cqe_gsi.vlan);
428 src_mac_addrhi = le32_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrhi);
429 src_mac_addrlo = le16_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrlo);
430 if (qed_chain_consume(&p_rx->rxq_chain) != p_pkt->rxq_bd)
432 "Mismatch between active_descq and the LL2 Rx chain\n");
433 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);
435 spin_unlock_irqrestore(&p_rx->lock, lock_flags);
436 qed_ll2b_complete_rx_gsi_packet(p_hwfn,
441 p_cqe->rx_cqe_gsi.data_length_error,
445 src_mac_addrlo, b_last_cqe);
446 spin_lock_irqsave(&p_rx->lock, lock_flags);
451 static int qed_ll2_rxq_completion_reg(struct qed_hwfn *p_hwfn,
452 struct qed_ll2_info *p_ll2_conn,
453 union core_rx_cqe_union *p_cqe,
454 unsigned long lock_flags,
457 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
458 struct qed_ll2_rx_packet *p_pkt = NULL;
460 if (!list_empty(&p_rx->active_descq))
461 p_pkt = list_first_entry(&p_rx->active_descq,
462 struct qed_ll2_rx_packet, list_entry);
465 "LL2 Rx completion but active_descq is empty\n");
468 list_del(&p_pkt->list_entry);
470 if (qed_chain_consume(&p_rx->rxq_chain) != p_pkt->rxq_bd)
472 "Mismatch between active_descq and the LL2 Rx chain\n");
473 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);
475 spin_unlock_irqrestore(&p_rx->lock, lock_flags);
476 qed_ll2b_complete_rx_packet(p_hwfn, p_ll2_conn->my_id,
477 p_pkt, &p_cqe->rx_cqe_fp, b_last_cqe);
478 spin_lock_irqsave(&p_rx->lock, lock_flags);
483 static int qed_ll2_rxq_completion(struct qed_hwfn *p_hwfn, void *cookie)
485 struct qed_ll2_info *p_ll2_conn = cookie;
486 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
487 union core_rx_cqe_union *cqe = NULL;
488 u16 cq_new_idx = 0, cq_old_idx = 0;
489 unsigned long flags = 0;
492 spin_lock_irqsave(&p_rx->lock, flags);
493 cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons);
494 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
496 while (cq_new_idx != cq_old_idx) {
497 bool b_last_cqe = (cq_new_idx == cq_old_idx);
499 cqe = qed_chain_consume(&p_rx->rcq_chain);
500 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
504 "LL2 [sw. cons %04x, fw. at %04x] - Got Packet of type %02x\n",
505 cq_old_idx, cq_new_idx, cqe->rx_cqe_sp.type);
507 switch (cqe->rx_cqe_sp.type) {
508 case CORE_RX_CQE_TYPE_SLOW_PATH:
509 DP_NOTICE(p_hwfn, "LL2 - unexpected Rx CQE slowpath\n");
512 case CORE_RX_CQE_TYPE_GSI_OFFLOAD:
513 rc = qed_ll2_rxq_completion_gsi(p_hwfn, p_ll2_conn,
514 cqe, flags, b_last_cqe);
516 case CORE_RX_CQE_TYPE_REGULAR:
517 rc = qed_ll2_rxq_completion_reg(p_hwfn, p_ll2_conn,
518 cqe, flags, b_last_cqe);
525 spin_unlock_irqrestore(&p_rx->lock, flags);
529 static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
531 struct qed_ll2_info *p_ll2_conn = NULL;
532 struct qed_ll2_rx_packet *p_pkt = NULL;
533 struct qed_ll2_rx_queue *p_rx;
535 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
539 p_rx = &p_ll2_conn->rx_queue;
541 while (!list_empty(&p_rx->active_descq)) {
542 dma_addr_t rx_buf_addr;
546 p_pkt = list_first_entry(&p_rx->active_descq,
547 struct qed_ll2_rx_packet, list_entry);
551 list_move_tail(&p_pkt->list_entry, &p_rx->free_descq);
553 if (p_ll2_conn->conn.conn_type == QED_LL2_TYPE_ISCSI_OOO) {
554 struct qed_ooo_buffer *p_buffer;
556 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
557 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
560 rx_buf_addr = p_pkt->rx_buf_addr;
561 cookie = p_pkt->cookie;
563 b_last = list_empty(&p_rx->active_descq);
568 #if IS_ENABLED(CONFIG_QED_ISCSI)
569 static u8 qed_ll2_convert_rx_parse_to_tx_flags(u16 parse_flags)
573 if (GET_FIELD(parse_flags, PARSING_AND_ERR_FLAGS_TAG8021QEXIST))
574 SET_FIELD(bd_flags, CORE_TX_BD_FLAGS_VLAN_INSERTION, 1);
579 static int qed_ll2_lb_rxq_handler(struct qed_hwfn *p_hwfn,
580 struct qed_ll2_info *p_ll2_conn)
582 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
583 u16 packet_length = 0, parse_flags = 0, vlan = 0;
584 struct qed_ll2_rx_packet *p_pkt = NULL;
585 u32 num_ooo_add_to_peninsula = 0, cid;
586 union core_rx_cqe_union *cqe = NULL;
587 u16 cq_new_idx = 0, cq_old_idx = 0;
588 struct qed_ooo_buffer *p_buffer;
589 struct ooo_opaque *iscsi_ooo;
590 u8 placement_offset = 0;
593 cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons);
594 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
595 if (cq_new_idx == cq_old_idx)
598 while (cq_new_idx != cq_old_idx) {
599 struct core_rx_fast_path_cqe *p_cqe_fp;
601 cqe = qed_chain_consume(&p_rx->rcq_chain);
602 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
603 cqe_type = cqe->rx_cqe_sp.type;
605 if (cqe_type != CORE_RX_CQE_TYPE_REGULAR) {
607 "Got a non-regular LB LL2 completion [type 0x%02x]\n",
611 p_cqe_fp = &cqe->rx_cqe_fp;
613 placement_offset = p_cqe_fp->placement_offset;
614 parse_flags = le16_to_cpu(p_cqe_fp->parse_flags.flags);
615 packet_length = le16_to_cpu(p_cqe_fp->packet_length);
616 vlan = le16_to_cpu(p_cqe_fp->vlan);
617 iscsi_ooo = (struct ooo_opaque *)&p_cqe_fp->opaque_data;
618 qed_ooo_save_history_entry(p_hwfn, p_hwfn->p_ooo_info,
620 cid = le32_to_cpu(iscsi_ooo->cid);
622 /* Process delete isle first */
623 if (iscsi_ooo->drop_size)
624 qed_ooo_delete_isles(p_hwfn, p_hwfn->p_ooo_info, cid,
625 iscsi_ooo->drop_isle,
626 iscsi_ooo->drop_size);
628 if (iscsi_ooo->ooo_opcode == TCP_EVENT_NOP)
631 /* Now process create/add/join isles */
632 if (list_empty(&p_rx->active_descq)) {
634 "LL2 OOO RX chain has no submitted buffers\n"
639 p_pkt = list_first_entry(&p_rx->active_descq,
640 struct qed_ll2_rx_packet, list_entry);
642 if ((iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_NEW_ISLE) ||
643 (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_RIGHT) ||
644 (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_LEFT) ||
645 (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_PEN) ||
646 (iscsi_ooo->ooo_opcode == TCP_EVENT_JOIN)) {
649 "LL2 OOO RX packet is not valid\n");
652 list_del(&p_pkt->list_entry);
653 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
654 p_buffer->packet_length = packet_length;
655 p_buffer->parse_flags = parse_flags;
656 p_buffer->vlan = vlan;
657 p_buffer->placement_offset = placement_offset;
658 qed_chain_consume(&p_rx->rxq_chain);
659 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);
661 switch (iscsi_ooo->ooo_opcode) {
662 case TCP_EVENT_ADD_NEW_ISLE:
663 qed_ooo_add_new_isle(p_hwfn,
669 case TCP_EVENT_ADD_ISLE_RIGHT:
670 qed_ooo_add_new_buffer(p_hwfn,
677 case TCP_EVENT_ADD_ISLE_LEFT:
678 qed_ooo_add_new_buffer(p_hwfn,
686 qed_ooo_add_new_buffer(p_hwfn,
689 iscsi_ooo->ooo_isle +
693 qed_ooo_join_isles(p_hwfn,
695 cid, iscsi_ooo->ooo_isle);
697 case TCP_EVENT_ADD_PEN:
698 num_ooo_add_to_peninsula++;
699 qed_ooo_put_ready_buffer(p_hwfn,
706 "Unexpected event (%d) TX OOO completion\n",
707 iscsi_ooo->ooo_opcode);
715 qed_ooo_submit_tx_buffers(struct qed_hwfn *p_hwfn,
716 struct qed_ll2_info *p_ll2_conn)
718 struct qed_ooo_buffer *p_buffer;
721 dma_addr_t first_frag;
725 /* Submit Tx buffers here */
726 while ((p_buffer = qed_ooo_get_ready_buffer(p_hwfn,
727 p_hwfn->p_ooo_info))) {
731 first_frag = p_buffer->rx_buffer_phys_addr +
732 p_buffer->placement_offset;
733 parse_flags = p_buffer->parse_flags;
734 bd_flags = qed_ll2_convert_rx_parse_to_tx_flags(parse_flags);
735 SET_FIELD(bd_flags, CORE_TX_BD_FLAGS_FORCE_VLAN_MODE, 1);
736 SET_FIELD(bd_flags, CORE_TX_BD_FLAGS_L4_PROTOCOL, 1);
738 rc = qed_ll2_prepare_tx_packet(p_hwfn, p_ll2_conn->my_id, 1,
739 p_buffer->vlan, bd_flags,
741 p_ll2_conn->conn.tx_dest, 0,
743 p_buffer->packet_length,
746 qed_ooo_put_ready_buffer(p_hwfn, p_hwfn->p_ooo_info,
754 qed_ooo_submit_rx_buffers(struct qed_hwfn *p_hwfn,
755 struct qed_ll2_info *p_ll2_conn)
757 struct qed_ooo_buffer *p_buffer;
760 while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn,
761 p_hwfn->p_ooo_info))) {
762 rc = qed_ll2_post_rx_buffer(p_hwfn,
764 p_buffer->rx_buffer_phys_addr,
767 qed_ooo_put_free_buffer(p_hwfn,
768 p_hwfn->p_ooo_info, p_buffer);
774 static int qed_ll2_lb_rxq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
776 struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie;
779 rc = qed_ll2_lb_rxq_handler(p_hwfn, p_ll2_conn);
783 qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn);
784 qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn);
789 static int qed_ll2_lb_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
791 struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie;
792 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
793 struct qed_ll2_tx_packet *p_pkt = NULL;
794 struct qed_ooo_buffer *p_buffer;
795 bool b_dont_submit_rx = false;
796 u16 new_idx = 0, num_bds = 0;
799 new_idx = le16_to_cpu(*p_tx->p_fw_cons);
800 num_bds = ((s16)new_idx - (s16)p_tx->bds_idx);
806 if (list_empty(&p_tx->active_descq))
809 p_pkt = list_first_entry(&p_tx->active_descq,
810 struct qed_ll2_tx_packet, list_entry);
814 if (p_pkt->bd_used != 1) {
816 "Unexpectedly many BDs(%d) in TX OOO completion\n",
821 list_del(&p_pkt->list_entry);
825 qed_chain_consume(&p_tx->txq_chain);
827 p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
828 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
830 if (b_dont_submit_rx) {
831 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
836 rc = qed_ll2_post_rx_buffer(p_hwfn, p_ll2_conn->my_id,
837 p_buffer->rx_buffer_phys_addr, 0,
840 qed_ooo_put_free_buffer(p_hwfn,
841 p_hwfn->p_ooo_info, p_buffer);
842 b_dont_submit_rx = true;
846 qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn);
852 qed_ll2_acquire_connection_ooo(struct qed_hwfn *p_hwfn,
853 struct qed_ll2_info *p_ll2_info,
854 u16 rx_num_ooo_buffers, u16 mtu)
856 struct qed_ooo_buffer *p_buf = NULL;
861 if (p_ll2_info->conn.conn_type != QED_LL2_TYPE_ISCSI_OOO)
864 if (!rx_num_ooo_buffers)
867 for (buf_idx = 0; buf_idx < rx_num_ooo_buffers; buf_idx++) {
868 p_buf = kzalloc(sizeof(*p_buf), GFP_KERNEL);
874 p_buf->rx_buffer_size = mtu + 26 + ETH_CACHE_LINE_SIZE;
875 p_buf->rx_buffer_size = (p_buf->rx_buffer_size +
876 ETH_CACHE_LINE_SIZE - 1) &
877 ~(ETH_CACHE_LINE_SIZE - 1);
878 p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
879 p_buf->rx_buffer_size,
880 &p_buf->rx_buffer_phys_addr,
888 p_buf->rx_buffer_virt_addr = p_virt;
889 qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info, p_buf);
892 DP_VERBOSE(p_hwfn, QED_MSG_LL2,
893 "Allocated [%04x] LL2 OOO buffers [each of size 0x%08x]\n",
894 rx_num_ooo_buffers, p_buf->rx_buffer_size);
901 qed_ll2_establish_connection_ooo(struct qed_hwfn *p_hwfn,
902 struct qed_ll2_info *p_ll2_conn)
904 if (p_ll2_conn->conn.conn_type != QED_LL2_TYPE_ISCSI_OOO)
907 qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
908 qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn);
911 static void qed_ll2_release_connection_ooo(struct qed_hwfn *p_hwfn,
912 struct qed_ll2_info *p_ll2_conn)
914 struct qed_ooo_buffer *p_buffer;
916 if (p_ll2_conn->conn.conn_type != QED_LL2_TYPE_ISCSI_OOO)
919 qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
920 while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn,
921 p_hwfn->p_ooo_info))) {
922 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
923 p_buffer->rx_buffer_size,
924 p_buffer->rx_buffer_virt_addr,
925 p_buffer->rx_buffer_phys_addr);
930 static void qed_ll2_stop_ooo(struct qed_dev *cdev)
932 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
933 u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id;
935 DP_VERBOSE(cdev, QED_MSG_STORAGE, "Stopping LL2 OOO queue [%02x]\n",
938 qed_ll2_terminate_connection(hwfn, *handle);
939 qed_ll2_release_connection(hwfn, *handle);
940 *handle = QED_LL2_UNUSED_HANDLE;
943 static int qed_ll2_start_ooo(struct qed_dev *cdev,
944 struct qed_ll2_params *params)
946 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
947 u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id;
948 struct qed_ll2_conn ll2_info;
951 ll2_info.conn_type = QED_LL2_TYPE_ISCSI_OOO;
952 ll2_info.mtu = params->mtu;
953 ll2_info.rx_drop_ttl0_flg = params->drop_ttl0_packets;
954 ll2_info.rx_vlan_removal_en = params->rx_vlan_stripping;
955 ll2_info.tx_tc = OOO_LB_TC;
956 ll2_info.tx_dest = CORE_TX_DEST_LB;
958 rc = qed_ll2_acquire_connection(hwfn, &ll2_info,
959 QED_LL2_RX_SIZE, QED_LL2_TX_SIZE,
962 DP_INFO(cdev, "Failed to acquire LL2 OOO connection\n");
966 rc = qed_ll2_establish_connection(hwfn, *handle);
968 DP_INFO(cdev, "Failed to establist LL2 OOO connection\n");
975 qed_ll2_release_connection(hwfn, *handle);
977 *handle = QED_LL2_UNUSED_HANDLE;
980 #else /* IS_ENABLED(CONFIG_QED_ISCSI) */
981 static int qed_ll2_lb_rxq_completion(struct qed_hwfn *p_hwfn,
982 void *p_cookie) { return -EINVAL; }
983 static int qed_ll2_lb_txq_completion(struct qed_hwfn *p_hwfn,
984 void *p_cookie) { return -EINVAL; }
986 qed_ll2_acquire_connection_ooo(struct qed_hwfn *p_hwfn,
987 struct qed_ll2_info *p_ll2_info,
988 u16 rx_num_ooo_buffers, u16 mtu) { return 0; }
990 qed_ll2_establish_connection_ooo(struct qed_hwfn *p_hwfn,
991 struct qed_ll2_info *p_ll2_conn) { return; }
993 qed_ll2_release_connection_ooo(struct qed_hwfn *p_hwfn,
994 struct qed_ll2_info *p_ll2_conn) { return; }
995 static inline void qed_ll2_stop_ooo(struct qed_dev *cdev) { return; }
996 static inline int qed_ll2_start_ooo(struct qed_dev *cdev,
997 struct qed_ll2_params *params)
999 #endif /* IS_ENABLED(CONFIG_QED_ISCSI) */
1001 static int qed_sp_ll2_rx_queue_start(struct qed_hwfn *p_hwfn,
1002 struct qed_ll2_info *p_ll2_conn,
1005 enum qed_ll2_conn_type conn_type = p_ll2_conn->conn.conn_type;
1006 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
1007 struct core_rx_start_ramrod_data *p_ramrod = NULL;
1008 struct qed_spq_entry *p_ent = NULL;
1009 struct qed_sp_init_data init_data;
1014 memset(&init_data, 0, sizeof(init_data));
1015 init_data.cid = p_ll2_conn->cid;
1016 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1017 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1019 rc = qed_sp_init_request(p_hwfn, &p_ent,
1020 CORE_RAMROD_RX_QUEUE_START,
1021 PROTOCOLID_CORE, &init_data);
1025 p_ramrod = &p_ent->ramrod.core_rx_queue_start;
1027 p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn));
1028 p_ramrod->sb_index = p_rx->rx_sb_index;
1029 p_ramrod->complete_event_flg = 1;
1031 p_ramrod->mtu = cpu_to_le16(p_ll2_conn->conn.mtu);
1032 DMA_REGPAIR_LE(p_ramrod->bd_base,
1033 p_rx->rxq_chain.p_phys_addr);
1034 cqe_pbl_size = (u16)qed_chain_get_page_cnt(&p_rx->rcq_chain);
1035 p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
1036 DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr,
1037 qed_chain_get_pbl_phys(&p_rx->rcq_chain));
1039 p_ramrod->drop_ttl0_flg = p_ll2_conn->conn.rx_drop_ttl0_flg;
1040 p_ramrod->inner_vlan_removal_en = p_ll2_conn->conn.rx_vlan_removal_en;
1041 p_ramrod->queue_id = p_ll2_conn->queue_id;
1042 p_ramrod->main_func_queue = (conn_type == QED_LL2_TYPE_ISCSI_OOO) ? 0
1045 if ((IS_MF_DEFAULT(p_hwfn) || IS_MF_SI(p_hwfn)) &&
1046 p_ramrod->main_func_queue && (conn_type != QED_LL2_TYPE_ROCE)) {
1047 p_ramrod->mf_si_bcast_accept_all = 1;
1048 p_ramrod->mf_si_mcast_accept_all = 1;
1050 p_ramrod->mf_si_bcast_accept_all = 0;
1051 p_ramrod->mf_si_mcast_accept_all = 0;
1054 p_ramrod->action_on_error.error_type = action_on_error;
1055 p_ramrod->gsi_offload_flag = p_ll2_conn->conn.gsi_enable;
1056 return qed_spq_post(p_hwfn, p_ent, NULL);
1059 static int qed_sp_ll2_tx_queue_start(struct qed_hwfn *p_hwfn,
1060 struct qed_ll2_info *p_ll2_conn)
1062 enum qed_ll2_conn_type conn_type = p_ll2_conn->conn.conn_type;
1063 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
1064 struct core_tx_start_ramrod_data *p_ramrod = NULL;
1065 struct qed_spq_entry *p_ent = NULL;
1066 struct qed_sp_init_data init_data;
1067 union qed_qm_pq_params pq_params;
1068 u16 pq_id = 0, pbl_size;
1071 if (!QED_LL2_TX_REGISTERED(p_ll2_conn))
1074 if (p_ll2_conn->conn.conn_type == QED_LL2_TYPE_ISCSI_OOO)
1075 p_ll2_conn->tx_stats_en = 0;
1077 p_ll2_conn->tx_stats_en = 1;
1080 memset(&init_data, 0, sizeof(init_data));
1081 init_data.cid = p_ll2_conn->cid;
1082 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1083 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1085 rc = qed_sp_init_request(p_hwfn, &p_ent,
1086 CORE_RAMROD_TX_QUEUE_START,
1087 PROTOCOLID_CORE, &init_data);
1091 p_ramrod = &p_ent->ramrod.core_tx_queue_start;
1093 p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn));
1094 p_ramrod->sb_index = p_tx->tx_sb_index;
1095 p_ramrod->mtu = cpu_to_le16(p_ll2_conn->conn.mtu);
1096 p_ramrod->stats_en = p_ll2_conn->tx_stats_en;
1097 p_ramrod->stats_id = p_ll2_conn->tx_stats_id;
1099 DMA_REGPAIR_LE(p_ramrod->pbl_base_addr,
1100 qed_chain_get_pbl_phys(&p_tx->txq_chain));
1101 pbl_size = qed_chain_get_page_cnt(&p_tx->txq_chain);
1102 p_ramrod->pbl_size = cpu_to_le16(pbl_size);
1104 memset(&pq_params, 0, sizeof(pq_params));
1105 pq_params.core.tc = p_ll2_conn->conn.tx_tc;
1106 pq_id = qed_get_qm_pq(p_hwfn, PROTOCOLID_CORE, &pq_params);
1107 p_ramrod->qm_pq_id = cpu_to_le16(pq_id);
1109 switch (conn_type) {
1110 case QED_LL2_TYPE_ISCSI:
1111 case QED_LL2_TYPE_ISCSI_OOO:
1112 p_ramrod->conn_type = PROTOCOLID_ISCSI;
1114 case QED_LL2_TYPE_ROCE:
1115 p_ramrod->conn_type = PROTOCOLID_ROCE;
1118 p_ramrod->conn_type = PROTOCOLID_ETH;
1119 DP_NOTICE(p_hwfn, "Unknown connection type: %d\n", conn_type);
1122 p_ramrod->gsi_offload_flag = p_ll2_conn->conn.gsi_enable;
1123 return qed_spq_post(p_hwfn, p_ent, NULL);
1126 static int qed_sp_ll2_rx_queue_stop(struct qed_hwfn *p_hwfn,
1127 struct qed_ll2_info *p_ll2_conn)
1129 struct core_rx_stop_ramrod_data *p_ramrod = NULL;
1130 struct qed_spq_entry *p_ent = NULL;
1131 struct qed_sp_init_data init_data;
1135 memset(&init_data, 0, sizeof(init_data));
1136 init_data.cid = p_ll2_conn->cid;
1137 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1138 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1140 rc = qed_sp_init_request(p_hwfn, &p_ent,
1141 CORE_RAMROD_RX_QUEUE_STOP,
1142 PROTOCOLID_CORE, &init_data);
1146 p_ramrod = &p_ent->ramrod.core_rx_queue_stop;
1148 p_ramrod->complete_event_flg = 1;
1149 p_ramrod->queue_id = p_ll2_conn->queue_id;
1151 return qed_spq_post(p_hwfn, p_ent, NULL);
1154 static int qed_sp_ll2_tx_queue_stop(struct qed_hwfn *p_hwfn,
1155 struct qed_ll2_info *p_ll2_conn)
1157 struct qed_spq_entry *p_ent = NULL;
1158 struct qed_sp_init_data init_data;
1162 memset(&init_data, 0, sizeof(init_data));
1163 init_data.cid = p_ll2_conn->cid;
1164 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1165 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1167 rc = qed_sp_init_request(p_hwfn, &p_ent,
1168 CORE_RAMROD_TX_QUEUE_STOP,
1169 PROTOCOLID_CORE, &init_data);
1173 return qed_spq_post(p_hwfn, p_ent, NULL);
1177 qed_ll2_acquire_connection_rx(struct qed_hwfn *p_hwfn,
1178 struct qed_ll2_info *p_ll2_info, u16 rx_num_desc)
1180 struct qed_ll2_rx_packet *p_descq;
1187 rc = qed_chain_alloc(p_hwfn->cdev,
1188 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1189 QED_CHAIN_MODE_NEXT_PTR,
1190 QED_CHAIN_CNT_TYPE_U16,
1192 sizeof(struct core_rx_bd),
1193 &p_ll2_info->rx_queue.rxq_chain);
1195 DP_NOTICE(p_hwfn, "Failed to allocate ll2 rxq chain\n");
1199 capacity = qed_chain_get_capacity(&p_ll2_info->rx_queue.rxq_chain);
1200 p_descq = kcalloc(capacity, sizeof(struct qed_ll2_rx_packet),
1204 DP_NOTICE(p_hwfn, "Failed to allocate ll2 Rx desc\n");
1207 p_ll2_info->rx_queue.descq_array = p_descq;
1209 rc = qed_chain_alloc(p_hwfn->cdev,
1210 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1212 QED_CHAIN_CNT_TYPE_U16,
1214 sizeof(struct core_rx_fast_path_cqe),
1215 &p_ll2_info->rx_queue.rcq_chain);
1217 DP_NOTICE(p_hwfn, "Failed to allocate ll2 rcq chain\n");
1221 DP_VERBOSE(p_hwfn, QED_MSG_LL2,
1222 "Allocated LL2 Rxq [Type %08x] with 0x%08x buffers\n",
1223 p_ll2_info->conn.conn_type, rx_num_desc);
1229 static int qed_ll2_acquire_connection_tx(struct qed_hwfn *p_hwfn,
1230 struct qed_ll2_info *p_ll2_info,
1233 struct qed_ll2_tx_packet *p_descq;
1240 rc = qed_chain_alloc(p_hwfn->cdev,
1241 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1243 QED_CHAIN_CNT_TYPE_U16,
1245 sizeof(struct core_tx_bd),
1246 &p_ll2_info->tx_queue.txq_chain);
1250 capacity = qed_chain_get_capacity(&p_ll2_info->tx_queue.txq_chain);
1251 p_descq = kcalloc(capacity, sizeof(struct qed_ll2_tx_packet),
1257 p_ll2_info->tx_queue.descq_array = p_descq;
1259 DP_VERBOSE(p_hwfn, QED_MSG_LL2,
1260 "Allocated LL2 Txq [Type %08x] with 0x%08x buffers\n",
1261 p_ll2_info->conn.conn_type, tx_num_desc);
1266 "Can't allocate memory for Tx LL2 with 0x%08x buffers\n",
1271 int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
1272 struct qed_ll2_conn *p_params,
1275 u8 *p_connection_handle)
1277 qed_int_comp_cb_t comp_rx_cb, comp_tx_cb;
1278 struct qed_ll2_info *p_ll2_info = NULL;
1282 if (!p_connection_handle || !p_hwfn->p_ll2_info)
1285 /* Find a free connection to be used */
1286 for (i = 0; (i < QED_MAX_NUM_OF_LL2_CONNECTIONS); i++) {
1287 mutex_lock(&p_hwfn->p_ll2_info[i].mutex);
1288 if (p_hwfn->p_ll2_info[i].b_active) {
1289 mutex_unlock(&p_hwfn->p_ll2_info[i].mutex);
1293 p_hwfn->p_ll2_info[i].b_active = true;
1294 p_ll2_info = &p_hwfn->p_ll2_info[i];
1295 mutex_unlock(&p_hwfn->p_ll2_info[i].mutex);
1301 p_ll2_info->conn = *p_params;
1303 rc = qed_ll2_acquire_connection_rx(p_hwfn, p_ll2_info, rx_num_desc);
1305 goto q_allocate_fail;
1307 rc = qed_ll2_acquire_connection_tx(p_hwfn, p_ll2_info, tx_num_desc);
1309 goto q_allocate_fail;
1311 rc = qed_ll2_acquire_connection_ooo(p_hwfn, p_ll2_info,
1312 rx_num_desc * 2, p_params->mtu);
1314 goto q_allocate_fail;
1316 /* Register callbacks for the Rx/Tx queues */
1317 if (p_params->conn_type == QED_LL2_TYPE_ISCSI_OOO) {
1318 comp_rx_cb = qed_ll2_lb_rxq_completion;
1319 comp_tx_cb = qed_ll2_lb_txq_completion;
1321 comp_rx_cb = qed_ll2_rxq_completion;
1322 comp_tx_cb = qed_ll2_txq_completion;
1326 qed_int_register_cb(p_hwfn, comp_rx_cb,
1327 &p_hwfn->p_ll2_info[i],
1328 &p_ll2_info->rx_queue.rx_sb_index,
1329 &p_ll2_info->rx_queue.p_fw_cons);
1330 p_ll2_info->rx_queue.b_cb_registred = true;
1334 qed_int_register_cb(p_hwfn,
1336 &p_hwfn->p_ll2_info[i],
1337 &p_ll2_info->tx_queue.tx_sb_index,
1338 &p_ll2_info->tx_queue.p_fw_cons);
1339 p_ll2_info->tx_queue.b_cb_registred = true;
1342 *p_connection_handle = i;
1346 qed_ll2_release_connection(p_hwfn, i);
1350 static int qed_ll2_establish_connection_rx(struct qed_hwfn *p_hwfn,
1351 struct qed_ll2_info *p_ll2_conn)
1353 u8 action_on_error = 0;
1355 if (!QED_LL2_RX_REGISTERED(p_ll2_conn))
1358 DIRECT_REG_WR(p_ll2_conn->rx_queue.set_prod_addr, 0x0);
1360 SET_FIELD(action_on_error,
1361 CORE_RX_ACTION_ON_ERROR_PACKET_TOO_BIG,
1362 p_ll2_conn->conn.ai_err_packet_too_big);
1363 SET_FIELD(action_on_error,
1364 CORE_RX_ACTION_ON_ERROR_NO_BUFF, p_ll2_conn->conn.ai_err_no_buf);
1366 return qed_sp_ll2_rx_queue_start(p_hwfn, p_ll2_conn, action_on_error);
1369 int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle)
1371 struct qed_ll2_info *p_ll2_conn;
1372 struct qed_ll2_rx_queue *p_rx;
1373 struct qed_ll2_tx_queue *p_tx;
1378 p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle);
1381 p_rx = &p_ll2_conn->rx_queue;
1382 p_tx = &p_ll2_conn->tx_queue;
1384 qed_chain_reset(&p_rx->rxq_chain);
1385 qed_chain_reset(&p_rx->rcq_chain);
1386 INIT_LIST_HEAD(&p_rx->active_descq);
1387 INIT_LIST_HEAD(&p_rx->free_descq);
1388 INIT_LIST_HEAD(&p_rx->posting_descq);
1389 spin_lock_init(&p_rx->lock);
1390 capacity = qed_chain_get_capacity(&p_rx->rxq_chain);
1391 for (i = 0; i < capacity; i++)
1392 list_add_tail(&p_rx->descq_array[i].list_entry,
1394 *p_rx->p_fw_cons = 0;
1396 qed_chain_reset(&p_tx->txq_chain);
1397 INIT_LIST_HEAD(&p_tx->active_descq);
1398 INIT_LIST_HEAD(&p_tx->free_descq);
1399 INIT_LIST_HEAD(&p_tx->sending_descq);
1400 spin_lock_init(&p_tx->lock);
1401 capacity = qed_chain_get_capacity(&p_tx->txq_chain);
1402 for (i = 0; i < capacity; i++)
1403 list_add_tail(&p_tx->descq_array[i].list_entry,
1405 p_tx->cur_completing_bd_idx = 0;
1407 p_tx->b_completing_packet = false;
1408 p_tx->cur_send_packet = NULL;
1409 p_tx->cur_send_frag_num = 0;
1410 p_tx->cur_completing_frag_num = 0;
1411 *p_tx->p_fw_cons = 0;
1413 qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_CORE, &p_ll2_conn->cid);
1415 qid = p_hwfn->hw_info.resc_start[QED_LL2_QUEUE] + connection_handle;
1416 p_ll2_conn->queue_id = qid;
1417 p_ll2_conn->tx_stats_id = qid;
1418 p_rx->set_prod_addr = (u8 __iomem *)p_hwfn->regview +
1419 GTT_BAR0_MAP_REG_TSDM_RAM +
1420 TSTORM_LL2_RX_PRODS_OFFSET(qid);
1421 p_tx->doorbell_addr = (u8 __iomem *)p_hwfn->doorbells +
1422 qed_db_addr(p_ll2_conn->cid,
1425 rc = qed_ll2_establish_connection_rx(p_hwfn, p_ll2_conn);
1429 rc = qed_sp_ll2_tx_queue_start(p_hwfn, p_ll2_conn);
1433 if (p_hwfn->hw_info.personality != QED_PCI_ETH_ROCE)
1434 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PRS_REG_USE_LIGHT_L2, 1);
1436 qed_ll2_establish_connection_ooo(p_hwfn, p_ll2_conn);
1441 static void qed_ll2_post_rx_buffer_notify_fw(struct qed_hwfn *p_hwfn,
1442 struct qed_ll2_rx_queue *p_rx,
1443 struct qed_ll2_rx_packet *p_curp)
1445 struct qed_ll2_rx_packet *p_posting_packet = NULL;
1446 struct core_ll2_rx_prod rx_prod = { 0, 0, 0 };
1447 bool b_notify_fw = false;
1448 u16 bd_prod, cq_prod;
1450 /* This handles the flushing of already posted buffers */
1451 while (!list_empty(&p_rx->posting_descq)) {
1452 p_posting_packet = list_first_entry(&p_rx->posting_descq,
1453 struct qed_ll2_rx_packet,
1455 list_move_tail(&p_posting_packet->list_entry,
1456 &p_rx->active_descq);
1460 /* This handles the supplied packet [if there is one] */
1462 list_add_tail(&p_curp->list_entry, &p_rx->active_descq);
1469 bd_prod = qed_chain_get_prod_idx(&p_rx->rxq_chain);
1470 cq_prod = qed_chain_get_prod_idx(&p_rx->rcq_chain);
1471 rx_prod.bd_prod = cpu_to_le16(bd_prod);
1472 rx_prod.cqe_prod = cpu_to_le16(cq_prod);
1473 DIRECT_REG_WR(p_rx->set_prod_addr, *((u32 *)&rx_prod));
1476 int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
1477 u8 connection_handle,
1479 u16 buf_len, void *cookie, u8 notify_fw)
1481 struct core_rx_bd_with_buff_len *p_curb = NULL;
1482 struct qed_ll2_rx_packet *p_curp = NULL;
1483 struct qed_ll2_info *p_ll2_conn;
1484 struct qed_ll2_rx_queue *p_rx;
1485 unsigned long flags;
1489 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
1492 p_rx = &p_ll2_conn->rx_queue;
1494 spin_lock_irqsave(&p_rx->lock, flags);
1495 if (!list_empty(&p_rx->free_descq))
1496 p_curp = list_first_entry(&p_rx->free_descq,
1497 struct qed_ll2_rx_packet, list_entry);
1499 if (qed_chain_get_elem_left(&p_rx->rxq_chain) &&
1500 qed_chain_get_elem_left(&p_rx->rcq_chain)) {
1501 p_data = qed_chain_produce(&p_rx->rxq_chain);
1502 p_curb = (struct core_rx_bd_with_buff_len *)p_data;
1503 qed_chain_produce(&p_rx->rcq_chain);
1507 /* If we're lacking entires, let's try to flush buffers to FW */
1508 if (!p_curp || !p_curb) {
1514 /* We have an Rx packet we can fill */
1515 DMA_REGPAIR_LE(p_curb->addr, addr);
1516 p_curb->buff_length = cpu_to_le16(buf_len);
1517 p_curp->rx_buf_addr = addr;
1518 p_curp->cookie = cookie;
1519 p_curp->rxq_bd = p_curb;
1520 p_curp->buf_length = buf_len;
1521 list_del(&p_curp->list_entry);
1523 /* Check if we only want to enqueue this packet without informing FW */
1525 list_add_tail(&p_curp->list_entry, &p_rx->posting_descq);
1530 qed_ll2_post_rx_buffer_notify_fw(p_hwfn, p_rx, p_curp);
1532 spin_unlock_irqrestore(&p_rx->lock, flags);
1536 static void qed_ll2_prepare_tx_packet_set(struct qed_hwfn *p_hwfn,
1537 struct qed_ll2_tx_queue *p_tx,
1538 struct qed_ll2_tx_packet *p_curp,
1540 dma_addr_t first_frag,
1541 u16 first_frag_len, void *p_cookie,
1544 list_del(&p_curp->list_entry);
1545 p_curp->cookie = p_cookie;
1546 p_curp->bd_used = num_of_bds;
1547 p_curp->notify_fw = notify_fw;
1548 p_tx->cur_send_packet = p_curp;
1549 p_tx->cur_send_frag_num = 0;
1551 p_curp->bds_set[p_tx->cur_send_frag_num].tx_frag = first_frag;
1552 p_curp->bds_set[p_tx->cur_send_frag_num].frag_len = first_frag_len;
1553 p_tx->cur_send_frag_num++;
1556 static void qed_ll2_prepare_tx_packet_set_bd(struct qed_hwfn *p_hwfn,
1557 struct qed_ll2_info *p_ll2,
1558 struct qed_ll2_tx_packet *p_curp,
1560 enum core_tx_dest tx_dest,
1563 u16 l4_hdr_offset_w,
1564 enum core_roce_flavor_type type,
1565 dma_addr_t first_frag,
1568 struct qed_chain *p_tx_chain = &p_ll2->tx_queue.txq_chain;
1569 u16 prod_idx = qed_chain_get_prod_idx(p_tx_chain);
1570 struct core_tx_bd *start_bd = NULL;
1573 start_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain);
1574 start_bd->nw_vlan_or_lb_echo = cpu_to_le16(vlan);
1575 SET_FIELD(start_bd->bitfield1, CORE_TX_BD_L4_HDR_OFFSET_W,
1576 cpu_to_le16(l4_hdr_offset_w));
1577 SET_FIELD(start_bd->bitfield1, CORE_TX_BD_TX_DST, tx_dest);
1578 start_bd->bd_flags.as_bitfield = bd_flags;
1579 start_bd->bd_flags.as_bitfield |= CORE_TX_BD_FLAGS_START_BD_MASK <<
1580 CORE_TX_BD_FLAGS_START_BD_SHIFT;
1581 SET_FIELD(start_bd->bitfield0, CORE_TX_BD_NBDS, num_of_bds);
1582 SET_FIELD(start_bd->bitfield0, CORE_TX_BD_ROCE_FLAV, type);
1583 DMA_REGPAIR_LE(start_bd->addr, first_frag);
1584 start_bd->nbytes = cpu_to_le16(first_frag_len);
1587 (NETIF_MSG_TX_QUEUED | QED_MSG_LL2),
1588 "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",
1591 p_ll2->conn.conn_type,
1595 le32_to_cpu(start_bd->addr.hi),
1596 le32_to_cpu(start_bd->addr.lo));
1598 if (p_ll2->tx_queue.cur_send_frag_num == num_of_bds)
1601 /* Need to provide the packet with additional BDs for frags */
1602 for (frag_idx = p_ll2->tx_queue.cur_send_frag_num;
1603 frag_idx < num_of_bds; frag_idx++) {
1604 struct core_tx_bd **p_bd = &p_curp->bds_set[frag_idx].txq_bd;
1606 *p_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain);
1607 (*p_bd)->bd_flags.as_bitfield = 0;
1608 (*p_bd)->bitfield1 = 0;
1609 (*p_bd)->bitfield0 = 0;
1610 p_curp->bds_set[frag_idx].tx_frag = 0;
1611 p_curp->bds_set[frag_idx].frag_len = 0;
1615 /* This should be called while the Txq spinlock is being held */
1616 static void qed_ll2_tx_packet_notify(struct qed_hwfn *p_hwfn,
1617 struct qed_ll2_info *p_ll2_conn)
1619 bool b_notify = p_ll2_conn->tx_queue.cur_send_packet->notify_fw;
1620 struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
1621 struct qed_ll2_tx_packet *p_pkt = NULL;
1622 struct core_db_data db_msg = { 0, 0, 0 };
1625 /* If there are missing BDs, don't do anything now */
1626 if (p_ll2_conn->tx_queue.cur_send_frag_num !=
1627 p_ll2_conn->tx_queue.cur_send_packet->bd_used)
1630 /* Push the current packet to the list and clean after it */
1631 list_add_tail(&p_ll2_conn->tx_queue.cur_send_packet->list_entry,
1632 &p_ll2_conn->tx_queue.sending_descq);
1633 p_ll2_conn->tx_queue.cur_send_packet = NULL;
1634 p_ll2_conn->tx_queue.cur_send_frag_num = 0;
1636 /* Notify FW of packet only if requested to */
1640 bd_prod = qed_chain_get_prod_idx(&p_ll2_conn->tx_queue.txq_chain);
1642 while (!list_empty(&p_tx->sending_descq)) {
1643 p_pkt = list_first_entry(&p_tx->sending_descq,
1644 struct qed_ll2_tx_packet, list_entry);
1648 list_move_tail(&p_pkt->list_entry, &p_tx->active_descq);
1651 SET_FIELD(db_msg.params, CORE_DB_DATA_DEST, DB_DEST_XCM);
1652 SET_FIELD(db_msg.params, CORE_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
1653 SET_FIELD(db_msg.params, CORE_DB_DATA_AGG_VAL_SEL,
1654 DQ_XCM_CORE_TX_BD_PROD_CMD);
1655 db_msg.agg_flags = DQ_XCM_CORE_DQ_CF_CMD;
1656 db_msg.spq_prod = cpu_to_le16(bd_prod);
1658 /* Make sure the BDs data is updated before ringing the doorbell */
1661 DIRECT_REG_WR(p_tx->doorbell_addr, *((u32 *)&db_msg));
1664 (NETIF_MSG_TX_QUEUED | QED_MSG_LL2),
1665 "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Doorbelled [producer 0x%04x]\n",
1666 p_ll2_conn->queue_id,
1667 p_ll2_conn->cid, p_ll2_conn->conn.conn_type, db_msg.spq_prod);
1670 int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
1671 u8 connection_handle,
1675 u16 l4_hdr_offset_w,
1676 enum qed_ll2_tx_dest e_tx_dest,
1677 enum qed_ll2_roce_flavor_type qed_roce_flavor,
1678 dma_addr_t first_frag,
1679 u16 first_frag_len, void *cookie, u8 notify_fw)
1681 struct qed_ll2_tx_packet *p_curp = NULL;
1682 struct qed_ll2_info *p_ll2_conn = NULL;
1683 enum core_roce_flavor_type roce_flavor;
1684 struct qed_ll2_tx_queue *p_tx;
1685 struct qed_chain *p_tx_chain;
1686 enum core_tx_dest tx_dest;
1687 unsigned long flags;
1690 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
1693 p_tx = &p_ll2_conn->tx_queue;
1694 p_tx_chain = &p_tx->txq_chain;
1696 if (num_of_bds > CORE_LL2_TX_MAX_BDS_PER_PACKET)
1699 spin_lock_irqsave(&p_tx->lock, flags);
1700 if (p_tx->cur_send_packet) {
1705 /* Get entry, but only if we have tx elements for it */
1706 if (!list_empty(&p_tx->free_descq))
1707 p_curp = list_first_entry(&p_tx->free_descq,
1708 struct qed_ll2_tx_packet, list_entry);
1709 if (p_curp && qed_chain_get_elem_left(p_tx_chain) < num_of_bds)
1717 tx_dest = e_tx_dest == QED_LL2_TX_DEST_NW ? CORE_TX_DEST_NW :
1719 if (qed_roce_flavor == QED_LL2_ROCE) {
1720 roce_flavor = CORE_ROCE;
1721 } else if (qed_roce_flavor == QED_LL2_RROCE) {
1722 roce_flavor = CORE_RROCE;
1728 /* Prepare packet and BD, and perhaps send a doorbell to FW */
1729 qed_ll2_prepare_tx_packet_set(p_hwfn, p_tx, p_curp,
1730 num_of_bds, first_frag,
1731 first_frag_len, cookie, notify_fw);
1732 qed_ll2_prepare_tx_packet_set_bd(p_hwfn, p_ll2_conn, p_curp,
1733 num_of_bds, tx_dest,
1734 vlan, bd_flags, l4_hdr_offset_w,
1736 first_frag, first_frag_len);
1738 qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn);
1741 spin_unlock_irqrestore(&p_tx->lock, flags);
1745 int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
1746 u8 connection_handle,
1747 dma_addr_t addr, u16 nbytes)
1749 struct qed_ll2_tx_packet *p_cur_send_packet = NULL;
1750 struct qed_ll2_info *p_ll2_conn = NULL;
1751 u16 cur_send_frag_num = 0;
1752 struct core_tx_bd *p_bd;
1753 unsigned long flags;
1755 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
1759 if (!p_ll2_conn->tx_queue.cur_send_packet)
1762 p_cur_send_packet = p_ll2_conn->tx_queue.cur_send_packet;
1763 cur_send_frag_num = p_ll2_conn->tx_queue.cur_send_frag_num;
1765 if (cur_send_frag_num >= p_cur_send_packet->bd_used)
1768 /* Fill the BD information, and possibly notify FW */
1769 p_bd = p_cur_send_packet->bds_set[cur_send_frag_num].txq_bd;
1770 DMA_REGPAIR_LE(p_bd->addr, addr);
1771 p_bd->nbytes = cpu_to_le16(nbytes);
1772 p_cur_send_packet->bds_set[cur_send_frag_num].tx_frag = addr;
1773 p_cur_send_packet->bds_set[cur_send_frag_num].frag_len = nbytes;
1775 p_ll2_conn->tx_queue.cur_send_frag_num++;
1777 spin_lock_irqsave(&p_ll2_conn->tx_queue.lock, flags);
1778 qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn);
1779 spin_unlock_irqrestore(&p_ll2_conn->tx_queue.lock, flags);
1784 int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle)
1786 struct qed_ll2_info *p_ll2_conn = NULL;
1789 p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle);
1793 /* Stop Tx & Rx of connection, if needed */
1794 if (QED_LL2_TX_REGISTERED(p_ll2_conn)) {
1795 rc = qed_sp_ll2_tx_queue_stop(p_hwfn, p_ll2_conn);
1798 qed_ll2_txq_flush(p_hwfn, connection_handle);
1801 if (QED_LL2_RX_REGISTERED(p_ll2_conn)) {
1802 rc = qed_sp_ll2_rx_queue_stop(p_hwfn, p_ll2_conn);
1805 qed_ll2_rxq_flush(p_hwfn, connection_handle);
1808 if (p_ll2_conn->conn.conn_type == QED_LL2_TYPE_ISCSI_OOO)
1809 qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
1814 void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle)
1816 struct qed_ll2_info *p_ll2_conn = NULL;
1818 p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
1822 if (QED_LL2_RX_REGISTERED(p_ll2_conn)) {
1823 p_ll2_conn->rx_queue.b_cb_registred = false;
1824 qed_int_unregister_cb(p_hwfn, p_ll2_conn->rx_queue.rx_sb_index);
1827 if (QED_LL2_TX_REGISTERED(p_ll2_conn)) {
1828 p_ll2_conn->tx_queue.b_cb_registred = false;
1829 qed_int_unregister_cb(p_hwfn, p_ll2_conn->tx_queue.tx_sb_index);
1832 kfree(p_ll2_conn->tx_queue.descq_array);
1833 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->tx_queue.txq_chain);
1835 kfree(p_ll2_conn->rx_queue.descq_array);
1836 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rxq_chain);
1837 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rcq_chain);
1839 qed_cxt_release_cid(p_hwfn, p_ll2_conn->cid);
1841 qed_ll2_release_connection_ooo(p_hwfn, p_ll2_conn);
1843 mutex_lock(&p_ll2_conn->mutex);
1844 p_ll2_conn->b_active = false;
1845 mutex_unlock(&p_ll2_conn->mutex);
1848 struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn)
1850 struct qed_ll2_info *p_ll2_connections;
1853 /* Allocate LL2's set struct */
1854 p_ll2_connections = kcalloc(QED_MAX_NUM_OF_LL2_CONNECTIONS,
1855 sizeof(struct qed_ll2_info), GFP_KERNEL);
1856 if (!p_ll2_connections) {
1857 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_ll2'\n");
1861 for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++)
1862 p_ll2_connections[i].my_id = i;
1864 return p_ll2_connections;
1867 void qed_ll2_setup(struct qed_hwfn *p_hwfn,
1868 struct qed_ll2_info *p_ll2_connections)
1872 for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++)
1873 mutex_init(&p_ll2_connections[i].mutex);
1876 void qed_ll2_free(struct qed_hwfn *p_hwfn,
1877 struct qed_ll2_info *p_ll2_connections)
1879 kfree(p_ll2_connections);
1882 static void _qed_ll2_get_tstats(struct qed_hwfn *p_hwfn,
1883 struct qed_ptt *p_ptt,
1884 struct qed_ll2_info *p_ll2_conn,
1885 struct qed_ll2_stats *p_stats)
1887 struct core_ll2_tstorm_per_queue_stat tstats;
1888 u8 qid = p_ll2_conn->queue_id;
1891 memset(&tstats, 0, sizeof(tstats));
1892 tstats_addr = BAR0_MAP_REG_TSDM_RAM +
1893 CORE_LL2_TSTORM_PER_QUEUE_STAT_OFFSET(qid);
1894 qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, sizeof(tstats));
1896 p_stats->packet_too_big_discard =
1897 HILO_64_REGPAIR(tstats.packet_too_big_discard);
1898 p_stats->no_buff_discard = HILO_64_REGPAIR(tstats.no_buff_discard);
1901 static void _qed_ll2_get_ustats(struct qed_hwfn *p_hwfn,
1902 struct qed_ptt *p_ptt,
1903 struct qed_ll2_info *p_ll2_conn,
1904 struct qed_ll2_stats *p_stats)
1906 struct core_ll2_ustorm_per_queue_stat ustats;
1907 u8 qid = p_ll2_conn->queue_id;
1910 memset(&ustats, 0, sizeof(ustats));
1911 ustats_addr = BAR0_MAP_REG_USDM_RAM +
1912 CORE_LL2_USTORM_PER_QUEUE_STAT_OFFSET(qid);
1913 qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, sizeof(ustats));
1915 p_stats->rcv_ucast_bytes = HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
1916 p_stats->rcv_mcast_bytes = HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
1917 p_stats->rcv_bcast_bytes = HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
1918 p_stats->rcv_ucast_pkts = HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
1919 p_stats->rcv_mcast_pkts = HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
1920 p_stats->rcv_bcast_pkts = HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
1923 static void _qed_ll2_get_pstats(struct qed_hwfn *p_hwfn,
1924 struct qed_ptt *p_ptt,
1925 struct qed_ll2_info *p_ll2_conn,
1926 struct qed_ll2_stats *p_stats)
1928 struct core_ll2_pstorm_per_queue_stat pstats;
1929 u8 stats_id = p_ll2_conn->tx_stats_id;
1932 memset(&pstats, 0, sizeof(pstats));
1933 pstats_addr = BAR0_MAP_REG_PSDM_RAM +
1934 CORE_LL2_PSTORM_PER_QUEUE_STAT_OFFSET(stats_id);
1935 qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, sizeof(pstats));
1937 p_stats->sent_ucast_bytes = HILO_64_REGPAIR(pstats.sent_ucast_bytes);
1938 p_stats->sent_mcast_bytes = HILO_64_REGPAIR(pstats.sent_mcast_bytes);
1939 p_stats->sent_bcast_bytes = HILO_64_REGPAIR(pstats.sent_bcast_bytes);
1940 p_stats->sent_ucast_pkts = HILO_64_REGPAIR(pstats.sent_ucast_pkts);
1941 p_stats->sent_mcast_pkts = HILO_64_REGPAIR(pstats.sent_mcast_pkts);
1942 p_stats->sent_bcast_pkts = HILO_64_REGPAIR(pstats.sent_bcast_pkts);
1945 int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
1946 u8 connection_handle, struct qed_ll2_stats *p_stats)
1948 struct qed_ll2_info *p_ll2_conn = NULL;
1949 struct qed_ptt *p_ptt;
1951 memset(p_stats, 0, sizeof(*p_stats));
1953 if ((connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS) ||
1954 !p_hwfn->p_ll2_info)
1957 p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle];
1959 p_ptt = qed_ptt_acquire(p_hwfn);
1961 DP_ERR(p_hwfn, "Failed to acquire ptt\n");
1965 _qed_ll2_get_tstats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
1966 _qed_ll2_get_ustats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
1967 if (p_ll2_conn->tx_stats_en)
1968 _qed_ll2_get_pstats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
1970 qed_ptt_release(p_hwfn, p_ptt);
1974 static void qed_ll2_register_cb_ops(struct qed_dev *cdev,
1975 const struct qed_ll2_cb_ops *ops,
1978 cdev->ll2->cbs = ops;
1979 cdev->ll2->cb_cookie = cookie;
1982 static int qed_ll2_start(struct qed_dev *cdev, struct qed_ll2_params *params)
1984 struct qed_ll2_conn ll2_info;
1985 struct qed_ll2_buffer *buffer, *tmp_buffer;
1986 enum qed_ll2_conn_type conn_type;
1987 struct qed_ptt *p_ptt;
1991 /* Initialize LL2 locks & lists */
1992 INIT_LIST_HEAD(&cdev->ll2->list);
1993 spin_lock_init(&cdev->ll2->lock);
1994 cdev->ll2->rx_size = NET_SKB_PAD + ETH_HLEN +
1995 L1_CACHE_BYTES + params->mtu;
1996 cdev->ll2->frags_mapped = params->frags_mapped;
1998 /*Allocate memory for LL2 */
1999 DP_INFO(cdev, "Allocating LL2 buffers of size %08x bytes\n",
2000 cdev->ll2->rx_size);
2001 for (i = 0; i < QED_LL2_RX_SIZE; i++) {
2002 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
2004 DP_INFO(cdev, "Failed to allocate LL2 buffers\n");
2008 rc = qed_ll2_alloc_buffer(cdev, (u8 **)&buffer->data,
2009 &buffer->phys_addr);
2015 list_add_tail(&buffer->list, &cdev->ll2->list);
2018 switch (QED_LEADING_HWFN(cdev)->hw_info.personality) {
2020 conn_type = QED_LL2_TYPE_ISCSI;
2023 case QED_PCI_ETH_ROCE:
2024 conn_type = QED_LL2_TYPE_ROCE;
2027 conn_type = QED_LL2_TYPE_TEST;
2030 /* Prepare the temporary ll2 information */
2031 memset(&ll2_info, 0, sizeof(ll2_info));
2033 ll2_info.conn_type = conn_type;
2034 ll2_info.mtu = params->mtu;
2035 ll2_info.rx_drop_ttl0_flg = params->drop_ttl0_packets;
2036 ll2_info.rx_vlan_removal_en = params->rx_vlan_stripping;
2038 ll2_info.tx_dest = CORE_TX_DEST_NW;
2039 ll2_info.gsi_enable = gsi_enable;
2041 rc = qed_ll2_acquire_connection(QED_LEADING_HWFN(cdev), &ll2_info,
2042 QED_LL2_RX_SIZE, QED_LL2_TX_SIZE,
2043 &cdev->ll2->handle);
2045 DP_INFO(cdev, "Failed to acquire LL2 connection\n");
2049 rc = qed_ll2_establish_connection(QED_LEADING_HWFN(cdev),
2052 DP_INFO(cdev, "Failed to establish LL2 connection\n");
2056 /* Post all Rx buffers to FW */
2057 spin_lock_bh(&cdev->ll2->lock);
2058 list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list) {
2059 rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev),
2061 buffer->phys_addr, 0, buffer, 1);
2064 "Failed to post an Rx buffer; Deleting it\n");
2065 dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
2066 cdev->ll2->rx_size, DMA_FROM_DEVICE);
2067 kfree(buffer->data);
2068 list_del(&buffer->list);
2071 cdev->ll2->rx_cnt++;
2074 spin_unlock_bh(&cdev->ll2->lock);
2076 if (!cdev->ll2->rx_cnt) {
2077 DP_INFO(cdev, "Failed passing even a single Rx buffer\n");
2078 goto release_terminate;
2081 if (!is_valid_ether_addr(params->ll2_mac_address)) {
2082 DP_INFO(cdev, "Invalid Ethernet address\n");
2083 goto release_terminate;
2086 if (cdev->hwfns[0].hw_info.personality == QED_PCI_ISCSI &&
2087 cdev->hwfns[0].pf_params.iscsi_pf_params.ooo_enable) {
2088 DP_VERBOSE(cdev, QED_MSG_STORAGE, "Starting OOO LL2 queue\n");
2089 rc = qed_ll2_start_ooo(cdev, params);
2092 "Failed to initialize the OOO LL2 queue\n");
2093 goto release_terminate;
2097 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
2099 DP_INFO(cdev, "Failed to acquire PTT\n");
2100 goto release_terminate;
2103 rc = qed_llh_add_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
2104 params->ll2_mac_address);
2105 qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
2107 DP_ERR(cdev, "Failed to allocate LLH filter\n");
2108 goto release_terminate_all;
2111 ether_addr_copy(cdev->ll2_mac_address, params->ll2_mac_address);
2114 release_terminate_all:
2117 qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
2119 qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
2121 qed_ll2_kill_buffers(cdev);
2122 cdev->ll2->handle = QED_LL2_UNUSED_HANDLE;
2126 static int qed_ll2_stop(struct qed_dev *cdev)
2128 struct qed_ptt *p_ptt;
2131 if (cdev->ll2->handle == QED_LL2_UNUSED_HANDLE)
2134 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
2136 DP_INFO(cdev, "Failed to acquire PTT\n");
2140 qed_llh_remove_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
2141 cdev->ll2_mac_address);
2142 qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
2143 eth_zero_addr(cdev->ll2_mac_address);
2145 if (cdev->hwfns[0].hw_info.personality == QED_PCI_ISCSI &&
2146 cdev->hwfns[0].pf_params.iscsi_pf_params.ooo_enable)
2147 qed_ll2_stop_ooo(cdev);
2149 rc = qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev),
2152 DP_INFO(cdev, "Failed to terminate LL2 connection\n");
2154 qed_ll2_kill_buffers(cdev);
2156 qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
2157 cdev->ll2->handle = QED_LL2_UNUSED_HANDLE;
2164 static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb)
2166 const skb_frag_t *frag;
2167 int rc = -EINVAL, i;
2172 if (unlikely(skb->ip_summed != CHECKSUM_NONE)) {
2173 DP_INFO(cdev, "Cannot transmit a checksumed packet\n");
2177 if (1 + skb_shinfo(skb)->nr_frags > CORE_LL2_TX_MAX_BDS_PER_PACKET) {
2178 DP_ERR(cdev, "Cannot transmit a packet with %d fragments\n",
2179 1 + skb_shinfo(skb)->nr_frags);
2183 mapping = dma_map_single(&cdev->pdev->dev, skb->data,
2184 skb->len, DMA_TO_DEVICE);
2185 if (unlikely(dma_mapping_error(&cdev->pdev->dev, mapping))) {
2186 DP_NOTICE(cdev, "SKB mapping failed\n");
2190 /* Request HW to calculate IP csum */
2191 if (!((vlan_get_protocol(skb) == htons(ETH_P_IPV6)) &&
2192 ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
2193 flags |= BIT(CORE_TX_BD_FLAGS_IP_CSUM_SHIFT);
2195 if (skb_vlan_tag_present(skb)) {
2196 vlan = skb_vlan_tag_get(skb);
2197 flags |= BIT(CORE_TX_BD_FLAGS_VLAN_INSERTION_SHIFT);
2200 rc = qed_ll2_prepare_tx_packet(QED_LEADING_HWFN(cdev),
2202 1 + skb_shinfo(skb)->nr_frags,
2203 vlan, flags, 0, QED_LL2_TX_DEST_NW,
2204 0 /* RoCE FLAVOR */,
2205 mapping, skb->len, skb, 1);
2209 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2210 frag = &skb_shinfo(skb)->frags[i];
2211 if (!cdev->ll2->frags_mapped) {
2212 mapping = skb_frag_dma_map(&cdev->pdev->dev, frag, 0,
2213 skb_frag_size(frag),
2216 if (unlikely(dma_mapping_error(&cdev->pdev->dev,
2219 "Unable to map frag - dropping packet\n");
2224 mapping = page_to_phys(skb_frag_page(frag)) |
2228 rc = qed_ll2_set_fragment_of_tx_packet(QED_LEADING_HWFN(cdev),
2231 skb_frag_size(frag));
2233 /* if failed not much to do here, partial packet has been posted
2234 * we can't free memory, will need to wait for completion.
2243 dma_unmap_single(&cdev->pdev->dev, mapping, skb->len, DMA_TO_DEVICE);
2249 static int qed_ll2_stats(struct qed_dev *cdev, struct qed_ll2_stats *stats)
2254 return qed_ll2_get_stats(QED_LEADING_HWFN(cdev),
2255 cdev->ll2->handle, stats);
2258 const struct qed_ll2_ops qed_ll2_ops_pass = {
2259 .start = &qed_ll2_start,
2260 .stop = &qed_ll2_stop,
2261 .start_xmit = &qed_ll2_start_xmit,
2262 .register_cb_ops = &qed_ll2_register_cb_ops,
2263 .get_stats = &qed_ll2_stats,
2266 int qed_ll2_alloc_if(struct qed_dev *cdev)
2268 cdev->ll2 = kzalloc(sizeof(*cdev->ll2), GFP_KERNEL);
2269 return cdev->ll2 ? 0 : -ENOMEM;
2272 void qed_ll2_dealloc_if(struct qed_dev *cdev)