18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is part of the Chelsio FCoE driver for Linux. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2008-2013 Chelsio Communications, Inc. All rights reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 78c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 98c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 128c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 138c2ecf20Sopenharmony_ci * conditions are met: 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 168c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 178c2ecf20Sopenharmony_ci * disclaimer. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 208c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 218c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 228c2ecf20Sopenharmony_ci * provided with the distribution. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 258c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 268c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 278c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 288c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 298c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 308c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 318c2ecf20Sopenharmony_ci * SOFTWARE. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#include "csio_hw.h" 358c2ecf20Sopenharmony_ci#include "csio_init.h" 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic int 388c2ecf20Sopenharmony_cicsio_t5_set_mem_win(struct csio_hw *hw, uint32_t win) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci u32 mem_win_base; 418c2ecf20Sopenharmony_ci /* 428c2ecf20Sopenharmony_ci * Truncation intentional: we only read the bottom 32-bits of the 438c2ecf20Sopenharmony_ci * 64-bit BAR0/BAR1 ... We use the hardware backdoor mechanism to 448c2ecf20Sopenharmony_ci * read BAR0 instead of using pci_resource_start() because we could be 458c2ecf20Sopenharmony_ci * operating from within a Virtual Machine which is trapping our 468c2ecf20Sopenharmony_ci * accesses to our Configuration Space and we need to set up the PCI-E 478c2ecf20Sopenharmony_ci * Memory Window decoders with the actual addresses which will be 488c2ecf20Sopenharmony_ci * coming across the PCI-E link. 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci /* For T5, only relative offset inside the PCIe BAR is passed */ 528c2ecf20Sopenharmony_ci mem_win_base = MEMWIN_BASE; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci /* 558c2ecf20Sopenharmony_ci * Set up memory window for accessing adapter memory ranges. (Read 568c2ecf20Sopenharmony_ci * back MA register to ensure that changes propagate before we attempt 578c2ecf20Sopenharmony_ci * to use the new values.) 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci csio_wr_reg32(hw, mem_win_base | BIR_V(0) | 608c2ecf20Sopenharmony_ci WINDOW_V(ilog2(MEMWIN_APERTURE) - 10), 618c2ecf20Sopenharmony_ci PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, win)); 628c2ecf20Sopenharmony_ci csio_rd_reg32(hw, 638c2ecf20Sopenharmony_ci PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, win)); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci return 0; 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* 698c2ecf20Sopenharmony_ci * Interrupt handler for the PCIE module. 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_cistatic void 728c2ecf20Sopenharmony_cicsio_t5_pcie_intr_handler(struct csio_hw *hw) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci static struct intr_info pcie_intr_info[] = { 758c2ecf20Sopenharmony_ci { MSTGRPPERR_F, "Master Response Read Queue parity error", 768c2ecf20Sopenharmony_ci -1, 1 }, 778c2ecf20Sopenharmony_ci { MSTTIMEOUTPERR_F, "Master Timeout FIFO parity error", -1, 1 }, 788c2ecf20Sopenharmony_ci { MSIXSTIPERR_F, "MSI-X STI SRAM parity error", -1, 1 }, 798c2ecf20Sopenharmony_ci { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 }, 808c2ecf20Sopenharmony_ci { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 }, 818c2ecf20Sopenharmony_ci { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 }, 828c2ecf20Sopenharmony_ci { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 }, 838c2ecf20Sopenharmony_ci { PIOCPLGRPPERR_F, "PCI PIO completion Group FIFO parity error", 848c2ecf20Sopenharmony_ci -1, 1 }, 858c2ecf20Sopenharmony_ci { PIOREQGRPPERR_F, "PCI PIO request Group FIFO parity error", 868c2ecf20Sopenharmony_ci -1, 1 }, 878c2ecf20Sopenharmony_ci { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 }, 888c2ecf20Sopenharmony_ci { MSTTAGQPERR_F, "PCI master tag queue parity error", -1, 1 }, 898c2ecf20Sopenharmony_ci { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 }, 908c2ecf20Sopenharmony_ci { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 }, 918c2ecf20Sopenharmony_ci { DREQWRPERR_F, "PCI DMA channel write request parity error", 928c2ecf20Sopenharmony_ci -1, 1 }, 938c2ecf20Sopenharmony_ci { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 }, 948c2ecf20Sopenharmony_ci { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 }, 958c2ecf20Sopenharmony_ci { HREQWRPERR_F, "PCI HMA channel count parity error", -1, 1 }, 968c2ecf20Sopenharmony_ci { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 }, 978c2ecf20Sopenharmony_ci { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 }, 988c2ecf20Sopenharmony_ci { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 }, 998c2ecf20Sopenharmony_ci { FIDPERR_F, "PCI FID parity error", -1, 1 }, 1008c2ecf20Sopenharmony_ci { VFIDPERR_F, "PCI INTx clear parity error", -1, 1 }, 1018c2ecf20Sopenharmony_ci { MAGRPPERR_F, "PCI MA group FIFO parity error", -1, 1 }, 1028c2ecf20Sopenharmony_ci { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 }, 1038c2ecf20Sopenharmony_ci { IPRXHDRGRPPERR_F, "PCI IP Rx header group parity error", 1048c2ecf20Sopenharmony_ci -1, 1 }, 1058c2ecf20Sopenharmony_ci { IPRXDATAGRPPERR_F, "PCI IP Rx data group parity error", 1068c2ecf20Sopenharmony_ci -1, 1 }, 1078c2ecf20Sopenharmony_ci { RPLPERR_F, "PCI IP replay buffer parity error", -1, 1 }, 1088c2ecf20Sopenharmony_ci { IPSOTPERR_F, "PCI IP SOT buffer parity error", -1, 1 }, 1098c2ecf20Sopenharmony_ci { TRGT1GRPPERR_F, "PCI TRGT1 group FIFOs parity error", -1, 1 }, 1108c2ecf20Sopenharmony_ci { READRSPERR_F, "Outbound read error", -1, 0 }, 1118c2ecf20Sopenharmony_ci { 0, NULL, 0, 0 } 1128c2ecf20Sopenharmony_ci }; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci int fat; 1158c2ecf20Sopenharmony_ci fat = csio_handle_intr_status(hw, PCIE_INT_CAUSE_A, pcie_intr_info); 1168c2ecf20Sopenharmony_ci if (fat) 1178c2ecf20Sopenharmony_ci csio_hw_fatal_err(hw); 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci/* 1218c2ecf20Sopenharmony_ci * csio_t5_flash_cfg_addr - return the address of the flash configuration file 1228c2ecf20Sopenharmony_ci * @hw: the HW module 1238c2ecf20Sopenharmony_ci * 1248c2ecf20Sopenharmony_ci * Return the address within the flash where the Firmware Configuration 1258c2ecf20Sopenharmony_ci * File is stored. 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_cistatic unsigned int 1288c2ecf20Sopenharmony_cicsio_t5_flash_cfg_addr(struct csio_hw *hw) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci return FLASH_CFG_START; 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* 1348c2ecf20Sopenharmony_ci * csio_t5_mc_read - read from MC through backdoor accesses 1358c2ecf20Sopenharmony_ci * @hw: the hw module 1368c2ecf20Sopenharmony_ci * @idx: index to the register 1378c2ecf20Sopenharmony_ci * @addr: address of first byte requested 1388c2ecf20Sopenharmony_ci * @data: 64 bytes of data containing the requested address 1398c2ecf20Sopenharmony_ci * @ecc: where to store the corresponding 64-bit ECC word 1408c2ecf20Sopenharmony_ci * 1418c2ecf20Sopenharmony_ci * Read 64 bytes of data from MC starting at a 64-byte-aligned address 1428c2ecf20Sopenharmony_ci * that covers the requested address @addr. If @parity is not %NULL it 1438c2ecf20Sopenharmony_ci * is assigned the 64-bit ECC word for the read data. 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_cistatic int 1468c2ecf20Sopenharmony_cicsio_t5_mc_read(struct csio_hw *hw, int idx, uint32_t addr, __be32 *data, 1478c2ecf20Sopenharmony_ci uint64_t *ecc) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci int i; 1508c2ecf20Sopenharmony_ci uint32_t mc_bist_cmd_reg, mc_bist_cmd_addr_reg, mc_bist_cmd_len_reg; 1518c2ecf20Sopenharmony_ci uint32_t mc_bist_data_pattern_reg; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci mc_bist_cmd_reg = MC_REG(MC_P_BIST_CMD_A, idx); 1548c2ecf20Sopenharmony_ci mc_bist_cmd_addr_reg = MC_REG(MC_P_BIST_CMD_ADDR_A, idx); 1558c2ecf20Sopenharmony_ci mc_bist_cmd_len_reg = MC_REG(MC_P_BIST_CMD_LEN_A, idx); 1568c2ecf20Sopenharmony_ci mc_bist_data_pattern_reg = MC_REG(MC_P_BIST_DATA_PATTERN_A, idx); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci if (csio_rd_reg32(hw, mc_bist_cmd_reg) & START_BIST_F) 1598c2ecf20Sopenharmony_ci return -EBUSY; 1608c2ecf20Sopenharmony_ci csio_wr_reg32(hw, addr & ~0x3fU, mc_bist_cmd_addr_reg); 1618c2ecf20Sopenharmony_ci csio_wr_reg32(hw, 64, mc_bist_cmd_len_reg); 1628c2ecf20Sopenharmony_ci csio_wr_reg32(hw, 0xc, mc_bist_data_pattern_reg); 1638c2ecf20Sopenharmony_ci csio_wr_reg32(hw, BIST_OPCODE_V(1) | START_BIST_F | BIST_CMD_GAP_V(1), 1648c2ecf20Sopenharmony_ci mc_bist_cmd_reg); 1658c2ecf20Sopenharmony_ci i = csio_hw_wait_op_done_val(hw, mc_bist_cmd_reg, START_BIST_F, 1668c2ecf20Sopenharmony_ci 0, 10, 1, NULL); 1678c2ecf20Sopenharmony_ci if (i) 1688c2ecf20Sopenharmony_ci return i; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define MC_DATA(i) MC_BIST_STATUS_REG(MC_BIST_STATUS_RDATA_A, i) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci for (i = 15; i >= 0; i--) 1738c2ecf20Sopenharmony_ci *data++ = htonl(csio_rd_reg32(hw, MC_DATA(i))); 1748c2ecf20Sopenharmony_ci if (ecc) 1758c2ecf20Sopenharmony_ci *ecc = csio_rd_reg64(hw, MC_DATA(16)); 1768c2ecf20Sopenharmony_ci#undef MC_DATA 1778c2ecf20Sopenharmony_ci return 0; 1788c2ecf20Sopenharmony_ci} 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci/* 1818c2ecf20Sopenharmony_ci * csio_t5_edc_read - read from EDC through backdoor accesses 1828c2ecf20Sopenharmony_ci * @hw: the hw module 1838c2ecf20Sopenharmony_ci * @idx: which EDC to access 1848c2ecf20Sopenharmony_ci * @addr: address of first byte requested 1858c2ecf20Sopenharmony_ci * @data: 64 bytes of data containing the requested address 1868c2ecf20Sopenharmony_ci * @ecc: where to store the corresponding 64-bit ECC word 1878c2ecf20Sopenharmony_ci * 1888c2ecf20Sopenharmony_ci * Read 64 bytes of data from EDC starting at a 64-byte-aligned address 1898c2ecf20Sopenharmony_ci * that covers the requested address @addr. If @parity is not %NULL it 1908c2ecf20Sopenharmony_ci * is assigned the 64-bit ECC word for the read data. 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_cistatic int 1938c2ecf20Sopenharmony_cicsio_t5_edc_read(struct csio_hw *hw, int idx, uint32_t addr, __be32 *data, 1948c2ecf20Sopenharmony_ci uint64_t *ecc) 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci int i; 1978c2ecf20Sopenharmony_ci uint32_t edc_bist_cmd_reg, edc_bist_cmd_addr_reg, edc_bist_cmd_len_reg; 1988c2ecf20Sopenharmony_ci uint32_t edc_bist_cmd_data_pattern; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* 2018c2ecf20Sopenharmony_ci * These macro are missing in t4_regs.h file. 2028c2ecf20Sopenharmony_ci */ 2038c2ecf20Sopenharmony_ci#define EDC_STRIDE_T5 (EDC_T51_BASE_ADDR - EDC_T50_BASE_ADDR) 2048c2ecf20Sopenharmony_ci#define EDC_REG_T5(reg, idx) (reg + EDC_STRIDE_T5 * idx) 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci edc_bist_cmd_reg = EDC_REG_T5(EDC_H_BIST_CMD_A, idx); 2078c2ecf20Sopenharmony_ci edc_bist_cmd_addr_reg = EDC_REG_T5(EDC_H_BIST_CMD_ADDR_A, idx); 2088c2ecf20Sopenharmony_ci edc_bist_cmd_len_reg = EDC_REG_T5(EDC_H_BIST_CMD_LEN_A, idx); 2098c2ecf20Sopenharmony_ci edc_bist_cmd_data_pattern = EDC_REG_T5(EDC_H_BIST_DATA_PATTERN_A, idx); 2108c2ecf20Sopenharmony_ci#undef EDC_REG_T5 2118c2ecf20Sopenharmony_ci#undef EDC_STRIDE_T5 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci if (csio_rd_reg32(hw, edc_bist_cmd_reg) & START_BIST_F) 2148c2ecf20Sopenharmony_ci return -EBUSY; 2158c2ecf20Sopenharmony_ci csio_wr_reg32(hw, addr & ~0x3fU, edc_bist_cmd_addr_reg); 2168c2ecf20Sopenharmony_ci csio_wr_reg32(hw, 64, edc_bist_cmd_len_reg); 2178c2ecf20Sopenharmony_ci csio_wr_reg32(hw, 0xc, edc_bist_cmd_data_pattern); 2188c2ecf20Sopenharmony_ci csio_wr_reg32(hw, BIST_OPCODE_V(1) | START_BIST_F | BIST_CMD_GAP_V(1), 2198c2ecf20Sopenharmony_ci edc_bist_cmd_reg); 2208c2ecf20Sopenharmony_ci i = csio_hw_wait_op_done_val(hw, edc_bist_cmd_reg, START_BIST_F, 2218c2ecf20Sopenharmony_ci 0, 10, 1, NULL); 2228c2ecf20Sopenharmony_ci if (i) 2238c2ecf20Sopenharmony_ci return i; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci#define EDC_DATA(i) (EDC_BIST_STATUS_REG(EDC_BIST_STATUS_RDATA_A, i) + idx) 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci for (i = 15; i >= 0; i--) 2288c2ecf20Sopenharmony_ci *data++ = htonl(csio_rd_reg32(hw, EDC_DATA(i))); 2298c2ecf20Sopenharmony_ci if (ecc) 2308c2ecf20Sopenharmony_ci *ecc = csio_rd_reg64(hw, EDC_DATA(16)); 2318c2ecf20Sopenharmony_ci#undef EDC_DATA 2328c2ecf20Sopenharmony_ci return 0; 2338c2ecf20Sopenharmony_ci} 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci/* 2368c2ecf20Sopenharmony_ci * csio_t5_memory_rw - read/write EDC 0, EDC 1 or MC via PCIE memory window 2378c2ecf20Sopenharmony_ci * @hw: the csio_hw 2388c2ecf20Sopenharmony_ci * @win: PCI-E memory Window to use 2398c2ecf20Sopenharmony_ci * @mtype: memory type: MEM_EDC0, MEM_EDC1, MEM_MC0 (or MEM_MC) or MEM_MC1 2408c2ecf20Sopenharmony_ci * @addr: address within indicated memory type 2418c2ecf20Sopenharmony_ci * @len: amount of memory to transfer 2428c2ecf20Sopenharmony_ci * @buf: host memory buffer 2438c2ecf20Sopenharmony_ci * @dir: direction of transfer 1 => read, 0 => write 2448c2ecf20Sopenharmony_ci * 2458c2ecf20Sopenharmony_ci * Reads/writes an [almost] arbitrary memory region in the firmware: the 2468c2ecf20Sopenharmony_ci * firmware memory address, length and host buffer must be aligned on 2478c2ecf20Sopenharmony_ci * 32-bit boudaries. The memory is transferred as a raw byte sequence 2488c2ecf20Sopenharmony_ci * from/to the firmware's memory. If this memory contains data 2498c2ecf20Sopenharmony_ci * structures which contain multi-byte integers, it's the callers 2508c2ecf20Sopenharmony_ci * responsibility to perform appropriate byte order conversions. 2518c2ecf20Sopenharmony_ci */ 2528c2ecf20Sopenharmony_cistatic int 2538c2ecf20Sopenharmony_cicsio_t5_memory_rw(struct csio_hw *hw, u32 win, int mtype, u32 addr, 2548c2ecf20Sopenharmony_ci u32 len, uint32_t *buf, int dir) 2558c2ecf20Sopenharmony_ci{ 2568c2ecf20Sopenharmony_ci u32 pos, start, offset, memoffset; 2578c2ecf20Sopenharmony_ci u32 edc_size, mc_size, win_pf, mem_reg, mem_aperture, mem_base; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci /* 2608c2ecf20Sopenharmony_ci * Argument sanity checks ... 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_ci if ((addr & 0x3) || (len & 0x3)) 2638c2ecf20Sopenharmony_ci return -EINVAL; 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci /* Offset into the region of memory which is being accessed 2668c2ecf20Sopenharmony_ci * MEM_EDC0 = 0 2678c2ecf20Sopenharmony_ci * MEM_EDC1 = 1 2688c2ecf20Sopenharmony_ci * MEM_MC = 2 -- T4 2698c2ecf20Sopenharmony_ci * MEM_MC0 = 2 -- For T5 2708c2ecf20Sopenharmony_ci * MEM_MC1 = 3 -- For T5 2718c2ecf20Sopenharmony_ci */ 2728c2ecf20Sopenharmony_ci edc_size = EDRAM0_SIZE_G(csio_rd_reg32(hw, MA_EDRAM0_BAR_A)); 2738c2ecf20Sopenharmony_ci if (mtype != MEM_MC1) 2748c2ecf20Sopenharmony_ci memoffset = (mtype * (edc_size * 1024 * 1024)); 2758c2ecf20Sopenharmony_ci else { 2768c2ecf20Sopenharmony_ci mc_size = EXT_MEM_SIZE_G(csio_rd_reg32(hw, 2778c2ecf20Sopenharmony_ci MA_EXT_MEMORY_BAR_A)); 2788c2ecf20Sopenharmony_ci memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024; 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci /* Determine the PCIE_MEM_ACCESS_OFFSET */ 2828c2ecf20Sopenharmony_ci addr = addr + memoffset; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci /* 2858c2ecf20Sopenharmony_ci * Each PCI-E Memory Window is programmed with a window size -- or 2868c2ecf20Sopenharmony_ci * "aperture" -- which controls the granularity of its mapping onto 2878c2ecf20Sopenharmony_ci * adapter memory. We need to grab that aperture in order to know 2888c2ecf20Sopenharmony_ci * how to use the specified window. The window is also programmed 2898c2ecf20Sopenharmony_ci * with the base address of the Memory Window in BAR0's address 2908c2ecf20Sopenharmony_ci * space. For T4 this is an absolute PCI-E Bus Address. For T5 2918c2ecf20Sopenharmony_ci * the address is relative to BAR0. 2928c2ecf20Sopenharmony_ci */ 2938c2ecf20Sopenharmony_ci mem_reg = csio_rd_reg32(hw, 2948c2ecf20Sopenharmony_ci PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, win)); 2958c2ecf20Sopenharmony_ci mem_aperture = 1 << (WINDOW_V(mem_reg) + 10); 2968c2ecf20Sopenharmony_ci mem_base = PCIEOFST_G(mem_reg) << 10; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci start = addr & ~(mem_aperture-1); 2998c2ecf20Sopenharmony_ci offset = addr - start; 3008c2ecf20Sopenharmony_ci win_pf = PFNUM_V(hw->pfn); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci csio_dbg(hw, "csio_t5_memory_rw: mem_reg: 0x%x, mem_aperture: 0x%x\n", 3038c2ecf20Sopenharmony_ci mem_reg, mem_aperture); 3048c2ecf20Sopenharmony_ci csio_dbg(hw, "csio_t5_memory_rw: mem_base: 0x%x, mem_offset: 0x%x\n", 3058c2ecf20Sopenharmony_ci mem_base, memoffset); 3068c2ecf20Sopenharmony_ci csio_dbg(hw, "csio_t5_memory_rw: start:0x%x, offset:0x%x, win_pf:%d\n", 3078c2ecf20Sopenharmony_ci start, offset, win_pf); 3088c2ecf20Sopenharmony_ci csio_dbg(hw, "csio_t5_memory_rw: mtype: %d, addr: 0x%x, len: %d\n", 3098c2ecf20Sopenharmony_ci mtype, addr, len); 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci for (pos = start; len > 0; pos += mem_aperture, offset = 0) { 3128c2ecf20Sopenharmony_ci /* 3138c2ecf20Sopenharmony_ci * Move PCI-E Memory Window to our current transfer 3148c2ecf20Sopenharmony_ci * position. Read it back to ensure that changes propagate 3158c2ecf20Sopenharmony_ci * before we attempt to use the new value. 3168c2ecf20Sopenharmony_ci */ 3178c2ecf20Sopenharmony_ci csio_wr_reg32(hw, pos | win_pf, 3188c2ecf20Sopenharmony_ci PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win)); 3198c2ecf20Sopenharmony_ci csio_rd_reg32(hw, 3208c2ecf20Sopenharmony_ci PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win)); 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci while (offset < mem_aperture && len > 0) { 3238c2ecf20Sopenharmony_ci if (dir) 3248c2ecf20Sopenharmony_ci *buf++ = csio_rd_reg32(hw, mem_base + offset); 3258c2ecf20Sopenharmony_ci else 3268c2ecf20Sopenharmony_ci csio_wr_reg32(hw, *buf++, mem_base + offset); 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci offset += sizeof(__be32); 3298c2ecf20Sopenharmony_ci len -= sizeof(__be32); 3308c2ecf20Sopenharmony_ci } 3318c2ecf20Sopenharmony_ci } 3328c2ecf20Sopenharmony_ci return 0; 3338c2ecf20Sopenharmony_ci} 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci/* 3368c2ecf20Sopenharmony_ci * csio_t5_dfs_create_ext_mem - setup debugfs for MC0 or MC1 to read the values 3378c2ecf20Sopenharmony_ci * @hw: the csio_hw 3388c2ecf20Sopenharmony_ci * 3398c2ecf20Sopenharmony_ci * This function creates files in the debugfs with external memory region 3408c2ecf20Sopenharmony_ci * MC0 & MC1. 3418c2ecf20Sopenharmony_ci */ 3428c2ecf20Sopenharmony_cistatic void 3438c2ecf20Sopenharmony_cicsio_t5_dfs_create_ext_mem(struct csio_hw *hw) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci u32 size; 3468c2ecf20Sopenharmony_ci int i = csio_rd_reg32(hw, MA_TARGET_MEM_ENABLE_A); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci if (i & EXT_MEM_ENABLE_F) { 3498c2ecf20Sopenharmony_ci size = csio_rd_reg32(hw, MA_EXT_MEMORY_BAR_A); 3508c2ecf20Sopenharmony_ci csio_add_debugfs_mem(hw, "mc0", MEM_MC0, 3518c2ecf20Sopenharmony_ci EXT_MEM_SIZE_G(size)); 3528c2ecf20Sopenharmony_ci } 3538c2ecf20Sopenharmony_ci if (i & EXT_MEM1_ENABLE_F) { 3548c2ecf20Sopenharmony_ci size = csio_rd_reg32(hw, MA_EXT_MEMORY1_BAR_A); 3558c2ecf20Sopenharmony_ci csio_add_debugfs_mem(hw, "mc1", MEM_MC1, 3568c2ecf20Sopenharmony_ci EXT_MEM_SIZE_G(size)); 3578c2ecf20Sopenharmony_ci } 3588c2ecf20Sopenharmony_ci} 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci/* T5 adapter specific function */ 3618c2ecf20Sopenharmony_cistruct csio_hw_chip_ops t5_ops = { 3628c2ecf20Sopenharmony_ci .chip_set_mem_win = csio_t5_set_mem_win, 3638c2ecf20Sopenharmony_ci .chip_pcie_intr_handler = csio_t5_pcie_intr_handler, 3648c2ecf20Sopenharmony_ci .chip_flash_cfg_addr = csio_t5_flash_cfg_addr, 3658c2ecf20Sopenharmony_ci .chip_mc_read = csio_t5_mc_read, 3668c2ecf20Sopenharmony_ci .chip_edc_read = csio_t5_edc_read, 3678c2ecf20Sopenharmony_ci .chip_memory_rw = csio_t5_memory_rw, 3688c2ecf20Sopenharmony_ci .chip_dfs_create_ext_mem = csio_t5_dfs_create_ext_mem, 3698c2ecf20Sopenharmony_ci}; 370