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
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/list.h>
16 #include <linux/mutex.h>
17 #include <linux/slab.h>
18 #include <linux/spinlock.h>
19 #include <linux/qed/qed_chain.h>
20 #include <linux/qed/qed_ll2_if.h>
25 #define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
27 enum qed_ll2_conn_type {
28 QED_LL2_TYPE_RESERVED,
31 QED_LL2_TYPE_ISCSI_OOO,
32 QED_LL2_TYPE_RESERVED2,
34 QED_LL2_TYPE_RESERVED3,
35 MAX_QED_LL2_RX_CONN_TYPE
38 struct qed_ll2_rx_packet {
39 struct list_head list_entry;
40 struct core_rx_bd_with_buff_len *rxq_bd;
41 dma_addr_t rx_buf_addr;
51 struct qed_ll2_tx_packet {
52 struct list_head list_entry;
61 struct core_tx_bd *txq_bd;
64 } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
67 struct qed_ll2_rx_queue {
68 /* Lock protecting the Rx queue manipulation */
70 struct qed_chain rxq_chain;
71 struct qed_chain rcq_chain;
75 struct list_head active_descq;
76 struct list_head free_descq;
77 struct list_head posting_descq;
78 struct qed_ll2_rx_packet *descq_array;
79 void __iomem *set_prod_addr;
82 struct qed_ll2_tx_queue {
83 /* Lock protecting the Tx queue manipulation */
85 struct qed_chain txq_chain;
89 struct list_head active_descq;
90 struct list_head free_descq;
91 struct list_head sending_descq;
92 struct qed_ll2_tx_packet *descq_array;
93 struct qed_ll2_tx_packet *cur_send_packet;
94 struct qed_ll2_tx_packet cur_completing_packet;
95 u16 cur_completing_bd_idx;
96 void __iomem *doorbell_addr;
98 u16 cur_send_frag_num;
99 u16 cur_completing_frag_num;
100 bool b_completing_packet;
103 struct qed_ll2_info {
104 /* Lock protecting the state of LL2 */
106 enum qed_ll2_conn_type conn_type;
114 u8 rx_vlan_removal_en;
116 enum core_tx_dest tx_dest;
117 enum core_error_handle ai_err_packet_too_big;
118 enum core_error_handle ai_err_no_buf;
120 struct qed_ll2_rx_queue rx_queue;
121 struct qed_ll2_tx_queue tx_queue;
125 * @brief qed_ll2_acquire_connection - allocate resources,
126 * starts rx & tx (if relevant) queues pair. Provides
127 * connecion handler as output parameter.
130 * @param p_params Contain various configuration properties
134 * @param p_connection_handle Output container for LL2 connection's handle
136 * @return 0 on success, failure otherwise
138 int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
139 struct qed_ll2_info *p_params,
142 u8 *p_connection_handle);
145 * @brief qed_ll2_establish_connection - start previously
146 * allocated LL2 queues pair
150 * @param connection_handle LL2 connection's handle obtained from
151 * qed_ll2_require_connection
153 * @return 0 on success, failure otherwise
155 int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
158 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
161 * @param connection_handle LL2 connection's handle obtained from
162 * qed_ll2_require_connection
163 * @param addr rx (physical address) buffers to submit
165 * @param notify_fw produce corresponding Rx BD immediately
167 * @return 0 on success, failure otherwise
169 int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
170 u8 connection_handle,
172 u16 buf_len, void *cookie, u8 notify_fw);
175 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
176 * to prepare Tx packet submission to FW.
179 * @param connection_handle LL2 connection's handle obtained from
180 * qed_ll2_require_connection
181 * @param num_of_bds a number of requested BD equals a number of
182 * fragments in Tx packet
183 * @param vlan VLAN to insert to packet (if insertion set)
185 * @param l4_hdr_offset_w L4 Header Offset from start of packet
186 * (in words). This is needed if both l4_csum
187 * and ipv6_ext are set
189 * @param first_frag_len
194 * @return 0 on success, failure otherwise
196 int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
197 u8 connection_handle,
202 dma_addr_t first_frag,
203 u16 first_frag_len, void *cookie, u8 notify_fw);
206 * @brief qed_ll2_release_connection - releases resources
207 * allocated for LL2 connection
210 * @param connection_handle LL2 connection's handle obtained from
211 * qed_ll2_require_connection
213 void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
216 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
217 * Tx BD of BDs requested by
218 * qed_ll2_prepare_tx_packet
221 * @param connection_handle LL2 connection's handle
223 * qed_ll2_require_connection
227 * @return 0 on success, failure otherwise
229 int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
230 u8 connection_handle,
231 dma_addr_t addr, u16 nbytes);
234 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
238 * @param connection_handle LL2 connection's handle
240 * qed_ll2_require_connection
242 * @return 0 on success, failure otherwise
244 int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
247 * @brief qed_ll2_get_stats - get LL2 queue's statistics
251 * @param connection_handle LL2 connection's handle obtained from
252 * qed_ll2_require_connection
255 * @return 0 on success, failure otherwise
257 int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
258 u8 connection_handle, struct qed_ll2_stats *p_stats);
261 * @brief qed_ll2_alloc - Allocates LL2 connections set
265 * @return pointer to alocated qed_ll2_info or NULL
267 struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn);
270 * @brief qed_ll2_setup - Inits LL2 connections set
273 * @param p_ll2_connections
276 void qed_ll2_setup(struct qed_hwfn *p_hwfn,
277 struct qed_ll2_info *p_ll2_connections);
280 * @brief qed_ll2_free - Releases LL2 connections set
283 * @param p_ll2_connections
286 void qed_ll2_free(struct qed_hwfn *p_hwfn,
287 struct qed_ll2_info *p_ll2_connections);