cf678b6966f864b73bb5e29785cb8a26c03a2c49
[linux-2.6-microblaze.git] / drivers / net / ethernet / qlogic / qed / qed_mcp.h
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /* QLogic qed NIC Driver
3  * Copyright (c) 2015-2017  QLogic Corporation
4  * Copyright (c) 2019-2020 Marvell International Ltd.
5  */
6
7 #ifndef _QED_MCP_H
8 #define _QED_MCP_H
9
10 #include <linux/types.h>
11 #include <linux/delay.h>
12 #include <linux/slab.h>
13 #include <linux/spinlock.h>
14 #include <linux/qed/qed_fcoe_if.h>
15 #include "qed_hsi.h"
16 #include "qed_dev_api.h"
17
18 struct qed_mcp_link_speed_params {
19         bool    autoneg;
20         u32     advertised_speeds;      /* bitmask of DRV_SPEED_CAPABILITY */
21         u32     forced_speed;      /* In Mb/s */
22 };
23
24 struct qed_mcp_link_pause_params {
25         bool    autoneg;
26         bool    forced_rx;
27         bool    forced_tx;
28 };
29
30 enum qed_mcp_eee_mode {
31         QED_MCP_EEE_DISABLED,
32         QED_MCP_EEE_ENABLED,
33         QED_MCP_EEE_UNSUPPORTED
34 };
35
36 struct qed_mcp_link_params {
37         struct qed_mcp_link_speed_params        speed;
38         struct qed_mcp_link_pause_params        pause;
39         u32                                     loopback_mode;
40         struct qed_link_eee_params              eee;
41 };
42
43 struct qed_mcp_link_capabilities {
44         u32                                     speed_capabilities;
45         bool                                    default_speed_autoneg;
46         enum qed_mcp_eee_mode                   default_eee;
47         u32                                     eee_lpi_timer;
48         u8                                      eee_speed_caps;
49 };
50
51 struct qed_mcp_link_state {
52         bool                                    link_up;
53         u32                                     min_pf_rate;
54
55         /* Actual link speed in Mb/s */
56         u32                                     line_speed;
57
58         /* PF max speed in Mb/s, deduced from line_speed
59          * according to PF max bandwidth configuration.
60          */
61         u32                                     speed;
62
63         bool                                    full_duplex;
64         bool                                    an;
65         bool                                    an_complete;
66         bool                                    parallel_detection;
67         bool                                    pfc_enabled;
68
69         u32                                     partner_adv_speed;
70 #define QED_LINK_PARTNER_SPEED_1G_HD            BIT(0)
71 #define QED_LINK_PARTNER_SPEED_1G_FD            BIT(1)
72 #define QED_LINK_PARTNER_SPEED_10G              BIT(2)
73 #define QED_LINK_PARTNER_SPEED_20G              BIT(3)
74 #define QED_LINK_PARTNER_SPEED_25G              BIT(4)
75 #define QED_LINK_PARTNER_SPEED_40G              BIT(5)
76 #define QED_LINK_PARTNER_SPEED_50G              BIT(6)
77 #define QED_LINK_PARTNER_SPEED_100G             BIT(7)
78
79         bool                                    partner_tx_flow_ctrl_en;
80         bool                                    partner_rx_flow_ctrl_en;
81
82         u8                                      partner_adv_pause;
83 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE        0x1
84 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE       0x2
85 #define QED_LINK_PARTNER_BOTH_PAUSE             0x3
86
87         bool                                    sfp_tx_fault;
88         bool                                    eee_active;
89         u8                                      eee_adv_caps;
90         u8                                      eee_lp_adv_caps;
91 };
92
93 struct qed_mcp_function_info {
94         u8                              pause_on_host;
95
96         enum qed_pci_personality        protocol;
97
98         u8                              bandwidth_min;
99         u8                              bandwidth_max;
100
101         u8                              mac[ETH_ALEN];
102
103         u64                             wwn_port;
104         u64                             wwn_node;
105
106 #define QED_MCP_VLAN_UNSET              (0xffff)
107         u16                             ovlan;
108
109         u16                             mtu;
110 };
111
112 struct qed_mcp_nvm_common {
113         u32     offset;
114         u32     param;
115         u32     resp;
116         u32     cmd;
117 };
118
119 struct qed_mcp_drv_version {
120         u32     version;
121         u8      name[MCP_DRV_VER_STR_SIZE - 4];
122 };
123
124 struct qed_mcp_lan_stats {
125         u64 ucast_rx_pkts;
126         u64 ucast_tx_pkts;
127         u32 fcs_err;
128 };
129
130 struct qed_mcp_fcoe_stats {
131         u64 rx_pkts;
132         u64 tx_pkts;
133         u32 fcs_err;
134         u32 login_failure;
135 };
136
137 struct qed_mcp_iscsi_stats {
138         u64 rx_pdus;
139         u64 tx_pdus;
140         u64 rx_bytes;
141         u64 tx_bytes;
142 };
143
144 struct qed_mcp_rdma_stats {
145         u64 rx_pkts;
146         u64 tx_pkts;
147         u64 rx_bytes;
148         u64 tx_byts;
149 };
150
151 enum qed_mcp_protocol_type {
152         QED_MCP_LAN_STATS,
153         QED_MCP_FCOE_STATS,
154         QED_MCP_ISCSI_STATS,
155         QED_MCP_RDMA_STATS
156 };
157
158 union qed_mcp_protocol_stats {
159         struct qed_mcp_lan_stats lan_stats;
160         struct qed_mcp_fcoe_stats fcoe_stats;
161         struct qed_mcp_iscsi_stats iscsi_stats;
162         struct qed_mcp_rdma_stats rdma_stats;
163 };
164
165 enum qed_ov_eswitch {
166         QED_OV_ESWITCH_NONE,
167         QED_OV_ESWITCH_VEB,
168         QED_OV_ESWITCH_VEPA
169 };
170
171 enum qed_ov_client {
172         QED_OV_CLIENT_DRV,
173         QED_OV_CLIENT_USER,
174         QED_OV_CLIENT_VENDOR_SPEC
175 };
176
177 enum qed_ov_driver_state {
178         QED_OV_DRIVER_STATE_NOT_LOADED,
179         QED_OV_DRIVER_STATE_DISABLED,
180         QED_OV_DRIVER_STATE_ACTIVE
181 };
182
183 enum qed_ov_wol {
184         QED_OV_WOL_DEFAULT,
185         QED_OV_WOL_DISABLED,
186         QED_OV_WOL_ENABLED
187 };
188
189 enum qed_mfw_tlv_type {
190         QED_MFW_TLV_GENERIC = 0x1,      /* Core driver TLVs */
191         QED_MFW_TLV_ETH = 0x2,          /* L2 driver TLVs */
192         QED_MFW_TLV_FCOE = 0x4,         /* FCoE protocol TLVs */
193         QED_MFW_TLV_ISCSI = 0x8,        /* SCSI protocol TLVs */
194         QED_MFW_TLV_MAX = 0x16,
195 };
196
197 struct qed_mfw_tlv_generic {
198 #define QED_MFW_TLV_FLAGS_SIZE  2
199         struct {
200                 u8 ipv4_csum_offload;
201                 u8 lso_supported;
202                 bool b_set;
203         } flags;
204
205 #define QED_MFW_TLV_MAC_COUNT 3
206         /* First entry for primary MAC, 2 secondary MACs possible */
207         u8 mac[QED_MFW_TLV_MAC_COUNT][6];
208         bool mac_set[QED_MFW_TLV_MAC_COUNT];
209
210         u64 rx_frames;
211         bool rx_frames_set;
212         u64 rx_bytes;
213         bool rx_bytes_set;
214         u64 tx_frames;
215         bool tx_frames_set;
216         u64 tx_bytes;
217         bool tx_bytes_set;
218 };
219
220 union qed_mfw_tlv_data {
221         struct qed_mfw_tlv_generic generic;
222         struct qed_mfw_tlv_eth eth;
223         struct qed_mfw_tlv_fcoe fcoe;
224         struct qed_mfw_tlv_iscsi iscsi;
225 };
226
227 #define QED_NVM_CFG_OPTION_ALL          BIT(0)
228 #define QED_NVM_CFG_OPTION_INIT         BIT(1)
229 #define QED_NVM_CFG_OPTION_COMMIT       BIT(2)
230 #define QED_NVM_CFG_OPTION_FREE         BIT(3)
231 #define QED_NVM_CFG_OPTION_ENTITY_SEL   BIT(4)
232
233 /**
234  * @brief - returns the link params of the hw function
235  *
236  * @param p_hwfn
237  *
238  * @returns pointer to link params
239  */
240 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
241
242 /**
243  * @brief - return the link state of the hw function
244  *
245  * @param p_hwfn
246  *
247  * @returns pointer to link state
248  */
249 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
250
251 /**
252  * @brief - return the link capabilities of the hw function
253  *
254  * @param p_hwfn
255  *
256  * @returns pointer to link capabilities
257  */
258 struct qed_mcp_link_capabilities
259         *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
260
261 /**
262  * @brief Request the MFW to set the the link according to 'link_input'.
263  *
264  * @param p_hwfn
265  * @param p_ptt
266  * @param b_up - raise link if `true'. Reset link if `false'.
267  *
268  * @return int
269  */
270 int qed_mcp_set_link(struct qed_hwfn   *p_hwfn,
271                      struct qed_ptt     *p_ptt,
272                      bool               b_up);
273
274 /**
275  * @brief Get the management firmware version value
276  *
277  * @param p_hwfn
278  * @param p_ptt
279  * @param p_mfw_ver    - mfw version value
280  * @param p_running_bundle_id   - image id in nvram; Optional.
281  *
282  * @return int - 0 - operation was successful.
283  */
284 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
285                         struct qed_ptt *p_ptt,
286                         u32 *p_mfw_ver, u32 *p_running_bundle_id);
287
288 /**
289  * @brief Get the MBI version value
290  *
291  * @param p_hwfn
292  * @param p_ptt
293  * @param p_mbi_ver - A pointer to a variable to be filled with the MBI version.
294  *
295  * @return int - 0 - operation was successful.
296  */
297 int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
298                         struct qed_ptt *p_ptt, u32 *p_mbi_ver);
299
300 /**
301  * @brief Get media type value of the port.
302  *
303  * @param cdev      - qed dev pointer
304  * @param p_ptt
305  * @param mfw_ver    - media type value
306  *
307  * @return int -
308  *      0 - Operation was successul.
309  *      -EBUSY - Operation failed
310  */
311 int qed_mcp_get_media_type(struct qed_hwfn *p_hwfn,
312                            struct qed_ptt *p_ptt, u32 *media_type);
313
314 /**
315  * @brief Get transceiver data of the port.
316  *
317  * @param cdev      - qed dev pointer
318  * @param p_ptt
319  * @param p_transceiver_state - transceiver state.
320  * @param p_transceiver_type - media type value
321  *
322  * @return int -
323  *      0 - Operation was successful.
324  *      -EBUSY - Operation failed
325  */
326 int qed_mcp_get_transceiver_data(struct qed_hwfn *p_hwfn,
327                                  struct qed_ptt *p_ptt,
328                                  u32 *p_transceiver_state,
329                                  u32 *p_tranceiver_type);
330
331 /**
332  * @brief Get transceiver supported speed mask.
333  *
334  * @param cdev      - qed dev pointer
335  * @param p_ptt
336  * @param p_speed_mask - Bit mask of all supported speeds.
337  *
338  * @return int -
339  *      0 - Operation was successful.
340  *      -EBUSY - Operation failed
341  */
342
343 int qed_mcp_trans_speed_mask(struct qed_hwfn *p_hwfn,
344                              struct qed_ptt *p_ptt, u32 *p_speed_mask);
345
346 /**
347  * @brief Get board configuration.
348  *
349  * @param cdev      - qed dev pointer
350  * @param p_ptt
351  * @param p_board_config - Board config.
352  *
353  * @return int -
354  *      0 - Operation was successful.
355  *      -EBUSY - Operation failed
356  */
357 int qed_mcp_get_board_config(struct qed_hwfn *p_hwfn,
358                              struct qed_ptt *p_ptt, u32 *p_board_config);
359
360 /**
361  * @brief General function for sending commands to the MCP
362  *        mailbox. It acquire mutex lock for the entire
363  *        operation, from sending the request until the MCP
364  *        response. Waiting for MCP response will be checked up
365  *        to 5 seconds every 5ms.
366  *
367  * @param p_hwfn     - hw function
368  * @param p_ptt      - PTT required for register access
369  * @param cmd        - command to be sent to the MCP.
370  * @param param      - Optional param
371  * @param o_mcp_resp - The MCP response code (exclude sequence).
372  * @param o_mcp_param- Optional parameter provided by the MCP
373  *                     response
374  * @return int - 0 - operation
375  * was successul.
376  */
377 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
378                 struct qed_ptt *p_ptt,
379                 u32 cmd,
380                 u32 param,
381                 u32 *o_mcp_resp,
382                 u32 *o_mcp_param);
383
384 /**
385  * @brief - drains the nig, allowing completion to pass in case of pauses.
386  *          (Should be called only from sleepable context)
387  *
388  * @param p_hwfn
389  * @param p_ptt
390  */
391 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
392                   struct qed_ptt *p_ptt);
393
394 /**
395  * @brief Get the flash size value
396  *
397  * @param p_hwfn
398  * @param p_ptt
399  * @param p_flash_size  - flash size in bytes to be filled.
400  *
401  * @return int - 0 - operation was successul.
402  */
403 int qed_mcp_get_flash_size(struct qed_hwfn     *p_hwfn,
404                            struct qed_ptt       *p_ptt,
405                            u32 *p_flash_size);
406
407 /**
408  * @brief Send driver version to MFW
409  *
410  * @param p_hwfn
411  * @param p_ptt
412  * @param version - Version value
413  * @param name - Protocol driver name
414  *
415  * @return int - 0 - operation was successul.
416  */
417 int
418 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
419                          struct qed_ptt *p_ptt,
420                          struct qed_mcp_drv_version *p_ver);
421
422 /**
423  * @brief Read the MFW process kill counter
424  *
425  * @param p_hwfn
426  * @param p_ptt
427  *
428  * @return u32
429  */
430 u32 qed_get_process_kill_counter(struct qed_hwfn *p_hwfn,
431                                  struct qed_ptt *p_ptt);
432
433 /**
434  * @brief Trigger a recovery process
435  *
436  *  @param p_hwfn
437  *  @param p_ptt
438  *
439  * @return int
440  */
441 int qed_start_recovery_process(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
442
443 /**
444  * @brief A recovery handler must call this function as its first step.
445  *        It is assumed that the handler is not run from an interrupt context.
446  *
447  *  @param cdev
448  *  @param p_ptt
449  *
450  * @return int
451  */
452 int qed_recovery_prolog(struct qed_dev *cdev);
453
454 /**
455  * @brief Notify MFW about the change in base device properties
456  *
457  *  @param p_hwfn
458  *  @param p_ptt
459  *  @param client - qed client type
460  *
461  * @return int - 0 - operation was successful.
462  */
463 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
464                                      struct qed_ptt *p_ptt,
465                                      enum qed_ov_client client);
466
467 /**
468  * @brief Notify MFW about the driver state
469  *
470  *  @param p_hwfn
471  *  @param p_ptt
472  *  @param drv_state - Driver state
473  *
474  * @return int - 0 - operation was successful.
475  */
476 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
477                                    struct qed_ptt *p_ptt,
478                                    enum qed_ov_driver_state drv_state);
479
480 /**
481  * @brief Send MTU size to MFW
482  *
483  *  @param p_hwfn
484  *  @param p_ptt
485  *  @param mtu - MTU size
486  *
487  * @return int - 0 - operation was successful.
488  */
489 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
490                           struct qed_ptt *p_ptt, u16 mtu);
491
492 /**
493  * @brief Send MAC address to MFW
494  *
495  *  @param p_hwfn
496  *  @param p_ptt
497  *  @param mac - MAC address
498  *
499  * @return int - 0 - operation was successful.
500  */
501 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
502                           struct qed_ptt *p_ptt, u8 *mac);
503
504 /**
505  * @brief Send WOL mode to MFW
506  *
507  *  @param p_hwfn
508  *  @param p_ptt
509  *  @param wol - WOL mode
510  *
511  * @return int - 0 - operation was successful.
512  */
513 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
514                           struct qed_ptt *p_ptt,
515                           enum qed_ov_wol wol);
516
517 /**
518  * @brief Set LED status
519  *
520  *  @param p_hwfn
521  *  @param p_ptt
522  *  @param mode - LED mode
523  *
524  * @return int - 0 - operation was successful.
525  */
526 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
527                     struct qed_ptt *p_ptt,
528                     enum qed_led_mode mode);
529
530 /**
531  * @brief Read from nvm
532  *
533  *  @param cdev
534  *  @param addr - nvm offset
535  *  @param p_buf - nvm read buffer
536  *  @param len - buffer len
537  *
538  * @return int - 0 - operation was successful.
539  */
540 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
541
542 /**
543  * @brief Write to nvm
544  *
545  *  @param cdev
546  *  @param addr - nvm offset
547  *  @param cmd - nvm command
548  *  @param p_buf - nvm write buffer
549  *  @param len - buffer len
550  *
551  * @return int - 0 - operation was successful.
552  */
553 int qed_mcp_nvm_write(struct qed_dev *cdev,
554                       u32 cmd, u32 addr, u8 *p_buf, u32 len);
555
556 /**
557  * @brief Check latest response
558  *
559  *  @param cdev
560  *  @param p_buf - nvm write buffer
561  *
562  * @return int - 0 - operation was successful.
563  */
564 int qed_mcp_nvm_resp(struct qed_dev *cdev, u8 *p_buf);
565
566 struct qed_nvm_image_att {
567         u32 start_addr;
568         u32 length;
569 };
570
571 /**
572  * @brief Allows reading a whole nvram image
573  *
574  * @param p_hwfn
575  * @param image_id - image to get attributes for
576  * @param p_image_att - image attributes structure into which to fill data
577  *
578  * @return int - 0 - operation was successful.
579  */
580 int
581 qed_mcp_get_nvm_image_att(struct qed_hwfn *p_hwfn,
582                           enum qed_nvm_images image_id,
583                           struct qed_nvm_image_att *p_image_att);
584
585 /**
586  * @brief Allows reading a whole nvram image
587  *
588  * @param p_hwfn
589  * @param image_id - image requested for reading
590  * @param p_buffer - allocated buffer into which to fill data
591  * @param buffer_len - length of the allocated buffer.
592  *
593  * @return 0 iff p_buffer now contains the nvram image.
594  */
595 int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn,
596                           enum qed_nvm_images image_id,
597                           u8 *p_buffer, u32 buffer_len);
598
599 /**
600  * @brief Bist register test
601  *
602  *  @param p_hwfn    - hw function
603  *  @param p_ptt     - PTT required for register access
604  *
605  * @return int - 0 - operation was successful.
606  */
607 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
608                                struct qed_ptt *p_ptt);
609
610 /**
611  * @brief Bist clock test
612  *
613  *  @param p_hwfn    - hw function
614  *  @param p_ptt     - PTT required for register access
615  *
616  * @return int - 0 - operation was successful.
617  */
618 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
619                             struct qed_ptt *p_ptt);
620
621 /**
622  * @brief Bist nvm test - get number of images
623  *
624  *  @param p_hwfn       - hw function
625  *  @param p_ptt        - PTT required for register access
626  *  @param num_images   - number of images if operation was
627  *                        successful. 0 if not.
628  *
629  * @return int - 0 - operation was successful.
630  */
631 int qed_mcp_bist_nvm_get_num_images(struct qed_hwfn *p_hwfn,
632                                     struct qed_ptt *p_ptt,
633                                     u32 *num_images);
634
635 /**
636  * @brief Bist nvm test - get image attributes by index
637  *
638  *  @param p_hwfn      - hw function
639  *  @param p_ptt       - PTT required for register access
640  *  @param p_image_att - Attributes of image
641  *  @param image_index - Index of image to get information for
642  *
643  * @return int - 0 - operation was successful.
644  */
645 int qed_mcp_bist_nvm_get_image_att(struct qed_hwfn *p_hwfn,
646                                    struct qed_ptt *p_ptt,
647                                    struct bist_nvm_image_att *p_image_att,
648                                    u32 image_index);
649
650 /**
651  * @brief - Processes the TLV request from MFW i.e., get the required TLV info
652  *          from the qed client and send it to the MFW.
653  *
654  * @param p_hwfn
655  * @param p_ptt
656  *
657  * @param return 0 upon success.
658  */
659 int qed_mfw_process_tlv_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
660
661 /**
662  * @brief Send raw debug data to the MFW
663  *
664  * @param p_hwfn
665  * @param p_ptt
666  * @param p_buf - raw debug data buffer
667  * @param size - buffer size
668  */
669 int
670 qed_mcp_send_raw_debug_data(struct qed_hwfn *p_hwfn,
671                             struct qed_ptt *p_ptt, u8 *p_buf, u32 size);
672
673 /* Using hwfn number (and not pf_num) is required since in CMT mode,
674  * same pf_num may be used by two different hwfn
675  * TODO - this shouldn't really be in .h file, but until all fields
676  * required during hw-init will be placed in their correct place in shmem
677  * we need it in qed_dev.c [for readin the nvram reflection in shmem].
678  */
679 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ?        \
680                                             ((rel_pfid) |                      \
681                                              ((p_hwfn)->abs_pf_id & 1) << 3) : \
682                                             rel_pfid)
683 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
684
685 struct qed_mcp_info {
686         /* List for mailbox commands which were sent and wait for a response */
687         struct list_head                        cmd_list;
688
689         /* Spinlock used for protecting the access to the mailbox commands list
690          * and the sending of the commands.
691          */
692         spinlock_t                              cmd_lock;
693
694         /* Flag to indicate whether sending a MFW mailbox command is blocked */
695         bool                                    b_block_cmd;
696
697         /* Spinlock used for syncing SW link-changes and link-changes
698          * originating from attention context.
699          */
700         spinlock_t                              link_lock;
701
702         u32                                     public_base;
703         u32                                     drv_mb_addr;
704         u32                                     mfw_mb_addr;
705         u32                                     port_addr;
706         u16                                     drv_mb_seq;
707         u16                                     drv_pulse_seq;
708         struct qed_mcp_link_params              link_input;
709         struct qed_mcp_link_state               link_output;
710         struct qed_mcp_link_capabilities        link_capabilities;
711         struct qed_mcp_function_info            func_info;
712         u8                                      *mfw_mb_cur;
713         u8                                      *mfw_mb_shadow;
714         u16                                     mfw_mb_length;
715         u32                                     mcp_hist;
716
717         /* Capabilties negotiated with the MFW */
718         u32                                     capabilities;
719
720         /* S/N for debug data mailbox commands */
721         atomic_t dbg_data_seq;
722 };
723
724 struct qed_mcp_mb_params {
725         u32 cmd;
726         u32 param;
727         void *p_data_src;
728         void *p_data_dst;
729         u8 data_src_size;
730         u8 data_dst_size;
731         u32 mcp_resp;
732         u32 mcp_param;
733         u32 flags;
734 #define QED_MB_FLAG_CAN_SLEEP   (0x1 << 0)
735 #define QED_MB_FLAG_AVOID_BLOCK (0x1 << 1)
736 #define QED_MB_FLAGS_IS_SET(params, flag) \
737         ({ typeof(params) __params = (params); \
738            (__params && (__params->flags & QED_MB_FLAG_ ## flag)); })
739 };
740
741 struct qed_drv_tlv_hdr {
742         u8 tlv_type;
743         u8 tlv_length;  /* In dwords - not including this header */
744         u8 tlv_reserved;
745 #define QED_DRV_TLV_FLAGS_CHANGED 0x01
746         u8 tlv_flags;
747 };
748
749 /**
750  * @brief Initialize the interface with the MCP
751  *
752  * @param p_hwfn - HW func
753  * @param p_ptt - PTT required for register access
754  *
755  * @return int
756  */
757 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
758                      struct qed_ptt *p_ptt);
759
760 /**
761  * @brief Initialize the port interface with the MCP
762  *
763  * @param p_hwfn
764  * @param p_ptt
765  * Can only be called after `num_ports_in_engines' is set
766  */
767 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
768                            struct qed_ptt *p_ptt);
769 /**
770  * @brief Releases resources allocated during the init process.
771  *
772  * @param p_hwfn - HW func
773  * @param p_ptt - PTT required for register access
774  *
775  * @return int
776  */
777
778 int qed_mcp_free(struct qed_hwfn *p_hwfn);
779
780 /**
781  * @brief This function is called from the DPC context. After
782  * pointing PTT to the mfw mb, check for events sent by the MCP
783  * to the driver and ack them. In case a critical event
784  * detected, it will be handled here, otherwise the work will be
785  * queued to a sleepable work-queue.
786  *
787  * @param p_hwfn - HW function
788  * @param p_ptt - PTT required for register access
789  * @return int - 0 - operation
790  * was successul.
791  */
792 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
793                           struct qed_ptt *p_ptt);
794
795 enum qed_drv_role {
796         QED_DRV_ROLE_OS,
797         QED_DRV_ROLE_KDUMP,
798 };
799
800 struct qed_load_req_params {
801         /* Input params */
802         enum qed_drv_role drv_role;
803         u8 timeout_val;
804         bool avoid_eng_reset;
805         enum qed_override_force_load override_force_load;
806
807         /* Output params */
808         u32 load_code;
809 };
810
811 /**
812  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
813  *        returns whether this PF is the first on the engine/port or function.
814  *
815  * @param p_hwfn
816  * @param p_ptt
817  * @param p_params
818  *
819  * @return int - 0 - Operation was successful.
820  */
821 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
822                      struct qed_ptt *p_ptt,
823                      struct qed_load_req_params *p_params);
824
825 /**
826  * @brief Sends a LOAD_DONE message to the MFW
827  *
828  * @param p_hwfn
829  * @param p_ptt
830  *
831  * @return int - 0 - Operation was successful.
832  */
833 int qed_mcp_load_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
834
835 /**
836  * @brief Sends a UNLOAD_REQ message to the MFW
837  *
838  * @param p_hwfn
839  * @param p_ptt
840  *
841  * @return int - 0 - Operation was successful.
842  */
843 int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
844
845 /**
846  * @brief Sends a UNLOAD_DONE message to the MFW
847  *
848  * @param p_hwfn
849  * @param p_ptt
850  *
851  * @return int - 0 - Operation was successful.
852  */
853 int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
854
855 /**
856  * @brief Read the MFW mailbox into Current buffer.
857  *
858  * @param p_hwfn
859  * @param p_ptt
860  */
861 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
862                      struct qed_ptt *p_ptt);
863
864 /**
865  * @brief Ack to mfw that driver finished FLR process for VFs
866  *
867  * @param p_hwfn
868  * @param p_ptt
869  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
870  *
871  * @param return int - 0 upon success.
872  */
873 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
874                        struct qed_ptt *p_ptt, u32 *vfs_to_ack);
875
876 /**
877  * @brief - calls during init to read shmem of all function-related info.
878  *
879  * @param p_hwfn
880  *
881  * @param return 0 upon success.
882  */
883 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
884                                  struct qed_ptt *p_ptt);
885
886 /**
887  * @brief - Reset the MCP using mailbox command.
888  *
889  * @param p_hwfn
890  * @param p_ptt
891  *
892  * @param return 0 upon success.
893  */
894 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
895                   struct qed_ptt *p_ptt);
896
897 /**
898  * @brief - Sends an NVM read command request to the MFW to get
899  *        a buffer.
900  *
901  * @param p_hwfn
902  * @param p_ptt
903  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
904  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
905  * @param param - [0:23] - Offset [24:31] - Size
906  * @param o_mcp_resp - MCP response
907  * @param o_mcp_param - MCP response param
908  * @param o_txn_size -  Buffer size output
909  * @param o_buf - Pointer to the buffer returned by the MFW.
910  *
911  * @param return 0 upon success.
912  */
913 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
914                        struct qed_ptt *p_ptt,
915                        u32 cmd,
916                        u32 param,
917                        u32 *o_mcp_resp,
918                        u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
919
920 /**
921  * @brief Read from sfp
922  *
923  *  @param p_hwfn - hw function
924  *  @param p_ptt  - PTT required for register access
925  *  @param port   - transceiver port
926  *  @param addr   - I2C address
927  *  @param offset - offset in sfp
928  *  @param len    - buffer length
929  *  @param p_buf  - buffer to read into
930  *
931  * @return int - 0 - operation was successful.
932  */
933 int qed_mcp_phy_sfp_read(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
934                          u32 port, u32 addr, u32 offset, u32 len, u8 *p_buf);
935
936 /**
937  * @brief indicates whether the MFW objects [under mcp_info] are accessible
938  *
939  * @param p_hwfn
940  *
941  * @return true iff MFW is running and mcp_info is initialized
942  */
943 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
944
945 /**
946  * @brief request MFW to configure MSI-X for a VF
947  *
948  * @param p_hwfn
949  * @param p_ptt
950  * @param vf_id - absolute inside engine
951  * @param num_sbs - number of entries to request
952  *
953  * @return int
954  */
955 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
956                            struct qed_ptt *p_ptt, u8 vf_id, u8 num);
957
958 /**
959  * @brief - Halt the MCP.
960  *
961  * @param p_hwfn
962  * @param p_ptt
963  *
964  * @param return 0 upon success.
965  */
966 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
967
968 /**
969  * @brief - Wake up the MCP.
970  *
971  * @param p_hwfn
972  * @param p_ptt
973  *
974  * @param return 0 upon success.
975  */
976 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
977
978 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
979 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
980 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
981                                      struct qed_ptt *p_ptt,
982                                      struct qed_mcp_link_state *p_link,
983                                      u8 max_bw);
984 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
985                                      struct qed_ptt *p_ptt,
986                                      struct qed_mcp_link_state *p_link,
987                                      u8 min_bw);
988
989 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
990                           struct qed_ptt *p_ptt, u32 mask_parities);
991
992 /* @brief - Gets the mdump retained data from the MFW.
993  *
994  * @param p_hwfn
995  * @param p_ptt
996  * @param p_mdump_retain
997  *
998  * @param return 0 upon success.
999  */
1000 int
1001 qed_mcp_mdump_get_retain(struct qed_hwfn *p_hwfn,
1002                          struct qed_ptt *p_ptt,
1003                          struct mdump_retain_data_stc *p_mdump_retain);
1004
1005 /**
1006  * @brief - Sets the MFW's max value for the given resource
1007  *
1008  *  @param p_hwfn
1009  *  @param p_ptt
1010  *  @param res_id
1011  *  @param resc_max_val
1012  *  @param p_mcp_resp
1013  *
1014  * @return int - 0 - operation was successful.
1015  */
1016 int
1017 qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn,
1018                          struct qed_ptt *p_ptt,
1019                          enum qed_resources res_id,
1020                          u32 resc_max_val, u32 *p_mcp_resp);
1021
1022 /**
1023  * @brief - Gets the MFW allocation info for the given resource
1024  *
1025  *  @param p_hwfn
1026  *  @param p_ptt
1027  *  @param res_id
1028  *  @param p_mcp_resp
1029  *  @param p_resc_num
1030  *  @param p_resc_start
1031  *
1032  * @return int - 0 - operation was successful.
1033  */
1034 int
1035 qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
1036                       struct qed_ptt *p_ptt,
1037                       enum qed_resources res_id,
1038                       u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start);
1039
1040 /**
1041  * @brief Send eswitch mode to MFW
1042  *
1043  *  @param p_hwfn
1044  *  @param p_ptt
1045  *  @param eswitch - eswitch mode
1046  *
1047  * @return int - 0 - operation was successful.
1048  */
1049 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
1050                               struct qed_ptt *p_ptt,
1051                               enum qed_ov_eswitch eswitch);
1052
1053 #define QED_MCP_RESC_LOCK_MIN_VAL       RESOURCE_DUMP
1054 #define QED_MCP_RESC_LOCK_MAX_VAL       31
1055
1056 enum qed_resc_lock {
1057         QED_RESC_LOCK_DBG_DUMP = QED_MCP_RESC_LOCK_MIN_VAL,
1058         QED_RESC_LOCK_PTP_PORT0,
1059         QED_RESC_LOCK_PTP_PORT1,
1060         QED_RESC_LOCK_PTP_PORT2,
1061         QED_RESC_LOCK_PTP_PORT3,
1062         QED_RESC_LOCK_RESC_ALLOC = QED_MCP_RESC_LOCK_MAX_VAL,
1063         QED_RESC_LOCK_RESC_INVALID
1064 };
1065
1066 /**
1067  * @brief - Initiates PF FLR
1068  *
1069  *  @param p_hwfn
1070  *  @param p_ptt
1071  *
1072  * @return int - 0 - operation was successful.
1073  */
1074 int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1075 struct qed_resc_lock_params {
1076         /* Resource number [valid values are 0..31] */
1077         u8 resource;
1078
1079         /* Lock timeout value in seconds [default, none or 1..254] */
1080         u8 timeout;
1081 #define QED_MCP_RESC_LOCK_TO_DEFAULT    0
1082 #define QED_MCP_RESC_LOCK_TO_NONE       255
1083
1084         /* Number of times to retry locking */
1085         u8 retry_num;
1086 #define QED_MCP_RESC_LOCK_RETRY_CNT_DFLT        10
1087
1088         /* The interval in usec between retries */
1089         u16 retry_interval;
1090 #define QED_MCP_RESC_LOCK_RETRY_VAL_DFLT        10000
1091
1092         /* Use sleep or delay between retries */
1093         bool sleep_b4_retry;
1094
1095         /* Will be set as true if the resource is free and granted */
1096         bool b_granted;
1097
1098         /* Will be filled with the resource owner.
1099          * [0..15 = PF0-15, 16 = MFW]
1100          */
1101         u8 owner;
1102 };
1103
1104 /**
1105  * @brief Acquires MFW generic resource lock
1106  *
1107  *  @param p_hwfn
1108  *  @param p_ptt
1109  *  @param p_params
1110  *
1111  * @return int - 0 - operation was successful.
1112  */
1113 int
1114 qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
1115                   struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params);
1116
1117 struct qed_resc_unlock_params {
1118         /* Resource number [valid values are 0..31] */
1119         u8 resource;
1120
1121         /* Allow to release a resource even if belongs to another PF */
1122         bool b_force;
1123
1124         /* Will be set as true if the resource is released */
1125         bool b_released;
1126 };
1127
1128 /**
1129  * @brief Releases MFW generic resource lock
1130  *
1131  *  @param p_hwfn
1132  *  @param p_ptt
1133  *  @param p_params
1134  *
1135  * @return int - 0 - operation was successful.
1136  */
1137 int
1138 qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn,
1139                     struct qed_ptt *p_ptt,
1140                     struct qed_resc_unlock_params *p_params);
1141
1142 /**
1143  * @brief - default initialization for lock/unlock resource structs
1144  *
1145  * @param p_lock - lock params struct to be initialized; Can be NULL
1146  * @param p_unlock - unlock params struct to be initialized; Can be NULL
1147  * @param resource - the requested resource
1148  * @paral b_is_permanent - disable retries & aging when set
1149  */
1150 void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock,
1151                                     struct qed_resc_unlock_params *p_unlock,
1152                                     enum qed_resc_lock
1153                                     resource, bool b_is_permanent);
1154
1155 /**
1156  * @brief - Return whether management firmware support smart AN
1157  *
1158  * @param p_hwfn
1159  *
1160  * @return bool - true if feature is supported.
1161  */
1162 bool qed_mcp_is_smart_an_supported(struct qed_hwfn *p_hwfn);
1163
1164 /**
1165  * @brief Learn of supported MFW features; To be done during early init
1166  *
1167  * @param p_hwfn
1168  * @param p_ptt
1169  */
1170 int qed_mcp_get_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1171
1172 /**
1173  * @brief Inform MFW of set of features supported by driver. Should be done
1174  * inside the content of the LOAD_REQ.
1175  *
1176  * @param p_hwfn
1177  * @param p_ptt
1178  */
1179 int qed_mcp_set_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1180
1181 /**
1182  * @brief Read ufp config from the shared memory.
1183  *
1184  * @param p_hwfn
1185  * @param p_ptt
1186  */
1187 void qed_mcp_read_ufp_config(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1188
1189 /**
1190  * @brief Populate the nvm info shadow in the given hardware function
1191  *
1192  * @param p_hwfn
1193  */
1194 int qed_mcp_nvm_info_populate(struct qed_hwfn *p_hwfn);
1195
1196 /**
1197  * @brief Delete nvm info shadow in the given hardware function
1198  *
1199  * @param p_hwfn
1200  */
1201 void qed_mcp_nvm_info_free(struct qed_hwfn *p_hwfn);
1202
1203 /**
1204  * @brief Get the engine affinity configuration.
1205  *
1206  * @param p_hwfn
1207  * @param p_ptt
1208  */
1209 int qed_mcp_get_engine_config(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1210
1211 /**
1212  * @brief Get the PPFID bitmap.
1213  *
1214  * @param p_hwfn
1215  * @param p_ptt
1216  */
1217 int qed_mcp_get_ppfid_bitmap(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
1218
1219 /**
1220  * @brief Get NVM config attribute value.
1221  *
1222  * @param p_hwfn
1223  * @param p_ptt
1224  * @param option_id
1225  * @param entity_id
1226  * @param flags
1227  * @param p_buf
1228  * @param p_len
1229  */
1230 int qed_mcp_nvm_get_cfg(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1231                         u16 option_id, u8 entity_id, u16 flags, u8 *p_buf,
1232                         u32 *p_len);
1233
1234 /**
1235  * @brief Set NVM config attribute value.
1236  *
1237  * @param p_hwfn
1238  * @param p_ptt
1239  * @param option_id
1240  * @param entity_id
1241  * @param flags
1242  * @param p_buf
1243  * @param len
1244  */
1245 int qed_mcp_nvm_set_cfg(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1246                         u16 option_id, u8 entity_id, u16 flags, u8 *p_buf,
1247                         u32 len);
1248 #endif