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
{
45 /* Actual link speed in Mb/s */
48 /* PF max speed in Mb/s, deduced from line_speed
49 * according to PF max bandwidth configuration.
56 bool parallel_detection
;
59 #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
60 #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
61 #define QED_LINK_PARTNER_SPEED_10G BIT(2)
62 #define QED_LINK_PARTNER_SPEED_20G BIT(3)
63 #define QED_LINK_PARTNER_SPEED_25G BIT(4)
64 #define QED_LINK_PARTNER_SPEED_40G BIT(5)
65 #define QED_LINK_PARTNER_SPEED_50G BIT(6)
66 #define QED_LINK_PARTNER_SPEED_100G BIT(7)
67 u32 partner_adv_speed
;
69 bool partner_tx_flow_ctrl_en
;
70 bool partner_rx_flow_ctrl_en
;
72 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
73 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
74 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
80 struct qed_mcp_function_info
{
83 enum qed_pci_personality protocol
;
93 #define QED_MCP_VLAN_UNSET (0xffff)
97 struct qed_mcp_nvm_common
{
104 struct qed_mcp_drv_version
{
106 u8 name
[MCP_DRV_VER_STR_SIZE
- 4];
110 * @brief - returns the link params of the hw function
114 * @returns pointer to link params
116 struct qed_mcp_link_params
*qed_mcp_get_link_params(struct qed_hwfn
*);
119 * @brief - return the link state of the hw function
123 * @returns pointer to link state
125 struct qed_mcp_link_state
*qed_mcp_get_link_state(struct qed_hwfn
*);
128 * @brief - return the link capabilities of the hw function
132 * @returns pointer to link capabilities
134 struct qed_mcp_link_capabilities
135 *qed_mcp_get_link_capabilities(struct qed_hwfn
*p_hwfn
);
138 * @brief Request the MFW to set the the link according to 'link_input'.
142 * @param b_up - raise link if `true'. Reset link if `false'.
146 int qed_mcp_set_link(struct qed_hwfn
*p_hwfn
,
147 struct qed_ptt
*p_ptt
,
151 * @brief Get the management firmware version value
155 * @param p_mfw_ver - mfw version value
156 * @param p_running_bundle_id - image id in nvram; Optional.
158 * @return int - 0 - operation was successful.
160 int qed_mcp_get_mfw_ver(struct qed_hwfn
*p_hwfn
,
161 struct qed_ptt
*p_ptt
,
162 u32
*p_mfw_ver
, u32
*p_running_bundle_id
);
165 * @brief Get media type value of the port.
167 * @param cdev - qed dev pointer
168 * @param mfw_ver - media type value
171 * 0 - Operation was successul.
172 * -EBUSY - Operation failed
174 int qed_mcp_get_media_type(struct qed_dev
*cdev
,
178 * @brief General function for sending commands to the MCP
179 * mailbox. It acquire mutex lock for the entire
180 * operation, from sending the request until the MCP
181 * response. Waiting for MCP response will be checked up
182 * to 5 seconds every 5ms.
184 * @param p_hwfn - hw function
185 * @param p_ptt - PTT required for register access
186 * @param cmd - command to be sent to the MCP.
187 * @param param - Optional param
188 * @param o_mcp_resp - The MCP response code (exclude sequence).
189 * @param o_mcp_param- Optional parameter provided by the MCP
191 * @return int - 0 - operation
194 int qed_mcp_cmd(struct qed_hwfn
*p_hwfn
,
195 struct qed_ptt
*p_ptt
,
202 * @brief - drains the nig, allowing completion to pass in case of pauses.
203 * (Should be called only from sleepable context)
208 int qed_mcp_drain(struct qed_hwfn
*p_hwfn
,
209 struct qed_ptt
*p_ptt
);
212 * @brief Get the flash size value
216 * @param p_flash_size - flash size in bytes to be filled.
218 * @return int - 0 - operation was successul.
220 int qed_mcp_get_flash_size(struct qed_hwfn
*p_hwfn
,
221 struct qed_ptt
*p_ptt
,
225 * @brief Send driver version to MFW
229 * @param version - Version value
230 * @param name - Protocol driver name
232 * @return int - 0 - operation was successul.
235 qed_mcp_send_drv_version(struct qed_hwfn
*p_hwfn
,
236 struct qed_ptt
*p_ptt
,
237 struct qed_mcp_drv_version
*p_ver
);
240 * @brief Set LED status
244 * @param mode - LED mode
246 * @return int - 0 - operation was successful.
248 int qed_mcp_set_led(struct qed_hwfn
*p_hwfn
,
249 struct qed_ptt
*p_ptt
,
250 enum qed_led_mode mode
);
253 * @brief Bist register test
255 * @param p_hwfn - hw function
256 * @param p_ptt - PTT required for register access
258 * @return int - 0 - operation was successful.
260 int qed_mcp_bist_register_test(struct qed_hwfn
*p_hwfn
,
261 struct qed_ptt
*p_ptt
);
264 * @brief Bist clock test
266 * @param p_hwfn - hw function
267 * @param p_ptt - PTT required for register access
269 * @return int - 0 - operation was successful.
271 int qed_mcp_bist_clock_test(struct qed_hwfn
*p_hwfn
,
272 struct qed_ptt
*p_ptt
);
274 /* Using hwfn number (and not pf_num) is required since in CMT mode,
275 * same pf_num may be used by two different hwfn
276 * TODO - this shouldn't really be in .h file, but until all fields
277 * required during hw-init will be placed in their correct place in shmem
278 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
280 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
282 ((p_hwfn)->abs_pf_id & 1) << 3) : \
284 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
286 /* TODO - this is only correct as long as only BB is supported, and
287 * no port-swapping is implemented; Afterwards we'll need to fix it.
289 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
290 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
291 struct qed_mcp_info
{
293 bool block_mb_sending
;
300 struct qed_mcp_link_params link_input
;
301 struct qed_mcp_link_state link_output
;
302 struct qed_mcp_link_capabilities link_capabilities
;
303 struct qed_mcp_function_info func_info
;
310 struct qed_mcp_mb_params
{
313 union drv_union_data
*p_data_src
;
314 union drv_union_data
*p_data_dst
;
320 * @brief Initialize the interface with the MCP
322 * @param p_hwfn - HW func
323 * @param p_ptt - PTT required for register access
327 int qed_mcp_cmd_init(struct qed_hwfn
*p_hwfn
,
328 struct qed_ptt
*p_ptt
);
331 * @brief Initialize the port interface with the MCP
335 * Can only be called after `num_ports_in_engines' is set
337 void qed_mcp_cmd_port_init(struct qed_hwfn
*p_hwfn
,
338 struct qed_ptt
*p_ptt
);
340 * @brief Releases resources allocated during the init process.
342 * @param p_hwfn - HW func
343 * @param p_ptt - PTT required for register access
348 int qed_mcp_free(struct qed_hwfn
*p_hwfn
);
351 * @brief This function is called from the DPC context. After
352 * pointing PTT to the mfw mb, check for events sent by the MCP
353 * to the driver and ack them. In case a critical event
354 * detected, it will be handled here, otherwise the work will be
355 * queued to a sleepable work-queue.
357 * @param p_hwfn - HW function
358 * @param p_ptt - PTT required for register access
359 * @return int - 0 - operation
362 int qed_mcp_handle_events(struct qed_hwfn
*p_hwfn
,
363 struct qed_ptt
*p_ptt
);
366 * @brief Sends a LOAD_REQ to the MFW, and in case operation
367 * succeed, returns whether this PF is the first on the
368 * chip/engine/port or function. This function should be
369 * called when driver is ready to accept MFW events after
370 * Storms initializations are done.
372 * @param p_hwfn - hw function
373 * @param p_ptt - PTT required for register access
374 * @param p_load_code - The MCP response param containing one
376 * FW_MSG_CODE_DRV_LOAD_ENGINE
377 * FW_MSG_CODE_DRV_LOAD_PORT
378 * FW_MSG_CODE_DRV_LOAD_FUNCTION
380 * 0 - Operation was successul.
381 * -EBUSY - Operation failed
383 int qed_mcp_load_req(struct qed_hwfn
*p_hwfn
,
384 struct qed_ptt
*p_ptt
,
388 * @brief Read the MFW mailbox into Current buffer.
393 void qed_mcp_read_mb(struct qed_hwfn
*p_hwfn
,
394 struct qed_ptt
*p_ptt
);
397 * @brief Ack to mfw that driver finished FLR process for VFs
401 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
403 * @param return int - 0 upon success.
405 int qed_mcp_ack_vf_flr(struct qed_hwfn
*p_hwfn
,
406 struct qed_ptt
*p_ptt
, u32
*vfs_to_ack
);
409 * @brief - calls during init to read shmem of all function-related info.
413 * @param return 0 upon success.
415 int qed_mcp_fill_shmem_func_info(struct qed_hwfn
*p_hwfn
,
416 struct qed_ptt
*p_ptt
);
419 * @brief - Reset the MCP using mailbox command.
424 * @param return 0 upon success.
426 int qed_mcp_reset(struct qed_hwfn
*p_hwfn
,
427 struct qed_ptt
*p_ptt
);
430 * @brief indicates whether the MFW objects [under mcp_info] are accessible
434 * @return true iff MFW is running and mcp_info is initialized
436 bool qed_mcp_is_init(struct qed_hwfn
*p_hwfn
);
439 * @brief request MFW to configure MSI-X for a VF
443 * @param vf_id - absolute inside engine
444 * @param num_sbs - number of entries to request
448 int qed_mcp_config_vf_msix(struct qed_hwfn
*p_hwfn
,
449 struct qed_ptt
*p_ptt
, u8 vf_id
, u8 num
);
451 int qed_configure_pf_min_bandwidth(struct qed_dev
*cdev
, u8 min_bw
);
452 int qed_configure_pf_max_bandwidth(struct qed_dev
*cdev
, u8 max_bw
);
453 int __qed_configure_pf_max_bandwidth(struct qed_hwfn
*p_hwfn
,
454 struct qed_ptt
*p_ptt
,
455 struct qed_mcp_link_state
*p_link
,
457 int __qed_configure_pf_min_bandwidth(struct qed_hwfn
*p_hwfn
,
458 struct qed_ptt
*p_ptt
,
459 struct qed_mcp_link_state
*p_link
,
462 int qed_hw_init_first_eth(struct qed_hwfn
*p_hwfn
,
463 struct qed_ptt
*p_ptt
, u8
*p_pf
);