blob: cceac3272cce63c39dd7635022372b3a07e60239 [file] [log] [blame]
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
9#ifndef _QED_H
10#define _QED_H
11
12#include <linux/types.h>
13#include <linux/io.h>
14#include <linux/delay.h>
15#include <linux/firmware.h>
16#include <linux/interrupt.h>
17#include <linux/list.h>
18#include <linux/mutex.h>
19#include <linux/pci.h>
20#include <linux/slab.h>
21#include <linux/string.h>
22#include <linux/workqueue.h>
23#include <linux/zlib.h>
24#include <linux/hashtable.h>
25#include <linux/qed/qed_if.h>
26#include "qed_hsi.h"
27
Yuval Mintz25c089d2015-10-26 11:02:26 +020028extern const struct qed_common_ops qed_common_ops_pass;
Yuval Mintz7c2d7d72016-04-10 12:43:02 +030029#define DRV_MODULE_VERSION "8.7.1.20"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020030
31#define MAX_HWFNS_PER_DEVICE (4)
32#define NAME_SIZE 16
33#define VER_SIZE 16
34
Manish Choprabcd197c2016-04-26 10:56:08 -040035#define QED_WFQ_UNIT 100
36
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020037/* cau states */
38enum qed_coalescing_mode {
39 QED_COAL_MODE_DISABLE,
40 QED_COAL_MODE_ENABLE
41};
42
43struct qed_eth_cb_ops;
44struct qed_dev_info;
45
46/* helpers */
47static inline u32 qed_db_addr(u32 cid, u32 DEMS)
48{
49 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
50 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
51
52 return db_addr;
53}
54
55#define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
56 ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
57 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
58
59#define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
60
61#define D_TRINE(val, cond1, cond2, true1, true2, def) \
62 (val == (cond1) ? true1 : \
63 (val == (cond2) ? true2 : def))
64
65/* forward */
66struct qed_ptt_pool;
67struct qed_spq;
68struct qed_sb_info;
69struct qed_sb_attn_info;
70struct qed_cxt_mngr;
71struct qed_sb_sp_info;
72struct qed_mcp_info;
73
74struct qed_rt_data {
Yuval Mintzfc48b7a2016-02-15 13:22:35 -050075 u32 *init_val;
76 bool *b_valid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020077};
78
Manish Chopra464f6642016-04-14 01:38:29 -040079enum qed_tunn_mode {
80 QED_MODE_L2GENEVE_TUNN,
81 QED_MODE_IPGENEVE_TUNN,
82 QED_MODE_L2GRE_TUNN,
83 QED_MODE_IPGRE_TUNN,
84 QED_MODE_VXLAN_TUNN,
85};
86
87enum qed_tunn_clss {
88 QED_TUNN_CLSS_MAC_VLAN,
89 QED_TUNN_CLSS_MAC_VNI,
90 QED_TUNN_CLSS_INNER_MAC_VLAN,
91 QED_TUNN_CLSS_INNER_MAC_VNI,
92 MAX_QED_TUNN_CLSS,
93};
94
95struct qed_tunn_start_params {
96 unsigned long tunn_mode;
97 u16 vxlan_udp_port;
98 u16 geneve_udp_port;
99 u8 update_vxlan_udp_port;
100 u8 update_geneve_udp_port;
101 u8 tunn_clss_vxlan;
102 u8 tunn_clss_l2geneve;
103 u8 tunn_clss_ipgeneve;
104 u8 tunn_clss_l2gre;
105 u8 tunn_clss_ipgre;
106};
107
108struct qed_tunn_update_params {
109 unsigned long tunn_mode_update_mask;
110 unsigned long tunn_mode;
111 u16 vxlan_udp_port;
112 u16 geneve_udp_port;
113 u8 update_rx_pf_clss;
114 u8 update_tx_pf_clss;
115 u8 update_vxlan_udp_port;
116 u8 update_geneve_udp_port;
117 u8 tunn_clss_vxlan;
118 u8 tunn_clss_l2geneve;
119 u8 tunn_clss_ipgeneve;
120 u8 tunn_clss_l2gre;
121 u8 tunn_clss_ipgre;
122};
123
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200124/* The PCI personality is not quite synonymous to protocol ID:
125 * 1. All personalities need CORE connections
126 * 2. The Ethernet personality may support also the RoCE protocol
127 */
128enum qed_pci_personality {
129 QED_PCI_ETH,
130 QED_PCI_DEFAULT /* default in shmem */
131};
132
133/* All VFs are symmetric, all counters are PF + all VFs */
134struct qed_qm_iids {
135 u32 cids;
136 u32 vf_cids;
137 u32 tids;
138};
139
140enum QED_RESOURCES {
141 QED_SB,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200142 QED_L2_QUEUE,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200143 QED_VPORT,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200144 QED_RSS_ENG,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200145 QED_PQ,
146 QED_RL,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200147 QED_MAC,
148 QED_VLAN,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200149 QED_ILT,
150 QED_MAX_RESC,
151};
152
Yuval Mintz25c089d2015-10-26 11:02:26 +0200153enum QED_FEATURE {
154 QED_PF_L2_QUE,
155 QED_MAX_FEATURES,
156};
157
Yuval Mintzcc875c22015-10-26 11:02:31 +0200158enum QED_PORT_MODE {
159 QED_PORT_MODE_DE_2X40G,
160 QED_PORT_MODE_DE_2X50G,
161 QED_PORT_MODE_DE_1X100G,
162 QED_PORT_MODE_DE_4X10G_F,
163 QED_PORT_MODE_DE_4X10G_E,
164 QED_PORT_MODE_DE_4X20G,
165 QED_PORT_MODE_DE_1X40G,
166 QED_PORT_MODE_DE_2X25G,
167 QED_PORT_MODE_DE_1X25G
168};
169
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500170enum qed_dev_cap {
171 QED_DEV_CAP_ETH,
172};
173
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200174struct qed_hw_info {
175 /* PCI personality */
176 enum qed_pci_personality personality;
177
178 /* Resource Allocation scheme results */
179 u32 resc_start[QED_MAX_RESC];
180 u32 resc_num[QED_MAX_RESC];
Yuval Mintz25c089d2015-10-26 11:02:26 +0200181 u32 feat_num[QED_MAX_FEATURES];
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200182
183#define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
184#define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
185#define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
186
187 u8 num_tc;
188 u8 offload_tc;
189 u8 non_offload_tc;
190
191 u32 concrete_fid;
192 u16 opaque_fid;
193 u16 ovlan;
194 u32 part_num[4];
195
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200196 unsigned char hw_mac_addr[ETH_ALEN];
197
198 struct qed_igu_info *p_igu_info;
199
200 u32 port_mode;
201 u32 hw_mode;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500202 unsigned long device_capabilities;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200203};
204
205struct qed_hw_cid_data {
206 u32 cid;
207 bool b_cid_allocated;
208
209 /* Additional identifiers */
210 u16 opaque_fid;
211 u8 vport_id;
212};
213
214/* maximun size of read/write commands (HW limit) */
215#define DMAE_MAX_RW_SIZE 0x2000
216
217struct qed_dmae_info {
218 /* Mutex for synchronizing access to functions */
219 struct mutex mutex;
220
221 u8 channel;
222
223 dma_addr_t completion_word_phys_addr;
224
225 /* The memory location where the DMAE writes the completion
226 * value when an operation is finished on this context.
227 */
228 u32 *p_completion_word;
229
230 dma_addr_t intermediate_buffer_phys_addr;
231
232 /* An intermediate buffer for DMAE operations that use virtual
233 * addresses - data is DMA'd to/from this buffer and then
234 * memcpy'd to/from the virtual address
235 */
236 u32 *p_intermediate_buffer;
237
238 dma_addr_t dmae_cmd_phys_addr;
239 struct dmae_cmd *p_dmae_cmd;
240};
241
Manish Choprabcd197c2016-04-26 10:56:08 -0400242struct qed_wfq_data {
243 /* when feature is configured for at least 1 vport */
244 u32 min_speed;
245 bool configured;
246};
247
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200248struct qed_qm_info {
249 struct init_qm_pq_params *qm_pq_params;
250 struct init_qm_vport_params *qm_vport_params;
251 struct init_qm_port_params *qm_port_params;
252 u16 start_pq;
253 u8 start_vport;
254 u8 pure_lb_pq;
255 u8 offload_pq;
256 u8 pure_ack_pq;
257 u8 vf_queues_offset;
258 u16 num_pqs;
259 u16 num_vf_pqs;
260 u8 num_vports;
261 u8 max_phys_tcs_per_port;
262 bool pf_rl_en;
263 bool pf_wfq_en;
264 bool vport_rl_en;
265 bool vport_wfq_en;
266 u8 pf_wfq;
267 u32 pf_rl;
Manish Choprabcd197c2016-04-26 10:56:08 -0400268 struct qed_wfq_data *wfq_data;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200269};
270
Manish Chopra9df2ed02015-10-26 11:02:33 +0200271struct storm_stats {
272 u32 address;
273 u32 len;
274};
275
276struct qed_storm_stats {
277 struct storm_stats mstats;
278 struct storm_stats pstats;
279 struct storm_stats tstats;
280 struct storm_stats ustats;
281};
282
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200283struct qed_fw_data {
Manish Chopra9df2ed02015-10-26 11:02:33 +0200284 struct fw_ver_info *fw_ver_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200285 const u8 *modes_tree_buf;
286 union init_op *init_ops;
287 const u32 *arr_data;
288 u32 init_ops_size;
289};
290
291struct qed_simd_fp_handler {
292 void *token;
293 void (*func)(void *);
294};
295
296struct qed_hwfn {
297 struct qed_dev *cdev;
298 u8 my_id; /* ID inside the PF */
299#define IS_LEAD_HWFN(edev) (!((edev)->my_id))
300 u8 rel_pf_id; /* Relative to engine*/
301 u8 abs_pf_id;
302#define QED_PATH_ID(_p_hwfn) ((_p_hwfn)->abs_pf_id & 1)
303 u8 port_id;
304 bool b_active;
305
306 u32 dp_module;
307 u8 dp_level;
308 char name[NAME_SIZE];
309
310 bool first_on_engine;
311 bool hw_init_done;
312
313 /* BAR access */
314 void __iomem *regview;
315 void __iomem *doorbells;
316 u64 db_phys_addr;
317 unsigned long db_size;
318
319 /* PTT pool */
320 struct qed_ptt_pool *p_ptt_pool;
321
322 /* HW info */
323 struct qed_hw_info hw_info;
324
325 /* rt_array (for init-tool) */
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500326 struct qed_rt_data rt_data;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200327
328 /* SPQ */
329 struct qed_spq *p_spq;
330
331 /* EQ */
332 struct qed_eq *p_eq;
333
334 /* Consolidate Q*/
335 struct qed_consq *p_consq;
336
337 /* Slow-Path definitions */
338 struct tasklet_struct *sp_dpc;
339 bool b_sp_dpc_enabled;
340
341 struct qed_ptt *p_main_ptt;
342 struct qed_ptt *p_dpc_ptt;
343
344 struct qed_sb_sp_info *p_sp_sb;
345 struct qed_sb_attn_info *p_sb_attn;
346
347 /* Protocol related */
348 struct qed_pf_params pf_params;
349
350 /* Array of sb_info of all status blocks */
351 struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD];
352 u16 num_sbs;
353
354 struct qed_cxt_mngr *p_cxt_mngr;
355
356 /* Flag indicating whether interrupts are enabled or not*/
357 bool b_int_enabled;
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500358 bool b_int_requested;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200359
Sudarsana Reddy Kallurufc916ff2016-03-09 09:16:23 +0200360 /* True if the driver requests for the link */
361 bool b_drv_link_init;
362
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200363 struct qed_mcp_info *mcp_info;
364
Yuval Mintz25c089d2015-10-26 11:02:26 +0200365 struct qed_hw_cid_data *p_tx_cids;
366 struct qed_hw_cid_data *p_rx_cids;
367
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200368 struct qed_dmae_info dmae_info;
369
370 /* QM init */
371 struct qed_qm_info qm_info;
Manish Chopra9df2ed02015-10-26 11:02:33 +0200372 struct qed_storm_stats storm_stats;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200373
374 /* Buffer for unzipping firmware data */
375 void *unzip_buf;
376
377 struct qed_simd_fp_handler simd_proto_handler[64];
378
379 struct z_stream_s *stream;
380};
381
382struct pci_params {
383 int pm_cap;
384
385 unsigned long mem_start;
386 unsigned long mem_end;
387 unsigned int irq;
388 u8 pf_num;
389};
390
391struct qed_int_param {
392 u32 int_mode;
393 u8 num_vectors;
394 u8 min_msix_cnt; /* for minimal functionality */
395};
396
397struct qed_int_params {
398 struct qed_int_param in;
399 struct qed_int_param out;
400 struct msix_entry *msix_table;
401 bool fp_initialized;
402 u8 fp_msix_base;
403 u8 fp_msix_cnt;
404};
405
406struct qed_dev {
407 u32 dp_module;
408 u8 dp_level;
409 char name[NAME_SIZE];
410
411 u8 type;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500412#define QED_DEV_TYPE_BB (0 << 0)
413#define QED_DEV_TYPE_AH BIT(0)
414/* Translate type/revision combo into the proper conditions */
415#define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
416#define QED_IS_BB_A0(dev) (QED_IS_BB(dev) && \
417 CHIP_REV_IS_A0(dev))
418#define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
419 CHIP_REV_IS_B0(dev))
420
421#define QED_GET_TYPE(dev) (QED_IS_BB_A0(dev) ? CHIP_BB_A0 : \
422 QED_IS_BB_B0(dev) ? CHIP_BB_B0 : CHIP_K2)
423
424 u16 vendor_id;
425 u16 device_id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200426
427 u16 chip_num;
428#define CHIP_NUM_MASK 0xffff
429#define CHIP_NUM_SHIFT 16
430
431 u16 chip_rev;
432#define CHIP_REV_MASK 0xf
433#define CHIP_REV_SHIFT 12
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500434#define CHIP_REV_IS_A0(_cdev) (!(_cdev)->chip_rev)
435#define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200436
437 u16 chip_metal;
438#define CHIP_METAL_MASK 0xff
439#define CHIP_METAL_SHIFT 4
440
441 u16 chip_bond_id;
442#define CHIP_BOND_ID_MASK 0xf
443#define CHIP_BOND_ID_SHIFT 0
444
445 u8 num_engines;
446 u8 num_ports_in_engines;
447 u8 num_funcs_in_port;
448
449 u8 path_id;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500450 enum qed_mf_mode mf_mode;
451#define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
452#define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
453#define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200454
455 int pcie_width;
456 int pcie_speed;
457 u8 ver_str[VER_SIZE];
458
459 /* Add MF related configuration */
460 u8 mcp_rev;
461 u8 boot_mode;
462
463 u8 wol;
464
465 u32 int_mode;
466 enum qed_coalescing_mode int_coalescing_mode;
467 u8 rx_coalesce_usecs;
468 u8 tx_coalesce_usecs;
469
470 /* Start Bar offset of first hwfn */
471 void __iomem *regview;
472 void __iomem *doorbells;
473 u64 db_phys_addr;
474 unsigned long db_size;
475
476 /* PCI */
477 u8 cache_shift;
478
479 /* Init */
480 const struct iro *iro_arr;
481#define IRO (p_hwfn->cdev->iro_arr)
482
483 /* HW functions */
484 u8 num_hwfns;
485 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
486
Manish Chopra464f6642016-04-14 01:38:29 -0400487 unsigned long tunn_mode;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200488 u32 drv_type;
489
490 struct qed_eth_stats *reset_stats;
491 struct qed_fw_data *fw_data;
492
493 u32 mcp_nvm_resp;
494
495 /* Linux specific here */
496 struct qede_dev *edev;
497 struct pci_dev *pdev;
498 int msg_enable;
499
500 struct pci_params pci_params;
501
502 struct qed_int_params int_params;
503
504 u8 protocol;
505#define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
506
Yuval Mintzcc875c22015-10-26 11:02:31 +0200507 /* Callbacks to protocol driver */
508 union {
509 struct qed_common_cb_ops *common;
510 struct qed_eth_cb_ops *eth;
511 } protocol_ops;
512 void *ops_cookie;
513
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200514 const struct firmware *firmware;
515};
516
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200517#define NUM_OF_SBS(dev) MAX_SB_PER_PATH_BB
518#define NUM_OF_ENG_PFS(dev) MAX_NUM_PFS_BB
519
520/**
521 * @brief qed_concrete_to_sw_fid - get the sw function id from
522 * the concrete value.
523 *
524 * @param concrete_fid
525 *
526 * @return inline u8
527 */
528static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
529 u32 concrete_fid)
530{
531 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
532
533 return pfid;
534}
535
536#define PURE_LB_TC 8
537
Manish Choprabcd197c2016-04-26 10:56:08 -0400538void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, u32 min_pf_rate);
539
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200540#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
541
542/* Other Linux specific common definitions */
543#define DP_NAME(cdev) ((cdev)->name)
544
545#define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
546 (cdev->regview) + \
547 (offset))
548
549#define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
550#define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
551#define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
552
553#define DOORBELL(cdev, db_addr, val) \
554 writel((u32)val, (void __iomem *)((u8 __iomem *)\
555 (cdev->doorbells) + (db_addr)))
556
557/* Prototypes */
558int qed_fill_dev_info(struct qed_dev *cdev,
559 struct qed_dev_info *dev_info);
Yuval Mintzcc875c22015-10-26 11:02:31 +0200560void qed_link_update(struct qed_hwfn *hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200561u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
562 u32 input_len, u8 *input_buf,
563 u32 max_size, u8 *unzip_buf);
564
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500565int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
566
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200567#endif /* _QED_H */