1 /* 2 * Copyright (c) 2016 QLogic Corporation. 3 * All rights reserved. 4 * www.qlogic.com 5 * 6 * See LICENSE.qede_pmd for copyright and licensing details. 7 */ 8 9 #ifndef __ECORE_MCP_H__ 10 #define __ECORE_MCP_H__ 11 12 #include "bcm_osal.h" 13 #include "mcp_public.h" 14 #include "ecore.h" 15 #include "ecore_mcp_api.h" 16 17 /* Using hwfn number (and not pf_num) is required since in CMT mode, 18 * same pf_num may be used by two different hwfn 19 * TODO - this shouldn't really be in .h file, but until all fields 20 * required during hw-init will be placed in their correct place in shmem 21 * we need it in ecore_dev.c [for readin the nvram reflection in shmem]. 22 */ 23 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \ 24 ((rel_pfid) | \ 25 ((p_hwfn)->abs_pf_id & 1) << 3) : \ 26 rel_pfid) 27 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id) 28 29 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \ 30 ((_p_hwfn)->p_dev->num_ports_in_engines * \ 31 ecore_device_num_engines((_p_hwfn)->p_dev))) 32 33 struct ecore_mcp_info { 34 /* Spinlock used for protecting the access to the MFW mailbox */ 35 osal_spinlock_t lock; 36 /* Flag to indicate whether sending a MFW mailbox is forbidden */ 37 bool block_mb_sending; 38 39 /* Address of the MCP public area */ 40 u32 public_base; 41 /* Address of the driver mailbox */ 42 u32 drv_mb_addr; 43 /* Address of the MFW mailbox */ 44 u32 mfw_mb_addr; 45 /* Address of the port configuration (link) */ 46 u32 port_addr; 47 48 /* Current driver mailbox sequence */ 49 u16 drv_mb_seq; 50 /* Current driver pulse sequence */ 51 u16 drv_pulse_seq; 52 53 struct ecore_mcp_link_params link_input; 54 struct ecore_mcp_link_state link_output; 55 struct ecore_mcp_link_capabilities link_capabilities; 56 57 struct ecore_mcp_function_info func_info; 58 59 u8 *mfw_mb_cur; 60 u8 *mfw_mb_shadow; 61 u16 mfw_mb_length; 62 u16 mcp_hist; 63 64 /* Capabilties negotiated with the MFW */ 65 u32 capabilities; 66 }; 67 68 struct ecore_mcp_mb_params { 69 u32 cmd; 70 u32 param; 71 void *p_data_src; 72 u8 data_src_size; 73 void *p_data_dst; 74 u8 data_dst_size; 75 u32 mcp_resp; 76 u32 mcp_param; 77 }; 78 79 struct ecore_drv_tlv_hdr { 80 u8 tlv_type; /* According to the enum below */ 81 u8 tlv_length; /* In dwords - not including this header */ 82 u8 tlv_reserved; 83 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01 84 u8 tlv_flags; 85 }; 86 87 /** 88 * @brief Initialize the interface with the MCP 89 * 90 * @param p_hwfn - HW func 91 * @param p_ptt - PTT required for register access 92 * 93 * @return enum _ecore_status_t 94 */ 95 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn, 96 struct ecore_ptt *p_ptt); 97 98 /** 99 * @brief Initialize the port interface with the MCP 100 * 101 * @param p_hwfn 102 * @param p_ptt 103 * Can only be called after `num_ports_in_engines' is set 104 */ 105 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn, 106 struct ecore_ptt *p_ptt); 107 /** 108 * @brief Releases resources allocated during the init process. 109 * 110 * @param p_hwfn - HW func 111 * @param p_ptt - PTT required for register access 112 * 113 * @return enum _ecore_status_t 114 */ 115 116 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn); 117 118 /** 119 * @brief This function is called from the DPC context. After 120 * pointing PTT to the mfw mb, check for events sent by the MCP 121 * to the driver and ack them. In case a critical event 122 * detected, it will be handled here, otherwise the work will be 123 * queued to a sleepable work-queue. 124 * 125 * @param p_hwfn - HW function 126 * @param p_ptt - PTT required for register access 127 * @return enum _ecore_status_t - ECORE_SUCCESS - operation 128 * was successul. 129 */ 130 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn, 131 struct ecore_ptt *p_ptt); 132 133 /** 134 * @brief When MFW doesn't get driver pulse for couple of seconds, at some 135 * threshold before timeout expires, it will generate interrupt 136 * through a dedicated status block (DPSB - Driver Pulse Status 137 * Block), which the driver should respond immediately, by 138 * providing keepalive indication after setting the PTT to the 139 * driver-MFW mailbox. This function is called directly from the 140 * DPC upon receiving the DPSB attention. 141 * 142 * @param p_hwfn - hw function 143 * @param p_ptt - PTT required for register access 144 * @return enum _ecore_status_t - ECORE_SUCCESS - operation 145 * was successful. 146 */ 147 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn, 148 struct ecore_ptt *p_ptt); 149 150 enum ecore_drv_role { 151 ECORE_DRV_ROLE_OS, 152 ECORE_DRV_ROLE_KDUMP, 153 }; 154 155 struct ecore_load_req_params { 156 enum ecore_drv_role drv_role; 157 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */ 158 bool avoid_eng_reset; 159 u32 load_code; 160 }; 161 162 /** 163 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds, 164 * returns whether this PF is the first on the engine/port or function. 165 * 166 * @param p_hwfn 167 * @param p_ptt 168 * @param p_params 169 * 170 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful. 171 */ 172 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn, 173 struct ecore_ptt *p_ptt, 174 struct ecore_load_req_params *p_params); 175 176 /** 177 * @brief Sends a LOAD_DONE message to the MFW 178 * 179 * @param p_hwfn 180 * @param p_ptt 181 * 182 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful. 183 */ 184 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn, 185 struct ecore_ptt *p_ptt); 186 187 /** 188 * @brief Sends a UNLOAD_REQ message to the MFW 189 * 190 * @param p_hwfn 191 * @param p_ptt 192 * 193 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful. 194 */ 195 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn, 196 struct ecore_ptt *p_ptt); 197 198 /** 199 * @brief Sends a UNLOAD_DONE message to the MFW 200 * 201 * @param p_hwfn 202 * @param p_ptt 203 * 204 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful. 205 */ 206 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn, 207 struct ecore_ptt *p_ptt); 208 209 /** 210 * @brief Read the MFW mailbox into Current buffer. 211 * 212 * @param p_hwfn 213 * @param p_ptt 214 */ 215 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn, 216 struct ecore_ptt *p_ptt); 217 218 /** 219 * @brief Ack to mfw that driver finished FLR process for VFs 220 * 221 * @param p_hwfn 222 * @param p_ptt 223 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks. 224 * 225 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success. 226 */ 227 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn, 228 struct ecore_ptt *p_ptt, 229 u32 *vfs_to_ack); 230 231 /** 232 * @brief - calls during init to read shmem of all function-related info. 233 * 234 * @param p_hwfn 235 * 236 * @param return ECORE_SUCCESS upon success. 237 */ 238 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn, 239 struct ecore_ptt *p_ptt); 240 241 /** 242 * @brief - Reset the MCP using mailbox command. 243 * 244 * @param p_hwfn 245 * @param p_ptt 246 * 247 * @param return ECORE_SUCCESS upon success. 248 */ 249 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn, 250 struct ecore_ptt *p_ptt); 251 252 /** 253 * @brief - Sends an NVM write command request to the MFW with 254 * payload. 255 * 256 * @param p_hwfn 257 * @param p_ptt 258 * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or 259 * DRV_MSG_CODE_NVM_PUT_FILE_DATA 260 * @param param - [0:23] - Offset [24:31] - Size 261 * @param o_mcp_resp - MCP response 262 * @param o_mcp_param - MCP response param 263 * @param i_txn_size - Buffer size 264 * @param i_buf - Pointer to the buffer 265 * 266 * @param return ECORE_SUCCESS upon success. 267 */ 268 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn, 269 struct ecore_ptt *p_ptt, 270 u32 cmd, 271 u32 param, 272 u32 *o_mcp_resp, 273 u32 *o_mcp_param, 274 u32 i_txn_size, 275 u32 *i_buf); 276 277 /** 278 * @brief - Sends an NVM read command request to the MFW to get 279 * a buffer. 280 * 281 * @param p_hwfn 282 * @param p_ptt 283 * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or 284 * DRV_MSG_CODE_NVM_READ_NVRAM commands 285 * @param param - [0:23] - Offset [24:31] - Size 286 * @param o_mcp_resp - MCP response 287 * @param o_mcp_param - MCP response param 288 * @param o_txn_size - Buffer size output 289 * @param o_buf - Pointer to the buffer returned by the MFW. 290 * 291 * @param return ECORE_SUCCESS upon success. 292 */ 293 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn, 294 struct ecore_ptt *p_ptt, 295 u32 cmd, 296 u32 param, 297 u32 *o_mcp_resp, 298 u32 *o_mcp_param, 299 u32 *o_txn_size, 300 u32 *o_buf); 301 302 /** 303 * @brief indicates whether the MFW objects [under mcp_info] are accessible 304 * 305 * @param p_hwfn 306 * 307 * @return true iff MFW is running and mcp_info is initialized 308 */ 309 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn); 310 311 /** 312 * @brief request MFW to configure MSI-X for a VF 313 * 314 * @param p_hwfn 315 * @param p_ptt 316 * @param vf_id - absolute inside engine 317 * @param num_sbs - number of entries to request 318 * 319 * @return enum _ecore_status_t 320 */ 321 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn, 322 struct ecore_ptt *p_ptt, 323 u8 vf_id, u8 num); 324 325 /** 326 * @brief - Halt the MCP. 327 * 328 * @param p_hwfn 329 * @param p_ptt 330 * 331 * @param return ECORE_SUCCESS upon success. 332 */ 333 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn, 334 struct ecore_ptt *p_ptt); 335 336 /** 337 * @brief - Wake up the MCP. 338 * 339 * @param p_hwfn 340 * @param p_ptt 341 * 342 * @param return ECORE_SUCCESS upon success. 343 */ 344 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn, 345 struct ecore_ptt *p_ptt); 346 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn, 347 struct ecore_ptt *p_ptt, 348 struct ecore_mcp_link_state *p_link, 349 u8 max_bw); 350 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn, 351 struct ecore_ptt *p_ptt, 352 struct ecore_mcp_link_state *p_link, 353 u8 min_bw); 354 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn, 355 struct ecore_ptt *p_ptt, 356 u32 mask_parities); 357 /** 358 * @brief - Sends crash mdump related info to the MFW. 359 * 360 * @param p_hwfn 361 * @param p_ptt 362 * 363 * @param return ECORE_SUCCESS upon success. 364 */ 365 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn, 366 struct ecore_ptt *p_ptt, 367 u32 epoch); 368 369 /** 370 * @brief - Triggers a MFW crash dump procedure. 371 * 372 * @param p_hwfn 373 * @param p_ptt 374 * 375 * @param return ECORE_SUCCESS upon success. 376 */ 377 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn, 378 struct ecore_ptt *p_ptt); 379 380 /** 381 * @brief - Sets the MFW's max value for the given resource 382 * 383 * @param p_hwfn 384 * @param p_ptt 385 * @param res_id 386 * @param resc_max_val 387 * @param p_mcp_resp 388 * 389 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 390 */ 391 enum _ecore_status_t 392 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 393 enum ecore_resources res_id, u32 resc_max_val, 394 u32 *p_mcp_resp); 395 396 /** 397 * @brief - Gets the MFW allocation info for the given resource 398 * 399 * @param p_hwfn 400 * @param p_ptt 401 * @param res_id 402 * @param p_mcp_resp 403 * @param p_resc_num 404 * @param p_resc_start 405 * 406 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 407 */ 408 enum _ecore_status_t 409 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 410 enum ecore_resources res_id, u32 *p_mcp_resp, 411 u32 *p_resc_num, u32 *p_resc_start); 412 413 /** 414 * @brief - Initiates PF FLR 415 * 416 * @param p_hwfn 417 * @param p_ptt 418 * 419 * @param return ECORE_SUCCESS upon success. 420 */ 421 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn, 422 struct ecore_ptt *p_ptt); 423 424 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */ 425 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31 426 427 enum ecore_resc_lock { 428 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL, 429 /* Locks that the MFW is aware of should be added here downwards */ 430 431 /* Ecore only locks should be added here upwards */ 432 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL 433 }; 434 435 struct ecore_resc_lock_params { 436 /* Resource number [valid values are 0..31] */ 437 u8 resource; 438 439 /* Lock timeout value in seconds [default, none or 1..254] */ 440 u8 timeout; 441 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0 442 #define ECORE_MCP_RESC_LOCK_TO_NONE 255 443 444 /* Number of times to retry locking */ 445 u8 retry_num; 446 447 /* The interval in usec between retries */ 448 u16 retry_interval; 449 450 /* Use sleep or delay between retries */ 451 bool sleep_b4_retry; 452 453 /* Will be set as true if the resource is free and granted */ 454 bool b_granted; 455 456 /* Will be filled with the resource owner. 457 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial] 458 */ 459 u8 owner; 460 }; 461 462 /** 463 * @brief Acquires MFW generic resource lock 464 * 465 * @param p_hwfn 466 * @param p_ptt 467 * @param p_params 468 * 469 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 470 */ 471 enum _ecore_status_t 472 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 473 struct ecore_resc_lock_params *p_params); 474 475 struct ecore_resc_unlock_params { 476 /* Resource number [valid values are 0..31] */ 477 u8 resource; 478 479 /* Allow to release a resource even if belongs to another PF */ 480 bool b_force; 481 482 /* Will be set as true if the resource is released */ 483 bool b_released; 484 }; 485 486 /** 487 * @brief Releases MFW generic resource lock 488 * 489 * @param p_hwfn 490 * @param p_ptt 491 * @param p_params 492 * 493 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 494 */ 495 enum _ecore_status_t 496 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 497 struct ecore_resc_unlock_params *p_params); 498 499 /** 500 * @brief Learn of supported MFW features; To be done during early init 501 * 502 * @param p_hwfn 503 * @param p_ptt 504 */ 505 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn, 506 struct ecore_ptt *p_ptt); 507 508 /** 509 * @brief Inform MFW of set of features supported by driver. Should be done 510 * inside the contet of the LOAD_REQ. 511 * 512 * @param p_hwfn 513 * @param p_ptt 514 */ 515 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn, 516 struct ecore_ptt *p_ptt); 517 518 #endif /* __ECORE_MCP_H__ */ 519