1 /* 2 * Copyright (c) 2017-2018 Cavium, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 * 29 */ 30 31 32 #ifndef __ECORE_MCP_H__ 33 #define __ECORE_MCP_H__ 34 35 #include "bcm_osal.h" 36 #include "mcp_public.h" 37 #include "ecore.h" 38 #include "ecore_mcp_api.h" 39 #include "ecore_dev_api.h" 40 41 /* Using hwfn number (and not pf_num) is required since in CMT mode, 42 * same pf_num may be used by two different hwfn 43 * TODO - this shouldn't really be in .h file, but until all fields 44 * required during hw-init will be placed in their correct place in shmem 45 * we need it in ecore_dev.c [for readin the nvram reflection in shmem]. 46 */ 47 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \ 48 ((rel_pfid) | \ 49 ((p_hwfn)->abs_pf_id & 1) << 3) : \ 50 rel_pfid) 51 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id) 52 53 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \ 54 ((_p_hwfn)->p_dev->num_ports_in_engine * \ 55 ecore_device_num_engines((_p_hwfn)->p_dev))) 56 57 struct ecore_mcp_info { 58 /* List for mailbox commands which were sent and wait for a response */ 59 osal_list_t cmd_list; 60 61 /* Spinlock used for protecting the access to the mailbox commands list 62 * and the sending of the commands. 63 */ 64 osal_spinlock_t cmd_lock; 65 66 /* Flag to indicate whether sending a MFW mailbox command is blocked */ 67 bool b_block_cmd; 68 69 /* Spinlock used for syncing SW link-changes and link-changes 70 * originating from attention context. 71 */ 72 osal_spinlock_t link_lock; 73 74 /* Address of the MCP public area */ 75 u32 public_base; 76 /* Address of the driver mailbox */ 77 u32 drv_mb_addr; 78 /* Address of the MFW mailbox */ 79 u32 mfw_mb_addr; 80 /* Address of the port configuration (link) */ 81 u32 port_addr; 82 83 /* Current driver mailbox sequence */ 84 u16 drv_mb_seq; 85 /* Current driver pulse sequence */ 86 u16 drv_pulse_seq; 87 88 struct ecore_mcp_link_params link_input; 89 struct ecore_mcp_link_state link_output; 90 struct ecore_mcp_link_capabilities link_capabilities; 91 92 struct ecore_mcp_function_info func_info; 93 94 u8 *mfw_mb_cur; 95 u8 *mfw_mb_shadow; 96 u16 mfw_mb_length; 97 u32 mcp_hist; 98 99 /* Capabilties negotiated with the MFW */ 100 u32 capabilities; 101 }; 102 103 struct ecore_mcp_mb_params { 104 u32 cmd; 105 u32 param; 106 void *p_data_src; 107 u8 data_src_size; 108 void *p_data_dst; 109 u8 data_dst_size; 110 u32 mcp_resp; 111 u32 mcp_param; 112 }; 113 114 enum ecore_ov_eswitch { 115 ECORE_OV_ESWITCH_NONE, 116 ECORE_OV_ESWITCH_VEB, 117 ECORE_OV_ESWITCH_VEPA 118 }; 119 120 struct ecore_drv_tlv_hdr { 121 u8 tlv_type; /* According to the enum below */ 122 u8 tlv_length; /* In dwords - not including this header */ 123 u8 tlv_reserved; 124 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01 125 u8 tlv_flags; 126 }; 127 128 /** 129 * @brief Initialize the interface with the MCP 130 * 131 * @param p_hwfn - HW func 132 * @param p_ptt - PTT required for register access 133 * 134 * @return enum _ecore_status_t 135 */ 136 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn, 137 struct ecore_ptt *p_ptt); 138 139 /** 140 * @brief Intialize the port interface with the MCP 141 * 142 * @param p_hwfn 143 * @param p_ptt 144 * Can only be called after `num_ports_in_engine' is set 145 */ 146 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn, 147 struct ecore_ptt *p_ptt); 148 /** 149 * @brief Releases resources allocated during the init process. 150 * 151 * @param p_hwfn - HW func 152 * @param p_ptt - PTT required for register access 153 * 154 * @return enum _ecore_status_t 155 */ 156 157 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn); 158 159 /** 160 * @brief This function is called from the DPC context. After 161 * pointing PTT to the mfw mb, check for events sent by the MCP 162 * to the driver and ack them. In case a critical event 163 * detected, it will be handled here, otherwise the work will be 164 * queued to a sleepable work-queue. 165 * 166 * @param p_hwfn - HW function 167 * @param p_ptt - PTT required for register access 168 * @return enum _ecore_status_t - ECORE_SUCCESS - operation 169 * was successul. 170 */ 171 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn, 172 struct ecore_ptt *p_ptt); 173 174 /** 175 * @brief When MFW doesn't get driver pulse for couple of seconds, at some 176 * threshold before timeout expires, it will generate interrupt 177 * through a dedicated status block (DPSB - Driver Pulse Status 178 * Block), which the driver should respond immediately, by 179 * providing keepalive indication after setting the PTT to the 180 * driver-MFW mailbox. This function is called directly from the 181 * DPC upon receiving the DPSB attention. 182 * 183 * @param p_hwfn - hw function 184 * @param p_ptt - PTT required for register access 185 * @return enum _ecore_status_t - ECORE_SUCCESS - operation 186 * was successful. 187 */ 188 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn, 189 struct ecore_ptt *p_ptt); 190 191 enum ecore_drv_role { 192 ECORE_DRV_ROLE_OS, 193 ECORE_DRV_ROLE_KDUMP, 194 }; 195 196 struct ecore_load_req_params { 197 /* Input params */ 198 enum ecore_drv_role drv_role; 199 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */ 200 bool avoid_eng_reset; 201 enum ecore_override_force_load override_force_load; 202 203 /* Output params */ 204 u32 load_code; 205 }; 206 207 /** 208 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds, 209 * returns whether this PF is the first on the engine/port or function. 210 * 211 * @param p_hwfn 212 * @param p_ptt 213 * @param p_params 214 * 215 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful. 216 */ 217 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn, 218 struct ecore_ptt *p_ptt, 219 struct ecore_load_req_params *p_params); 220 221 /** 222 * @brief Sends a UNLOAD_REQ message to the MFW 223 * 224 * @param p_hwfn 225 * @param p_ptt 226 * 227 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful. 228 */ 229 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn, 230 struct ecore_ptt *p_ptt); 231 232 /** 233 * @brief Sends a UNLOAD_DONE message to the MFW 234 * 235 * @param p_hwfn 236 * @param p_ptt 237 * 238 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful. 239 */ 240 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn, 241 struct ecore_ptt *p_ptt); 242 243 /** 244 * @brief Read the MFW mailbox into Current buffer. 245 * 246 * @param p_hwfn 247 * @param p_ptt 248 */ 249 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn, 250 struct ecore_ptt *p_ptt); 251 252 /** 253 * @brief Ack to mfw that driver finished FLR process for VFs 254 * 255 * @param p_hwfn 256 * @param p_ptt 257 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks. 258 * 259 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success. 260 */ 261 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn, 262 struct ecore_ptt *p_ptt, 263 u32 *vfs_to_ack); 264 265 /** 266 * @brief - calls during init to read shmem of all function-related info. 267 * 268 * @param p_hwfn 269 * 270 * @param return ECORE_SUCCESS upon success. 271 */ 272 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn, 273 struct ecore_ptt *p_ptt); 274 275 /** 276 * @brief - Reset the MCP using mailbox command. 277 * 278 * @param p_hwfn 279 * @param p_ptt 280 * 281 * @param return ECORE_SUCCESS upon success. 282 */ 283 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn, 284 struct ecore_ptt *p_ptt); 285 286 /** 287 * @brief indicates whether the MFW objects [under mcp_info] are accessible 288 * 289 * @param p_hwfn 290 * 291 * @return true iff MFW is running and mcp_info is initialized 292 */ 293 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn); 294 295 /** 296 * @brief request MFW to configure MSI-X for a VF 297 * 298 * @param p_hwfn 299 * @param p_ptt 300 * @param vf_id - absolute inside engine 301 * @param num_sbs - number of entries to request 302 * 303 * @return enum _ecore_status_t 304 */ 305 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn, 306 struct ecore_ptt *p_ptt, 307 u8 vf_id, u8 num); 308 309 /** 310 * @brief - Halt the MCP. 311 * 312 * @param p_hwfn 313 * @param p_ptt 314 * 315 * @param return ECORE_SUCCESS upon success. 316 */ 317 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn, 318 struct ecore_ptt *p_ptt); 319 320 /** 321 * @brief - Wake up the MCP. 322 * 323 * @param p_hwfn 324 * @param p_ptt 325 * 326 * @param return ECORE_SUCCESS upon success. 327 */ 328 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn, 329 struct ecore_ptt *p_ptt); 330 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn, 331 struct ecore_ptt *p_ptt, 332 struct ecore_mcp_link_state *p_link, 333 u8 max_bw); 334 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn, 335 struct ecore_ptt *p_ptt, 336 struct ecore_mcp_link_state *p_link, 337 u8 min_bw); 338 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn, 339 struct ecore_ptt *p_ptt, 340 u32 mask_parities); 341 #if 0 342 enum _ecore_status_t ecore_hw_init_first_eth(struct ecore_hwfn *p_hwfn, 343 struct ecore_ptt *p_ptt, 344 u8 *p_pf); 345 #endif 346 347 /** 348 * @brief - Sends crash mdump related info to the MFW. 349 * 350 * @param p_hwfn 351 * @param p_ptt 352 * @param epoch 353 * 354 * @param return ECORE_SUCCESS upon success. 355 */ 356 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn, 357 struct ecore_ptt *p_ptt, 358 u32 epoch); 359 360 /** 361 * @brief - Triggers a MFW crash dump procedure. 362 * 363 * @param p_hwfn 364 * @param p_ptt 365 * 366 * @param return ECORE_SUCCESS upon success. 367 */ 368 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn, 369 struct ecore_ptt *p_ptt); 370 371 struct ecore_mdump_retain_data { 372 u32 valid; 373 u32 epoch; 374 u32 pf; 375 u32 status; 376 }; 377 378 /** 379 * @brief - Gets the mdump retained data from the MFW. 380 * 381 * @param p_hwfn 382 * @param p_ptt 383 * @param p_mdump_retain 384 * 385 * @param return ECORE_SUCCESS upon success. 386 */ 387 enum _ecore_status_t 388 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 389 struct ecore_mdump_retain_data *p_mdump_retain); 390 391 /** 392 * @brief - Sets the MFW's max value for the given resource 393 * 394 * @param p_hwfn 395 * @param p_ptt 396 * @param res_id 397 * @param resc_max_val 398 * @param p_mcp_resp 399 * 400 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 401 */ 402 enum _ecore_status_t 403 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 404 enum ecore_resources res_id, u32 resc_max_val, 405 u32 *p_mcp_resp); 406 407 /** 408 * @brief - Gets the MFW allocation info for the given resource 409 * 410 * @param p_hwfn 411 * @param p_ptt 412 * @param res_id 413 * @param p_mcp_resp 414 * @param p_resc_num 415 * @param p_resc_start 416 * 417 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 418 */ 419 enum _ecore_status_t 420 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 421 enum ecore_resources res_id, u32 *p_mcp_resp, 422 u32 *p_resc_num, u32 *p_resc_start); 423 424 /** 425 * @brief - Initiates PF FLR 426 * 427 * @param p_hwfn 428 * @param p_ptt 429 * 430 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 431 */ 432 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn, 433 struct ecore_ptt *p_ptt); 434 435 /** 436 * @brief Send eswitch mode to MFW 437 * 438 * @param p_hwfn 439 * @param p_ptt 440 * @param eswitch - eswitch mode 441 * 442 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 443 */ 444 enum _ecore_status_t 445 ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 446 enum ecore_ov_eswitch eswitch); 447 448 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */ 449 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31 450 451 enum ecore_resc_lock { 452 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL, 453 /* Locks that the MFW is aware of should be added here downwards */ 454 455 /* Ecore only locks should be added here upwards */ 456 ECORE_RESC_LOCK_PTP_PORT0, 457 ECORE_RESC_LOCK_PTP_PORT1, 458 ECORE_RESC_LOCK_PTP_PORT2, 459 ECORE_RESC_LOCK_PTP_PORT3, 460 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL, 461 462 /* A dummy value to be used for auxillary functions in need of 463 * returning an 'error' value. 464 */ 465 ECORE_RESC_LOCK_RESC_INVALID, 466 }; 467 468 struct ecore_resc_lock_params { 469 /* Resource number [valid values are 0..31] */ 470 u8 resource; 471 472 /* Lock timeout value in seconds [default, none or 1..254] */ 473 u8 timeout; 474 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0 475 #define ECORE_MCP_RESC_LOCK_TO_NONE 255 476 477 /* Number of times to retry locking */ 478 u8 retry_num; 479 #define ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT 10 480 481 /* The interval in usec between retries */ 482 u16 retry_interval; 483 #define ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000 484 485 /* Use sleep or delay between retries */ 486 bool sleep_b4_retry; 487 488 /* Will be set as true if the resource is free and granted */ 489 bool b_granted; 490 491 /* Will be filled with the resource owner. 492 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial] 493 */ 494 u8 owner; 495 }; 496 497 /** 498 * @brief Acquires MFW generic resource lock 499 * 500 * @param p_hwfn 501 * @param p_ptt 502 * @param p_params 503 * 504 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 505 */ 506 enum _ecore_status_t 507 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 508 struct ecore_resc_lock_params *p_params); 509 510 struct ecore_resc_unlock_params { 511 /* Resource number [valid values are 0..31] */ 512 u8 resource; 513 514 /* Allow to release a resource even if belongs to another PF */ 515 bool b_force; 516 517 /* Will be set as true if the resource is released */ 518 bool b_released; 519 }; 520 521 /** 522 * @brief Releases MFW generic resource lock 523 * 524 * @param p_hwfn 525 * @param p_ptt 526 * @param p_params 527 * 528 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful. 529 */ 530 enum _ecore_status_t 531 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 532 struct ecore_resc_unlock_params *p_params); 533 534 /** 535 * @brief - default initialization for lock/unlock resource structs 536 * 537 * @param p_lock - lock params struct to be initialized; Can be OSAL_NULL 538 * @param p_unlock - unlock params struct to be initialized; Can be OSAL_NULL 539 * @param resource - the requested resource 540 * @paral b_is_permanent - disable retries & aging when set 541 */ 542 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock, 543 struct ecore_resc_unlock_params *p_unlock, 544 enum ecore_resc_lock resource, 545 bool b_is_permanent); 546 547 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, 548 u32 offset, u32 val); 549 550 /** 551 * @brief Learn of supported MFW features; To be done during early init 552 * 553 * @param p_hwfn 554 * @param p_ptt 555 */ 556 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn, 557 struct ecore_ptt *p_ptt); 558 559 /** 560 * @brief Inform MFW of set of features supported by driver. Should be done 561 * inside the contet of the LOAD_REQ. 562 * 563 * @param p_hwfn 564 * @param p_ptt 565 */ 566 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn, 567 struct ecore_ptt *p_ptt); 568 569 /** 570 * @brief Initialize MFW mailbox and sequence values for driver interaction. 571 * 572 * @param p_hwfn 573 * @param p_ptt 574 */ 575 enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn, 576 struct ecore_ptt *p_ptt); 577 578 #endif /* __ECORE_MCP_H__ */ 579