OSDN Git Service

qed: Add support for processing fcoe tlv request.
[uclinux-h8/linux.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 enum qed_mfw_tlv_type {
217         QED_MFW_TLV_GENERIC = 0x1,      /* Core driver TLVs */
218         QED_MFW_TLV_ETH = 0x2,          /* L2 driver TLVs */
219         QED_MFW_TLV_FCOE = 0x4,         /* FCoE protocol TLVs */
220         QED_MFW_TLV_MAX = 0x8,
221 };
222
223 struct qed_mfw_tlv_generic {
224 #define QED_MFW_TLV_FLAGS_SIZE  2
225         struct {
226                 u8 ipv4_csum_offload;
227                 u8 lso_supported;
228                 bool b_set;
229         } flags;
230
231 #define QED_MFW_TLV_MAC_COUNT 3
232         /* First entry for primary MAC, 2 secondary MACs possible */
233         u8 mac[QED_MFW_TLV_MAC_COUNT][6];
234         bool mac_set[QED_MFW_TLV_MAC_COUNT];
235
236         u64 rx_frames;
237         bool rx_frames_set;
238         u64 rx_bytes;
239         bool rx_bytes_set;
240         u64 tx_frames;
241         bool tx_frames_set;
242         u64 tx_bytes;
243         bool tx_bytes_set;
244 };
245
246 union qed_mfw_tlv_data {
247         struct qed_mfw_tlv_generic generic;
248         struct qed_mfw_tlv_eth eth;
249         struct qed_mfw_tlv_fcoe fcoe;
250 };
251
252 /**
253  * @brief - returns the link params of the hw function
254  *
255  * @param p_hwfn
256  *
257  * @returns pointer to link params
258  */
259 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
260
261 /**
262  * @brief - return the link state of the hw function
263  *
264  * @param p_hwfn
265  *
266  * @returns pointer to link state
267  */
268 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
269
270 /**
271  * @brief - return the link capabilities of the hw function
272  *
273  * @param p_hwfn
274  *
275  * @returns pointer to link capabilities
276  */
277 struct qed_mcp_link_capabilities
278         *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
279
280 /**
281  * @brief Request the MFW to set the the link according to 'link_input'.
282  *
283  * @param p_hwfn
284  * @param p_ptt
285  * @param b_up - raise link if `true'. Reset link if `false'.
286  *
287  * @return int
288  */
289 int qed_mcp_set_link(struct qed_hwfn   *p_hwfn,
290                      struct qed_ptt     *p_ptt,
291                      bool               b_up);
292
293 /**
294  * @brief Get the management firmware version value
295  *
296  * @param p_hwfn
297  * @param p_ptt
298  * @param p_mfw_ver    - mfw version value
299  * @param p_running_bundle_id   - image id in nvram; Optional.
300  *
301  * @return int - 0 - operation was successful.
302  */
303 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
304                         struct qed_ptt *p_ptt,
305                         u32 *p_mfw_ver, u32 *p_running_bundle_id);
306
307 /**
308  * @brief Get the MBI version value
309  *
310  * @param p_hwfn
311  * @param p_ptt
312  * @param p_mbi_ver - A pointer to a variable to be filled with the MBI version.
313  *
314  * @return int - 0 - operation was successful.
315  */
316 int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
317                         struct qed_ptt *p_ptt, u32 *p_mbi_ver);
318
319 /**
320  * @brief Get media type value of the port.
321  *
322  * @param cdev      - qed dev pointer
323  * @param mfw_ver    - media type value
324  *
325  * @return int -
326  *      0 - Operation was successul.
327  *      -EBUSY - Operation failed
328  */
329 int qed_mcp_get_media_type(struct qed_dev      *cdev,
330                            u32                  *media_type);
331
332 /**
333  * @brief General function for sending commands to the MCP
334  *        mailbox. It acquire mutex lock for the entire
335  *        operation, from sending the request until the MCP
336  *        response. Waiting for MCP response will be checked up
337  *        to 5 seconds every 5ms.
338  *
339  * @param p_hwfn     - hw function
340  * @param p_ptt      - PTT required for register access
341  * @param cmd        - command to be sent to the MCP.
342  * @param param      - Optional param
343  * @param o_mcp_resp - The MCP response code (exclude sequence).
344  * @param o_mcp_param- Optional parameter provided by the MCP
345  *                     response
346  * @return int - 0 - operation
347  * was successul.
348  */
349 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
350                 struct qed_ptt *p_ptt,
351                 u32 cmd,
352                 u32 param,
353                 u32 *o_mcp_resp,
354                 u32 *o_mcp_param);
355
356 /**
357  * @brief - drains the nig, allowing completion to pass in case of pauses.
358  *          (Should be called only from sleepable context)
359  *
360  * @param p_hwfn
361  * @param p_ptt
362  */
363 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
364                   struct qed_ptt *p_ptt);
365
366 /**
367  * @brief Get the flash size value
368  *
369  * @param p_hwfn
370  * @param p_ptt
371  * @param p_flash_size  - flash size in bytes to be filled.
372  *
373  * @return int - 0 - operation was successul.
374  */
375 int qed_mcp_get_flash_size(struct qed_hwfn     *p_hwfn,
376                            struct qed_ptt       *p_ptt,
377                            u32 *p_flash_size);
378
379 /**
380  * @brief Send driver version to MFW
381  *
382  * @param p_hwfn
383  * @param p_ptt
384  * @param version - Version value
385  * @param name - Protocol driver name
386  *
387  * @return int - 0 - operation was successul.
388  */
389 int
390 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
391                          struct qed_ptt *p_ptt,
392                          struct qed_mcp_drv_version *p_ver);
393
394 /**
395  * @brief Notify MFW about the change in base device properties
396  *
397  *  @param p_hwfn
398  *  @param p_ptt
399  *  @param client - qed client type
400  *
401  * @return int - 0 - operation was successful.
402  */
403 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
404                                      struct qed_ptt *p_ptt,
405                                      enum qed_ov_client client);
406
407 /**
408  * @brief Notify MFW about the driver state
409  *
410  *  @param p_hwfn
411  *  @param p_ptt
412  *  @param drv_state - Driver state
413  *
414  * @return int - 0 - operation was successful.
415  */
416 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
417                                    struct qed_ptt *p_ptt,
418                                    enum qed_ov_driver_state drv_state);
419
420 /**
421  * @brief Send MTU size to MFW
422  *
423  *  @param p_hwfn
424  *  @param p_ptt
425  *  @param mtu - MTU size
426  *
427  * @return int - 0 - operation was successful.
428  */
429 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
430                           struct qed_ptt *p_ptt, u16 mtu);
431
432 /**
433  * @brief Send MAC address to MFW
434  *
435  *  @param p_hwfn
436  *  @param p_ptt
437  *  @param mac - MAC address
438  *
439  * @return int - 0 - operation was successful.
440  */
441 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
442                           struct qed_ptt *p_ptt, u8 *mac);
443
444 /**
445  * @brief Send WOL mode to MFW
446  *
447  *  @param p_hwfn
448  *  @param p_ptt
449  *  @param wol - WOL mode
450  *
451  * @return int - 0 - operation was successful.
452  */
453 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
454                           struct qed_ptt *p_ptt,
455                           enum qed_ov_wol wol);
456
457 /**
458  * @brief Set LED status
459  *
460  *  @param p_hwfn
461  *  @param p_ptt
462  *  @param mode - LED mode
463  *
464  * @return int - 0 - operation was successful.
465  */
466 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
467                     struct qed_ptt *p_ptt,
468                     enum qed_led_mode mode);
469
470 /**
471  * @brief Read from nvm
472  *
473  *  @param cdev
474  *  @param addr - nvm offset
475  *  @param p_buf - nvm read buffer
476  *  @param len - buffer len
477  *
478  * @return int - 0 - operation was successful.
479  */
480 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
481
482 /**
483  * @brief Write to nvm
484  *
485  *  @param cdev
486  *  @param addr - nvm offset
487  *  @param cmd - nvm command
488  *  @param p_buf - nvm write buffer
489  *  @param len - buffer len
490  *
491  * @return int - 0 - operation was successful.
492  */
493 int qed_mcp_nvm_write(struct qed_dev *cdev,
494                       u32 cmd, u32 addr, u8 *p_buf, u32 len);
495
496 /**
497  * @brief Put file begin
498  *
499  *  @param cdev
500  *  @param addr - nvm offset
501  *
502  * @return int - 0 - operation was successful.
503  */
504 int qed_mcp_nvm_put_file_begin(struct qed_dev *cdev, u32 addr);
505
506 /**
507  * @brief Check latest response
508  *
509  *  @param cdev
510  *  @param p_buf - nvm write buffer
511  *
512  * @return int - 0 - operation was successful.
513  */
514 int qed_mcp_nvm_resp(struct qed_dev *cdev, u8 *p_buf);
515
516 struct qed_nvm_image_att {
517         u32 start_addr;
518         u32 length;
519 };
520
521 /**
522  * @brief Allows reading a whole nvram image
523  *
524  * @param p_hwfn
525  * @param image_id - image to get attributes for
526  * @param p_image_att - image attributes structure into which to fill data
527  *
528  * @return int - 0 - operation was successful.
529  */
530 int
531 qed_mcp_get_nvm_image_att(struct qed_hwfn *p_hwfn,
532                           enum qed_nvm_images image_id,
533                           struct qed_nvm_image_att *p_image_att);
534
535 /**
536  * @brief Allows reading a whole nvram image
537  *
538  * @param p_hwfn
539  * @param image_id - image requested for reading
540  * @param p_buffer - allocated buffer into which to fill data
541  * @param buffer_len - length of the allocated buffer.
542  *
543  * @return 0 iff p_buffer now contains the nvram image.
544  */
545 int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn,
546                           enum qed_nvm_images image_id,
547                           u8 *p_buffer, u32 buffer_len);
548
549 /**
550  * @brief Bist register test
551  *
552  *  @param p_hwfn    - hw function
553  *  @param p_ptt     - PTT required for register access
554  *
555  * @return int - 0 - operation was successful.
556  */
557 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
558                                struct qed_ptt *p_ptt);
559
560 /**
561  * @brief Bist clock test
562  *
563  *  @param p_hwfn    - hw function
564  *  @param p_ptt     - PTT required for register access
565  *
566  * @return int - 0 - operation was successful.
567  */
568 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
569                             struct qed_ptt *p_ptt);
570
571 /**
572  * @brief Bist nvm test - get number of images
573  *
574  *  @param p_hwfn       - hw function
575  *  @param p_ptt        - PTT required for register access
576  *  @param num_images   - number of images if operation was
577  *                        successful. 0 if not.
578  *
579  * @return int - 0 - operation was successful.
580  */
581 int qed_mcp_bist_nvm_get_num_images(struct qed_hwfn *p_hwfn,
582                                     struct qed_ptt *p_ptt,
583                                     u32 *num_images);
584
585 /**
586  * @brief Bist nvm test - get image attributes by index
587  *
588  *  @param p_hwfn      - hw function
589  *  @param p_ptt       - PTT required for register access
590  *  @param p_image_att - Attributes of image
591  *  @param image_index - Index of image to get information for
592  *
593  * @return int - 0 - operation was successful.
594  */
595 int qed_mcp_bist_nvm_get_image_att(struct qed_hwfn *p_hwfn,
596                                    struct qed_ptt *p_ptt,
597                                    struct bist_nvm_image_att *p_image_att,
598                                    u32 image_index);
599
600 /**
601  * @brief - Processes the TLV request from MFW i.e., get the required TLV info
602  *          from the qed client and send it to the MFW.
603  *
604  * @param p_hwfn
605  * @param p_ptt
606  *
607  * @param return 0 upon success.
608  */
609 int qed_mfw_process_tlv_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
610
611 /* Using hwfn number (and not pf_num) is required since in CMT mode,
612  * same pf_num may be used by two different hwfn
613  * TODO - this shouldn't really be in .h file, but until all fields
614  * required during hw-init will be placed in their correct place in shmem
615  * we need it in qed_dev.c [for readin the nvram reflection in shmem].
616  */
617 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ?        \
618                                             ((rel_pfid) |                      \
619                                              ((p_hwfn)->abs_pf_id & 1) << 3) : \
620                                             rel_pfid)
621 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
622
623 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id %                   \
624                                  ((_p_hwfn)->cdev->num_ports_in_engine * \
625                                   qed_device_num_engines((_p_hwfn)->cdev)))
626
627 struct qed_mcp_info {
628         /* List for mailbox commands which were sent and wait for a response */
629         struct list_head                        cmd_list;
630
631         /* Spinlock used for protecting the access to the mailbox commands list
632          * and the sending of the commands.
633          */
634         spinlock_t                              cmd_lock;
635
636         /* Spinlock used for syncing SW link-changes and link-changes
637          * originating from attention context.
638          */
639         spinlock_t                              link_lock;
640         bool                                    block_mb_sending;
641         u32                                     public_base;
642         u32                                     drv_mb_addr;
643         u32                                     mfw_mb_addr;
644         u32                                     port_addr;
645         u16                                     drv_mb_seq;
646         u16                                     drv_pulse_seq;
647         struct qed_mcp_link_params              link_input;
648         struct qed_mcp_link_state               link_output;
649         struct qed_mcp_link_capabilities        link_capabilities;
650         struct qed_mcp_function_info            func_info;
651         u8                                      *mfw_mb_cur;
652         u8                                      *mfw_mb_shadow;
653         u16                                     mfw_mb_length;
654         u32                                     mcp_hist;
655
656         /* Capabilties negotiated with the MFW */
657         u32                                     capabilities;
658 };
659
660 struct qed_mcp_mb_params {
661         u32                     cmd;
662         u32                     param;
663         void                    *p_data_src;
664         u8                      data_src_size;
665         void                    *p_data_dst;
666         u8                      data_dst_size;
667         u32                     mcp_resp;
668         u32                     mcp_param;
669 };
670
671 struct qed_drv_tlv_hdr {
672         u8 tlv_type;
673         u8 tlv_length;  /* In dwords - not including this header */
674         u8 tlv_reserved;
675 #define QED_DRV_TLV_FLAGS_CHANGED 0x01
676         u8 tlv_flags;
677 };
678
679 /**
680  * @brief Initialize the interface with the MCP
681  *
682  * @param p_hwfn - HW func
683  * @param p_ptt - PTT required for register access
684  *
685  * @return int
686  */
687 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
688                      struct qed_ptt *p_ptt);
689
690 /**
691  * @brief Initialize the port interface with the MCP
692  *
693  * @param p_hwfn
694  * @param p_ptt
695  * Can only be called after `num_ports_in_engines' is set
696  */
697 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
698                            struct qed_ptt *p_ptt);
699 /**
700  * @brief Releases resources allocated during the init process.
701  *
702  * @param p_hwfn - HW func
703  * @param p_ptt - PTT required for register access
704  *
705  * @return int
706  */
707
708 int qed_mcp_free(struct qed_hwfn *p_hwfn);
709
710 /**
711  * @brief This function is called from the DPC context. After
712  * pointing PTT to the mfw mb, check for events sent by the MCP
713  * to the driver and ack them. In case a critical event
714  * detected, it will be handled here, otherwise the work will be
715  * queued to a sleepable work-queue.
716  *
717  * @param p_hwfn - HW function
718  * @param p_ptt - PTT required for register access
719  * @return int - 0 - operation
720  * was successul.
721  */
722 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
723                           struct qed_ptt *p_ptt);
724
725 enum qed_drv_role {
726         QED_DRV_ROLE_OS,
727         QED_DRV_ROLE_KDUMP,
728 };
729
730 struct qed_load_req_params {
731         /* Input params */
732         enum qed_drv_role drv_role;
733         u8 timeout_val;
734         bool avoid_eng_reset;
735         enum qed_override_force_load override_force_load;
736
737         /* Output params */
738         u32 load_code;
739 };
740
741 /**
742  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
743  *        returns whether this PF is the first on the engine/port or function.
744  *
745  * @param p_hwfn
746  * @param p_ptt
747  * @param p_params
748  *
749  * @return int - 0 - Operation was successful.
750  */
751 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
752                      struct qed_ptt *p_ptt,
753                      struct qed_load_req_params *p_params);
754
755 /**
756  * @brief Sends a UNLOAD_REQ message to the MFW
757  *
758  * @param p_hwfn
759  * @param p_ptt
760  *
761  * @return int - 0 - Operation was successful.
762  */
763 int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
764
765 /**
766  * @brief Sends a UNLOAD_DONE message to the MFW
767  *
768  * @param p_hwfn
769  * @param p_ptt
770  *
771  * @return int - 0 - Operation was successful.
772  */
773 int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
774
775 /**
776  * @brief Read the MFW mailbox into Current buffer.
777  *
778  * @param p_hwfn
779  * @param p_ptt
780  */
781 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
782                      struct qed_ptt *p_ptt);
783
784 /**
785  * @brief Ack to mfw that driver finished FLR process for VFs
786  *
787  * @param p_hwfn
788  * @param p_ptt
789  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
790  *
791  * @param return int - 0 upon success.
792  */
793 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
794                        struct qed_ptt *p_ptt, u32 *vfs_to_ack);
795
796 /**
797  * @brief - calls during init to read shmem of all function-related info.
798  *
799  * @param p_hwfn
800  *
801  * @param return 0 upon success.
802  */
803 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
804                                  struct qed_ptt *p_ptt);
805
806 /**
807  * @brief - Reset the MCP using mailbox command.
808  *
809  * @param p_hwfn
810  * @param p_ptt
811  *
812  * @param return 0 upon success.
813  */
814 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
815                   struct qed_ptt *p_ptt);
816
817 /**
818  * @brief - Sends an NVM read command request to the MFW to get
819  *        a buffer.
820  *
821  * @param p_hwfn
822  * @param p_ptt
823  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
824  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
825  * @param param - [0:23] - Offset [24:31] - Size
826  * @param o_mcp_resp - MCP response
827  * @param o_mcp_param - MCP response param
828  * @param o_txn_size -  Buffer size output
829  * @param o_buf - Pointer to the buffer returned by the MFW.
830  *
831  * @param return 0 upon success.
832  */
833 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
834                        struct qed_ptt *p_ptt,
835                        u32 cmd,
836                        u32 param,
837                        u32 *o_mcp_resp,
838                        u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
839
840 /**
841  * @brief indicates whether the MFW objects [under mcp_info] are accessible
842  *
843  * @param p_hwfn
844  *
845  * @return true iff MFW is running and mcp_info is initialized
846  */
847 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
848
849 /**
850  * @brief request MFW to configure MSI-X for a VF
851  *
852  * @param p_hwfn
853  * @param p_ptt
854  * @param vf_id - absolute inside engine
855  * @param num_sbs - number of entries to request
856  *
857  * @return int
858  */
859 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
860                            struct qed_ptt *p_ptt, u8 vf_id, u8 num);
861
862 /**
863  * @brief - Halt the MCP.
864  *
865  * @param p_hwfn
866  * @param p_ptt
867  *
868  * @param return 0 upon success.
869  */
870 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
871
872 /**
873  * @brief - Wake up the MCP.
874  *
875  * @param p_hwfn
876  * @param p_ptt
877  *
878  * @param return 0 upon success.
879  */
880 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
881
882 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
883 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
884 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
885                                      struct qed_ptt *p_ptt,
886                                      struct qed_mcp_link_state *p_link,
887                                      u8 max_bw);
888 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
889                                      struct qed_ptt *p_ptt,
890                                      struct qed_mcp_link_state *p_link,
891                                      u8 min_bw);
892
893 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
894                           struct qed_ptt *p_ptt, u32 mask_parities);
895
896 /**
897  * @brief - Sets the MFW's max value for the given resource
898  *
899  *  @param p_hwfn
900  *  @param p_ptt
901  *  @param res_id
902  *  @param resc_max_val
903  *  @param p_mcp_resp
904  *
905  * @return int - 0 - operation was successful.
906  */
907 int
908 qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn,
909                          struct qed_ptt *p_ptt,
910                          enum qed_resources res_id,
911                          u32 resc_max_val, u32 *p_mcp_resp);
912
913 /**
914  * @brief - Gets the MFW allocation info for the given resource
915  *
916  *  @param p_hwfn
917  *  @param p_ptt
918  *  @param res_id
919  *  @param p_mcp_resp
920  *  @param p_resc_num
921  *  @param p_resc_start
922  *
923  * @return int - 0 - operation was successful.
924  */
925 int
926 qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
927                       struct qed_ptt *p_ptt,
928                       enum qed_resources res_id,
929                       u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start);
930
931 /**
932  * @brief Send eswitch mode to MFW
933  *
934  *  @param p_hwfn
935  *  @param p_ptt
936  *  @param eswitch - eswitch mode
937  *
938  * @return int - 0 - operation was successful.
939  */
940 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
941                               struct qed_ptt *p_ptt,
942                               enum qed_ov_eswitch eswitch);
943
944 #define QED_MCP_RESC_LOCK_MIN_VAL       RESOURCE_DUMP
945 #define QED_MCP_RESC_LOCK_MAX_VAL       31
946
947 enum qed_resc_lock {
948         QED_RESC_LOCK_DBG_DUMP = QED_MCP_RESC_LOCK_MIN_VAL,
949         QED_RESC_LOCK_PTP_PORT0,
950         QED_RESC_LOCK_PTP_PORT1,
951         QED_RESC_LOCK_PTP_PORT2,
952         QED_RESC_LOCK_PTP_PORT3,
953         QED_RESC_LOCK_RESC_ALLOC = QED_MCP_RESC_LOCK_MAX_VAL,
954         QED_RESC_LOCK_RESC_INVALID
955 };
956
957 /**
958  * @brief - Initiates PF FLR
959  *
960  *  @param p_hwfn
961  *  @param p_ptt
962  *
963  * @return int - 0 - operation was successful.
964  */
965 int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
966 struct qed_resc_lock_params {
967         /* Resource number [valid values are 0..31] */
968         u8 resource;
969
970         /* Lock timeout value in seconds [default, none or 1..254] */
971         u8 timeout;
972 #define QED_MCP_RESC_LOCK_TO_DEFAULT    0
973 #define QED_MCP_RESC_LOCK_TO_NONE       255
974
975         /* Number of times to retry locking */
976         u8 retry_num;
977 #define QED_MCP_RESC_LOCK_RETRY_CNT_DFLT        10
978
979         /* The interval in usec between retries */
980         u16 retry_interval;
981 #define QED_MCP_RESC_LOCK_RETRY_VAL_DFLT        10000
982
983         /* Use sleep or delay between retries */
984         bool sleep_b4_retry;
985
986         /* Will be set as true if the resource is free and granted */
987         bool b_granted;
988
989         /* Will be filled with the resource owner.
990          * [0..15 = PF0-15, 16 = MFW]
991          */
992         u8 owner;
993 };
994
995 /**
996  * @brief Acquires MFW generic resource lock
997  *
998  *  @param p_hwfn
999  *  @param p_ptt
1000  *  @param p_params
1001  *
1002  * @return int - 0 - operation was successful.
1003  */
1004 int
1005 qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
1006                   struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params);
1007
1008 struct qed_resc_unlock_params {
1009         /* Resource number [valid values are 0..31] */
1010         u8 resource;
1011
1012         /* Allow to release a resource even if belongs to another PF */
1013         bool b_force;
1014
1015         /* Will be set as true if the resource is released */
1016         bool b_released;
1017 };
1018
1019 /**
1020  * @brief Releases MFW generic resource lock
1021  *
1022  *  @param p_hwfn
1023  *  @param p_ptt
1024  *  @param p_params
1025  *
1026  * @return int - 0 - operation was successful.
1027  */
1028 int
1029 qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn,
1030                     struct qed_ptt *p_ptt,
1031                     struct qed_resc_unlock_params *p_params);
1032
1033 /**
1034  * @brief - default initialization for lock/unlock resource structs
1035  *
1036  * @param p_lock - lock params struct to be initialized; Can be NULL
1037  * @param p_unlock - unlock params struct to be initialized; Can be NULL
1038  * @param resource - the requested resource
1039  * @paral b_is_permanent - disable retries & aging when set
1040  */
1041 void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock,
1042                                     struct qed_resc_unlock_params *p_unlock,
1043                                     enum qed_resc_lock
1044                                     resource, bool b_is_permanent);
1045 /**
1046  * @brief Learn of supported MFW features; To be done during early init
1047  *
1048  * @param p_hwfn
1049  * @param p_ptt
1050  */
1051 int qed_mcp_get_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1052
1053 /**
1054  * @brief Inform MFW of set of features supported by driver. Should be done
1055  * inside the content of the LOAD_REQ.
1056  *
1057  * @param p_hwfn
1058  * @param p_ptt
1059  */
1060 int qed_mcp_set_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1061
1062 /**
1063  * @brief Read ufp config from the shared memory.
1064  *
1065  * @param p_hwfn
1066  * @param p_ptt
1067  */
1068 void qed_mcp_read_ufp_config(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1069
1070 /**
1071  * @brief Populate the nvm info shadow in the given hardware function
1072  *
1073  * @param p_hwfn
1074  */
1075 int qed_mcp_nvm_info_populate(struct qed_hwfn *p_hwfn);
1076
1077 #endif