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 = kzalloc(sizeof(PER_TARANG_DATA), GFP_KERNEL);
26 pTarang->Adapter = Adapter;
27 pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
29 down(&Adapter->RxAppControlQueuelock);
30 pTarang->next = Adapter->pTarangs;
31 Adapter->pTarangs = pTarang;
32 up(&Adapter->RxAppControlQueuelock);
34 /* Store the Adapter structure */
35 filp->private_data = pTarang;
37 /* Start Queuing the control response Packets */
38 atomic_inc(&Adapter->ApplicationRunning);
40 nonseekable_open(inode, filp);
44 static int bcm_char_release(struct inode *inode, struct file *filp)
46 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;
52 if (pTarang == NULL) {
53 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
58 Adapter = pTarang->Adapter;
60 down(&Adapter->RxAppControlQueuelock);
62 tmp = Adapter->pTarangs;
63 for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
70 Adapter->pTarangs = tmp->next;
72 ptmp->next = tmp->next;
74 up(&Adapter->RxAppControlQueuelock);
78 pkt = pTarang->RxAppControlHead;
85 up(&Adapter->RxAppControlQueuelock);
87 /* Stop Queuing the control response Packets */
88 atomic_dec(&Adapter->ApplicationRunning);
92 /* remove this filp from the asynchronously notified filp's */
93 filp->private_data = NULL;
97 static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
100 PPER_TARANG_DATA pTarang = filp->private_data;
101 PMINI_ADAPTER Adapter = pTarang->Adapter;
102 struct sk_buff *Packet = NULL;
104 int wait_ret_val = 0;
105 unsigned long ret = 0;
107 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
108 (pTarang->RxAppControlHead ||
109 Adapter->device_removed));
110 if ((wait_ret_val == -ERESTARTSYS)) {
111 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
112 "Exiting as i've been asked to exit!!!\n");
116 if (Adapter->device_removed) {
117 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
118 "Device Removed... Killing the Apps...\n");
122 if (FALSE == Adapter->fw_download_done)
125 down(&Adapter->RxAppControlQueuelock);
127 if (pTarang->RxAppControlHead) {
128 Packet = pTarang->RxAppControlHead;
129 DEQUEUEPACKET(pTarang->RxAppControlHead,
130 pTarang->RxAppControlTail);
131 pTarang->AppCtrlQueueLen--;
134 up(&Adapter->RxAppControlQueuelock);
137 PktLen = Packet->len;
138 ret = copy_to_user(buf, Packet->data,
139 min_t(size_t, PktLen, size));
141 dev_kfree_skb(Packet);
142 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
143 "Returning from copy to user failure\n");
146 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
147 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
148 PktLen, Packet, current->pid);
149 dev_kfree_skb(Packet);
152 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
156 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
158 PPER_TARANG_DATA pTarang = filp->private_data;
159 void __user *argp = (void __user *)arg;
160 PMINI_ADAPTER Adapter = pTarang->Adapter;
161 INT Status = STATUS_FAILURE;
163 IOCTL_BUFFER IoBuffer;
165 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);
167 if (_IOC_TYPE(cmd) != BCM_IOCTL)
169 if (_IOC_DIR(cmd) & _IOC_READ)
170 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
171 else if (_IOC_DIR(cmd) & _IOC_WRITE)
172 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
173 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
174 Status = STATUS_SUCCESS;
179 if (Adapter->device_removed)
182 if (FALSE == Adapter->fw_download_done) {
184 case IOCTL_MAC_ADDR_REQ:
186 case IOCTL_CM_REQUEST:
187 case IOCTL_SS_INFO_REQ:
188 case IOCTL_SEND_CONTROL_MESSAGE:
190 case IOCTL_BCM_GPIO_SET_REQUEST:
191 case IOCTL_BCM_GPIO_STATUS_REQUEST:
198 Status = vendorextnIoctl(Adapter, cmd, arg);
199 if (Status != CONTINUE_COMMON_PATH)
203 /* Rdms for Swin Idle... */
204 case IOCTL_BCM_REGISTER_READ_PRIVATE: {
205 RDM_BUFFER sRdmBuffer = {0};
209 /* Copy Ioctl Buffer structure */
210 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
213 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
216 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
219 if (IoBuffer.OutputLength > USHRT_MAX ||
220 IoBuffer.OutputLength == 0) {
224 Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
225 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
229 Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
230 (PUINT)temp_buff, Bufflen);
231 if (Status == STATUS_SUCCESS) {
232 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
240 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");
266 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
267 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
269 if (Status == STATUS_SUCCESS) {
270 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
272 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
278 case IOCTL_BCM_REGISTER_READ:
279 case IOCTL_BCM_EEPROM_REGISTER_READ: {
280 RDM_BUFFER sRdmBuffer = {0};
281 PCHAR temp_buff = NULL;
283 if ((Adapter->IdleMode == TRUE) ||
284 (Adapter->bShutStatus == TRUE) ||
285 (Adapter->bPreparingForLowPowerMode == TRUE)) {
287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
291 /* Copy Ioctl Buffer structure */
292 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
295 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
298 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
301 /* FIXME: don't trust user supplied length */
302 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
304 return STATUS_FAILURE;
306 if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
307 ((ULONG)sRdmBuffer.Register & 0x3)) {
309 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
310 (int)sRdmBuffer.Register);
316 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
317 Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register, (PUINT)temp_buff, IoBuffer.OutputLength);
319 if (Status == STATUS_SUCCESS)
320 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
326 case IOCTL_BCM_REGISTER_WRITE:
327 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", (int)sWrmBuffer.Register);
356 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
357 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
358 ((uiTempVar == EEPROM_REJECT_REG_1) ||
359 (uiTempVar == EEPROM_REJECT_REG_2) ||
360 (uiTempVar == EEPROM_REJECT_REG_3) ||
361 (uiTempVar == EEPROM_REJECT_REG_4)) &&
362 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
364 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
368 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
369 (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
371 if (Status == STATUS_SUCCESS) {
372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
374 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
379 case IOCTL_BCM_GPIO_SET_REQUEST: {
380 UCHAR ucResetValue[4];
383 UINT uiOperation = 0;
385 GPIO_INFO gpio_info = {0};
386 if ((Adapter->IdleMode == TRUE) ||
387 (Adapter->bShutStatus == TRUE) ||
388 (Adapter->bPreparingForLowPowerMode == TRUE)) {
390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
394 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
397 if (IoBuffer.InputLength > sizeof(gpio_info))
400 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
403 uiBit = gpio_info.uiGpioNumber;
404 uiOperation = gpio_info.uiGpioValue;
407 if (IsReqGpioIsLedInNVM(Adapter, value) == FALSE) {
408 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!", value);
413 /* Set - setting 1 */
415 /* Set the gpio output register */
416 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, (PUINT)(&value), sizeof(UINT));
418 if (Status == STATUS_SUCCESS) {
419 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
421 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to set the %dth GPIO\n", uiBit);
425 /* Set the gpio output register */
426 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)(&value), sizeof(UINT));
428 if (Status == STATUS_SUCCESS) {
429 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 clear the %dth GPIO\n", uiBit);
436 Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
438 if (STATUS_SUCCESS != Status) {
439 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
440 "GPIO_MODE_REGISTER read failed");
444 /* Set the gpio mode register to output */
445 *(UINT *)ucResetValue |= (1<<uiBit);
446 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
447 (PUINT)ucResetValue, sizeof(UINT));
449 if (Status == STATUS_SUCCESS) {
450 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO to output Mode\n");
452 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
458 case BCM_LED_THREAD_STATE_CHANGE_REQ: {
459 USER_THREAD_REQ threadReq = {0};
460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "User made LED thread InActive");
462 if ((Adapter->IdleMode == TRUE) ||
463 (Adapter->bShutStatus == TRUE) ||
464 (Adapter->bPreparingForLowPowerMode == TRUE)) {
466 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
471 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
474 if (IoBuffer.InputLength > sizeof(threadReq))
477 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
480 /* if LED thread is running(Actively or Inactively) set it state to make inactive */
481 if (Adapter->LEDInfo.led_thread_running) {
482 if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
483 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Activating thread req");
484 Adapter->DriverState = LED_THREAD_ACTIVE;
486 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DeActivating Thread req.....");
487 Adapter->DriverState = LED_THREAD_INACTIVE;
491 wake_up(&Adapter->LEDInfo.notify_led_event);
496 case IOCTL_BCM_GPIO_STATUS_REQUEST: {
499 GPIO_INFO gpio_info = {0};
501 if ((Adapter->IdleMode == TRUE) ||
502 (Adapter->bShutStatus == TRUE) ||
503 (Adapter->bPreparingForLowPowerMode == TRUE))
506 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
509 if (IoBuffer.InputLength > sizeof(gpio_info))
512 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
515 uiBit = gpio_info.uiGpioNumber;
517 /* Set the gpio output register */
518 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
519 (PUINT)ucRead, sizeof(UINT));
521 if (Status != STATUS_SUCCESS) {
522 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
528 case IOCTL_BCM_GPIO_MULTI_REQUEST: {
529 UCHAR ucResetValue[4];
530 GPIO_MULTI_INFO gpio_multi_info[MAX_IDX];
531 PGPIO_MULTI_INFO pgpio_multi_info = (PGPIO_MULTI_INFO)gpio_multi_info;
533 memset(pgpio_multi_info, 0, MAX_IDX * sizeof(GPIO_MULTI_INFO));
535 if ((Adapter->IdleMode == TRUE) ||
536 (Adapter->bShutStatus == TRUE) ||
537 (Adapter->bPreparingForLowPowerMode == TRUE))
540 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
543 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
546 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
549 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_info[WIMAX_IDX].uiGPIOMask) == FALSE) {
550 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
551 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
552 pgpio_multi_info[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
557 /* Set the gpio output register */
558 if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
559 (pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
560 /* Set 1's in GPIO OUTPUT REGISTER */
561 *(UINT *)ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
562 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
563 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
565 if (*(UINT *) ucResetValue)
566 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG,
567 (PUINT)ucResetValue, sizeof(ULONG));
569 if (Status != STATUS_SUCCESS) {
570 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
574 /* Clear to 0'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_CLR_REG, (PUINT)ucResetValue, sizeof(ULONG));
582 if (Status != STATUS_SUCCESS) {
583 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
588 if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
589 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
591 if (Status != STATUS_SUCCESS) {
592 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM to GPIO_PIN_STATE_REGISTER Failed.");
596 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = (*(UINT *)ucResetValue &
597 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
600 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
602 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
603 "Failed while copying Content to IOBufer for user space err:%d", Status);
609 case IOCTL_BCM_GPIO_MODE_REQUEST: {
610 UCHAR ucResetValue[4];
611 GPIO_MULTI_MODE gpio_multi_mode[MAX_IDX];
612 PGPIO_MULTI_MODE pgpio_multi_mode = (PGPIO_MULTI_MODE)gpio_multi_mode;
614 if ((Adapter->IdleMode == TRUE) ||
615 (Adapter->bShutStatus == TRUE) ||
616 (Adapter->bPreparingForLowPowerMode == TRUE))
619 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
622 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
625 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
628 Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
630 if (STATUS_SUCCESS != Status) {
631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read of GPIO_MODE_REGISTER failed");
635 /* Validating the request */
636 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) == FALSE) {
637 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
638 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
639 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
644 if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
645 /* write all OUT's (1's) */
646 *(UINT *) ucResetValue |= (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
647 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
649 /* write all IN's (0's) */
650 *(UINT *) ucResetValue &= ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
651 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
653 /* Currently implemented return the modes of all GPIO's
654 * else needs to bit AND with mask
656 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
658 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(ULONG));
659 if (Status == STATUS_SUCCESS) {
660 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
661 "WRM to GPIO_MODE_REGISTER Done");
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
664 "WRM to GPIO_MODE_REGISTER Failed");
669 /* if uiGPIOMask is 0 then return mode register configuration */
670 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
673 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
675 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
676 "Failed while copying Content to IOBufer for user space err:%d", Status);
682 case IOCTL_MAC_ADDR_REQ:
684 case IOCTL_CM_REQUEST:
685 case IOCTL_SS_INFO_REQ:
686 case IOCTL_SEND_CONTROL_MESSAGE:
687 case IOCTL_IDLE_REQ: {
688 PVOID pvBuffer = NULL;
690 /* Copy Ioctl Buffer structure */
691 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
694 if (IoBuffer.InputLength < sizeof(struct link_request))
697 if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
700 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
704 if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
710 down(&Adapter->LowPowerModeSync);
711 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
712 !Adapter->bPreparingForLowPowerMode,
714 if (Status == -ERESTARTSYS)
717 if (Adapter->bPreparingForLowPowerMode) {
718 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
719 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
720 Status = STATUS_FAILURE;
723 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
726 up(&Adapter->LowPowerModeSync);
731 case IOCTL_BCM_BUFFER_DOWNLOAD_START: {
732 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
735 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
740 "Starting the firmware download PID =0x%x!!!!\n", current->pid);
742 if (!down_trylock(&Adapter->fw_download_sema)) {
743 Adapter->bBinDownloaded = FALSE;
744 Adapter->fw_download_process_pid = current->pid;
745 Adapter->bCfgDownloaded = FALSE;
746 Adapter->fw_download_done = FALSE;
747 netif_carrier_off(Adapter->dev);
748 netif_stop_queue(Adapter->dev);
749 Status = reset_card_proc(Adapter);
751 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
752 up(&Adapter->fw_download_sema);
753 up(&Adapter->NVMRdmWrmLock);
761 up(&Adapter->NVMRdmWrmLock);
765 case IOCTL_BCM_BUFFER_DOWNLOAD: {
766 FIRMWARE_INFO *psFwInfo = NULL;
767 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
769 if (!down_trylock(&Adapter->fw_download_sema)) {
770 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
771 "Invalid way to download buffer. Use Start and then call this!!!\n");
776 /* Copy Ioctl Buffer structure */
777 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
780 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
781 "Length for FW DLD is : %lx\n", IoBuffer.InputLength);
783 if (IoBuffer.InputLength > sizeof(FIRMWARE_INFO))
786 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
790 if (copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength))
793 if (!psFwInfo->pvMappedFirmwareAddress ||
794 (psFwInfo->u32FirmwareLength == 0)) {
796 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
797 psFwInfo->u32FirmwareLength);
802 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
804 if (Status != STATUS_SUCCESS) {
805 if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR)
806 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
808 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
810 /* up(&Adapter->fw_download_sema); */
812 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
813 Adapter->DriverState = DRIVER_INIT;
814 Adapter->LEDInfo.bLedInitDone = FALSE;
815 wake_up(&Adapter->LEDInfo.notify_led_event);
822 if (Status != STATUS_SUCCESS)
823 up(&Adapter->fw_download_sema);
825 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
830 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP: {
831 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
834 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
835 "FW download blocked as EEPROM Read/Write is in progress\n");
836 up(&Adapter->fw_download_sema);
840 if (down_trylock(&Adapter->fw_download_sema)) {
841 Adapter->bBinDownloaded = TRUE;
842 Adapter->bCfgDownloaded = TRUE;
843 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
844 Adapter->CurrNumRecvDescs = 0;
845 Adapter->downloadDDR = 0;
847 /* setting the Mips to Run */
848 Status = run_card_proc(Adapter);
851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
852 up(&Adapter->fw_download_sema);
853 up(&Adapter->NVMRdmWrmLock);
856 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
857 DBG_LVL_ALL, "Firm Download Over...\n");
862 /* Wait for MailBox Interrupt */
863 if (StartInterruptUrb((PS_INTERFACE_ADAPTER)Adapter->pvInterfaceAdapter))
864 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
867 Adapter->waiting_to_fw_download_done = FALSE;
868 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
869 Adapter->waiting_to_fw_download_done, timeout);
870 Adapter->fw_download_process_pid = INVALID_PID;
871 Adapter->fw_download_done = TRUE;
872 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
873 Adapter->CurrNumRecvDescs = 0;
874 Adapter->PrevNumRecvDescs = 0;
875 atomic_set(&Adapter->cntrlpktCnt, 0);
876 Adapter->LinkUpStatus = 0;
877 Adapter->LinkStatus = 0;
879 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
880 Adapter->DriverState = FW_DOWNLOAD_DONE;
881 wake_up(&Adapter->LEDInfo.notify_led_event);
890 up(&Adapter->fw_download_sema);
891 up(&Adapter->NVMRdmWrmLock);
895 case IOCTL_BE_BUCKET_SIZE:
897 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
901 case IOCTL_RTPS_BUCKET_SIZE:
903 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
907 case IOCTL_CHIP_RESET: {
908 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
910 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
914 down(&Adapter->RxAppControlQueuelock);
915 Status = reset_card_proc(Adapter);
917 up(&Adapter->RxAppControlQueuelock);
918 up(&Adapter->NVMRdmWrmLock);
919 ResetCounters(Adapter);
923 case IOCTL_QOS_THRESHOLD: {
927 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
928 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
929 (unsigned long __user *)arg)) {
937 case IOCTL_DUMP_PACKET_INFO:
938 DumpPackInfo(Adapter);
939 DumpPhsRules(&Adapter->stBCMPhsContext);
940 Status = STATUS_SUCCESS;
943 case IOCTL_GET_PACK_INFO:
944 if (copy_to_user(argp, &Adapter->PackInfo, sizeof(PacketInfo)*NO_OF_QUEUES))
946 Status = STATUS_SUCCESS;
949 case IOCTL_BCM_SWITCH_TRANSFER_MODE: {
951 if (copy_from_user(&uiData, argp, sizeof(UINT)))
955 /* Allow All Packets */
956 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
957 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
959 /* Allow IP only Packets */
960 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
961 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
963 Status = STATUS_SUCCESS;
967 case IOCTL_BCM_GET_DRIVER_VERSION: {
968 /* Copy Ioctl Buffer structure */
969 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
972 if (copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, IoBuffer.OutputLength))
974 Status = STATUS_SUCCESS;
978 case IOCTL_BCM_GET_CURRENT_STATUS: {
979 LINK_STATE link_state;
981 /* Copy Ioctl Buffer structure */
982 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) {
983 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
988 if (IoBuffer.OutputLength != sizeof(link_state)) {
993 memset(&link_state, 0, sizeof(link_state));
994 link_state.bIdleMode = Adapter->IdleMode;
995 link_state.bShutdownMode = Adapter->bShutStatus;
996 link_state.ucLinkStatus = Adapter->LinkStatus;
998 if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) {
999 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1003 Status = STATUS_SUCCESS;
1007 case IOCTL_BCM_SET_MAC_TRACING: {
1010 /* copy ioctl Buffer structure */
1011 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1014 if (copy_from_user(&tracing_flag, IoBuffer.InputBuffer, sizeof(UINT)))
1018 Adapter->pTarangs->MacTracingEnabled = TRUE;
1020 Adapter->pTarangs->MacTracingEnabled = FALSE;
1024 case IOCTL_BCM_GET_DSX_INDICATION: {
1026 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1029 if (IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt)) {
1030 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1031 "Mismatch req: %lx needed is =0x%zx!!!",
1032 IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
1036 if (copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1039 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId);
1040 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1041 Status = STATUS_SUCCESS;
1045 case IOCTL_BCM_GET_HOST_MIBS: {
1048 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1051 if (IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS)) {
1052 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1053 "Length Check failed %lu %zd\n",
1054 IoBuffer.OutputLength, sizeof(S_MIBS_HOST_STATS_MIBS));
1058 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1059 temp_buff = kzalloc(sizeof(S_MIBS_HOST_STATS_MIBS), GFP_KERNEL);
1061 return STATUS_FAILURE;
1063 Status = ProcessGetHostMibs(Adapter, temp_buff);
1064 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1066 if (Status != STATUS_FAILURE)
1067 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS)))
1074 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1075 if ((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE == Adapter->IdleMode)) {
1076 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1077 Adapter->bWakeUpDevice = TRUE;
1078 wake_up(&Adapter->process_rx_cntrlpkt);
1081 Status = STATUS_SUCCESS;
1084 case IOCTL_BCM_BULK_WRM: {
1085 PBULKWRM_BUFFER pBulkBuffer;
1087 PCHAR pvBuffer = NULL;
1089 if ((Adapter->IdleMode == TRUE) ||
1090 (Adapter->bShutStatus == TRUE) ||
1091 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1093 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1098 /* Copy Ioctl Buffer structure */
1099 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1102 /* FIXME: restrict length */
1103 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
1107 /* Get WrmBuffer structure */
1108 if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
1114 pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
1116 if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1117 ((ULONG)pBulkBuffer->Register & 0x3)) {
1119 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer->Register);
1124 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1125 if (!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE) &&
1126 ((uiTempVar == EEPROM_REJECT_REG_1) ||
1127 (uiTempVar == EEPROM_REJECT_REG_2) ||
1128 (uiTempVar == EEPROM_REJECT_REG_3) ||
1129 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1130 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
1133 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
1138 if (pBulkBuffer->SwapEndian == FALSE)
1139 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1141 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1143 if (Status != STATUS_SUCCESS)
1144 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1150 case IOCTL_BCM_GET_NVM_SIZE:
1151 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1154 if (Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH) {
1155 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1159 Status = STATUS_SUCCESS;
1162 case IOCTL_BCM_CAL_INIT: {
1163 UINT uiSectorSize = 0 ;
1164 if (Adapter->eNVMType == NVM_FLASH) {
1165 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1168 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1171 if ((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) {
1172 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1176 if (IsFlash2x(Adapter)) {
1177 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize, sizeof(UINT)))
1180 if ((TRUE == Adapter->bShutStatus) || (TRUE == Adapter->IdleMode)) {
1181 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is in Idle/Shutdown Mode\n");
1185 Adapter->uiSectorSize = uiSectorSize;
1186 BcmUpdateSectorSize(Adapter, Adapter->uiSectorSize);
1189 Status = STATUS_SUCCESS;
1191 Status = STATUS_FAILURE;
1196 case IOCTL_BCM_SET_DEBUG:
1199 USER_BCM_DBG_STATE sUserDebugState;
1201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1202 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1205 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE)))
1208 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1209 sUserDebugState.OnOff, sUserDebugState.Type);
1210 /* sUserDebugState.Subtype <<= 1; */
1211 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1212 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1214 /* Update new 'DebugState' in the Adapter */
1215 Adapter->stDebugState.type |= sUserDebugState.Type;
1216 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1217 * Valid indexes in 'subtype' array: 1,2,4,8
1218 * corresponding to valid Type values. Hence we can use the 'Type' field
1219 * as the index value, ignoring the array entries 0,3,5,6,7 !
1221 if (sUserDebugState.OnOff)
1222 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1224 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1226 BCM_SHOW_DEBUG_BITMAP(Adapter);
1231 case IOCTL_BCM_NVM_READ:
1232 case IOCTL_BCM_NVM_WRITE: {
1233 NVM_READWRITE stNVMReadWrite;
1234 PUCHAR pReadData = NULL;
1235 ULONG ulDSDMagicNumInUsrBuff = 0;
1236 struct timeval tv0, tv1;
1237 memset(&tv0, 0, sizeof(struct timeval));
1238 memset(&tv1, 0, sizeof(struct timeval));
1239 if ((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0)) {
1240 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1245 if (IsFlash2x(Adapter)) {
1246 if ((Adapter->eActiveDSD != DSD0) &&
1247 (Adapter->eActiveDSD != DSD1) &&
1248 (Adapter->eActiveDSD != DSD2)) {
1250 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No DSD is active..hence NVM Command is blocked");
1251 return STATUS_FAILURE ;
1255 /* Copy Ioctl Buffer structure */
1256 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1259 if (copy_from_user(&stNVMReadWrite,
1260 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1261 sizeof(NVM_READWRITE)))
1265 * Deny the access if the offset crosses the cal area limit.
1268 if ((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) > Adapter->uiNVMDSDSize) {
1269 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes); */
1270 Status = STATUS_FAILURE;
1274 pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
1278 if (copy_from_user(pReadData, stNVMReadWrite.pBuffer, stNVMReadWrite.uiNumBytes)) {
1284 do_gettimeofday(&tv0);
1285 if (IOCTL_BCM_NVM_READ == cmd) {
1286 down(&Adapter->NVMRdmWrmLock);
1288 if ((Adapter->IdleMode == TRUE) ||
1289 (Adapter->bShutStatus == TRUE) ||
1290 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1292 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1293 up(&Adapter->NVMRdmWrmLock);
1298 Status = BeceemNVMRead(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1299 up(&Adapter->NVMRdmWrmLock);
1301 if (Status != STATUS_SUCCESS) {
1306 if (copy_to_user(stNVMReadWrite.pBuffer, pReadData, stNVMReadWrite.uiNumBytes)) {
1311 down(&Adapter->NVMRdmWrmLock);
1313 if ((Adapter->IdleMode == TRUE) ||
1314 (Adapter->bShutStatus == TRUE) ||
1315 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1317 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1318 up(&Adapter->NVMRdmWrmLock);
1323 Adapter->bHeaderChangeAllowed = TRUE;
1324 if (IsFlash2x(Adapter)) {
1327 * DSD section updation will be allowed in two case:-
1328 * 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1329 * 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1330 * corrupted then user space program first modify the DSD header with valid DSD sig so
1331 * that this as well as further write may be worthwhile.
1333 * This restriction has been put assuming that if DSD sig is corrupted, DSD
1334 * data won't be considered valid.
1337 Status = BcmFlash2xCorruptSig(Adapter, Adapter->eActiveDSD);
1338 if (Status != STATUS_SUCCESS) {
1339 if (((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize) ||
1340 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE)) {
1342 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1343 up(&Adapter->NVMRdmWrmLock);
1348 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1349 if (ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER) {
1350 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1351 up(&Adapter->NVMRdmWrmLock);
1358 Status = BeceemNVMWrite(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1359 if (IsFlash2x(Adapter))
1360 BcmFlash2xWriteSig(Adapter, Adapter->eActiveDSD);
1362 Adapter->bHeaderChangeAllowed = FALSE;
1364 up(&Adapter->NVMRdmWrmLock);
1366 if (Status != STATUS_SUCCESS) {
1372 do_gettimeofday(&tv1);
1373 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);
1376 Status = STATUS_SUCCESS;
1380 case IOCTL_BCM_FLASH2X_SECTION_READ: {
1381 FLASH2X_READWRITE sFlash2xRead = {0};
1382 PUCHAR pReadBuff = NULL ;
1386 UINT ReadOffset = 0;
1387 void __user *OutPutBuff;
1389 if (IsFlash2x(Adapter) != TRUE) {
1390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1395 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1398 /* Reading FLASH 2.x READ structure */
1399 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
1402 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xRead.Section);
1403 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%x", sFlash2xRead.offset);
1404 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xRead.numOfBytes);
1405 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xRead.bVerify);
1407 /* This was internal to driver for raw read. now it has ben exposed to user space app. */
1408 if (validateFlash2xReadWrite(Adapter, &sFlash2xRead) == FALSE)
1409 return STATUS_FAILURE;
1411 NOB = sFlash2xRead.numOfBytes;
1412 if (NOB > Adapter->uiSectorSize)
1413 BuffSize = Adapter->uiSectorSize;
1417 ReadOffset = sFlash2xRead.offset ;
1418 OutPutBuff = IoBuffer.OutputBuffer;
1419 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1421 if (pReadBuff == NULL) {
1422 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1425 down(&Adapter->NVMRdmWrmLock);
1427 if ((Adapter->IdleMode == TRUE) ||
1428 (Adapter->bShutStatus == TRUE) ||
1429 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1431 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1432 up(&Adapter->NVMRdmWrmLock);
1438 if (NOB > Adapter->uiSectorSize)
1439 ReadBytes = Adapter->uiSectorSize;
1443 /* Reading the data from Flash 2.x */
1444 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pReadBuff, sFlash2xRead.Section, ReadOffset, ReadBytes);
1446 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Flash 2x read err with Status :%d", Status);
1450 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1452 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1454 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status);
1457 NOB = NOB - ReadBytes;
1459 ReadOffset = ReadOffset + ReadBytes;
1460 OutPutBuff = OutPutBuff + ReadBytes ;
1464 up(&Adapter->NVMRdmWrmLock);
1469 case IOCTL_BCM_FLASH2X_SECTION_WRITE: {
1470 FLASH2X_READWRITE sFlash2xWrite = {0};
1472 void __user *InputAddr;
1475 UINT WriteOffset = 0;
1476 UINT WriteBytes = 0;
1478 if (IsFlash2x(Adapter) != TRUE) {
1479 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1483 /* First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite */
1484 Adapter->bAllDSDWriteAllow = FALSE;
1486 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1488 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1491 /* Reading FLASH 2.x READ structure */
1492 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
1495 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xWrite.Section);
1496 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%d", sFlash2xWrite.offset);
1497 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite.numOfBytes);
1498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite.bVerify);
1500 if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) && (sFlash2xWrite.Section != VSA2)) {
1501 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Only VSA write is allowed");
1505 if (validateFlash2xReadWrite(Adapter, &sFlash2xWrite) == FALSE)
1506 return STATUS_FAILURE;
1508 InputAddr = sFlash2xWrite.pDataBuff;
1509 WriteOffset = sFlash2xWrite.offset;
1510 NOB = sFlash2xWrite.numOfBytes;
1512 if (NOB > Adapter->uiSectorSize)
1513 BuffSize = Adapter->uiSectorSize;
1517 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1519 if (pWriteBuff == NULL)
1522 /* extracting the remainder of the given offset. */
1523 WriteBytes = Adapter->uiSectorSize;
1524 if (WriteOffset % Adapter->uiSectorSize)
1525 WriteBytes = Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1527 if (NOB < WriteBytes)
1530 down(&Adapter->NVMRdmWrmLock);
1532 if ((Adapter->IdleMode == TRUE) ||
1533 (Adapter->bShutStatus == TRUE) ||
1534 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1536 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1537 up(&Adapter->NVMRdmWrmLock);
1542 BcmFlash2xCorruptSig(Adapter, sFlash2xWrite.Section);
1544 Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
1546 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status);
1549 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
1551 /* Writing the data from Flash 2.x */
1552 Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pWriteBuff, sFlash2xWrite.Section, WriteOffset, WriteBytes, sFlash2xWrite.bVerify);
1555 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1559 NOB = NOB - WriteBytes;
1561 WriteOffset = WriteOffset + WriteBytes;
1562 InputAddr = InputAddr + WriteBytes;
1563 if (NOB > Adapter->uiSectorSize)
1564 WriteBytes = Adapter->uiSectorSize;
1570 BcmFlash2xWriteSig(Adapter, sFlash2xWrite.Section);
1571 up(&Adapter->NVMRdmWrmLock);
1576 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP: {
1577 PFLASH2X_BITMAP psFlash2xBitMap;
1578 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1580 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1583 if (IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
1586 psFlash2xBitMap = kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
1587 if (psFlash2xBitMap == NULL) {
1588 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory is not available");
1592 /* Reading the Flash Sectio Bit map */
1593 down(&Adapter->NVMRdmWrmLock);
1595 if ((Adapter->IdleMode == TRUE) ||
1596 (Adapter->bShutStatus == TRUE) ||
1597 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1599 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1600 up(&Adapter->NVMRdmWrmLock);
1601 kfree(psFlash2xBitMap);
1605 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1606 up(&Adapter->NVMRdmWrmLock);
1607 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP)))
1610 kfree(psFlash2xBitMap);
1614 case IOCTL_BCM_SET_ACTIVE_SECTION: {
1615 FLASH2X_SECTION_VAL eFlash2xSectionVal = 0;
1616 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1618 if (IsFlash2x(Adapter) != TRUE) {
1619 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1623 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1625 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1629 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1635 down(&Adapter->NVMRdmWrmLock);
1637 if ((Adapter->IdleMode == TRUE) ||
1638 (Adapter->bShutStatus == TRUE) ||
1639 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1641 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1642 up(&Adapter->NVMRdmWrmLock);
1646 Status = BcmSetActiveSection(Adapter, eFlash2xSectionVal);
1648 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Failed to make it's priority Highest. Status %d", Status);
1650 up(&Adapter->NVMRdmWrmLock);
1654 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION: {
1655 /* Right Now we are taking care of only DSD */
1656 Adapter->bAllDSDWriteAllow = FALSE;
1657 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1658 Status = STATUS_SUCCESS;
1662 case IOCTL_BCM_COPY_SECTION: {
1663 FLASH2X_COPY_SECTION sCopySectStrut = {0};
1664 Status = STATUS_SUCCESS;
1665 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1667 Adapter->bAllDSDWriteAllow = FALSE;
1668 if (IsFlash2x(Adapter) != TRUE) {
1669 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1673 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1675 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1679 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
1681 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1687 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1688 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1690 if (IsSectionExistInFlash(Adapter, sCopySectStrut.SrcSection) == FALSE) {
1691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
1695 if (IsSectionExistInFlash(Adapter, sCopySectStrut.DstSection) == FALSE) {
1696 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
1700 if (sCopySectStrut.SrcSection == sCopySectStrut.DstSection) {
1701 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source and Destination section should be different");
1705 down(&Adapter->NVMRdmWrmLock);
1707 if ((Adapter->IdleMode == TRUE) ||
1708 (Adapter->bShutStatus == TRUE) ||
1709 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1711 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1712 up(&Adapter->NVMRdmWrmLock);
1716 if (sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2) {
1717 if (IsNonCDLessDevice(Adapter)) {
1718 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is Non-CDLess hence won't have ISO !!");
1720 } else if (sCopySectStrut.numOfBytes == 0) {
1721 Status = BcmCopyISO(Adapter, sCopySectStrut);
1723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Partial Copy of ISO section is not Allowed..");
1724 Status = STATUS_FAILURE;
1726 up(&Adapter->NVMRdmWrmLock);
1730 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
1731 sCopySectStrut.DstSection, sCopySectStrut.offset, sCopySectStrut.numOfBytes);
1732 up(&Adapter->NVMRdmWrmLock);
1736 case IOCTL_BCM_GET_FLASH_CS_INFO: {
1737 Status = STATUS_SUCCESS;
1738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1740 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1746 if (Adapter->eNVMType != NVM_FLASH) {
1747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Connected device does not have flash");
1752 if (IsFlash2x(Adapter) == TRUE) {
1753 if (IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
1756 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO)))
1759 if (IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
1762 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO)))
1768 case IOCTL_BCM_SELECT_DSD: {
1770 FLASH2X_SECTION_VAL eFlash2xSectionVal;
1771 eFlash2xSectionVal = NO_SECTION_VAL;
1772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SELECT_DSD Called");
1774 if (IsFlash2x(Adapter) != TRUE) {
1775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1779 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1781 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1784 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1786 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1790 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal);
1791 if ((eFlash2xSectionVal != DSD0) &&
1792 (eFlash2xSectionVal != DSD1) &&
1793 (eFlash2xSectionVal != DSD2)) {
1795 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Passed section<%x> is not DSD section", eFlash2xSectionVal);
1796 return STATUS_FAILURE;
1799 SectOfset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
1800 if (SectOfset == INVALID_OFFSET) {
1801 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
1805 Adapter->bAllDSDWriteAllow = TRUE;
1806 Adapter->ulFlashCalStart = SectOfset;
1807 Adapter->eActiveDSD = eFlash2xSectionVal;
1809 Status = STATUS_SUCCESS;
1812 case IOCTL_BCM_NVM_RAW_READ: {
1813 NVM_READWRITE stNVMRead;
1817 UINT ReadBytes = 0 ;
1819 void __user *OutPutBuff;
1821 if (Adapter->eNVMType != NVM_FLASH) {
1822 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "NVM TYPE is not Flash");
1826 /* Copy Ioctl Buffer structure */
1827 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) {
1828 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
1833 if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(NVM_READWRITE)))
1836 NOB = stNVMRead.uiNumBytes;
1837 /* In Raw-Read max Buff size : 64MB */
1839 if (NOB > DEFAULT_BUFF_SIZE)
1840 BuffSize = DEFAULT_BUFF_SIZE;
1844 ReadOffset = stNVMRead.uiOffset;
1845 OutPutBuff = stNVMRead.pBuffer;
1847 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
1848 if (pReadBuff == NULL) {
1849 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1853 down(&Adapter->NVMRdmWrmLock);
1855 if ((Adapter->IdleMode == TRUE) ||
1856 (Adapter->bShutStatus == TRUE) ||
1857 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1859 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1861 up(&Adapter->NVMRdmWrmLock);
1865 Adapter->bFlashRawRead = TRUE;
1868 if (NOB > DEFAULT_BUFF_SIZE)
1869 ReadBytes = DEFAULT_BUFF_SIZE;
1873 /* Reading the data from Flash 2.x */
1874 Status = BeceemNVMRead(Adapter, (PUINT)pReadBuff, ReadOffset, ReadBytes);
1876 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1880 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1882 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1884 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status);
1887 NOB = NOB - ReadBytes;
1889 ReadOffset = ReadOffset + ReadBytes;
1890 OutPutBuff = OutPutBuff + ReadBytes;
1893 Adapter->bFlashRawRead = FALSE;
1894 up(&Adapter->NVMRdmWrmLock);
1899 case IOCTL_BCM_CNTRLMSG_MASK: {
1900 ULONG RxCntrlMsgBitMask = 0;
1902 /* Copy Ioctl Buffer structure */
1903 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1905 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space");
1910 if (IoBuffer.InputLength != sizeof(unsigned long)) {
1915 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
1917 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space");
1921 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
1922 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;
1926 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO: {
1927 DEVICE_DRIVER_INFO DevInfo;
1929 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
1931 DevInfo.MaxRDMBufferSize = BUFFER_4K;
1932 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
1933 DevInfo.u32RxAlignmentCorrection = 0;
1934 DevInfo.u32NVMType = Adapter->eNVMType;
1935 DevInfo.u32InterfaceType = BCM_USB;
1937 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1940 if (IoBuffer.OutputLength < sizeof(DevInfo))
1943 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
1948 case IOCTL_BCM_TIME_SINCE_NET_ENTRY: {
1949 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
1951 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
1953 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1956 if (IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
1959 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
1961 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED)))
1966 case IOCTL_CLOSE_NOTIFICATION:
1967 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_CLOSE_NOTIFICATION");
1971 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
1972 Status = STATUS_FAILURE;
1979 static const struct file_operations bcm_fops = {
1980 .owner = THIS_MODULE,
1981 .open = bcm_char_open,
1982 .release = bcm_char_release,
1983 .read = bcm_char_read,
1984 .unlocked_ioctl = bcm_char_ioctl,
1985 .llseek = no_llseek,
1988 int register_control_device_interface(PMINI_ADAPTER Adapter)
1991 if (Adapter->major > 0)
1992 return Adapter->major;
1994 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
1995 if (Adapter->major < 0) {
1996 pr_err(DRV_NAME ": could not created character device\n");
1997 return Adapter->major;
2000 Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
2001 MKDEV(Adapter->major, 0),
2004 if (IS_ERR(Adapter->pstCreatedClassDevice)) {
2005 pr_err(DRV_NAME ": class device create failed\n");
2006 unregister_chrdev(Adapter->major, DEV_NAME);
2007 return PTR_ERR(Adapter->pstCreatedClassDevice);
2013 void unregister_control_device_interface(PMINI_ADAPTER Adapter)
2015 if (Adapter->major > 0) {
2016 device_destroy(bcm_class, MKDEV(Adapter->major, 0));
2017 unregister_chrdev(Adapter->major, DEV_NAME);