cn68xx_device.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more details.
  17. ***********************************************************************/
  18. #include <linux/pci.h>
  19. #include <linux/netdevice.h>
  20. #include "liquidio_common.h"
  21. #include "octeon_droq.h"
  22. #include "octeon_iq.h"
  23. #include "response_manager.h"
  24. #include "octeon_device.h"
  25. #include "octeon_main.h"
  26. #include "cn66xx_regs.h"
  27. #include "cn66xx_device.h"
  28. #include "cn68xx_regs.h"
  29. static void lio_cn68xx_set_dpi_regs(struct octeon_device *oct)
  30. {
  31. u32 i;
  32. u32 fifo_sizes[6] = { 3, 3, 1, 1, 1, 8 };
  33. lio_pci_writeq(oct, CN6XXX_DPI_DMA_CTL_MASK, CN6XXX_DPI_DMA_CONTROL);
  34. dev_dbg(&oct->pci_dev->dev, "DPI_DMA_CONTROL: 0x%016llx\n",
  35. lio_pci_readq(oct, CN6XXX_DPI_DMA_CONTROL));
  36. for (i = 0; i < 6; i++) {
  37. /* Prevent service of instruction queue for all DMA engines
  38. * Engine 5 will remain 0. Engines 0 - 4 will be setup by
  39. * core.
  40. */
  41. lio_pci_writeq(oct, 0, CN6XXX_DPI_DMA_ENG_ENB(i));
  42. lio_pci_writeq(oct, fifo_sizes[i], CN6XXX_DPI_DMA_ENG_BUF(i));
  43. dev_dbg(&oct->pci_dev->dev, "DPI_ENG_BUF%d: 0x%016llx\n", i,
  44. lio_pci_readq(oct, CN6XXX_DPI_DMA_ENG_BUF(i)));
  45. }
  46. /* DPI_SLI_PRT_CFG has MPS and MRRS settings that will be set
  47. * separately.
  48. */
  49. lio_pci_writeq(oct, 1, CN6XXX_DPI_CTL);
  50. dev_dbg(&oct->pci_dev->dev, "DPI_CTL: 0x%016llx\n",
  51. lio_pci_readq(oct, CN6XXX_DPI_CTL));
  52. }
  53. static int lio_cn68xx_soft_reset(struct octeon_device *oct)
  54. {
  55. lio_cn6xxx_soft_reset(oct);
  56. lio_cn68xx_set_dpi_regs(oct);
  57. return 0;
  58. }
  59. static void lio_cn68xx_setup_pkt_ctl_regs(struct octeon_device *oct)
  60. {
  61. struct octeon_cn6xxx *cn68xx = (struct octeon_cn6xxx *)oct->chip;
  62. u64 pktctl, tx_pipe, max_oqs;
  63. pktctl = octeon_read_csr64(oct, CN6XXX_SLI_PKT_CTL);
  64. /* 68XX specific */
  65. max_oqs = CFG_GET_OQ_MAX_Q(CHIP_CONF(oct, cn6xxx));
  66. tx_pipe = octeon_read_csr64(oct, CN68XX_SLI_TX_PIPE);
  67. tx_pipe &= 0xffffffffff00ffffULL; /* clear out NUMP field */
  68. tx_pipe |= max_oqs << 16; /* put max_oqs in NUMP field */
  69. octeon_write_csr64(oct, CN68XX_SLI_TX_PIPE, tx_pipe);
  70. if (CFG_GET_IS_SLI_BP_ON(cn68xx->conf))
  71. pktctl |= 0xF;
  72. else
  73. /* Disable per-port backpressure. */
  74. pktctl &= ~0xF;
  75. octeon_write_csr64(oct, CN6XXX_SLI_PKT_CTL, pktctl);
  76. }
  77. static int lio_cn68xx_setup_device_regs(struct octeon_device *oct)
  78. {
  79. lio_cn6xxx_setup_pcie_mps(oct, PCIE_MPS_DEFAULT);
  80. lio_cn6xxx_setup_pcie_mrrs(oct, PCIE_MRRS_256B);
  81. lio_cn6xxx_enable_error_reporting(oct);
  82. lio_cn6xxx_setup_global_input_regs(oct);
  83. lio_cn68xx_setup_pkt_ctl_regs(oct);
  84. lio_cn6xxx_setup_global_output_regs(oct);
  85. /* Default error timeout value should be 0x200000 to avoid host hang
  86. * when reads invalid register
  87. */
  88. octeon_write_csr64(oct, CN6XXX_SLI_WINDOW_CTL, 0x200000ULL);
  89. return 0;
  90. }
  91. static inline void lio_cn68xx_vendor_message_fix(struct octeon_device *oct)
  92. {
  93. u32 val = 0;
  94. /* Set M_VEND1_DRP and M_VEND0_DRP bits */
  95. pci_read_config_dword(oct->pci_dev, CN6XXX_PCIE_FLTMSK, &val);
  96. val |= 0x3;
  97. pci_write_config_dword(oct->pci_dev, CN6XXX_PCIE_FLTMSK, val);
  98. }
  99. static int lio_is_210nv(struct octeon_device *oct)
  100. {
  101. u64 mio_qlm4_cfg = lio_pci_readq(oct, CN6XXX_MIO_QLM4_CFG);
  102. return ((mio_qlm4_cfg & CN6XXX_MIO_QLM_CFG_MASK) == 0);
  103. }
  104. int lio_setup_cn68xx_octeon_device(struct octeon_device *oct)
  105. {
  106. struct octeon_cn6xxx *cn68xx = (struct octeon_cn6xxx *)oct->chip;
  107. u16 card_type = LIO_410NV;
  108. if (octeon_map_pci_barx(oct, 0, 0))
  109. return 1;
  110. if (octeon_map_pci_barx(oct, 1, MAX_BAR1_IOREMAP_SIZE)) {
  111. dev_err(&oct->pci_dev->dev, "%s CN68XX BAR1 map failed\n",
  112. __func__);
  113. octeon_unmap_pci_barx(oct, 0);
  114. return 1;
  115. }
  116. spin_lock_init(&cn68xx->lock_for_droq_int_enb_reg);
  117. oct->fn_list.setup_iq_regs = lio_cn6xxx_setup_iq_regs;
  118. oct->fn_list.setup_oq_regs = lio_cn6xxx_setup_oq_regs;
  119. oct->fn_list.process_interrupt_regs = lio_cn6xxx_process_interrupt_regs;
  120. oct->fn_list.soft_reset = lio_cn68xx_soft_reset;
  121. oct->fn_list.setup_device_regs = lio_cn68xx_setup_device_regs;
  122. oct->fn_list.update_iq_read_idx = lio_cn6xxx_update_read_index;
  123. oct->fn_list.bar1_idx_setup = lio_cn6xxx_bar1_idx_setup;
  124. oct->fn_list.bar1_idx_write = lio_cn6xxx_bar1_idx_write;
  125. oct->fn_list.bar1_idx_read = lio_cn6xxx_bar1_idx_read;
  126. oct->fn_list.enable_interrupt = lio_cn6xxx_enable_interrupt;
  127. oct->fn_list.disable_interrupt = lio_cn6xxx_disable_interrupt;
  128. oct->fn_list.enable_io_queues = lio_cn6xxx_enable_io_queues;
  129. oct->fn_list.disable_io_queues = lio_cn6xxx_disable_io_queues;
  130. lio_cn6xxx_setup_reg_address(oct, oct->chip, &oct->reg_list);
  131. /* Determine variant of card */
  132. if (lio_is_210nv(oct))
  133. card_type = LIO_210NV;
  134. cn68xx->conf = (struct octeon_config *)
  135. oct_get_config_info(oct, card_type);
  136. if (!cn68xx->conf) {
  137. dev_err(&oct->pci_dev->dev, "%s No Config found for CN68XX %s\n",
  138. __func__,
  139. (card_type == LIO_410NV) ? LIO_410NV_NAME :
  140. LIO_210NV_NAME);
  141. octeon_unmap_pci_barx(oct, 0);
  142. octeon_unmap_pci_barx(oct, 1);
  143. return 1;
  144. }
  145. oct->coproc_clock_rate = 1000000ULL * lio_cn6xxx_coprocessor_clock(oct);
  146. lio_cn68xx_vendor_message_fix(oct);
  147. return 0;
  148. }