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