1 /**********************************************************************
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
7 * Copyright (c) 2003-2015 Cavium, Inc.
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.
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
19 * This file may also be available under a different license from Cavium.
20 * Contact Cavium, Inc. for more information
21 **********************************************************************/
22 #include <linux/pci.h>
23 #include <linux/netdevice.h>
24 #include "liquidio_common.h"
25 #include "octeon_droq.h"
26 #include "octeon_iq.h"
27 #include "response_manager.h"
28 #include "octeon_device.h"
29 #include "octeon_main.h"
30 #include "cn66xx_regs.h"
31 #include "cn66xx_device.h"
33 int lio_cn6xxx_soft_reset(struct octeon_device
*oct
)
35 octeon_write_csr64(oct
, CN6XXX_WIN_WR_MASK_REG
, 0xFF);
37 dev_dbg(&oct
->pci_dev
->dev
, "BIST enabled for soft reset\n");
39 lio_pci_writeq(oct
, 1, CN6XXX_CIU_SOFT_BIST
);
40 octeon_write_csr64(oct
, CN6XXX_SLI_SCRATCH1
, 0x1234ULL
);
42 lio_pci_readq(oct
, CN6XXX_CIU_SOFT_RST
);
43 lio_pci_writeq(oct
, 1, CN6XXX_CIU_SOFT_RST
);
45 /* make sure that the reset is written before starting timer */
48 /* Wait for 10ms as Octeon resets. */
51 if (octeon_read_csr64(oct
, CN6XXX_SLI_SCRATCH1
) == 0x1234ULL
) {
52 dev_err(&oct
->pci_dev
->dev
, "Soft reset failed\n");
56 dev_dbg(&oct
->pci_dev
->dev
, "Reset completed\n");
57 octeon_write_csr64(oct
, CN6XXX_WIN_WR_MASK_REG
, 0xFF);
62 void lio_cn6xxx_enable_error_reporting(struct octeon_device
*oct
)
66 pci_read_config_dword(oct
->pci_dev
, CN6XXX_PCIE_DEVCTL
, &val
);
67 if (val
& 0x000c0000) {
68 dev_err(&oct
->pci_dev
->dev
, "PCI-E Link error detected: 0x%08x\n",
72 val
|= 0xf; /* Enable Link error reporting */
74 dev_dbg(&oct
->pci_dev
->dev
, "Enabling PCI-E error reporting..\n");
75 pci_write_config_dword(oct
->pci_dev
, CN6XXX_PCIE_DEVCTL
, val
);
78 void lio_cn6xxx_setup_pcie_mps(struct octeon_device
*oct
,
79 enum octeon_pcie_mps mps
)
84 /* Read config register for MPS */
85 pci_read_config_dword(oct
->pci_dev
, CN6XXX_PCIE_DEVCTL
, &val
);
87 if (mps
== PCIE_MPS_DEFAULT
) {
88 mps
= ((val
& (0x7 << 5)) >> 5);
90 val
&= ~(0x7 << 5); /* Turn off any MPS bits */
91 val
|= (mps
<< 5); /* Set MPS */
92 pci_write_config_dword(oct
->pci_dev
, CN6XXX_PCIE_DEVCTL
, val
);
95 /* Set MPS in DPI_SLI_PRT0_CFG to the same value. */
96 r64
= lio_pci_readq(oct
, CN6XXX_DPI_SLI_PRTX_CFG(oct
->pcie_port
));
98 lio_pci_writeq(oct
, r64
, CN6XXX_DPI_SLI_PRTX_CFG(oct
->pcie_port
));
101 void lio_cn6xxx_setup_pcie_mrrs(struct octeon_device
*oct
,
102 enum octeon_pcie_mrrs mrrs
)
107 /* Read config register for MRRS */
108 pci_read_config_dword(oct
->pci_dev
, CN6XXX_PCIE_DEVCTL
, &val
);
110 if (mrrs
== PCIE_MRRS_DEFAULT
) {
111 mrrs
= ((val
& (0x7 << 12)) >> 12);
113 val
&= ~(0x7 << 12); /* Turn off any MRRS bits */
114 val
|= (mrrs
<< 12); /* Set MRRS */
115 pci_write_config_dword(oct
->pci_dev
, CN6XXX_PCIE_DEVCTL
, val
);
118 /* Set MRRS in SLI_S2M_PORT0_CTL to the same value. */
119 r64
= octeon_read_csr64(oct
, CN6XXX_SLI_S2M_PORTX_CTL(oct
->pcie_port
));
121 octeon_write_csr64(oct
, CN6XXX_SLI_S2M_PORTX_CTL(oct
->pcie_port
), r64
);
123 /* Set MRRS in DPI_SLI_PRT0_CFG to the same value. */
124 r64
= lio_pci_readq(oct
, CN6XXX_DPI_SLI_PRTX_CFG(oct
->pcie_port
));
126 lio_pci_writeq(oct
, r64
, CN6XXX_DPI_SLI_PRTX_CFG(oct
->pcie_port
));
129 u32
lio_cn6xxx_coprocessor_clock(struct octeon_device
*oct
)
131 /* Bits 29:24 of MIO_RST_BOOT holds the ref. clock multiplier
134 return ((lio_pci_readq(oct
, CN6XXX_MIO_RST_BOOT
) >> 24) & 0x3f) * 50;
137 u32
lio_cn6xxx_get_oq_ticks(struct octeon_device
*oct
,
140 /* This gives the SLI clock per microsec */
141 u32 oqticks_per_us
= lio_cn6xxx_coprocessor_clock(oct
);
143 /* core clock per us / oq ticks will be fractional. TO avoid that
144 * we use the method below.
147 /* This gives the clock cycles per millisecond */
148 oqticks_per_us
*= 1000;
150 /* This gives the oq ticks (1024 core clock cycles) per millisecond */
151 oqticks_per_us
/= 1024;
153 /* time_intr is in microseconds. The next 2 steps gives the oq ticks
154 * corressponding to time_intr.
156 oqticks_per_us
*= time_intr_in_us
;
157 oqticks_per_us
/= 1000;
159 return oqticks_per_us
;
162 void lio_cn6xxx_setup_global_input_regs(struct octeon_device
*oct
)
164 /* Select Round-Robin Arb, ES, RO, NS for Input Queues */
165 octeon_write_csr(oct
, CN6XXX_SLI_PKT_INPUT_CONTROL
,
166 CN6XXX_INPUT_CTL_MASK
);
168 /* Instruction Read Size - Max 4 instructions per PCIE Read */
169 octeon_write_csr64(oct
, CN6XXX_SLI_PKT_INSTR_RD_SIZE
,
170 0xFFFFFFFFFFFFFFFFULL
);
172 /* Select PCIE Port for all Input rings. */
173 octeon_write_csr64(oct
, CN6XXX_SLI_IN_PCIE_PORT
,
174 (oct
->pcie_port
* 0x5555555555555555ULL
));
177 static void lio_cn66xx_setup_pkt_ctl_regs(struct octeon_device
*oct
)
181 struct octeon_cn6xxx
*cn6xxx
= (struct octeon_cn6xxx
*)oct
->chip
;
183 pktctl
= octeon_read_csr64(oct
, CN6XXX_SLI_PKT_CTL
);
186 if (CFG_GET_OQ_MAX_Q(cn6xxx
->conf
) <= 4)
187 /* Disable RING_EN if only upto 4 rings are used. */
192 if (CFG_GET_IS_SLI_BP_ON(cn6xxx
->conf
))
195 /* Disable per-port backpressure. */
197 octeon_write_csr64(oct
, CN6XXX_SLI_PKT_CTL
, pktctl
);
200 void lio_cn6xxx_setup_global_output_regs(struct octeon_device
*oct
)
203 struct octeon_cn6xxx
*cn6xxx
= (struct octeon_cn6xxx
*)oct
->chip
;
205 /* / Select PCI-E Port for all Output queues */
206 octeon_write_csr64(oct
, CN6XXX_SLI_PKT_PCIE_PORT64
,
207 (oct
->pcie_port
* 0x5555555555555555ULL
));
209 if (CFG_GET_IS_SLI_BP_ON(cn6xxx
->conf
)) {
210 octeon_write_csr64(oct
, CN6XXX_SLI_OQ_WMARK
, 32);
212 /* / Set Output queue watermark to 0 to disable backpressure */
213 octeon_write_csr64(oct
, CN6XXX_SLI_OQ_WMARK
, 0);
216 /* / Select Info Ptr for length & data */
217 octeon_write_csr(oct
, CN6XXX_SLI_PKT_IPTR
, 0xFFFFFFFF);
219 /* / Select Packet count instead of bytes for SLI_PKTi_CNTS[CNT] */
220 octeon_write_csr(oct
, CN6XXX_SLI_PKT_OUT_BMODE
, 0);
222 /* Select ES, RO, NS setting from register for Output Queue Packet
225 octeon_write_csr(oct
, CN6XXX_SLI_PKT_DPADDR
, 0xFFFFFFFF);
227 /* No Relaxed Ordering, No Snoop, 64-bit swap for Output
230 octeon_write_csr(oct
, CN6XXX_SLI_PKT_SLIST_ROR
, 0);
231 octeon_write_csr(oct
, CN6XXX_SLI_PKT_SLIST_NS
, 0);
233 /* / ENDIAN_SPECIFIC CHANGES - 0 works for LE. */
234 #ifdef __BIG_ENDIAN_BITFIELD
235 octeon_write_csr64(oct
, CN6XXX_SLI_PKT_SLIST_ES64
,
236 0x5555555555555555ULL
);
238 octeon_write_csr64(oct
, CN6XXX_SLI_PKT_SLIST_ES64
, 0ULL);
241 /* / No Relaxed Ordering, No Snoop, 64-bit swap for Output Queue Data */
242 octeon_write_csr(oct
, CN6XXX_SLI_PKT_DATA_OUT_ROR
, 0);
243 octeon_write_csr(oct
, CN6XXX_SLI_PKT_DATA_OUT_NS
, 0);
244 octeon_write_csr64(oct
, CN6XXX_SLI_PKT_DATA_OUT_ES64
,
245 0x5555555555555555ULL
);
247 /* / Set up interrupt packet and time threshold */
248 octeon_write_csr(oct
, CN6XXX_SLI_OQ_INT_LEVEL_PKTS
,
249 (u32
)CFG_GET_OQ_INTR_PKT(cn6xxx
->conf
));
251 lio_cn6xxx_get_oq_ticks(oct
, (u32
)
252 CFG_GET_OQ_INTR_TIME(cn6xxx
->conf
));
254 octeon_write_csr(oct
, CN6XXX_SLI_OQ_INT_LEVEL_TIME
, time_threshold
);
257 static int lio_cn6xxx_setup_device_regs(struct octeon_device
*oct
)
259 lio_cn6xxx_setup_pcie_mps(oct
, PCIE_MPS_DEFAULT
);
260 lio_cn6xxx_setup_pcie_mrrs(oct
, PCIE_MRRS_512B
);
261 lio_cn6xxx_enable_error_reporting(oct
);
263 lio_cn6xxx_setup_global_input_regs(oct
);
264 lio_cn66xx_setup_pkt_ctl_regs(oct
);
265 lio_cn6xxx_setup_global_output_regs(oct
);
267 /* Default error timeout value should be 0x200000 to avoid host hang
268 * when reads invalid register
270 octeon_write_csr64(oct
, CN6XXX_SLI_WINDOW_CTL
, 0x200000ULL
);
274 void lio_cn6xxx_setup_iq_regs(struct octeon_device
*oct
, u32 iq_no
)
276 struct octeon_instr_queue
*iq
= oct
->instr_queue
[iq_no
];
278 /* Disable Packet-by-Packet mode; No Parse Mode or Skip length */
279 octeon_write_csr64(oct
, CN6XXX_SLI_IQ_PKT_INSTR_HDR64(iq_no
), 0);
281 /* Write the start of the input queue's ring and its size */
282 octeon_write_csr64(oct
, CN6XXX_SLI_IQ_BASE_ADDR64(iq_no
),
284 octeon_write_csr(oct
, CN6XXX_SLI_IQ_SIZE(iq_no
), iq
->max_count
);
286 /* Remember the doorbell & instruction count register addr for this
289 iq
->doorbell_reg
= oct
->mmio
[0].hw_addr
+ CN6XXX_SLI_IQ_DOORBELL(iq_no
);
290 iq
->inst_cnt_reg
= oct
->mmio
[0].hw_addr
291 + CN6XXX_SLI_IQ_INSTR_COUNT(iq_no
);
292 dev_dbg(&oct
->pci_dev
->dev
, "InstQ[%d]:dbell reg @ 0x%p instcnt_reg @ 0x%p\n",
293 iq_no
, iq
->doorbell_reg
, iq
->inst_cnt_reg
);
295 /* Store the current instruction counter
296 * (used in flush_iq calculation)
298 iq
->reset_instr_cnt
= readl(iq
->inst_cnt_reg
);
301 static void lio_cn66xx_setup_iq_regs(struct octeon_device
*oct
, u32 iq_no
)
303 lio_cn6xxx_setup_iq_regs(oct
, iq_no
);
305 /* Backpressure for this queue - WMARK set to all F's. This effectively
306 * disables the backpressure mechanism.
308 octeon_write_csr64(oct
, CN66XX_SLI_IQ_BP64(iq_no
),
309 (0xFFFFFFFFULL
<< 32));
312 void lio_cn6xxx_setup_oq_regs(struct octeon_device
*oct
, u32 oq_no
)
315 struct octeon_droq
*droq
= oct
->droq
[oq_no
];
317 octeon_write_csr64(oct
, CN6XXX_SLI_OQ_BASE_ADDR64(oq_no
),
318 droq
->desc_ring_dma
);
319 octeon_write_csr(oct
, CN6XXX_SLI_OQ_SIZE(oq_no
), droq
->max_count
);
321 octeon_write_csr(oct
, CN6XXX_SLI_OQ_BUFF_INFO_SIZE(oq_no
),
322 (droq
->buffer_size
| (OCT_RH_SIZE
<< 16)));
324 /* Get the mapped address of the pkt_sent and pkts_credit regs */
325 droq
->pkts_sent_reg
=
326 oct
->mmio
[0].hw_addr
+ CN6XXX_SLI_OQ_PKTS_SENT(oq_no
);
327 droq
->pkts_credit_reg
=
328 oct
->mmio
[0].hw_addr
+ CN6XXX_SLI_OQ_PKTS_CREDIT(oq_no
);
330 /* Enable this output queue to generate Packet Timer Interrupt */
331 intr
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_TIME_INT_ENB
);
332 intr
|= (1 << oq_no
);
333 octeon_write_csr(oct
, CN6XXX_SLI_PKT_TIME_INT_ENB
, intr
);
335 /* Enable this output queue to generate Packet Timer Interrupt */
336 intr
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_CNT_INT_ENB
);
337 intr
|= (1 << oq_no
);
338 octeon_write_csr(oct
, CN6XXX_SLI_PKT_CNT_INT_ENB
, intr
);
341 int lio_cn6xxx_enable_io_queues(struct octeon_device
*oct
)
345 mask
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_INSTR_SIZE
);
346 mask
|= oct
->io_qmask
.iq64B
;
347 octeon_write_csr(oct
, CN6XXX_SLI_PKT_INSTR_SIZE
, mask
);
349 mask
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_INSTR_ENB
);
350 mask
|= oct
->io_qmask
.iq
;
351 octeon_write_csr(oct
, CN6XXX_SLI_PKT_INSTR_ENB
, mask
);
353 mask
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_OUT_ENB
);
354 mask
|= oct
->io_qmask
.oq
;
355 octeon_write_csr(oct
, CN6XXX_SLI_PKT_OUT_ENB
, mask
);
360 void lio_cn6xxx_disable_io_queues(struct octeon_device
*oct
)
366 /* Reset the Enable bits for Input Queues. */
367 mask
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_INSTR_ENB
);
368 mask
^= oct
->io_qmask
.iq
;
369 octeon_write_csr(oct
, CN6XXX_SLI_PKT_INSTR_ENB
, mask
);
371 /* Wait until hardware indicates that the queues are out of reset. */
372 mask
= (u32
)oct
->io_qmask
.iq
;
373 d32
= octeon_read_csr(oct
, CN6XXX_SLI_PORT_IN_RST_IQ
);
374 while (((d32
& mask
) != mask
) && loop
--) {
375 d32
= octeon_read_csr(oct
, CN6XXX_SLI_PORT_IN_RST_IQ
);
376 schedule_timeout_uninterruptible(1);
379 /* Reset the doorbell register for each Input queue. */
380 for (i
= 0; i
< MAX_OCTEON_INSTR_QUEUES(oct
); i
++) {
381 if (!(oct
->io_qmask
.iq
& (1ULL << i
)))
383 octeon_write_csr(oct
, CN6XXX_SLI_IQ_DOORBELL(i
), 0xFFFFFFFF);
384 d32
= octeon_read_csr(oct
, CN6XXX_SLI_IQ_DOORBELL(i
));
387 /* Reset the Enable bits for Output Queues. */
388 mask
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_OUT_ENB
);
389 mask
^= oct
->io_qmask
.oq
;
390 octeon_write_csr(oct
, CN6XXX_SLI_PKT_OUT_ENB
, mask
);
392 /* Wait until hardware indicates that the queues are out of reset. */
394 mask
= (u32
)oct
->io_qmask
.oq
;
395 d32
= octeon_read_csr(oct
, CN6XXX_SLI_PORT_IN_RST_OQ
);
396 while (((d32
& mask
) != mask
) && loop
--) {
397 d32
= octeon_read_csr(oct
, CN6XXX_SLI_PORT_IN_RST_OQ
);
398 schedule_timeout_uninterruptible(1);
402 /* Reset the doorbell register for each Output queue. */
403 /* for (i = 0; i < oct->num_oqs; i++) { */
404 for (i
= 0; i
< MAX_OCTEON_OUTPUT_QUEUES(oct
); i
++) {
405 if (!(oct
->io_qmask
.oq
& (1ULL << i
)))
407 octeon_write_csr(oct
, CN6XXX_SLI_OQ_PKTS_CREDIT(i
), 0xFFFFFFFF);
408 d32
= octeon_read_csr(oct
, CN6XXX_SLI_OQ_PKTS_CREDIT(i
));
410 d32
= octeon_read_csr(oct
, CN6XXX_SLI_OQ_PKTS_SENT(i
));
411 octeon_write_csr(oct
, CN6XXX_SLI_OQ_PKTS_SENT(i
), d32
);
414 d32
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_CNT_INT
);
416 octeon_write_csr(oct
, CN6XXX_SLI_PKT_CNT_INT
, d32
);
418 d32
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_TIME_INT
);
420 octeon_write_csr(oct
, CN6XXX_SLI_PKT_TIME_INT
, d32
);
424 lio_cn6xxx_bar1_idx_setup(struct octeon_device
*oct
,
432 bar1
= lio_pci_readq(oct
, CN6XXX_BAR1_REG(idx
, oct
->pcie_port
));
433 lio_pci_writeq(oct
, (bar1
& 0xFFFFFFFEULL
),
434 CN6XXX_BAR1_REG(idx
, oct
->pcie_port
));
435 bar1
= lio_pci_readq(oct
, CN6XXX_BAR1_REG(idx
, oct
->pcie_port
));
439 /* Bits 17:4 of the PCI_BAR1_INDEXx stores bits 35:22 of
442 lio_pci_writeq(oct
, (((core_addr
>> 22) << 4) | PCI_BAR1_MASK
),
443 CN6XXX_BAR1_REG(idx
, oct
->pcie_port
));
445 bar1
= lio_pci_readq(oct
, CN6XXX_BAR1_REG(idx
, oct
->pcie_port
));
448 void lio_cn6xxx_bar1_idx_write(struct octeon_device
*oct
,
452 lio_pci_writeq(oct
, mask
, CN6XXX_BAR1_REG(idx
, oct
->pcie_port
));
455 u32
lio_cn6xxx_bar1_idx_read(struct octeon_device
*oct
, u32 idx
)
457 return (u32
)lio_pci_readq(oct
, CN6XXX_BAR1_REG(idx
, oct
->pcie_port
));
461 lio_cn6xxx_update_read_index(struct octeon_instr_queue
*iq
)
463 u32 new_idx
= readl(iq
->inst_cnt_reg
);
465 /* The new instr cnt reg is a 32-bit counter that can roll over. We have
466 * noted the counter's initial value at init time into
469 if (iq
->reset_instr_cnt
< new_idx
)
470 new_idx
-= iq
->reset_instr_cnt
;
472 new_idx
+= (0xffffffff - iq
->reset_instr_cnt
) + 1;
474 /* Modulo of the new index with the IQ size will give us
477 new_idx
%= iq
->max_count
;
482 void lio_cn6xxx_enable_interrupt(struct octeon_device
*oct
,
483 u8 unused
__attribute__((unused
)))
485 struct octeon_cn6xxx
*cn6xxx
= (struct octeon_cn6xxx
*)oct
->chip
;
486 u64 mask
= cn6xxx
->intr_mask64
| CN6XXX_INTR_DMA0_FORCE
;
488 /* Enable Interrupt */
489 writeq(mask
, cn6xxx
->intr_enb_reg64
);
492 void lio_cn6xxx_disable_interrupt(struct octeon_device
*oct
,
493 u8 unused
__attribute__((unused
)))
495 struct octeon_cn6xxx
*cn6xxx
= (struct octeon_cn6xxx
*)oct
->chip
;
497 /* Disable Interrupts */
498 writeq(0, cn6xxx
->intr_enb_reg64
);
500 /* make sure interrupts are really disabled */
504 static void lio_cn6xxx_get_pcie_qlmport(struct octeon_device
*oct
)
506 /* CN63xx Pass2 and newer parts implements the SLI_MAC_NUMBER register
507 * to determine the PCIE port #
509 oct
->pcie_port
= octeon_read_csr(oct
, CN6XXX_SLI_MAC_NUMBER
) & 0xff;
511 dev_dbg(&oct
->pci_dev
->dev
, "Using PCIE Port %d\n", oct
->pcie_port
);
515 lio_cn6xxx_process_pcie_error_intr(struct octeon_device
*oct
, u64 intr64
)
517 dev_err(&oct
->pci_dev
->dev
, "Error Intr: 0x%016llx\n",
521 static int lio_cn6xxx_process_droq_intr_regs(struct octeon_device
*oct
)
523 struct octeon_droq
*droq
;
525 u32 pkt_count
, droq_time_mask
, droq_mask
, droq_int_enb
;
526 u32 droq_cnt_enb
, droq_cnt_mask
;
528 droq_cnt_enb
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_CNT_INT_ENB
);
529 droq_cnt_mask
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_CNT_INT
);
530 droq_mask
= droq_cnt_mask
& droq_cnt_enb
;
532 droq_time_mask
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_TIME_INT
);
533 droq_int_enb
= octeon_read_csr(oct
, CN6XXX_SLI_PKT_TIME_INT_ENB
);
534 droq_mask
|= (droq_time_mask
& droq_int_enb
);
536 droq_mask
&= oct
->io_qmask
.oq
;
540 /* for (oq_no = 0; oq_no < oct->num_oqs; oq_no++) { */
541 for (oq_no
= 0; oq_no
< MAX_OCTEON_OUTPUT_QUEUES(oct
); oq_no
++) {
542 if (!(droq_mask
& (1ULL << oq_no
)))
545 droq
= oct
->droq
[oq_no
];
546 pkt_count
= octeon_droq_check_hw_for_pkts(droq
);
548 oct
->droq_intr
|= (1ULL << oq_no
);
549 if (droq
->ops
.poll_mode
) {
553 struct octeon_cn6xxx
*cn6xxx
=
554 (struct octeon_cn6xxx
*)oct
->chip
;
556 /* disable interrupts for this droq */
558 (&cn6xxx
->lock_for_droq_int_enb_reg
);
559 reg
= CN6XXX_SLI_PKT_TIME_INT_ENB
;
560 value
= octeon_read_csr(oct
, reg
);
561 value
&= ~(1 << oq_no
);
562 octeon_write_csr(oct
, reg
, value
);
563 reg
= CN6XXX_SLI_PKT_CNT_INT_ENB
;
564 value
= octeon_read_csr(oct
, reg
);
565 value
&= ~(1 << oq_no
);
566 octeon_write_csr(oct
, reg
, value
);
568 /* Ensure that the enable register is written.
572 spin_unlock(&cn6xxx
->lock_for_droq_int_enb_reg
);
577 droq_time_mask
&= oct
->io_qmask
.oq
;
578 droq_cnt_mask
&= oct
->io_qmask
.oq
;
580 /* Reset the PKT_CNT/TIME_INT registers. */
582 octeon_write_csr(oct
, CN6XXX_SLI_PKT_TIME_INT
, droq_time_mask
);
584 if (droq_cnt_mask
) /* reset PKT_CNT register:66xx */
585 octeon_write_csr(oct
, CN6XXX_SLI_PKT_CNT_INT
, droq_cnt_mask
);
590 irqreturn_t
lio_cn6xxx_process_interrupt_regs(void *dev
)
592 struct octeon_device
*oct
= (struct octeon_device
*)dev
;
593 struct octeon_cn6xxx
*cn6xxx
= (struct octeon_cn6xxx
*)oct
->chip
;
596 intr64
= readq(cn6xxx
->intr_sum_reg64
);
598 /* If our device has interrupted, then proceed.
599 * Also check for all f's if interrupt was triggered on an error
600 * and the PCI read fails.
602 if (!intr64
|| (intr64
== 0xFFFFFFFFFFFFFFFFULL
))
607 if (intr64
& CN6XXX_INTR_ERR
)
608 lio_cn6xxx_process_pcie_error_intr(oct
, intr64
);
610 if (intr64
& CN6XXX_INTR_PKT_DATA
) {
611 lio_cn6xxx_process_droq_intr_regs(oct
);
612 oct
->int_status
|= OCT_DEV_INTR_PKT_DATA
;
615 if (intr64
& CN6XXX_INTR_DMA0_FORCE
)
616 oct
->int_status
|= OCT_DEV_INTR_DMA0_FORCE
;
618 if (intr64
& CN6XXX_INTR_DMA1_FORCE
)
619 oct
->int_status
|= OCT_DEV_INTR_DMA1_FORCE
;
621 /* Clear the current interrupts */
622 writeq(intr64
, cn6xxx
->intr_sum_reg64
);
627 void lio_cn6xxx_setup_reg_address(struct octeon_device
*oct
,
629 struct octeon_reg_list
*reg_list
)
631 u8 __iomem
*bar0_pciaddr
= oct
->mmio
[0].hw_addr
;
632 struct octeon_cn6xxx
*cn6xxx
= (struct octeon_cn6xxx
*)chip
;
634 reg_list
->pci_win_wr_addr_hi
=
635 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_WR_ADDR_HI
);
636 reg_list
->pci_win_wr_addr_lo
=
637 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_WR_ADDR_LO
);
638 reg_list
->pci_win_wr_addr
=
639 (u64 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_WR_ADDR64
);
641 reg_list
->pci_win_rd_addr_hi
=
642 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_RD_ADDR_HI
);
643 reg_list
->pci_win_rd_addr_lo
=
644 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_RD_ADDR_LO
);
645 reg_list
->pci_win_rd_addr
=
646 (u64 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_RD_ADDR64
);
648 reg_list
->pci_win_wr_data_hi
=
649 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_WR_DATA_HI
);
650 reg_list
->pci_win_wr_data_lo
=
651 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_WR_DATA_LO
);
652 reg_list
->pci_win_wr_data
=
653 (u64 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_WR_DATA64
);
655 reg_list
->pci_win_rd_data_hi
=
656 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_RD_DATA_HI
);
657 reg_list
->pci_win_rd_data_lo
=
658 (u32 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_RD_DATA_LO
);
659 reg_list
->pci_win_rd_data
=
660 (u64 __iomem
*)(bar0_pciaddr
+ CN6XXX_WIN_RD_DATA64
);
662 lio_cn6xxx_get_pcie_qlmport(oct
);
664 cn6xxx
->intr_sum_reg64
= bar0_pciaddr
+ CN6XXX_SLI_INT_SUM64
;
665 cn6xxx
->intr_mask64
= CN6XXX_INTR_MASK
;
666 cn6xxx
->intr_enb_reg64
=
667 bar0_pciaddr
+ CN6XXX_SLI_INT_ENB64(oct
->pcie_port
);
670 int lio_setup_cn66xx_octeon_device(struct octeon_device
*oct
)
672 struct octeon_cn6xxx
*cn6xxx
= (struct octeon_cn6xxx
*)oct
->chip
;
674 if (octeon_map_pci_barx(oct
, 0, 0))
677 if (octeon_map_pci_barx(oct
, 1, MAX_BAR1_IOREMAP_SIZE
)) {
678 dev_err(&oct
->pci_dev
->dev
, "%s CN66XX BAR1 map failed\n",
680 octeon_unmap_pci_barx(oct
, 0);
684 spin_lock_init(&cn6xxx
->lock_for_droq_int_enb_reg
);
686 oct
->fn_list
.setup_iq_regs
= lio_cn66xx_setup_iq_regs
;
687 oct
->fn_list
.setup_oq_regs
= lio_cn6xxx_setup_oq_regs
;
689 oct
->fn_list
.soft_reset
= lio_cn6xxx_soft_reset
;
690 oct
->fn_list
.setup_device_regs
= lio_cn6xxx_setup_device_regs
;
691 oct
->fn_list
.update_iq_read_idx
= lio_cn6xxx_update_read_index
;
693 oct
->fn_list
.bar1_idx_setup
= lio_cn6xxx_bar1_idx_setup
;
694 oct
->fn_list
.bar1_idx_write
= lio_cn6xxx_bar1_idx_write
;
695 oct
->fn_list
.bar1_idx_read
= lio_cn6xxx_bar1_idx_read
;
697 oct
->fn_list
.process_interrupt_regs
= lio_cn6xxx_process_interrupt_regs
;
698 oct
->fn_list
.enable_interrupt
= lio_cn6xxx_enable_interrupt
;
699 oct
->fn_list
.disable_interrupt
= lio_cn6xxx_disable_interrupt
;
701 oct
->fn_list
.enable_io_queues
= lio_cn6xxx_enable_io_queues
;
702 oct
->fn_list
.disable_io_queues
= lio_cn6xxx_disable_io_queues
;
704 lio_cn6xxx_setup_reg_address(oct
, oct
->chip
, &oct
->reg_list
);
706 cn6xxx
->conf
= (struct octeon_config
*)
707 oct_get_config_info(oct
, LIO_210SV
);
709 dev_err(&oct
->pci_dev
->dev
, "%s No Config found for CN66XX\n",
711 octeon_unmap_pci_barx(oct
, 0);
712 octeon_unmap_pci_barx(oct
, 1);
716 oct
->coproc_clock_rate
= 1000000ULL * lio_cn6xxx_coprocessor_clock(oct
);
721 int lio_validate_cn6xxx_config_info(struct octeon_device
*oct
,
722 struct octeon_config
*conf6xxx
)
724 /* int total_instrs = 0; */
726 if (CFG_GET_IQ_MAX_Q(conf6xxx
) > CN6XXX_MAX_INPUT_QUEUES
) {
727 dev_err(&oct
->pci_dev
->dev
, "%s: Num IQ (%d) exceeds Max (%d)\n",
728 __func__
, CFG_GET_IQ_MAX_Q(conf6xxx
),
729 CN6XXX_MAX_INPUT_QUEUES
);
733 if (CFG_GET_OQ_MAX_Q(conf6xxx
) > CN6XXX_MAX_OUTPUT_QUEUES
) {
734 dev_err(&oct
->pci_dev
->dev
, "%s: Num OQ (%d) exceeds Max (%d)\n",
735 __func__
, CFG_GET_OQ_MAX_Q(conf6xxx
),
736 CN6XXX_MAX_OUTPUT_QUEUES
);
740 if (CFG_GET_IQ_INSTR_TYPE(conf6xxx
) != OCTEON_32BYTE_INSTR
&&
741 CFG_GET_IQ_INSTR_TYPE(conf6xxx
) != OCTEON_64BYTE_INSTR
) {
742 dev_err(&oct
->pci_dev
->dev
, "%s: Invalid instr type for IQ\n",
746 if (!(CFG_GET_OQ_INFO_PTR(conf6xxx
)) ||
747 !(CFG_GET_OQ_REFILL_THRESHOLD(conf6xxx
))) {
748 dev_err(&oct
->pci_dev
->dev
, "%s: Invalid parameter for OQ\n",
753 if (!(CFG_GET_OQ_INTR_TIME(conf6xxx
))) {
754 dev_err(&oct
->pci_dev
->dev
, "%s: No Time Interrupt for OQ\n",