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