1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
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
12 #include <linux/types.h>
13 #include <linux/delay.h>
14 #include <linux/slab.h>
15 #include <linux/spinlock.h>
18 struct qed_mcp_link_speed_params
{
20 u32 advertised_speeds
; /* bitmask of DRV_SPEED_CAPABILITY */
21 u32 forced_speed
; /* In Mb/s */
24 struct qed_mcp_link_pause_params
{
30 struct qed_mcp_link_params
{
31 struct qed_mcp_link_speed_params speed
;
32 struct qed_mcp_link_pause_params pause
;
36 struct qed_mcp_link_capabilities
{
37 u32 speed_capabilities
;
40 struct qed_mcp_link_state
{
43 u32 speed
; /* In Mb/s */
48 bool parallel_detection
;
51 #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
52 #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
53 #define QED_LINK_PARTNER_SPEED_10G BIT(2)
54 #define QED_LINK_PARTNER_SPEED_20G BIT(3)
55 #define QED_LINK_PARTNER_SPEED_40G BIT(4)
56 #define QED_LINK_PARTNER_SPEED_50G BIT(5)
57 #define QED_LINK_PARTNER_SPEED_100G BIT(6)
58 u32 partner_adv_speed
;
60 bool partner_tx_flow_ctrl_en
;
61 bool partner_rx_flow_ctrl_en
;
63 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
64 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
65 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
71 struct qed_mcp_function_info
{
74 enum qed_pci_personality protocol
;
84 #define QED_MCP_VLAN_UNSET (0xffff)
88 struct qed_mcp_nvm_common
{
95 struct qed_mcp_drv_version
{
97 u8 name
[MCP_DRV_VER_STR_SIZE
- 4];
101 * @brief - returns the link params of the hw function
105 * @returns pointer to link params
107 struct qed_mcp_link_params
*qed_mcp_get_link_params(struct qed_hwfn
*);
110 * @brief - return the link state of the hw function
114 * @returns pointer to link state
116 struct qed_mcp_link_state
*qed_mcp_get_link_state(struct qed_hwfn
*);
119 * @brief - return the link capabilities of the hw function
123 * @returns pointer to link capabilities
125 struct qed_mcp_link_capabilities
126 *qed_mcp_get_link_capabilities(struct qed_hwfn
*p_hwfn
);
129 * @brief Request the MFW to set the the link according to 'link_input'.
133 * @param b_up - raise link if `true'. Reset link if `false'.
137 int qed_mcp_set_link(struct qed_hwfn
*p_hwfn
,
138 struct qed_ptt
*p_ptt
,
142 * @brief Get the management firmware version value
144 * @param cdev - qed dev pointer
145 * @param mfw_ver - mfw version value
147 * @return int - 0 - operation was successul.
149 int qed_mcp_get_mfw_ver(struct qed_dev
*cdev
,
153 * @brief Get media type value of the port.
155 * @param cdev - qed dev pointer
156 * @param mfw_ver - media type value
159 * 0 - Operation was successul.
160 * -EBUSY - Operation failed
162 int qed_mcp_get_media_type(struct qed_dev
*cdev
,
166 * @brief General function for sending commands to the MCP
167 * mailbox. It acquire mutex lock for the entire
168 * operation, from sending the request until the MCP
169 * response. Waiting for MCP response will be checked up
170 * to 5 seconds every 5ms.
172 * @param p_hwfn - hw function
173 * @param p_ptt - PTT required for register access
174 * @param cmd - command to be sent to the MCP.
175 * @param param - Optional param
176 * @param o_mcp_resp - The MCP response code (exclude sequence).
177 * @param o_mcp_param- Optional parameter provided by the MCP
179 * @return int - 0 - operation
182 int qed_mcp_cmd(struct qed_hwfn
*p_hwfn
,
183 struct qed_ptt
*p_ptt
,
190 * @brief - drains the nig, allowing completion to pass in case of pauses.
191 * (Should be called only from sleepable context)
196 int qed_mcp_drain(struct qed_hwfn
*p_hwfn
,
197 struct qed_ptt
*p_ptt
);
200 * @brief Get the flash size value
204 * @param p_flash_size - flash size in bytes to be filled.
206 * @return int - 0 - operation was successul.
208 int qed_mcp_get_flash_size(struct qed_hwfn
*p_hwfn
,
209 struct qed_ptt
*p_ptt
,
213 * @brief Send driver version to MFW
217 * @param version - Version value
218 * @param name - Protocol driver name
220 * @return int - 0 - operation was successul.
223 qed_mcp_send_drv_version(struct qed_hwfn
*p_hwfn
,
224 struct qed_ptt
*p_ptt
,
225 struct qed_mcp_drv_version
*p_ver
);
228 * @brief Set LED status
232 * @param mode - LED mode
234 * @return int - 0 - operation was successful.
236 int qed_mcp_set_led(struct qed_hwfn
*p_hwfn
,
237 struct qed_ptt
*p_ptt
,
238 enum qed_led_mode mode
);
240 /* Using hwfn number (and not pf_num) is required since in CMT mode,
241 * same pf_num may be used by two different hwfn
242 * TODO - this shouldn't really be in .h file, but until all fields
243 * required during hw-init will be placed in their correct place in shmem
244 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
246 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
248 ((p_hwfn)->abs_pf_id & 1) << 3) : \
250 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
252 /* TODO - this is only correct as long as only BB is supported, and
253 * no port-swapping is implemented; Afterwards we'll need to fix it.
255 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
256 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
257 struct qed_mcp_info
{
259 bool block_mb_sending
;
266 struct qed_mcp_link_params link_input
;
267 struct qed_mcp_link_state link_output
;
268 struct qed_mcp_link_capabilities link_capabilities
;
269 struct qed_mcp_function_info func_info
;
276 struct qed_mcp_mb_params
{
279 union drv_union_data
*p_data_src
;
280 union drv_union_data
*p_data_dst
;
286 * @brief Initialize the interface with the MCP
288 * @param p_hwfn - HW func
289 * @param p_ptt - PTT required for register access
293 int qed_mcp_cmd_init(struct qed_hwfn
*p_hwfn
,
294 struct qed_ptt
*p_ptt
);
297 * @brief Initialize the port interface with the MCP
301 * Can only be called after `num_ports_in_engines' is set
303 void qed_mcp_cmd_port_init(struct qed_hwfn
*p_hwfn
,
304 struct qed_ptt
*p_ptt
);
306 * @brief Releases resources allocated during the init process.
308 * @param p_hwfn - HW func
309 * @param p_ptt - PTT required for register access
314 int qed_mcp_free(struct qed_hwfn
*p_hwfn
);
317 * @brief This function is called from the DPC context. After
318 * pointing PTT to the mfw mb, check for events sent by the MCP
319 * to the driver and ack them. In case a critical event
320 * detected, it will be handled here, otherwise the work will be
321 * queued to a sleepable work-queue.
323 * @param p_hwfn - HW function
324 * @param p_ptt - PTT required for register access
325 * @return int - 0 - operation
328 int qed_mcp_handle_events(struct qed_hwfn
*p_hwfn
,
329 struct qed_ptt
*p_ptt
);
332 * @brief Sends a LOAD_REQ to the MFW, and in case operation
333 * succeed, returns whether this PF is the first on the
334 * chip/engine/port or function. This function should be
335 * called when driver is ready to accept MFW events after
336 * Storms initializations are done.
338 * @param p_hwfn - hw function
339 * @param p_ptt - PTT required for register access
340 * @param p_load_code - The MCP response param containing one
342 * FW_MSG_CODE_DRV_LOAD_ENGINE
343 * FW_MSG_CODE_DRV_LOAD_PORT
344 * FW_MSG_CODE_DRV_LOAD_FUNCTION
346 * 0 - Operation was successul.
347 * -EBUSY - Operation failed
349 int qed_mcp_load_req(struct qed_hwfn
*p_hwfn
,
350 struct qed_ptt
*p_ptt
,
354 * @brief Read the MFW mailbox into Current buffer.
359 void qed_mcp_read_mb(struct qed_hwfn
*p_hwfn
,
360 struct qed_ptt
*p_ptt
);
363 * @brief - calls during init to read shmem of all function-related info.
367 * @param return 0 upon success.
369 int qed_mcp_fill_shmem_func_info(struct qed_hwfn
*p_hwfn
,
370 struct qed_ptt
*p_ptt
);
373 * @brief - Reset the MCP using mailbox command.
378 * @param return 0 upon success.
380 int qed_mcp_reset(struct qed_hwfn
*p_hwfn
,
381 struct qed_ptt
*p_ptt
);
384 * @brief indicates whether the MFW objects [under mcp_info] are accessible
388 * @return true iff MFW is running and mcp_info is initialized
390 bool qed_mcp_is_init(struct qed_hwfn
*p_hwfn
);