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