summaryrefslogtreecommitdiff
path: root/sta_dk_4_0_4_32/pform/linux/src/osapi.c
blob: 6378b2e576288374cb5f7eed05646e9f73bf8249 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
/****************************************************************************
**+-----------------------------------------------------------------------+**
**|                                                                       |**
**| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
**| All rights reserved.                                                  |**
**|                                                                       |**
**| Redistribution and use in source and binary forms, with or without    |**
**| modification, are permitted provided that the following conditions    |**
**| are met:                                                              |**
**|                                                                       |**
**|  * Redistributions of source code must retain the above copyright     |**
**|    notice, this list of conditions and the following disclaimer.      |**
**|  * Redistributions in binary form must reproduce the above copyright  |**
**|    notice, this list of conditions and the following disclaimer in    |**
**|    the documentation and/or other materials provided with the         |**
**|    distribution.                                                      |**
**|  * Neither the name Texas Instruments nor the names of its            |**
**|    contributors may be used to endorse or promote products derived    |**
**|    from this software without specific prior written permission.      |**
**|                                                                       |**
**| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
**| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
**| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
**| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
**| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
**| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
**| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
**| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
**| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
**| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
**| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
**|                                                                       |**
**+-----------------------------------------------------------------------+**
****************************************************************************/


#include "arch_ti.h"

#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/time.h>
#include <linux/timer.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/time.h>
#include <linux/list.h>
#include <asm/io.h>
#ifdef CONFIG_TROUT_PWRSINK
#include <asm/arch/trout_pwrsink.h>
#endif

#include "debug_module.h"
#include "esta_drv.h"
#ifdef DRIVER_PROFILING
#include "tiwlan_profile.h"
#endif
#include "osApi.h"
#include "osTIType.h"
#include "srcApi.h"
#include "whalHwRegs.h"
#include "bmtrace.h"
#include "TI_IPC_Api.h"
#include "whalBus_Defs.h"
#include "802_11Defs.h"
#include "Ethernet.h"

#define OS_PROTECT_HANDLE   0xffffeee0
/*#define DEBUG_REG_ACCESS*/

#ifdef DEBUG_REG_ACCESS
#define PRINT_REG(fmt, args...)     print_info(fmt, args)
#else
#define PRINT_REG(fmt, args...)
#endif
#define NOPRINT_REG(fmt, args...)

#ifdef ESTA_TIMER_DEBUG
#define esta_timer_log(fmt,args...)  printk(fmt, ## args)
#else
#define esta_timer_log(fmt,args...)
#endif

#define FRAG_SIZE        200

/* Wlan chip reset defines */
#define GPIO_16						16
#define GPIO_16_DIRECTION_OUTPUT	0
#define GPIO_16_CLEAR				0
#define GPIO_16_SET					1
	
#define GPIO1_IRQSTATUS1 	0xFFFBE418
#define GPIO1_DATAIN 		0xFFFBE42C

/*********************    LOCAL DECLARATIONS ************************/
static inline void os_timer_dec_use_count(timer_obj_t *tmr);
static int os_tl_timerHandlr(struct tiwlan_req *req);
static void os_timerHandlr(unsigned long parm);
static void send_frag(char* msg, int message_len, int level, int module);

BOOL use_debug_module = FALSE;

/****************************************************************************************
 *                        																*
 *						OS Report API													*       
 *																						*
 ****************************************************************************************/

/****************************************************************************************
 *                        os_setDebugMode()                                 
 ****************************************************************************************
DESCRIPTION:  	Set the Debug Mode 

INPUT:            

RETURN:			None   

NOTES:         	
*****************************************************************************************/
void os_setDebugMode(BOOL enable)
{
	use_debug_module = enable;
}


/****************************************************************************************
 *                        os_printf()                                 
 ****************************************************************************************
DESCRIPTION:  	Print formatted output. 

INPUT:          format -  Specifies the string, to be printed

RETURN:			None   

NOTES:         	
*****************************************************************************************/
void os_printf(const char *format ,...)
{
	static int from_new_line = 1;		/* Used to save the last message EOL */
	static UINT8 module = 0;			/* Used to save the last message module */
	static UINT8 level = 0;				/* Used to save the last message level */
    va_list ap;
    static char msg[500];
	char *p_msg = msg;					/* Pointer to the message */
	UINT16 message_len;					
    UINT32 sec = 0;
    UINT32 uSec = 0;
   
	/* Format the message and keep the message length */
    va_start(ap,format);
	message_len = vsnprintf(&msg[1], sizeof(msg) - 1, format, ap);

    
	if (use_debug_module)
	{
		/*********************/
		/* Use debug module */
		/*******************/

		if (msg[1] == '$')
		{
			/************************************
				  Message format:		"$XX" 
										 |||
					  message prefix ----|||
					  module index -------||
					  severity index ------|
			************************************/

			level = (msg[2] - 'A');
			module = (msg[3] - 'A');
		}
		else
		{
            send_frag(msg, message_len, level, module);
        }
    }
    else
    {
        /***********************/
        /* Use regular printk */
        /*********************/
        
        if( from_new_line )
        {
            if (msg[1] == '$')
            {
                p_msg += 4;
            }
            
            sec = os_timeStampUs(NULL);
            uSec = sec % 1000000;
            sec /= 1000000;
            
            printk(KERN_INFO DRIVER_NAME ": %d.%06d: %s",sec,uSec,p_msg);
        }
        else
        {
            printk(&msg[1]);
        }
        
        from_new_line = ( msg[message_len] == '\n' );
    }
}

static void send_frag(char* msg, int message_len, int level, int module)
{
#ifdef TIWLAN_OMAP1610 /* Dm: */
    int return_value;
    int offset = 1;
    int TmpLen;
    char* FragMsg;
    
    do
    {            
        TmpLen = min(message_len - offset, FRAG_SIZE);
        FragMsg = msg + offset - 1;
        FragMsg[0] = module;
        
        return_value = debug_module_enqueue_message(DEBUG_MODULE_TRACE_QUEUE_ID, level, FragMsg, TmpLen+1, CONTROL_CODE_TYPE_MESSAGE);

			if (return_value)
			{
				/* Message overrun */

				/* Send the overrun indication to the debug module */
				os_memoryCopy(NULL, &msg[1], "*** Message Overrun ***", strlen("*** Message Overrun ***"));
				msg[0] = 0;
				debug_module_enqueue_message(DEBUG_MODULE_TRACE_QUEUE_ID, 0, msg, (strlen("*** Message Overrun ***") + 1), CONTROL_CODE_TYPE_MESSAGE);

				/* Print overrun indication to the terminal */
				/*printk(KERN_INFO DRIVER_NAME ": %d.%06d: %s\n", sec, uSec, "**** Debug module message overrun! ****\n");*/
			}
        offset += TmpLen;
    }while (offset < message_len);
  
#endif    
}

/****************************************************************************************
 *                        																*
 *							OS DMA CALLBACK API											*
 ****************************************************************************************/
 
/****************************************************************************************
 *                        os_TNETWIF_BusTxn_Complete()                                 
 ****************************************************************************************
DESCRIPTION:    Callback directly called at an IRQ context from the SPI modue
				This should triger a tasklet_schedule so that the End of DMA will be handled
				in a tasklet  context and then be directed to the TNETWIF to call the Client callback.

INPUT:          OsContext - our adapter context.

RETURN:         None

NOTES:         	
*****************************************************************************************/
void os_TNETWIF_BusTxn_Complete(TI_HANDLE OsContext,int status)
{
    tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;

    drv->dma_done = 1;
#ifdef DM_USE_WORKQUEUE
    /* printk("TI: %s:\t%lu\n", __FUNCTION__, jiffies); */
    if( queue_work( drv->tiwlan_wq, &drv->tw ) != 0 ) {
#ifdef CONFIG_ANDROID_POWER
        android_lock_suspend( &drv->timer_wake_lock );
#endif
    }
#else
   	tasklet_schedule(&drv->tl);
#endif
}

/****************************************************************************************
 *                        																*
 *							OS TIMER API												*
 *																						*
 ****************************************************************************************/

/****************************************************************************************
 *                        os_timerCreate()                                 
 ****************************************************************************************
DESCRIPTION:    This function creates and initializes a timer object associated with a
                caller's pRoutine function.

ARGUMENTS:      

RETURN:         A handle of the created timer.
                TI_HANDLE_INVALID if there is insufficient memory available

NOTES:          Using the Kernel timer feature, problem is that kernel timers are one-shots.
                For timers that are periodic this abstraction layer will have to mediate
                between the callback function and the re-submission of a timer request.

*****************************************************************************************/
TI_HANDLE
os_timerCreate(
        TI_HANDLE OsContext,
        PTIMER_FUNCTION pRoutine,
        TI_HANDLE Context
        )
{
    timer_obj_t *tmr;

#ifdef ESTA_TIMER_DEBUG
    esta_timer_log("\n\n%s:%d ::os_timerCreate(%p,%p,%p)",__FUNCTION__, __LINE__,OsContext,pRoutine,Context);
#endif
    ti_nodprintf(TIWLAN_LOG_INFO, "\n----> os_timerCreate function = 0x%08x , context= 0x%08x",
                 (int)pRoutine, (int)Context);

    os_profile (OsContext, 6, 0);

    tmr = os_memoryAlloc (OsContext, sizeof(timer_obj_t));
    if (tmr == NULL)
        return(TI_HANDLE_INVALID);

    memset (tmr,0,sizeof(timer_obj_t));

    init_timer(&tmr->timer);
    INIT_LIST_HEAD(&tmr->req.list);
    tmr->timer.function = os_timerHandlr;
    tmr->timer.data = (int)tmr;
    tmr->req.drv = (tiwlan_net_dev_t *)OsContext;
    tmr->req.u.req.p1 = (UINT32)pRoutine;
    tmr->req.u.req.p2 = (UINT32)Context;
    tmr->req.u.req.f  = os_tl_timerHandlr;
    tmr->use_count = 1;

    esta_timer_log("=%p\n\n", tmr);

    return (TI_HANDLE)tmr;
}


/****************************************************************************************
 *                        os_timerDestroy()                                 
 ****************************************************************************************
DESCRIPTION:    This function destroy the timer object.

ARGUMENTS:      

RETURN:         

NOTES:          Returning the Kernel level timer_list memory allocation and the
                abstraction level timer object.
*****************************************************************************************/
VOID
os_timerDestroy(
        TI_HANDLE OsContext,
        TI_HANDLE TimerHandle
        )
{
    timer_obj_t *tmr = TimerHandle;

    os_profile (OsContext, 6, 0);

    os_timerStop (OsContext, TimerHandle);
    os_timer_dec_use_count (tmr);
}


/****************************************************************************************
 *                        os_timerStart()                                 
 ****************************************************************************************
DESCRIPTION:    This function start the timer object.

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
VOID
os_timerStart(
        TI_HANDLE OsContext,
        TI_HANDLE TimerHandle,
        UINT32 DelayMs,
        BOOL bPeriodic
        )
{
   timer_obj_t *tmr= (timer_obj_t *)TimerHandle;

   UINT32 jiffie_cnt = msecs_to_jiffies(DelayMs);

#ifdef ESTA_TIMER_DEBUG
	esta_timer_log("\n\n%s:%d ::os_timerStart(%p,%p,%u,%d)\n\n",__FUNCTION__, __LINE__,OsContext,TimerHandle,DelayMs,bPeriodic);
#endif

   tmr->req.u.req.p3 = bPeriodic;
   tmr->req.u.req.p4 = jiffie_cnt;
   tmr->timer.data    = (unsigned long)tmr;
   mod_timer(&tmr->timer, jiffies + jiffie_cnt);


   return;
}

/****************************************************************************************
 *                        os_stopTimer()                                 
 ****************************************************************************************
DESCRIPTION:    This function stop the timer object.

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
VOID
os_timerStop(
        TI_HANDLE OsContext,
        TI_HANDLE TimerHandle
        )
{
   timer_obj_t *tmr= (timer_obj_t *)TimerHandle;

   del_timer_sync(&tmr->timer);
   tmr->req.u.req.p3 = 0; /* Turn "periodic" off */
   list_del_init(&tmr->req.list);

   return;
}

/****************************************************************************************
 *                        os_periodicIntrTimerStart()                                 
 ****************************************************************************************
DESCRIPTION:    This function starts the periodic interrupt mechanism. This mode is used 
				when interrupts that usually received from the Fw is now masked, and we are
				checking for any need of Fw handling in time periods.

ARGUMENTS:		

RETURN:			

NOTES:         	Power level of the CHIP should be always awake in this mode (no ELP)
*****************************************************************************************/
VOID
os_periodicIntrTimerStart(
	TI_HANDLE OsContext
	)
{
	tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;

	mod_timer (&drv->poll_timer, jiffies + TIWLAN_IRQ_POLL_INTERVAL);
}

/****************************************************************************************
 *                        os_timeStampMs()                                 
 ****************************************************************************************
DESCRIPTION:	This function returns the number of milliseconds that have elapsed since
				the system was booted.

ARGUMENTS:		OsContext - our adapter context.

RETURN:			

NOTES:         	
*****************************************************************************************/
UINT32
os_timeStampMs(
        TI_HANDLE OsContext
        )
{
    struct timeval tv;
    do_gettimeofday(&tv);
    return tv.tv_sec*1000 + tv.tv_usec/1000;
}

/****************************************************************************************
 *                        os_timeStampUs()                                 
 ****************************************************************************************
DESCRIPTION:	This function returns the number of microseconds that have elapsed since
				the system was booted.

ARGUMENTS:		OsContext - our adapter context.
				Note that sometimes this function will be called with NULL(!!!) as argument!

RETURN:			

NOTES:         	
*****************************************************************************************/
UINT32
os_timeStampUs(
        TI_HANDLE OsContext
        )
{
    struct timeval tv;
    do_gettimeofday(&tv);
    return tv.tv_sec*1000000 + tv.tv_usec;
}

/****************************************************************************************
 *                        os_StalluSec()                                 
 ****************************************************************************************
DESCRIPTION:	This function make delay in microseconds.

ARGUMENTS:		OsContext - our adapter context.
				uSec - delay time in microseconds

RETURN:			

NOTES:         	
*****************************************************************************************/
VOID
os_StalluSec(
        TI_HANDLE OsContext,
        UINT32 uSec
        )
{
    /*UINT32 usec_now = os_timeStampUs(OsContext);
    while(os_timeStampUs(OsContext) - usec_now < uSec)
      ;
	*/
    udelay(uSec);
}

/****************************************************************************************
 *                        os_WaitComplete()                                 
 ****************************************************************************************
DESCRIPTION:    This function start waiting for the complete

ARGUMENTS:		

RETURN:			

NOTES:         	can be called only from process context, and not from tasklet
*****************************************************************************************/
VOID 
os_WaitComplete(
	TI_HANDLE OsContext
	)
{
	tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;
		
	/* ti_dprintf(TIWLAN_LOG_INFO, "os_WaitComplete drv %x drv->comp %x\n",(UINT32)drv,(UINT32)&drv->comp); */
	
   	/* 
   	he tasklet should them send back the user (here)the completion event so the user could
   	go through the configuration phase 
   	*/
  	wait_for_completion(&drv->comp);
}

/****************************************************************************************
 *                        os_Complete()                                 
 ****************************************************************************************
DESCRIPTION:    This function signals to the waiting process that completion occured

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
VOID 
os_Complete(
	TI_HANDLE OsContext
	)
{
   	tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;
		
	/* ti_dprintf(TIWLAN_LOG_INFO, "os_Complete drv %x drv->comp %x\n",(UINT32)drv, (UINT32)&drv->comp); */

   	/* 
   	Call the completion routine  that will unblock the caller that was waiting on that object 
   	*/
   	complete(&drv->comp);
}



/****************************************************************************************
 *                        																*
 *							Hardware access functions	API								*
 *																						*
 ****************************************************************************************/

/****************************************************************************************
 *                        os_clearWlanReady()                                 
 ****************************************************************************************
DESCRIPTION:  	Clear the WLAN Ready Interrupt Line stored in the PIC Controller 

INPUT:          None  

RETURN:			None   

NOTES:         	
*****************************************************************************************/

__inline__ VOID
os_clearWlanReady(
	void)
{
#ifdef TIWLAN_OMAP1610
    omap_writel(4,GPIO1_IRQSTATUS1);
#endif
}


/****************************************************************************************
 *                        os_senseIrqLine()                                 
 ****************************************************************************************
DESCRIPTION:  	Read the WLAN_IRQ line 

INPUT:          void

RETURN:			Read value   

NOTES:         	
*****************************************************************************************/

__inline__  UINT32
os_senseIrqLine(
	TI_HANDLE OsContext
    )
{
#ifdef TIWLAN_OMAP1610
    return (omap_readl(GPIO1_DATAIN) & 0x4);
#else
    return 0;
#endif
}



/****************************************************************************************
 *                        os_hwGetRegistersAddr()                                 
 ****************************************************************************************
DESCRIPTION:	

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
PVOID
os_hwGetRegistersAddr(
        TI_HANDLE OsContext
        )
{
	return (PVOID)OS_API_REG_ADRR;
}

/****************************************************************************************
 *                        os_hwGetMemoryAddr()                                 
 ****************************************************************************************
DESCRIPTION:	

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
PVOID
os_hwGetMemoryAddr(
        TI_HANDLE OsContext
        )
{
	return (PVOID)OS_API_MEM_ADRR;
}

/****************************************************************************************
 *                        os_memoryGetPhysicalLow()                                 
 ****************************************************************************************
DESCRIPTION:	return the lower 32 bits of a 64bit number / address *	

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
UINT32 os_memoryGetPhysicalLow (OS_PHYSICAL_ADDRESS pAddr)
{
   UINT32 res;
   res = pAddr & 0xffffffff;
   ti_dprintf(TIWLAN_LOG_ERROR, "\n 64bit low. Got 0x%x; Returning 0x%x \n", (UINT32)pAddr, res);
   return res;
}

/****************************************************************************************
 *                        os_memoryGetPhysicalHigh()                                 
 ****************************************************************************************
DESCRIPTION:	return the higher order 32 bits of a 64bit number / address *	

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
UINT32 os_memoryGetPhysicalHigh (OS_PHYSICAL_ADDRESS pAddr)
{
   UINT32 res;
   res = pAddr >> 32;
   ti_dprintf(TIWLAN_LOG_ERROR, "\n 64bit high. Got 0x%x; Returning 0x%x \n", (UINT32)pAddr, res);
   return res;
}


/****************************************************************************************
 *                        																*
 *							Protection services	API										*
 *																						*
 ****************************************************************************************
 * OS protection is implemented as dummy functions because								*
 * all driver code is executed in context of a single tasklet,							*
 * except IOCTL handlers and xmition.													*
 * Protection in IOCTL handlers and hard_start_xmit is done by different				*
 * means.																				*
 ****************************************************************************************/


/****************************************************************************************
 *                        os_protectCreate()                                 
 ****************************************************************************************
DESCRIPTION:	

ARGUMENTS:		OsContext - our adapter context.

RETURN:			A handle of the created mutex/spinlock.
				TI_HANDLE_INVALID if there is insufficient memory available or problems
				initializing the mutex

NOTES:         	
*****************************************************************************************/
TI_HANDLE
os_protectCreate(
        TI_HANDLE OsContext
        )
{
    return (TI_HANDLE)OS_PROTECT_HANDLE;
}



/****************************************************************************************
 *                        os_protectDestroy()                                 
 ****************************************************************************************
DESCRIPTION:		

ARGUMENTS:		OsContext - our adapter context.

RETURN:			None - This had better work since there is not a return value to the user

NOTES:         	
*****************************************************************************************/
VOID
os_protectDestroy(
        TI_HANDLE OsContext,
        TI_HANDLE ProtectCtx
        )
{
    return;
}


/****************************************************************************************
 *                        os_protectLock()                                 
 ****************************************************************************************
DESCRIPTION:		

ARGUMENTS:		OsContext - our adapter context.

RETURN:			None - This had better work since there is not a return value to the user

NOTES:         	
*****************************************************************************************/
VOID
os_protectLock(
        TI_HANDLE OsContext,
        TI_HANDLE ProtectContext
        )
{
#if 1    /* uncomment for work in INDIRECT mode (HwACXAccessMethod=0) */
    tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;
    spin_lock_irqsave(&drv->lock, drv->flags);
#endif
}


/****************************************************************************************
 *                        os_protectUnlock()                                 
 ****************************************************************************************
DESCRIPTION:		

ARGUMENTS:		OsContext - our adapter context.

RETURN:			None - This had better work since there is not a return value to the user

NOTES:         	
*****************************************************************************************/
VOID
os_protectUnlock(
        TI_HANDLE OsContext,
        TI_HANDLE ProtectContext
        )
{
#if 1    /* uncomment for work in INDIRECT mode (HwACXAccessMethod=0) */
    tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;
    spin_unlock_irqrestore(&drv->lock, drv->flags);
#endif
}


/*-----------------------------------------------------------------------------

Routine Name:

        os_resetWakeOnGpio

Routine Description:

        set the GPIO to low after awaking the TNET from ELP.

Arguments:

        OsContext - our adapter context.


Return Value:

        None

-----------------------------------------------------------------------------*/
VOID
os_hardResetTnetw( void )
{
/*
 *  Define the OMAP GPIO registers, the TNETW reset is currently connected
 *  to GPIO 16, this logic assumes that the loading code had muxed the 
 *  GPIO 16 to the Y1 pinout.
 */
    /* direction out */
#ifdef TIWLAN_OMAP1610    
	omap_set_gpio_direction(GPIO_16, GPIO_16_DIRECTION_OUTPUT);
	
	/* clear reset WLAN chip */
	omap_set_gpio_dataout(GPIO_16, GPIO_16_CLEAR);

	/* wait for 50msec */
    mdelay(50);
	omap_set_gpio_dataout(GPIO_16, GPIO_16_SET);

	/* wait for 50msec */
	mdelay(50);
#endif /* Dm: */
#ifdef TIWLAN_MSM7000
    trout_wifi_reset(1); /* Reset active */
    trout_wifi_power(0); /* Power disable */
    trout_wifi_power(1); /* Power enable */
    trout_wifi_reset(0); /* Reset clear */
#endif
}


#ifndef GWSI_DRIVER

/****************************************************************************************
						START OF TI DRIVER API				
*****************************************************************************************/

/****************************************************************************************
 *                        os_setWakeOnGpio()                                 
 ****************************************************************************************
DESCRIPTION:	set the GPIO to high for awaking the TNET from ELP.	

ARGUMENTS:		OsContext - our adapter context.

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_setWakeOnGpio(
    TI_HANDLE OsContext
    )
{
#ifdef TIWLAN_OMAP1610
    /*
    Clear ELP_REQ by GPIO_CLEAR_DATAOUT
    */
    os_resetWakeOnGpio(OsContext);

    /*
    Rising edge on ELP_REQ by GPIO_SET_DATAOUT
    */
    omap_writel(0x00000200, 0xFFFBBCF0);
#endif
}

/****************************************************************************************
 *                        os_resetWakeOnGpio()                                 
 ****************************************************************************************
DESCRIPTION:	set the GPIO to low after awaking the TNET from ELP.	

ARGUMENTS:		OsContext - our adapter context.

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_resetWakeOnGpio(
    TI_HANDLE OsContext
    )
{
    /*
    Clear ELP_REQ by GPIO_CLEAR_DATAOUT
    */
#ifdef TIWLAN_OMAP1610
    omap_writel(0x00000200, 0xFFFBBCB0);
#endif
}

/****************************************************************************************
 *                        _os_memorySharedFree()                                 
 ****************************************************************************************
DESCRIPTION:		

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
VOID
_os_memorySharedFree(
    TI_HANDLE OsContext,
    PVOID pVirtual,
    UINT32 Size,
    OS_PHYSICAL_ADDRESS pPhysical
    )
{
    ti_dprintf(TIWLAN_LOG_ERROR, "\n\n\n %s is not implemented\n\n\n", __FUNCTION__);
}

/****************************************************************************************
 *                        _os_memorySharedAlloc()                                 
 ****************************************************************************************
DESCRIPTION:		

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
PVOID
_os_memorySharedAlloc(
    TI_HANDLE OsContext,
    UINT32 Size,
    OS_PHYSICAL_ADDRESS *pPhysical
    )
{
    ti_dprintf(TIWLAN_LOG_ERROR, "\n\n\n %s is not implemented\n\n\n", __FUNCTION__);
    return NULL;
}

/****************************************************************************************
 *                        os_powerStateBusy()                                 
 ****************************************************************************************
DESCRIPTION:	notify to the host that the TI_WLAN application is busy.	

ARGUMENTS:		OsContext - our adapter context.

RETURN:			

NOTES:         	
*****************************************************************************************/
VOID
os_powerStateBusy(
    TI_HANDLE OsContext
    )
{
#if 0
    ti_dprintf(TIWLAN_LOG_INFO,
               "%s(%d) - os_powerStateBusy: TI_WLAN is busy!\n",
               __FILE__,__LINE__);
#endif
}

/****************************************************************************************
 *                        os_powerStateIdle()                                 
 ****************************************************************************************
DESCRIPTION:	notify to the host that the TI_WLAN application is idle.	

ARGUMENTS:		OsContext - our adapter context.

RETURN:			

NOTES:         	
*****************************************************************************************/
VOID
os_powerStateIdle(
    TI_HANDLE OsContext
    )
{
#if 0
    ti_dprintf(TIWLAN_LOG_INFO,
               "%s(%d) - os_powerStateIdle: TI_WLAN is idle!\n",
               __FILE__,__LINE__);
#endif
}

/****************************************************************************************
 *                        os_memoryMove()                                 
 ****************************************************************************************
DESCRIPTION:	Move memory block from pSource to pDestination	

ARGUMENTS:		OsContext - Our adapter context.
				pDestination - destination
				pSource - source
				Size - Number of characters
RETURN:			

NOTES:         	
*****************************************************************************************/
VOID
os_memoryMove(
        TI_HANDLE pOsContext,
        PVOID pDestination,
        PVOID pSource,
        UINT32 Size
        )
{
    memmove(pDestination, pSource, Size);
}


/****************************************************************************************
 *                        os_memoryMoveToHw()                                 
 ****************************************************************************************
DESCRIPTION:	This function copies data from a system-space buffer to device memory.	

ARGUMENTS:		OsContext - Our adapter context.

				pTarget - Specifies the base address within a device memory range where
                the copy should begin.

				pSource - Pointer to a system-space buffer from which this function copies
                data to the destination range.

				Size - Specifies the number of bytes to copy.

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_memoryMoveToHw(
        TI_HANDLE OsContext,
        PVOID pTarget,
        PVOID pSource,
        UINT32 Size
        )
{
    print_info("\nos_memoryMoveToHw pTarget 0x%08x pSource 0x%08x Size 0x%08x",(int)pTarget, (int)pSource,(int)Size);
    print_info("\n-------------------------> Not Implemented <--------------------------------------------------- ");
}

/****************************************************************************************
 *                        os_memoryMoveFromHw()                                 
 ****************************************************************************************
DESCRIPTION:	This function copies data from a system-space buffer to device memory.	

ARGUMENTS:		OsContext - Our adapter context.

				pTarget - Pointer to a system-space buffer into which this function copies
                data from device memory.

				pSource - Specifies the base virtual address within device memory from
                which to copy the data.

				Size - Specifies the number of bytes to copy.

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_memoryMoveFromHw(
        TI_HANDLE OsContext,
        PVOID pTarget,
        PVOID pSource,
        UINT32 Size
        )
{
    print_info("\nos_memoryMoveFromHw pTarget 0x%08x pSource 0x%08x Size 0x%08x",(int)pTarget, (int)pSource,(int)Size);
    print_info("\n-------------------------> Not Implemented <--------------------------------------------------- ");
}

/****************************************************************************************
 *                        os_hwReadMemRegisterUINT8()                                 
 ****************************************************************************************
DESCRIPTION:	Reads a UINT8 from a memory-mapped device register.	

ARGUMENTS:		OsContext - our adapter context.

				Register - Pointer to the memory-mapped register.

				Data - Pointer to the caller-supplied variable in which this function
                returns the UINT8 read from Register.	

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_hwReadMemRegisterUINT8(
        TI_HANDLE OsContext,
        PUCHAR Register,
        PUINT8 Data
        )
{
    *Data = *Register;
    PRINT_REG("R8: %p=0x%x\n", Register, *Data);
    return;
}

/****************************************************************************************
 *                        os_hwWriteMemRegisterUINT16()                                 
 ****************************************************************************************
DESCRIPTION:	Writes a 'unsigned short' to a memory-mapped device register.	

ARGUMENTS:		OsContext - our adapter context.

				Register - Pointer to the memory-mapped register.

				Data - Specifies the caller-supplied UINT16 that this function transfers
                to the Register.

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_hwWriteMemRegisterUINT16(
        TI_HANDLE OsContext,
        PUINT16 Register,
        UINT16 Data
        )
{
    PRINT_REG("W16: %p=0x%x\n", Register, Data);
    *Register = Data;
    return;
}

/****************************************************************************************
 *                        os_hwReadMemRegisterUINT16()                                 
 ****************************************************************************************
DESCRIPTION:	Reads a UINT16 from a memory-mapped device register.	

ARGUMENTS:	    OsContext - our adapter context.

				Register - Pointer to the memory-mapped register.

				Data - Pointer to the caller-supplied variable in which this function
                returns the UINT16 read from Register.
	
RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_hwReadMemRegisterUINT16(
        TI_HANDLE OsContext,
        PUINT16 Register,
        PUINT16 Data
        )
{
    *Data = *Register;
    PRINT_REG("R16: %p=0x%x\n", Register, *Data);
    return;
}

/****************************************************************************************
 *                        os_hwWriteMemRegisterUINT32()                                 
 ****************************************************************************************
DESCRIPTION:	Writes a 'unsigned long' to a memory-mapped device register.	

ARGUMENTS:		OsContext - our adapter context.

				Register - Pointer to the memory-mapped register.

				Data - Specifies the caller-supplied UINT32 that this function transfers
                to the Register.

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_hwWriteMemRegisterUINT32(
        TI_HANDLE OsContext,
        PUINT32 Register,
        UINT32 Data
        )
{
    PRINT_REG("W32: %p=0x%x\n", Register, Data);
    *Register = Data;
    return;
}


/****************************************************************************************
 *                        os_hwReadMemRegisterUINT32()                                 
 ****************************************************************************************
DESCRIPTION:	Reads a UINT32 from a memory-mapped device register.	

ARGUMENTS:		OsContext - our adapter context.

				Register - Pointer to the memory-mapped register.

				Data - Pointer to the caller-supplied variable in which this function
                returns the UINT32 read from Register.

RETURN:			None

NOTES:         	
*****************************************************************************************/
VOID
os_hwReadMemRegisterUINT32(
        TI_HANDLE OsContext,
        PUINT32 Register,
        PUINT32 Data
        )
{
    *Data = *Register;
    PRINT_REG("R32: %p=0x%x\n", Register, *Data);
    return;
}


/****************************************************************************************
 *                        os_receivePacket()                                 
 ****************************************************************************************
DESCRIPTION:		

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
BOOL
os_receivePacket(
        TI_HANDLE OsContext,
        PVOID pPacket,
        UINT16 Length
        )
{
    tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;
    struct sk_buff *skb;
    mem_MSDU_T* pMsdu = (mem_MSDU_T*)pPacket;
    mem_BD_T *pCurBd;
    ti_nodprintf(TIWLAN_LOG_INFO, "os_receivePacket - Received EAPOL len-%d\n", pMsdu->firstBDPtr->length );

    bm_trace(10, Length, 0);

    if (pMsdu->firstBDPtr->length > Length) { /* Dm: Security fix */
        ti_dprintf(TIWLAN_LOG_ERROR, " TI: %s - Security Error\n", __FUNCTION__);
        return FALSE;
    }

    skb = dev_alloc_skb(Length+2);
    if(!skb) {
        print_deb(" os_receivePacket() : dev_alloc_skb failed!\n");
        configMgr_memMngrFreeMSDU(drv->adapter.CoreHalCtx, memMgr_MsduHandle(pPacket));
        drv->stats.rx_dropped++;
        return FALSE;
    }
    skb_reserve(skb, 2);

    pCurBd = pMsdu->firstBDPtr;
    while (pCurBd) {
        memcpy(skb_put(skb,pCurBd->length),pCurBd->data+pCurBd->dataOffset,pCurBd->length);
        pCurBd = pCurBd->nextBDPtr;
    }

    skb->dev = drv->netdev;
    skb->protocol = eth_type_trans(skb, drv->netdev);
    skb->ip_summed = CHECKSUM_NONE;

    drv->stats.rx_packets++;
    drv->stats.rx_bytes += skb->len;

    bm_trace(11, Length, 0);
#ifdef CONFIG_ANDROID_POWER
    drv->receive_packet = 1; /* Remember to stay awake */
#endif
    netif_rx(skb);

    configMgr_memMngrFreeMSDU(drv->adapter.CoreHalCtx, memMgr_MsduHandle(pPacket));

    bm_trace(12, Length, 0);

    return TRUE;
}

/****************************************************************************************
 *                        os_sendPacket()                                 
 ****************************************************************************************
DESCRIPTION:	send EAPOL packet from Supplicant	

ARGUMENTS:		

RETURN:			

NOTES:         	
*****************************************************************************************/
INT32
os_sendPacket(
        TI_HANDLE OsContext,
        PVOID pPacket,
        UINT16 Length
        )
{
    struct net_device *dev = (struct net_device *)OsContext;
    tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)dev->priv;

    INT32 status;
    mem_MSDU_T* pMsdu;
    char *pMsduData;
    UINT32 packetHeaderLength;

    ti_nodprintf(TIWLAN_LOG_INFO, "os_sendPacket - Transmit EAPOL len-%x\n",Length );

   /*
    * Allocate enough place also for 802.11 header (24 bytes) and LLC (8 bytes)
    * to replace the Ethernet header (14 bytes)
    */
    if(!Length)
    {
        ti_dprintf(TIWLAN_LOG_ERROR, " EAPOL Packet Length = 0 \n");
        return -1;
    }
	/* 
	 * Retrieve the Packet Header length 
	 * from QoS Manager (through configMgr) and RSN 
	 */
	packetHeaderLength = configMgr_getPacketHeaderLength(drv->adapter.CoreHalCtx,pPacket,TX_DATA_EAPOL_MSDU);

    /* 
	 * need to reserve enough space for header translation 
	 * in the same first Bd.
	 * Allocate enough place also for 802.11 header (24 bytes or 26 for QoS) and LLC (8 bytes)
	 * to replace the Ethernet header (14 bytes)
	 */

	status = configMgr_allocMSDU(drv->adapter.CoreHalCtx, &pMsdu,
									 Length + packetHeaderLength , OS_ABS_TX_MODULE);
	if(status != OK)
	{
	   ti_dprintf(TIWLAN_LOG_ERROR, " configMgr_allocMSDU failed !!!\n");
	   ++drv->alloc_msdu_failures;
	   return -ENOMEM;
	}

	/* 
	 * case 1: only legacy wlan header 
	 *
  	 * case 2: only QoS wlan header 
	 *
	 * case 3: only legacy wlan header with new snap
	 *
	 * case 4: only QoS wlan header with new snap
	 */
	pMsdu->firstBDPtr->dataOffset = packetHeaderLength - ETHERNET_HDR_LEN;
	pMsduData = pMsdu->firstBDPtr->data + pMsdu->firstBDPtr->dataOffset;
	memcpy(pMsduData, pPacket, Length);
	pMsdu->dataLen = Length;
	pMsdu->firstBDPtr->length = pMsdu->dataLen + pMsdu->firstBDPtr->dataOffset;
	pMsdu->freeFunc = 0;
	pMsdu->freeArgs[0] = 0;
	pMsdu->freeArgs[1] = 0;

   /*
    * Propagate Msdu through Config Manager.
    * Set DTag to 0 
	* (note that classification is further handled in the Core)
    */
    status = configMgr_sendMsdu(drv->adapter.CoreHalCtx, pMsdu, 0);

    return status;
}


#endif /* NDEF  GWSI_DRIVER*/



/*******************************************************************************************************
  
									LOCAL FUNCTIONS

********************************************************************************************************/

/*-----------------------------------------------------------------------------
Routine Name:

        os_timer_dec_use_count

Routine Description:

    This function is decrements timer use count.
    When use_count becomes 0, the timer block is destroyed
-----------------------------------------------------------------------------*/
static inline void os_timer_dec_use_count(timer_obj_t *tmr)
{
    if (unlikely(!tmr->use_count)) {
        ti_dprintf(TIWLAN_LOG_ERROR, "\n\n\n %s: attempt to delete a deleted timer %p\n\n\n", __FUNCTION__, tmr);
        tmr->use_count = 1;
    }
    if (!(--tmr->use_count))
        os_memoryFree(tmr->req.drv, tmr, sizeof(timer_obj_t));
}


/*-----------------------------------------------------------------------------

Routine Name:

        os_tl_timerHandlr

Routine Description:

    This function is called in context of the control tasklet.
    It evokes user timer handler and restarts the timer if periodic

Arguments:
    p1 - user handler
    p2 - user parameter
    p3 - periodic
    p4 - jiffies

Return Value:

    None.

Notes:

-----------------------------------------------------------------------------*/
static int os_tl_timerHandlr(struct tiwlan_req *req)
{
    timer_obj_t *tmr= (timer_obj_t *)req;
    PTIMER_FUNCTION f = (PTIMER_FUNCTION)req->u.req.p1;
    TI_HANDLE parm = (TI_HANDLE)req->u.req.p2;

    esta_timer_log("%s: req=0x%x f=0x%p parm=0x%p\n", __FUNCTION__, req, f, parm);
    ++tmr->use_count;
    f(parm);
    if (req->u.req.p3) /* Periodic ? */
        mod_timer(&tmr->timer, jiffies + req->u.req.p4);
    os_timer_dec_use_count(tmr);

    return 0;
}


/*-----------------------------------------------------------------------------

Routine Name:

        os_timerHandlr

Routine Description:

    This function is called on timer expiration in context of
    softIsr. It delegates the timer handling to the control tasklet.

Arguments:
    parm - timer object handle

Return Value:

    None.

Notes:

-----------------------------------------------------------------------------*/
static void os_timerHandlr(unsigned long parm)
{
    timer_obj_t *tmr= (timer_obj_t *)parm;
    tiwlan_net_dev_t *drv = tmr->req.drv;
    unsigned long flags;

    esta_timer_log("%s: drv=%p f=0x%x ctx=0x%x\n",
          __FUNCTION__, tmr->req.drv, tmr->req.u.req.p1, tmr->req.u.req.p2);

    spin_lock_irqsave(&drv->lock, flags);
    list_del(&tmr->req.list);
    list_add_tail(&tmr->req.list, &drv->request_q);
    spin_unlock_irqrestore(&drv->lock, flags);
#ifdef DM_USE_WORKQUEUE
    /* printk("TI: %s:\t%lu\n", __FUNCTION__, jiffies); */
    if( queue_work( drv->tiwlan_wq, &drv->tw ) != 0 ) {
#ifdef CONFIG_ANDROID_POWER
        android_lock_suspend( &drv->timer_wake_lock );
#endif
    }
#else
    tasklet_schedule(&drv->tl);
#endif
}


/*-----------------------------------------------------------------------------

Routine Name:

        os_connectionStatus

Routine Description:

The eSTA-DK will call this API so the OS stack is aware that the
WLAN layer is ready to function.

Arguments:
cStatus = 1; WLAN in ready for network packets
cStatus = 0; WLAN in not ready for network packets

Return Value:

        None

-----------------------------------------------------------------------------*/

tiINT32
os_IndicateEvent(IPC_EV_DATA* pData)
{
   IPC_EVENT_PARAMS * pInParam =  (IPC_EVENT_PARAMS *)pData;
   tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)(pInParam->hUserParam);
   /*UCHAR AuthBuf[sizeof(ULONG) + sizeof(OS_802_11_AUTHENTICATION_REQUEST)];*/

   ti_nodprintf(TIWLAN_LOG_INFO, "\n  os_ConnectionStatus Event 0x%08x \n", CsStatus->Event);
   
   switch(pInParam->uEventType)
     {
   case IPC_EVENT_ASSOCIATED:
         if (drv->netdev != NULL) {
            netif_carrier_on(drv->netdev);
#ifdef CONFIG_TROUT_PWRSINK
            queue_delayed_work(drv->tiwlan_wq, &drv->trxw, 0);
#endif
         }
         break;

       case IPC_EVENT_DISASSOCIATED:
         if (drv->netdev != NULL) {
#ifdef CONFIG_TROUT_PWRSINK
            cancel_delayed_work_sync(&drv->trxw);
            trout_pwrsink_set(PWRSINK_WIFI, PWRSINK_WIFI_PERCENT_BASE);	
#endif
            netif_carrier_off(drv->netdev);
         }
      break;

      case IPC_EVENT_LINK_SPEED:
         drv->adapter.LinkSpeed = (*(PULONG)pData->uBuffer * 10000) / 2;
         ti_nodprintf(TIWLAN_LOG_INFO, "\n  Link Speed = 0x%08x \n",drv->adapter.LinkSpeed);
      break;

      case IPC_EVENT_AUTH_SUCC:
/*         *(PULONG)AuthBuf = os802_11StatusType_Authentication;
         memcpy((PUCHAR)&AuthBuf[sizeof(ULONG)], pData->uBuffer,sizeof(OS_802_11_AUTHENTICATION_REQUEST));*/
         ti_dprintf(TIWLAN_LOG_OTHER, "\n  Auth Succ Event from Driver to another BSSID. \n");
      break;

      case IPC_EVENT_SCAN_COMPLETE:
         ti_dprintf(TIWLAN_LOG_OTHER, "\n  Driver Event = Scan Complete. \n");
      break;

      case IPC_EVENT_TIMEOUT:
         ti_dprintf(TIWLAN_LOG_OTHER, "\n  Driver Event = Timeout. \n");
      break;

      case IPC_EVENT_CCKM_START:
         ti_dprintf(TIWLAN_LOG_OTHER, "\n  Driver Event = IPC_EVENT_CCKM_START \n");
      break;

      default:
         ti_dprintf(TIWLAN_LOG_ERROR, "\n  Unrecognized driver event. \n");
      break;

   }

   return OK;
}


/****************************************************************************/
/* The following 4 functions are debug functions that enable the user
   to set/reset GPIO_25 and GPIO_27 in the OMAP - for debug purposes.
   Note: In order to enable GPIO_25/GPIO_27 the user must enable the define
	TIWLAN_OMAP1610_CRTWIPP_GPIO_DEBUG in the esta_drv.c/osapi.c files.		*/

void os_ToggleDebugGPIO(int count)
{
#if 0
    int i,j;

	omap_writel(0x00000200, 0xFFFBBCB0 );/* 0 */
	for(i=0;i<count;i++)
	{
		omap_writel(0x00000200, 0xFFFBBCF0 );/* 1 */
		for(j=0;j<100;j++);
		omap_writel(0x00000200, 0xFFFBBCB0 );/* 0 */
		for(j=0;j<100;j++);
	}
#endif
}					
#ifdef TIWLAN_OMAP1610_CRTWIPP_GPIO_DEBUG
VOID
os_SetGpio_25(
    TI_HANDLE OsContext
    )
{
    /*
    Setting GPIO_25 by GPIO_SET_DATAOUT
    */
    omap_writel(0x00000200, 0xFFFBECF0 );
}


VOID
os_ResetGpio25(
    TI_HANDLE OsContext
    )
{
	/*
    Clear GPIO_25 by GPIO_CLEAR_DATAOUT
    */
    omap_writel(0x00000200, 0xFFFBECB0 );
}


VOID
os_SetGpio27(
    TI_HANDLE OsContext
    )
{
    /*
    Setting GPIO_27 by GPIO_SET_DATAOUT
    */
    omap_writel(0x00000800, 0xFFFBECF0 );
}


VOID
os_ResetGpio27(
    TI_HANDLE OsContext
    )
{
	/*
    Clear GPIO_27 by GPIO_CLEAR_DATAOUT
    */
    omap_writel(0x00000800, 0xFFFBECB0 );
}
#endif
/******************************************************************************/

VOID
os_disableIrq( TI_HANDLE OsContext)
{
    tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;
    disable_irq (drv->irq);
}

VOID
os_enableIrq( TI_HANDLE OsContext)
{
    tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;
    enable_irq (drv->irq);
}

int
os_getFirmwareImage(
        TI_HANDLE OsContext,
        PUINT8 *pBuffer,
        PUINT32 Length,
        UINT8 RadioType
        )
{
   tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;

   *pBuffer = drv->firmware_image.va;
   *Length = drv->firmware_image.size;

   return OK;
}


/*-----------------------------------------------------------------------------

Routine Name:

        os_getRadioImage

Routine Description:


Arguments:


Return Value:

        OK

-----------------------------------------------------------------------------*/
int
os_getRadioImage(
        TI_HANDLE OsContext,
        PUINT8 *pBuffer,
        PUINT32 Length,
        UINT8 RadioType
        )
{

#ifdef FIRMWARE_DYNAMIC_LOAD
   tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *)OsContext;

   *pBuffer = drv->eeprom_image.va;
   *Length = drv->eeprom_image.size;
#else
   extern unsigned char tiwlan_radimage[];
   extern unsigned int sizeof_tiwlan_radimage;
   *pBuffer = (PUINT8)tiwlan_radimage;
   *Length = sizeof_tiwlan_radimage;
#endif
   ti_dprintf(TIWLAN_LOG_INFO, "%s: radio type: 0x%x\n", __FUNCTION__, RadioType);

   return OK;
}


#ifdef DRIVER_PROFILING
void _os_profile (TI_HANDLE OsContext, UINT32 fn, UINT32 par)
{
    tiwlan_profile (OsContext, fn, par);
}
#endif

VOID
os_closeFirmwareImage( TI_HANDLE OsContext )
{
    return;
}

VOID
os_closeRadioImage( TI_HANDLE OsContext )
{
    return;
}