4 /***************************************************************
5 * Function - bcm_char_open()
7 * Description - This is the "open" entry point for the character
10 * Parameters - inode: Pointer to the Inode structure of char device
11 * filp : File pointer of the char device
13 * Returns - Zero(Success)
14 ****************************************************************/
16 static int bcm_char_open(struct inode
*inode
, struct file
* filp
)
18 struct bcm_mini_adapter
*Adapter
= NULL
;
19 struct bcm_tarang_data
*pTarang
= NULL
;
21 Adapter
= GET_BCM_ADAPTER(gblpnetdev
);
22 pTarang
= kzalloc(sizeof(struct bcm_tarang_data
), GFP_KERNEL
);
26 pTarang
->Adapter
= Adapter
;
27 pTarang
->RxCntrlMsgBitMask
= 0xFFFFFFFF & ~(1 << 0xB);
29 down(&Adapter
->RxAppControlQueuelock
);
30 pTarang
->next
= Adapter
->pTarangs
;
31 Adapter
->pTarangs
= pTarang
;
32 up(&Adapter
->RxAppControlQueuelock
);
34 /* Store the Adapter structure */
35 filp
->private_data
= pTarang
;
37 /* Start Queuing the control response Packets */
38 atomic_inc(&Adapter
->ApplicationRunning
);
40 nonseekable_open(inode
, filp
);
44 static int bcm_char_release(struct inode
*inode
, struct file
*filp
)
46 struct bcm_tarang_data
*pTarang
, *tmp
, *ptmp
;
47 struct bcm_mini_adapter
*Adapter
= NULL
;
48 struct sk_buff
*pkt
, *npkt
;
50 pTarang
= (struct bcm_tarang_data
*)filp
->private_data
;
52 if (pTarang
== NULL
) {
53 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
58 Adapter
= pTarang
->Adapter
;
60 down(&Adapter
->RxAppControlQueuelock
);
62 tmp
= Adapter
->pTarangs
;
63 for (ptmp
= NULL
; tmp
; ptmp
= tmp
, tmp
= tmp
->next
) {
70 Adapter
->pTarangs
= tmp
->next
;
72 ptmp
->next
= tmp
->next
;
74 up(&Adapter
->RxAppControlQueuelock
);
78 pkt
= pTarang
->RxAppControlHead
;
85 up(&Adapter
->RxAppControlQueuelock
);
87 /* Stop Queuing the control response Packets */
88 atomic_dec(&Adapter
->ApplicationRunning
);
92 /* remove this filp from the asynchronously notified filp's */
93 filp
->private_data
= NULL
;
97 static ssize_t
bcm_char_read(struct file
*filp
, char __user
*buf
, size_t size
,
100 struct bcm_tarang_data
*pTarang
= filp
->private_data
;
101 struct bcm_mini_adapter
*Adapter
= pTarang
->Adapter
;
102 struct sk_buff
*Packet
= NULL
;
104 int wait_ret_val
= 0;
105 unsigned long ret
= 0;
107 wait_ret_val
= wait_event_interruptible(Adapter
->process_read_wait_queue
,
108 (pTarang
->RxAppControlHead
||
109 Adapter
->device_removed
));
110 if ((wait_ret_val
== -ERESTARTSYS
)) {
111 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
112 "Exiting as i've been asked to exit!!!\n");
116 if (Adapter
->device_removed
) {
117 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
118 "Device Removed... Killing the Apps...\n");
122 if (FALSE
== Adapter
->fw_download_done
)
125 down(&Adapter
->RxAppControlQueuelock
);
127 if (pTarang
->RxAppControlHead
) {
128 Packet
= pTarang
->RxAppControlHead
;
129 DEQUEUEPACKET(pTarang
->RxAppControlHead
,
130 pTarang
->RxAppControlTail
);
131 pTarang
->AppCtrlQueueLen
--;
134 up(&Adapter
->RxAppControlQueuelock
);
137 PktLen
= Packet
->len
;
138 ret
= copy_to_user(buf
, Packet
->data
,
139 min_t(size_t, PktLen
, size
));
141 dev_kfree_skb(Packet
);
142 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
143 "Returning from copy to user failure\n");
146 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
147 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
148 PktLen
, Packet
, current
->pid
);
149 dev_kfree_skb(Packet
);
152 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "<\n");
156 static long bcm_char_ioctl(struct file
*filp
, UINT cmd
, ULONG arg
)
158 struct bcm_tarang_data
*pTarang
= filp
->private_data
;
159 void __user
*argp
= (void __user
*)arg
;
160 struct bcm_mini_adapter
*Adapter
= pTarang
->Adapter
;
161 INT Status
= STATUS_FAILURE
;
163 IOCTL_BUFFER IoBuffer
;
166 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
);
168 if (_IOC_TYPE(cmd
) != BCM_IOCTL
)
170 if (_IOC_DIR(cmd
) & _IOC_READ
)
171 Status
= !access_ok(VERIFY_WRITE
, argp
, _IOC_SIZE(cmd
));
172 else if (_IOC_DIR(cmd
) & _IOC_WRITE
)
173 Status
= !access_ok(VERIFY_READ
, argp
, _IOC_SIZE(cmd
));
174 else if (_IOC_NONE
== (_IOC_DIR(cmd
) & _IOC_NONE
))
175 Status
= STATUS_SUCCESS
;
180 if (Adapter
->device_removed
)
183 if (FALSE
== Adapter
->fw_download_done
) {
185 case IOCTL_MAC_ADDR_REQ
:
187 case IOCTL_CM_REQUEST
:
188 case IOCTL_SS_INFO_REQ
:
189 case IOCTL_SEND_CONTROL_MESSAGE
:
191 case IOCTL_BCM_GPIO_SET_REQUEST
:
192 case IOCTL_BCM_GPIO_STATUS_REQUEST
:
199 Status
= vendorextnIoctl(Adapter
, cmd
, arg
);
200 if (Status
!= CONTINUE_COMMON_PATH
)
204 /* Rdms for Swin Idle... */
205 case IOCTL_BCM_REGISTER_READ_PRIVATE
: {
206 RDM_BUFFER sRdmBuffer
= {0};
211 /* Copy Ioctl Buffer structure */
212 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
215 if (IoBuffer
.InputLength
> sizeof(sRdmBuffer
))
218 if (copy_from_user(&sRdmBuffer
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
221 if (IoBuffer
.OutputLength
> USHRT_MAX
||
222 IoBuffer
.OutputLength
== 0) {
226 Bufflen
= IoBuffer
.OutputLength
;
227 temp_value
= 4 - (Bufflen
% 4);
228 Bufflen
+= temp_value
% 4;
230 temp_buff
= kmalloc(Bufflen
, GFP_KERNEL
);
234 bytes
= rdmalt(Adapter
, (UINT
)sRdmBuffer
.Register
,
235 (PUINT
)temp_buff
, Bufflen
);
237 Status
= STATUS_SUCCESS
;
238 if (copy_to_user(IoBuffer
.OutputBuffer
, temp_buff
, bytes
)) {
250 case IOCTL_BCM_REGISTER_WRITE_PRIVATE
: {
251 WRM_BUFFER sWrmBuffer
= {0};
253 /* Copy Ioctl Buffer structure */
255 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
258 if (IoBuffer
.InputLength
> sizeof(sWrmBuffer
))
261 /* Get WrmBuffer structure */
262 if (copy_from_user(&sWrmBuffer
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
265 uiTempVar
= sWrmBuffer
.Register
& EEPROM_REJECT_MASK
;
266 if (!((Adapter
->pstargetparams
->m_u32Customize
) & VSG_MODE
) &&
267 ((uiTempVar
== EEPROM_REJECT_REG_1
) ||
268 (uiTempVar
== EEPROM_REJECT_REG_2
) ||
269 (uiTempVar
== EEPROM_REJECT_REG_3
) ||
270 (uiTempVar
== EEPROM_REJECT_REG_4
))) {
272 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
276 Status
= wrmalt(Adapter
, (UINT
)sWrmBuffer
.Register
,
277 (PUINT
)sWrmBuffer
.Data
, sizeof(ULONG
));
279 if (Status
== STATUS_SUCCESS
) {
280 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "WRM Done\n");
282 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "WRM Failed\n");
288 case IOCTL_BCM_REGISTER_READ
:
289 case IOCTL_BCM_EEPROM_REGISTER_READ
: {
290 RDM_BUFFER sRdmBuffer
= {0};
291 PCHAR temp_buff
= NULL
;
293 if ((Adapter
->IdleMode
== TRUE
) ||
294 (Adapter
->bShutStatus
== TRUE
) ||
295 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
297 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
301 /* Copy Ioctl Buffer structure */
302 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
305 if (IoBuffer
.InputLength
> sizeof(sRdmBuffer
))
308 if (copy_from_user(&sRdmBuffer
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
311 if (IoBuffer
.OutputLength
> USHRT_MAX
||
312 IoBuffer
.OutputLength
== 0) {
316 temp_buff
= kmalloc(IoBuffer
.OutputLength
, GFP_KERNEL
);
318 return STATUS_FAILURE
;
320 if ((((ULONG
)sRdmBuffer
.Register
& 0x0F000000) != 0x0F000000) ||
321 ((ULONG
)sRdmBuffer
.Register
& 0x3)) {
323 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
324 (int)sRdmBuffer
.Register
);
330 uiTempVar
= sRdmBuffer
.Register
& EEPROM_REJECT_MASK
;
331 bytes
= rdmaltWithLock(Adapter
, (UINT
)sRdmBuffer
.Register
, (PUINT
)temp_buff
, IoBuffer
.OutputLength
);
334 Status
= STATUS_SUCCESS
;
335 if (copy_to_user(IoBuffer
.OutputBuffer
, temp_buff
, bytes
)) {
346 case IOCTL_BCM_REGISTER_WRITE
:
347 case IOCTL_BCM_EEPROM_REGISTER_WRITE
: {
348 WRM_BUFFER sWrmBuffer
= {0};
350 if ((Adapter
->IdleMode
== TRUE
) ||
351 (Adapter
->bShutStatus
== TRUE
) ||
352 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
354 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
358 /* Copy Ioctl Buffer structure */
359 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
362 if (IoBuffer
.InputLength
> sizeof(sWrmBuffer
))
365 /* Get WrmBuffer structure */
366 if (copy_from_user(&sWrmBuffer
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
369 if ((((ULONG
)sWrmBuffer
.Register
& 0x0F000000) != 0x0F000000) ||
370 ((ULONG
)sWrmBuffer
.Register
& 0x3)) {
372 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)sWrmBuffer
.Register
);
376 uiTempVar
= sWrmBuffer
.Register
& EEPROM_REJECT_MASK
;
377 if (!((Adapter
->pstargetparams
->m_u32Customize
) & VSG_MODE
) &&
378 ((uiTempVar
== EEPROM_REJECT_REG_1
) ||
379 (uiTempVar
== EEPROM_REJECT_REG_2
) ||
380 (uiTempVar
== EEPROM_REJECT_REG_3
) ||
381 (uiTempVar
== EEPROM_REJECT_REG_4
)) &&
382 (cmd
== IOCTL_BCM_REGISTER_WRITE
)) {
384 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
388 Status
= wrmaltWithLock(Adapter
, (UINT
)sWrmBuffer
.Register
,
389 (PUINT
)sWrmBuffer
.Data
, sWrmBuffer
.Length
);
391 if (Status
== STATUS_SUCCESS
) {
392 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, OSAL_DBG
, DBG_LVL_ALL
, "WRM Done\n");
394 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "WRM Failed\n");
399 case IOCTL_BCM_GPIO_SET_REQUEST
: {
400 UCHAR ucResetValue
[4];
403 UINT uiOperation
= 0;
405 GPIO_INFO gpio_info
= {0};
406 if ((Adapter
->IdleMode
== TRUE
) ||
407 (Adapter
->bShutStatus
== TRUE
) ||
408 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
410 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "GPIO Can't be set/clear in Low power Mode");
414 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
417 if (IoBuffer
.InputLength
> sizeof(gpio_info
))
420 if (copy_from_user(&gpio_info
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
423 uiBit
= gpio_info
.uiGpioNumber
;
424 uiOperation
= gpio_info
.uiGpioValue
;
427 if (IsReqGpioIsLedInNVM(Adapter
, value
) == FALSE
) {
428 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!", value
);
433 /* Set - setting 1 */
435 /* Set the gpio output register */
436 Status
= wrmaltWithLock(Adapter
, BCM_GPIO_OUTPUT_SET_REG
, (PUINT
)(&value
), sizeof(UINT
));
438 if (Status
== STATUS_SUCCESS
) {
439 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Set the GPIO bit\n");
441 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Failed to set the %dth GPIO\n", uiBit
);
445 /* Set the gpio output register */
446 Status
= wrmaltWithLock(Adapter
, BCM_GPIO_OUTPUT_CLR_REG
, (PUINT
)(&value
), sizeof(UINT
));
448 if (Status
== STATUS_SUCCESS
) {
449 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Set the GPIO bit\n");
451 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Failed to clear the %dth GPIO\n", uiBit
);
456 bytes
= rdmaltWithLock(Adapter
, (UINT
)GPIO_MODE_REGISTER
, (PUINT
)ucResetValue
, sizeof(UINT
));
459 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
460 "GPIO_MODE_REGISTER read failed");
463 Status
= STATUS_SUCCESS
;
466 /* Set the gpio mode register to output */
467 *(UINT
*)ucResetValue
|= (1<<uiBit
);
468 Status
= wrmaltWithLock(Adapter
, GPIO_MODE_REGISTER
,
469 (PUINT
)ucResetValue
, sizeof(UINT
));
471 if (Status
== STATUS_SUCCESS
) {
472 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Set the GPIO to output Mode\n");
474 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Failed to put GPIO in Output Mode\n");
480 case BCM_LED_THREAD_STATE_CHANGE_REQ
: {
481 USER_THREAD_REQ threadReq
= {0};
482 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "User made LED thread InActive");
484 if ((Adapter
->IdleMode
== TRUE
) ||
485 (Adapter
->bShutStatus
== TRUE
) ||
486 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
488 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(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
496 if (IoBuffer
.InputLength
> sizeof(threadReq
))
499 if (copy_from_user(&threadReq
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
502 /* if LED thread is running(Actively or Inactively) set it state to make inactive */
503 if (Adapter
->LEDInfo
.led_thread_running
) {
504 if (threadReq
.ThreadState
== LED_THREAD_ACTIVATION_REQ
) {
505 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Activating thread req");
506 Adapter
->DriverState
= LED_THREAD_ACTIVE
;
508 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "DeActivating Thread req.....");
509 Adapter
->DriverState
= LED_THREAD_INACTIVE
;
513 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
518 case IOCTL_BCM_GPIO_STATUS_REQUEST
: {
521 GPIO_INFO gpio_info
= {0};
523 if ((Adapter
->IdleMode
== TRUE
) ||
524 (Adapter
->bShutStatus
== TRUE
) ||
525 (Adapter
->bPreparingForLowPowerMode
== TRUE
))
528 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
531 if (IoBuffer
.InputLength
> sizeof(gpio_info
))
534 if (copy_from_user(&gpio_info
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
537 uiBit
= gpio_info
.uiGpioNumber
;
539 /* Set the gpio output register */
540 bytes
= rdmaltWithLock(Adapter
, (UINT
)GPIO_PIN_STATE_REGISTER
,
541 (PUINT
)ucRead
, sizeof(UINT
));
545 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "RDM Failed\n");
548 Status
= STATUS_SUCCESS
;
553 case IOCTL_BCM_GPIO_MULTI_REQUEST
: {
554 UCHAR ucResetValue
[4];
555 GPIO_MULTI_INFO gpio_multi_info
[MAX_IDX
];
556 PGPIO_MULTI_INFO pgpio_multi_info
= (PGPIO_MULTI_INFO
)gpio_multi_info
;
558 memset(pgpio_multi_info
, 0, MAX_IDX
* sizeof(GPIO_MULTI_INFO
));
560 if ((Adapter
->IdleMode
== TRUE
) ||
561 (Adapter
->bShutStatus
== TRUE
) ||
562 (Adapter
->bPreparingForLowPowerMode
== TRUE
))
565 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
568 if (IoBuffer
.InputLength
> sizeof(gpio_multi_info
))
571 if (copy_from_user(&gpio_multi_info
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
574 if (IsReqGpioIsLedInNVM(Adapter
, pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
) == FALSE
) {
575 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
576 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
577 pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
, Adapter
->gpioBitMap
);
582 /* Set the gpio output register */
583 if ((pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
) &
584 (pgpio_multi_info
[WIMAX_IDX
].uiGPIOCommand
)) {
585 /* Set 1's in GPIO OUTPUT REGISTER */
586 *(UINT
*)ucResetValue
= pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
&
587 pgpio_multi_info
[WIMAX_IDX
].uiGPIOCommand
&
588 pgpio_multi_info
[WIMAX_IDX
].uiGPIOValue
;
590 if (*(UINT
*) ucResetValue
)
591 Status
= wrmaltWithLock(Adapter
, BCM_GPIO_OUTPUT_SET_REG
,
592 (PUINT
)ucResetValue
, sizeof(ULONG
));
594 if (Status
!= STATUS_SUCCESS
) {
595 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
599 /* Clear to 0's in GPIO OUTPUT REGISTER */
600 *(UINT
*)ucResetValue
= (pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
&
601 pgpio_multi_info
[WIMAX_IDX
].uiGPIOCommand
&
602 (~(pgpio_multi_info
[WIMAX_IDX
].uiGPIOValue
)));
604 if (*(UINT
*) ucResetValue
)
605 Status
= wrmaltWithLock(Adapter
, BCM_GPIO_OUTPUT_CLR_REG
, (PUINT
)ucResetValue
, sizeof(ULONG
));
607 if (Status
!= STATUS_SUCCESS
) {
608 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
613 if (pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
) {
614 bytes
= rdmaltWithLock(Adapter
, (UINT
)GPIO_PIN_STATE_REGISTER
, (PUINT
)ucResetValue
, sizeof(UINT
));
618 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "RDM to GPIO_PIN_STATE_REGISTER Failed.");
621 Status
= STATUS_SUCCESS
;
624 pgpio_multi_info
[WIMAX_IDX
].uiGPIOValue
= (*(UINT
*)ucResetValue
&
625 pgpio_multi_info
[WIMAX_IDX
].uiGPIOMask
);
628 Status
= copy_to_user(IoBuffer
.OutputBuffer
, &gpio_multi_info
, IoBuffer
.OutputLength
);
630 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
631 "Failed while copying Content to IOBufer for user space err:%d", Status
);
637 case IOCTL_BCM_GPIO_MODE_REQUEST
: {
638 UCHAR ucResetValue
[4];
639 GPIO_MULTI_MODE gpio_multi_mode
[MAX_IDX
];
640 PGPIO_MULTI_MODE pgpio_multi_mode
= (PGPIO_MULTI_MODE
)gpio_multi_mode
;
642 if ((Adapter
->IdleMode
== TRUE
) ||
643 (Adapter
->bShutStatus
== TRUE
) ||
644 (Adapter
->bPreparingForLowPowerMode
== TRUE
))
647 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
650 if (IoBuffer
.InputLength
> sizeof(gpio_multi_mode
))
653 if (copy_from_user(&gpio_multi_mode
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
))
656 bytes
= rdmaltWithLock(Adapter
, (UINT
)GPIO_MODE_REGISTER
, (PUINT
)ucResetValue
, sizeof(UINT
));
660 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Read of GPIO_MODE_REGISTER failed");
663 Status
= STATUS_SUCCESS
;
666 /* Validating the request */
667 if (IsReqGpioIsLedInNVM(Adapter
, pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
) == FALSE
) {
668 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
669 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
670 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
, Adapter
->gpioBitMap
);
675 if (pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
) {
676 /* write all OUT's (1's) */
677 *(UINT
*) ucResetValue
|= (pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
&
678 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
);
680 /* write all IN's (0's) */
681 *(UINT
*) ucResetValue
&= ~((~pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
) &
682 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMask
);
684 /* Currently implemented return the modes of all GPIO's
685 * else needs to bit AND with mask
687 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
= *(UINT
*)ucResetValue
;
689 Status
= wrmaltWithLock(Adapter
, GPIO_MODE_REGISTER
, (PUINT
)ucResetValue
, sizeof(ULONG
));
690 if (Status
== STATUS_SUCCESS
) {
691 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
692 "WRM to GPIO_MODE_REGISTER Done");
694 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
695 "WRM to GPIO_MODE_REGISTER Failed");
700 /* if uiGPIOMask is 0 then return mode register configuration */
701 pgpio_multi_mode
[WIMAX_IDX
].uiGPIOMode
= *(UINT
*)ucResetValue
;
704 Status
= copy_to_user(IoBuffer
.OutputBuffer
, &gpio_multi_mode
, IoBuffer
.OutputLength
);
706 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
707 "Failed while copying Content to IOBufer for user space err:%d", Status
);
713 case IOCTL_MAC_ADDR_REQ
:
715 case IOCTL_CM_REQUEST
:
716 case IOCTL_SS_INFO_REQ
:
717 case IOCTL_SEND_CONTROL_MESSAGE
:
718 case IOCTL_IDLE_REQ
: {
719 PVOID pvBuffer
= NULL
;
721 /* Copy Ioctl Buffer structure */
722 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
725 if (IoBuffer
.InputLength
< sizeof(struct bcm_link_request
))
728 if (IoBuffer
.InputLength
> MAX_CNTL_PKT_SIZE
)
731 pvBuffer
= memdup_user(IoBuffer
.InputBuffer
,
732 IoBuffer
.InputLength
);
733 if (IS_ERR(pvBuffer
))
734 return PTR_ERR(pvBuffer
);
736 down(&Adapter
->LowPowerModeSync
);
737 Status
= wait_event_interruptible_timeout(Adapter
->lowpower_mode_wait_queue
,
738 !Adapter
->bPreparingForLowPowerMode
,
740 if (Status
== -ERESTARTSYS
)
743 if (Adapter
->bPreparingForLowPowerMode
) {
744 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
745 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
746 Status
= STATUS_FAILURE
;
749 Status
= CopyBufferToControlPacket(Adapter
, (PVOID
)pvBuffer
);
752 up(&Adapter
->LowPowerModeSync
);
757 case IOCTL_BCM_BUFFER_DOWNLOAD_START
: {
758 if (down_trylock(&Adapter
->NVMRdmWrmLock
)) {
759 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
,
760 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
764 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
765 "Starting the firmware download PID =0x%x!!!!\n", current
->pid
);
767 if (down_trylock(&Adapter
->fw_download_sema
))
770 Adapter
->bBinDownloaded
= FALSE
;
771 Adapter
->fw_download_process_pid
= current
->pid
;
772 Adapter
->bCfgDownloaded
= FALSE
;
773 Adapter
->fw_download_done
= FALSE
;
774 netif_carrier_off(Adapter
->dev
);
775 netif_stop_queue(Adapter
->dev
);
776 Status
= reset_card_proc(Adapter
);
778 pr_err(PFX
"%s: reset_card_proc Failed!\n", Adapter
->dev
->name
);
779 up(&Adapter
->fw_download_sema
);
780 up(&Adapter
->NVMRdmWrmLock
);
785 up(&Adapter
->NVMRdmWrmLock
);
789 case IOCTL_BCM_BUFFER_DOWNLOAD
: {
790 struct bcm_firmware_info
*psFwInfo
= NULL
;
791 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current
->pid
);
793 if (!down_trylock(&Adapter
->fw_download_sema
)) {
794 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
795 "Invalid way to download buffer. Use Start and then call this!!!\n");
796 up(&Adapter
->fw_download_sema
);
801 /* Copy Ioctl Buffer structure */
802 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
))) {
803 up(&Adapter
->fw_download_sema
);
807 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
808 "Length for FW DLD is : %lx\n", IoBuffer
.InputLength
);
810 if (IoBuffer
.InputLength
> sizeof(struct bcm_firmware_info
)) {
811 up(&Adapter
->fw_download_sema
);
815 psFwInfo
= kmalloc(sizeof(*psFwInfo
), GFP_KERNEL
);
817 up(&Adapter
->fw_download_sema
);
821 if (copy_from_user(psFwInfo
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
)) {
822 up(&Adapter
->fw_download_sema
);
826 if (!psFwInfo
->pvMappedFirmwareAddress
||
827 (psFwInfo
->u32FirmwareLength
== 0)) {
829 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Something else is wrong %lu\n",
830 psFwInfo
->u32FirmwareLength
);
831 up(&Adapter
->fw_download_sema
);
836 Status
= bcm_ioctl_fw_download(Adapter
, psFwInfo
);
838 if (Status
!= STATUS_SUCCESS
) {
839 if (psFwInfo
->u32StartingAddress
== CONFIG_BEGIN_ADDR
)
840 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "IOCTL: Configuration File Upload Failed\n");
842 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "IOCTL: Firmware File Upload Failed\n");
844 /* up(&Adapter->fw_download_sema); */
846 if (Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
) {
847 Adapter
->DriverState
= DRIVER_INIT
;
848 Adapter
->LEDInfo
.bLedInitDone
= FALSE
;
849 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
853 if (Status
!= STATUS_SUCCESS
)
854 up(&Adapter
->fw_download_sema
);
856 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL: Firmware File Uploaded\n");
861 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP
: {
862 if (!down_trylock(&Adapter
->fw_download_sema
)) {
863 up(&Adapter
->fw_download_sema
);
867 if (down_trylock(&Adapter
->NVMRdmWrmLock
)) {
868 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
869 "FW download blocked as EEPROM Read/Write is in progress\n");
870 up(&Adapter
->fw_download_sema
);
874 Adapter
->bBinDownloaded
= TRUE
;
875 Adapter
->bCfgDownloaded
= TRUE
;
876 atomic_set(&Adapter
->CurrNumFreeTxDesc
, 0);
877 Adapter
->CurrNumRecvDescs
= 0;
878 Adapter
->downloadDDR
= 0;
880 /* setting the Mips to Run */
881 Status
= run_card_proc(Adapter
);
884 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Firm Download Failed\n");
885 up(&Adapter
->fw_download_sema
);
886 up(&Adapter
->NVMRdmWrmLock
);
889 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
,
890 DBG_LVL_ALL
, "Firm Download Over...\n");
895 /* Wait for MailBox Interrupt */
896 if (StartInterruptUrb((PS_INTERFACE_ADAPTER
)Adapter
->pvInterfaceAdapter
))
897 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Unable to send interrupt...\n");
900 Adapter
->waiting_to_fw_download_done
= FALSE
;
901 wait_event_timeout(Adapter
->ioctl_fw_dnld_wait_queue
,
902 Adapter
->waiting_to_fw_download_done
, timeout
);
903 Adapter
->fw_download_process_pid
= INVALID_PID
;
904 Adapter
->fw_download_done
= TRUE
;
905 atomic_set(&Adapter
->CurrNumFreeTxDesc
, 0);
906 Adapter
->CurrNumRecvDescs
= 0;
907 Adapter
->PrevNumRecvDescs
= 0;
908 atomic_set(&Adapter
->cntrlpktCnt
, 0);
909 Adapter
->LinkUpStatus
= 0;
910 Adapter
->LinkStatus
= 0;
912 if (Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
) {
913 Adapter
->DriverState
= FW_DOWNLOAD_DONE
;
914 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
920 up(&Adapter
->fw_download_sema
);
921 up(&Adapter
->NVMRdmWrmLock
);
925 case IOCTL_BE_BUCKET_SIZE
:
927 if (get_user(Adapter
->BEBucketSize
, (unsigned long __user
*)arg
))
931 case IOCTL_RTPS_BUCKET_SIZE
:
933 if (get_user(Adapter
->rtPSBucketSize
, (unsigned long __user
*)arg
))
937 case IOCTL_CHIP_RESET
: {
938 INT NVMAccess
= down_trylock(&Adapter
->NVMRdmWrmLock
);
940 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
944 down(&Adapter
->RxAppControlQueuelock
);
945 Status
= reset_card_proc(Adapter
);
947 up(&Adapter
->RxAppControlQueuelock
);
948 up(&Adapter
->NVMRdmWrmLock
);
949 ResetCounters(Adapter
);
953 case IOCTL_QOS_THRESHOLD
: {
957 for (uiLoopIndex
= 0; uiLoopIndex
< NO_OF_QUEUES
; uiLoopIndex
++) {
958 if (get_user(Adapter
->PackInfo
[uiLoopIndex
].uiThreshold
,
959 (unsigned long __user
*)arg
)) {
967 case IOCTL_DUMP_PACKET_INFO
:
968 DumpPackInfo(Adapter
);
969 DumpPhsRules(&Adapter
->stBCMPhsContext
);
970 Status
= STATUS_SUCCESS
;
973 case IOCTL_GET_PACK_INFO
:
974 if (copy_to_user(argp
, &Adapter
->PackInfo
, sizeof(struct bcm_packet_info
)*NO_OF_QUEUES
))
976 Status
= STATUS_SUCCESS
;
979 case IOCTL_BCM_SWITCH_TRANSFER_MODE
: {
981 if (copy_from_user(&uiData
, argp
, sizeof(UINT
)))
985 /* Allow All Packets */
986 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
987 Adapter
->TransferMode
= ETH_PACKET_TUNNELING_MODE
;
989 /* Allow IP only Packets */
990 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
991 Adapter
->TransferMode
= IP_PACKET_ONLY_MODE
;
993 Status
= STATUS_SUCCESS
;
997 case IOCTL_BCM_GET_DRIVER_VERSION
: {
1000 /* Copy Ioctl Buffer structure */
1001 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1004 len
= min_t(ulong
, IoBuffer
.OutputLength
, strlen(VER_FILEVERSION_STR
) + 1);
1006 if (copy_to_user(IoBuffer
.OutputBuffer
, VER_FILEVERSION_STR
, len
))
1008 Status
= STATUS_SUCCESS
;
1012 case IOCTL_BCM_GET_CURRENT_STATUS
: {
1013 LINK_STATE link_state
;
1015 /* Copy Ioctl Buffer structure */
1016 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
))) {
1017 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "copy_from_user failed..\n");
1021 if (IoBuffer
.OutputLength
!= sizeof(link_state
)) {
1026 memset(&link_state
, 0, sizeof(link_state
));
1027 link_state
.bIdleMode
= Adapter
->IdleMode
;
1028 link_state
.bShutdownMode
= Adapter
->bShutStatus
;
1029 link_state
.ucLinkStatus
= Adapter
->LinkStatus
;
1031 if (copy_to_user(IoBuffer
.OutputBuffer
, &link_state
, min_t(size_t, sizeof(link_state
), IoBuffer
.OutputLength
))) {
1032 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy_to_user Failed..\n");
1035 Status
= STATUS_SUCCESS
;
1039 case IOCTL_BCM_SET_MAC_TRACING
: {
1042 /* copy ioctl Buffer structure */
1043 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1046 if (copy_from_user(&tracing_flag
, IoBuffer
.InputBuffer
, sizeof(UINT
)))
1050 Adapter
->pTarangs
->MacTracingEnabled
= TRUE
;
1052 Adapter
->pTarangs
->MacTracingEnabled
= FALSE
;
1056 case IOCTL_BCM_GET_DSX_INDICATION
: {
1058 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1061 if (IoBuffer
.OutputLength
< sizeof(stLocalSFAddIndicationAlt
)) {
1062 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
1063 "Mismatch req: %lx needed is =0x%zx!!!",
1064 IoBuffer
.OutputLength
, sizeof(stLocalSFAddIndicationAlt
));
1068 if (copy_from_user(&ulSFId
, IoBuffer
.InputBuffer
, sizeof(ulSFId
)))
1071 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Get DSX Data SF ID is =%lx\n", ulSFId
);
1072 get_dsx_sf_data_to_application(Adapter
, ulSFId
, IoBuffer
.OutputBuffer
);
1073 Status
= STATUS_SUCCESS
;
1077 case IOCTL_BCM_GET_HOST_MIBS
: {
1080 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1083 if (IoBuffer
.OutputLength
!= sizeof(S_MIBS_HOST_STATS_MIBS
)) {
1084 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0,
1085 "Length Check failed %lu %zd\n",
1086 IoBuffer
.OutputLength
, sizeof(S_MIBS_HOST_STATS_MIBS
));
1090 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1091 temp_buff
= kzalloc(sizeof(S_MIBS_HOST_STATS_MIBS
), GFP_KERNEL
);
1093 return STATUS_FAILURE
;
1095 Status
= ProcessGetHostMibs(Adapter
, temp_buff
);
1096 GetDroppedAppCntrlPktMibs(temp_buff
, pTarang
);
1098 if (Status
!= STATUS_FAILURE
)
1099 if (copy_to_user(IoBuffer
.OutputBuffer
, temp_buff
, sizeof(S_MIBS_HOST_STATS_MIBS
))) {
1108 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE
:
1109 if ((FALSE
== Adapter
->bTriedToWakeUpFromlowPowerMode
) && (TRUE
== Adapter
->IdleMode
)) {
1110 Adapter
->usIdleModePattern
= ABORT_IDLE_MODE
;
1111 Adapter
->bWakeUpDevice
= TRUE
;
1112 wake_up(&Adapter
->process_rx_cntrlpkt
);
1115 Status
= STATUS_SUCCESS
;
1118 case IOCTL_BCM_BULK_WRM
: {
1119 PBULKWRM_BUFFER pBulkBuffer
;
1121 PCHAR pvBuffer
= NULL
;
1123 if ((Adapter
->IdleMode
== TRUE
) ||
1124 (Adapter
->bShutStatus
== TRUE
) ||
1125 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1127 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1132 /* Copy Ioctl Buffer structure */
1133 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1136 if (IoBuffer
.InputLength
< sizeof(ULONG
) * 2)
1139 pvBuffer
= memdup_user(IoBuffer
.InputBuffer
,
1140 IoBuffer
.InputLength
);
1141 if (IS_ERR(pvBuffer
))
1142 return PTR_ERR(pvBuffer
);
1144 pBulkBuffer
= (PBULKWRM_BUFFER
)pvBuffer
;
1146 if (((ULONG
)pBulkBuffer
->Register
& 0x0F000000) != 0x0F000000 ||
1147 ((ULONG
)pBulkBuffer
->Register
& 0x3)) {
1149 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer
->Register
);
1154 uiTempVar
= pBulkBuffer
->Register
& EEPROM_REJECT_MASK
;
1155 if (!((Adapter
->pstargetparams
->m_u32Customize
)&VSG_MODE
) &&
1156 ((uiTempVar
== EEPROM_REJECT_REG_1
) ||
1157 (uiTempVar
== EEPROM_REJECT_REG_2
) ||
1158 (uiTempVar
== EEPROM_REJECT_REG_3
) ||
1159 (uiTempVar
== EEPROM_REJECT_REG_4
)) &&
1160 (cmd
== IOCTL_BCM_REGISTER_WRITE
)) {
1163 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
1168 if (pBulkBuffer
->SwapEndian
== FALSE
)
1169 Status
= wrmWithLock(Adapter
, (UINT
)pBulkBuffer
->Register
, (PCHAR
)pBulkBuffer
->Values
, IoBuffer
.InputLength
- 2*sizeof(ULONG
));
1171 Status
= wrmaltWithLock(Adapter
, (UINT
)pBulkBuffer
->Register
, (PUINT
)pBulkBuffer
->Values
, IoBuffer
.InputLength
- 2*sizeof(ULONG
));
1173 if (Status
!= STATUS_SUCCESS
)
1174 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "WRM Failed\n");
1180 case IOCTL_BCM_GET_NVM_SIZE
:
1181 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1184 if (Adapter
->eNVMType
== NVM_EEPROM
|| Adapter
->eNVMType
== NVM_FLASH
) {
1185 if (copy_to_user(IoBuffer
.OutputBuffer
, &Adapter
->uiNVMDSDSize
, sizeof(UINT
)))
1189 Status
= STATUS_SUCCESS
;
1192 case IOCTL_BCM_CAL_INIT
: {
1193 UINT uiSectorSize
= 0 ;
1194 if (Adapter
->eNVMType
== NVM_FLASH
) {
1195 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1198 if (copy_from_user(&uiSectorSize
, IoBuffer
.InputBuffer
, sizeof(UINT
)))
1201 if ((uiSectorSize
< MIN_SECTOR_SIZE
) || (uiSectorSize
> MAX_SECTOR_SIZE
)) {
1202 if (copy_to_user(IoBuffer
.OutputBuffer
, &Adapter
->uiSectorSize
,
1206 if (IsFlash2x(Adapter
)) {
1207 if (copy_to_user(IoBuffer
.OutputBuffer
, &Adapter
->uiSectorSize
, sizeof(UINT
)))
1210 if ((TRUE
== Adapter
->bShutStatus
) || (TRUE
== Adapter
->IdleMode
)) {
1211 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device is in Idle/Shutdown Mode\n");
1215 Adapter
->uiSectorSize
= uiSectorSize
;
1216 BcmUpdateSectorSize(Adapter
, Adapter
->uiSectorSize
);
1219 Status
= STATUS_SUCCESS
;
1221 Status
= STATUS_FAILURE
;
1226 case IOCTL_BCM_SET_DEBUG
:
1229 USER_BCM_DBG_STATE sUserDebugState
;
1231 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "In SET_DEBUG ioctl\n");
1232 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1235 if (copy_from_user(&sUserDebugState
, IoBuffer
.InputBuffer
, sizeof(USER_BCM_DBG_STATE
)))
1238 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1239 sUserDebugState
.OnOff
, sUserDebugState
.Type
);
1240 /* sUserDebugState.Subtype <<= 1; */
1241 sUserDebugState
.Subtype
= 1 << sUserDebugState
.Subtype
;
1242 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_PRINTK
, 0, 0, "actual Subtype=0x%x\n", sUserDebugState
.Subtype
);
1244 /* Update new 'DebugState' in the Adapter */
1245 Adapter
->stDebugState
.type
|= sUserDebugState
.Type
;
1246 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1247 * Valid indexes in 'subtype' array: 1,2,4,8
1248 * corresponding to valid Type values. Hence we can use the 'Type' field
1249 * as the index value, ignoring the array entries 0,3,5,6,7 !
1251 if (sUserDebugState
.OnOff
)
1252 Adapter
->stDebugState
.subtype
[sUserDebugState
.Type
] |= sUserDebugState
.Subtype
;
1254 Adapter
->stDebugState
.subtype
[sUserDebugState
.Type
] &= ~sUserDebugState
.Subtype
;
1256 BCM_SHOW_DEBUG_BITMAP(Adapter
);
1261 case IOCTL_BCM_NVM_READ
:
1262 case IOCTL_BCM_NVM_WRITE
: {
1263 NVM_READWRITE stNVMReadWrite
;
1264 PUCHAR pReadData
= NULL
;
1265 ULONG ulDSDMagicNumInUsrBuff
= 0;
1266 struct timeval tv0
, tv1
;
1267 memset(&tv0
, 0, sizeof(struct timeval
));
1268 memset(&tv1
, 0, sizeof(struct timeval
));
1269 if ((Adapter
->eNVMType
== NVM_FLASH
) && (Adapter
->uiFlashLayoutMajorVersion
== 0)) {
1270 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1274 if (IsFlash2x(Adapter
)) {
1275 if ((Adapter
->eActiveDSD
!= DSD0
) &&
1276 (Adapter
->eActiveDSD
!= DSD1
) &&
1277 (Adapter
->eActiveDSD
!= DSD2
)) {
1279 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "No DSD is active..hence NVM Command is blocked");
1280 return STATUS_FAILURE
;
1284 /* Copy Ioctl Buffer structure */
1285 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1288 if (copy_from_user(&stNVMReadWrite
,
1289 (IOCTL_BCM_NVM_READ
== cmd
) ? IoBuffer
.OutputBuffer
: IoBuffer
.InputBuffer
,
1290 sizeof(NVM_READWRITE
)))
1294 * Deny the access if the offset crosses the cal area limit.
1296 if (stNVMReadWrite
.uiNumBytes
> Adapter
->uiNVMDSDSize
)
1297 return STATUS_FAILURE
;
1299 if (stNVMReadWrite
.uiOffset
> Adapter
->uiNVMDSDSize
- stNVMReadWrite
.uiNumBytes
) {
1300 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes); */
1301 return STATUS_FAILURE
;
1304 pReadData
= memdup_user(stNVMReadWrite
.pBuffer
,
1305 stNVMReadWrite
.uiNumBytes
);
1306 if (IS_ERR(pReadData
))
1307 return PTR_ERR(pReadData
);
1309 do_gettimeofday(&tv0
);
1310 if (IOCTL_BCM_NVM_READ
== cmd
) {
1311 down(&Adapter
->NVMRdmWrmLock
);
1313 if ((Adapter
->IdleMode
== TRUE
) ||
1314 (Adapter
->bShutStatus
== TRUE
) ||
1315 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1317 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device is in Idle/Shutdown Mode\n");
1318 up(&Adapter
->NVMRdmWrmLock
);
1323 Status
= BeceemNVMRead(Adapter
, (PUINT
)pReadData
, stNVMReadWrite
.uiOffset
, stNVMReadWrite
.uiNumBytes
);
1324 up(&Adapter
->NVMRdmWrmLock
);
1326 if (Status
!= STATUS_SUCCESS
) {
1331 if (copy_to_user(stNVMReadWrite
.pBuffer
, pReadData
, stNVMReadWrite
.uiNumBytes
)) {
1336 down(&Adapter
->NVMRdmWrmLock
);
1338 if ((Adapter
->IdleMode
== TRUE
) ||
1339 (Adapter
->bShutStatus
== TRUE
) ||
1340 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1342 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device is in Idle/Shutdown Mode\n");
1343 up(&Adapter
->NVMRdmWrmLock
);
1348 Adapter
->bHeaderChangeAllowed
= TRUE
;
1349 if (IsFlash2x(Adapter
)) {
1352 * DSD section updation will be allowed in two case:-
1353 * 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1354 * 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1355 * corrupted then user space program first modify the DSD header with valid DSD sig so
1356 * that this as well as further write may be worthwhile.
1358 * This restriction has been put assuming that if DSD sig is corrupted, DSD
1359 * data won't be considered valid.
1362 Status
= BcmFlash2xCorruptSig(Adapter
, Adapter
->eActiveDSD
);
1363 if (Status
!= STATUS_SUCCESS
) {
1364 if (((stNVMReadWrite
.uiOffset
+ stNVMReadWrite
.uiNumBytes
) != Adapter
->uiNVMDSDSize
) ||
1365 (stNVMReadWrite
.uiNumBytes
< SIGNATURE_SIZE
)) {
1367 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "DSD Sig is present neither in Flash nor User provided Input..");
1368 up(&Adapter
->NVMRdmWrmLock
);
1373 ulDSDMagicNumInUsrBuff
= ntohl(*(PUINT
)(pReadData
+ stNVMReadWrite
.uiNumBytes
- SIGNATURE_SIZE
));
1374 if (ulDSDMagicNumInUsrBuff
!= DSD_IMAGE_MAGIC_NUMBER
) {
1375 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "DSD Sig is present neither in Flash nor User provided Input..");
1376 up(&Adapter
->NVMRdmWrmLock
);
1383 Status
= BeceemNVMWrite(Adapter
, (PUINT
)pReadData
, stNVMReadWrite
.uiOffset
, stNVMReadWrite
.uiNumBytes
, stNVMReadWrite
.bVerify
);
1384 if (IsFlash2x(Adapter
))
1385 BcmFlash2xWriteSig(Adapter
, Adapter
->eActiveDSD
);
1387 Adapter
->bHeaderChangeAllowed
= FALSE
;
1389 up(&Adapter
->NVMRdmWrmLock
);
1391 if (Status
!= STATUS_SUCCESS
) {
1397 do_gettimeofday(&tv1
);
1398 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);
1401 return STATUS_SUCCESS
;
1404 case IOCTL_BCM_FLASH2X_SECTION_READ
: {
1405 FLASH2X_READWRITE sFlash2xRead
= {0};
1406 PUCHAR pReadBuff
= NULL
;
1410 UINT ReadOffset
= 0;
1411 void __user
*OutPutBuff
;
1413 if (IsFlash2x(Adapter
) != TRUE
) {
1414 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Does not have 2.x map");
1418 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1419 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1422 /* Reading FLASH 2.x READ structure */
1423 if (copy_from_user(&sFlash2xRead
, IoBuffer
.InputBuffer
, sizeof(FLASH2X_READWRITE
)))
1426 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.Section :%x", sFlash2xRead
.Section
);
1427 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.offset :%x", sFlash2xRead
.offset
);
1428 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.numOfBytes :%x", sFlash2xRead
.numOfBytes
);
1429 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.bVerify :%x\n", sFlash2xRead
.bVerify
);
1431 /* This was internal to driver for raw read. now it has ben exposed to user space app. */
1432 if (validateFlash2xReadWrite(Adapter
, &sFlash2xRead
) == FALSE
)
1433 return STATUS_FAILURE
;
1435 NOB
= sFlash2xRead
.numOfBytes
;
1436 if (NOB
> Adapter
->uiSectorSize
)
1437 BuffSize
= Adapter
->uiSectorSize
;
1441 ReadOffset
= sFlash2xRead
.offset
;
1442 OutPutBuff
= IoBuffer
.OutputBuffer
;
1443 pReadBuff
= (PCHAR
)kzalloc(BuffSize
, GFP_KERNEL
);
1445 if (pReadBuff
== NULL
) {
1446 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1449 down(&Adapter
->NVMRdmWrmLock
);
1451 if ((Adapter
->IdleMode
== TRUE
) ||
1452 (Adapter
->bShutStatus
== TRUE
) ||
1453 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1455 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device is in Idle/Shutdown Mode\n");
1456 up(&Adapter
->NVMRdmWrmLock
);
1462 if (NOB
> Adapter
->uiSectorSize
)
1463 ReadBytes
= Adapter
->uiSectorSize
;
1467 /* Reading the data from Flash 2.x */
1468 Status
= BcmFlash2xBulkRead(Adapter
, (PUINT
)pReadBuff
, sFlash2xRead
.Section
, ReadOffset
, ReadBytes
);
1470 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Flash 2x read err with Status :%d", Status
);
1474 BCM_DEBUG_PRINT_BUFFER(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, pReadBuff
, ReadBytes
);
1476 Status
= copy_to_user(OutPutBuff
, pReadBuff
, ReadBytes
);
1478 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Copy to use failed with status :%d", Status
);
1479 up(&Adapter
->NVMRdmWrmLock
);
1483 NOB
= NOB
- ReadBytes
;
1485 ReadOffset
= ReadOffset
+ ReadBytes
;
1486 OutPutBuff
= OutPutBuff
+ ReadBytes
;
1490 up(&Adapter
->NVMRdmWrmLock
);
1495 case IOCTL_BCM_FLASH2X_SECTION_WRITE
: {
1496 FLASH2X_READWRITE sFlash2xWrite
= {0};
1498 void __user
*InputAddr
;
1501 UINT WriteOffset
= 0;
1502 UINT WriteBytes
= 0;
1504 if (IsFlash2x(Adapter
) != TRUE
) {
1505 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Does not have 2.x map");
1509 /* First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite */
1510 Adapter
->bAllDSDWriteAllow
= FALSE
;
1512 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1514 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1517 /* Reading FLASH 2.x READ structure */
1518 if (copy_from_user(&sFlash2xWrite
, IoBuffer
.InputBuffer
, sizeof(FLASH2X_READWRITE
)))
1521 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.Section :%x", sFlash2xWrite
.Section
);
1522 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.offset :%d", sFlash2xWrite
.offset
);
1523 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite
.numOfBytes
);
1524 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite
.bVerify
);
1526 if ((sFlash2xWrite
.Section
!= VSA0
) && (sFlash2xWrite
.Section
!= VSA1
) && (sFlash2xWrite
.Section
!= VSA2
)) {
1527 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Only VSA write is allowed");
1531 if (validateFlash2xReadWrite(Adapter
, &sFlash2xWrite
) == FALSE
)
1532 return STATUS_FAILURE
;
1534 InputAddr
= sFlash2xWrite
.pDataBuff
;
1535 WriteOffset
= sFlash2xWrite
.offset
;
1536 NOB
= sFlash2xWrite
.numOfBytes
;
1538 if (NOB
> Adapter
->uiSectorSize
)
1539 BuffSize
= Adapter
->uiSectorSize
;
1543 pWriteBuff
= kmalloc(BuffSize
, GFP_KERNEL
);
1545 if (pWriteBuff
== NULL
)
1548 /* extracting the remainder of the given offset. */
1549 WriteBytes
= Adapter
->uiSectorSize
;
1550 if (WriteOffset
% Adapter
->uiSectorSize
)
1551 WriteBytes
= Adapter
->uiSectorSize
- (WriteOffset
% Adapter
->uiSectorSize
);
1553 if (NOB
< WriteBytes
)
1556 down(&Adapter
->NVMRdmWrmLock
);
1558 if ((Adapter
->IdleMode
== TRUE
) ||
1559 (Adapter
->bShutStatus
== TRUE
) ||
1560 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1562 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device is in Idle/Shutdown Mode\n");
1563 up(&Adapter
->NVMRdmWrmLock
);
1568 BcmFlash2xCorruptSig(Adapter
, sFlash2xWrite
.Section
);
1570 Status
= copy_from_user(pWriteBuff
, InputAddr
, WriteBytes
);
1572 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy to user failed with status :%d", Status
);
1573 up(&Adapter
->NVMRdmWrmLock
);
1577 BCM_DEBUG_PRINT_BUFFER(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, pWriteBuff
, WriteBytes
);
1579 /* Writing the data from Flash 2.x */
1580 Status
= BcmFlash2xBulkWrite(Adapter
, (PUINT
)pWriteBuff
, sFlash2xWrite
.Section
, WriteOffset
, WriteBytes
, sFlash2xWrite
.bVerify
);
1583 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash 2x read err with Status :%d", Status
);
1587 NOB
= NOB
- WriteBytes
;
1589 WriteOffset
= WriteOffset
+ WriteBytes
;
1590 InputAddr
= InputAddr
+ WriteBytes
;
1591 if (NOB
> Adapter
->uiSectorSize
)
1592 WriteBytes
= Adapter
->uiSectorSize
;
1598 BcmFlash2xWriteSig(Adapter
, sFlash2xWrite
.Section
);
1599 up(&Adapter
->NVMRdmWrmLock
);
1604 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP
: {
1605 PFLASH2X_BITMAP psFlash2xBitMap
;
1606 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1608 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1611 if (IoBuffer
.OutputLength
!= sizeof(FLASH2X_BITMAP
))
1614 psFlash2xBitMap
= kzalloc(sizeof(FLASH2X_BITMAP
), GFP_KERNEL
);
1615 if (psFlash2xBitMap
== NULL
) {
1616 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Memory is not available");
1620 /* Reading the Flash Sectio Bit map */
1621 down(&Adapter
->NVMRdmWrmLock
);
1623 if ((Adapter
->IdleMode
== TRUE
) ||
1624 (Adapter
->bShutStatus
== TRUE
) ||
1625 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1627 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device is in Idle/Shutdown Mode\n");
1628 up(&Adapter
->NVMRdmWrmLock
);
1629 kfree(psFlash2xBitMap
);
1633 BcmGetFlash2xSectionalBitMap(Adapter
, psFlash2xBitMap
);
1634 up(&Adapter
->NVMRdmWrmLock
);
1635 if (copy_to_user(IoBuffer
.OutputBuffer
, psFlash2xBitMap
, sizeof(FLASH2X_BITMAP
))) {
1636 kfree(psFlash2xBitMap
);
1640 kfree(psFlash2xBitMap
);
1644 case IOCTL_BCM_SET_ACTIVE_SECTION
: {
1645 FLASH2X_SECTION_VAL eFlash2xSectionVal
= 0;
1646 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1648 if (IsFlash2x(Adapter
) != TRUE
) {
1649 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Does not have 2.x map");
1653 Status
= copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
));
1655 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
1659 Status
= copy_from_user(&eFlash2xSectionVal
, IoBuffer
.InputBuffer
, sizeof(INT
));
1661 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of flash section val failed");
1665 down(&Adapter
->NVMRdmWrmLock
);
1667 if ((Adapter
->IdleMode
== TRUE
) ||
1668 (Adapter
->bShutStatus
== TRUE
) ||
1669 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1671 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device is in Idle/Shutdown Mode\n");
1672 up(&Adapter
->NVMRdmWrmLock
);
1676 Status
= BcmSetActiveSection(Adapter
, eFlash2xSectionVal
);
1678 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Failed to make it's priority Highest. Status %d", Status
);
1680 up(&Adapter
->NVMRdmWrmLock
);
1684 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION
: {
1685 /* Right Now we are taking care of only DSD */
1686 Adapter
->bAllDSDWriteAllow
= FALSE
;
1687 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1688 Status
= STATUS_SUCCESS
;
1692 case IOCTL_BCM_COPY_SECTION
: {
1693 FLASH2X_COPY_SECTION sCopySectStrut
= {0};
1694 Status
= STATUS_SUCCESS
;
1695 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_COPY_SECTION Called");
1697 Adapter
->bAllDSDWriteAllow
= FALSE
;
1698 if (IsFlash2x(Adapter
) != TRUE
) {
1699 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Does not have 2.x map");
1703 Status
= copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
));
1705 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status
);
1709 Status
= copy_from_user(&sCopySectStrut
, IoBuffer
.InputBuffer
, sizeof(FLASH2X_COPY_SECTION
));
1711 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status
);
1715 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Source SEction :%x", sCopySectStrut
.SrcSection
);
1716 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Destination SEction :%x", sCopySectStrut
.DstSection
);
1717 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "offset :%x", sCopySectStrut
.offset
);
1718 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "NOB :%x", sCopySectStrut
.numOfBytes
);
1720 if (IsSectionExistInFlash(Adapter
, sCopySectStrut
.SrcSection
) == FALSE
) {
1721 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Source Section<%x> does not exixt in Flash ", sCopySectStrut
.SrcSection
);
1725 if (IsSectionExistInFlash(Adapter
, sCopySectStrut
.DstSection
) == FALSE
) {
1726 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut
.DstSection
);
1730 if (sCopySectStrut
.SrcSection
== sCopySectStrut
.DstSection
) {
1731 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Source and Destination section should be different");
1735 down(&Adapter
->NVMRdmWrmLock
);
1737 if ((Adapter
->IdleMode
== TRUE
) ||
1738 (Adapter
->bShutStatus
== TRUE
) ||
1739 (Adapter
->bPreparingForLowPowerMode
== TRUE
)) {
1741 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Device is in Idle/Shutdown Mode\n");
1742 up(&Adapter
->NVMRdmWrmLock
);
1746 if (sCopySectStrut
.SrcSection
== ISO_IMAGE1
|| sCopySectStrut
.SrcSection
== ISO_IMAGE2
) {
1747 if (IsNonCDLessDevice(Adapter
)) {
1748 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Device is Non-CDLess hence won't have ISO !!");
1750 } else if (sCopySectStrut
.numOfBytes
== 0) {
1751 Status
= BcmCopyISO(Adapter
, sCopySectStrut
);
1753 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Partial Copy of ISO section is not Allowed..");
1754 Status
= STATUS_FAILURE
;
1756 up(&Adapter
->NVMRdmWrmLock
);
1760 Status
= BcmCopySection(Adapter
, sCopySectStrut
.SrcSection
,
1761 sCopySectStrut
.DstSection
, sCopySectStrut
.offset
, sCopySectStrut
.numOfBytes
);
1762 up(&Adapter
->NVMRdmWrmLock
);
1766 case IOCTL_BCM_GET_FLASH_CS_INFO
: {
1767 Status
= STATUS_SUCCESS
;
1768 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1770 Status
= copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
));
1772 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
1776 if (Adapter
->eNVMType
!= NVM_FLASH
) {
1777 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Connected device does not have flash");
1782 if (IsFlash2x(Adapter
) == TRUE
) {
1783 if (IoBuffer
.OutputLength
< sizeof(FLASH2X_CS_INFO
))
1786 if (copy_to_user(IoBuffer
.OutputBuffer
, Adapter
->psFlash2xCSInfo
, sizeof(FLASH2X_CS_INFO
)))
1789 if (IoBuffer
.OutputLength
< sizeof(FLASH_CS_INFO
))
1792 if (copy_to_user(IoBuffer
.OutputBuffer
, Adapter
->psFlashCSInfo
, sizeof(FLASH_CS_INFO
)))
1798 case IOCTL_BCM_SELECT_DSD
: {
1800 FLASH2X_SECTION_VAL eFlash2xSectionVal
;
1801 eFlash2xSectionVal
= NO_SECTION_VAL
;
1802 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_SELECT_DSD Called");
1804 if (IsFlash2x(Adapter
) != TRUE
) {
1805 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash Does not have 2.x map");
1809 Status
= copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
));
1811 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of IOCTL BUFFER failed");
1814 Status
= copy_from_user(&eFlash2xSectionVal
, IoBuffer
.InputBuffer
, sizeof(INT
));
1816 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy of flash section val failed");
1820 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Read Section :%d", eFlash2xSectionVal
);
1821 if ((eFlash2xSectionVal
!= DSD0
) &&
1822 (eFlash2xSectionVal
!= DSD1
) &&
1823 (eFlash2xSectionVal
!= DSD2
)) {
1825 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Passed section<%x> is not DSD section", eFlash2xSectionVal
);
1826 return STATUS_FAILURE
;
1829 SectOfset
= BcmGetSectionValStartOffset(Adapter
, eFlash2xSectionVal
);
1830 if (SectOfset
== INVALID_OFFSET
) {
1831 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal
);
1835 Adapter
->bAllDSDWriteAllow
= TRUE
;
1836 Adapter
->ulFlashCalStart
= SectOfset
;
1837 Adapter
->eActiveDSD
= eFlash2xSectionVal
;
1839 Status
= STATUS_SUCCESS
;
1842 case IOCTL_BCM_NVM_RAW_READ
: {
1843 NVM_READWRITE stNVMRead
;
1847 UINT ReadBytes
= 0 ;
1849 void __user
*OutPutBuff
;
1851 if (Adapter
->eNVMType
!= NVM_FLASH
) {
1852 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "NVM TYPE is not Flash");
1856 /* Copy Ioctl Buffer structure */
1857 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
))) {
1858 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "copy_from_user 1 failed\n");
1862 if (copy_from_user(&stNVMRead
, IoBuffer
.OutputBuffer
, sizeof(NVM_READWRITE
)))
1865 NOB
= stNVMRead
.uiNumBytes
;
1866 /* In Raw-Read max Buff size : 64MB */
1868 if (NOB
> DEFAULT_BUFF_SIZE
)
1869 BuffSize
= DEFAULT_BUFF_SIZE
;
1873 ReadOffset
= stNVMRead
.uiOffset
;
1874 OutPutBuff
= stNVMRead
.pBuffer
;
1876 pReadBuff
= kzalloc(BuffSize
, GFP_KERNEL
);
1877 if (pReadBuff
== NULL
) {
1878 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
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");
1890 up(&Adapter
->NVMRdmWrmLock
);
1894 Adapter
->bFlashRawRead
= TRUE
;
1897 if (NOB
> DEFAULT_BUFF_SIZE
)
1898 ReadBytes
= DEFAULT_BUFF_SIZE
;
1902 /* Reading the data from Flash 2.x */
1903 Status
= BeceemNVMRead(Adapter
, (PUINT
)pReadBuff
, ReadOffset
, ReadBytes
);
1905 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Flash 2x read err with Status :%d", Status
);
1909 BCM_DEBUG_PRINT_BUFFER(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, pReadBuff
, ReadBytes
);
1911 Status
= copy_to_user(OutPutBuff
, pReadBuff
, ReadBytes
);
1913 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_PRINTK
, 0, 0, "Copy to use failed with status :%d", Status
);
1914 up(&Adapter
->NVMRdmWrmLock
);
1918 NOB
= NOB
- ReadBytes
;
1920 ReadOffset
= ReadOffset
+ ReadBytes
;
1921 OutPutBuff
= OutPutBuff
+ ReadBytes
;
1924 Adapter
->bFlashRawRead
= FALSE
;
1925 up(&Adapter
->NVMRdmWrmLock
);
1930 case IOCTL_BCM_CNTRLMSG_MASK
: {
1931 ULONG RxCntrlMsgBitMask
= 0;
1933 /* Copy Ioctl Buffer structure */
1934 Status
= copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
));
1936 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "copy of Ioctl buffer is failed from user space");
1940 if (IoBuffer
.InputLength
!= sizeof(unsigned long)) {
1945 Status
= copy_from_user(&RxCntrlMsgBitMask
, IoBuffer
.InputBuffer
, IoBuffer
.InputLength
);
1947 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "copy of control bit mask failed from user space");
1950 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask
);
1951 pTarang
->RxCntrlMsgBitMask
= RxCntrlMsgBitMask
;
1955 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO
: {
1956 DEVICE_DRIVER_INFO DevInfo
;
1958 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
1960 DevInfo
.MaxRDMBufferSize
= BUFFER_4K
;
1961 DevInfo
.u32DSDStartOffset
= EEPROM_CALPARAM_START
;
1962 DevInfo
.u32RxAlignmentCorrection
= 0;
1963 DevInfo
.u32NVMType
= Adapter
->eNVMType
;
1964 DevInfo
.u32InterfaceType
= BCM_USB
;
1966 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1969 if (IoBuffer
.OutputLength
< sizeof(DevInfo
))
1972 if (copy_to_user(IoBuffer
.OutputBuffer
, &DevInfo
, sizeof(DevInfo
)))
1977 case IOCTL_BCM_TIME_SINCE_NET_ENTRY
: {
1978 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry
= {0};
1980 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
1982 if (copy_from_user(&IoBuffer
, argp
, sizeof(IOCTL_BUFFER
)))
1985 if (IoBuffer
.OutputLength
< sizeof(ST_TIME_ELAPSED
))
1988 stTimeElapsedSinceNetEntry
.ul64TimeElapsedSinceNetEntry
= get_seconds() - Adapter
->liTimeSinceLastNetEntry
;
1990 if (copy_to_user(IoBuffer
.OutputBuffer
, &stTimeElapsedSinceNetEntry
, sizeof(ST_TIME_ELAPSED
)))
1995 case IOCTL_CLOSE_NOTIFICATION
:
1996 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_OTHERS
, OSAL_DBG
, DBG_LVL_ALL
, "IOCTL_CLOSE_NOTIFICATION");
2000 pr_info(DRV_NAME
": unknown ioctl cmd=%#x\n", cmd
);
2001 Status
= STATUS_FAILURE
;
2008 static const struct file_operations bcm_fops
= {
2009 .owner
= THIS_MODULE
,
2010 .open
= bcm_char_open
,
2011 .release
= bcm_char_release
,
2012 .read
= bcm_char_read
,
2013 .unlocked_ioctl
= bcm_char_ioctl
,
2014 .llseek
= no_llseek
,
2017 int register_control_device_interface(struct bcm_mini_adapter
*Adapter
)
2020 if (Adapter
->major
> 0)
2021 return Adapter
->major
;
2023 Adapter
->major
= register_chrdev(0, DEV_NAME
, &bcm_fops
);
2024 if (Adapter
->major
< 0) {
2025 pr_err(DRV_NAME
": could not created character device\n");
2026 return Adapter
->major
;
2029 Adapter
->pstCreatedClassDevice
= device_create(bcm_class
, NULL
,
2030 MKDEV(Adapter
->major
, 0),
2033 if (IS_ERR(Adapter
->pstCreatedClassDevice
)) {
2034 pr_err(DRV_NAME
": class device create failed\n");
2035 unregister_chrdev(Adapter
->major
, DEV_NAME
);
2036 return PTR_ERR(Adapter
->pstCreatedClassDevice
);
2042 void unregister_control_device_interface(struct bcm_mini_adapter
*Adapter
)
2044 if (Adapter
->major
> 0) {
2045 device_destroy(bcm_class
, MKDEV(Adapter
->major
, 0));
2046 unregister_chrdev(Adapter
->major
, DEV_NAME
);