blob: cfb575859cc622d8c5b8ea13607829e82a642c9b [file] [log] [blame]
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * 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:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020031 */
32
33#ifndef _QED_H
34#define _QED_H
35
36#include <linux/types.h>
37#include <linux/io.h>
38#include <linux/delay.h>
39#include <linux/firmware.h>
40#include <linux/interrupt.h>
41#include <linux/list.h>
42#include <linux/mutex.h>
43#include <linux/pci.h>
44#include <linux/slab.h>
45#include <linux/string.h>
46#include <linux/workqueue.h>
47#include <linux/zlib.h>
48#include <linux/hashtable.h>
49#include <linux/qed/qed_if.h>
Tomer Tayarc965db42016-09-07 16:36:24 +030050#include "qed_debug.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020051#include "qed_hsi.h"
52
Yuval Mintz25c089d2015-10-26 11:02:26 +020053extern const struct qed_common_ops qed_common_ops_pass;
Tomer Tayar5d24bcf2017-03-28 15:12:52 +030054
55#define QED_MAJOR_VERSION 8
56#define QED_MINOR_VERSION 10
Mintz, Yuval7b6859f2017-05-18 19:41:04 +030057#define QED_REVISION_VERSION 11
Tomer Tayar5d24bcf2017-03-28 15:12:52 +030058#define QED_ENGINEERING_VERSION 21
59
60#define QED_VERSION \
61 ((QED_MAJOR_VERSION << 24) | (QED_MINOR_VERSION << 16) | \
62 (QED_REVISION_VERSION << 8) | QED_ENGINEERING_VERSION)
63
64#define STORM_FW_VERSION \
65 ((FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) | \
66 (FW_REVISION_VERSION << 8) | FW_ENGINEERING_VERSION)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020067
68#define MAX_HWFNS_PER_DEVICE (4)
69#define NAME_SIZE 16
70#define VER_SIZE 16
71
Manish Choprabcd197c2016-04-26 10:56:08 -040072#define QED_WFQ_UNIT 100
73
Ram Amrani51ff1722016-10-01 21:59:57 +030074#define QED_WID_SIZE (1024)
Ram Amrani107392b2017-04-30 11:49:09 +030075#define QED_MIN_WIDS (4)
Ram Amrani51ff1722016-10-01 21:59:57 +030076#define QED_PF_DEMS_SIZE (4)
77
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020078/* cau states */
79enum qed_coalescing_mode {
80 QED_COAL_MODE_DISABLE,
81 QED_COAL_MODE_ENABLE
82};
83
84struct qed_eth_cb_ops;
85struct qed_dev_info;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -040086union qed_mcp_protocol_stats;
87enum qed_mcp_protocol_type;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020088
89/* helpers */
Tomer Tayar5d24bcf2017-03-28 15:12:52 +030090#define QED_MFW_GET_FIELD(name, field) \
91 (((name) & (field ## _MASK)) >> (field ## _SHIFT))
92
93#define QED_MFW_SET_FIELD(name, field, value) \
94 do { \
Tomer Tayarb19601b2017-05-21 12:10:59 +030095 (name) &= ~(field ## _MASK); \
Tomer Tayar5d24bcf2017-03-28 15:12:52 +030096 (name) |= (((value) << (field ## _SHIFT)) & (field ## _MASK));\
97 } while (0)
98
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020099static inline u32 qed_db_addr(u32 cid, u32 DEMS)
100{
101 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
Ram Amrani51ff1722016-10-01 21:59:57 +0300102 (cid * QED_PF_DEMS_SIZE);
103
104 return db_addr;
105}
106
107static inline u32 qed_db_addr_vf(u32 cid, u32 DEMS)
108{
109 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200110 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
111
112 return db_addr;
113}
114
115#define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
116 ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
117 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
118
119#define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
120
121#define D_TRINE(val, cond1, cond2, true1, true2, def) \
122 (val == (cond1) ? true1 : \
123 (val == (cond2) ? true2 : def))
124
125/* forward */
126struct qed_ptt_pool;
127struct qed_spq;
128struct qed_sb_info;
129struct qed_sb_attn_info;
130struct qed_cxt_mngr;
131struct qed_sb_sp_info;
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300132struct qed_ll2_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200133struct qed_mcp_info;
134
135struct qed_rt_data {
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500136 u32 *init_val;
137 bool *b_valid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200138};
139
Manish Chopra464f6642016-04-14 01:38:29 -0400140enum qed_tunn_mode {
141 QED_MODE_L2GENEVE_TUNN,
142 QED_MODE_IPGENEVE_TUNN,
143 QED_MODE_L2GRE_TUNN,
144 QED_MODE_IPGRE_TUNN,
145 QED_MODE_VXLAN_TUNN,
146};
147
148enum qed_tunn_clss {
149 QED_TUNN_CLSS_MAC_VLAN,
150 QED_TUNN_CLSS_MAC_VNI,
151 QED_TUNN_CLSS_INNER_MAC_VLAN,
152 QED_TUNN_CLSS_INNER_MAC_VNI,
Chopra, Manish199684302017-04-24 10:00:44 -0700153 QED_TUNN_CLSS_MAC_VLAN_DUAL_STAGE,
Manish Chopra464f6642016-04-14 01:38:29 -0400154 MAX_QED_TUNN_CLSS,
155};
156
Chopra, Manish199684302017-04-24 10:00:44 -0700157struct qed_tunn_update_type {
158 bool b_update_mode;
159 bool b_mode_enabled;
160 enum qed_tunn_clss tun_cls;
161};
162
163struct qed_tunn_update_udp_port {
164 bool b_update_port;
165 u16 port;
166};
167
168struct qed_tunnel_info {
169 struct qed_tunn_update_type vxlan;
170 struct qed_tunn_update_type l2_geneve;
171 struct qed_tunn_update_type ip_geneve;
172 struct qed_tunn_update_type l2_gre;
173 struct qed_tunn_update_type ip_gre;
174
175 struct qed_tunn_update_udp_port vxlan_port;
176 struct qed_tunn_update_udp_port geneve_port;
177
178 bool b_update_rx_cls;
179 bool b_update_tx_cls;
180};
181
Manish Chopra464f6642016-04-14 01:38:29 -0400182struct qed_tunn_start_params {
183 unsigned long tunn_mode;
184 u16 vxlan_udp_port;
185 u16 geneve_udp_port;
186 u8 update_vxlan_udp_port;
187 u8 update_geneve_udp_port;
188 u8 tunn_clss_vxlan;
189 u8 tunn_clss_l2geneve;
190 u8 tunn_clss_ipgeneve;
191 u8 tunn_clss_l2gre;
192 u8 tunn_clss_ipgre;
193};
194
195struct qed_tunn_update_params {
196 unsigned long tunn_mode_update_mask;
197 unsigned long tunn_mode;
198 u16 vxlan_udp_port;
199 u16 geneve_udp_port;
200 u8 update_rx_pf_clss;
201 u8 update_tx_pf_clss;
202 u8 update_vxlan_udp_port;
203 u8 update_geneve_udp_port;
204 u8 tunn_clss_vxlan;
205 u8 tunn_clss_l2geneve;
206 u8 tunn_clss_ipgeneve;
207 u8 tunn_clss_l2gre;
208 u8 tunn_clss_ipgre;
209};
210
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200211/* The PCI personality is not quite synonymous to protocol ID:
212 * 1. All personalities need CORE connections
213 * 2. The Ethernet personality may support also the RoCE protocol
214 */
215enum qed_pci_personality {
216 QED_PCI_ETH,
Arun Easi1e128c82017-02-15 06:28:22 -0800217 QED_PCI_FCOE,
Yuval Mintzc5ac9312016-06-03 14:35:34 +0300218 QED_PCI_ISCSI,
219 QED_PCI_ETH_ROCE,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200220 QED_PCI_DEFAULT /* default in shmem */
221};
222
223/* All VFs are symmetric, all counters are PF + all VFs */
224struct qed_qm_iids {
225 u32 cids;
226 u32 vf_cids;
227 u32 tids;
228};
229
Tomer Tayar2edbff82016-10-31 07:14:27 +0200230/* HW / FW resources, output of features supported below, most information
231 * is received from MFW.
232 */
233enum qed_resources {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200234 QED_SB,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200235 QED_L2_QUEUE,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200236 QED_VPORT,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200237 QED_RSS_ENG,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200238 QED_PQ,
239 QED_RL,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200240 QED_MAC,
241 QED_VLAN,
Ram Amrani51ff1722016-10-01 21:59:57 +0300242 QED_RDMA_CNQ_RAM,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200243 QED_ILT,
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300244 QED_LL2_QUEUE,
Tomer Tayar2edbff82016-10-31 07:14:27 +0200245 QED_CMDQS_CQS,
Ram Amrani51ff1722016-10-01 21:59:57 +0300246 QED_RDMA_STATS_QUEUE,
Tomer Tayar9c8517c2017-03-28 15:12:55 +0300247 QED_BDQ,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200248 QED_MAX_RESC,
249};
250
Yuval Mintz25c089d2015-10-26 11:02:26 +0200251enum QED_FEATURE {
252 QED_PF_L2_QUE,
Yuval Mintz32a47e72016-05-11 16:36:12 +0300253 QED_VF,
Ram Amrani51ff1722016-10-01 21:59:57 +0300254 QED_RDMA_CNQ,
Mintz, Yuval08737a32017-04-06 15:58:33 +0300255 QED_ISCSI_CQ,
Arun Easi1e128c82017-02-15 06:28:22 -0800256 QED_FCOE_CQ,
Mintz, Yuval08737a32017-04-06 15:58:33 +0300257 QED_VF_L2_QUE,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200258 QED_MAX_FEATURES,
259};
260
Yuval Mintzcc875c22015-10-26 11:02:31 +0200261enum QED_PORT_MODE {
262 QED_PORT_MODE_DE_2X40G,
263 QED_PORT_MODE_DE_2X50G,
264 QED_PORT_MODE_DE_1X100G,
265 QED_PORT_MODE_DE_4X10G_F,
266 QED_PORT_MODE_DE_4X10G_E,
267 QED_PORT_MODE_DE_4X20G,
268 QED_PORT_MODE_DE_1X40G,
269 QED_PORT_MODE_DE_2X25G,
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200270 QED_PORT_MODE_DE_1X25G,
271 QED_PORT_MODE_DE_4X25G,
272 QED_PORT_MODE_DE_2X10G,
Yuval Mintzcc875c22015-10-26 11:02:31 +0200273};
274
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500275enum qed_dev_cap {
276 QED_DEV_CAP_ETH,
Arun Easi1e128c82017-02-15 06:28:22 -0800277 QED_DEV_CAP_FCOE,
Yuval Mintzc5ac9312016-06-03 14:35:34 +0300278 QED_DEV_CAP_ISCSI,
279 QED_DEV_CAP_ROCE,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500280};
281
Mintz, Yuval14d39642016-10-31 07:14:23 +0200282enum qed_wol_support {
283 QED_WOL_SUPPORT_NONE,
284 QED_WOL_SUPPORT_PME,
285};
286
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200287struct qed_hw_info {
288 /* PCI personality */
289 enum qed_pci_personality personality;
290
291 /* Resource Allocation scheme results */
292 u32 resc_start[QED_MAX_RESC];
293 u32 resc_num[QED_MAX_RESC];
Yuval Mintz25c089d2015-10-26 11:02:26 +0200294 u32 feat_num[QED_MAX_FEATURES];
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200295
296#define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
297#define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300298#define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
299 RESC_NUM(_p_hwfn, resc))
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200300#define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
301
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300302 /* Amount of traffic classes HW supports */
303 u8 num_hw_tc;
304
305 /* Amount of TCs which should be active according to DCBx or upper
306 * layer driver configuration.
307 */
308 u8 num_active_tc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200309 u8 offload_tc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200310
311 u32 concrete_fid;
312 u16 opaque_fid;
313 u16 ovlan;
314 u32 part_num[4];
315
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200316 unsigned char hw_mac_addr[ETH_ALEN];
Arun Easi1e128c82017-02-15 06:28:22 -0800317 u64 node_wwn;
318 u64 port_wwn;
319
320 u16 num_fcoe_conns;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200321
322 struct qed_igu_info *p_igu_info;
323
324 u32 port_mode;
325 u32 hw_mode;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500326 unsigned long device_capabilities;
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200327 u16 mtu;
Mintz, Yuval14d39642016-10-31 07:14:23 +0200328
329 enum qed_wol_support b_wol_support;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200330};
331
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200332/* maximun size of read/write commands (HW limit) */
333#define DMAE_MAX_RW_SIZE 0x2000
334
335struct qed_dmae_info {
336 /* Mutex for synchronizing access to functions */
337 struct mutex mutex;
338
339 u8 channel;
340
341 dma_addr_t completion_word_phys_addr;
342
343 /* The memory location where the DMAE writes the completion
344 * value when an operation is finished on this context.
345 */
346 u32 *p_completion_word;
347
348 dma_addr_t intermediate_buffer_phys_addr;
349
350 /* An intermediate buffer for DMAE operations that use virtual
351 * addresses - data is DMA'd to/from this buffer and then
352 * memcpy'd to/from the virtual address
353 */
354 u32 *p_intermediate_buffer;
355
356 dma_addr_t dmae_cmd_phys_addr;
357 struct dmae_cmd *p_dmae_cmd;
358};
359
Manish Choprabcd197c2016-04-26 10:56:08 -0400360struct qed_wfq_data {
361 /* when feature is configured for at least 1 vport */
362 u32 min_speed;
363 bool configured;
364};
365
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200366struct qed_qm_info {
367 struct init_qm_pq_params *qm_pq_params;
368 struct init_qm_vport_params *qm_vport_params;
369 struct init_qm_port_params *qm_port_params;
370 u16 start_pq;
371 u8 start_vport;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300372 u16 pure_lb_pq;
373 u16 offload_pq;
374 u16 low_latency_pq;
375 u16 pure_ack_pq;
376 u16 ooo_pq;
377 u16 first_vf_pq;
378 u16 first_mcos_pq;
379 u16 first_rl_pq;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200380 u16 num_pqs;
381 u16 num_vf_pqs;
382 u8 num_vports;
383 u8 max_phys_tcs_per_port;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300384 u8 ooo_tc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200385 bool pf_rl_en;
386 bool pf_wfq_en;
387 bool vport_rl_en;
388 bool vport_wfq_en;
389 u8 pf_wfq;
390 u32 pf_rl;
Manish Choprabcd197c2016-04-26 10:56:08 -0400391 struct qed_wfq_data *wfq_data;
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300392 u8 num_pf_rls;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200393};
394
Manish Chopra9df2ed02015-10-26 11:02:33 +0200395struct storm_stats {
396 u32 address;
397 u32 len;
398};
399
400struct qed_storm_stats {
401 struct storm_stats mstats;
402 struct storm_stats pstats;
403 struct storm_stats tstats;
404 struct storm_stats ustats;
405};
406
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200407struct qed_fw_data {
Manish Chopra9df2ed02015-10-26 11:02:33 +0200408 struct fw_ver_info *fw_ver_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200409 const u8 *modes_tree_buf;
410 union init_op *init_ops;
411 const u32 *arr_data;
412 u32 init_ops_size;
413};
414
Tomer Tayar5d24bcf2017-03-28 15:12:52 +0300415#define DRV_MODULE_VERSION \
416 __stringify(QED_MAJOR_VERSION) "." \
417 __stringify(QED_MINOR_VERSION) "." \
418 __stringify(QED_REVISION_VERSION) "." \
419 __stringify(QED_ENGINEERING_VERSION)
420
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200421struct qed_simd_fp_handler {
422 void *token;
423 void (*func)(void *);
424};
425
426struct qed_hwfn {
427 struct qed_dev *cdev;
428 u8 my_id; /* ID inside the PF */
429#define IS_LEAD_HWFN(edev) (!((edev)->my_id))
430 u8 rel_pf_id; /* Relative to engine*/
431 u8 abs_pf_id;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200432#define QED_PATH_ID(_p_hwfn) \
433 (QED_IS_K2((_p_hwfn)->cdev) ? 0 : ((_p_hwfn)->abs_pf_id & 1))
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200434 u8 port_id;
435 bool b_active;
436
437 u32 dp_module;
438 u8 dp_level;
439 char name[NAME_SIZE];
440
441 bool first_on_engine;
442 bool hw_init_done;
443
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300444 u8 num_funcs_on_engine;
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300445 u8 enabled_func_idx;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300446
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200447 /* BAR access */
448 void __iomem *regview;
449 void __iomem *doorbells;
450 u64 db_phys_addr;
451 unsigned long db_size;
452
453 /* PTT pool */
454 struct qed_ptt_pool *p_ptt_pool;
455
456 /* HW info */
457 struct qed_hw_info hw_info;
458
459 /* rt_array (for init-tool) */
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500460 struct qed_rt_data rt_data;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200461
462 /* SPQ */
463 struct qed_spq *p_spq;
464
465 /* EQ */
466 struct qed_eq *p_eq;
467
468 /* Consolidate Q*/
469 struct qed_consq *p_consq;
470
471 /* Slow-Path definitions */
472 struct tasklet_struct *sp_dpc;
473 bool b_sp_dpc_enabled;
474
475 struct qed_ptt *p_main_ptt;
476 struct qed_ptt *p_dpc_ptt;
477
sudarsana.kalluru@cavium.comd179bd12017-04-26 09:00:53 -0700478 /* PTP will be used only by the leading function.
479 * Usage of all PTP-apis should be synchronized as result.
480 */
481 struct qed_ptt *p_ptp_ptt;
482
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200483 struct qed_sb_sp_info *p_sp_sb;
484 struct qed_sb_attn_info *p_sb_attn;
485
486 /* Protocol related */
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300487 bool using_ll2;
488 struct qed_ll2_info *p_ll2_info;
Yuval Mintz1d6cff42016-12-01 00:21:07 -0800489 struct qed_ooo_info *p_ooo_info;
Ram Amrani51ff1722016-10-01 21:59:57 +0300490 struct qed_rdma_info *p_rdma_info;
Yuval Mintzfc831822016-12-01 00:21:06 -0800491 struct qed_iscsi_info *p_iscsi_info;
Arun Easi1e128c82017-02-15 06:28:22 -0800492 struct qed_fcoe_info *p_fcoe_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200493 struct qed_pf_params pf_params;
494
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300495 bool b_rdma_enabled_in_prs;
496 u32 rdma_prs_search_reg;
497
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200498 struct qed_cxt_mngr *p_cxt_mngr;
499
500 /* Flag indicating whether interrupts are enabled or not*/
501 bool b_int_enabled;
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500502 bool b_int_requested;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200503
Sudarsana Reddy Kallurufc916ff2016-03-09 09:16:23 +0200504 /* True if the driver requests for the link */
505 bool b_drv_link_init;
506
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300507 struct qed_vf_iov *vf_iov_info;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300508 struct qed_pf_iov *pf_iov_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200509 struct qed_mcp_info *mcp_info;
510
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400511 struct qed_dcbx_info *p_dcbx_info;
512
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200513 struct qed_dmae_info dmae_info;
514
515 /* QM init */
516 struct qed_qm_info qm_info;
Manish Chopra9df2ed02015-10-26 11:02:33 +0200517 struct qed_storm_stats storm_stats;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200518
519 /* Buffer for unzipping firmware data */
520 void *unzip_buf;
521
Tomer Tayarc965db42016-09-07 16:36:24 +0300522 struct dbg_tools_data dbg_info;
523
Ram Amrani51ff1722016-10-01 21:59:57 +0300524 /* PWM region specific data */
Ram Amrani20b1bd92017-04-30 11:49:10 +0300525 u16 wid_count;
Ram Amrani51ff1722016-10-01 21:59:57 +0300526 u32 dpi_size;
527 u32 dpi_count;
528
529 /* This is used to calculate the doorbell address */
530 u32 dpi_start_offset;
531
532 /* If one of the following is set then EDPM shouldn't be used */
533 u8 dcbx_no_edpm;
534 u8 db_bar_no_edpm;
535
Mintz, Yuval0db711b2017-06-04 13:31:00 +0300536 /* L2-related */
537 struct qed_l2_info *p_l2_info;
538
Chopra, Manishd51e4af2017-04-13 04:54:44 -0700539 struct qed_ptt *p_arfs_ptt;
540
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200541 struct qed_simd_fp_handler simd_proto_handler[64];
542
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300543#ifdef CONFIG_QED_SRIOV
544 struct workqueue_struct *iov_wq;
545 struct delayed_work iov_task;
546 unsigned long iov_task_flags;
547#endif
548
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200549 struct z_stream_s *stream;
Ram Amraniabd49672016-10-01 22:00:01 +0300550 struct qed_roce_ll2_info *ll2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200551};
552
553struct pci_params {
554 int pm_cap;
555
556 unsigned long mem_start;
557 unsigned long mem_end;
558 unsigned int irq;
559 u8 pf_num;
560};
561
562struct qed_int_param {
563 u32 int_mode;
564 u8 num_vectors;
565 u8 min_msix_cnt; /* for minimal functionality */
566};
567
568struct qed_int_params {
569 struct qed_int_param in;
570 struct qed_int_param out;
571 struct msix_entry *msix_table;
572 bool fp_initialized;
573 u8 fp_msix_base;
574 u8 fp_msix_cnt;
Ram Amrani51ff1722016-10-01 21:59:57 +0300575 u8 rdma_msix_base;
576 u8 rdma_msix_cnt;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200577};
578
Tomer Tayarc965db42016-09-07 16:36:24 +0300579struct qed_dbg_feature {
580 struct dentry *dentry;
581 u8 *dump_buf;
582 u32 buf_size;
583 u32 dumped_dwords;
584};
585
586struct qed_dbg_params {
587 struct qed_dbg_feature features[DBG_FEATURE_NUM];
588 u8 engine_for_debug;
589 bool print_data;
590};
591
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200592struct qed_dev {
593 u32 dp_module;
594 u8 dp_level;
595 char name[NAME_SIZE];
596
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200597 enum qed_dev_type type;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500598/* Translate type/revision combo into the proper conditions */
599#define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500600#define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
601 CHIP_REV_IS_B0(dev))
Tomer Tayarc965db42016-09-07 16:36:24 +0300602#define QED_IS_AH(dev) ((dev)->type == QED_DEV_TYPE_AH)
603#define QED_IS_K2(dev) QED_IS_AH(dev)
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500604
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500605 u16 vendor_id;
606 u16 device_id;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200607#define QED_DEV_ID_MASK 0xff00
608#define QED_DEV_ID_MASK_BB 0x1600
609#define QED_DEV_ID_MASK_AH 0x8000
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200610
611 u16 chip_num;
612#define CHIP_NUM_MASK 0xffff
613#define CHIP_NUM_SHIFT 16
614
615 u16 chip_rev;
616#define CHIP_REV_MASK 0xf
617#define CHIP_REV_SHIFT 12
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500618#define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200619
620 u16 chip_metal;
621#define CHIP_METAL_MASK 0xff
622#define CHIP_METAL_SHIFT 4
623
624 u16 chip_bond_id;
625#define CHIP_BOND_ID_MASK 0xf
626#define CHIP_BOND_ID_SHIFT 0
627
628 u8 num_engines;
Tomer Tayar78cea9f2017-05-23 09:41:22 +0300629 u8 num_ports_in_engine;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200630 u8 num_funcs_in_port;
631
632 u8 path_id;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500633 enum qed_mf_mode mf_mode;
634#define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
635#define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
636#define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200637
638 int pcie_width;
639 int pcie_speed;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200640
641 /* Add MF related configuration */
642 u8 mcp_rev;
643 u8 boot_mode;
644
Mintz, Yuval14d39642016-10-31 07:14:23 +0200645 /* WoL related configurations */
646 u8 wol_config;
647 u8 wol_mac[ETH_ALEN];
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200648
649 u32 int_mode;
650 enum qed_coalescing_mode int_coalescing_mode;
Sudarsana Reddy Kalluru51d99882016-06-28 02:10:58 -0400651 u16 rx_coalesce_usecs;
652 u16 tx_coalesce_usecs;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200653
654 /* Start Bar offset of first hwfn */
655 void __iomem *regview;
656 void __iomem *doorbells;
657 u64 db_phys_addr;
658 unsigned long db_size;
659
660 /* PCI */
661 u8 cache_shift;
662
663 /* Init */
664 const struct iro *iro_arr;
665#define IRO (p_hwfn->cdev->iro_arr)
666
667 /* HW functions */
668 u8 num_hwfns;
669 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
670
Yuval Mintz32a47e72016-05-11 16:36:12 +0300671 /* SRIOV */
672 struct qed_hw_sriov_info *p_iov_info;
673#define IS_QED_SRIOV(cdev) (!!(cdev)->p_iov_info)
Chopra, Manish199684302017-04-24 10:00:44 -0700674 struct qed_tunnel_info tunnel;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300675 bool b_is_vf;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200676 u32 drv_type;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200677 struct qed_eth_stats *reset_stats;
678 struct qed_fw_data *fw_data;
679
680 u32 mcp_nvm_resp;
681
682 /* Linux specific here */
683 struct qede_dev *edev;
684 struct pci_dev *pdev;
Yuval Mintzfc831822016-12-01 00:21:06 -0800685 u32 flags;
686#define QED_FLAG_STORAGE_STARTED (BIT(0))
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200687 int msg_enable;
688
689 struct pci_params pci_params;
690
691 struct qed_int_params int_params;
692
693 u8 protocol;
694#define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
Arun Easi1e128c82017-02-15 06:28:22 -0800695#define IS_QED_FCOE_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_FCOE)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200696
Yuval Mintzcc875c22015-10-26 11:02:31 +0200697 /* Callbacks to protocol driver */
698 union {
699 struct qed_common_cb_ops *common;
700 struct qed_eth_cb_ops *eth;
Arun Easi1e128c82017-02-15 06:28:22 -0800701 struct qed_fcoe_cb_ops *fcoe;
Yuval Mintzfc831822016-12-01 00:21:06 -0800702 struct qed_iscsi_cb_ops *iscsi;
Yuval Mintzcc875c22015-10-26 11:02:31 +0200703 } protocol_ops;
704 void *ops_cookie;
705
Tomer Tayarc965db42016-09-07 16:36:24 +0300706 struct qed_dbg_params dbg_params;
707
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300708#ifdef CONFIG_QED_LL2
709 struct qed_cb_ll2_info *ll2;
710 u8 ll2_mac_address[ETH_ALEN];
711#endif
Yuval Mintzfc831822016-12-01 00:21:06 -0800712 DECLARE_HASHTABLE(connections, 10);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200713 const struct firmware *firmware;
Ram Amrani51ff1722016-10-01 21:59:57 +0300714
715 u32 rdma_max_sge;
716 u32 rdma_max_inline;
717 u32 rdma_max_srq_sge;
Chopra, Manisheaf3c0c2017-04-24 10:00:49 -0700718 u16 tunn_feature_mask;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200719};
720
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200721#define NUM_OF_VFS(dev) (QED_IS_BB(dev) ? MAX_NUM_VFS_BB \
722 : MAX_NUM_VFS_K2)
723#define NUM_OF_L2_QUEUES(dev) (QED_IS_BB(dev) ? MAX_NUM_L2_QUEUES_BB \
724 : MAX_NUM_L2_QUEUES_K2)
725#define NUM_OF_PORTS(dev) (QED_IS_BB(dev) ? MAX_NUM_PORTS_BB \
726 : MAX_NUM_PORTS_K2)
727#define NUM_OF_SBS(dev) (QED_IS_BB(dev) ? MAX_SB_PER_PATH_BB \
728 : MAX_SB_PER_PATH_K2)
729#define NUM_OF_ENG_PFS(dev) (QED_IS_BB(dev) ? MAX_NUM_PFS_BB \
730 : MAX_NUM_PFS_K2)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200731
732/**
733 * @brief qed_concrete_to_sw_fid - get the sw function id from
734 * the concrete value.
735 *
736 * @param concrete_fid
737 *
738 * @return inline u8
739 */
740static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
741 u32 concrete_fid)
742{
Yuval Mintz4870e702016-08-22 12:03:29 +0300743 u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200744 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
Yuval Mintz4870e702016-08-22 12:03:29 +0300745 u8 vf_valid = GET_FIELD(concrete_fid,
746 PXP_CONCRETE_FID_VFVALID);
747 u8 sw_fid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200748
Yuval Mintz4870e702016-08-22 12:03:29 +0300749 if (vf_valid)
750 sw_fid = vfid + MAX_NUM_PFS;
751 else
752 sw_fid = pfid;
753
754 return sw_fid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200755}
756
757#define PURE_LB_TC 8
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300758#define OOO_LB_TC 9
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200759
Yuval Mintz733def62016-05-11 16:36:22 +0300760int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate);
Mintz, Yuval6f437d42017-02-27 11:06:33 +0200761void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
762 struct qed_ptt *p_ptt,
763 u32 min_pf_rate);
Manish Choprabcd197c2016-04-26 10:56:08 -0400764
Yuval Mintz733def62016-05-11 16:36:22 +0300765void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200766int qed_device_num_engines(struct qed_dev *cdev);
sudarsana.kalluru@cavium.comdb82f702017-04-26 09:00:50 -0700767int qed_device_get_port_id(struct qed_dev *cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200768
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300769#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
770
771/* Flags for indication of required queues */
772#define PQ_FLAGS_RLS (BIT(0))
773#define PQ_FLAGS_MCOS (BIT(1))
774#define PQ_FLAGS_LB (BIT(2))
775#define PQ_FLAGS_OOO (BIT(3))
776#define PQ_FLAGS_ACK (BIT(4))
777#define PQ_FLAGS_OFLD (BIT(5))
778#define PQ_FLAGS_VFS (BIT(6))
779#define PQ_FLAGS_LLT (BIT(7))
780
781/* physical queue index for cm context intialization */
782u16 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags);
783u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc);
784u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf);
785
786#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
787
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200788/* Other Linux specific common definitions */
789#define DP_NAME(cdev) ((cdev)->name)
790
791#define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
792 (cdev->regview) + \
793 (offset))
794
795#define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
796#define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
797#define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
798
799#define DOORBELL(cdev, db_addr, val) \
800 writel((u32)val, (void __iomem *)((u8 __iomem *)\
801 (cdev->doorbells) + (db_addr)))
802
803/* Prototypes */
804int qed_fill_dev_info(struct qed_dev *cdev,
805 struct qed_dev_info *dev_info);
Yuval Mintzcc875c22015-10-26 11:02:31 +0200806void qed_link_update(struct qed_hwfn *hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200807u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
808 u32 input_len, u8 *input_buf,
809 u32 max_size, u8 *unzip_buf);
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -0400810void qed_get_protocol_stats(struct qed_dev *cdev,
811 enum qed_mcp_protocol_type type,
812 union qed_mcp_protocol_stats *stats);
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500813int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
Tomer Tayar12263372017-03-28 15:12:50 +0300814void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn);
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500815
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200816#endif /* _QED_H */