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;
55 Adapter = pTarang->Adapter;
57 down(&Adapter->RxAppControlQueuelock);
59 tmp = Adapter->pTarangs;
60 for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
67 Adapter->pTarangs = tmp->next;
69 ptmp->next = tmp->next;
71 up(&Adapter->RxAppControlQueuelock);
75 pkt = pTarang->RxAppControlHead;
82 up(&Adapter->RxAppControlQueuelock);
84 /* Stop Queuing the control response Packets */
85 atomic_dec(&Adapter->ApplicationRunning);
89 /* remove this filp from the asynchronously notified filp's */
90 filp->private_data = NULL;
94 static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
97 struct bcm_tarang_data *pTarang = filp->private_data;
98 struct bcm_mini_adapter *Adapter = pTarang->Adapter;
99 struct sk_buff *Packet = NULL;
101 int wait_ret_val = 0;
102 unsigned long ret = 0;
104 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
105 (pTarang->RxAppControlHead ||
106 Adapter->device_removed));
107 if ((wait_ret_val == -ERESTARTSYS)) {
108 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
109 "Exiting as i've been asked to exit!!!\n");
113 if (Adapter->device_removed) {
114 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
115 "Device Removed... Killing the Apps...\n");
119 if (false == Adapter->fw_download_done)
122 down(&Adapter->RxAppControlQueuelock);
124 if (pTarang->RxAppControlHead) {
125 Packet = pTarang->RxAppControlHead;
126 DEQUEUEPACKET(pTarang->RxAppControlHead,
127 pTarang->RxAppControlTail);
128 pTarang->AppCtrlQueueLen--;
131 up(&Adapter->RxAppControlQueuelock);
134 PktLen = Packet->len;
135 ret = copy_to_user(buf, Packet->data,
136 min_t(size_t, PktLen, size));
138 dev_kfree_skb(Packet);
139 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
140 "Returning from copy to user failure\n");
143 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
144 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
145 PktLen, Packet, current->pid);
146 dev_kfree_skb(Packet);
149 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
153 static int bcm_char_ioctl_reg_read_private(void __user *argp, struct bcm_mini_adapter *Adapter)
155 struct bcm_rdm_buffer sRdmBuffer = {0};
156 struct bcm_ioctl_buffer IoBuffer;
158 INT Status = STATUS_FAILURE;
163 /* Copy Ioctl Buffer structure */
164 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
167 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
170 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
173 if (IoBuffer.OutputLength > USHRT_MAX ||
174 IoBuffer.OutputLength == 0) {
178 Bufflen = IoBuffer.OutputLength;
179 temp_value = 4 - (Bufflen % 4);
180 Bufflen += temp_value % 4;
182 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
186 bytes = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
187 (PUINT)temp_buff, Bufflen);
189 Status = STATUS_SUCCESS;
190 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
202 static int bcm_char_ioctl_reg_write_private(void __user *argp, struct bcm_mini_adapter *Adapter)
204 struct bcm_wrm_buffer sWrmBuffer = {0};
205 struct bcm_ioctl_buffer IoBuffer;
209 /* Copy Ioctl Buffer structure */
211 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
214 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
217 /* Get WrmBuffer structure */
218 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
221 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
222 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
223 ((uiTempVar == EEPROM_REJECT_REG_1) ||
224 (uiTempVar == EEPROM_REJECT_REG_2) ||
225 (uiTempVar == EEPROM_REJECT_REG_3) ||
226 (uiTempVar == EEPROM_REJECT_REG_4))) {
228 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
229 "EEPROM Access Denied, not in VSG Mode\n");
233 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
234 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
236 if (Status == STATUS_SUCCESS) {
237 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
238 DBG_LVL_ALL, "WRM Done\n");
240 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
241 DBG_LVL_ALL, "WRM Failed\n");
247 static int bcm_char_ioctl_eeprom_reg_read(void __user *argp, struct bcm_mini_adapter *Adapter)
249 struct bcm_rdm_buffer sRdmBuffer = {0};
250 struct bcm_ioctl_buffer IoBuffer;
251 PCHAR temp_buff = NULL;
256 if ((Adapter->IdleMode == TRUE) ||
257 (Adapter->bShutStatus == TRUE) ||
258 (Adapter->bPreparingForLowPowerMode == TRUE)) {
260 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
261 "Device in Idle Mode, Blocking Rdms\n");
265 /* Copy Ioctl Buffer structure */
266 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
269 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
272 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
275 if (IoBuffer.OutputLength > USHRT_MAX ||
276 IoBuffer.OutputLength == 0) {
280 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
282 return STATUS_FAILURE;
284 if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
285 ((ULONG)sRdmBuffer.Register & 0x3)) {
287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
288 "RDM Done On invalid Address : %x Access Denied.\n",
289 (int)sRdmBuffer.Register);
295 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
296 bytes = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
297 (PUINT)temp_buff, IoBuffer.OutputLength);
300 Status = STATUS_SUCCESS;
301 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
313 static int bcm_char_ioctl_eeprom_reg_write(void __user *argp, struct bcm_mini_adapter *Adapter, UINT cmd)
315 struct bcm_wrm_buffer sWrmBuffer = {0};
316 struct bcm_ioctl_buffer IoBuffer;
320 if ((Adapter->IdleMode == TRUE) ||
321 (Adapter->bShutStatus == TRUE) ||
322 (Adapter->bPreparingForLowPowerMode == TRUE)) {
324 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
325 "Device in Idle Mode, Blocking Wrms\n");
329 /* Copy Ioctl Buffer structure */
330 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
333 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
336 /* Get WrmBuffer structure */
337 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
340 if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
341 ((ULONG)sWrmBuffer.Register & 0x3)) {
343 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
344 "WRM Done On invalid Address : %x Access Denied.\n",
345 (int)sWrmBuffer.Register);
349 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
350 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
351 ((uiTempVar == EEPROM_REJECT_REG_1) ||
352 (uiTempVar == EEPROM_REJECT_REG_2) ||
353 (uiTempVar == EEPROM_REJECT_REG_3) ||
354 (uiTempVar == EEPROM_REJECT_REG_4)) &&
355 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
357 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
358 "EEPROM Access Denied, not in VSG Mode\n");
362 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
363 (PUINT)sWrmBuffer.Data,
366 if (Status == STATUS_SUCCESS) {
367 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG,
368 DBG_LVL_ALL, "WRM Done\n");
370 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
371 DBG_LVL_ALL, "WRM Failed\n");
377 static int bcm_char_ioctl_gpio_set_request(void __user *argp, struct bcm_mini_adapter *Adapter)
379 struct bcm_gpio_info gpio_info = {0};
380 struct bcm_ioctl_buffer IoBuffer;
381 UCHAR ucResetValue[4];
384 UINT uiOperation = 0;
388 if ((Adapter->IdleMode == TRUE) ||
389 (Adapter->bShutStatus == TRUE) ||
390 (Adapter->bPreparingForLowPowerMode == TRUE)) {
392 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
394 "GPIO Can't be set/clear in Low power Mode");
398 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
401 if (IoBuffer.InputLength > sizeof(gpio_info))
404 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
407 uiBit = gpio_info.uiGpioNumber;
408 uiOperation = gpio_info.uiGpioValue;
411 if (IsReqGpioIsLedInNVM(Adapter, value) == false) {
412 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
414 "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",
419 /* Set - setting 1 */
421 /* Set the gpio output register */
422 Status = wrmaltWithLock(Adapter,
423 BCM_GPIO_OUTPUT_SET_REG,
424 (PUINT)(&value), sizeof(UINT));
426 if (Status == STATUS_SUCCESS) {
427 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
428 OSAL_DBG, DBG_LVL_ALL,
429 "Set the GPIO bit\n");
431 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
432 OSAL_DBG, DBG_LVL_ALL,
433 "Failed to set the %dth GPIO\n",
438 /* Set the gpio output register */
439 Status = wrmaltWithLock(Adapter,
440 BCM_GPIO_OUTPUT_CLR_REG,
441 (PUINT)(&value), sizeof(UINT));
443 if (Status == STATUS_SUCCESS) {
444 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
445 OSAL_DBG, DBG_LVL_ALL,
446 "Set the GPIO bit\n");
448 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
449 OSAL_DBG, DBG_LVL_ALL,
450 "Failed to clear the %dth GPIO\n",
456 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
457 (PUINT)ucResetValue, sizeof(UINT));
460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
461 "GPIO_MODE_REGISTER read failed");
464 Status = STATUS_SUCCESS;
467 /* Set the gpio mode register to output */
468 *(UINT *)ucResetValue |= (1<<uiBit);
469 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
470 (PUINT)ucResetValue, sizeof(UINT));
472 if (Status == STATUS_SUCCESS) {
473 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
475 "Set the GPIO to output Mode\n");
477 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
479 "Failed to put GPIO in Output Mode\n");
485 static int bcm_char_ioctl_led_thread_state_change_req(void __user *argp, struct bcm_mini_adapter *Adapter)
487 struct bcm_user_thread_req threadReq = {0};
488 struct bcm_ioctl_buffer IoBuffer;
490 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
491 "User made LED thread InActive");
493 if ((Adapter->IdleMode == TRUE) ||
494 (Adapter->bShutStatus == TRUE) ||
495 (Adapter->bPreparingForLowPowerMode == TRUE)) {
497 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
499 "GPIO Can't be set/clear in Low power Mode");
503 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
506 if (IoBuffer.InputLength > sizeof(threadReq))
509 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
512 /* if LED thread is running(Actively or Inactively) set it state to make inactive */
513 if (Adapter->LEDInfo.led_thread_running) {
514 if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
515 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
516 OSAL_DBG, DBG_LVL_ALL,
517 "Activating thread req");
518 Adapter->DriverState = LED_THREAD_ACTIVE;
520 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
521 OSAL_DBG, DBG_LVL_ALL,
522 "DeActivating Thread req.....");
523 Adapter->DriverState = LED_THREAD_INACTIVE;
527 wake_up(&Adapter->LEDInfo.notify_led_event);
529 return STATUS_SUCCESS;
532 static int bcm_char_ioctl_gpio_status_request(void __user *argp, struct bcm_mini_adapter *Adapter)
534 struct bcm_gpio_info gpio_info = {0};
535 struct bcm_ioctl_buffer IoBuffer;
541 if ((Adapter->IdleMode == TRUE) ||
542 (Adapter->bShutStatus == TRUE) ||
543 (Adapter->bPreparingForLowPowerMode == TRUE))
546 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
549 if (IoBuffer.InputLength > sizeof(gpio_info))
552 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
555 uiBit = gpio_info.uiGpioNumber;
557 /* Set the gpio output register */
558 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
559 (PUINT)ucRead, sizeof(UINT));
563 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
567 Status = STATUS_SUCCESS;
572 static int bcm_char_ioctl_gpio_multi_request(void __user *argp, struct bcm_mini_adapter *Adapter)
574 struct bcm_gpio_multi_info gpio_multi_info[MAX_IDX];
575 struct bcm_gpio_multi_info *pgpio_multi_info = (struct bcm_gpio_multi_info *)gpio_multi_info;
576 struct bcm_ioctl_buffer IoBuffer;
577 UCHAR ucResetValue[4];
578 INT Status = STATUS_FAILURE;
581 memset(pgpio_multi_info, 0, MAX_IDX * sizeof(struct bcm_gpio_multi_info));
583 if ((Adapter->IdleMode == TRUE) ||
584 (Adapter->bShutStatus == TRUE) ||
585 (Adapter->bPreparingForLowPowerMode == TRUE))
588 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
591 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
594 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
597 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_info[WIMAX_IDX].uiGPIOMask) == false) {
598 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
600 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
601 pgpio_multi_info[WIMAX_IDX].uiGPIOMask,
602 Adapter->gpioBitMap);
606 /* Set the gpio output register */
607 if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
608 (pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
609 /* Set 1's in GPIO OUTPUT REGISTER */
610 *(UINT *)ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
611 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
612 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
614 if (*(UINT *) ucResetValue)
615 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG,
616 (PUINT)ucResetValue, sizeof(ULONG));
618 if (Status != STATUS_SUCCESS) {
619 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
620 "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
624 /* Clear to 0's in GPIO OUTPUT REGISTER */
625 *(UINT *)ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
626 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
627 (~(pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
629 if (*(UINT *) ucResetValue)
630 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)ucResetValue, sizeof(ULONG));
632 if (Status != STATUS_SUCCESS) {
633 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
634 "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
639 if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
640 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
644 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
645 "RDM to GPIO_PIN_STATE_REGISTER Failed.");
648 Status = STATUS_SUCCESS;
651 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = (*(UINT *)ucResetValue &
652 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
655 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
657 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
658 "Failed while copying Content to IOBufer for user space err:%d", Status);
664 static int bcm_char_ioctl_gpio_mode_request(void __user *argp, struct bcm_mini_adapter *Adapter)
666 struct bcm_gpio_multi_mode gpio_multi_mode[MAX_IDX];
667 struct bcm_gpio_multi_mode *pgpio_multi_mode = (struct bcm_gpio_multi_mode *)gpio_multi_mode;
668 struct bcm_ioctl_buffer IoBuffer;
669 UCHAR ucResetValue[4];
673 if ((Adapter->IdleMode == TRUE) ||
674 (Adapter->bShutStatus == TRUE) ||
675 (Adapter->bPreparingForLowPowerMode == TRUE))
678 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
681 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
684 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
687 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read of GPIO_MODE_REGISTER failed");
694 Status = STATUS_SUCCESS;
697 /* Validating the request */
698 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) == false) {
699 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
700 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
701 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
705 if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
706 /* write all OUT's (1's) */
707 *(UINT *) ucResetValue |= (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
708 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
710 /* write all IN's (0's) */
711 *(UINT *) ucResetValue &= ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
712 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
714 /* Currently implemented return the modes of all GPIO's
715 * else needs to bit AND with mask
717 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
719 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(ULONG));
720 if (Status == STATUS_SUCCESS) {
721 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
722 "WRM to GPIO_MODE_REGISTER Done");
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
725 "WRM to GPIO_MODE_REGISTER Failed");
729 /* if uiGPIOMask is 0 then return mode register configuration */
730 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
733 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
736 "Failed while copying Content to IOBufer for user space err:%d", Status);
742 static int bcm_char_ioctl_misc_request(void __user *argp, struct bcm_mini_adapter *Adapter)
744 struct bcm_ioctl_buffer IoBuffer;
745 PVOID pvBuffer = NULL;
748 /* Copy Ioctl Buffer structure */
749 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
752 if (IoBuffer.InputLength < sizeof(struct bcm_link_request))
755 if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
758 pvBuffer = memdup_user(IoBuffer.InputBuffer,
759 IoBuffer.InputLength);
760 if (IS_ERR(pvBuffer))
761 return PTR_ERR(pvBuffer);
763 down(&Adapter->LowPowerModeSync);
764 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
765 !Adapter->bPreparingForLowPowerMode,
767 if (Status == -ERESTARTSYS)
770 if (Adapter->bPreparingForLowPowerMode) {
771 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
772 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
773 Status = STATUS_FAILURE;
776 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
779 up(&Adapter->LowPowerModeSync);
784 static int bcm_char_ioctl_buffer_download_start(struct bcm_mini_adapter *Adapter)
788 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
789 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
790 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
794 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
795 "Starting the firmware download PID =0x%x!!!!\n", current->pid);
797 if (down_trylock(&Adapter->fw_download_sema))
800 Adapter->bBinDownloaded = false;
801 Adapter->fw_download_process_pid = current->pid;
802 Adapter->bCfgDownloaded = false;
803 Adapter->fw_download_done = false;
804 netif_carrier_off(Adapter->dev);
805 netif_stop_queue(Adapter->dev);
806 Status = reset_card_proc(Adapter);
808 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
809 up(&Adapter->fw_download_sema);
810 up(&Adapter->NVMRdmWrmLock);
815 up(&Adapter->NVMRdmWrmLock);
819 static int bcm_char_ioctl_buffer_download(void __user *argp, struct bcm_mini_adapter *Adapter)
821 struct bcm_firmware_info *psFwInfo = NULL;
822 struct bcm_ioctl_buffer IoBuffer;
825 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
827 if (!down_trylock(&Adapter->fw_download_sema)) {
828 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
829 "Invalid way to download buffer. Use Start and then call this!!!\n");
830 up(&Adapter->fw_download_sema);
834 /* Copy Ioctl Buffer structure */
835 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
836 up(&Adapter->fw_download_sema);
840 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
841 "Length for FW DLD is : %lx\n", IoBuffer.InputLength);
843 if (IoBuffer.InputLength > sizeof(struct bcm_firmware_info)) {
844 up(&Adapter->fw_download_sema);
848 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
850 up(&Adapter->fw_download_sema);
854 if (copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
855 up(&Adapter->fw_download_sema);
860 if (!psFwInfo->pvMappedFirmwareAddress ||
861 (psFwInfo->u32FirmwareLength == 0)) {
863 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
864 psFwInfo->u32FirmwareLength);
865 up(&Adapter->fw_download_sema);
871 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
873 if (Status != STATUS_SUCCESS) {
874 if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR)
875 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
877 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
879 /* up(&Adapter->fw_download_sema); */
881 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
882 Adapter->DriverState = DRIVER_INIT;
883 Adapter->LEDInfo.bLedInitDone = false;
884 wake_up(&Adapter->LEDInfo.notify_led_event);
888 if (Status != STATUS_SUCCESS)
889 up(&Adapter->fw_download_sema);
891 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
897 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
899 struct bcm_tarang_data *pTarang = filp->private_data;
900 void __user *argp = (void __user *)arg;
901 struct bcm_mini_adapter *Adapter = pTarang->Adapter;
902 INT Status = STATUS_FAILURE;
904 struct bcm_ioctl_buffer IoBuffer;
906 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
907 "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX",
910 if (_IOC_TYPE(cmd) != BCM_IOCTL)
912 if (_IOC_DIR(cmd) & _IOC_READ)
913 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
914 else if (_IOC_DIR(cmd) & _IOC_WRITE)
915 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
916 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
917 Status = STATUS_SUCCESS;
922 if (Adapter->device_removed)
925 if (false == Adapter->fw_download_done) {
927 case IOCTL_MAC_ADDR_REQ:
929 case IOCTL_CM_REQUEST:
930 case IOCTL_SS_INFO_REQ:
931 case IOCTL_SEND_CONTROL_MESSAGE:
933 case IOCTL_BCM_GPIO_SET_REQUEST:
934 case IOCTL_BCM_GPIO_STATUS_REQUEST:
941 Status = vendorextnIoctl(Adapter, cmd, arg);
942 if (Status != CONTINUE_COMMON_PATH)
946 /* Rdms for Swin Idle... */
947 case IOCTL_BCM_REGISTER_READ_PRIVATE:
948 Status = bcm_char_ioctl_reg_read_private(argp, Adapter);
951 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
952 Status = bcm_char_ioctl_reg_write_private(argp, Adapter);
955 case IOCTL_BCM_REGISTER_READ:
956 case IOCTL_BCM_EEPROM_REGISTER_READ:
957 Status = bcm_char_ioctl_eeprom_reg_read(argp, Adapter);
960 case IOCTL_BCM_REGISTER_WRITE:
961 case IOCTL_BCM_EEPROM_REGISTER_WRITE:
962 Status = bcm_char_ioctl_eeprom_reg_write(argp, Adapter, cmd);
965 case IOCTL_BCM_GPIO_SET_REQUEST:
966 Status = bcm_char_ioctl_gpio_set_request(argp, Adapter);
969 case BCM_LED_THREAD_STATE_CHANGE_REQ:
970 Status = bcm_char_ioctl_led_thread_state_change_req(argp, Adapter);
973 case IOCTL_BCM_GPIO_STATUS_REQUEST:
974 Status = bcm_char_ioctl_gpio_status_request(argp, Adapter);
977 case IOCTL_BCM_GPIO_MULTI_REQUEST:
978 Status = bcm_char_ioctl_gpio_multi_request(argp, Adapter);
981 case IOCTL_BCM_GPIO_MODE_REQUEST:
982 Status = bcm_char_ioctl_gpio_mode_request(argp, Adapter);
985 case IOCTL_MAC_ADDR_REQ:
987 case IOCTL_CM_REQUEST:
988 case IOCTL_SS_INFO_REQ:
989 case IOCTL_SEND_CONTROL_MESSAGE:
991 Status = bcm_char_ioctl_misc_request(argp, Adapter);
994 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
995 Status = bcm_char_ioctl_buffer_download_start(Adapter);
998 case IOCTL_BCM_BUFFER_DOWNLOAD:
999 Status = bcm_char_ioctl_buffer_download(argp, Adapter);
1002 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP: {
1003 if (!down_trylock(&Adapter->fw_download_sema)) {
1004 up(&Adapter->fw_download_sema);
1008 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
1009 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1010 "FW download blocked as EEPROM Read/Write is in progress\n");
1011 up(&Adapter->fw_download_sema);
1015 Adapter->bBinDownloaded = TRUE;
1016 Adapter->bCfgDownloaded = TRUE;
1017 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
1018 Adapter->CurrNumRecvDescs = 0;
1019 Adapter->downloadDDR = 0;
1021 /* setting the Mips to Run */
1022 Status = run_card_proc(Adapter);
1025 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
1026 up(&Adapter->fw_download_sema);
1027 up(&Adapter->NVMRdmWrmLock);
1030 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
1031 DBG_LVL_ALL, "Firm Download Over...\n");
1036 /* Wait for MailBox Interrupt */
1037 if (StartInterruptUrb((struct bcm_interface_adapter *)Adapter->pvInterfaceAdapter))
1038 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
1041 Adapter->waiting_to_fw_download_done = false;
1042 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
1043 Adapter->waiting_to_fw_download_done, timeout);
1044 Adapter->fw_download_process_pid = INVALID_PID;
1045 Adapter->fw_download_done = TRUE;
1046 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
1047 Adapter->CurrNumRecvDescs = 0;
1048 Adapter->PrevNumRecvDescs = 0;
1049 atomic_set(&Adapter->cntrlpktCnt, 0);
1050 Adapter->LinkUpStatus = 0;
1051 Adapter->LinkStatus = 0;
1053 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1054 Adapter->DriverState = FW_DOWNLOAD_DONE;
1055 wake_up(&Adapter->LEDInfo.notify_led_event);
1061 up(&Adapter->fw_download_sema);
1062 up(&Adapter->NVMRdmWrmLock);
1066 case IOCTL_BE_BUCKET_SIZE:
1068 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
1072 case IOCTL_RTPS_BUCKET_SIZE:
1074 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
1078 case IOCTL_CHIP_RESET: {
1079 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1081 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
1085 down(&Adapter->RxAppControlQueuelock);
1086 Status = reset_card_proc(Adapter);
1088 up(&Adapter->RxAppControlQueuelock);
1089 up(&Adapter->NVMRdmWrmLock);
1090 ResetCounters(Adapter);
1094 case IOCTL_QOS_THRESHOLD: {
1098 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
1099 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
1100 (unsigned long __user *)arg)) {
1108 case IOCTL_DUMP_PACKET_INFO:
1109 DumpPackInfo(Adapter);
1110 DumpPhsRules(&Adapter->stBCMPhsContext);
1111 Status = STATUS_SUCCESS;
1114 case IOCTL_GET_PACK_INFO:
1115 if (copy_to_user(argp, &Adapter->PackInfo, sizeof(struct bcm_packet_info)*NO_OF_QUEUES))
1117 Status = STATUS_SUCCESS;
1120 case IOCTL_BCM_SWITCH_TRANSFER_MODE: {
1122 if (copy_from_user(&uiData, argp, sizeof(UINT)))
1126 /* Allow All Packets */
1127 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
1128 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
1130 /* Allow IP only Packets */
1131 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
1132 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
1134 Status = STATUS_SUCCESS;
1138 case IOCTL_BCM_GET_DRIVER_VERSION: {
1141 /* Copy Ioctl Buffer structure */
1142 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1145 len = min_t(ulong, IoBuffer.OutputLength, strlen(DRV_VERSION) + 1);
1147 if (copy_to_user(IoBuffer.OutputBuffer, DRV_VERSION, len))
1149 Status = STATUS_SUCCESS;
1153 case IOCTL_BCM_GET_CURRENT_STATUS: {
1154 struct bcm_link_state link_state;
1156 /* Copy Ioctl Buffer structure */
1157 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
1158 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
1162 if (IoBuffer.OutputLength != sizeof(link_state)) {
1167 memset(&link_state, 0, sizeof(link_state));
1168 link_state.bIdleMode = Adapter->IdleMode;
1169 link_state.bShutdownMode = Adapter->bShutStatus;
1170 link_state.ucLinkStatus = Adapter->LinkStatus;
1172 if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) {
1173 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1176 Status = STATUS_SUCCESS;
1180 case IOCTL_BCM_SET_MAC_TRACING: {
1183 /* copy ioctl Buffer structure */
1184 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1187 if (copy_from_user(&tracing_flag, IoBuffer.InputBuffer, sizeof(UINT)))
1191 Adapter->pTarangs->MacTracingEnabled = TRUE;
1193 Adapter->pTarangs->MacTracingEnabled = false;
1197 case IOCTL_BCM_GET_DSX_INDICATION: {
1199 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1202 if (IoBuffer.OutputLength < sizeof(struct bcm_add_indication_alt)) {
1203 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1204 "Mismatch req: %lx needed is =0x%zx!!!",
1205 IoBuffer.OutputLength, sizeof(struct bcm_add_indication_alt));
1209 if (copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1212 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId);
1213 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1214 Status = STATUS_SUCCESS;
1218 case IOCTL_BCM_GET_HOST_MIBS: {
1221 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1224 if (IoBuffer.OutputLength != sizeof(struct bcm_host_stats_mibs)) {
1225 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1226 "Length Check failed %lu %zd\n",
1227 IoBuffer.OutputLength, sizeof(struct bcm_host_stats_mibs));
1231 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1232 temp_buff = kzalloc(sizeof(struct bcm_host_stats_mibs), GFP_KERNEL);
1234 return STATUS_FAILURE;
1236 Status = ProcessGetHostMibs(Adapter, temp_buff);
1237 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1239 if (Status != STATUS_FAILURE)
1240 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(struct bcm_host_stats_mibs))) {
1249 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1250 if ((false == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE == Adapter->IdleMode)) {
1251 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1252 Adapter->bWakeUpDevice = TRUE;
1253 wake_up(&Adapter->process_rx_cntrlpkt);
1256 Status = STATUS_SUCCESS;
1259 case IOCTL_BCM_BULK_WRM: {
1260 struct bcm_bulk_wrm_buffer *pBulkBuffer;
1262 PCHAR pvBuffer = NULL;
1264 if ((Adapter->IdleMode == TRUE) ||
1265 (Adapter->bShutStatus == TRUE) ||
1266 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1268 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1273 /* Copy Ioctl Buffer structure */
1274 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1277 if (IoBuffer.InputLength < sizeof(ULONG) * 2)
1280 pvBuffer = memdup_user(IoBuffer.InputBuffer,
1281 IoBuffer.InputLength);
1282 if (IS_ERR(pvBuffer))
1283 return PTR_ERR(pvBuffer);
1285 pBulkBuffer = (struct bcm_bulk_wrm_buffer *)pvBuffer;
1287 if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1288 ((ULONG)pBulkBuffer->Register & 0x3)) {
1289 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer->Register);
1295 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1296 if (!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE) &&
1297 ((uiTempVar == EEPROM_REJECT_REG_1) ||
1298 (uiTempVar == EEPROM_REJECT_REG_2) ||
1299 (uiTempVar == EEPROM_REJECT_REG_3) ||
1300 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1301 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
1304 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
1309 if (pBulkBuffer->SwapEndian == false)
1310 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1312 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1314 if (Status != STATUS_SUCCESS)
1315 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1321 case IOCTL_BCM_GET_NVM_SIZE:
1322 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1325 if (Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH) {
1326 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1330 Status = STATUS_SUCCESS;
1333 case IOCTL_BCM_CAL_INIT: {
1334 UINT uiSectorSize = 0;
1335 if (Adapter->eNVMType == NVM_FLASH) {
1336 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1339 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1342 if ((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) {
1343 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1347 if (IsFlash2x(Adapter)) {
1348 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize, sizeof(UINT)))
1351 if ((TRUE == Adapter->bShutStatus) || (TRUE == Adapter->IdleMode)) {
1352 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is in Idle/Shutdown Mode\n");
1356 Adapter->uiSectorSize = uiSectorSize;
1357 BcmUpdateSectorSize(Adapter, Adapter->uiSectorSize);
1360 Status = STATUS_SUCCESS;
1362 Status = STATUS_FAILURE;
1367 case IOCTL_BCM_SET_DEBUG:
1370 struct bcm_user_debug_state sUserDebugState;
1372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1373 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1376 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(struct bcm_user_debug_state)))
1379 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1380 sUserDebugState.OnOff, sUserDebugState.Type);
1381 /* sUserDebugState.Subtype <<= 1; */
1382 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1383 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1385 /* Update new 'DebugState' in the Adapter */
1386 Adapter->stDebugState.type |= sUserDebugState.Type;
1387 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1388 * Valid indexes in 'subtype' array: 1,2,4,8
1389 * corresponding to valid Type values. Hence we can use the 'Type' field
1390 * as the index value, ignoring the array entries 0,3,5,6,7 !
1392 if (sUserDebugState.OnOff)
1393 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1395 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1397 BCM_SHOW_DEBUG_BITMAP(Adapter);
1402 case IOCTL_BCM_NVM_READ:
1403 case IOCTL_BCM_NVM_WRITE: {
1404 struct bcm_nvm_readwrite stNVMReadWrite;
1405 PUCHAR pReadData = NULL;
1406 ULONG ulDSDMagicNumInUsrBuff = 0;
1407 struct timeval tv0, tv1;
1408 memset(&tv0, 0, sizeof(struct timeval));
1409 memset(&tv1, 0, sizeof(struct timeval));
1410 if ((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0)) {
1411 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1415 if (IsFlash2x(Adapter)) {
1416 if ((Adapter->eActiveDSD != DSD0) &&
1417 (Adapter->eActiveDSD != DSD1) &&
1418 (Adapter->eActiveDSD != DSD2)) {
1420 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No DSD is active..hence NVM Command is blocked");
1421 return STATUS_FAILURE;
1425 /* Copy Ioctl Buffer structure */
1426 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1429 if (copy_from_user(&stNVMReadWrite,
1430 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1431 sizeof(struct bcm_nvm_readwrite)))
1435 * Deny the access if the offset crosses the cal area limit.
1437 if (stNVMReadWrite.uiNumBytes > Adapter->uiNVMDSDSize)
1438 return STATUS_FAILURE;
1440 if (stNVMReadWrite.uiOffset > Adapter->uiNVMDSDSize - stNVMReadWrite.uiNumBytes) {
1441 /* 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); */
1442 return STATUS_FAILURE;
1445 pReadData = memdup_user(stNVMReadWrite.pBuffer,
1446 stNVMReadWrite.uiNumBytes);
1447 if (IS_ERR(pReadData))
1448 return PTR_ERR(pReadData);
1450 do_gettimeofday(&tv0);
1451 if (IOCTL_BCM_NVM_READ == cmd) {
1452 down(&Adapter->NVMRdmWrmLock);
1454 if ((Adapter->IdleMode == TRUE) ||
1455 (Adapter->bShutStatus == TRUE) ||
1456 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1458 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1459 up(&Adapter->NVMRdmWrmLock);
1464 Status = BeceemNVMRead(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1465 up(&Adapter->NVMRdmWrmLock);
1467 if (Status != STATUS_SUCCESS) {
1472 if (copy_to_user(stNVMReadWrite.pBuffer, pReadData, stNVMReadWrite.uiNumBytes)) {
1477 down(&Adapter->NVMRdmWrmLock);
1479 if ((Adapter->IdleMode == TRUE) ||
1480 (Adapter->bShutStatus == TRUE) ||
1481 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1483 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1484 up(&Adapter->NVMRdmWrmLock);
1489 Adapter->bHeaderChangeAllowed = TRUE;
1490 if (IsFlash2x(Adapter)) {
1493 * DSD section updation will be allowed in two case:-
1494 * 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1495 * 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1496 * corrupted then user space program first modify the DSD header with valid DSD sig so
1497 * that this as well as further write may be worthwhile.
1499 * This restriction has been put assuming that if DSD sig is corrupted, DSD
1500 * data won't be considered valid.
1503 Status = BcmFlash2xCorruptSig(Adapter, Adapter->eActiveDSD);
1504 if (Status != STATUS_SUCCESS) {
1505 if (((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize) ||
1506 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE)) {
1508 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1509 up(&Adapter->NVMRdmWrmLock);
1514 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1515 if (ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER) {
1516 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1517 up(&Adapter->NVMRdmWrmLock);
1524 Status = BeceemNVMWrite(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1525 if (IsFlash2x(Adapter))
1526 BcmFlash2xWriteSig(Adapter, Adapter->eActiveDSD);
1528 Adapter->bHeaderChangeAllowed = false;
1530 up(&Adapter->NVMRdmWrmLock);
1532 if (Status != STATUS_SUCCESS) {
1538 do_gettimeofday(&tv1);
1539 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);
1542 return STATUS_SUCCESS;
1545 case IOCTL_BCM_FLASH2X_SECTION_READ: {
1546 struct bcm_flash2x_readwrite sFlash2xRead = {0};
1547 PUCHAR pReadBuff = NULL;
1551 UINT ReadOffset = 0;
1552 void __user *OutPutBuff;
1554 if (IsFlash2x(Adapter) != TRUE) {
1555 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1559 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1560 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1563 /* Reading FLASH 2.x READ structure */
1564 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
1567 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xRead.Section);
1568 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%x", sFlash2xRead.offset);
1569 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xRead.numOfBytes);
1570 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xRead.bVerify);
1572 /* This was internal to driver for raw read. now it has ben exposed to user space app. */
1573 if (validateFlash2xReadWrite(Adapter, &sFlash2xRead) == false)
1574 return STATUS_FAILURE;
1576 NOB = sFlash2xRead.numOfBytes;
1577 if (NOB > Adapter->uiSectorSize)
1578 BuffSize = Adapter->uiSectorSize;
1582 ReadOffset = sFlash2xRead.offset;
1583 OutPutBuff = IoBuffer.OutputBuffer;
1584 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1586 if (pReadBuff == NULL) {
1587 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1590 down(&Adapter->NVMRdmWrmLock);
1592 if ((Adapter->IdleMode == TRUE) ||
1593 (Adapter->bShutStatus == TRUE) ||
1594 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1596 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1597 up(&Adapter->NVMRdmWrmLock);
1603 if (NOB > Adapter->uiSectorSize)
1604 ReadBytes = Adapter->uiSectorSize;
1608 /* Reading the data from Flash 2.x */
1609 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pReadBuff, sFlash2xRead.Section, ReadOffset, ReadBytes);
1611 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Flash 2x read err with Status :%d", Status);
1615 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1617 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1619 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status);
1620 up(&Adapter->NVMRdmWrmLock);
1624 NOB = NOB - ReadBytes;
1626 ReadOffset = ReadOffset + ReadBytes;
1627 OutPutBuff = OutPutBuff + ReadBytes;
1631 up(&Adapter->NVMRdmWrmLock);
1636 case IOCTL_BCM_FLASH2X_SECTION_WRITE: {
1637 struct bcm_flash2x_readwrite sFlash2xWrite = {0};
1639 void __user *InputAddr;
1642 UINT WriteOffset = 0;
1643 UINT WriteBytes = 0;
1645 if (IsFlash2x(Adapter) != TRUE) {
1646 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1650 /* First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite */
1651 Adapter->bAllDSDWriteAllow = false;
1653 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1655 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1658 /* Reading FLASH 2.x READ structure */
1659 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
1662 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xWrite.Section);
1663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%d", sFlash2xWrite.offset);
1664 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite.numOfBytes);
1665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite.bVerify);
1667 if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) && (sFlash2xWrite.Section != VSA2)) {
1668 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Only VSA write is allowed");
1672 if (validateFlash2xReadWrite(Adapter, &sFlash2xWrite) == false)
1673 return STATUS_FAILURE;
1675 InputAddr = sFlash2xWrite.pDataBuff;
1676 WriteOffset = sFlash2xWrite.offset;
1677 NOB = sFlash2xWrite.numOfBytes;
1679 if (NOB > Adapter->uiSectorSize)
1680 BuffSize = Adapter->uiSectorSize;
1684 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1686 if (pWriteBuff == NULL)
1689 /* extracting the remainder of the given offset. */
1690 WriteBytes = Adapter->uiSectorSize;
1691 if (WriteOffset % Adapter->uiSectorSize)
1692 WriteBytes = Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1694 if (NOB < WriteBytes)
1697 down(&Adapter->NVMRdmWrmLock);
1699 if ((Adapter->IdleMode == TRUE) ||
1700 (Adapter->bShutStatus == TRUE) ||
1701 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1703 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1704 up(&Adapter->NVMRdmWrmLock);
1709 BcmFlash2xCorruptSig(Adapter, sFlash2xWrite.Section);
1711 Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
1713 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status);
1714 up(&Adapter->NVMRdmWrmLock);
1718 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
1720 /* Writing the data from Flash 2.x */
1721 Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pWriteBuff, sFlash2xWrite.Section, WriteOffset, WriteBytes, sFlash2xWrite.bVerify);
1724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1728 NOB = NOB - WriteBytes;
1730 WriteOffset = WriteOffset + WriteBytes;
1731 InputAddr = InputAddr + WriteBytes;
1732 if (NOB > Adapter->uiSectorSize)
1733 WriteBytes = Adapter->uiSectorSize;
1739 BcmFlash2xWriteSig(Adapter, sFlash2xWrite.Section);
1740 up(&Adapter->NVMRdmWrmLock);
1745 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP: {
1746 struct bcm_flash2x_bitmap *psFlash2xBitMap;
1747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1749 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1752 if (IoBuffer.OutputLength != sizeof(struct bcm_flash2x_bitmap))
1755 psFlash2xBitMap = kzalloc(sizeof(struct bcm_flash2x_bitmap), GFP_KERNEL);
1756 if (psFlash2xBitMap == NULL) {
1757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory is not available");
1761 /* Reading the Flash Sectio Bit map */
1762 down(&Adapter->NVMRdmWrmLock);
1764 if ((Adapter->IdleMode == TRUE) ||
1765 (Adapter->bShutStatus == TRUE) ||
1766 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1768 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1769 up(&Adapter->NVMRdmWrmLock);
1770 kfree(psFlash2xBitMap);
1774 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1775 up(&Adapter->NVMRdmWrmLock);
1776 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(struct bcm_flash2x_bitmap))) {
1777 kfree(psFlash2xBitMap);
1781 kfree(psFlash2xBitMap);
1785 case IOCTL_BCM_SET_ACTIVE_SECTION: {
1786 enum bcm_flash2x_section_val eFlash2xSectionVal = 0;
1787 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1789 if (IsFlash2x(Adapter) != TRUE) {
1790 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1794 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1796 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1800 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1802 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1806 down(&Adapter->NVMRdmWrmLock);
1808 if ((Adapter->IdleMode == TRUE) ||
1809 (Adapter->bShutStatus == TRUE) ||
1810 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1812 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1813 up(&Adapter->NVMRdmWrmLock);
1817 Status = BcmSetActiveSection(Adapter, eFlash2xSectionVal);
1819 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Failed to make it's priority Highest. Status %d", Status);
1821 up(&Adapter->NVMRdmWrmLock);
1825 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION: {
1826 /* Right Now we are taking care of only DSD */
1827 Adapter->bAllDSDWriteAllow = false;
1828 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1829 Status = STATUS_SUCCESS;
1833 case IOCTL_BCM_COPY_SECTION: {
1834 struct bcm_flash2x_copy_section sCopySectStrut = {0};
1835 Status = STATUS_SUCCESS;
1836 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1838 Adapter->bAllDSDWriteAllow = false;
1839 if (IsFlash2x(Adapter) != TRUE) {
1840 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1844 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1846 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1850 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_copy_section));
1852 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1856 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1857 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1858 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1859 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1861 if (IsSectionExistInFlash(Adapter, sCopySectStrut.SrcSection) == false) {
1862 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source Section<%x> does not exist in Flash ", sCopySectStrut.SrcSection);
1866 if (IsSectionExistInFlash(Adapter, sCopySectStrut.DstSection) == false) {
1867 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Destinatio Section<%x> does not exist in Flash ", sCopySectStrut.DstSection);
1871 if (sCopySectStrut.SrcSection == sCopySectStrut.DstSection) {
1872 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source and Destination section should be different");
1876 down(&Adapter->NVMRdmWrmLock);
1878 if ((Adapter->IdleMode == TRUE) ||
1879 (Adapter->bShutStatus == TRUE) ||
1880 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1882 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1883 up(&Adapter->NVMRdmWrmLock);
1887 if (sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2) {
1888 if (IsNonCDLessDevice(Adapter)) {
1889 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is Non-CDLess hence won't have ISO !!");
1891 } else if (sCopySectStrut.numOfBytes == 0) {
1892 Status = BcmCopyISO(Adapter, sCopySectStrut);
1894 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Partial Copy of ISO section is not Allowed..");
1895 Status = STATUS_FAILURE;
1897 up(&Adapter->NVMRdmWrmLock);
1901 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
1902 sCopySectStrut.DstSection, sCopySectStrut.offset, sCopySectStrut.numOfBytes);
1903 up(&Adapter->NVMRdmWrmLock);
1907 case IOCTL_BCM_GET_FLASH_CS_INFO: {
1908 Status = STATUS_SUCCESS;
1909 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1911 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1913 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1917 if (Adapter->eNVMType != NVM_FLASH) {
1918 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Connected device does not have flash");
1923 if (IsFlash2x(Adapter) == TRUE) {
1924 if (IoBuffer.OutputLength < sizeof(struct bcm_flash2x_cs_info))
1927 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(struct bcm_flash2x_cs_info)))
1930 if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info))
1933 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash_cs_info)))
1939 case IOCTL_BCM_SELECT_DSD: {
1941 enum bcm_flash2x_section_val eFlash2xSectionVal;
1942 eFlash2xSectionVal = NO_SECTION_VAL;
1943 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SELECT_DSD Called");
1945 if (IsFlash2x(Adapter) != TRUE) {
1946 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1950 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1952 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1955 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1957 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1961 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal);
1962 if ((eFlash2xSectionVal != DSD0) &&
1963 (eFlash2xSectionVal != DSD1) &&
1964 (eFlash2xSectionVal != DSD2)) {
1966 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Passed section<%x> is not DSD section", eFlash2xSectionVal);
1967 return STATUS_FAILURE;
1970 SectOfset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
1971 if (SectOfset == INVALID_OFFSET) {
1972 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Provided Section val <%d> does not exist in Flash 2.x", eFlash2xSectionVal);
1976 Adapter->bAllDSDWriteAllow = TRUE;
1977 Adapter->ulFlashCalStart = SectOfset;
1978 Adapter->eActiveDSD = eFlash2xSectionVal;
1980 Status = STATUS_SUCCESS;
1983 case IOCTL_BCM_NVM_RAW_READ: {
1984 struct bcm_nvm_readwrite stNVMRead;
1990 void __user *OutPutBuff;
1992 if (Adapter->eNVMType != NVM_FLASH) {
1993 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "NVM TYPE is not Flash");
1997 /* Copy Ioctl Buffer structure */
1998 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
1999 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
2003 if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(struct bcm_nvm_readwrite)))
2006 NOB = stNVMRead.uiNumBytes;
2007 /* In Raw-Read max Buff size : 64MB */
2009 if (NOB > DEFAULT_BUFF_SIZE)
2010 BuffSize = DEFAULT_BUFF_SIZE;
2014 ReadOffset = stNVMRead.uiOffset;
2015 OutPutBuff = stNVMRead.pBuffer;
2017 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
2018 if (pReadBuff == NULL) {
2019 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
2023 down(&Adapter->NVMRdmWrmLock);
2025 if ((Adapter->IdleMode == TRUE) ||
2026 (Adapter->bShutStatus == TRUE) ||
2027 (Adapter->bPreparingForLowPowerMode == TRUE)) {
2029 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
2031 up(&Adapter->NVMRdmWrmLock);
2035 Adapter->bFlashRawRead = TRUE;
2038 if (NOB > DEFAULT_BUFF_SIZE)
2039 ReadBytes = DEFAULT_BUFF_SIZE;
2043 /* Reading the data from Flash 2.x */
2044 Status = BeceemNVMRead(Adapter, (PUINT)pReadBuff, ReadOffset, ReadBytes);
2046 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
2050 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
2052 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
2054 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status);
2055 up(&Adapter->NVMRdmWrmLock);
2059 NOB = NOB - ReadBytes;
2061 ReadOffset = ReadOffset + ReadBytes;
2062 OutPutBuff = OutPutBuff + ReadBytes;
2065 Adapter->bFlashRawRead = false;
2066 up(&Adapter->NVMRdmWrmLock);
2071 case IOCTL_BCM_CNTRLMSG_MASK: {
2072 ULONG RxCntrlMsgBitMask = 0;
2074 /* Copy Ioctl Buffer structure */
2075 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
2077 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space");
2081 if (IoBuffer.InputLength != sizeof(unsigned long)) {
2086 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
2088 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space");
2091 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
2092 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;
2096 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO: {
2097 struct bcm_driver_info DevInfo;
2099 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2101 memset(&DevInfo, 0, sizeof(DevInfo));
2102 DevInfo.MaxRDMBufferSize = BUFFER_4K;
2103 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
2104 DevInfo.u32RxAlignmentCorrection = 0;
2105 DevInfo.u32NVMType = Adapter->eNVMType;
2106 DevInfo.u32InterfaceType = BCM_USB;
2108 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
2111 if (IoBuffer.OutputLength < sizeof(DevInfo))
2114 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
2119 case IOCTL_BCM_TIME_SINCE_NET_ENTRY: {
2120 struct bcm_time_elapsed stTimeElapsedSinceNetEntry = {0};
2122 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2124 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
2127 if (IoBuffer.OutputLength < sizeof(struct bcm_time_elapsed))
2130 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
2132 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(struct bcm_time_elapsed)))
2137 case IOCTL_CLOSE_NOTIFICATION:
2138 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_CLOSE_NOTIFICATION");
2142 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2143 Status = STATUS_FAILURE;
2150 static const struct file_operations bcm_fops = {
2151 .owner = THIS_MODULE,
2152 .open = bcm_char_open,
2153 .release = bcm_char_release,
2154 .read = bcm_char_read,
2155 .unlocked_ioctl = bcm_char_ioctl,
2156 .llseek = no_llseek,
2159 int register_control_device_interface(struct bcm_mini_adapter *Adapter)
2162 if (Adapter->major > 0)
2163 return Adapter->major;
2165 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
2166 if (Adapter->major < 0) {
2167 pr_err(DRV_NAME ": could not created character device\n");
2168 return Adapter->major;
2171 Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
2172 MKDEV(Adapter->major, 0),
2175 if (IS_ERR(Adapter->pstCreatedClassDevice)) {
2176 pr_err(DRV_NAME ": class device create failed\n");
2177 unregister_chrdev(Adapter->major, DEV_NAME);
2178 return PTR_ERR(Adapter->pstCreatedClassDevice);
2184 void unregister_control_device_interface(struct bcm_mini_adapter *Adapter)
2186 if (Adapter->major > 0) {
2187 device_destroy(bcm_class, MKDEV(Adapter->major, 0));
2188 unregister_chrdev(Adapter->major, DEV_NAME);