4 *Copyright (C) 2010 Beceem Communications, Inc.
6 *This program is free software: you can redistribute it and/or modify
7 *it under the terms of the GNU General Public License version 2 as
8 *published by the Free Software Foundation.
10 *This program is distributed in the hope that it will be useful,but
11 *WITHOUT ANY WARRANTY; without even the implied warranty of
12 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *See the GNU General Public License for more details.
15 *You should have received a copy of the GNU General Public License
16 *along with this program. If not, write to the Free Software Foundation, Inc.,
17 *51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 /***************************************************************
24 * Function - bcm_char_open()
26 * Description - This is the "open" entry point for the character
29 * Parameters - inode: Pointer to the Inode structure of char device
30 * filp : File pointer of the char device
32 * Returns - Zero(Success)
33 ****************************************************************/
34 static struct class *bcm_class
= NULL
;
35 static int bcm_char_open(struct inode
*inode
, struct file
* filp
)
37 PMINI_ADAPTER Adapter
= NULL
;
38 PPER_TARANG_DATA pTarang
= NULL
;
40 Adapter
= GET_BCM_ADAPTER(gblpnetdev
);
41 pTarang
= (PPER_TARANG_DATA
)kmalloc(sizeof(PER_TARANG_DATA
), GFP_KERNEL
);
45 memset (pTarang
, 0, sizeof(PER_TARANG_DATA
));
46 pTarang
->Adapter
= Adapter
;
47 pTarang
->RxCntrlMsgBitMask
= 0xFFFFFFFF & ~(1 << 0xB) ;
49 down(&Adapter
->RxAppControlQueuelock
);
50 pTarang
->next
= Adapter
->pTarangs
;
51 Adapter
->pTarangs
= pTarang
;
52 up(&Adapter
->RxAppControlQueuelock
);
54 /* Store the Adapter structure */
55 filp
->private_data
= pTarang
;
57 /*Start Queuing the control response Packets*/
58 atomic_inc(&Adapter
->ApplicationRunning
);
61 static int bcm_char_release(struct inode
*inode
, struct file
*filp
)
63 PPER_TARANG_DATA pTarang
, tmp
, ptmp
;
64 PMINI_ADAPTER Adapter
=NULL
;
65 struct sk_buff
* pkt
, * npkt
;
67 pTarang
= (PPER_TARANG_DATA
)filp
->private_data
;
71 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "ptarang is null\n");
75 Adapter
= pTarang
->Adapter
;
77 down( &Adapter
->RxAppControlQueuelock
);
79 tmp
= Adapter
->pTarangs
;
80 for ( ptmp
= NULL
; tmp
; ptmp
= tmp
, tmp
= tmp
->next
)
89 Adapter
->pTarangs
= tmp
->next
;
91 ptmp
->next
= tmp
->next
;
96 up( &Adapter
->RxAppControlQueuelock
);
100 pkt
= pTarang
->RxAppControlHead
;
108 up( &Adapter
->RxAppControlQueuelock
);
110 /*Stop Queuing the control response Packets*/
111 atomic_dec(&Adapter
->ApplicationRunning
);
115 /* remove this filp from the asynchronously notified filp's */
116 filp
->private_data
= NULL
;
120 static int bcm_char_read(struct file
*filp
, PCHAR buf
, size_t size
, loff_t
*f_pos
)
122 PPER_TARANG_DATA pTarang
= (PPER_TARANG_DATA
)filp
->private_data
;
123 PMINI_ADAPTER Adapter
= pTarang
->Adapter
;
124 struct sk_buff
* Packet
= NULL
;
128 wait_ret_val
= wait_event_interruptible(Adapter
->process_read_wait_queue
,
129 (pTarang
->RxAppControlHead
|| Adapter
->device_removed
));
130 if((wait_ret_val
== -ERESTARTSYS
))
132 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Exiting as i've been asked to exit!!!\n");
136 if(Adapter
->device_removed
)
138 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device Removed... Killing the Apps...\n");
142 if(FALSE
== Adapter
->fw_download_done
)
145 down( &Adapter
->RxAppControlQueuelock
);
147 if(pTarang
->RxAppControlHead
)
149 Packet
= pTarang
->RxAppControlHead
;
150 DEQUEUEPACKET(pTarang
->RxAppControlHead
,pTarang
->RxAppControlTail
);
151 pTarang
->AppCtrlQueueLen
--;
154 up(&Adapter
->RxAppControlQueuelock
);
158 PktLen
= Packet
->len
;
159 if(copy_to_user(buf
, Packet
->data
, PktLen
))
161 bcm_kfree_skb(Packet
);
162 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "\nReturning from copy to user failure \n");
165 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
);
166 bcm_kfree_skb(Packet
);
169 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "<====\n");
173 static INT
bcm_char_ioctl(struct inode
*inode
, struct file
*filp
,
176 PPER_TARANG_DATA pTarang
= (PPER_TARANG_DATA
)filp
->private_data
;
177 PMINI_ADAPTER Adapter
= pTarang
->Adapter
;
178 INT Status
= STATUS_FAILURE
;
179 IOCTL_BUFFER IoBuffer
={0};
180 #ifndef BCM_SHM_INTERFACE
185 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
);
187 if(_IOC_TYPE(cmd
) != BCM_IOCTL
)
189 if(_IOC_DIR(cmd
) & _IOC_READ
)
190 Status
= !access_ok(VERIFY_WRITE
, (PVOID
)arg
, _IOC_SIZE(cmd
));
191 else if (_IOC_DIR(cmd
) & _IOC_WRITE
)
192 Status
= !access_ok(VERIFY_READ
, (PVOID
)arg
, _IOC_SIZE(cmd
));
193 else if (_IOC_NONE
== (_IOC_DIR(cmd
) & _IOC_NONE
))
194 Status
= STATUS_SUCCESS
;
199 if(Adapter
->device_removed
)
204 if(FALSE
== Adapter
->fw_download_done
)
208 case IOCTL_MAC_ADDR_REQ
:
210 case IOCTL_CM_REQUEST
:
211 case IOCTL_SS_INFO_REQ
:
212 case IOCTL_SEND_CONTROL_MESSAGE
:
220 Status
= vendorextnIoctl(Adapter
, cmd
, arg
);
221 if(Status
!= CONTINUE_COMMON_PATH
)
227 // Rdms for Swin Idle...
228 case IOCTL_BCM_REGISTER_READ_PRIVATE
:
230 RDM_BUFFER sRdmBuffer
= {0};
231 PCHAR temp_buff
= NULL
;
233 /* Copy Ioctl Buffer structure */
234 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
,
235 sizeof(IOCTL_BUFFER
)))
241 Bufflen
= IoBuffer
.OutputLength
+ (4 - IoBuffer
.OutputLength
%4)%4;
242 temp_buff
= (PCHAR
)kmalloc(Bufflen
, GFP_KERNEL
);
245 return STATUS_FAILURE
;
247 if(copy_from_user(&sRdmBuffer
, IoBuffer
.InputBuffer
,
248 IoBuffer
.InputLength
))
254 down(&Adapter
->rdmWrmDevAccLock
);
255 Status
= rdmalt(Adapter
, (UINT
)sRdmBuffer
.Register
,
256 (PUINT
)temp_buff
, Bufflen
);
257 up(&Adapter
->rdmWrmDevAccLock
);
259 if(Status
!= STATUS_SUCCESS
)
261 bcm_kfree(temp_buff
);
264 if(copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
,
265 (PCHAR
)temp_buff
, (UINT
)IoBuffer
.OutputLength
))
269 bcm_kfree(temp_buff
);
272 case IOCTL_BCM_REGISTER_WRITE_PRIVATE
:
274 WRM_BUFFER sWrmBuffer
= {0};
276 /* Copy Ioctl Buffer structure */
278 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
,
279 sizeof(IOCTL_BUFFER
)))
284 /* Get WrmBuffer structure */
285 if(copy_from_user(&sWrmBuffer
, IoBuffer
.InputBuffer
,
286 IoBuffer
.InputLength
))
291 uiTempVar
= sWrmBuffer
.Register
& EEPROM_REJECT_MASK
;
292 if(!((Adapter
->pstargetparams
->m_u32Customize
) & VSG_MODE
) &&
293 ((uiTempVar
== EEPROM_REJECT_REG_1
)||
294 (uiTempVar
== EEPROM_REJECT_REG_2
) ||
295 (uiTempVar
== EEPROM_REJECT_REG_3
) ||
296 (uiTempVar
== EEPROM_REJECT_REG_4
)))
298 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
303 down(&Adapter
->rdmWrmDevAccLock
);
304 Status
= wrmalt(Adapter
, (UINT
)sWrmBuffer
.Register
,
305 (PUINT
)sWrmBuffer
.Data
, sizeof(ULONG
));
306 up(&Adapter
->rdmWrmDevAccLock
);
308 if(Status
== STATUS_SUCCESS
)
310 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"WRM Done\n");
314 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "WRM Failed\n");
320 case IOCTL_BCM_REGISTER_READ
:
321 case IOCTL_BCM_EEPROM_REGISTER_READ
:
323 RDM_BUFFER sRdmBuffer
= {0};
324 PCHAR temp_buff
= NULL
;
327 if((Adapter
->IdleMode
== TRUE
) ||
328 (Adapter
->bShutStatus
==TRUE
) ||
329 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
331 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
336 /* Copy Ioctl Buffer structure */
337 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
,
338 sizeof(IOCTL_BUFFER
)))
344 temp_buff
= (PCHAR
)kmalloc(IoBuffer
.OutputLength
, GFP_KERNEL
);
347 return STATUS_FAILURE
;
349 if(copy_from_user(&sRdmBuffer
, IoBuffer
.InputBuffer
,
350 IoBuffer
.InputLength
))
355 #ifdef BCM_SHM_INTERFACE
356 sRdmBuffer
.Register
|= 0xA0000000;
359 #if !defined(BCM_SHM_INTERFACE)
360 (((ULONG
)sRdmBuffer
.Register
& 0x0F000000) != 0x0F000000) ||
363 ((ULONG
)sRdmBuffer
.Register
< 0xAF000000)
365 (((ULONG
)sRdmBuffer
.Register
> 0xBFFFFFFF))
368 ((ULONG
)sRdmBuffer
.Register
& 0x3)
371 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
372 (int)sRdmBuffer
.Register
);
377 uiTempVar
= sRdmBuffer
.Register
& EEPROM_REJECT_MASK
;
379 down(&Adapter
->rdmWrmDevAccLock
);
380 Status
= rdmaltWithLock(Adapter
, (UINT
)sRdmBuffer
.Register
,
381 (PUINT
)temp_buff
, IoBuffer
.OutputLength
);
382 up(&Adapter
->rdmWrmDevAccLock
);
384 if(Status
!= STATUS_SUCCESS
)
386 bcm_kfree(temp_buff
);
389 if(copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
,
390 (PCHAR
)temp_buff
, (UINT
)IoBuffer
.OutputLength
))
394 bcm_kfree(temp_buff
);
397 case IOCTL_BCM_REGISTER_WRITE
:
398 case IOCTL_BCM_EEPROM_REGISTER_WRITE
:
400 WRM_BUFFER sWrmBuffer
= {0};
403 if((Adapter
->IdleMode
== TRUE
) ||
404 (Adapter
->bShutStatus
==TRUE
) ||
405 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
407 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
411 /* Copy Ioctl Buffer structure */
412 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
,
413 sizeof(IOCTL_BUFFER
)))
418 /* Get WrmBuffer structure */
419 if(copy_from_user(&sWrmBuffer
, IoBuffer
.InputBuffer
,
420 IoBuffer
.InputLength
))
426 #ifdef BCM_SHM_INTERFACE
427 sWrmBuffer
.Register
|= 0xA0000000;
430 #if !defined(BCM_SHM_INTERFACE)
432 (((ULONG
)sWrmBuffer
.Register
& 0x0F000000) != 0x0F000000) ||
435 ((ULONG
)sWrmBuffer
.Register
< 0xAF000000)
437 (((ULONG
)sWrmBuffer
.Register
> 0xBFFFFFFF))
440 ((ULONG
)sWrmBuffer
.Register
& 0x3)
443 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n",
444 (int)sWrmBuffer
.Register
);
448 uiTempVar
= sWrmBuffer
.Register
& EEPROM_REJECT_MASK
;
449 if(!((Adapter
->pstargetparams
->m_u32Customize
) & VSG_MODE
) &&
450 ((uiTempVar
== EEPROM_REJECT_REG_1
)||
451 (uiTempVar
== EEPROM_REJECT_REG_2
) ||
452 (uiTempVar
== EEPROM_REJECT_REG_3
) ||
453 (uiTempVar
== EEPROM_REJECT_REG_4
)) &&
454 (cmd
== IOCTL_BCM_REGISTER_WRITE
))
456 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
461 down(&Adapter
->rdmWrmDevAccLock
);
462 Status
= wrmaltWithLock(Adapter
, (UINT
)sWrmBuffer
.Register
,
463 (PUINT
)sWrmBuffer
.Data
, sWrmBuffer
.Length
);
464 up(&Adapter
->rdmWrmDevAccLock
);
466 if(Status
== STATUS_SUCCESS
)
468 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, OSAL_DBG
, DBG_LVL_ALL
, "WRM Done\n");
472 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "WRM Failed\n");
477 case IOCTL_BCM_GPIO_SET_REQUEST
:
479 UCHAR ucResetValue
[4];
482 UINT uiOperation
= 0;
484 GPIO_INFO gpio_info
= {0};
485 if((Adapter
->IdleMode
== TRUE
) ||
486 (Adapter
->bShutStatus
==TRUE
) ||
487 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
489 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"GPIO Can't be set/clear in Low power Mode");
493 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
498 if(copy_from_user(&gpio_info
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
503 uiBit
= gpio_info
.uiGpioNumber
;
504 uiOperation
= gpio_info
.uiGpioValue
;
508 if(IsReqGpioIsLedInNVM(Adapter
,value
) ==FALSE
)
510 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",value
);
516 if(uiOperation
)//Set - setting 1
518 //Set the gpio output register
519 Status
= wrmaltWithLock(Adapter
,BCM_GPIO_OUTPUT_SET_REG
,
520 (PUINT
)(&value
), sizeof(UINT
));
521 if(Status
== STATUS_SUCCESS
)
523 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Set the GPIO bit\n");
527 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Failed to set the %dth GPIO \n",uiBit
);
531 else//Unset - setting 0
533 //Set the gpio output register
534 Status
= wrmaltWithLock(Adapter
,BCM_GPIO_OUTPUT_CLR_REG
,
535 (PUINT
)(&value
), sizeof(UINT
));
536 if(Status
== STATUS_SUCCESS
)
538 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Set the GPIO bit\n");
542 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Failed to clear the %dth GPIO \n",uiBit
);
547 Status
= rdmaltWithLock(Adapter
, (UINT
)GPIO_MODE_REGISTER
,
548 (PUINT
)ucResetValue
, sizeof(UINT
));
549 if (STATUS_SUCCESS
!= Status
)
551 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"GPIO_MODE_REGISTER read failed");
554 //Set the gpio mode register to output
555 *(UINT
*)ucResetValue
|= (1<<uiBit
);
556 Status
= wrmaltWithLock(Adapter
,GPIO_MODE_REGISTER
,
557 (PUINT
)ucResetValue
, sizeof(UINT
));
558 if(Status
== STATUS_SUCCESS
)
560 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Set the GPIO to output Mode\n");
564 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Failed to put GPIO in Output Mode\n");
569 case BCM_LED_THREAD_STATE_CHANGE_REQ
:
572 USER_THREAD_REQ threadReq
= {0};
573 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"User made LED thread InActive");
575 if((Adapter
->IdleMode
== TRUE
) ||
576 (Adapter
->bShutStatus
==TRUE
) ||
577 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
579 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"GPIO Can't be set/clear in Low power Mode");
583 Status
=copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
586 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status
);
590 Status
= copy_from_user(&threadReq
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
);
593 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying the InputBuffer from user space err:%d",Status
);
596 //if LED thread is running(Actively or Inactively) set it state to make inactive
597 if(Adapter
->LEDInfo
.led_thread_running
)
599 if(threadReq
.ThreadState
== LED_THREAD_ACTIVATION_REQ
)
601 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Activating thread req");
602 Adapter
->DriverState
= LED_THREAD_ACTIVE
;
606 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"DeActivating Thread req.....");
607 Adapter
->DriverState
= LED_THREAD_INACTIVE
;
611 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
616 case IOCTL_BCM_GPIO_STATUS_REQUEST
:
620 GPIO_INFO gpio_info
= {0};
621 if((Adapter
->IdleMode
== TRUE
) ||
622 (Adapter
->bShutStatus
==TRUE
) ||
623 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
628 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
633 if(copy_from_user(&gpio_info
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
638 uiBit
= gpio_info
.uiGpioNumber
;
639 //Set the gpio output register
640 Status
= rdmaltWithLock(Adapter
, (UINT
)GPIO_PIN_STATE_REGISTER
,
641 (PUINT
)ucRead
, sizeof(UINT
));
642 if(Status
!= STATUS_SUCCESS
)
644 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "RDM Failed\n");
650 case IOCTL_BCM_GPIO_MULTI_REQUEST
:
652 UCHAR ucResetValue
[4];
653 GPIO_MULTI_INFO gpio_multi_info
[MAX_IDX
];
654 PGPIO_MULTI_INFO pgpio_multi_info
= (PGPIO_MULTI_INFO
)gpio_multi_info
;
656 memset( pgpio_multi_info
, 0, MAX_IDX
* sizeof( GPIO_MULTI_INFO
));
658 if((Adapter
->IdleMode
== TRUE
) ||
659 (Adapter
->bShutStatus
==TRUE
) ||
660 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
665 Status
= copy_from_user( (PCHAR
)&IoBuffer
, ( PCHAR
)arg
, sizeof( IOCTL_BUFFER
));
668 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status
);
672 Status
= copy_from_user( &gpio_multi_info
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
);
675 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status
);
678 if(IsReqGpioIsLedInNVM(Adapter
,pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
)== FALSE
)
680 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
);
685 /* Set the gpio output register */
687 if( ( pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
) &
688 ( pgpio_multi_info
[WIMAX_IDX
].uiGPIOCommand
))
690 /* Set 1's in GPIO OUTPUT REGISTER */
691 *(UINT
*) ucResetValue
= pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
&
692 pgpio_multi_info
[WIMAX_IDX
].uiGPIOCommand
&
693 pgpio_multi_info
[WIMAX_IDX
].uiGPIOValue
;
695 if( *(UINT
*) ucResetValue
)
696 Status
= wrmaltWithLock( Adapter
, BCM_GPIO_OUTPUT_SET_REG
, (PUINT
) ucResetValue
, sizeof(ULONG
));
698 if( Status
!= STATUS_SUCCESS
)
700 BCM_DEBUG_PRINT( Adapter
,DBG_TYPE_PRINTK
, 0, 0,"WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
704 /* Clear to 0's in GPIO OUTPUT REGISTER */
705 *(UINT
*) ucResetValue
= (pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
&
706 pgpio_multi_info
[WIMAX_IDX
].uiGPIOCommand
&
707 ( ~( pgpio_multi_info
[WIMAX_IDX
].uiGPIOValue
)));
709 if( *(UINT
*) ucResetValue
)
710 Status
= wrmaltWithLock( Adapter
, BCM_GPIO_OUTPUT_CLR_REG
, (PUINT
) ucResetValue
, sizeof(ULONG
));
712 if( Status
!= STATUS_SUCCESS
)
714 BCM_DEBUG_PRINT( Adapter
,DBG_TYPE_PRINTK
, 0, 0,"WRM to BCM_GPIO_OUTPUT_CLR_REG Failed." );
719 if( pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
)
721 Status
= rdmaltWithLock(Adapter
, (UINT
)GPIO_PIN_STATE_REGISTER
, (PUINT
)ucResetValue
, sizeof(UINT
));
723 if(Status
!= STATUS_SUCCESS
)
725 BCM_DEBUG_PRINT( Adapter
,DBG_TYPE_PRINTK
, 0, 0,"RDM to GPIO_PIN_STATE_REGISTER Failed.");
729 pgpio_multi_info
[WIMAX_IDX
].uiGPIOValue
= ( *(UINT
*)ucResetValue
&
730 pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
);
733 Status
= copy_to_user( (PCHAR
)IoBuffer
.OutputBuffer
, &gpio_multi_info
, IoBuffer
.OutputLength
);
736 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status
);
741 case IOCTL_BCM_GPIO_MODE_REQUEST
:
743 UCHAR ucResetValue
[4];
744 GPIO_MULTI_MODE gpio_multi_mode
[MAX_IDX
];
745 PGPIO_MULTI_MODE pgpio_multi_mode
= ( PGPIO_MULTI_MODE
) gpio_multi_mode
;
747 if((Adapter
->IdleMode
== TRUE
) ||
748 (Adapter
->bShutStatus
==TRUE
) ||
749 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
754 Status
= copy_from_user( (PCHAR
)&IoBuffer
, ( PCHAR
)arg
, sizeof( IOCTL_BUFFER
));
757 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status
);
761 Status
= copy_from_user( &gpio_multi_mode
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
);
764 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status
);
768 Status
= rdmaltWithLock( Adapter
, ( UINT
) GPIO_MODE_REGISTER
, ( PUINT
) ucResetValue
, sizeof( UINT
));
769 if( STATUS_SUCCESS
!= Status
)
771 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Read of GPIO_MODE_REGISTER failed");
775 //Validating the request
776 if(IsReqGpioIsLedInNVM(Adapter
,pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
)== FALSE
)
778 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
);
783 if( pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
)
785 /* write all OUT's (1's) */
786 *( UINT
*) ucResetValue
|= ( pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
&
787 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
);
788 /* write all IN's (0's) */
789 *( UINT
*) ucResetValue
&= ~( ( ~pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
) &
790 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
);
792 /* Currently implemented return the modes of all GPIO's
793 * else needs to bit AND with mask
795 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
= *(UINT
*)ucResetValue
;
797 Status
= wrmaltWithLock( Adapter
, GPIO_MODE_REGISTER
, ( PUINT
) ucResetValue
, sizeof( ULONG
));
798 if( Status
== STATUS_SUCCESS
)
800 BCM_DEBUG_PRINT( Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "WRM to GPIO_MODE_REGISTER Done");
804 BCM_DEBUG_PRINT( Adapter
,DBG_TYPE_PRINTK
, 0, 0,"WRM to GPIO_MODE_REGISTER Failed");
809 else /* if uiGPIOMask is 0 then return mode register configuration */
811 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
= *( UINT
*) ucResetValue
;
813 Status
= copy_to_user( (PCHAR
)IoBuffer
.OutputBuffer
, &gpio_multi_mode
, IoBuffer
.OutputLength
);
816 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status
);
822 case IOCTL_MAC_ADDR_REQ
:
824 case IOCTL_CM_REQUEST
:
825 case IOCTL_SS_INFO_REQ
:
826 case IOCTL_SEND_CONTROL_MESSAGE
:
830 /* Copy Ioctl Buffer structure */
831 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
,
832 sizeof(IOCTL_BUFFER
)))
837 pvBuffer
=kmalloc(IoBuffer
.InputLength
, GFP_KERNEL
);
843 if(copy_from_user(pvBuffer
, IoBuffer
.InputBuffer
,
844 IoBuffer
.InputLength
))
851 down(&Adapter
->LowPowerModeSync
);
852 Status
= wait_event_interruptible_timeout(Adapter
->lowpower_mode_wait_queue
,
853 !Adapter
->bPreparingForLowPowerMode
,
855 if(Status
== -ERESTARTSYS
)
858 if(Adapter
->bPreparingForLowPowerMode
)
860 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Preparing Idle Mode is still True - Hence Rejecting control message\n");
861 Status
= STATUS_FAILURE
;
864 Status
= CopyBufferToControlPacket(Adapter
, (PVOID
)pvBuffer
);
866 up(&Adapter
->LowPowerModeSync
);
870 #ifndef BCM_SHM_INTERFACE
871 case IOCTL_BCM_BUFFER_DOWNLOAD_START
:
873 INT NVMAccess
= down_trylock(&Adapter
->NVMRdmWrmLock
) ;
876 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");
879 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current
->pid
);
880 if(!down_trylock(&Adapter
->fw_download_sema
))
882 Adapter
->bBinDownloaded
=FALSE
;
883 Adapter
->fw_download_process_pid
=current
->pid
;
884 Adapter
->bCfgDownloaded
=FALSE
;
885 Adapter
->fw_download_done
=FALSE
;
886 netif_carrier_off(Adapter
->dev
);
887 netif_stop_queue(Adapter
->dev
);
888 down(&Adapter
->rdmWrmDevAccLock
);
889 Status
= reset_card_proc(Adapter
);
891 //Initializing the NVM.
893 up(&Adapter
->rdmWrmDevAccLock
);
897 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "reset_card_proc Failed!\n");
898 up(&Adapter
->fw_download_sema
);
899 up(&Adapter
->NVMRdmWrmLock
);
910 up(&Adapter
->NVMRdmWrmLock
);
913 case IOCTL_BCM_BUFFER_DOWNLOAD
:
915 FIRMWARE_INFO
*psFwInfo
=NULL
;
916 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current
->pid
);
918 if(!down_trylock(&Adapter
->fw_download_sema
))
920 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Invalid way to download buffer. Use Start and then call this!!!\n");
924 /* Copy Ioctl Buffer structure */
925 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
,
926 sizeof(IOCTL_BUFFER
)))
928 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "copy_from_user 1 failed\n");
932 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Length for FW DLD is : %lx\n",
933 IoBuffer
.InputLength
);
934 psFwInfo
=kmalloc(sizeof(*psFwInfo
), GFP_KERNEL
);
937 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Failed to allocate buffer!!!!\n");
941 if(copy_from_user(psFwInfo
, IoBuffer
.InputBuffer
,
942 IoBuffer
.InputLength
))
944 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy_from_user 2 failed\n");
949 if(!psFwInfo
->pvMappedFirmwareAddress
||
950 (psFwInfo
->u32FirmwareLength
== 0))
952 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Something else is wrong %lu\n",
953 psFwInfo
->u32FirmwareLength
);
959 down(&Adapter
->rdmWrmDevAccLock
);
960 Status
= bcm_ioctl_fw_download(Adapter
, psFwInfo
);
961 up(&Adapter
->rdmWrmDevAccLock
);
963 if(Status
!= STATUS_SUCCESS
)
965 if(psFwInfo
->u32StartingAddress
==CONFIG_BEGIN_ADDR
)
967 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "IOCTL: Configuration File Upload Failed\n");
971 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "IOCTL: Firmware File Upload Failed\n");
973 //up(&Adapter->fw_download_sema);
975 if(Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
)
977 Adapter
->DriverState
= DRIVER_INIT
;
978 Adapter
->LEDInfo
.bLedInitDone
= FALSE
;
979 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
985 if(Status
!= STATUS_SUCCESS
)
986 up(&Adapter
->fw_download_sema
);
987 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL: Firmware File Uploaded\n");
991 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP
:
993 INT NVMAccess
= down_trylock(&Adapter
->NVMRdmWrmLock
);
996 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, " FW download blocked as EEPROM Read/Write is in progress\n");
997 up(&Adapter
->fw_download_sema
);
1000 if(down_trylock(&Adapter
->fw_download_sema
))
1002 Adapter
->bBinDownloaded
=TRUE
;
1003 Adapter
->bCfgDownloaded
=TRUE
;
1004 atomic_set(&Adapter
->CurrNumFreeTxDesc
, 0);
1005 atomic_set(&Adapter
->RxRollOverCount
, 0);
1006 Adapter
->CurrNumRecvDescs
=0;
1007 Adapter
->uiFirstInterrupt
= 0;
1009 //setting the Mips to Run
1011 down(&Adapter
->rdmWrmDevAccLock
);
1012 Status
= run_card_proc(Adapter
);
1013 up(&Adapter
->rdmWrmDevAccLock
);
1017 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Firm Download Failed\n");
1018 up(&Adapter
->fw_download_sema
);
1019 up(&Adapter
->NVMRdmWrmLock
);
1023 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Firm Download Over...\n");
1025 /* Wait for MailBox Interrupt */
1026 if(StartInterruptUrb((PS_INTERFACE_ADAPTER
)Adapter
->pvInterfaceAdapter
))
1028 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Unable to send interrupt...\n");
1031 Adapter
->waiting_to_fw_download_done
= FALSE
;
1032 wait_event_timeout(Adapter
->ioctl_fw_dnld_wait_queue
,
1033 Adapter
->waiting_to_fw_download_done
, timeout
);
1034 Adapter
->fw_download_process_pid
=INVALID_PID
;
1035 Adapter
->fw_download_done
=TRUE
;
1036 atomic_set(&Adapter
->CurrNumFreeTxDesc
, 0);
1037 Adapter
->CurrNumRecvDescs
= 0;
1038 Adapter
->PrevNumRecvDescs
= 0;
1039 atomic_set(&Adapter
->cntrlpktCnt
,0);
1040 Adapter
->LinkUpStatus
= 0;
1041 Adapter
->LinkStatus
= 0;
1043 if(Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
)
1045 Adapter
->DriverState
= FW_DOWNLOAD_DONE
;
1046 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
1058 up(&Adapter
->fw_download_sema
);
1059 up(&Adapter
->NVMRdmWrmLock
);
1063 case IOCTL_BE_BUCKET_SIZE
:
1064 Adapter
->BEBucketSize
= *(PULONG
)arg
;
1065 Status
= STATUS_SUCCESS
;
1068 case IOCTL_RTPS_BUCKET_SIZE
:
1069 Adapter
->rtPSBucketSize
= *(PULONG
)arg
;
1070 Status
= STATUS_SUCCESS
;
1072 case IOCTL_CHIP_RESET
:
1074 INT NVMAccess
= down_trylock(&Adapter
->NVMRdmWrmLock
);
1077 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
1080 down(&Adapter
->RxAppControlQueuelock
);
1082 down(&Adapter
->rdmWrmDevAccLock
);
1083 Status
= reset_card_proc(Adapter
);
1085 //Initializing the NVM.
1086 BcmInitNVM(Adapter
);
1087 up(&Adapter
->rdmWrmDevAccLock
);
1090 up(&Adapter
->RxAppControlQueuelock
);
1091 up(&Adapter
->NVMRdmWrmLock
);
1092 ResetCounters(Adapter
);
1095 case IOCTL_QOS_THRESHOLD
:
1098 for(uiLoopIndex
= 0 ; uiLoopIndex
< NO_OF_QUEUES
; uiLoopIndex
++)
1100 Adapter
->PackInfo
[uiLoopIndex
].uiThreshold
= *(PULONG
)arg
;
1102 Status
= STATUS_SUCCESS
;
1106 case IOCTL_DUMP_PACKET_INFO
:
1108 DumpPackInfo(Adapter
);
1109 DumpPhsRules(&Adapter
->stBCMPhsContext
);
1110 Status
= STATUS_SUCCESS
;
1113 case IOCTL_GET_PACK_INFO
:
1114 if(copy_to_user((PCHAR
)arg
, &Adapter
->PackInfo
,
1115 sizeof(PacketInfo
)*NO_OF_QUEUES
))
1120 Status
= STATUS_SUCCESS
;
1122 case IOCTL_BCM_SWITCH_TRANSFER_MODE
:
1125 if(copy_from_user(&uiData
, (PUINT
)arg
, sizeof(UINT
)))
1130 if(uiData
) /* Allow All Packets */
1132 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
1133 Adapter
->TransferMode
= ETH_PACKET_TUNNELING_MODE
;
1135 else /* Allow IP only Packets */
1137 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
1138 Adapter
->TransferMode
= IP_PACKET_ONLY_MODE
;
1140 Status
= STATUS_SUCCESS
;
1144 case IOCTL_BCM_GET_DRIVER_VERSION
:
1146 /* Copy Ioctl Buffer structure */
1147 if(copy_from_user((PCHAR
)&IoBuffer
,
1148 (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
1153 if(copy_to_user((PUCHAR
)IoBuffer
.OutputBuffer
,
1154 VER_FILEVERSION_STR
, (UINT
)IoBuffer
.OutputLength
))
1159 Status
= STATUS_SUCCESS
;
1162 case IOCTL_BCM_GET_CURRENT_STATUS
:
1164 LINK_STATE
*plink_state
= NULL
;
1165 /* Copy Ioctl Buffer structure */
1166 if(copy_from_user((PCHAR
)&IoBuffer
,
1167 (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
1169 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "copy_from_user failed..\n");
1173 plink_state
= (LINK_STATE
*)arg
;
1174 plink_state
->bIdleMode
= (UCHAR
)Adapter
->IdleMode
;
1175 plink_state
->bShutdownMode
= Adapter
->bShutStatus
;
1176 plink_state
->ucLinkStatus
= (UCHAR
)Adapter
->LinkStatus
;
1177 if(copy_to_user((PUCHAR
)IoBuffer
.OutputBuffer
,
1178 (PUCHAR
)plink_state
, (UINT
)IoBuffer
.OutputLength
))
1180 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy_to_user Failed..\n");
1184 Status
= STATUS_SUCCESS
;
1187 case IOCTL_BCM_SET_MAC_TRACING
:
1190 /* copy ioctl Buffer structure */
1191 if(copy_from_user((PCHAR
)&IoBuffer
,
1192 (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
1197 if(copy_from_user((PCHAR
)&tracing_flag
,
1198 (PCHAR
)IoBuffer
.InputBuffer
,sizeof(UINT
)))
1204 Adapter
->pTarangs
->MacTracingEnabled
= TRUE
;
1206 Adapter
->pTarangs
->MacTracingEnabled
= FALSE
;
1209 case IOCTL_BCM_GET_DSX_INDICATION
:
1212 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
,
1213 sizeof(IOCTL_BUFFER
)))
1215 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Invalid IO buffer!!!" );
1219 if(IoBuffer
.OutputLength
< sizeof(stLocalSFAddIndicationAlt
))
1221 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Mismatch req: %lx needed is =0x%x!!!",
1222 IoBuffer
.OutputLength
, sizeof(stLocalSFAddIndicationAlt
));
1225 if(copy_from_user((PCHAR
)&ulSFId
, (PCHAR
)IoBuffer
.InputBuffer
,
1228 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Invalid SFID!!! %lu", ulSFId
);
1232 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Get DSX Data SF ID is =%lx\n", ulSFId
);
1233 get_dsx_sf_data_to_application(Adapter
, ulSFId
,
1234 IoBuffer
.OutputBuffer
);
1235 Status
=STATUS_SUCCESS
;
1238 case IOCTL_BCM_GET_HOST_MIBS
:
1242 if(copy_from_user((PCHAR
)&IoBuffer
,
1243 (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
1245 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy_from user for IoBuff failed\n");
1250 if(IoBuffer
.OutputLength
!= sizeof(S_MIBS_HOST_STATS_MIBS
))
1252 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Length Check failed %lu %d\n", IoBuffer
.OutputLength
,
1253 sizeof(S_MIBS_HOST_STATS_MIBS
));
1257 temp_buff
= (PCHAR
)kmalloc(IoBuffer
.OutputLength
, GFP_KERNEL
);
1261 return STATUS_FAILURE
;
1264 Status
= ProcessGetHostMibs(Adapter
,
1265 (PUCHAR
)temp_buff
, IoBuffer
.OutputLength
);
1267 Status
= GetDroppedAppCntrlPktMibs((PVOID
)temp_buff
,
1268 (PPER_TARANG_DATA
)filp
->private_data
);
1270 if(copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
,(PCHAR
)temp_buff
,
1271 sizeof(S_MIBS_HOST_STATS_MIBS
)))
1273 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy to user failed\n");
1274 bcm_kfree(temp_buff
);
1278 bcm_kfree(temp_buff
);
1282 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE
:
1283 if((FALSE
== Adapter
->bTriedToWakeUpFromlowPowerMode
) && (TRUE
==Adapter
->IdleMode
))
1285 Adapter
->usIdleModePattern
= ABORT_IDLE_MODE
;
1286 Adapter
->bWakeUpDevice
= TRUE
;
1287 wake_up(&Adapter
->process_rx_cntrlpkt
);
1289 Adapter
->bTriedToWakeUpFromlowPowerMode
= TRUE
;
1290 InterfaceAbortIdlemode (Adapter
, Adapter
->usIdleModePattern
);
1293 Status
= STATUS_SUCCESS
;
1296 case IOCTL_BCM_BULK_WRM
:
1298 PBULKWRM_BUFFER pBulkBuffer
;
1300 PCHAR pvBuffer
= NULL
;
1302 if((Adapter
->IdleMode
== TRUE
) ||
1303 (Adapter
->bShutStatus
==TRUE
) ||
1304 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
1306 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1310 /* Copy Ioctl Buffer structure */
1311 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
1317 pvBuffer
=kmalloc(IoBuffer
.InputLength
, GFP_KERNEL
);
1324 /* Get WrmBuffer structure */
1325 if(copy_from_user(pvBuffer
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
1327 bcm_kfree(pvBuffer
);
1332 pBulkBuffer
= (PBULKWRM_BUFFER
)pvBuffer
;
1334 if(((ULONG
)pBulkBuffer
->Register
& 0x0F000000) != 0x0F000000 ||
1335 ((ULONG
)pBulkBuffer
->Register
& 0x3))
1337 bcm_kfree(pvBuffer
);
1338 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer
->Register
);
1344 uiTempVar
= pBulkBuffer
->Register
& EEPROM_REJECT_MASK
;
1345 if(!((Adapter
->pstargetparams
->m_u32Customize
)&VSG_MODE
)
1346 && ((uiTempVar
== EEPROM_REJECT_REG_1
)||
1347 (uiTempVar
== EEPROM_REJECT_REG_2
) ||
1348 (uiTempVar
== EEPROM_REJECT_REG_3
) ||
1349 (uiTempVar
== EEPROM_REJECT_REG_4
)) &&
1350 (cmd
== IOCTL_BCM_REGISTER_WRITE
))
1352 bcm_kfree(pvBuffer
);
1353 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0,"EEPROM Access Denied, not in VSG Mode\n");
1358 down(&Adapter
->rdmWrmDevAccLock
);
1360 if(pBulkBuffer
->SwapEndian
== FALSE
)
1361 Status
= wrmWithLock(Adapter
, (UINT
)pBulkBuffer
->Register
, (PCHAR
)pBulkBuffer
->Values
, IoBuffer
.InputLength
- 2*sizeof(ULONG
));
1364 Status
= wrmaltWithLock(Adapter
, (UINT
)pBulkBuffer
->Register
, (PUINT
)pBulkBuffer
->Values
, IoBuffer
.InputLength
- 2*sizeof(ULONG
));
1366 up(&Adapter
->rdmWrmDevAccLock
);
1368 if(Status
!= STATUS_SUCCESS
)
1370 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "WRM Failed\n");
1373 bcm_kfree(pvBuffer
);
1377 case IOCTL_BCM_GET_NVM_SIZE
:
1380 if(copy_from_user((unsigned char *)&IoBuffer
,
1381 (unsigned char *)arg
, sizeof(IOCTL_BUFFER
)))
1383 //IOLog("failed NVM first");
1387 if(Adapter
->eNVMType
== NVM_EEPROM
|| Adapter
->eNVMType
== NVM_FLASH
) {
1388 if(copy_to_user(IoBuffer
.OutputBuffer
,
1389 (unsigned char *)&Adapter
->uiNVMDSDSize
, (UINT
)sizeof(UINT
)))
1396 Status
= STATUS_SUCCESS
;
1400 case IOCTL_BCM_CAL_INIT
:
1402 UINT uiSectorSize
= 0 ;
1404 if(Adapter
->eNVMType
== NVM_FLASH
)
1406 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
1409 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Copy From User space failed. status :%d", Status
);
1412 uiSectorSize
= *((PUINT
)(IoBuffer
.InputBuffer
));
1413 if((uiSectorSize
< MIN_SECTOR_SIZE
) || (uiSectorSize
> MAX_SECTOR_SIZE
))
1416 Status
= copy_to_user(IoBuffer
.OutputBuffer
,
1417 (unsigned char *)&Adapter
->uiSectorSize
,
1418 (UINT
)sizeof(UINT
));
1421 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Coping the sector size to use space failed. status:%d",Status
);
1427 if(IsFlash2x(Adapter
))
1429 Status
= copy_to_user(IoBuffer
.OutputBuffer
,
1430 (unsigned char *)&Adapter
->uiSectorSize
,
1431 (UINT
)sizeof(UINT
));
1434 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Coping the sector size to use space failed. status:%d",Status
);
1442 down(&Adapter
->NVMRdmWrmLock
);
1444 if((Adapter
->IdleMode
== TRUE
) ||
1445 (Adapter
->bShutStatus
==TRUE
) ||
1446 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
1448 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
1449 up(&Adapter
->NVMRdmWrmLock
);
1453 Adapter
->uiSectorSize
= uiSectorSize
;
1454 BcmUpdateSectorSize(Adapter
,Adapter
->uiSectorSize
);
1455 up(&Adapter
->NVMRdmWrmLock
);
1458 Status
= STATUS_SUCCESS
;
1462 Status
= STATUS_FAILURE
;
1466 case IOCTL_BCM_SET_DEBUG
:
1468 USER_BCM_DBG_STATE sUserDebugState
;
1470 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG );
1472 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "In SET_DEBUG ioctl\n");
1473 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
1476 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy from user failed\n");
1479 Status
= copy_from_user(&sUserDebugState
,(USER_BCM_DBG_STATE
*)IoBuffer
.InputBuffer
, sizeof(USER_BCM_DBG_STATE
));
1482 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of IoBuffer.InputBuffer failed");
1486 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1487 sUserDebugState
.OnOff
, sUserDebugState
.Type
);
1488 //sUserDebugState.Subtype <<= 1;
1489 sUserDebugState
.Subtype
= 1 << sUserDebugState
.Subtype
;
1490 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "actual Subtype=0x%x\n", sUserDebugState
.Subtype
);
1492 // Update new 'DebugState' in the Adapter
1493 Adapter
->stDebugState
.type
|= sUserDebugState
.Type
;
1494 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1495 * Valid indexes in 'subtype' array: 1,2,4,8
1496 * corresponding to valid Type values. Hence we can use the 'Type' field
1497 * as the index value, ignoring the array entries 0,3,5,6,7 !
1499 if (sUserDebugState
.OnOff
)
1500 Adapter
->stDebugState
.subtype
[sUserDebugState
.Type
] |= sUserDebugState
.Subtype
;
1502 Adapter
->stDebugState
.subtype
[sUserDebugState
.Type
] &= ~sUserDebugState
.Subtype
;
1504 BCM_SHOW_DEBUG_BITMAP(Adapter
);
1508 case IOCTL_BCM_NVM_READ
:
1509 case IOCTL_BCM_NVM_WRITE
:
1512 NVM_READWRITE stNVMReadWrite
= {0};
1513 PUCHAR pReadData
= NULL
;
1514 PUCHAR pBuffertobeCopied
= NULL
;
1515 ULONG ulDSDMagicNumInUsrBuff
= 0 ;
1516 struct timeval tv0
, tv1
;
1517 memset(&tv0
,0,sizeof(struct timeval
));
1518 memset(&tv1
,0,sizeof(struct timeval
));
1519 if((Adapter
->eNVMType
== NVM_FLASH
) && (Adapter
->uiFlashLayoutMajorVersion
== 0))
1521 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,"The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1526 if(IsFlash2x(Adapter
))
1528 if((Adapter
->eActiveDSD
!= DSD0
) &&
1529 (Adapter
->eActiveDSD
!= DSD1
) &&
1530 (Adapter
->eActiveDSD
!= DSD2
))
1532 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"No DSD is active..hence NVM Command is blocked");
1533 return STATUS_FAILURE
;
1537 /* Copy Ioctl Buffer structure */
1539 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
1541 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"copy_from_user failed\n");
1545 if(IOCTL_BCM_NVM_READ
== cmd
)
1546 pBuffertobeCopied
= IoBuffer
.OutputBuffer
;
1548 pBuffertobeCopied
= IoBuffer
.InputBuffer
;
1550 if(copy_from_user(&stNVMReadWrite
, pBuffertobeCopied
,sizeof(NVM_READWRITE
)))
1557 // Deny the access if the offset crosses the cal area limit.
1559 if((stNVMReadWrite
.uiOffset
+ stNVMReadWrite
.uiNumBytes
) > Adapter
->uiNVMDSDSize
)
1561 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset ,
1562 // stNVMReadWrite.uiNumBytes);
1563 Status
= STATUS_FAILURE
;
1567 pReadData
=(PCHAR
)kmalloc(stNVMReadWrite
.uiNumBytes
, GFP_KERNEL
);
1572 memset(pReadData
,0,stNVMReadWrite
.uiNumBytes
);
1574 if(copy_from_user(pReadData
, stNVMReadWrite
.pBuffer
,
1575 stNVMReadWrite
.uiNumBytes
))
1578 bcm_kfree(pReadData
);
1582 do_gettimeofday(&tv0
);
1583 if(IOCTL_BCM_NVM_READ
== cmd
)
1585 down(&Adapter
->NVMRdmWrmLock
);
1587 if((Adapter
->IdleMode
== TRUE
) ||
1588 (Adapter
->bShutStatus
==TRUE
) ||
1589 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
1591 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
1592 up(&Adapter
->NVMRdmWrmLock
);
1593 bcm_kfree(pReadData
);
1597 Status
= BeceemNVMRead(Adapter
, (PUINT
)pReadData
,
1598 stNVMReadWrite
.uiOffset
, stNVMReadWrite
.uiNumBytes
);
1600 up(&Adapter
->NVMRdmWrmLock
);
1602 if(Status
!= STATUS_SUCCESS
)
1604 bcm_kfree(pReadData
);
1607 if(copy_to_user((PCHAR
)stNVMReadWrite
.pBuffer
,
1608 (PCHAR
)pReadData
, (UINT
)stNVMReadWrite
.uiNumBytes
))
1610 bcm_kfree(pReadData
);
1617 down(&Adapter
->NVMRdmWrmLock
);
1619 if((Adapter
->IdleMode
== TRUE
) ||
1620 (Adapter
->bShutStatus
==TRUE
) ||
1621 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
1623 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
1624 up(&Adapter
->NVMRdmWrmLock
);
1625 bcm_kfree(pReadData
);
1629 Adapter
->bHeaderChangeAllowed
= TRUE
;
1630 if(IsFlash2x(Adapter
))
1634 DSD section updation will be allowed in two case:-
1635 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1636 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1637 corrupted then user space program first modify the DSD header with valid DSD sig so
1638 that this as well as further write may be worthwhile.
1640 This restriction has been put assuming that if DSD sig is corrupted, DSD
1641 data won't be considered valid.
1645 Status
= BcmFlash2xCorruptSig(Adapter
,Adapter
->eActiveDSD
);
1646 if(Status
!= STATUS_SUCCESS
)
1648 if(( (stNVMReadWrite
.uiOffset
+ stNVMReadWrite
.uiNumBytes
) != Adapter
->uiNVMDSDSize
) ||
1649 (stNVMReadWrite
.uiNumBytes
< SIGNATURE_SIZE
))
1651 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"DSD Sig is present neither in Flash nor User provided Input..");
1652 up(&Adapter
->NVMRdmWrmLock
);
1653 bcm_kfree(pReadData
);
1657 ulDSDMagicNumInUsrBuff
= ntohl(*(PUINT
)(pReadData
+ stNVMReadWrite
.uiNumBytes
- SIGNATURE_SIZE
));
1658 if(ulDSDMagicNumInUsrBuff
!= DSD_IMAGE_MAGIC_NUMBER
)
1660 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"DSD Sig is present neither in Flash nor User provided Input..");
1661 up(&Adapter
->NVMRdmWrmLock
);
1662 bcm_kfree(pReadData
);
1667 Status
= BeceemNVMWrite(Adapter
, (PUINT
)pReadData
,
1668 stNVMReadWrite
.uiOffset
, stNVMReadWrite
.uiNumBytes
, stNVMReadWrite
.bVerify
);
1669 if(IsFlash2x(Adapter
))
1670 BcmFlash2xWriteSig(Adapter
,Adapter
->eActiveDSD
);
1672 Adapter
->bHeaderChangeAllowed
= FALSE
;
1674 up(&Adapter
->NVMRdmWrmLock
);
1677 if(Status
!= STATUS_SUCCESS
)
1679 bcm_kfree(pReadData
);
1683 do_gettimeofday(&tv1
);
1684 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);
1687 bcm_kfree(pReadData
);
1688 Status
= STATUS_SUCCESS
;
1691 case IOCTL_BCM_FLASH2X_SECTION_READ
:
1694 FLASH2X_READWRITE sFlash2xRead
= {0};
1695 PUCHAR pReadBuff
= NULL
;
1699 UINT ReadOffset
= 0;
1700 PUCHAR OutPutBuff
= NULL
;
1702 if(IsFlash2x(Adapter
) != TRUE
)
1704 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Flash Does not have 2.x map");
1708 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1709 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
1712 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
1716 //Reading FLASH 2.x READ structure
1717 Status
= copy_from_user((PUCHAR
)&sFlash2xRead
, (PUCHAR
)IoBuffer
.InputBuffer
,sizeof(FLASH2X_READWRITE
));
1720 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of Input Buffer failed");
1725 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.Section :%x" ,sFlash2xRead
.Section
);
1726 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.offset :%x" ,sFlash2xRead
.offset
);
1727 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xRead
.numOfBytes
);
1728 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xRead
.bVerify
);
1730 //This was internal to driver for raw read. now it has ben exposed to user space app.
1731 if(validateFlash2xReadWrite(Adapter
,&sFlash2xRead
) == FALSE
)
1732 return STATUS_FAILURE
;
1734 NOB
= sFlash2xRead
.numOfBytes
;
1735 if(NOB
> Adapter
->uiSectorSize
)
1736 BuffSize
= Adapter
->uiSectorSize
;
1740 ReadOffset
= sFlash2xRead
.offset
;
1741 OutPutBuff
= (PUCHAR
)(IoBuffer
.OutputBuffer
) ;
1744 pReadBuff
= (PCHAR
)kzalloc(BuffSize
, GFP_KERNEL
);
1745 if(pReadBuff
== NULL
)
1747 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1750 down(&Adapter
->NVMRdmWrmLock
);
1752 if((Adapter
->IdleMode
== TRUE
) ||
1753 (Adapter
->bShutStatus
==TRUE
) ||
1754 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
1756 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
1757 up(&Adapter
->NVMRdmWrmLock
);
1758 bcm_kfree(pReadBuff
);
1765 if(NOB
> Adapter
->uiSectorSize
)
1766 ReadBytes
= Adapter
->uiSectorSize
;
1771 //Reading the data from Flash 2.x
1773 Status
= BcmFlash2xBulkRead(Adapter
,(PUINT
)pReadBuff
,sFlash2xRead
.Section
,ReadOffset
,ReadBytes
);
1776 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Flash 2x read err with Status :%d", Status
);
1780 BCM_DEBUG_PRINT_BUFFER(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,pReadBuff
, ReadBytes
);
1782 Status
= copy_to_user(OutPutBuff
, pReadBuff
,ReadBytes
);
1785 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Copy to use failed with status :%d", Status
);
1788 NOB
= NOB
- ReadBytes
;
1791 ReadOffset
= ReadOffset
+ ReadBytes
;
1792 OutPutBuff
= OutPutBuff
+ ReadBytes
;
1796 up(&Adapter
->NVMRdmWrmLock
);
1797 bcm_kfree(pReadBuff
);
1801 case IOCTL_BCM_FLASH2X_SECTION_WRITE
:
1803 FLASH2X_READWRITE sFlash2xWrite
= {0};
1804 PUCHAR pWriteBuff
= NULL
;
1805 PUCHAR InputAddr
= NULL
;
1808 UINT WriteOffset
= 0;
1809 UINT WriteBytes
= 0;
1811 if(IsFlash2x(Adapter
) != TRUE
)
1813 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Flash Does not have 2.x map");
1817 //First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite
1818 Adapter
->bAllDSDWriteAllow
= FALSE
;
1821 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1822 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
1825 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
1829 //Reading FLASH 2.x READ structure
1830 Status
= copy_from_user((PCHAR
)&sFlash2xWrite
, (PCHAR
)IoBuffer
.InputBuffer
, sizeof(FLASH2X_READWRITE
));
1833 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Reading of output Buffer from IOCTL buffer fails");
1837 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite
.Section
);
1838 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite
.offset
);
1839 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite
.numOfBytes
);
1840 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite
.bVerify
);
1842 if((sFlash2xWrite
.Section
== ISO_IMAGE1
) ||(sFlash2xWrite
.Section
== ISO_IMAGE2
) ||
1843 (sFlash2xWrite
.Section
== DSD0
) || (sFlash2xWrite
.Section
== DSD1
) || (sFlash2xWrite
.Section
== DSD2
))
1845 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"ISO/DSD Image write is not allowed.... ");
1846 return STATUS_FAILURE
;
1849 if((sFlash2xWrite
.Section
!= VSA0
) && (sFlash2xWrite
.Section
!= VSA1
) &&
1850 (sFlash2xWrite
.Section
!= VSA2
) )
1852 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Only VSA write is allowed");
1856 if(validateFlash2xReadWrite(Adapter
,&sFlash2xWrite
) == FALSE
)
1857 return STATUS_FAILURE
;
1859 InputAddr
= (PCHAR
)(sFlash2xWrite
.pDataBuff
) ;
1860 WriteOffset
= sFlash2xWrite
.offset
;
1861 NOB
= sFlash2xWrite
.numOfBytes
;
1863 if(NOB
> Adapter
->uiSectorSize
)
1864 BuffSize
= Adapter
->uiSectorSize
;
1868 pWriteBuff
= (PCHAR
)kmalloc(BuffSize
, GFP_KERNEL
);
1869 if(pWriteBuff
== NULL
)
1871 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1875 //extracting the remainder of the given offset.
1876 WriteBytes
= Adapter
->uiSectorSize
;
1877 if(WriteOffset
% Adapter
->uiSectorSize
)
1878 WriteBytes
=Adapter
->uiSectorSize
- (WriteOffset
% Adapter
->uiSectorSize
);
1879 if(NOB
< WriteBytes
)
1882 down(&Adapter
->NVMRdmWrmLock
);
1884 if((Adapter
->IdleMode
== TRUE
) ||
1885 (Adapter
->bShutStatus
==TRUE
) ||
1886 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
1888 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
1889 up(&Adapter
->NVMRdmWrmLock
);
1890 bcm_kfree(pWriteBuff
);
1894 BcmFlash2xCorruptSig(Adapter
,sFlash2xWrite
.Section
);
1897 Status
= copy_from_user(pWriteBuff
,InputAddr
,WriteBytes
);
1900 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Copy to user failed with status :%d", Status
);
1903 BCM_DEBUG_PRINT_BUFFER(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,pWriteBuff
,WriteBytes
);
1904 //Writing the data from Flash 2.x
1905 Status
= BcmFlash2xBulkWrite(Adapter
,(PUINT
)pWriteBuff
,sFlash2xWrite
.Section
,WriteOffset
,WriteBytes
,sFlash2xWrite
.bVerify
);
1909 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Flash 2x read err with Status :%d", Status
);
1913 NOB
= NOB
- WriteBytes
;
1916 WriteOffset
= WriteOffset
+ WriteBytes
;
1917 InputAddr
= InputAddr
+ WriteBytes
;
1918 if(NOB
> Adapter
->uiSectorSize
)
1919 WriteBytes
= Adapter
->uiSectorSize
;
1926 BcmFlash2xWriteSig(Adapter
,sFlash2xWrite
.Section
);
1927 up(&Adapter
->NVMRdmWrmLock
);
1928 bcm_kfree(pWriteBuff
);
1931 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP
:
1934 PFLASH2X_BITMAP psFlash2xBitMap
= NULL
;
1935 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1937 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
1940 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
1943 if(IoBuffer
.OutputLength
!= sizeof(FLASH2X_BITMAP
))
1945 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Structure size mismatch Lib :0x%lx Driver :0x%x ",IoBuffer
.OutputLength
, sizeof(FLASH2X_BITMAP
));
1949 psFlash2xBitMap
= (PFLASH2X_BITMAP
)kzalloc(sizeof(FLASH2X_BITMAP
), GFP_KERNEL
);
1950 if(psFlash2xBitMap
== NULL
)
1952 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Memory is not available");
1955 //Reading the Flash Sectio Bit map
1956 down(&Adapter
->NVMRdmWrmLock
);
1958 if((Adapter
->IdleMode
== TRUE
) ||
1959 (Adapter
->bShutStatus
==TRUE
) ||
1960 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
1962 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
1963 up(&Adapter
->NVMRdmWrmLock
);
1964 bcm_kfree(psFlash2xBitMap
);
1968 BcmGetFlash2xSectionalBitMap(Adapter
, psFlash2xBitMap
);
1969 up(&Adapter
->NVMRdmWrmLock
);
1970 Status
= copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
, (PCHAR
)psFlash2xBitMap
, sizeof(FLASH2X_BITMAP
));
1973 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "copying Flash2x bitMap failed");
1974 bcm_kfree(psFlash2xBitMap
);
1977 bcm_kfree(psFlash2xBitMap
);
1980 case IOCTL_BCM_SET_ACTIVE_SECTION
:
1982 FLASH2X_SECTION_VAL eFlash2xSectionVal
= 0;
1983 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1985 if(IsFlash2x(Adapter
) != TRUE
)
1987 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Flash Does not have 2.x map");
1991 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
1994 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
1998 Status
= copy_from_user((PCHAR
)&eFlash2xSectionVal
,(PCHAR
)IoBuffer
.InputBuffer
, sizeof(INT
));
2001 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of flash section val failed");
2005 down(&Adapter
->NVMRdmWrmLock
);
2007 if((Adapter
->IdleMode
== TRUE
) ||
2008 (Adapter
->bShutStatus
==TRUE
) ||
2009 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
2011 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
2012 up(&Adapter
->NVMRdmWrmLock
);
2016 Status
= BcmSetActiveSection(Adapter
,eFlash2xSectionVal
);
2019 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Failed to make it's priority Highest. Status %d", Status
);
2021 up(&Adapter
->NVMRdmWrmLock
);
2024 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION
:
2026 //Right Now we are taking care of only DSD
2027 Adapter
->bAllDSDWriteAllow
= FALSE
;
2028 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
2031 SECTION_TYPE section
= 0 ;
2034 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION Called");
2035 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
2038 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Copy of IOCTL BUFFER failed");
2041 Status
= copy_from_user((PCHAR
)section
,(PCHAR
)&IoBuffer
, sizeof(INT
));
2044 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Copy of section type failed failed");
2047 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Read Section :%d", section
);
2049 Adapter
->ulFlashCalStart
= Adapter
->uiActiveDSDOffsetAtFwDld
;
2051 Status
= STATUS_FAILURE
;
2053 Status
= STATUS_SUCCESS
;
2056 case IOCTL_BCM_COPY_SECTION
:
2058 FLASH2X_COPY_SECTION sCopySectStrut
= {0};
2059 Status
= STATUS_SUCCESS
;
2060 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_COPY_SECTION Called");
2062 Adapter
->bAllDSDWriteAllow
= FALSE
;
2064 if(IsFlash2x(Adapter
) != TRUE
)
2066 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Flash Does not have 2.x map");
2070 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
2073 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status
);
2077 Status
= copy_from_user((PCHAR
)&sCopySectStrut
,(PCHAR
)IoBuffer
.InputBuffer
, sizeof(FLASH2X_COPY_SECTION
));
2080 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status
);
2083 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Source SEction :%x", sCopySectStrut
.SrcSection
);
2084 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Destination SEction :%x", sCopySectStrut
.DstSection
);
2085 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "offset :%x", sCopySectStrut
.offset
);
2086 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "NOB :%x", sCopySectStrut
.numOfBytes
);
2089 if(IsSectionExistInFlash(Adapter
,sCopySectStrut
.SrcSection
) == FALSE
)
2091 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Source Section<%x> does not exixt in Flash ", sCopySectStrut
.SrcSection
);
2095 if(IsSectionExistInFlash(Adapter
,sCopySectStrut
.DstSection
) == FALSE
)
2097 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut
.DstSection
);
2101 if(sCopySectStrut
.SrcSection
== sCopySectStrut
.DstSection
)
2103 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Source and Destination section should be different");
2107 down(&Adapter
->NVMRdmWrmLock
);
2109 if((Adapter
->IdleMode
== TRUE
) ||
2110 (Adapter
->bShutStatus
==TRUE
) ||
2111 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
2113 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
2114 up(&Adapter
->NVMRdmWrmLock
);
2118 if(sCopySectStrut
.SrcSection
== ISO_IMAGE1
|| sCopySectStrut
.SrcSection
== ISO_IMAGE2
)
2120 if(IsNonCDLessDevice(Adapter
))
2122 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Device is Non-CDLess hence won't have ISO !!");
2125 else if(sCopySectStrut
.numOfBytes
== 0)
2127 Status
= BcmCopyISO(Adapter
,sCopySectStrut
);
2131 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Partial Copy of ISO section is not Allowed..");
2132 Status
= STATUS_FAILURE
;
2134 up(&Adapter
->NVMRdmWrmLock
);
2138 Status
= BcmCopySection(Adapter
, sCopySectStrut
.SrcSection
,
2139 sCopySectStrut
.DstSection
,sCopySectStrut
.offset
,sCopySectStrut
.numOfBytes
);
2140 up(&Adapter
->NVMRdmWrmLock
);
2143 case IOCTL_BCM_GET_FLASH_CS_INFO
:
2145 Status
= STATUS_SUCCESS
;
2146 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
2148 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
2151 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
2154 if(Adapter
->eNVMType
!= NVM_FLASH
)
2156 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Connected device does not have flash");
2161 if(IsFlash2x(Adapter
) == TRUE
)
2164 if(IoBuffer
.OutputLength
< sizeof(FLASH2X_CS_INFO
))
2166 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. \nRequired size :0x%x ",IoBuffer
.OutputLength
, sizeof(FLASH2X_CS_INFO
));
2171 Status
= copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
, (PCHAR
)Adapter
->psFlash2xCSInfo
, sizeof(FLASH2X_CS_INFO
));
2174 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "copying Flash2x cs info failed");
2180 if(IoBuffer
.OutputLength
< sizeof(FLASH_CS_INFO
))
2182 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. Required size :0x%u ",IoBuffer
.OutputLength
, sizeof(FLASH_CS_INFO
));
2186 Status
= copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
, (PCHAR
)Adapter
->psFlashCSInfo
, sizeof(FLASH_CS_INFO
));
2189 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "copying Flash CS info failed");
2196 case IOCTL_BCM_SELECT_DSD
:
2199 FLASH2X_SECTION_VAL eFlash2xSectionVal
;
2200 eFlash2xSectionVal
= NO_SECTION_VAL
;
2201 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, " IOCTL_BCM_SELECT_DSD Called");
2203 if(IsFlash2x(Adapter
) != TRUE
)
2205 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Flash Does not have 2.x map");
2209 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
2212 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
2215 Status
= copy_from_user((PCHAR
)&eFlash2xSectionVal
,(PCHAR
)IoBuffer
.InputBuffer
, sizeof(INT
));
2218 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of flash section val failed");
2222 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Read Section :%d", eFlash2xSectionVal
);
2223 if((eFlash2xSectionVal
!= DSD0
) &&
2224 (eFlash2xSectionVal
!= DSD1
) &&
2225 (eFlash2xSectionVal
!= DSD2
) )
2227 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Passed section<%x> is not DSD section", eFlash2xSectionVal
);
2228 return STATUS_FAILURE
;
2231 SectOfset
= BcmGetSectionValStartOffset(Adapter
,eFlash2xSectionVal
);
2232 if(SectOfset
== INVALID_OFFSET
)
2234 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal
);
2238 Adapter
->bAllDSDWriteAllow
= TRUE
;
2240 Adapter
->ulFlashCalStart
= SectOfset
;
2241 Adapter
->eActiveDSD
= eFlash2xSectionVal
;
2243 Status
= STATUS_SUCCESS
;
2246 case IOCTL_BCM_NVM_RAW_READ
:
2249 NVM_READWRITE stNVMRead
= {0};
2253 UINT ReadBytes
= 0 ;
2254 PUCHAR pReadBuff
= NULL
;
2255 PUCHAR OutPutBuff
= NULL
;
2257 if(Adapter
->eNVMType
!= NVM_FLASH
)
2259 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"NVM TYPE is not Flash ");
2263 /* Copy Ioctl Buffer structure */
2264 if(copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
)))
2266 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "copy_from_user 1 failed\n");
2271 if(copy_from_user(&stNVMRead
, (PUCHAR
)IoBuffer
.OutputBuffer
,sizeof(NVM_READWRITE
)))
2277 NOB
= stNVMRead
.uiNumBytes
;
2278 //In Raw-Read max Buff size : 64MB
2280 if(NOB
> DEFAULT_BUFF_SIZE
)
2281 BuffSize
= DEFAULT_BUFF_SIZE
;
2285 ReadOffset
= stNVMRead
.uiOffset
;
2286 OutPutBuff
= (PUCHAR
)(stNVMRead
.pBuffer
) ;
2289 pReadBuff
= (PCHAR
)kzalloc(BuffSize
, GFP_KERNEL
);
2290 if(pReadBuff
== NULL
)
2292 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
2296 down(&Adapter
->NVMRdmWrmLock
);
2298 if((Adapter
->IdleMode
== TRUE
) ||
2299 (Adapter
->bShutStatus
==TRUE
) ||
2300 (Adapter
->bPreparingForLowPowerMode
==TRUE
))
2302 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Device is in Idle/Shutdown Mode\n");
2303 bcm_kfree(pReadBuff
);
2304 up(&Adapter
->NVMRdmWrmLock
);
2308 Adapter
->bFlashRawRead
= TRUE
;
2311 if(NOB
> DEFAULT_BUFF_SIZE
)
2312 ReadBytes
= DEFAULT_BUFF_SIZE
;
2316 //Reading the data from Flash 2.x
2317 Status
= BeceemNVMRead(Adapter
,(PUINT
)pReadBuff
,ReadOffset
,ReadBytes
);
2320 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Flash 2x read err with Status :%d", Status
);
2324 BCM_DEBUG_PRINT_BUFFER(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,pReadBuff
, ReadBytes
);
2326 Status
= copy_to_user(OutPutBuff
, pReadBuff
,ReadBytes
);
2329 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"Copy to use failed with status :%d", Status
);
2332 NOB
= NOB
- ReadBytes
;
2335 ReadOffset
= ReadOffset
+ ReadBytes
;
2336 OutPutBuff
= OutPutBuff
+ ReadBytes
;
2340 Adapter
->bFlashRawRead
= FALSE
;
2341 up(&Adapter
->NVMRdmWrmLock
);
2342 bcm_kfree(pReadBuff
);
2346 case IOCTL_BCM_CNTRLMSG_MASK
:
2348 ULONG RxCntrlMsgBitMask
= 0 ;
2350 /* Copy Ioctl Buffer structure */
2351 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
2354 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"copy of Ioctl buffer is failed from user space");
2358 Status
= copy_from_user(&RxCntrlMsgBitMask
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
);
2361 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"copy of control bit mask failed from user space");
2364 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask
);
2365 pTarang
->RxCntrlMsgBitMask
= RxCntrlMsgBitMask
;
2368 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO
:
2370 DEVICE_DRIVER_INFO DevInfo
;
2372 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2374 memset(&DevInfo
,0,sizeof(DEVICE_DRIVER_INFO
));
2376 DevInfo
.MaxRDMBufferSize
= BUFFER_4K
;
2377 DevInfo
.u32DSDStartOffset
= EEPROM_CALPARAM_START
;
2378 DevInfo
.u32RxAlignmentCorrection
= 0;
2379 DevInfo
.u32NVMType
= Adapter
->eNVMType
;
2382 if(Adapter
->fw_download_done
== TRUE
)
2384 DevInfo
.u32DeviceStatus
= DEV_NOT_IN_RESET
;
2388 DevInfo
.u32DeviceStatus
= DEV_IN_RESET
;
2391 #ifndef BCM_SHM_INTERFACE
2392 DevInfo
.u32InterfaceType
= BCM_USB
;
2395 DevInfo
.u32InterfaceType
= BCM_SHM
;
2397 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
2400 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
2403 if(IoBuffer
.OutputLength
< sizeof(DevInfo
))
2405 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"User Passed buffer length is less than actural buffer size");
2406 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"user passed buffer size :0x%lX, expected size :0x%x",IoBuffer
.OutputLength
, sizeof(DevInfo
));
2410 Status
= copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
, (PCHAR
)&DevInfo
, sizeof(DevInfo
));
2413 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"copying Dev info structure to user space buffer failed");
2419 case IOCTL_BCM_TIME_SINCE_NET_ENTRY
:
2421 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry
= {0};
2422 struct timeval tv
= {0} ;
2424 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2426 Status
= copy_from_user((PCHAR
)&IoBuffer
, (PCHAR
)arg
, sizeof(IOCTL_BUFFER
));
2429 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
2432 if(IoBuffer
.OutputLength
< sizeof(ST_TIME_ELAPSED
))
2434 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"User Passed buffer length:0x%lx is less than expected buff size :0x%X",IoBuffer
.OutputLength
,sizeof(ST_TIME_ELAPSED
));
2439 //stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = Adapter->liTimeSinceLastNetEntry;
2440 do_gettimeofday(&tv
);
2441 stTimeElapsedSinceNetEntry
.ul64TimeElapsedSinceNetEntry
= tv
.tv_sec
- Adapter
->liTimeSinceLastNetEntry
;
2443 Status
= copy_to_user((PCHAR
)IoBuffer
.OutputBuffer
, (PCHAR
)&stTimeElapsedSinceNetEntry
, sizeof(ST_TIME_ELAPSED
));
2446 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0,"copying ST_TIME_ELAPSED structure to user space buffer failed");
2454 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "wrong input %x",cmd
);
2455 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "In default ioctl %d\n", cmd
);
2456 Status
= STATUS_FAILURE
;
2463 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
2464 static INT
bcm_char_unlocked_ioctl(struct file
*filp
,
2465 UINT cmd
, ULONG arg
)
2467 return bcm_char_ioctl(NULL
, filp
, cmd
, arg
);
2471 static struct file_operations bcm_fops
= {
2472 .owner
= THIS_MODULE
,
2473 .open
= bcm_char_open
,
2474 .release
= bcm_char_release
,
2475 .read
= bcm_char_read
,
2476 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
2477 .unlocked_ioctl
= bcm_char_unlocked_ioctl
2479 .ioctl
= bcm_char_ioctl
2484 int register_control_device_interface(PMINI_ADAPTER Adapter
)
2486 if(Adapter
->major
>0)
2487 return Adapter
->major
;
2488 Adapter
->major
= register_chrdev(0, "tarang", &bcm_fops
);
2489 if(Adapter
->major
< 0)
2491 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, DRV_ENTRY
, DBG_LVL_ALL
, "register_chrdev:Failed to registering WiMax control char device!");
2492 return Adapter
->major
;
2496 bcm_class
= class_create (THIS_MODULE
, "tarang");
2497 if(IS_ERR (bcm_class
))
2499 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, DRV_ENTRY
, DBG_LVL_ALL
, "Unable to create class\n");
2500 unregister_chrdev(Adapter
->major
, "tarang");
2504 Adapter
->pstCreatedClassDevice
= device_create (bcm_class
, NULL
,
2505 MKDEV(Adapter
->major
, 0),
2506 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)
2511 if(IS_ERR(Adapter
->pstCreatedClassDevice
))
2513 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, DRV_ENTRY
, DBG_LVL_ALL
, "class device did not get created : %ld", PTR_ERR(Adapter
->pstCreatedClassDevice
) );
2515 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, DRV_ENTRY
, DBG_LVL_ALL
, "Got Major No: %d", Adapter
->major
);
2519 void unregister_control_device_interface(PMINI_ADAPTER Adapter
)
2521 if(Adapter
->major
> 0)
2523 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, DRV_ENTRY
, DBG_LVL_ALL
, "destroying class device");
2524 device_destroy (bcm_class
, MKDEV(Adapter
->major
, 0));
2526 if(!IS_ERR(bcm_class
))
2528 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, DRV_ENTRY
, DBG_LVL_ALL
, "destroying created class ");
2529 class_destroy (bcm_class
);
2532 if(Adapter
->major
> 0)
2534 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, DRV_ENTRY
, DBG_LVL_ALL
,"unregistering character interface");
2535 unregister_chrdev(Adapter
->major
, "tarang");