csio_hw_t5.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 pcie_intr_info[] = {
  69. { MSTGRPPERR_F, "Master Response Read Queue parity error",
  70. -1, 1 },
  71. { MSTTIMEOUTPERR_F, "Master Timeout FIFO parity error", -1, 1 },
  72. { MSIXSTIPERR_F, "MSI-X STI SRAM parity error", -1, 1 },
  73. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  74. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  75. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  76. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  77. { PIOCPLGRPPERR_F, "PCI PIO completion Group FIFO parity error",
  78. -1, 1 },
  79. { PIOREQGRPPERR_F, "PCI PIO request Group FIFO parity error",
  80. -1, 1 },
  81. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  82. { MSTTAGQPERR_F, "PCI master tag queue parity error", -1, 1 },
  83. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  84. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  85. { DREQWRPERR_F, "PCI DMA channel write request parity error",
  86. -1, 1 },
  87. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  88. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  89. { HREQWRPERR_F, "PCI HMA channel count parity error", -1, 1 },
  90. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  91. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  92. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  93. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  94. { VFIDPERR_F, "PCI INTx clear parity error", -1, 1 },
  95. { MAGRPPERR_F, "PCI MA group FIFO parity error", -1, 1 },
  96. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  97. { IPRXHDRGRPPERR_F, "PCI IP Rx header group parity error",
  98. -1, 1 },
  99. { IPRXDATAGRPPERR_F, "PCI IP Rx data group parity error",
  100. -1, 1 },
  101. { RPLPERR_F, "PCI IP replay buffer parity error", -1, 1 },
  102. { IPSOTPERR_F, "PCI IP SOT buffer parity error", -1, 1 },
  103. { TRGT1GRPPERR_F, "PCI TRGT1 group FIFOs parity error", -1, 1 },
  104. { READRSPERR_F, "Outbound read error", -1, 0 },
  105. { 0, NULL, 0, 0 }
  106. };
  107. int fat;
  108. fat = csio_handle_intr_status(hw, PCIE_INT_CAUSE_A, pcie_intr_info);
  109. if (fat)
  110. csio_hw_fatal_err(hw);
  111. }
  112. /*
  113. * csio_t5_flash_cfg_addr - return the address of the flash configuration file
  114. * @hw: the HW module
  115. *
  116. * Return the address within the flash where the Firmware Configuration
  117. * File is stored.
  118. */
  119. static unsigned int
  120. csio_t5_flash_cfg_addr(struct csio_hw *hw)
  121. {
  122. return FLASH_CFG_START;
  123. }
  124. /*
  125. * csio_t5_mc_read - read from MC through backdoor accesses
  126. * @hw: the hw module
  127. * @idx: index to the register
  128. * @addr: address of first byte requested
  129. * @data: 64 bytes of data containing the requested address
  130. * @ecc: where to store the corresponding 64-bit ECC word
  131. *
  132. * Read 64 bytes of data from MC starting at a 64-byte-aligned address
  133. * that covers the requested address @addr. If @parity is not %NULL it
  134. * is assigned the 64-bit ECC word for the read data.
  135. */
  136. static int
  137. csio_t5_mc_read(struct csio_hw *hw, int idx, uint32_t addr, __be32 *data,
  138. uint64_t *ecc)
  139. {
  140. int i;
  141. uint32_t mc_bist_cmd_reg, mc_bist_cmd_addr_reg, mc_bist_cmd_len_reg;
  142. uint32_t mc_bist_status_rdata_reg, mc_bist_data_pattern_reg;
  143. mc_bist_cmd_reg = MC_REG(MC_P_BIST_CMD_A, idx);
  144. mc_bist_cmd_addr_reg = MC_REG(MC_P_BIST_CMD_ADDR_A, idx);
  145. mc_bist_cmd_len_reg = MC_REG(MC_P_BIST_CMD_LEN_A, idx);
  146. mc_bist_status_rdata_reg = MC_REG(MC_P_BIST_STATUS_RDATA_A, idx);
  147. mc_bist_data_pattern_reg = MC_REG(MC_P_BIST_DATA_PATTERN_A, idx);
  148. if (csio_rd_reg32(hw, mc_bist_cmd_reg) & START_BIST_F)
  149. return -EBUSY;
  150. csio_wr_reg32(hw, addr & ~0x3fU, mc_bist_cmd_addr_reg);
  151. csio_wr_reg32(hw, 64, mc_bist_cmd_len_reg);
  152. csio_wr_reg32(hw, 0xc, mc_bist_data_pattern_reg);
  153. csio_wr_reg32(hw, BIST_OPCODE_V(1) | START_BIST_F | BIST_CMD_GAP_V(1),
  154. mc_bist_cmd_reg);
  155. i = csio_hw_wait_op_done_val(hw, mc_bist_cmd_reg, START_BIST_F,
  156. 0, 10, 1, NULL);
  157. if (i)
  158. return i;
  159. #define MC_DATA(i) MC_BIST_STATUS_REG(MC_BIST_STATUS_RDATA_A, i)
  160. for (i = 15; i >= 0; i--)
  161. *data++ = htonl(csio_rd_reg32(hw, MC_DATA(i)));
  162. if (ecc)
  163. *ecc = csio_rd_reg64(hw, MC_DATA(16));
  164. #undef MC_DATA
  165. return 0;
  166. }
  167. /*
  168. * csio_t5_edc_read - read from EDC through backdoor accesses
  169. * @hw: the hw module
  170. * @idx: which EDC to access
  171. * @addr: address of first byte requested
  172. * @data: 64 bytes of data containing the requested address
  173. * @ecc: where to store the corresponding 64-bit ECC word
  174. *
  175. * Read 64 bytes of data from EDC starting at a 64-byte-aligned address
  176. * that covers the requested address @addr. If @parity is not %NULL it
  177. * is assigned the 64-bit ECC word for the read data.
  178. */
  179. static int
  180. csio_t5_edc_read(struct csio_hw *hw, int idx, uint32_t addr, __be32 *data,
  181. uint64_t *ecc)
  182. {
  183. int i;
  184. uint32_t edc_bist_cmd_reg, edc_bist_cmd_addr_reg, edc_bist_cmd_len_reg;
  185. uint32_t edc_bist_cmd_data_pattern, edc_bist_status_rdata_reg;
  186. /*
  187. * These macro are missing in t4_regs.h file.
  188. */
  189. #define EDC_STRIDE_T5 (EDC_T51_BASE_ADDR - EDC_T50_BASE_ADDR)
  190. #define EDC_REG_T5(reg, idx) (reg + EDC_STRIDE_T5 * idx)
  191. edc_bist_cmd_reg = EDC_REG_T5(EDC_H_BIST_CMD_A, idx);
  192. edc_bist_cmd_addr_reg = EDC_REG_T5(EDC_H_BIST_CMD_ADDR_A, idx);
  193. edc_bist_cmd_len_reg = EDC_REG_T5(EDC_H_BIST_CMD_LEN_A, idx);
  194. edc_bist_cmd_data_pattern = EDC_REG_T5(EDC_H_BIST_DATA_PATTERN_A, idx);
  195. edc_bist_status_rdata_reg = EDC_REG_T5(EDC_H_BIST_STATUS_RDATA_A, idx);
  196. #undef EDC_REG_T5
  197. #undef EDC_STRIDE_T5
  198. if (csio_rd_reg32(hw, edc_bist_cmd_reg) & START_BIST_F)
  199. return -EBUSY;
  200. csio_wr_reg32(hw, addr & ~0x3fU, edc_bist_cmd_addr_reg);
  201. csio_wr_reg32(hw, 64, edc_bist_cmd_len_reg);
  202. csio_wr_reg32(hw, 0xc, edc_bist_cmd_data_pattern);
  203. csio_wr_reg32(hw, BIST_OPCODE_V(1) | START_BIST_F | BIST_CMD_GAP_V(1),
  204. edc_bist_cmd_reg);
  205. i = csio_hw_wait_op_done_val(hw, edc_bist_cmd_reg, START_BIST_F,
  206. 0, 10, 1, NULL);
  207. if (i)
  208. return i;
  209. #define EDC_DATA(i) (EDC_BIST_STATUS_REG(EDC_BIST_STATUS_RDATA_A, i) + idx)
  210. for (i = 15; i >= 0; i--)
  211. *data++ = htonl(csio_rd_reg32(hw, EDC_DATA(i)));
  212. if (ecc)
  213. *ecc = csio_rd_reg64(hw, EDC_DATA(16));
  214. #undef EDC_DATA
  215. return 0;
  216. }
  217. /*
  218. * csio_t5_memory_rw - read/write EDC 0, EDC 1 or MC via PCIE memory window
  219. * @hw: the csio_hw
  220. * @win: PCI-E memory Window to use
  221. * @mtype: memory type: MEM_EDC0, MEM_EDC1, MEM_MC0 (or MEM_MC) or MEM_MC1
  222. * @addr: address within indicated memory type
  223. * @len: amount of memory to transfer
  224. * @buf: host memory buffer
  225. * @dir: direction of transfer 1 => read, 0 => write
  226. *
  227. * Reads/writes an [almost] arbitrary memory region in the firmware: the
  228. * firmware memory address, length and host buffer must be aligned on
  229. * 32-bit boudaries. The memory is transferred as a raw byte sequence
  230. * from/to the firmware's memory. If this memory contains data
  231. * structures which contain multi-byte integers, it's the callers
  232. * responsibility to perform appropriate byte order conversions.
  233. */
  234. static int
  235. csio_t5_memory_rw(struct csio_hw *hw, u32 win, int mtype, u32 addr,
  236. u32 len, uint32_t *buf, int dir)
  237. {
  238. u32 pos, start, offset, memoffset;
  239. u32 edc_size, mc_size, win_pf, mem_reg, mem_aperture, mem_base;
  240. /*
  241. * Argument sanity checks ...
  242. */
  243. if ((addr & 0x3) || (len & 0x3))
  244. return -EINVAL;
  245. /* Offset into the region of memory which is being accessed
  246. * MEM_EDC0 = 0
  247. * MEM_EDC1 = 1
  248. * MEM_MC = 2 -- T4
  249. * MEM_MC0 = 2 -- For T5
  250. * MEM_MC1 = 3 -- For T5
  251. */
  252. edc_size = EDRAM0_SIZE_G(csio_rd_reg32(hw, MA_EDRAM0_BAR_A));
  253. if (mtype != MEM_MC1)
  254. memoffset = (mtype * (edc_size * 1024 * 1024));
  255. else {
  256. mc_size = EXT_MEM_SIZE_G(csio_rd_reg32(hw,
  257. MA_EXT_MEMORY_BAR_A));
  258. memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024;
  259. }
  260. /* Determine the PCIE_MEM_ACCESS_OFFSET */
  261. addr = addr + memoffset;
  262. /*
  263. * Each PCI-E Memory Window is programmed with a window size -- or
  264. * "aperture" -- which controls the granularity of its mapping onto
  265. * adapter memory. We need to grab that aperture in order to know
  266. * how to use the specified window. The window is also programmed
  267. * with the base address of the Memory Window in BAR0's address
  268. * space. For T4 this is an absolute PCI-E Bus Address. For T5
  269. * the address is relative to BAR0.
  270. */
  271. mem_reg = csio_rd_reg32(hw,
  272. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, win));
  273. mem_aperture = 1 << (WINDOW_V(mem_reg) + 10);
  274. mem_base = PCIEOFST_G(mem_reg) << 10;
  275. start = addr & ~(mem_aperture-1);
  276. offset = addr - start;
  277. win_pf = PFNUM_V(hw->pfn);
  278. csio_dbg(hw, "csio_t5_memory_rw: mem_reg: 0x%x, mem_aperture: 0x%x\n",
  279. mem_reg, mem_aperture);
  280. csio_dbg(hw, "csio_t5_memory_rw: mem_base: 0x%x, mem_offset: 0x%x\n",
  281. mem_base, memoffset);
  282. csio_dbg(hw, "csio_t5_memory_rw: start:0x%x, offset:0x%x, win_pf:%d\n",
  283. start, offset, win_pf);
  284. csio_dbg(hw, "csio_t5_memory_rw: mtype: %d, addr: 0x%x, len: %d\n",
  285. mtype, addr, len);
  286. for (pos = start; len > 0; pos += mem_aperture, offset = 0) {
  287. /*
  288. * Move PCI-E Memory Window to our current transfer
  289. * position. Read it back to ensure that changes propagate
  290. * before we attempt to use the new value.
  291. */
  292. csio_wr_reg32(hw, pos | win_pf,
  293. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
  294. csio_rd_reg32(hw,
  295. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
  296. while (offset < mem_aperture && len > 0) {
  297. if (dir)
  298. *buf++ = csio_rd_reg32(hw, mem_base + offset);
  299. else
  300. csio_wr_reg32(hw, *buf++, mem_base + offset);
  301. offset += sizeof(__be32);
  302. len -= sizeof(__be32);
  303. }
  304. }
  305. return 0;
  306. }
  307. /*
  308. * csio_t5_dfs_create_ext_mem - setup debugfs for MC0 or MC1 to read the values
  309. * @hw: the csio_hw
  310. *
  311. * This function creates files in the debugfs with external memory region
  312. * MC0 & MC1.
  313. */
  314. static void
  315. csio_t5_dfs_create_ext_mem(struct csio_hw *hw)
  316. {
  317. u32 size;
  318. int i = csio_rd_reg32(hw, MA_TARGET_MEM_ENABLE_A);
  319. if (i & EXT_MEM_ENABLE_F) {
  320. size = csio_rd_reg32(hw, MA_EXT_MEMORY_BAR_A);
  321. csio_add_debugfs_mem(hw, "mc0", MEM_MC0,
  322. EXT_MEM_SIZE_G(size));
  323. }
  324. if (i & EXT_MEM1_ENABLE_F) {
  325. size = csio_rd_reg32(hw, MA_EXT_MEMORY1_BAR_A);
  326. csio_add_debugfs_mem(hw, "mc1", MEM_MC1,
  327. EXT_MEM_SIZE_G(size));
  328. }
  329. }
  330. /* T5 adapter specific function */
  331. struct csio_hw_chip_ops t5_ops = {
  332. .chip_set_mem_win = csio_t5_set_mem_win,
  333. .chip_pcie_intr_handler = csio_t5_pcie_intr_handler,
  334. .chip_flash_cfg_addr = csio_t5_flash_cfg_addr,
  335. .chip_mc_read = csio_t5_mc_read,
  336. .chip_edc_read = csio_t5_edc_read,
  337. .chip_memory_rw = csio_t5_memory_rw,
  338. .chip_dfs_create_ext_mem = csio_t5_dfs_create_ext_mem,
  339. };