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;
38 bool default_speed_autoneg;
41 struct qed_mcp_link_state {
46 /* Actual link speed in Mb/s */
49 /* PF max speed in Mb/s, deduced from line_speed
50 * according to PF max bandwidth configuration.
57 bool parallel_detection;
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;
70 bool partner_tx_flow_ctrl_en;
71 bool partner_rx_flow_ctrl_en;
73 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
74 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
75 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
81 struct qed_mcp_function_info {
84 enum qed_pci_personality protocol;
94 #define QED_MCP_VLAN_UNSET (0xffff)
98 struct qed_mcp_nvm_common {
105 struct qed_mcp_drv_version {
107 u8 name[MCP_DRV_VER_STR_SIZE - 4];
110 struct qed_mcp_lan_stats {
116 struct qed_mcp_fcoe_stats {
123 struct qed_mcp_iscsi_stats {
130 struct qed_mcp_rdma_stats {
137 enum qed_mcp_protocol_type {
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;
152 * @brief - returns the link params of the hw function
156 * @returns pointer to link params
158 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
161 * @brief - return the link state of the hw function
165 * @returns pointer to link state
167 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
170 * @brief - return the link capabilities of the hw function
174 * @returns pointer to link capabilities
176 struct qed_mcp_link_capabilities
177 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
180 * @brief Request the MFW to set the the link according to 'link_input'.
184 * @param b_up - raise link if `true'. Reset link if `false'.
188 int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
189 struct qed_ptt *p_ptt,
193 * @brief Get the management firmware version value
197 * @param p_mfw_ver - mfw version value
198 * @param p_running_bundle_id - image id in nvram; Optional.
200 * @return int - 0 - operation was successful.
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);
207 * @brief Get media type value of the port.
209 * @param cdev - qed dev pointer
210 * @param mfw_ver - media type value
213 * 0 - Operation was successul.
214 * -EBUSY - Operation failed
216 int qed_mcp_get_media_type(struct qed_dev *cdev,
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.
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
233 * @return int - 0 - operation
236 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
237 struct qed_ptt *p_ptt,
244 * @brief - drains the nig, allowing completion to pass in case of pauses.
245 * (Should be called only from sleepable context)
250 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
251 struct qed_ptt *p_ptt);
254 * @brief Get the flash size value
258 * @param p_flash_size - flash size in bytes to be filled.
260 * @return int - 0 - operation was successul.
262 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
263 struct qed_ptt *p_ptt,
267 * @brief Send driver version to MFW
271 * @param version - Version value
272 * @param name - Protocol driver name
274 * @return int - 0 - operation was successul.
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);
282 * @brief Set LED status
286 * @param mode - LED mode
288 * @return int - 0 - operation was successful.
290 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
291 struct qed_ptt *p_ptt,
292 enum qed_led_mode mode);
295 * @brief Bist register test
297 * @param p_hwfn - hw function
298 * @param p_ptt - PTT required for register access
300 * @return int - 0 - operation was successful.
302 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
303 struct qed_ptt *p_ptt);
306 * @brief Bist clock test
308 * @param p_hwfn - hw function
309 * @param p_ptt - PTT required for register access
311 * @return int - 0 - operation was successful.
313 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
314 struct qed_ptt *p_ptt);
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].
322 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
324 ((p_hwfn)->abs_pf_id & 1) << 3) : \
326 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
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.
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 {
335 bool block_mb_sending;
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;
352 struct qed_mcp_mb_params {
355 union drv_union_data *p_data_src;
356 union drv_union_data *p_data_dst;
362 * @brief Initialize the interface with the MCP
364 * @param p_hwfn - HW func
365 * @param p_ptt - PTT required for register access
369 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
370 struct qed_ptt *p_ptt);
373 * @brief Initialize the port interface with the MCP
377 * Can only be called after `num_ports_in_engines' is set
379 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
380 struct qed_ptt *p_ptt);
382 * @brief Releases resources allocated during the init process.
384 * @param p_hwfn - HW func
385 * @param p_ptt - PTT required for register access
390 int qed_mcp_free(struct qed_hwfn *p_hwfn);
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.
399 * @param p_hwfn - HW function
400 * @param p_ptt - PTT required for register access
401 * @return int - 0 - operation
404 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
405 struct qed_ptt *p_ptt);
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.
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
418 * FW_MSG_CODE_DRV_LOAD_ENGINE
419 * FW_MSG_CODE_DRV_LOAD_PORT
420 * FW_MSG_CODE_DRV_LOAD_FUNCTION
422 * 0 - Operation was successul.
423 * -EBUSY - Operation failed
425 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
426 struct qed_ptt *p_ptt,
430 * @brief Read the MFW mailbox into Current buffer.
435 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
436 struct qed_ptt *p_ptt);
439 * @brief Ack to mfw that driver finished FLR process for VFs
443 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
445 * @param return int - 0 upon success.
447 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
448 struct qed_ptt *p_ptt, u32 *vfs_to_ack);
451 * @brief - calls during init to read shmem of all function-related info.
455 * @param return 0 upon success.
457 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
458 struct qed_ptt *p_ptt);
461 * @brief - Reset the MCP using mailbox command.
466 * @param return 0 upon success.
468 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
469 struct qed_ptt *p_ptt);
472 * @brief - Sends an NVM read command request to the MFW to get
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.
485 * @param return 0 upon success.
487 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
488 struct qed_ptt *p_ptt,
492 u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
495 * @brief indicates whether the MFW objects [under mcp_info] are accessible
499 * @return true iff MFW is running and mcp_info is initialized
501 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
504 * @brief request MFW to configure MSI-X for a VF
508 * @param vf_id - absolute inside engine
509 * @param num_sbs - number of entries to request
513 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
514 struct qed_ptt *p_ptt, u8 vf_id, u8 num);
517 * @brief - Halt the MCP.
522 * @param return 0 upon success.
524 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
527 * @brief - Wake up the MCP.
532 * @param return 0 upon success.
534 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
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,
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,
547 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
548 struct qed_ptt *p_ptt, u32 mask_parities);