]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/bcm/Bcmchar.c
staging/bcm: add sparse annotations
[mv-sheeva.git] / drivers / staging / bcm / Bcmchar.c
1 #include <linux/fs.h>
2
3 #include "headers.h"
4 /***************************************************************
5 * Function        - bcm_char_open()
6 *
7 * Description - This is the "open" entry point for the character
8 *                               driver.
9 *
10 * Parameters  - inode: Pointer to the Inode structure of char device
11 *                               filp : File pointer of the char device
12 *
13 * Returns         - Zero(Success)
14 ****************************************************************/
15 static struct class *bcm_class = NULL;
16 static int bcm_char_open(struct inode *inode, struct file * filp)
17 {
18         PMINI_ADAPTER           Adapter = NULL;
19     PPER_TARANG_DATA    pTarang = NULL;
20
21         Adapter = GET_BCM_ADAPTER(gblpnetdev);
22     pTarang = (PPER_TARANG_DATA)kmalloc(sizeof(PER_TARANG_DATA), GFP_KERNEL);
23     if (!pTarang)
24         return -ENOMEM;
25
26         memset (pTarang, 0, sizeof(PER_TARANG_DATA));
27     pTarang->Adapter = Adapter;
28         pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB) ;
29
30         down(&Adapter->RxAppControlQueuelock);
31     pTarang->next = Adapter->pTarangs;
32     Adapter->pTarangs = pTarang;
33         up(&Adapter->RxAppControlQueuelock);
34
35         /* Store the Adapter structure */
36         filp->private_data = pTarang;
37
38         /*Start Queuing the control response Packets*/
39         atomic_inc(&Adapter->ApplicationRunning);
40
41         nonseekable_open(inode, filp);
42         return 0;
43 }
44 static int bcm_char_release(struct inode *inode, struct file *filp)
45 {
46     PPER_TARANG_DATA pTarang, tmp, ptmp;
47         PMINI_ADAPTER Adapter=NULL;
48     struct sk_buff * pkt, * npkt;
49
50     pTarang = (PPER_TARANG_DATA)filp->private_data;
51
52     if(pTarang == NULL)
53         {
54         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "ptarang is null\n");
55         return 0;
56         }
57
58         Adapter = pTarang->Adapter;
59
60     down( &Adapter->RxAppControlQueuelock);
61
62     tmp = Adapter->pTarangs;
63     for ( ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next )
64         {
65         if ( tmp == pTarang )
66                         break;
67         }
68
69     if ( tmp )
70         {
71         if ( !ptmp )
72             Adapter->pTarangs = tmp->next;
73         else
74             ptmp->next = tmp->next;
75         }
76
77     else
78         {
79         up( &Adapter->RxAppControlQueuelock);
80         return 0;
81         }
82
83     pkt = pTarang->RxAppControlHead;
84     while ( pkt )
85         {
86         npkt = pkt->next;
87         kfree_skb(pkt);
88         pkt = npkt;
89         }
90
91     up( &Adapter->RxAppControlQueuelock);
92
93     /*Stop Queuing the control response Packets*/
94     atomic_dec(&Adapter->ApplicationRunning);
95
96     bcm_kfree(pTarang);
97
98         /* remove this filp from the asynchronously notified filp's */
99     filp->private_data = NULL;
100     return 0;
101 }
102
103 static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
104 {
105     PPER_TARANG_DATA pTarang = (PPER_TARANG_DATA)filp->private_data;
106         PMINI_ADAPTER   Adapter = pTarang->Adapter;
107     struct sk_buff* Packet = NULL;
108     UINT            PktLen = 0;
109         int                     wait_ret_val=0;
110
111         wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
112                 (pTarang->RxAppControlHead || Adapter->device_removed));
113         if((wait_ret_val == -ERESTARTSYS))
114         {
115                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Exiting as i've been asked to exit!!!\n");
116                 return wait_ret_val;
117         }
118
119         if(Adapter->device_removed)
120         {
121                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device Removed... Killing the Apps...\n");
122                 return -ENODEV;
123         }
124
125         if(FALSE == Adapter->fw_download_done)
126                 return -EACCES;
127
128     down( &Adapter->RxAppControlQueuelock);
129
130         if(pTarang->RxAppControlHead)
131         {
132                 Packet = pTarang->RxAppControlHead;
133                 DEQUEUEPACKET(pTarang->RxAppControlHead,pTarang->RxAppControlTail);
134                 pTarang->AppCtrlQueueLen--;
135         }
136
137     up(&Adapter->RxAppControlQueuelock);
138
139         if(Packet)
140         {
141                 PktLen = Packet->len;
142                 if(copy_to_user(buf, Packet->data, PktLen))
143                 {
144                         bcm_kfree_skb(Packet);
145                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\nReturning from copy to user failure \n");
146                         return -EFAULT;
147                 }
148                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read %d Bytes From Adapter packet = 0x%p by process %d!\n", PktLen, Packet, current->pid);
149                 bcm_kfree_skb(Packet);
150         }
151
152     BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<====\n");
153     return PktLen;
154 }
155
156 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
157 {
158     PPER_TARANG_DATA  pTarang = (PPER_TARANG_DATA)filp->private_data;
159         void __user *argp = (void __user *)argp;
160         PMINI_ADAPTER   Adapter = pTarang->Adapter;
161         INT                     Status = STATUS_FAILURE;
162         IOCTL_BUFFER    IoBuffer={};
163 #ifndef BCM_SHM_INTERFACE
164     int timeout = 0;
165 #endif
166
167
168         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg);
169
170         if(_IOC_TYPE(cmd) != BCM_IOCTL)
171                 return -EFAULT;
172         if(_IOC_DIR(cmd) & _IOC_READ)
173                 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
174         else if (_IOC_DIR(cmd) & _IOC_WRITE)
175             Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
176         else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
177             Status = STATUS_SUCCESS;
178
179         if(Status)
180                 return -EFAULT;
181
182         if(Adapter->device_removed)
183         {
184                 return -EFAULT;
185         }
186
187         if(FALSE == Adapter->fw_download_done)
188         {
189                 switch (cmd)
190                 {
191                         case IOCTL_MAC_ADDR_REQ:
192                         case IOCTL_LINK_REQ:
193                         case IOCTL_CM_REQUEST:
194                         case IOCTL_SS_INFO_REQ:
195                         case IOCTL_SEND_CONTROL_MESSAGE:
196                         case IOCTL_IDLE_REQ:
197                         case IOCTL_BCM_GPIO_SET_REQUEST:
198                         case IOCTL_BCM_GPIO_STATUS_REQUEST:
199                                 return -EACCES;
200                         default:
201                                 break;
202                 }
203         }
204
205         Status = vendorextnIoctl(Adapter, cmd, arg);
206         if(Status != CONTINUE_COMMON_PATH )
207         {
208                  return Status;
209         }
210
211         switch(cmd){
212                 // Rdms for Swin Idle...
213                 case IOCTL_BCM_REGISTER_READ_PRIVATE:
214                 {
215                         RDM_BUFFER  sRdmBuffer = {0};
216                         PCHAR temp_buff = NULL;
217                         UINT Bufflen = 0;
218                         /* Copy Ioctl Buffer structure */
219                         if(copy_from_user((PCHAR)&IoBuffer, argp,
220                                 sizeof(IOCTL_BUFFER)))
221                         {
222                                 Status = -EFAULT;
223                                 break;
224                         }
225
226                         Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
227                         temp_buff = (PCHAR)kmalloc(Bufflen, GFP_KERNEL);
228                         if(!temp_buff)
229                         {
230                                 return STATUS_FAILURE;
231                         }
232                         if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
233                                 IoBuffer.InputLength))
234                         {
235                                 Status = -EFAULT;
236                                 break;
237                         }
238                         Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
239                                         (PUINT)temp_buff, Bufflen);
240                         if(Status != STATUS_SUCCESS)
241                         {
242                                 bcm_kfree(temp_buff);
243                                 return Status;
244                         }
245                         if(copy_to_user(IoBuffer.OutputBuffer,
246                                 (PCHAR)temp_buff, (UINT)IoBuffer.OutputLength))
247                         {
248                                 Status = -EFAULT;
249                         }
250                         bcm_kfree(temp_buff);
251                         break;
252                 }
253                 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
254                 {
255                         WRM_BUFFER  sWrmBuffer = {0};
256                         UINT uiTempVar=0;
257                         /* Copy Ioctl Buffer structure */
258
259                         if(copy_from_user(&IoBuffer, argp,
260                                 sizeof(IOCTL_BUFFER)))
261                         {
262                                 Status = -EFAULT;
263                                 break;
264                         }
265                         /* Get WrmBuffer structure */
266                         if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer,
267                                 IoBuffer.InputLength))
268                         {
269                                 Status = -EFAULT;
270                                 break;
271                         }
272                         uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
273                         if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
274                                 ((uiTempVar == EEPROM_REJECT_REG_1)||
275                                 (uiTempVar == EEPROM_REJECT_REG_2) ||
276                                 (uiTempVar == EEPROM_REJECT_REG_3) ||
277                                 (uiTempVar == EEPROM_REJECT_REG_4)))
278                         {
279                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
280                                 Status = -EFAULT;
281                                 break;
282                         }
283                         Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
284                                                 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
285                         if(Status == STATUS_SUCCESS)
286                         {
287                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"WRM Done\n");
288                         }
289                         else
290                         {
291                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
292                                 Status = -EFAULT;
293                         }
294                         break;
295                 }
296
297                 case IOCTL_BCM_REGISTER_READ:
298                 case IOCTL_BCM_EEPROM_REGISTER_READ:
299                 {
300                         RDM_BUFFER  sRdmBuffer = {0};
301                         PCHAR temp_buff = NULL;
302                         UINT uiTempVar = 0;
303                         if((Adapter->IdleMode == TRUE) ||
304                                 (Adapter->bShutStatus ==TRUE) ||
305                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
306                         {
307                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
308                                 Status = -EACCES;
309                                 break;
310                         }
311                         /* Copy Ioctl Buffer structure */
312                         if(copy_from_user(&IoBuffer, argp,
313                                 sizeof(IOCTL_BUFFER)))
314                         {
315                                 Status = -EFAULT;
316                                 break;
317                         }
318
319                         temp_buff = (PCHAR)kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
320                         if(!temp_buff)
321                         {
322                                 return STATUS_FAILURE;
323                         }
324                         if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
325                                 IoBuffer.InputLength))
326                         {
327                                 Status = -EFAULT;
328                                 break;
329                         }
330
331                         if(
332 #if !defined(BCM_SHM_INTERFACE)
333                                 (((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
334 #endif
335                                         ((ULONG)sRdmBuffer.Register & 0x3)
336                           )
337                         {
338                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
339                                         (int)sRdmBuffer.Register);
340                                 Status = -EINVAL;
341                                 break;
342                         }
343
344                         uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
345                         Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
346                                                 (PUINT)temp_buff, IoBuffer.OutputLength);
347                         if(Status != STATUS_SUCCESS)
348                         {
349                                 bcm_kfree(temp_buff);
350                                 return Status;
351                         }
352                         if(copy_to_user(IoBuffer.OutputBuffer,
353                                 (PCHAR)temp_buff, (UINT)IoBuffer.OutputLength))
354                         {
355                                 Status = -EFAULT;
356                         }
357                         bcm_kfree(temp_buff);
358                         break;
359                 }
360                 case IOCTL_BCM_REGISTER_WRITE:
361                 case IOCTL_BCM_EEPROM_REGISTER_WRITE:
362                 {
363                         WRM_BUFFER  sWrmBuffer = {0};
364                         UINT uiTempVar=0;
365                         if((Adapter->IdleMode == TRUE) ||
366                                 (Adapter->bShutStatus ==TRUE) ||
367                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
368                         {
369                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
370                                 Status = -EACCES;
371                                 break;
372                         }
373                         /* Copy Ioctl Buffer structure */
374                         if(copy_from_user((PCHAR)&IoBuffer, argp,
375                                         sizeof(IOCTL_BUFFER)))
376                         {
377                                 Status = -EFAULT;
378                                 break;
379                         }
380                         /* Get WrmBuffer structure */
381                         if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer,
382                                 IoBuffer.InputLength))
383                         {
384                                 Status = -EFAULT;
385                                 break;
386                         }
387                         if(
388 #if !defined(BCM_SHM_INTERFACE)
389
390                                 (((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
391 #endif
392                                         ((ULONG)sWrmBuffer.Register & 0x3)
393                          )
394                         {
395                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n",
396                                                 (int)sWrmBuffer.Register);
397                                 Status = -EINVAL;
398                                 break;
399                         }
400                         uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
401                         if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
402                                 ((uiTempVar == EEPROM_REJECT_REG_1)||
403                                 (uiTempVar == EEPROM_REJECT_REG_2) ||
404                                 (uiTempVar == EEPROM_REJECT_REG_3) ||
405                                 (uiTempVar == EEPROM_REJECT_REG_4)) &&
406                                 (cmd == IOCTL_BCM_REGISTER_WRITE))
407                         {
408                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
409                                 Status = -EFAULT;
410                                 break;
411                         }
412
413                         Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
414                                                         (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
415                         if(Status == STATUS_SUCCESS)
416                         {
417                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
418                         }
419                         else
420                         {
421                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
422                                 Status = -EFAULT;
423                         }
424                         break;
425                 }
426                 case IOCTL_BCM_GPIO_SET_REQUEST:
427                 {
428                         UCHAR ucResetValue[4];
429                         UINT value =0;
430                         UINT uiBit = 0;
431                 UINT uiOperation = 0;
432
433                         GPIO_INFO   gpio_info = {0};
434                         if((Adapter->IdleMode == TRUE) ||
435                                 (Adapter->bShutStatus ==TRUE) ||
436                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
437                         {
438                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
439                                 Status = -EACCES;
440                                 break;
441                         }
442                         if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
443                         {
444                                 Status = -EFAULT;
445                                 break;
446                     }
447                         if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
448                         {
449                                 Status = -EFAULT;
450                                 break;
451                         }
452                         uiBit  = gpio_info.uiGpioNumber;
453                         uiOperation = gpio_info.uiGpioValue;
454
455                         value= (1<<uiBit);
456
457                         if(IsReqGpioIsLedInNVM(Adapter,value) ==FALSE)
458                         {
459                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",value);
460                                 Status = -EINVAL;
461                                 break;
462                         }
463
464
465                         if(uiOperation)//Set - setting 1
466                         {
467                                 //Set the gpio output register
468                                 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_SET_REG ,
469                                                 (PUINT)(&value), sizeof(UINT));
470                                 if(Status == STATUS_SUCCESS)
471                                 {
472                     BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
473                                 }
474                     else
475                         {
476                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to set the %dth GPIO \n",uiBit);
477                         break;
478                 }
479                         }
480                         else//Unset - setting 0
481                         {
482                                 //Set the gpio output register
483                                 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_CLR_REG ,
484                                                 (PUINT)(&value), sizeof(UINT));
485                                 if(Status == STATUS_SUCCESS)
486                                 {
487                     BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO bit\n");
488                                 }
489                     else
490                         {
491                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to clear the %dth GPIO \n",uiBit);
492                         break;
493                 }
494                         }
495
496                         Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
497                                         (PUINT)ucResetValue, sizeof(UINT));
498                         if (STATUS_SUCCESS != Status)
499             {
500                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO_MODE_REGISTER read failed");
501                                 break;
502                         }
503                         //Set the gpio mode register to output
504                         *(UINT*)ucResetValue |= (1<<uiBit);
505                         Status = wrmaltWithLock(Adapter,GPIO_MODE_REGISTER ,
506                                         (PUINT)ucResetValue, sizeof(UINT));
507                         if(Status == STATUS_SUCCESS)
508                         {
509                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO to output Mode\n");
510                         }
511             else
512             {
513                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
514                 break;
515             }
516                 }
517                 break;
518                 case BCM_LED_THREAD_STATE_CHANGE_REQ:
519                 {
520
521                         USER_THREAD_REQ threadReq = {0};
522                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"User made LED thread InActive");
523
524                         if((Adapter->IdleMode == TRUE) ||
525                                 (Adapter->bShutStatus ==TRUE) ||
526                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
527                         {
528                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
529                                 Status = -EACCES;
530                                 break;
531                         }
532                         Status =copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
533                         if(Status)
534                         {
535                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
536                                 break;
537                         }
538
539                         Status= copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength);
540                         if(Status)
541                         {
542                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the InputBuffer from user space err:%d",Status);
543                                 break;
544                         }
545                         //if LED thread is running(Actively or Inactively) set it state to make inactive
546                         if(Adapter->LEDInfo.led_thread_running)
547                         {
548                                 if(threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ)
549                                 {
550                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Activating thread req");
551                                         Adapter->DriverState = LED_THREAD_ACTIVE;
552                                 }
553                                 else
554                                 {
555                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DeActivating Thread req.....");
556                                         Adapter->DriverState = LED_THREAD_INACTIVE;
557                                 }
558
559                                 //signal thread.
560                                 wake_up(&Adapter->LEDInfo.notify_led_event);
561
562                         }
563                 }
564                 break;
565                 case IOCTL_BCM_GPIO_STATUS_REQUEST:
566                 {
567                         ULONG uiBit = 0;
568                         UCHAR ucRead[4];
569                         GPIO_INFO   gpio_info = {0};
570                         if((Adapter->IdleMode == TRUE) ||
571                                 (Adapter->bShutStatus ==TRUE) ||
572                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
573                         {
574                                 Status = -EACCES;
575                                 break;
576                         }
577                         if(copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
578             {
579                 Status = -EFAULT;
580                     break;
581                 }
582                 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
583                 {
584                     Status = -EFAULT;
585                     break;
586                 }
587                 uiBit  = gpio_info.uiGpioNumber;
588                                   //Set the gpio output register
589                                 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
590                         (PUINT)ucRead, sizeof(UINT));
591                 if(Status != STATUS_SUCCESS)
592                 {
593                     BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
594                                         return Status;
595                 }
596
597                         }
598                         break;
599                         case IOCTL_BCM_GPIO_MULTI_REQUEST:
600                         {
601                                 UCHAR ucResetValue[4];
602                                 GPIO_MULTI_INFO gpio_multi_info[MAX_IDX];
603                                 PGPIO_MULTI_INFO pgpio_multi_info = (PGPIO_MULTI_INFO)gpio_multi_info;
604
605                                 memset( pgpio_multi_info, 0, MAX_IDX * sizeof( GPIO_MULTI_INFO));
606
607                                 if((Adapter->IdleMode == TRUE) ||
608                                 (Adapter->bShutStatus ==TRUE) ||
609                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
610                                 {
611                                         Status = -EINVAL;
612                                         break;
613                                 }
614                                 Status = copy_from_user( (PCHAR)&IoBuffer, argp, sizeof( IOCTL_BUFFER));
615                                 if(Status)
616                                 {
617                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
618                                         break;
619                                 }
620
621                                 Status = copy_from_user( &gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength);
622                                 if(Status)
623                                 {
624                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status);
625                                         break;
626                                 }
627                                 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_info[WIMAX_IDX].uiGPIOMask)== FALSE)
628                                 {
629                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_info[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap);
630                                         Status = -EINVAL;
631                                         break;
632                                 }
633
634                                 /* Set the gpio output register */
635
636                                 if( ( pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
637                                         ( pgpio_multi_info[WIMAX_IDX].uiGPIOCommand))
638                                 {
639                                         /* Set 1's in GPIO OUTPUT REGISTER */
640                                         *(UINT*) ucResetValue =  pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
641                                                                                  pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
642                                                                                          pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
643
644                                         if( *(UINT*) ucResetValue)
645                                                 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_SET_REG , (PUINT) ucResetValue, sizeof(ULONG));
646
647                                         if( Status != STATUS_SUCCESS)
648                                         {
649                                                 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
650                                                 return Status;
651                                         }
652
653                                         /* Clear to 0's in GPIO OUTPUT REGISTER */
654                                         *(UINT*) ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
655                                                         pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
656                                                         ( ~( pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
657
658                                         if( *(UINT*) ucResetValue)
659                                                 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_CLR_REG , (PUINT) ucResetValue, sizeof(ULONG));
660
661                                         if( Status != STATUS_SUCCESS)
662                                         {
663                                                 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_CLR_REG Failed." );
664                                                 return Status;
665                                         }
666                                 }
667
668                                 if( pgpio_multi_info[WIMAX_IDX].uiGPIOMask)
669                                 {
670                                         Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
671
672                                         if(Status != STATUS_SUCCESS)
673                                         {
674                                                 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"RDM to GPIO_PIN_STATE_REGISTER Failed.");
675                                                 return Status;
676                                         }
677
678                                         pgpio_multi_info[WIMAX_IDX].uiGPIOValue = ( *(UINT*)ucResetValue &
679                                                                                         pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
680                                 }
681
682                                 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
683                                 if(Status)
684                                 {
685                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
686                                         break;
687                                 }
688                         }
689                         break;
690                 case IOCTL_BCM_GPIO_MODE_REQUEST:
691                 {
692                         UCHAR ucResetValue[4];
693                         GPIO_MULTI_MODE gpio_multi_mode[MAX_IDX];
694                         PGPIO_MULTI_MODE pgpio_multi_mode = ( PGPIO_MULTI_MODE) gpio_multi_mode;
695
696                         if((Adapter->IdleMode == TRUE) ||
697                                 (Adapter->bShutStatus ==TRUE) ||
698                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
699                         {
700                                         Status = -EINVAL;
701                                         break;
702                         }
703                         Status = copy_from_user(&IoBuffer, argp, sizeof( IOCTL_BUFFER));
704                         if(Status)
705                         {
706                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
707                                 break;
708                         }
709
710                         Status = copy_from_user( &gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength);
711                         if(Status)
712                         {
713                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status);
714                                 break;
715                         }
716
717                         Status = rdmaltWithLock( Adapter, ( UINT) GPIO_MODE_REGISTER, ( PUINT) ucResetValue, sizeof( UINT));
718                         if( STATUS_SUCCESS != Status)
719                         {
720                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Read of GPIO_MODE_REGISTER failed");
721                                 return Status;
722                         }
723
724                         //Validating the request
725                         if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)== FALSE)
726                         {
727                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_mode[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap);
728                                 Status = -EINVAL;
729                                 break;
730                         }
731
732                         if( pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)
733                         {
734                                 /* write all OUT's (1's) */
735                                 *( UINT*) ucResetValue |= ( pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
736                                                                 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
737                                 /* write all IN's (0's) */
738                                 *( UINT*) ucResetValue &= ~( ( ~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
739                                                                 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
740
741                                 /* Currently implemented return the modes of all GPIO's
742                                  * else needs to bit AND with  mask
743                                  * */
744                                 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT*)ucResetValue;
745
746                                 Status = wrmaltWithLock( Adapter, GPIO_MODE_REGISTER , ( PUINT) ucResetValue, sizeof( ULONG));
747                                 if( Status == STATUS_SUCCESS)
748                                 {
749                                         BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM to GPIO_MODE_REGISTER Done");
750                                 }
751                                 else
752                                 {
753                                         BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to GPIO_MODE_REGISTER Failed");
754                                         Status = -EFAULT;
755                                         break;
756                                 }
757                         }
758                         else /* if uiGPIOMask is 0 then return mode register configuration */
759                         {
760                                 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *( UINT*) ucResetValue;
761                         }
762                         Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
763                         if(Status)
764                         {
765                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
766                                 break;
767                         }
768                 }
769                 break;
770
771                 case IOCTL_MAC_ADDR_REQ:
772                 case IOCTL_LINK_REQ:
773                 case IOCTL_CM_REQUEST:
774                 case IOCTL_SS_INFO_REQ:
775                 case IOCTL_SEND_CONTROL_MESSAGE:
776                 case IOCTL_IDLE_REQ:
777                 {
778                         PVOID pvBuffer=NULL;
779                         /* Copy Ioctl Buffer structure */
780                         if(copy_from_user(&IoBuffer, argp,
781                                                         sizeof(IOCTL_BUFFER)))
782                         {
783                                 Status = -EFAULT;
784                                 break;
785                         }
786                         pvBuffer=kmalloc(IoBuffer.InputLength, GFP_KERNEL);
787                         if(!pvBuffer)
788                         {
789                                 return -ENOMEM;
790                         }
791
792                         if(copy_from_user(pvBuffer, IoBuffer.InputBuffer,
793                                         IoBuffer.InputLength))
794                         {
795                                 Status = -EFAULT;
796                                 bcm_kfree(pvBuffer);
797                                 break;
798                         }
799
800                         down(&Adapter->LowPowerModeSync);
801                         Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
802                                                                                                         !Adapter->bPreparingForLowPowerMode,
803                                                                                                         (1 * HZ));
804                         if(Status == -ERESTARTSYS)
805                                         goto cntrlEnd;
806
807                         if(Adapter->bPreparingForLowPowerMode)
808                         {
809                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Preparing Idle Mode is still True - Hence Rejecting control message\n");
810                                 Status = STATUS_FAILURE ;
811                                 goto cntrlEnd ;
812                         }
813                         Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
814                 cntrlEnd:
815                         up(&Adapter->LowPowerModeSync);
816                         bcm_kfree(pvBuffer);
817                         break;
818                 }
819 #ifndef BCM_SHM_INTERFACE
820                 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
821                 {
822                         INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock) ;
823                         if(NVMAccess)
824                         {
825                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
826                                 return -EACCES;
827                         }
828                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
829                     if(!down_trylock(&Adapter->fw_download_sema))
830                         {
831                                 Adapter->bBinDownloaded=FALSE;
832                                 Adapter->fw_download_process_pid=current->pid;
833                                 Adapter->bCfgDownloaded=FALSE;
834                                 Adapter->fw_download_done=FALSE;
835                                 netif_carrier_off(Adapter->dev);
836                                 netif_stop_queue(Adapter->dev);
837                                 Status = reset_card_proc(Adapter);
838                                 if(Status)
839                                 {
840                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "reset_card_proc Failed!\n");
841                                         up(&Adapter->fw_download_sema);
842                                         up(&Adapter->NVMRdmWrmLock);
843                                         break;
844                                 }
845                                 mdelay(10);
846                         }
847                         else
848                         {
849
850                                 Status = -EBUSY;
851
852                         }
853                         up(&Adapter->NVMRdmWrmLock);
854                         break;
855                 }
856                 case IOCTL_BCM_BUFFER_DOWNLOAD:
857                         {
858                                 FIRMWARE_INFO   *psFwInfo=NULL;
859                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
860                         do{
861                                 if(!down_trylock(&Adapter->fw_download_sema))
862                                 {
863                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid way to download buffer. Use Start and then call this!!!\n");
864                                         Status=-EINVAL;
865                                         break;
866                                 }
867                                 /* Copy Ioctl Buffer structure */
868                                 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
869                                 {
870                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
871                                         Status = -EFAULT;
872                                         break;
873                                 }
874                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length for FW DLD is : %lx\n",
875                                                                                 IoBuffer.InputLength);
876                                 psFwInfo=kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
877                                 if(!psFwInfo)
878                                 {
879                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Failed to allocate buffer!!!!\n");
880                                         Status = -ENOMEM;
881                                         break;
882                                 }
883                                 if(copy_from_user(psFwInfo, IoBuffer.InputBuffer,
884                                                         IoBuffer.InputLength))
885                                 {
886                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_from_user 2 failed\n");
887                                         Status = -EFAULT;
888                                         break;
889                                 }
890
891                                 if(!psFwInfo->pvMappedFirmwareAddress ||
892                                                 (psFwInfo->u32FirmwareLength == 0))
893                                 {
894                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
895                                         psFwInfo->u32FirmwareLength);
896                                         Status = -EINVAL;
897                                         break;
898                                 }
899                                 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
900                                 if(Status != STATUS_SUCCESS)
901                                 {
902                                         if(psFwInfo->u32StartingAddress==CONFIG_BEGIN_ADDR)
903                                         {
904                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
905                                         }
906                                         else
907                                         {
908                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
909                                         }
910                                         //up(&Adapter->fw_download_sema);
911
912                                         if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
913                                         {
914                                                 Adapter->DriverState = DRIVER_INIT;
915                                                 Adapter->LEDInfo.bLedInitDone = FALSE;
916                                                 wake_up(&Adapter->LEDInfo.notify_led_event);
917                                         }
918                                 }
919                                 break ;
920                           }while(0);
921
922                           if(Status != STATUS_SUCCESS)
923                                         up(&Adapter->fw_download_sema);
924                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
925                                 bcm_kfree(psFwInfo);
926                                 break;
927                         }
928                 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
929                 {
930                         INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
931                         if(NVMAccess)
932                         {
933                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " FW download blocked as EEPROM Read/Write is in progress\n");
934                                 up(&Adapter->fw_download_sema);
935                                 return -EACCES;
936                         }
937                         if(down_trylock(&Adapter->fw_download_sema))
938                         {
939                                 Adapter->bBinDownloaded=TRUE;
940                                 Adapter->bCfgDownloaded=TRUE;
941                                 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
942                                 atomic_set(&Adapter->RxRollOverCount, 0);
943                                 Adapter->CurrNumRecvDescs=0;
944                                 Adapter->downloadDDR = 0;
945
946                                 //setting the Mips to Run
947                                 Status = run_card_proc(Adapter);
948                                 if(Status)
949                                 {
950                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
951                                         up(&Adapter->fw_download_sema);
952                                         up(&Adapter->NVMRdmWrmLock);
953                                         break;
954                                 }
955                                 else
956                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Firm Download Over...\n");
957                                 mdelay(10);
958                                 /* Wait for MailBox Interrupt */
959                                 if(StartInterruptUrb((PS_INTERFACE_ADAPTER)Adapter->pvInterfaceAdapter))
960                                 {
961                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
962                                 }
963                                 timeout = 5*HZ;
964                                 Adapter->waiting_to_fw_download_done = FALSE;
965                                 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
966                                         Adapter->waiting_to_fw_download_done, timeout);
967                                 Adapter->fw_download_process_pid=INVALID_PID;
968                                 Adapter->fw_download_done=TRUE;
969                                 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
970                                 Adapter->CurrNumRecvDescs = 0;
971                                 Adapter->PrevNumRecvDescs = 0;
972                                 atomic_set(&Adapter->cntrlpktCnt,0);
973                 Adapter->LinkUpStatus = 0;
974                 Adapter->LinkStatus = 0;
975
976                                 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
977                                 {
978                                         Adapter->DriverState = FW_DOWNLOAD_DONE;
979                                         wake_up(&Adapter->LEDInfo.notify_led_event);
980                                 }
981
982                                 if(!timeout)
983                                 {
984                                         Status = -ENODEV;
985                                 }
986                         }
987                         else
988                         {
989                                 Status = -EINVAL;
990                         }
991                         up(&Adapter->fw_download_sema);
992                         up(&Adapter->NVMRdmWrmLock);
993                         break;
994                 }
995 #endif
996                 case IOCTL_BE_BUCKET_SIZE:
997                         Adapter->BEBucketSize = *(PULONG)arg;
998                         Status = STATUS_SUCCESS;
999                         break;
1000
1001                 case IOCTL_RTPS_BUCKET_SIZE:
1002                         Adapter->rtPSBucketSize = *(PULONG)arg;
1003                         Status = STATUS_SUCCESS;
1004                         break;
1005                 case IOCTL_CHIP_RESET:
1006             {
1007                         INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1008                         if(NVMAccess)
1009                         {
1010                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
1011                                 return -EACCES;
1012                         }
1013                         down(&Adapter->RxAppControlQueuelock);
1014                         Status = reset_card_proc(Adapter);
1015                         flushAllAppQ();
1016                         up(&Adapter->RxAppControlQueuelock);
1017                         up(&Adapter->NVMRdmWrmLock);
1018                         ResetCounters(Adapter);
1019                         break;
1020                 }
1021                 case IOCTL_QOS_THRESHOLD:
1022                 {
1023                         USHORT uiLoopIndex;
1024                         for(uiLoopIndex = 0 ; uiLoopIndex < NO_OF_QUEUES ; uiLoopIndex++)
1025                         {
1026                                 Adapter->PackInfo[uiLoopIndex].uiThreshold = *(PULONG)arg;
1027                         }
1028                         Status = STATUS_SUCCESS;
1029                         break;
1030                 }
1031
1032                 case IOCTL_DUMP_PACKET_INFO:
1033
1034                         DumpPackInfo(Adapter);
1035                 DumpPhsRules(&Adapter->stBCMPhsContext);
1036                         Status = STATUS_SUCCESS;
1037                         break;
1038
1039                 case IOCTL_GET_PACK_INFO:
1040                         if(copy_to_user(argp, &Adapter->PackInfo,
1041                                 sizeof(PacketInfo)*NO_OF_QUEUES))
1042                         {
1043                                 Status = -EFAULT;
1044                                 break;
1045                         }
1046                         Status = STATUS_SUCCESS;
1047                         break;
1048                 case IOCTL_BCM_SWITCH_TRANSFER_MODE:
1049                 {
1050                         UINT uiData = 0;
1051                         if(copy_from_user(&uiData, argp, sizeof(UINT)))
1052                         {
1053                                 Status = -EFAULT;
1054                                 break;
1055                         }
1056                         if(uiData)      /* Allow All Packets */
1057                         {
1058                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
1059                                 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
1060                         }
1061                         else    /* Allow IP only Packets */
1062                         {
1063                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
1064                                 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
1065                         }
1066                         Status = STATUS_SUCCESS;
1067                         break;
1068                 }
1069
1070                 case IOCTL_BCM_GET_DRIVER_VERSION:
1071                 {
1072                         /* Copy Ioctl Buffer structure */
1073                         if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1074                         {
1075                                 Status = -EFAULT;
1076                                 break;
1077                         }
1078                         if(copy_to_user(IoBuffer.OutputBuffer,
1079                                 VER_FILEVERSION_STR, (UINT)IoBuffer.OutputLength))
1080                         {
1081                                 Status = -EFAULT;
1082                                 break;
1083                         }
1084                         Status = STATUS_SUCCESS;
1085                         break;
1086                 }
1087                 case IOCTL_BCM_GET_CURRENT_STATUS:
1088                 {
1089                         LINK_STATE *plink_state = NULL;
1090                         /* Copy Ioctl Buffer structure */
1091                         if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1092                         {
1093                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
1094                                 Status = -EFAULT;
1095                                 break;
1096                         }
1097                         plink_state = (LINK_STATE*)arg;
1098                         plink_state->bIdleMode = (UCHAR)Adapter->IdleMode;
1099                         plink_state->bShutdownMode = Adapter->bShutStatus;
1100                         plink_state->ucLinkStatus = (UCHAR)Adapter->LinkStatus;
1101                         if(copy_to_user(IoBuffer.OutputBuffer,
1102                                 (PUCHAR)plink_state, (UINT)IoBuffer.OutputLength))
1103                         {
1104                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1105                                 Status = -EFAULT;
1106                                 break;
1107                         }
1108                         Status = STATUS_SUCCESS;
1109                         break;
1110                 }
1111         case IOCTL_BCM_SET_MAC_TRACING:
1112         {
1113             UINT  tracing_flag;
1114             /* copy ioctl Buffer structure */
1115                         if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1116                         {
1117                                 Status = -EFAULT;
1118                                 break;
1119                         }
1120                         if(copy_from_user(&tracing_flag, IoBuffer.InputBuffer,sizeof(UINT)))
1121             {
1122                                 Status = -EFAULT;
1123                                 break;
1124                         }
1125             if (tracing_flag)
1126                 Adapter->pTarangs->MacTracingEnabled = TRUE;
1127             else
1128                 Adapter->pTarangs->MacTracingEnabled = FALSE;
1129             break;
1130         }
1131                 case IOCTL_BCM_GET_DSX_INDICATION:
1132                 {
1133                         ULONG ulSFId=0;
1134                         if(copy_from_user((PCHAR)&IoBuffer, argp,
1135                                         sizeof(IOCTL_BUFFER)))
1136                         {
1137                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid IO buffer!!!" );
1138                                 Status = -EFAULT;
1139                                 break;
1140                         }
1141                         if(IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt))
1142                         {
1143                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Mismatch req: %lx needed is =0x%zx!!!",
1144                                         IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
1145                                 return -EINVAL;
1146                         }
1147                         if(copy_from_user(&ulSFId, IoBuffer.InputBuffer,
1148                                         sizeof(ulSFId)))
1149                         {
1150                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Invalid SFID!!! %lu", ulSFId );
1151                                 Status = -EFAULT;
1152                                 break;
1153                         }
1154                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId );
1155                         get_dsx_sf_data_to_application(Adapter, ulSFId,
1156                                 IoBuffer.OutputBuffer);
1157                         Status=STATUS_SUCCESS;
1158                 }
1159                 break;
1160                 case IOCTL_BCM_GET_HOST_MIBS:
1161                 {
1162                         PCHAR temp_buff;
1163
1164                         if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1165                         {
1166                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_from user for IoBuff failed\n");
1167                                 Status = -EFAULT;
1168                                 break;
1169                         }
1170
1171                         if(IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS))
1172                         {
1173                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length Check failed %lu %zd\n", IoBuffer.OutputLength,
1174                                                                                         sizeof(S_MIBS_HOST_STATS_MIBS));
1175                         return -EINVAL;
1176                         }
1177
1178                         temp_buff = (PCHAR)kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
1179
1180                         if(!temp_buff)
1181                         {
1182                                 return STATUS_FAILURE;
1183                         }
1184
1185                         Status = ProcessGetHostMibs(Adapter,
1186                                         (PUCHAR)temp_buff, IoBuffer.OutputLength);
1187
1188                 Status = GetDroppedAppCntrlPktMibs((PVOID)temp_buff,
1189                                                                         (PPER_TARANG_DATA)filp->private_data);
1190
1191                         if(copy_to_user(IoBuffer.OutputBuffer,(PCHAR)temp_buff,
1192                                 sizeof(S_MIBS_HOST_STATS_MIBS)))
1193                         {
1194                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy to user failed\n");
1195                                 bcm_kfree(temp_buff);
1196                                 return -EFAULT;
1197                         }
1198
1199                         bcm_kfree(temp_buff);
1200                         break;
1201                 }
1202
1203                 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1204                         if((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE==Adapter->IdleMode))
1205                         {
1206                                 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1207                                 Adapter->bWakeUpDevice = TRUE;
1208                                 wake_up(&Adapter->process_rx_cntrlpkt);
1209                                 #if 0
1210                                 Adapter->bTriedToWakeUpFromlowPowerMode = TRUE;
1211                                 InterfaceAbortIdlemode (Adapter, Adapter->usIdleModePattern);
1212                                 #endif
1213                         }
1214                         Status = STATUS_SUCCESS;
1215                         break;
1216
1217                 case IOCTL_BCM_BULK_WRM:
1218                         {
1219                                 PBULKWRM_BUFFER pBulkBuffer;
1220                                 UINT uiTempVar=0;
1221                                 PCHAR pvBuffer = NULL;
1222
1223                                 if((Adapter->IdleMode == TRUE) ||
1224                                         (Adapter->bShutStatus ==TRUE) ||
1225                                         (Adapter->bPreparingForLowPowerMode ==TRUE))
1226                                 {
1227                     BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1228                                         Status = -EACCES;
1229                                         break;
1230                                 }
1231                                 /* Copy Ioctl Buffer structure */
1232                                 if(copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1233                                 {
1234                                         Status = -EFAULT;
1235                                         break;
1236                                 }
1237
1238                                 pvBuffer=kmalloc(IoBuffer.InputLength, GFP_KERNEL);
1239                                 if(!pvBuffer)
1240                                 {
1241                                         return -ENOMEM;
1242                                         break;
1243                                 }
1244
1245                                 /* Get WrmBuffer structure */
1246                 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
1247                                 {
1248                                         bcm_kfree(pvBuffer);
1249                                         Status = -EFAULT;
1250                                         break;
1251                                 }
1252
1253                                 pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
1254
1255                                 if(((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1256                                         ((ULONG)pBulkBuffer->Register & 0x3))
1257                                 {
1258                                         bcm_kfree(pvBuffer);
1259                     BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer->Register);
1260                                         Status = -EINVAL;
1261                                         break;
1262                                 }
1263
1264
1265                                 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1266                                 if(!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE)
1267                                 &&      ((uiTempVar == EEPROM_REJECT_REG_1)||
1268                                                 (uiTempVar == EEPROM_REJECT_REG_2) ||
1269                                         (uiTempVar == EEPROM_REJECT_REG_3) ||
1270                                         (uiTempVar == EEPROM_REJECT_REG_4)) &&
1271                                         (cmd == IOCTL_BCM_REGISTER_WRITE))
1272                                 {
1273                                         bcm_kfree(pvBuffer);
1274                     BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"EEPROM Access Denied, not in VSG Mode\n");
1275                                         Status = -EFAULT;
1276                                         break;
1277                                 }
1278
1279                                 if(pBulkBuffer->SwapEndian == FALSE)
1280                                         Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1281                                 else
1282                                         Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1283
1284                                 if(Status != STATUS_SUCCESS)
1285                                 {
1286                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1287                                 }
1288
1289                                 bcm_kfree(pvBuffer);
1290                                 break;
1291                         }
1292
1293                 case IOCTL_BCM_GET_NVM_SIZE:
1294                         {
1295
1296                         if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1297                         {
1298                                 //IOLog("failed NVM first");
1299                                 Status = -EFAULT;
1300                                 break;
1301                         }
1302                         if(Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH ) {
1303                                 if(copy_to_user(IoBuffer.OutputBuffer,
1304                                         (unsigned char *)&Adapter->uiNVMDSDSize, (UINT)sizeof(UINT)))
1305                                 {
1306                                                 Status = -EFAULT;
1307                                                 return Status;
1308                                 }
1309                         }
1310
1311                         Status = STATUS_SUCCESS ;
1312                         }
1313                         break;
1314
1315                 case IOCTL_BCM_CAL_INIT :
1316
1317                         {
1318                                 UINT uiSectorSize = 0 ;
1319                                 if(Adapter->eNVMType == NVM_FLASH)
1320                                 {
1321                                         Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1322                                         if(Status)
1323                                         {
1324                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy From User space failed. status :%d", Status);
1325                                                 return Status;
1326                                         }
1327                                         uiSectorSize = *((PUINT)(IoBuffer.InputBuffer)); /* FIXME: unchecked __user access */
1328                                         if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE))
1329                                         {
1330
1331                                                 Status = copy_to_user(IoBuffer.OutputBuffer,
1332                                                                         (unsigned char *)&Adapter->uiSectorSize ,
1333                                                                         (UINT)sizeof(UINT));
1334                                                 if(Status)
1335                                                 {
1336                                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Coping the sector size to use space failed. status:%d",Status);
1337                                                                 return Status;
1338                                                 }
1339                                         }
1340                                         else
1341                                         {
1342                                                 if(IsFlash2x(Adapter))
1343                                                 {
1344                                                         Status = copy_to_user(IoBuffer.OutputBuffer,
1345                                                                         (unsigned char *)&Adapter->uiSectorSize ,
1346                                                                         (UINT)sizeof(UINT));
1347                                                         if(Status)
1348                                                         {
1349                                                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Coping the sector size to use space failed. status:%d",Status);
1350                                                                         return Status;
1351                                                         }
1352
1353                                                 }
1354                                                 else
1355                                                 {
1356                                                         if((TRUE == Adapter->bShutStatus) ||
1357                                                            (TRUE == Adapter->IdleMode))
1358                                                         {
1359                                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle/Shutdown Mode\n");
1360                                                                 return -EACCES;
1361                                                         }
1362
1363                                                         Adapter->uiSectorSize = uiSectorSize ;
1364                                                         BcmUpdateSectorSize(Adapter,Adapter->uiSectorSize);
1365                                                 }
1366                                         }
1367                                         Status = STATUS_SUCCESS ;
1368                                 }
1369                                 else
1370                                 {
1371                                         Status = STATUS_FAILURE;
1372                                 }
1373                         }
1374                         break;
1375         case IOCTL_BCM_SET_DEBUG :
1376             {
1377                 USER_BCM_DBG_STATE sUserDebugState;
1378
1379 //                              BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG );
1380
1381                                 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1382                                 Status = copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1383                                 if(Status)
1384                                 {
1385                                         BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy from user failed\n");
1386                                         break;
1387                                 }
1388                                 Status = copy_from_user(&sUserDebugState,IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE));
1389                                 if(Status)
1390                                 {
1391                                         BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,  "Copy of IoBuffer.InputBuffer failed");
1392                                         return Status;
1393                                 }
1394
1395                                 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1396                                 sUserDebugState.OnOff, sUserDebugState.Type);
1397                                 //sUserDebugState.Subtype <<= 1;
1398                                 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1399                                 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1400
1401                                 // Update new 'DebugState' in the Adapter
1402                                 Adapter->stDebugState.type |= sUserDebugState.Type;
1403                                 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1404                                  * Valid indexes in 'subtype' array: 1,2,4,8
1405                                  * corresponding to valid Type values. Hence we can use the 'Type' field
1406                                  * as the index value, ignoring the array entries 0,3,5,6,7 !
1407                                  */
1408                                 if (sUserDebugState.OnOff)
1409                                         Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1410                                 else
1411                                         Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1412
1413                 BCM_SHOW_DEBUG_BITMAP(Adapter);
1414
1415                         }
1416                         break;
1417                 case IOCTL_BCM_NVM_READ:
1418                 case IOCTL_BCM_NVM_WRITE:
1419                         {
1420
1421                                 NVM_READWRITE  stNVMReadWrite = {};
1422                                 PUCHAR pReadData = NULL;
1423                                 void __user * pBuffertobeCopied = NULL;
1424                                 ULONG ulDSDMagicNumInUsrBuff = 0 ;
1425                                 struct timeval tv0, tv1;
1426                                 memset(&tv0,0,sizeof(struct timeval));
1427                                 memset(&tv1,0,sizeof(struct timeval));
1428                                 if((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0))
1429                                 {
1430                                         BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,"The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1431                                         Status = -EFAULT;
1432                                         break;
1433                                 }
1434
1435                                 if(IsFlash2x(Adapter))
1436                                 {
1437                                         if((Adapter->eActiveDSD != DSD0) &&
1438                                                 (Adapter->eActiveDSD != DSD1) &&
1439                                                 (Adapter->eActiveDSD != DSD2))
1440                                         {
1441                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"No DSD is active..hence NVM Command is blocked");
1442                                                 return STATUS_FAILURE ;
1443                                         }
1444                                 }
1445
1446                         /* Copy Ioctl Buffer structure */
1447
1448                                 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1449                                 {
1450                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copy_from_user failed\n");
1451                     Status = -EFAULT;
1452                                         break;
1453                                 }
1454                                 if(IOCTL_BCM_NVM_READ == cmd)
1455                                         pBuffertobeCopied = IoBuffer.OutputBuffer;
1456                                 else
1457                                         pBuffertobeCopied = IoBuffer.InputBuffer;
1458
1459                                 if(copy_from_user(&stNVMReadWrite, pBuffertobeCopied,sizeof(NVM_READWRITE)))
1460                                 {
1461                                         Status = -EFAULT;
1462                                         break;
1463                                 }
1464
1465                                 //
1466                                 // Deny the access if the offset crosses the cal area limit.
1467                                 //
1468                                 if((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) > Adapter->uiNVMDSDSize)
1469                                 {
1470                                 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset ,
1471 //                                                      stNVMReadWrite.uiNumBytes);
1472                                         Status = STATUS_FAILURE;
1473                                         break;
1474                                 }
1475
1476                                 pReadData =(PCHAR)kmalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
1477
1478                                 if(!pReadData)
1479                                         return -ENOMEM;
1480
1481                                 memset(pReadData,0,stNVMReadWrite.uiNumBytes);
1482
1483                                 if(copy_from_user(pReadData, stNVMReadWrite.pBuffer,
1484                                                         stNVMReadWrite.uiNumBytes))
1485                                 {
1486                                         Status = -EFAULT;
1487                                         bcm_kfree(pReadData);
1488                                         break;
1489                                 }
1490
1491                                 do_gettimeofday(&tv0);
1492                                 if(IOCTL_BCM_NVM_READ == cmd)
1493                                 {
1494                                         down(&Adapter->NVMRdmWrmLock);
1495
1496                                         if((Adapter->IdleMode == TRUE) ||
1497                                                 (Adapter->bShutStatus ==TRUE) ||
1498                                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
1499                                         {
1500                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1501                                                 up(&Adapter->NVMRdmWrmLock);
1502                                                 bcm_kfree(pReadData);
1503                                                 return -EACCES;
1504                                         }
1505
1506                                         Status = BeceemNVMRead(Adapter, (PUINT)pReadData,
1507                                                 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1508
1509                                         up(&Adapter->NVMRdmWrmLock);
1510
1511                                         if(Status != STATUS_SUCCESS)
1512                                                 {
1513                                                         bcm_kfree(pReadData);
1514                                                         return Status;
1515                                                 }
1516                                         if(copy_to_user(stNVMReadWrite.pBuffer,
1517                                                         pReadData, (UINT)stNVMReadWrite.uiNumBytes))
1518                                                 {
1519                                                         bcm_kfree(pReadData);
1520                                                         Status = -EFAULT;
1521                                                 }
1522                                 }
1523                                 else
1524                                 {
1525
1526                                         down(&Adapter->NVMRdmWrmLock);
1527
1528                                         if((Adapter->IdleMode == TRUE) ||
1529                                                 (Adapter->bShutStatus ==TRUE) ||
1530                                                 (Adapter->bPreparingForLowPowerMode ==TRUE))
1531                                         {
1532                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1533                                                 up(&Adapter->NVMRdmWrmLock);
1534                                                 bcm_kfree(pReadData);
1535                                                 return -EACCES;
1536                                         }
1537
1538                                         Adapter->bHeaderChangeAllowed = TRUE ;
1539                                         if(IsFlash2x(Adapter))
1540                                         {
1541                                                 /*
1542                                                         New Requirement:-
1543                                                         DSD section updation will be allowed in two case:-
1544                                                         1.  if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1545                                                         2.  if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1546                                                               corrupted then user space program first modify the DSD header with valid DSD sig so
1547                                                               that this as well as further write may be worthwhile.
1548
1549                                                          This restriction has been put assuming that if DSD sig is corrupted, DSD
1550                                                          data won't be considered valid.
1551
1552
1553                                                 */
1554                                                 Status = BcmFlash2xCorruptSig(Adapter,Adapter->eActiveDSD);
1555                                                 if(Status != STATUS_SUCCESS)
1556                                                 {
1557                                                         if(( (stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize ) ||
1558                                                                 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE))
1559                                                         {
1560                                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1561                                                                 up(&Adapter->NVMRdmWrmLock);
1562                                                                 bcm_kfree(pReadData);
1563                                                                 return Status;
1564                                                         }
1565
1566                                                         ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1567                                                         if(ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER)
1568                                                         {
1569                                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1570                                                                 up(&Adapter->NVMRdmWrmLock);
1571                                                                 bcm_kfree(pReadData);
1572                                                                 return Status;
1573                                                         }
1574                                                 }
1575                                         }
1576                                         Status = BeceemNVMWrite(Adapter, (PUINT )pReadData,
1577                                                                         stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1578                                         if(IsFlash2x(Adapter))
1579                                                 BcmFlash2xWriteSig(Adapter,Adapter->eActiveDSD);
1580
1581                                         Adapter->bHeaderChangeAllowed = FALSE ;
1582
1583                                         up(&Adapter->NVMRdmWrmLock);
1584
1585
1586                                         if(Status != STATUS_SUCCESS)
1587                                         {
1588                                                 bcm_kfree(pReadData);
1589                                                 return Status;
1590                                         }
1591                                 }
1592                                 do_gettimeofday(&tv1);
1593                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " timetaken by Write/read :%ld msec\n",(tv1.tv_sec - tv0.tv_sec)*1000 +(tv1.tv_usec - tv0.tv_usec)/1000);
1594
1595
1596                                 bcm_kfree(pReadData);
1597                                 Status = STATUS_SUCCESS;
1598                         }
1599                         break;
1600                 case IOCTL_BCM_FLASH2X_SECTION_READ :
1601                          {
1602
1603                                 FLASH2X_READWRITE sFlash2xRead = {0};
1604                                 PUCHAR pReadBuff = NULL ;
1605                                 UINT NOB = 0;
1606                                 UINT BuffSize = 0;
1607                                 UINT ReadBytes = 0;
1608                                 UINT ReadOffset = 0;
1609                                 char __user *OutPutBuff = NULL;
1610
1611                                 if(IsFlash2x(Adapter) != TRUE)
1612                                 {
1613                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1614                                         return -EINVAL;
1615                                 }
1616
1617                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1618                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1619                                 if(Status)
1620                                 {
1621                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1622                                         return Status ;
1623                                 }
1624
1625                                 //Reading FLASH 2.x READ structure
1626                                 Status = copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,sizeof(FLASH2X_READWRITE));
1627                                 if(Status)
1628                                 {
1629                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Input Buffer failed");
1630                                         return Status ;
1631                                 }
1632
1633
1634                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xRead.Section);
1635                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%x" ,sFlash2xRead.offset);
1636                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xRead.numOfBytes);
1637                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xRead.bVerify);
1638
1639                                 //This was internal to driver for raw read. now it has ben exposed to user space app.
1640                                 if(validateFlash2xReadWrite(Adapter,&sFlash2xRead) == FALSE)
1641                                         return STATUS_FAILURE ;
1642
1643                                 NOB = sFlash2xRead.numOfBytes;
1644                                 if(NOB > Adapter->uiSectorSize )
1645                                         BuffSize = Adapter->uiSectorSize;
1646                                 else
1647                                         BuffSize = NOB ;
1648
1649                                 ReadOffset = sFlash2xRead.offset ;
1650                                 OutPutBuff = IoBuffer.OutputBuffer;
1651
1652
1653                                 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1654                                 if(pReadBuff == NULL)
1655                                 {
1656                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1657                                         return -ENOMEM;
1658                                 }
1659                                 down(&Adapter->NVMRdmWrmLock);
1660
1661                                 if((Adapter->IdleMode == TRUE) ||
1662                                         (Adapter->bShutStatus ==TRUE) ||
1663                                         (Adapter->bPreparingForLowPowerMode ==TRUE))
1664                                 {
1665                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1666                                         up(&Adapter->NVMRdmWrmLock);
1667                                         bcm_kfree(pReadBuff);
1668                                         return -EACCES;
1669                                 }
1670
1671                                 while(NOB)
1672                                 {
1673
1674                                         if(NOB > Adapter->uiSectorSize )
1675                                                 ReadBytes = Adapter->uiSectorSize;
1676                                         else
1677                                                 ReadBytes = NOB;
1678
1679
1680                                         //Reading the data from Flash 2.x
1681
1682                                         Status = BcmFlash2xBulkRead(Adapter,(PUINT)pReadBuff,sFlash2xRead.Section,ReadOffset,ReadBytes);
1683                                         if(Status)
1684                                         {
1685                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Flash 2x read err with Status :%d", Status);
1686                                                 break ;
1687                                         }
1688
1689                                         BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes);
1690
1691                                         Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
1692                                         if(Status)
1693                                         {
1694                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Copy to use failed with status :%d", Status);
1695                                                 break;
1696                                         }
1697                                         NOB = NOB - ReadBytes;
1698                                         if(NOB)
1699                                         {
1700                                                 ReadOffset = ReadOffset + ReadBytes ;
1701                                                 OutPutBuff = OutPutBuff + ReadBytes ;
1702                                         }
1703
1704                                 }
1705                                 up(&Adapter->NVMRdmWrmLock);
1706                                 bcm_kfree(pReadBuff);
1707
1708                          }
1709                          break ;
1710                 case IOCTL_BCM_FLASH2X_SECTION_WRITE :
1711                          {
1712                                 FLASH2X_READWRITE sFlash2xWrite = {0};
1713                                 PUCHAR pWriteBuff = NULL;
1714                                 void __user *InputAddr = NULL;
1715                                 UINT NOB = 0;
1716                                 UINT BuffSize = 0;
1717                                 UINT WriteOffset = 0;
1718                                 UINT WriteBytes = 0;
1719
1720                                 if(IsFlash2x(Adapter) != TRUE)
1721                                 {
1722                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1723                                         return -EINVAL;
1724                                 }
1725
1726                                 //First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite
1727                                 Adapter->bAllDSDWriteAllow = FALSE;
1728
1729
1730                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1731                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1732                                 if(Status)
1733                                 {
1734                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1735                                         return Status;
1736                                 }
1737
1738                                 //Reading FLASH 2.x READ structure
1739                                 Status = copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE));
1740                                 if(Status)
1741                                 {
1742                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reading of output Buffer from IOCTL buffer fails");
1743                                         return Status;
1744                                 }
1745
1746                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite.Section);
1747                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite.offset);
1748                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite.numOfBytes);
1749                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite.bVerify);
1750                                 #if 0
1751                                 if((sFlash2xWrite.Section == ISO_IMAGE1) ||(sFlash2xWrite.Section == ISO_IMAGE2) ||
1752                                         (sFlash2xWrite.Section == DSD0) || (sFlash2xWrite.Section == DSD1) || (sFlash2xWrite.Section == DSD2))
1753                                 {
1754                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"ISO/DSD Image write is not allowed....  ");
1755                                         return STATUS_FAILURE ;
1756                                 }
1757                                 #endif
1758                                 if((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) &&
1759                                         (sFlash2xWrite.Section != VSA2) )
1760                                 {
1761                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Only VSA write is allowed");
1762                                         return -EINVAL;
1763                                 }
1764
1765                                 if(validateFlash2xReadWrite(Adapter,&sFlash2xWrite) == FALSE)
1766                                         return STATUS_FAILURE ;
1767
1768                                 InputAddr = sFlash2xWrite.pDataBuff;
1769                                 WriteOffset = sFlash2xWrite.offset ;
1770                                 NOB = sFlash2xWrite.numOfBytes;
1771
1772                                 if(NOB > Adapter->uiSectorSize )
1773                                         BuffSize = Adapter->uiSectorSize;
1774                                 else
1775                                         BuffSize = NOB ;
1776
1777                                 pWriteBuff = (PCHAR)kmalloc(BuffSize, GFP_KERNEL);
1778                                 if(pWriteBuff == NULL)
1779                                 {
1780                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1781                                         return -ENOMEM;
1782                                 }
1783
1784                                 //extracting the remainder of the given offset.
1785                                 WriteBytes = Adapter->uiSectorSize ;
1786                                 if(WriteOffset % Adapter->uiSectorSize)
1787                                         WriteBytes =Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1788                                 if(NOB < WriteBytes)
1789                                         WriteBytes = NOB;
1790
1791                                 down(&Adapter->NVMRdmWrmLock);
1792
1793                                 if((Adapter->IdleMode == TRUE) ||
1794                                         (Adapter->bShutStatus ==TRUE) ||
1795                                         (Adapter->bPreparingForLowPowerMode ==TRUE))
1796                                 {
1797                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1798                                         up(&Adapter->NVMRdmWrmLock);
1799                                         bcm_kfree(pWriteBuff);
1800                                         return -EACCES;
1801                                 }
1802
1803                                 BcmFlash2xCorruptSig(Adapter,sFlash2xWrite.Section);
1804                                 do
1805                                 {
1806                                         Status = copy_from_user(pWriteBuff,InputAddr,WriteBytes);
1807                                         if(Status)
1808                                         {
1809                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to user failed with status :%d", Status);
1810                                                 break ;
1811                                         }
1812                                         BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pWriteBuff,WriteBytes);
1813                                         //Writing the data from Flash 2.x
1814                                         Status = BcmFlash2xBulkWrite(Adapter,(PUINT)pWriteBuff,sFlash2xWrite.Section,WriteOffset,WriteBytes,sFlash2xWrite.bVerify);
1815
1816                                         if(Status)
1817                                         {
1818                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
1819                                                 break ;
1820                                         }
1821
1822                                         NOB = NOB - WriteBytes;
1823                                         if(NOB)
1824                                         {
1825                                                 WriteOffset = WriteOffset + WriteBytes ;
1826                                                 InputAddr = InputAddr + WriteBytes ;
1827                                                 if(NOB > Adapter->uiSectorSize )
1828                                                         WriteBytes = Adapter->uiSectorSize;
1829                                                 else
1830                                                         WriteBytes = NOB;
1831                                         }
1832
1833
1834                                 }       while(NOB > 0);
1835                                 BcmFlash2xWriteSig(Adapter,sFlash2xWrite.Section);
1836                                 up(&Adapter->NVMRdmWrmLock);
1837                                 bcm_kfree(pWriteBuff);
1838                          }
1839                          break ;
1840                 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP :
1841                          {
1842
1843                                 PFLASH2X_BITMAP psFlash2xBitMap = NULL ;
1844                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1845
1846                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1847                                 if(Status)
1848                                 {
1849                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1850                                         return Status;
1851                                 }
1852                                 if(IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
1853                                 {
1854                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Structure size mismatch Lib :0x%lx Driver :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH2X_BITMAP));
1855                                         break;
1856                                 }
1857
1858                                 psFlash2xBitMap = (PFLASH2X_BITMAP)kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
1859                                 if(psFlash2xBitMap == NULL)
1860                                 {
1861                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory is not available");
1862                                         return -ENOMEM ;
1863                                 }
1864                                 //Reading the Flash Sectio Bit map
1865                                 down(&Adapter->NVMRdmWrmLock);
1866
1867                                 if((Adapter->IdleMode == TRUE) ||
1868                                         (Adapter->bShutStatus ==TRUE) ||
1869                                         (Adapter->bPreparingForLowPowerMode ==TRUE))
1870                                 {
1871                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1872                                         up(&Adapter->NVMRdmWrmLock);
1873                                         bcm_kfree(psFlash2xBitMap);
1874                                         return -EACCES;
1875                                 }
1876
1877                                 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1878                                 up(&Adapter->NVMRdmWrmLock);
1879                                 Status = copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP));
1880                                 if(Status)
1881                                 {
1882                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash2x bitMap failed");
1883                                         bcm_kfree(psFlash2xBitMap);
1884                                         return Status;
1885                                 }
1886                                 bcm_kfree(psFlash2xBitMap);
1887                          }
1888                          break ;
1889                 case IOCTL_BCM_SET_ACTIVE_SECTION :
1890                          {
1891                                 FLASH2X_SECTION_VAL eFlash2xSectionVal = 0;
1892                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1893
1894                                 if(IsFlash2x(Adapter) != TRUE)
1895                                 {
1896                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1897                                         return -EINVAL;
1898                                 }
1899
1900                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1901                                 if(Status)
1902                                 {
1903                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1904                                         return Status;
1905                                 }
1906
1907                                 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
1908                                 if(Status)
1909                                 {
1910                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1911                                         return Status;
1912                                 }
1913
1914                                 down(&Adapter->NVMRdmWrmLock);
1915
1916                                 if((Adapter->IdleMode == TRUE) ||
1917                                         (Adapter->bShutStatus ==TRUE) ||
1918                                         (Adapter->bPreparingForLowPowerMode ==TRUE))
1919                                 {
1920                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1921                                         up(&Adapter->NVMRdmWrmLock);
1922                                         return -EACCES;
1923                                 }
1924
1925                                 Status = BcmSetActiveSection(Adapter,eFlash2xSectionVal);
1926                                 if(Status)
1927                                 {
1928                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed to make it's priority Highest. Status %d", Status);
1929                                 }
1930                                 up(&Adapter->NVMRdmWrmLock);
1931                         }
1932                         break ;
1933                 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION :
1934                          {
1935                                 //Right Now we are taking care of only DSD
1936                                 Adapter->bAllDSDWriteAllow = FALSE ;
1937                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1938
1939                                 #if 0
1940                                 SECTION_TYPE section = 0 ;
1941
1942
1943                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION Called");
1944                                 Status = copy_from_user((PCHAR)&IoBuffer, (PCHAR)arg, sizeof(IOCTL_BUFFER));
1945                                 if(Status)
1946                                 {
1947                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy of IOCTL BUFFER failed");
1948                                         return Status;
1949                                 }
1950                                 Status = copy_from_user((PCHAR)section,(PCHAR)&IoBuffer, sizeof(INT));
1951                                 if(Status)
1952                                 {
1953                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy of section type failed failed");
1954                                         return Status;
1955                                 }
1956                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", section);
1957                                 if(section == DSD)
1958                                         Adapter->ulFlashCalStart = Adapter->uiActiveDSDOffsetAtFwDld ;
1959                                 else
1960                                         Status = STATUS_FAILURE ;
1961                                 #endif
1962                                 Status = STATUS_SUCCESS ;
1963                          }
1964                          break ;
1965                 case IOCTL_BCM_COPY_SECTION :
1966                          {
1967                                 FLASH2X_COPY_SECTION sCopySectStrut = {0};
1968                                 Status = STATUS_SUCCESS;
1969                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION  Called");
1970
1971                                 Adapter->bAllDSDWriteAllow = FALSE ;
1972                                 if(IsFlash2x(Adapter) != TRUE)
1973                                 {
1974                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1975                                         return -EINVAL;
1976                                 }
1977
1978                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1979                                 if(Status)
1980                                 {
1981                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1982                                         return Status;
1983                                 }
1984
1985                                 Status = copy_from_user(&sCopySectStrut,IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
1986                                 if(Status)
1987                                 {
1988                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1989                                         return Status;
1990                                 }
1991                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1992                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1993                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1994                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1995
1996
1997                                 if(IsSectionExistInFlash(Adapter,sCopySectStrut.SrcSection) == FALSE)
1998                                 {
1999                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
2000                                         return -EINVAL;
2001                                 }
2002
2003                                 if(IsSectionExistInFlash(Adapter,sCopySectStrut.DstSection) == FALSE)
2004                                 {
2005                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
2006                                         return -EINVAL;
2007                                 }
2008
2009                                 if(sCopySectStrut.SrcSection == sCopySectStrut.DstSection)
2010                                 {
2011                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Source and Destination section should be different");
2012                                         return -EINVAL;
2013                                 }
2014
2015                                 down(&Adapter->NVMRdmWrmLock);
2016
2017                                 if((Adapter->IdleMode == TRUE) ||
2018                                         (Adapter->bShutStatus ==TRUE) ||
2019                                         (Adapter->bPreparingForLowPowerMode ==TRUE))
2020                                 {
2021                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
2022                                         up(&Adapter->NVMRdmWrmLock);
2023                                         return -EACCES;
2024                                 }
2025
2026                                 if(sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2)
2027                                 {
2028                                         if(IsNonCDLessDevice(Adapter))
2029                                         {
2030                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is Non-CDLess hence won't have ISO !!");
2031                                                 Status = -EINVAL ;
2032                                         }
2033                                         else if(sCopySectStrut.numOfBytes == 0)
2034                                         {
2035                                                 Status = BcmCopyISO(Adapter,sCopySectStrut);
2036                                         }
2037                                         else
2038                                         {
2039                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Partial Copy of ISO section is not Allowed..");
2040                                                 Status = STATUS_FAILURE ;
2041                                         }
2042                                         up(&Adapter->NVMRdmWrmLock);
2043                                         return Status;
2044                                 }
2045
2046                                 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
2047                                                         sCopySectStrut.DstSection,sCopySectStrut.offset,sCopySectStrut.numOfBytes);
2048                                 up(&Adapter->NVMRdmWrmLock);
2049                          }
2050                          break ;
2051                 case IOCTL_BCM_GET_FLASH_CS_INFO :
2052                          {
2053                                 Status = STATUS_SUCCESS;
2054                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
2055
2056                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2057                                 if(Status)
2058                                 {
2059                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2060                                         break;
2061                                 }
2062                                 if(Adapter->eNVMType != NVM_FLASH)
2063                                 {
2064                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Connected device does not have flash");
2065                                         Status = -EINVAL;
2066                                         break;
2067                                 }
2068                                 if(IsFlash2x(Adapter) == TRUE)
2069                                 {
2070
2071                                         if(IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
2072                                         {
2073                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. \nRequired size :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH2X_CS_INFO));
2074                                                 Status = -EINVAL;
2075                                                 break;
2076                                         }
2077
2078                                         Status = copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO));
2079                                         if(Status)
2080                                         {
2081                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash2x cs info failed");
2082                                                 break;
2083                                         }
2084                                 }
2085                                 else
2086                                 {
2087                                         if(IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
2088                                         {
2089                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. Required size :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH_CS_INFO));
2090                                                 Status = -EINVAL;
2091                                                 break;
2092                                         }
2093                                         Status = copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO));
2094                                         if(Status)
2095                                         {
2096                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash CS info failed");
2097                                                 break;
2098                                         }
2099
2100                                  }
2101                           }
2102                           break ;
2103                 case IOCTL_BCM_SELECT_DSD :
2104                          {
2105                                 UINT SectOfset = 0;
2106                                 FLASH2X_SECTION_VAL eFlash2xSectionVal;
2107                                 eFlash2xSectionVal = NO_SECTION_VAL ;
2108                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_SELECT_DSD Called");
2109
2110                                 if(IsFlash2x(Adapter) != TRUE)
2111                                 {
2112                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
2113                                         return -EINVAL;
2114                                 }
2115
2116                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2117                                 if(Status)
2118                                 {
2119                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2120                                         return Status;
2121                                 }
2122                                 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
2123                                 if(Status)
2124                                 {
2125                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
2126                                         return Status;
2127                                 }
2128
2129                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", eFlash2xSectionVal);
2130                                 if((eFlash2xSectionVal != DSD0) &&
2131                                         (eFlash2xSectionVal != DSD1) &&
2132                                         (eFlash2xSectionVal != DSD2) )
2133                                 {
2134                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Passed section<%x> is not DSD section", eFlash2xSectionVal);
2135                                         return STATUS_FAILURE ;
2136                                 }
2137
2138                                 SectOfset= BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
2139                                 if(SectOfset == INVALID_OFFSET)
2140                                 {
2141                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
2142                                         return -EINVAL;
2143                                 }
2144
2145                                 Adapter->bAllDSDWriteAllow = TRUE ;
2146
2147                                 Adapter->ulFlashCalStart = SectOfset ;
2148                                 Adapter->eActiveDSD = eFlash2xSectionVal;
2149                          }
2150                          Status = STATUS_SUCCESS ;
2151                          break;
2152
2153                 case IOCTL_BCM_NVM_RAW_READ :
2154                          {
2155
2156                                 NVM_READWRITE  stNVMRead = {};
2157                                 INT NOB ;
2158                                 INT BuffSize ;
2159                                 INT ReadOffset = 0;
2160                                 UINT ReadBytes = 0 ;
2161                                 PUCHAR pReadBuff = NULL ;
2162                                 char __user *OutPutBuff = NULL ;
2163
2164                                 if(Adapter->eNVMType != NVM_FLASH)
2165                                 {
2166                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"NVM TYPE is not Flash ");
2167                                         return -EINVAL ;
2168                                 }
2169
2170                                 /* Copy Ioctl Buffer structure */
2171                                 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2172                                 {
2173                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
2174                                         Status = -EFAULT;
2175                                         break;
2176                                 }
2177
2178                                 if(copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,sizeof(NVM_READWRITE)))
2179                                 {
2180                                         Status = -EFAULT;
2181                                         break;
2182                                 }
2183
2184                                 NOB = stNVMRead.uiNumBytes;
2185                                 //In Raw-Read max Buff size : 64MB
2186
2187                                 if(NOB > DEFAULT_BUFF_SIZE)
2188                                         BuffSize = DEFAULT_BUFF_SIZE;
2189                                 else
2190                                         BuffSize = NOB ;
2191
2192                                 ReadOffset = stNVMRead.uiOffset ;
2193                                 OutPutBuff = stNVMRead.pBuffer;
2194
2195
2196                                 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
2197                                 if(pReadBuff == NULL)
2198                                 {
2199                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
2200                                         Status = -ENOMEM;
2201                                         break;
2202                                 }
2203                                 down(&Adapter->NVMRdmWrmLock);
2204
2205                                 if((Adapter->IdleMode == TRUE) ||
2206                                         (Adapter->bShutStatus ==TRUE) ||
2207                                         (Adapter->bPreparingForLowPowerMode ==TRUE))
2208                                 {
2209                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
2210                                         bcm_kfree(pReadBuff);
2211                                         up(&Adapter->NVMRdmWrmLock);
2212                                         return -EACCES;
2213                                 }
2214
2215                                 Adapter->bFlashRawRead = TRUE ;
2216                                 while(NOB)
2217                                 {
2218                                         if(NOB > DEFAULT_BUFF_SIZE )
2219                                                 ReadBytes = DEFAULT_BUFF_SIZE;
2220                                         else
2221                                                 ReadBytes = NOB;
2222
2223                                         //Reading the data from Flash 2.x
2224                                         Status = BeceemNVMRead(Adapter,(PUINT)pReadBuff,ReadOffset,ReadBytes);
2225                                         if(Status)
2226                                         {
2227                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
2228                                                 break;
2229                                         }
2230
2231                                         BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes);
2232
2233                                         Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
2234                                         if(Status)
2235                                         {
2236                                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to use failed with status :%d", Status);
2237                                                 break;
2238                                         }
2239                                         NOB = NOB - ReadBytes;
2240                                         if(NOB)
2241                                         {
2242                                                 ReadOffset = ReadOffset + ReadBytes ;
2243                                                 OutPutBuff = OutPutBuff + ReadBytes ;
2244                                         }
2245
2246                                 }
2247                                 Adapter->bFlashRawRead = FALSE ;
2248                                 up(&Adapter->NVMRdmWrmLock);
2249                                 bcm_kfree(pReadBuff);
2250                                 break ;
2251                          }
2252
2253                 case IOCTL_BCM_CNTRLMSG_MASK:
2254                          {
2255                                 ULONG RxCntrlMsgBitMask = 0 ;
2256
2257                                 /* Copy Ioctl Buffer structure */
2258                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2259                                 if(Status)
2260                                 {
2261                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of Ioctl buffer is failed from user space");
2262                                         break;
2263                                 }
2264
2265                                 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
2266                                 if(Status)
2267                                 {
2268                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of control bit mask failed from user space");
2269                                         break;
2270                                 }
2271                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
2272                                 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask ;
2273                          }
2274                          break;
2275                         case IOCTL_BCM_GET_DEVICE_DRIVER_INFO:
2276                         {
2277                                 DEVICE_DRIVER_INFO DevInfo;
2278
2279                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2280
2281                                 DevInfo.MaxRDMBufferSize = BUFFER_4K;
2282                                 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
2283                                 DevInfo.u32RxAlignmentCorrection = 0;
2284                                 DevInfo.u32NVMType = Adapter->eNVMType;
2285                                 DevInfo.u32InterfaceType = BCM_USB;
2286
2287                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2288                                 if(Status)
2289                                 {
2290                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2291                                         break;
2292                                 }
2293                                 if(IoBuffer.OutputLength < sizeof(DevInfo))
2294                                 {
2295                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"User Passed buffer length is less than actural buffer size");
2296                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"user passed buffer size :0x%lX, expected size :0x%zx",IoBuffer.OutputLength, sizeof(DevInfo));
2297                                         Status = -EINVAL;
2298                                         break;
2299                                 }
2300                                 Status = copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo));
2301                                 if(Status)
2302                                 {
2303                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copying Dev info structure to user space buffer failed");
2304                                         break;
2305                                 }
2306                         }
2307                         break ;
2308
2309                         case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
2310                         {
2311                                 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
2312                                 struct timeval tv = {0} ;
2313
2314                                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2315
2316                                 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2317                                 if(Status)
2318                                 {
2319                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2320                                         break;
2321                                 }
2322                                 if(IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
2323                                 {
2324                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"User Passed buffer length:0x%lx is less than expected buff size :0x%zX",IoBuffer.OutputLength,sizeof(ST_TIME_ELAPSED));
2325                                         Status = -EINVAL;
2326                                         break;
2327                                 }
2328
2329                                 //stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = Adapter->liTimeSinceLastNetEntry;
2330                                 do_gettimeofday(&tv);
2331                                 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = tv.tv_sec - Adapter->liTimeSinceLastNetEntry;
2332
2333                                 Status = copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED));
2334                                 if(Status)
2335                                 {
2336                                         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copying ST_TIME_ELAPSED structure to user space buffer failed");
2337                                         break;
2338                                 }
2339
2340                         }
2341                         break;
2342
2343                 default:
2344             BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "wrong input %x",cmd);
2345                         BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In default ioctl %d\n", cmd);
2346                          Status = STATUS_FAILURE;
2347
2348                         break;
2349         }
2350         return Status;
2351 }
2352
2353
2354 static struct file_operations bcm_fops = {
2355         .owner    = THIS_MODULE,
2356         .open     = bcm_char_open,
2357         .release  = bcm_char_release,
2358         .read     = bcm_char_read,
2359         .unlocked_ioctl    = bcm_char_ioctl,
2360         .llseek = no_llseek,
2361 };
2362
2363
2364 int register_control_device_interface(PMINI_ADAPTER Adapter)
2365 {
2366         if(Adapter->major>0)
2367         return Adapter->major;
2368     Adapter->major = register_chrdev(0, "tarang", &bcm_fops);
2369     if(Adapter->major < 0)
2370     {
2371         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "register_chrdev:Failed to registering WiMax control char device!");
2372         return Adapter->major;
2373     }
2374
2375         bcm_class = NULL;
2376         bcm_class = class_create (THIS_MODULE, "tarang");
2377         if(IS_ERR (bcm_class))
2378         {
2379         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Unable to create class\n");
2380         unregister_chrdev(Adapter->major, "tarang");
2381                 Adapter->major = 0;
2382                 return -ENODEV;
2383         }
2384         Adapter->pstCreatedClassDevice = device_create (bcm_class, NULL,
2385                                                                 MKDEV(Adapter->major, 0),
2386 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)
2387                                                                 NULL    ,
2388 #endif
2389                                                                 "tarang");
2390
2391         if(IS_ERR(Adapter->pstCreatedClassDevice))
2392         {
2393                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "class device did not get created : %ld", PTR_ERR(Adapter->pstCreatedClassDevice) );
2394         }
2395         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Got Major No: %d", Adapter->major);
2396     return 0;
2397 }
2398
2399 void unregister_control_device_interface(PMINI_ADAPTER Adapter)
2400 {
2401         if(Adapter->major > 0)
2402         {
2403         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying class device");
2404                 device_destroy (bcm_class, MKDEV(Adapter->major, 0));
2405         }
2406     if(!IS_ERR(bcm_class))
2407         {
2408         BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying created class ");
2409         class_destroy (bcm_class);
2410                 bcm_class = NULL;
2411         }
2412         if(Adapter->major > 0)
2413         {
2414                 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"unregistering character interface");
2415         unregister_chrdev(Adapter->major, "tarang");
2416         }
2417
2418 }