blob: ac17d8669b1adad9291a6a39646b51ff80693176 [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 Mintzfe56b9e2015-10-26 11:02:25 +020029#define DRV_MODULE_VERSION "8.4.0.0"
30
31#define MAX_HWFNS_PER_DEVICE (4)
32#define NAME_SIZE 16
33#define VER_SIZE 16
34
35/* cau states */
36enum qed_coalescing_mode {
37 QED_COAL_MODE_DISABLE,
38 QED_COAL_MODE_ENABLE
39};
40
41struct qed_eth_cb_ops;
42struct qed_dev_info;
43
44/* helpers */
45static inline u32 qed_db_addr(u32 cid, u32 DEMS)
46{
47 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
48 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
49
50 return db_addr;
51}
52
53#define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
54 ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
55 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
56
57#define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
58
59#define D_TRINE(val, cond1, cond2, true1, true2, def) \
60 (val == (cond1) ? true1 : \
61 (val == (cond2) ? true2 : def))
62
63/* forward */
64struct qed_ptt_pool;
65struct qed_spq;
66struct qed_sb_info;
67struct qed_sb_attn_info;
68struct qed_cxt_mngr;
69struct qed_sb_sp_info;
70struct qed_mcp_info;
71
72struct qed_rt_data {
73 u32 init_val;
74 bool b_valid;
75};
76
77/* The PCI personality is not quite synonymous to protocol ID:
78 * 1. All personalities need CORE connections
79 * 2. The Ethernet personality may support also the RoCE protocol
80 */
81enum qed_pci_personality {
82 QED_PCI_ETH,
83 QED_PCI_DEFAULT /* default in shmem */
84};
85
86/* All VFs are symmetric, all counters are PF + all VFs */
87struct qed_qm_iids {
88 u32 cids;
89 u32 vf_cids;
90 u32 tids;
91};
92
93enum QED_RESOURCES {
94 QED_SB,
Yuval Mintz25c089d2015-10-26 11:02:26 +020095 QED_L2_QUEUE,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020096 QED_VPORT,
Yuval Mintz25c089d2015-10-26 11:02:26 +020097 QED_RSS_ENG,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020098 QED_PQ,
99 QED_RL,
Yuval Mintz25c089d2015-10-26 11:02:26 +0200100 QED_MAC,
101 QED_VLAN,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200102 QED_ILT,
103 QED_MAX_RESC,
104};
105
Yuval Mintz25c089d2015-10-26 11:02:26 +0200106enum QED_FEATURE {
107 QED_PF_L2_QUE,
108 QED_MAX_FEATURES,
109};
110
Yuval Mintzcc875c22015-10-26 11:02:31 +0200111enum QED_PORT_MODE {
112 QED_PORT_MODE_DE_2X40G,
113 QED_PORT_MODE_DE_2X50G,
114 QED_PORT_MODE_DE_1X100G,
115 QED_PORT_MODE_DE_4X10G_F,
116 QED_PORT_MODE_DE_4X10G_E,
117 QED_PORT_MODE_DE_4X20G,
118 QED_PORT_MODE_DE_1X40G,
119 QED_PORT_MODE_DE_2X25G,
120 QED_PORT_MODE_DE_1X25G
121};
122
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200123struct qed_hw_info {
124 /* PCI personality */
125 enum qed_pci_personality personality;
126
127 /* Resource Allocation scheme results */
128 u32 resc_start[QED_MAX_RESC];
129 u32 resc_num[QED_MAX_RESC];
Yuval Mintz25c089d2015-10-26 11:02:26 +0200130 u32 feat_num[QED_MAX_FEATURES];
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200131
132#define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
133#define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
134#define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
135
136 u8 num_tc;
137 u8 offload_tc;
138 u8 non_offload_tc;
139
140 u32 concrete_fid;
141 u16 opaque_fid;
142 u16 ovlan;
143 u32 part_num[4];
144
145 u32 vendor_id;
146 u32 device_id;
147
148 unsigned char hw_mac_addr[ETH_ALEN];
149
150 struct qed_igu_info *p_igu_info;
151
152 u32 port_mode;
153 u32 hw_mode;
154};
155
156struct qed_hw_cid_data {
157 u32 cid;
158 bool b_cid_allocated;
159
160 /* Additional identifiers */
161 u16 opaque_fid;
162 u8 vport_id;
163};
164
165/* maximun size of read/write commands (HW limit) */
166#define DMAE_MAX_RW_SIZE 0x2000
167
168struct qed_dmae_info {
169 /* Mutex for synchronizing access to functions */
170 struct mutex mutex;
171
172 u8 channel;
173
174 dma_addr_t completion_word_phys_addr;
175
176 /* The memory location where the DMAE writes the completion
177 * value when an operation is finished on this context.
178 */
179 u32 *p_completion_word;
180
181 dma_addr_t intermediate_buffer_phys_addr;
182
183 /* An intermediate buffer for DMAE operations that use virtual
184 * addresses - data is DMA'd to/from this buffer and then
185 * memcpy'd to/from the virtual address
186 */
187 u32 *p_intermediate_buffer;
188
189 dma_addr_t dmae_cmd_phys_addr;
190 struct dmae_cmd *p_dmae_cmd;
191};
192
193struct qed_qm_info {
194 struct init_qm_pq_params *qm_pq_params;
195 struct init_qm_vport_params *qm_vport_params;
196 struct init_qm_port_params *qm_port_params;
197 u16 start_pq;
198 u8 start_vport;
199 u8 pure_lb_pq;
200 u8 offload_pq;
201 u8 pure_ack_pq;
202 u8 vf_queues_offset;
203 u16 num_pqs;
204 u16 num_vf_pqs;
205 u8 num_vports;
206 u8 max_phys_tcs_per_port;
207 bool pf_rl_en;
208 bool pf_wfq_en;
209 bool vport_rl_en;
210 bool vport_wfq_en;
211 u8 pf_wfq;
212 u32 pf_rl;
213};
214
Manish Chopra9df2ed02015-10-26 11:02:33 +0200215struct storm_stats {
216 u32 address;
217 u32 len;
218};
219
220struct qed_storm_stats {
221 struct storm_stats mstats;
222 struct storm_stats pstats;
223 struct storm_stats tstats;
224 struct storm_stats ustats;
225};
226
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200227struct qed_fw_data {
Manish Chopra9df2ed02015-10-26 11:02:33 +0200228 struct fw_ver_info *fw_ver_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200229 const u8 *modes_tree_buf;
230 union init_op *init_ops;
231 const u32 *arr_data;
232 u32 init_ops_size;
233};
234
235struct qed_simd_fp_handler {
236 void *token;
237 void (*func)(void *);
238};
239
240struct qed_hwfn {
241 struct qed_dev *cdev;
242 u8 my_id; /* ID inside the PF */
243#define IS_LEAD_HWFN(edev) (!((edev)->my_id))
244 u8 rel_pf_id; /* Relative to engine*/
245 u8 abs_pf_id;
246#define QED_PATH_ID(_p_hwfn) ((_p_hwfn)->abs_pf_id & 1)
247 u8 port_id;
248 bool b_active;
249
250 u32 dp_module;
251 u8 dp_level;
252 char name[NAME_SIZE];
253
254 bool first_on_engine;
255 bool hw_init_done;
256
257 /* BAR access */
258 void __iomem *regview;
259 void __iomem *doorbells;
260 u64 db_phys_addr;
261 unsigned long db_size;
262
263 /* PTT pool */
264 struct qed_ptt_pool *p_ptt_pool;
265
266 /* HW info */
267 struct qed_hw_info hw_info;
268
269 /* rt_array (for init-tool) */
270 struct qed_rt_data *rt_data;
271
272 /* SPQ */
273 struct qed_spq *p_spq;
274
275 /* EQ */
276 struct qed_eq *p_eq;
277
278 /* Consolidate Q*/
279 struct qed_consq *p_consq;
280
281 /* Slow-Path definitions */
282 struct tasklet_struct *sp_dpc;
283 bool b_sp_dpc_enabled;
284
285 struct qed_ptt *p_main_ptt;
286 struct qed_ptt *p_dpc_ptt;
287
288 struct qed_sb_sp_info *p_sp_sb;
289 struct qed_sb_attn_info *p_sb_attn;
290
291 /* Protocol related */
292 struct qed_pf_params pf_params;
293
294 /* Array of sb_info of all status blocks */
295 struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD];
296 u16 num_sbs;
297
298 struct qed_cxt_mngr *p_cxt_mngr;
299
300 /* Flag indicating whether interrupts are enabled or not*/
301 bool b_int_enabled;
302
303 struct qed_mcp_info *mcp_info;
304
Yuval Mintz25c089d2015-10-26 11:02:26 +0200305 struct qed_hw_cid_data *p_tx_cids;
306 struct qed_hw_cid_data *p_rx_cids;
307
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200308 struct qed_dmae_info dmae_info;
309
310 /* QM init */
311 struct qed_qm_info qm_info;
Manish Chopra9df2ed02015-10-26 11:02:33 +0200312 struct qed_storm_stats storm_stats;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200313
314 /* Buffer for unzipping firmware data */
315 void *unzip_buf;
316
317 struct qed_simd_fp_handler simd_proto_handler[64];
318
319 struct z_stream_s *stream;
320};
321
322struct pci_params {
323 int pm_cap;
324
325 unsigned long mem_start;
326 unsigned long mem_end;
327 unsigned int irq;
328 u8 pf_num;
329};
330
331struct qed_int_param {
332 u32 int_mode;
333 u8 num_vectors;
334 u8 min_msix_cnt; /* for minimal functionality */
335};
336
337struct qed_int_params {
338 struct qed_int_param in;
339 struct qed_int_param out;
340 struct msix_entry *msix_table;
341 bool fp_initialized;
342 u8 fp_msix_base;
343 u8 fp_msix_cnt;
344};
345
346struct qed_dev {
347 u32 dp_module;
348 u8 dp_level;
349 char name[NAME_SIZE];
350
351 u8 type;
352#define QED_DEV_TYPE_BB_A0 (0 << 0)
353#define QED_DEV_TYPE_MASK (0x3)
354#define QED_DEV_TYPE_SHIFT (0)
355
356 u16 chip_num;
357#define CHIP_NUM_MASK 0xffff
358#define CHIP_NUM_SHIFT 16
359
360 u16 chip_rev;
361#define CHIP_REV_MASK 0xf
362#define CHIP_REV_SHIFT 12
363
364 u16 chip_metal;
365#define CHIP_METAL_MASK 0xff
366#define CHIP_METAL_SHIFT 4
367
368 u16 chip_bond_id;
369#define CHIP_BOND_ID_MASK 0xf
370#define CHIP_BOND_ID_SHIFT 0
371
372 u8 num_engines;
373 u8 num_ports_in_engines;
374 u8 num_funcs_in_port;
375
376 u8 path_id;
377 enum mf_mode mf_mode;
378#define IS_MF(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode != SF)
379#define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == MF_NPAR)
380#define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == MF_OVLAN)
381
382 int pcie_width;
383 int pcie_speed;
384 u8 ver_str[VER_SIZE];
385
386 /* Add MF related configuration */
387 u8 mcp_rev;
388 u8 boot_mode;
389
390 u8 wol;
391
392 u32 int_mode;
393 enum qed_coalescing_mode int_coalescing_mode;
394 u8 rx_coalesce_usecs;
395 u8 tx_coalesce_usecs;
396
397 /* Start Bar offset of first hwfn */
398 void __iomem *regview;
399 void __iomem *doorbells;
400 u64 db_phys_addr;
401 unsigned long db_size;
402
403 /* PCI */
404 u8 cache_shift;
405
406 /* Init */
407 const struct iro *iro_arr;
408#define IRO (p_hwfn->cdev->iro_arr)
409
410 /* HW functions */
411 u8 num_hwfns;
412 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
413
414 u32 drv_type;
415
416 struct qed_eth_stats *reset_stats;
417 struct qed_fw_data *fw_data;
418
419 u32 mcp_nvm_resp;
420
421 /* Linux specific here */
422 struct qede_dev *edev;
423 struct pci_dev *pdev;
424 int msg_enable;
425
426 struct pci_params pci_params;
427
428 struct qed_int_params int_params;
429
430 u8 protocol;
431#define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
432
Yuval Mintzcc875c22015-10-26 11:02:31 +0200433 /* Callbacks to protocol driver */
434 union {
435 struct qed_common_cb_ops *common;
436 struct qed_eth_cb_ops *eth;
437 } protocol_ops;
438 void *ops_cookie;
439
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200440 const struct firmware *firmware;
441};
442
443#define QED_GET_TYPE(dev) (((dev)->type & QED_DEV_TYPE_MASK) >> \
444 QED_DEV_TYPE_SHIFT)
445#define QED_IS_BB_A0(dev) (QED_GET_TYPE(dev) == QED_DEV_TYPE_BB_A0)
446#define QED_IS_BB(dev) (QED_IS_BB_A0(dev))
447
448#define NUM_OF_SBS(dev) MAX_SB_PER_PATH_BB
449#define NUM_OF_ENG_PFS(dev) MAX_NUM_PFS_BB
450
451/**
452 * @brief qed_concrete_to_sw_fid - get the sw function id from
453 * the concrete value.
454 *
455 * @param concrete_fid
456 *
457 * @return inline u8
458 */
459static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
460 u32 concrete_fid)
461{
462 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
463
464 return pfid;
465}
466
467#define PURE_LB_TC 8
468
469#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
470
471/* Other Linux specific common definitions */
472#define DP_NAME(cdev) ((cdev)->name)
473
474#define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
475 (cdev->regview) + \
476 (offset))
477
478#define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
479#define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
480#define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
481
482#define DOORBELL(cdev, db_addr, val) \
483 writel((u32)val, (void __iomem *)((u8 __iomem *)\
484 (cdev->doorbells) + (db_addr)))
485
486/* Prototypes */
487int qed_fill_dev_info(struct qed_dev *cdev,
488 struct qed_dev_info *dev_info);
Yuval Mintzcc875c22015-10-26 11:02:31 +0200489void qed_link_update(struct qed_hwfn *hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200490u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
491 u32 input_len, u8 *input_buf,
492 u32 max_size, u8 *unzip_buf);
493
494#define QED_ETH_INTERFACE_VERSION 300
495
496#endif /* _QED_H */