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 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 = 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, min_t(size_t, PktLen, size)))
144 dev_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,
149 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
150 PktLen, Packet, current->pid);
151 dev_kfree_skb(Packet);
154 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<====\n");
158 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
160 PPER_TARANG_DATA pTarang = filp->private_data;
161 void __user *argp = (void __user *)arg;
162 PMINI_ADAPTER Adapter = pTarang->Adapter;
163 INT Status = STATUS_FAILURE;
165 IOCTL_BUFFER IoBuffer;
167 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg);
169 if(_IOC_TYPE(cmd) != BCM_IOCTL)
171 if(_IOC_DIR(cmd) & _IOC_READ)
172 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
173 else if (_IOC_DIR(cmd) & _IOC_WRITE)
174 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
175 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
176 Status = STATUS_SUCCESS;
181 if(Adapter->device_removed)
186 if(FALSE == Adapter->fw_download_done)
190 case IOCTL_MAC_ADDR_REQ:
192 case IOCTL_CM_REQUEST:
193 case IOCTL_SS_INFO_REQ:
194 case IOCTL_SEND_CONTROL_MESSAGE:
196 case IOCTL_BCM_GPIO_SET_REQUEST:
197 case IOCTL_BCM_GPIO_STATUS_REQUEST:
204 Status = vendorextnIoctl(Adapter, cmd, arg);
205 if(Status != CONTINUE_COMMON_PATH )
209 // Rdms for Swin Idle...
210 case IOCTL_BCM_REGISTER_READ_PRIVATE:
212 RDM_BUFFER sRdmBuffer = {0};
216 /* Copy Ioctl Buffer structure */
217 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
220 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
223 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
226 /* FIXME: need to restrict BuffLen */
227 Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
228 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
232 Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
233 (PUINT)temp_buff, Bufflen);
234 if(Status == STATUS_SUCCESS)
236 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
243 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
245 WRM_BUFFER sWrmBuffer = {0};
247 /* Copy Ioctl Buffer structure */
249 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
252 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
255 /* Get WrmBuffer structure */
256 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
259 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
260 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
261 ((uiTempVar == EEPROM_REJECT_REG_1)||
262 (uiTempVar == EEPROM_REJECT_REG_2) ||
263 (uiTempVar == EEPROM_REJECT_REG_3) ||
264 (uiTempVar == EEPROM_REJECT_REG_4)))
266 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
269 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
270 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
271 if(Status == STATUS_SUCCESS)
273 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"WRM Done\n");
277 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
283 case IOCTL_BCM_REGISTER_READ:
284 case IOCTL_BCM_EEPROM_REGISTER_READ:
286 RDM_BUFFER sRdmBuffer = {0};
287 PCHAR temp_buff = NULL;
289 if((Adapter->IdleMode == TRUE) ||
290 (Adapter->bShutStatus ==TRUE) ||
291 (Adapter->bPreparingForLowPowerMode ==TRUE))
293 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
296 /* Copy Ioctl Buffer structure */
297 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
300 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
303 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
306 /* FIXME: don't trust user supplied length */
307 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
309 return STATUS_FAILURE;
311 if((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
312 ((ULONG)sRdmBuffer.Register & 0x3))
314 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
315 (int)sRdmBuffer.Register);
319 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
320 Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
321 (PUINT)temp_buff, IoBuffer.OutputLength);
322 if(Status == STATUS_SUCCESS)
323 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
329 case IOCTL_BCM_REGISTER_WRITE:
330 case IOCTL_BCM_EEPROM_REGISTER_WRITE:
332 WRM_BUFFER sWrmBuffer = {0};
334 if((Adapter->IdleMode == TRUE) ||
335 (Adapter->bShutStatus ==TRUE) ||
336 (Adapter->bPreparingForLowPowerMode ==TRUE))
338 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
342 /* Copy Ioctl Buffer structure */
343 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
346 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
349 /* Get WrmBuffer structure */
350 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
353 if( (((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
354 ((ULONG)sWrmBuffer.Register & 0x3) )
356 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n",
357 (int)sWrmBuffer.Register);
361 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
362 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
363 ((uiTempVar == EEPROM_REJECT_REG_1)||
364 (uiTempVar == EEPROM_REJECT_REG_2) ||
365 (uiTempVar == EEPROM_REJECT_REG_3) ||
366 (uiTempVar == EEPROM_REJECT_REG_4)) &&
367 (cmd == IOCTL_BCM_REGISTER_WRITE))
369 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
373 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
374 (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
375 if(Status == STATUS_SUCCESS)
377 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
381 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
386 case IOCTL_BCM_GPIO_SET_REQUEST:
388 UCHAR ucResetValue[4];
391 UINT uiOperation = 0;
393 GPIO_INFO gpio_info = {0};
394 if((Adapter->IdleMode == TRUE) ||
395 (Adapter->bShutStatus ==TRUE) ||
396 (Adapter->bPreparingForLowPowerMode ==TRUE))
398 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
401 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
403 if (IoBuffer.InputLength > sizeof(gpio_info))
405 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
407 uiBit = gpio_info.uiGpioNumber;
408 uiOperation = gpio_info.uiGpioValue;
412 if(IsReqGpioIsLedInNVM(Adapter,value) ==FALSE)
414 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",value);
420 if(uiOperation)//Set - setting 1
422 //Set the gpio output register
423 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_SET_REG ,
424 (PUINT)(&value), sizeof(UINT));
425 if(Status == STATUS_SUCCESS)
427 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
431 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to set the %dth GPIO \n",uiBit);
435 else//Unset - setting 0
437 //Set the gpio output register
438 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_CLR_REG ,
439 (PUINT)(&value), sizeof(UINT));
440 if(Status == STATUS_SUCCESS)
442 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO bit\n");
446 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to clear the %dth GPIO \n",uiBit);
451 Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
452 (PUINT)ucResetValue, sizeof(UINT));
453 if (STATUS_SUCCESS != Status)
455 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO_MODE_REGISTER read failed");
458 //Set the gpio mode register to output
459 *(UINT*)ucResetValue |= (1<<uiBit);
460 Status = wrmaltWithLock(Adapter,GPIO_MODE_REGISTER ,
461 (PUINT)ucResetValue, sizeof(UINT));
462 if(Status == STATUS_SUCCESS)
464 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO to output Mode\n");
468 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
473 case BCM_LED_THREAD_STATE_CHANGE_REQ:
475 USER_THREAD_REQ threadReq = { 0 };
476 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"User made LED thread InActive");
478 if((Adapter->IdleMode == TRUE) ||
479 (Adapter->bShutStatus ==TRUE) ||
480 (Adapter->bPreparingForLowPowerMode ==TRUE))
482 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
487 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
490 if (IoBuffer.InputLength > sizeof(threadReq))
493 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
496 //if LED thread is running(Actively or Inactively) set it state to make inactive
497 if(Adapter->LEDInfo.led_thread_running)
499 if(threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ)
501 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Activating thread req");
502 Adapter->DriverState = LED_THREAD_ACTIVE;
506 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DeActivating Thread req.....");
507 Adapter->DriverState = LED_THREAD_INACTIVE;
511 wake_up(&Adapter->LEDInfo.notify_led_event);
516 case IOCTL_BCM_GPIO_STATUS_REQUEST:
520 GPIO_INFO gpio_info = {0};
521 if((Adapter->IdleMode == TRUE) ||
522 (Adapter->bShutStatus ==TRUE) ||
523 (Adapter->bPreparingForLowPowerMode ==TRUE))
525 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
527 if (IoBuffer.InputLength > sizeof(gpio_info))
529 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
531 uiBit = gpio_info.uiGpioNumber;
532 //Set the gpio output register
533 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
534 (PUINT)ucRead, sizeof(UINT));
535 if(Status != STATUS_SUCCESS)
537 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
543 case IOCTL_BCM_GPIO_MULTI_REQUEST:
545 UCHAR ucResetValue[4];
546 GPIO_MULTI_INFO gpio_multi_info[MAX_IDX];
547 PGPIO_MULTI_INFO pgpio_multi_info = (PGPIO_MULTI_INFO)gpio_multi_info;
549 memset( pgpio_multi_info, 0, MAX_IDX * sizeof( GPIO_MULTI_INFO));
551 if((Adapter->IdleMode == TRUE) ||
552 (Adapter->bShutStatus ==TRUE) ||
553 (Adapter->bPreparingForLowPowerMode ==TRUE))
555 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
557 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
559 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
562 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_info[WIMAX_IDX].uiGPIOMask)== FALSE)
564 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);
569 /* Set the gpio output register */
571 if( ( pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
572 ( pgpio_multi_info[WIMAX_IDX].uiGPIOCommand))
574 /* Set 1's in GPIO OUTPUT REGISTER */
575 *(UINT*) ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
576 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
577 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
579 if( *(UINT*) ucResetValue)
580 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_SET_REG , (PUINT) ucResetValue, sizeof(ULONG));
582 if( Status != STATUS_SUCCESS)
584 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
588 /* Clear to 0's in GPIO OUTPUT REGISTER */
589 *(UINT*) ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
590 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
591 ( ~( pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
593 if( *(UINT*) ucResetValue)
594 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_CLR_REG , (PUINT) ucResetValue, sizeof(ULONG));
596 if( Status != STATUS_SUCCESS)
598 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_CLR_REG Failed." );
603 if( pgpio_multi_info[WIMAX_IDX].uiGPIOMask)
605 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
607 if(Status != STATUS_SUCCESS)
609 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"RDM to GPIO_PIN_STATE_REGISTER Failed.");
613 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = ( *(UINT*)ucResetValue &
614 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
617 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
620 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
625 case IOCTL_BCM_GPIO_MODE_REQUEST:
627 UCHAR ucResetValue[4];
628 GPIO_MULTI_MODE gpio_multi_mode[MAX_IDX];
629 PGPIO_MULTI_MODE pgpio_multi_mode = ( PGPIO_MULTI_MODE) gpio_multi_mode;
631 if((Adapter->IdleMode == TRUE) ||
632 (Adapter->bShutStatus ==TRUE) ||
633 (Adapter->bPreparingForLowPowerMode ==TRUE))
636 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
638 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
640 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
643 Status = rdmaltWithLock( Adapter, ( UINT) GPIO_MODE_REGISTER, ( PUINT) ucResetValue, sizeof( UINT));
644 if( STATUS_SUCCESS != Status)
646 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Read of GPIO_MODE_REGISTER failed");
650 //Validating the request
651 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)== FALSE)
653 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);
658 if( pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)
660 /* write all OUT's (1's) */
661 *( UINT*) ucResetValue |= ( pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
662 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
663 /* write all IN's (0's) */
664 *( UINT*) ucResetValue &= ~( ( ~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
665 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
667 /* Currently implemented return the modes of all GPIO's
668 * else needs to bit AND with mask
670 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT*)ucResetValue;
672 Status = wrmaltWithLock( Adapter, GPIO_MODE_REGISTER , ( PUINT) ucResetValue, sizeof( ULONG));
673 if( Status == STATUS_SUCCESS)
675 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM to GPIO_MODE_REGISTER Done");
679 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to GPIO_MODE_REGISTER Failed");
684 else /* if uiGPIOMask is 0 then return mode register configuration */
686 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *( UINT*) ucResetValue;
688 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
691 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
697 case IOCTL_MAC_ADDR_REQ:
699 case IOCTL_CM_REQUEST:
700 case IOCTL_SS_INFO_REQ:
701 case IOCTL_SEND_CONTROL_MESSAGE:
706 /* Copy Ioctl Buffer structure */
707 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
710 /* FIXME: don't accept any length from user */
711 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
715 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
722 down(&Adapter->LowPowerModeSync);
723 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
724 !Adapter->bPreparingForLowPowerMode,
726 if(Status == -ERESTARTSYS)
729 if(Adapter->bPreparingForLowPowerMode)
731 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Preparing Idle Mode is still True - Hence Rejecting control message\n");
732 Status = STATUS_FAILURE ;
735 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
737 up(&Adapter->LowPowerModeSync);
741 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
743 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock) ;
746 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");
749 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
750 if(!down_trylock(&Adapter->fw_download_sema))
752 Adapter->bBinDownloaded=FALSE;
753 Adapter->fw_download_process_pid=current->pid;
754 Adapter->bCfgDownloaded=FALSE;
755 Adapter->fw_download_done=FALSE;
756 netif_carrier_off(Adapter->dev);
757 netif_stop_queue(Adapter->dev);
758 Status = reset_card_proc(Adapter);
761 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
762 up(&Adapter->fw_download_sema);
763 up(&Adapter->NVMRdmWrmLock);
774 up(&Adapter->NVMRdmWrmLock);
777 case IOCTL_BCM_BUFFER_DOWNLOAD:
779 FIRMWARE_INFO *psFwInfo = NULL;
780 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
782 if(!down_trylock(&Adapter->fw_download_sema))
784 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid way to download buffer. Use Start and then call this!!!\n");
789 /* Copy Ioctl Buffer structure */
790 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
793 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length for FW DLD is : %lx\n",
794 IoBuffer.InputLength);
796 if (IoBuffer.InputLength > sizeof(FIRMWARE_INFO))
799 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
803 if(copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength))
806 if(!psFwInfo->pvMappedFirmwareAddress ||
807 (psFwInfo->u32FirmwareLength == 0))
809 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
810 psFwInfo->u32FirmwareLength);
814 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
815 if(Status != STATUS_SUCCESS)
817 if(psFwInfo->u32StartingAddress==CONFIG_BEGIN_ADDR)
819 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
823 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
825 //up(&Adapter->fw_download_sema);
827 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
829 Adapter->DriverState = DRIVER_INIT;
830 Adapter->LEDInfo.bLedInitDone = FALSE;
831 wake_up(&Adapter->LEDInfo.notify_led_event);
837 if(Status != STATUS_SUCCESS)
838 up(&Adapter->fw_download_sema);
839 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
843 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
845 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
848 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " FW download blocked as EEPROM Read/Write is in progress\n");
849 up(&Adapter->fw_download_sema);
852 if(down_trylock(&Adapter->fw_download_sema))
854 Adapter->bBinDownloaded=TRUE;
855 Adapter->bCfgDownloaded=TRUE;
856 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
858 Adapter->CurrNumRecvDescs=0;
859 Adapter->downloadDDR = 0;
861 //setting the Mips to Run
862 Status = run_card_proc(Adapter);
865 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
866 up(&Adapter->fw_download_sema);
867 up(&Adapter->NVMRdmWrmLock);
871 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Firm Download Over...\n");
873 /* Wait for MailBox Interrupt */
874 if(StartInterruptUrb((PS_INTERFACE_ADAPTER)Adapter->pvInterfaceAdapter))
876 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
879 Adapter->waiting_to_fw_download_done = FALSE;
880 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
881 Adapter->waiting_to_fw_download_done, timeout);
882 Adapter->fw_download_process_pid=INVALID_PID;
883 Adapter->fw_download_done=TRUE;
884 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
885 Adapter->CurrNumRecvDescs = 0;
886 Adapter->PrevNumRecvDescs = 0;
887 atomic_set(&Adapter->cntrlpktCnt,0);
888 Adapter->LinkUpStatus = 0;
889 Adapter->LinkStatus = 0;
891 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
893 Adapter->DriverState = FW_DOWNLOAD_DONE;
894 wake_up(&Adapter->LEDInfo.notify_led_event);
906 up(&Adapter->fw_download_sema);
907 up(&Adapter->NVMRdmWrmLock);
910 case IOCTL_BE_BUCKET_SIZE:
912 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
916 case IOCTL_RTPS_BUCKET_SIZE:
918 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
921 case IOCTL_CHIP_RESET:
923 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
926 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
929 down(&Adapter->RxAppControlQueuelock);
930 Status = reset_card_proc(Adapter);
932 up(&Adapter->RxAppControlQueuelock);
933 up(&Adapter->NVMRdmWrmLock);
934 ResetCounters(Adapter);
937 case IOCTL_QOS_THRESHOLD:
942 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
943 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
944 (unsigned long __user *)arg)) {
952 case IOCTL_DUMP_PACKET_INFO:
954 DumpPackInfo(Adapter);
955 DumpPhsRules(&Adapter->stBCMPhsContext);
956 Status = STATUS_SUCCESS;
959 case IOCTL_GET_PACK_INFO:
960 if(copy_to_user(argp, &Adapter->PackInfo, sizeof(PacketInfo)*NO_OF_QUEUES))
962 Status = STATUS_SUCCESS;
964 case IOCTL_BCM_SWITCH_TRANSFER_MODE:
967 if(copy_from_user(&uiData, argp, sizeof(UINT)))
970 if(uiData) /* Allow All Packets */
972 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
973 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
975 else /* Allow IP only Packets */
977 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
978 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
980 Status = STATUS_SUCCESS;
984 case IOCTL_BCM_GET_DRIVER_VERSION:
986 /* Copy Ioctl Buffer structure */
987 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
990 if(copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, IoBuffer.OutputLength))
992 Status = STATUS_SUCCESS;
995 case IOCTL_BCM_GET_CURRENT_STATUS:
997 LINK_STATE link_state;
999 /* Copy Ioctl Buffer structure */
1000 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1002 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
1006 if (IoBuffer.OutputLength != sizeof(link_state)) {
1011 memset(&link_state, 0, sizeof(link_state));
1012 link_state.bIdleMode = Adapter->IdleMode;
1013 link_state.bShutdownMode = Adapter->bShutStatus;
1014 link_state.ucLinkStatus = Adapter->LinkStatus;
1016 if (copy_to_user(IoBuffer.OutputBuffer, &link_state,
1017 min_t(size_t, sizeof(link_state), IoBuffer.OutputLength)))
1019 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1023 Status = STATUS_SUCCESS;
1026 case IOCTL_BCM_SET_MAC_TRACING:
1030 /* copy ioctl Buffer structure */
1031 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1034 if(copy_from_user(&tracing_flag,IoBuffer.InputBuffer,sizeof(UINT)))
1038 Adapter->pTarangs->MacTracingEnabled = TRUE;
1040 Adapter->pTarangs->MacTracingEnabled = FALSE;
1043 case IOCTL_BCM_GET_DSX_INDICATION:
1046 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1049 if(IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt))
1051 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
1052 "Mismatch req: %lx needed is =0x%zx!!!",
1053 IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
1057 if(copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1060 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId );
1061 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1062 Status=STATUS_SUCCESS;
1065 case IOCTL_BCM_GET_HOST_MIBS:
1069 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1072 if(IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS))
1074 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
1075 "Length Check failed %lu %zd\n",
1076 IoBuffer.OutputLength, sizeof(S_MIBS_HOST_STATS_MIBS));
1080 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1081 temp_buff = kzalloc(sizeof(S_MIBS_HOST_STATS_MIBS), GFP_KERNEL);
1083 return STATUS_FAILURE;
1085 Status = ProcessGetHostMibs(Adapter, temp_buff);
1086 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1088 if (Status != STATUS_FAILURE)
1089 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS)))
1096 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1097 if((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE==Adapter->IdleMode))
1099 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1100 Adapter->bWakeUpDevice = TRUE;
1101 wake_up(&Adapter->process_rx_cntrlpkt);
1103 Status = STATUS_SUCCESS;
1106 case IOCTL_BCM_BULK_WRM:
1108 PBULKWRM_BUFFER pBulkBuffer;
1110 PCHAR pvBuffer = NULL;
1112 if((Adapter->IdleMode == TRUE) ||
1113 (Adapter->bShutStatus ==TRUE) ||
1114 (Adapter->bPreparingForLowPowerMode ==TRUE))
1116 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1121 /* Copy Ioctl Buffer structure */
1122 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1125 /* FIXME: restrict length */
1126 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
1130 /* Get WrmBuffer structure */
1131 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
1138 pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
1140 if(((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1141 ((ULONG)pBulkBuffer->Register & 0x3))
1144 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer->Register);
1150 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1151 if(!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE)
1152 && ((uiTempVar == EEPROM_REJECT_REG_1)||
1153 (uiTempVar == EEPROM_REJECT_REG_2) ||
1154 (uiTempVar == EEPROM_REJECT_REG_3) ||
1155 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1156 (cmd == IOCTL_BCM_REGISTER_WRITE))
1159 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"EEPROM Access Denied, not in VSG Mode\n");
1164 if(pBulkBuffer->SwapEndian == FALSE)
1165 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1167 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1169 if(Status != STATUS_SUCCESS)
1171 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1178 case IOCTL_BCM_GET_NVM_SIZE:
1179 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1182 if(Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH ) {
1183 if(copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1186 Status = STATUS_SUCCESS ;
1189 case IOCTL_BCM_CAL_INIT :
1192 UINT uiSectorSize = 0 ;
1193 if(Adapter->eNVMType == NVM_FLASH)
1195 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1198 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1201 if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE))
1203 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1209 if(IsFlash2x(Adapter))
1211 if (copy_to_user(IoBuffer.OutputBuffer,
1212 &Adapter->uiSectorSize ,
1218 if((TRUE == Adapter->bShutStatus) ||
1219 (TRUE == Adapter->IdleMode))
1221 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle/Shutdown Mode\n");
1225 Adapter->uiSectorSize = uiSectorSize ;
1226 BcmUpdateSectorSize(Adapter,Adapter->uiSectorSize);
1229 Status = STATUS_SUCCESS ;
1233 Status = STATUS_FAILURE;
1237 case IOCTL_BCM_SET_DEBUG :
1240 USER_BCM_DBG_STATE sUserDebugState;
1242 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG );
1244 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1245 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1248 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE)))
1252 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1253 sUserDebugState.OnOff, sUserDebugState.Type);
1254 //sUserDebugState.Subtype <<= 1;
1255 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1256 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1258 // Update new 'DebugState' in the Adapter
1259 Adapter->stDebugState.type |= sUserDebugState.Type;
1260 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1261 * Valid indexes in 'subtype' array: 1,2,4,8
1262 * corresponding to valid Type values. Hence we can use the 'Type' field
1263 * as the index value, ignoring the array entries 0,3,5,6,7 !
1265 if (sUserDebugState.OnOff)
1266 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1268 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1270 BCM_SHOW_DEBUG_BITMAP(Adapter);
1275 case IOCTL_BCM_NVM_READ:
1276 case IOCTL_BCM_NVM_WRITE:
1278 NVM_READWRITE stNVMReadWrite;
1279 PUCHAR pReadData = NULL;
1280 ULONG ulDSDMagicNumInUsrBuff = 0;
1281 struct timeval tv0, tv1;
1282 memset(&tv0,0,sizeof(struct timeval));
1283 memset(&tv1,0,sizeof(struct timeval));
1284 if((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0))
1286 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,"The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1291 if(IsFlash2x(Adapter))
1293 if((Adapter->eActiveDSD != DSD0) &&
1294 (Adapter->eActiveDSD != DSD1) &&
1295 (Adapter->eActiveDSD != DSD2))
1297 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"No DSD is active..hence NVM Command is blocked");
1298 return STATUS_FAILURE ;
1302 /* Copy Ioctl Buffer structure */
1304 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1307 if(copy_from_user(&stNVMReadWrite,
1308 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1309 sizeof(NVM_READWRITE)))
1313 // Deny the access if the offset crosses the cal area limit.
1315 if((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) > Adapter->uiNVMDSDSize)
1317 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset ,
1318 // stNVMReadWrite.uiNumBytes);
1319 Status = STATUS_FAILURE;
1323 pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
1327 if(copy_from_user(pReadData, stNVMReadWrite.pBuffer,
1328 stNVMReadWrite.uiNumBytes))
1335 do_gettimeofday(&tv0);
1336 if(IOCTL_BCM_NVM_READ == cmd)
1338 down(&Adapter->NVMRdmWrmLock);
1340 if((Adapter->IdleMode == TRUE) ||
1341 (Adapter->bShutStatus ==TRUE) ||
1342 (Adapter->bPreparingForLowPowerMode ==TRUE))
1344 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1345 up(&Adapter->NVMRdmWrmLock);
1350 Status = BeceemNVMRead(Adapter, (PUINT)pReadData,
1351 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1353 up(&Adapter->NVMRdmWrmLock);
1355 if(Status != STATUS_SUCCESS)
1360 if(copy_to_user(stNVMReadWrite.pBuffer,pReadData, stNVMReadWrite.uiNumBytes))
1369 down(&Adapter->NVMRdmWrmLock);
1371 if((Adapter->IdleMode == TRUE) ||
1372 (Adapter->bShutStatus ==TRUE) ||
1373 (Adapter->bPreparingForLowPowerMode ==TRUE))
1375 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1376 up(&Adapter->NVMRdmWrmLock);
1381 Adapter->bHeaderChangeAllowed = TRUE ;
1382 if(IsFlash2x(Adapter))
1386 DSD section updation will be allowed in two case:-
1387 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1388 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1389 corrupted then user space program first modify the DSD header with valid DSD sig so
1390 that this as well as further write may be worthwhile.
1392 This restriction has been put assuming that if DSD sig is corrupted, DSD
1393 data won't be considered valid.
1397 Status = BcmFlash2xCorruptSig(Adapter,Adapter->eActiveDSD);
1398 if(Status != STATUS_SUCCESS)
1400 if(( (stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize ) ||
1401 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE))
1403 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1404 up(&Adapter->NVMRdmWrmLock);
1409 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1410 if(ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER)
1412 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1413 up(&Adapter->NVMRdmWrmLock);
1419 Status = BeceemNVMWrite(Adapter, (PUINT )pReadData,
1420 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1421 if(IsFlash2x(Adapter))
1422 BcmFlash2xWriteSig(Adapter,Adapter->eActiveDSD);
1424 Adapter->bHeaderChangeAllowed = FALSE ;
1426 up(&Adapter->NVMRdmWrmLock);
1429 if(Status != STATUS_SUCCESS)
1435 do_gettimeofday(&tv1);
1436 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);
1440 Status = STATUS_SUCCESS;
1443 case IOCTL_BCM_FLASH2X_SECTION_READ :
1446 FLASH2X_READWRITE sFlash2xRead = {0};
1447 PUCHAR pReadBuff = NULL ;
1451 UINT ReadOffset = 0;
1452 void __user *OutPutBuff;
1454 if(IsFlash2x(Adapter) != TRUE)
1456 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1460 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1461 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1464 //Reading FLASH 2.x READ structure
1465 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,sizeof(FLASH2X_READWRITE)))
1469 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xRead.Section);
1470 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%x" ,sFlash2xRead.offset);
1471 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xRead.numOfBytes);
1472 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xRead.bVerify);
1474 //This was internal to driver for raw read. now it has ben exposed to user space app.
1475 if(validateFlash2xReadWrite(Adapter,&sFlash2xRead) == FALSE)
1476 return STATUS_FAILURE ;
1478 NOB = sFlash2xRead.numOfBytes;
1479 if(NOB > Adapter->uiSectorSize )
1480 BuffSize = Adapter->uiSectorSize;
1484 ReadOffset = sFlash2xRead.offset ;
1485 OutPutBuff = IoBuffer.OutputBuffer;
1488 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1489 if(pReadBuff == NULL)
1491 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1494 down(&Adapter->NVMRdmWrmLock);
1496 if((Adapter->IdleMode == TRUE) ||
1497 (Adapter->bShutStatus ==TRUE) ||
1498 (Adapter->bPreparingForLowPowerMode ==TRUE))
1500 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1501 up(&Adapter->NVMRdmWrmLock);
1509 if(NOB > Adapter->uiSectorSize )
1510 ReadBytes = Adapter->uiSectorSize;
1515 //Reading the data from Flash 2.x
1517 Status = BcmFlash2xBulkRead(Adapter,(PUINT)pReadBuff,sFlash2xRead.Section,ReadOffset,ReadBytes);
1520 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Flash 2x read err with Status :%d", Status);
1524 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes);
1526 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
1529 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Copy to use failed with status :%d", Status);
1532 NOB = NOB - ReadBytes;
1535 ReadOffset = ReadOffset + ReadBytes ;
1536 OutPutBuff = OutPutBuff + ReadBytes ;
1540 up(&Adapter->NVMRdmWrmLock);
1545 case IOCTL_BCM_FLASH2X_SECTION_WRITE :
1547 FLASH2X_READWRITE sFlash2xWrite = {0};
1549 void __user *InputAddr;
1552 UINT WriteOffset = 0;
1553 UINT WriteBytes = 0;
1555 if(IsFlash2x(Adapter) != TRUE)
1557 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1561 //First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite
1562 Adapter->bAllDSDWriteAllow = FALSE;
1565 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1566 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1569 //Reading FLASH 2.x READ structure
1570 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
1573 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite.Section);
1574 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite.offset);
1575 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite.numOfBytes);
1576 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite.bVerify);
1577 if((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) &&
1578 (sFlash2xWrite.Section != VSA2) )
1580 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Only VSA write is allowed");
1584 if(validateFlash2xReadWrite(Adapter,&sFlash2xWrite) == FALSE)
1585 return STATUS_FAILURE ;
1587 InputAddr = sFlash2xWrite.pDataBuff;
1588 WriteOffset = sFlash2xWrite.offset ;
1589 NOB = sFlash2xWrite.numOfBytes;
1591 if(NOB > Adapter->uiSectorSize )
1592 BuffSize = Adapter->uiSectorSize;
1596 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1597 if(pWriteBuff == NULL)
1601 //extracting the remainder of the given offset.
1602 WriteBytes = Adapter->uiSectorSize ;
1603 if(WriteOffset % Adapter->uiSectorSize)
1604 WriteBytes =Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1605 if(NOB < WriteBytes)
1608 down(&Adapter->NVMRdmWrmLock);
1610 if((Adapter->IdleMode == TRUE) ||
1611 (Adapter->bShutStatus ==TRUE) ||
1612 (Adapter->bPreparingForLowPowerMode ==TRUE))
1614 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1615 up(&Adapter->NVMRdmWrmLock);
1620 BcmFlash2xCorruptSig(Adapter,sFlash2xWrite.Section);
1623 Status = copy_from_user(pWriteBuff,InputAddr,WriteBytes);
1626 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to user failed with status :%d", Status);
1629 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pWriteBuff,WriteBytes);
1630 //Writing the data from Flash 2.x
1631 Status = BcmFlash2xBulkWrite(Adapter,(PUINT)pWriteBuff,sFlash2xWrite.Section,WriteOffset,WriteBytes,sFlash2xWrite.bVerify);
1635 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
1639 NOB = NOB - WriteBytes;
1642 WriteOffset = WriteOffset + WriteBytes ;
1643 InputAddr = InputAddr + WriteBytes ;
1644 if(NOB > Adapter->uiSectorSize )
1645 WriteBytes = Adapter->uiSectorSize;
1652 BcmFlash2xWriteSig(Adapter,sFlash2xWrite.Section);
1653 up(&Adapter->NVMRdmWrmLock);
1657 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP :
1660 PFLASH2X_BITMAP psFlash2xBitMap;
1661 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1663 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1666 if(IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
1669 psFlash2xBitMap = kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
1670 if(psFlash2xBitMap == NULL)
1672 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory is not available");
1675 //Reading the Flash Sectio Bit map
1676 down(&Adapter->NVMRdmWrmLock);
1678 if((Adapter->IdleMode == TRUE) ||
1679 (Adapter->bShutStatus ==TRUE) ||
1680 (Adapter->bPreparingForLowPowerMode ==TRUE))
1682 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1683 up(&Adapter->NVMRdmWrmLock);
1684 kfree(psFlash2xBitMap);
1688 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1689 up(&Adapter->NVMRdmWrmLock);
1690 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP)))
1693 kfree(psFlash2xBitMap);
1696 case IOCTL_BCM_SET_ACTIVE_SECTION :
1698 FLASH2X_SECTION_VAL eFlash2xSectionVal = 0;
1699 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1701 if(IsFlash2x(Adapter) != TRUE)
1703 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1707 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1710 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1714 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
1717 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1721 down(&Adapter->NVMRdmWrmLock);
1723 if((Adapter->IdleMode == TRUE) ||
1724 (Adapter->bShutStatus ==TRUE) ||
1725 (Adapter->bPreparingForLowPowerMode ==TRUE))
1727 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1728 up(&Adapter->NVMRdmWrmLock);
1732 Status = BcmSetActiveSection(Adapter,eFlash2xSectionVal);
1735 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed to make it's priority Highest. Status %d", Status);
1737 up(&Adapter->NVMRdmWrmLock);
1740 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION :
1742 //Right Now we are taking care of only DSD
1743 Adapter->bAllDSDWriteAllow = FALSE ;
1744 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1746 Status = STATUS_SUCCESS ;
1749 case IOCTL_BCM_COPY_SECTION :
1751 FLASH2X_COPY_SECTION sCopySectStrut = {0};
1752 Status = STATUS_SUCCESS;
1753 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1755 Adapter->bAllDSDWriteAllow = FALSE ;
1756 if(IsFlash2x(Adapter) != TRUE)
1758 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1762 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1765 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1769 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
1772 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1775 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1776 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1777 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1778 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1781 if(IsSectionExistInFlash(Adapter,sCopySectStrut.SrcSection) == FALSE)
1783 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
1787 if(IsSectionExistInFlash(Adapter,sCopySectStrut.DstSection) == FALSE)
1789 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
1793 if(sCopySectStrut.SrcSection == sCopySectStrut.DstSection)
1795 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Source and Destination section should be different");
1799 down(&Adapter->NVMRdmWrmLock);
1801 if((Adapter->IdleMode == TRUE) ||
1802 (Adapter->bShutStatus ==TRUE) ||
1803 (Adapter->bPreparingForLowPowerMode ==TRUE))
1805 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1806 up(&Adapter->NVMRdmWrmLock);
1810 if(sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2)
1812 if(IsNonCDLessDevice(Adapter))
1814 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is Non-CDLess hence won't have ISO !!");
1817 else if(sCopySectStrut.numOfBytes == 0)
1819 Status = BcmCopyISO(Adapter,sCopySectStrut);
1823 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Partial Copy of ISO section is not Allowed..");
1824 Status = STATUS_FAILURE ;
1826 up(&Adapter->NVMRdmWrmLock);
1830 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
1831 sCopySectStrut.DstSection,sCopySectStrut.offset,sCopySectStrut.numOfBytes);
1832 up(&Adapter->NVMRdmWrmLock);
1835 case IOCTL_BCM_GET_FLASH_CS_INFO :
1837 Status = STATUS_SUCCESS;
1838 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1840 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1843 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1846 if(Adapter->eNVMType != NVM_FLASH)
1848 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Connected device does not have flash");
1852 if(IsFlash2x(Adapter) == TRUE)
1855 if(IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
1858 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO)))
1863 if(IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
1866 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO)))
1872 case IOCTL_BCM_SELECT_DSD :
1875 FLASH2X_SECTION_VAL eFlash2xSectionVal;
1876 eFlash2xSectionVal = NO_SECTION_VAL ;
1877 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_SELECT_DSD Called");
1879 if(IsFlash2x(Adapter) != TRUE)
1881 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1885 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1888 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1891 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1894 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1898 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", eFlash2xSectionVal);
1899 if((eFlash2xSectionVal != DSD0) &&
1900 (eFlash2xSectionVal != DSD1) &&
1901 (eFlash2xSectionVal != DSD2) )
1903 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Passed section<%x> is not DSD section", eFlash2xSectionVal);
1904 return STATUS_FAILURE ;
1907 SectOfset= BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
1908 if(SectOfset == INVALID_OFFSET)
1910 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
1914 Adapter->bAllDSDWriteAllow = TRUE ;
1916 Adapter->ulFlashCalStart = SectOfset ;
1917 Adapter->eActiveDSD = eFlash2xSectionVal;
1919 Status = STATUS_SUCCESS ;
1922 case IOCTL_BCM_NVM_RAW_READ :
1925 NVM_READWRITE stNVMRead;
1929 UINT ReadBytes = 0 ;
1931 void __user *OutPutBuff;
1933 if(Adapter->eNVMType != NVM_FLASH)
1935 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"NVM TYPE is not Flash ");
1939 /* Copy Ioctl Buffer structure */
1940 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1942 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
1947 if(copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,sizeof(NVM_READWRITE)))
1950 NOB = stNVMRead.uiNumBytes;
1951 //In Raw-Read max Buff size : 64MB
1953 if(NOB > DEFAULT_BUFF_SIZE)
1954 BuffSize = DEFAULT_BUFF_SIZE;
1958 ReadOffset = stNVMRead.uiOffset;
1959 OutPutBuff = stNVMRead.pBuffer;
1961 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
1962 if(pReadBuff == NULL)
1964 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1968 down(&Adapter->NVMRdmWrmLock);
1970 if((Adapter->IdleMode == TRUE) ||
1971 (Adapter->bShutStatus ==TRUE) ||
1972 (Adapter->bPreparingForLowPowerMode ==TRUE))
1974 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1976 up(&Adapter->NVMRdmWrmLock);
1980 Adapter->bFlashRawRead = TRUE ;
1983 if(NOB > DEFAULT_BUFF_SIZE )
1984 ReadBytes = DEFAULT_BUFF_SIZE;
1988 //Reading the data from Flash 2.x
1989 Status = BeceemNVMRead(Adapter,(PUINT)pReadBuff,ReadOffset,ReadBytes);
1992 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
1996 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff,ReadBytes);
1998 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
2001 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to use failed with status :%d", Status);
2004 NOB = NOB - ReadBytes;
2007 ReadOffset = ReadOffset + ReadBytes ;
2008 OutPutBuff = OutPutBuff + ReadBytes ;
2012 Adapter->bFlashRawRead = FALSE ;
2013 up(&Adapter->NVMRdmWrmLock);
2018 case IOCTL_BCM_CNTRLMSG_MASK:
2020 ULONG RxCntrlMsgBitMask = 0 ;
2022 /* Copy Ioctl Buffer structure */
2023 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2026 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of Ioctl buffer is failed from user space");
2030 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
2033 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of control bit mask failed from user space");
2036 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
2037 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask ;
2040 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO:
2042 DEVICE_DRIVER_INFO DevInfo;
2044 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2046 DevInfo.MaxRDMBufferSize = BUFFER_4K;
2047 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
2048 DevInfo.u32RxAlignmentCorrection = 0;
2049 DevInfo.u32NVMType = Adapter->eNVMType;
2050 DevInfo.u32InterfaceType = BCM_USB;
2052 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2055 if(IoBuffer.OutputLength < sizeof(DevInfo))
2058 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
2063 case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
2065 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
2067 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2069 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2072 if(IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
2075 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
2077 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED)))
2083 case IOCTL_CLOSE_NOTIFICATION:
2084 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_CLOSE_NOTIFICATION");
2088 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2089 Status = STATUS_FAILURE;
2096 static struct file_operations bcm_fops = {
2097 .owner = THIS_MODULE,
2098 .open = bcm_char_open,
2099 .release = bcm_char_release,
2100 .read = bcm_char_read,
2101 .unlocked_ioctl = bcm_char_ioctl,
2102 .llseek = no_llseek,
2105 extern struct class *bcm_class;
2107 int register_control_device_interface(PMINI_ADAPTER Adapter)
2110 if(Adapter->major>0)
2111 return Adapter->major;
2113 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
2114 if(Adapter->major < 0) {
2115 pr_err(DRV_NAME ": could not created character device\n");
2116 return Adapter->major;
2119 Adapter->pstCreatedClassDevice = device_create (bcm_class, NULL,
2120 MKDEV(Adapter->major, 0), Adapter,
2123 if(IS_ERR(Adapter->pstCreatedClassDevice)) {
2124 pr_err(DRV_NAME ": class device create failed\n");
2125 unregister_chrdev(Adapter->major, DEV_NAME);
2126 return PTR_ERR(Adapter->pstCreatedClassDevice);
2132 void unregister_control_device_interface(PMINI_ADAPTER Adapter)
2134 if(Adapter->major > 0) {
2135 device_destroy (bcm_class, MKDEV(Adapter->major, 0));
2136 unregister_chrdev(Adapter->major, DEV_NAME);