]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/ethernet/qlogic/qed/qed.h
qed: Acquire/release ptt_ptp lock when enabling/disabling PTP.
[mirror_ubuntu-artful-kernel.git] / drivers / net / ethernet / qlogic / qed / qed.h
CommitLineData
fe56b9e6 1/* QLogic qed NIC Driver
e8f1cb50 2 * Copyright (c) 2015-2017 QLogic Corporation
fe56b9e6 3 *
e8f1cb50
MY
4 * 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.
fe56b9e6
YM
31 */
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>
c965db44 50#include "qed_debug.h"
fe56b9e6
YM
51#include "qed_hsi.h"
52
25c089d7 53extern const struct qed_common_ops qed_common_ops_pass;
5d24bcf1
TT
54
55#define QED_MAJOR_VERSION 8
56#define QED_MINOR_VERSION 10
57#define QED_REVISION_VERSION 10
58#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)
fe56b9e6
YM
67
68#define MAX_HWFNS_PER_DEVICE (4)
69#define NAME_SIZE 16
70#define VER_SIZE 16
71
bcd197c8
MC
72#define QED_WFQ_UNIT 100
73
51ff1725
RA
74#define QED_WID_SIZE (1024)
75#define QED_PF_DEMS_SIZE (4)
76
fe56b9e6
YM
77/* cau states */
78enum qed_coalescing_mode {
79 QED_COAL_MODE_DISABLE,
80 QED_COAL_MODE_ENABLE
81};
82
83struct qed_eth_cb_ops;
84struct qed_dev_info;
6c754246
SRK
85union qed_mcp_protocol_stats;
86enum qed_mcp_protocol_type;
fe56b9e6
YM
87
88/* helpers */
5d24bcf1
TT
89#define QED_MFW_GET_FIELD(name, field) \
90 (((name) & (field ## _MASK)) >> (field ## _SHIFT))
91
92#define QED_MFW_SET_FIELD(name, field, value) \
93 do { \
94 (name) &= ~((field ## _MASK) << (field ## _SHIFT)); \
95 (name) |= (((value) << (field ## _SHIFT)) & (field ## _MASK));\
96 } while (0)
97
fe56b9e6 98static inline u32 qed_db_addr(u32 cid, u32 DEMS)
51ff1725
RA
99{
100 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
101 (cid * QED_PF_DEMS_SIZE);
102
103 return db_addr;
104}
105
106static inline u32 qed_db_addr_vf(u32 cid, u32 DEMS)
fe56b9e6
YM
107{
108 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
109 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
110
111 return db_addr;
112}
113
114#define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
115 ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
116 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
117
118#define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
119
120#define D_TRINE(val, cond1, cond2, true1, true2, def) \
121 (val == (cond1) ? true1 : \
122 (val == (cond2) ? true2 : def))
123
124/* forward */
125struct qed_ptt_pool;
126struct qed_spq;
127struct qed_sb_info;
128struct qed_sb_attn_info;
129struct qed_cxt_mngr;
130struct qed_sb_sp_info;
0a7fb11c 131struct qed_ll2_info;
fe56b9e6
YM
132struct qed_mcp_info;
133
134struct qed_rt_data {
fc48b7a6
YM
135 u32 *init_val;
136 bool *b_valid;
fe56b9e6
YM
137};
138
464f6645
MC
139enum qed_tunn_mode {
140 QED_MODE_L2GENEVE_TUNN,
141 QED_MODE_IPGENEVE_TUNN,
142 QED_MODE_L2GRE_TUNN,
143 QED_MODE_IPGRE_TUNN,
144 QED_MODE_VXLAN_TUNN,
145};
146
147enum qed_tunn_clss {
148 QED_TUNN_CLSS_MAC_VLAN,
149 QED_TUNN_CLSS_MAC_VNI,
150 QED_TUNN_CLSS_INNER_MAC_VLAN,
151 QED_TUNN_CLSS_INNER_MAC_VNI,
19968430 152 QED_TUNN_CLSS_MAC_VLAN_DUAL_STAGE,
464f6645
MC
153 MAX_QED_TUNN_CLSS,
154};
155
19968430
CM
156struct qed_tunn_update_type {
157 bool b_update_mode;
158 bool b_mode_enabled;
159 enum qed_tunn_clss tun_cls;
160};
161
162struct qed_tunn_update_udp_port {
163 bool b_update_port;
164 u16 port;
165};
166
167struct qed_tunnel_info {
168 struct qed_tunn_update_type vxlan;
169 struct qed_tunn_update_type l2_geneve;
170 struct qed_tunn_update_type ip_geneve;
171 struct qed_tunn_update_type l2_gre;
172 struct qed_tunn_update_type ip_gre;
173
174 struct qed_tunn_update_udp_port vxlan_port;
175 struct qed_tunn_update_udp_port geneve_port;
176
177 bool b_update_rx_cls;
178 bool b_update_tx_cls;
179};
180
464f6645
MC
181struct qed_tunn_start_params {
182 unsigned long tunn_mode;
183 u16 vxlan_udp_port;
184 u16 geneve_udp_port;
185 u8 update_vxlan_udp_port;
186 u8 update_geneve_udp_port;
187 u8 tunn_clss_vxlan;
188 u8 tunn_clss_l2geneve;
189 u8 tunn_clss_ipgeneve;
190 u8 tunn_clss_l2gre;
191 u8 tunn_clss_ipgre;
192};
193
194struct qed_tunn_update_params {
195 unsigned long tunn_mode_update_mask;
196 unsigned long tunn_mode;
197 u16 vxlan_udp_port;
198 u16 geneve_udp_port;
199 u8 update_rx_pf_clss;
200 u8 update_tx_pf_clss;
201 u8 update_vxlan_udp_port;
202 u8 update_geneve_udp_port;
203 u8 tunn_clss_vxlan;
204 u8 tunn_clss_l2geneve;
205 u8 tunn_clss_ipgeneve;
206 u8 tunn_clss_l2gre;
207 u8 tunn_clss_ipgre;
208};
209
fe56b9e6
YM
210/* The PCI personality is not quite synonymous to protocol ID:
211 * 1. All personalities need CORE connections
212 * 2. The Ethernet personality may support also the RoCE protocol
213 */
214enum qed_pci_personality {
215 QED_PCI_ETH,
1e128c81 216 QED_PCI_FCOE,
c5ac9319
YM
217 QED_PCI_ISCSI,
218 QED_PCI_ETH_ROCE,
fe56b9e6
YM
219 QED_PCI_DEFAULT /* default in shmem */
220};
221
222/* All VFs are symmetric, all counters are PF + all VFs */
223struct qed_qm_iids {
224 u32 cids;
225 u32 vf_cids;
226 u32 tids;
227};
228
2edbff8d
TT
229/* HW / FW resources, output of features supported below, most information
230 * is received from MFW.
231 */
232enum qed_resources {
fe56b9e6 233 QED_SB,
25c089d7 234 QED_L2_QUEUE,
fe56b9e6 235 QED_VPORT,
25c089d7 236 QED_RSS_ENG,
fe56b9e6
YM
237 QED_PQ,
238 QED_RL,
25c089d7
YM
239 QED_MAC,
240 QED_VLAN,
51ff1725 241 QED_RDMA_CNQ_RAM,
fe56b9e6 242 QED_ILT,
0a7fb11c 243 QED_LL2_QUEUE,
2edbff8d 244 QED_CMDQS_CQS,
51ff1725 245 QED_RDMA_STATS_QUEUE,
9c8517c4 246 QED_BDQ,
fe56b9e6
YM
247 QED_MAX_RESC,
248};
249
25c089d7
YM
250enum QED_FEATURE {
251 QED_PF_L2_QUE,
32a47e72 252 QED_VF,
51ff1725 253 QED_RDMA_CNQ,
08737a3f 254 QED_ISCSI_CQ,
1e128c81 255 QED_FCOE_CQ,
08737a3f 256 QED_VF_L2_QUE,
25c089d7
YM
257 QED_MAX_FEATURES,
258};
259
cc875c2e
YM
260enum QED_PORT_MODE {
261 QED_PORT_MODE_DE_2X40G,
262 QED_PORT_MODE_DE_2X50G,
263 QED_PORT_MODE_DE_1X100G,
264 QED_PORT_MODE_DE_4X10G_F,
265 QED_PORT_MODE_DE_4X10G_E,
266 QED_PORT_MODE_DE_4X20G,
267 QED_PORT_MODE_DE_1X40G,
268 QED_PORT_MODE_DE_2X25G,
9c79ddaa
MY
269 QED_PORT_MODE_DE_1X25G,
270 QED_PORT_MODE_DE_4X25G,
271 QED_PORT_MODE_DE_2X10G,
cc875c2e
YM
272};
273
fc48b7a6
YM
274enum qed_dev_cap {
275 QED_DEV_CAP_ETH,
1e128c81 276 QED_DEV_CAP_FCOE,
c5ac9319
YM
277 QED_DEV_CAP_ISCSI,
278 QED_DEV_CAP_ROCE,
fc48b7a6
YM
279};
280
14d39648
MY
281enum qed_wol_support {
282 QED_WOL_SUPPORT_NONE,
283 QED_WOL_SUPPORT_PME,
284};
285
fe56b9e6
YM
286struct qed_hw_info {
287 /* PCI personality */
288 enum qed_pci_personality personality;
289
290 /* Resource Allocation scheme results */
291 u32 resc_start[QED_MAX_RESC];
292 u32 resc_num[QED_MAX_RESC];
25c089d7 293 u32 feat_num[QED_MAX_FEATURES];
fe56b9e6
YM
294
295#define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
296#define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
dbb799c3
YM
297#define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
298 RESC_NUM(_p_hwfn, resc))
fe56b9e6
YM
299#define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
300
b5a9ee7c
AE
301 /* Amount of traffic classes HW supports */
302 u8 num_hw_tc;
303
304 /* Amount of TCs which should be active according to DCBx or upper
305 * layer driver configuration.
306 */
307 u8 num_active_tc;
fe56b9e6 308 u8 offload_tc;
fe56b9e6
YM
309
310 u32 concrete_fid;
311 u16 opaque_fid;
312 u16 ovlan;
313 u32 part_num[4];
314
fe56b9e6 315 unsigned char hw_mac_addr[ETH_ALEN];
1e128c81
AE
316 u64 node_wwn;
317 u64 port_wwn;
318
319 u16 num_fcoe_conns;
fe56b9e6
YM
320
321 struct qed_igu_info *p_igu_info;
322
323 u32 port_mode;
324 u32 hw_mode;
fc48b7a6 325 unsigned long device_capabilities;
0fefbfba 326 u16 mtu;
14d39648
MY
327
328 enum qed_wol_support b_wol_support;
fe56b9e6
YM
329};
330
fe56b9e6
YM
331/* maximun size of read/write commands (HW limit) */
332#define DMAE_MAX_RW_SIZE 0x2000
333
334struct qed_dmae_info {
335 /* Mutex for synchronizing access to functions */
336 struct mutex mutex;
337
338 u8 channel;
339
340 dma_addr_t completion_word_phys_addr;
341
342 /* The memory location where the DMAE writes the completion
343 * value when an operation is finished on this context.
344 */
345 u32 *p_completion_word;
346
347 dma_addr_t intermediate_buffer_phys_addr;
348
349 /* An intermediate buffer for DMAE operations that use virtual
350 * addresses - data is DMA'd to/from this buffer and then
351 * memcpy'd to/from the virtual address
352 */
353 u32 *p_intermediate_buffer;
354
355 dma_addr_t dmae_cmd_phys_addr;
356 struct dmae_cmd *p_dmae_cmd;
357};
358
bcd197c8
MC
359struct qed_wfq_data {
360 /* when feature is configured for at least 1 vport */
361 u32 min_speed;
362 bool configured;
363};
364
fe56b9e6
YM
365struct qed_qm_info {
366 struct init_qm_pq_params *qm_pq_params;
367 struct init_qm_vport_params *qm_vport_params;
368 struct init_qm_port_params *qm_port_params;
369 u16 start_pq;
370 u8 start_vport;
b5a9ee7c
AE
371 u16 pure_lb_pq;
372 u16 offload_pq;
373 u16 low_latency_pq;
374 u16 pure_ack_pq;
375 u16 ooo_pq;
376 u16 first_vf_pq;
377 u16 first_mcos_pq;
378 u16 first_rl_pq;
fe56b9e6
YM
379 u16 num_pqs;
380 u16 num_vf_pqs;
381 u8 num_vports;
382 u8 max_phys_tcs_per_port;
b5a9ee7c 383 u8 ooo_tc;
fe56b9e6
YM
384 bool pf_rl_en;
385 bool pf_wfq_en;
386 bool vport_rl_en;
387 bool vport_wfq_en;
388 u8 pf_wfq;
389 u32 pf_rl;
bcd197c8 390 struct qed_wfq_data *wfq_data;
dbb799c3 391 u8 num_pf_rls;
fe56b9e6
YM
392};
393
9df2ed04
MC
394struct storm_stats {
395 u32 address;
396 u32 len;
397};
398
399struct qed_storm_stats {
400 struct storm_stats mstats;
401 struct storm_stats pstats;
402 struct storm_stats tstats;
403 struct storm_stats ustats;
404};
405
fe56b9e6 406struct qed_fw_data {
9df2ed04 407 struct fw_ver_info *fw_ver_info;
fe56b9e6
YM
408 const u8 *modes_tree_buf;
409 union init_op *init_ops;
410 const u32 *arr_data;
411 u32 init_ops_size;
412};
413
5d24bcf1
TT
414#define DRV_MODULE_VERSION \
415 __stringify(QED_MAJOR_VERSION) "." \
416 __stringify(QED_MINOR_VERSION) "." \
417 __stringify(QED_REVISION_VERSION) "." \
418 __stringify(QED_ENGINEERING_VERSION)
419
fe56b9e6
YM
420struct qed_simd_fp_handler {
421 void *token;
422 void (*func)(void *);
423};
424
425struct qed_hwfn {
426 struct qed_dev *cdev;
427 u8 my_id; /* ID inside the PF */
428#define IS_LEAD_HWFN(edev) (!((edev)->my_id))
429 u8 rel_pf_id; /* Relative to engine*/
430 u8 abs_pf_id;
9c79ddaa
MY
431#define QED_PATH_ID(_p_hwfn) \
432 (QED_IS_K2((_p_hwfn)->cdev) ? 0 : ((_p_hwfn)->abs_pf_id & 1))
fe56b9e6
YM
433 u8 port_id;
434 bool b_active;
435
436 u32 dp_module;
437 u8 dp_level;
438 char name[NAME_SIZE];
439
440 bool first_on_engine;
441 bool hw_init_done;
442
1408cc1f 443 u8 num_funcs_on_engine;
dbb799c3 444 u8 enabled_func_idx;
1408cc1f 445
fe56b9e6
YM
446 /* BAR access */
447 void __iomem *regview;
448 void __iomem *doorbells;
449 u64 db_phys_addr;
450 unsigned long db_size;
451
452 /* PTT pool */
453 struct qed_ptt_pool *p_ptt_pool;
454
455 /* HW info */
456 struct qed_hw_info hw_info;
457
458 /* rt_array (for init-tool) */
fc48b7a6 459 struct qed_rt_data rt_data;
fe56b9e6
YM
460
461 /* SPQ */
462 struct qed_spq *p_spq;
463
464 /* EQ */
465 struct qed_eq *p_eq;
466
467 /* Consolidate Q*/
468 struct qed_consq *p_consq;
469
470 /* Slow-Path definitions */
471 struct tasklet_struct *sp_dpc;
472 bool b_sp_dpc_enabled;
473
474 struct qed_ptt *p_main_ptt;
475 struct qed_ptt *p_dpc_ptt;
476
d179bd16 477 /* PTP will be used only by the leading function.
478 * Usage of all PTP-apis should be synchronized as result.
479 */
480 struct qed_ptt *p_ptp_ptt;
481
fe56b9e6
YM
482 struct qed_sb_sp_info *p_sp_sb;
483 struct qed_sb_attn_info *p_sb_attn;
484
485 /* Protocol related */
0a7fb11c
YM
486 bool using_ll2;
487 struct qed_ll2_info *p_ll2_info;
1d6cff4f 488 struct qed_ooo_info *p_ooo_info;
51ff1725 489 struct qed_rdma_info *p_rdma_info;
fc831825 490 struct qed_iscsi_info *p_iscsi_info;
1e128c81 491 struct qed_fcoe_info *p_fcoe_info;
fe56b9e6
YM
492 struct qed_pf_params pf_params;
493
dbb799c3
YM
494 bool b_rdma_enabled_in_prs;
495 u32 rdma_prs_search_reg;
496
fe56b9e6
YM
497 /* Array of sb_info of all status blocks */
498 struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD];
499 u16 num_sbs;
500
501 struct qed_cxt_mngr *p_cxt_mngr;
502
503 /* Flag indicating whether interrupts are enabled or not*/
504 bool b_int_enabled;
8f16bc97 505 bool b_int_requested;
fe56b9e6 506
fc916ff2
SRK
507 /* True if the driver requests for the link */
508 bool b_drv_link_init;
509
1408cc1f 510 struct qed_vf_iov *vf_iov_info;
32a47e72 511 struct qed_pf_iov *pf_iov_info;
fe56b9e6
YM
512 struct qed_mcp_info *mcp_info;
513
39651abd
SRK
514 struct qed_dcbx_info *p_dcbx_info;
515
fe56b9e6
YM
516 struct qed_dmae_info dmae_info;
517
518 /* QM init */
519 struct qed_qm_info qm_info;
9df2ed04 520 struct qed_storm_stats storm_stats;
fe56b9e6
YM
521
522 /* Buffer for unzipping firmware data */
523 void *unzip_buf;
524
c965db44
TT
525 struct dbg_tools_data dbg_info;
526
51ff1725
RA
527 /* PWM region specific data */
528 u32 dpi_size;
529 u32 dpi_count;
530
531 /* This is used to calculate the doorbell address */
532 u32 dpi_start_offset;
533
534 /* If one of the following is set then EDPM shouldn't be used */
535 u8 dcbx_no_edpm;
536 u8 db_bar_no_edpm;
537
d51e4af5
CM
538 struct qed_ptt *p_arfs_ptt;
539
fe56b9e6
YM
540 struct qed_simd_fp_handler simd_proto_handler[64];
541
37bff2b9
YM
542#ifdef CONFIG_QED_SRIOV
543 struct workqueue_struct *iov_wq;
544 struct delayed_work iov_task;
545 unsigned long iov_task_flags;
546#endif
547
fe56b9e6 548 struct z_stream_s *stream;
abd49676 549 struct qed_roce_ll2_info *ll2;
fe56b9e6
YM
550};
551
552struct pci_params {
553 int pm_cap;
554
555 unsigned long mem_start;
556 unsigned long mem_end;
557 unsigned int irq;
558 u8 pf_num;
559};
560
561struct qed_int_param {
562 u32 int_mode;
563 u8 num_vectors;
564 u8 min_msix_cnt; /* for minimal functionality */
565};
566
567struct qed_int_params {
568 struct qed_int_param in;
569 struct qed_int_param out;
570 struct msix_entry *msix_table;
571 bool fp_initialized;
572 u8 fp_msix_base;
573 u8 fp_msix_cnt;
51ff1725
RA
574 u8 rdma_msix_base;
575 u8 rdma_msix_cnt;
fe56b9e6
YM
576};
577
c965db44
TT
578struct qed_dbg_feature {
579 struct dentry *dentry;
580 u8 *dump_buf;
581 u32 buf_size;
582 u32 dumped_dwords;
583};
584
585struct qed_dbg_params {
586 struct qed_dbg_feature features[DBG_FEATURE_NUM];
587 u8 engine_for_debug;
588 bool print_data;
589};
590
fe56b9e6
YM
591struct qed_dev {
592 u32 dp_module;
593 u8 dp_level;
594 char name[NAME_SIZE];
595
9c79ddaa 596 enum qed_dev_type type;
fc48b7a6
YM
597/* Translate type/revision combo into the proper conditions */
598#define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
599#define QED_IS_BB_A0(dev) (QED_IS_BB(dev) && \
600 CHIP_REV_IS_A0(dev))
601#define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
602 CHIP_REV_IS_B0(dev))
c965db44
TT
603#define QED_IS_AH(dev) ((dev)->type == QED_DEV_TYPE_AH)
604#define QED_IS_K2(dev) QED_IS_AH(dev)
fc48b7a6
YM
605
606#define QED_GET_TYPE(dev) (QED_IS_BB_A0(dev) ? CHIP_BB_A0 : \
607 QED_IS_BB_B0(dev) ? CHIP_BB_B0 : CHIP_K2)
608
609 u16 vendor_id;
610 u16 device_id;
9c79ddaa
MY
611#define QED_DEV_ID_MASK 0xff00
612#define QED_DEV_ID_MASK_BB 0x1600
613#define QED_DEV_ID_MASK_AH 0x8000
fe56b9e6
YM
614
615 u16 chip_num;
616#define CHIP_NUM_MASK 0xffff
617#define CHIP_NUM_SHIFT 16
618
619 u16 chip_rev;
620#define CHIP_REV_MASK 0xf
621#define CHIP_REV_SHIFT 12
fc48b7a6
YM
622#define CHIP_REV_IS_A0(_cdev) (!(_cdev)->chip_rev)
623#define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
fe56b9e6
YM
624
625 u16 chip_metal;
626#define CHIP_METAL_MASK 0xff
627#define CHIP_METAL_SHIFT 4
628
629 u16 chip_bond_id;
630#define CHIP_BOND_ID_MASK 0xf
631#define CHIP_BOND_ID_SHIFT 0
632
633 u8 num_engines;
634 u8 num_ports_in_engines;
635 u8 num_funcs_in_port;
636
637 u8 path_id;
fc48b7a6
YM
638 enum qed_mf_mode mf_mode;
639#define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
640#define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
641#define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
fe56b9e6
YM
642
643 int pcie_width;
644 int pcie_speed;
645 u8 ver_str[VER_SIZE];
646
647 /* Add MF related configuration */
648 u8 mcp_rev;
649 u8 boot_mode;
650
14d39648
MY
651 /* WoL related configurations */
652 u8 wol_config;
653 u8 wol_mac[ETH_ALEN];
fe56b9e6
YM
654
655 u32 int_mode;
656 enum qed_coalescing_mode int_coalescing_mode;
51d99880
SRK
657 u16 rx_coalesce_usecs;
658 u16 tx_coalesce_usecs;
fe56b9e6
YM
659
660 /* Start Bar offset of first hwfn */
661 void __iomem *regview;
662 void __iomem *doorbells;
663 u64 db_phys_addr;
664 unsigned long db_size;
665
666 /* PCI */
667 u8 cache_shift;
668
669 /* Init */
670 const struct iro *iro_arr;
671#define IRO (p_hwfn->cdev->iro_arr)
672
673 /* HW functions */
674 u8 num_hwfns;
675 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
676
32a47e72
YM
677 /* SRIOV */
678 struct qed_hw_sriov_info *p_iov_info;
679#define IS_QED_SRIOV(cdev) (!!(cdev)->p_iov_info)
19968430 680 struct qed_tunnel_info tunnel;
1408cc1f 681 bool b_is_vf;
fe56b9e6 682 u32 drv_type;
fe56b9e6
YM
683 struct qed_eth_stats *reset_stats;
684 struct qed_fw_data *fw_data;
685
686 u32 mcp_nvm_resp;
687
688 /* Linux specific here */
689 struct qede_dev *edev;
690 struct pci_dev *pdev;
fc831825
YM
691 u32 flags;
692#define QED_FLAG_STORAGE_STARTED (BIT(0))
fe56b9e6
YM
693 int msg_enable;
694
695 struct pci_params pci_params;
696
697 struct qed_int_params int_params;
698
699 u8 protocol;
700#define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
1e128c81 701#define IS_QED_FCOE_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_FCOE)
fe56b9e6 702
cc875c2e
YM
703 /* Callbacks to protocol driver */
704 union {
705 struct qed_common_cb_ops *common;
706 struct qed_eth_cb_ops *eth;
1e128c81 707 struct qed_fcoe_cb_ops *fcoe;
fc831825 708 struct qed_iscsi_cb_ops *iscsi;
cc875c2e
YM
709 } protocol_ops;
710 void *ops_cookie;
711
c965db44
TT
712 struct qed_dbg_params dbg_params;
713
0a7fb11c
YM
714#ifdef CONFIG_QED_LL2
715 struct qed_cb_ll2_info *ll2;
716 u8 ll2_mac_address[ETH_ALEN];
717#endif
fc831825 718 DECLARE_HASHTABLE(connections, 10);
fe56b9e6 719 const struct firmware *firmware;
51ff1725
RA
720
721 u32 rdma_max_sge;
722 u32 rdma_max_inline;
723 u32 rdma_max_srq_sge;
eaf3c0c6 724 u16 tunn_feature_mask;
fe56b9e6
YM
725};
726
9c79ddaa
MY
727#define NUM_OF_VFS(dev) (QED_IS_BB(dev) ? MAX_NUM_VFS_BB \
728 : MAX_NUM_VFS_K2)
729#define NUM_OF_L2_QUEUES(dev) (QED_IS_BB(dev) ? MAX_NUM_L2_QUEUES_BB \
730 : MAX_NUM_L2_QUEUES_K2)
731#define NUM_OF_PORTS(dev) (QED_IS_BB(dev) ? MAX_NUM_PORTS_BB \
732 : MAX_NUM_PORTS_K2)
733#define NUM_OF_SBS(dev) (QED_IS_BB(dev) ? MAX_SB_PER_PATH_BB \
734 : MAX_SB_PER_PATH_K2)
735#define NUM_OF_ENG_PFS(dev) (QED_IS_BB(dev) ? MAX_NUM_PFS_BB \
736 : MAX_NUM_PFS_K2)
fe56b9e6
YM
737
738/**
739 * @brief qed_concrete_to_sw_fid - get the sw function id from
740 * the concrete value.
741 *
742 * @param concrete_fid
743 *
744 * @return inline u8
745 */
746static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
747 u32 concrete_fid)
748{
4870e704 749 u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
fe56b9e6 750 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
4870e704
YM
751 u8 vf_valid = GET_FIELD(concrete_fid,
752 PXP_CONCRETE_FID_VFVALID);
753 u8 sw_fid;
fe56b9e6 754
4870e704
YM
755 if (vf_valid)
756 sw_fid = vfid + MAX_NUM_PFS;
757 else
758 sw_fid = pfid;
759
760 return sw_fid;
fe56b9e6
YM
761}
762
763#define PURE_LB_TC 8
dbb799c3 764#define OOO_LB_TC 9
fe56b9e6 765
733def6a 766int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate);
6f437d43
MY
767void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
768 struct qed_ptt *p_ptt,
769 u32 min_pf_rate);
bcd197c8 770
733def6a 771void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
9c79ddaa 772int qed_device_num_engines(struct qed_dev *cdev);
db82f70e 773int qed_device_get_port_id(struct qed_dev *cdev);
fe56b9e6 774
b5a9ee7c
AE
775#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
776
777/* Flags for indication of required queues */
778#define PQ_FLAGS_RLS (BIT(0))
779#define PQ_FLAGS_MCOS (BIT(1))
780#define PQ_FLAGS_LB (BIT(2))
781#define PQ_FLAGS_OOO (BIT(3))
782#define PQ_FLAGS_ACK (BIT(4))
783#define PQ_FLAGS_OFLD (BIT(5))
784#define PQ_FLAGS_VFS (BIT(6))
785#define PQ_FLAGS_LLT (BIT(7))
786
787/* physical queue index for cm context intialization */
788u16 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags);
789u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc);
790u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf);
791
792#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
793
fe56b9e6
YM
794/* Other Linux specific common definitions */
795#define DP_NAME(cdev) ((cdev)->name)
796
797#define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
798 (cdev->regview) + \
799 (offset))
800
801#define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
802#define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
803#define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
804
805#define DOORBELL(cdev, db_addr, val) \
806 writel((u32)val, (void __iomem *)((u8 __iomem *)\
807 (cdev->doorbells) + (db_addr)))
808
809/* Prototypes */
810int qed_fill_dev_info(struct qed_dev *cdev,
811 struct qed_dev_info *dev_info);
cc875c2e 812void qed_link_update(struct qed_hwfn *hwfn);
fe56b9e6
YM
813u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
814 u32 input_len, u8 *input_buf,
815 u32 max_size, u8 *unzip_buf);
6c754246
SRK
816void qed_get_protocol_stats(struct qed_dev *cdev,
817 enum qed_mcp_protocol_type type,
818 union qed_mcp_protocol_stats *stats);
8f16bc97 819int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
1226337a 820void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn);
8f16bc97 821
fe56b9e6 822#endif /* _QED_H */