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;
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 struct bcm_tarang_data *pTarang = filp->private_data;
101 struct bcm_mini_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 struct bcm_tarang_data *pTarang = filp->private_data;
159 void __user *argp = (void __user *)arg;
160 struct bcm_mini_adapter *Adapter = pTarang->Adapter;
161 INT Status = STATUS_FAILURE;
163 struct bcm_ioctl_buffer IoBuffer;
166 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);
168 if (_IOC_TYPE(cmd) != BCM_IOCTL)
170 if (_IOC_DIR(cmd) & _IOC_READ)
171 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
172 else if (_IOC_DIR(cmd) & _IOC_WRITE)
173 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
174 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
175 Status = STATUS_SUCCESS;
180 if (Adapter->device_removed)
183 if (FALSE == Adapter->fw_download_done) {
185 case IOCTL_MAC_ADDR_REQ:
187 case IOCTL_CM_REQUEST:
188 case IOCTL_SS_INFO_REQ:
189 case IOCTL_SEND_CONTROL_MESSAGE:
191 case IOCTL_BCM_GPIO_SET_REQUEST:
192 case IOCTL_BCM_GPIO_STATUS_REQUEST:
199 Status = vendorextnIoctl(Adapter, cmd, arg);
200 if (Status != CONTINUE_COMMON_PATH)
204 /* Rdms for Swin Idle... */
205 case IOCTL_BCM_REGISTER_READ_PRIVATE: {
206 struct bcm_rdm_buffer sRdmBuffer = {0};
211 /* Copy Ioctl Buffer structure */
212 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
215 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
218 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
221 if (IoBuffer.OutputLength > USHRT_MAX ||
222 IoBuffer.OutputLength == 0) {
226 Bufflen = IoBuffer.OutputLength;
227 temp_value = 4 - (Bufflen % 4);
228 Bufflen += temp_value % 4;
230 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
234 bytes = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
235 (PUINT)temp_buff, Bufflen);
237 Status = STATUS_SUCCESS;
238 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
250 case IOCTL_BCM_REGISTER_WRITE_PRIVATE: {
251 struct bcm_wrm_buffer sWrmBuffer = {0};
253 /* Copy Ioctl Buffer structure */
255 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
258 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
261 /* Get WrmBuffer structure */
262 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
265 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
266 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
267 ((uiTempVar == EEPROM_REJECT_REG_1) ||
268 (uiTempVar == EEPROM_REJECT_REG_2) ||
269 (uiTempVar == EEPROM_REJECT_REG_3) ||
270 (uiTempVar == EEPROM_REJECT_REG_4))) {
272 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
276 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
277 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
279 if (Status == STATUS_SUCCESS) {
280 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
282 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
288 case IOCTL_BCM_REGISTER_READ:
289 case IOCTL_BCM_EEPROM_REGISTER_READ: {
290 struct bcm_rdm_buffer sRdmBuffer = {0};
291 PCHAR temp_buff = NULL;
293 if ((Adapter->IdleMode == TRUE) ||
294 (Adapter->bShutStatus == TRUE) ||
295 (Adapter->bPreparingForLowPowerMode == TRUE)) {
297 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
301 /* Copy Ioctl Buffer structure */
302 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
305 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
308 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
311 if (IoBuffer.OutputLength > USHRT_MAX ||
312 IoBuffer.OutputLength == 0) {
316 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
318 return STATUS_FAILURE;
320 if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
321 ((ULONG)sRdmBuffer.Register & 0x3)) {
323 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
324 (int)sRdmBuffer.Register);
330 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
331 bytes = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register, (PUINT)temp_buff, IoBuffer.OutputLength);
334 Status = STATUS_SUCCESS;
335 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
346 case IOCTL_BCM_REGISTER_WRITE:
347 case IOCTL_BCM_EEPROM_REGISTER_WRITE: {
348 struct bcm_wrm_buffer sWrmBuffer = {0};
351 if ((Adapter->IdleMode == TRUE) ||
352 (Adapter->bShutStatus == TRUE) ||
353 (Adapter->bPreparingForLowPowerMode == TRUE)) {
355 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
359 /* Copy Ioctl Buffer structure */
360 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
363 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
366 /* Get WrmBuffer structure */
367 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
370 if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
371 ((ULONG)sWrmBuffer.Register & 0x3)) {
373 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)sWrmBuffer.Register);
377 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
378 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
379 ((uiTempVar == EEPROM_REJECT_REG_1) ||
380 (uiTempVar == EEPROM_REJECT_REG_2) ||
381 (uiTempVar == EEPROM_REJECT_REG_3) ||
382 (uiTempVar == EEPROM_REJECT_REG_4)) &&
383 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
385 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
389 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
390 (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
392 if (Status == STATUS_SUCCESS) {
393 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
395 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
400 case IOCTL_BCM_GPIO_SET_REQUEST: {
401 UCHAR ucResetValue[4];
404 UINT uiOperation = 0;
405 struct bcm_gpio_info gpio_info = {0};
407 if ((Adapter->IdleMode == TRUE) ||
408 (Adapter->bShutStatus == TRUE) ||
409 (Adapter->bPreparingForLowPowerMode == TRUE)) {
411 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
415 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
418 if (IoBuffer.InputLength > sizeof(gpio_info))
421 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
424 uiBit = gpio_info.uiGpioNumber;
425 uiOperation = gpio_info.uiGpioValue;
428 if (IsReqGpioIsLedInNVM(Adapter, value) == FALSE) {
429 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!", value);
434 /* Set - setting 1 */
436 /* Set the gpio output register */
437 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, (PUINT)(&value), sizeof(UINT));
439 if (Status == STATUS_SUCCESS) {
440 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
442 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to set the %dth GPIO\n", uiBit);
446 /* Set the gpio output register */
447 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)(&value), sizeof(UINT));
449 if (Status == STATUS_SUCCESS) {
450 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
452 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to clear the %dth GPIO\n", uiBit);
457 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
461 "GPIO_MODE_REGISTER read failed");
464 Status = STATUS_SUCCESS;
467 /* Set the gpio mode register to output */
468 *(UINT *)ucResetValue |= (1<<uiBit);
469 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
470 (PUINT)ucResetValue, sizeof(UINT));
472 if (Status == STATUS_SUCCESS) {
473 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO to output Mode\n");
475 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
481 case BCM_LED_THREAD_STATE_CHANGE_REQ: {
482 struct bcm_user_thread_req threadReq = {0};
483 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "User made LED thread InActive");
485 if ((Adapter->IdleMode == TRUE) ||
486 (Adapter->bShutStatus == TRUE) ||
487 (Adapter->bPreparingForLowPowerMode == TRUE)) {
489 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
494 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
497 if (IoBuffer.InputLength > sizeof(threadReq))
500 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
503 /* if LED thread is running(Actively or Inactively) set it state to make inactive */
504 if (Adapter->LEDInfo.led_thread_running) {
505 if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
506 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Activating thread req");
507 Adapter->DriverState = LED_THREAD_ACTIVE;
509 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DeActivating Thread req.....");
510 Adapter->DriverState = LED_THREAD_INACTIVE;
514 wake_up(&Adapter->LEDInfo.notify_led_event);
519 case IOCTL_BCM_GPIO_STATUS_REQUEST: {
522 struct bcm_gpio_info gpio_info = {0};
524 if ((Adapter->IdleMode == TRUE) ||
525 (Adapter->bShutStatus == TRUE) ||
526 (Adapter->bPreparingForLowPowerMode == TRUE))
529 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
532 if (IoBuffer.InputLength > sizeof(gpio_info))
535 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
538 uiBit = gpio_info.uiGpioNumber;
540 /* Set the gpio output register */
541 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
542 (PUINT)ucRead, sizeof(UINT));
546 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
549 Status = STATUS_SUCCESS;
554 case IOCTL_BCM_GPIO_MULTI_REQUEST: {
555 UCHAR ucResetValue[4];
556 struct bcm_gpio_multi_info gpio_multi_info[MAX_IDX];
557 struct bcm_gpio_multi_info *pgpio_multi_info = (struct bcm_gpio_multi_info *)gpio_multi_info;
559 memset(pgpio_multi_info, 0, MAX_IDX * sizeof(struct bcm_gpio_multi_info));
561 if ((Adapter->IdleMode == TRUE) ||
562 (Adapter->bShutStatus == TRUE) ||
563 (Adapter->bPreparingForLowPowerMode == TRUE))
566 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
569 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
572 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
575 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_info[WIMAX_IDX].uiGPIOMask) == FALSE) {
576 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
577 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
578 pgpio_multi_info[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
583 /* Set the gpio output register */
584 if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
585 (pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
586 /* Set 1's in GPIO OUTPUT REGISTER */
587 *(UINT *)ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
588 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
589 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
591 if (*(UINT *) ucResetValue)
592 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG,
593 (PUINT)ucResetValue, sizeof(ULONG));
595 if (Status != STATUS_SUCCESS) {
596 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
600 /* Clear to 0's in GPIO OUTPUT REGISTER */
601 *(UINT *)ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
602 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
603 (~(pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
605 if (*(UINT *) ucResetValue)
606 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)ucResetValue, sizeof(ULONG));
608 if (Status != STATUS_SUCCESS) {
609 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
614 if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
615 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
619 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM to GPIO_PIN_STATE_REGISTER Failed.");
622 Status = STATUS_SUCCESS;
625 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = (*(UINT *)ucResetValue &
626 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
629 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
632 "Failed while copying Content to IOBufer for user space err:%d", Status);
638 case IOCTL_BCM_GPIO_MODE_REQUEST: {
639 UCHAR ucResetValue[4];
640 struct bcm_gpio_multi_mode gpio_multi_mode[MAX_IDX];
641 struct bcm_gpio_multi_mode *pgpio_multi_mode = (struct bcm_gpio_multi_mode *)gpio_multi_mode;
643 if ((Adapter->IdleMode == TRUE) ||
644 (Adapter->bShutStatus == TRUE) ||
645 (Adapter->bPreparingForLowPowerMode == TRUE))
648 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
651 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
654 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
657 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
661 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read of GPIO_MODE_REGISTER failed");
664 Status = STATUS_SUCCESS;
667 /* Validating the request */
668 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) == FALSE) {
669 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
670 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
671 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
676 if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
677 /* write all OUT's (1's) */
678 *(UINT *) ucResetValue |= (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
679 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
681 /* write all IN's (0's) */
682 *(UINT *) ucResetValue &= ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
683 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
685 /* Currently implemented return the modes of all GPIO's
686 * else needs to bit AND with mask
688 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
690 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(ULONG));
691 if (Status == STATUS_SUCCESS) {
692 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
693 "WRM to GPIO_MODE_REGISTER Done");
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
696 "WRM to GPIO_MODE_REGISTER Failed");
701 /* if uiGPIOMask is 0 then return mode register configuration */
702 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
705 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
708 "Failed while copying Content to IOBufer for user space err:%d", Status);
714 case IOCTL_MAC_ADDR_REQ:
716 case IOCTL_CM_REQUEST:
717 case IOCTL_SS_INFO_REQ:
718 case IOCTL_SEND_CONTROL_MESSAGE:
719 case IOCTL_IDLE_REQ: {
720 PVOID pvBuffer = NULL;
722 /* Copy Ioctl Buffer structure */
723 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
726 if (IoBuffer.InputLength < sizeof(struct bcm_link_request))
729 if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
732 pvBuffer = memdup_user(IoBuffer.InputBuffer,
733 IoBuffer.InputLength);
734 if (IS_ERR(pvBuffer))
735 return PTR_ERR(pvBuffer);
737 down(&Adapter->LowPowerModeSync);
738 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
739 !Adapter->bPreparingForLowPowerMode,
741 if (Status == -ERESTARTSYS)
744 if (Adapter->bPreparingForLowPowerMode) {
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
746 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
747 Status = STATUS_FAILURE;
750 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
753 up(&Adapter->LowPowerModeSync);
758 case IOCTL_BCM_BUFFER_DOWNLOAD_START: {
759 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
760 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
761 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
765 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
766 "Starting the firmware download PID =0x%x!!!!\n", current->pid);
768 if (down_trylock(&Adapter->fw_download_sema))
771 Adapter->bBinDownloaded = FALSE;
772 Adapter->fw_download_process_pid = current->pid;
773 Adapter->bCfgDownloaded = FALSE;
774 Adapter->fw_download_done = FALSE;
775 netif_carrier_off(Adapter->dev);
776 netif_stop_queue(Adapter->dev);
777 Status = reset_card_proc(Adapter);
779 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
780 up(&Adapter->fw_download_sema);
781 up(&Adapter->NVMRdmWrmLock);
786 up(&Adapter->NVMRdmWrmLock);
790 case IOCTL_BCM_BUFFER_DOWNLOAD: {
791 struct bcm_firmware_info *psFwInfo = NULL;
792 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
794 if (!down_trylock(&Adapter->fw_download_sema)) {
795 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
796 "Invalid way to download buffer. Use Start and then call this!!!\n");
797 up(&Adapter->fw_download_sema);
802 /* Copy Ioctl Buffer structure */
803 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
804 up(&Adapter->fw_download_sema);
808 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
809 "Length for FW DLD is : %lx\n", IoBuffer.InputLength);
811 if (IoBuffer.InputLength > sizeof(struct bcm_firmware_info)) {
812 up(&Adapter->fw_download_sema);
816 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
818 up(&Adapter->fw_download_sema);
822 if (copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
823 up(&Adapter->fw_download_sema);
828 if (!psFwInfo->pvMappedFirmwareAddress ||
829 (psFwInfo->u32FirmwareLength == 0)) {
831 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
832 psFwInfo->u32FirmwareLength);
833 up(&Adapter->fw_download_sema);
839 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
841 if (Status != STATUS_SUCCESS) {
842 if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR)
843 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
845 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
847 /* up(&Adapter->fw_download_sema); */
849 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
850 Adapter->DriverState = DRIVER_INIT;
851 Adapter->LEDInfo.bLedInitDone = FALSE;
852 wake_up(&Adapter->LEDInfo.notify_led_event);
856 if (Status != STATUS_SUCCESS)
857 up(&Adapter->fw_download_sema);
859 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
864 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP: {
865 if (!down_trylock(&Adapter->fw_download_sema)) {
866 up(&Adapter->fw_download_sema);
870 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
871 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
872 "FW download blocked as EEPROM Read/Write is in progress\n");
873 up(&Adapter->fw_download_sema);
877 Adapter->bBinDownloaded = TRUE;
878 Adapter->bCfgDownloaded = TRUE;
879 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
880 Adapter->CurrNumRecvDescs = 0;
881 Adapter->downloadDDR = 0;
883 /* setting the Mips to Run */
884 Status = run_card_proc(Adapter);
887 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
888 up(&Adapter->fw_download_sema);
889 up(&Adapter->NVMRdmWrmLock);
892 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
893 DBG_LVL_ALL, "Firm Download Over...\n");
898 /* Wait for MailBox Interrupt */
899 if (StartInterruptUrb((struct bcm_interface_adapter *)Adapter->pvInterfaceAdapter))
900 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
903 Adapter->waiting_to_fw_download_done = FALSE;
904 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
905 Adapter->waiting_to_fw_download_done, timeout);
906 Adapter->fw_download_process_pid = INVALID_PID;
907 Adapter->fw_download_done = TRUE;
908 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
909 Adapter->CurrNumRecvDescs = 0;
910 Adapter->PrevNumRecvDescs = 0;
911 atomic_set(&Adapter->cntrlpktCnt, 0);
912 Adapter->LinkUpStatus = 0;
913 Adapter->LinkStatus = 0;
915 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
916 Adapter->DriverState = FW_DOWNLOAD_DONE;
917 wake_up(&Adapter->LEDInfo.notify_led_event);
923 up(&Adapter->fw_download_sema);
924 up(&Adapter->NVMRdmWrmLock);
928 case IOCTL_BE_BUCKET_SIZE:
930 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
934 case IOCTL_RTPS_BUCKET_SIZE:
936 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
940 case IOCTL_CHIP_RESET: {
941 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
943 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
947 down(&Adapter->RxAppControlQueuelock);
948 Status = reset_card_proc(Adapter);
950 up(&Adapter->RxAppControlQueuelock);
951 up(&Adapter->NVMRdmWrmLock);
952 ResetCounters(Adapter);
956 case IOCTL_QOS_THRESHOLD: {
960 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
961 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
962 (unsigned long __user *)arg)) {
970 case IOCTL_DUMP_PACKET_INFO:
971 DumpPackInfo(Adapter);
972 DumpPhsRules(&Adapter->stBCMPhsContext);
973 Status = STATUS_SUCCESS;
976 case IOCTL_GET_PACK_INFO:
977 if (copy_to_user(argp, &Adapter->PackInfo, sizeof(struct bcm_packet_info)*NO_OF_QUEUES))
979 Status = STATUS_SUCCESS;
982 case IOCTL_BCM_SWITCH_TRANSFER_MODE: {
984 if (copy_from_user(&uiData, argp, sizeof(UINT)))
988 /* Allow All Packets */
989 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
990 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
992 /* Allow IP only Packets */
993 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
994 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
996 Status = STATUS_SUCCESS;
1000 case IOCTL_BCM_GET_DRIVER_VERSION: {
1003 /* Copy Ioctl Buffer structure */
1004 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1007 len = min_t(ulong, IoBuffer.OutputLength, strlen(VER_FILEVERSION_STR) + 1);
1009 if (copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, len))
1011 Status = STATUS_SUCCESS;
1015 case IOCTL_BCM_GET_CURRENT_STATUS: {
1016 struct bcm_link_state link_state;
1018 /* Copy Ioctl Buffer structure */
1019 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
1020 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
1024 if (IoBuffer.OutputLength != sizeof(link_state)) {
1029 memset(&link_state, 0, sizeof(link_state));
1030 link_state.bIdleMode = Adapter->IdleMode;
1031 link_state.bShutdownMode = Adapter->bShutStatus;
1032 link_state.ucLinkStatus = Adapter->LinkStatus;
1034 if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) {
1035 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1038 Status = STATUS_SUCCESS;
1042 case IOCTL_BCM_SET_MAC_TRACING: {
1045 /* copy ioctl Buffer structure */
1046 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1049 if (copy_from_user(&tracing_flag, IoBuffer.InputBuffer, sizeof(UINT)))
1053 Adapter->pTarangs->MacTracingEnabled = TRUE;
1055 Adapter->pTarangs->MacTracingEnabled = FALSE;
1059 case IOCTL_BCM_GET_DSX_INDICATION: {
1061 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1064 if (IoBuffer.OutputLength < sizeof(struct bcm_add_indication_alt)) {
1065 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1066 "Mismatch req: %lx needed is =0x%zx!!!",
1067 IoBuffer.OutputLength, sizeof(struct bcm_add_indication_alt));
1071 if (copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1074 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId);
1075 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1076 Status = STATUS_SUCCESS;
1080 case IOCTL_BCM_GET_HOST_MIBS: {
1083 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1086 if (IoBuffer.OutputLength != sizeof(struct bcm_host_stats_mibs)) {
1087 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1088 "Length Check failed %lu %zd\n",
1089 IoBuffer.OutputLength, sizeof(struct bcm_host_stats_mibs));
1093 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1094 temp_buff = kzalloc(sizeof(struct bcm_host_stats_mibs), GFP_KERNEL);
1096 return STATUS_FAILURE;
1098 Status = ProcessGetHostMibs(Adapter, temp_buff);
1099 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1101 if (Status != STATUS_FAILURE)
1102 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(struct bcm_host_stats_mibs))) {
1111 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1112 if ((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE == Adapter->IdleMode)) {
1113 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1114 Adapter->bWakeUpDevice = TRUE;
1115 wake_up(&Adapter->process_rx_cntrlpkt);
1118 Status = STATUS_SUCCESS;
1121 case IOCTL_BCM_BULK_WRM: {
1122 struct bcm_bulk_wrm_buffer *pBulkBuffer;
1124 PCHAR pvBuffer = NULL;
1126 if ((Adapter->IdleMode == TRUE) ||
1127 (Adapter->bShutStatus == TRUE) ||
1128 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1130 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1135 /* Copy Ioctl Buffer structure */
1136 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1139 if (IoBuffer.InputLength < sizeof(ULONG) * 2)
1142 pvBuffer = memdup_user(IoBuffer.InputBuffer,
1143 IoBuffer.InputLength);
1144 if (IS_ERR(pvBuffer))
1145 return PTR_ERR(pvBuffer);
1147 pBulkBuffer = (struct bcm_bulk_wrm_buffer *)pvBuffer;
1149 if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1150 ((ULONG)pBulkBuffer->Register & 0x3)) {
1151 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer->Register);
1157 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1158 if (!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE) &&
1159 ((uiTempVar == EEPROM_REJECT_REG_1) ||
1160 (uiTempVar == EEPROM_REJECT_REG_2) ||
1161 (uiTempVar == EEPROM_REJECT_REG_3) ||
1162 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1163 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
1166 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
1171 if (pBulkBuffer->SwapEndian == FALSE)
1172 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1174 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1176 if (Status != STATUS_SUCCESS)
1177 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1183 case IOCTL_BCM_GET_NVM_SIZE:
1184 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1187 if (Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH) {
1188 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1192 Status = STATUS_SUCCESS;
1195 case IOCTL_BCM_CAL_INIT: {
1196 UINT uiSectorSize = 0 ;
1197 if (Adapter->eNVMType == NVM_FLASH) {
1198 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1201 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1204 if ((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) {
1205 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1209 if (IsFlash2x(Adapter)) {
1210 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize, sizeof(UINT)))
1213 if ((TRUE == Adapter->bShutStatus) || (TRUE == Adapter->IdleMode)) {
1214 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is in Idle/Shutdown Mode\n");
1218 Adapter->uiSectorSize = uiSectorSize;
1219 BcmUpdateSectorSize(Adapter, Adapter->uiSectorSize);
1222 Status = STATUS_SUCCESS;
1224 Status = STATUS_FAILURE;
1229 case IOCTL_BCM_SET_DEBUG:
1232 struct bcm_user_debug_state sUserDebugState;
1234 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1235 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1238 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(struct bcm_user_debug_state)))
1241 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1242 sUserDebugState.OnOff, sUserDebugState.Type);
1243 /* sUserDebugState.Subtype <<= 1; */
1244 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1245 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1247 /* Update new 'DebugState' in the Adapter */
1248 Adapter->stDebugState.type |= sUserDebugState.Type;
1249 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1250 * Valid indexes in 'subtype' array: 1,2,4,8
1251 * corresponding to valid Type values. Hence we can use the 'Type' field
1252 * as the index value, ignoring the array entries 0,3,5,6,7 !
1254 if (sUserDebugState.OnOff)
1255 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1257 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1259 BCM_SHOW_DEBUG_BITMAP(Adapter);
1264 case IOCTL_BCM_NVM_READ:
1265 case IOCTL_BCM_NVM_WRITE: {
1266 struct bcm_nvm_readwrite stNVMReadWrite;
1267 PUCHAR pReadData = NULL;
1268 ULONG ulDSDMagicNumInUsrBuff = 0;
1269 struct timeval tv0, tv1;
1270 memset(&tv0, 0, sizeof(struct timeval));
1271 memset(&tv1, 0, sizeof(struct timeval));
1272 if ((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0)) {
1273 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1277 if (IsFlash2x(Adapter)) {
1278 if ((Adapter->eActiveDSD != DSD0) &&
1279 (Adapter->eActiveDSD != DSD1) &&
1280 (Adapter->eActiveDSD != DSD2)) {
1282 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No DSD is active..hence NVM Command is blocked");
1283 return STATUS_FAILURE;
1287 /* Copy Ioctl Buffer structure */
1288 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1291 if (copy_from_user(&stNVMReadWrite,
1292 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1293 sizeof(struct bcm_nvm_readwrite)))
1297 * Deny the access if the offset crosses the cal area limit.
1299 if (stNVMReadWrite.uiNumBytes > Adapter->uiNVMDSDSize)
1300 return STATUS_FAILURE;
1302 if (stNVMReadWrite.uiOffset > Adapter->uiNVMDSDSize - stNVMReadWrite.uiNumBytes) {
1303 /* 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); */
1304 return STATUS_FAILURE;
1307 pReadData = memdup_user(stNVMReadWrite.pBuffer,
1308 stNVMReadWrite.uiNumBytes);
1309 if (IS_ERR(pReadData))
1310 return PTR_ERR(pReadData);
1312 do_gettimeofday(&tv0);
1313 if (IOCTL_BCM_NVM_READ == cmd) {
1314 down(&Adapter->NVMRdmWrmLock);
1316 if ((Adapter->IdleMode == TRUE) ||
1317 (Adapter->bShutStatus == TRUE) ||
1318 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1320 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1321 up(&Adapter->NVMRdmWrmLock);
1326 Status = BeceemNVMRead(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1327 up(&Adapter->NVMRdmWrmLock);
1329 if (Status != STATUS_SUCCESS) {
1334 if (copy_to_user(stNVMReadWrite.pBuffer, pReadData, stNVMReadWrite.uiNumBytes)) {
1339 down(&Adapter->NVMRdmWrmLock);
1341 if ((Adapter->IdleMode == TRUE) ||
1342 (Adapter->bShutStatus == TRUE) ||
1343 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1345 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1346 up(&Adapter->NVMRdmWrmLock);
1351 Adapter->bHeaderChangeAllowed = TRUE;
1352 if (IsFlash2x(Adapter)) {
1355 * DSD section updation will be allowed in two case:-
1356 * 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1357 * 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1358 * corrupted then user space program first modify the DSD header with valid DSD sig so
1359 * that this as well as further write may be worthwhile.
1361 * This restriction has been put assuming that if DSD sig is corrupted, DSD
1362 * data won't be considered valid.
1365 Status = BcmFlash2xCorruptSig(Adapter, Adapter->eActiveDSD);
1366 if (Status != STATUS_SUCCESS) {
1367 if (((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize) ||
1368 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE)) {
1370 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1371 up(&Adapter->NVMRdmWrmLock);
1376 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1377 if (ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER) {
1378 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1379 up(&Adapter->NVMRdmWrmLock);
1386 Status = BeceemNVMWrite(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1387 if (IsFlash2x(Adapter))
1388 BcmFlash2xWriteSig(Adapter, Adapter->eActiveDSD);
1390 Adapter->bHeaderChangeAllowed = FALSE;
1392 up(&Adapter->NVMRdmWrmLock);
1394 if (Status != STATUS_SUCCESS) {
1400 do_gettimeofday(&tv1);
1401 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);
1404 return STATUS_SUCCESS;
1407 case IOCTL_BCM_FLASH2X_SECTION_READ: {
1408 struct bcm_flash2x_readwrite sFlash2xRead = {0};
1409 PUCHAR pReadBuff = NULL ;
1413 UINT ReadOffset = 0;
1414 void __user *OutPutBuff;
1416 if (IsFlash2x(Adapter) != TRUE) {
1417 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1421 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1422 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1425 /* Reading FLASH 2.x READ structure */
1426 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
1429 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xRead.Section);
1430 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%x", sFlash2xRead.offset);
1431 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xRead.numOfBytes);
1432 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xRead.bVerify);
1434 /* This was internal to driver for raw read. now it has ben exposed to user space app. */
1435 if (validateFlash2xReadWrite(Adapter, &sFlash2xRead) == FALSE)
1436 return STATUS_FAILURE;
1438 NOB = sFlash2xRead.numOfBytes;
1439 if (NOB > Adapter->uiSectorSize)
1440 BuffSize = Adapter->uiSectorSize;
1444 ReadOffset = sFlash2xRead.offset ;
1445 OutPutBuff = IoBuffer.OutputBuffer;
1446 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1448 if (pReadBuff == NULL) {
1449 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1452 down(&Adapter->NVMRdmWrmLock);
1454 if ((Adapter->IdleMode == TRUE) ||
1455 (Adapter->bShutStatus == TRUE) ||
1456 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1458 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1459 up(&Adapter->NVMRdmWrmLock);
1465 if (NOB > Adapter->uiSectorSize)
1466 ReadBytes = Adapter->uiSectorSize;
1470 /* Reading the data from Flash 2.x */
1471 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pReadBuff, sFlash2xRead.Section, ReadOffset, ReadBytes);
1473 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Flash 2x read err with Status :%d", Status);
1477 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1479 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1481 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status);
1482 up(&Adapter->NVMRdmWrmLock);
1486 NOB = NOB - ReadBytes;
1488 ReadOffset = ReadOffset + ReadBytes;
1489 OutPutBuff = OutPutBuff + ReadBytes ;
1493 up(&Adapter->NVMRdmWrmLock);
1498 case IOCTL_BCM_FLASH2X_SECTION_WRITE: {
1499 struct bcm_flash2x_readwrite sFlash2xWrite = {0};
1501 void __user *InputAddr;
1504 UINT WriteOffset = 0;
1505 UINT WriteBytes = 0;
1507 if (IsFlash2x(Adapter) != TRUE) {
1508 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1512 /* First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite */
1513 Adapter->bAllDSDWriteAllow = FALSE;
1515 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1517 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1520 /* Reading FLASH 2.x READ structure */
1521 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
1524 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xWrite.Section);
1525 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%d", sFlash2xWrite.offset);
1526 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite.numOfBytes);
1527 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite.bVerify);
1529 if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) && (sFlash2xWrite.Section != VSA2)) {
1530 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Only VSA write is allowed");
1534 if (validateFlash2xReadWrite(Adapter, &sFlash2xWrite) == FALSE)
1535 return STATUS_FAILURE;
1537 InputAddr = sFlash2xWrite.pDataBuff;
1538 WriteOffset = sFlash2xWrite.offset;
1539 NOB = sFlash2xWrite.numOfBytes;
1541 if (NOB > Adapter->uiSectorSize)
1542 BuffSize = Adapter->uiSectorSize;
1546 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1548 if (pWriteBuff == NULL)
1551 /* extracting the remainder of the given offset. */
1552 WriteBytes = Adapter->uiSectorSize;
1553 if (WriteOffset % Adapter->uiSectorSize)
1554 WriteBytes = Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1556 if (NOB < WriteBytes)
1559 down(&Adapter->NVMRdmWrmLock);
1561 if ((Adapter->IdleMode == TRUE) ||
1562 (Adapter->bShutStatus == TRUE) ||
1563 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1565 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1566 up(&Adapter->NVMRdmWrmLock);
1571 BcmFlash2xCorruptSig(Adapter, sFlash2xWrite.Section);
1573 Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
1575 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status);
1576 up(&Adapter->NVMRdmWrmLock);
1580 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
1582 /* Writing the data from Flash 2.x */
1583 Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pWriteBuff, sFlash2xWrite.Section, WriteOffset, WriteBytes, sFlash2xWrite.bVerify);
1586 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1590 NOB = NOB - WriteBytes;
1592 WriteOffset = WriteOffset + WriteBytes;
1593 InputAddr = InputAddr + WriteBytes;
1594 if (NOB > Adapter->uiSectorSize)
1595 WriteBytes = Adapter->uiSectorSize;
1601 BcmFlash2xWriteSig(Adapter, sFlash2xWrite.Section);
1602 up(&Adapter->NVMRdmWrmLock);
1607 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP: {
1608 struct bcm_flash2x_bitmap *psFlash2xBitMap;
1609 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1611 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1614 if (IoBuffer.OutputLength != sizeof(struct bcm_flash2x_bitmap))
1617 psFlash2xBitMap = kzalloc(sizeof(struct bcm_flash2x_bitmap), GFP_KERNEL);
1618 if (psFlash2xBitMap == NULL) {
1619 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory is not available");
1623 /* Reading the Flash Sectio Bit map */
1624 down(&Adapter->NVMRdmWrmLock);
1626 if ((Adapter->IdleMode == TRUE) ||
1627 (Adapter->bShutStatus == TRUE) ||
1628 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1630 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1631 up(&Adapter->NVMRdmWrmLock);
1632 kfree(psFlash2xBitMap);
1636 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1637 up(&Adapter->NVMRdmWrmLock);
1638 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(struct bcm_flash2x_bitmap))) {
1639 kfree(psFlash2xBitMap);
1643 kfree(psFlash2xBitMap);
1647 case IOCTL_BCM_SET_ACTIVE_SECTION: {
1648 enum bcm_flash2x_section_val eFlash2xSectionVal = 0;
1649 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1651 if (IsFlash2x(Adapter) != TRUE) {
1652 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1656 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1658 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1662 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1664 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1668 down(&Adapter->NVMRdmWrmLock);
1670 if ((Adapter->IdleMode == TRUE) ||
1671 (Adapter->bShutStatus == TRUE) ||
1672 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1674 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1675 up(&Adapter->NVMRdmWrmLock);
1679 Status = BcmSetActiveSection(Adapter, eFlash2xSectionVal);
1681 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Failed to make it's priority Highest. Status %d", Status);
1683 up(&Adapter->NVMRdmWrmLock);
1687 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION: {
1688 /* Right Now we are taking care of only DSD */
1689 Adapter->bAllDSDWriteAllow = FALSE;
1690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1691 Status = STATUS_SUCCESS;
1695 case IOCTL_BCM_COPY_SECTION: {
1696 struct bcm_flash2x_copy_section sCopySectStrut = {0};
1697 Status = STATUS_SUCCESS;
1698 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1700 Adapter->bAllDSDWriteAllow = FALSE;
1701 if (IsFlash2x(Adapter) != TRUE) {
1702 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1706 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1708 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1712 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_copy_section));
1714 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1718 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1721 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1723 if (IsSectionExistInFlash(Adapter, sCopySectStrut.SrcSection) == FALSE) {
1724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
1728 if (IsSectionExistInFlash(Adapter, sCopySectStrut.DstSection) == FALSE) {
1729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
1733 if (sCopySectStrut.SrcSection == sCopySectStrut.DstSection) {
1734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source and Destination section should be different");
1738 down(&Adapter->NVMRdmWrmLock);
1740 if ((Adapter->IdleMode == TRUE) ||
1741 (Adapter->bShutStatus == TRUE) ||
1742 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1745 up(&Adapter->NVMRdmWrmLock);
1749 if (sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2) {
1750 if (IsNonCDLessDevice(Adapter)) {
1751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is Non-CDLess hence won't have ISO !!");
1753 } else if (sCopySectStrut.numOfBytes == 0) {
1754 Status = BcmCopyISO(Adapter, sCopySectStrut);
1756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Partial Copy of ISO section is not Allowed..");
1757 Status = STATUS_FAILURE;
1759 up(&Adapter->NVMRdmWrmLock);
1763 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
1764 sCopySectStrut.DstSection, sCopySectStrut.offset, sCopySectStrut.numOfBytes);
1765 up(&Adapter->NVMRdmWrmLock);
1769 case IOCTL_BCM_GET_FLASH_CS_INFO: {
1770 Status = STATUS_SUCCESS;
1771 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1773 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1779 if (Adapter->eNVMType != NVM_FLASH) {
1780 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Connected device does not have flash");
1785 if (IsFlash2x(Adapter) == TRUE) {
1786 if (IoBuffer.OutputLength < sizeof(struct bcm_flash2x_cs_info))
1789 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(struct bcm_flash2x_cs_info)))
1792 if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info))
1795 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash_cs_info)))
1801 case IOCTL_BCM_SELECT_DSD: {
1803 enum bcm_flash2x_section_val eFlash2xSectionVal;
1804 eFlash2xSectionVal = NO_SECTION_VAL;
1805 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SELECT_DSD Called");
1807 if (IsFlash2x(Adapter) != TRUE) {
1808 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1812 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1814 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1817 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1819 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1823 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal);
1824 if ((eFlash2xSectionVal != DSD0) &&
1825 (eFlash2xSectionVal != DSD1) &&
1826 (eFlash2xSectionVal != DSD2)) {
1828 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Passed section<%x> is not DSD section", eFlash2xSectionVal);
1829 return STATUS_FAILURE;
1832 SectOfset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
1833 if (SectOfset == INVALID_OFFSET) {
1834 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
1838 Adapter->bAllDSDWriteAllow = TRUE;
1839 Adapter->ulFlashCalStart = SectOfset;
1840 Adapter->eActiveDSD = eFlash2xSectionVal;
1842 Status = STATUS_SUCCESS;
1845 case IOCTL_BCM_NVM_RAW_READ: {
1846 struct bcm_nvm_readwrite stNVMRead;
1850 UINT ReadBytes = 0 ;
1852 void __user *OutPutBuff;
1854 if (Adapter->eNVMType != NVM_FLASH) {
1855 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "NVM TYPE is not Flash");
1859 /* Copy Ioctl Buffer structure */
1860 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
1861 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
1865 if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(struct bcm_nvm_readwrite)))
1868 NOB = stNVMRead.uiNumBytes;
1869 /* In Raw-Read max Buff size : 64MB */
1871 if (NOB > DEFAULT_BUFF_SIZE)
1872 BuffSize = DEFAULT_BUFF_SIZE;
1876 ReadOffset = stNVMRead.uiOffset;
1877 OutPutBuff = stNVMRead.pBuffer;
1879 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
1880 if (pReadBuff == NULL) {
1881 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1885 down(&Adapter->NVMRdmWrmLock);
1887 if ((Adapter->IdleMode == TRUE) ||
1888 (Adapter->bShutStatus == TRUE) ||
1889 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1891 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1893 up(&Adapter->NVMRdmWrmLock);
1897 Adapter->bFlashRawRead = TRUE;
1900 if (NOB > DEFAULT_BUFF_SIZE)
1901 ReadBytes = DEFAULT_BUFF_SIZE;
1905 /* Reading the data from Flash 2.x */
1906 Status = BeceemNVMRead(Adapter, (PUINT)pReadBuff, ReadOffset, ReadBytes);
1908 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1912 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1914 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1916 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status);
1917 up(&Adapter->NVMRdmWrmLock);
1921 NOB = NOB - ReadBytes;
1923 ReadOffset = ReadOffset + ReadBytes;
1924 OutPutBuff = OutPutBuff + ReadBytes;
1927 Adapter->bFlashRawRead = FALSE;
1928 up(&Adapter->NVMRdmWrmLock);
1933 case IOCTL_BCM_CNTRLMSG_MASK: {
1934 ULONG RxCntrlMsgBitMask = 0;
1936 /* Copy Ioctl Buffer structure */
1937 Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
1939 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space");
1943 if (IoBuffer.InputLength != sizeof(unsigned long)) {
1948 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
1950 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space");
1953 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
1954 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;
1958 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO: {
1959 struct bcm_driver_info DevInfo;
1961 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
1963 DevInfo.MaxRDMBufferSize = BUFFER_4K;
1964 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
1965 DevInfo.u32RxAlignmentCorrection = 0;
1966 DevInfo.u32NVMType = Adapter->eNVMType;
1967 DevInfo.u32InterfaceType = BCM_USB;
1969 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1972 if (IoBuffer.OutputLength < sizeof(DevInfo))
1975 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
1980 case IOCTL_BCM_TIME_SINCE_NET_ENTRY: {
1981 struct bcm_time_elapsed stTimeElapsedSinceNetEntry = {0};
1983 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
1985 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1988 if (IoBuffer.OutputLength < sizeof(struct bcm_time_elapsed))
1991 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
1993 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(struct bcm_time_elapsed)))
1998 case IOCTL_CLOSE_NOTIFICATION:
1999 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_CLOSE_NOTIFICATION");
2003 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2004 Status = STATUS_FAILURE;
2011 static const struct file_operations bcm_fops = {
2012 .owner = THIS_MODULE,
2013 .open = bcm_char_open,
2014 .release = bcm_char_release,
2015 .read = bcm_char_read,
2016 .unlocked_ioctl = bcm_char_ioctl,
2017 .llseek = no_llseek,
2020 int register_control_device_interface(struct bcm_mini_adapter *Adapter)
2023 if (Adapter->major > 0)
2024 return Adapter->major;
2026 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
2027 if (Adapter->major < 0) {
2028 pr_err(DRV_NAME ": could not created character device\n");
2029 return Adapter->major;
2032 Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
2033 MKDEV(Adapter->major, 0),
2036 if (IS_ERR(Adapter->pstCreatedClassDevice)) {
2037 pr_err(DRV_NAME ": class device create failed\n");
2038 unregister_chrdev(Adapter->major, DEV_NAME);
2039 return PTR_ERR(Adapter->pstCreatedClassDevice);
2045 void unregister_control_device_interface(struct bcm_mini_adapter *Adapter)
2047 if (Adapter->major > 0) {
2048 device_destroy(bcm_class, MKDEV(Adapter->major, 0));
2049 unregister_chrdev(Adapter->major, DEV_NAME);