blob: 5c0877a906479958cdc7feeabe97ec757f91d686 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
2 * Copyright (c) 2011-2015 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/*
29 *
30 * mac_init_api.c - This file has all the mac level init functions
31 * for all the defined threads at system level.
32 * Author: Dinesh Upadhyay
33 * Date: 04/23/2007
34 * History:-
35 * Date: 04/08/2008 Modified by: Santosh Mandiganal
36 * Modification Information: Code to allocate and free the memory for DumpTable entry.
37 * --------------------------------------------------------------------------
38 *
39 */
40/* Standard include files */
41#include "cfg_api.h" /* cfg_cleanup */
42#include "lim_api.h" /* lim_cleanup */
43#include "sir_types.h"
44#include "sys_debug.h"
45#include "sys_entry_func.h"
46#include "mac_init_api.h"
47
48#ifdef TRACE_RECORD
49#include "mac_trace.h"
50#endif
51
52extern tSirRetStatus halDoCfgInit(tpAniSirGlobal pMac);
53extern tSirRetStatus halProcessStartEvent(tpAniSirGlobal pMac);
54
55tSirRetStatus mac_start(tHalHandle hHal, void *pHalMacStartParams)
56{
57 tSirRetStatus status = eSIR_SUCCESS;
58 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
59
60 if (NULL == pMac) {
61 CDF_ASSERT(0);
62 status = eSIR_FAILURE;
63 return status;
64 }
65
66 pMac->gDriverType =
67 ((tHalMacStartParameters *) pHalMacStartParams)->driverType;
68
69 sys_log(pMac, LOG2, FL("called\n"));
70
71 if (ANI_DRIVER_TYPE(pMac) != eDRIVER_TYPE_MFG) {
72 status = pe_start(pMac);
73 }
74
75 return status;
76}
77
78/** -------------------------------------------------------------
79 \fn mac_stop
80 \brief this function will be called from HDD to stop MAC. This function will stop all the mac modules.
81 \ memory with global context will only be initialized not freed here.
82 \param tHalHandle hHal
83 \param tHalStopType
84 \return tSirRetStatus
85 -------------------------------------------------------------*/
86
87tSirRetStatus mac_stop(tHalHandle hHal, tHalStopType stopType)
88{
89 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
90 pe_stop(pMac);
91 cfg_cleanup(pMac);
92
93 return eSIR_SUCCESS;
94}
95
96/** -------------------------------------------------------------
97 \fn mac_open
98 \brief this function will be called during init. This function is suppose to allocate all the
99 \ memory with the global context will be allocated here.
100 \param tHalHandle pHalHandle
101 \param tHddHandle hHdd
102 \param tHalOpenParameters* pHalOpenParams
103 \return tSirRetStatus
104 -------------------------------------------------------------*/
105
106tSirRetStatus mac_open(tHalHandle *pHalHandle, tHddHandle hHdd,
107 tMacOpenParameters *pMacOpenParms)
108{
109 tpAniSirGlobal p_mac = NULL;
110 tSirRetStatus status = eSIR_SUCCESS;
111
112 if (pHalHandle == NULL)
113 return eSIR_FAILURE;
114
115 /*
116 * Make sure this adapter is not already opened. (Compare pAdapter pointer in already
117 * allocated p_mac structures.)
118 * If it is opened just return pointer to previously allocated p_mac pointer.
119 * Or should this result in error?
120 */
121
122 /* Allocate p_mac */
123 p_mac = cdf_mem_malloc(sizeof(tAniSirGlobal));
124 if (NULL == p_mac)
125 return eSIR_MEM_ALLOC_FAILED;
126
127 /* Initialize the p_mac structure */
128 cdf_mem_set(p_mac, sizeof(tAniSirGlobal), 0);
129
130 /*
131 * Set various global fields of p_mac here
132 * (Could be platform dependant as some variables in p_mac are platform
133 * dependant)
134 */
135 p_mac->hHdd = hHdd;
136 *pHalHandle = (tHalHandle) p_mac;
137
138 {
139 /* Call various PE (and other layer init here) */
140 if (eSIR_SUCCESS != log_init(p_mac)) {
141 cdf_mem_free(p_mac);
142 return eSIR_FAILURE;
143 }
144
145 /* Call routine to initialize CFG data structures */
146 if (eSIR_SUCCESS != cfg_init(p_mac)) {
147 cdf_mem_free(p_mac);
148 return eSIR_FAILURE;
149 }
150
151 sys_init_globals(p_mac);
152 }
153
154 /* FW: 0 to 2047 and Host: 2048 to 4095 */
155 p_mac->mgmtSeqNum = WLAN_HOST_SEQ_NUM_MIN - 1;
156 p_mac->first_scan_done = false;
157
158 status = pe_open(p_mac, pMacOpenParms);
159 if (eSIR_SUCCESS != status) {
160 sys_log(p_mac, LOGE, FL("mac_open failure\n"));
161 cdf_mem_free(p_mac);
162 }
163
164 return status;
165}
166
167/** -------------------------------------------------------------
168 \fn mac_close
169 \brief this function will be called in shutdown sequence from HDD. All the
170 \ allocated memory with global context will be freed here.
171 \param tpAniSirGlobal pMac
172 \return none
173 -------------------------------------------------------------*/
174
175tSirRetStatus mac_close(tHalHandle hHal)
176{
177
178 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
179
180 if (!pMac)
181 return eSIR_FAILURE;
182
183 pe_close(pMac);
184
185 /* Call routine to free-up all CFG data structures */
186 cfg_de_init(pMac);
187
188 log_deinit(pMac);
189
190 /* Finally, de-allocate the global MAC datastructure: */
191 cdf_mem_free(pMac);
192
193 return eSIR_SUCCESS;
194}