GNU Linux-libre 4.9.301-gnu1
[releases.git] / drivers / net / ethernet / qlogic / qed / qed_mcp.h
1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015 QLogic Corporation
3  *
4  * This software is available under the terms of the GNU General Public License
5  * (GPL) Version 2, available from the file COPYING in the main directory of
6  * this source tree.
7  */
8
9 #ifndef _QED_MCP_H
10 #define _QED_MCP_H
11
12 #include <linux/types.h>
13 #include <linux/delay.h>
14 #include <linux/slab.h>
15 #include <linux/spinlock.h>
16 #include "qed_hsi.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 struct qed_mcp_link_params {
31         struct qed_mcp_link_speed_params        speed;
32         struct qed_mcp_link_pause_params        pause;
33         u32                                  loopback_mode;
34 };
35
36 struct qed_mcp_link_capabilities {
37         u32 speed_capabilities;
38         bool default_speed_autoneg;
39 };
40
41 struct qed_mcp_link_state {
42         bool    link_up;
43
44         u32     min_pf_rate;
45
46         /* Actual link speed in Mb/s */
47         u32     line_speed;
48
49         /* PF max speed in Mb/s, deduced from line_speed
50          * according to PF max bandwidth configuration.
51          */
52         u32     speed;
53         bool    full_duplex;
54
55         bool    an;
56         bool    an_complete;
57         bool    parallel_detection;
58         bool    pfc_enabled;
59
60 #define QED_LINK_PARTNER_SPEED_1G_HD    BIT(0)
61 #define QED_LINK_PARTNER_SPEED_1G_FD    BIT(1)
62 #define QED_LINK_PARTNER_SPEED_10G      BIT(2)
63 #define QED_LINK_PARTNER_SPEED_20G      BIT(3)
64 #define QED_LINK_PARTNER_SPEED_25G      BIT(4)
65 #define QED_LINK_PARTNER_SPEED_40G      BIT(5)
66 #define QED_LINK_PARTNER_SPEED_50G      BIT(6)
67 #define QED_LINK_PARTNER_SPEED_100G     BIT(7)
68         u32     partner_adv_speed;
69
70         bool    partner_tx_flow_ctrl_en;
71         bool    partner_rx_flow_ctrl_en;
72
73 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
74 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
75 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
76         u8      partner_adv_pause;
77
78         bool    sfp_tx_fault;
79 };
80
81 struct qed_mcp_function_info {
82         u8                              pause_on_host;
83
84         enum qed_pci_personality        protocol;
85
86         u8                              bandwidth_min;
87         u8                              bandwidth_max;
88
89         u8                              mac[ETH_ALEN];
90
91         u64                             wwn_port;
92         u64                             wwn_node;
93
94 #define QED_MCP_VLAN_UNSET              (0xffff)
95         u16                             ovlan;
96 };
97
98 struct qed_mcp_nvm_common {
99         u32     offset;
100         u32     param;
101         u32     resp;
102         u32     cmd;
103 };
104
105 struct qed_mcp_drv_version {
106         u32     version;
107         u8      name[MCP_DRV_VER_STR_SIZE - 4];
108 };
109
110 struct qed_mcp_lan_stats {
111         u64 ucast_rx_pkts;
112         u64 ucast_tx_pkts;
113         u32 fcs_err;
114 };
115
116 struct qed_mcp_fcoe_stats {
117         u64 rx_pkts;
118         u64 tx_pkts;
119         u32 fcs_err;
120         u32 login_failure;
121 };
122
123 struct qed_mcp_iscsi_stats {
124         u64 rx_pdus;
125         u64 tx_pdus;
126         u64 rx_bytes;
127         u64 tx_bytes;
128 };
129
130 struct qed_mcp_rdma_stats {
131         u64 rx_pkts;
132         u64 tx_pkts;
133         u64 rx_bytes;
134         u64 tx_byts;
135 };
136
137 enum qed_mcp_protocol_type {
138         QED_MCP_LAN_STATS,
139         QED_MCP_FCOE_STATS,
140         QED_MCP_ISCSI_STATS,
141         QED_MCP_RDMA_STATS
142 };
143
144 union qed_mcp_protocol_stats {
145         struct qed_mcp_lan_stats lan_stats;
146         struct qed_mcp_fcoe_stats fcoe_stats;
147         struct qed_mcp_iscsi_stats iscsi_stats;
148         struct qed_mcp_rdma_stats rdma_stats;
149 };
150
151 /**
152  * @brief - returns the link params of the hw function
153  *
154  * @param p_hwfn
155  *
156  * @returns pointer to link params
157  */
158 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
159
160 /**
161  * @brief - return the link state of the hw function
162  *
163  * @param p_hwfn
164  *
165  * @returns pointer to link state
166  */
167 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
168
169 /**
170  * @brief - return the link capabilities of the hw function
171  *
172  * @param p_hwfn
173  *
174  * @returns pointer to link capabilities
175  */
176 struct qed_mcp_link_capabilities
177         *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
178
179 /**
180  * @brief Request the MFW to set the the link according to 'link_input'.
181  *
182  * @param p_hwfn
183  * @param p_ptt
184  * @param b_up - raise link if `true'. Reset link if `false'.
185  *
186  * @return int
187  */
188 int qed_mcp_set_link(struct qed_hwfn   *p_hwfn,
189                      struct qed_ptt     *p_ptt,
190                      bool               b_up);
191
192 /**
193  * @brief Get the management firmware version value
194  *
195  * @param p_hwfn
196  * @param p_ptt
197  * @param p_mfw_ver    - mfw version value
198  * @param p_running_bundle_id   - image id in nvram; Optional.
199  *
200  * @return int - 0 - operation was successful.
201  */
202 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
203                         struct qed_ptt *p_ptt,
204                         u32 *p_mfw_ver, u32 *p_running_bundle_id);
205
206 /**
207  * @brief Get media type value of the port.
208  *
209  * @param cdev      - qed dev pointer
210  * @param mfw_ver    - media type value
211  *
212  * @return int -
213  *      0 - Operation was successul.
214  *      -EBUSY - Operation failed
215  */
216 int qed_mcp_get_media_type(struct qed_dev      *cdev,
217                            u32                  *media_type);
218
219 /**
220  * @brief General function for sending commands to the MCP
221  *        mailbox. It acquire mutex lock for the entire
222  *        operation, from sending the request until the MCP
223  *        response. Waiting for MCP response will be checked up
224  *        to 5 seconds every 5ms.
225  *
226  * @param p_hwfn     - hw function
227  * @param p_ptt      - PTT required for register access
228  * @param cmd        - command to be sent to the MCP.
229  * @param param      - Optional param
230  * @param o_mcp_resp - The MCP response code (exclude sequence).
231  * @param o_mcp_param- Optional parameter provided by the MCP
232  *                     response
233  * @return int - 0 - operation
234  * was successul.
235  */
236 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
237                 struct qed_ptt *p_ptt,
238                 u32 cmd,
239                 u32 param,
240                 u32 *o_mcp_resp,
241                 u32 *o_mcp_param);
242
243 /**
244  * @brief - drains the nig, allowing completion to pass in case of pauses.
245  *          (Should be called only from sleepable context)
246  *
247  * @param p_hwfn
248  * @param p_ptt
249  */
250 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
251                   struct qed_ptt *p_ptt);
252
253 /**
254  * @brief Get the flash size value
255  *
256  * @param p_hwfn
257  * @param p_ptt
258  * @param p_flash_size  - flash size in bytes to be filled.
259  *
260  * @return int - 0 - operation was successul.
261  */
262 int qed_mcp_get_flash_size(struct qed_hwfn     *p_hwfn,
263                            struct qed_ptt       *p_ptt,
264                            u32 *p_flash_size);
265
266 /**
267  * @brief Send driver version to MFW
268  *
269  * @param p_hwfn
270  * @param p_ptt
271  * @param version - Version value
272  * @param name - Protocol driver name
273  *
274  * @return int - 0 - operation was successul.
275  */
276 int
277 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
278                          struct qed_ptt *p_ptt,
279                          struct qed_mcp_drv_version *p_ver);
280
281 /**
282  * @brief Set LED status
283  *
284  *  @param p_hwfn
285  *  @param p_ptt
286  *  @param mode - LED mode
287  *
288  * @return int - 0 - operation was successful.
289  */
290 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
291                     struct qed_ptt *p_ptt,
292                     enum qed_led_mode mode);
293
294 /**
295  * @brief Bist register test
296  *
297  *  @param p_hwfn    - hw function
298  *  @param p_ptt     - PTT required for register access
299  *
300  * @return int - 0 - operation was successful.
301  */
302 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
303                                struct qed_ptt *p_ptt);
304
305 /**
306  * @brief Bist clock test
307  *
308  *  @param p_hwfn    - hw function
309  *  @param p_ptt     - PTT required for register access
310  *
311  * @return int - 0 - operation was successful.
312  */
313 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
314                             struct qed_ptt *p_ptt);
315
316 /* Using hwfn number (and not pf_num) is required since in CMT mode,
317  * same pf_num may be used by two different hwfn
318  * TODO - this shouldn't really be in .h file, but until all fields
319  * required during hw-init will be placed in their correct place in shmem
320  * we need it in qed_dev.c [for readin the nvram reflection in shmem].
321  */
322 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ?        \
323                                             ((rel_pfid) |                      \
324                                              ((p_hwfn)->abs_pf_id & 1) << 3) : \
325                                             rel_pfid)
326 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
327
328 /* TODO - this is only correct as long as only BB is supported, and
329  * no port-swapping is implemented; Afterwards we'll need to fix it.
330  */
331 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id % \
332                                  ((_p_hwfn)->cdev->num_ports_in_engines * 2))
333 struct qed_mcp_info {
334         spinlock_t                              lock;
335         bool                                    block_mb_sending;
336         u32                                     public_base;
337         u32                                     drv_mb_addr;
338         u32                                     mfw_mb_addr;
339         u32                                     port_addr;
340         u16                                     drv_mb_seq;
341         u16                                     drv_pulse_seq;
342         struct qed_mcp_link_params              link_input;
343         struct qed_mcp_link_state               link_output;
344         struct qed_mcp_link_capabilities        link_capabilities;
345         struct qed_mcp_function_info            func_info;
346         u8                                      *mfw_mb_cur;
347         u8                                      *mfw_mb_shadow;
348         u16                                     mfw_mb_length;
349         u16                                     mcp_hist;
350 };
351
352 struct qed_mcp_mb_params {
353         u32                     cmd;
354         u32                     param;
355         union drv_union_data    *p_data_src;
356         union drv_union_data    *p_data_dst;
357         u32                     mcp_resp;
358         u32                     mcp_param;
359 };
360
361 /**
362  * @brief Initialize the interface with the MCP
363  *
364  * @param p_hwfn - HW func
365  * @param p_ptt - PTT required for register access
366  *
367  * @return int
368  */
369 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
370                      struct qed_ptt *p_ptt);
371
372 /**
373  * @brief Initialize the port interface with the MCP
374  *
375  * @param p_hwfn
376  * @param p_ptt
377  * Can only be called after `num_ports_in_engines' is set
378  */
379 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
380                            struct qed_ptt *p_ptt);
381 /**
382  * @brief Releases resources allocated during the init process.
383  *
384  * @param p_hwfn - HW func
385  * @param p_ptt - PTT required for register access
386  *
387  * @return int
388  */
389
390 int qed_mcp_free(struct qed_hwfn *p_hwfn);
391
392 /**
393  * @brief This function is called from the DPC context. After
394  * pointing PTT to the mfw mb, check for events sent by the MCP
395  * to the driver and ack them. In case a critical event
396  * detected, it will be handled here, otherwise the work will be
397  * queued to a sleepable work-queue.
398  *
399  * @param p_hwfn - HW function
400  * @param p_ptt - PTT required for register access
401  * @return int - 0 - operation
402  * was successul.
403  */
404 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
405                           struct qed_ptt *p_ptt);
406
407 /**
408  * @brief Sends a LOAD_REQ to the MFW, and in case operation
409  *        succeed, returns whether this PF is the first on the
410  *        chip/engine/port or function. This function should be
411  *        called when driver is ready to accept MFW events after
412  *        Storms initializations are done.
413  *
414  * @param p_hwfn       - hw function
415  * @param p_ptt        - PTT required for register access
416  * @param p_load_code  - The MCP response param containing one
417  *      of the following:
418  *      FW_MSG_CODE_DRV_LOAD_ENGINE
419  *      FW_MSG_CODE_DRV_LOAD_PORT
420  *      FW_MSG_CODE_DRV_LOAD_FUNCTION
421  * @return int -
422  *      0 - Operation was successul.
423  *      -EBUSY - Operation failed
424  */
425 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
426                      struct qed_ptt *p_ptt,
427                      u32 *p_load_code);
428
429 /**
430  * @brief Read the MFW mailbox into Current buffer.
431  *
432  * @param p_hwfn
433  * @param p_ptt
434  */
435 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
436                      struct qed_ptt *p_ptt);
437
438 /**
439  * @brief Ack to mfw that driver finished FLR process for VFs
440  *
441  * @param p_hwfn
442  * @param p_ptt
443  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
444  *
445  * @param return int - 0 upon success.
446  */
447 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
448                        struct qed_ptt *p_ptt, u32 *vfs_to_ack);
449
450 /**
451  * @brief - calls during init to read shmem of all function-related info.
452  *
453  * @param p_hwfn
454  *
455  * @param return 0 upon success.
456  */
457 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
458                                  struct qed_ptt *p_ptt);
459
460 /**
461  * @brief - Reset the MCP using mailbox command.
462  *
463  * @param p_hwfn
464  * @param p_ptt
465  *
466  * @param return 0 upon success.
467  */
468 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
469                   struct qed_ptt *p_ptt);
470
471 /**
472  * @brief - Sends an NVM read command request to the MFW to get
473  *        a buffer.
474  *
475  * @param p_hwfn
476  * @param p_ptt
477  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
478  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
479  * @param param - [0:23] - Offset [24:31] - Size
480  * @param o_mcp_resp - MCP response
481  * @param o_mcp_param - MCP response param
482  * @param o_txn_size -  Buffer size output
483  * @param o_buf - Pointer to the buffer returned by the MFW.
484  *
485  * @param return 0 upon success.
486  */
487 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
488                        struct qed_ptt *p_ptt,
489                        u32 cmd,
490                        u32 param,
491                        u32 *o_mcp_resp,
492                        u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
493
494 /**
495  * @brief indicates whether the MFW objects [under mcp_info] are accessible
496  *
497  * @param p_hwfn
498  *
499  * @return true iff MFW is running and mcp_info is initialized
500  */
501 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
502
503 /**
504  * @brief request MFW to configure MSI-X for a VF
505  *
506  * @param p_hwfn
507  * @param p_ptt
508  * @param vf_id - absolute inside engine
509  * @param num_sbs - number of entries to request
510  *
511  * @return int
512  */
513 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
514                            struct qed_ptt *p_ptt, u8 vf_id, u8 num);
515
516 /**
517  * @brief - Halt the MCP.
518  *
519  * @param p_hwfn
520  * @param p_ptt
521  *
522  * @param return 0 upon success.
523  */
524 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
525
526 /**
527  * @brief - Wake up the MCP.
528  *
529  * @param p_hwfn
530  * @param p_ptt
531  *
532  * @param return 0 upon success.
533  */
534 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
535
536 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
537 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
538 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
539                                      struct qed_ptt *p_ptt,
540                                      struct qed_mcp_link_state *p_link,
541                                      u8 max_bw);
542 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
543                                      struct qed_ptt *p_ptt,
544                                      struct qed_mcp_link_state *p_link,
545                                      u8 min_bw);
546
547 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
548                           struct qed_ptt *p_ptt, u32 mask_parities);
549
550 #endif