xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_mcp.h (revision ab00ac327a66a53edaac95b536b209db3ae2cd9f)
1 /*
2  * Copyright (c) 2017-2018 Cavium, Inc.
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  *
29  */
30 
31 
32 #ifndef __ECORE_MCP_H__
33 #define __ECORE_MCP_H__
34 
35 #include "bcm_osal.h"
36 #include "mcp_public.h"
37 #include "ecore.h"
38 #include "ecore_mcp_api.h"
39 #include "ecore_dev_api.h"
40 
41 /* Using hwfn number (and not pf_num) is required since in CMT mode,
42  * same pf_num may be used by two different hwfn
43  * TODO - this shouldn't really be in .h file, but until all fields
44  * required during hw-init will be placed in their correct place in shmem
45  * we need it in ecore_dev.c [for readin the nvram reflection in shmem].
46  */
47 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \
48 					    ((rel_pfid) | \
49 					     ((p_hwfn)->abs_pf_id & 1) << 3) : \
50 					     rel_pfid)
51 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
52 
53 #define MFW_PORT(_p_hwfn)	((_p_hwfn)->abs_pf_id % \
54 				 ((_p_hwfn)->p_dev->num_ports_in_engines * \
55 				  ecore_device_num_engines((_p_hwfn)->p_dev)))
56 
57 struct ecore_mcp_info {
58 	/* Spinlock used for protecting the access to the MFW mailbox */
59 	osal_spinlock_t lock;
60 
61 	/* Spinglock used for syncing SW link-changes and link-changes
62 	 * originating from attention context.
63 	 */
64 	osal_spinlock_t link_lock;
65 
66 	/* Flag to indicate whether sending a MFW mailbox is forbidden */
67 	bool block_mb_sending;
68 
69 	/* Address of the MCP public area */
70 	u32 public_base;
71 	/* Address of the driver mailbox */
72 	u32 drv_mb_addr;
73 	/* Address of the MFW mailbox */
74 	u32 mfw_mb_addr;
75 	/* Address of the port configuration (link) */
76 	u32 port_addr;
77 
78 	/* Current driver mailbox sequence */
79 	u16 drv_mb_seq;
80 	/* Current driver pulse sequence */
81 	u16 drv_pulse_seq;
82 
83 	struct ecore_mcp_link_params       link_input;
84 	struct ecore_mcp_link_state	   link_output;
85 	struct ecore_mcp_link_capabilities link_capabilities;
86 
87 	struct ecore_mcp_function_info	   func_info;
88 
89 	u8 *mfw_mb_cur;
90 	u8 *mfw_mb_shadow;
91 	u16 mfw_mb_length;
92 	u16 mcp_hist;
93 
94 	/* Capabilties negotiated with the MFW */
95 	u32 capabilities;
96 };
97 
98 struct ecore_mcp_mb_params {
99 	u32 cmd;
100 	u32 param;
101 	void *p_data_src;
102 	u8 data_src_size;
103 	void *p_data_dst;
104 	u8 data_dst_size;
105 	u32 mcp_resp;
106 	u32 mcp_param;
107 };
108 
109 enum ecore_ov_eswitch {
110 	ECORE_OV_ESWITCH_NONE,
111 	ECORE_OV_ESWITCH_VEB,
112 	ECORE_OV_ESWITCH_VEPA
113 };
114 
115 struct ecore_drv_tlv_hdr {
116 	u8 tlv_type;	/* According to the enum below */
117 	u8 tlv_length;	/* In dwords - not including this header */
118 	u8 tlv_reserved;
119 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
120 	u8 tlv_flags;
121 };
122 
123 /**
124  * @brief Initialize the interface with the MCP
125  *
126  * @param p_hwfn - HW func
127  * @param p_ptt - PTT required for register access
128  *
129  * @return enum _ecore_status_t
130  */
131 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
132 					struct ecore_ptt *p_ptt);
133 
134 /**
135  * @brief Intialize the port interface with the MCP
136  *
137  * @param p_hwfn
138  * @param p_ptt
139  * Can only be called after `num_ports_in_engines' is set
140  */
141 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
142 			     struct ecore_ptt *p_ptt);
143 /**
144  * @brief Releases resources allocated during the init process.
145  *
146  * @param p_hwfn - HW func
147  * @param p_ptt - PTT required for register access
148  *
149  * @return enum _ecore_status_t
150  */
151 
152 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
153 
154 /**
155  * @brief This function is called from the DPC context. After
156  * pointing PTT to the mfw mb, check for events sent by the MCP
157  * to the driver and ack them. In case a critical event
158  * detected, it will be handled here, otherwise the work will be
159  * queued to a sleepable work-queue.
160  *
161  * @param p_hwfn - HW function
162  * @param p_ptt - PTT required for register access
163  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
164  * was successul.
165  */
166 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
167 					     struct ecore_ptt *p_ptt);
168 
169 /**
170  * @brief When MFW doesn't get driver pulse for couple of seconds, at some
171  * threshold before timeout expires, it will generate interrupt
172  * through a dedicated status block (DPSB - Driver Pulse Status
173  * Block), which the driver should respond immediately, by
174  * providing keepalive indication after setting the PTT to the
175  * driver-MFW mailbox. This function is called directly from the
176  * DPC upon receiving the DPSB attention.
177  *
178  * @param p_hwfn - hw function
179  * @param p_ptt - PTT required for register access
180  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
181  * was successful.
182  */
183 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
184 				       struct ecore_ptt *p_ptt);
185 
186 enum ecore_drv_role {
187 	ECORE_DRV_ROLE_OS,
188 	ECORE_DRV_ROLE_KDUMP,
189 };
190 
191 struct ecore_load_req_params {
192 	/* Input params */
193 	enum ecore_drv_role drv_role;
194 	u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
195 	bool avoid_eng_reset;
196 	enum ecore_override_force_load override_force_load;
197 
198 	/* Output params */
199 	u32 load_code;
200 };
201 
202 /**
203  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
204  *        returns whether this PF is the first on the engine/port or function.
205  *
206  * @param p_hwfn
207  * @param p_ptt
208  * @param p_params
209  *
210  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
211  */
212 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
213 					struct ecore_ptt *p_ptt,
214 					struct ecore_load_req_params *p_params);
215 
216 /**
217  * @brief Sends a UNLOAD_REQ message to the MFW
218  *
219  * @param p_hwfn
220  * @param p_ptt
221  *
222  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
223  */
224 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
225 					  struct ecore_ptt *p_ptt);
226 
227 /**
228  * @brief Sends a UNLOAD_DONE message to the MFW
229  *
230  * @param p_hwfn
231  * @param p_ptt
232  *
233  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
234  */
235 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
236 					   struct ecore_ptt *p_ptt);
237 
238 /**
239  * @brief Read the MFW mailbox into Current buffer.
240  *
241  * @param p_hwfn
242  * @param p_ptt
243  */
244 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
245 		       struct ecore_ptt *p_ptt);
246 
247 /**
248  * @brief Ack to mfw that driver finished FLR process for VFs
249  *
250  * @param p_hwfn
251  * @param p_ptt
252  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
253  *
254  * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
255  */
256 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
257 					  struct ecore_ptt *p_ptt,
258 					  u32 *vfs_to_ack);
259 
260 /**
261  * @brief - calls during init to read shmem of all function-related info.
262  *
263  * @param p_hwfn
264  *
265  * @param return ECORE_SUCCESS upon success.
266  */
267 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
268 						    struct ecore_ptt *p_ptt);
269 
270 /**
271  * @brief - Reset the MCP using mailbox command.
272  *
273  * @param p_hwfn
274  * @param p_ptt
275  *
276  * @param return ECORE_SUCCESS upon success.
277  */
278 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
279 				     struct ecore_ptt *p_ptt);
280 
281 /**
282  * @brief - Sends an NVM write command request to the MFW with
283  *          payload.
284  *
285  * @param p_hwfn
286  * @param p_ptt
287  * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
288  *            DRV_MSG_CODE_NVM_PUT_FILE_DATA
289  * @param param - [0:23] - Offset [24:31] - Size
290  * @param o_mcp_resp - MCP response
291  * @param o_mcp_param - MCP response param
292  * @param i_txn_size -  Buffer size
293  * @param i_buf - Pointer to the buffer
294  *
295  * @param return ECORE_SUCCESS upon success.
296  */
297 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
298 					  struct ecore_ptt *p_ptt,
299 					  u32 cmd,
300 					  u32 param,
301 					  u32 *o_mcp_resp,
302 					  u32 *o_mcp_param,
303 					  u32 i_txn_size,
304 					  u32 *i_buf);
305 
306 /**
307  * @brief - Sends an NVM read command request to the MFW to get
308  *        a buffer.
309  *
310  * @param p_hwfn
311  * @param p_ptt
312  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
313  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
314  * @param param - [0:23] - Offset [24:31] - Size
315  * @param o_mcp_resp - MCP response
316  * @param o_mcp_param - MCP response param
317  * @param o_txn_size -  Buffer size output
318  * @param o_buf - Pointer to the buffer returned by the MFW.
319  *
320  * @param return ECORE_SUCCESS upon success.
321  */
322 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
323 					  struct ecore_ptt *p_ptt,
324 					  u32 cmd,
325 					  u32 param,
326 					  u32 *o_mcp_resp,
327 					  u32 *o_mcp_param,
328 					  u32 *o_txn_size,
329 					  u32 *o_buf);
330 
331 /**
332  * @brief indicates whether the MFW objects [under mcp_info] are accessible
333  *
334  * @param p_hwfn
335  *
336  * @return true iff MFW is running and mcp_info is initialized
337  */
338 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
339 
340 /**
341  * @brief request MFW to configure MSI-X for a VF
342  *
343  * @param p_hwfn
344  * @param p_ptt
345  * @param vf_id - absolute inside engine
346  * @param num_sbs - number of entries to request
347  *
348  * @return enum _ecore_status_t
349  */
350 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
351 					      struct ecore_ptt *p_ptt,
352 					      u8 vf_id, u8 num);
353 
354 /**
355  * @brief - Halt the MCP.
356  *
357  * @param p_hwfn
358  * @param p_ptt
359  *
360  * @param return ECORE_SUCCESS upon success.
361  */
362 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
363 				    struct ecore_ptt *p_ptt);
364 
365 /**
366  * @brief - Wake up the MCP.
367  *
368  * @param p_hwfn
369  * @param p_ptt
370  *
371  * @param return ECORE_SUCCESS upon success.
372  */
373 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
374 				      struct ecore_ptt *p_ptt);
375 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
376 				       struct ecore_ptt *p_ptt,
377 				       struct ecore_mcp_link_state *p_link,
378 				       u8 max_bw);
379 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
380 				       struct ecore_ptt *p_ptt,
381 				       struct ecore_mcp_link_state *p_link,
382 				       u8 min_bw);
383 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
384 					     struct ecore_ptt *p_ptt,
385 					     u32 mask_parities);
386 #if 0
387 enum _ecore_status_t ecore_hw_init_first_eth(struct ecore_hwfn *p_hwfn,
388 					     struct ecore_ptt *p_ptt,
389 					     u8 *p_pf);
390 #endif
391 
392 /**
393  * @brief - Sends crash mdump related info to the MFW.
394  *
395  * @param p_hwfn
396  * @param p_ptt
397  * @param epoch
398  *
399  * @param return ECORE_SUCCESS upon success.
400  */
401 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
402 						struct ecore_ptt *p_ptt,
403 						u32 epoch);
404 
405 /**
406  * @brief - Triggers a MFW crash dump procedure.
407  *
408  * @param p_hwfn
409  * @param p_ptt
410  *
411  * @param return ECORE_SUCCESS upon success.
412  */
413 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
414 					     struct ecore_ptt *p_ptt);
415 
416 struct ecore_mdump_retain_data {
417 	u32 valid;
418 	u32 epoch;
419 	u32 pf;
420 	u32 status;
421 };
422 
423 /**
424  * @brief - Gets the mdump retained data from the MFW.
425  *
426  * @param p_hwfn
427  * @param p_ptt
428  * @param p_mdump_retain
429  *
430  * @param return ECORE_SUCCESS upon success.
431  */
432 enum _ecore_status_t
433 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
434 			   struct ecore_mdump_retain_data *p_mdump_retain);
435 
436 /**
437  * @brief - Clear the mdump retained data.
438  *
439  * @param p_hwfn
440  * @param p_ptt
441  *
442  * @param return ECORE_SUCCESS upon success.
443  */
444 enum _ecore_status_t ecore_mcp_mdump_clr_retain(struct ecore_hwfn *p_hwfn,
445 						struct ecore_ptt *p_ptt);
446 
447 /**
448  * @brief - Sets the MFW's max value for the given resource
449  *
450  *  @param p_hwfn
451  *  @param p_ptt
452  *  @param res_id
453  *  @param resc_max_val
454  *  @param p_mcp_resp
455  *
456  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
457  */
458 enum _ecore_status_t
459 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
460 			   enum ecore_resources res_id, u32 resc_max_val,
461 			   u32 *p_mcp_resp);
462 
463 /**
464  * @brief - Gets the MFW allocation info for the given resource
465  *
466  *  @param p_hwfn
467  *  @param p_ptt
468  *  @param res_id
469  *  @param p_mcp_resp
470  *  @param p_resc_num
471  *  @param p_resc_start
472  *
473  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
474  */
475 enum _ecore_status_t
476 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
477 			enum ecore_resources res_id, u32 *p_mcp_resp,
478 			u32 *p_resc_num, u32 *p_resc_start);
479 
480 /**
481  * @brief - Initiates PF FLR
482  *
483  *  @param p_hwfn
484  *  @param p_ptt
485  *
486  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
487  */
488 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
489 					       struct ecore_ptt *p_ptt);
490 
491 /**
492  * @brief Send eswitch mode to MFW
493  *
494  *  @param p_hwfn
495  *  @param p_ptt
496  *  @param eswitch - eswitch mode
497  *
498  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
499  */
500 enum _ecore_status_t
501 ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
502 			    enum ecore_ov_eswitch eswitch);
503 
504 #define ECORE_MCP_RESC_LOCK_MIN_VAL	RESOURCE_DUMP /* 0 */
505 #define ECORE_MCP_RESC_LOCK_MAX_VAL	31
506 
507 enum ecore_resc_lock {
508 	ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
509 	/* Locks that the MFW is aware of should be added here downwards */
510 
511 	/* Ecore only locks should be added here upwards */
512 	ECORE_RESC_LOCK_PTP_PORT0,
513 	ECORE_RESC_LOCK_PTP_PORT1,
514 	ECORE_RESC_LOCK_PTP_PORT2,
515 	ECORE_RESC_LOCK_PTP_PORT3,
516 	ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL
517 };
518 
519 struct ecore_resc_lock_params {
520 	/* Resource number [valid values are 0..31] */
521 	u8 resource;
522 
523 	/* Lock timeout value in seconds [default, none or 1..254] */
524 	u8 timeout;
525 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT	0
526 #define ECORE_MCP_RESC_LOCK_TO_NONE	255
527 
528 	/* Number of times to retry locking */
529 	u8 retry_num;
530 
531 	/* The interval in usec between retries */
532 	u16 retry_interval;
533 
534 	/* Use sleep or delay between retries */
535 	bool sleep_b4_retry;
536 
537 	/* Will be set as true if the resource is free and granted */
538 	bool b_granted;
539 
540 	/* Will be filled with the resource owner.
541 	 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
542 	 */
543 	u8 owner;
544 };
545 
546 /**
547  * @brief Acquires MFW generic resource lock
548  *
549  *  @param p_hwfn
550  *  @param p_ptt
551  *  @param p_params
552  *
553  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
554  */
555 enum _ecore_status_t
556 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
557 		    struct ecore_resc_lock_params *p_params);
558 
559 struct ecore_resc_unlock_params {
560 	/* Resource number [valid values are 0..31] */
561 	u8 resource;
562 
563 	/* Allow to release a resource even if belongs to another PF */
564 	bool b_force;
565 
566 	/* Will be set as true if the resource is released */
567 	bool b_released;
568 };
569 
570 /**
571  * @brief Releases MFW generic resource lock
572  *
573  *  @param p_hwfn
574  *  @param p_ptt
575  *  @param p_params
576  *
577  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
578  */
579 enum _ecore_status_t
580 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
581 		      struct ecore_resc_unlock_params *p_params);
582 
583 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
584 		      u32 offset, u32 val);
585 
586 /**
587  * @brief Learn of supported MFW features; To be done during early init
588  *
589  * @param p_hwfn
590  * @param p_ptt
591  */
592 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
593 						struct ecore_ptt *p_ptt);
594 
595 /**
596  * @brief Inform MFW of set of features supported by driver. Should be done
597  * inside the contet of the LOAD_REQ.
598  *
599  * @param p_hwfn
600  * @param p_ptt
601  */
602 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
603 						struct ecore_ptt *p_ptt);
604 
605 /**
606  * @brief Initialize MFW mailbox and sequence values for driver interaction.
607  *
608  * @param p_hwfn
609  * @param p_ptt
610  */
611 enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn,
612 					    struct ecore_ptt *p_ptt);
613 
614 #endif /* __ECORE_MCP_H__ */
615