Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
0002 /* QLogic qed NIC Driver
0003  * Copyright (c) 2015-2017  QLogic Corporation
0004  * Copyright (c) 2019-2020 Marvell International Ltd.
0005  */
0006 
0007 #ifndef _QED_LL2_H
0008 #define _QED_LL2_H
0009 
0010 #include <linux/types.h>
0011 #include <linux/kernel.h>
0012 #include <linux/list.h>
0013 #include <linux/mutex.h>
0014 #include <linux/slab.h>
0015 #include <linux/spinlock.h>
0016 #include <linux/qed/qed_chain.h>
0017 #include <linux/qed/qed_ll2_if.h>
0018 #include "qed.h"
0019 #include "qed_hsi.h"
0020 #include "qed_sp.h"
0021 
0022 #define QED_MAX_NUM_OF_LL2_CONNECTIONS                    (4)
0023 /* LL2 queues handles will be split as follows:
0024  * first will be legacy queues, and then the ctx based queues.
0025  */
0026 #define QED_MAX_NUM_OF_LL2_CONNS_PF            (4)
0027 #define QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF   (3)
0028 
0029 #define QED_MAX_NUM_OF_CTX_LL2_CONNS_PF \
0030     (QED_MAX_NUM_OF_LL2_CONNS_PF - QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF)
0031 
0032 #define QED_LL2_LEGACY_CONN_BASE_PF     0
0033 #define QED_LL2_CTX_CONN_BASE_PF        QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF
0034 
0035 struct qed_ll2_rx_packet {
0036     struct list_head list_entry;
0037     struct core_rx_bd_with_buff_len *rxq_bd;
0038     dma_addr_t rx_buf_addr;
0039     u16 buf_length;
0040     void *cookie;
0041     u8 placement_offset;
0042     u16 parse_flags;
0043     u16 packet_length;
0044     u16 vlan;
0045     u32 opaque_data[2];
0046 };
0047 
0048 struct qed_ll2_tx_packet {
0049     struct list_head list_entry;
0050     u16 bd_used;
0051     bool notify_fw;
0052     void *cookie;
0053     /* Flexible Array of bds_set determined by max_bds_per_packet */
0054     struct {
0055         struct core_tx_bd *txq_bd;
0056         dma_addr_t tx_frag;
0057         u16 frag_len;
0058     } bds_set[];
0059 };
0060 
0061 struct qed_ll2_rx_queue {
0062     /* Lock protecting the Rx queue manipulation */
0063     spinlock_t lock;
0064     struct qed_chain rxq_chain;
0065     struct qed_chain rcq_chain;
0066     u8 rx_sb_index;
0067     u8 ctx_based;
0068     bool b_cb_registered;
0069     __le16 *p_fw_cons;
0070     struct list_head active_descq;
0071     struct list_head free_descq;
0072     struct list_head posting_descq;
0073     struct qed_ll2_rx_packet *descq_array;
0074     void __iomem *set_prod_addr;
0075     struct core_pwm_prod_update_data db_data;
0076 };
0077 
0078 struct qed_ll2_tx_queue {
0079     /* Lock protecting the Tx queue manipulation */
0080     spinlock_t lock;
0081     struct qed_chain txq_chain;
0082     u8 tx_sb_index;
0083     bool b_cb_registered;
0084     __le16 *p_fw_cons;
0085     struct list_head active_descq;
0086     struct list_head free_descq;
0087     struct list_head sending_descq;
0088     u16 cur_completing_bd_idx;
0089     void __iomem *doorbell_addr;
0090     struct core_db_data db_msg;
0091     u16 bds_idx;
0092     u16 cur_send_frag_num;
0093     u16 cur_completing_frag_num;
0094     bool b_completing_packet;
0095     void *descq_mem; /* memory for variable sized qed_ll2_tx_packet*/
0096     struct qed_ll2_tx_packet *cur_send_packet;
0097     struct qed_ll2_tx_packet cur_completing_packet;
0098 };
0099 
0100 struct qed_ll2_info {
0101     /* Lock protecting the state of LL2 */
0102     struct mutex mutex;
0103 
0104     struct qed_ll2_acquire_data_inputs input;
0105     u32 cid;
0106     u8 my_id;
0107     u8 queue_id;
0108     u8 tx_stats_id;
0109     bool b_active;
0110     enum core_tx_dest tx_dest;
0111     u8 tx_stats_en;
0112     bool main_func_queue;
0113     struct qed_ll2_rx_queue rx_queue;
0114     struct qed_ll2_tx_queue tx_queue;
0115     struct qed_ll2_cbs cbs;
0116 };
0117 
0118 extern const struct qed_ll2_ops qed_ll2_ops_pass;
0119 
0120 /**
0121  * qed_ll2_acquire_connection(): Allocate resources,
0122  *                               starts rx & tx (if relevant) queues pair.
0123  *                               Provides connecion handler as output
0124  *                               parameter.
0125  *
0126  * @cxt: Pointer to the hw-function [opaque to some].
0127  * @data: Describes connection parameters.
0128  *
0129  * Return: Int.
0130  */
0131 int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data);
0132 
0133 /**
0134  * qed_ll2_establish_connection(): start previously allocated LL2 queues pair
0135  *
0136  * @cxt: Pointer to the hw-function [opaque to some].
0137  * @connection_handle: LL2 connection's handle obtained from
0138  *                     qed_ll2_require_connection.
0139  *
0140  * Return: 0 on success, failure otherwise.
0141  */
0142 int qed_ll2_establish_connection(void *cxt, u8 connection_handle);
0143 
0144 /**
0145  * qed_ll2_post_rx_buffer(): Submit buffers to LL2 Rx queue.
0146  *
0147  * @cxt: Pointer to the hw-function [opaque to some].
0148  * @connection_handle: LL2 connection's handle obtained from
0149  *                     qed_ll2_require_connection.
0150  * @addr: RX (physical address) buffers to submit.
0151  * @buf_len: Buffer Len.
0152  * @cookie: Cookie.
0153  * @notify_fw: Produce corresponding Rx BD immediately.
0154  *
0155  * Return: 0 on success, failure otherwise.
0156  */
0157 int qed_ll2_post_rx_buffer(void *cxt,
0158                u8 connection_handle,
0159                dma_addr_t addr,
0160                u16 buf_len, void *cookie, u8 notify_fw);
0161 
0162 /**
0163  * qed_ll2_prepare_tx_packet(): Request for start Tx BD
0164  *              to prepare Tx packet submission to FW.
0165  *
0166  * @cxt: Pointer to the hw-function [opaque to some].
0167  * @connection_handle: Connection handle.
0168  * @pkt: Info regarding the tx packet.
0169  * @notify_fw: Issue doorbell to fw for this packet.
0170  *
0171  * Return: 0 on success, failure otherwise.
0172  */
0173 int qed_ll2_prepare_tx_packet(void *cxt,
0174                   u8 connection_handle,
0175                   struct qed_ll2_tx_pkt_info *pkt,
0176                   bool notify_fw);
0177 
0178 /**
0179  * qed_ll2_release_connection(): Releases resources allocated for LL2
0180  *                               connection.
0181  *
0182  * @cxt: Pointer to the hw-function [opaque to some].
0183  * @connection_handle: LL2 connection's handle obtained from
0184  *                     qed_ll2_require_connection.
0185  *
0186  * Return: Void.
0187  */
0188 void qed_ll2_release_connection(void *cxt, u8 connection_handle);
0189 
0190 /**
0191  * qed_ll2_set_fragment_of_tx_packet(): Provides fragments to fill
0192  *                                      Tx BD of BDs requested by
0193  *                                      qed_ll2_prepare_tx_packet
0194  *
0195  * @cxt: Pointer to the hw-function [opaque to some].
0196  * @connection_handle: LL2 connection's handle obtained from
0197  *                     qed_ll2_require_connection.
0198  * @addr: Address.
0199  * @nbytes: Number of bytes.
0200  *
0201  * Return: 0 on success, failure otherwise.
0202  */
0203 int qed_ll2_set_fragment_of_tx_packet(void *cxt,
0204                       u8 connection_handle,
0205                       dma_addr_t addr, u16 nbytes);
0206 
0207 /**
0208  * qed_ll2_terminate_connection(): Stops Tx/Rx queues
0209  *
0210  * @cxt: Pointer to the hw-function [opaque to some].
0211  * @connection_handle: LL2 connection's handle obtained from
0212  *                    qed_ll2_require_connection.
0213  *
0214  * Return: 0 on success, failure otherwise.
0215  */
0216 int qed_ll2_terminate_connection(void *cxt, u8 connection_handle);
0217 
0218 /**
0219  * qed_ll2_get_stats(): Get LL2 queue's statistics
0220  *
0221  * @cxt: Pointer to the hw-function [opaque to some].
0222  * @connection_handle: LL2 connection's handle obtained from
0223  *                    qed_ll2_require_connection.
0224  * @p_stats: Pointer Status.
0225  *
0226  * Return: 0 on success, failure otherwise.
0227  */
0228 int qed_ll2_get_stats(void *cxt,
0229               u8 connection_handle, struct qed_ll2_stats *p_stats);
0230 
0231 /**
0232  * qed_ll2_alloc(): Allocates LL2 connections set.
0233  *
0234  * @p_hwfn: HW device data.
0235  *
0236  * Return: Int.
0237  */
0238 int qed_ll2_alloc(struct qed_hwfn *p_hwfn);
0239 
0240 /**
0241  * qed_ll2_setup(): Inits LL2 connections set.
0242  *
0243  * @p_hwfn: HW device data.
0244  *
0245  * Return: Void.
0246  *
0247  */
0248 void qed_ll2_setup(struct qed_hwfn *p_hwfn);
0249 
0250 /**
0251  * qed_ll2_free(): Releases LL2 connections set
0252  *
0253  * @p_hwfn: HW device data.
0254  *
0255  * Return: Void.
0256  *
0257  */
0258 void qed_ll2_free(struct qed_hwfn *p_hwfn);
0259 
0260 #endif