xref: /dpdk/drivers/raw/ifpga/base/ifpga_port_error.c (revision 7c4fe2ad3b1214a6704a373dbaec087a4386c4bb)
1473c88f9SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2473c88f9SBruce Richardson  * Copyright(c) 2010-2018 Intel Corporation
3473c88f9SBruce Richardson  */
4473c88f9SBruce Richardson 
5473c88f9SBruce Richardson #include "ifpga_feature_dev.h"
6473c88f9SBruce Richardson 
port_err_get_revision(struct ifpga_port_hw * port,u64 * val)7473c88f9SBruce Richardson static int port_err_get_revision(struct ifpga_port_hw *port, u64 *val)
8473c88f9SBruce Richardson {
9473c88f9SBruce Richardson 	struct feature_port_error *port_err;
10473c88f9SBruce Richardson 	struct feature_header header;
11473c88f9SBruce Richardson 
12473c88f9SBruce Richardson 	port_err = get_port_feature_ioaddr_by_index(port,
13473c88f9SBruce Richardson 						    PORT_FEATURE_ID_ERROR);
14473c88f9SBruce Richardson 	header.csr = readq(&port_err->header);
15473c88f9SBruce Richardson 	*val = header.revision;
16473c88f9SBruce Richardson 
17473c88f9SBruce Richardson 	return 0;
18473c88f9SBruce Richardson }
19473c88f9SBruce Richardson 
port_err_get_errors(struct ifpga_port_hw * port,u64 * val)20473c88f9SBruce Richardson static int port_err_get_errors(struct ifpga_port_hw *port, u64 *val)
21473c88f9SBruce Richardson {
22473c88f9SBruce Richardson 	struct feature_port_error *port_err;
23473c88f9SBruce Richardson 	struct feature_port_err_key error;
24473c88f9SBruce Richardson 
25473c88f9SBruce Richardson 	port_err = get_port_feature_ioaddr_by_index(port,
26473c88f9SBruce Richardson 						    PORT_FEATURE_ID_ERROR);
27473c88f9SBruce Richardson 	error.csr = readq(&port_err->port_error);
28473c88f9SBruce Richardson 	*val = error.csr;
29473c88f9SBruce Richardson 
30473c88f9SBruce Richardson 	return 0;
31473c88f9SBruce Richardson }
32473c88f9SBruce Richardson 
port_err_get_first_error(struct ifpga_port_hw * port,u64 * val)33473c88f9SBruce Richardson static int port_err_get_first_error(struct ifpga_port_hw *port, u64 *val)
34473c88f9SBruce Richardson {
35473c88f9SBruce Richardson 	struct feature_port_error *port_err;
36473c88f9SBruce Richardson 	struct feature_port_first_err_key first_error;
37473c88f9SBruce Richardson 
38473c88f9SBruce Richardson 	port_err = get_port_feature_ioaddr_by_index(port,
39473c88f9SBruce Richardson 						    PORT_FEATURE_ID_ERROR);
40473c88f9SBruce Richardson 	first_error.csr = readq(&port_err->port_first_error);
41473c88f9SBruce Richardson 	*val = first_error.csr;
42473c88f9SBruce Richardson 
43473c88f9SBruce Richardson 	return 0;
44473c88f9SBruce Richardson }
45473c88f9SBruce Richardson 
port_err_get_first_malformed_req_lsb(struct ifpga_port_hw * port,u64 * val)46473c88f9SBruce Richardson static int port_err_get_first_malformed_req_lsb(struct ifpga_port_hw *port,
47473c88f9SBruce Richardson 						u64 *val)
48473c88f9SBruce Richardson {
49473c88f9SBruce Richardson 	struct feature_port_error *port_err;
50473c88f9SBruce Richardson 	struct feature_port_malformed_req0 malreq0;
51473c88f9SBruce Richardson 
52473c88f9SBruce Richardson 	port_err = get_port_feature_ioaddr_by_index(port,
53473c88f9SBruce Richardson 						    PORT_FEATURE_ID_ERROR);
54473c88f9SBruce Richardson 
55473c88f9SBruce Richardson 	malreq0.header_lsb = readq(&port_err->malreq0);
56473c88f9SBruce Richardson 	*val = malreq0.header_lsb;
57473c88f9SBruce Richardson 
58473c88f9SBruce Richardson 	return 0;
59473c88f9SBruce Richardson }
60473c88f9SBruce Richardson 
port_err_get_first_malformed_req_msb(struct ifpga_port_hw * port,u64 * val)61473c88f9SBruce Richardson static int port_err_get_first_malformed_req_msb(struct ifpga_port_hw *port,
62473c88f9SBruce Richardson 						u64 *val)
63473c88f9SBruce Richardson {
64473c88f9SBruce Richardson 	struct feature_port_error *port_err;
65473c88f9SBruce Richardson 	struct feature_port_malformed_req1 malreq1;
66473c88f9SBruce Richardson 
67473c88f9SBruce Richardson 	port_err = get_port_feature_ioaddr_by_index(port,
68473c88f9SBruce Richardson 						    PORT_FEATURE_ID_ERROR);
69473c88f9SBruce Richardson 
70473c88f9SBruce Richardson 	malreq1.header_msb = readq(&port_err->malreq1);
71473c88f9SBruce Richardson 	*val = malreq1.header_msb;
72473c88f9SBruce Richardson 
73473c88f9SBruce Richardson 	return 0;
74473c88f9SBruce Richardson }
75473c88f9SBruce Richardson 
port_err_set_clear(struct ifpga_port_hw * port,u64 val)76473c88f9SBruce Richardson static int port_err_set_clear(struct ifpga_port_hw *port, u64 val)
77473c88f9SBruce Richardson {
78473c88f9SBruce Richardson 	int ret;
79473c88f9SBruce Richardson 
80473c88f9SBruce Richardson 	spinlock_lock(&port->lock);
81473c88f9SBruce Richardson 	ret = port_err_clear(port, val);
82473c88f9SBruce Richardson 	spinlock_unlock(&port->lock);
83473c88f9SBruce Richardson 
84473c88f9SBruce Richardson 	return ret;
85473c88f9SBruce Richardson }
86473c88f9SBruce Richardson 
port_error_init(struct ifpga_feature * feature)87473c88f9SBruce Richardson static int port_error_init(struct ifpga_feature *feature)
88473c88f9SBruce Richardson {
89473c88f9SBruce Richardson 	struct ifpga_port_hw *port = feature->parent;
90473c88f9SBruce Richardson 
91*7c4fe2adSWei Huang 	dev_info(NULL, "port error_module Init.\n");
92473c88f9SBruce Richardson 
93473c88f9SBruce Richardson 	spinlock_lock(&port->lock);
94473c88f9SBruce Richardson 	port_err_mask(port, false);
95473c88f9SBruce Richardson 	if (feature->ctx_num)
96473c88f9SBruce Richardson 		port->capability |= FPGA_PORT_CAP_ERR_IRQ;
97473c88f9SBruce Richardson 	spinlock_unlock(&port->lock);
98473c88f9SBruce Richardson 
99473c88f9SBruce Richardson 	return 0;
100473c88f9SBruce Richardson }
101473c88f9SBruce Richardson 
port_error_uinit(struct ifpga_feature * feature)102473c88f9SBruce Richardson static void port_error_uinit(struct ifpga_feature *feature)
103473c88f9SBruce Richardson {
104473c88f9SBruce Richardson 	UNUSED(feature);
105473c88f9SBruce Richardson }
106473c88f9SBruce Richardson 
port_error_get_prop(struct ifpga_feature * feature,struct feature_prop * prop)107473c88f9SBruce Richardson static int port_error_get_prop(struct ifpga_feature *feature,
108473c88f9SBruce Richardson 			       struct feature_prop *prop)
109473c88f9SBruce Richardson {
110473c88f9SBruce Richardson 	struct ifpga_port_hw *port = feature->parent;
111473c88f9SBruce Richardson 
112473c88f9SBruce Richardson 	switch (prop->prop_id) {
113473c88f9SBruce Richardson 	case PORT_ERR_PROP_REVISION:
114473c88f9SBruce Richardson 		return port_err_get_revision(port, &prop->data);
115473c88f9SBruce Richardson 	case PORT_ERR_PROP_ERRORS:
116473c88f9SBruce Richardson 		return port_err_get_errors(port, &prop->data);
117473c88f9SBruce Richardson 	case PORT_ERR_PROP_FIRST_ERROR:
118473c88f9SBruce Richardson 		return port_err_get_first_error(port, &prop->data);
119473c88f9SBruce Richardson 	case PORT_ERR_PROP_FIRST_MALFORMED_REQ_LSB:
120473c88f9SBruce Richardson 		return port_err_get_first_malformed_req_lsb(port, &prop->data);
121473c88f9SBruce Richardson 	case PORT_ERR_PROP_FIRST_MALFORMED_REQ_MSB:
122473c88f9SBruce Richardson 		return port_err_get_first_malformed_req_msb(port, &prop->data);
123473c88f9SBruce Richardson 	}
124473c88f9SBruce Richardson 
125473c88f9SBruce Richardson 	return -ENOENT;
126473c88f9SBruce Richardson }
127473c88f9SBruce Richardson 
port_error_set_prop(struct ifpga_feature * feature,struct feature_prop * prop)128473c88f9SBruce Richardson static int port_error_set_prop(struct ifpga_feature *feature,
129473c88f9SBruce Richardson 			       struct feature_prop *prop)
130473c88f9SBruce Richardson {
131473c88f9SBruce Richardson 	struct ifpga_port_hw *port = feature->parent;
132473c88f9SBruce Richardson 
133473c88f9SBruce Richardson 	if (prop->prop_id == PORT_ERR_PROP_CLEAR)
134473c88f9SBruce Richardson 		return port_err_set_clear(port, prop->data);
135473c88f9SBruce Richardson 
136473c88f9SBruce Richardson 	return -ENOENT;
137473c88f9SBruce Richardson }
138473c88f9SBruce Richardson 
port_error_set_irq(struct ifpga_feature * feature,void * irq_set)1399bf03321STianfei Zhang static int port_error_set_irq(struct ifpga_feature *feature, void *irq_set)
1409bf03321STianfei Zhang {
1419bf03321STianfei Zhang 	struct fpga_port_err_irq_set *err_irq_set = irq_set;
1429bf03321STianfei Zhang 	struct ifpga_port_hw *port;
1439bf03321STianfei Zhang 	int ret;
1449bf03321STianfei Zhang 
1459bf03321STianfei Zhang 	port = feature->parent;
1469bf03321STianfei Zhang 
1479bf03321STianfei Zhang 	if (!(port->capability & FPGA_PORT_CAP_ERR_IRQ))
1489bf03321STianfei Zhang 		return -ENODEV;
1499bf03321STianfei Zhang 
1509bf03321STianfei Zhang 	spinlock_lock(&port->lock);
1519bf03321STianfei Zhang 	ret = fpga_msix_set_block(feature, 0, 1, &err_irq_set->evtfd);
1529bf03321STianfei Zhang 	spinlock_unlock(&port->lock);
1539bf03321STianfei Zhang 
1549bf03321STianfei Zhang 	return ret;
1559bf03321STianfei Zhang }
1569bf03321STianfei Zhang 
157473c88f9SBruce Richardson struct ifpga_feature_ops ifpga_rawdev_port_error_ops = {
158473c88f9SBruce Richardson 	.init = port_error_init,
159473c88f9SBruce Richardson 	.uinit = port_error_uinit,
160473c88f9SBruce Richardson 	.get_prop = port_error_get_prop,
161473c88f9SBruce Richardson 	.set_prop = port_error_set_prop,
1629bf03321STianfei Zhang 	.set_irq = port_error_set_irq,
163473c88f9SBruce Richardson };
164