4 /***************************************************************
5 * Function - bcm_char_open()
7 * Description - This is the "open" entry point for the character
10 * Parameters - inode: Pointer to the Inode structure of char device
11 * filp : File pointer of the char device
13 * Returns - Zero(Success)
14 ****************************************************************/
16 static int bcm_char_open(struct inode *inode, struct file *filp)
18 struct bcm_mini_adapter *Adapter = NULL;
19 struct bcm_tarang_data *pTarang = NULL;
21 Adapter = GET_BCM_ADAPTER(gblpnetdev);
22 pTarang = kzalloc(sizeof(struct bcm_tarang_data), GFP_KERNEL);
26 pTarang->Adapter = Adapter;
27 pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
29 down(&Adapter->RxAppControlQueuelock);
30 pTarang->next = Adapter->pTarangs;
31 Adapter->pTarangs = pTarang;
32 up(&Adapter->RxAppControlQueuelock);
34 /* Store the Adapter structure */
35 filp->private_data = pTarang;
37 /* Start Queuing the control response Packets */
38 atomic_inc(&Adapter->ApplicationRunning);
40 nonseekable_open(inode, filp);
44 static int bcm_char_release(struct inode *inode, struct file *filp)
46 struct bcm_tarang_data *pTarang, *tmp, *ptmp;
47 struct bcm_mini_adapter *Adapter = NULL;
48 struct sk_buff *pkt, *npkt;
50 pTarang = (struct bcm_tarang_data *)filp->private_data;
55 Adapter = pTarang->Adapter;
57 down(&Adapter->RxAppControlQueuelock);
59 tmp = Adapter->pTarangs;
60 for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
67 Adapter->pTarangs = tmp->next;
69 ptmp->next = tmp->next;
71 up(&Adapter->RxAppControlQueuelock);
75 pkt = pTarang->RxAppControlHead;
82 up(&Adapter->RxAppControlQueuelock);
84 /* Stop Queuing the control response Packets */
85 atomic_dec(&Adapter->ApplicationRunning);
89 /* remove this filp from the asynchronously notified filp's */
90 filp->private_data = NULL;
94 static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
97 struct bcm_tarang_data *pTarang = filp->private_data;
98 struct bcm_mini_adapter *Adapter = pTarang->Adapter;
99 struct sk_buff *Packet = NULL;
101 int wait_ret_val = 0;
102 unsigned long ret = 0;
104 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
105 (pTarang->RxAppControlHead ||
106 Adapter->device_removed));
107 if ((wait_ret_val == -ERESTARTSYS)) {
108 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
109 "Exiting as i've been asked to exit!!!\n");
113 if (Adapter->device_removed) {
114 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
115 "Device Removed... Killing the Apps...\n");
119 if (false == Adapter->fw_download_done)
122 down(&Adapter->RxAppControlQueuelock);
124 if (pTarang->RxAppControlHead) {
125 Packet = pTarang->RxAppControlHead;
126 DEQUEUEPACKET(pTarang->RxAppControlHead,
127 pTarang->RxAppControlTail);
128 pTarang->AppCtrlQueueLen--;
131 up(&Adapter->RxAppControlQueuelock);
134 PktLen = Packet->len;
135 ret = copy_to_user(buf, Packet->data,
136 min_t(size_t, PktLen, size));
138 dev_kfree_skb(Packet);
139 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
140 "Returning from copy to user failure\n");
143 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
144 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
145 PktLen, Packet, current->pid);
146 dev_kfree_skb(Packet);
149 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
153 static int bcm_char_ioctl_reg_read_private(void __user *argp, struct bcm_mini_adapter *Adapter)
155 struct bcm_rdm_buffer sRdmBuffer = {0};
156 struct bcm_ioctl_buffer IoBuffer;
158 INT Status = STATUS_FAILURE;
163 /* Copy Ioctl Buffer structure */
164 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
167 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
170 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
173 if (IoBuffer.OutputLength > USHRT_MAX ||
174 IoBuffer.OutputLength == 0) {
178 Bufflen = IoBuffer.OutputLength;
179 temp_value = 4 - (Bufflen % 4);
180 Bufflen += temp_value % 4;
182 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
186 bytes = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
187 (PUINT)temp_buff, Bufflen);
189 Status = STATUS_SUCCESS;
190 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
202 static int bcm_char_ioctl_reg_write_private(void __user *argp, struct bcm_mini_adapter *Adapter)
204 struct bcm_wrm_buffer sWrmBuffer = {0};
205 struct bcm_ioctl_buffer IoBuffer;
209 /* Copy Ioctl Buffer structure */
211 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
214 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
217 /* Get WrmBuffer structure */
218 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
221 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
222 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
223 ((uiTempVar == EEPROM_REJECT_REG_1) ||
224 (uiTempVar == EEPROM_REJECT_REG_2) ||
225 (uiTempVar == EEPROM_REJECT_REG_3) ||
226 (uiTempVar == EEPROM_REJECT_REG_4))) {
228 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
229 "EEPROM Access Denied, not in VSG Mode\n");
233 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
234 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
236 if (Status == STATUS_SUCCESS) {
237 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
238 DBG_LVL_ALL, "WRM Done\n");
240 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
241 DBG_LVL_ALL, "WRM Failed\n");
248 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
250 struct bcm_tarang_data *pTarang = filp->private_data;
251 void __user *argp = (void __user *)arg;
252 struct bcm_mini_adapter *Adapter = pTarang->Adapter;
253 INT Status = STATUS_FAILURE;
255 struct bcm_ioctl_buffer IoBuffer;
258 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
259 "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX",
262 if (_IOC_TYPE(cmd) != BCM_IOCTL)
264 if (_IOC_DIR(cmd) & _IOC_READ)
265 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
266 else if (_IOC_DIR(cmd) & _IOC_WRITE)
267 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
268 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
269 Status = STATUS_SUCCESS;
274 if (Adapter->device_removed)
277 if (false == Adapter->fw_download_done) {
279 case IOCTL_MAC_ADDR_REQ:
281 case IOCTL_CM_REQUEST:
282 case IOCTL_SS_INFO_REQ:
283 case IOCTL_SEND_CONTROL_MESSAGE:
285 case IOCTL_BCM_GPIO_SET_REQUEST:
286 case IOCTL_BCM_GPIO_STATUS_REQUEST:
293 Status = vendorextnIoctl(Adapter, cmd, arg);
294 if (Status != CONTINUE_COMMON_PATH)
298 /* Rdms for Swin Idle... */
299 case IOCTL_BCM_REGISTER_READ_PRIVATE:
300 Status = bcm_char_ioctl_reg_read_private(argp, Adapter);
303 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
304 Status = bcm_char_ioctl_reg_write_private(argp, Adapter);
307 case IOCTL_BCM_REGISTER_READ:
308 case IOCTL_BCM_EEPROM_REGISTER_READ: {
309 struct bcm_rdm_buffer sRdmBuffer = {0};
310 PCHAR temp_buff = NULL;
312 if ((Adapter->IdleMode == TRUE) ||
313 (Adapter->bShutStatus == TRUE) ||
314 (Adapter->bPreparingForLowPowerMode == TRUE)) {
316 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
317 "Device in Idle Mode, Blocking Rdms\n");
321 /* Copy Ioctl Buffer structure */
322 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
325 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
328 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
331 if (IoBuffer.OutputLength > USHRT_MAX ||
332 IoBuffer.OutputLength == 0) {
336 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
338 return STATUS_FAILURE;
340 if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
341 ((ULONG)sRdmBuffer.Register & 0x3)) {
343 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
344 "RDM Done On invalid Address : %x Access Denied.\n",
345 (int)sRdmBuffer.Register);
351 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
352 bytes = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
353 (PUINT)temp_buff, IoBuffer.OutputLength);
356 Status = STATUS_SUCCESS;
357 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
368 case IOCTL_BCM_REGISTER_WRITE:
369 case IOCTL_BCM_EEPROM_REGISTER_WRITE: {
370 struct bcm_wrm_buffer sWrmBuffer = {0};
373 if ((Adapter->IdleMode == TRUE) ||
374 (Adapter->bShutStatus == TRUE) ||
375 (Adapter->bPreparingForLowPowerMode == TRUE)) {
377 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
378 "Device in Idle Mode, Blocking Wrms\n");
382 /* Copy Ioctl Buffer structure */
383 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
386 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
389 /* Get WrmBuffer structure */
390 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
393 if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
394 ((ULONG)sWrmBuffer.Register & 0x3)) {
396 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
397 "WRM Done On invalid Address : %x Access Denied.\n",
398 (int)sWrmBuffer.Register);
402 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
403 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
404 ((uiTempVar == EEPROM_REJECT_REG_1) ||
405 (uiTempVar == EEPROM_REJECT_REG_2) ||
406 (uiTempVar == EEPROM_REJECT_REG_3) ||
407 (uiTempVar == EEPROM_REJECT_REG_4)) &&
408 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
410 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
411 "EEPROM Access Denied, not in VSG Mode\n");
415 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
416 (PUINT)sWrmBuffer.Data,
419 if (Status == STATUS_SUCCESS) {
420 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG,
421 DBG_LVL_ALL, "WRM Done\n");
423 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
424 DBG_LVL_ALL, "WRM Failed\n");
429 case IOCTL_BCM_GPIO_SET_REQUEST: {
430 UCHAR ucResetValue[4];
433 UINT uiOperation = 0;
434 struct bcm_gpio_info gpio_info = {0};
436 if ((Adapter->IdleMode == TRUE) ||
437 (Adapter->bShutStatus == TRUE) ||
438 (Adapter->bPreparingForLowPowerMode == TRUE)) {
440 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
442 "GPIO Can't be set/clear in Low power Mode");
446 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
449 if (IoBuffer.InputLength > sizeof(gpio_info))
452 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
455 uiBit = gpio_info.uiGpioNumber;
456 uiOperation = gpio_info.uiGpioValue;
459 if (IsReqGpioIsLedInNVM(Adapter, value) == false) {
460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
462 "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",
468 /* Set - setting 1 */
470 /* Set the gpio output register */
471 Status = wrmaltWithLock(Adapter,
472 BCM_GPIO_OUTPUT_SET_REG,
473 (PUINT)(&value), sizeof(UINT));
475 if (Status == STATUS_SUCCESS) {
476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
477 OSAL_DBG, DBG_LVL_ALL,
478 "Set the GPIO bit\n");
480 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
481 OSAL_DBG, DBG_LVL_ALL,
482 "Failed to set the %dth GPIO\n",
487 /* Set the gpio output register */
488 Status = wrmaltWithLock(Adapter,
489 BCM_GPIO_OUTPUT_CLR_REG,
490 (PUINT)(&value), sizeof(UINT));
492 if (Status == STATUS_SUCCESS) {
493 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
494 OSAL_DBG, DBG_LVL_ALL,
495 "Set the GPIO bit\n");
497 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
498 OSAL_DBG, DBG_LVL_ALL,
499 "Failed to clear the %dth GPIO\n",
505 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
506 (PUINT)ucResetValue, sizeof(UINT));
509 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
510 "GPIO_MODE_REGISTER read failed");
513 Status = STATUS_SUCCESS;
516 /* Set the gpio mode register to output */
517 *(UINT *)ucResetValue |= (1<<uiBit);
518 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
519 (PUINT)ucResetValue, sizeof(UINT));
521 if (Status == STATUS_SUCCESS) {
522 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
524 "Set the GPIO to output Mode\n");
526 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
528 "Failed to put GPIO in Output Mode\n");
534 case BCM_LED_THREAD_STATE_CHANGE_REQ: {
535 struct bcm_user_thread_req threadReq = {0};
536 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
537 "User made LED thread InActive");
539 if ((Adapter->IdleMode == TRUE) ||
540 (Adapter->bShutStatus == TRUE) ||
541 (Adapter->bPreparingForLowPowerMode == TRUE)) {
543 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
545 "GPIO Can't be set/clear in Low power Mode");
550 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
553 if (IoBuffer.InputLength > sizeof(threadReq))
556 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
559 /* if LED thread is running(Actively or Inactively) set it state to make inactive */
560 if (Adapter->LEDInfo.led_thread_running) {
561 if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
562 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
563 OSAL_DBG, DBG_LVL_ALL,
564 "Activating thread req");
565 Adapter->DriverState = LED_THREAD_ACTIVE;
567 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
568 OSAL_DBG, DBG_LVL_ALL,
569 "DeActivating Thread req.....");
570 Adapter->DriverState = LED_THREAD_INACTIVE;
574 wake_up(&Adapter->LEDInfo.notify_led_event);
579 case IOCTL_BCM_GPIO_STATUS_REQUEST: {
582 struct bcm_gpio_info gpio_info = {0};
584 if ((Adapter->IdleMode == TRUE) ||
585 (Adapter->bShutStatus == TRUE) ||
586 (Adapter->bPreparingForLowPowerMode == TRUE))
589 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
592 if (IoBuffer.InputLength > sizeof(gpio_info))
595 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
598 uiBit = gpio_info.uiGpioNumber;
600 /* Set the gpio output register */
601 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
602 (PUINT)ucRead, sizeof(UINT));
606 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
610 Status = STATUS_SUCCESS;
615 case IOCTL_BCM_GPIO_MULTI_REQUEST: {
616 UCHAR ucResetValue[4];
617 struct bcm_gpio_multi_info gpio_multi_info[MAX_IDX];
618 struct bcm_gpio_multi_info *pgpio_multi_info = (struct bcm_gpio_multi_info *)gpio_multi_info;
620 memset(pgpio_multi_info, 0, MAX_IDX * sizeof(struct bcm_gpio_multi_info));
622 if ((Adapter->IdleMode == TRUE) ||
623 (Adapter->bShutStatus == TRUE) ||
624 (Adapter->bPreparingForLowPowerMode == TRUE))
627 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
630 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
633 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
636 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_info[WIMAX_IDX].uiGPIOMask) == false) {
637 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
639 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
640 pgpio_multi_info[WIMAX_IDX].uiGPIOMask,
641 Adapter->gpioBitMap);
646 /* Set the gpio output register */
647 if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
648 (pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
649 /* Set 1's in GPIO OUTPUT REGISTER */
650 *(UINT *)ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
651 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
652 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
654 if (*(UINT *) ucResetValue)
655 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG,
656 (PUINT)ucResetValue, sizeof(ULONG));
658 if (Status != STATUS_SUCCESS) {
659 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
660 "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
664 /* Clear to 0's in GPIO OUTPUT REGISTER */
665 *(UINT *)ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
666 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
667 (~(pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
669 if (*(UINT *) ucResetValue)
670 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)ucResetValue, sizeof(ULONG));
672 if (Status != STATUS_SUCCESS) {
673 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
674 "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
679 if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
680 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
684 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
685 "RDM to GPIO_PIN_STATE_REGISTER Failed.");
688 Status = STATUS_SUCCESS;
691 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = (*(UINT *)ucResetValue &
692 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
695 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
697 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
698 "Failed while copying Content to IOBufer for user space err:%d", Status);
704 case IOCTL_BCM_GPIO_MODE_REQUEST: {
705 UCHAR ucResetValue[4];
706 struct bcm_gpio_multi_mode gpio_multi_mode[MAX_IDX];
707 struct bcm_gpio_multi_mode *pgpio_multi_mode = (struct bcm_gpio_multi_mode *)gpio_multi_mode;
709 if ((Adapter->IdleMode == TRUE) ||
710 (Adapter->bShutStatus == TRUE) ||
711 (Adapter->bPreparingForLowPowerMode == TRUE))
714 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
717 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
720 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
723 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read of GPIO_MODE_REGISTER failed");
730 Status = STATUS_SUCCESS;
733 /* Validating the request */
734 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) == false) {
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
736 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
737 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
742 if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
743 /* write all OUT's (1's) */
744 *(UINT *) ucResetValue |= (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
745 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
747 /* write all IN's (0's) */
748 *(UINT *) ucResetValue &= ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
749 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
751 /* Currently implemented return the modes of all GPIO's
752 * else needs to bit AND with mask
754 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
756 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(ULONG));
757 if (Status == STATUS_SUCCESS) {
758 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
759 "WRM to GPIO_MODE_REGISTER Done");
761 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
762 "WRM to GPIO_MODE_REGISTER Failed");
767 /* if uiGPIOMask is 0 then return mode register configuration */
768 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
771 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
773 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
774 "Failed while copying Content to IOBufer for user space err:%d", Status);
780 case IOCTL_MAC_ADDR_REQ:
782 case IOCTL_CM_REQUEST:
783 case IOCTL_SS_INFO_REQ:
784 case IOCTL_SEND_CONTROL_MESSAGE:
785 case IOCTL_IDLE_REQ: {
786 PVOID pvBuffer = NULL;
788 /* Copy Ioctl Buffer structure */
789 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
792 if (IoBuffer.InputLength < sizeof(struct bcm_link_request))
795 if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
798 pvBuffer = memdup_user(IoBuffer.InputBuffer,
799 IoBuffer.InputLength);
800 if (IS_ERR(pvBuffer))
801 return PTR_ERR(pvBuffer);
803 down(&Adapter->LowPowerModeSync);
804 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
805 !Adapter->bPreparingForLowPowerMode,
807 if (Status == -ERESTARTSYS)
810 if (Adapter->bPreparingForLowPowerMode) {
811 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
812 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
813 Status = STATUS_FAILURE;
816 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
819 up(&Adapter->LowPowerModeSync);
824 case IOCTL_BCM_BUFFER_DOWNLOAD_START: {
825 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
826 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
827 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
831 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
832 "Starting the firmware download PID =0x%x!!!!\n", current->pid);
834 if (down_trylock(&Adapter->fw_download_sema))
837 Adapter->bBinDownloaded = false;
838 Adapter->fw_download_process_pid = current->pid;
839 Adapter->bCfgDownloaded = false;
840 Adapter->fw_download_done = false;
841 netif_carrier_off(Adapter->dev);
842 netif_stop_queue(Adapter->dev);
843 Status = reset_card_proc(Adapter);
845 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
846 up(&Adapter->fw_download_sema);
847 up(&Adapter->NVMRdmWrmLock);
852 up(&Adapter->NVMRdmWrmLock);
856 case IOCTL_BCM_BUFFER_DOWNLOAD: {
857 struct bcm_firmware_info *psFwInfo = NULL;
858 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
860 if (!down_trylock(&Adapter->fw_download_sema)) {
861 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
862 "Invalid way to download buffer. Use Start and then call this!!!\n");
863 up(&Adapter->fw_download_sema);
868 /* Copy Ioctl Buffer structure */
869 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
870 up(&Adapter->fw_download_sema);
874 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
875 "Length for FW DLD is : %lx\n", IoBuffer.InputLength);
877 if (IoBuffer.InputLength > sizeof(struct bcm_firmware_info)) {
878 up(&Adapter->fw_download_sema);
882 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
884 up(&Adapter->fw_download_sema);
888 if (copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
889 up(&Adapter->fw_download_sema);
894 if (!psFwInfo->pvMappedFirmwareAddress ||
895 (psFwInfo->u32FirmwareLength == 0)) {
897 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
898 psFwInfo->u32FirmwareLength);
899 up(&Adapter->fw_download_sema);
905 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
907 if (Status != STATUS_SUCCESS) {
908 if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR)
909 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
911 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
913 /* up(&Adapter->fw_download_sema); */
915 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
916 Adapter->DriverState = DRIVER_INIT;
917 Adapter->LEDInfo.bLedInitDone = false;
918 wake_up(&Adapter->LEDInfo.notify_led_event);
922 if (Status != STATUS_SUCCESS)
923 up(&Adapter->fw_download_sema);
925 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
930 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP: {
931 if (!down_trylock(&Adapter->fw_download_sema)) {
932 up(&Adapter->fw_download_sema);
936 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
937 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
938 "FW download blocked as EEPROM Read/Write is in progress\n");
939 up(&Adapter->fw_download_sema);
943 Adapter->bBinDownloaded = TRUE;
944 Adapter->bCfgDownloaded = TRUE;
945 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
946 Adapter->CurrNumRecvDescs = 0;
947 Adapter->downloadDDR = 0;
949 /* setting the Mips to Run */
950 Status = run_card_proc(Adapter);
953 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
954 up(&Adapter->fw_download_sema);
955 up(&Adapter->NVMRdmWrmLock);
958 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
959 DBG_LVL_ALL, "Firm Download Over...\n");
964 /* Wait for MailBox Interrupt */
965 if (StartInterruptUrb((struct bcm_interface_adapter *)Adapter->pvInterfaceAdapter))
966 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
969 Adapter->waiting_to_fw_download_done = false;
970 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
971 Adapter->waiting_to_fw_download_done, timeout);
972 Adapter->fw_download_process_pid = INVALID_PID;
973 Adapter->fw_download_done = TRUE;
974 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
975 Adapter->CurrNumRecvDescs = 0;
976 Adapter->PrevNumRecvDescs = 0;
977 atomic_set(&Adapter->cntrlpktCnt, 0);
978 Adapter->LinkUpStatus = 0;
979 Adapter->LinkStatus = 0;
981 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
982 Adapter->DriverState = FW_DOWNLOAD_DONE;
983 wake_up(&Adapter->LEDInfo.notify_led_event);
989 up(&Adapter->fw_download_sema);
990 up(&Adapter->NVMRdmWrmLock);
994 case IOCTL_BE_BUCKET_SIZE:
996 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
1000 case IOCTL_RTPS_BUCKET_SIZE:
1002 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
1006 case IOCTL_CHIP_RESET: {
1007 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1009 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
1013 down(&Adapter->RxAppControlQueuelock);
1014 Status = reset_card_proc(Adapter);
1016 up(&Adapter->RxAppControlQueuelock);
1017 up(&Adapter->NVMRdmWrmLock);
1018 ResetCounters(Adapter);
1022 case IOCTL_QOS_THRESHOLD: {
1026 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
1027 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
1028 (unsigned long __user *)arg)) {
1036 case IOCTL_DUMP_PACKET_INFO:
1037 DumpPackInfo(Adapter);
1038 DumpPhsRules(&Adapter->stBCMPhsContext);
1039 Status = STATUS_SUCCESS;
1042 case IOCTL_GET_PACK_INFO:
1043 if (copy_to_user(argp, &Adapter->PackInfo, sizeof(struct bcm_packet_info)*NO_OF_QUEUES))
1045 Status = STATUS_SUCCESS;
1048 case IOCTL_BCM_SWITCH_TRANSFER_MODE: {
1050 if (copy_from_user(&uiData, argp, sizeof(UINT)))
1054 /* Allow All Packets */
1055 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
1056 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
1058 /* Allow IP only Packets */
1059 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
1060 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
1062 Status = STATUS_SUCCESS;
1066 case IOCTL_BCM_GET_DRIVER_VERSION: {
1069 /* Copy Ioctl Buffer structure */
1070 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1073 len = min_t(ulong, IoBuffer.OutputLength, strlen(DRV_VERSION) + 1);
1075 if (copy_to_user(IoBuffer.OutputBuffer, DRV_VERSION, len))
1077 Status = STATUS_SUCCESS;
1081 case IOCTL_BCM_GET_CURRENT_STATUS: {
1082 struct bcm_link_state link_state;
1084 /* Copy Ioctl Buffer structure */
1085 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
1086 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
1090 if (IoBuffer.OutputLength != sizeof(link_state)) {
1095 memset(&link_state, 0, sizeof(link_state));
1096 link_state.bIdleMode = Adapter->IdleMode;
1097 link_state.bShutdownMode = Adapter->bShutStatus;
1098 link_state.ucLinkStatus = Adapter->LinkStatus;
1100 if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) {
1101 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1104 Status = STATUS_SUCCESS;
1108 case IOCTL_BCM_SET_MAC_TRACING: {
1111 /* copy ioctl Buffer structure */
1112 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1115 if (copy_from_user(&tracing_flag, IoBuffer.InputBuffer, sizeof(UINT)))
1119 Adapter->pTarangs->MacTracingEnabled = TRUE;
1121 Adapter->pTarangs->MacTracingEnabled = false;
1125 case IOCTL_BCM_GET_DSX_INDICATION: {
1127 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1130 if (IoBuffer.OutputLength < sizeof(struct bcm_add_indication_alt)) {
1131 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1132 "Mismatch req: %lx needed is =0x%zx!!!",
1133 IoBuffer.OutputLength, sizeof(struct bcm_add_indication_alt));
1137 if (copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1140 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId);
1141 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1142 Status = STATUS_SUCCESS;
1146 case IOCTL_BCM_GET_HOST_MIBS: {
1149 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1152 if (IoBuffer.OutputLength != sizeof(struct bcm_host_stats_mibs)) {
1153 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1154 "Length Check failed %lu %zd\n",
1155 IoBuffer.OutputLength, sizeof(struct bcm_host_stats_mibs));
1159 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1160 temp_buff = kzalloc(sizeof(struct bcm_host_stats_mibs), GFP_KERNEL);
1162 return STATUS_FAILURE;
1164 Status = ProcessGetHostMibs(Adapter, temp_buff);
1165 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1167 if (Status != STATUS_FAILURE)
1168 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(struct bcm_host_stats_mibs))) {
1177 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1178 if ((false == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE == Adapter->IdleMode)) {
1179 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1180 Adapter->bWakeUpDevice = TRUE;
1181 wake_up(&Adapter->process_rx_cntrlpkt);
1184 Status = STATUS_SUCCESS;
1187 case IOCTL_BCM_BULK_WRM: {
1188 struct bcm_bulk_wrm_buffer *pBulkBuffer;
1190 PCHAR pvBuffer = NULL;
1192 if ((Adapter->IdleMode == TRUE) ||
1193 (Adapter->bShutStatus == TRUE) ||
1194 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1196 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1201 /* Copy Ioctl Buffer structure */
1202 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1205 if (IoBuffer.InputLength < sizeof(ULONG) * 2)
1208 pvBuffer = memdup_user(IoBuffer.InputBuffer,
1209 IoBuffer.InputLength);
1210 if (IS_ERR(pvBuffer))
1211 return PTR_ERR(pvBuffer);
1213 pBulkBuffer = (struct bcm_bulk_wrm_buffer *)pvBuffer;
1215 if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1216 ((ULONG)pBulkBuffer->Register & 0x3)) {
1217 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer->Register);
1223 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1224 if (!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE) &&
1225 ((uiTempVar == EEPROM_REJECT_REG_1) ||
1226 (uiTempVar == EEPROM_REJECT_REG_2) ||
1227 (uiTempVar == EEPROM_REJECT_REG_3) ||
1228 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1229 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
1232 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
1237 if (pBulkBuffer->SwapEndian == false)
1238 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1240 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1242 if (Status != STATUS_SUCCESS)
1243 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1249 case IOCTL_BCM_GET_NVM_SIZE:
1250 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1253 if (Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH) {
1254 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1258 Status = STATUS_SUCCESS;
1261 case IOCTL_BCM_CAL_INIT: {
1262 UINT uiSectorSize = 0;
1263 if (Adapter->eNVMType == NVM_FLASH) {
1264 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1267 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1270 if ((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) {
1271 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1275 if (IsFlash2x(Adapter)) {
1276 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize, sizeof(UINT)))
1279 if ((TRUE == Adapter->bShutStatus) || (TRUE == Adapter->IdleMode)) {
1280 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is in Idle/Shutdown Mode\n");
1284 Adapter->uiSectorSize = uiSectorSize;
1285 BcmUpdateSectorSize(Adapter, Adapter->uiSectorSize);
1288 Status = STATUS_SUCCESS;
1290 Status = STATUS_FAILURE;
1295 case IOCTL_BCM_SET_DEBUG:
1298 struct bcm_user_debug_state sUserDebugState;
1300 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1301 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1304 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(struct bcm_user_debug_state)))
1307 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1308 sUserDebugState.OnOff, sUserDebugState.Type);
1309 /* sUserDebugState.Subtype <<= 1; */
1310 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1311 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1313 /* Update new 'DebugState' in the Adapter */
1314 Adapter->stDebugState.type |= sUserDebugState.Type;
1315 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1316 * Valid indexes in 'subtype' array: 1,2,4,8
1317 * corresponding to valid Type values. Hence we can use the 'Type' field
1318 * as the index value, ignoring the array entries 0,3,5,6,7 !
1320 if (sUserDebugState.OnOff)
1321 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1323 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1325 BCM_SHOW_DEBUG_BITMAP(Adapter);
1330 case IOCTL_BCM_NVM_READ:
1331 case IOCTL_BCM_NVM_WRITE: {
1332 struct bcm_nvm_readwrite stNVMReadWrite;
1333 PUCHAR pReadData = NULL;
1334 ULONG ulDSDMagicNumInUsrBuff = 0;
1335 struct timeval tv0, tv1;
1336 memset(&tv0, 0, sizeof(struct timeval));
1337 memset(&tv1, 0, sizeof(struct timeval));
1338 if ((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0)) {
1339 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1343 if (IsFlash2x(Adapter)) {
1344 if ((Adapter->eActiveDSD != DSD0) &&
1345 (Adapter->eActiveDSD != DSD1) &&
1346 (Adapter->eActiveDSD != DSD2)) {
1348 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No DSD is active..hence NVM Command is blocked");
1349 return STATUS_FAILURE;
1353 /* Copy Ioctl Buffer structure */
1354 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1357 if (copy_from_user(&stNVMReadWrite,
1358 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1359 sizeof(struct bcm_nvm_readwrite)))
1363 * Deny the access if the offset crosses the cal area limit.
1365 if (stNVMReadWrite.uiNumBytes > Adapter->uiNVMDSDSize)
1366 return STATUS_FAILURE;
1368 if (stNVMReadWrite.uiOffset > Adapter->uiNVMDSDSize - stNVMReadWrite.uiNumBytes) {
1369 /* 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); */
1370 return STATUS_FAILURE;
1373 pReadData = memdup_user(stNVMReadWrite.pBuffer,
1374 stNVMReadWrite.uiNumBytes);
1375 if (IS_ERR(pReadData))
1376 return PTR_ERR(pReadData);
1378 do_gettimeofday(&tv0);
1379 if (IOCTL_BCM_NVM_READ == cmd) {
1380 down(&Adapter->NVMRdmWrmLock);
1382 if ((Adapter->IdleMode == TRUE) ||
1383 (Adapter->bShutStatus == TRUE) ||
1384 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1387 up(&Adapter->NVMRdmWrmLock);
1392 Status = BeceemNVMRead(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1393 up(&Adapter->NVMRdmWrmLock);
1395 if (Status != STATUS_SUCCESS) {
1400 if (copy_to_user(stNVMReadWrite.pBuffer, pReadData, stNVMReadWrite.uiNumBytes)) {
1405 down(&Adapter->NVMRdmWrmLock);
1407 if ((Adapter->IdleMode == TRUE) ||
1408 (Adapter->bShutStatus == TRUE) ||
1409 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1411 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1412 up(&Adapter->NVMRdmWrmLock);
1417 Adapter->bHeaderChangeAllowed = TRUE;
1418 if (IsFlash2x(Adapter)) {
1421 * DSD section updation will be allowed in two case:-
1422 * 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1423 * 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1424 * corrupted then user space program first modify the DSD header with valid DSD sig so
1425 * that this as well as further write may be worthwhile.
1427 * This restriction has been put assuming that if DSD sig is corrupted, DSD
1428 * data won't be considered valid.
1431 Status = BcmFlash2xCorruptSig(Adapter, Adapter->eActiveDSD);
1432 if (Status != STATUS_SUCCESS) {
1433 if (((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize) ||
1434 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE)) {
1436 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1437 up(&Adapter->NVMRdmWrmLock);
1442 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1443 if (ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER) {
1444 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1445 up(&Adapter->NVMRdmWrmLock);
1452 Status = BeceemNVMWrite(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1453 if (IsFlash2x(Adapter))
1454 BcmFlash2xWriteSig(Adapter, Adapter->eActiveDSD);
1456 Adapter->bHeaderChangeAllowed = false;
1458 up(&Adapter->NVMRdmWrmLock);
1460 if (Status != STATUS_SUCCESS) {
1466 do_gettimeofday(&tv1);
1467 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);
1470 return STATUS_SUCCESS;
1473 case IOCTL_BCM_FLASH2X_SECTION_READ: {
1474 struct bcm_flash2x_readwrite sFlash2xRead = {0};
1475 PUCHAR pReadBuff = NULL;
1479 UINT ReadOffset = 0;
1480 void __user *OutPutBuff;
1482 if (IsFlash2x(Adapter) != TRUE) {
1483 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1487 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1488 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1491 /* Reading FLASH 2.x READ structure */
1492 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
1495 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xRead.Section);
1496 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%x", sFlash2xRead.offset);
1497 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xRead.numOfBytes);
1498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xRead.bVerify);
1500 /* This was internal to driver for raw read. now it has ben exposed to user space app. */
1501 if (validateFlash2xReadWrite(Adapter, &sFlash2xRead) == false)
1502 return STATUS_FAILURE;
1504 NOB = sFlash2xRead.numOfBytes;
1505 if (NOB > Adapter->uiSectorSize)
1506 BuffSize = Adapter->uiSectorSize;
1510 ReadOffset = sFlash2xRead.offset;
1511 OutPutBuff = IoBuffer.OutputBuffer;
1512 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1514 if (pReadBuff == NULL) {
1515 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1518 down(&Adapter->NVMRdmWrmLock);
1520 if ((Adapter->IdleMode == TRUE) ||
1521 (Adapter->bShutStatus == TRUE) ||
1522 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1524 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1525 up(&Adapter->NVMRdmWrmLock);
1531 if (NOB > Adapter->uiSectorSize)
1532 ReadBytes = Adapter->uiSectorSize;
1536 /* Reading the data from Flash 2.x */
1537 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pReadBuff, sFlash2xRead.Section, ReadOffset, ReadBytes);
1539 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Flash 2x read err with Status :%d", Status);
1543 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1545 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1547 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status);
1548 up(&Adapter->NVMRdmWrmLock);
1552 NOB = NOB - ReadBytes;
1554 ReadOffset = ReadOffset + ReadBytes;
1555 OutPutBuff = OutPutBuff + ReadBytes;
1559 up(&Adapter->NVMRdmWrmLock);
1564 case IOCTL_BCM_FLASH2X_SECTION_WRITE: {
1565 struct bcm_flash2x_readwrite sFlash2xWrite = {0};
1567 void __user *InputAddr;
1570 UINT WriteOffset = 0;
1571 UINT WriteBytes = 0;
1573 if (IsFlash2x(Adapter) != TRUE) {
1574 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1578 /* First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite */
1579 Adapter->bAllDSDWriteAllow = false;
1581 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1583 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1586 /* Reading FLASH 2.x READ structure */
1587 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
1590 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xWrite.Section);
1591 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%d", sFlash2xWrite.offset);
1592 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite.numOfBytes);
1593 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite.bVerify);
1595 if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) && (sFlash2xWrite.Section != VSA2)) {
1596 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Only VSA write is allowed");
1600 if (validateFlash2xReadWrite(Adapter, &sFlash2xWrite) == false)
1601 return STATUS_FAILURE;
1603 InputAddr = sFlash2xWrite.pDataBuff;
1604 WriteOffset = sFlash2xWrite.offset;
1605 NOB = sFlash2xWrite.numOfBytes;
1607 if (NOB > Adapter->uiSectorSize)
1608 BuffSize = Adapter->uiSectorSize;
1612 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1614 if (pWriteBuff == NULL)
1617 /* extracting the remainder of the given offset. */
1618 WriteBytes = Adapter->uiSectorSize;
1619 if (WriteOffset % Adapter->uiSectorSize)
1620 WriteBytes = Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1622 if (NOB < WriteBytes)
1625 down(&Adapter->NVMRdmWrmLock);
1627 if ((Adapter->IdleMode == TRUE) ||
1628 (Adapter->bShutStatus == TRUE) ||
1629 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1632 up(&Adapter->NVMRdmWrmLock);
1637 BcmFlash2xCorruptSig(Adapter, sFlash2xWrite.Section);
1639 Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
1641 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status);
1642 up(&Adapter->NVMRdmWrmLock);
1646 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
1648 /* Writing the data from Flash 2.x */
1649 Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pWriteBuff, sFlash2xWrite.Section, WriteOffset, WriteBytes, sFlash2xWrite.bVerify);
1652 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1656 NOB = NOB - WriteBytes;
1658 WriteOffset = WriteOffset + WriteBytes;
1659 InputAddr = InputAddr + WriteBytes;
1660 if (NOB > Adapter->uiSectorSize)
1661 WriteBytes = Adapter->uiSectorSize;
1667 BcmFlash2xWriteSig(Adapter, sFlash2xWrite.Section);
1668 up(&Adapter->NVMRdmWrmLock);
1673 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP: {
1674 struct bcm_flash2x_bitmap *psFlash2xBitMap;
1675 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1677 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1680 if (IoBuffer.OutputLength != sizeof(struct bcm_flash2x_bitmap))
1683 psFlash2xBitMap = kzalloc(sizeof(struct bcm_flash2x_bitmap), GFP_KERNEL);
1684 if (psFlash2xBitMap == NULL) {
1685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory is not available");
1689 /* Reading the Flash Sectio Bit map */
1690 down(&Adapter->NVMRdmWrmLock);
1692 if ((Adapter->IdleMode == TRUE) ||
1693 (Adapter->bShutStatus == TRUE) ||
1694 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1696 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1697 up(&Adapter->NVMRdmWrmLock);
1698 kfree(psFlash2xBitMap);
1702 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1703 up(&Adapter->NVMRdmWrmLock);
1704 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(struct bcm_flash2x_bitmap))) {
1705 kfree(psFlash2xBitMap);
1709 kfree(psFlash2xBitMap);
1713 case IOCTL_BCM_SET_ACTIVE_SECTION: {
1714 enum bcm_flash2x_section_val eFlash2xSectionVal = 0;
1715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1717 if (IsFlash2x(Adapter) != TRUE) {
1718 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1722 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1728 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1734 down(&Adapter->NVMRdmWrmLock);
1736 if ((Adapter->IdleMode == TRUE) ||
1737 (Adapter->bShutStatus == TRUE) ||
1738 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1741 up(&Adapter->NVMRdmWrmLock);
1745 Status = BcmSetActiveSection(Adapter, eFlash2xSectionVal);
1747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Failed to make it's priority Highest. Status %d", Status);
1749 up(&Adapter->NVMRdmWrmLock);
1753 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION: {
1754 /* Right Now we are taking care of only DSD */
1755 Adapter->bAllDSDWriteAllow = false;
1756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1757 Status = STATUS_SUCCESS;
1761 case IOCTL_BCM_COPY_SECTION: {
1762 struct bcm_flash2x_copy_section sCopySectStrut = {0};
1763 Status = STATUS_SUCCESS;
1764 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1766 Adapter->bAllDSDWriteAllow = false;
1767 if (IsFlash2x(Adapter) != TRUE) {
1768 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1772 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1774 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1778 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_copy_section));
1780 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1784 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1785 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1786 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1787 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1789 if (IsSectionExistInFlash(Adapter, sCopySectStrut.SrcSection) == false) {
1790 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source Section<%x> does not exist in Flash ", sCopySectStrut.SrcSection);
1794 if (IsSectionExistInFlash(Adapter, sCopySectStrut.DstSection) == false) {
1795 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Destinatio Section<%x> does not exist in Flash ", sCopySectStrut.DstSection);
1799 if (sCopySectStrut.SrcSection == sCopySectStrut.DstSection) {
1800 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source and Destination section should be different");
1804 down(&Adapter->NVMRdmWrmLock);
1806 if ((Adapter->IdleMode == TRUE) ||
1807 (Adapter->bShutStatus == TRUE) ||
1808 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1810 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1811 up(&Adapter->NVMRdmWrmLock);
1815 if (sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2) {
1816 if (IsNonCDLessDevice(Adapter)) {
1817 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is Non-CDLess hence won't have ISO !!");
1819 } else if (sCopySectStrut.numOfBytes == 0) {
1820 Status = BcmCopyISO(Adapter, sCopySectStrut);
1822 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Partial Copy of ISO section is not Allowed..");
1823 Status = STATUS_FAILURE;
1825 up(&Adapter->NVMRdmWrmLock);
1829 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
1830 sCopySectStrut.DstSection, sCopySectStrut.offset, sCopySectStrut.numOfBytes);
1831 up(&Adapter->NVMRdmWrmLock);
1835 case IOCTL_BCM_GET_FLASH_CS_INFO: {
1836 Status = STATUS_SUCCESS;
1837 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1839 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1841 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1845 if (Adapter->eNVMType != NVM_FLASH) {
1846 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Connected device does not have flash");
1851 if (IsFlash2x(Adapter) == TRUE) {
1852 if (IoBuffer.OutputLength < sizeof(struct bcm_flash2x_cs_info))
1855 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(struct bcm_flash2x_cs_info)))
1858 if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info))
1861 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash_cs_info)))
1867 case IOCTL_BCM_SELECT_DSD: {
1869 enum bcm_flash2x_section_val eFlash2xSectionVal;
1870 eFlash2xSectionVal = NO_SECTION_VAL;
1871 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SELECT_DSD Called");
1873 if (IsFlash2x(Adapter) != TRUE) {
1874 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1878 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1880 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1883 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1885 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1889 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal);
1890 if ((eFlash2xSectionVal != DSD0) &&
1891 (eFlash2xSectionVal != DSD1) &&
1892 (eFlash2xSectionVal != DSD2)) {
1894 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Passed section<%x> is not DSD section", eFlash2xSectionVal);
1895 return STATUS_FAILURE;
1898 SectOfset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
1899 if (SectOfset == INVALID_OFFSET) {
1900 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Provided Section val <%d> does not exist in Flash 2.x", eFlash2xSectionVal);
1904 Adapter->bAllDSDWriteAllow = TRUE;
1905 Adapter->ulFlashCalStart = SectOfset;
1906 Adapter->eActiveDSD = eFlash2xSectionVal;
1908 Status = STATUS_SUCCESS;
1911 case IOCTL_BCM_NVM_RAW_READ: {
1912 struct bcm_nvm_readwrite stNVMRead;
1918 void __user *OutPutBuff;
1920 if (Adapter->eNVMType != NVM_FLASH) {
1921 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "NVM TYPE is not Flash");
1925 /* Copy Ioctl Buffer structure */
1926 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
1927 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
1931 if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(struct bcm_nvm_readwrite)))
1934 NOB = stNVMRead.uiNumBytes;
1935 /* In Raw-Read max Buff size : 64MB */
1937 if (NOB > DEFAULT_BUFF_SIZE)
1938 BuffSize = DEFAULT_BUFF_SIZE;
1942 ReadOffset = stNVMRead.uiOffset;
1943 OutPutBuff = stNVMRead.pBuffer;
1945 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
1946 if (pReadBuff == NULL) {
1947 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1951 down(&Adapter->NVMRdmWrmLock);
1953 if ((Adapter->IdleMode == TRUE) ||
1954 (Adapter->bShutStatus == TRUE) ||
1955 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1957 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1959 up(&Adapter->NVMRdmWrmLock);
1963 Adapter->bFlashRawRead = TRUE;
1966 if (NOB > DEFAULT_BUFF_SIZE)
1967 ReadBytes = DEFAULT_BUFF_SIZE;
1971 /* Reading the data from Flash 2.x */
1972 Status = BeceemNVMRead(Adapter, (PUINT)pReadBuff, ReadOffset, ReadBytes);
1974 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1978 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1980 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1982 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status);
1983 up(&Adapter->NVMRdmWrmLock);
1987 NOB = NOB - ReadBytes;
1989 ReadOffset = ReadOffset + ReadBytes;
1990 OutPutBuff = OutPutBuff + ReadBytes;
1993 Adapter->bFlashRawRead = false;
1994 up(&Adapter->NVMRdmWrmLock);
1999 case IOCTL_BCM_CNTRLMSG_MASK: {
2000 ULONG RxCntrlMsgBitMask = 0;
2002 /* Copy Ioctl Buffer structure */
2003 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
2005 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space");
2009 if (IoBuffer.InputLength != sizeof(unsigned long)) {
2014 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
2016 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space");
2019 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
2020 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;
2024 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO: {
2025 struct bcm_driver_info DevInfo;
2027 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2029 memset(&DevInfo, 0, sizeof(DevInfo));
2030 DevInfo.MaxRDMBufferSize = BUFFER_4K;
2031 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
2032 DevInfo.u32RxAlignmentCorrection = 0;
2033 DevInfo.u32NVMType = Adapter->eNVMType;
2034 DevInfo.u32InterfaceType = BCM_USB;
2036 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
2039 if (IoBuffer.OutputLength < sizeof(DevInfo))
2042 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
2047 case IOCTL_BCM_TIME_SINCE_NET_ENTRY: {
2048 struct bcm_time_elapsed stTimeElapsedSinceNetEntry = {0};
2050 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2052 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
2055 if (IoBuffer.OutputLength < sizeof(struct bcm_time_elapsed))
2058 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
2060 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(struct bcm_time_elapsed)))
2065 case IOCTL_CLOSE_NOTIFICATION:
2066 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_CLOSE_NOTIFICATION");
2070 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2071 Status = STATUS_FAILURE;
2078 static const struct file_operations bcm_fops = {
2079 .owner = THIS_MODULE,
2080 .open = bcm_char_open,
2081 .release = bcm_char_release,
2082 .read = bcm_char_read,
2083 .unlocked_ioctl = bcm_char_ioctl,
2084 .llseek = no_llseek,
2087 int register_control_device_interface(struct bcm_mini_adapter *Adapter)
2090 if (Adapter->major > 0)
2091 return Adapter->major;
2093 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
2094 if (Adapter->major < 0) {
2095 pr_err(DRV_NAME ": could not created character device\n");
2096 return Adapter->major;
2099 Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
2100 MKDEV(Adapter->major, 0),
2103 if (IS_ERR(Adapter->pstCreatedClassDevice)) {
2104 pr_err(DRV_NAME ": class device create failed\n");
2105 unregister_chrdev(Adapter->major, DEV_NAME);
2106 return PTR_ERR(Adapter->pstCreatedClassDevice);
2112 void unregister_control_device_interface(struct bcm_mini_adapter *Adapter)
2114 if (Adapter->major > 0) {
2115 device_destroy(bcm_class, MKDEV(Adapter->major, 0));
2116 unregister_chrdev(Adapter->major, DEV_NAME);