aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/raw/ifpga_rawdev/base/ifpga_port.c
blob: 8b5668d49a6a9c997ae89c5e082229b405630ccf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2018 Intel Corporation
 */

#include "ifpga_feature_dev.h"

int port_get_prop(struct ifpga_port_hw *port, struct feature_prop *prop)
{
	struct feature *feature;

	if (!port)
		return -ENOENT;

	feature = get_port_feature_by_id(port, prop->feature_id);

	if (feature && feature->ops && feature->ops->get_prop)
		return feature->ops->get_prop(feature, prop);

	return -ENOENT;
}

int port_set_prop(struct ifpga_port_hw *port, struct feature_prop *prop)
{
	struct feature *feature;

	if (!port)
		return -ENOENT;

	feature = get_port_feature_by_id(port, prop->feature_id);

	if (feature && feature->ops && feature->ops->set_prop)
		return feature->ops->set_prop(feature, prop);

	return -ENOENT;
}

int port_set_irq(struct ifpga_port_hw *port, u32 feature_id, void *irq_set)
{
	struct feature *feature;

	if (!port)
		return -ENOENT;

	feature = get_port_feature_by_id(port, feature_id);

	if (feature && feature->ops && feature->ops->set_irq)
		return feature->ops->set_irq(feature, irq_set);

	return -ENOENT;
}

static int port_get_revision(struct ifpga_port_hw *port, u64 *revision)
{
	struct feature_port_header *port_hdr
		= get_port_feature_ioaddr_by_index(port,
						   PORT_FEATURE_ID_HEADER);
	struct feature_header header;

	header.csr = readq(&port_hdr->header);

	*revision = header.revision;

	return 0;
}

static int port_get_portidx(struct ifpga_port_hw *port, u64 *idx)
{
	struct feature_port_header *port_hdr;
	struct feature_port_capability capability;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	capability.csr = readq(&port_hdr->capability);
	*idx = capability.port_number;

	return 0;
}

static int port_get_latency_tolerance(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;
	struct feature_port_control control;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	control.csr = readq(&port_hdr->control);
	*val = control.latency_tolerance;

	return 0;
}

static int port_get_ap1_event(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;
	struct feature_port_status status;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	status.csr = readq(&port_hdr->status);
	spinlock_unlock(&port->lock);

	*val = status.ap1_event;

	return 0;
}

static int port_set_ap1_event(struct ifpga_port_hw *port, u64 val)
{
	struct feature_port_header *port_hdr;
	struct feature_port_status status;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	status.csr = readq(&port_hdr->status);
	status.ap1_event = val;
	writeq(status.csr, &port_hdr->status);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_get_ap2_event(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;
	struct feature_port_status status;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	status.csr = readq(&port_hdr->status);
	spinlock_unlock(&port->lock);

	*val = status.ap2_event;

	return 0;
}

static int port_set_ap2_event(struct ifpga_port_hw *port, u64 val)
{
	struct feature_port_header *port_hdr;
	struct feature_port_status status;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	status.csr = readq(&port_hdr->status);
	status.ap2_event = val;
	writeq(status.csr, &port_hdr->status);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_get_power_state(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;
	struct feature_port_status status;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	status.csr = readq(&port_hdr->status);
	spinlock_unlock(&port->lock);

	*val = status.power_state;

	return 0;
}

static int port_get_userclk_freqcmd(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	*val = readq(&port_hdr->user_clk_freq_cmd0);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_set_userclk_freqcmd(struct ifpga_port_hw *port, u64 val)
{
	struct feature_port_header *port_hdr;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	writeq(val, &port_hdr->user_clk_freq_cmd0);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_get_userclk_freqcntrcmd(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	*val = readq(&port_hdr->user_clk_freq_cmd1);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_set_userclk_freqcntrcmd(struct ifpga_port_hw *port, u64 val)
{
	struct feature_port_header *port_hdr;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	writeq(val, &port_hdr->user_clk_freq_cmd1);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_get_userclk_freqsts(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	*val = readq(&port_hdr->user_clk_freq_sts0);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_get_userclk_freqcntrsts(struct ifpga_port_hw *port, u64 *val)
{
	struct feature_port_header *port_hdr;

	port_hdr = get_port_feature_ioaddr_by_index(port,
						    PORT_FEATURE_ID_HEADER);

	spinlock_lock(&port->lock);
	*val = readq(&port_hdr->user_clk_freq_sts1);
	spinlock_unlock(&port->lock);

	return 0;
}

static int port_hdr_init(struct feature *feature)
{
	struct ifpga_port_hw *port = feature->parent;

	dev_info(NULL, "port hdr Init.\n");

	fpga_port_reset(port);

	return 0;
}

static void port_hdr_uinit(struct feature *feature)
{
	UNUSED(feature);

	dev_info(NULL, "port hdr uinit.\n");
}

static int port_hdr_get_prop(struct feature *feature, struct feature_prop *prop)
{
	struct ifpga_port_hw *port = feature->parent;

	switch (prop->prop_id) {
	case PORT_HDR_PROP_REVISION:
		return port_get_revision(port, &prop->data);
	case PORT_HDR_PROP_PORTIDX:
		return port_get_portidx(port, &prop->data);
	case PORT_HDR_PROP_LATENCY_TOLERANCE:
		return port_get_latency_tolerance(port, &prop->data);
	case PORT_HDR_PROP_AP1_EVENT:
		return port_get_ap1_event(port, &prop->data);
	case PORT_HDR_PROP_AP2_EVENT:
		return port_get_ap2_event(port, &prop->data);
	case PORT_HDR_PROP_POWER_STATE:
		return port_get_power_state(port, &prop->data);
	case PORT_HDR_PROP_USERCLK_FREQCMD:
		return port_get_userclk_freqcmd(port, &prop->data);
	case PORT_HDR_PROP_USERCLK_FREQCNTRCMD:
		return port_get_userclk_freqcntrcmd(port, &prop->data);
	case PORT_HDR_PROP_USERCLK_FREQSTS:
		return port_get_userclk_freqsts(port, &prop->data);
	case PORT_HDR_PROP_USERCLK_CNTRSTS:
		return port_get_userclk_freqcntrsts(port, &prop->data);
	}

	return -ENOENT;
}

static int port_hdr_set_prop(struct feature *feature, struct feature_prop *prop)
{
	struct ifpga_port_hw *port = feature->parent;

	switch (prop->prop_id) {
	case PORT_HDR_PROP_AP1_EVENT:
		return port_set_ap1_event(port, prop->data);
	case PORT_HDR_PROP_AP2_EVENT:
		return port_set_ap2_event(port, prop->data);
	case PORT_HDR_PROP_USERCLK_FREQCMD:
		return port_set_userclk_freqcmd(port, prop->data);
	case PORT_HDR_PROP_USERCLK_FREQCNTRCMD:
		return port_set_userclk_freqcntrcmd(port, prop->data);
	}

	return -ENOENT;
}

struct feature_ops ifpga_rawdev_port_hdr_ops = {
	.init = port_hdr_init,
	.uinit = port_hdr_uinit,
	.get_prop = port_hdr_get_prop,
	.set_prop = port_hdr_set_prop,
};

static int port_stp_init(struct feature *feature)
{
	struct ifpga_port_hw *port = feature->parent;

	dev_info(NULL, "port stp Init.\n");

	spinlock_lock(&port->lock);
	port->stp_addr = feature->addr;
	port->stp_size = feature->size;
	spinlock_unlock(&port->lock);

	return 0;
}

static void port_stp_uinit(struct feature *feature)
{
	UNUSED(feature);

	dev_info(NULL, "port stp uinit.\n");
}

struct feature_ops ifpga_rawdev_port_stp_ops = {
	.init = port_stp_init,
	.uinit = port_stp_uinit,
};

static int port_uint_init(struct feature *feature)
{
	struct ifpga_port_hw *port = feature->parent;

	dev_info(NULL, "PORT UINT Init.\n");

	spinlock_lock(&port->lock);
	if (feature->ctx_num) {
		port->capability |= FPGA_PORT_CAP_UAFU_IRQ;
		port->num_uafu_irqs = feature->ctx_num;
	}
	spinlock_unlock(&port->lock);

	return 0;
}

static void port_uint_uinit(struct feature *feature)
{
	UNUSED(feature);

	dev_info(NULL, "PORT UINT UInit.\n");
}

struct feature_ops ifpga_rawdev_port_uint_ops = {
	.init = port_uint_init,
	.uinit = port_uint_uinit,
};