xref: /wlan-driver/qca-wifi-host-cmn/qdf/linux/src/qdf_dev.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2018,2021 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name  * above copyright notice and this permission notice appear in all
7*5113495bSYour Name  * copies.
8*5113495bSYour Name  *
9*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name  */
18*5113495bSYour Name 
19*5113495bSYour Name /**
20*5113495bSYour Name  * DOC: qdf_dev
21*5113495bSYour Name  * This file provides OS dependent device related APIs
22*5113495bSYour Name  */
23*5113495bSYour Name 
24*5113495bSYour Name #include "qdf_dev.h"
25*5113495bSYour Name #include "qdf_mem.h"
26*5113495bSYour Name #include "qdf_util.h"
27*5113495bSYour Name #include "qdf_module.h"
28*5113495bSYour Name #include <linux/irq.h>
29*5113495bSYour Name 
30*5113495bSYour Name QDF_STATUS
qdf_dev_alloc_mem(struct qdf_dev * qdfdev,struct qdf_devm ** mrptr,uint32_t reqsize,uint32_t mask)31*5113495bSYour Name qdf_dev_alloc_mem(struct qdf_dev *qdfdev, struct qdf_devm **mrptr,
32*5113495bSYour Name 		  uint32_t reqsize, uint32_t mask)
33*5113495bSYour Name {
34*5113495bSYour Name 	struct qdf_devm *mptr;
35*5113495bSYour Name 
36*5113495bSYour Name 	if (!qdfdev)
37*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
38*5113495bSYour Name 
39*5113495bSYour Name 	mptr = devm_kzalloc((struct device *)qdfdev, reqsize, mask);
40*5113495bSYour Name 
41*5113495bSYour Name 	if (!mrptr)
42*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
43*5113495bSYour Name 
44*5113495bSYour Name 	*mrptr = mptr;
45*5113495bSYour Name 
46*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
47*5113495bSYour Name }
48*5113495bSYour Name 
49*5113495bSYour Name qdf_export_symbol(qdf_dev_alloc_mem);
50*5113495bSYour Name 
51*5113495bSYour Name QDF_STATUS
qdf_dev_release_mem(struct qdf_dev * qdfdev,struct qdf_devm * mrptr)52*5113495bSYour Name qdf_dev_release_mem(struct qdf_dev *qdfdev, struct qdf_devm *mrptr)
53*5113495bSYour Name {
54*5113495bSYour Name 	if (!mrptr)
55*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
56*5113495bSYour Name 
57*5113495bSYour Name 	devm_kfree((struct device *)qdfdev, mrptr);
58*5113495bSYour Name 
59*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
60*5113495bSYour Name }
61*5113495bSYour Name 
62*5113495bSYour Name qdf_export_symbol(qdf_dev_release_mem);
63*5113495bSYour Name 
64*5113495bSYour Name QDF_STATUS
qdf_dev_modify_irq_status(uint32_t irnum,unsigned long cmask,unsigned long smask)65*5113495bSYour Name qdf_dev_modify_irq_status(uint32_t irnum, unsigned long cmask,
66*5113495bSYour Name 			  unsigned long smask)
67*5113495bSYour Name {
68*5113495bSYour Name 	if (irnum <= 0)
69*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
70*5113495bSYour Name 
71*5113495bSYour Name 	irq_modify_status(irnum, cmask, smask);
72*5113495bSYour Name 
73*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
74*5113495bSYour Name }
75*5113495bSYour Name 
76*5113495bSYour Name qdf_export_symbol(qdf_dev_modify_irq_status);
77*5113495bSYour Name 
78*5113495bSYour Name QDF_STATUS
qdf_dev_set_irq_affinity(uint32_t irnum,struct qdf_cpu_mask * cpmask)79*5113495bSYour Name qdf_dev_set_irq_affinity(uint32_t irnum, struct qdf_cpu_mask *cpmask)
80*5113495bSYour Name {
81*5113495bSYour Name 	int ret;
82*5113495bSYour Name 
83*5113495bSYour Name 	if (irnum <= 0)
84*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
85*5113495bSYour Name 
86*5113495bSYour Name 	ret = irq_set_affinity_hint(irnum, (struct cpumask *)cpmask);
87*5113495bSYour Name 
88*5113495bSYour Name 	return qdf_status_from_os_return(ret);
89*5113495bSYour Name }
90*5113495bSYour Name 
91*5113495bSYour Name qdf_export_symbol(qdf_dev_set_irq_affinity);
92*5113495bSYour Name 
93*5113495bSYour Name #ifdef ENHANCED_OS_ABSTRACTION
94*5113495bSYour Name QDF_STATUS
qdf_dev_set_irq_status_flags(unsigned int irnum,unsigned long set)95*5113495bSYour Name qdf_dev_set_irq_status_flags(unsigned int irnum, unsigned long set)
96*5113495bSYour Name {
97*5113495bSYour Name 	if (irnum <= 0)
98*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
99*5113495bSYour Name 
100*5113495bSYour Name 	irq_set_status_flags(irnum, set);
101*5113495bSYour Name 
102*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
103*5113495bSYour Name }
104*5113495bSYour Name 
105*5113495bSYour Name qdf_export_symbol(qdf_dev_set_irq_status_flags);
106*5113495bSYour Name 
107*5113495bSYour Name QDF_STATUS
qdf_dev_clear_irq_status_flags(unsigned int irnum,unsigned long clr)108*5113495bSYour Name qdf_dev_clear_irq_status_flags(unsigned int irnum, unsigned long clr)
109*5113495bSYour Name {
110*5113495bSYour Name 	if (irnum <= 0)
111*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
112*5113495bSYour Name 
113*5113495bSYour Name 	irq_clear_status_flags(irnum, clr);
114*5113495bSYour Name 
115*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
116*5113495bSYour Name }
117*5113495bSYour Name 
118*5113495bSYour Name qdf_export_symbol(qdf_dev_clear_irq_status_flags);
119*5113495bSYour Name #endif
120