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 ****************************************************************/
15 static struct class *bcm_class = NULL;
16 static int bcm_char_open(struct inode *inode, struct file * filp)
18 PMINI_ADAPTER Adapter = NULL;
19 PPER_TARANG_DATA pTarang = NULL;
21 Adapter = GET_BCM_ADAPTER(gblpnetdev);
22 pTarang = (PPER_TARANG_DATA)kmalloc(sizeof(PER_TARANG_DATA), GFP_KERNEL);
26 memset (pTarang, 0, sizeof(PER_TARANG_DATA));
27 pTarang->Adapter = Adapter;
28 pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB) ;
30 down(&Adapter->RxAppControlQueuelock);
31 pTarang->next = Adapter->pTarangs;
32 Adapter->pTarangs = pTarang;
33 up(&Adapter->RxAppControlQueuelock);
35 /* Store the Adapter structure */
36 filp->private_data = pTarang;
38 /*Start Queuing the control response Packets*/
39 atomic_inc(&Adapter->ApplicationRunning);
41 nonseekable_open(inode, filp);
44 static int bcm_char_release(struct inode *inode, struct file *filp)
46 PPER_TARANG_DATA pTarang, tmp, ptmp;
47 PMINI_ADAPTER Adapter=NULL;
48 struct sk_buff * pkt, * npkt;
50 pTarang = (PPER_TARANG_DATA)filp->private_data;
54 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "ptarang is null\n");
58 Adapter = pTarang->Adapter;
60 down( &Adapter->RxAppControlQueuelock);
62 tmp = Adapter->pTarangs;
63 for ( ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next )
72 Adapter->pTarangs = tmp->next;
74 ptmp->next = tmp->next;
79 up( &Adapter->RxAppControlQueuelock);
83 pkt = pTarang->RxAppControlHead;
91 up( &Adapter->RxAppControlQueuelock);
93 /*Stop Queuing the control response Packets*/
94 atomic_dec(&Adapter->ApplicationRunning);
98 /* remove this filp from the asynchronously notified filp's */
99 filp->private_data = NULL;
103 static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
105 PPER_TARANG_DATA pTarang = (PPER_TARANG_DATA)filp->private_data;
106 PMINI_ADAPTER Adapter = pTarang->Adapter;
107 struct sk_buff* Packet = NULL;
111 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
112 (pTarang->RxAppControlHead || Adapter->device_removed));
113 if((wait_ret_val == -ERESTARTSYS))
115 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Exiting as i've been asked to exit!!!\n");
119 if(Adapter->device_removed)
121 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device Removed... Killing the Apps...\n");
125 if(FALSE == Adapter->fw_download_done)
128 down( &Adapter->RxAppControlQueuelock);
130 if(pTarang->RxAppControlHead)
132 Packet = pTarang->RxAppControlHead;
133 DEQUEUEPACKET(pTarang->RxAppControlHead,pTarang->RxAppControlTail);
134 pTarang->AppCtrlQueueLen--;
137 up(&Adapter->RxAppControlQueuelock);
141 PktLen = Packet->len;
142 if(copy_to_user(buf, Packet->data, PktLen))
144 bcm_kfree_skb(Packet);
145 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\nReturning from copy to user failure \n");
148 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read %d Bytes From Adapter packet = 0x%p by process %d!\n", PktLen, Packet, current->pid);
149 bcm_kfree_skb(Packet);
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 PPER_TARANG_DATA pTarang = (PPER_TARANG_DATA)filp->private_data;
159 void __user *argp = (void __user *)argp;
160 PMINI_ADAPTER Adapter = pTarang->Adapter;
161 INT Status = STATUS_FAILURE;
162 IOCTL_BUFFER IoBuffer={};
163 #ifndef BCM_SHM_INTERFACE
168 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg);
170 if(_IOC_TYPE(cmd) != BCM_IOCTL)
172 if(_IOC_DIR(cmd) & _IOC_READ)
173 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
174 else if (_IOC_DIR(cmd) & _IOC_WRITE)
175 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
176 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
177 Status = STATUS_SUCCESS;
182 if(Adapter->device_removed)
187 if(FALSE == Adapter->fw_download_done)
191 case IOCTL_MAC_ADDR_REQ:
193 case IOCTL_CM_REQUEST:
194 case IOCTL_SS_INFO_REQ:
195 case IOCTL_SEND_CONTROL_MESSAGE:
197 case IOCTL_BCM_GPIO_SET_REQUEST:
198 case IOCTL_BCM_GPIO_STATUS_REQUEST:
205 Status = vendorextnIoctl(Adapter, cmd, arg);
206 if(Status != CONTINUE_COMMON_PATH )
212 // Rdms for Swin Idle...
213 case IOCTL_BCM_REGISTER_READ_PRIVATE:
215 RDM_BUFFER sRdmBuffer = {0};
216 PCHAR temp_buff = NULL;
218 /* Copy Ioctl Buffer structure */
219 if(copy_from_user((PCHAR)&IoBuffer, argp,
220 sizeof(IOCTL_BUFFER)))
226 Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
227 temp_buff = (PCHAR)kmalloc(Bufflen, GFP_KERNEL);
230 return STATUS_FAILURE;
232 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
233 IoBuffer.InputLength))
238 Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
239 (PUINT)temp_buff, Bufflen);
240 if(Status != STATUS_SUCCESS)
242 bcm_kfree(temp_buff);
245 if(copy_to_user(IoBuffer.OutputBuffer,
246 (PCHAR)temp_buff, (UINT)IoBuffer.OutputLength))
250 bcm_kfree(temp_buff);
253 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
255 WRM_BUFFER sWrmBuffer = {0};
257 /* Copy Ioctl Buffer structure */
259 if(copy_from_user(&IoBuffer, argp,
260 sizeof(IOCTL_BUFFER)))
265 /* Get WrmBuffer structure */
266 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer,
267 IoBuffer.InputLength))
272 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
273 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
274 ((uiTempVar == EEPROM_REJECT_REG_1)||
275 (uiTempVar == EEPROM_REJECT_REG_2) ||
276 (uiTempVar == EEPROM_REJECT_REG_3) ||
277 (uiTempVar == EEPROM_REJECT_REG_4)))
279 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
283 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
284 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
285 if(Status == STATUS_SUCCESS)
287 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"WRM Done\n");
291 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
297 case IOCTL_BCM_REGISTER_READ:
298 case IOCTL_BCM_EEPROM_REGISTER_READ:
300 RDM_BUFFER sRdmBuffer = {0};
301 PCHAR temp_buff = NULL;
303 if((Adapter->IdleMode == TRUE) ||
304 (Adapter->bShutStatus ==TRUE) ||
305 (Adapter->bPreparingForLowPowerMode ==TRUE))
307 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
311 /* Copy Ioctl Buffer structure */
312 if(copy_from_user(&IoBuffer, argp,
313 sizeof(IOCTL_BUFFER)))
319 temp_buff = (PCHAR)kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
322 return STATUS_FAILURE;
324 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
325 IoBuffer.InputLength))
332 (((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
333 ((ULONG)sRdmBuffer.Register & 0x3)
336 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
337 (int)sRdmBuffer.Register);
342 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
343 Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
344 (PUINT)temp_buff, IoBuffer.OutputLength);
345 if(Status != STATUS_SUCCESS)
347 bcm_kfree(temp_buff);
350 if(copy_to_user(IoBuffer.OutputBuffer,
351 (PCHAR)temp_buff, (UINT)IoBuffer.OutputLength))
355 bcm_kfree(temp_buff);
358 case IOCTL_BCM_REGISTER_WRITE:
359 case IOCTL_BCM_EEPROM_REGISTER_WRITE:
361 WRM_BUFFER sWrmBuffer = {0};
363 if((Adapter->IdleMode == TRUE) ||
364 (Adapter->bShutStatus ==TRUE) ||
365 (Adapter->bPreparingForLowPowerMode ==TRUE))
367 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
371 /* Copy Ioctl Buffer structure */
372 if(copy_from_user((PCHAR)&IoBuffer, argp,
373 sizeof(IOCTL_BUFFER)))
378 /* Get WrmBuffer structure */
379 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer,
380 IoBuffer.InputLength))
387 (((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
388 ((ULONG)sWrmBuffer.Register & 0x3)
391 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n",
392 (int)sWrmBuffer.Register);
396 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
397 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
398 ((uiTempVar == EEPROM_REJECT_REG_1)||
399 (uiTempVar == EEPROM_REJECT_REG_2) ||
400 (uiTempVar == EEPROM_REJECT_REG_3) ||
401 (uiTempVar == EEPROM_REJECT_REG_4)) &&
402 (cmd == IOCTL_BCM_REGISTER_WRITE))
404 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
409 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
410 (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
411 if(Status == STATUS_SUCCESS)
413 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
417 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
422 case IOCTL_BCM_GPIO_SET_REQUEST:
424 UCHAR ucResetValue[4];
427 UINT uiOperation = 0;
429 GPIO_INFO gpio_info = {0};
430 if((Adapter->IdleMode == TRUE) ||
431 (Adapter->bShutStatus ==TRUE) ||
432 (Adapter->bPreparingForLowPowerMode ==TRUE))
434 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
438 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
443 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
448 uiBit = gpio_info.uiGpioNumber;
449 uiOperation = gpio_info.uiGpioValue;
453 if(IsReqGpioIsLedInNVM(Adapter,value) ==FALSE)
455 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",value);
461 if(uiOperation)//Set - setting 1
463 //Set the gpio output register
464 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_SET_REG ,
465 (PUINT)(&value), sizeof(UINT));
466 if(Status == STATUS_SUCCESS)
468 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
472 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to set the %dth GPIO \n",uiBit);
476 else//Unset - setting 0
478 //Set the gpio output register
479 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_CLR_REG ,
480 (PUINT)(&value), sizeof(UINT));
481 if(Status == STATUS_SUCCESS)
483 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO bit\n");
487 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to clear the %dth GPIO \n",uiBit);
492 Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
493 (PUINT)ucResetValue, sizeof(UINT));
494 if (STATUS_SUCCESS != Status)
496 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO_MODE_REGISTER read failed");
499 //Set the gpio mode register to output
500 *(UINT*)ucResetValue |= (1<<uiBit);
501 Status = wrmaltWithLock(Adapter,GPIO_MODE_REGISTER ,
502 (PUINT)ucResetValue, sizeof(UINT));
503 if(Status == STATUS_SUCCESS)
505 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO to output Mode\n");
509 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
514 case BCM_LED_THREAD_STATE_CHANGE_REQ:
517 USER_THREAD_REQ threadReq = {0};
518 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"User made LED thread InActive");
520 if((Adapter->IdleMode == TRUE) ||
521 (Adapter->bShutStatus ==TRUE) ||
522 (Adapter->bPreparingForLowPowerMode ==TRUE))
524 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
528 Status =copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
531 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
536 Status= copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength);
539 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the InputBuffer from user space err:%d",Status);
543 //if LED thread is running(Actively or Inactively) set it state to make inactive
544 if(Adapter->LEDInfo.led_thread_running)
546 if(threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ)
548 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Activating thread req");
549 Adapter->DriverState = LED_THREAD_ACTIVE;
553 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DeActivating Thread req.....");
554 Adapter->DriverState = LED_THREAD_INACTIVE;
558 wake_up(&Adapter->LEDInfo.notify_led_event);
563 case IOCTL_BCM_GPIO_STATUS_REQUEST:
567 GPIO_INFO gpio_info = {0};
568 if((Adapter->IdleMode == TRUE) ||
569 (Adapter->bShutStatus ==TRUE) ||
570 (Adapter->bPreparingForLowPowerMode ==TRUE))
575 if(copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER))) {
579 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
584 uiBit = gpio_info.uiGpioNumber;
585 //Set the gpio output register
586 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
587 (PUINT)ucRead, sizeof(UINT));
588 if(Status != STATUS_SUCCESS)
590 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
596 case IOCTL_BCM_GPIO_MULTI_REQUEST:
598 UCHAR ucResetValue[4];
599 GPIO_MULTI_INFO gpio_multi_info[MAX_IDX];
600 PGPIO_MULTI_INFO pgpio_multi_info = (PGPIO_MULTI_INFO)gpio_multi_info;
602 memset( pgpio_multi_info, 0, MAX_IDX * sizeof( GPIO_MULTI_INFO));
604 if((Adapter->IdleMode == TRUE) ||
605 (Adapter->bShutStatus ==TRUE) ||
606 (Adapter->bPreparingForLowPowerMode ==TRUE))
611 Status = copy_from_user( (PCHAR)&IoBuffer, argp, sizeof( IOCTL_BUFFER));
614 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
619 Status = copy_from_user( &gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength);
622 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status);
626 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_info[WIMAX_IDX].uiGPIOMask)== FALSE)
628 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_info[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap);
633 /* Set the gpio output register */
635 if( ( pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
636 ( pgpio_multi_info[WIMAX_IDX].uiGPIOCommand))
638 /* Set 1's in GPIO OUTPUT REGISTER */
639 *(UINT*) ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
640 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
641 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
643 if( *(UINT*) ucResetValue)
644 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_SET_REG , (PUINT) ucResetValue, sizeof(ULONG));
646 if( Status != STATUS_SUCCESS)
648 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
652 /* Clear to 0's in GPIO OUTPUT REGISTER */
653 *(UINT*) ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
654 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
655 ( ~( pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
657 if( *(UINT*) ucResetValue)
658 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_CLR_REG , (PUINT) ucResetValue, sizeof(ULONG));
660 if( Status != STATUS_SUCCESS)
662 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_CLR_REG Failed." );
667 if( pgpio_multi_info[WIMAX_IDX].uiGPIOMask)
669 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
671 if(Status != STATUS_SUCCESS)
673 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"RDM to GPIO_PIN_STATE_REGISTER Failed.");
677 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = ( *(UINT*)ucResetValue &
678 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
681 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
684 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
690 case IOCTL_BCM_GPIO_MODE_REQUEST:
692 UCHAR ucResetValue[4];
693 GPIO_MULTI_MODE gpio_multi_mode[MAX_IDX];
694 PGPIO_MULTI_MODE pgpio_multi_mode = ( PGPIO_MULTI_MODE) gpio_multi_mode;
696 if((Adapter->IdleMode == TRUE) ||
697 (Adapter->bShutStatus ==TRUE) ||
698 (Adapter->bPreparingForLowPowerMode ==TRUE))
703 Status = copy_from_user(&IoBuffer, argp, sizeof( IOCTL_BUFFER));
706 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
711 Status = copy_from_user( &gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength);
714 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status);
719 Status = rdmaltWithLock( Adapter, ( UINT) GPIO_MODE_REGISTER, ( PUINT) ucResetValue, sizeof( UINT));
720 if( STATUS_SUCCESS != Status)
722 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Read of GPIO_MODE_REGISTER failed");
726 //Validating the request
727 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)== FALSE)
729 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_mode[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap);
734 if( pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)
736 /* write all OUT's (1's) */
737 *( UINT*) ucResetValue |= ( pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
738 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
739 /* write all IN's (0's) */
740 *( UINT*) ucResetValue &= ~( ( ~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
741 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
743 /* Currently implemented return the modes of all GPIO's
744 * else needs to bit AND with mask
746 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT*)ucResetValue;
748 Status = wrmaltWithLock( Adapter, GPIO_MODE_REGISTER , ( PUINT) ucResetValue, sizeof( ULONG));
749 if( Status == STATUS_SUCCESS)
751 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM to GPIO_MODE_REGISTER Done");
755 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to GPIO_MODE_REGISTER Failed");
760 else /* if uiGPIOMask is 0 then return mode register configuration */
762 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *( UINT*) ucResetValue;
764 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
767 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
774 case IOCTL_MAC_ADDR_REQ:
776 case IOCTL_CM_REQUEST:
777 case IOCTL_SS_INFO_REQ:
778 case IOCTL_SEND_CONTROL_MESSAGE:
782 /* Copy Ioctl Buffer structure */
783 if(copy_from_user(&IoBuffer, argp,
784 sizeof(IOCTL_BUFFER)))
789 pvBuffer=kmalloc(IoBuffer.InputLength, GFP_KERNEL);
795 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer,
796 IoBuffer.InputLength))
803 down(&Adapter->LowPowerModeSync);
804 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
805 !Adapter->bPreparingForLowPowerMode,
807 if(Status == -ERESTARTSYS)
810 if(Adapter->bPreparingForLowPowerMode)
812 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Preparing Idle Mode is still True - Hence Rejecting control message\n");
813 Status = STATUS_FAILURE ;
816 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
818 up(&Adapter->LowPowerModeSync);
822 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
824 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock) ;
827 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
830 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
831 if(!down_trylock(&Adapter->fw_download_sema))
833 Adapter->bBinDownloaded=FALSE;
834 Adapter->fw_download_process_pid=current->pid;
835 Adapter->bCfgDownloaded=FALSE;
836 Adapter->fw_download_done=FALSE;
837 netif_carrier_off(Adapter->dev);
838 netif_stop_queue(Adapter->dev);
839 Status = reset_card_proc(Adapter);
842 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "reset_card_proc Failed!\n");
843 up(&Adapter->fw_download_sema);
844 up(&Adapter->NVMRdmWrmLock);
855 up(&Adapter->NVMRdmWrmLock);
858 case IOCTL_BCM_BUFFER_DOWNLOAD:
860 FIRMWARE_INFO *psFwInfo=NULL;
861 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
863 if(!down_trylock(&Adapter->fw_download_sema))
865 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid way to download buffer. Use Start and then call this!!!\n");
869 /* Copy Ioctl Buffer structure */
870 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
872 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
876 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length for FW DLD is : %lx\n",
877 IoBuffer.InputLength);
878 psFwInfo=kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
881 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Failed to allocate buffer!!!!\n");
885 if(copy_from_user(psFwInfo, IoBuffer.InputBuffer,
886 IoBuffer.InputLength))
888 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_from_user 2 failed\n");
893 if(!psFwInfo->pvMappedFirmwareAddress ||
894 (psFwInfo->u32FirmwareLength == 0))
896 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
897 psFwInfo->u32FirmwareLength);
901 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
902 if(Status != STATUS_SUCCESS)
904 if(psFwInfo->u32StartingAddress==CONFIG_BEGIN_ADDR)
906 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
910 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
912 //up(&Adapter->fw_download_sema);
914 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
916 Adapter->DriverState = DRIVER_INIT;
917 Adapter->LEDInfo.bLedInitDone = FALSE;
918 wake_up(&Adapter->LEDInfo.notify_led_event);
924 if(Status != STATUS_SUCCESS)
925 up(&Adapter->fw_download_sema);
926 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
930 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
932 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
935 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " FW download blocked as EEPROM Read/Write is in progress\n");
936 up(&Adapter->fw_download_sema);
939 if(down_trylock(&Adapter->fw_download_sema))
941 Adapter->bBinDownloaded=TRUE;
942 Adapter->bCfgDownloaded=TRUE;
943 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
944 atomic_set(&Adapter->RxRollOverCount, 0);
945 Adapter->CurrNumRecvDescs=0;
946 Adapter->downloadDDR = 0;
948 //setting the Mips to Run
949 Status = run_card_proc(Adapter);
952 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
953 up(&Adapter->fw_download_sema);
954 up(&Adapter->NVMRdmWrmLock);
958 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Firm Download Over...\n");
960 /* Wait for MailBox Interrupt */
961 if(StartInterruptUrb((PS_INTERFACE_ADAPTER)Adapter->pvInterfaceAdapter))
963 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
966 Adapter->waiting_to_fw_download_done = FALSE;
967 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
968 Adapter->waiting_to_fw_download_done, timeout);
969 Adapter->fw_download_process_pid=INVALID_PID;
970 Adapter->fw_download_done=TRUE;
971 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
972 Adapter->CurrNumRecvDescs = 0;
973 Adapter->PrevNumRecvDescs = 0;
974 atomic_set(&Adapter->cntrlpktCnt,0);
975 Adapter->LinkUpStatus = 0;
976 Adapter->LinkStatus = 0;
978 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
980 Adapter->DriverState = FW_DOWNLOAD_DONE;
981 wake_up(&Adapter->LEDInfo.notify_led_event);
993 up(&Adapter->fw_download_sema);
994 up(&Adapter->NVMRdmWrmLock);
997 case IOCTL_BE_BUCKET_SIZE:
998 Adapter->BEBucketSize = *(PULONG)arg;
999 Status = STATUS_SUCCESS;
1002 case IOCTL_RTPS_BUCKET_SIZE:
1003 Adapter->rtPSBucketSize = *(PULONG)arg;
1004 Status = STATUS_SUCCESS;
1006 case IOCTL_CHIP_RESET:
1008 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1011 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
1014 down(&Adapter->RxAppControlQueuelock);
1015 Status = reset_card_proc(Adapter);
1017 up(&Adapter->RxAppControlQueuelock);
1018 up(&Adapter->NVMRdmWrmLock);
1019 ResetCounters(Adapter);
1022 case IOCTL_QOS_THRESHOLD:
1025 for(uiLoopIndex = 0 ; uiLoopIndex < NO_OF_QUEUES ; uiLoopIndex++)
1027 Adapter->PackInfo[uiLoopIndex].uiThreshold = *(PULONG)arg;
1029 Status = STATUS_SUCCESS;
1033 case IOCTL_DUMP_PACKET_INFO:
1035 DumpPackInfo(Adapter);
1036 DumpPhsRules(&Adapter->stBCMPhsContext);
1037 Status = STATUS_SUCCESS;
1040 case IOCTL_GET_PACK_INFO:
1041 if(copy_to_user(argp, &Adapter->PackInfo,
1042 sizeof(PacketInfo)*NO_OF_QUEUES))
1047 Status = STATUS_SUCCESS;
1049 case IOCTL_BCM_SWITCH_TRANSFER_MODE:
1052 if(copy_from_user(&uiData, argp, sizeof(UINT)))
1057 if(uiData) /* Allow All Packets */
1059 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
1060 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
1062 else /* Allow IP only Packets */
1064 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
1065 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
1067 Status = STATUS_SUCCESS;
1071 case IOCTL_BCM_GET_DRIVER_VERSION:
1073 /* Copy Ioctl Buffer structure */
1074 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1079 if(copy_to_user(IoBuffer.OutputBuffer,
1080 VER_FILEVERSION_STR, (UINT)IoBuffer.OutputLength))
1085 Status = STATUS_SUCCESS;
1088 case IOCTL_BCM_GET_CURRENT_STATUS:
1090 LINK_STATE *plink_state = NULL;
1091 /* Copy Ioctl Buffer structure */
1092 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1094 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
1098 plink_state = (LINK_STATE*)arg;
1099 plink_state->bIdleMode = (UCHAR)Adapter->IdleMode;
1100 plink_state->bShutdownMode = Adapter->bShutStatus;
1101 plink_state->ucLinkStatus = (UCHAR)Adapter->LinkStatus;
1102 if(copy_to_user(IoBuffer.OutputBuffer,
1103 (PUCHAR)plink_state, (UINT)IoBuffer.OutputLength))
1105 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1109 Status = STATUS_SUCCESS;
1112 case IOCTL_BCM_SET_MAC_TRACING:
1115 /* copy ioctl Buffer structure */
1116 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1121 if(copy_from_user(&tracing_flag, IoBuffer.InputBuffer,sizeof(UINT)))
1127 Adapter->pTarangs->MacTracingEnabled = TRUE;
1129 Adapter->pTarangs->MacTracingEnabled = FALSE;
1132 case IOCTL_BCM_GET_DSX_INDICATION:
1135 if(copy_from_user((PCHAR)&IoBuffer, argp,
1136 sizeof(IOCTL_BUFFER)))
1138 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid IO buffer!!!" );
1142 if(IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt))
1144 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Mismatch req: %lx needed is =0x%zx!!!",
1145 IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
1148 if(copy_from_user(&ulSFId, IoBuffer.InputBuffer,
1151 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Invalid SFID!!! %lu", ulSFId );
1155 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId );
1156 get_dsx_sf_data_to_application(Adapter, ulSFId,
1157 IoBuffer.OutputBuffer);
1158 Status=STATUS_SUCCESS;
1161 case IOCTL_BCM_GET_HOST_MIBS:
1165 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1167 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_from user for IoBuff failed\n");
1172 if(IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS))
1174 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length Check failed %lu %zd\n", IoBuffer.OutputLength,
1175 sizeof(S_MIBS_HOST_STATS_MIBS));
1179 temp_buff = (PCHAR)kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
1183 return STATUS_FAILURE;
1186 Status = ProcessGetHostMibs(Adapter,
1187 (PUCHAR)temp_buff, IoBuffer.OutputLength);
1189 Status = GetDroppedAppCntrlPktMibs((PVOID)temp_buff,
1190 (PPER_TARANG_DATA)filp->private_data);
1192 if(copy_to_user(IoBuffer.OutputBuffer,(PCHAR)temp_buff,
1193 sizeof(S_MIBS_HOST_STATS_MIBS)))
1195 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy to user failed\n");
1196 bcm_kfree(temp_buff);
1200 bcm_kfree(temp_buff);
1204 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1205 if((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE==Adapter->IdleMode))
1207 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1208 Adapter->bWakeUpDevice = TRUE;
1209 wake_up(&Adapter->process_rx_cntrlpkt);
1211 Adapter->bTriedToWakeUpFromlowPowerMode = TRUE;
1212 InterfaceAbortIdlemode (Adapter, Adapter->usIdleModePattern);
1215 Status = STATUS_SUCCESS;
1218 case IOCTL_BCM_BULK_WRM:
1220 PBULKWRM_BUFFER pBulkBuffer;
1222 PCHAR pvBuffer = NULL;
1224 if((Adapter->IdleMode == TRUE) ||
1225 (Adapter->bShutStatus ==TRUE) ||
1226 (Adapter->bPreparingForLowPowerMode ==TRUE))
1228 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1232 /* Copy Ioctl Buffer structure */
1233 if(copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1239 pvBuffer=kmalloc(IoBuffer.InputLength, GFP_KERNEL);
1246 /* Get WrmBuffer structure */
1247 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
1249 bcm_kfree(pvBuffer);
1254 pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
1256 if(((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1257 ((ULONG)pBulkBuffer->Register & 0x3))
1259 bcm_kfree(pvBuffer);
1260 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer->Register);
1266 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1267 if(!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE)
1268 && ((uiTempVar == EEPROM_REJECT_REG_1)||
1269 (uiTempVar == EEPROM_REJECT_REG_2) ||
1270 (uiTempVar == EEPROM_REJECT_REG_3) ||
1271 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1272 (cmd == IOCTL_BCM_REGISTER_WRITE))
1274 bcm_kfree(pvBuffer);
1275 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"EEPROM Access Denied, not in VSG Mode\n");
1280 if(pBulkBuffer->SwapEndian == FALSE)
1281 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1283 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1285 if(Status != STATUS_SUCCESS)
1287 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1290 bcm_kfree(pvBuffer);
1294 case IOCTL_BCM_GET_NVM_SIZE:
1297 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1299 //IOLog("failed NVM first");
1303 if(Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH ) {
1304 if(copy_to_user(IoBuffer.OutputBuffer,
1305 (unsigned char *)&Adapter->uiNVMDSDSize, (UINT)sizeof(UINT)))
1312 Status = STATUS_SUCCESS ;
1316 case IOCTL_BCM_CAL_INIT :
1319 UINT uiSectorSize = 0 ;
1320 if(Adapter->eNVMType == NVM_FLASH)
1322 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1325 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy From User space failed. status :%d", Status);
1328 uiSectorSize = *((PUINT)(IoBuffer.InputBuffer)); /* FIXME: unchecked __user access */
1329 if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE))
1332 Status = copy_to_user(IoBuffer.OutputBuffer,
1333 (unsigned char *)&Adapter->uiSectorSize ,
1334 (UINT)sizeof(UINT));
1337 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Coping the sector size to use space failed. status:%d",Status);
1343 if(IsFlash2x(Adapter))
1345 Status = copy_to_user(IoBuffer.OutputBuffer,
1346 (unsigned char *)&Adapter->uiSectorSize ,
1347 (UINT)sizeof(UINT));
1350 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Coping the sector size to use space failed. status:%d",Status);
1357 if((TRUE == Adapter->bShutStatus) ||
1358 (TRUE == Adapter->IdleMode))
1360 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle/Shutdown Mode\n");
1364 Adapter->uiSectorSize = uiSectorSize ;
1365 BcmUpdateSectorSize(Adapter,Adapter->uiSectorSize);
1368 Status = STATUS_SUCCESS ;
1372 Status = STATUS_FAILURE;
1376 case IOCTL_BCM_SET_DEBUG :
1378 USER_BCM_DBG_STATE sUserDebugState;
1380 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG );
1382 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1383 Status = copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1386 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy from user failed\n");
1390 Status = copy_from_user(&sUserDebugState,IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE));
1393 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IoBuffer.InputBuffer failed");
1397 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1398 sUserDebugState.OnOff, sUserDebugState.Type);
1399 //sUserDebugState.Subtype <<= 1;
1400 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1401 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1403 // Update new 'DebugState' in the Adapter
1404 Adapter->stDebugState.type |= sUserDebugState.Type;
1405 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1406 * Valid indexes in 'subtype' array: 1,2,4,8
1407 * corresponding to valid Type values. Hence we can use the 'Type' field
1408 * as the index value, ignoring the array entries 0,3,5,6,7 !
1410 if (sUserDebugState.OnOff)
1411 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1413 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1415 BCM_SHOW_DEBUG_BITMAP(Adapter);
1419 case IOCTL_BCM_NVM_READ:
1420 case IOCTL_BCM_NVM_WRITE:
1423 NVM_READWRITE stNVMReadWrite = {};
1424 PUCHAR pReadData = NULL;
1425 void __user * pBuffertobeCopied = NULL;
1426 ULONG ulDSDMagicNumInUsrBuff = 0 ;
1427 struct timeval tv0, tv1;
1428 memset(&tv0,0,sizeof(struct timeval));
1429 memset(&tv1,0,sizeof(struct timeval));
1430 if((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0))
1432 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,"The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1437 if(IsFlash2x(Adapter))
1439 if((Adapter->eActiveDSD != DSD0) &&
1440 (Adapter->eActiveDSD != DSD1) &&
1441 (Adapter->eActiveDSD != DSD2))
1443 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"No DSD is active..hence NVM Command is blocked");
1444 return STATUS_FAILURE ;
1448 /* Copy Ioctl Buffer structure */
1450 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1452 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copy_from_user failed\n");
1456 if(IOCTL_BCM_NVM_READ == cmd)
1457 pBuffertobeCopied = IoBuffer.OutputBuffer;
1459 pBuffertobeCopied = IoBuffer.InputBuffer;
1461 if(copy_from_user(&stNVMReadWrite, pBuffertobeCopied,sizeof(NVM_READWRITE)))
1468 // Deny the access if the offset crosses the cal area limit.
1470 if((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) > Adapter->uiNVMDSDSize)
1472 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset ,
1473 // stNVMReadWrite.uiNumBytes);
1474 Status = STATUS_FAILURE;
1478 pReadData =(PCHAR)kmalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
1483 memset(pReadData,0,stNVMReadWrite.uiNumBytes);
1485 if(copy_from_user(pReadData, stNVMReadWrite.pBuffer,
1486 stNVMReadWrite.uiNumBytes))
1489 bcm_kfree(pReadData);
1493 do_gettimeofday(&tv0);
1494 if(IOCTL_BCM_NVM_READ == cmd)
1496 down(&Adapter->NVMRdmWrmLock);
1498 if((Adapter->IdleMode == TRUE) ||
1499 (Adapter->bShutStatus ==TRUE) ||
1500 (Adapter->bPreparingForLowPowerMode ==TRUE))
1502 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1503 up(&Adapter->NVMRdmWrmLock);
1504 bcm_kfree(pReadData);
1508 Status = BeceemNVMRead(Adapter, (PUINT)pReadData,
1509 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1511 up(&Adapter->NVMRdmWrmLock);
1513 if(Status != STATUS_SUCCESS)
1515 bcm_kfree(pReadData);
1518 if(copy_to_user(stNVMReadWrite.pBuffer,
1519 pReadData, (UINT)stNVMReadWrite.uiNumBytes))
1521 bcm_kfree(pReadData);
1528 down(&Adapter->NVMRdmWrmLock);
1530 if((Adapter->IdleMode == TRUE) ||
1531 (Adapter->bShutStatus ==TRUE) ||
1532 (Adapter->bPreparingForLowPowerMode ==TRUE))
1534 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1535 up(&Adapter->NVMRdmWrmLock);
1536 bcm_kfree(pReadData);
1540 Adapter->bHeaderChangeAllowed = TRUE ;
1541 if(IsFlash2x(Adapter))
1545 DSD section updation will be allowed in two case:-
1546 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1547 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1548 corrupted then user space program first modify the DSD header with valid DSD sig so
1549 that this as well as further write may be worthwhile.
1551 This restriction has been put assuming that if DSD sig is corrupted, DSD
1552 data won't be considered valid.
1556 Status = BcmFlash2xCorruptSig(Adapter,Adapter->eActiveDSD);
1557 if(Status != STATUS_SUCCESS)
1559 if(( (stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize ) ||
1560 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE))
1562 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1563 up(&Adapter->NVMRdmWrmLock);
1564 bcm_kfree(pReadData);
1568 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1569 if(ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER)
1571 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1572 up(&Adapter->NVMRdmWrmLock);
1573 bcm_kfree(pReadData);
1578 Status = BeceemNVMWrite(Adapter, (PUINT )pReadData,
1579 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1580 if(IsFlash2x(Adapter))
1581 BcmFlash2xWriteSig(Adapter,Adapter->eActiveDSD);
1583 Adapter->bHeaderChangeAllowed = FALSE ;
1585 up(&Adapter->NVMRdmWrmLock);
1588 if(Status != STATUS_SUCCESS)
1590 bcm_kfree(pReadData);
1594 do_gettimeofday(&tv1);
1595 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " timetaken by Write/read :%ld msec\n",(tv1.tv_sec - tv0.tv_sec)*1000 +(tv1.tv_usec - tv0.tv_usec)/1000);
1598 bcm_kfree(pReadData);
1599 Status = STATUS_SUCCESS;
1602 case IOCTL_BCM_FLASH2X_SECTION_READ :
1605 FLASH2X_READWRITE sFlash2xRead = {0};
1606 PUCHAR pReadBuff = NULL ;
1610 UINT ReadOffset = 0;
1611 char __user *OutPutBuff = NULL;
1613 if(IsFlash2x(Adapter) != TRUE)
1615 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1619 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1620 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1623 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1627 //Reading FLASH 2.x READ structure
1628 Status = copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,sizeof(FLASH2X_READWRITE));
1631 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Input Buffer failed");
1636 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xRead.Section);
1637 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%x" ,sFlash2xRead.offset);
1638 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xRead.numOfBytes);
1639 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xRead.bVerify);
1641 //This was internal to driver for raw read. now it has ben exposed to user space app.
1642 if(validateFlash2xReadWrite(Adapter,&sFlash2xRead) == FALSE)
1643 return STATUS_FAILURE ;
1645 NOB = sFlash2xRead.numOfBytes;
1646 if(NOB > Adapter->uiSectorSize )
1647 BuffSize = Adapter->uiSectorSize;
1651 ReadOffset = sFlash2xRead.offset ;
1652 OutPutBuff = IoBuffer.OutputBuffer;
1655 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1656 if(pReadBuff == NULL)
1658 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1661 down(&Adapter->NVMRdmWrmLock);
1663 if((Adapter->IdleMode == TRUE) ||
1664 (Adapter->bShutStatus ==TRUE) ||
1665 (Adapter->bPreparingForLowPowerMode ==TRUE))
1667 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1668 up(&Adapter->NVMRdmWrmLock);
1669 bcm_kfree(pReadBuff);
1676 if(NOB > Adapter->uiSectorSize )
1677 ReadBytes = Adapter->uiSectorSize;
1682 //Reading the data from Flash 2.x
1684 Status = BcmFlash2xBulkRead(Adapter,(PUINT)pReadBuff,sFlash2xRead.Section,ReadOffset,ReadBytes);
1687 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Flash 2x read err with Status :%d", Status);
1691 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes);
1693 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
1696 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Copy to use failed with status :%d", Status);
1700 NOB = NOB - ReadBytes;
1703 ReadOffset = ReadOffset + ReadBytes ;
1704 OutPutBuff = OutPutBuff + ReadBytes ;
1708 up(&Adapter->NVMRdmWrmLock);
1709 bcm_kfree(pReadBuff);
1713 case IOCTL_BCM_FLASH2X_SECTION_WRITE :
1715 FLASH2X_READWRITE sFlash2xWrite = {0};
1716 PUCHAR pWriteBuff = NULL;
1717 void __user *InputAddr = NULL;
1720 UINT WriteOffset = 0;
1721 UINT WriteBytes = 0;
1723 if(IsFlash2x(Adapter) != TRUE)
1725 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1729 //First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite
1730 Adapter->bAllDSDWriteAllow = FALSE;
1733 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1734 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1737 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1741 //Reading FLASH 2.x READ structure
1742 Status = copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE));
1745 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reading of output Buffer from IOCTL buffer fails");
1749 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite.Section);
1750 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite.offset);
1751 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite.numOfBytes);
1752 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite.bVerify);
1754 if((sFlash2xWrite.Section == ISO_IMAGE1) ||(sFlash2xWrite.Section == ISO_IMAGE2) ||
1755 (sFlash2xWrite.Section == DSD0) || (sFlash2xWrite.Section == DSD1) || (sFlash2xWrite.Section == DSD2))
1757 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"ISO/DSD Image write is not allowed.... ");
1758 return STATUS_FAILURE ;
1761 if((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) &&
1762 (sFlash2xWrite.Section != VSA2) )
1764 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Only VSA write is allowed");
1768 if(validateFlash2xReadWrite(Adapter,&sFlash2xWrite) == FALSE)
1769 return STATUS_FAILURE ;
1771 InputAddr = sFlash2xWrite.pDataBuff;
1772 WriteOffset = sFlash2xWrite.offset ;
1773 NOB = sFlash2xWrite.numOfBytes;
1775 if(NOB > Adapter->uiSectorSize )
1776 BuffSize = Adapter->uiSectorSize;
1780 pWriteBuff = (PCHAR)kmalloc(BuffSize, GFP_KERNEL);
1781 if(pWriteBuff == NULL)
1783 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1787 //extracting the remainder of the given offset.
1788 WriteBytes = Adapter->uiSectorSize ;
1789 if(WriteOffset % Adapter->uiSectorSize)
1790 WriteBytes =Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1791 if(NOB < WriteBytes)
1794 down(&Adapter->NVMRdmWrmLock);
1796 if((Adapter->IdleMode == TRUE) ||
1797 (Adapter->bShutStatus ==TRUE) ||
1798 (Adapter->bPreparingForLowPowerMode ==TRUE))
1800 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1801 up(&Adapter->NVMRdmWrmLock);
1802 bcm_kfree(pWriteBuff);
1806 BcmFlash2xCorruptSig(Adapter,sFlash2xWrite.Section);
1809 Status = copy_from_user(pWriteBuff,InputAddr,WriteBytes);
1812 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to user failed with status :%d", Status);
1816 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pWriteBuff,WriteBytes);
1817 //Writing the data from Flash 2.x
1818 Status = BcmFlash2xBulkWrite(Adapter,(PUINT)pWriteBuff,sFlash2xWrite.Section,WriteOffset,WriteBytes,sFlash2xWrite.bVerify);
1822 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
1826 NOB = NOB - WriteBytes;
1829 WriteOffset = WriteOffset + WriteBytes ;
1830 InputAddr = InputAddr + WriteBytes ;
1831 if(NOB > Adapter->uiSectorSize )
1832 WriteBytes = Adapter->uiSectorSize;
1839 BcmFlash2xWriteSig(Adapter,sFlash2xWrite.Section);
1840 up(&Adapter->NVMRdmWrmLock);
1841 bcm_kfree(pWriteBuff);
1844 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP :
1847 PFLASH2X_BITMAP psFlash2xBitMap = NULL ;
1848 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1850 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1853 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1856 if(IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
1858 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Structure size mismatch Lib :0x%lx Driver :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH2X_BITMAP));
1862 psFlash2xBitMap = (PFLASH2X_BITMAP)kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
1863 if(psFlash2xBitMap == NULL)
1865 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory is not available");
1868 //Reading the Flash Sectio Bit map
1869 down(&Adapter->NVMRdmWrmLock);
1871 if((Adapter->IdleMode == TRUE) ||
1872 (Adapter->bShutStatus ==TRUE) ||
1873 (Adapter->bPreparingForLowPowerMode ==TRUE))
1875 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1876 up(&Adapter->NVMRdmWrmLock);
1877 bcm_kfree(psFlash2xBitMap);
1881 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1882 up(&Adapter->NVMRdmWrmLock);
1883 Status = copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP));
1886 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash2x bitMap failed");
1887 bcm_kfree(psFlash2xBitMap);
1890 bcm_kfree(psFlash2xBitMap);
1893 case IOCTL_BCM_SET_ACTIVE_SECTION :
1895 FLASH2X_SECTION_VAL eFlash2xSectionVal = 0;
1896 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1898 if(IsFlash2x(Adapter) != TRUE)
1900 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1904 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1907 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1911 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
1914 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1918 down(&Adapter->NVMRdmWrmLock);
1920 if((Adapter->IdleMode == TRUE) ||
1921 (Adapter->bShutStatus ==TRUE) ||
1922 (Adapter->bPreparingForLowPowerMode ==TRUE))
1924 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1925 up(&Adapter->NVMRdmWrmLock);
1929 Status = BcmSetActiveSection(Adapter,eFlash2xSectionVal);
1932 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed to make it's priority Highest. Status %d", Status);
1934 up(&Adapter->NVMRdmWrmLock);
1937 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION :
1939 //Right Now we are taking care of only DSD
1940 Adapter->bAllDSDWriteAllow = FALSE ;
1941 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1944 SECTION_TYPE section = 0 ;
1947 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION Called");
1948 Status = copy_from_user((PCHAR)&IoBuffer, (PCHAR)arg, sizeof(IOCTL_BUFFER));
1951 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy of IOCTL BUFFER failed");
1954 Status = copy_from_user((PCHAR)section,(PCHAR)&IoBuffer, sizeof(INT));
1957 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy of section type failed failed");
1960 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", section);
1962 Adapter->ulFlashCalStart = Adapter->uiActiveDSDOffsetAtFwDld ;
1964 Status = STATUS_FAILURE ;
1966 Status = STATUS_SUCCESS ;
1969 case IOCTL_BCM_COPY_SECTION :
1971 FLASH2X_COPY_SECTION sCopySectStrut = {0};
1972 Status = STATUS_SUCCESS;
1973 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1975 Adapter->bAllDSDWriteAllow = FALSE ;
1976 if(IsFlash2x(Adapter) != TRUE)
1978 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1982 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1985 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1989 Status = copy_from_user(&sCopySectStrut,IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
1992 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1995 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1996 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1997 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1998 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
2001 if(IsSectionExistInFlash(Adapter,sCopySectStrut.SrcSection) == FALSE)
2003 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
2007 if(IsSectionExistInFlash(Adapter,sCopySectStrut.DstSection) == FALSE)
2009 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
2013 if(sCopySectStrut.SrcSection == sCopySectStrut.DstSection)
2015 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Source and Destination section should be different");
2019 down(&Adapter->NVMRdmWrmLock);
2021 if((Adapter->IdleMode == TRUE) ||
2022 (Adapter->bShutStatus ==TRUE) ||
2023 (Adapter->bPreparingForLowPowerMode ==TRUE))
2025 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
2026 up(&Adapter->NVMRdmWrmLock);
2030 if(sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2)
2032 if(IsNonCDLessDevice(Adapter))
2034 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is Non-CDLess hence won't have ISO !!");
2037 else if(sCopySectStrut.numOfBytes == 0)
2039 Status = BcmCopyISO(Adapter,sCopySectStrut);
2043 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Partial Copy of ISO section is not Allowed..");
2044 Status = STATUS_FAILURE ;
2046 up(&Adapter->NVMRdmWrmLock);
2050 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
2051 sCopySectStrut.DstSection,sCopySectStrut.offset,sCopySectStrut.numOfBytes);
2052 up(&Adapter->NVMRdmWrmLock);
2055 case IOCTL_BCM_GET_FLASH_CS_INFO :
2057 Status = STATUS_SUCCESS;
2058 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
2060 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2063 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2067 if(Adapter->eNVMType != NVM_FLASH)
2069 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Connected device does not have flash");
2073 if(IsFlash2x(Adapter) == TRUE)
2076 if(IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
2078 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. \nRequired size :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH2X_CS_INFO));
2083 Status = copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO));
2086 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash2x cs info failed");
2093 if(IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
2095 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. Required size :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH_CS_INFO));
2099 Status = copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO));
2102 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash CS info failed");
2110 case IOCTL_BCM_SELECT_DSD :
2113 FLASH2X_SECTION_VAL eFlash2xSectionVal;
2114 eFlash2xSectionVal = NO_SECTION_VAL ;
2115 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_SELECT_DSD Called");
2117 if(IsFlash2x(Adapter) != TRUE)
2119 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
2123 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2126 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2129 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
2132 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
2136 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", eFlash2xSectionVal);
2137 if((eFlash2xSectionVal != DSD0) &&
2138 (eFlash2xSectionVal != DSD1) &&
2139 (eFlash2xSectionVal != DSD2) )
2141 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Passed section<%x> is not DSD section", eFlash2xSectionVal);
2142 return STATUS_FAILURE ;
2145 SectOfset= BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
2146 if(SectOfset == INVALID_OFFSET)
2148 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
2152 Adapter->bAllDSDWriteAllow = TRUE ;
2154 Adapter->ulFlashCalStart = SectOfset ;
2155 Adapter->eActiveDSD = eFlash2xSectionVal;
2157 Status = STATUS_SUCCESS ;
2160 case IOCTL_BCM_NVM_RAW_READ :
2163 NVM_READWRITE stNVMRead = {};
2167 UINT ReadBytes = 0 ;
2168 PUCHAR pReadBuff = NULL ;
2169 char __user *OutPutBuff = NULL ;
2171 if(Adapter->eNVMType != NVM_FLASH)
2173 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"NVM TYPE is not Flash ");
2177 /* Copy Ioctl Buffer structure */
2178 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2180 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
2185 if(copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,sizeof(NVM_READWRITE)))
2191 NOB = stNVMRead.uiNumBytes;
2192 //In Raw-Read max Buff size : 64MB
2194 if(NOB > DEFAULT_BUFF_SIZE)
2195 BuffSize = DEFAULT_BUFF_SIZE;
2199 ReadOffset = stNVMRead.uiOffset ;
2200 OutPutBuff = stNVMRead.pBuffer;
2203 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
2204 if(pReadBuff == NULL)
2206 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
2210 down(&Adapter->NVMRdmWrmLock);
2212 if((Adapter->IdleMode == TRUE) ||
2213 (Adapter->bShutStatus ==TRUE) ||
2214 (Adapter->bPreparingForLowPowerMode ==TRUE))
2216 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
2217 bcm_kfree(pReadBuff);
2218 up(&Adapter->NVMRdmWrmLock);
2222 Adapter->bFlashRawRead = TRUE ;
2225 if(NOB > DEFAULT_BUFF_SIZE )
2226 ReadBytes = DEFAULT_BUFF_SIZE;
2230 //Reading the data from Flash 2.x
2231 Status = BeceemNVMRead(Adapter,(PUINT)pReadBuff,ReadOffset,ReadBytes);
2234 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
2238 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes);
2240 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
2243 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to use failed with status :%d", Status);
2247 NOB = NOB - ReadBytes;
2250 ReadOffset = ReadOffset + ReadBytes ;
2251 OutPutBuff = OutPutBuff + ReadBytes ;
2255 Adapter->bFlashRawRead = FALSE ;
2256 up(&Adapter->NVMRdmWrmLock);
2257 bcm_kfree(pReadBuff);
2261 case IOCTL_BCM_CNTRLMSG_MASK:
2263 ULONG RxCntrlMsgBitMask = 0 ;
2265 /* Copy Ioctl Buffer structure */
2266 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2269 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of Ioctl buffer is failed from user space");
2274 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
2277 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of control bit mask failed from user space");
2281 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
2282 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask ;
2285 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO:
2287 DEVICE_DRIVER_INFO DevInfo;
2289 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2291 DevInfo.MaxRDMBufferSize = BUFFER_4K;
2292 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
2293 DevInfo.u32RxAlignmentCorrection = 0;
2294 DevInfo.u32NVMType = Adapter->eNVMType;
2295 DevInfo.u32InterfaceType = BCM_USB;
2297 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2300 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2304 if(IoBuffer.OutputLength < sizeof(DevInfo))
2306 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"User Passed buffer length is less than actural buffer size");
2307 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"user passed buffer size :0x%lX, expected size :0x%zx",IoBuffer.OutputLength, sizeof(DevInfo));
2311 Status = copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo));
2314 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copying Dev info structure to user space buffer failed");
2321 case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
2323 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
2324 struct timeval tv = {0} ;
2326 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2328 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2331 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2335 if(IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
2337 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"User Passed buffer length:0x%lx is less than expected buff size :0x%zX",IoBuffer.OutputLength,sizeof(ST_TIME_ELAPSED));
2342 //stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = Adapter->liTimeSinceLastNetEntry;
2343 do_gettimeofday(&tv);
2344 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = tv.tv_sec - Adapter->liTimeSinceLastNetEntry;
2346 Status = copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED));
2349 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copying ST_TIME_ELAPSED structure to user space buffer failed");
2358 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "wrong input %x",cmd);
2359 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In default ioctl %d\n", cmd);
2360 Status = STATUS_FAILURE;
2368 static struct file_operations bcm_fops = {
2369 .owner = THIS_MODULE,
2370 .open = bcm_char_open,
2371 .release = bcm_char_release,
2372 .read = bcm_char_read,
2373 .unlocked_ioctl = bcm_char_ioctl,
2374 .llseek = no_llseek,
2378 int register_control_device_interface(PMINI_ADAPTER Adapter)
2380 if(Adapter->major>0)
2381 return Adapter->major;
2382 Adapter->major = register_chrdev(0, "tarang", &bcm_fops);
2383 if(Adapter->major < 0)
2385 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "register_chrdev:Failed to registering WiMax control char device!");
2386 return Adapter->major;
2390 bcm_class = class_create (THIS_MODULE, "tarang");
2391 if(IS_ERR (bcm_class))
2393 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Unable to create class\n");
2394 unregister_chrdev(Adapter->major, "tarang");
2398 Adapter->pstCreatedClassDevice = device_create (bcm_class, NULL,
2399 MKDEV(Adapter->major, 0),
2400 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)
2405 if(IS_ERR(Adapter->pstCreatedClassDevice))
2407 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "class device did not get created : %ld", PTR_ERR(Adapter->pstCreatedClassDevice) );
2409 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Got Major No: %d", Adapter->major);
2413 void unregister_control_device_interface(PMINI_ADAPTER Adapter)
2415 if(Adapter->major > 0)
2417 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying class device");
2418 device_destroy (bcm_class, MKDEV(Adapter->major, 0));
2420 if(!IS_ERR(bcm_class))
2422 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying created class ");
2423 class_destroy (bcm_class);
2426 if(Adapter->major > 0)
2428 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"unregistering character interface");
2429 unregister_chrdev(Adapter->major, "tarang");