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),
27 memset(pTarang, 0, sizeof(PER_TARANG_DATA));
28 pTarang->Adapter = Adapter;
29 pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
31 down(&Adapter->RxAppControlQueuelock);
32 pTarang->next = Adapter->pTarangs;
33 Adapter->pTarangs = pTarang;
34 up(&Adapter->RxAppControlQueuelock);
36 /* Store the Adapter structure */
37 filp->private_data = pTarang;
39 /*Start Queuing the control response Packets*/
40 atomic_inc(&Adapter->ApplicationRunning);
42 nonseekable_open(inode, filp);
46 static int bcm_char_release(struct inode *inode, struct file *filp)
48 PPER_TARANG_DATA pTarang, tmp, ptmp;
49 PMINI_ADAPTER Adapter = NULL;
50 struct sk_buff *pkt, *npkt;
52 pTarang = (PPER_TARANG_DATA)filp->private_data;
54 if (pTarang == NULL) {
55 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
60 Adapter = pTarang->Adapter;
62 down(&Adapter->RxAppControlQueuelock);
64 tmp = Adapter->pTarangs;
65 for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
72 Adapter->pTarangs = tmp->next;
74 ptmp->next = tmp->next;
76 up(&Adapter->RxAppControlQueuelock);
80 pkt = pTarang->RxAppControlHead;
87 up(&Adapter->RxAppControlQueuelock);
89 /*Stop Queuing the control response Packets*/
90 atomic_dec(&Adapter->ApplicationRunning);
94 /* remove this filp from the asynchronously notified filp's */
95 filp->private_data = NULL;
99 static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
101 PPER_TARANG_DATA pTarang = filp->private_data;
102 PMINI_ADAPTER Adapter = pTarang->Adapter;
103 struct sk_buff* Packet = NULL;
107 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
108 (pTarang->RxAppControlHead || Adapter->device_removed));
109 if((wait_ret_val == -ERESTARTSYS))
111 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Exiting as i've been asked to exit!!!\n");
115 if(Adapter->device_removed)
117 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device Removed... Killing the Apps...\n");
121 if(FALSE == Adapter->fw_download_done)
124 down( &Adapter->RxAppControlQueuelock);
126 if(pTarang->RxAppControlHead)
128 Packet = pTarang->RxAppControlHead;
129 DEQUEUEPACKET(pTarang->RxAppControlHead,pTarang->RxAppControlTail);
130 pTarang->AppCtrlQueueLen--;
133 up(&Adapter->RxAppControlQueuelock);
137 PktLen = Packet->len;
138 if(copy_to_user(buf, Packet->data, min_t(size_t, PktLen, size)))
140 dev_kfree_skb(Packet);
141 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\nReturning from copy to user failure \n");
144 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
145 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
146 PktLen, Packet, current->pid);
147 dev_kfree_skb(Packet);
150 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<====\n");
154 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
156 PPER_TARANG_DATA pTarang = filp->private_data;
157 void __user *argp = (void __user *)arg;
158 PMINI_ADAPTER Adapter = pTarang->Adapter;
159 INT Status = STATUS_FAILURE;
161 IOCTL_BUFFER IoBuffer;
163 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);
165 if(_IOC_TYPE(cmd) != BCM_IOCTL)
167 if(_IOC_DIR(cmd) & _IOC_READ)
168 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
169 else if (_IOC_DIR(cmd) & _IOC_WRITE)
170 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
171 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
172 Status = STATUS_SUCCESS;
177 if(Adapter->device_removed)
182 if(FALSE == Adapter->fw_download_done)
186 case IOCTL_MAC_ADDR_REQ:
188 case IOCTL_CM_REQUEST:
189 case IOCTL_SS_INFO_REQ:
190 case IOCTL_SEND_CONTROL_MESSAGE:
192 case IOCTL_BCM_GPIO_SET_REQUEST:
193 case IOCTL_BCM_GPIO_STATUS_REQUEST:
200 Status = vendorextnIoctl(Adapter, cmd, arg);
201 if(Status != CONTINUE_COMMON_PATH )
205 // Rdms for Swin Idle...
206 case IOCTL_BCM_REGISTER_READ_PRIVATE:
208 RDM_BUFFER sRdmBuffer = {0};
212 /* Copy Ioctl Buffer structure */
213 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
216 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
219 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
222 /* FIXME: need to restrict BuffLen */
223 Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
224 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
228 Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
229 (PUINT)temp_buff, Bufflen);
230 if(Status == STATUS_SUCCESS)
232 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
239 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
241 WRM_BUFFER sWrmBuffer = {0};
243 /* Copy Ioctl Buffer structure */
245 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
248 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
251 /* Get WrmBuffer structure */
252 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
255 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
256 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
257 ((uiTempVar == EEPROM_REJECT_REG_1)||
258 (uiTempVar == EEPROM_REJECT_REG_2) ||
259 (uiTempVar == EEPROM_REJECT_REG_3) ||
260 (uiTempVar == EEPROM_REJECT_REG_4)))
262 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
265 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
266 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
267 if(Status == STATUS_SUCCESS)
269 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"WRM Done\n");
273 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
279 case IOCTL_BCM_REGISTER_READ:
280 case IOCTL_BCM_EEPROM_REGISTER_READ:
282 RDM_BUFFER sRdmBuffer = {0};
283 PCHAR temp_buff = NULL;
285 if((Adapter->IdleMode == TRUE) ||
286 (Adapter->bShutStatus ==TRUE) ||
287 (Adapter->bPreparingForLowPowerMode ==TRUE))
289 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
292 /* Copy Ioctl Buffer structure */
293 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
296 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
299 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
302 /* FIXME: don't trust user supplied length */
303 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
305 return STATUS_FAILURE;
307 if((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
308 ((ULONG)sRdmBuffer.Register & 0x3))
310 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
311 (int)sRdmBuffer.Register);
315 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
316 Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
317 (PUINT)temp_buff, IoBuffer.OutputLength);
318 if(Status == STATUS_SUCCESS)
319 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
325 case IOCTL_BCM_REGISTER_WRITE:
326 case IOCTL_BCM_EEPROM_REGISTER_WRITE:
328 WRM_BUFFER sWrmBuffer = {0};
330 if((Adapter->IdleMode == TRUE) ||
331 (Adapter->bShutStatus ==TRUE) ||
332 (Adapter->bPreparingForLowPowerMode ==TRUE))
334 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
338 /* Copy Ioctl Buffer structure */
339 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
342 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
345 /* Get WrmBuffer structure */
346 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
349 if( (((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
350 ((ULONG)sWrmBuffer.Register & 0x3) )
352 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n",
353 (int)sWrmBuffer.Register);
357 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
358 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
359 ((uiTempVar == EEPROM_REJECT_REG_1)||
360 (uiTempVar == EEPROM_REJECT_REG_2) ||
361 (uiTempVar == EEPROM_REJECT_REG_3) ||
362 (uiTempVar == EEPROM_REJECT_REG_4)) &&
363 (cmd == IOCTL_BCM_REGISTER_WRITE))
365 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
369 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
370 (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
371 if(Status == STATUS_SUCCESS)
373 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
377 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
382 case IOCTL_BCM_GPIO_SET_REQUEST:
384 UCHAR ucResetValue[4];
387 UINT uiOperation = 0;
389 GPIO_INFO gpio_info = {0};
390 if((Adapter->IdleMode == TRUE) ||
391 (Adapter->bShutStatus ==TRUE) ||
392 (Adapter->bPreparingForLowPowerMode ==TRUE))
394 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
397 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
399 if (IoBuffer.InputLength > sizeof(gpio_info))
401 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
403 uiBit = gpio_info.uiGpioNumber;
404 uiOperation = gpio_info.uiGpioValue;
408 if(IsReqGpioIsLedInNVM(Adapter,value) ==FALSE)
410 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",value);
416 if(uiOperation)//Set - setting 1
418 //Set the gpio output register
419 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_SET_REG ,
420 (PUINT)(&value), sizeof(UINT));
421 if(Status == STATUS_SUCCESS)
423 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
427 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to set the %dth GPIO \n",uiBit);
431 else//Unset - setting 0
433 //Set the gpio output register
434 Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_CLR_REG ,
435 (PUINT)(&value), sizeof(UINT));
436 if(Status == STATUS_SUCCESS)
438 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO bit\n");
442 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to clear the %dth GPIO \n",uiBit);
447 Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
448 (PUINT)ucResetValue, sizeof(UINT));
449 if (STATUS_SUCCESS != Status)
451 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO_MODE_REGISTER read failed");
454 //Set the gpio mode register to output
455 *(UINT*)ucResetValue |= (1<<uiBit);
456 Status = wrmaltWithLock(Adapter,GPIO_MODE_REGISTER ,
457 (PUINT)ucResetValue, sizeof(UINT));
458 if(Status == STATUS_SUCCESS)
460 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO to output Mode\n");
464 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
469 case BCM_LED_THREAD_STATE_CHANGE_REQ:
471 USER_THREAD_REQ threadReq = { 0 };
472 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"User made LED thread InActive");
474 if((Adapter->IdleMode == TRUE) ||
475 (Adapter->bShutStatus ==TRUE) ||
476 (Adapter->bPreparingForLowPowerMode ==TRUE))
478 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
483 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
486 if (IoBuffer.InputLength > sizeof(threadReq))
489 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
492 //if LED thread is running(Actively or Inactively) set it state to make inactive
493 if(Adapter->LEDInfo.led_thread_running)
495 if(threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ)
497 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Activating thread req");
498 Adapter->DriverState = LED_THREAD_ACTIVE;
502 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DeActivating Thread req.....");
503 Adapter->DriverState = LED_THREAD_INACTIVE;
507 wake_up(&Adapter->LEDInfo.notify_led_event);
512 case IOCTL_BCM_GPIO_STATUS_REQUEST:
516 GPIO_INFO gpio_info = {0};
517 if((Adapter->IdleMode == TRUE) ||
518 (Adapter->bShutStatus ==TRUE) ||
519 (Adapter->bPreparingForLowPowerMode ==TRUE))
521 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
523 if (IoBuffer.InputLength > sizeof(gpio_info))
525 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
527 uiBit = gpio_info.uiGpioNumber;
528 //Set the gpio output register
529 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
530 (PUINT)ucRead, sizeof(UINT));
531 if(Status != STATUS_SUCCESS)
533 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
539 case IOCTL_BCM_GPIO_MULTI_REQUEST:
541 UCHAR ucResetValue[4];
542 GPIO_MULTI_INFO gpio_multi_info[MAX_IDX];
543 PGPIO_MULTI_INFO pgpio_multi_info = (PGPIO_MULTI_INFO)gpio_multi_info;
545 memset( pgpio_multi_info, 0, MAX_IDX * sizeof( GPIO_MULTI_INFO));
547 if((Adapter->IdleMode == TRUE) ||
548 (Adapter->bShutStatus ==TRUE) ||
549 (Adapter->bPreparingForLowPowerMode ==TRUE))
551 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
553 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
555 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
558 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_info[WIMAX_IDX].uiGPIOMask)== FALSE)
560 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);
565 /* Set the gpio output register */
567 if( ( pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
568 ( pgpio_multi_info[WIMAX_IDX].uiGPIOCommand))
570 /* Set 1's in GPIO OUTPUT REGISTER */
571 *(UINT*) ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
572 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
573 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
575 if( *(UINT*) ucResetValue)
576 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_SET_REG , (PUINT) ucResetValue, sizeof(ULONG));
578 if( Status != STATUS_SUCCESS)
580 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
584 /* Clear to 0's in GPIO OUTPUT REGISTER */
585 *(UINT*) ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
586 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
587 ( ~( pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
589 if( *(UINT*) ucResetValue)
590 Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_CLR_REG , (PUINT) ucResetValue, sizeof(ULONG));
592 if( Status != STATUS_SUCCESS)
594 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_CLR_REG Failed." );
599 if( pgpio_multi_info[WIMAX_IDX].uiGPIOMask)
601 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
603 if(Status != STATUS_SUCCESS)
605 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"RDM to GPIO_PIN_STATE_REGISTER Failed.");
609 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = ( *(UINT*)ucResetValue &
610 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
613 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
616 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
621 case IOCTL_BCM_GPIO_MODE_REQUEST:
623 UCHAR ucResetValue[4];
624 GPIO_MULTI_MODE gpio_multi_mode[MAX_IDX];
625 PGPIO_MULTI_MODE pgpio_multi_mode = ( PGPIO_MULTI_MODE) gpio_multi_mode;
627 if((Adapter->IdleMode == TRUE) ||
628 (Adapter->bShutStatus ==TRUE) ||
629 (Adapter->bPreparingForLowPowerMode ==TRUE))
632 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
634 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
636 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
639 Status = rdmaltWithLock( Adapter, ( UINT) GPIO_MODE_REGISTER, ( PUINT) ucResetValue, sizeof( UINT));
640 if( STATUS_SUCCESS != Status)
642 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Read of GPIO_MODE_REGISTER failed");
646 //Validating the request
647 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)== FALSE)
649 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);
654 if( pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)
656 /* write all OUT's (1's) */
657 *( UINT*) ucResetValue |= ( pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
658 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
659 /* write all IN's (0's) */
660 *( UINT*) ucResetValue &= ~( ( ~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
661 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
663 /* Currently implemented return the modes of all GPIO's
664 * else needs to bit AND with mask
666 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT*)ucResetValue;
668 Status = wrmaltWithLock( Adapter, GPIO_MODE_REGISTER , ( PUINT) ucResetValue, sizeof( ULONG));
669 if( Status == STATUS_SUCCESS)
671 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM to GPIO_MODE_REGISTER Done");
675 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to GPIO_MODE_REGISTER Failed");
680 else /* if uiGPIOMask is 0 then return mode register configuration */
682 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *( UINT*) ucResetValue;
684 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
687 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
693 case IOCTL_MAC_ADDR_REQ:
695 case IOCTL_CM_REQUEST:
696 case IOCTL_SS_INFO_REQ:
697 case IOCTL_SEND_CONTROL_MESSAGE:
702 /* Copy Ioctl Buffer structure */
703 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
706 /* FIXME: don't accept any length from user */
707 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
711 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
718 down(&Adapter->LowPowerModeSync);
719 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
720 !Adapter->bPreparingForLowPowerMode,
722 if(Status == -ERESTARTSYS)
725 if(Adapter->bPreparingForLowPowerMode)
727 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Preparing Idle Mode is still True - Hence Rejecting control message\n");
728 Status = STATUS_FAILURE ;
731 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
733 up(&Adapter->LowPowerModeSync);
737 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
739 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock) ;
742 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");
745 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
746 if(!down_trylock(&Adapter->fw_download_sema))
748 Adapter->bBinDownloaded=FALSE;
749 Adapter->fw_download_process_pid=current->pid;
750 Adapter->bCfgDownloaded=FALSE;
751 Adapter->fw_download_done=FALSE;
752 netif_carrier_off(Adapter->dev);
753 netif_stop_queue(Adapter->dev);
754 Status = reset_card_proc(Adapter);
757 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
758 up(&Adapter->fw_download_sema);
759 up(&Adapter->NVMRdmWrmLock);
770 up(&Adapter->NVMRdmWrmLock);
773 case IOCTL_BCM_BUFFER_DOWNLOAD:
775 FIRMWARE_INFO *psFwInfo = NULL;
776 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
778 if(!down_trylock(&Adapter->fw_download_sema))
780 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid way to download buffer. Use Start and then call this!!!\n");
785 /* Copy Ioctl Buffer structure */
786 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
789 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length for FW DLD is : %lx\n",
790 IoBuffer.InputLength);
792 if (IoBuffer.InputLength > sizeof(FIRMWARE_INFO))
795 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
799 if(copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength))
802 if(!psFwInfo->pvMappedFirmwareAddress ||
803 (psFwInfo->u32FirmwareLength == 0))
805 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
806 psFwInfo->u32FirmwareLength);
810 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
811 if(Status != STATUS_SUCCESS)
813 if(psFwInfo->u32StartingAddress==CONFIG_BEGIN_ADDR)
815 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
819 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
821 //up(&Adapter->fw_download_sema);
823 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
825 Adapter->DriverState = DRIVER_INIT;
826 Adapter->LEDInfo.bLedInitDone = FALSE;
827 wake_up(&Adapter->LEDInfo.notify_led_event);
833 if(Status != STATUS_SUCCESS)
834 up(&Adapter->fw_download_sema);
835 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
839 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
841 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
844 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " FW download blocked as EEPROM Read/Write is in progress\n");
845 up(&Adapter->fw_download_sema);
848 if(down_trylock(&Adapter->fw_download_sema))
850 Adapter->bBinDownloaded=TRUE;
851 Adapter->bCfgDownloaded=TRUE;
852 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
854 Adapter->CurrNumRecvDescs=0;
855 Adapter->downloadDDR = 0;
857 //setting the Mips to Run
858 Status = run_card_proc(Adapter);
861 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
862 up(&Adapter->fw_download_sema);
863 up(&Adapter->NVMRdmWrmLock);
867 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Firm Download Over...\n");
869 /* Wait for MailBox Interrupt */
870 if(StartInterruptUrb((PS_INTERFACE_ADAPTER)Adapter->pvInterfaceAdapter))
872 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
875 Adapter->waiting_to_fw_download_done = FALSE;
876 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
877 Adapter->waiting_to_fw_download_done, timeout);
878 Adapter->fw_download_process_pid=INVALID_PID;
879 Adapter->fw_download_done=TRUE;
880 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
881 Adapter->CurrNumRecvDescs = 0;
882 Adapter->PrevNumRecvDescs = 0;
883 atomic_set(&Adapter->cntrlpktCnt,0);
884 Adapter->LinkUpStatus = 0;
885 Adapter->LinkStatus = 0;
887 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
889 Adapter->DriverState = FW_DOWNLOAD_DONE;
890 wake_up(&Adapter->LEDInfo.notify_led_event);
902 up(&Adapter->fw_download_sema);
903 up(&Adapter->NVMRdmWrmLock);
906 case IOCTL_BE_BUCKET_SIZE:
908 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
912 case IOCTL_RTPS_BUCKET_SIZE:
914 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
917 case IOCTL_CHIP_RESET:
919 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
922 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
925 down(&Adapter->RxAppControlQueuelock);
926 Status = reset_card_proc(Adapter);
928 up(&Adapter->RxAppControlQueuelock);
929 up(&Adapter->NVMRdmWrmLock);
930 ResetCounters(Adapter);
933 case IOCTL_QOS_THRESHOLD:
938 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
939 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
940 (unsigned long __user *)arg)) {
948 case IOCTL_DUMP_PACKET_INFO:
950 DumpPackInfo(Adapter);
951 DumpPhsRules(&Adapter->stBCMPhsContext);
952 Status = STATUS_SUCCESS;
955 case IOCTL_GET_PACK_INFO:
956 if(copy_to_user(argp, &Adapter->PackInfo, sizeof(PacketInfo)*NO_OF_QUEUES))
958 Status = STATUS_SUCCESS;
960 case IOCTL_BCM_SWITCH_TRANSFER_MODE:
963 if(copy_from_user(&uiData, argp, sizeof(UINT)))
966 if(uiData) /* Allow All Packets */
968 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
969 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
971 else /* Allow IP only Packets */
973 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
974 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
976 Status = STATUS_SUCCESS;
980 case IOCTL_BCM_GET_DRIVER_VERSION:
982 /* Copy Ioctl Buffer structure */
983 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
986 if(copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, IoBuffer.OutputLength))
988 Status = STATUS_SUCCESS;
991 case IOCTL_BCM_GET_CURRENT_STATUS:
993 LINK_STATE link_state;
995 /* Copy Ioctl Buffer structure */
996 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
998 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
1002 if (IoBuffer.OutputLength != sizeof(link_state)) {
1007 memset(&link_state, 0, sizeof(link_state));
1008 link_state.bIdleMode = Adapter->IdleMode;
1009 link_state.bShutdownMode = Adapter->bShutStatus;
1010 link_state.ucLinkStatus = Adapter->LinkStatus;
1012 if (copy_to_user(IoBuffer.OutputBuffer, &link_state,
1013 min_t(size_t, sizeof(link_state), IoBuffer.OutputLength)))
1015 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1019 Status = STATUS_SUCCESS;
1022 case IOCTL_BCM_SET_MAC_TRACING:
1026 /* copy ioctl Buffer structure */
1027 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1030 if(copy_from_user(&tracing_flag,IoBuffer.InputBuffer,sizeof(UINT)))
1034 Adapter->pTarangs->MacTracingEnabled = TRUE;
1036 Adapter->pTarangs->MacTracingEnabled = FALSE;
1039 case IOCTL_BCM_GET_DSX_INDICATION:
1042 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1045 if(IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt))
1047 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
1048 "Mismatch req: %lx needed is =0x%zx!!!",
1049 IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
1053 if(copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1056 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId );
1057 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1058 Status=STATUS_SUCCESS;
1061 case IOCTL_BCM_GET_HOST_MIBS:
1065 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1068 if(IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS))
1070 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
1071 "Length Check failed %lu %zd\n",
1072 IoBuffer.OutputLength, sizeof(S_MIBS_HOST_STATS_MIBS));
1076 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1077 temp_buff = kzalloc(sizeof(S_MIBS_HOST_STATS_MIBS), GFP_KERNEL);
1079 return STATUS_FAILURE;
1081 Status = ProcessGetHostMibs(Adapter, temp_buff);
1082 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1084 if (Status != STATUS_FAILURE)
1085 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS)))
1092 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1093 if((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE==Adapter->IdleMode))
1095 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1096 Adapter->bWakeUpDevice = TRUE;
1097 wake_up(&Adapter->process_rx_cntrlpkt);
1099 Status = STATUS_SUCCESS;
1102 case IOCTL_BCM_BULK_WRM:
1104 PBULKWRM_BUFFER pBulkBuffer;
1106 PCHAR pvBuffer = NULL;
1108 if((Adapter->IdleMode == TRUE) ||
1109 (Adapter->bShutStatus ==TRUE) ||
1110 (Adapter->bPreparingForLowPowerMode ==TRUE))
1112 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1117 /* Copy Ioctl Buffer structure */
1118 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1121 /* FIXME: restrict length */
1122 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
1126 /* Get WrmBuffer structure */
1127 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
1134 pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
1136 if(((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1137 ((ULONG)pBulkBuffer->Register & 0x3))
1140 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer->Register);
1146 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1147 if(!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE)
1148 && ((uiTempVar == EEPROM_REJECT_REG_1)||
1149 (uiTempVar == EEPROM_REJECT_REG_2) ||
1150 (uiTempVar == EEPROM_REJECT_REG_3) ||
1151 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1152 (cmd == IOCTL_BCM_REGISTER_WRITE))
1155 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"EEPROM Access Denied, not in VSG Mode\n");
1160 if(pBulkBuffer->SwapEndian == FALSE)
1161 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1163 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1165 if(Status != STATUS_SUCCESS)
1167 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1174 case IOCTL_BCM_GET_NVM_SIZE:
1175 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1178 if(Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH ) {
1179 if(copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1182 Status = STATUS_SUCCESS ;
1185 case IOCTL_BCM_CAL_INIT :
1188 UINT uiSectorSize = 0 ;
1189 if(Adapter->eNVMType == NVM_FLASH)
1191 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1194 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1197 if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE))
1199 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1205 if(IsFlash2x(Adapter))
1207 if (copy_to_user(IoBuffer.OutputBuffer,
1208 &Adapter->uiSectorSize ,
1214 if((TRUE == Adapter->bShutStatus) ||
1215 (TRUE == Adapter->IdleMode))
1217 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle/Shutdown Mode\n");
1221 Adapter->uiSectorSize = uiSectorSize ;
1222 BcmUpdateSectorSize(Adapter,Adapter->uiSectorSize);
1225 Status = STATUS_SUCCESS ;
1229 Status = STATUS_FAILURE;
1233 case IOCTL_BCM_SET_DEBUG :
1236 USER_BCM_DBG_STATE sUserDebugState;
1238 // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG );
1240 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1241 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1244 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE)))
1248 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1249 sUserDebugState.OnOff, sUserDebugState.Type);
1250 //sUserDebugState.Subtype <<= 1;
1251 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1252 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1254 // Update new 'DebugState' in the Adapter
1255 Adapter->stDebugState.type |= sUserDebugState.Type;
1256 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1257 * Valid indexes in 'subtype' array: 1,2,4,8
1258 * corresponding to valid Type values. Hence we can use the 'Type' field
1259 * as the index value, ignoring the array entries 0,3,5,6,7 !
1261 if (sUserDebugState.OnOff)
1262 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1264 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1266 BCM_SHOW_DEBUG_BITMAP(Adapter);
1271 case IOCTL_BCM_NVM_READ:
1272 case IOCTL_BCM_NVM_WRITE:
1274 NVM_READWRITE stNVMReadWrite;
1275 PUCHAR pReadData = NULL;
1276 ULONG ulDSDMagicNumInUsrBuff = 0;
1277 struct timeval tv0, tv1;
1278 memset(&tv0,0,sizeof(struct timeval));
1279 memset(&tv1,0,sizeof(struct timeval));
1280 if((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0))
1282 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,"The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1287 if(IsFlash2x(Adapter))
1289 if((Adapter->eActiveDSD != DSD0) &&
1290 (Adapter->eActiveDSD != DSD1) &&
1291 (Adapter->eActiveDSD != DSD2))
1293 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"No DSD is active..hence NVM Command is blocked");
1294 return STATUS_FAILURE ;
1298 /* Copy Ioctl Buffer structure */
1300 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1303 if(copy_from_user(&stNVMReadWrite,
1304 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1305 sizeof(NVM_READWRITE)))
1309 // Deny the access if the offset crosses the cal area limit.
1311 if((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) > Adapter->uiNVMDSDSize)
1313 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset ,
1314 // stNVMReadWrite.uiNumBytes);
1315 Status = STATUS_FAILURE;
1319 pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
1323 if(copy_from_user(pReadData, stNVMReadWrite.pBuffer,
1324 stNVMReadWrite.uiNumBytes))
1331 do_gettimeofday(&tv0);
1332 if(IOCTL_BCM_NVM_READ == cmd)
1334 down(&Adapter->NVMRdmWrmLock);
1336 if((Adapter->IdleMode == TRUE) ||
1337 (Adapter->bShutStatus ==TRUE) ||
1338 (Adapter->bPreparingForLowPowerMode ==TRUE))
1340 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1341 up(&Adapter->NVMRdmWrmLock);
1346 Status = BeceemNVMRead(Adapter, (PUINT)pReadData,
1347 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1349 up(&Adapter->NVMRdmWrmLock);
1351 if(Status != STATUS_SUCCESS)
1356 if(copy_to_user(stNVMReadWrite.pBuffer,pReadData, stNVMReadWrite.uiNumBytes))
1365 down(&Adapter->NVMRdmWrmLock);
1367 if((Adapter->IdleMode == TRUE) ||
1368 (Adapter->bShutStatus ==TRUE) ||
1369 (Adapter->bPreparingForLowPowerMode ==TRUE))
1371 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1372 up(&Adapter->NVMRdmWrmLock);
1377 Adapter->bHeaderChangeAllowed = TRUE ;
1378 if(IsFlash2x(Adapter))
1382 DSD section updation will be allowed in two case:-
1383 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1384 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1385 corrupted then user space program first modify the DSD header with valid DSD sig so
1386 that this as well as further write may be worthwhile.
1388 This restriction has been put assuming that if DSD sig is corrupted, DSD
1389 data won't be considered valid.
1393 Status = BcmFlash2xCorruptSig(Adapter,Adapter->eActiveDSD);
1394 if(Status != STATUS_SUCCESS)
1396 if(( (stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize ) ||
1397 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE))
1399 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1400 up(&Adapter->NVMRdmWrmLock);
1405 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1406 if(ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER)
1408 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1409 up(&Adapter->NVMRdmWrmLock);
1415 Status = BeceemNVMWrite(Adapter, (PUINT )pReadData,
1416 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1417 if(IsFlash2x(Adapter))
1418 BcmFlash2xWriteSig(Adapter,Adapter->eActiveDSD);
1420 Adapter->bHeaderChangeAllowed = FALSE ;
1422 up(&Adapter->NVMRdmWrmLock);
1425 if(Status != STATUS_SUCCESS)
1431 do_gettimeofday(&tv1);
1432 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);
1436 Status = STATUS_SUCCESS;
1439 case IOCTL_BCM_FLASH2X_SECTION_READ :
1442 FLASH2X_READWRITE sFlash2xRead = {0};
1443 PUCHAR pReadBuff = NULL ;
1447 UINT ReadOffset = 0;
1448 void __user *OutPutBuff;
1450 if(IsFlash2x(Adapter) != TRUE)
1452 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1456 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1457 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1460 //Reading FLASH 2.x READ structure
1461 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,sizeof(FLASH2X_READWRITE)))
1465 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xRead.Section);
1466 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%x" ,sFlash2xRead.offset);
1467 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xRead.numOfBytes);
1468 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xRead.bVerify);
1470 //This was internal to driver for raw read. now it has ben exposed to user space app.
1471 if(validateFlash2xReadWrite(Adapter,&sFlash2xRead) == FALSE)
1472 return STATUS_FAILURE ;
1474 NOB = sFlash2xRead.numOfBytes;
1475 if(NOB > Adapter->uiSectorSize )
1476 BuffSize = Adapter->uiSectorSize;
1480 ReadOffset = sFlash2xRead.offset ;
1481 OutPutBuff = IoBuffer.OutputBuffer;
1484 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1485 if(pReadBuff == NULL)
1487 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1490 down(&Adapter->NVMRdmWrmLock);
1492 if((Adapter->IdleMode == TRUE) ||
1493 (Adapter->bShutStatus ==TRUE) ||
1494 (Adapter->bPreparingForLowPowerMode ==TRUE))
1496 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1497 up(&Adapter->NVMRdmWrmLock);
1505 if(NOB > Adapter->uiSectorSize )
1506 ReadBytes = Adapter->uiSectorSize;
1511 //Reading the data from Flash 2.x
1513 Status = BcmFlash2xBulkRead(Adapter,(PUINT)pReadBuff,sFlash2xRead.Section,ReadOffset,ReadBytes);
1516 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Flash 2x read err with Status :%d", Status);
1520 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes);
1522 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
1525 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Copy to use failed with status :%d", Status);
1528 NOB = NOB - ReadBytes;
1531 ReadOffset = ReadOffset + ReadBytes ;
1532 OutPutBuff = OutPutBuff + ReadBytes ;
1536 up(&Adapter->NVMRdmWrmLock);
1541 case IOCTL_BCM_FLASH2X_SECTION_WRITE :
1543 FLASH2X_READWRITE sFlash2xWrite = {0};
1545 void __user *InputAddr;
1548 UINT WriteOffset = 0;
1549 UINT WriteBytes = 0;
1551 if(IsFlash2x(Adapter) != TRUE)
1553 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1557 //First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite
1558 Adapter->bAllDSDWriteAllow = FALSE;
1561 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1562 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1565 //Reading FLASH 2.x READ structure
1566 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
1569 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite.Section);
1570 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite.offset);
1571 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite.numOfBytes);
1572 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite.bVerify);
1573 if((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) &&
1574 (sFlash2xWrite.Section != VSA2) )
1576 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Only VSA write is allowed");
1580 if(validateFlash2xReadWrite(Adapter,&sFlash2xWrite) == FALSE)
1581 return STATUS_FAILURE ;
1583 InputAddr = sFlash2xWrite.pDataBuff;
1584 WriteOffset = sFlash2xWrite.offset ;
1585 NOB = sFlash2xWrite.numOfBytes;
1587 if(NOB > Adapter->uiSectorSize )
1588 BuffSize = Adapter->uiSectorSize;
1592 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1593 if(pWriteBuff == NULL)
1597 //extracting the remainder of the given offset.
1598 WriteBytes = Adapter->uiSectorSize ;
1599 if(WriteOffset % Adapter->uiSectorSize)
1600 WriteBytes =Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1601 if(NOB < WriteBytes)
1604 down(&Adapter->NVMRdmWrmLock);
1606 if((Adapter->IdleMode == TRUE) ||
1607 (Adapter->bShutStatus ==TRUE) ||
1608 (Adapter->bPreparingForLowPowerMode ==TRUE))
1610 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1611 up(&Adapter->NVMRdmWrmLock);
1616 BcmFlash2xCorruptSig(Adapter,sFlash2xWrite.Section);
1619 Status = copy_from_user(pWriteBuff,InputAddr,WriteBytes);
1622 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to user failed with status :%d", Status);
1625 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pWriteBuff,WriteBytes);
1626 //Writing the data from Flash 2.x
1627 Status = BcmFlash2xBulkWrite(Adapter,(PUINT)pWriteBuff,sFlash2xWrite.Section,WriteOffset,WriteBytes,sFlash2xWrite.bVerify);
1631 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
1635 NOB = NOB - WriteBytes;
1638 WriteOffset = WriteOffset + WriteBytes ;
1639 InputAddr = InputAddr + WriteBytes ;
1640 if(NOB > Adapter->uiSectorSize )
1641 WriteBytes = Adapter->uiSectorSize;
1648 BcmFlash2xWriteSig(Adapter,sFlash2xWrite.Section);
1649 up(&Adapter->NVMRdmWrmLock);
1653 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP :
1656 PFLASH2X_BITMAP psFlash2xBitMap;
1657 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1659 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1662 if(IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
1665 psFlash2xBitMap = kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
1666 if(psFlash2xBitMap == NULL)
1668 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory is not available");
1671 //Reading the Flash Sectio Bit map
1672 down(&Adapter->NVMRdmWrmLock);
1674 if((Adapter->IdleMode == TRUE) ||
1675 (Adapter->bShutStatus ==TRUE) ||
1676 (Adapter->bPreparingForLowPowerMode ==TRUE))
1678 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1679 up(&Adapter->NVMRdmWrmLock);
1680 kfree(psFlash2xBitMap);
1684 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1685 up(&Adapter->NVMRdmWrmLock);
1686 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP)))
1689 kfree(psFlash2xBitMap);
1692 case IOCTL_BCM_SET_ACTIVE_SECTION :
1694 FLASH2X_SECTION_VAL eFlash2xSectionVal = 0;
1695 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1697 if(IsFlash2x(Adapter) != TRUE)
1699 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1703 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1706 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1710 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
1713 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1717 down(&Adapter->NVMRdmWrmLock);
1719 if((Adapter->IdleMode == TRUE) ||
1720 (Adapter->bShutStatus ==TRUE) ||
1721 (Adapter->bPreparingForLowPowerMode ==TRUE))
1723 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1724 up(&Adapter->NVMRdmWrmLock);
1728 Status = BcmSetActiveSection(Adapter,eFlash2xSectionVal);
1731 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed to make it's priority Highest. Status %d", Status);
1733 up(&Adapter->NVMRdmWrmLock);
1736 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION :
1738 //Right Now we are taking care of only DSD
1739 Adapter->bAllDSDWriteAllow = FALSE ;
1740 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1742 Status = STATUS_SUCCESS ;
1745 case IOCTL_BCM_COPY_SECTION :
1747 FLASH2X_COPY_SECTION sCopySectStrut = {0};
1748 Status = STATUS_SUCCESS;
1749 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1751 Adapter->bAllDSDWriteAllow = FALSE ;
1752 if(IsFlash2x(Adapter) != TRUE)
1754 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1758 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1761 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1765 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
1768 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1771 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1772 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1773 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1774 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1777 if(IsSectionExistInFlash(Adapter,sCopySectStrut.SrcSection) == FALSE)
1779 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
1783 if(IsSectionExistInFlash(Adapter,sCopySectStrut.DstSection) == FALSE)
1785 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
1789 if(sCopySectStrut.SrcSection == sCopySectStrut.DstSection)
1791 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Source and Destination section should be different");
1795 down(&Adapter->NVMRdmWrmLock);
1797 if((Adapter->IdleMode == TRUE) ||
1798 (Adapter->bShutStatus ==TRUE) ||
1799 (Adapter->bPreparingForLowPowerMode ==TRUE))
1801 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1802 up(&Adapter->NVMRdmWrmLock);
1806 if(sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2)
1808 if(IsNonCDLessDevice(Adapter))
1810 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is Non-CDLess hence won't have ISO !!");
1813 else if(sCopySectStrut.numOfBytes == 0)
1815 Status = BcmCopyISO(Adapter,sCopySectStrut);
1819 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Partial Copy of ISO section is not Allowed..");
1820 Status = STATUS_FAILURE ;
1822 up(&Adapter->NVMRdmWrmLock);
1826 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
1827 sCopySectStrut.DstSection,sCopySectStrut.offset,sCopySectStrut.numOfBytes);
1828 up(&Adapter->NVMRdmWrmLock);
1831 case IOCTL_BCM_GET_FLASH_CS_INFO :
1833 Status = STATUS_SUCCESS;
1834 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1836 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1839 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1842 if(Adapter->eNVMType != NVM_FLASH)
1844 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Connected device does not have flash");
1848 if(IsFlash2x(Adapter) == TRUE)
1851 if(IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
1854 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO)))
1859 if(IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
1862 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO)))
1868 case IOCTL_BCM_SELECT_DSD :
1871 FLASH2X_SECTION_VAL eFlash2xSectionVal;
1872 eFlash2xSectionVal = NO_SECTION_VAL ;
1873 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_SELECT_DSD Called");
1875 if(IsFlash2x(Adapter) != TRUE)
1877 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
1881 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1884 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1887 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1890 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1894 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", eFlash2xSectionVal);
1895 if((eFlash2xSectionVal != DSD0) &&
1896 (eFlash2xSectionVal != DSD1) &&
1897 (eFlash2xSectionVal != DSD2) )
1899 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Passed section<%x> is not DSD section", eFlash2xSectionVal);
1900 return STATUS_FAILURE ;
1903 SectOfset= BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
1904 if(SectOfset == INVALID_OFFSET)
1906 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
1910 Adapter->bAllDSDWriteAllow = TRUE ;
1912 Adapter->ulFlashCalStart = SectOfset ;
1913 Adapter->eActiveDSD = eFlash2xSectionVal;
1915 Status = STATUS_SUCCESS ;
1918 case IOCTL_BCM_NVM_RAW_READ :
1921 NVM_READWRITE stNVMRead;
1925 UINT ReadBytes = 0 ;
1927 void __user *OutPutBuff;
1929 if(Adapter->eNVMType != NVM_FLASH)
1931 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"NVM TYPE is not Flash ");
1935 /* Copy Ioctl Buffer structure */
1936 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1938 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
1943 if(copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,sizeof(NVM_READWRITE)))
1946 NOB = stNVMRead.uiNumBytes;
1947 //In Raw-Read max Buff size : 64MB
1949 if(NOB > DEFAULT_BUFF_SIZE)
1950 BuffSize = DEFAULT_BUFF_SIZE;
1954 ReadOffset = stNVMRead.uiOffset;
1955 OutPutBuff = stNVMRead.pBuffer;
1957 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
1958 if(pReadBuff == NULL)
1960 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1964 down(&Adapter->NVMRdmWrmLock);
1966 if((Adapter->IdleMode == TRUE) ||
1967 (Adapter->bShutStatus ==TRUE) ||
1968 (Adapter->bPreparingForLowPowerMode ==TRUE))
1970 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1972 up(&Adapter->NVMRdmWrmLock);
1976 Adapter->bFlashRawRead = TRUE ;
1979 if(NOB > DEFAULT_BUFF_SIZE )
1980 ReadBytes = DEFAULT_BUFF_SIZE;
1984 //Reading the data from Flash 2.x
1985 Status = BeceemNVMRead(Adapter,(PUINT)pReadBuff,ReadOffset,ReadBytes);
1988 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
1992 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff,ReadBytes);
1994 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
1997 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to use failed with status :%d", Status);
2000 NOB = NOB - ReadBytes;
2003 ReadOffset = ReadOffset + ReadBytes ;
2004 OutPutBuff = OutPutBuff + ReadBytes ;
2008 Adapter->bFlashRawRead = FALSE ;
2009 up(&Adapter->NVMRdmWrmLock);
2014 case IOCTL_BCM_CNTRLMSG_MASK:
2016 ULONG RxCntrlMsgBitMask = 0 ;
2018 /* Copy Ioctl Buffer structure */
2019 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
2022 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of Ioctl buffer is failed from user space");
2027 if (IoBuffer.InputLength != sizeof(unsigned long)) {
2032 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
2035 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of control bit mask failed from user space");
2039 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
2040 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask ;
2043 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO:
2045 DEVICE_DRIVER_INFO DevInfo;
2047 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2049 DevInfo.MaxRDMBufferSize = BUFFER_4K;
2050 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
2051 DevInfo.u32RxAlignmentCorrection = 0;
2052 DevInfo.u32NVMType = Adapter->eNVMType;
2053 DevInfo.u32InterfaceType = BCM_USB;
2055 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2058 if(IoBuffer.OutputLength < sizeof(DevInfo))
2061 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
2066 case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
2068 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
2070 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2072 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2075 if(IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
2078 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
2080 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED)))
2086 case IOCTL_CLOSE_NOTIFICATION:
2087 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_CLOSE_NOTIFICATION");
2091 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2092 Status = STATUS_FAILURE;
2099 static struct file_operations bcm_fops = {
2100 .owner = THIS_MODULE,
2101 .open = bcm_char_open,
2102 .release = bcm_char_release,
2103 .read = bcm_char_read,
2104 .unlocked_ioctl = bcm_char_ioctl,
2105 .llseek = no_llseek,
2108 extern struct class *bcm_class;
2110 int register_control_device_interface(PMINI_ADAPTER Adapter)
2113 if(Adapter->major>0)
2114 return Adapter->major;
2116 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
2117 if(Adapter->major < 0) {
2118 pr_err(DRV_NAME ": could not created character device\n");
2119 return Adapter->major;
2122 Adapter->pstCreatedClassDevice = device_create (bcm_class, NULL,
2123 MKDEV(Adapter->major, 0), Adapter,
2126 if(IS_ERR(Adapter->pstCreatedClassDevice)) {
2127 pr_err(DRV_NAME ": class device create failed\n");
2128 unregister_chrdev(Adapter->major, DEV_NAME);
2129 return PTR_ERR(Adapter->pstCreatedClassDevice);
2135 void unregister_control_device_interface(PMINI_ADAPTER Adapter)
2137 if(Adapter->major > 0) {
2138 device_destroy (bcm_class, MKDEV(Adapter->major, 0));
2139 unregister_chrdev(Adapter->major, DEV_NAME);