Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 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 | /** |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame^] | 93 | * @brief Get the flash size value |
| 94 | * |
| 95 | * @param p_hwfn |
| 96 | * @param p_ptt |
| 97 | * @param p_flash_size - flash size in bytes to be filled. |
| 98 | * |
| 99 | * @return int - 0 - operation was successul. |
| 100 | */ |
| 101 | int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn, |
| 102 | struct qed_ptt *p_ptt, |
| 103 | u32 *p_flash_size); |
| 104 | |
| 105 | /** |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 106 | * @brief Send driver version to MFW |
| 107 | * |
| 108 | * @param p_hwfn |
| 109 | * @param p_ptt |
| 110 | * @param version - Version value |
| 111 | * @param name - Protocol driver name |
| 112 | * |
| 113 | * @return int - 0 - operation was successul. |
| 114 | */ |
| 115 | int |
| 116 | qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn, |
| 117 | struct qed_ptt *p_ptt, |
| 118 | struct qed_mcp_drv_version *p_ver); |
| 119 | |
| 120 | /* Using hwfn number (and not pf_num) is required since in CMT mode, |
| 121 | * same pf_num may be used by two different hwfn |
| 122 | * TODO - this shouldn't really be in .h file, but until all fields |
| 123 | * required during hw-init will be placed in their correct place in shmem |
| 124 | * we need it in qed_dev.c [for readin the nvram reflection in shmem]. |
| 125 | */ |
| 126 | #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \ |
| 127 | ((rel_pfid) | \ |
| 128 | ((p_hwfn)->abs_pf_id & 1) << 3) : \ |
| 129 | rel_pfid) |
| 130 | #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id) |
| 131 | |
| 132 | /* TODO - this is only correct as long as only BB is supported, and |
| 133 | * no port-swapping is implemented; Afterwards we'll need to fix it. |
| 134 | */ |
| 135 | #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \ |
| 136 | ((_p_hwfn)->cdev->num_ports_in_engines * 2)) |
| 137 | struct qed_mcp_info { |
| 138 | struct mutex mutex; /* MCP access lock */ |
| 139 | u32 public_base; |
| 140 | u32 drv_mb_addr; |
| 141 | u32 mfw_mb_addr; |
| 142 | u32 port_addr; |
| 143 | u16 drv_mb_seq; |
| 144 | u16 drv_pulse_seq; |
| 145 | struct qed_mcp_function_info func_info; |
| 146 | |
| 147 | u8 *mfw_mb_cur; |
| 148 | u8 *mfw_mb_shadow; |
| 149 | u16 mfw_mb_length; |
| 150 | u16 mcp_hist; |
| 151 | }; |
| 152 | |
| 153 | /** |
| 154 | * @brief Initialize the interface with the MCP |
| 155 | * |
| 156 | * @param p_hwfn - HW func |
| 157 | * @param p_ptt - PTT required for register access |
| 158 | * |
| 159 | * @return int |
| 160 | */ |
| 161 | int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn, |
| 162 | struct qed_ptt *p_ptt); |
| 163 | |
| 164 | /** |
| 165 | * @brief Initialize the port interface with the MCP |
| 166 | * |
| 167 | * @param p_hwfn |
| 168 | * @param p_ptt |
| 169 | * Can only be called after `num_ports_in_engines' is set |
| 170 | */ |
| 171 | void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn, |
| 172 | struct qed_ptt *p_ptt); |
| 173 | /** |
| 174 | * @brief Releases resources allocated during the init process. |
| 175 | * |
| 176 | * @param p_hwfn - HW func |
| 177 | * @param p_ptt - PTT required for register access |
| 178 | * |
| 179 | * @return int |
| 180 | */ |
| 181 | |
| 182 | int qed_mcp_free(struct qed_hwfn *p_hwfn); |
| 183 | |
| 184 | /** |
| 185 | * @brief Sends a LOAD_REQ to the MFW, and in case operation |
| 186 | * succeed, returns whether this PF is the first on the |
| 187 | * chip/engine/port or function. This function should be |
| 188 | * called when driver is ready to accept MFW events after |
| 189 | * Storms initializations are done. |
| 190 | * |
| 191 | * @param p_hwfn - hw function |
| 192 | * @param p_ptt - PTT required for register access |
| 193 | * @param p_load_code - The MCP response param containing one |
| 194 | * of the following: |
| 195 | * FW_MSG_CODE_DRV_LOAD_ENGINE |
| 196 | * FW_MSG_CODE_DRV_LOAD_PORT |
| 197 | * FW_MSG_CODE_DRV_LOAD_FUNCTION |
| 198 | * @return int - |
| 199 | * 0 - Operation was successul. |
| 200 | * -EBUSY - Operation failed |
| 201 | */ |
| 202 | int qed_mcp_load_req(struct qed_hwfn *p_hwfn, |
| 203 | struct qed_ptt *p_ptt, |
| 204 | u32 *p_load_code); |
| 205 | |
| 206 | /** |
| 207 | * @brief Read the MFW mailbox into Current buffer. |
| 208 | * |
| 209 | * @param p_hwfn |
| 210 | * @param p_ptt |
| 211 | */ |
| 212 | void qed_mcp_read_mb(struct qed_hwfn *p_hwfn, |
| 213 | struct qed_ptt *p_ptt); |
| 214 | |
| 215 | /** |
| 216 | * @brief - calls during init to read shmem of all function-related info. |
| 217 | * |
| 218 | * @param p_hwfn |
| 219 | * |
| 220 | * @param return 0 upon success. |
| 221 | */ |
| 222 | int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn, |
| 223 | struct qed_ptt *p_ptt); |
| 224 | |
| 225 | /** |
| 226 | * @brief - Reset the MCP using mailbox command. |
| 227 | * |
| 228 | * @param p_hwfn |
| 229 | * @param p_ptt |
| 230 | * |
| 231 | * @param return 0 upon success. |
| 232 | */ |
| 233 | int qed_mcp_reset(struct qed_hwfn *p_hwfn, |
| 234 | struct qed_ptt *p_ptt); |
| 235 | |
| 236 | /** |
| 237 | * @brief indicates whether the MFW objects [under mcp_info] are accessible |
| 238 | * |
| 239 | * @param p_hwfn |
| 240 | * |
| 241 | * @return true iff MFW is running and mcp_info is initialized |
| 242 | */ |
| 243 | bool qed_mcp_is_init(struct qed_hwfn *p_hwfn); |
| 244 | |
| 245 | #endif |