csio_hw_t5.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2013 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include "csio_hw.h"
  34. #include "csio_init.h"
  35. static int
  36. csio_t5_set_mem_win(struct csio_hw *hw, uint32_t win)
  37. {
  38. u32 mem_win_base;
  39. /*
  40. * Truncation intentional: we only read the bottom 32-bits of the
  41. * 64-bit BAR0/BAR1 ... We use the hardware backdoor mechanism to
  42. * read BAR0 instead of using pci_resource_start() because we could be
  43. * operating from within a Virtual Machine which is trapping our
  44. * accesses to our Configuration Space and we need to set up the PCI-E
  45. * Memory Window decoders with the actual addresses which will be
  46. * coming across the PCI-E link.
  47. */
  48. /* For T5, only relative offset inside the PCIe BAR is passed */
  49. mem_win_base = MEMWIN_BASE;
  50. /*
  51. * Set up memory window for accessing adapter memory ranges. (Read
  52. * back MA register to ensure that changes propagate before we attempt
  53. * to use the new values.)
  54. */
  55. csio_wr_reg32(hw, mem_win_base | BIR_V(0) |
  56. WINDOW_V(ilog2(MEMWIN_APERTURE) - 10),
  57. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, win));
  58. csio_rd_reg32(hw,
  59. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, win));
  60. return 0;
  61. }
  62. /*
  63. * Interrupt handler for the PCIE module.
  64. */
  65. static void
  66. csio_t5_pcie_intr_handler(struct csio_hw *hw)
  67. {
  68. static struct intr_info sysbus_intr_info[] = {
  69. { RNPP_F, "RXNP array parity error", -1, 1 },
  70. { RPCP_F, "RXPC array parity error", -1, 1 },
  71. { RCIP_F, "RXCIF array parity error", -1, 1 },
  72. { RCCP_F, "Rx completions control array parity error", -1, 1 },
  73. { RFTP_F, "RXFT array parity error", -1, 1 },
  74. { 0, NULL, 0, 0 }
  75. };
  76. static struct intr_info pcie_port_intr_info[] = {
  77. { TPCP_F, "TXPC array parity error", -1, 1 },
  78. { TNPP_F, "TXNP array parity error", -1, 1 },
  79. { TFTP_F, "TXFT array parity error", -1, 1 },
  80. { TCAP_F, "TXCA array parity error", -1, 1 },
  81. { TCIP_F, "TXCIF array parity error", -1, 1 },
  82. { RCAP_F, "RXCA array parity error", -1, 1 },
  83. { OTDD_F, "outbound request TLP discarded", -1, 1 },
  84. { RDPE_F, "Rx data parity error", -1, 1 },
  85. { TDUE_F, "Tx uncorrectable data error", -1, 1 },
  86. { 0, NULL, 0, 0 }
  87. };
  88. static struct intr_info pcie_intr_info[] = {
  89. { MSTGRPPERR_F, "Master Response Read Queue parity error",
  90. -1, 1 },
  91. { MSTTIMEOUTPERR_F, "Master Timeout FIFO parity error", -1, 1 },
  92. { MSIXSTIPERR_F, "MSI-X STI SRAM parity error", -1, 1 },
  93. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  94. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  95. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  96. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  97. { PIOCPLGRPPERR_F, "PCI PIO completion Group FIFO parity error",
  98. -1, 1 },
  99. { PIOREQGRPPERR_F, "PCI PIO request Group FIFO parity error",
  100. -1, 1 },
  101. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  102. { MSTTAGQPERR_F, "PCI master tag queue parity error", -1, 1 },
  103. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  104. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  105. { DREQWRPERR_F, "PCI DMA channel write request parity error",
  106. -1, 1 },
  107. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  108. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  109. { HREQWRPERR_F, "PCI HMA channel count parity error", -1, 1 },
  110. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  111. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  112. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  113. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  114. { VFIDPERR_F, "PCI INTx clear parity error", -1, 1 },
  115. { MAGRPPERR_F, "PCI MA group FIFO parity error", -1, 1 },
  116. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  117. { IPRXHDRGRPPERR_F, "PCI IP Rx header group parity error",
  118. -1, 1 },
  119. { IPRXDATAGRPPERR_F, "PCI IP Rx data group parity error",
  120. -1, 1 },
  121. { RPLPERR_F, "PCI IP replay buffer parity error", -1, 1 },
  122. { IPSOTPERR_F, "PCI IP SOT buffer parity error", -1, 1 },
  123. { TRGT1GRPPERR_F, "PCI TRGT1 group FIFOs parity error", -1, 1 },
  124. { READRSPERR_F, "Outbound read error", -1, 0 },
  125. { 0, NULL, 0, 0 }
  126. };
  127. int fat;
  128. fat = csio_handle_intr_status(hw,
  129. PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS_A,
  130. sysbus_intr_info) +
  131. csio_handle_intr_status(hw,
  132. PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS_A,
  133. pcie_port_intr_info) +
  134. csio_handle_intr_status(hw, PCIE_INT_CAUSE_A, pcie_intr_info);
  135. if (fat)
  136. csio_hw_fatal_err(hw);
  137. }
  138. /*
  139. * csio_t5_flash_cfg_addr - return the address of the flash configuration file
  140. * @hw: the HW module
  141. *
  142. * Return the address within the flash where the Firmware Configuration
  143. * File is stored.
  144. */
  145. static unsigned int
  146. csio_t5_flash_cfg_addr(struct csio_hw *hw)
  147. {
  148. return FLASH_CFG_START;
  149. }
  150. /*
  151. * csio_t5_mc_read - read from MC through backdoor accesses
  152. * @hw: the hw module
  153. * @idx: index to the register
  154. * @addr: address of first byte requested
  155. * @data: 64 bytes of data containing the requested address
  156. * @ecc: where to store the corresponding 64-bit ECC word
  157. *
  158. * Read 64 bytes of data from MC starting at a 64-byte-aligned address
  159. * that covers the requested address @addr. If @parity is not %NULL it
  160. * is assigned the 64-bit ECC word for the read data.
  161. */
  162. static int
  163. csio_t5_mc_read(struct csio_hw *hw, int idx, uint32_t addr, __be32 *data,
  164. uint64_t *ecc)
  165. {
  166. int i;
  167. uint32_t mc_bist_cmd_reg, mc_bist_cmd_addr_reg, mc_bist_cmd_len_reg;
  168. uint32_t mc_bist_status_rdata_reg, mc_bist_data_pattern_reg;
  169. mc_bist_cmd_reg = MC_REG(MC_P_BIST_CMD_A, idx);
  170. mc_bist_cmd_addr_reg = MC_REG(MC_P_BIST_CMD_ADDR_A, idx);
  171. mc_bist_cmd_len_reg = MC_REG(MC_P_BIST_CMD_LEN_A, idx);
  172. mc_bist_status_rdata_reg = MC_REG(MC_P_BIST_STATUS_RDATA_A, idx);
  173. mc_bist_data_pattern_reg = MC_REG(MC_P_BIST_DATA_PATTERN_A, idx);
  174. if (csio_rd_reg32(hw, mc_bist_cmd_reg) & START_BIST_F)
  175. return -EBUSY;
  176. csio_wr_reg32(hw, addr & ~0x3fU, mc_bist_cmd_addr_reg);
  177. csio_wr_reg32(hw, 64, mc_bist_cmd_len_reg);
  178. csio_wr_reg32(hw, 0xc, mc_bist_data_pattern_reg);
  179. csio_wr_reg32(hw, BIST_OPCODE_V(1) | START_BIST_F | BIST_CMD_GAP_V(1),
  180. mc_bist_cmd_reg);
  181. i = csio_hw_wait_op_done_val(hw, mc_bist_cmd_reg, START_BIST_F,
  182. 0, 10, 1, NULL);
  183. if (i)
  184. return i;
  185. #define MC_DATA(i) MC_BIST_STATUS_REG(MC_BIST_STATUS_RDATA_A, i)
  186. for (i = 15; i >= 0; i--)
  187. *data++ = htonl(csio_rd_reg32(hw, MC_DATA(i)));
  188. if (ecc)
  189. *ecc = csio_rd_reg64(hw, MC_DATA(16));
  190. #undef MC_DATA
  191. return 0;
  192. }
  193. /*
  194. * csio_t5_edc_read - read from EDC through backdoor accesses
  195. * @hw: the hw module
  196. * @idx: which EDC to access
  197. * @addr: address of first byte requested
  198. * @data: 64 bytes of data containing the requested address
  199. * @ecc: where to store the corresponding 64-bit ECC word
  200. *
  201. * Read 64 bytes of data from EDC starting at a 64-byte-aligned address
  202. * that covers the requested address @addr. If @parity is not %NULL it
  203. * is assigned the 64-bit ECC word for the read data.
  204. */
  205. static int
  206. csio_t5_edc_read(struct csio_hw *hw, int idx, uint32_t addr, __be32 *data,
  207. uint64_t *ecc)
  208. {
  209. int i;
  210. uint32_t edc_bist_cmd_reg, edc_bist_cmd_addr_reg, edc_bist_cmd_len_reg;
  211. uint32_t edc_bist_cmd_data_pattern, edc_bist_status_rdata_reg;
  212. /*
  213. * These macro are missing in t4_regs.h file.
  214. */
  215. #define EDC_STRIDE_T5 (EDC_T51_BASE_ADDR - EDC_T50_BASE_ADDR)
  216. #define EDC_REG_T5(reg, idx) (reg + EDC_STRIDE_T5 * idx)
  217. edc_bist_cmd_reg = EDC_REG_T5(EDC_H_BIST_CMD_A, idx);
  218. edc_bist_cmd_addr_reg = EDC_REG_T5(EDC_H_BIST_CMD_ADDR_A, idx);
  219. edc_bist_cmd_len_reg = EDC_REG_T5(EDC_H_BIST_CMD_LEN_A, idx);
  220. edc_bist_cmd_data_pattern = EDC_REG_T5(EDC_H_BIST_DATA_PATTERN_A, idx);
  221. edc_bist_status_rdata_reg = EDC_REG_T5(EDC_H_BIST_STATUS_RDATA_A, idx);
  222. #undef EDC_REG_T5
  223. #undef EDC_STRIDE_T5
  224. if (csio_rd_reg32(hw, edc_bist_cmd_reg) & START_BIST_F)
  225. return -EBUSY;
  226. csio_wr_reg32(hw, addr & ~0x3fU, edc_bist_cmd_addr_reg);
  227. csio_wr_reg32(hw, 64, edc_bist_cmd_len_reg);
  228. csio_wr_reg32(hw, 0xc, edc_bist_cmd_data_pattern);
  229. csio_wr_reg32(hw, BIST_OPCODE_V(1) | START_BIST_F | BIST_CMD_GAP_V(1),
  230. edc_bist_cmd_reg);
  231. i = csio_hw_wait_op_done_val(hw, edc_bist_cmd_reg, START_BIST_F,
  232. 0, 10, 1, NULL);
  233. if (i)
  234. return i;
  235. #define EDC_DATA(i) (EDC_BIST_STATUS_REG(EDC_BIST_STATUS_RDATA_A, i) + idx)
  236. for (i = 15; i >= 0; i--)
  237. *data++ = htonl(csio_rd_reg32(hw, EDC_DATA(i)));
  238. if (ecc)
  239. *ecc = csio_rd_reg64(hw, EDC_DATA(16));
  240. #undef EDC_DATA
  241. return 0;
  242. }
  243. /*
  244. * csio_t5_memory_rw - read/write EDC 0, EDC 1 or MC via PCIE memory window
  245. * @hw: the csio_hw
  246. * @win: PCI-E memory Window to use
  247. * @mtype: memory type: MEM_EDC0, MEM_EDC1, MEM_MC0 (or MEM_MC) or MEM_MC1
  248. * @addr: address within indicated memory type
  249. * @len: amount of memory to transfer
  250. * @buf: host memory buffer
  251. * @dir: direction of transfer 1 => read, 0 => write
  252. *
  253. * Reads/writes an [almost] arbitrary memory region in the firmware: the
  254. * firmware memory address, length and host buffer must be aligned on
  255. * 32-bit boudaries. The memory is transferred as a raw byte sequence
  256. * from/to the firmware's memory. If this memory contains data
  257. * structures which contain multi-byte integers, it's the callers
  258. * responsibility to perform appropriate byte order conversions.
  259. */
  260. static int
  261. csio_t5_memory_rw(struct csio_hw *hw, u32 win, int mtype, u32 addr,
  262. u32 len, uint32_t *buf, int dir)
  263. {
  264. u32 pos, start, offset, memoffset;
  265. u32 edc_size, mc_size, win_pf, mem_reg, mem_aperture, mem_base;
  266. /*
  267. * Argument sanity checks ...
  268. */
  269. if ((addr & 0x3) || (len & 0x3))
  270. return -EINVAL;
  271. /* Offset into the region of memory which is being accessed
  272. * MEM_EDC0 = 0
  273. * MEM_EDC1 = 1
  274. * MEM_MC = 2 -- T4
  275. * MEM_MC0 = 2 -- For T5
  276. * MEM_MC1 = 3 -- For T5
  277. */
  278. edc_size = EDRAM0_SIZE_G(csio_rd_reg32(hw, MA_EDRAM0_BAR_A));
  279. if (mtype != MEM_MC1)
  280. memoffset = (mtype * (edc_size * 1024 * 1024));
  281. else {
  282. mc_size = EXT_MEM_SIZE_G(csio_rd_reg32(hw,
  283. MA_EXT_MEMORY_BAR_A));
  284. memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024;
  285. }
  286. /* Determine the PCIE_MEM_ACCESS_OFFSET */
  287. addr = addr + memoffset;
  288. /*
  289. * Each PCI-E Memory Window is programmed with a window size -- or
  290. * "aperture" -- which controls the granularity of its mapping onto
  291. * adapter memory. We need to grab that aperture in order to know
  292. * how to use the specified window. The window is also programmed
  293. * with the base address of the Memory Window in BAR0's address
  294. * space. For T4 this is an absolute PCI-E Bus Address. For T5
  295. * the address is relative to BAR0.
  296. */
  297. mem_reg = csio_rd_reg32(hw,
  298. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, win));
  299. mem_aperture = 1 << (WINDOW_V(mem_reg) + 10);
  300. mem_base = PCIEOFST_G(mem_reg) << 10;
  301. start = addr & ~(mem_aperture-1);
  302. offset = addr - start;
  303. win_pf = PFNUM_V(hw->pfn);
  304. csio_dbg(hw, "csio_t5_memory_rw: mem_reg: 0x%x, mem_aperture: 0x%x\n",
  305. mem_reg, mem_aperture);
  306. csio_dbg(hw, "csio_t5_memory_rw: mem_base: 0x%x, mem_offset: 0x%x\n",
  307. mem_base, memoffset);
  308. csio_dbg(hw, "csio_t5_memory_rw: start:0x%x, offset:0x%x, win_pf:%d\n",
  309. start, offset, win_pf);
  310. csio_dbg(hw, "csio_t5_memory_rw: mtype: %d, addr: 0x%x, len: %d\n",
  311. mtype, addr, len);
  312. for (pos = start; len > 0; pos += mem_aperture, offset = 0) {
  313. /*
  314. * Move PCI-E Memory Window to our current transfer
  315. * position. Read it back to ensure that changes propagate
  316. * before we attempt to use the new value.
  317. */
  318. csio_wr_reg32(hw, pos | win_pf,
  319. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
  320. csio_rd_reg32(hw,
  321. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
  322. while (offset < mem_aperture && len > 0) {
  323. if (dir)
  324. *buf++ = csio_rd_reg32(hw, mem_base + offset);
  325. else
  326. csio_wr_reg32(hw, *buf++, mem_base + offset);
  327. offset += sizeof(__be32);
  328. len -= sizeof(__be32);
  329. }
  330. }
  331. return 0;
  332. }
  333. /*
  334. * csio_t5_dfs_create_ext_mem - setup debugfs for MC0 or MC1 to read the values
  335. * @hw: the csio_hw
  336. *
  337. * This function creates files in the debugfs with external memory region
  338. * MC0 & MC1.
  339. */
  340. static void
  341. csio_t5_dfs_create_ext_mem(struct csio_hw *hw)
  342. {
  343. u32 size;
  344. int i = csio_rd_reg32(hw, MA_TARGET_MEM_ENABLE_A);
  345. if (i & EXT_MEM_ENABLE_F) {
  346. size = csio_rd_reg32(hw, MA_EXT_MEMORY_BAR_A);
  347. csio_add_debugfs_mem(hw, "mc0", MEM_MC0,
  348. EXT_MEM_SIZE_G(size));
  349. }
  350. if (i & EXT_MEM1_ENABLE_F) {
  351. size = csio_rd_reg32(hw, MA_EXT_MEMORY1_BAR_A);
  352. csio_add_debugfs_mem(hw, "mc1", MEM_MC1,
  353. EXT_MEM_SIZE_G(size));
  354. }
  355. }
  356. /* T5 adapter specific function */
  357. struct csio_hw_chip_ops t5_ops = {
  358. .chip_set_mem_win = csio_t5_set_mem_win,
  359. .chip_pcie_intr_handler = csio_t5_pcie_intr_handler,
  360. .chip_flash_cfg_addr = csio_t5_flash_cfg_addr,
  361. .chip_mc_read = csio_t5_mc_read,
  362. .chip_edc_read = csio_t5_edc_read,
  363. .chip_memory_rw = csio_t5_memory_rw,
  364. .chip_dfs_create_ext_mem = csio_t5_dfs_create_ext_mem,
  365. };