xref: /linux/drivers/net/ethernet/qlogic/qed/qed_mcp.h (revision f412eed9dfdeeb6becd7de2ffe8b5d0a8b3f81ca)
1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015-2017  QLogic Corporation
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and /or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 
33 #ifndef _QED_MCP_H
34 #define _QED_MCP_H
35 
36 #include <linux/types.h>
37 #include <linux/delay.h>
38 #include <linux/slab.h>
39 #include <linux/spinlock.h>
40 #include <linux/qed/qed_fcoe_if.h>
41 #include "qed_hsi.h"
42 #include "qed_dev_api.h"
43 
44 struct qed_mcp_link_speed_params {
45 	bool    autoneg;
46 	u32     advertised_speeds;      /* bitmask of DRV_SPEED_CAPABILITY */
47 	u32     forced_speed;	   /* In Mb/s */
48 };
49 
50 struct qed_mcp_link_pause_params {
51 	bool    autoneg;
52 	bool    forced_rx;
53 	bool    forced_tx;
54 };
55 
56 enum qed_mcp_eee_mode {
57 	QED_MCP_EEE_DISABLED,
58 	QED_MCP_EEE_ENABLED,
59 	QED_MCP_EEE_UNSUPPORTED
60 };
61 
62 struct qed_mcp_link_params {
63 	struct qed_mcp_link_speed_params speed;
64 	struct qed_mcp_link_pause_params pause;
65 	u32 loopback_mode;
66 	struct qed_link_eee_params eee;
67 };
68 
69 struct qed_mcp_link_capabilities {
70 	u32 speed_capabilities;
71 	bool default_speed_autoneg;
72 	enum qed_mcp_eee_mode default_eee;
73 	u32 eee_lpi_timer;
74 	u8 eee_speed_caps;
75 };
76 
77 struct qed_mcp_link_state {
78 	bool    link_up;
79 
80 	u32	min_pf_rate;
81 
82 	/* Actual link speed in Mb/s */
83 	u32	line_speed;
84 
85 	/* PF max speed in Mb/s, deduced from line_speed
86 	 * according to PF max bandwidth configuration.
87 	 */
88 	u32     speed;
89 	bool    full_duplex;
90 
91 	bool    an;
92 	bool    an_complete;
93 	bool    parallel_detection;
94 	bool    pfc_enabled;
95 
96 #define QED_LINK_PARTNER_SPEED_1G_HD    BIT(0)
97 #define QED_LINK_PARTNER_SPEED_1G_FD    BIT(1)
98 #define QED_LINK_PARTNER_SPEED_10G      BIT(2)
99 #define QED_LINK_PARTNER_SPEED_20G      BIT(3)
100 #define QED_LINK_PARTNER_SPEED_25G      BIT(4)
101 #define QED_LINK_PARTNER_SPEED_40G      BIT(5)
102 #define QED_LINK_PARTNER_SPEED_50G      BIT(6)
103 #define QED_LINK_PARTNER_SPEED_100G     BIT(7)
104 	u32     partner_adv_speed;
105 
106 	bool    partner_tx_flow_ctrl_en;
107 	bool    partner_rx_flow_ctrl_en;
108 
109 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
110 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
111 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
112 	u8      partner_adv_pause;
113 
114 	bool    sfp_tx_fault;
115 	bool    eee_active;
116 	u8      eee_adv_caps;
117 	u8      eee_lp_adv_caps;
118 };
119 
120 struct qed_mcp_function_info {
121 	u8				pause_on_host;
122 
123 	enum qed_pci_personality	protocol;
124 
125 	u8				bandwidth_min;
126 	u8				bandwidth_max;
127 
128 	u8				mac[ETH_ALEN];
129 
130 	u64				wwn_port;
131 	u64				wwn_node;
132 
133 #define QED_MCP_VLAN_UNSET              (0xffff)
134 	u16				ovlan;
135 
136 	u16				mtu;
137 };
138 
139 struct qed_mcp_nvm_common {
140 	u32	offset;
141 	u32	param;
142 	u32	resp;
143 	u32	cmd;
144 };
145 
146 struct qed_mcp_drv_version {
147 	u32	version;
148 	u8	name[MCP_DRV_VER_STR_SIZE - 4];
149 };
150 
151 struct qed_mcp_lan_stats {
152 	u64 ucast_rx_pkts;
153 	u64 ucast_tx_pkts;
154 	u32 fcs_err;
155 };
156 
157 struct qed_mcp_fcoe_stats {
158 	u64 rx_pkts;
159 	u64 tx_pkts;
160 	u32 fcs_err;
161 	u32 login_failure;
162 };
163 
164 struct qed_mcp_iscsi_stats {
165 	u64 rx_pdus;
166 	u64 tx_pdus;
167 	u64 rx_bytes;
168 	u64 tx_bytes;
169 };
170 
171 struct qed_mcp_rdma_stats {
172 	u64 rx_pkts;
173 	u64 tx_pkts;
174 	u64 rx_bytes;
175 	u64 tx_byts;
176 };
177 
178 enum qed_mcp_protocol_type {
179 	QED_MCP_LAN_STATS,
180 	QED_MCP_FCOE_STATS,
181 	QED_MCP_ISCSI_STATS,
182 	QED_MCP_RDMA_STATS
183 };
184 
185 union qed_mcp_protocol_stats {
186 	struct qed_mcp_lan_stats lan_stats;
187 	struct qed_mcp_fcoe_stats fcoe_stats;
188 	struct qed_mcp_iscsi_stats iscsi_stats;
189 	struct qed_mcp_rdma_stats rdma_stats;
190 };
191 
192 enum qed_ov_eswitch {
193 	QED_OV_ESWITCH_NONE,
194 	QED_OV_ESWITCH_VEB,
195 	QED_OV_ESWITCH_VEPA
196 };
197 
198 enum qed_ov_client {
199 	QED_OV_CLIENT_DRV,
200 	QED_OV_CLIENT_USER,
201 	QED_OV_CLIENT_VENDOR_SPEC
202 };
203 
204 enum qed_ov_driver_state {
205 	QED_OV_DRIVER_STATE_NOT_LOADED,
206 	QED_OV_DRIVER_STATE_DISABLED,
207 	QED_OV_DRIVER_STATE_ACTIVE
208 };
209 
210 enum qed_ov_wol {
211 	QED_OV_WOL_DEFAULT,
212 	QED_OV_WOL_DISABLED,
213 	QED_OV_WOL_ENABLED
214 };
215 
216 /**
217  * @brief - returns the link params of the hw function
218  *
219  * @param p_hwfn
220  *
221  * @returns pointer to link params
222  */
223 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
224 
225 /**
226  * @brief - return the link state of the hw function
227  *
228  * @param p_hwfn
229  *
230  * @returns pointer to link state
231  */
232 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
233 
234 /**
235  * @brief - return the link capabilities of the hw function
236  *
237  * @param p_hwfn
238  *
239  * @returns pointer to link capabilities
240  */
241 struct qed_mcp_link_capabilities
242 	*qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
243 
244 /**
245  * @brief Request the MFW to set the the link according to 'link_input'.
246  *
247  * @param p_hwfn
248  * @param p_ptt
249  * @param b_up - raise link if `true'. Reset link if `false'.
250  *
251  * @return int
252  */
253 int qed_mcp_set_link(struct qed_hwfn   *p_hwfn,
254 		     struct qed_ptt     *p_ptt,
255 		     bool               b_up);
256 
257 /**
258  * @brief Get the management firmware version value
259  *
260  * @param p_hwfn
261  * @param p_ptt
262  * @param p_mfw_ver    - mfw version value
263  * @param p_running_bundle_id	- image id in nvram; Optional.
264  *
265  * @return int - 0 - operation was successful.
266  */
267 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
268 			struct qed_ptt *p_ptt,
269 			u32 *p_mfw_ver, u32 *p_running_bundle_id);
270 
271 /**
272  * @brief Get the MBI version value
273  *
274  * @param p_hwfn
275  * @param p_ptt
276  * @param p_mbi_ver - A pointer to a variable to be filled with the MBI version.
277  *
278  * @return int - 0 - operation was successful.
279  */
280 int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
281 			struct qed_ptt *p_ptt, u32 *p_mbi_ver);
282 
283 /**
284  * @brief Get media type value of the port.
285  *
286  * @param cdev      - qed dev pointer
287  * @param mfw_ver    - media type value
288  *
289  * @return int -
290  *      0 - Operation was successul.
291  *      -EBUSY - Operation failed
292  */
293 int qed_mcp_get_media_type(struct qed_dev      *cdev,
294 			   u32                  *media_type);
295 
296 /**
297  * @brief General function for sending commands to the MCP
298  *        mailbox. It acquire mutex lock for the entire
299  *        operation, from sending the request until the MCP
300  *        response. Waiting for MCP response will be checked up
301  *        to 5 seconds every 5ms.
302  *
303  * @param p_hwfn     - hw function
304  * @param p_ptt      - PTT required for register access
305  * @param cmd        - command to be sent to the MCP.
306  * @param param      - Optional param
307  * @param o_mcp_resp - The MCP response code (exclude sequence).
308  * @param o_mcp_param- Optional parameter provided by the MCP
309  *                     response
310  * @return int - 0 - operation
311  * was successul.
312  */
313 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
314 		struct qed_ptt *p_ptt,
315 		u32 cmd,
316 		u32 param,
317 		u32 *o_mcp_resp,
318 		u32 *o_mcp_param);
319 
320 /**
321  * @brief - drains the nig, allowing completion to pass in case of pauses.
322  *          (Should be called only from sleepable context)
323  *
324  * @param p_hwfn
325  * @param p_ptt
326  */
327 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
328 		  struct qed_ptt *p_ptt);
329 
330 /**
331  * @brief Get the flash size value
332  *
333  * @param p_hwfn
334  * @param p_ptt
335  * @param p_flash_size  - flash size in bytes to be filled.
336  *
337  * @return int - 0 - operation was successul.
338  */
339 int qed_mcp_get_flash_size(struct qed_hwfn     *p_hwfn,
340 			   struct qed_ptt       *p_ptt,
341 			   u32 *p_flash_size);
342 
343 /**
344  * @brief Send driver version to MFW
345  *
346  * @param p_hwfn
347  * @param p_ptt
348  * @param version - Version value
349  * @param name - Protocol driver name
350  *
351  * @return int - 0 - operation was successul.
352  */
353 int
354 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
355 			 struct qed_ptt *p_ptt,
356 			 struct qed_mcp_drv_version *p_ver);
357 
358 /**
359  * @brief Notify MFW about the change in base device properties
360  *
361  *  @param p_hwfn
362  *  @param p_ptt
363  *  @param client - qed client type
364  *
365  * @return int - 0 - operation was successful.
366  */
367 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
368 				     struct qed_ptt *p_ptt,
369 				     enum qed_ov_client client);
370 
371 /**
372  * @brief Notify MFW about the driver state
373  *
374  *  @param p_hwfn
375  *  @param p_ptt
376  *  @param drv_state - Driver state
377  *
378  * @return int - 0 - operation was successful.
379  */
380 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
381 				   struct qed_ptt *p_ptt,
382 				   enum qed_ov_driver_state drv_state);
383 
384 /**
385  * @brief Send MTU size to MFW
386  *
387  *  @param p_hwfn
388  *  @param p_ptt
389  *  @param mtu - MTU size
390  *
391  * @return int - 0 - operation was successful.
392  */
393 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
394 			  struct qed_ptt *p_ptt, u16 mtu);
395 
396 /**
397  * @brief Send MAC address to MFW
398  *
399  *  @param p_hwfn
400  *  @param p_ptt
401  *  @param mac - MAC address
402  *
403  * @return int - 0 - operation was successful.
404  */
405 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
406 			  struct qed_ptt *p_ptt, u8 *mac);
407 
408 /**
409  * @brief Send WOL mode to MFW
410  *
411  *  @param p_hwfn
412  *  @param p_ptt
413  *  @param wol - WOL mode
414  *
415  * @return int - 0 - operation was successful.
416  */
417 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
418 			  struct qed_ptt *p_ptt,
419 			  enum qed_ov_wol wol);
420 
421 /**
422  * @brief Set LED status
423  *
424  *  @param p_hwfn
425  *  @param p_ptt
426  *  @param mode - LED mode
427  *
428  * @return int - 0 - operation was successful.
429  */
430 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
431 		    struct qed_ptt *p_ptt,
432 		    enum qed_led_mode mode);
433 
434 /**
435  * @brief Read from nvm
436  *
437  *  @param cdev
438  *  @param addr - nvm offset
439  *  @param p_buf - nvm read buffer
440  *  @param len - buffer len
441  *
442  * @return int - 0 - operation was successful.
443  */
444 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
445 
446 /**
447  * @brief Write to nvm
448  *
449  *  @param cdev
450  *  @param addr - nvm offset
451  *  @param cmd - nvm command
452  *  @param p_buf - nvm write buffer
453  *  @param len - buffer len
454  *
455  * @return int - 0 - operation was successful.
456  */
457 int qed_mcp_nvm_write(struct qed_dev *cdev,
458 		      u32 cmd, u32 addr, u8 *p_buf, u32 len);
459 
460 /**
461  * @brief Put file begin
462  *
463  *  @param cdev
464  *  @param addr - nvm offset
465  *
466  * @return int - 0 - operation was successful.
467  */
468 int qed_mcp_nvm_put_file_begin(struct qed_dev *cdev, u32 addr);
469 
470 /**
471  * @brief Check latest response
472  *
473  *  @param cdev
474  *  @param p_buf - nvm write buffer
475  *
476  * @return int - 0 - operation was successful.
477  */
478 int qed_mcp_nvm_resp(struct qed_dev *cdev, u8 *p_buf);
479 
480 struct qed_nvm_image_att {
481 	u32 start_addr;
482 	u32 length;
483 };
484 
485 /**
486  * @brief Allows reading a whole nvram image
487  *
488  * @param p_hwfn
489  * @param image_id - image to get attributes for
490  * @param p_image_att - image attributes structure into which to fill data
491  *
492  * @return int - 0 - operation was successful.
493  */
494 int
495 qed_mcp_get_nvm_image_att(struct qed_hwfn *p_hwfn,
496 			  enum qed_nvm_images image_id,
497 			  struct qed_nvm_image_att *p_image_att);
498 
499 /**
500  * @brief Allows reading a whole nvram image
501  *
502  * @param p_hwfn
503  * @param image_id - image requested for reading
504  * @param p_buffer - allocated buffer into which to fill data
505  * @param buffer_len - length of the allocated buffer.
506  *
507  * @return 0 iff p_buffer now contains the nvram image.
508  */
509 int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn,
510 			  enum qed_nvm_images image_id,
511 			  u8 *p_buffer, u32 buffer_len);
512 
513 /**
514  * @brief Bist register test
515  *
516  *  @param p_hwfn    - hw function
517  *  @param p_ptt     - PTT required for register access
518  *
519  * @return int - 0 - operation was successful.
520  */
521 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
522 			       struct qed_ptt *p_ptt);
523 
524 /**
525  * @brief Bist clock test
526  *
527  *  @param p_hwfn    - hw function
528  *  @param p_ptt     - PTT required for register access
529  *
530  * @return int - 0 - operation was successful.
531  */
532 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
533 			    struct qed_ptt *p_ptt);
534 
535 /**
536  * @brief Bist nvm test - get number of images
537  *
538  *  @param p_hwfn       - hw function
539  *  @param p_ptt        - PTT required for register access
540  *  @param num_images   - number of images if operation was
541  *			  successful. 0 if not.
542  *
543  * @return int - 0 - operation was successful.
544  */
545 int qed_mcp_bist_nvm_get_num_images(struct qed_hwfn *p_hwfn,
546 				    struct qed_ptt *p_ptt,
547 				    u32 *num_images);
548 
549 /**
550  * @brief Bist nvm test - get image attributes by index
551  *
552  *  @param p_hwfn      - hw function
553  *  @param p_ptt       - PTT required for register access
554  *  @param p_image_att - Attributes of image
555  *  @param image_index - Index of image to get information for
556  *
557  * @return int - 0 - operation was successful.
558  */
559 int qed_mcp_bist_nvm_get_image_att(struct qed_hwfn *p_hwfn,
560 				   struct qed_ptt *p_ptt,
561 				   struct bist_nvm_image_att *p_image_att,
562 				   u32 image_index);
563 
564 /* Using hwfn number (and not pf_num) is required since in CMT mode,
565  * same pf_num may be used by two different hwfn
566  * TODO - this shouldn't really be in .h file, but until all fields
567  * required during hw-init will be placed in their correct place in shmem
568  * we need it in qed_dev.c [for readin the nvram reflection in shmem].
569  */
570 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ?	       \
571 					    ((rel_pfid) |		       \
572 					     ((p_hwfn)->abs_pf_id & 1) << 3) : \
573 					    rel_pfid)
574 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
575 
576 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id %			  \
577 				 ((_p_hwfn)->cdev->num_ports_in_engine * \
578 				  qed_device_num_engines((_p_hwfn)->cdev)))
579 
580 struct qed_mcp_info {
581 	/* List for mailbox commands which were sent and wait for a response */
582 	struct list_head			cmd_list;
583 
584 	/* Spinlock used for protecting the access to the mailbox commands list
585 	 * and the sending of the commands.
586 	 */
587 	spinlock_t				cmd_lock;
588 
589 	/* Spinlock used for syncing SW link-changes and link-changes
590 	 * originating from attention context.
591 	 */
592 	spinlock_t				link_lock;
593 	bool					block_mb_sending;
594 	u32					public_base;
595 	u32					drv_mb_addr;
596 	u32					mfw_mb_addr;
597 	u32					port_addr;
598 	u16					drv_mb_seq;
599 	u16					drv_pulse_seq;
600 	struct qed_mcp_link_params		link_input;
601 	struct qed_mcp_link_state		link_output;
602 	struct qed_mcp_link_capabilities	link_capabilities;
603 	struct qed_mcp_function_info		func_info;
604 	u8					*mfw_mb_cur;
605 	u8					*mfw_mb_shadow;
606 	u16					mfw_mb_length;
607 	u32					mcp_hist;
608 
609 	/* Capabilties negotiated with the MFW */
610 	u32					capabilities;
611 };
612 
613 struct qed_mcp_mb_params {
614 	u32			cmd;
615 	u32			param;
616 	void			*p_data_src;
617 	u8			data_src_size;
618 	void			*p_data_dst;
619 	u8			data_dst_size;
620 	u32			mcp_resp;
621 	u32			mcp_param;
622 };
623 
624 /**
625  * @brief Initialize the interface with the MCP
626  *
627  * @param p_hwfn - HW func
628  * @param p_ptt - PTT required for register access
629  *
630  * @return int
631  */
632 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
633 		     struct qed_ptt *p_ptt);
634 
635 /**
636  * @brief Initialize the port interface with the MCP
637  *
638  * @param p_hwfn
639  * @param p_ptt
640  * Can only be called after `num_ports_in_engines' is set
641  */
642 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
643 			   struct qed_ptt *p_ptt);
644 /**
645  * @brief Releases resources allocated during the init process.
646  *
647  * @param p_hwfn - HW func
648  * @param p_ptt - PTT required for register access
649  *
650  * @return int
651  */
652 
653 int qed_mcp_free(struct qed_hwfn *p_hwfn);
654 
655 /**
656  * @brief This function is called from the DPC context. After
657  * pointing PTT to the mfw mb, check for events sent by the MCP
658  * to the driver and ack them. In case a critical event
659  * detected, it will be handled here, otherwise the work will be
660  * queued to a sleepable work-queue.
661  *
662  * @param p_hwfn - HW function
663  * @param p_ptt - PTT required for register access
664  * @return int - 0 - operation
665  * was successul.
666  */
667 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
668 			  struct qed_ptt *p_ptt);
669 
670 enum qed_drv_role {
671 	QED_DRV_ROLE_OS,
672 	QED_DRV_ROLE_KDUMP,
673 };
674 
675 struct qed_load_req_params {
676 	/* Input params */
677 	enum qed_drv_role drv_role;
678 	u8 timeout_val;
679 	bool avoid_eng_reset;
680 	enum qed_override_force_load override_force_load;
681 
682 	/* Output params */
683 	u32 load_code;
684 };
685 
686 /**
687  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
688  *        returns whether this PF is the first on the engine/port or function.
689  *
690  * @param p_hwfn
691  * @param p_ptt
692  * @param p_params
693  *
694  * @return int - 0 - Operation was successful.
695  */
696 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
697 		     struct qed_ptt *p_ptt,
698 		     struct qed_load_req_params *p_params);
699 
700 /**
701  * @brief Sends a UNLOAD_REQ message to the MFW
702  *
703  * @param p_hwfn
704  * @param p_ptt
705  *
706  * @return int - 0 - Operation was successful.
707  */
708 int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
709 
710 /**
711  * @brief Sends a UNLOAD_DONE message to the MFW
712  *
713  * @param p_hwfn
714  * @param p_ptt
715  *
716  * @return int - 0 - Operation was successful.
717  */
718 int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
719 
720 /**
721  * @brief Read the MFW mailbox into Current buffer.
722  *
723  * @param p_hwfn
724  * @param p_ptt
725  */
726 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
727 		     struct qed_ptt *p_ptt);
728 
729 /**
730  * @brief Ack to mfw that driver finished FLR process for VFs
731  *
732  * @param p_hwfn
733  * @param p_ptt
734  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
735  *
736  * @param return int - 0 upon success.
737  */
738 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
739 		       struct qed_ptt *p_ptt, u32 *vfs_to_ack);
740 
741 /**
742  * @brief - calls during init to read shmem of all function-related info.
743  *
744  * @param p_hwfn
745  *
746  * @param return 0 upon success.
747  */
748 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
749 				 struct qed_ptt *p_ptt);
750 
751 /**
752  * @brief - Reset the MCP using mailbox command.
753  *
754  * @param p_hwfn
755  * @param p_ptt
756  *
757  * @param return 0 upon success.
758  */
759 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
760 		  struct qed_ptt *p_ptt);
761 
762 /**
763  * @brief - Sends an NVM read command request to the MFW to get
764  *        a buffer.
765  *
766  * @param p_hwfn
767  * @param p_ptt
768  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
769  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
770  * @param param - [0:23] - Offset [24:31] - Size
771  * @param o_mcp_resp - MCP response
772  * @param o_mcp_param - MCP response param
773  * @param o_txn_size -  Buffer size output
774  * @param o_buf - Pointer to the buffer returned by the MFW.
775  *
776  * @param return 0 upon success.
777  */
778 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
779 		       struct qed_ptt *p_ptt,
780 		       u32 cmd,
781 		       u32 param,
782 		       u32 *o_mcp_resp,
783 		       u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
784 
785 /**
786  * @brief indicates whether the MFW objects [under mcp_info] are accessible
787  *
788  * @param p_hwfn
789  *
790  * @return true iff MFW is running and mcp_info is initialized
791  */
792 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
793 
794 /**
795  * @brief request MFW to configure MSI-X for a VF
796  *
797  * @param p_hwfn
798  * @param p_ptt
799  * @param vf_id - absolute inside engine
800  * @param num_sbs - number of entries to request
801  *
802  * @return int
803  */
804 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
805 			   struct qed_ptt *p_ptt, u8 vf_id, u8 num);
806 
807 /**
808  * @brief - Halt the MCP.
809  *
810  * @param p_hwfn
811  * @param p_ptt
812  *
813  * @param return 0 upon success.
814  */
815 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
816 
817 /**
818  * @brief - Wake up the MCP.
819  *
820  * @param p_hwfn
821  * @param p_ptt
822  *
823  * @param return 0 upon success.
824  */
825 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
826 
827 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
828 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
829 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
830 				     struct qed_ptt *p_ptt,
831 				     struct qed_mcp_link_state *p_link,
832 				     u8 max_bw);
833 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
834 				     struct qed_ptt *p_ptt,
835 				     struct qed_mcp_link_state *p_link,
836 				     u8 min_bw);
837 
838 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
839 			  struct qed_ptt *p_ptt, u32 mask_parities);
840 
841 /**
842  * @brief - Sets the MFW's max value for the given resource
843  *
844  *  @param p_hwfn
845  *  @param p_ptt
846  *  @param res_id
847  *  @param resc_max_val
848  *  @param p_mcp_resp
849  *
850  * @return int - 0 - operation was successful.
851  */
852 int
853 qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn,
854 			 struct qed_ptt *p_ptt,
855 			 enum qed_resources res_id,
856 			 u32 resc_max_val, u32 *p_mcp_resp);
857 
858 /**
859  * @brief - Gets the MFW allocation info for the given resource
860  *
861  *  @param p_hwfn
862  *  @param p_ptt
863  *  @param res_id
864  *  @param p_mcp_resp
865  *  @param p_resc_num
866  *  @param p_resc_start
867  *
868  * @return int - 0 - operation was successful.
869  */
870 int
871 qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
872 		      struct qed_ptt *p_ptt,
873 		      enum qed_resources res_id,
874 		      u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start);
875 
876 /**
877  * @brief Send eswitch mode to MFW
878  *
879  *  @param p_hwfn
880  *  @param p_ptt
881  *  @param eswitch - eswitch mode
882  *
883  * @return int - 0 - operation was successful.
884  */
885 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
886 			      struct qed_ptt *p_ptt,
887 			      enum qed_ov_eswitch eswitch);
888 
889 #define QED_MCP_RESC_LOCK_MIN_VAL       RESOURCE_DUMP
890 #define QED_MCP_RESC_LOCK_MAX_VAL       31
891 
892 enum qed_resc_lock {
893 	QED_RESC_LOCK_DBG_DUMP = QED_MCP_RESC_LOCK_MIN_VAL,
894 	QED_RESC_LOCK_PTP_PORT0,
895 	QED_RESC_LOCK_PTP_PORT1,
896 	QED_RESC_LOCK_PTP_PORT2,
897 	QED_RESC_LOCK_PTP_PORT3,
898 	QED_RESC_LOCK_RESC_ALLOC = QED_MCP_RESC_LOCK_MAX_VAL,
899 	QED_RESC_LOCK_RESC_INVALID
900 };
901 
902 /**
903  * @brief - Initiates PF FLR
904  *
905  *  @param p_hwfn
906  *  @param p_ptt
907  *
908  * @return int - 0 - operation was successful.
909  */
910 int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
911 struct qed_resc_lock_params {
912 	/* Resource number [valid values are 0..31] */
913 	u8 resource;
914 
915 	/* Lock timeout value in seconds [default, none or 1..254] */
916 	u8 timeout;
917 #define QED_MCP_RESC_LOCK_TO_DEFAULT    0
918 #define QED_MCP_RESC_LOCK_TO_NONE       255
919 
920 	/* Number of times to retry locking */
921 	u8 retry_num;
922 #define QED_MCP_RESC_LOCK_RETRY_CNT_DFLT        10
923 
924 	/* The interval in usec between retries */
925 	u16 retry_interval;
926 #define QED_MCP_RESC_LOCK_RETRY_VAL_DFLT        10000
927 
928 	/* Use sleep or delay between retries */
929 	bool sleep_b4_retry;
930 
931 	/* Will be set as true if the resource is free and granted */
932 	bool b_granted;
933 
934 	/* Will be filled with the resource owner.
935 	 * [0..15 = PF0-15, 16 = MFW]
936 	 */
937 	u8 owner;
938 };
939 
940 /**
941  * @brief Acquires MFW generic resource lock
942  *
943  *  @param p_hwfn
944  *  @param p_ptt
945  *  @param p_params
946  *
947  * @return int - 0 - operation was successful.
948  */
949 int
950 qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
951 		  struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params);
952 
953 struct qed_resc_unlock_params {
954 	/* Resource number [valid values are 0..31] */
955 	u8 resource;
956 
957 	/* Allow to release a resource even if belongs to another PF */
958 	bool b_force;
959 
960 	/* Will be set as true if the resource is released */
961 	bool b_released;
962 };
963 
964 /**
965  * @brief Releases MFW generic resource lock
966  *
967  *  @param p_hwfn
968  *  @param p_ptt
969  *  @param p_params
970  *
971  * @return int - 0 - operation was successful.
972  */
973 int
974 qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn,
975 		    struct qed_ptt *p_ptt,
976 		    struct qed_resc_unlock_params *p_params);
977 
978 /**
979  * @brief - default initialization for lock/unlock resource structs
980  *
981  * @param p_lock - lock params struct to be initialized; Can be NULL
982  * @param p_unlock - unlock params struct to be initialized; Can be NULL
983  * @param resource - the requested resource
984  * @paral b_is_permanent - disable retries & aging when set
985  */
986 void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock,
987 				    struct qed_resc_unlock_params *p_unlock,
988 				    enum qed_resc_lock
989 				    resource, bool b_is_permanent);
990 /**
991  * @brief Learn of supported MFW features; To be done during early init
992  *
993  * @param p_hwfn
994  * @param p_ptt
995  */
996 int qed_mcp_get_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
997 
998 /**
999  * @brief Inform MFW of set of features supported by driver. Should be done
1000  * inside the content of the LOAD_REQ.
1001  *
1002  * @param p_hwfn
1003  * @param p_ptt
1004  */
1005 int qed_mcp_set_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1006 
1007 /**
1008  * @brief Populate the nvm info shadow in the given hardware function
1009  *
1010  * @param p_hwfn
1011  */
1012 int qed_mcp_nvm_info_populate(struct qed_hwfn *p_hwfn);
1013 
1014 #endif
1015