1473c88f9SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2473c88f9SBruce Richardson * Copyright(c) 2010-2018 Intel Corporation
3473c88f9SBruce Richardson */
4473c88f9SBruce Richardson
5473c88f9SBruce Richardson #include "ifpga_api.h"
6473c88f9SBruce Richardson #include "ifpga_enumerate.h"
7473c88f9SBruce Richardson #include "ifpga_feature_dev.h"
8a05bd1b4SWei Huang #include "ifpga_sec_mgr.h"
9473c88f9SBruce Richardson
10473c88f9SBruce Richardson #include "opae_hw_api.h"
11473c88f9SBruce Richardson
12473c88f9SBruce Richardson /* Accelerator APIs */
ifpga_acc_get_uuid(struct opae_accelerator * acc,struct uuid * uuid)13473c88f9SBruce Richardson static int ifpga_acc_get_uuid(struct opae_accelerator *acc,
14473c88f9SBruce Richardson struct uuid *uuid)
15473c88f9SBruce Richardson {
16673c897fSWei Huang struct ifpga_afu_info *afu_info = acc->data;
17673c897fSWei Huang struct opae_reg_region *region;
18673c897fSWei Huang u64 val = 0;
19473c88f9SBruce Richardson
20673c897fSWei Huang if (!afu_info)
21673c897fSWei Huang return -ENODEV;
22473c88f9SBruce Richardson
23673c897fSWei Huang region = &afu_info->region[0];
24673c897fSWei Huang if (uuid) {
25673c897fSWei Huang val = readq(region->addr + sizeof(struct feature_header));
26673c897fSWei Huang opae_memcpy(uuid->b, &val, sizeof(u64));
27673c897fSWei Huang val = readq(region->addr + sizeof(struct feature_header) + 8);
28673c897fSWei Huang opae_memcpy(uuid->b + 8, &val, sizeof(u64));
29673c897fSWei Huang }
30473c88f9SBruce Richardson
31673c897fSWei Huang return 0;
32473c88f9SBruce Richardson }
33473c88f9SBruce Richardson
ifpga_acc_set_irq(struct opae_accelerator * acc,u32 start,u32 count,s32 evtfds[])34473c88f9SBruce Richardson static int ifpga_acc_set_irq(struct opae_accelerator *acc,
35473c88f9SBruce Richardson u32 start, u32 count, s32 evtfds[])
36473c88f9SBruce Richardson {
37473c88f9SBruce Richardson struct ifpga_afu_info *afu_info = acc->data;
38473c88f9SBruce Richardson struct opae_bridge *br = acc->br;
39473c88f9SBruce Richardson struct ifpga_port_hw *port;
40473c88f9SBruce Richardson struct fpga_uafu_irq_set irq_set;
41473c88f9SBruce Richardson
42673c897fSWei Huang if (!afu_info)
43673c897fSWei Huang return -ENODEV;
44673c897fSWei Huang
45473c88f9SBruce Richardson if (!br || !br->data)
46473c88f9SBruce Richardson return -EINVAL;
47473c88f9SBruce Richardson
48473c88f9SBruce Richardson if (start >= afu_info->num_irqs || start + count > afu_info->num_irqs)
49473c88f9SBruce Richardson return -EINVAL;
50473c88f9SBruce Richardson
51473c88f9SBruce Richardson port = br->data;
52473c88f9SBruce Richardson
53473c88f9SBruce Richardson irq_set.start = start;
54473c88f9SBruce Richardson irq_set.count = count;
55473c88f9SBruce Richardson irq_set.evtfds = evtfds;
56473c88f9SBruce Richardson
57473c88f9SBruce Richardson return ifpga_set_irq(port->parent, FEATURE_FIU_ID_PORT, port->port_id,
58473c88f9SBruce Richardson IFPGA_PORT_FEATURE_ID_UINT, &irq_set);
59473c88f9SBruce Richardson }
60473c88f9SBruce Richardson
ifpga_acc_get_info(struct opae_accelerator * acc,struct opae_acc_info * info)61473c88f9SBruce Richardson static int ifpga_acc_get_info(struct opae_accelerator *acc,
62473c88f9SBruce Richardson struct opae_acc_info *info)
63473c88f9SBruce Richardson {
64473c88f9SBruce Richardson struct ifpga_afu_info *afu_info = acc->data;
65473c88f9SBruce Richardson
66473c88f9SBruce Richardson if (!afu_info)
67473c88f9SBruce Richardson return -ENODEV;
68473c88f9SBruce Richardson
69473c88f9SBruce Richardson info->num_regions = afu_info->num_regions;
70473c88f9SBruce Richardson info->num_irqs = afu_info->num_irqs;
71473c88f9SBruce Richardson
72473c88f9SBruce Richardson return 0;
73473c88f9SBruce Richardson }
74473c88f9SBruce Richardson
ifpga_acc_get_region_info(struct opae_accelerator * acc,struct opae_acc_region_info * info)75473c88f9SBruce Richardson static int ifpga_acc_get_region_info(struct opae_accelerator *acc,
76473c88f9SBruce Richardson struct opae_acc_region_info *info)
77473c88f9SBruce Richardson {
78473c88f9SBruce Richardson struct ifpga_afu_info *afu_info = acc->data;
79473c88f9SBruce Richardson
80473c88f9SBruce Richardson if (!afu_info)
81673c897fSWei Huang return -ENODEV;
82473c88f9SBruce Richardson
83473c88f9SBruce Richardson if (info->index >= afu_info->num_regions)
84473c88f9SBruce Richardson return -EINVAL;
85473c88f9SBruce Richardson
86473c88f9SBruce Richardson /* always one RW region only for AFU now */
87473c88f9SBruce Richardson info->flags = ACC_REGION_READ | ACC_REGION_WRITE | ACC_REGION_MMIO;
88473c88f9SBruce Richardson info->len = afu_info->region[info->index].len;
89473c88f9SBruce Richardson info->addr = afu_info->region[info->index].addr;
90473c88f9SBruce Richardson info->phys_addr = afu_info->region[info->index].phys_addr;
91473c88f9SBruce Richardson
92473c88f9SBruce Richardson return 0;
93473c88f9SBruce Richardson }
94473c88f9SBruce Richardson
ifpga_acc_read(struct opae_accelerator * acc,unsigned int region_idx,u64 offset,unsigned int byte,void * data)95473c88f9SBruce Richardson static int ifpga_acc_read(struct opae_accelerator *acc, unsigned int region_idx,
96473c88f9SBruce Richardson u64 offset, unsigned int byte, void *data)
97473c88f9SBruce Richardson {
98473c88f9SBruce Richardson struct ifpga_afu_info *afu_info = acc->data;
99473c88f9SBruce Richardson struct opae_reg_region *region;
100473c88f9SBruce Richardson
101473c88f9SBruce Richardson if (!afu_info)
102673c897fSWei Huang return -ENODEV;
103473c88f9SBruce Richardson
104473c88f9SBruce Richardson if (offset + byte <= offset)
105473c88f9SBruce Richardson return -EINVAL;
106473c88f9SBruce Richardson
107473c88f9SBruce Richardson if (region_idx >= afu_info->num_regions)
108473c88f9SBruce Richardson return -EINVAL;
109473c88f9SBruce Richardson
110473c88f9SBruce Richardson region = &afu_info->region[region_idx];
111473c88f9SBruce Richardson if (offset + byte > region->len)
112473c88f9SBruce Richardson return -EINVAL;
113473c88f9SBruce Richardson
114473c88f9SBruce Richardson switch (byte) {
115473c88f9SBruce Richardson case 8:
116473c88f9SBruce Richardson *(u64 *)data = opae_readq(region->addr + offset);
117473c88f9SBruce Richardson break;
118473c88f9SBruce Richardson case 4:
119473c88f9SBruce Richardson *(u32 *)data = opae_readl(region->addr + offset);
120473c88f9SBruce Richardson break;
121473c88f9SBruce Richardson case 2:
122473c88f9SBruce Richardson *(u16 *)data = opae_readw(region->addr + offset);
123473c88f9SBruce Richardson break;
124473c88f9SBruce Richardson case 1:
125473c88f9SBruce Richardson *(u8 *)data = opae_readb(region->addr + offset);
126473c88f9SBruce Richardson break;
127473c88f9SBruce Richardson default:
128473c88f9SBruce Richardson return -EINVAL;
129473c88f9SBruce Richardson }
130473c88f9SBruce Richardson
131473c88f9SBruce Richardson return 0;
132473c88f9SBruce Richardson }
133473c88f9SBruce Richardson
ifpga_acc_write(struct opae_accelerator * acc,unsigned int region_idx,u64 offset,unsigned int byte,void * data)134473c88f9SBruce Richardson static int ifpga_acc_write(struct opae_accelerator *acc,
135473c88f9SBruce Richardson unsigned int region_idx, u64 offset,
136473c88f9SBruce Richardson unsigned int byte, void *data)
137473c88f9SBruce Richardson {
138473c88f9SBruce Richardson struct ifpga_afu_info *afu_info = acc->data;
139473c88f9SBruce Richardson struct opae_reg_region *region;
140473c88f9SBruce Richardson
141473c88f9SBruce Richardson if (!afu_info)
142673c897fSWei Huang return -ENODEV;
143473c88f9SBruce Richardson
144473c88f9SBruce Richardson if (offset + byte <= offset)
145473c88f9SBruce Richardson return -EINVAL;
146473c88f9SBruce Richardson
147473c88f9SBruce Richardson if (region_idx >= afu_info->num_regions)
148473c88f9SBruce Richardson return -EINVAL;
149473c88f9SBruce Richardson
150473c88f9SBruce Richardson region = &afu_info->region[region_idx];
151473c88f9SBruce Richardson if (offset + byte > region->len)
152473c88f9SBruce Richardson return -EINVAL;
153473c88f9SBruce Richardson
154473c88f9SBruce Richardson /* normal mmio case */
155473c88f9SBruce Richardson switch (byte) {
156473c88f9SBruce Richardson case 8:
157473c88f9SBruce Richardson opae_writeq(*(u64 *)data, region->addr + offset);
158473c88f9SBruce Richardson break;
159473c88f9SBruce Richardson case 4:
160473c88f9SBruce Richardson opae_writel(*(u32 *)data, region->addr + offset);
161473c88f9SBruce Richardson break;
162473c88f9SBruce Richardson case 2:
163473c88f9SBruce Richardson opae_writew(*(u16 *)data, region->addr + offset);
164473c88f9SBruce Richardson break;
165473c88f9SBruce Richardson case 1:
166473c88f9SBruce Richardson opae_writeb(*(u8 *)data, region->addr + offset);
167473c88f9SBruce Richardson break;
168473c88f9SBruce Richardson default:
169473c88f9SBruce Richardson return -EINVAL;
170473c88f9SBruce Richardson }
171473c88f9SBruce Richardson
172473c88f9SBruce Richardson return 0;
173473c88f9SBruce Richardson }
174473c88f9SBruce Richardson
175473c88f9SBruce Richardson struct opae_accelerator_ops ifpga_acc_ops = {
176473c88f9SBruce Richardson .read = ifpga_acc_read,
177473c88f9SBruce Richardson .write = ifpga_acc_write,
178473c88f9SBruce Richardson .set_irq = ifpga_acc_set_irq,
179473c88f9SBruce Richardson .get_info = ifpga_acc_get_info,
180473c88f9SBruce Richardson .get_region_info = ifpga_acc_get_region_info,
181473c88f9SBruce Richardson .get_uuid = ifpga_acc_get_uuid,
182473c88f9SBruce Richardson };
183473c88f9SBruce Richardson
184473c88f9SBruce Richardson /* Bridge APIs */
ifpga_br_reset(struct opae_bridge * br)185473c88f9SBruce Richardson static int ifpga_br_reset(struct opae_bridge *br)
186473c88f9SBruce Richardson {
187473c88f9SBruce Richardson struct ifpga_port_hw *port = br->data;
188473c88f9SBruce Richardson
189473c88f9SBruce Richardson return fpga_port_reset(port);
190473c88f9SBruce Richardson }
191473c88f9SBruce Richardson
192473c88f9SBruce Richardson struct opae_bridge_ops ifpga_br_ops = {
193473c88f9SBruce Richardson .reset = ifpga_br_reset,
194473c88f9SBruce Richardson };
195473c88f9SBruce Richardson
196473c88f9SBruce Richardson /* Manager APIs */
ifpga_mgr_flash(struct opae_manager * mgr,int id,const char * buf,u32 size,u64 * status)197473c88f9SBruce Richardson static int ifpga_mgr_flash(struct opae_manager *mgr, int id, const char *buf,
198473c88f9SBruce Richardson u32 size, u64 *status)
199473c88f9SBruce Richardson {
200473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
201473c88f9SBruce Richardson struct ifpga_hw *hw = fme->parent;
202473c88f9SBruce Richardson
203473c88f9SBruce Richardson return ifpga_pr(hw, id, buf, size, status);
204473c88f9SBruce Richardson }
205473c88f9SBruce Richardson
ifpga_mgr_get_eth_group_region_info(struct opae_manager * mgr,struct opae_eth_group_region_info * info)206473c88f9SBruce Richardson static int ifpga_mgr_get_eth_group_region_info(struct opae_manager *mgr,
207473c88f9SBruce Richardson struct opae_eth_group_region_info *info)
208473c88f9SBruce Richardson {
209473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
210473c88f9SBruce Richardson
211473c88f9SBruce Richardson if (info->group_id >= MAX_ETH_GROUP_DEVICES)
212473c88f9SBruce Richardson return -EINVAL;
213473c88f9SBruce Richardson
214473c88f9SBruce Richardson info->phys_addr = fme->eth_group_region[info->group_id].phys_addr;
215473c88f9SBruce Richardson info->addr = fme->eth_group_region[info->group_id].addr;
216473c88f9SBruce Richardson info->len = fme->eth_group_region[info->group_id].len;
217473c88f9SBruce Richardson
218473c88f9SBruce Richardson info->mem_idx = fme->nums_acc_region + info->group_id;
219473c88f9SBruce Richardson
220473c88f9SBruce Richardson return 0;
221473c88f9SBruce Richardson }
222473c88f9SBruce Richardson
ifpga_mgr_get_sensor_value(struct opae_manager * mgr,struct opae_sensor_info * sensor,unsigned int * value)22319118989STianfei Zhang static int ifpga_mgr_get_sensor_value(struct opae_manager *mgr,
22419118989STianfei Zhang struct opae_sensor_info *sensor,
22519118989STianfei Zhang unsigned int *value)
22619118989STianfei Zhang {
22719118989STianfei Zhang struct ifpga_fme_hw *fme = mgr->data;
22819118989STianfei Zhang
22919118989STianfei Zhang return fme_mgr_get_sensor_value(fme, sensor, value);
23019118989STianfei Zhang }
23119118989STianfei Zhang
ifpga_mgr_get_board_info(struct opae_manager * mgr,struct opae_board_info ** info)232c127953fSTianfei Zhang static int ifpga_mgr_get_board_info(struct opae_manager *mgr,
233c127953fSTianfei Zhang struct opae_board_info **info)
234c127953fSTianfei Zhang {
235c127953fSTianfei Zhang struct ifpga_fme_hw *fme = mgr->data;
236c127953fSTianfei Zhang
237c127953fSTianfei Zhang *info = &fme->board_info;
238c127953fSTianfei Zhang
239c127953fSTianfei Zhang return 0;
240c127953fSTianfei Zhang }
241c127953fSTianfei Zhang
ifpga_mgr_get_uuid(struct opae_manager * mgr,struct uuid * uuid)242cf38bcd7SWei Huang static int ifpga_mgr_get_uuid(struct opae_manager *mgr, struct uuid *uuid)
243cf38bcd7SWei Huang {
244cf38bcd7SWei Huang struct ifpga_fme_hw *fme = mgr->data;
245cf38bcd7SWei Huang
246cf38bcd7SWei Huang return fpga_get_pr_uuid(fme, uuid);
247cf38bcd7SWei Huang }
248cf38bcd7SWei Huang
ifpga_mgr_update_flash(struct opae_manager * mgr,const char * image,u64 * status)249a05bd1b4SWei Huang static int ifpga_mgr_update_flash(struct opae_manager *mgr, const char *image,
250a05bd1b4SWei Huang u64 *status)
251a05bd1b4SWei Huang {
252a05bd1b4SWei Huang struct ifpga_fme_hw *fme = mgr->data;
253a05bd1b4SWei Huang
254a05bd1b4SWei Huang return fpga_update_flash(fme, image, status);
255a05bd1b4SWei Huang }
256a05bd1b4SWei Huang
ifpga_mgr_stop_flash_update(struct opae_manager * mgr,int force)257a05bd1b4SWei Huang static int ifpga_mgr_stop_flash_update(struct opae_manager *mgr, int force)
258a05bd1b4SWei Huang {
259a05bd1b4SWei Huang struct ifpga_fme_hw *fme = mgr->data;
260a05bd1b4SWei Huang
261a05bd1b4SWei Huang return fpga_stop_flash_update(fme, force);
262a05bd1b4SWei Huang }
263a05bd1b4SWei Huang
ifpga_mgr_reload(struct opae_manager * mgr,int type,int page)264a05bd1b4SWei Huang static int ifpga_mgr_reload(struct opae_manager *mgr, int type, int page)
265a05bd1b4SWei Huang {
266a05bd1b4SWei Huang struct ifpga_fme_hw *fme = mgr->data;
267a05bd1b4SWei Huang
268a05bd1b4SWei Huang return fpga_reload(fme, type, page);
269a05bd1b4SWei Huang }
270a05bd1b4SWei Huang
ifpga_mgr_read_flash(struct opae_manager * mgr,u32 address,u32 size,void * buf)271*b74ee6c8SWei Huang static int ifpga_mgr_read_flash(struct opae_manager *mgr, u32 address,
272*b74ee6c8SWei Huang u32 size, void *buf)
273*b74ee6c8SWei Huang {
274*b74ee6c8SWei Huang struct ifpga_fme_hw *fme = mgr->data;
275*b74ee6c8SWei Huang
276*b74ee6c8SWei Huang return fme_mgr_read_flash(fme, address, size, buf);
277*b74ee6c8SWei Huang }
278*b74ee6c8SWei Huang
279473c88f9SBruce Richardson struct opae_manager_ops ifpga_mgr_ops = {
280473c88f9SBruce Richardson .flash = ifpga_mgr_flash,
281473c88f9SBruce Richardson .get_eth_group_region_info = ifpga_mgr_get_eth_group_region_info,
28219118989STianfei Zhang .get_sensor_value = ifpga_mgr_get_sensor_value,
283c127953fSTianfei Zhang .get_board_info = ifpga_mgr_get_board_info,
284cf38bcd7SWei Huang .get_uuid = ifpga_mgr_get_uuid,
285a05bd1b4SWei Huang .update_flash = ifpga_mgr_update_flash,
286a05bd1b4SWei Huang .stop_flash_update = ifpga_mgr_stop_flash_update,
287a05bd1b4SWei Huang .reload = ifpga_mgr_reload,
288*b74ee6c8SWei Huang .read_flash = ifpga_mgr_read_flash
289473c88f9SBruce Richardson };
290473c88f9SBruce Richardson
ifpga_mgr_read_mac_rom(struct opae_manager * mgr,int offset,void * buf,int size)291473c88f9SBruce Richardson static int ifpga_mgr_read_mac_rom(struct opae_manager *mgr, int offset,
292473c88f9SBruce Richardson void *buf, int size)
293473c88f9SBruce Richardson {
294473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
295473c88f9SBruce Richardson
296473c88f9SBruce Richardson return fme_mgr_read_mac_rom(fme, offset, buf, size);
297473c88f9SBruce Richardson }
298473c88f9SBruce Richardson
ifpga_mgr_write_mac_rom(struct opae_manager * mgr,int offset,void * buf,int size)299473c88f9SBruce Richardson static int ifpga_mgr_write_mac_rom(struct opae_manager *mgr, int offset,
300473c88f9SBruce Richardson void *buf, int size)
301473c88f9SBruce Richardson {
302473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
303473c88f9SBruce Richardson
304473c88f9SBruce Richardson return fme_mgr_write_mac_rom(fme, offset, buf, size);
305473c88f9SBruce Richardson }
306473c88f9SBruce Richardson
ifpga_mgr_get_eth_group_nums(struct opae_manager * mgr)307473c88f9SBruce Richardson static int ifpga_mgr_get_eth_group_nums(struct opae_manager *mgr)
308473c88f9SBruce Richardson {
309473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
310473c88f9SBruce Richardson
311473c88f9SBruce Richardson return fme_mgr_get_eth_group_nums(fme);
312473c88f9SBruce Richardson }
313473c88f9SBruce Richardson
ifpga_mgr_get_eth_group_info(struct opae_manager * mgr,u8 group_id,struct opae_eth_group_info * info)314473c88f9SBruce Richardson static int ifpga_mgr_get_eth_group_info(struct opae_manager *mgr,
315473c88f9SBruce Richardson u8 group_id, struct opae_eth_group_info *info)
316473c88f9SBruce Richardson {
317473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
318473c88f9SBruce Richardson
319473c88f9SBruce Richardson return fme_mgr_get_eth_group_info(fme, group_id, info);
320473c88f9SBruce Richardson }
321473c88f9SBruce Richardson
ifpga_mgr_eth_group_reg_read(struct opae_manager * mgr,u8 group_id,u8 type,u8 index,u16 addr,u32 * data)322473c88f9SBruce Richardson static int ifpga_mgr_eth_group_reg_read(struct opae_manager *mgr, u8 group_id,
323473c88f9SBruce Richardson u8 type, u8 index, u16 addr, u32 *data)
324473c88f9SBruce Richardson {
325473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
326473c88f9SBruce Richardson
327473c88f9SBruce Richardson return fme_mgr_eth_group_read_reg(fme, group_id,
328473c88f9SBruce Richardson type, index, addr, data);
329473c88f9SBruce Richardson }
330473c88f9SBruce Richardson
ifpga_mgr_eth_group_reg_write(struct opae_manager * mgr,u8 group_id,u8 type,u8 index,u16 addr,u32 data)331473c88f9SBruce Richardson static int ifpga_mgr_eth_group_reg_write(struct opae_manager *mgr, u8 group_id,
332473c88f9SBruce Richardson u8 type, u8 index, u16 addr, u32 data)
333473c88f9SBruce Richardson {
334473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
335473c88f9SBruce Richardson
336473c88f9SBruce Richardson return fme_mgr_eth_group_write_reg(fme, group_id,
337473c88f9SBruce Richardson type, index, addr, data);
338473c88f9SBruce Richardson }
339473c88f9SBruce Richardson
ifpga_mgr_get_retimer_info(struct opae_manager * mgr,struct opae_retimer_info * info)340473c88f9SBruce Richardson static int ifpga_mgr_get_retimer_info(struct opae_manager *mgr,
341473c88f9SBruce Richardson struct opae_retimer_info *info)
342473c88f9SBruce Richardson {
343473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
344473c88f9SBruce Richardson
345473c88f9SBruce Richardson return fme_mgr_get_retimer_info(fme, info);
346473c88f9SBruce Richardson }
347473c88f9SBruce Richardson
ifpga_mgr_get_retimer_status(struct opae_manager * mgr,struct opae_retimer_status * status)348473c88f9SBruce Richardson static int ifpga_mgr_get_retimer_status(struct opae_manager *mgr,
349473c88f9SBruce Richardson struct opae_retimer_status *status)
350473c88f9SBruce Richardson {
351473c88f9SBruce Richardson struct ifpga_fme_hw *fme = mgr->data;
352473c88f9SBruce Richardson
353473c88f9SBruce Richardson return fme_mgr_get_retimer_status(fme, status);
354473c88f9SBruce Richardson }
355473c88f9SBruce Richardson
356473c88f9SBruce Richardson /* Network APIs in FME */
357473c88f9SBruce Richardson struct opae_manager_networking_ops ifpga_mgr_network_ops = {
358473c88f9SBruce Richardson .read_mac_rom = ifpga_mgr_read_mac_rom,
359473c88f9SBruce Richardson .write_mac_rom = ifpga_mgr_write_mac_rom,
360473c88f9SBruce Richardson .get_eth_group_nums = ifpga_mgr_get_eth_group_nums,
361473c88f9SBruce Richardson .get_eth_group_info = ifpga_mgr_get_eth_group_info,
362473c88f9SBruce Richardson .eth_group_reg_read = ifpga_mgr_eth_group_reg_read,
363473c88f9SBruce Richardson .eth_group_reg_write = ifpga_mgr_eth_group_reg_write,
364473c88f9SBruce Richardson .get_retimer_info = ifpga_mgr_get_retimer_info,
365473c88f9SBruce Richardson .get_retimer_status = ifpga_mgr_get_retimer_status,
366473c88f9SBruce Richardson };
367473c88f9SBruce Richardson
368473c88f9SBruce Richardson /* Adapter APIs */
ifpga_adapter_enumerate(struct opae_adapter * adapter)369473c88f9SBruce Richardson static int ifpga_adapter_enumerate(struct opae_adapter *adapter)
370473c88f9SBruce Richardson {
371473c88f9SBruce Richardson struct ifpga_hw *hw = malloc(sizeof(*hw));
372473c88f9SBruce Richardson
373473c88f9SBruce Richardson if (hw) {
374473c88f9SBruce Richardson opae_memset(hw, 0, sizeof(*hw));
375473c88f9SBruce Richardson hw->pci_data = adapter->data;
376473c88f9SBruce Richardson hw->adapter = adapter;
377473c88f9SBruce Richardson if (ifpga_bus_enumerate(hw))
378473c88f9SBruce Richardson goto error;
379473c88f9SBruce Richardson return ifpga_bus_init(hw);
380473c88f9SBruce Richardson }
381473c88f9SBruce Richardson
382473c88f9SBruce Richardson error:
383473c88f9SBruce Richardson return -ENOMEM;
384473c88f9SBruce Richardson }
385473c88f9SBruce Richardson
ifpga_adapter_destroy(struct opae_adapter * adapter)38682255e03SWei Huang static void ifpga_adapter_destroy(struct opae_adapter *adapter)
38782255e03SWei Huang {
38882255e03SWei Huang struct ifpga_fme_hw *fme;
38982255e03SWei Huang
39082255e03SWei Huang if (adapter && adapter->mgr && adapter->mgr->data) {
39182255e03SWei Huang fme = (struct ifpga_fme_hw *)adapter->mgr->data;
39282255e03SWei Huang if (fme->parent)
39382255e03SWei Huang ifpga_bus_uinit(fme->parent);
39482255e03SWei Huang }
39582255e03SWei Huang }
39682255e03SWei Huang
397473c88f9SBruce Richardson struct opae_adapter_ops ifpga_adapter_ops = {
398473c88f9SBruce Richardson .enumerate = ifpga_adapter_enumerate,
39982255e03SWei Huang .destroy = ifpga_adapter_destroy,
400473c88f9SBruce Richardson };
401473c88f9SBruce Richardson
402473c88f9SBruce Richardson /**
403473c88f9SBruce Richardson * ifpga_pr - do the partial reconfiguration for a given port device
404473c88f9SBruce Richardson * @hw: pointer to the HW structure
405473c88f9SBruce Richardson * @port_id: the port device id
406473c88f9SBruce Richardson * @buffer: the buffer of the bitstream
407473c88f9SBruce Richardson * @size: the size of the bitstream
408473c88f9SBruce Richardson * @status: hardware status including PR error code if return -EIO.
409473c88f9SBruce Richardson *
410473c88f9SBruce Richardson * @return
411473c88f9SBruce Richardson * - 0: Success, partial reconfiguration finished.
412473c88f9SBruce Richardson * - <0: Error code returned in partial reconfiguration.
413473c88f9SBruce Richardson **/
ifpga_pr(struct ifpga_hw * hw,u32 port_id,const char * buffer,u32 size,u64 * status)414473c88f9SBruce Richardson int ifpga_pr(struct ifpga_hw *hw, u32 port_id, const char *buffer, u32 size,
415473c88f9SBruce Richardson u64 *status)
416473c88f9SBruce Richardson {
417473c88f9SBruce Richardson if (!is_valid_port_id(hw, port_id))
418473c88f9SBruce Richardson return -ENODEV;
419473c88f9SBruce Richardson
420473c88f9SBruce Richardson return do_pr(hw, port_id, buffer, size, status);
421473c88f9SBruce Richardson }
422473c88f9SBruce Richardson
ifpga_get_prop(struct ifpga_hw * hw,u32 fiu_id,u32 port_id,struct feature_prop * prop)423473c88f9SBruce Richardson int ifpga_get_prop(struct ifpga_hw *hw, u32 fiu_id, u32 port_id,
424473c88f9SBruce Richardson struct feature_prop *prop)
425473c88f9SBruce Richardson {
426473c88f9SBruce Richardson if (!hw || !prop)
427473c88f9SBruce Richardson return -EINVAL;
428473c88f9SBruce Richardson
429473c88f9SBruce Richardson switch (fiu_id) {
430473c88f9SBruce Richardson case FEATURE_FIU_ID_FME:
431473c88f9SBruce Richardson return fme_get_prop(&hw->fme, prop);
432473c88f9SBruce Richardson case FEATURE_FIU_ID_PORT:
433473c88f9SBruce Richardson if (!is_valid_port_id(hw, port_id))
434473c88f9SBruce Richardson return -ENODEV;
435473c88f9SBruce Richardson return port_get_prop(&hw->port[port_id], prop);
436473c88f9SBruce Richardson }
437473c88f9SBruce Richardson
438473c88f9SBruce Richardson return -ENOENT;
439473c88f9SBruce Richardson }
440473c88f9SBruce Richardson
ifpga_set_prop(struct ifpga_hw * hw,u32 fiu_id,u32 port_id,struct feature_prop * prop)441473c88f9SBruce Richardson int ifpga_set_prop(struct ifpga_hw *hw, u32 fiu_id, u32 port_id,
442473c88f9SBruce Richardson struct feature_prop *prop)
443473c88f9SBruce Richardson {
444473c88f9SBruce Richardson if (!hw || !prop)
445473c88f9SBruce Richardson return -EINVAL;
446473c88f9SBruce Richardson
447473c88f9SBruce Richardson switch (fiu_id) {
448473c88f9SBruce Richardson case FEATURE_FIU_ID_FME:
449473c88f9SBruce Richardson return fme_set_prop(&hw->fme, prop);
450473c88f9SBruce Richardson case FEATURE_FIU_ID_PORT:
451473c88f9SBruce Richardson if (!is_valid_port_id(hw, port_id))
452473c88f9SBruce Richardson return -ENODEV;
453473c88f9SBruce Richardson return port_set_prop(&hw->port[port_id], prop);
454473c88f9SBruce Richardson }
455473c88f9SBruce Richardson
456473c88f9SBruce Richardson return -ENOENT;
457473c88f9SBruce Richardson }
458473c88f9SBruce Richardson
ifpga_set_irq(struct ifpga_hw * hw,u32 fiu_id,u32 port_id,u32 feature_id,void * irq_set)459473c88f9SBruce Richardson int ifpga_set_irq(struct ifpga_hw *hw, u32 fiu_id, u32 port_id,
460473c88f9SBruce Richardson u32 feature_id, void *irq_set)
461473c88f9SBruce Richardson {
462473c88f9SBruce Richardson if (!hw || !irq_set)
463473c88f9SBruce Richardson return -EINVAL;
464473c88f9SBruce Richardson
465473c88f9SBruce Richardson switch (fiu_id) {
466473c88f9SBruce Richardson case FEATURE_FIU_ID_FME:
467473c88f9SBruce Richardson return fme_set_irq(&hw->fme, feature_id, irq_set);
468473c88f9SBruce Richardson case FEATURE_FIU_ID_PORT:
469473c88f9SBruce Richardson if (!is_valid_port_id(hw, port_id))
470473c88f9SBruce Richardson return -ENODEV;
471473c88f9SBruce Richardson return port_set_irq(&hw->port[port_id], feature_id, irq_set);
472473c88f9SBruce Richardson }
473473c88f9SBruce Richardson
474473c88f9SBruce Richardson return -ENOENT;
475473c88f9SBruce Richardson }
476