GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / net / ethernet / qlogic / qed / qed_mcp.h
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 p_ptt
288  * @param mfw_ver    - media type value
289  *
290  * @return int -
291  *      0 - Operation was successul.
292  *      -EBUSY - Operation failed
293  */
294 int qed_mcp_get_media_type(struct qed_hwfn *p_hwfn,
295                            struct qed_ptt *p_ptt, u32 *media_type);
296
297 /**
298  * @brief General function for sending commands to the MCP
299  *        mailbox. It acquire mutex lock for the entire
300  *        operation, from sending the request until the MCP
301  *        response. Waiting for MCP response will be checked up
302  *        to 5 seconds every 5ms.
303  *
304  * @param p_hwfn     - hw function
305  * @param p_ptt      - PTT required for register access
306  * @param cmd        - command to be sent to the MCP.
307  * @param param      - Optional param
308  * @param o_mcp_resp - The MCP response code (exclude sequence).
309  * @param o_mcp_param- Optional parameter provided by the MCP
310  *                     response
311  * @return int - 0 - operation
312  * was successul.
313  */
314 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
315                 struct qed_ptt *p_ptt,
316                 u32 cmd,
317                 u32 param,
318                 u32 *o_mcp_resp,
319                 u32 *o_mcp_param);
320
321 /**
322  * @brief - drains the nig, allowing completion to pass in case of pauses.
323  *          (Should be called only from sleepable context)
324  *
325  * @param p_hwfn
326  * @param p_ptt
327  */
328 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
329                   struct qed_ptt *p_ptt);
330
331 /**
332  * @brief Get the flash size value
333  *
334  * @param p_hwfn
335  * @param p_ptt
336  * @param p_flash_size  - flash size in bytes to be filled.
337  *
338  * @return int - 0 - operation was successul.
339  */
340 int qed_mcp_get_flash_size(struct qed_hwfn     *p_hwfn,
341                            struct qed_ptt       *p_ptt,
342                            u32 *p_flash_size);
343
344 /**
345  * @brief Send driver version to MFW
346  *
347  * @param p_hwfn
348  * @param p_ptt
349  * @param version - Version value
350  * @param name - Protocol driver name
351  *
352  * @return int - 0 - operation was successul.
353  */
354 int
355 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
356                          struct qed_ptt *p_ptt,
357                          struct qed_mcp_drv_version *p_ver);
358
359 /**
360  * @brief Notify MFW about the change in base device properties
361  *
362  *  @param p_hwfn
363  *  @param p_ptt
364  *  @param client - qed client type
365  *
366  * @return int - 0 - operation was successful.
367  */
368 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
369                                      struct qed_ptt *p_ptt,
370                                      enum qed_ov_client client);
371
372 /**
373  * @brief Notify MFW about the driver state
374  *
375  *  @param p_hwfn
376  *  @param p_ptt
377  *  @param drv_state - Driver state
378  *
379  * @return int - 0 - operation was successful.
380  */
381 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
382                                    struct qed_ptt *p_ptt,
383                                    enum qed_ov_driver_state drv_state);
384
385 /**
386  * @brief Send MTU size to MFW
387  *
388  *  @param p_hwfn
389  *  @param p_ptt
390  *  @param mtu - MTU size
391  *
392  * @return int - 0 - operation was successful.
393  */
394 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
395                           struct qed_ptt *p_ptt, u16 mtu);
396
397 /**
398  * @brief Send MAC address to MFW
399  *
400  *  @param p_hwfn
401  *  @param p_ptt
402  *  @param mac - MAC address
403  *
404  * @return int - 0 - operation was successful.
405  */
406 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
407                           struct qed_ptt *p_ptt, u8 *mac);
408
409 /**
410  * @brief Send WOL mode to MFW
411  *
412  *  @param p_hwfn
413  *  @param p_ptt
414  *  @param wol - WOL mode
415  *
416  * @return int - 0 - operation was successful.
417  */
418 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
419                           struct qed_ptt *p_ptt,
420                           enum qed_ov_wol wol);
421
422 /**
423  * @brief Set LED status
424  *
425  *  @param p_hwfn
426  *  @param p_ptt
427  *  @param mode - LED mode
428  *
429  * @return int - 0 - operation was successful.
430  */
431 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
432                     struct qed_ptt *p_ptt,
433                     enum qed_led_mode mode);
434
435 /**
436  * @brief Read from nvm
437  *
438  *  @param cdev
439  *  @param addr - nvm offset
440  *  @param p_buf - nvm read buffer
441  *  @param len - buffer len
442  *
443  * @return int - 0 - operation was successful.
444  */
445 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
446
447 struct qed_nvm_image_att {
448         u32 start_addr;
449         u32 length;
450 };
451
452 /**
453  * @brief Allows reading a whole nvram image
454  *
455  * @param p_hwfn
456  * @param p_ptt
457  * @param image_id - image requested for reading
458  * @param p_buffer - allocated buffer into which to fill data
459  * @param buffer_len - length of the allocated buffer.
460  *
461  * @return 0 iff p_buffer now contains the nvram image.
462  */
463 int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn,
464                           struct qed_ptt *p_ptt,
465                           enum qed_nvm_images image_id,
466                           u8 *p_buffer, u32 buffer_len);
467
468 /**
469  * @brief Bist register test
470  *
471  *  @param p_hwfn    - hw function
472  *  @param p_ptt     - PTT required for register access
473  *
474  * @return int - 0 - operation was successful.
475  */
476 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
477                                struct qed_ptt *p_ptt);
478
479 /**
480  * @brief Bist clock test
481  *
482  *  @param p_hwfn    - hw function
483  *  @param p_ptt     - PTT required for register access
484  *
485  * @return int - 0 - operation was successful.
486  */
487 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
488                             struct qed_ptt *p_ptt);
489
490 /**
491  * @brief Bist nvm test - get number of images
492  *
493  *  @param p_hwfn       - hw function
494  *  @param p_ptt        - PTT required for register access
495  *  @param num_images   - number of images if operation was
496  *                        successful. 0 if not.
497  *
498  * @return int - 0 - operation was successful.
499  */
500 int qed_mcp_bist_nvm_test_get_num_images(struct qed_hwfn *p_hwfn,
501                                          struct qed_ptt *p_ptt,
502                                          u32 *num_images);
503
504 /**
505  * @brief Bist nvm test - get image attributes by index
506  *
507  *  @param p_hwfn      - hw function
508  *  @param p_ptt       - PTT required for register access
509  *  @param p_image_att - Attributes of image
510  *  @param image_index - Index of image to get information for
511  *
512  * @return int - 0 - operation was successful.
513  */
514 int qed_mcp_bist_nvm_test_get_image_att(struct qed_hwfn *p_hwfn,
515                                         struct qed_ptt *p_ptt,
516                                         struct bist_nvm_image_att *p_image_att,
517                                         u32 image_index);
518
519 /* Using hwfn number (and not pf_num) is required since in CMT mode,
520  * same pf_num may be used by two different hwfn
521  * TODO - this shouldn't really be in .h file, but until all fields
522  * required during hw-init will be placed in their correct place in shmem
523  * we need it in qed_dev.c [for readin the nvram reflection in shmem].
524  */
525 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ?        \
526                                             ((rel_pfid) |                      \
527                                              ((p_hwfn)->abs_pf_id & 1) << 3) : \
528                                             rel_pfid)
529 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
530
531 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id %                   \
532                                  ((_p_hwfn)->cdev->num_ports_in_engine * \
533                                   qed_device_num_engines((_p_hwfn)->cdev)))
534
535 struct qed_mcp_info {
536         /* List for mailbox commands which were sent and wait for a response */
537         struct list_head                        cmd_list;
538
539         /* Spinlock used for protecting the access to the mailbox commands list
540          * and the sending of the commands.
541          */
542         spinlock_t                              cmd_lock;
543
544         /* Flag to indicate whether sending a MFW mailbox command is blocked */
545         bool                                    b_block_cmd;
546
547         /* Spinlock used for syncing SW link-changes and link-changes
548          * originating from attention context.
549          */
550         spinlock_t                              link_lock;
551
552         u32                                     public_base;
553         u32                                     drv_mb_addr;
554         u32                                     mfw_mb_addr;
555         u32                                     port_addr;
556         u16                                     drv_mb_seq;
557         u16                                     drv_pulse_seq;
558         struct qed_mcp_link_params              link_input;
559         struct qed_mcp_link_state               link_output;
560         struct qed_mcp_link_capabilities        link_capabilities;
561         struct qed_mcp_function_info            func_info;
562         u8                                      *mfw_mb_cur;
563         u8                                      *mfw_mb_shadow;
564         u16                                     mfw_mb_length;
565         u32                                     mcp_hist;
566
567         /* Capabilties negotiated with the MFW */
568         u32                                     capabilities;
569 };
570
571 struct qed_mcp_mb_params {
572         u32 cmd;
573         u32 param;
574         void *p_data_src;
575         void *p_data_dst;
576         u8 data_src_size;
577         u8 data_dst_size;
578         u32 mcp_resp;
579         u32 mcp_param;
580         u32 flags;
581 #define QED_MB_FLAG_CAN_SLEEP   (0x1 << 0)
582 #define QED_MB_FLAG_AVOID_BLOCK (0x1 << 1)
583 #define QED_MB_FLAGS_IS_SET(params, flag) \
584         ({ typeof(params) __params = (params); \
585            (__params && (__params->flags & QED_MB_FLAG_ ## flag)); })
586 };
587
588 /**
589  * @brief Initialize the interface with the MCP
590  *
591  * @param p_hwfn - HW func
592  * @param p_ptt - PTT required for register access
593  *
594  * @return int
595  */
596 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
597                      struct qed_ptt *p_ptt);
598
599 /**
600  * @brief Initialize the port interface with the MCP
601  *
602  * @param p_hwfn
603  * @param p_ptt
604  * Can only be called after `num_ports_in_engines' is set
605  */
606 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
607                            struct qed_ptt *p_ptt);
608 /**
609  * @brief Releases resources allocated during the init process.
610  *
611  * @param p_hwfn - HW func
612  * @param p_ptt - PTT required for register access
613  *
614  * @return int
615  */
616
617 int qed_mcp_free(struct qed_hwfn *p_hwfn);
618
619 /**
620  * @brief This function is called from the DPC context. After
621  * pointing PTT to the mfw mb, check for events sent by the MCP
622  * to the driver and ack them. In case a critical event
623  * detected, it will be handled here, otherwise the work will be
624  * queued to a sleepable work-queue.
625  *
626  * @param p_hwfn - HW function
627  * @param p_ptt - PTT required for register access
628  * @return int - 0 - operation
629  * was successul.
630  */
631 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
632                           struct qed_ptt *p_ptt);
633
634 enum qed_drv_role {
635         QED_DRV_ROLE_OS,
636         QED_DRV_ROLE_KDUMP,
637 };
638
639 struct qed_load_req_params {
640         /* Input params */
641         enum qed_drv_role drv_role;
642         u8 timeout_val;
643         bool avoid_eng_reset;
644         enum qed_override_force_load override_force_load;
645
646         /* Output params */
647         u32 load_code;
648 };
649
650 /**
651  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
652  *        returns whether this PF is the first on the engine/port or function.
653  *
654  * @param p_hwfn
655  * @param p_ptt
656  * @param p_params
657  *
658  * @return int - 0 - Operation was successful.
659  */
660 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
661                      struct qed_ptt *p_ptt,
662                      struct qed_load_req_params *p_params);
663
664 /**
665  * @brief Sends a UNLOAD_REQ message to the MFW
666  *
667  * @param p_hwfn
668  * @param p_ptt
669  *
670  * @return int - 0 - Operation was successful.
671  */
672 int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
673
674 /**
675  * @brief Sends a UNLOAD_DONE message to the MFW
676  *
677  * @param p_hwfn
678  * @param p_ptt
679  *
680  * @return int - 0 - Operation was successful.
681  */
682 int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
683
684 /**
685  * @brief Read the MFW mailbox into Current buffer.
686  *
687  * @param p_hwfn
688  * @param p_ptt
689  */
690 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
691                      struct qed_ptt *p_ptt);
692
693 /**
694  * @brief Ack to mfw that driver finished FLR process for VFs
695  *
696  * @param p_hwfn
697  * @param p_ptt
698  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
699  *
700  * @param return int - 0 upon success.
701  */
702 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
703                        struct qed_ptt *p_ptt, u32 *vfs_to_ack);
704
705 /**
706  * @brief - calls during init to read shmem of all function-related info.
707  *
708  * @param p_hwfn
709  *
710  * @param return 0 upon success.
711  */
712 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
713                                  struct qed_ptt *p_ptt);
714
715 /**
716  * @brief - Reset the MCP using mailbox command.
717  *
718  * @param p_hwfn
719  * @param p_ptt
720  *
721  * @param return 0 upon success.
722  */
723 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
724                   struct qed_ptt *p_ptt);
725
726 /**
727  * @brief - Sends an NVM read command request to the MFW to get
728  *        a buffer.
729  *
730  * @param p_hwfn
731  * @param p_ptt
732  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
733  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
734  * @param param - [0:23] - Offset [24:31] - Size
735  * @param o_mcp_resp - MCP response
736  * @param o_mcp_param - MCP response param
737  * @param o_txn_size -  Buffer size output
738  * @param o_buf - Pointer to the buffer returned by the MFW.
739  *
740  * @param return 0 upon success.
741  */
742 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
743                        struct qed_ptt *p_ptt,
744                        u32 cmd,
745                        u32 param,
746                        u32 *o_mcp_resp,
747                        u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
748
749 /**
750  * @brief indicates whether the MFW objects [under mcp_info] are accessible
751  *
752  * @param p_hwfn
753  *
754  * @return true iff MFW is running and mcp_info is initialized
755  */
756 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
757
758 /**
759  * @brief request MFW to configure MSI-X for a VF
760  *
761  * @param p_hwfn
762  * @param p_ptt
763  * @param vf_id - absolute inside engine
764  * @param num_sbs - number of entries to request
765  *
766  * @return int
767  */
768 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
769                            struct qed_ptt *p_ptt, u8 vf_id, u8 num);
770
771 /**
772  * @brief - Halt the MCP.
773  *
774  * @param p_hwfn
775  * @param p_ptt
776  *
777  * @param return 0 upon success.
778  */
779 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
780
781 /**
782  * @brief - Wake up the MCP.
783  *
784  * @param p_hwfn
785  * @param p_ptt
786  *
787  * @param return 0 upon success.
788  */
789 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
790
791 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
792 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
793 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
794                                      struct qed_ptt *p_ptt,
795                                      struct qed_mcp_link_state *p_link,
796                                      u8 max_bw);
797 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
798                                      struct qed_ptt *p_ptt,
799                                      struct qed_mcp_link_state *p_link,
800                                      u8 min_bw);
801
802 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
803                           struct qed_ptt *p_ptt, u32 mask_parities);
804
805 /**
806  * @brief - Sets the MFW's max value for the given resource
807  *
808  *  @param p_hwfn
809  *  @param p_ptt
810  *  @param res_id
811  *  @param resc_max_val
812  *  @param p_mcp_resp
813  *
814  * @return int - 0 - operation was successful.
815  */
816 int
817 qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn,
818                          struct qed_ptt *p_ptt,
819                          enum qed_resources res_id,
820                          u32 resc_max_val, u32 *p_mcp_resp);
821
822 /**
823  * @brief - Gets the MFW allocation info for the given resource
824  *
825  *  @param p_hwfn
826  *  @param p_ptt
827  *  @param res_id
828  *  @param p_mcp_resp
829  *  @param p_resc_num
830  *  @param p_resc_start
831  *
832  * @return int - 0 - operation was successful.
833  */
834 int
835 qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
836                       struct qed_ptt *p_ptt,
837                       enum qed_resources res_id,
838                       u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start);
839
840 /**
841  * @brief Send eswitch mode to MFW
842  *
843  *  @param p_hwfn
844  *  @param p_ptt
845  *  @param eswitch - eswitch mode
846  *
847  * @return int - 0 - operation was successful.
848  */
849 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
850                               struct qed_ptt *p_ptt,
851                               enum qed_ov_eswitch eswitch);
852
853 #define QED_MCP_RESC_LOCK_MIN_VAL       RESOURCE_DUMP
854 #define QED_MCP_RESC_LOCK_MAX_VAL       31
855
856 enum qed_resc_lock {
857         QED_RESC_LOCK_DBG_DUMP = QED_MCP_RESC_LOCK_MIN_VAL,
858         QED_RESC_LOCK_PTP_PORT0,
859         QED_RESC_LOCK_PTP_PORT1,
860         QED_RESC_LOCK_PTP_PORT2,
861         QED_RESC_LOCK_PTP_PORT3,
862         QED_RESC_LOCK_RESC_ALLOC = QED_MCP_RESC_LOCK_MAX_VAL,
863         QED_RESC_LOCK_RESC_INVALID
864 };
865
866 /**
867  * @brief - Initiates PF FLR
868  *
869  *  @param p_hwfn
870  *  @param p_ptt
871  *
872  * @return int - 0 - operation was successful.
873  */
874 int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
875 struct qed_resc_lock_params {
876         /* Resource number [valid values are 0..31] */
877         u8 resource;
878
879         /* Lock timeout value in seconds [default, none or 1..254] */
880         u8 timeout;
881 #define QED_MCP_RESC_LOCK_TO_DEFAULT    0
882 #define QED_MCP_RESC_LOCK_TO_NONE       255
883
884         /* Number of times to retry locking */
885         u8 retry_num;
886 #define QED_MCP_RESC_LOCK_RETRY_CNT_DFLT        10
887
888         /* The interval in usec between retries */
889         u16 retry_interval;
890 #define QED_MCP_RESC_LOCK_RETRY_VAL_DFLT        10000
891
892         /* Use sleep or delay between retries */
893         bool sleep_b4_retry;
894
895         /* Will be set as true if the resource is free and granted */
896         bool b_granted;
897
898         /* Will be filled with the resource owner.
899          * [0..15 = PF0-15, 16 = MFW]
900          */
901         u8 owner;
902 };
903
904 /**
905  * @brief Acquires MFW generic resource lock
906  *
907  *  @param p_hwfn
908  *  @param p_ptt
909  *  @param p_params
910  *
911  * @return int - 0 - operation was successful.
912  */
913 int
914 qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
915                   struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params);
916
917 struct qed_resc_unlock_params {
918         /* Resource number [valid values are 0..31] */
919         u8 resource;
920
921         /* Allow to release a resource even if belongs to another PF */
922         bool b_force;
923
924         /* Will be set as true if the resource is released */
925         bool b_released;
926 };
927
928 /**
929  * @brief Releases MFW generic resource lock
930  *
931  *  @param p_hwfn
932  *  @param p_ptt
933  *  @param p_params
934  *
935  * @return int - 0 - operation was successful.
936  */
937 int
938 qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn,
939                     struct qed_ptt *p_ptt,
940                     struct qed_resc_unlock_params *p_params);
941
942 /**
943  * @brief - default initialization for lock/unlock resource structs
944  *
945  * @param p_lock - lock params struct to be initialized; Can be NULL
946  * @param p_unlock - unlock params struct to be initialized; Can be NULL
947  * @param resource - the requested resource
948  * @paral b_is_permanent - disable retries & aging when set
949  */
950 void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock,
951                                     struct qed_resc_unlock_params *p_unlock,
952                                     enum qed_resc_lock
953                                     resource, bool b_is_permanent);
954 /**
955  * @brief Learn of supported MFW features; To be done during early init
956  *
957  * @param p_hwfn
958  * @param p_ptt
959  */
960 int qed_mcp_get_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
961
962 /**
963  * @brief Inform MFW of set of features supported by driver. Should be done
964  * inside the content of the LOAD_REQ.
965  *
966  * @param p_hwfn
967  * @param p_ptt
968  */
969 int qed_mcp_set_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
970 #endif