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