1*5113495bSYour Name // SPDX-License-Identifier: GPL-2.0-only
2*5113495bSYour Name /*
3*5113495bSYour Name * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
4*5113495bSYour Name * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
5*5113495bSYour Name */
6*5113495bSYour Name
7*5113495bSYour Name #include "bus.h"
8*5113495bSYour Name #include "debug.h"
9*5113495bSYour Name #include "pci.h"
10*5113495bSYour Name
cnss_get_dev_bus_type(struct device * dev)11*5113495bSYour Name enum cnss_dev_bus_type cnss_get_dev_bus_type(struct device *dev)
12*5113495bSYour Name {
13*5113495bSYour Name if (!dev)
14*5113495bSYour Name return CNSS_BUS_NONE;
15*5113495bSYour Name
16*5113495bSYour Name if (!dev->bus)
17*5113495bSYour Name return CNSS_BUS_NONE;
18*5113495bSYour Name
19*5113495bSYour Name if (memcmp(dev->bus->name, "pci", 3) == 0)
20*5113495bSYour Name return CNSS_BUS_PCI;
21*5113495bSYour Name else
22*5113495bSYour Name return CNSS_BUS_NONE;
23*5113495bSYour Name }
24*5113495bSYour Name
cnss_get_bus_type(struct cnss_plat_data * plat_priv)25*5113495bSYour Name enum cnss_dev_bus_type cnss_get_bus_type(struct cnss_plat_data *plat_priv)
26*5113495bSYour Name {
27*5113495bSYour Name int ret;
28*5113495bSYour Name struct device *dev;
29*5113495bSYour Name u32 bus_type_dt = CNSS_BUS_NONE;
30*5113495bSYour Name
31*5113495bSYour Name if (plat_priv->dt_type == CNSS_DTT_MULTIEXCHG) {
32*5113495bSYour Name dev = &plat_priv->plat_dev->dev;
33*5113495bSYour Name ret = of_property_read_u32(dev->of_node, "qcom,bus-type",
34*5113495bSYour Name &bus_type_dt);
35*5113495bSYour Name if (!ret)
36*5113495bSYour Name if (bus_type_dt < CNSS_BUS_MAX)
37*5113495bSYour Name cnss_pr_dbg("Got bus type[%u] from dt\n",
38*5113495bSYour Name bus_type_dt);
39*5113495bSYour Name else
40*5113495bSYour Name bus_type_dt = CNSS_BUS_NONE;
41*5113495bSYour Name else
42*5113495bSYour Name cnss_pr_err("No bus type for multi-exchg dt\n");
43*5113495bSYour Name
44*5113495bSYour Name return bus_type_dt;
45*5113495bSYour Name }
46*5113495bSYour Name
47*5113495bSYour Name switch (plat_priv->device_id) {
48*5113495bSYour Name case QCA6174_DEVICE_ID:
49*5113495bSYour Name case QCA6290_DEVICE_ID:
50*5113495bSYour Name case QCA6390_DEVICE_ID:
51*5113495bSYour Name case QCN7605_DEVICE_ID:
52*5113495bSYour Name case QCA6490_DEVICE_ID:
53*5113495bSYour Name case KIWI_DEVICE_ID:
54*5113495bSYour Name case MANGO_DEVICE_ID:
55*5113495bSYour Name case PEACH_DEVICE_ID:
56*5113495bSYour Name return CNSS_BUS_PCI;
57*5113495bSYour Name default:
58*5113495bSYour Name cnss_pr_err("Unknown device_id: 0x%lx\n", plat_priv->device_id);
59*5113495bSYour Name return CNSS_BUS_NONE;
60*5113495bSYour Name }
61*5113495bSYour Name }
62*5113495bSYour Name
cnss_bus_dev_to_bus_priv(struct device * dev)63*5113495bSYour Name void *cnss_bus_dev_to_bus_priv(struct device *dev)
64*5113495bSYour Name {
65*5113495bSYour Name if (!dev)
66*5113495bSYour Name return NULL;
67*5113495bSYour Name
68*5113495bSYour Name switch (cnss_get_dev_bus_type(dev)) {
69*5113495bSYour Name case CNSS_BUS_PCI:
70*5113495bSYour Name return cnss_get_pci_priv(to_pci_dev(dev));
71*5113495bSYour Name default:
72*5113495bSYour Name return NULL;
73*5113495bSYour Name }
74*5113495bSYour Name }
75*5113495bSYour Name
cnss_bus_dev_to_plat_priv(struct device * dev)76*5113495bSYour Name struct cnss_plat_data *cnss_bus_dev_to_plat_priv(struct device *dev)
77*5113495bSYour Name {
78*5113495bSYour Name void *bus_priv;
79*5113495bSYour Name
80*5113495bSYour Name if (!dev)
81*5113495bSYour Name return cnss_get_plat_priv(NULL);
82*5113495bSYour Name
83*5113495bSYour Name bus_priv = cnss_bus_dev_to_bus_priv(dev);
84*5113495bSYour Name if (!bus_priv)
85*5113495bSYour Name return NULL;
86*5113495bSYour Name
87*5113495bSYour Name switch (cnss_get_dev_bus_type(dev)) {
88*5113495bSYour Name case CNSS_BUS_PCI:
89*5113495bSYour Name return cnss_pci_priv_to_plat_priv(bus_priv);
90*5113495bSYour Name default:
91*5113495bSYour Name return NULL;
92*5113495bSYour Name }
93*5113495bSYour Name }
94*5113495bSYour Name
cnss_bus_init(struct cnss_plat_data * plat_priv)95*5113495bSYour Name int cnss_bus_init(struct cnss_plat_data *plat_priv)
96*5113495bSYour Name {
97*5113495bSYour Name if (!plat_priv)
98*5113495bSYour Name return -ENODEV;
99*5113495bSYour Name
100*5113495bSYour Name switch (plat_priv->bus_type) {
101*5113495bSYour Name case CNSS_BUS_PCI:
102*5113495bSYour Name return cnss_pci_init(plat_priv);
103*5113495bSYour Name default:
104*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
105*5113495bSYour Name plat_priv->bus_type);
106*5113495bSYour Name return -EINVAL;
107*5113495bSYour Name }
108*5113495bSYour Name }
109*5113495bSYour Name
cnss_bus_deinit(struct cnss_plat_data * plat_priv)110*5113495bSYour Name void cnss_bus_deinit(struct cnss_plat_data *plat_priv)
111*5113495bSYour Name {
112*5113495bSYour Name if (!plat_priv)
113*5113495bSYour Name return;
114*5113495bSYour Name
115*5113495bSYour Name switch (plat_priv->bus_type) {
116*5113495bSYour Name case CNSS_BUS_PCI:
117*5113495bSYour Name return cnss_pci_deinit(plat_priv);
118*5113495bSYour Name default:
119*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
120*5113495bSYour Name plat_priv->bus_type);
121*5113495bSYour Name return;
122*5113495bSYour Name }
123*5113495bSYour Name }
124*5113495bSYour Name
cnss_bus_add_fw_prefix_name(struct cnss_plat_data * plat_priv,char * prefix_name,char * name)125*5113495bSYour Name void cnss_bus_add_fw_prefix_name(struct cnss_plat_data *plat_priv,
126*5113495bSYour Name char *prefix_name, char *name)
127*5113495bSYour Name {
128*5113495bSYour Name if (!plat_priv)
129*5113495bSYour Name return;
130*5113495bSYour Name
131*5113495bSYour Name switch (plat_priv->bus_type) {
132*5113495bSYour Name case CNSS_BUS_PCI:
133*5113495bSYour Name return cnss_pci_add_fw_prefix_name(plat_priv->bus_priv,
134*5113495bSYour Name prefix_name, name);
135*5113495bSYour Name default:
136*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
137*5113495bSYour Name plat_priv->bus_type);
138*5113495bSYour Name return;
139*5113495bSYour Name }
140*5113495bSYour Name }
141*5113495bSYour Name
cnss_bus_load_tme_patch(struct cnss_plat_data * plat_priv)142*5113495bSYour Name int cnss_bus_load_tme_patch(struct cnss_plat_data *plat_priv)
143*5113495bSYour Name {
144*5113495bSYour Name if (!plat_priv)
145*5113495bSYour Name return -ENODEV;
146*5113495bSYour Name
147*5113495bSYour Name switch (plat_priv->bus_type) {
148*5113495bSYour Name case CNSS_BUS_PCI:
149*5113495bSYour Name return cnss_pci_load_tme_patch(plat_priv->bus_priv);
150*5113495bSYour Name default:
151*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
152*5113495bSYour Name plat_priv->bus_type);
153*5113495bSYour Name return -EINVAL;
154*5113495bSYour Name }
155*5113495bSYour Name }
156*5113495bSYour Name
cnss_bus_load_tme_opt_file(struct cnss_plat_data * plat_priv,enum wlfw_tme_lite_file_type_v01 file)157*5113495bSYour Name int cnss_bus_load_tme_opt_file(struct cnss_plat_data *plat_priv,
158*5113495bSYour Name enum wlfw_tme_lite_file_type_v01 file)
159*5113495bSYour Name {
160*5113495bSYour Name if (!plat_priv)
161*5113495bSYour Name return -ENODEV;
162*5113495bSYour Name
163*5113495bSYour Name switch (plat_priv->bus_type) {
164*5113495bSYour Name case CNSS_BUS_PCI:
165*5113495bSYour Name return cnss_pci_load_tme_opt_file(plat_priv->bus_priv, file);
166*5113495bSYour Name default:
167*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
168*5113495bSYour Name plat_priv->bus_type);
169*5113495bSYour Name return -EINVAL;
170*5113495bSYour Name }
171*5113495bSYour Name }
172*5113495bSYour Name
cnss_bus_load_m3(struct cnss_plat_data * plat_priv)173*5113495bSYour Name int cnss_bus_load_m3(struct cnss_plat_data *plat_priv)
174*5113495bSYour Name {
175*5113495bSYour Name if (!plat_priv)
176*5113495bSYour Name return -ENODEV;
177*5113495bSYour Name
178*5113495bSYour Name switch (plat_priv->bus_type) {
179*5113495bSYour Name case CNSS_BUS_PCI:
180*5113495bSYour Name return cnss_pci_load_m3(plat_priv->bus_priv);
181*5113495bSYour Name default:
182*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
183*5113495bSYour Name plat_priv->bus_type);
184*5113495bSYour Name return -EINVAL;
185*5113495bSYour Name }
186*5113495bSYour Name }
187*5113495bSYour Name
cnss_bus_load_aux(struct cnss_plat_data * plat_priv)188*5113495bSYour Name int cnss_bus_load_aux(struct cnss_plat_data *plat_priv)
189*5113495bSYour Name {
190*5113495bSYour Name if (!plat_priv)
191*5113495bSYour Name return -ENODEV;
192*5113495bSYour Name
193*5113495bSYour Name switch (plat_priv->bus_type) {
194*5113495bSYour Name case CNSS_BUS_PCI:
195*5113495bSYour Name return cnss_pci_load_aux(plat_priv->bus_priv);
196*5113495bSYour Name default:
197*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
198*5113495bSYour Name plat_priv->bus_type);
199*5113495bSYour Name return -EINVAL;
200*5113495bSYour Name }
201*5113495bSYour Name }
202*5113495bSYour Name
cnss_bus_handle_dev_sol_irq(struct cnss_plat_data * plat_priv)203*5113495bSYour Name int cnss_bus_handle_dev_sol_irq(struct cnss_plat_data *plat_priv)
204*5113495bSYour Name {
205*5113495bSYour Name if (!plat_priv)
206*5113495bSYour Name return -ENODEV;
207*5113495bSYour Name
208*5113495bSYour Name switch (plat_priv->bus_type) {
209*5113495bSYour Name case CNSS_BUS_PCI:
210*5113495bSYour Name return cnss_pci_handle_dev_sol_irq(plat_priv->bus_priv);
211*5113495bSYour Name default:
212*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
213*5113495bSYour Name plat_priv->bus_type);
214*5113495bSYour Name return -EINVAL;
215*5113495bSYour Name }
216*5113495bSYour Name }
217*5113495bSYour Name
cnss_bus_alloc_fw_mem(struct cnss_plat_data * plat_priv)218*5113495bSYour Name int cnss_bus_alloc_fw_mem(struct cnss_plat_data *plat_priv)
219*5113495bSYour Name {
220*5113495bSYour Name if (!plat_priv)
221*5113495bSYour Name return -ENODEV;
222*5113495bSYour Name
223*5113495bSYour Name switch (plat_priv->bus_type) {
224*5113495bSYour Name case CNSS_BUS_PCI:
225*5113495bSYour Name return cnss_pci_alloc_fw_mem(plat_priv->bus_priv);
226*5113495bSYour Name default:
227*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
228*5113495bSYour Name plat_priv->bus_type);
229*5113495bSYour Name return -EINVAL;
230*5113495bSYour Name }
231*5113495bSYour Name }
232*5113495bSYour Name
cnss_bus_alloc_qdss_mem(struct cnss_plat_data * plat_priv)233*5113495bSYour Name int cnss_bus_alloc_qdss_mem(struct cnss_plat_data *plat_priv)
234*5113495bSYour Name {
235*5113495bSYour Name if (!plat_priv)
236*5113495bSYour Name return -ENODEV;
237*5113495bSYour Name
238*5113495bSYour Name switch (plat_priv->bus_type) {
239*5113495bSYour Name case CNSS_BUS_PCI:
240*5113495bSYour Name return cnss_pci_alloc_qdss_mem(plat_priv->bus_priv);
241*5113495bSYour Name default:
242*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
243*5113495bSYour Name plat_priv->bus_type);
244*5113495bSYour Name return -EINVAL;
245*5113495bSYour Name }
246*5113495bSYour Name }
247*5113495bSYour Name
cnss_bus_free_qdss_mem(struct cnss_plat_data * plat_priv)248*5113495bSYour Name void cnss_bus_free_qdss_mem(struct cnss_plat_data *plat_priv)
249*5113495bSYour Name {
250*5113495bSYour Name if (!plat_priv)
251*5113495bSYour Name return;
252*5113495bSYour Name
253*5113495bSYour Name switch (plat_priv->bus_type) {
254*5113495bSYour Name case CNSS_BUS_PCI:
255*5113495bSYour Name cnss_pci_free_qdss_mem(plat_priv->bus_priv);
256*5113495bSYour Name return;
257*5113495bSYour Name default:
258*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
259*5113495bSYour Name plat_priv->bus_type);
260*5113495bSYour Name return;
261*5113495bSYour Name }
262*5113495bSYour Name }
263*5113495bSYour Name
cnss_bus_get_wake_irq(struct cnss_plat_data * plat_priv)264*5113495bSYour Name u32 cnss_bus_get_wake_irq(struct cnss_plat_data *plat_priv)
265*5113495bSYour Name {
266*5113495bSYour Name if (!plat_priv)
267*5113495bSYour Name return -ENODEV;
268*5113495bSYour Name
269*5113495bSYour Name switch (plat_priv->bus_type) {
270*5113495bSYour Name case CNSS_BUS_PCI:
271*5113495bSYour Name return cnss_pci_get_wake_msi(plat_priv->bus_priv);
272*5113495bSYour Name default:
273*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
274*5113495bSYour Name plat_priv->bus_type);
275*5113495bSYour Name return -EINVAL;
276*5113495bSYour Name }
277*5113495bSYour Name }
278*5113495bSYour Name
cnss_bus_force_fw_assert_hdlr(struct cnss_plat_data * plat_priv)279*5113495bSYour Name int cnss_bus_force_fw_assert_hdlr(struct cnss_plat_data *plat_priv)
280*5113495bSYour Name {
281*5113495bSYour Name if (!plat_priv)
282*5113495bSYour Name return -ENODEV;
283*5113495bSYour Name
284*5113495bSYour Name switch (plat_priv->bus_type) {
285*5113495bSYour Name case CNSS_BUS_PCI:
286*5113495bSYour Name return cnss_pci_force_fw_assert_hdlr(plat_priv->bus_priv);
287*5113495bSYour Name default:
288*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
289*5113495bSYour Name plat_priv->bus_type);
290*5113495bSYour Name return -EINVAL;
291*5113495bSYour Name }
292*5113495bSYour Name }
293*5113495bSYour Name
cnss_bus_qmi_send_get(struct cnss_plat_data * plat_priv)294*5113495bSYour Name int cnss_bus_qmi_send_get(struct cnss_plat_data *plat_priv)
295*5113495bSYour Name {
296*5113495bSYour Name if (!plat_priv)
297*5113495bSYour Name return -ENODEV;
298*5113495bSYour Name
299*5113495bSYour Name switch (plat_priv->bus_type) {
300*5113495bSYour Name case CNSS_BUS_PCI:
301*5113495bSYour Name return cnss_pci_qmi_send_get(plat_priv->bus_priv);
302*5113495bSYour Name default:
303*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
304*5113495bSYour Name plat_priv->bus_type);
305*5113495bSYour Name return -EINVAL;
306*5113495bSYour Name }
307*5113495bSYour Name }
308*5113495bSYour Name
cnss_bus_qmi_send_put(struct cnss_plat_data * plat_priv)309*5113495bSYour Name int cnss_bus_qmi_send_put(struct cnss_plat_data *plat_priv)
310*5113495bSYour Name {
311*5113495bSYour Name if (!plat_priv)
312*5113495bSYour Name return -ENODEV;
313*5113495bSYour Name
314*5113495bSYour Name switch (plat_priv->bus_type) {
315*5113495bSYour Name case CNSS_BUS_PCI:
316*5113495bSYour Name return cnss_pci_qmi_send_put(plat_priv->bus_priv);
317*5113495bSYour Name default:
318*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
319*5113495bSYour Name plat_priv->bus_type);
320*5113495bSYour Name return -EINVAL;
321*5113495bSYour Name }
322*5113495bSYour Name }
323*5113495bSYour Name
cnss_bus_fw_boot_timeout_hdlr(struct timer_list * t)324*5113495bSYour Name void cnss_bus_fw_boot_timeout_hdlr(struct timer_list *t)
325*5113495bSYour Name {
326*5113495bSYour Name struct cnss_plat_data *plat_priv =
327*5113495bSYour Name from_timer(plat_priv, t, fw_boot_timer);
328*5113495bSYour Name
329*5113495bSYour Name if (!plat_priv)
330*5113495bSYour Name return;
331*5113495bSYour Name
332*5113495bSYour Name switch (plat_priv->bus_type) {
333*5113495bSYour Name case CNSS_BUS_PCI:
334*5113495bSYour Name return cnss_pci_fw_boot_timeout_hdlr(plat_priv->bus_priv);
335*5113495bSYour Name default:
336*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
337*5113495bSYour Name plat_priv->bus_type);
338*5113495bSYour Name return;
339*5113495bSYour Name }
340*5113495bSYour Name }
341*5113495bSYour Name
cnss_bus_collect_dump_info(struct cnss_plat_data * plat_priv,bool in_panic)342*5113495bSYour Name void cnss_bus_collect_dump_info(struct cnss_plat_data *plat_priv, bool in_panic)
343*5113495bSYour Name {
344*5113495bSYour Name if (!plat_priv)
345*5113495bSYour Name return;
346*5113495bSYour Name
347*5113495bSYour Name switch (plat_priv->bus_type) {
348*5113495bSYour Name case CNSS_BUS_PCI:
349*5113495bSYour Name return cnss_pci_collect_dump_info(plat_priv->bus_priv,
350*5113495bSYour Name in_panic);
351*5113495bSYour Name default:
352*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
353*5113495bSYour Name plat_priv->bus_type);
354*5113495bSYour Name return;
355*5113495bSYour Name }
356*5113495bSYour Name }
357*5113495bSYour Name
cnss_bus_device_crashed(struct cnss_plat_data * plat_priv)358*5113495bSYour Name void cnss_bus_device_crashed(struct cnss_plat_data *plat_priv)
359*5113495bSYour Name {
360*5113495bSYour Name if (!plat_priv)
361*5113495bSYour Name return;
362*5113495bSYour Name
363*5113495bSYour Name switch (plat_priv->bus_type) {
364*5113495bSYour Name case CNSS_BUS_PCI:
365*5113495bSYour Name return cnss_pci_device_crashed(plat_priv->bus_priv);
366*5113495bSYour Name default:
367*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
368*5113495bSYour Name plat_priv->bus_type);
369*5113495bSYour Name return;
370*5113495bSYour Name }
371*5113495bSYour Name }
372*5113495bSYour Name
cnss_bus_call_driver_probe(struct cnss_plat_data * plat_priv)373*5113495bSYour Name int cnss_bus_call_driver_probe(struct cnss_plat_data *plat_priv)
374*5113495bSYour Name {
375*5113495bSYour Name if (!plat_priv)
376*5113495bSYour Name return -ENODEV;
377*5113495bSYour Name
378*5113495bSYour Name switch (plat_priv->bus_type) {
379*5113495bSYour Name case CNSS_BUS_PCI:
380*5113495bSYour Name return cnss_pci_call_driver_probe(plat_priv->bus_priv);
381*5113495bSYour Name default:
382*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
383*5113495bSYour Name plat_priv->bus_type);
384*5113495bSYour Name return -EINVAL;
385*5113495bSYour Name }
386*5113495bSYour Name }
387*5113495bSYour Name
cnss_bus_call_driver_remove(struct cnss_plat_data * plat_priv)388*5113495bSYour Name int cnss_bus_call_driver_remove(struct cnss_plat_data *plat_priv)
389*5113495bSYour Name {
390*5113495bSYour Name if (!plat_priv)
391*5113495bSYour Name return -ENODEV;
392*5113495bSYour Name
393*5113495bSYour Name switch (plat_priv->bus_type) {
394*5113495bSYour Name case CNSS_BUS_PCI:
395*5113495bSYour Name return cnss_pci_call_driver_remove(plat_priv->bus_priv);
396*5113495bSYour Name default:
397*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
398*5113495bSYour Name plat_priv->bus_type);
399*5113495bSYour Name return -EINVAL;
400*5113495bSYour Name }
401*5113495bSYour Name }
402*5113495bSYour Name
cnss_bus_dev_powerup(struct cnss_plat_data * plat_priv)403*5113495bSYour Name int cnss_bus_dev_powerup(struct cnss_plat_data *plat_priv)
404*5113495bSYour Name {
405*5113495bSYour Name if (!plat_priv)
406*5113495bSYour Name return -ENODEV;
407*5113495bSYour Name
408*5113495bSYour Name switch (plat_priv->bus_type) {
409*5113495bSYour Name case CNSS_BUS_PCI:
410*5113495bSYour Name return cnss_pci_dev_powerup(plat_priv->bus_priv);
411*5113495bSYour Name default:
412*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
413*5113495bSYour Name plat_priv->bus_type);
414*5113495bSYour Name return -EINVAL;
415*5113495bSYour Name }
416*5113495bSYour Name }
417*5113495bSYour Name
cnss_bus_dev_shutdown(struct cnss_plat_data * plat_priv)418*5113495bSYour Name int cnss_bus_dev_shutdown(struct cnss_plat_data *plat_priv)
419*5113495bSYour Name {
420*5113495bSYour Name if (!plat_priv)
421*5113495bSYour Name return -ENODEV;
422*5113495bSYour Name
423*5113495bSYour Name switch (plat_priv->bus_type) {
424*5113495bSYour Name case CNSS_BUS_PCI:
425*5113495bSYour Name return cnss_pci_dev_shutdown(plat_priv->bus_priv);
426*5113495bSYour Name default:
427*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
428*5113495bSYour Name plat_priv->bus_type);
429*5113495bSYour Name return -EINVAL;
430*5113495bSYour Name }
431*5113495bSYour Name }
432*5113495bSYour Name
cnss_bus_dev_crash_shutdown(struct cnss_plat_data * plat_priv)433*5113495bSYour Name int cnss_bus_dev_crash_shutdown(struct cnss_plat_data *plat_priv)
434*5113495bSYour Name {
435*5113495bSYour Name if (!plat_priv)
436*5113495bSYour Name return -ENODEV;
437*5113495bSYour Name
438*5113495bSYour Name switch (plat_priv->bus_type) {
439*5113495bSYour Name case CNSS_BUS_PCI:
440*5113495bSYour Name return cnss_pci_dev_crash_shutdown(plat_priv->bus_priv);
441*5113495bSYour Name default:
442*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
443*5113495bSYour Name plat_priv->bus_type);
444*5113495bSYour Name return -EINVAL;
445*5113495bSYour Name }
446*5113495bSYour Name }
447*5113495bSYour Name
cnss_bus_dev_ramdump(struct cnss_plat_data * plat_priv)448*5113495bSYour Name int cnss_bus_dev_ramdump(struct cnss_plat_data *plat_priv)
449*5113495bSYour Name {
450*5113495bSYour Name if (!plat_priv)
451*5113495bSYour Name return -ENODEV;
452*5113495bSYour Name
453*5113495bSYour Name switch (plat_priv->bus_type) {
454*5113495bSYour Name case CNSS_BUS_PCI:
455*5113495bSYour Name return cnss_pci_dev_ramdump(plat_priv->bus_priv);
456*5113495bSYour Name default:
457*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
458*5113495bSYour Name plat_priv->bus_type);
459*5113495bSYour Name return -EINVAL;
460*5113495bSYour Name }
461*5113495bSYour Name }
462*5113495bSYour Name
cnss_bus_register_driver_hdlr(struct cnss_plat_data * plat_priv,void * data)463*5113495bSYour Name int cnss_bus_register_driver_hdlr(struct cnss_plat_data *plat_priv, void *data)
464*5113495bSYour Name {
465*5113495bSYour Name if (!plat_priv)
466*5113495bSYour Name return -ENODEV;
467*5113495bSYour Name
468*5113495bSYour Name switch (plat_priv->bus_type) {
469*5113495bSYour Name case CNSS_BUS_PCI:
470*5113495bSYour Name return cnss_pci_register_driver_hdlr(plat_priv->bus_priv, data);
471*5113495bSYour Name default:
472*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
473*5113495bSYour Name plat_priv->bus_type);
474*5113495bSYour Name return -EINVAL;
475*5113495bSYour Name }
476*5113495bSYour Name }
477*5113495bSYour Name
cnss_bus_runtime_pm_get_sync(struct cnss_plat_data * plat_priv)478*5113495bSYour Name int cnss_bus_runtime_pm_get_sync(struct cnss_plat_data *plat_priv)
479*5113495bSYour Name {
480*5113495bSYour Name if (!plat_priv)
481*5113495bSYour Name return -ENODEV;
482*5113495bSYour Name
483*5113495bSYour Name switch (plat_priv->bus_type) {
484*5113495bSYour Name case CNSS_BUS_PCI:
485*5113495bSYour Name return cnss_pci_pm_runtime_get_sync(plat_priv->bus_priv, RTPM_ID_CNSS);
486*5113495bSYour Name default:
487*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
488*5113495bSYour Name plat_priv->bus_type);
489*5113495bSYour Name return -EINVAL;
490*5113495bSYour Name }
491*5113495bSYour Name }
492*5113495bSYour Name
cnss_bus_runtime_pm_put(struct cnss_plat_data * plat_priv)493*5113495bSYour Name void cnss_bus_runtime_pm_put(struct cnss_plat_data *plat_priv)
494*5113495bSYour Name {
495*5113495bSYour Name if (!plat_priv)
496*5113495bSYour Name return;
497*5113495bSYour Name
498*5113495bSYour Name switch (plat_priv->bus_type) {
499*5113495bSYour Name case CNSS_BUS_PCI:
500*5113495bSYour Name cnss_pci_pm_runtime_mark_last_busy(plat_priv->bus_priv);
501*5113495bSYour Name cnss_pci_pm_runtime_put_autosuspend(plat_priv->bus_priv, RTPM_ID_CNSS);
502*5113495bSYour Name break;
503*5113495bSYour Name default:
504*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
505*5113495bSYour Name plat_priv->bus_type);
506*5113495bSYour Name }
507*5113495bSYour Name }
508*5113495bSYour Name
cnss_bus_unregister_driver_hdlr(struct cnss_plat_data * plat_priv)509*5113495bSYour Name int cnss_bus_unregister_driver_hdlr(struct cnss_plat_data *plat_priv)
510*5113495bSYour Name {
511*5113495bSYour Name if (!plat_priv)
512*5113495bSYour Name return -ENODEV;
513*5113495bSYour Name
514*5113495bSYour Name switch (plat_priv->bus_type) {
515*5113495bSYour Name case CNSS_BUS_PCI:
516*5113495bSYour Name return cnss_pci_unregister_driver_hdlr(plat_priv->bus_priv);
517*5113495bSYour Name default:
518*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
519*5113495bSYour Name plat_priv->bus_type);
520*5113495bSYour Name return -EINVAL;
521*5113495bSYour Name }
522*5113495bSYour Name }
523*5113495bSYour Name
cnss_bus_call_driver_modem_status(struct cnss_plat_data * plat_priv,int modem_current_status)524*5113495bSYour Name int cnss_bus_call_driver_modem_status(struct cnss_plat_data *plat_priv,
525*5113495bSYour Name int modem_current_status)
526*5113495bSYour Name {
527*5113495bSYour Name if (!plat_priv)
528*5113495bSYour Name return -ENODEV;
529*5113495bSYour Name
530*5113495bSYour Name switch (plat_priv->bus_type) {
531*5113495bSYour Name case CNSS_BUS_PCI:
532*5113495bSYour Name return cnss_pci_call_driver_modem_status(plat_priv->bus_priv,
533*5113495bSYour Name modem_current_status);
534*5113495bSYour Name default:
535*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
536*5113495bSYour Name plat_priv->bus_type);
537*5113495bSYour Name return -EINVAL;
538*5113495bSYour Name }
539*5113495bSYour Name }
540*5113495bSYour Name
cnss_bus_update_status(struct cnss_plat_data * plat_priv,enum cnss_driver_status status)541*5113495bSYour Name int cnss_bus_update_status(struct cnss_plat_data *plat_priv,
542*5113495bSYour Name enum cnss_driver_status status)
543*5113495bSYour Name {
544*5113495bSYour Name if (!plat_priv)
545*5113495bSYour Name return -ENODEV;
546*5113495bSYour Name
547*5113495bSYour Name switch (plat_priv->bus_type) {
548*5113495bSYour Name case CNSS_BUS_PCI:
549*5113495bSYour Name return cnss_pci_update_status(plat_priv->bus_priv, status);
550*5113495bSYour Name default:
551*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
552*5113495bSYour Name plat_priv->bus_type);
553*5113495bSYour Name return -EINVAL;
554*5113495bSYour Name }
555*5113495bSYour Name }
556*5113495bSYour Name
cnss_bus_update_uevent(struct cnss_plat_data * plat_priv,enum cnss_driver_status status,void * data)557*5113495bSYour Name int cnss_bus_update_uevent(struct cnss_plat_data *plat_priv,
558*5113495bSYour Name enum cnss_driver_status status, void *data)
559*5113495bSYour Name {
560*5113495bSYour Name if (!plat_priv)
561*5113495bSYour Name return -ENODEV;
562*5113495bSYour Name
563*5113495bSYour Name switch (plat_priv->bus_type) {
564*5113495bSYour Name case CNSS_BUS_PCI:
565*5113495bSYour Name return cnss_pci_call_driver_uevent(plat_priv->bus_priv,
566*5113495bSYour Name status, data);
567*5113495bSYour Name default:
568*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
569*5113495bSYour Name plat_priv->bus_type);
570*5113495bSYour Name return -EINVAL;
571*5113495bSYour Name }
572*5113495bSYour Name }
573*5113495bSYour Name
cnss_bus_is_device_down(struct cnss_plat_data * plat_priv)574*5113495bSYour Name int cnss_bus_is_device_down(struct cnss_plat_data *plat_priv)
575*5113495bSYour Name {
576*5113495bSYour Name if (!plat_priv)
577*5113495bSYour Name return -ENODEV;
578*5113495bSYour Name
579*5113495bSYour Name switch (plat_priv->bus_type) {
580*5113495bSYour Name case CNSS_BUS_PCI:
581*5113495bSYour Name return cnss_pcie_is_device_down(plat_priv->bus_priv);
582*5113495bSYour Name default:
583*5113495bSYour Name cnss_pr_dbg("Unsupported bus type: %d\n",
584*5113495bSYour Name plat_priv->bus_type);
585*5113495bSYour Name return 0;
586*5113495bSYour Name }
587*5113495bSYour Name }
588*5113495bSYour Name
cnss_bus_shutdown_cleanup(struct cnss_plat_data * plat_priv)589*5113495bSYour Name int cnss_bus_shutdown_cleanup(struct cnss_plat_data *plat_priv)
590*5113495bSYour Name {
591*5113495bSYour Name if (!plat_priv)
592*5113495bSYour Name return -ENODEV;
593*5113495bSYour Name
594*5113495bSYour Name switch (plat_priv->bus_type) {
595*5113495bSYour Name case CNSS_BUS_PCI:
596*5113495bSYour Name return cnss_pci_shutdown_cleanup(plat_priv->bus_priv);
597*5113495bSYour Name default:
598*5113495bSYour Name cnss_pr_dbg("Unsupported bus type: %d\n",
599*5113495bSYour Name plat_priv->bus_type);
600*5113495bSYour Name return 0;
601*5113495bSYour Name }
602*5113495bSYour Name }
603*5113495bSYour Name
cnss_bus_check_link_status(struct cnss_plat_data * plat_priv)604*5113495bSYour Name int cnss_bus_check_link_status(struct cnss_plat_data *plat_priv)
605*5113495bSYour Name {
606*5113495bSYour Name if (!plat_priv)
607*5113495bSYour Name return -ENODEV;
608*5113495bSYour Name
609*5113495bSYour Name switch (plat_priv->bus_type) {
610*5113495bSYour Name case CNSS_BUS_PCI:
611*5113495bSYour Name return cnss_pci_check_link_status(plat_priv->bus_priv);
612*5113495bSYour Name default:
613*5113495bSYour Name cnss_pr_dbg("Unsupported bus type: %d\n",
614*5113495bSYour Name plat_priv->bus_type);
615*5113495bSYour Name return 0;
616*5113495bSYour Name }
617*5113495bSYour Name }
618*5113495bSYour Name
cnss_bus_recover_link_down(struct cnss_plat_data * plat_priv)619*5113495bSYour Name int cnss_bus_recover_link_down(struct cnss_plat_data *plat_priv)
620*5113495bSYour Name {
621*5113495bSYour Name if (!plat_priv)
622*5113495bSYour Name return -ENODEV;
623*5113495bSYour Name
624*5113495bSYour Name switch (plat_priv->bus_type) {
625*5113495bSYour Name case CNSS_BUS_PCI:
626*5113495bSYour Name return cnss_pci_recover_link_down(plat_priv->bus_priv);
627*5113495bSYour Name default:
628*5113495bSYour Name cnss_pr_dbg("Unsupported bus type: %d\n",
629*5113495bSYour Name plat_priv->bus_type);
630*5113495bSYour Name return -EINVAL;
631*5113495bSYour Name }
632*5113495bSYour Name }
633*5113495bSYour Name
cnss_bus_debug_reg_read(struct cnss_plat_data * plat_priv,u32 offset,u32 * val,bool raw_access)634*5113495bSYour Name int cnss_bus_debug_reg_read(struct cnss_plat_data *plat_priv, u32 offset,
635*5113495bSYour Name u32 *val, bool raw_access)
636*5113495bSYour Name {
637*5113495bSYour Name if (!plat_priv)
638*5113495bSYour Name return -ENODEV;
639*5113495bSYour Name
640*5113495bSYour Name switch (plat_priv->bus_type) {
641*5113495bSYour Name case CNSS_BUS_PCI:
642*5113495bSYour Name return cnss_pci_debug_reg_read(plat_priv->bus_priv, offset,
643*5113495bSYour Name val, raw_access);
644*5113495bSYour Name default:
645*5113495bSYour Name cnss_pr_dbg("Unsupported bus type: %d\n",
646*5113495bSYour Name plat_priv->bus_type);
647*5113495bSYour Name return 0;
648*5113495bSYour Name }
649*5113495bSYour Name }
650*5113495bSYour Name
cnss_bus_debug_reg_write(struct cnss_plat_data * plat_priv,u32 offset,u32 val,bool raw_access)651*5113495bSYour Name int cnss_bus_debug_reg_write(struct cnss_plat_data *plat_priv, u32 offset,
652*5113495bSYour Name u32 val, bool raw_access)
653*5113495bSYour Name {
654*5113495bSYour Name if (!plat_priv)
655*5113495bSYour Name return -ENODEV;
656*5113495bSYour Name
657*5113495bSYour Name switch (plat_priv->bus_type) {
658*5113495bSYour Name case CNSS_BUS_PCI:
659*5113495bSYour Name return cnss_pci_debug_reg_write(plat_priv->bus_priv, offset,
660*5113495bSYour Name val, raw_access);
661*5113495bSYour Name default:
662*5113495bSYour Name cnss_pr_dbg("Unsupported bus type: %d\n",
663*5113495bSYour Name plat_priv->bus_type);
664*5113495bSYour Name return 0;
665*5113495bSYour Name }
666*5113495bSYour Name }
667*5113495bSYour Name
cnss_bus_get_iova(struct cnss_plat_data * plat_priv,u64 * addr,u64 * size)668*5113495bSYour Name int cnss_bus_get_iova(struct cnss_plat_data *plat_priv, u64 *addr, u64 *size)
669*5113495bSYour Name {
670*5113495bSYour Name if (!plat_priv)
671*5113495bSYour Name return -ENODEV;
672*5113495bSYour Name
673*5113495bSYour Name switch (plat_priv->bus_type) {
674*5113495bSYour Name case CNSS_BUS_PCI:
675*5113495bSYour Name return cnss_pci_get_iova(plat_priv->bus_priv, addr, size);
676*5113495bSYour Name default:
677*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
678*5113495bSYour Name plat_priv->bus_type);
679*5113495bSYour Name return -EINVAL;
680*5113495bSYour Name }
681*5113495bSYour Name }
682*5113495bSYour Name
cnss_bus_get_iova_ipa(struct cnss_plat_data * plat_priv,u64 * addr,u64 * size)683*5113495bSYour Name int cnss_bus_get_iova_ipa(struct cnss_plat_data *plat_priv, u64 *addr,
684*5113495bSYour Name u64 *size)
685*5113495bSYour Name {
686*5113495bSYour Name if (!plat_priv)
687*5113495bSYour Name return -ENODEV;
688*5113495bSYour Name
689*5113495bSYour Name switch (plat_priv->bus_type) {
690*5113495bSYour Name case CNSS_BUS_PCI:
691*5113495bSYour Name return cnss_pci_get_iova_ipa(plat_priv->bus_priv, addr, size);
692*5113495bSYour Name default:
693*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
694*5113495bSYour Name plat_priv->bus_type);
695*5113495bSYour Name return -EINVAL;
696*5113495bSYour Name }
697*5113495bSYour Name }
698*5113495bSYour Name
cnss_bus_is_smmu_s1_enabled(struct cnss_plat_data * plat_priv)699*5113495bSYour Name bool cnss_bus_is_smmu_s1_enabled(struct cnss_plat_data *plat_priv)
700*5113495bSYour Name {
701*5113495bSYour Name if (!plat_priv)
702*5113495bSYour Name return false;
703*5113495bSYour Name
704*5113495bSYour Name switch (plat_priv->bus_type) {
705*5113495bSYour Name case CNSS_BUS_PCI:
706*5113495bSYour Name return cnss_pci_is_smmu_s1_enabled(plat_priv->bus_priv);
707*5113495bSYour Name default:
708*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
709*5113495bSYour Name plat_priv->bus_type);
710*5113495bSYour Name return false;
711*5113495bSYour Name }
712*5113495bSYour Name }
713*5113495bSYour Name
cnss_bus_update_time_sync_period(struct cnss_plat_data * plat_priv,unsigned int time_sync_period)714*5113495bSYour Name int cnss_bus_update_time_sync_period(struct cnss_plat_data *plat_priv,
715*5113495bSYour Name unsigned int time_sync_period)
716*5113495bSYour Name {
717*5113495bSYour Name if (!plat_priv)
718*5113495bSYour Name return -ENODEV;
719*5113495bSYour Name
720*5113495bSYour Name switch (plat_priv->bus_type) {
721*5113495bSYour Name case CNSS_BUS_PCI:
722*5113495bSYour Name return cnss_pci_update_time_sync_period(plat_priv->bus_priv,
723*5113495bSYour Name time_sync_period);
724*5113495bSYour Name default:
725*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n",
726*5113495bSYour Name plat_priv->bus_type);
727*5113495bSYour Name return -EINVAL;
728*5113495bSYour Name }
729*5113495bSYour Name }
730*5113495bSYour Name
cnss_bus_set_therm_cdev_state(struct cnss_plat_data * plat_priv,unsigned long thermal_state,int tcdev_id)731*5113495bSYour Name int cnss_bus_set_therm_cdev_state(struct cnss_plat_data *plat_priv,
732*5113495bSYour Name unsigned long thermal_state,
733*5113495bSYour Name int tcdev_id)
734*5113495bSYour Name {
735*5113495bSYour Name if (!plat_priv)
736*5113495bSYour Name return -ENODEV;
737*5113495bSYour Name
738*5113495bSYour Name switch (plat_priv->bus_type) {
739*5113495bSYour Name case CNSS_BUS_PCI:
740*5113495bSYour Name return cnss_pci_set_therm_cdev_state(plat_priv->bus_priv,
741*5113495bSYour Name thermal_state,
742*5113495bSYour Name tcdev_id);
743*5113495bSYour Name default:
744*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n", plat_priv->bus_type);
745*5113495bSYour Name return -EINVAL;
746*5113495bSYour Name }
747*5113495bSYour Name }
748*5113495bSYour Name
cnss_bus_get_msi_assignment(struct cnss_plat_data * plat_priv,char * msi_name,int * num_vectors,u32 * user_base_data,u32 * base_vector)749*5113495bSYour Name int cnss_bus_get_msi_assignment(struct cnss_plat_data *plat_priv,
750*5113495bSYour Name char *msi_name,
751*5113495bSYour Name int *num_vectors,
752*5113495bSYour Name u32 *user_base_data,
753*5113495bSYour Name u32 *base_vector)
754*5113495bSYour Name {
755*5113495bSYour Name if (!plat_priv)
756*5113495bSYour Name return -ENODEV;
757*5113495bSYour Name
758*5113495bSYour Name switch (plat_priv->bus_type) {
759*5113495bSYour Name case CNSS_BUS_PCI:
760*5113495bSYour Name return cnss_pci_get_user_msi_assignment(plat_priv->bus_priv,
761*5113495bSYour Name msi_name,
762*5113495bSYour Name num_vectors,
763*5113495bSYour Name user_base_data,
764*5113495bSYour Name base_vector);
765*5113495bSYour Name default:
766*5113495bSYour Name cnss_pr_err("Unsupported bus type: %d\n", plat_priv->bus_type);
767*5113495bSYour Name return -EINVAL;
768*5113495bSYour Name }
769*5113495bSYour Name }
770*5113495bSYour Name
771*5113495bSYour Name #if IS_ENABLED(CONFIG_MHI_BUS_MISC)
cnss_bus_disable_mhi_satellite_cfg(struct cnss_plat_data * plat_priv)772*5113495bSYour Name void cnss_bus_disable_mhi_satellite_cfg(struct cnss_plat_data *plat_priv)
773*5113495bSYour Name {
774*5113495bSYour Name struct cnss_pci_data *pci_priv;
775*5113495bSYour Name
776*5113495bSYour Name pci_priv = plat_priv->bus_priv;
777*5113495bSYour Name if (!pci_priv) {
778*5113495bSYour Name cnss_pr_err("mhi satellite could not be disabled since pci_priv is NULL\n");
779*5113495bSYour Name return;
780*5113495bSYour Name }
781*5113495bSYour Name
782*5113495bSYour Name switch (plat_priv->bus_type) {
783*5113495bSYour Name case CNSS_BUS_PCI:
784*5113495bSYour Name /* MHI satellite configuration is only for KIWI V2 and
785*5113495bSYour Name * that too only in DRV mode.
786*5113495bSYour Name */
787*5113495bSYour Name if (plat_priv->device_id == KIWI_DEVICE_ID &&
788*5113495bSYour Name plat_priv->device_version.major_version == FW_V2_NUMBER) {
789*5113495bSYour Name cnss_pr_dbg("Remove MHI satellite configuration\n");
790*5113495bSYour Name return cnss_mhi_controller_set_base(pci_priv, 0);
791*5113495bSYour Name }
792*5113495bSYour Name break;
793*5113495bSYour Name default:
794*5113495bSYour Name cnss_pr_dbg("Unsupported bus type: %d, ignore disable mhi satellite cfg\n",
795*5113495bSYour Name plat_priv->bus_type);
796*5113495bSYour Name return;
797*5113495bSYour Name }
798*5113495bSYour Name
799*5113495bSYour Name return;
800*5113495bSYour Name }
801*5113495bSYour Name #else
cnss_bus_disable_mhi_satellite_cfg(struct cnss_plat_data * pci_priv)802*5113495bSYour Name void cnss_bus_disable_mhi_satellite_cfg(struct cnss_plat_data *pci_priv)
803*5113495bSYour Name {
804*5113495bSYour Name }
805*5113495bSYour Name #endif
806