18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ 28c2ecf20Sopenharmony_ci/* QLogic qed NIC Driver 38c2ecf20Sopenharmony_ci * Copyright (c) 2015-2017 QLogic Corporation 48c2ecf20Sopenharmony_ci * Copyright (c) 2019-2020 Marvell International Ltd. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef _QED_HW_H 88c2ecf20Sopenharmony_ci#define _QED_HW_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/types.h> 118c2ecf20Sopenharmony_ci#include <linux/bitops.h> 128c2ecf20Sopenharmony_ci#include <linux/slab.h> 138c2ecf20Sopenharmony_ci#include <linux/string.h> 148c2ecf20Sopenharmony_ci#include "qed.h" 158c2ecf20Sopenharmony_ci#include "qed_dev_api.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* Forward decleration */ 188c2ecf20Sopenharmony_cistruct qed_ptt; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cienum reserved_ptts { 218c2ecf20Sopenharmony_ci RESERVED_PTT_EDIAG, 228c2ecf20Sopenharmony_ci RESERVED_PTT_USER_SPACE, 238c2ecf20Sopenharmony_ci RESERVED_PTT_MAIN, 248c2ecf20Sopenharmony_ci RESERVED_PTT_DPC, 258c2ecf20Sopenharmony_ci RESERVED_PTT_MAX 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cienum _dmae_cmd_dst_mask { 298c2ecf20Sopenharmony_ci DMAE_CMD_DST_MASK_NONE = 0, 308c2ecf20Sopenharmony_ci DMAE_CMD_DST_MASK_PCIE = 1, 318c2ecf20Sopenharmony_ci DMAE_CMD_DST_MASK_GRC = 2 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cienum _dmae_cmd_src_mask { 358c2ecf20Sopenharmony_ci DMAE_CMD_SRC_MASK_PCIE = 0, 368c2ecf20Sopenharmony_ci DMAE_CMD_SRC_MASK_GRC = 1 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cienum _dmae_cmd_crc_mask { 408c2ecf20Sopenharmony_ci DMAE_CMD_COMP_CRC_EN_MASK_NONE = 0, 418c2ecf20Sopenharmony_ci DMAE_CMD_COMP_CRC_EN_MASK_SET = 1 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* definitions for DMA constants */ 458c2ecf20Sopenharmony_ci#define DMAE_GO_VALUE 0x1 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define DMAE_COMPLETION_VAL 0xD1AE 488c2ecf20Sopenharmony_ci#define DMAE_CMD_ENDIANITY 0x2 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define DMAE_CMD_SIZE 14 518c2ecf20Sopenharmony_ci#define DMAE_CMD_SIZE_TO_FILL (DMAE_CMD_SIZE - 5) 528c2ecf20Sopenharmony_ci#define DMAE_MIN_WAIT_TIME 0x2 538c2ecf20Sopenharmony_ci#define DMAE_MAX_CLIENTS 32 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/** 568c2ecf20Sopenharmony_ci * @brief qed_gtt_init - Initialize GTT windows 578c2ecf20Sopenharmony_ci * 588c2ecf20Sopenharmony_ci * @param p_hwfn 598c2ecf20Sopenharmony_ci */ 608c2ecf20Sopenharmony_civoid qed_gtt_init(struct qed_hwfn *p_hwfn); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/** 638c2ecf20Sopenharmony_ci * @brief qed_ptt_invalidate - Forces all ptt entries to be re-configured 648c2ecf20Sopenharmony_ci * 658c2ecf20Sopenharmony_ci * @param p_hwfn 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_civoid qed_ptt_invalidate(struct qed_hwfn *p_hwfn); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/** 708c2ecf20Sopenharmony_ci * @brief qed_ptt_pool_alloc - Allocate and initialize PTT pool 718c2ecf20Sopenharmony_ci * 728c2ecf20Sopenharmony_ci * @param p_hwfn 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * @return struct _qed_status - success (0), negative - error. 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_ciint qed_ptt_pool_alloc(struct qed_hwfn *p_hwfn); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/** 798c2ecf20Sopenharmony_ci * @brief qed_ptt_pool_free - 808c2ecf20Sopenharmony_ci * 818c2ecf20Sopenharmony_ci * @param p_hwfn 828c2ecf20Sopenharmony_ci */ 838c2ecf20Sopenharmony_civoid qed_ptt_pool_free(struct qed_hwfn *p_hwfn); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/** 868c2ecf20Sopenharmony_ci * @brief qed_ptt_get_hw_addr - Get PTT's GRC/HW address 878c2ecf20Sopenharmony_ci * 888c2ecf20Sopenharmony_ci * @param p_hwfn 898c2ecf20Sopenharmony_ci * @param p_ptt 908c2ecf20Sopenharmony_ci * 918c2ecf20Sopenharmony_ci * @return u32 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_ciu32 qed_ptt_get_hw_addr(struct qed_hwfn *p_hwfn, 948c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/** 978c2ecf20Sopenharmony_ci * @brief qed_ptt_get_bar_addr - Get PPT's external BAR address 988c2ecf20Sopenharmony_ci * 998c2ecf20Sopenharmony_ci * @param p_hwfn 1008c2ecf20Sopenharmony_ci * @param p_ptt 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * @return u32 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ciu32 qed_ptt_get_bar_addr(struct qed_ptt *p_ptt); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/** 1078c2ecf20Sopenharmony_ci * @brief qed_ptt_set_win - Set PTT Window's GRC BAR address 1088c2ecf20Sopenharmony_ci * 1098c2ecf20Sopenharmony_ci * @param p_hwfn 1108c2ecf20Sopenharmony_ci * @param new_hw_addr 1118c2ecf20Sopenharmony_ci * @param p_ptt 1128c2ecf20Sopenharmony_ci */ 1138c2ecf20Sopenharmony_civoid qed_ptt_set_win(struct qed_hwfn *p_hwfn, 1148c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 1158c2ecf20Sopenharmony_ci u32 new_hw_addr); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/** 1188c2ecf20Sopenharmony_ci * @brief qed_get_reserved_ptt - Get a specific reserved PTT 1198c2ecf20Sopenharmony_ci * 1208c2ecf20Sopenharmony_ci * @param p_hwfn 1218c2ecf20Sopenharmony_ci * @param ptt_idx 1228c2ecf20Sopenharmony_ci * 1238c2ecf20Sopenharmony_ci * @return struct qed_ptt * 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_cistruct qed_ptt *qed_get_reserved_ptt(struct qed_hwfn *p_hwfn, 1268c2ecf20Sopenharmony_ci enum reserved_ptts ptt_idx); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/** 1298c2ecf20Sopenharmony_ci * @brief qed_wr - Write value to BAR using the given ptt 1308c2ecf20Sopenharmony_ci * 1318c2ecf20Sopenharmony_ci * @param p_hwfn 1328c2ecf20Sopenharmony_ci * @param p_ptt 1338c2ecf20Sopenharmony_ci * @param val 1348c2ecf20Sopenharmony_ci * @param hw_addr 1358c2ecf20Sopenharmony_ci */ 1368c2ecf20Sopenharmony_civoid qed_wr(struct qed_hwfn *p_hwfn, 1378c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 1388c2ecf20Sopenharmony_ci u32 hw_addr, 1398c2ecf20Sopenharmony_ci u32 val); 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci/** 1428c2ecf20Sopenharmony_ci * @brief qed_rd - Read value from BAR using the given ptt 1438c2ecf20Sopenharmony_ci * 1448c2ecf20Sopenharmony_ci * @param p_hwfn 1458c2ecf20Sopenharmony_ci * @param p_ptt 1468c2ecf20Sopenharmony_ci * @param val 1478c2ecf20Sopenharmony_ci * @param hw_addr 1488c2ecf20Sopenharmony_ci */ 1498c2ecf20Sopenharmony_ciu32 qed_rd(struct qed_hwfn *p_hwfn, 1508c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 1518c2ecf20Sopenharmony_ci u32 hw_addr); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/** 1548c2ecf20Sopenharmony_ci * @brief qed_memcpy_from - copy n bytes from BAR using the given 1558c2ecf20Sopenharmony_ci * ptt 1568c2ecf20Sopenharmony_ci * 1578c2ecf20Sopenharmony_ci * @param p_hwfn 1588c2ecf20Sopenharmony_ci * @param p_ptt 1598c2ecf20Sopenharmony_ci * @param dest 1608c2ecf20Sopenharmony_ci * @param hw_addr 1618c2ecf20Sopenharmony_ci * @param n 1628c2ecf20Sopenharmony_ci */ 1638c2ecf20Sopenharmony_civoid qed_memcpy_from(struct qed_hwfn *p_hwfn, 1648c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 1658c2ecf20Sopenharmony_ci void *dest, 1668c2ecf20Sopenharmony_ci u32 hw_addr, 1678c2ecf20Sopenharmony_ci size_t n); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci/** 1708c2ecf20Sopenharmony_ci * @brief qed_memcpy_to - copy n bytes to BAR using the given 1718c2ecf20Sopenharmony_ci * ptt 1728c2ecf20Sopenharmony_ci * 1738c2ecf20Sopenharmony_ci * @param p_hwfn 1748c2ecf20Sopenharmony_ci * @param p_ptt 1758c2ecf20Sopenharmony_ci * @param hw_addr 1768c2ecf20Sopenharmony_ci * @param src 1778c2ecf20Sopenharmony_ci * @param n 1788c2ecf20Sopenharmony_ci */ 1798c2ecf20Sopenharmony_civoid qed_memcpy_to(struct qed_hwfn *p_hwfn, 1808c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 1818c2ecf20Sopenharmony_ci u32 hw_addr, 1828c2ecf20Sopenharmony_ci void *src, 1838c2ecf20Sopenharmony_ci size_t n); 1848c2ecf20Sopenharmony_ci/** 1858c2ecf20Sopenharmony_ci * @brief qed_fid_pretend - pretend to another function when 1868c2ecf20Sopenharmony_ci * accessing the ptt window. There is no way to unpretend 1878c2ecf20Sopenharmony_ci * a function. The only way to cancel a pretend is to 1888c2ecf20Sopenharmony_ci * pretend back to the original function. 1898c2ecf20Sopenharmony_ci * 1908c2ecf20Sopenharmony_ci * @param p_hwfn 1918c2ecf20Sopenharmony_ci * @param p_ptt 1928c2ecf20Sopenharmony_ci * @param fid - fid field of pxp_pretend structure. Can contain 1938c2ecf20Sopenharmony_ci * either pf / vf, port/path fields are don't care. 1948c2ecf20Sopenharmony_ci */ 1958c2ecf20Sopenharmony_civoid qed_fid_pretend(struct qed_hwfn *p_hwfn, 1968c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 1978c2ecf20Sopenharmony_ci u16 fid); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci/** 2008c2ecf20Sopenharmony_ci * @brief qed_port_pretend - pretend to another port when 2018c2ecf20Sopenharmony_ci * accessing the ptt window 2028c2ecf20Sopenharmony_ci * 2038c2ecf20Sopenharmony_ci * @param p_hwfn 2048c2ecf20Sopenharmony_ci * @param p_ptt 2058c2ecf20Sopenharmony_ci * @param port_id - the port to pretend to 2068c2ecf20Sopenharmony_ci */ 2078c2ecf20Sopenharmony_civoid qed_port_pretend(struct qed_hwfn *p_hwfn, 2088c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 2098c2ecf20Sopenharmony_ci u8 port_id); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci/** 2128c2ecf20Sopenharmony_ci * @brief qed_port_unpretend - cancel any previously set port 2138c2ecf20Sopenharmony_ci * pretend 2148c2ecf20Sopenharmony_ci * 2158c2ecf20Sopenharmony_ci * @param p_hwfn 2168c2ecf20Sopenharmony_ci * @param p_ptt 2178c2ecf20Sopenharmony_ci */ 2188c2ecf20Sopenharmony_civoid qed_port_unpretend(struct qed_hwfn *p_hwfn, 2198c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt); 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci/** 2228c2ecf20Sopenharmony_ci * @brief qed_port_fid_pretend - pretend to another port and another function 2238c2ecf20Sopenharmony_ci * when accessing the ptt window 2248c2ecf20Sopenharmony_ci * 2258c2ecf20Sopenharmony_ci * @param p_hwfn 2268c2ecf20Sopenharmony_ci * @param p_ptt 2278c2ecf20Sopenharmony_ci * @param port_id - the port to pretend to 2288c2ecf20Sopenharmony_ci * @param fid - fid field of pxp_pretend structure. Can contain either pf / vf. 2298c2ecf20Sopenharmony_ci */ 2308c2ecf20Sopenharmony_civoid qed_port_fid_pretend(struct qed_hwfn *p_hwfn, 2318c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, u8 port_id, u16 fid); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci/** 2348c2ecf20Sopenharmony_ci * @brief qed_vfid_to_concrete - build a concrete FID for a 2358c2ecf20Sopenharmony_ci * given VF ID 2368c2ecf20Sopenharmony_ci * 2378c2ecf20Sopenharmony_ci * @param p_hwfn 2388c2ecf20Sopenharmony_ci * @param p_ptt 2398c2ecf20Sopenharmony_ci * @param vfid 2408c2ecf20Sopenharmony_ci */ 2418c2ecf20Sopenharmony_ciu32 qed_vfid_to_concrete(struct qed_hwfn *p_hwfn, u8 vfid); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci/** 2448c2ecf20Sopenharmony_ci * @brief qed_dmae_idx_to_go_cmd - map the idx to dmae cmd 2458c2ecf20Sopenharmony_ci * this is declared here since other files will require it. 2468c2ecf20Sopenharmony_ci * @param idx 2478c2ecf20Sopenharmony_ci */ 2488c2ecf20Sopenharmony_ciu32 qed_dmae_idx_to_go_cmd(u8 idx); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci/** 2518c2ecf20Sopenharmony_ci * @brief qed_dmae_info_alloc - Init the dmae_info structure 2528c2ecf20Sopenharmony_ci * which is part of p_hwfn. 2538c2ecf20Sopenharmony_ci * @param p_hwfn 2548c2ecf20Sopenharmony_ci */ 2558c2ecf20Sopenharmony_ciint qed_dmae_info_alloc(struct qed_hwfn *p_hwfn); 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci/** 2588c2ecf20Sopenharmony_ci * @brief qed_dmae_info_free - Free the dmae_info structure 2598c2ecf20Sopenharmony_ci * which is part of p_hwfn 2608c2ecf20Sopenharmony_ci * 2618c2ecf20Sopenharmony_ci * @param p_hwfn 2628c2ecf20Sopenharmony_ci */ 2638c2ecf20Sopenharmony_civoid qed_dmae_info_free(struct qed_hwfn *p_hwfn); 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ciunion qed_qm_pq_params { 2668c2ecf20Sopenharmony_ci struct { 2678c2ecf20Sopenharmony_ci u8 q_idx; 2688c2ecf20Sopenharmony_ci } iscsi; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci struct { 2718c2ecf20Sopenharmony_ci u8 tc; 2728c2ecf20Sopenharmony_ci } core; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci struct { 2758c2ecf20Sopenharmony_ci u8 is_vf; 2768c2ecf20Sopenharmony_ci u8 vf_id; 2778c2ecf20Sopenharmony_ci u8 tc; 2788c2ecf20Sopenharmony_ci } eth; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci struct { 2818c2ecf20Sopenharmony_ci u8 dcqcn; 2828c2ecf20Sopenharmony_ci u8 qpid; /* roce relative */ 2838c2ecf20Sopenharmony_ci } roce; 2848c2ecf20Sopenharmony_ci}; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ciint qed_init_fw_data(struct qed_dev *cdev, 2878c2ecf20Sopenharmony_ci const u8 *fw_data); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ciint qed_dmae_sanity(struct qed_hwfn *p_hwfn, 2908c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, const char *phase); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci#define QED_HW_ERR_MAX_STR_SIZE 256 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci/** 2958c2ecf20Sopenharmony_ci * @brief qed_hw_err_notify - Notify upper layer driver and management FW 2968c2ecf20Sopenharmony_ci * about a HW error. 2978c2ecf20Sopenharmony_ci * 2988c2ecf20Sopenharmony_ci * @param p_hwfn 2998c2ecf20Sopenharmony_ci * @param p_ptt 3008c2ecf20Sopenharmony_ci * @param err_type 3018c2ecf20Sopenharmony_ci * @param fmt - debug data buffer to send to the MFW 3028c2ecf20Sopenharmony_ci * @param ... - buffer format args 3038c2ecf20Sopenharmony_ci */ 3048c2ecf20Sopenharmony_civoid __printf(4, 5) __cold qed_hw_err_notify(struct qed_hwfn *p_hwfn, 3058c2ecf20Sopenharmony_ci struct qed_ptt *p_ptt, 3068c2ecf20Sopenharmony_ci enum qed_hw_err_type err_type, 3078c2ecf20Sopenharmony_ci const char *fmt, ...); 3088c2ecf20Sopenharmony_ci#endif 309