1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2a88b5ba8SSam Ravnborg /* psycho_common.c: Code common to PSYCHO and derivative PCI controllers.
3a88b5ba8SSam Ravnborg *
4a88b5ba8SSam Ravnborg * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
5a88b5ba8SSam Ravnborg */
6a88b5ba8SSam Ravnborg #include <linux/kernel.h>
7a88b5ba8SSam Ravnborg #include <linux/interrupt.h>
898fa15f3SAnshuman Khandual #include <linux/numa.h>
9*263291faSRob Herring #include <linux/platform_device.h>
10a88b5ba8SSam Ravnborg
11a88b5ba8SSam Ravnborg #include <asm/upa.h>
12a88b5ba8SSam Ravnborg
13a88b5ba8SSam Ravnborg #include "pci_impl.h"
14a88b5ba8SSam Ravnborg #include "iommu_common.h"
15a88b5ba8SSam Ravnborg #include "psycho_common.h"
16a88b5ba8SSam Ravnborg
17e8dc7c48SSam Ravnborg #define PSYCHO_STRBUF_CTRL_DENAB 0x0000000000000002ULL
18e8dc7c48SSam Ravnborg #define PSYCHO_STCERR_WRITE 0x0000000000000002ULL
19e8dc7c48SSam Ravnborg #define PSYCHO_STCERR_READ 0x0000000000000001ULL
20e8dc7c48SSam Ravnborg #define PSYCHO_STCTAG_PPN 0x0fffffff00000000ULL
21e8dc7c48SSam Ravnborg #define PSYCHO_STCTAG_VPN 0x00000000ffffe000ULL
22e8dc7c48SSam Ravnborg #define PSYCHO_STCTAG_VALID 0x0000000000000002ULL
23e8dc7c48SSam Ravnborg #define PSYCHO_STCTAG_WRITE 0x0000000000000001ULL
24e8dc7c48SSam Ravnborg #define PSYCHO_STCLINE_LINDX 0x0000000001e00000ULL
25e8dc7c48SSam Ravnborg #define PSYCHO_STCLINE_SPTR 0x00000000001f8000ULL
26e8dc7c48SSam Ravnborg #define PSYCHO_STCLINE_LADDR 0x0000000000007f00ULL
27e8dc7c48SSam Ravnborg #define PSYCHO_STCLINE_EPTR 0x00000000000000fcULL
28e8dc7c48SSam Ravnborg #define PSYCHO_STCLINE_VALID 0x0000000000000002ULL
29e8dc7c48SSam Ravnborg #define PSYCHO_STCLINE_FOFN 0x0000000000000001ULL
30a88b5ba8SSam Ravnborg
31a88b5ba8SSam Ravnborg static DEFINE_SPINLOCK(stc_buf_lock);
32a88b5ba8SSam Ravnborg static unsigned long stc_error_buf[128];
33a88b5ba8SSam Ravnborg static unsigned long stc_tag_buf[16];
34a88b5ba8SSam Ravnborg static unsigned long stc_line_buf[16];
35a88b5ba8SSam Ravnborg
psycho_check_stc_error(struct pci_pbm_info * pbm)36a88b5ba8SSam Ravnborg static void psycho_check_stc_error(struct pci_pbm_info *pbm)
37a88b5ba8SSam Ravnborg {
38a88b5ba8SSam Ravnborg unsigned long err_base, tag_base, line_base;
39a88b5ba8SSam Ravnborg struct strbuf *strbuf = &pbm->stc;
40a88b5ba8SSam Ravnborg u64 control;
41a88b5ba8SSam Ravnborg int i;
42a88b5ba8SSam Ravnborg
43a88b5ba8SSam Ravnborg if (!strbuf->strbuf_control)
44a88b5ba8SSam Ravnborg return;
45a88b5ba8SSam Ravnborg
46a88b5ba8SSam Ravnborg err_base = strbuf->strbuf_err_stat;
47a88b5ba8SSam Ravnborg tag_base = strbuf->strbuf_tag_diag;
48a88b5ba8SSam Ravnborg line_base = strbuf->strbuf_line_diag;
49a88b5ba8SSam Ravnborg
50a88b5ba8SSam Ravnborg spin_lock(&stc_buf_lock);
51a88b5ba8SSam Ravnborg
52a88b5ba8SSam Ravnborg /* This is __REALLY__ dangerous. When we put the streaming
53a88b5ba8SSam Ravnborg * buffer into diagnostic mode to probe it's tags and error
54a88b5ba8SSam Ravnborg * status, we _must_ clear all of the line tag valid bits
55a88b5ba8SSam Ravnborg * before re-enabling the streaming buffer. If any dirty data
56a88b5ba8SSam Ravnborg * lives in the STC when we do this, we will end up
57a88b5ba8SSam Ravnborg * invalidating it before it has a chance to reach main
58a88b5ba8SSam Ravnborg * memory.
59a88b5ba8SSam Ravnborg */
60a88b5ba8SSam Ravnborg control = upa_readq(strbuf->strbuf_control);
61a88b5ba8SSam Ravnborg upa_writeq(control | PSYCHO_STRBUF_CTRL_DENAB, strbuf->strbuf_control);
62a88b5ba8SSam Ravnborg for (i = 0; i < 128; i++) {
63a88b5ba8SSam Ravnborg u64 val;
64a88b5ba8SSam Ravnborg
65a88b5ba8SSam Ravnborg val = upa_readq(err_base + (i * 8UL));
66a88b5ba8SSam Ravnborg upa_writeq(0UL, err_base + (i * 8UL));
67a88b5ba8SSam Ravnborg stc_error_buf[i] = val;
68a88b5ba8SSam Ravnborg }
69a88b5ba8SSam Ravnborg for (i = 0; i < 16; i++) {
70a88b5ba8SSam Ravnborg stc_tag_buf[i] = upa_readq(tag_base + (i * 8UL));
71a88b5ba8SSam Ravnborg stc_line_buf[i] = upa_readq(line_base + (i * 8UL));
72a88b5ba8SSam Ravnborg upa_writeq(0UL, tag_base + (i * 8UL));
73a88b5ba8SSam Ravnborg upa_writeq(0UL, line_base + (i * 8UL));
74a88b5ba8SSam Ravnborg }
75a88b5ba8SSam Ravnborg
76a88b5ba8SSam Ravnborg /* OK, state is logged, exit diagnostic mode. */
77a88b5ba8SSam Ravnborg upa_writeq(control, strbuf->strbuf_control);
78a88b5ba8SSam Ravnborg
79a88b5ba8SSam Ravnborg for (i = 0; i < 16; i++) {
80a88b5ba8SSam Ravnborg int j, saw_error, first, last;
81a88b5ba8SSam Ravnborg
82a88b5ba8SSam Ravnborg saw_error = 0;
83a88b5ba8SSam Ravnborg first = i * 8;
84a88b5ba8SSam Ravnborg last = first + 8;
85a88b5ba8SSam Ravnborg for (j = first; j < last; j++) {
86a88b5ba8SSam Ravnborg u64 errval = stc_error_buf[j];
87a88b5ba8SSam Ravnborg if (errval != 0) {
88a88b5ba8SSam Ravnborg saw_error++;
89a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: STC_ERR(%d)[wr(%d)"
90a88b5ba8SSam Ravnborg "rd(%d)]\n",
91a88b5ba8SSam Ravnborg pbm->name,
92a88b5ba8SSam Ravnborg j,
93a88b5ba8SSam Ravnborg (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,
94a88b5ba8SSam Ravnborg (errval & PSYCHO_STCERR_READ) ? 1 : 0);
95a88b5ba8SSam Ravnborg }
96a88b5ba8SSam Ravnborg }
97a88b5ba8SSam Ravnborg if (saw_error != 0) {
98a88b5ba8SSam Ravnborg u64 tagval = stc_tag_buf[i];
99a88b5ba8SSam Ravnborg u64 lineval = stc_line_buf[i];
10090181136SSam Ravnborg printk(KERN_ERR "%s: STC_TAG(%d)[PA(%016llx)VA(%08llx)"
101a88b5ba8SSam Ravnborg "V(%d)W(%d)]\n",
102a88b5ba8SSam Ravnborg pbm->name,
103a88b5ba8SSam Ravnborg i,
104a88b5ba8SSam Ravnborg ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),
105a88b5ba8SSam Ravnborg (tagval & PSYCHO_STCTAG_VPN),
106a88b5ba8SSam Ravnborg ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),
107a88b5ba8SSam Ravnborg ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));
10890181136SSam Ravnborg printk(KERN_ERR "%s: STC_LINE(%d)[LIDX(%llx)SP(%llx)"
10990181136SSam Ravnborg "LADDR(%llx)EP(%llx)V(%d)FOFN(%d)]\n",
110a88b5ba8SSam Ravnborg pbm->name,
111a88b5ba8SSam Ravnborg i,
112a88b5ba8SSam Ravnborg ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),
113a88b5ba8SSam Ravnborg ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),
114a88b5ba8SSam Ravnborg ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),
115a88b5ba8SSam Ravnborg ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),
116a88b5ba8SSam Ravnborg ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),
117a88b5ba8SSam Ravnborg ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));
118a88b5ba8SSam Ravnborg }
119a88b5ba8SSam Ravnborg }
120a88b5ba8SSam Ravnborg
121a88b5ba8SSam Ravnborg spin_unlock(&stc_buf_lock);
122a88b5ba8SSam Ravnborg }
123a88b5ba8SSam Ravnborg
124a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TAG 0xa580UL
125a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_DATA 0xa600UL
126a88b5ba8SSam Ravnborg
psycho_record_iommu_tags_and_data(struct pci_pbm_info * pbm,u64 * tag,u64 * data)127a88b5ba8SSam Ravnborg static void psycho_record_iommu_tags_and_data(struct pci_pbm_info *pbm,
128a88b5ba8SSam Ravnborg u64 *tag, u64 *data)
129a88b5ba8SSam Ravnborg {
130a88b5ba8SSam Ravnborg int i;
131a88b5ba8SSam Ravnborg
132a88b5ba8SSam Ravnborg for (i = 0; i < 16; i++) {
133a88b5ba8SSam Ravnborg unsigned long base = pbm->controller_regs;
134a88b5ba8SSam Ravnborg unsigned long off = i * 8UL;
135a88b5ba8SSam Ravnborg
136a88b5ba8SSam Ravnborg tag[i] = upa_readq(base + PSYCHO_IOMMU_TAG+off);
137a88b5ba8SSam Ravnborg data[i] = upa_readq(base + PSYCHO_IOMMU_DATA+off);
138a88b5ba8SSam Ravnborg
139a88b5ba8SSam Ravnborg /* Now clear out the entry. */
140a88b5ba8SSam Ravnborg upa_writeq(0, base + PSYCHO_IOMMU_TAG + off);
141a88b5ba8SSam Ravnborg upa_writeq(0, base + PSYCHO_IOMMU_DATA + off);
142a88b5ba8SSam Ravnborg }
143a88b5ba8SSam Ravnborg }
144a88b5ba8SSam Ravnborg
145a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)
146a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TAG_ERR (0x1UL << 22UL)
147a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TAG_WRITE (0x1UL << 21UL)
148a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)
149a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TAG_SIZE (0x1UL << 19UL)
150e8dc7c48SSam Ravnborg #define PSYCHO_IOMMU_TAG_VPAGE 0x7ffffULL
151a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)
152a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)
153e8dc7c48SSam Ravnborg #define PSYCHO_IOMMU_DATA_PPAGE 0xfffffffULL
154a88b5ba8SSam Ravnborg
psycho_dump_iommu_tags_and_data(struct pci_pbm_info * pbm,u64 * tag,u64 * data)155a88b5ba8SSam Ravnborg static void psycho_dump_iommu_tags_and_data(struct pci_pbm_info *pbm,
156a88b5ba8SSam Ravnborg u64 *tag, u64 *data)
157a88b5ba8SSam Ravnborg {
158a88b5ba8SSam Ravnborg int i;
159a88b5ba8SSam Ravnborg
160a88b5ba8SSam Ravnborg for (i = 0; i < 16; i++) {
161a88b5ba8SSam Ravnborg u64 tag_val, data_val;
162a88b5ba8SSam Ravnborg const char *type_str;
163a88b5ba8SSam Ravnborg tag_val = tag[i];
164a88b5ba8SSam Ravnborg if (!(tag_val & PSYCHO_IOMMU_TAG_ERR))
165a88b5ba8SSam Ravnborg continue;
166a88b5ba8SSam Ravnborg
167a88b5ba8SSam Ravnborg data_val = data[i];
168a88b5ba8SSam Ravnborg switch((tag_val & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {
169a88b5ba8SSam Ravnborg case 0:
170a88b5ba8SSam Ravnborg type_str = "Protection Error";
171a88b5ba8SSam Ravnborg break;
172a88b5ba8SSam Ravnborg case 1:
173a88b5ba8SSam Ravnborg type_str = "Invalid Error";
174a88b5ba8SSam Ravnborg break;
175a88b5ba8SSam Ravnborg case 2:
176a88b5ba8SSam Ravnborg type_str = "TimeOut Error";
177a88b5ba8SSam Ravnborg break;
178a88b5ba8SSam Ravnborg case 3:
179a88b5ba8SSam Ravnborg default:
180a88b5ba8SSam Ravnborg type_str = "ECC Error";
181a88b5ba8SSam Ravnborg break;
182a88b5ba8SSam Ravnborg }
183a88b5ba8SSam Ravnborg
184a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: IOMMU TAG(%d)[error(%s) wr(%d) "
18590181136SSam Ravnborg "str(%d) sz(%dK) vpg(%08llx)]\n",
186a88b5ba8SSam Ravnborg pbm->name, i, type_str,
187a88b5ba8SSam Ravnborg ((tag_val & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),
188a88b5ba8SSam Ravnborg ((tag_val & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),
189a88b5ba8SSam Ravnborg ((tag_val & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),
190a88b5ba8SSam Ravnborg (tag_val & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
191a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: IOMMU DATA(%d)[valid(%d) cache(%d) "
19290181136SSam Ravnborg "ppg(%016llx)]\n",
193a88b5ba8SSam Ravnborg pbm->name, i,
194a88b5ba8SSam Ravnborg ((data_val & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),
195a88b5ba8SSam Ravnborg ((data_val & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),
196a88b5ba8SSam Ravnborg (data_val & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
197a88b5ba8SSam Ravnborg }
198a88b5ba8SSam Ravnborg }
199a88b5ba8SSam Ravnborg
200a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL
201a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL
202a88b5ba8SSam Ravnborg
psycho_check_iommu_error(struct pci_pbm_info * pbm,unsigned long afsr,unsigned long afar,enum psycho_error_type type)203a88b5ba8SSam Ravnborg void psycho_check_iommu_error(struct pci_pbm_info *pbm,
204a88b5ba8SSam Ravnborg unsigned long afsr,
205a88b5ba8SSam Ravnborg unsigned long afar,
206a88b5ba8SSam Ravnborg enum psycho_error_type type)
207a88b5ba8SSam Ravnborg {
208a88b5ba8SSam Ravnborg u64 control, iommu_tag[16], iommu_data[16];
209a88b5ba8SSam Ravnborg struct iommu *iommu = pbm->iommu;
210a88b5ba8SSam Ravnborg unsigned long flags;
211a88b5ba8SSam Ravnborg
212a88b5ba8SSam Ravnborg spin_lock_irqsave(&iommu->lock, flags);
213a88b5ba8SSam Ravnborg control = upa_readq(iommu->iommu_control);
214a88b5ba8SSam Ravnborg if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {
215a88b5ba8SSam Ravnborg const char *type_str;
216a88b5ba8SSam Ravnborg
217a88b5ba8SSam Ravnborg control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;
218a88b5ba8SSam Ravnborg upa_writeq(control, iommu->iommu_control);
219a88b5ba8SSam Ravnborg
220a88b5ba8SSam Ravnborg switch ((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
221a88b5ba8SSam Ravnborg case 0:
222a88b5ba8SSam Ravnborg type_str = "Protection Error";
223a88b5ba8SSam Ravnborg break;
224a88b5ba8SSam Ravnborg case 1:
225a88b5ba8SSam Ravnborg type_str = "Invalid Error";
226a88b5ba8SSam Ravnborg break;
227a88b5ba8SSam Ravnborg case 2:
228a88b5ba8SSam Ravnborg type_str = "TimeOut Error";
229a88b5ba8SSam Ravnborg break;
230a88b5ba8SSam Ravnborg case 3:
231a88b5ba8SSam Ravnborg default:
232a88b5ba8SSam Ravnborg type_str = "ECC Error";
233a88b5ba8SSam Ravnborg break;
2346cb79b3fSJoe Perches }
235a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: IOMMU Error, type[%s]\n",
236a88b5ba8SSam Ravnborg pbm->name, type_str);
237a88b5ba8SSam Ravnborg
238a88b5ba8SSam Ravnborg /* It is very possible for another DVMA to occur while
239a88b5ba8SSam Ravnborg * we do this probe, and corrupt the system further.
240a88b5ba8SSam Ravnborg * But we are so screwed at this point that we are
241a88b5ba8SSam Ravnborg * likely to crash hard anyways, so get as much
242a88b5ba8SSam Ravnborg * diagnostic information to the console as we can.
243a88b5ba8SSam Ravnborg */
244a88b5ba8SSam Ravnborg psycho_record_iommu_tags_and_data(pbm, iommu_tag, iommu_data);
245a88b5ba8SSam Ravnborg psycho_dump_iommu_tags_and_data(pbm, iommu_tag, iommu_data);
246a88b5ba8SSam Ravnborg }
247a88b5ba8SSam Ravnborg psycho_check_stc_error(pbm);
248a88b5ba8SSam Ravnborg spin_unlock_irqrestore(&iommu->lock, flags);
249a88b5ba8SSam Ravnborg }
250a88b5ba8SSam Ravnborg
251a88b5ba8SSam Ravnborg #define PSYCHO_PCICTRL_SBH_ERR 0x0000000800000000UL
252a88b5ba8SSam Ravnborg #define PSYCHO_PCICTRL_SERR 0x0000000400000000UL
253a88b5ba8SSam Ravnborg
psycho_pcierr_intr_other(struct pci_pbm_info * pbm)254a88b5ba8SSam Ravnborg static irqreturn_t psycho_pcierr_intr_other(struct pci_pbm_info *pbm)
255a88b5ba8SSam Ravnborg {
256a88b5ba8SSam Ravnborg irqreturn_t ret = IRQ_NONE;
257a88b5ba8SSam Ravnborg u64 csr, csr_error_bits;
258a88b5ba8SSam Ravnborg u16 stat, *addr;
259a88b5ba8SSam Ravnborg
260a88b5ba8SSam Ravnborg csr = upa_readq(pbm->pci_csr);
261a88b5ba8SSam Ravnborg csr_error_bits = csr & (PSYCHO_PCICTRL_SBH_ERR | PSYCHO_PCICTRL_SERR);
262a88b5ba8SSam Ravnborg if (csr_error_bits) {
263a88b5ba8SSam Ravnborg /* Clear the errors. */
264a88b5ba8SSam Ravnborg upa_writeq(csr, pbm->pci_csr);
265a88b5ba8SSam Ravnborg
266a88b5ba8SSam Ravnborg /* Log 'em. */
267a88b5ba8SSam Ravnborg if (csr_error_bits & PSYCHO_PCICTRL_SBH_ERR)
268a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: PCI streaming byte hole "
269a88b5ba8SSam Ravnborg "error asserted.\n", pbm->name);
270a88b5ba8SSam Ravnborg if (csr_error_bits & PSYCHO_PCICTRL_SERR)
271a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: PCI SERR signal asserted.\n",
272a88b5ba8SSam Ravnborg pbm->name);
273a88b5ba8SSam Ravnborg ret = IRQ_HANDLED;
274a88b5ba8SSam Ravnborg }
275a88b5ba8SSam Ravnborg addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
276a88b5ba8SSam Ravnborg 0, PCI_STATUS);
277a88b5ba8SSam Ravnborg pci_config_read16(addr, &stat);
278a88b5ba8SSam Ravnborg if (stat & (PCI_STATUS_PARITY |
279a88b5ba8SSam Ravnborg PCI_STATUS_SIG_TARGET_ABORT |
280a88b5ba8SSam Ravnborg PCI_STATUS_REC_TARGET_ABORT |
281a88b5ba8SSam Ravnborg PCI_STATUS_REC_MASTER_ABORT |
282a88b5ba8SSam Ravnborg PCI_STATUS_SIG_SYSTEM_ERROR)) {
283a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: PCI bus error, PCI_STATUS[%04x]\n",
284a88b5ba8SSam Ravnborg pbm->name, stat);
285a88b5ba8SSam Ravnborg pci_config_write16(addr, 0xffff);
286a88b5ba8SSam Ravnborg ret = IRQ_HANDLED;
287a88b5ba8SSam Ravnborg }
288a88b5ba8SSam Ravnborg return ret;
289a88b5ba8SSam Ravnborg }
290a88b5ba8SSam Ravnborg
291e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_PMA 0x8000000000000000ULL
292e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_PTA 0x4000000000000000ULL
293e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_PRTRY 0x2000000000000000ULL
294e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_PPERR 0x1000000000000000ULL
295e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_SMA 0x0800000000000000ULL
296e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_STA 0x0400000000000000ULL
297e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_SRTRY 0x0200000000000000ULL
298e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_SPERR 0x0100000000000000ULL
299e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_RESV1 0x00ff000000000000ULL
300e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000ULL
301e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_BLK 0x0000000080000000ULL
302e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_RESV2 0x0000000040000000ULL
303e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_MID 0x000000003e000000ULL
304e8dc7c48SSam Ravnborg #define PSYCHO_PCIAFSR_RESV3 0x0000000001ffffffULL
305a88b5ba8SSam Ravnborg
psycho_pcierr_intr(int irq,void * dev_id)306a88b5ba8SSam Ravnborg irqreturn_t psycho_pcierr_intr(int irq, void *dev_id)
307a88b5ba8SSam Ravnborg {
308a88b5ba8SSam Ravnborg struct pci_pbm_info *pbm = dev_id;
309a88b5ba8SSam Ravnborg u64 afsr, afar, error_bits;
310a88b5ba8SSam Ravnborg int reported;
311a88b5ba8SSam Ravnborg
312a88b5ba8SSam Ravnborg afsr = upa_readq(pbm->pci_afsr);
313a88b5ba8SSam Ravnborg afar = upa_readq(pbm->pci_afar);
314a88b5ba8SSam Ravnborg error_bits = afsr &
315a88b5ba8SSam Ravnborg (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA |
316a88b5ba8SSam Ravnborg PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR |
317a88b5ba8SSam Ravnborg PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA |
318a88b5ba8SSam Ravnborg PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR);
319a88b5ba8SSam Ravnborg if (!error_bits)
320a88b5ba8SSam Ravnborg return psycho_pcierr_intr_other(pbm);
321a88b5ba8SSam Ravnborg upa_writeq(error_bits, pbm->pci_afsr);
322a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: PCI Error, primary error type[%s]\n",
323a88b5ba8SSam Ravnborg pbm->name,
324a88b5ba8SSam Ravnborg (((error_bits & PSYCHO_PCIAFSR_PMA) ?
325a88b5ba8SSam Ravnborg "Master Abort" :
326a88b5ba8SSam Ravnborg ((error_bits & PSYCHO_PCIAFSR_PTA) ?
327a88b5ba8SSam Ravnborg "Target Abort" :
328a88b5ba8SSam Ravnborg ((error_bits & PSYCHO_PCIAFSR_PRTRY) ?
329a88b5ba8SSam Ravnborg "Excessive Retries" :
330a88b5ba8SSam Ravnborg ((error_bits & PSYCHO_PCIAFSR_PPERR) ?
331a88b5ba8SSam Ravnborg "Parity Error" : "???"))))));
33290181136SSam Ravnborg printk(KERN_ERR "%s: bytemask[%04llx] UPA_MID[%02llx] was_block(%d)\n",
333a88b5ba8SSam Ravnborg pbm->name,
334a88b5ba8SSam Ravnborg (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL,
335a88b5ba8SSam Ravnborg (afsr & PSYCHO_PCIAFSR_MID) >> 25UL,
336a88b5ba8SSam Ravnborg (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0);
33790181136SSam Ravnborg printk(KERN_ERR "%s: PCI AFAR [%016llx]\n", pbm->name, afar);
338a88b5ba8SSam Ravnborg printk(KERN_ERR "%s: PCI Secondary errors [", pbm->name);
339a88b5ba8SSam Ravnborg reported = 0;
340a88b5ba8SSam Ravnborg if (afsr & PSYCHO_PCIAFSR_SMA) {
341a88b5ba8SSam Ravnborg reported++;
342a88b5ba8SSam Ravnborg printk("(Master Abort)");
343a88b5ba8SSam Ravnborg }
344a88b5ba8SSam Ravnborg if (afsr & PSYCHO_PCIAFSR_STA) {
345a88b5ba8SSam Ravnborg reported++;
346a88b5ba8SSam Ravnborg printk("(Target Abort)");
347a88b5ba8SSam Ravnborg }
348a88b5ba8SSam Ravnborg if (afsr & PSYCHO_PCIAFSR_SRTRY) {
349a88b5ba8SSam Ravnborg reported++;
350a88b5ba8SSam Ravnborg printk("(Excessive Retries)");
351a88b5ba8SSam Ravnborg }
352a88b5ba8SSam Ravnborg if (afsr & PSYCHO_PCIAFSR_SPERR) {
353a88b5ba8SSam Ravnborg reported++;
354a88b5ba8SSam Ravnborg printk("(Parity Error)");
355a88b5ba8SSam Ravnborg }
356a88b5ba8SSam Ravnborg if (!reported)
357a88b5ba8SSam Ravnborg printk("(none)");
358a88b5ba8SSam Ravnborg printk("]\n");
359a88b5ba8SSam Ravnborg
360a88b5ba8SSam Ravnborg if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) {
361a88b5ba8SSam Ravnborg psycho_check_iommu_error(pbm, afsr, afar, PCI_ERR);
362a88b5ba8SSam Ravnborg pci_scan_for_target_abort(pbm, pbm->pci_bus);
363a88b5ba8SSam Ravnborg }
364a88b5ba8SSam Ravnborg if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA))
365a88b5ba8SSam Ravnborg pci_scan_for_master_abort(pbm, pbm->pci_bus);
366a88b5ba8SSam Ravnborg
367a88b5ba8SSam Ravnborg if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR))
368a88b5ba8SSam Ravnborg pci_scan_for_parity_error(pbm, pbm->pci_bus);
369a88b5ba8SSam Ravnborg
370a88b5ba8SSam Ravnborg return IRQ_HANDLED;
371a88b5ba8SSam Ravnborg }
372a88b5ba8SSam Ravnborg
psycho_iommu_flush(struct pci_pbm_info * pbm)373a88b5ba8SSam Ravnborg static void psycho_iommu_flush(struct pci_pbm_info *pbm)
374a88b5ba8SSam Ravnborg {
375a88b5ba8SSam Ravnborg int i;
376a88b5ba8SSam Ravnborg
377a88b5ba8SSam Ravnborg for (i = 0; i < 16; i++) {
378a88b5ba8SSam Ravnborg unsigned long off = i * 8;
379a88b5ba8SSam Ravnborg
380a88b5ba8SSam Ravnborg upa_writeq(0, pbm->controller_regs + PSYCHO_IOMMU_TAG + off);
381a88b5ba8SSam Ravnborg upa_writeq(0, pbm->controller_regs + PSYCHO_IOMMU_DATA + off);
382a88b5ba8SSam Ravnborg }
383a88b5ba8SSam Ravnborg }
384a88b5ba8SSam Ravnborg
385a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_CONTROL 0x0200UL
386a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL
387a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_1K 0x0000000000000000UL
388a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_2K 0x0000000000010000UL
389a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_4K 0x0000000000020000UL
390a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_8K 0x0000000000030000UL
391a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_16K 0x0000000000040000UL
392a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_32K 0x0000000000050000UL
393a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_64K 0x0000000000060000UL
394a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBSZ_128K 0x0000000000070000UL
395a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL
396a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_CTRL_DENAB 0x0000000000000002UL
397a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_CTRL_ENAB 0x0000000000000001UL
398a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_FLUSH 0x0210UL
399a88b5ba8SSam Ravnborg #define PSYCHO_IOMMU_TSBBASE 0x0208UL
400a88b5ba8SSam Ravnborg
psycho_iommu_init(struct pci_pbm_info * pbm,int tsbsize,u32 dvma_offset,u32 dma_mask,unsigned long write_complete_offset)401a88b5ba8SSam Ravnborg int psycho_iommu_init(struct pci_pbm_info *pbm, int tsbsize,
402a88b5ba8SSam Ravnborg u32 dvma_offset, u32 dma_mask,
403a88b5ba8SSam Ravnborg unsigned long write_complete_offset)
404a88b5ba8SSam Ravnborg {
405a88b5ba8SSam Ravnborg struct iommu *iommu = pbm->iommu;
406a88b5ba8SSam Ravnborg u64 control;
407a88b5ba8SSam Ravnborg int err;
408a88b5ba8SSam Ravnborg
409a88b5ba8SSam Ravnborg iommu->iommu_control = pbm->controller_regs + PSYCHO_IOMMU_CONTROL;
410a88b5ba8SSam Ravnborg iommu->iommu_tsbbase = pbm->controller_regs + PSYCHO_IOMMU_TSBBASE;
411a88b5ba8SSam Ravnborg iommu->iommu_flush = pbm->controller_regs + PSYCHO_IOMMU_FLUSH;
412a88b5ba8SSam Ravnborg iommu->iommu_tags = pbm->controller_regs + PSYCHO_IOMMU_TAG;
413a88b5ba8SSam Ravnborg iommu->write_complete_reg = (pbm->controller_regs +
414a88b5ba8SSam Ravnborg write_complete_offset);
415a88b5ba8SSam Ravnborg
416a88b5ba8SSam Ravnborg iommu->iommu_ctxflush = 0;
417a88b5ba8SSam Ravnborg
418a88b5ba8SSam Ravnborg control = upa_readq(iommu->iommu_control);
419a88b5ba8SSam Ravnborg control |= PSYCHO_IOMMU_CTRL_DENAB;
420a88b5ba8SSam Ravnborg upa_writeq(control, iommu->iommu_control);
421a88b5ba8SSam Ravnborg
422a88b5ba8SSam Ravnborg psycho_iommu_flush(pbm);
423a88b5ba8SSam Ravnborg
424a88b5ba8SSam Ravnborg /* Leave diag mode enabled for full-flushing done in pci_iommu.c */
425a88b5ba8SSam Ravnborg err = iommu_table_init(iommu, tsbsize * 1024 * 8,
426a88b5ba8SSam Ravnborg dvma_offset, dma_mask, pbm->numa_node);
427a88b5ba8SSam Ravnborg if (err)
428a88b5ba8SSam Ravnborg return err;
429a88b5ba8SSam Ravnborg
430a88b5ba8SSam Ravnborg upa_writeq(__pa(iommu->page_table), iommu->iommu_tsbbase);
431a88b5ba8SSam Ravnborg
432a88b5ba8SSam Ravnborg control = upa_readq(iommu->iommu_control);
433a88b5ba8SSam Ravnborg control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
434a88b5ba8SSam Ravnborg control |= PSYCHO_IOMMU_CTRL_ENAB;
435a88b5ba8SSam Ravnborg
436a88b5ba8SSam Ravnborg switch (tsbsize) {
437a88b5ba8SSam Ravnborg case 64:
438a88b5ba8SSam Ravnborg control |= PSYCHO_IOMMU_TSBSZ_64K;
439a88b5ba8SSam Ravnborg break;
440a88b5ba8SSam Ravnborg case 128:
441a88b5ba8SSam Ravnborg control |= PSYCHO_IOMMU_TSBSZ_128K;
442a88b5ba8SSam Ravnborg break;
443a88b5ba8SSam Ravnborg default:
444a88b5ba8SSam Ravnborg return -EINVAL;
445a88b5ba8SSam Ravnborg }
446a88b5ba8SSam Ravnborg
447a88b5ba8SSam Ravnborg upa_writeq(control, iommu->iommu_control);
448a88b5ba8SSam Ravnborg
449a88b5ba8SSam Ravnborg return 0;
450a88b5ba8SSam Ravnborg
451a88b5ba8SSam Ravnborg }
452a88b5ba8SSam Ravnborg
psycho_pbm_init_common(struct pci_pbm_info * pbm,struct platform_device * op,const char * chip_name,int chip_type)453cd4cd730SGrant Likely void psycho_pbm_init_common(struct pci_pbm_info *pbm, struct platform_device *op,
454a88b5ba8SSam Ravnborg const char *chip_name, int chip_type)
455a88b5ba8SSam Ravnborg {
45661c7a080SGrant Likely struct device_node *dp = op->dev.of_node;
457a88b5ba8SSam Ravnborg
458a88b5ba8SSam Ravnborg pbm->name = dp->full_name;
45998fa15f3SAnshuman Khandual pbm->numa_node = NUMA_NO_NODE;
460a88b5ba8SSam Ravnborg pbm->chip_type = chip_type;
461a88b5ba8SSam Ravnborg pbm->chip_version = of_getintprop_default(dp, "version#", 0);
462a88b5ba8SSam Ravnborg pbm->chip_revision = of_getintprop_default(dp, "module-revision#", 0);
463a88b5ba8SSam Ravnborg pbm->op = op;
464a88b5ba8SSam Ravnborg pbm->pci_ops = &sun4u_pci_ops;
465a88b5ba8SSam Ravnborg pbm->config_space_reg_bits = 8;
466a88b5ba8SSam Ravnborg pbm->index = pci_num_pbms++;
467a88b5ba8SSam Ravnborg pci_get_pbm_props(pbm);
468a88b5ba8SSam Ravnborg pci_determine_mem_io_space(pbm);
469a88b5ba8SSam Ravnborg
470a88b5ba8SSam Ravnborg printk(KERN_INFO "%s: %s PCI Bus Module ver[%x:%x]\n",
471a88b5ba8SSam Ravnborg pbm->name, chip_name,
472a88b5ba8SSam Ravnborg pbm->chip_version, pbm->chip_revision);
473a88b5ba8SSam Ravnborg }
474