qed: Add module with basic common support
[cascardo/linux.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/mutex.h>
15 #include <linux/slab.h>
16 #include "qed_hsi.h"
17
18 struct qed_mcp_function_info {
19         u8                              pause_on_host;
20
21         enum qed_pci_personality        protocol;
22
23         u8                              bandwidth_min;
24         u8                              bandwidth_max;
25
26         u8                              mac[ETH_ALEN];
27
28         u64                             wwn_port;
29         u64                             wwn_node;
30
31 #define QED_MCP_VLAN_UNSET              (0xffff)
32         u16                             ovlan;
33 };
34
35 struct qed_mcp_nvm_common {
36         u32     offset;
37         u32     param;
38         u32     resp;
39         u32     cmd;
40 };
41
42 struct qed_mcp_drv_version {
43         u32     version;
44         u8      name[MCP_DRV_VER_STR_SIZE - 4];
45 };
46
47 /**
48  * @brief Get the management firmware version value
49  *
50  * @param cdev       - qed dev pointer
51  * @param mfw_ver    - mfw version value
52  *
53  * @return int - 0 - operation was successul.
54  */
55 int qed_mcp_get_mfw_ver(struct qed_dev *cdev,
56                         u32 *mfw_ver);
57
58 /**
59  * @brief General function for sending commands to the MCP
60  *        mailbox. It acquire mutex lock for the entire
61  *        operation, from sending the request until the MCP
62  *        response. Waiting for MCP response will be checked up
63  *        to 5 seconds every 5ms.
64  *
65  * @param p_hwfn     - hw function
66  * @param p_ptt      - PTT required for register access
67  * @param cmd        - command to be sent to the MCP.
68  * @param param      - Optional param
69  * @param o_mcp_resp - The MCP response code (exclude sequence).
70  * @param o_mcp_param- Optional parameter provided by the MCP
71  *                     response
72  * @return int - 0 - operation
73  * was successul.
74  */
75 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
76                 struct qed_ptt *p_ptt,
77                 u32 cmd,
78                 u32 param,
79                 u32 *o_mcp_resp,
80                 u32 *o_mcp_param);
81
82 /**
83  * @brief - drains the nig, allowing completion to pass in case of pauses.
84  *          (Should be called only from sleepable context)
85  *
86  * @param p_hwfn
87  * @param p_ptt
88  */
89 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
90                   struct qed_ptt *p_ptt);
91
92 /**
93  * @brief Send driver version to MFW
94  *
95  * @param p_hwfn
96  * @param p_ptt
97  * @param version - Version value
98  * @param name - Protocol driver name
99  *
100  * @return int - 0 - operation was successul.
101  */
102 int
103 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
104                          struct qed_ptt *p_ptt,
105                          struct qed_mcp_drv_version *p_ver);
106
107 /* Using hwfn number (and not pf_num) is required since in CMT mode,
108  * same pf_num may be used by two different hwfn
109  * TODO - this shouldn't really be in .h file, but until all fields
110  * required during hw-init will be placed in their correct place in shmem
111  * we need it in qed_dev.c [for readin the nvram reflection in shmem].
112  */
113 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ?        \
114                                             ((rel_pfid) |                      \
115                                              ((p_hwfn)->abs_pf_id & 1) << 3) : \
116                                             rel_pfid)
117 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
118
119 /* TODO - this is only correct as long as only BB is supported, and
120  * no port-swapping is implemented; Afterwards we'll need to fix it.
121  */
122 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id % \
123                                  ((_p_hwfn)->cdev->num_ports_in_engines * 2))
124 struct qed_mcp_info {
125         struct mutex                            mutex; /* MCP access lock */
126         u32                                     public_base;
127         u32                                     drv_mb_addr;
128         u32                                     mfw_mb_addr;
129         u32                                     port_addr;
130         u16                                     drv_mb_seq;
131         u16                                     drv_pulse_seq;
132         struct qed_mcp_function_info            func_info;
133
134         u8                                      *mfw_mb_cur;
135         u8                                      *mfw_mb_shadow;
136         u16                                     mfw_mb_length;
137         u16                                     mcp_hist;
138 };
139
140 /**
141  * @brief Initialize the interface with the MCP
142  *
143  * @param p_hwfn - HW func
144  * @param p_ptt - PTT required for register access
145  *
146  * @return int
147  */
148 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
149                      struct qed_ptt *p_ptt);
150
151 /**
152  * @brief Initialize the port interface with the MCP
153  *
154  * @param p_hwfn
155  * @param p_ptt
156  * Can only be called after `num_ports_in_engines' is set
157  */
158 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
159                            struct qed_ptt *p_ptt);
160 /**
161  * @brief Releases resources allocated during the init process.
162  *
163  * @param p_hwfn - HW func
164  * @param p_ptt - PTT required for register access
165  *
166  * @return int
167  */
168
169 int qed_mcp_free(struct qed_hwfn *p_hwfn);
170
171 /**
172  * @brief Sends a LOAD_REQ to the MFW, and in case operation
173  *        succeed, returns whether this PF is the first on the
174  *        chip/engine/port or function. This function should be
175  *        called when driver is ready to accept MFW events after
176  *        Storms initializations are done.
177  *
178  * @param p_hwfn       - hw function
179  * @param p_ptt        - PTT required for register access
180  * @param p_load_code  - The MCP response param containing one
181  *      of the following:
182  *      FW_MSG_CODE_DRV_LOAD_ENGINE
183  *      FW_MSG_CODE_DRV_LOAD_PORT
184  *      FW_MSG_CODE_DRV_LOAD_FUNCTION
185  * @return int -
186  *      0 - Operation was successul.
187  *      -EBUSY - Operation failed
188  */
189 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
190                      struct qed_ptt *p_ptt,
191                      u32 *p_load_code);
192
193 /**
194  * @brief Read the MFW mailbox into Current buffer.
195  *
196  * @param p_hwfn
197  * @param p_ptt
198  */
199 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
200                      struct qed_ptt *p_ptt);
201
202 /**
203  * @brief - calls during init to read shmem of all function-related info.
204  *
205  * @param p_hwfn
206  *
207  * @param return 0 upon success.
208  */
209 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
210                                  struct qed_ptt *p_ptt);
211
212 /**
213  * @brief - Reset the MCP using mailbox command.
214  *
215  * @param p_hwfn
216  * @param p_ptt
217  *
218  * @param return 0 upon success.
219  */
220 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
221                   struct qed_ptt *p_ptt);
222
223 /**
224  * @brief indicates whether the MFW objects [under mcp_info] are accessible
225  *
226  * @param p_hwfn
227  *
228  * @return true iff MFW is running and mcp_info is initialized
229  */
230 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
231
232 #endif