]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/winbond/wbhal.c
da39eef7dce4c959a2a1d0564905732f13221b10
[linux-2.6-omap-h63xx.git] / drivers / staging / winbond / wbhal.c
1 #include "os_common.h"
2 #include "wbhal_f.h"
3 #include "wblinux_f.h"
4
5 void hal_get_ethernet_address( phw_data_t pHwData, u8 *current_address )
6 {
7         if( pHwData->SurpriseRemove ) return;
8
9         memcpy( current_address, pHwData->CurrentMacAddress, ETH_LENGTH_OF_ADDRESS );
10 }
11
12 void hal_set_ethernet_address( phw_data_t pHwData, u8 *current_address )
13 {
14         u32 ltmp[2];
15
16         if( pHwData->SurpriseRemove ) return;
17
18         memcpy( pHwData->CurrentMacAddress, current_address, ETH_LENGTH_OF_ADDRESS );
19
20         ltmp[0]= cpu_to_le32( *(u32 *)pHwData->CurrentMacAddress );
21         ltmp[1]= cpu_to_le32( *(u32 *)(pHwData->CurrentMacAddress + 4) ) & 0xffff;
22
23         Wb35Reg_BurstWrite( pHwData, 0x03e8, ltmp, 2, AUTO_INCREMENT );
24 }
25
26 void hal_get_permanent_address( phw_data_t pHwData, u8 *pethernet_address )
27 {
28         if( pHwData->SurpriseRemove ) return;
29
30         memcpy( pethernet_address, pHwData->PermanentMacAddress, 6 );
31 }
32
33 static void hal_led_control(unsigned long data)
34 {
35         struct wb35_adapter *adapter = (struct wb35_adapter *) data;
36         phw_data_t pHwData = &adapter->sHwData;
37         struct wb35_reg *reg = &pHwData->reg;
38         u32     LEDSet = (pHwData->SoftwareSet & HAL_LED_SET_MASK) >> HAL_LED_SET_SHIFT;
39         u8      LEDgray[20] = { 0,3,4,6,8,10,11,12,13,14,15,14,13,12,11,10,8,6,4,2 };
40         u8      LEDgray2[30] = { 7,8,9,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,15,14,13,12,11,10,9,8 };
41         u32     TimeInterval = 500, ltmp, ltmp2;
42         ltmp=0;
43
44         if( pHwData->SurpriseRemove ) return;
45
46         if( pHwData->LED_control ) {
47                 ltmp2 = pHwData->LED_control & 0xff;
48                 if( ltmp2 == 5 ) // 5 is WPS mode
49                 {
50                         TimeInterval = 100;
51                         ltmp2 = (pHwData->LED_control>>8) & 0xff;
52                         switch( ltmp2 )
53                         {
54                                 case 1: // [0.2 On][0.1 Off]...
55                                         pHwData->LED_Blinking %= 3;
56                                         ltmp = 0x1010; // Led 1 & 0 Green and Red
57                                         if( pHwData->LED_Blinking == 2 ) // Turn off
58                                                 ltmp = 0;
59                                         break;
60                                 case 2: // [0.1 On][0.1 Off]...
61                                         pHwData->LED_Blinking %= 2;
62                                         ltmp = 0x0010; // Led 0 red color
63                                         if( pHwData->LED_Blinking ) // Turn off
64                                                 ltmp = 0;
65                                         break;
66                                 case 3: // [0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.5 Off]...
67                                         pHwData->LED_Blinking %= 15;
68                                         ltmp = 0x0010; // Led 0 red color
69                                         if( (pHwData->LED_Blinking >= 9) || (pHwData->LED_Blinking%2) ) // Turn off 0.6 sec
70                                                 ltmp = 0;
71                                         break;
72                                 case 4: // [300 On][ off ]
73                                         ltmp = 0x1000; // Led 1 Green color
74                                         if( pHwData->LED_Blinking >= 3000 )
75                                                 ltmp = 0; // led maybe on after 300sec * 32bit counter overlap.
76                                         break;
77                         }
78                         pHwData->LED_Blinking++;
79
80                         reg->U1BC_LEDConfigure = ltmp;
81                         if( LEDSet != 7 ) // Only 111 mode has 2 LEDs on PCB.
82                         {
83                                 reg->U1BC_LEDConfigure |= (ltmp &0xff)<<8; // Copy LED result to each LED control register
84                                 reg->U1BC_LEDConfigure |= (ltmp &0xff00)>>8;
85                         }
86                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
87                 }
88         }
89         else if( pHwData->CurrentRadioSw || pHwData->CurrentRadioHw ) // If radio off
90         {
91                 if( reg->U1BC_LEDConfigure & 0x1010 )
92                 {
93                         reg->U1BC_LEDConfigure &= ~0x1010;
94                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
95                 }
96         }
97         else
98         {
99                 switch( LEDSet )
100                 {
101                         case 4: // [100] Only 1 Led be placed on PCB and use pin 21 of IC. Use LED_0 for showing
102                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
103                                 {
104                                         // Blinking if scanning is on progress
105                                         if( pHwData->LED_Scanning )
106                                         {
107                                                 if( pHwData->LED_Blinking == 0 )
108                                                 {
109                                                         reg->U1BC_LEDConfigure |= 0x10;
110                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 On
111                                                         pHwData->LED_Blinking = 1;
112                                                         TimeInterval = 300;
113                                                 }
114                                                 else
115                                                 {
116                                                         reg->U1BC_LEDConfigure &= ~0x10;
117                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
118                                                         pHwData->LED_Blinking = 0;
119                                                         TimeInterval = 300;
120                                                 }
121                                         }
122                                         else
123                                         {
124                                                 //Turn Off LED_0
125                                                 if( reg->U1BC_LEDConfigure & 0x10 )
126                                                 {
127                                                         reg->U1BC_LEDConfigure &= ~0x10;
128                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
129                                                 }
130                                         }
131                                 }
132                                 else
133                                 {
134                                         // Turn On LED_0
135                                         if( (reg->U1BC_LEDConfigure & 0x10) == 0 )
136                                         {
137                                                 reg->U1BC_LEDConfigure |= 0x10;
138                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
139                                         }
140                                 }
141                                 break;
142
143                         case 6: // [110] Only 1 Led be placed on PCB and use pin 21 of IC. Use LED_0 for showing
144                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
145                                 {
146                                         // Blinking if scanning is on progress
147                                         if( pHwData->LED_Scanning )
148                                         {
149                                                 if( pHwData->LED_Blinking == 0 )
150                                                 {
151                                                         reg->U1BC_LEDConfigure &= ~0xf;
152                                                         reg->U1BC_LEDConfigure |= 0x10;
153                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 On
154                                                         pHwData->LED_Blinking = 1;
155                                                         TimeInterval = 300;
156                                                 }
157                                                 else
158                                                 {
159                                                         reg->U1BC_LEDConfigure &= ~0x1f;
160                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
161                                                         pHwData->LED_Blinking = 0;
162                                                         TimeInterval = 300;
163                                                 }
164                                         }
165                                         else
166                                         {
167                                                 // 20060901 Gray blinking if in disconnect state and not scanning
168                                                 ltmp = reg->U1BC_LEDConfigure;
169                                                 reg->U1BC_LEDConfigure &= ~0x1f;
170                                                 if( LEDgray2[(pHwData->LED_Blinking%30)] )
171                                                 {
172                                                         reg->U1BC_LEDConfigure |= 0x10;
173                                                         reg->U1BC_LEDConfigure |= LEDgray2[ (pHwData->LED_Blinking%30) ];
174                                                 }
175                                                 pHwData->LED_Blinking++;
176                                                 if( reg->U1BC_LEDConfigure != ltmp )
177                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
178                                                 TimeInterval = 100;
179                                         }
180                                 }
181                                 else
182                                 {
183                                         // Turn On LED_0
184                                         if( (reg->U1BC_LEDConfigure & 0x10) == 0 )
185                                         {
186                                                 reg->U1BC_LEDConfigure |= 0x10;
187                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
188                                         }
189                                 }
190                                 break;
191
192                         case 5: // [101] Only 1 Led be placed on PCB and use LED_1 for showing
193                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
194                                 {
195                                         // Blinking if scanning is on progress
196                                         if( pHwData->LED_Scanning )
197                                         {
198                                                 if( pHwData->LED_Blinking == 0 )
199                                                 {
200                                                         reg->U1BC_LEDConfigure |= 0x1000;
201                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
202                                                         pHwData->LED_Blinking = 1;
203                                                         TimeInterval = 300;
204                                                 }
205                                                 else
206                                                 {
207                                                         reg->U1BC_LEDConfigure &= ~0x1000;
208                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 Off
209                                                         pHwData->LED_Blinking = 0;
210                                                         TimeInterval = 300;
211                                                 }
212                                         }
213                                         else
214                                         {
215                                                 //Turn Off LED_1
216                                                 if( reg->U1BC_LEDConfigure & 0x1000 )
217                                                 {
218                                                         reg->U1BC_LEDConfigure &= ~0x1000;
219                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 Off
220                                                 }
221                                         }
222                                 }
223                                 else
224                                 {
225                                         // Is transmitting/receiving ??
226                                         if( (OS_CURRENT_RX_BYTE( adapter ) != pHwData->RxByteCountLast ) ||
227                                                 (OS_CURRENT_TX_BYTE( adapter ) != pHwData->TxByteCountLast ) )
228                                         {
229                                                 if( (reg->U1BC_LEDConfigure & 0x3000) != 0x3000 )
230                                                 {
231                                                         reg->U1BC_LEDConfigure |= 0x3000;
232                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
233                                                 }
234
235                                                 // Update variable
236                                                 pHwData->RxByteCountLast = OS_CURRENT_RX_BYTE( adapter );
237                                                 pHwData->TxByteCountLast = OS_CURRENT_TX_BYTE( adapter );
238                                                 TimeInterval = 200;
239                                         }
240                                         else
241                                         {
242                                                 // Turn On LED_1 and blinking if transmitting/receiving
243                                                  if( (reg->U1BC_LEDConfigure & 0x3000) != 0x1000 )
244                                                  {
245                                                          reg->U1BC_LEDConfigure &= ~0x3000;
246                                                          reg->U1BC_LEDConfigure |= 0x1000;
247                                                          Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
248                                                  }
249                                         }
250                                 }
251                                 break;
252
253                         default: // Default setting. 2 LED be placed on PCB. LED_0: Link On LED_1 Active
254                                 if( (reg->U1BC_LEDConfigure & 0x3000) != 0x3000 )
255                                 {
256                                         reg->U1BC_LEDConfigure |= 0x3000;// LED_1 is always on and event enable
257                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
258                                 }
259
260                                 if( pHwData->LED_Blinking )
261                                 {
262                                         // Gray blinking
263                                         reg->U1BC_LEDConfigure &= ~0x0f;
264                                         reg->U1BC_LEDConfigure |= 0x10;
265                                         reg->U1BC_LEDConfigure |= LEDgray[ (pHwData->LED_Blinking-1)%20 ];
266                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
267
268                                         pHwData->LED_Blinking += 2;
269                                         if( pHwData->LED_Blinking < 40 )
270                                                 TimeInterval = 100;
271                                         else
272                                         {
273                                                 pHwData->LED_Blinking = 0; // Stop blinking
274                                                 reg->U1BC_LEDConfigure &= ~0x0f;
275                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
276                                         }
277                                         break;
278                                 }
279
280                                 if( pHwData->LED_LinkOn )
281                                 {
282                                         if( !(reg->U1BC_LEDConfigure & 0x10) ) // Check the LED_0
283                                         {
284                                                 //Try to turn ON LED_0 after gray blinking
285                                                 reg->U1BC_LEDConfigure |= 0x10;
286                                                 pHwData->LED_Blinking = 1; //Start blinking
287                                                 TimeInterval = 50;
288                                         }
289                                 }
290                                 else
291                                 {
292                                         if( reg->U1BC_LEDConfigure & 0x10 ) // Check the LED_0
293                                         {
294                                                 reg->U1BC_LEDConfigure &= ~0x10;
295                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
296                                         }
297                                 }
298                                 break;
299                 }
300
301                 //20060828.1 Active send null packet to avoid AP disconnect
302                 if( pHwData->LED_LinkOn )
303                 {
304                         pHwData->NullPacketCount += TimeInterval;
305                         if( pHwData->NullPacketCount >= DEFAULT_NULL_PACKET_COUNT )
306                         {
307                                 pHwData->NullPacketCount = 0;
308                         }
309                 }
310         }
311
312         pHwData->time_count += TimeInterval;
313         Wb35Tx_CurrentTime(adapter, pHwData->time_count); // 20060928 add
314         pHwData->LEDTimer.expires = jiffies + msecs_to_jiffies(TimeInterval);
315         add_timer(&pHwData->LEDTimer);
316 }
317
318
319 u8 hal_init_hardware(phw_data_t pHwData, struct wb35_adapter * adapter)
320 {
321         u16 SoftwareSet;
322
323         // Initial the variable
324         pHwData->MaxReceiveLifeTime = DEFAULT_MSDU_LIFE_TIME; // Setting Rx maximum MSDU life time
325         pHwData->FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; // Setting default fragment threshold
326
327         pHwData->InitialResource = 1;
328         if( Wb35Reg_initial(pHwData)) {
329                 pHwData->InitialResource = 2;
330                 if (Wb35Tx_initial(pHwData)) {
331                         pHwData->InitialResource = 3;
332                         if (Wb35Rx_initial(pHwData)) {
333                                 pHwData->InitialResource = 4;
334                                 init_timer(&pHwData->LEDTimer);
335                                 pHwData->LEDTimer.function = hal_led_control;
336                                 pHwData->LEDTimer.data = (unsigned long) adapter;
337                                 pHwData->LEDTimer.expires = jiffies + msecs_to_jiffies(1000);
338                                 add_timer(&pHwData->LEDTimer);
339
340                                 //
341                                 // For restrict to vendor's hardware
342                                 //
343                                 SoftwareSet = hal_software_set( pHwData );
344
345                                 #ifdef Vendor2
346                                 // Try to make sure the EEPROM contain
347                                 SoftwareSet >>= 8;
348                                 if( SoftwareSet != 0x82 )
349                                         return false;
350                                 #endif
351
352                                 Wb35Rx_start( pHwData );
353                                 Wb35Tx_EP2VM_start(adapter);
354
355                                 return true;
356                         }
357                 }
358         }
359
360         pHwData->SurpriseRemove = 1;
361         return false;
362 }
363
364
365 void hal_halt(phw_data_t pHwData, void *ppa_data)
366 {
367         switch( pHwData->InitialResource )
368         {
369                 case 4:
370                 case 3: del_timer_sync(&pHwData->LEDTimer);
371                         msleep(100); // Wait for Timer DPC exit 940623.2
372                         Wb35Rx_destroy( pHwData ); // Release the Rx
373                 case 2: Wb35Tx_destroy( pHwData ); // Release the Tx
374                 case 1: Wb35Reg_destroy( pHwData ); // Release the Wb35 Regisster resources
375         }
376 }
377
378 //---------------------------------------------------------------------------------------------------
379 void hal_set_rates(phw_data_t pHwData, u8 *pbss_rates,
380                    u8 length, unsigned char basic_rate_set)
381 {
382         struct wb35_reg *reg = &pHwData->reg;
383         u32             tmp, tmp1;
384         u8              Rate[12]={ 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 };
385         u8              SupportedRate[16];
386         u8              i, j, k, Count1, Count2, Byte;
387
388         if( pHwData->SurpriseRemove ) return;
389
390         if (basic_rate_set) {
391                 reg->M28_MacControl &= ~0x000fff00;
392                 tmp1 = 0x00000100;
393         } else {
394                 reg->M28_MacControl &= ~0xfff00000;
395                 tmp1 = 0x00100000;
396         }
397
398         tmp = 0;
399         for (i=0; i<length; i++) {
400                 Byte = pbss_rates[i] & 0x7f;
401                 for (j=0; j<12; j++) {
402                         if( Byte == Rate[j] )
403                                 break;
404                 }
405
406                 if (j < 12)
407                         tmp |= (tmp1<<j);
408         }
409
410         reg->M28_MacControl |= tmp;
411         Wb35Reg_Write( pHwData, 0x0828, reg->M28_MacControl );
412
413         // 930206.2.c M78 setting
414         j = k = Count1 = Count2 = 0;
415         memset( SupportedRate, 0, 16 );
416         tmp = 0x00100000;
417         tmp1 = 0x00000100;
418         for (i=0; i<12; i++) { // Get the supported rate
419                 if (tmp & reg->M28_MacControl) {
420                         SupportedRate[j] = Rate[i];
421
422                         if (tmp1 & reg->M28_MacControl)
423                                 SupportedRate[j] |= 0x80;
424
425                         if (k)
426                                 Count2++;
427                         else
428                                 Count1++;
429
430                         j++;
431                 }
432
433                 if (i==4 && k==0) {
434                         if( !(reg->M28_MacControl & 0x000ff000) ) // if basic rate in 11g domain)
435                         {
436                                 k = 1;
437                                 j = 8;
438                         }
439                 }
440
441                 tmp <<= 1;
442                 tmp1 <<= 1;
443         }
444
445         // Fill data into support rate until buffer full
446         //---20060926 add by anson's endian
447         for (i=0; i<4; i++)
448                 *(u32 *)(SupportedRate+(i<<2)) = cpu_to_le32( *(u32 *)(SupportedRate+(i<<2)) );
449         //--- end 20060926 add by anson's endian
450         Wb35Reg_BurstWrite( pHwData,0x087c, (u32 *)SupportedRate, 4, AUTO_INCREMENT );
451         reg->M7C_MacControl = ((u32 *)SupportedRate)[0];
452         reg->M80_MacControl = ((u32 *)SupportedRate)[1];
453         reg->M84_MacControl = ((u32 *)SupportedRate)[2];
454         reg->M88_MacControl = ((u32 *)SupportedRate)[3];
455
456         // Fill length
457         tmp = Count1<<28 | Count2<<24;
458         reg->M78_ERPInformation &= ~0xff000000;
459         reg->M78_ERPInformation |= tmp;
460         Wb35Reg_Write( pHwData, 0x0878, reg->M78_ERPInformation );
461 }
462
463
464 //---------------------------------------------------------------------------------------------------
465 void hal_set_beacon_period(  phw_data_t pHwData,  u16 beacon_period )
466 {
467         u32     tmp;
468
469         if( pHwData->SurpriseRemove ) return;
470
471         pHwData->BeaconPeriod = beacon_period;
472         tmp = pHwData->BeaconPeriod << 16;
473         tmp |= pHwData->ProbeDelay;
474         Wb35Reg_Write( pHwData, 0x0848, tmp );
475 }
476
477
478 void hal_set_current_channel_ex(  phw_data_t pHwData,  ChanInfo channel )
479 {
480         struct wb35_reg *reg = &pHwData->reg;
481
482         if( pHwData->SurpriseRemove )
483                 return;
484
485         printk("Going to channel: %d/%d\n", channel.band, channel.ChanNo);
486
487         RFSynthesizer_SwitchingChannel( pHwData, channel );// Switch channel
488         pHwData->Channel = channel.ChanNo;
489         pHwData->band = channel.band;
490         #ifdef _PE_STATE_DUMP_
491         WBDEBUG(("Set channel is %d, band =%d\n", pHwData->Channel, pHwData->band));
492         #endif
493         reg->M28_MacControl &= ~0xff; // Clean channel information field
494         reg->M28_MacControl |= channel.ChanNo;
495         Wb35Reg_WriteWithCallbackValue( pHwData, 0x0828, reg->M28_MacControl,
496                                         (s8 *)&channel, sizeof(ChanInfo));
497 }
498 //---------------------------------------------------------------------------------------------------
499 void hal_set_current_channel(  phw_data_t pHwData,  ChanInfo channel )
500 {
501         hal_set_current_channel_ex( pHwData, channel );
502 }
503 //---------------------------------------------------------------------------------------------------
504 void hal_get_current_channel(  phw_data_t pHwData,  ChanInfo *channel )
505 {
506         channel->ChanNo = pHwData->Channel;
507         channel->band = pHwData->band;
508 }
509 //---------------------------------------------------------------------------------------------------
510 void hal_set_accept_broadcast(  phw_data_t pHwData,  u8 enable )
511 {
512         struct wb35_reg *reg = &pHwData->reg;
513
514         if( pHwData->SurpriseRemove ) return;
515
516         reg->M00_MacControl &= ~0x02000000;//The HW value
517
518         if (enable)
519                 reg->M00_MacControl |= 0x02000000;//The HW value
520
521         Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
522 }
523
524 //for wep key error detection, we need to accept broadcast packets to be received temporary.
525 void hal_set_accept_promiscuous( phw_data_t pHwData,  u8 enable)
526 {
527         struct wb35_reg *reg = &pHwData->reg;
528
529         if (pHwData->SurpriseRemove) return;
530         if (enable) {
531                 reg->M00_MacControl |= 0x00400000;
532                 Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
533         } else {
534                 reg->M00_MacControl&=~0x00400000;
535                 Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
536         }
537 }
538
539 void hal_set_accept_multicast(  phw_data_t pHwData,  u8 enable )
540 {
541         struct wb35_reg *reg = &pHwData->reg;
542
543         if( pHwData->SurpriseRemove ) return;
544
545         reg->M00_MacControl &= ~0x01000000;//The HW value
546         if (enable)  reg->M00_MacControl |= 0x01000000;//The HW value
547         Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
548 }
549
550 void hal_set_accept_beacon(  phw_data_t pHwData,  u8 enable )
551 {
552         struct wb35_reg *reg = &pHwData->reg;
553
554         if( pHwData->SurpriseRemove ) return;
555
556         // 20040108 debug
557         if( !enable )//Due to SME and MLME are not suitable for 35
558                 return;
559
560         reg->M00_MacControl &= ~0x04000000;//The HW value
561         if( enable )
562                 reg->M00_MacControl |= 0x04000000;//The HW value
563
564         Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
565 }
566 //---------------------------------------------------------------------------------------------------
567 void hal_set_multicast_address( phw_data_t pHwData, u8 *address, u8 number )
568 {
569         struct wb35_reg *reg = &pHwData->reg;
570         u8              Byte, Bit;
571
572         if( pHwData->SurpriseRemove ) return;
573
574         //Erases and refills the card multicast registers. Used when an address
575         //    has been deleted and all bits must be recomputed.
576         reg->M04_MulticastAddress1 = 0;
577         reg->M08_MulticastAddress2 = 0;
578
579         while( number )
580         {
581                 number--;
582                 CardGetMulticastBit( (address+(number*ETH_LENGTH_OF_ADDRESS)), &Byte, &Bit);
583                 reg->Multicast[Byte] |= Bit;
584         }
585
586         // Updating register
587         Wb35Reg_BurstWrite( pHwData, 0x0804, (u32 *)reg->Multicast, 2, AUTO_INCREMENT );
588 }
589 //---------------------------------------------------------------------------------------------------
590 u8 hal_get_accept_beacon(  phw_data_t pHwData )
591 {
592         struct wb35_reg *reg = &pHwData->reg;
593
594         if( pHwData->SurpriseRemove ) return 0;
595
596         if( reg->M00_MacControl & 0x04000000 )
597                 return 1;
598         else
599                 return 0;
600 }
601
602 unsigned char hal_reset_hardware( phw_data_t pHwData, void* ppa )
603 {
604         // Not implement yet
605         return true;
606 }
607
608 void hal_stop(  phw_data_t pHwData )
609 {
610         struct wb35_reg *reg = &pHwData->reg;
611
612         pHwData->Wb35Rx.rx_halt = 1;
613         Wb35Rx_stop( pHwData );
614
615         pHwData->Wb35Tx.tx_halt = 1;
616         Wb35Tx_stop( pHwData );
617
618         reg->D00_DmaControl &= ~0xc0000000;//Tx Off, Rx Off
619         Wb35Reg_Write( pHwData, 0x0400, reg->D00_DmaControl );
620 }
621
622 unsigned char hal_idle(phw_data_t pHwData)
623 {
624         struct wb35_reg *reg = &pHwData->reg;
625         PWBUSB  pWbUsb = &pHwData->WbUsb;
626
627         if( !pHwData->SurpriseRemove && ( pWbUsb->DetectCount || reg->EP0vm_state!=VM_STOP ) )
628                 return false;
629
630         return true;
631 }
632 //---------------------------------------------------------------------------------------------------
633 void hal_set_cwmin(  phw_data_t pHwData,  u8    cwin_min )
634 {
635         struct wb35_reg *reg = &pHwData->reg;
636
637         if( pHwData->SurpriseRemove ) return;
638
639         pHwData->cwmin = cwin_min;
640         reg->M2C_MacControl &= ~0x7c00; //bit 10 ~ 14
641         reg->M2C_MacControl |= (pHwData->cwmin<<10);
642         Wb35Reg_Write( pHwData, 0x082c, reg->M2C_MacControl );
643 }
644
645 s32 hal_get_rssi(  phw_data_t pHwData,  u32 *HalRssiArry,  u8 Count )
646 {
647         struct wb35_reg *reg = &pHwData->reg;
648         R01_DESCRIPTOR  r01;
649         s32 ltmp = 0, tmp;
650         u8      i;
651
652         if( pHwData->SurpriseRemove ) return -200;
653         if( Count > MAX_ACC_RSSI_COUNT ) // Because the TS may use this funtion
654                 Count = MAX_ACC_RSSI_COUNT;
655
656         // RSSI = C1 + C2 * (agc_state[7:0] + offset_map(lna_state[1:0]))
657         // C1 = -195, C2 = 0.66 = 85/128
658         for (i=0; i<Count; i++)
659         {
660                 r01.value = HalRssiArry[i];
661                 tmp = ((( r01.R01_AGC_state + reg->LNAValue[r01.R01_LNA_state]) * 85 ) >>7 ) - 195;
662                 ltmp += tmp;
663         }
664         ltmp /= Count;
665         if( pHwData->phy_type == RF_AIROHA_2230 ) ltmp -= 5; // 10;
666         if( pHwData->phy_type == RF_AIROHA_2230S ) ltmp -= 5; // 10; 20060420 Add this
667
668         //if( ltmp < -200 ) ltmp = -200;
669         if( ltmp < -110 ) ltmp = -110;// 1.0.24.0 For NJRC
670
671         return ltmp;
672 }
673 //----------------------------------------------------------------------------------------------------
674 s32 hal_get_rssi_bss(struct wb35_adapter *adapter,  u16 idx,  u8 Count)
675 {
676         phw_data_t pHwData = &adapter->sHwData;
677         struct wb35_reg *reg = &pHwData->reg;
678         R01_DESCRIPTOR  r01;
679         s32 ltmp = 0, tmp;
680         u8      i, j;
681 //      u32 *HalRssiArry = psBSS(idx)->HalRssi;
682
683         if( pHwData->SurpriseRemove ) return -200;
684         if( Count > MAX_ACC_RSSI_COUNT ) // Because the TS may use this funtion
685                 Count = MAX_ACC_RSSI_COUNT;
686
687         // RSSI = C1 + C2 * (agc_state[7:0] + offset_map(lna_state[1:0]))
688         // C1 = -195, C2 = 0.66 = 85/128
689 #if 0
690         for (i=0; i<Count; i++)
691         {
692                 r01.value = HalRssiArry[i];
693                 tmp = ((( r01.R01_AGC_state + reg->LNAValue[r01.R01_LNA_state]) * 85 ) >>7 ) - 195;
694                 ltmp += tmp;
695         }
696 #else
697         if (psBSS(idx)->HalRssiIndex == 0)
698                 psBSS(idx)->HalRssiIndex = MAX_ACC_RSSI_COUNT;
699         j = (u8)psBSS(idx)->HalRssiIndex-1;
700
701         for (i=0; i<Count; i++)
702         {
703                 r01.value = psBSS(idx)->HalRssi[j];
704                 tmp = ((( r01.R01_AGC_state + reg->LNAValue[r01.R01_LNA_state]) * 85 ) >>7 ) - 195;
705                 ltmp += tmp;
706                 if (j == 0)
707                 {
708                         j = MAX_ACC_RSSI_COUNT;
709                 }
710                 j--;
711         }
712 #endif
713         ltmp /= Count;
714         if( pHwData->phy_type == RF_AIROHA_2230 ) ltmp -= 5; // 10;
715         if( pHwData->phy_type == RF_AIROHA_2230S ) ltmp -= 5; // 10; 20060420 Add this
716
717         //if( ltmp < -200 ) ltmp = -200;
718         if( ltmp < -110 ) ltmp = -110;// 1.0.24.0 For NJRC
719
720         return ltmp;
721 }
722
723 //---------------------------------------------------------------------------
724
725 void hal_set_phy_type(  phw_data_t pHwData,  u8 PhyType )
726 {
727         pHwData->phy_type = PhyType;
728 }
729
730 void hal_get_phy_type(  phw_data_t pHwData,  u8 *PhyType )
731 {
732         *PhyType = pHwData->phy_type;
733 }
734
735 void hal_reset_counter(  phw_data_t pHwData )
736 {
737         pHwData->dto_tx_retry_count = 0;
738         pHwData->dto_tx_frag_count = 0;
739         memset( pHwData->tx_retry_count, 0, 8);
740 }
741
742 void hal_set_radio_mode( phw_data_t pHwData,  unsigned char radio_off)
743 {
744         struct wb35_reg *reg = &pHwData->reg;
745
746         if( pHwData->SurpriseRemove ) return;
747
748         if (radio_off)  //disable Baseband receive off
749         {
750                 pHwData->CurrentRadioSw = 1; // off
751                 reg->M24_MacControl &= 0xffffffbf;
752         }
753         else
754         {
755                 pHwData->CurrentRadioSw = 0; // on
756                 reg->M24_MacControl |= 0x00000040;
757         }
758         Wb35Reg_Write( pHwData, 0x0824, reg->M24_MacControl );
759 }
760
761 u8 hal_get_antenna_number(  phw_data_t pHwData )
762 {
763         struct wb35_reg *reg = &pHwData->reg;
764
765         if ((reg->BB2C & BIT(11)) == 0)
766                 return 0;
767         else
768                 return 1;
769 }
770
771 void hal_set_antenna_number(  phw_data_t pHwData, u8 number )
772 {
773
774         struct wb35_reg *reg = &pHwData->reg;
775
776         if (number == 1) {
777                 reg->BB2C |= BIT(11);
778         } else {
779                 reg->BB2C &= ~BIT(11);
780         }
781         Wb35Reg_Write( pHwData, 0x102c, reg->BB2C );
782 #ifdef _PE_STATE_DUMP_
783         WBDEBUG(("Current antenna number : %d\n", number));
784 #endif
785 }
786
787 //----------------------------------------------------------------------------------------------------
788 //0 : radio on; 1: radio off
789 u8 hal_get_hw_radio_off(  phw_data_t pHwData )
790 {
791         struct wb35_reg *reg = &pHwData->reg;
792
793         if( pHwData->SurpriseRemove ) return 1;
794
795         //read the bit16 of register U1B0
796         Wb35Reg_Read( pHwData, 0x3b0, &reg->U1B0 );
797         if ((reg->U1B0 & 0x00010000)) {
798                 pHwData->CurrentRadioHw = 1;
799                 return 1;
800         } else {
801                 pHwData->CurrentRadioHw = 0;
802                 return 0;
803         }
804 }
805
806 unsigned char hal_get_dxx_reg(  phw_data_t pHwData,  u16 number,  u32 * pValue )
807 {
808         if( number < 0x1000 )
809                 number += 0x1000;
810         return Wb35Reg_ReadSync( pHwData, number, pValue );
811 }
812
813 unsigned char hal_set_dxx_reg(  phw_data_t pHwData,  u16 number,  u32 value )
814 {
815         unsigned char   ret;
816
817         if( number < 0x1000 )
818                 number += 0x1000;
819         ret = Wb35Reg_WriteSync( pHwData, number, value );
820         return ret;
821 }
822
823 void hal_scan_status_indicate(phw_data_t pHwData, unsigned char IsOnProgress)
824 {
825         if( pHwData->SurpriseRemove ) return;
826         pHwData->LED_Scanning = IsOnProgress ? 1 : 0;
827 }
828
829 void hal_system_power_change(phw_data_t pHwData, u32 PowerState)
830 {
831         if( PowerState != 0 )
832         {
833                 pHwData->SurpriseRemove = 1;
834                 if( pHwData->WbUsb.IsUsb20 )
835                         hal_stop( pHwData );
836         }
837         else
838         {
839                 if( !pHwData->WbUsb.IsUsb20 )
840                         hal_stop( pHwData );
841         }
842 }
843
844 void hal_surprise_remove(struct wb35_adapter *adapter)
845 {
846         phw_data_t pHwData = &adapter->sHwData;
847
848         if (atomic_inc_return( &pHwData->SurpriseRemoveCount ) == 1) {
849                 #ifdef _PE_STATE_DUMP_
850                 WBDEBUG(("Calling hal_surprise_remove\n"));
851                 #endif
852                 OS_STOP( adapter );
853         }
854 }
855
856 void hal_rate_change(struct wb35_adapter *adapter) // Notify the HAL rate is changing 20060613.1
857 {
858         phw_data_t pHwData = &adapter->sHwData;
859         u8              rate = CURRENT_TX_RATE;
860
861         BBProcessor_RateChanging( pHwData, rate );
862 }
863
864 void hal_set_rf_power(phw_data_t pHwData, u8 PowerIndex)
865 {
866         RFSynthesizer_SetPowerIndex( pHwData, PowerIndex );
867 }
868
869 unsigned char hal_set_LED(phw_data_t pHwData, u32 Mode) // 20061108 for WPS led control
870 {
871         pHwData->LED_Blinking = 0;
872         pHwData->LED_control = Mode;
873         pHwData->LEDTimer.expires = jiffies + msecs_to_jiffies(10);
874         add_timer(&pHwData->LEDTimer);
875         return true;
876 }
877