xref: /linux/drivers/net/ethernet/qlogic/qed/qed_hw.h (revision 663eacd899ac131dcfc2279184c1ce3c4fd2815f)
11f4d4ed6SAlexander Lobakin /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2fe56b9e6SYuval Mintz /* QLogic qed NIC Driver
3e8f1cb50SMintz, Yuval  * Copyright (c) 2015-2017  QLogic Corporation
4*663eacd8SAlexander Lobakin  * Copyright (c) 2019-2020 Marvell International Ltd.
5fe56b9e6SYuval Mintz  */
6fe56b9e6SYuval Mintz 
7fe56b9e6SYuval Mintz #ifndef _QED_HW_H
8fe56b9e6SYuval Mintz #define _QED_HW_H
9fe56b9e6SYuval Mintz 
10fe56b9e6SYuval Mintz #include <linux/types.h>
11fe56b9e6SYuval Mintz #include <linux/bitops.h>
12fe56b9e6SYuval Mintz #include <linux/slab.h>
13fe56b9e6SYuval Mintz #include <linux/string.h>
14fe56b9e6SYuval Mintz #include "qed.h"
15fe56b9e6SYuval Mintz #include "qed_dev_api.h"
16fe56b9e6SYuval Mintz 
17fe56b9e6SYuval Mintz /* Forward decleration */
18fe56b9e6SYuval Mintz struct qed_ptt;
19fe56b9e6SYuval Mintz 
20fe56b9e6SYuval Mintz enum reserved_ptts {
21fe56b9e6SYuval Mintz 	RESERVED_PTT_EDIAG,
22fe56b9e6SYuval Mintz 	RESERVED_PTT_USER_SPACE,
23fe56b9e6SYuval Mintz 	RESERVED_PTT_MAIN,
24fe56b9e6SYuval Mintz 	RESERVED_PTT_DPC,
25fe56b9e6SYuval Mintz 	RESERVED_PTT_MAX
26fe56b9e6SYuval Mintz };
27fe56b9e6SYuval Mintz 
28fe56b9e6SYuval Mintz enum _dmae_cmd_dst_mask {
29fe56b9e6SYuval Mintz 	DMAE_CMD_DST_MASK_NONE	= 0,
30fe56b9e6SYuval Mintz 	DMAE_CMD_DST_MASK_PCIE	= 1,
31fe56b9e6SYuval Mintz 	DMAE_CMD_DST_MASK_GRC	= 2
32fe56b9e6SYuval Mintz };
33fe56b9e6SYuval Mintz 
34fe56b9e6SYuval Mintz enum _dmae_cmd_src_mask {
35fe56b9e6SYuval Mintz 	DMAE_CMD_SRC_MASK_PCIE	= 0,
36fe56b9e6SYuval Mintz 	DMAE_CMD_SRC_MASK_GRC	= 1
37fe56b9e6SYuval Mintz };
38fe56b9e6SYuval Mintz 
39fe56b9e6SYuval Mintz enum _dmae_cmd_crc_mask {
40fe56b9e6SYuval Mintz 	DMAE_CMD_COMP_CRC_EN_MASK_NONE	= 0,
41fe56b9e6SYuval Mintz 	DMAE_CMD_COMP_CRC_EN_MASK_SET	= 1
42fe56b9e6SYuval Mintz };
43fe56b9e6SYuval Mintz 
44fe56b9e6SYuval Mintz /* definitions for DMA constants */
45fe56b9e6SYuval Mintz #define DMAE_GO_VALUE   0x1
46fe56b9e6SYuval Mintz 
47fe56b9e6SYuval Mintz #define DMAE_COMPLETION_VAL     0xD1AE
48fe56b9e6SYuval Mintz #define DMAE_CMD_ENDIANITY      0x2
49fe56b9e6SYuval Mintz 
50fe56b9e6SYuval Mintz #define DMAE_CMD_SIZE   14
51fe56b9e6SYuval Mintz #define DMAE_CMD_SIZE_TO_FILL   (DMAE_CMD_SIZE - 5)
52fe56b9e6SYuval Mintz #define DMAE_MIN_WAIT_TIME      0x2
53fe56b9e6SYuval Mintz #define DMAE_MAX_CLIENTS        32
54fe56b9e6SYuval Mintz 
55fe56b9e6SYuval Mintz /**
56fe56b9e6SYuval Mintz  * @brief qed_gtt_init - Initialize GTT windows
57fe56b9e6SYuval Mintz  *
58fe56b9e6SYuval Mintz  * @param p_hwfn
59fe56b9e6SYuval Mintz  */
60fe56b9e6SYuval Mintz void qed_gtt_init(struct qed_hwfn *p_hwfn);
61fe56b9e6SYuval Mintz 
62fe56b9e6SYuval Mintz /**
63fe56b9e6SYuval Mintz  * @brief qed_ptt_invalidate - Forces all ptt entries to be re-configured
64fe56b9e6SYuval Mintz  *
65fe56b9e6SYuval Mintz  * @param p_hwfn
66fe56b9e6SYuval Mintz  */
67fe56b9e6SYuval Mintz void qed_ptt_invalidate(struct qed_hwfn *p_hwfn);
68fe56b9e6SYuval Mintz 
69fe56b9e6SYuval Mintz /**
70fe56b9e6SYuval Mintz  * @brief qed_ptt_pool_alloc - Allocate and initialize PTT pool
71fe56b9e6SYuval Mintz  *
72fe56b9e6SYuval Mintz  * @param p_hwfn
73fe56b9e6SYuval Mintz  *
74fe56b9e6SYuval Mintz  * @return struct _qed_status - success (0), negative - error.
75fe56b9e6SYuval Mintz  */
76fe56b9e6SYuval Mintz int qed_ptt_pool_alloc(struct qed_hwfn *p_hwfn);
77fe56b9e6SYuval Mintz 
78fe56b9e6SYuval Mintz /**
79fe56b9e6SYuval Mintz  * @brief qed_ptt_pool_free -
80fe56b9e6SYuval Mintz  *
81fe56b9e6SYuval Mintz  * @param p_hwfn
82fe56b9e6SYuval Mintz  */
83fe56b9e6SYuval Mintz void qed_ptt_pool_free(struct qed_hwfn *p_hwfn);
84fe56b9e6SYuval Mintz 
85fe56b9e6SYuval Mintz /**
86fe56b9e6SYuval Mintz  * @brief qed_ptt_get_hw_addr - Get PTT's GRC/HW address
87fe56b9e6SYuval Mintz  *
88fe56b9e6SYuval Mintz  * @param p_hwfn
89fe56b9e6SYuval Mintz  * @param p_ptt
90fe56b9e6SYuval Mintz  *
91fe56b9e6SYuval Mintz  * @return u32
92fe56b9e6SYuval Mintz  */
93fe56b9e6SYuval Mintz u32 qed_ptt_get_hw_addr(struct qed_hwfn *p_hwfn,
94fe56b9e6SYuval Mintz 			struct qed_ptt *p_ptt);
95fe56b9e6SYuval Mintz 
96fe56b9e6SYuval Mintz /**
97fe56b9e6SYuval Mintz  * @brief qed_ptt_get_bar_addr - Get PPT's external BAR address
98fe56b9e6SYuval Mintz  *
99fe56b9e6SYuval Mintz  * @param p_hwfn
100fe56b9e6SYuval Mintz  * @param p_ptt
101fe56b9e6SYuval Mintz  *
102fe56b9e6SYuval Mintz  * @return u32
103fe56b9e6SYuval Mintz  */
104fe56b9e6SYuval Mintz u32 qed_ptt_get_bar_addr(struct qed_ptt *p_ptt);
105fe56b9e6SYuval Mintz 
106fe56b9e6SYuval Mintz /**
107fe56b9e6SYuval Mintz  * @brief qed_ptt_set_win - Set PTT Window's GRC BAR address
108fe56b9e6SYuval Mintz  *
109fe56b9e6SYuval Mintz  * @param p_hwfn
110fe56b9e6SYuval Mintz  * @param new_hw_addr
111fe56b9e6SYuval Mintz  * @param p_ptt
112fe56b9e6SYuval Mintz  */
113fe56b9e6SYuval Mintz void qed_ptt_set_win(struct qed_hwfn *p_hwfn,
114fe56b9e6SYuval Mintz 		     struct qed_ptt *p_ptt,
115fe56b9e6SYuval Mintz 		     u32 new_hw_addr);
116fe56b9e6SYuval Mintz 
117fe56b9e6SYuval Mintz /**
118fe56b9e6SYuval Mintz  * @brief qed_get_reserved_ptt - Get a specific reserved PTT
119fe56b9e6SYuval Mintz  *
120fe56b9e6SYuval Mintz  * @param p_hwfn
121fe56b9e6SYuval Mintz  * @param ptt_idx
122fe56b9e6SYuval Mintz  *
123fe56b9e6SYuval Mintz  * @return struct qed_ptt *
124fe56b9e6SYuval Mintz  */
125fe56b9e6SYuval Mintz struct qed_ptt *qed_get_reserved_ptt(struct qed_hwfn *p_hwfn,
126fe56b9e6SYuval Mintz 				     enum reserved_ptts ptt_idx);
127fe56b9e6SYuval Mintz 
128fe56b9e6SYuval Mintz /**
129fe56b9e6SYuval Mintz  * @brief qed_wr - Write value to BAR using the given ptt
130fe56b9e6SYuval Mintz  *
131fe56b9e6SYuval Mintz  * @param p_hwfn
132fe56b9e6SYuval Mintz  * @param p_ptt
133fe56b9e6SYuval Mintz  * @param val
134fe56b9e6SYuval Mintz  * @param hw_addr
135fe56b9e6SYuval Mintz  */
136fe56b9e6SYuval Mintz void qed_wr(struct qed_hwfn *p_hwfn,
137fe56b9e6SYuval Mintz 	    struct qed_ptt *p_ptt,
138fe56b9e6SYuval Mintz 	    u32 hw_addr,
139fe56b9e6SYuval Mintz 	    u32 val);
140fe56b9e6SYuval Mintz 
141fe56b9e6SYuval Mintz /**
142fe56b9e6SYuval Mintz  * @brief qed_rd - Read value from BAR using the given ptt
143fe56b9e6SYuval Mintz  *
144fe56b9e6SYuval Mintz  * @param p_hwfn
145fe56b9e6SYuval Mintz  * @param p_ptt
146fe56b9e6SYuval Mintz  * @param val
147fe56b9e6SYuval Mintz  * @param hw_addr
148fe56b9e6SYuval Mintz  */
149fe56b9e6SYuval Mintz u32 qed_rd(struct qed_hwfn *p_hwfn,
150fe56b9e6SYuval Mintz 	   struct qed_ptt *p_ptt,
151fe56b9e6SYuval Mintz 	   u32 hw_addr);
152fe56b9e6SYuval Mintz 
153fe56b9e6SYuval Mintz /**
154fe56b9e6SYuval Mintz  * @brief qed_memcpy_from - copy n bytes from BAR using the given
155fe56b9e6SYuval Mintz  *        ptt
156fe56b9e6SYuval Mintz  *
157fe56b9e6SYuval Mintz  * @param p_hwfn
158fe56b9e6SYuval Mintz  * @param p_ptt
159fe56b9e6SYuval Mintz  * @param dest
160fe56b9e6SYuval Mintz  * @param hw_addr
161fe56b9e6SYuval Mintz  * @param n
162fe56b9e6SYuval Mintz  */
163fe56b9e6SYuval Mintz void qed_memcpy_from(struct qed_hwfn *p_hwfn,
164fe56b9e6SYuval Mintz 		     struct qed_ptt *p_ptt,
165fe56b9e6SYuval Mintz 		     void *dest,
166fe56b9e6SYuval Mintz 		     u32 hw_addr,
167fe56b9e6SYuval Mintz 		     size_t n);
168fe56b9e6SYuval Mintz 
169fe56b9e6SYuval Mintz /**
170fe56b9e6SYuval Mintz  * @brief qed_memcpy_to - copy n bytes to BAR using the given
171fe56b9e6SYuval Mintz  *        ptt
172fe56b9e6SYuval Mintz  *
173fe56b9e6SYuval Mintz  * @param p_hwfn
174fe56b9e6SYuval Mintz  * @param p_ptt
175fe56b9e6SYuval Mintz  * @param hw_addr
176fe56b9e6SYuval Mintz  * @param src
177fe56b9e6SYuval Mintz  * @param n
178fe56b9e6SYuval Mintz  */
179fe56b9e6SYuval Mintz void qed_memcpy_to(struct qed_hwfn *p_hwfn,
180fe56b9e6SYuval Mintz 		   struct qed_ptt *p_ptt,
181fe56b9e6SYuval Mintz 		   u32 hw_addr,
182fe56b9e6SYuval Mintz 		   void *src,
183fe56b9e6SYuval Mintz 		   size_t n);
184fe56b9e6SYuval Mintz /**
185fe56b9e6SYuval Mintz  * @brief qed_fid_pretend - pretend to another function when
186fe56b9e6SYuval Mintz  *        accessing the ptt window. There is no way to unpretend
187fe56b9e6SYuval Mintz  *        a function. The only way to cancel a pretend is to
188fe56b9e6SYuval Mintz  *        pretend back to the original function.
189fe56b9e6SYuval Mintz  *
190fe56b9e6SYuval Mintz  * @param p_hwfn
191fe56b9e6SYuval Mintz  * @param p_ptt
192fe56b9e6SYuval Mintz  * @param fid - fid field of pxp_pretend structure. Can contain
193fe56b9e6SYuval Mintz  *            either pf / vf, port/path fields are don't care.
194fe56b9e6SYuval Mintz  */
195fe56b9e6SYuval Mintz void qed_fid_pretend(struct qed_hwfn *p_hwfn,
196fe56b9e6SYuval Mintz 		     struct qed_ptt *p_ptt,
197fe56b9e6SYuval Mintz 		     u16 fid);
198fe56b9e6SYuval Mintz 
199fe56b9e6SYuval Mintz /**
200fe56b9e6SYuval Mintz  * @brief qed_port_pretend - pretend to another port when
201fe56b9e6SYuval Mintz  *        accessing the ptt window
202fe56b9e6SYuval Mintz  *
203fe56b9e6SYuval Mintz  * @param p_hwfn
204fe56b9e6SYuval Mintz  * @param p_ptt
205fe56b9e6SYuval Mintz  * @param port_id - the port to pretend to
206fe56b9e6SYuval Mintz  */
207fe56b9e6SYuval Mintz void qed_port_pretend(struct qed_hwfn *p_hwfn,
208fe56b9e6SYuval Mintz 		      struct qed_ptt *p_ptt,
209fe56b9e6SYuval Mintz 		      u8 port_id);
210fe56b9e6SYuval Mintz 
211fe56b9e6SYuval Mintz /**
212fe56b9e6SYuval Mintz  * @brief qed_port_unpretend - cancel any previously set port
213fe56b9e6SYuval Mintz  *        pretend
214fe56b9e6SYuval Mintz  *
215fe56b9e6SYuval Mintz  * @param p_hwfn
216fe56b9e6SYuval Mintz  * @param p_ptt
217fe56b9e6SYuval Mintz  */
218fe56b9e6SYuval Mintz void qed_port_unpretend(struct qed_hwfn *p_hwfn,
219fe56b9e6SYuval Mintz 			struct qed_ptt *p_ptt);
220fe56b9e6SYuval Mintz 
221fe56b9e6SYuval Mintz /**
222d52c89f1SMichal Kalderon  * @brief qed_port_fid_pretend - pretend to another port and another function
223d52c89f1SMichal Kalderon  *        when accessing the ptt window
224d52c89f1SMichal Kalderon  *
225d52c89f1SMichal Kalderon  * @param p_hwfn
226d52c89f1SMichal Kalderon  * @param p_ptt
227d52c89f1SMichal Kalderon  * @param port_id - the port to pretend to
228d52c89f1SMichal Kalderon  * @param fid - fid field of pxp_pretend structure. Can contain either pf / vf.
229d52c89f1SMichal Kalderon  */
230d52c89f1SMichal Kalderon void qed_port_fid_pretend(struct qed_hwfn *p_hwfn,
231d52c89f1SMichal Kalderon 			  struct qed_ptt *p_ptt, u8 port_id, u16 fid);
232d52c89f1SMichal Kalderon 
233d52c89f1SMichal Kalderon /**
23432a47e72SYuval Mintz  * @brief qed_vfid_to_concrete - build a concrete FID for a
23532a47e72SYuval Mintz  *        given VF ID
23632a47e72SYuval Mintz  *
23732a47e72SYuval Mintz  * @param p_hwfn
23832a47e72SYuval Mintz  * @param p_ptt
23932a47e72SYuval Mintz  * @param vfid
24032a47e72SYuval Mintz  */
24132a47e72SYuval Mintz u32 qed_vfid_to_concrete(struct qed_hwfn *p_hwfn, u8 vfid);
24232a47e72SYuval Mintz 
24332a47e72SYuval Mintz /**
244fe56b9e6SYuval Mintz  * @brief qed_dmae_idx_to_go_cmd - map the idx to dmae cmd
245fe56b9e6SYuval Mintz  * this is declared here since other files will require it.
246fe56b9e6SYuval Mintz  * @param idx
247fe56b9e6SYuval Mintz  */
248fe56b9e6SYuval Mintz u32 qed_dmae_idx_to_go_cmd(u8 idx);
249fe56b9e6SYuval Mintz 
250fe56b9e6SYuval Mintz /**
251fe56b9e6SYuval Mintz  * @brief qed_dmae_info_alloc - Init the dmae_info structure
252fe56b9e6SYuval Mintz  * which is part of p_hwfn.
253fe56b9e6SYuval Mintz  * @param p_hwfn
254fe56b9e6SYuval Mintz  */
255fe56b9e6SYuval Mintz int qed_dmae_info_alloc(struct qed_hwfn *p_hwfn);
256fe56b9e6SYuval Mintz 
257fe56b9e6SYuval Mintz /**
258fe56b9e6SYuval Mintz  * @brief qed_dmae_info_free - Free the dmae_info structure
259fe56b9e6SYuval Mintz  * which is part of p_hwfn
260fe56b9e6SYuval Mintz  *
261fe56b9e6SYuval Mintz  * @param p_hwfn
262fe56b9e6SYuval Mintz  */
263fe56b9e6SYuval Mintz void qed_dmae_info_free(struct qed_hwfn *p_hwfn);
264fe56b9e6SYuval Mintz 
265fe56b9e6SYuval Mintz union qed_qm_pq_params {
266fe56b9e6SYuval Mintz 	struct {
267dbb799c3SYuval Mintz 		u8 q_idx;
268dbb799c3SYuval Mintz 	} iscsi;
269dbb799c3SYuval Mintz 
270dbb799c3SYuval Mintz 	struct {
271fe56b9e6SYuval Mintz 		u8 tc;
272fe56b9e6SYuval Mintz 	}	core;
273fe56b9e6SYuval Mintz 
274fe56b9e6SYuval Mintz 	struct {
275fe56b9e6SYuval Mintz 		u8	is_vf;
276fe56b9e6SYuval Mintz 		u8	vf_id;
277fe56b9e6SYuval Mintz 		u8	tc;
278fe56b9e6SYuval Mintz 	}	eth;
279dbb799c3SYuval Mintz 
280dbb799c3SYuval Mintz 	struct {
281dbb799c3SYuval Mintz 		u8 dcqcn;
282dbb799c3SYuval Mintz 		u8 qpid;	/* roce relative */
283dbb799c3SYuval Mintz 	} roce;
284fe56b9e6SYuval Mintz };
285fe56b9e6SYuval Mintz 
286fe56b9e6SYuval Mintz int qed_init_fw_data(struct qed_dev *cdev,
287fe56b9e6SYuval Mintz 		     const u8 *fw_data);
288da090917STomer Tayar 
289da090917STomer Tayar int qed_dmae_sanity(struct qed_hwfn *p_hwfn,
290da090917STomer Tayar 		    struct qed_ptt *p_ptt, const char *phase);
291da090917STomer Tayar 
292d639836aSIgor Russkikh #define QED_HW_ERR_MAX_STR_SIZE 256
293d639836aSIgor Russkikh 
294d639836aSIgor Russkikh /**
295d639836aSIgor Russkikh  * @brief qed_hw_err_notify - Notify upper layer driver and management FW
296d639836aSIgor Russkikh  *	about a HW error.
297d639836aSIgor Russkikh  *
298d639836aSIgor Russkikh  * @param p_hwfn
299d639836aSIgor Russkikh  * @param p_ptt
300d639836aSIgor Russkikh  * @param err_type
301d639836aSIgor Russkikh  * @param fmt - debug data buffer to send to the MFW
302d639836aSIgor Russkikh  * @param ... - buffer format args
303d639836aSIgor Russkikh  */
304d639836aSIgor Russkikh void qed_hw_err_notify(struct qed_hwfn *p_hwfn,
305d639836aSIgor Russkikh 		       struct qed_ptt *p_ptt,
306d639836aSIgor Russkikh 		       enum qed_hw_err_type err_type, char *fmt, ...);
307fe56b9e6SYuval Mintz #endif
308