blob: a538d0ceb61d7cf7d0b1ae968566ffbb6e59e3c9 [file] [log] [blame]
Thomas Gleixner59bd9de2019-05-28 10:10:12 -07001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 1992-1997, 2000-2003 Silicon Graphics, Inc.
4 * Copyright (C) 2004 Christoph Hellwig.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Support functions for the HUB ASIC - mostly PIO mapping related.
7 */
8
9#include <linux/bitops.h>
10#include <linux/string.h>
11#include <linux/mmzone.h>
12#include <asm/sn/addrs.h>
13#include <asm/sn/arch.h>
14#include <asm/sn/hub.h>
15
16
17static int force_fire_and_forget = 1;
18
19/**
Ralf Baechle70342282013-01-22 12:59:30 +010020 * hub_pio_map - establish a HUB PIO mapping
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 * @hub: hub to perform PIO mapping on
23 * @widget: widget ID to perform PIO mapping for
Ralf Baechle70342282013-01-22 12:59:30 +010024 * @xtalk_addr: xtalk_address that needs to be mapped
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * @size: size of the PIO mapping
26 *
27 **/
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +020028unsigned long hub_pio_map(nasid_t nasid, xwidgetnum_t widget,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 unsigned long xtalk_addr, size_t size)
30{
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 unsigned i;
32
33 /* use small-window mapping if possible */
34 if ((xtalk_addr % SWIN_SIZE) + size <= SWIN_SIZE)
35 return NODE_SWIN_BASE(nasid, widget) + (xtalk_addr % SWIN_SIZE);
36
37 if ((xtalk_addr % BWIN_SIZE) + size > BWIN_SIZE) {
38 printk(KERN_WARNING "PIO mapping at hub %d widget %d addr 0x%lx"
39 " too big (%ld)\n",
40 nasid, widget, xtalk_addr, size);
41 return 0;
42 }
43
44 xtalk_addr &= ~(BWIN_SIZE-1);
45 for (i = 0; i < HUB_NUM_BIG_WINDOW; i++) {
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +020046 if (test_and_set_bit(i, hub_data(nasid)->h_bigwin_used))
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 continue;
48
49 /*
50 * The code below does a PIO write to setup an ITTE entry.
51 *
52 * We need to prevent other CPUs from seeing our updated
53 * memory shadow of the ITTE (in the piomap) until the ITTE
54 * entry is actually set up; otherwise, another CPU might
55 * attempt a PIO prematurely.
56 *
57 * Also, the only way we can know that an entry has been
58 * received by the hub and can be used by future PIO reads/
59 * writes is by reading back the ITTE entry after writing it.
60 *
61 * For these two reasons, we PIO read back the ITTE entry
62 * after we write it.
63 */
64 IIO_ITTE_PUT(nasid, i, HUB_PIO_MAP_TO_MEM, widget, xtalk_addr);
Thomas Bogendoerferdb0e7d42019-02-19 16:57:15 +010065 __raw_readq(IIO_ITTE_GET(nasid, i));
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 return NODE_BWIN_BASE(nasid, widget) + (xtalk_addr % BWIN_SIZE);
68 }
69
70 printk(KERN_WARNING "unable to establish PIO mapping for at"
71 " hub %d widget %d addr 0x%lx\n",
72 nasid, widget, xtalk_addr);
73 return 0;
74}
75
76
77/*
78 * hub_setup_prb(nasid, prbnum, credits, conveyor)
79 *
Ralf Baechle70342282013-01-22 12:59:30 +010080 * Put a PRB into fire-and-forget mode if conveyor isn't set. Otherwise,
81 * put it into conveyor belt mode with the specified number of credits.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83static void hub_setup_prb(nasid_t nasid, int prbnum, int credits)
84{
85 iprb_t prb;
86 int prb_offset;
87
88 /*
89 * Get the current register value.
90 */
91 prb_offset = IIO_IOPRB(prbnum);
92 prb.iprb_regval = REMOTE_HUB_L(nasid, prb_offset);
93
94 /*
95 * Clear out some fields.
96 */
97 prb.iprb_ovflow = 1;
98 prb.iprb_bnakctr = 0;
99 prb.iprb_anakctr = 0;
100
101 /*
102 * Enable or disable fire-and-forget mode.
103 */
104 prb.iprb_ff = force_fire_and_forget ? 1 : 0;
105
106 /*
Andrea Gelmini87fd4e22016-05-21 14:00:11 +0200107 * Set the appropriate number of PIO credits for the widget.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 */
109 prb.iprb_xtalkctr = credits;
110
111 /*
112 * Store the new value to the register.
113 */
114 REMOTE_HUB_S(nasid, prb_offset, prb.iprb_regval);
115}
116
117/**
118 * hub_set_piomode - set pio mode for a given hub
119 *
120 * @nasid: physical node ID for the hub in question
121 *
122 * Put the hub into either "PIO conveyor belt" mode or "fire-and-forget" mode.
123 * To do this, we have to make absolutely sure that no PIOs are in progress
124 * so we turn off access to all widgets for the duration of the function.
125 *
126 * XXX - This code should really check what kind of widget we're talking
Ralf Baechle70342282013-01-22 12:59:30 +0100127 * to. Bridges can only handle three requests, but XG will do more.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 * How many can crossbow handle to widget 0? We're assuming 1.
129 *
130 * XXX - There is a bug in the crossbow that link reset PIOs do not
131 * return write responses. The easiest solution to this problem is to
Ralf Baechle70342282013-01-22 12:59:30 +0100132 * leave widget 0 (xbow) in fire-and-forget mode at all times. This
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 * only affects pio's to xbow registers, which should be rare.
134 **/
135static void hub_set_piomode(nasid_t nasid)
136{
Thomas Bogendoerferdb0e7d42019-02-19 16:57:15 +0100137 u64 ii_iowa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 hubii_wcr_t ii_wcr;
139 unsigned i;
140
141 ii_iowa = REMOTE_HUB_L(nasid, IIO_OUTWIDGET_ACCESS);
142 REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, 0);
143
144 ii_wcr.wcr_reg_value = REMOTE_HUB_L(nasid, IIO_WCR);
145
146 if (ii_wcr.iwcr_dir_con) {
147 /*
148 * Assume a bridge here.
149 */
150 hub_setup_prb(nasid, 0, 3);
151 } else {
152 /*
153 * Assume a crossbow here.
154 */
155 hub_setup_prb(nasid, 0, 1);
156 }
157
158 /*
159 * XXX - Here's where we should take the widget type into
160 * when account assigning credits.
161 */
162 for (i = HUB_WIDGET_ID_MIN; i <= HUB_WIDGET_ID_MAX; i++)
163 hub_setup_prb(nasid, i, 3);
164
165 REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, ii_iowa);
166}
167
168/*
Ralf Baechle70342282013-01-22 12:59:30 +0100169 * hub_pio_init - PIO-related hub initialization
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 *
171 * @hub: hubinfo structure for our hub
172 */
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200173void hub_pio_init(nasid_t nasid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 unsigned i;
176
177 /* initialize big window piomaps for this hub */
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200178 bitmap_zero(hub_data(nasid)->h_bigwin_used, HUB_NUM_BIG_WINDOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 for (i = 0; i < HUB_NUM_BIG_WINDOW; i++)
180 IIO_ITTE_DISABLE(nasid, i);
181
182 hub_set_piomode(nasid);
183}