cm-kernel /drivers/net/wireless/tiwlan1251/common/src/TNETW_Driver/TNETWIF/BusTxn/whalHwAccess.c

Language C Lines 2897
MD5 Hash bd175b6898da28455cde86bd40125cfc Estimated Cost $45,883 (why?)
Repository git://github.com/CyanogenMod/cm-kernel.git View Raw File View Project SPDX
   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
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
/****************************************************************************
**+-----------------------------------------------------------------------+**
**|                                                                       |**
**| 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.  |**
**|                                                                       |**     
**+-----------------------------------------------------------------------+**
****************************************************************************/
 
/****************************************************************************
 *
 *   MODULE:  hwAccess.c
 *   PURPOSE: Support access to the wlan hardware registers and memory
 *
 *  Direct Slave mode:   
 *  -----------------
 *
 *      1. 08 bit function 
 *              - access 16 bit (WA100 has no access to 8 bits)
 *              - set/get the relevant byte according to the address (odd or even)
 *              + ((char *)&DataShort)[Addr&0x1]
 *              - no endian handle 
 *      2. 16 bit function 
 *              - access 16 bit 
 *              - short endian handle 
 *      3. 32 bit function 
 *              - access 32 bit 
 *              - long endian handle 
 *      4. buffers copy to (stream of bytes)
 *              - addresses must be even
 *              - copy buffer as stream of 16 bits (in case of src/dst address ends with 0x2)
 *              - handle case of more bytes to copy
 *              * TempWord = (*shortDest & 0x00ff) | (*shortSrc & 0xff00);
 *              - no endian handle 
 *      5. registers
 *              - access 32 bit 
 *              - long endian handle 
 *              - no use of wlan hardware capability to swap endian
 *
 *  Indirect Slave mode:
 *  -------------------
 *
 *      1. 08 bit function 
 *              - access 16 bit (WA100 has no access to 8 bits)
 *              - set/get the relevant byte according to the address (odd or even)
 *              + ((char *)&DataLong)[Addr&0x3]
 *              - no endian handle  
 *      2. 16 bit function 
 *              - access 32 bit (set addr reg , get data reg) 
 *              - set/get the relevant short according to the address (00 or 02) 
 *              + ((short *)&DataLong)[(Addr>>1)&0x1])
 *              - short endian handle 
 *      3. 32 bit function 
 *              - access 32 bit (set addr reg , get data reg) 
 *              - long endian handle 
 *      4. buffers copy to (stream of bytes)
 *              - addresses must be even
 *              - handle case of dest(wlan hardware) address ends with 0x2 - read 32 from 0x0, set only high short
 *              - now the dest(wlan hardware) address is long address
 *              - use Auto Increment Mode
 *              - copy buffer as stream of 16 bits (in case of source address ends with 0x2)
 *              - handle case of more bytes to copy
 *              * i=0..Len&3 ==> ((char *)&DataLong)[i] = ((char *)shortSrc)[i]
 *              - no endian handle 
 *      5. buffers copy from (stream of bytes)
 *              - addresses must be even
 *              - handle case of source(wlan hardware) address ends with 0x2 - read 32 from 0x0, set only high short
 *              - now the source(wlan hardware) address is long address
 *              - use Auto Increment Mode
 *              - copy buffer as stream of 16 bits (in case of dest address ends with 0x2)
 *              - handle case of more bytes to copy
 *              * i=0..Len&3 ==> ((char *)shortDest)[i] = ((char *)&DataLong)[i]
 *              - no endian handle 
 *      6. registers
 *              - access 32 bit 
 *              - long endian handle 
 *              - no use of wlan hardware capability to swap endian
 *
 ****************************************************************************/
#include "osTIType.h"
#include "osApi.h"
#include "whalCommon.h"
#include "whalHwDefs.h"
#ifdef HW_ACCESS_SDIO 

  #ifndef _WINDOWS  /*Linux, Symbian, RVCT */

#include "mmc_omap_api.h"
#include "mmc_tnetw1150_api.h"

  #else /* ifdef _WINDOWS */
  #endif /* ifdef _WINDOWS */

#elif defined(HW_ACCESS_WSPI)

#include "wspi.h" 

#endif
#include "TNETWIF.h"
#include "whalHwAccess.h"

/* #define __HWACCESS_DEBUG__ */

/*
 * Define this flag to support SDIO asynchronous mode
 */
#undef HW_ACCESS_SDIO_ASYNC_SUPPORT


/************************************************************************
 * Types
 ************************************************************************/
typedef struct _HWAccess_CB_T
{
    HwAccess_callback_t CBFunc;
    void* CBArg;
} HWAccess_CB_T;

typedef void (*HwAccessErrorHandle)(TI_HANDLE theObjectHandle,char* Report , UINT32 strLen);

typedef  struct _partition_t
{
    UINT32 size;
    UINT32 start;
} partition_t;


/* HwAccess context */
typedef struct _HwAccess_T_new
{
    void       *hProtect;

    TI_HANDLE   hOs;           
    TI_HANDLE   hReport;

#if (defined(HW_ACCESS_SDIO)|defined(HW_ACCESS_WSPI))
    TI_HANDLE   hDriver;
    UINT32      MemRegionAddr;
    UINT32      RegisterRegionAddr;
    UINT32      workingPartUpperLimit;
    UINT32      registerPartUpperLimit;
#else /* HW_ACCESS_CARDBUS */   
    UINT32      RegBaseAddr;
    UINT32      MemBaseAddr;
#endif

    HWAccess_CB_T CB;
    
    UINT8       AsyncMode;

    UINT32      uBusError;
    HwAccessErrorHandle hwAccesserror_Cb;
    TI_HANDLE   hBackReference;

    PADDING (partition_t partition [2])

} HwAccess_T_new;


/************************************************************************
 * Defines
 ************************************************************************/

#ifdef HW_ACCESS_WSPI

/*
 *  Converts status from WSPI into TI_STATUS
 */
#define WSPI2TNETWIF(pHwAccess,status,addr)                                   \
    switch(status)  {                                                         \
        case WSPI_TXN_PENDING:  status = TNETWIF_PENDING; break;              \
        case WSPI_TXN_COMPLETE: status = TNETWIF_COMPLETE; break;             \
        default:                                                              \
            WLAN_REPORT_ERROR (pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,    \
                               ("whal_hwAccess: Error in read/write async, addr=0x%08x status=%d\n", \
                               addr, status));                                \
            status = TNETWIF_ERROR; break;                                    \
}
              
/* 
* Indicate the index position at which we should check if the HW is up - 
* i.e. (buf[HW_ACCESS_WSPI_FIXED_BUSY_LEN] & 0x1 == TRUE)
*/
#ifdef TNETW1251
#define HW_ACCESS_WSPI_FIXED_BUSY_LEN       ((TNETWIF_READ_OFFSET_BYTES - 4 ) / sizeof(UINT32))
#else
#define HW_ACCESS_WSPI_FIXED_BUSY_LEN       0
#endif

#endif /* HW_ACCESS_WSPI */

#define HW_ACCESS_WSPI_INIT_CMD_MASK        0

#define HW_ACCESS_WSPI_ALIGNED_SIZE         4
#define HW_ACCESS_NUM_OF_BIT_IN_BYTE        8

#define HW_ACCESS_REGISTER_SIZE             4


/* ELP CTRL  register */
#define HW_ACCESS_ELP_CTRL_REG_ADDR         0x1FFFC


#define HW_ACCESS_1_BYTE_REMINDE_MASK       0x000000FF
#define HW_ACCESS_2_BYTE_REMINDE_MASK       0x0000FFFF
#define HW_ACCESS_3_BYTE_REMINDE_MASK       0x00FFFFFF

/* translation registers */
#define HW_ACCESS_PART0_SIZE_ADDR           0x1FFC0
#define HW_ACCESS_PART0_START_ADDR          0x1FFC4
#define HW_ACCESS_PART1_SIZE_ADDR           0x1FFC8
#define HW_ACCESS_PART1_START_ADDR          0x1FFCC


/************************************************************************
 * Macros
 ************************************************************************/
#define EXTRACT_BYTE_FROM_WORD(DataShort, Addr)     (((char *)&DataShort)[((int)Addr)&0x1])
#define EXTRACT_BYTE_FROM_LONG(DataLong, Addr)      (((char *)&DataLong )[((int)Addr)&0x3])
#define EXTRACT_WORD_FROM_LONG(DataLong, Addr)      (((short *)&DataLong)[(((int)Addr>>1))&0x1])
#define EXTRACT_BYTE_LONG(DataLong, i)              (((char *)&DataLong)[i])

#define HW_MEM_SHORT(pHwAccess, Addr)  (*(volatile UINT16 *)(pHwAccess->MemBaseAddr + (UINT32)(Addr)))
#define HW_MEM_LONG(pHwAccess, Addr)   (*(volatile UINT32 *)(pHwAccess->MemBaseAddr + (UINT32)(Addr)))

#define TRANSLATE_ADDRESS_MEM(addr) ((addr) - pHwAccess->MemRegionAddr)
#define TRANSLATE_ADDRESS_REG(addr) ((addr) + pHwAccess->RegisterRegionAddr)

#if 1 /* 0 */
    #if (defined(HW_ACCESS_SDIO)|defined(HW_ACCESS_WSPI)) /* 1 */
        void HW_REG_LONG_WRITE(HwAccess_T_new *pHwAccess, UINT32 RegAddr, UINT32 BitVal);
        void HW_REG_LONG_READ(HwAccess_T_new *pHwAccess, UINT32 RegAddr, UINT32 *Val);
    #else /* 1 */
        #define HW_REG_SHORT_WRITE(pHwAccess, Addr, Data) ((*(volatile UINT16 *)(pHwAccess->RegBaseAddr + (UINT32)(Addr))) = (UINT16)(Data))
        #define HW_REG_SHORT_READ(pHwAccess, Addr, Data)  ((*(Data)) = (*(volatile UINT16 *)(pHwAccess->RegBaseAddr + (UINT32)(Addr))) )
        #ifdef NOT_SUPPORT_32_BIT_ACCESS_COMMAND /* for example: iPAQ model 38xx */ /* 2 */
            #define HW_REG_LONG_WRITE(pHwAccess, Addr, Data)  HW_REG_SHORT_WRITE(pHwAccess, Addr, Data); HW_REG_SHORT_WRITE(pHwAccess, Addr+2, ((UINT16)(Data>>16)))
            #define HW_REG_LONG_READ(pHwAccess, Addr, pData)   HW_REG_SHORT_READ(pHwAccess, Addr, pData); HW_REG_SHORT_READ(pHwAccess, Addr+2, ((UINT16 *)pData+1))
        #else /* 2 */
            #define HW_REG_LONG_WRITE(pHwAccess, Addr, Data)  ((*(volatile UINT32 *)(pHwAccess->RegBaseAddr + (UINT32)(Addr))) = (UINT32)(Data))
            #define HW_REG_LONG_READ(pHwAccess, Addr, Data)   ((*(Data)) = (*(volatile UINT32 *)(pHwAccess->RegBaseAddr + (UINT32)(Addr))) )
        #endif /* 2 */
    #endif /* 1 */
#else  /* 0 */
#endif /* 0 */



/************************************************************************
 * Functions
 ************************************************************************/

#if !defined(HW_ACCESS_SDIO) && !defined(HW_ACCESS_WSPI)
static void whal_hwAccess_DirectCopy_new(HwAccess_T_new *pHwAccess, UINT8* Dest, UINT8* Src, UINT32 Len);
#endif
#ifdef HW_ACCESS_SDIO
static void sdio_transaction_notify_read(struct SDIO_Request *req, int status);
static void sdio_transaction_notify_write(struct SDIO_Request *req, int status);
static void sdio_transaction_error(struct SDIO_Request *req, int stat);
#ifdef CONFIG_ASYNC_API
static void sdio_async_transaction_notify(struct SDIO_Request *req, int status);
static void sdio_async_transaction_error(struct SDIO_Request *req, int status);
#endif
#endif

/* 
** Read/Write interface
**----------------------------
**
** the memory space shell be divided to 2 Partions: Memory, and Registers.
** 1.   The memory Region will be set at init to point to the FW Ram, 
**      and after FW init complete, the Memory Region will be set to point the Packet Ram.
** 2.   Registry Region.
** 
** 
*/
 
 

/************************************************************************
 * new API
 ************************************************************************/



/****************************************************************************
 *                      whal_hwAccess_Create
 ****************************************************************************
 * DESCRIPTION: create the HwAccess module. allocate the module context and create the sublayers
 *
 * INPUTS:  hOs - handle to the OS module
 *
 * OUTPUT:  TI_HANDLE - the handle to the context that was created
 *
 * RETURNS: NULL = failure.
 *          otherwise = success
 ****************************************************************************/
TI_HANDLE   whal_hwAccess_Create(TI_HANDLE hOs)
{
    HwAccess_T_new *pHwAccess;
    int status = OK;
#ifdef HW_ACCESS_SDIO
    SDIO_ConfigParams configParams;
#endif  
    pHwAccess = os_memoryAlloc(hOs, sizeof(HwAccess_T_new));
    if (pHwAccess == NULL)
        return NULL;
    
    os_memoryZero(hOs, pHwAccess, sizeof(HwAccess_T_new));
    
    pHwAccess->hOs = hOs;

    pHwAccess->hProtect = os_protectCreate(pHwAccess->hOs);
    if (pHwAccess->hProtect == NULL)
    {
        whal_hwAccess_Destroy(pHwAccess);
        return NULL;
    }
    
#ifdef HW_ACCESS_SDIO

    pHwAccess->AsyncMode = FALSE;
    
    os_memoryZero(hOs, &configParams, sizeof(SDIO_ConfigParams));
    configParams.fnotify_read = sdio_transaction_notify_read; 
    configParams.fnotify_write = sdio_transaction_notify_write; 
    configParams.ferror = sdio_transaction_error;  
    configParams.fconfig_peripheral = SDIO_TNETWConfig; 
    configParams.fconvert = NULL;
    configParams.owner = pHwAccess;

    status = SDIO_Init(&configParams, &pHwAccess->hDriver); 
    
#elif defined(HW_ACCESS_WSPI)

    pHwAccess->AsyncMode = TRUE;

    pHwAccess->hDriver = WSPI_Open (pHwAccess->hOs);
    status = pHwAccess->hDriver == NULL;    
    
#else

    pHwAccess->AsyncMode = FALSE;
    
#endif

    if (status != 0) 
    {
        if (pHwAccess->hProtect)
            os_protectDestroy(pHwAccess->hOs, pHwAccess->hProtect);
        os_memoryFree(pHwAccess->hOs, pHwAccess, sizeof(HwAccess_T_new));
        return NULL;
    }
    
    return pHwAccess;
}

/****************************************************************************
 *                      whal_hwAccess_Destroy
 ****************************************************************************
 * DESCRIPTION: destroy the module. deallocate the cmodule context.
 *
 * INPUTS:  hHwAccess - handle to the module context
 *
 * OUTPUT:  none.
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int whal_hwAccess_Destroy(TI_HANDLE hHwAccess)
{
    HwAccess_T_new *pHwAccess = (HwAccess_T_new*)hHwAccess;

    if (pHwAccess)
    {
#ifdef HW_ACCESS_SDIO

        SDIO_Stop(pHwAccess->hDriver, 0);
        SDIO_Shutdown(pHwAccess->hDriver);  

#elif defined(HW_ACCESS_WSPI)

        WSPI_Close(pHwAccess->hDriver);

#endif      
    
    
        if (pHwAccess->hProtect)
            os_protectDestroy(pHwAccess->hOs, pHwAccess->hProtect);
        os_memoryFree(pHwAccess->hOs, pHwAccess, sizeof(HwAccess_T_new));       
    }
    return OK;
}


/****************************************************************************
 *                      whal_hwAccess_Config
 ****************************************************************************
 * DESCRIPTION: config the module.
 *
 * INPUTS:  hHwAccess   - handle to the module context
 *          hReport     - handle to report module context that is used when we output debug messages
 *
 * OUTPUT:  none.
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int whal_hwAccess_Config(TI_HANDLE hHwAccess, TI_HANDLE hReport,UINT32 RegBaseAddr, UINT32 MemBaseAddr, HwAccess_callback_t CBFunc,void* CBArg)
{
    HwAccess_T_new *pHwAccess = (HwAccess_T_new*) hHwAccess;
    int status = OK;

#ifdef HW_ACCESS_WSPI
    WSPIConfig_t wspi_config;        
#endif

    pHwAccess->hReport = hReport;

#ifdef GWSI_SPI_TEST
	/* For GWSI_API_TEST this parameter should be maximum allowed because we don't use setPartition */
	pHwAccess->workingPartUpperLimit = 0xFFFFFFFF;
#endif /* GWSI_API_TEST */
    /*
    Wait 200 usec for memory repair process to finish and device is ready.
    */
    os_StalluSec(pHwAccess->hOs, 200);
    
    pHwAccess->CB.CBFunc = CBFunc;
    pHwAccess->CB.CBArg = CBArg;

#ifdef HW_ACCESS_SDIO

    pHwAccess->RegisterRegionAddr = HW_ACCESS_DOWN_PART0_SIZE;
    pHwAccess->MemRegionAddr = HW_ACCESS_DOWN_PART0_ADDR;
    pHwAccess->uBusError = 0;

    status = SDIO_Start (pHwAccess->hDriver);

    status = (status == SDIO_SUCCESS) ? TNETWIF_COMPLETE : TNETWIF_ERROR;

#elif defined(HW_ACCESS_WSPI)

    wspi_config.isFixedAddress = FALSE;
    wspi_config.fixedBusyLength = HW_ACCESS_WSPI_FIXED_BUSY_LEN;
    wspi_config.mask = HW_ACCESS_WSPI_INIT_CMD_MASK;
        
    status = WSPI_Configure (pHwAccess->hDriver, 
                             pHwAccess->hReport, 
                             &wspi_config, 
                             (WSPI_CB_T*)&pHwAccess->CB);

	WSPI_SetErrLog(pHwAccess->hDriver, TNETWIF_printErrorLog);

    WSPI2TNETWIF (pHwAccess, status, 0x0);

#else /* HW_ACCESS_CARDBUS */   
    pHwAccess->RegBaseAddr = RegBaseAddr;
    pHwAccess->MemBaseAddr = MemBaseAddr;       
#endif

    return status;
}

/****************************************************************************
 *                      whal_hwAccess_ReConfig()
 ****************************************************************************
 * DESCRIPTION: 
 * 
 * INPUTS:  None
 * 
 * OUTPUT:  None
 * 
 * RETURNS: 
 ****************************************************************************/
int whal_hwAccess_ReConfig(TI_HANDLE hHwAccess)
{
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;

#ifdef _WINDOWS
#else /* _WINDOWS */
    /* unbclock the access to the bus */
    pHwAccess->uBusError = 0;

#ifdef HW_ACCESS_SDIO
    SDIO_Stop (pHwAccess->hDriver, 0);
    SDIO_Start (pHwAccess->hDriver);
#elif defined(HW_ACCESS_WSPI)
    /* TODO*/
#endif
#endif /* _WINDOWS */
    return OK;
}


#ifdef USE_SYNC_API
/****************************************************************************
 *                      whal_hwAccess_WriteELP
 ****************************************************************************
 * DESCRIPTION: write data synchronously to the TNET ELP register (1byte)
 *
 * INPUTS:  pHwAccess - TI_HANDLE * - the HwAccess context
 *          data - UINT8 - the data to write
 *
 * OUTPUT:  none
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int whal_hwAccess_WriteELP (TI_HANDLE hHwAccess, UINT32 data)
{
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    int status = OK;

    os_profile (pHwAccess->hOs, 2, 0);

#ifdef HW_ACCESS_SDIO
    status = SDIO_TNETW_Set_ELP_Reg(pHwAccess->hDriver, HW_ACCESS_ELP_CTRL_REG_ADDR, data);
#elif defined(HW_ACCESS_WSPI)
    status = WSPI_WriteSync (pHwAccess->hDriver, HW_ACCESS_ELP_CTRL_REG_ADDR, (UINT8*)&data, HW_ACCESS_REGISTER_SIZE); 
#endif

    os_profile (pHwAccess->hOs, 3, 0);

    if (status != OK)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                          ("whal_hwAccess_WriteReg_ELP: Error in ELP reg write status=%d\n",
                          status));
        return NOK; 
    }

    return OK;
}
#endif /* USE_SYNC_API */

/****************************************************************************
 *                      whal_hwAccess_WriteELPAsync
 ****************************************************************************
 * DESCRIPTION: write data synchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data is always 4bytes cause this is the size of the TNET registers
 *              the function is passed a call-back function that will be called after the read request ends.
 *
 * INPUTS:  pHwAccess - TI_HANDLE * - the HwAccess context
 *          addr - UINT32 - the address offset inside the TNET
 *          data - UINT8* - a pointer to the buffer that holds the data to write
 *          bMore - indicate whether more txn on the bus are about to happen (FALSE only when setting
 *                  the HW to sleep).
 *
 * OUTPUT:  none                                                                
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int whal_hwAccess_WriteELPAsync (TI_HANDLE hHwAccess, UINT32 data, BOOL bCb, BOOL bMore)
{
#if defined(HW_ACCESS_SDIO)
 
  #if defined(HW_ACCESS_SDIO_ASYNC_SUPPORT)

    #error "SDIO asynchronous mode is not supported"

    /* Not implemented yet */
    return OK;

  #else

     /* Just call to synchronous API */
    return (whal_hwAccess_WriteELP (hHwAccess, data) == OK) ? 
           TNETWIF_COMPLETE :
           TNETWIF_ERROR;


  #endif

#else /* HW_ACCESS_WSPI */

    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    WSPI_CB_T Cb = { NULL, NULL }, *pCb;
    int status;

    pCb = (bCb) ? ((WSPI_CB_T*)&pHwAccess->CB) : &Cb;

    os_profile (pHwAccess->hOs, 2, 0);

    /* since we are writing a register - no extra space is needed */
    status = WSPI_WriteAsync (pHwAccess->hDriver, 
                              HW_ACCESS_ELP_CTRL_REG_ADDR, 
                              (UINT8*)&data, 
                              HW_ACCESS_REGISTER_SIZE,
                              pCb,
                              bMore,
                              FALSE);   

    os_profile (pHwAccess->hOs, 3, 0);

    WSPI2TNETWIF (pHwAccess, status, HW_ACCESS_ELP_CTRL_REG_ADDR);

    return status;

#endif
}

/****************************************************************************
 *                      whal_hwAccess_ReadELPAsync
 ****************************************************************************
 * DESCRIPTION: Read the ELP register
 *
 * INPUTS:  pHwAccess - TI_HANDLE * - the HwAccess context
 *          addr - UINT32 - the address offset inside the TNET
 *          data - UINT8* - a pointer to the buffer to read data into
 *          bMore - indicate whether more txn on the bus are about to happen (FALSE only when setting
 *                  the HW to sleep).
 *
 * OUTPUT:  none                                                                
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int whal_hwAccess_ReadELPAsync (TI_HANDLE hHwAccess, UINT8 *data, BOOL bCb, BOOL bMore)
{
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    int status;      

#ifdef HW_ACCESS_SDIO

	#ifndef _WINDOWS
	status = SDIO_TNETW_Get_ELP_Reg(pHwAccess->hDriver, HW_ACCESS_ELP_CTRL_REG_ADDR, (UINT32*)data);
	#else
	#endif

	if (status != OK)
	{
		WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
			("whal_hwAccess_ReadELPAsync: Error in ELP reg raed status=%d\n",
			status));
		return TNETWIF_ERROR; 
	}
	return TNETWIF_COMPLETE;

#else /* HW_ACCESS_WSPI */
        
        os_profile (pHwAccess->hOs, 2, 0);
        
        /* In registers we don't save place */
        status = WSPI_ReadAsync (pHwAccess->hDriver, 
            HW_ACCESS_ELP_CTRL_REG_ADDR, 
            (UINT8*)data, 
            HW_ACCESS_REGISTER_SIZE,
            (WSPI_CB_T*)&pHwAccess->CB,
            TRUE,
            FALSE);   
        
        os_profile (pHwAccess->hOs, 3, 0);
        
        WSPI2TNETWIF (pHwAccess, status, HW_ACCESS_ELP_CTRL_REG_ADDR);
        
        return status;
        
#endif
}


#ifdef USE_SYNC_API
/****************************************************************************
 *                      whal_hwAccess_ReadMem_Align
 ****************************************************************************
 * DESCRIPTION: read data synchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data specified is rounded up so the length will be multiple of 4 (bytes)
 *
 * INPUTS:  hHwAccess - the handle of HwAccess module
 *          addr - UINT32 - the address offset inside the TNET
 *          len - int - the length of the data to read
 *
 * OUTPUT:  data - UINT8* - a pointer to the buffer to fill with the read data
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int         whal_hwAccess_ReadMem_Align(TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{                                                          
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    int status = OK;
#ifdef HW_ACCESS_SDIO
    struct SDIO_Request request;
#endif
    
    /* round up the length so it will be multiple of 4bytes */
    if(len&0x3)
        len = (len&0xFFFFFFFC)+4;

#ifdef HW_ACCESS_SDIO

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMem_Align: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

    request.buffer = data; /* Pointer to the data buffer aligned address.  */
    request.buffer_len = len; /* Data buffer length in bytes */ 
    request.status = SDIO_Request_None;
    request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
    request.acquire_window = 0;  /*Time out value is not set*/
    request.block_len = 0;       /*Block length. Assigned by driver*/
    request.physical_buffer = 0; /*Physical address of data buffer is not set*/
    request.owner = (SDIO_Owner) pHwAccess;
    request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
    request.access_flag = 1;

    os_profile (pHwAccess->hOs, 2, 0);

    status = SDIO_SyncRead(pHwAccess->hDriver, &request);

    os_profile (pHwAccess->hOs, 3, 0);

    
#elif defined(HW_ACCESS_WSPI)    

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMem_Align: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

    os_profile (pHwAccess->hOs, 2, 0);

    status = WSPI_ReadSync(pHwAccess->hDriver,TRANSLATE_ADDRESS_MEM(addr),data,len);    

    os_profile (pHwAccess->hOs, 3, 0);

#else
    whal_hwAccess_DirectCopy_new(pHwAccess, data, (UINT8*)addr, len);
#endif

    if (status != OK)
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_ReadMem_Align: Error in read, addr=0x%08x status=%d\n",
                             addr, status));

#ifdef HW_ACCESS_SDIO
    if (pHwAccess->uBusError)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
        ("whal_hwAccess_ReadMem_Align: SDIO Error status=%d\n",
        request.status));
        if (pHwAccess->hwAccesserror_Cb) 
        {
            UINT8 failure_reason = HEALTH_REPORT_BUS_ERROR;
            pHwAccess->hwAccesserror_Cb(pHwAccess->hBackReference,(char*)&failure_reason,2);
        }
        else
            pHwAccess->uBusError = 0;
    }
#endif

    return status;
}

/****************************************************************************
 *                      whal_hwAccess_WriteMem_Align
 ****************************************************************************
 * DESCRIPTION: write data synchronously to the TNET using the defined access (WSPI/SDIO). 
 *              the length of data specified is rounded up so the length will be multiple of 4 (bytes)
 *
 * INPUTS:  hHwAccess - the handle of HwAccess module
 *          addr - UINT32 - the address offset inside the TNET
 *          data - UINT8* - a pointer to the buffer that holds the data to write
 *          len - int - the length of the data to read
 *
 * OUTPUT:  none
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int         whal_hwAccess_WriteMem_Align(TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    int status = OK;
#ifdef HW_ACCESS_SDIO
    struct SDIO_Request request;
#endif
    
    /* round the length so it will be multiple of 4bytes */
    if(len&0x3)
        len = (len&0xFFFFFFFC)+4;
    
#ifdef HW_ACCESS_SDIO

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_WriteMem_Align: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }
    
    request.buffer = data; /* Pointer to the data buffer aligned address.  */
    request.buffer_len = len; /* Data buffer length in bytes */ 
    request.status = SDIO_Request_None;
    request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
    request.acquire_window = 0;  /*Time out value is not set*/
    request.block_len = 0;       /*Block length. Assigned by driver*/
    request.physical_buffer = 0; /*Physical address of data buffer is not set*/
    request.owner = (SDIO_Owner) pHwAccess;
    request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
    request.access_flag = 0;

    os_profile (pHwAccess->hOs, 2, 0);

    status = SDIO_SyncWrite(pHwAccess->hDriver, &request);  

    os_profile (pHwAccess->hOs, 3, 0);
 

#elif defined(HW_ACCESS_WSPI)

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_WriteMem_Align: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

    os_profile (pHwAccess->hOs, 2, 0);

    status = WSPI_WriteSync(pHwAccess->hDriver,TRANSLATE_ADDRESS_MEM(addr),data,len);

    os_profile (pHwAccess->hOs, 3, 0);
                
#else
    whal_hwAccess_DirectCopy_new(pHwAccess, (UINT8*)addr, data, len);
#endif

    if (status != OK)
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_WriteMem_Align: Error in write, addr=0x%08x status=%d\n",
                             addr, status));

#ifdef HW_ACCESS_SDIO
    if (pHwAccess->uBusError) 
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
        ("whal_hwAccess_WriteMem_Align: SDIO Error in write status=%d\n",
        request.status));
        if (pHwAccess->hwAccesserror_Cb) 
        {
            UINT8 failure_reason = HEALTH_REPORT_BUS_ERROR;
            pHwAccess->hwAccesserror_Cb(pHwAccess->hBackReference,(char*)&failure_reason,2);
        }
        else 
            pHwAccess->uBusError = 0;
    }
#endif

    return status;
}
#endif /* USE_SYNC_API */

/****************************************************************************
 *                      whal_hwAccess_ReadMemAsync_Align
 ****************************************************************************
 * DESCRIPTION: read data asynchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data specified is rounded up so the length will be multiple of 4 (bytes)
 *              the function is passed a call-back function that will be called after the read request ends.
 *
 * INPUTS:  hHwAccess - the handle of HwAccess module
 *          addr - UINT32 - the address offset inside the TNET
 *          len - int - the length of the data to read
 *          CB - HWAccess_CB_T* - a pointer to a structure that holds the CB function and the passed arg.
 *
 * OUTPUT:  data - UINT8* - a pointer to the buffer to fill with the read data
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int         whal_hwAccess_ReadMemAsync_Align(TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{       
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;

    /* Round the length so it will be multiple of 4bytes */
    if ((len & 0x3) != 0)
        len = (len & ~3) + 4;

    /* Check address */
    if (addr + len > pHwAccess->workingPartUpperLimit || addr < pHwAccess->MemRegionAddr)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMemAsync_Align: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

#if defined(HW_ACCESS_SDIO)

  #if defined(HW_ACCESS_SDIO_ASYNC_SUPPORT)
    {   
        struct SDIO_Request request;    
        int status = OK;

        request.buffer = data; /* Pointer to the data buffer aligned address.  */
        request.buffer_len = len; /* Data buffer length in bytes */ 
        request.status = SDIO_Request_None;
        request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
        request.acquire_window = 0;  /*Time out value is not set*/
        request.block_len = 0;       /*Block length. Assigned by driver*/
        request.physical_buffer = 0; /*Physical address of data buffer is not set*/
        request.owner = (SDIO_Owner) pHwAccess;
        request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
        request.access_flag = 1;
        request.fnotify = sdio_async_transaction_notify; /* completion notification */
        request.ferror = sdio_async_transaction_error; /* error notification */

        os_profile (pHwAccess->hOs, 2, 0);

        status = SDIO_AsyncRead (pHwAccess->hDriver, &request);  

        os_profile (pHwAccess->hOs, 3, 0);

        if (status != OK)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_ReadMemAsync_Align: Error in read async, addr=0x%08x status=%d\n",
                             addr, status));
            return TNETWIF_ERROR;
        }

        if (pHwAccess->uBusError)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                              ("whal_hwAccess_ReadMemAsync_Align: SDIO Error status=%d\n",
                              request.status));
            if (pHwAccess->hwAccesserror_Cb) 
            {
                UINT16 failure_reason = HEALTH_REPORT_BUS_ERROR;
                pHwAccess->hwAccesserror_Cb(pHwAccess->hBackReference,&failure_reason,2);
            }
            else
                pHwAccess->uBusError = 0;
        }

        return TNETWIF_COMPLETE;
    }

  #else

    return TNETWIF_COMPLETE;
  
  #endif
            
#else /*HW_ACCESS_WSPI*/
    {
        int status;
        
        os_profile (pHwAccess->hOs, 2, 0);

        status = WSPI_ReadAsync (pHwAccess->hDriver,
                                 TRANSLATE_ADDRESS_MEM(addr),
                                 data,
                                 len,
                                 (WSPI_CB_T*)&pHwAccess->CB,
                                 TRUE,
                                 0);

        os_profile (pHwAccess->hOs, 3, 0);

        WSPI2TNETWIF (pHwAccess, status, addr);

        return status; 
    }
  
#endif
}

/****************************************************************************                       
 *                      whal_hwAccess_WriteAsync_Align
 ****************************************************************************
 * DESCRIPTION: write data synchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data specified is rounded up so the length will be multiple of 4 (bytes)
 *              the function is passed a call-back function that will be called after the read request ends.
 *
 * INPUTS:  pHwAccess - HwAccess_T* - the HwAccess context
 *          addr - UINT32 - the address offset inside the TNET
 *          data - UINT8* - a pointer to the buffer that holds the data to write
 *          Len - int - the length of the data to read
 *          CB - HWAccess_CB_T* - a pointer to a structure that holds the CB function and the passed arg.
 *
 * OUTPUT:  none
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
 int         whal_hwAccess_WriteMemAsync_Align(TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{           
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;

    /* Round the length so it will be multiple of 4bytes */
    if ((len & 0x3) != 0)
        len = (len & ~3) + 4;

    /* Check address */
    if (addr + len > pHwAccess->workingPartUpperLimit || addr < pHwAccess->MemRegionAddr)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                          ("whal_hwAccess_WriteMemAsync_Align: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
                          addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

#if defined(HW_ACCESS_SDIO)

  #if defined(HW_ACCESS_SDIO_ASYNC_SUPPORT)
    {    
        struct SDIO_Request request;    
        int status = OK;

        request.buffer = data; /*Pointer to the data buffer aligned address*/
        request.buffer_len = len; /*Data buffer length in bytes*/ 
        request.status = SDIO_Request_None;
        request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
        request.acquire_window = 0;  /* Time out value is not set */
        request.block_len = 0;       /* Block length. Assigned by driver */
        request.physical_buffer = 0; /* Physical address of data buffer is not set */
        request.owner = (SDIO_Owner) pHwAccess;
        request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
        request.access_flag = 0;
        request.fnotify = sdio_async_transaction_notify; /* completion notification */
        request.ferror = sdio_async_transaction_error; /* error notification */

        os_profile (pHwAccess->hOs, 2, 0);

        status = SDIO_AsyncWrite (pHwAccess->hDriver, &request);    

        os_profile (pHwAccess->hOs, 3, 0);

        if (status != OK)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                              ("whal_hwAccess_WriteMemAsync_Align: Error in write async, addr=0x%08x status=%d\n",
                              addr, status));

            return TNETWIF_ERROR; 
        }

        return TNETWIF_COMPLETE;
    }

  #else

    return TNETWIF_COMPLETE;

  #endif
            
#else /*HW_ACCESS_WSPI*/
    {
        int status;

        os_profile (pHwAccess->hOs, 2, 0);

        status = WSPI_WriteAsync (pHwAccess->hDriver,
                                  TRANSLATE_ADDRESS_MEM(addr),
                                  data,
                                  len,
                                  (WSPI_CB_T*)&pHwAccess->CB,
                                  TRUE,
                                  FALSE);   

        os_profile (pHwAccess->hOs, 3, 0);
            
        WSPI2TNETWIF (pHwAccess, status, addr);

        return status;
    }
#endif
}


#ifdef USE_SYNC_API
/****************************************************************************
 *                      whal_hwAccess_ReadMem
 ****************************************************************************
 * DESCRIPTION: read data synchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data is checked and the remnant (length%4) is completed with read-modify
 *
 * INPUTS:  pHwAccess - HwAccess_T* - the HwAccess context
 *          AddrOffset - UINT32 - the address offset inside the TNET
 *          Len - int - the length of the data to read
 *
 * OUTPUT:  data - UINT8* - a pointer to the buffer to fill with the read data
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int         whal_hwAccess_ReadMem(TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{
    int status = OK;    
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;

#ifdef HW_ACCESS_SDIO
    struct SDIO_Request request;
#elif defined(HW_ACCESS_WSPI)
    int reminder = len%HW_ACCESS_WSPI_ALIGNED_SIZE;
    int tempLen = len - reminder;
    UINT32 mask = 0;
    status = whal_hwAccess_ReadMemAsync(hHwAccess, addr, data, len);
    if (status == TNETWIF_COMPLETE)
    {
        status = OK;
    }
    return status;
#endif

    /* access is blocked */
    if (pHwAccess->uBusError) 
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_CTRL_MODULE_LOG,
                              ("Bus is blocked \n"));
        return ERROR_HW_ACCEESS_ADDR;
    }

#ifdef __HWACCESS_DEBUG__
    /* check address alignment */
    if(addr & 0x3)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMem: addr is not aligned 0x%x\n",
            addr));     
    }
    
#endif
        
#ifdef HW_ACCESS_SDIO

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMem: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

    request.buffer = data; /* Pointer to the data buffer aligned address.  */
    request.buffer_len = len; /* Data buffer length in bytes */ 
    request.status = SDIO_Request_None;
    request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
    request.acquire_window = 0;  /*Time out value is not set*/
    request.block_len = 0;       /*Block length. Assigned by driver*/
    request.physical_buffer = 0; /*Physical address of data buffer is not set*/
    request.owner = (SDIO_Owner) pHwAccess;
    request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
    request.access_flag = 1;

    os_profile (pHwAccess->hOs, 2, 0);

    status = SDIO_SyncRead(pHwAccess->hDriver, &request);

    os_profile (pHwAccess->hOs, 3, 0);

    if (status != OK)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_ReadMem: SDIO Error in read\n"));
        return status;
    }

#elif defined(HW_ACCESS_WSPI) 

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMem: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }
    
    os_profile (pHwAccess->hOs, 2, 0);

    /* read the aligned size */
    status = WSPI_ReadSync(pHwAccess->hDriver,TRANSLATE_ADDRESS_MEM(addr),data,tempLen);

    os_profile (pHwAccess->hOs, 3, 0);

    if (status != OK)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_ReadMem: WSPI Error in read\n"));
        return status;
    }
    
    /* read the non aligned reminder */
    if(reminder)
    {
        UINT32 tempVal = 0;     
        
        os_profile (pHwAccess->hOs, 2, 0);

        /* read the extra data*/
        status |= WSPI_ReadSync(pHwAccess->hDriver,TRANSLATE_ADDRESS_MEM(addr+tempLen),(UINT8*)&tempVal,HW_ACCESS_WSPI_ALIGNED_SIZE);

        os_profile (pHwAccess->hOs, 3, 0);

        if (status != OK)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_ReadMem: WSPI Error in read\n"));
            return status;
        }
        
        /* extract the relevant data */
        switch(reminder) 
        {
            case 1:
                mask = HW_ACCESS_1_BYTE_REMINDE_MASK;
                break;
            case 2:
                mask = HW_ACCESS_2_BYTE_REMINDE_MASK;
                break;
            case 3:
                mask = HW_ACCESS_3_BYTE_REMINDE_MASK;
                break;
        }                           
        *(UINT32*)&data[tempLen] &= ~mask;
        *(UINT32*)&data[tempLen] |= tempVal & mask;
    }

#else
    whal_hwAccess_DirectCopy_new(pHwAccess, data, (UINT8*)(pHwAccess->MemBaseAddr+addr), len);
#endif

#ifdef HW_ACCESS_SDIO
    if (pHwAccess->uBusError)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
        ("whal_hwAccess_ReadMem: SDIO Error status=%d\n",
        request.status));
        if (pHwAccess->hwAccesserror_Cb) 
        {
            UINT8 failure_reason = HEALTH_REPORT_BUS_ERROR;
            pHwAccess->hwAccesserror_Cb(pHwAccess->hBackReference,(char*)&failure_reason,2);
        }
        else
            pHwAccess->uBusError = 0;
    }
#endif

    return OK;
}



/****************************************************************************
 *                      whal_hwAccess_WriteMem
 ****************************************************************************
 * DESCRIPTION: write data synchronously to the TNET using the defined access (WSPI/SDIO). 
 *              the length of data is checked and the remnant (length%4) is completed with read-modify-write
 *
 * INPUTS:  pHwAccess - TI_HANDLE* - the HwAccess context
 *          addr - UINT32 - the address offset inside the TNET
 *          data - UINT8* - a pointer to the buffer that holds the data to write
 *          Len - int - the length of the data to read
 *
 * OUTPUT:  none
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int         whal_hwAccess_WriteMem(TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{                                                         
    int status = OK;    
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    
#ifdef HW_ACCESS_SDIO
    struct SDIO_Request request;
#elif defined(HW_ACCESS_WSPI)    
    int reminder = len % HW_ACCESS_WSPI_ALIGNED_SIZE;
    int tempLen = len - reminder;
    UINT32 mask = 0;
    status = whal_hwAccess_WriteMemAsync(hHwAccess, addr, data,  len);
    if (status == TNETWIF_COMPLETE)
    {
        status = OK;
    }
    return status;
#endif

    /* access is blocked */
    if (pHwAccess->uBusError) 
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_CTRL_MODULE_LOG,
                              ("Bus is blocked \n"));
        return ERROR_HW_ACCEESS_ADDR;
    }

#ifdef __HWACCESS_DEBUG__
    /* check address alignment */
    if(addr & 0x3)
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_WriteMem: addr is not aligned 0x%x\n",
            addr));
#endif
    
#ifdef HW_ACCESS_SDIO                                       

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_WriteMem: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

    request.buffer = data; /* Pointer to the data buffer aligned address.  */
    request.buffer_len = len; /* Data buffer length in bytes */ 
    request.status = SDIO_Request_None;
    request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
    request.acquire_window = 0;  /*Time out value is not set*/
    request.block_len = 0;       /*Block length. Assigned by driver*/
    request.physical_buffer = 0; /*Physical address of data buffer is not set*/
    request.owner = (SDIO_Owner) pHwAccess;
    request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
    request.access_flag = 0;

    os_profile (pHwAccess->hOs, 2, 0);

    status = SDIO_SyncWrite(pHwAccess->hDriver, &request);  

    os_profile (pHwAccess->hOs, 3, 0);

    if (status != OK)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_WriteMem: SDIO Error in write (%d)\n", status));
        return status;
    }

#elif defined(HW_ACCESS_WSPI)

    /* check address */
    if (((addr+len) > pHwAccess->workingPartUpperLimit) || (addr < pHwAccess->MemRegionAddr))
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_WriteMem: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

    os_profile (pHwAccess->hOs, 2, 0);

    /* write the aligned size */
    status = WSPI_WriteSync(pHwAccess->hDriver,TRANSLATE_ADDRESS_MEM(addr),data,tempLen);

    os_profile (pHwAccess->hOs, 3, 0);


    if (status != OK)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_WriteMem: WSPI Error in write\n"));
        return status;
    }
    
    /* read the non aligned reminder */
    if(reminder)
    {
        UINT32 tempVal;     
        
        os_profile (pHwAccess->hOs, 2, 0);

        /* read the extra data*/
        status |= WSPI_ReadSync(pHwAccess->hDriver,TRANSLATE_ADDRESS_MEM(addr + tempLen),(UINT8*)&tempVal,HW_ACCESS_WSPI_ALIGNED_SIZE);

        os_profile (pHwAccess->hOs, 3, 0);

        if (status != OK)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_WriteMem: WSPI Error in read\n"));
            return status;
        }
        
        /* extract the relevant data */
        switch(reminder) 
        {
            case 1:
                mask = HW_ACCESS_1_BYTE_REMINDE_MASK;
                break;
            case 2:
                mask = HW_ACCESS_2_BYTE_REMINDE_MASK;
                break;
            case 3:
                mask = HW_ACCESS_3_BYTE_REMINDE_MASK;
                break;
        }

        tempVal &= ~mask;
        tempVal |= *(UINT32*)&data[tempLen] & mask;

        os_profile (pHwAccess->hOs, 2, 0);

        /* write the modified extra data */
        status = WSPI_WriteSync(pHwAccess->hDriver,TRANSLATE_ADDRESS_MEM(addr + tempLen),(UINT8*)&tempVal,HW_ACCESS_WSPI_ALIGNED_SIZE);     

        os_profile (pHwAccess->hOs, 3, 0);

        if (status != OK)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                             ("whal_hwAccess_WriteMem: WSPI Error in write\n"));
            return status;
        }                                       
    }   
            
#else
    whal_hwAccess_DirectCopy_new(pHwAccess, (UINT8*)(pHwAccess->MemBaseAddr+addr), data, len);
#endif

#ifdef HW_ACCESS_SDIO
    if (pHwAccess->uBusError) 
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
        ("whal_hwAccess_WriteMem: SDIO Error in write status=%d\n",
        request.status));
        if (pHwAccess->hwAccesserror_Cb) 
        {
            UINT8 failure_reason = HEALTH_REPORT_BUS_ERROR;
            pHwAccess->hwAccesserror_Cb(pHwAccess->hBackReference,(char*)&failure_reason,2);
        }
        else 
            pHwAccess->uBusError = 0;

    }
#endif
    return OK;
}
#endif /* USE_SYNC_API */ 


/****************************************************************************
 *                      whal_hwAccess_WriteMemAsync
 ****************************************************************************
 * DESCRIPTION: write data synchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data is checked and the remnant (length%4) is completed with read-modify-write
 *              the function is passed a call-back function that will be called after the read request ends.
 *
 * INPUTS:  pHwAccess - TI_HANDLE* - the HwAccess context
 *          addr - UINT32 - the address offset inside the TNET
 *          data - UINT8* - a pointer to the buffer that holds the data to write
 *          Len - int - the length of the data to read
 *          CB - HWAccess_CB_T* - a pointer to a structure that holds the CB function and the passed arg.
 *
 * OUTPUT:  none
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
TI_STATUS           whal_hwAccess_WriteMemAsync(TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{   
#if defined(HW_ACCESS_SDIO) && !defined(HW_ACCESS_SDIO_ASYNC_SUPPORT)

    /* Just call to synchronous API - add the offset that was added to the WSPI bus - only if it was reserved*/
    return (whal_hwAccess_WriteMem (hHwAccess, addr, data + TNETWIF_WRITE_OFFSET_BYTES, len) == OK) 
               ? TNETWIF_COMPLETE
               : TNETWIF_ERROR;   

#else

    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    int status = OK;

    /* Access is blocked */
    if (pHwAccess->uBusError) 
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_CTRL_MODULE_LOG,
                          ("Bus is blocked \n"));
        return (TI_STATUS)ERROR_HW_ACCEESS_ADDR;
    }

    /* Check length */
    if ((len & 0x3) != 0)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                          ("whal_hwAccess_WriteMemAsync: Error in length = %d\n",
                          len));
        return (TI_STATUS)ERROR_HW_ACCEESS_LEN;
    }

    /* Check address */
    if (addr + len > pHwAccess->workingPartUpperLimit || 
        addr < pHwAccess->MemRegionAddr)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                          ("whal_hwAccess_WriteMemAsync: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
                          addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return (TI_STATUS)ERROR_HW_ACCEESS_ADDR;
    }

#if defined(HW_ACCESS_SDIO)
    {
        struct SDIO_Request request;    

        request.buffer = data + TNETWIF_WRITE_OFFSET_BYTES; /*Pointer to the data buffer aligned address*/
        request.buffer_len = len; /*Data buffer length in bytes*/ 
        request.status = SDIO_Request_None;
        request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
        request.acquire_window = 0;  /* Time out value is not set */
        request.block_len = 0;       /* Block length. Assigned by driver */
        request.physical_buffer = 0; /* Physical address of data buffer is not set */
        request.owner = (SDIO_Owner) pHwAccess;
        request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
        request.access_flag = 0;
        request.fnotify = sdio_async_transaction_notify; /* completion notification */
        request.ferror = sdio_async_transaction_error; /* error notification */

        os_profile (pHwAccess->hOs, 2, 0);

        status = SDIO_AsyncWrite (pHwAccess->hDriver, &request); 

        os_profile (pHwAccess->hOs, 3, 0);

        if (status != OK)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                              ("whal_hwAccess_WriteMemAsync: Error in write async, addr=0x%08x status=%d\n",
                              addr, status));
            return TNETWIF_ERROR;
        }

        if (pHwAccess->uBusError) 
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_WriteMemAsync: SDIO Error in write status=%d\n",
            request.status));
            if (pHwAccess->hwAccesserror_Cb) 
            {
                UINT8 failure_reason = HEALTH_REPORT_BUS_ERROR;
                pHwAccess->hwAccesserror_Cb(pHwAccess->hBackReference,&failure_reason,2);
            }
            else 
                pHwAccess->uBusError = 0;
        
        }

        return TNETWIF_COMPLETE;
    }
        
#elif defined(HW_ACCESS_WSPI)

    os_profile (pHwAccess->hOs, 2, 0);

    status = WSPI_WriteAsync (pHwAccess->hDriver,
                              TRANSLATE_ADDRESS_MEM(addr),
                              data,
                              len,
                              (WSPI_CB_T*)&pHwAccess->CB,
                              TRUE, 
                              TRUE); /* place is always reserved in write mem operation */   

    os_profile (pHwAccess->hOs, 3, 0);
                
    WSPI2TNETWIF (pHwAccess, status, addr);

    return (TI_STATUS)status;

#else

    /* By now since the CB is a SYNCH interface then call the SYNCH interface */
    whal_hwAccess_DirectCopy_new(pHwAccess, (UINT8*)(pHwAccess->MemBaseAddr+addr), data, len);

    return OK;

#endif

#endif
}


/****************************************************************************
 *                      whal_hwAccess_ReadMemAsync
 ****************************************************************************
 * DESCRIPTION: read data asynchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data is checked and the remnant (length%4) is completed with read-modify
 *              the function is passed a call-back function that will be called after the read request ends.
 *
 * INPUTS:  pHwAccess - TI_HANDLE* - the HwAccess context
 *          addr - UINT32 - the address offset inside the TNET
 *          Len - int - the length of the data to read
 *          CB - HWAccess_CB_T* - a pointer to a structure that holds the CB function and the passed arg.
 *
 * OUTPUT:  data - UINT8* - a pointer to the buffer to fill with the read data
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int whal_hwAccess_ReadMemAsync (TI_HANDLE hHwAccess, UINT32 addr, UINT8* data, UINT16 len)
{
#if defined(HW_ACCESS_SDIO) && !defined(HW_ACCESS_SDIO_ASYNC_SUPPORT)  
  
    /* Just call to synchronous API - add the offset that was added to the WSPI bus */
    return (whal_hwAccess_ReadMem (hHwAccess, addr, data  + TNETWIF_READ_OFFSET_BYTES, len) == OK)
               ? TNETWIF_COMPLETE
               : TNETWIF_ERROR;

#else

    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    int status = OK;

    /* Access is blocked */
    if (pHwAccess->uBusError) 
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_CTRL_MODULE_LOG,
                              ("Bus is blocked \n"));
        return ERROR_HW_ACCEESS_ADDR;
    }

    /* Check length */
    if ((len & 0x3) != 0)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMemAsync: Error in length = %d\n",
            len));
        return ERROR_HW_ACCEESS_LEN;
    }
    
    /* Check address */
    if (addr + len > pHwAccess->workingPartUpperLimit || 
        addr < pHwAccess->MemRegionAddr)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadMemAsync: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->MemRegionAddr, pHwAccess->workingPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

#if defined(HW_ACCESS_SDIO)
    {
        struct SDIO_Request request;    

        request.buffer = data + TNETWIF_READ_OFFSET_BYTES; /*Pointer to the data buffer aligned address*/
        request.buffer_len = len; /*Data buffer length in bytes*/ 
        request.status = SDIO_Request_None;
        request.peripheral_addr = (SDIO_Address)TRANSLATE_ADDRESS_MEM(addr); /*SDIO peripheral address*/
        request.acquire_window = 0;  /* Time out value is not set */
        request.block_len = 0;       /* Block length. Assigned by driver */
        request.physical_buffer = 0; /* Physical address of data buffer is not set */
        request.owner = (SDIO_Owner) pHwAccess;
        request.mode = MMC_DEV_BYTE_INCREMENTAL_MODE;
        request.access_flag = 0;
        request.fnotify = sdio_async_transaction_notify; /* completion notification */
        request.ferror = sdio_async_transaction_error; /* error notification */

        os_profile (pHwAccess->hOs, 2, 0);

        status = SDIO_AsyncRead (pHwAccess->hDriver, &request);  

        os_profile (pHwAccess->hOs, 3, 0);

        if (status != OK)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                              ("whal_hwAccess_ReadMemAsync: Error in write async, addr=0x%08x status=%d\n",
                              addr, status));
            return TNETWIF_ERROR;
        }

        if (pHwAccess->uBusError)
        {
            WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
                              ("whal_hwAccess_ReadMemAsync: SDIO Error in write SrcOffset=0x%08x status=%d\n",
                              SrcOffset, request.status));
            if (pHwAccess->hwAccesserror_Cb) 
            {
                UINT16 failure_reason = HEALTH_REPORT_BUS_ERROR;
                pHwAccess->hwAccesserror_Cb(pHwAccess->hBackReference,&failure_reason,2);
            }
            else
                pHwAccess->uBusError = 0;
        }

        return TNETWIF_COMPLETE;
    }
            
#elif defined(HW_ACCESS_WSPI)

    os_profile (pHwAccess->hOs, 2, 0);

    status = WSPI_ReadAsync (pHwAccess->hDriver, 
                             TRANSLATE_ADDRESS_MEM(addr), 
                             data, 
                             len, 
                             (WSPI_CB_T*)&pHwAccess->CB,
                             TRUE,
                             TRUE); /* place is always reserved in readMem */    
            
    os_profile (pHwAccess->hOs, 3, 0);

    WSPI2TNETWIF (pHwAccess, status, addr);

    return status;

#endif

#endif
}


#ifdef USE_SYNC_API
/****************************************************************************
 *                      whal_hwAccess_ReadReg
 ****************************************************************************
 * DESCRIPTION: read data synchronously from the TNET using the defined access (WSPI/SDIO). 
 *              the length of data is always 4bytes cause this is the size of the TNET registers
 *
 * INPUTS:  pHwAccess - HwAccess_T_new* - the HwAccess context
 *          addr - UINT32 - the address offset inside the TNET
 *          Len - int - the length of the data to read
 *
 * OUTPUT:  data - UINT8* - a pointer to the buffer to fill with the read data
 *
 * RETURNS: one of the error codes (0 => OK)
 ****************************************************************************/
int         whal_hwAccess_ReadReg(TI_HANDLE hHwAccess, UINT32 addr, UINT32* data)
{
    HwAccess_T_new* pHwAccess = (HwAccess_T_new*)hHwAccess;
    int status = OK;

#ifdef HW_ACCESS_SDIO
    struct SDIO_Request request;

    /* check address */
    if (addr > pHwAccess->registerPartUpperLimit)
    {
        WLAN_REPORT_ERROR(pHwAccess->hReport, HAL_HW_CTRL_MODULE_LOG,  
            ("whal_hwAccess_ReadReg: Error in addr 0x%x (lower:0x%x,upper:0x%x)\n",
            addr, pHwAccess->RegisterRegionAddr, pHwAccess->registerPartUpperLimit));
        return ERROR_HW_ACCEESS_ADDR;
    }

    request.buffer = (UINT8*)data; /*Pointer to the data buffer aligned address.*/
    request.buffer_len = HW_ACCESS_REGISTER_SIZE; /*Data buffer length in bytes*/ 
    request.status = SDIO_Request_None;
    request.peripheral_addr = TRANSLATE_ADDRESS_REG(addr); 
    request.acquire_window = 0;  /* Time out value is not set */
    request.block_len = 0;       /* Block length. Assigned by driver */
    request.owner = (SDIO_Owner) pHwAccess;
    request.physical_buffer = 0; /* Physical address of data buffer is not set */
    request.mode 
Back to Top