blob: ca30a27df03511039e502fecd8f5b699cb2482de [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;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +020054#define DRV_MODULE_VERSION "8.10.10.21"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020055
56#define MAX_HWFNS_PER_DEVICE (4)
57#define NAME_SIZE 16
58#define VER_SIZE 16
59
Manish Choprabcd197c2016-04-26 10:56:08 -040060#define QED_WFQ_UNIT 100
61
Yuval Mintzfc831822016-12-01 00:21:06 -080062#define ISCSI_BDQ_ID(_port_id) (_port_id)
Arun Easi1e128c82017-02-15 06:28:22 -080063#define FCOE_BDQ_ID(_port_id) ((_port_id) + 2)
Ram Amrani51ff1722016-10-01 21:59:57 +030064#define QED_WID_SIZE (1024)
65#define QED_PF_DEMS_SIZE (4)
66
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020067/* cau states */
68enum qed_coalescing_mode {
69 QED_COAL_MODE_DISABLE,
70 QED_COAL_MODE_ENABLE
71};
72
73struct qed_eth_cb_ops;
74struct qed_dev_info;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -040075union qed_mcp_protocol_stats;
76enum qed_mcp_protocol_type;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020077
78/* helpers */
79static inline u32 qed_db_addr(u32 cid, u32 DEMS)
80{
81 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
Ram Amrani51ff1722016-10-01 21:59:57 +030082 (cid * QED_PF_DEMS_SIZE);
83
84 return db_addr;
85}
86
87static inline u32 qed_db_addr_vf(u32 cid, u32 DEMS)
88{
89 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020090 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
91
92 return db_addr;
93}
94
95#define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
96 ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
97 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
98
99#define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
100
101#define D_TRINE(val, cond1, cond2, true1, true2, def) \
102 (val == (cond1) ? true1 : \
103 (val == (cond2) ? true2 : def))
104
105/* forward */
106struct qed_ptt_pool;
107struct qed_spq;
108struct qed_sb_info;
109struct qed_sb_attn_info;
110struct qed_cxt_mngr;
111struct qed_sb_sp_info;
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300112struct qed_ll2_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200113struct qed_mcp_info;
114
115struct qed_rt_data {
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500116 u32 *init_val;
117 bool *b_valid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200118};
119
Manish Chopra464f6642016-04-14 01:38:29 -0400120enum qed_tunn_mode {
121 QED_MODE_L2GENEVE_TUNN,
122 QED_MODE_IPGENEVE_TUNN,
123 QED_MODE_L2GRE_TUNN,
124 QED_MODE_IPGRE_TUNN,
125 QED_MODE_VXLAN_TUNN,
126};
127
128enum qed_tunn_clss {
129 QED_TUNN_CLSS_MAC_VLAN,
130 QED_TUNN_CLSS_MAC_VNI,
131 QED_TUNN_CLSS_INNER_MAC_VLAN,
132 QED_TUNN_CLSS_INNER_MAC_VNI,
133 MAX_QED_TUNN_CLSS,
134};
135
136struct qed_tunn_start_params {
137 unsigned long tunn_mode;
138 u16 vxlan_udp_port;
139 u16 geneve_udp_port;
140 u8 update_vxlan_udp_port;
141 u8 update_geneve_udp_port;
142 u8 tunn_clss_vxlan;
143 u8 tunn_clss_l2geneve;
144 u8 tunn_clss_ipgeneve;
145 u8 tunn_clss_l2gre;
146 u8 tunn_clss_ipgre;
147};
148
149struct qed_tunn_update_params {
150 unsigned long tunn_mode_update_mask;
151 unsigned long tunn_mode;
152 u16 vxlan_udp_port;
153 u16 geneve_udp_port;
154 u8 update_rx_pf_clss;
155 u8 update_tx_pf_clss;
156 u8 update_vxlan_udp_port;
157 u8 update_geneve_udp_port;
158 u8 tunn_clss_vxlan;
159 u8 tunn_clss_l2geneve;
160 u8 tunn_clss_ipgeneve;
161 u8 tunn_clss_l2gre;
162 u8 tunn_clss_ipgre;
163};
164
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200165/* The PCI personality is not quite synonymous to protocol ID:
166 * 1. All personalities need CORE connections
167 * 2. The Ethernet personality may support also the RoCE protocol
168 */
169enum qed_pci_personality {
170 QED_PCI_ETH,
Arun Easi1e128c82017-02-15 06:28:22 -0800171 QED_PCI_FCOE,
Yuval Mintzc5ac9312016-06-03 14:35:34 +0300172 QED_PCI_ISCSI,
173 QED_PCI_ETH_ROCE,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200174 QED_PCI_DEFAULT /* default in shmem */
175};
176
177/* All VFs are symmetric, all counters are PF + all VFs */
178struct qed_qm_iids {
179 u32 cids;
180 u32 vf_cids;
181 u32 tids;
182};
183
Tomer Tayar2edbff82016-10-31 07:14:27 +0200184/* HW / FW resources, output of features supported below, most information
185 * is received from MFW.
186 */
187enum qed_resources {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200188 QED_SB,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200189 QED_L2_QUEUE,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200190 QED_VPORT,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200191 QED_RSS_ENG,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200192 QED_PQ,
193 QED_RL,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200194 QED_MAC,
195 QED_VLAN,
Ram Amrani51ff1722016-10-01 21:59:57 +0300196 QED_RDMA_CNQ_RAM,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200197 QED_ILT,
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300198 QED_LL2_QUEUE,
Tomer Tayar2edbff82016-10-31 07:14:27 +0200199 QED_CMDQS_CQS,
Ram Amrani51ff1722016-10-01 21:59:57 +0300200 QED_RDMA_STATS_QUEUE,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200201 QED_MAX_RESC,
202};
203
Yuval Mintz25c089d2015-10-26 11:02:26 +0200204enum QED_FEATURE {
205 QED_PF_L2_QUE,
Yuval Mintz32a47e72016-05-11 16:36:12 +0300206 QED_VF,
Ram Amrani51ff1722016-10-01 21:59:57 +0300207 QED_RDMA_CNQ,
Mintz, Yuval5a1f9652016-10-31 07:14:26 +0200208 QED_VF_L2_QUE,
Arun Easi1e128c82017-02-15 06:28:22 -0800209 QED_FCOE_CQ,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200210 QED_MAX_FEATURES,
211};
212
Yuval Mintzcc875c22015-10-26 11:02:31 +0200213enum QED_PORT_MODE {
214 QED_PORT_MODE_DE_2X40G,
215 QED_PORT_MODE_DE_2X50G,
216 QED_PORT_MODE_DE_1X100G,
217 QED_PORT_MODE_DE_4X10G_F,
218 QED_PORT_MODE_DE_4X10G_E,
219 QED_PORT_MODE_DE_4X20G,
220 QED_PORT_MODE_DE_1X40G,
221 QED_PORT_MODE_DE_2X25G,
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200222 QED_PORT_MODE_DE_1X25G,
223 QED_PORT_MODE_DE_4X25G,
224 QED_PORT_MODE_DE_2X10G,
Yuval Mintzcc875c22015-10-26 11:02:31 +0200225};
226
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500227enum qed_dev_cap {
228 QED_DEV_CAP_ETH,
Arun Easi1e128c82017-02-15 06:28:22 -0800229 QED_DEV_CAP_FCOE,
Yuval Mintzc5ac9312016-06-03 14:35:34 +0300230 QED_DEV_CAP_ISCSI,
231 QED_DEV_CAP_ROCE,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500232};
233
Mintz, Yuval14d39642016-10-31 07:14:23 +0200234enum qed_wol_support {
235 QED_WOL_SUPPORT_NONE,
236 QED_WOL_SUPPORT_PME,
237};
238
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200239struct qed_hw_info {
240 /* PCI personality */
241 enum qed_pci_personality personality;
242
243 /* Resource Allocation scheme results */
244 u32 resc_start[QED_MAX_RESC];
245 u32 resc_num[QED_MAX_RESC];
Yuval Mintz25c089d2015-10-26 11:02:26 +0200246 u32 feat_num[QED_MAX_FEATURES];
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200247
248#define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
249#define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300250#define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
251 RESC_NUM(_p_hwfn, resc))
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200252#define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
253
254 u8 num_tc;
255 u8 offload_tc;
256 u8 non_offload_tc;
257
258 u32 concrete_fid;
259 u16 opaque_fid;
260 u16 ovlan;
261 u32 part_num[4];
262
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200263 unsigned char hw_mac_addr[ETH_ALEN];
Arun Easi1e128c82017-02-15 06:28:22 -0800264 u64 node_wwn;
265 u64 port_wwn;
266
267 u16 num_fcoe_conns;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200268
269 struct qed_igu_info *p_igu_info;
270
271 u32 port_mode;
272 u32 hw_mode;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500273 unsigned long device_capabilities;
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200274 u16 mtu;
Mintz, Yuval14d39642016-10-31 07:14:23 +0200275
276 enum qed_wol_support b_wol_support;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200277};
278
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200279/* maximun size of read/write commands (HW limit) */
280#define DMAE_MAX_RW_SIZE 0x2000
281
282struct qed_dmae_info {
283 /* Mutex for synchronizing access to functions */
284 struct mutex mutex;
285
286 u8 channel;
287
288 dma_addr_t completion_word_phys_addr;
289
290 /* The memory location where the DMAE writes the completion
291 * value when an operation is finished on this context.
292 */
293 u32 *p_completion_word;
294
295 dma_addr_t intermediate_buffer_phys_addr;
296
297 /* An intermediate buffer for DMAE operations that use virtual
298 * addresses - data is DMA'd to/from this buffer and then
299 * memcpy'd to/from the virtual address
300 */
301 u32 *p_intermediate_buffer;
302
303 dma_addr_t dmae_cmd_phys_addr;
304 struct dmae_cmd *p_dmae_cmd;
305};
306
Manish Choprabcd197c2016-04-26 10:56:08 -0400307struct qed_wfq_data {
308 /* when feature is configured for at least 1 vport */
309 u32 min_speed;
310 bool configured;
311};
312
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200313struct qed_qm_info {
314 struct init_qm_pq_params *qm_pq_params;
315 struct init_qm_vport_params *qm_vport_params;
316 struct init_qm_port_params *qm_port_params;
317 u16 start_pq;
318 u8 start_vport;
319 u8 pure_lb_pq;
320 u8 offload_pq;
321 u8 pure_ack_pq;
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300322 u8 ooo_pq;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200323 u8 vf_queues_offset;
324 u16 num_pqs;
325 u16 num_vf_pqs;
326 u8 num_vports;
327 u8 max_phys_tcs_per_port;
328 bool pf_rl_en;
329 bool pf_wfq_en;
330 bool vport_rl_en;
331 bool vport_wfq_en;
332 u8 pf_wfq;
333 u32 pf_rl;
Manish Choprabcd197c2016-04-26 10:56:08 -0400334 struct qed_wfq_data *wfq_data;
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300335 u8 num_pf_rls;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200336};
337
Manish Chopra9df2ed02015-10-26 11:02:33 +0200338struct storm_stats {
339 u32 address;
340 u32 len;
341};
342
343struct qed_storm_stats {
344 struct storm_stats mstats;
345 struct storm_stats pstats;
346 struct storm_stats tstats;
347 struct storm_stats ustats;
348};
349
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200350struct qed_fw_data {
Manish Chopra9df2ed02015-10-26 11:02:33 +0200351 struct fw_ver_info *fw_ver_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200352 const u8 *modes_tree_buf;
353 union init_op *init_ops;
354 const u32 *arr_data;
355 u32 init_ops_size;
356};
357
358struct qed_simd_fp_handler {
359 void *token;
360 void (*func)(void *);
361};
362
363struct qed_hwfn {
364 struct qed_dev *cdev;
365 u8 my_id; /* ID inside the PF */
366#define IS_LEAD_HWFN(edev) (!((edev)->my_id))
367 u8 rel_pf_id; /* Relative to engine*/
368 u8 abs_pf_id;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200369#define QED_PATH_ID(_p_hwfn) \
370 (QED_IS_K2((_p_hwfn)->cdev) ? 0 : ((_p_hwfn)->abs_pf_id & 1))
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200371 u8 port_id;
372 bool b_active;
373
374 u32 dp_module;
375 u8 dp_level;
376 char name[NAME_SIZE];
377
378 bool first_on_engine;
379 bool hw_init_done;
380
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300381 u8 num_funcs_on_engine;
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300382 u8 enabled_func_idx;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300383
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200384 /* BAR access */
385 void __iomem *regview;
386 void __iomem *doorbells;
387 u64 db_phys_addr;
388 unsigned long db_size;
389
390 /* PTT pool */
391 struct qed_ptt_pool *p_ptt_pool;
392
393 /* HW info */
394 struct qed_hw_info hw_info;
395
396 /* rt_array (for init-tool) */
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500397 struct qed_rt_data rt_data;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200398
399 /* SPQ */
400 struct qed_spq *p_spq;
401
402 /* EQ */
403 struct qed_eq *p_eq;
404
405 /* Consolidate Q*/
406 struct qed_consq *p_consq;
407
408 /* Slow-Path definitions */
409 struct tasklet_struct *sp_dpc;
410 bool b_sp_dpc_enabled;
411
412 struct qed_ptt *p_main_ptt;
413 struct qed_ptt *p_dpc_ptt;
414
415 struct qed_sb_sp_info *p_sp_sb;
416 struct qed_sb_attn_info *p_sb_attn;
417
418 /* Protocol related */
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300419 bool using_ll2;
420 struct qed_ll2_info *p_ll2_info;
Yuval Mintz1d6cff42016-12-01 00:21:07 -0800421 struct qed_ooo_info *p_ooo_info;
Ram Amrani51ff1722016-10-01 21:59:57 +0300422 struct qed_rdma_info *p_rdma_info;
Yuval Mintzfc831822016-12-01 00:21:06 -0800423 struct qed_iscsi_info *p_iscsi_info;
Arun Easi1e128c82017-02-15 06:28:22 -0800424 struct qed_fcoe_info *p_fcoe_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200425 struct qed_pf_params pf_params;
426
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300427 bool b_rdma_enabled_in_prs;
428 u32 rdma_prs_search_reg;
429
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200430 /* Array of sb_info of all status blocks */
431 struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD];
432 u16 num_sbs;
433
434 struct qed_cxt_mngr *p_cxt_mngr;
435
436 /* Flag indicating whether interrupts are enabled or not*/
437 bool b_int_enabled;
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500438 bool b_int_requested;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200439
Sudarsana Reddy Kallurufc916ff2016-03-09 09:16:23 +0200440 /* True if the driver requests for the link */
441 bool b_drv_link_init;
442
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300443 struct qed_vf_iov *vf_iov_info;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300444 struct qed_pf_iov *pf_iov_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200445 struct qed_mcp_info *mcp_info;
446
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400447 struct qed_dcbx_info *p_dcbx_info;
448
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200449 struct qed_dmae_info dmae_info;
450
451 /* QM init */
452 struct qed_qm_info qm_info;
Manish Chopra9df2ed02015-10-26 11:02:33 +0200453 struct qed_storm_stats storm_stats;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200454
455 /* Buffer for unzipping firmware data */
456 void *unzip_buf;
457
Tomer Tayarc965db42016-09-07 16:36:24 +0300458 struct dbg_tools_data dbg_info;
459
Ram Amrani51ff1722016-10-01 21:59:57 +0300460 /* PWM region specific data */
461 u32 dpi_size;
462 u32 dpi_count;
463
464 /* This is used to calculate the doorbell address */
465 u32 dpi_start_offset;
466
467 /* If one of the following is set then EDPM shouldn't be used */
468 u8 dcbx_no_edpm;
469 u8 db_bar_no_edpm;
470
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +0200471 /* p_ptp_ptt is valid for leading HWFN only */
472 struct qed_ptt *p_ptp_ptt;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200473 struct qed_simd_fp_handler simd_proto_handler[64];
474
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300475#ifdef CONFIG_QED_SRIOV
476 struct workqueue_struct *iov_wq;
477 struct delayed_work iov_task;
478 unsigned long iov_task_flags;
479#endif
480
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200481 struct z_stream_s *stream;
Ram Amraniabd49672016-10-01 22:00:01 +0300482 struct qed_roce_ll2_info *ll2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200483};
484
485struct pci_params {
486 int pm_cap;
487
488 unsigned long mem_start;
489 unsigned long mem_end;
490 unsigned int irq;
491 u8 pf_num;
492};
493
494struct qed_int_param {
495 u32 int_mode;
496 u8 num_vectors;
497 u8 min_msix_cnt; /* for minimal functionality */
498};
499
500struct qed_int_params {
501 struct qed_int_param in;
502 struct qed_int_param out;
503 struct msix_entry *msix_table;
504 bool fp_initialized;
505 u8 fp_msix_base;
506 u8 fp_msix_cnt;
Ram Amrani51ff1722016-10-01 21:59:57 +0300507 u8 rdma_msix_base;
508 u8 rdma_msix_cnt;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200509};
510
Tomer Tayarc965db42016-09-07 16:36:24 +0300511struct qed_dbg_feature {
512 struct dentry *dentry;
513 u8 *dump_buf;
514 u32 buf_size;
515 u32 dumped_dwords;
516};
517
518struct qed_dbg_params {
519 struct qed_dbg_feature features[DBG_FEATURE_NUM];
520 u8 engine_for_debug;
521 bool print_data;
522};
523
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200524struct qed_dev {
525 u32 dp_module;
526 u8 dp_level;
527 char name[NAME_SIZE];
528
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200529 enum qed_dev_type type;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500530/* Translate type/revision combo into the proper conditions */
531#define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
532#define QED_IS_BB_A0(dev) (QED_IS_BB(dev) && \
533 CHIP_REV_IS_A0(dev))
534#define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
535 CHIP_REV_IS_B0(dev))
Tomer Tayarc965db42016-09-07 16:36:24 +0300536#define QED_IS_AH(dev) ((dev)->type == QED_DEV_TYPE_AH)
537#define QED_IS_K2(dev) QED_IS_AH(dev)
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500538
539#define QED_GET_TYPE(dev) (QED_IS_BB_A0(dev) ? CHIP_BB_A0 : \
540 QED_IS_BB_B0(dev) ? CHIP_BB_B0 : CHIP_K2)
541
542 u16 vendor_id;
543 u16 device_id;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200544#define QED_DEV_ID_MASK 0xff00
545#define QED_DEV_ID_MASK_BB 0x1600
546#define QED_DEV_ID_MASK_AH 0x8000
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200547
548 u16 chip_num;
549#define CHIP_NUM_MASK 0xffff
550#define CHIP_NUM_SHIFT 16
551
552 u16 chip_rev;
553#define CHIP_REV_MASK 0xf
554#define CHIP_REV_SHIFT 12
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500555#define CHIP_REV_IS_A0(_cdev) (!(_cdev)->chip_rev)
556#define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200557
558 u16 chip_metal;
559#define CHIP_METAL_MASK 0xff
560#define CHIP_METAL_SHIFT 4
561
562 u16 chip_bond_id;
563#define CHIP_BOND_ID_MASK 0xf
564#define CHIP_BOND_ID_SHIFT 0
565
566 u8 num_engines;
567 u8 num_ports_in_engines;
568 u8 num_funcs_in_port;
569
570 u8 path_id;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500571 enum qed_mf_mode mf_mode;
572#define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
573#define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
574#define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200575
576 int pcie_width;
577 int pcie_speed;
578 u8 ver_str[VER_SIZE];
579
580 /* Add MF related configuration */
581 u8 mcp_rev;
582 u8 boot_mode;
583
Mintz, Yuval14d39642016-10-31 07:14:23 +0200584 /* WoL related configurations */
585 u8 wol_config;
586 u8 wol_mac[ETH_ALEN];
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200587
588 u32 int_mode;
589 enum qed_coalescing_mode int_coalescing_mode;
Sudarsana Reddy Kalluru51d99882016-06-28 02:10:58 -0400590 u16 rx_coalesce_usecs;
591 u16 tx_coalesce_usecs;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200592
593 /* Start Bar offset of first hwfn */
594 void __iomem *regview;
595 void __iomem *doorbells;
596 u64 db_phys_addr;
597 unsigned long db_size;
598
599 /* PCI */
600 u8 cache_shift;
601
602 /* Init */
603 const struct iro *iro_arr;
604#define IRO (p_hwfn->cdev->iro_arr)
605
606 /* HW functions */
607 u8 num_hwfns;
608 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
609
Yuval Mintz32a47e72016-05-11 16:36:12 +0300610 /* SRIOV */
611 struct qed_hw_sriov_info *p_iov_info;
612#define IS_QED_SRIOV(cdev) (!!(cdev)->p_iov_info)
613
Manish Chopra464f6642016-04-14 01:38:29 -0400614 unsigned long tunn_mode;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300615
616 bool b_is_vf;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200617 u32 drv_type;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200618 struct qed_eth_stats *reset_stats;
619 struct qed_fw_data *fw_data;
620
621 u32 mcp_nvm_resp;
622
623 /* Linux specific here */
624 struct qede_dev *edev;
625 struct pci_dev *pdev;
Yuval Mintzfc831822016-12-01 00:21:06 -0800626 u32 flags;
627#define QED_FLAG_STORAGE_STARTED (BIT(0))
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200628 int msg_enable;
629
630 struct pci_params pci_params;
631
632 struct qed_int_params int_params;
633
634 u8 protocol;
635#define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
Arun Easi1e128c82017-02-15 06:28:22 -0800636#define IS_QED_FCOE_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_FCOE)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200637
Yuval Mintzcc875c22015-10-26 11:02:31 +0200638 /* Callbacks to protocol driver */
639 union {
640 struct qed_common_cb_ops *common;
641 struct qed_eth_cb_ops *eth;
Arun Easi1e128c82017-02-15 06:28:22 -0800642 struct qed_fcoe_cb_ops *fcoe;
Yuval Mintzfc831822016-12-01 00:21:06 -0800643 struct qed_iscsi_cb_ops *iscsi;
Yuval Mintzcc875c22015-10-26 11:02:31 +0200644 } protocol_ops;
645 void *ops_cookie;
646
Tomer Tayarc965db42016-09-07 16:36:24 +0300647 struct qed_dbg_params dbg_params;
648
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300649#ifdef CONFIG_QED_LL2
650 struct qed_cb_ll2_info *ll2;
651 u8 ll2_mac_address[ETH_ALEN];
652#endif
Yuval Mintzfc831822016-12-01 00:21:06 -0800653 DECLARE_HASHTABLE(connections, 10);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200654 const struct firmware *firmware;
Ram Amrani51ff1722016-10-01 21:59:57 +0300655
656 u32 rdma_max_sge;
657 u32 rdma_max_inline;
658 u32 rdma_max_srq_sge;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200659};
660
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200661#define NUM_OF_VFS(dev) (QED_IS_BB(dev) ? MAX_NUM_VFS_BB \
662 : MAX_NUM_VFS_K2)
663#define NUM_OF_L2_QUEUES(dev) (QED_IS_BB(dev) ? MAX_NUM_L2_QUEUES_BB \
664 : MAX_NUM_L2_QUEUES_K2)
665#define NUM_OF_PORTS(dev) (QED_IS_BB(dev) ? MAX_NUM_PORTS_BB \
666 : MAX_NUM_PORTS_K2)
667#define NUM_OF_SBS(dev) (QED_IS_BB(dev) ? MAX_SB_PER_PATH_BB \
668 : MAX_SB_PER_PATH_K2)
669#define NUM_OF_ENG_PFS(dev) (QED_IS_BB(dev) ? MAX_NUM_PFS_BB \
670 : MAX_NUM_PFS_K2)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200671
672/**
673 * @brief qed_concrete_to_sw_fid - get the sw function id from
674 * the concrete value.
675 *
676 * @param concrete_fid
677 *
678 * @return inline u8
679 */
680static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
681 u32 concrete_fid)
682{
Yuval Mintz4870e702016-08-22 12:03:29 +0300683 u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200684 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
Yuval Mintz4870e702016-08-22 12:03:29 +0300685 u8 vf_valid = GET_FIELD(concrete_fid,
686 PXP_CONCRETE_FID_VFVALID);
687 u8 sw_fid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200688
Yuval Mintz4870e702016-08-22 12:03:29 +0300689 if (vf_valid)
690 sw_fid = vfid + MAX_NUM_PFS;
691 else
692 sw_fid = pfid;
693
694 return sw_fid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200695}
696
697#define PURE_LB_TC 8
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300698#define OOO_LB_TC 9
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200699
Yuval Mintz733def62016-05-11 16:36:22 +0300700int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate);
Mintz, Yuval6f437d42017-02-27 11:06:33 +0200701void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
702 struct qed_ptt *p_ptt,
703 u32 min_pf_rate);
Manish Choprabcd197c2016-04-26 10:56:08 -0400704
Yuval Mintz733def62016-05-11 16:36:22 +0300705void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200706#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200707int qed_device_num_engines(struct qed_dev *cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200708
709/* Other Linux specific common definitions */
710#define DP_NAME(cdev) ((cdev)->name)
711
712#define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
713 (cdev->regview) + \
714 (offset))
715
716#define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
717#define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
718#define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
719
720#define DOORBELL(cdev, db_addr, val) \
721 writel((u32)val, (void __iomem *)((u8 __iomem *)\
722 (cdev->doorbells) + (db_addr)))
723
724/* Prototypes */
725int qed_fill_dev_info(struct qed_dev *cdev,
726 struct qed_dev_info *dev_info);
Yuval Mintzcc875c22015-10-26 11:02:31 +0200727void qed_link_update(struct qed_hwfn *hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200728u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
729 u32 input_len, u8 *input_buf,
730 u32 max_size, u8 *unzip_buf);
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -0400731void qed_get_protocol_stats(struct qed_dev *cdev,
732 enum qed_mcp_protocol_type type,
733 union qed_mcp_protocol_stats *stats);
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500734int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
735
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200736#endif /* _QED_H */