4 /***************************************************************
5 * Function - bcm_char_open()
7 * Description - This is the "open" entry point for the character
10 * Parameters - inode: Pointer to the Inode structure of char device
11 * filp : File pointer of the char device
13 * Returns - Zero(Success)
14 ****************************************************************/
16 static int bcm_char_open(struct inode *inode, struct file * filp)
18 PMINI_ADAPTER Adapter = NULL;
19 PPER_TARANG_DATA pTarang = NULL;
21 Adapter = GET_BCM_ADAPTER(gblpnetdev);
22 pTarang = kzalloc(sizeof(PER_TARANG_DATA), GFP_KERNEL);
26 pTarang->Adapter = Adapter;
27 pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
29 down(&Adapter->RxAppControlQueuelock);
30 pTarang->next = Adapter->pTarangs;
31 Adapter->pTarangs = pTarang;
32 up(&Adapter->RxAppControlQueuelock);
34 /* Store the Adapter structure */
35 filp->private_data = pTarang;
37 /* Start Queuing the control response Packets */
38 atomic_inc(&Adapter->ApplicationRunning);
40 nonseekable_open(inode, filp);
44 static int bcm_char_release(struct inode *inode, struct file *filp)
46 PPER_TARANG_DATA pTarang, tmp, ptmp;
47 PMINI_ADAPTER Adapter = NULL;
48 struct sk_buff *pkt, *npkt;
50 pTarang = (PPER_TARANG_DATA)filp->private_data;
52 if (pTarang == NULL) {
53 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
58 Adapter = pTarang->Adapter;
60 down(&Adapter->RxAppControlQueuelock);
62 tmp = Adapter->pTarangs;
63 for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
70 Adapter->pTarangs = tmp->next;
72 ptmp->next = tmp->next;
74 up(&Adapter->RxAppControlQueuelock);
78 pkt = pTarang->RxAppControlHead;
85 up(&Adapter->RxAppControlQueuelock);
87 /* Stop Queuing the control response Packets */
88 atomic_dec(&Adapter->ApplicationRunning);
92 /* remove this filp from the asynchronously notified filp's */
93 filp->private_data = NULL;
97 static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
100 PPER_TARANG_DATA pTarang = filp->private_data;
101 PMINI_ADAPTER Adapter = pTarang->Adapter;
102 struct sk_buff *Packet = NULL;
104 int wait_ret_val = 0;
105 unsigned long ret = 0;
107 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
108 (pTarang->RxAppControlHead ||
109 Adapter->device_removed));
110 if ((wait_ret_val == -ERESTARTSYS)) {
111 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
112 "Exiting as i've been asked to exit!!!\n");
116 if (Adapter->device_removed) {
117 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
118 "Device Removed... Killing the Apps...\n");
122 if (FALSE == Adapter->fw_download_done)
125 down(&Adapter->RxAppControlQueuelock);
127 if (pTarang->RxAppControlHead) {
128 Packet = pTarang->RxAppControlHead;
129 DEQUEUEPACKET(pTarang->RxAppControlHead,
130 pTarang->RxAppControlTail);
131 pTarang->AppCtrlQueueLen--;
134 up(&Adapter->RxAppControlQueuelock);
137 PktLen = Packet->len;
138 ret = copy_to_user(buf, Packet->data,
139 min_t(size_t, PktLen, size));
141 dev_kfree_skb(Packet);
142 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
143 "Returning from copy to user failure\n");
146 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
147 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
148 PktLen, Packet, current->pid);
149 dev_kfree_skb(Packet);
152 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
156 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
158 PPER_TARANG_DATA pTarang = filp->private_data;
159 void __user *argp = (void __user *)arg;
160 PMINI_ADAPTER Adapter = pTarang->Adapter;
161 INT Status = STATUS_FAILURE;
163 IOCTL_BUFFER IoBuffer;
165 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg);
167 if (_IOC_TYPE(cmd) != BCM_IOCTL)
169 if (_IOC_DIR(cmd) & _IOC_READ)
170 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
171 else if (_IOC_DIR(cmd) & _IOC_WRITE)
172 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
173 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
174 Status = STATUS_SUCCESS;
179 if (Adapter->device_removed)
182 if (FALSE == Adapter->fw_download_done) {
184 case IOCTL_MAC_ADDR_REQ:
186 case IOCTL_CM_REQUEST:
187 case IOCTL_SS_INFO_REQ:
188 case IOCTL_SEND_CONTROL_MESSAGE:
190 case IOCTL_BCM_GPIO_SET_REQUEST:
191 case IOCTL_BCM_GPIO_STATUS_REQUEST:
198 Status = vendorextnIoctl(Adapter, cmd, arg);
199 if (Status != CONTINUE_COMMON_PATH)
203 /* Rdms for Swin Idle... */
204 case IOCTL_BCM_REGISTER_READ_PRIVATE: {
205 RDM_BUFFER sRdmBuffer = {0};
209 /* Copy Ioctl Buffer structure */
210 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
213 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
216 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
219 /* FIXME: need to restrict BuffLen */
220 Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
221 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
225 Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
226 (PUINT)temp_buff, Bufflen);
227 if (Status == STATUS_SUCCESS) {
228 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
236 case IOCTL_BCM_REGISTER_WRITE_PRIVATE: {
237 WRM_BUFFER sWrmBuffer = {0};
239 /* Copy Ioctl Buffer structure */
241 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
244 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
247 /* Get WrmBuffer structure */
248 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
251 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
252 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
253 ((uiTempVar == EEPROM_REJECT_REG_1) ||
254 (uiTempVar == EEPROM_REJECT_REG_2) ||
255 (uiTempVar == EEPROM_REJECT_REG_3) ||
256 (uiTempVar == EEPROM_REJECT_REG_4))) {
258 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
262 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
263 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
265 if (Status == STATUS_SUCCESS) {
266 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
268 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
274 case IOCTL_BCM_REGISTER_READ:
275 case IOCTL_BCM_EEPROM_REGISTER_READ: {
276 RDM_BUFFER sRdmBuffer = {0};
277 PCHAR temp_buff = NULL;
279 if ((Adapter->IdleMode == TRUE) ||
280 (Adapter->bShutStatus == TRUE) ||
281 (Adapter->bPreparingForLowPowerMode == TRUE)) {
283 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
287 /* Copy Ioctl Buffer structure */
288 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
291 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
294 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
297 /* FIXME: don't trust user supplied length */
298 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
300 return STATUS_FAILURE;
302 if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
303 ((ULONG)sRdmBuffer.Register & 0x3)) {
305 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
306 (int)sRdmBuffer.Register);
310 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
311 Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register, (PUINT)temp_buff, IoBuffer.OutputLength);
313 if (Status == STATUS_SUCCESS)
314 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
320 case IOCTL_BCM_REGISTER_WRITE:
321 case IOCTL_BCM_EEPROM_REGISTER_WRITE: {
322 WRM_BUFFER sWrmBuffer = {0};
324 if ((Adapter->IdleMode == TRUE) ||
325 (Adapter->bShutStatus == TRUE) ||
326 (Adapter->bPreparingForLowPowerMode == TRUE)) {
328 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
332 /* Copy Ioctl Buffer structure */
333 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
336 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
339 /* Get WrmBuffer structure */
340 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
343 if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
344 ((ULONG)sWrmBuffer.Register & 0x3)) {
346 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)sWrmBuffer.Register);
350 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
351 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
352 ((uiTempVar == EEPROM_REJECT_REG_1) ||
353 (uiTempVar == EEPROM_REJECT_REG_2) ||
354 (uiTempVar == EEPROM_REJECT_REG_3) ||
355 (uiTempVar == EEPROM_REJECT_REG_4)) &&
356 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
358 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
362 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
363 (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
365 if (Status == STATUS_SUCCESS) {
366 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
368 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
373 case IOCTL_BCM_GPIO_SET_REQUEST: {
374 UCHAR ucResetValue[4];
377 UINT uiOperation = 0;
379 GPIO_INFO gpio_info = {0};
380 if ((Adapter->IdleMode == TRUE) ||
381 (Adapter->bShutStatus == TRUE) ||
382 (Adapter->bPreparingForLowPowerMode == TRUE)) {
384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
388 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
391 if (IoBuffer.InputLength > sizeof(gpio_info))
394 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
397 uiBit = gpio_info.uiGpioNumber;
398 uiOperation = gpio_info.uiGpioValue;
401 if (IsReqGpioIsLedInNVM(Adapter, value) == FALSE) {
402 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!", value);
407 /* Set - setting 1 */
409 /* Set the gpio output register */
410 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, (PUINT)(&value), sizeof(UINT));
412 if (Status == STATUS_SUCCESS) {
413 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
415 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to set the %dth GPIO\n", uiBit);
419 /* Set the gpio output register */
420 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)(&value), sizeof(UINT));
422 if (Status == STATUS_SUCCESS) {
423 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
425 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to clear the %dth GPIO\n", uiBit);
430 Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
432 if (STATUS_SUCCESS != Status) {
433 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
434 "GPIO_MODE_REGISTER read failed");
438 /* Set the gpio mode register to output */
439 *(UINT *)ucResetValue |= (1<<uiBit);
440 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
441 (PUINT)ucResetValue, sizeof(UINT));
443 if (Status == STATUS_SUCCESS) {
444 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO to output Mode\n");
446 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
452 case BCM_LED_THREAD_STATE_CHANGE_REQ: {
453 USER_THREAD_REQ threadReq = {0};
454 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "User made LED thread InActive");
456 if ((Adapter->IdleMode == TRUE) ||
457 (Adapter->bShutStatus == TRUE) ||
458 (Adapter->bPreparingForLowPowerMode == TRUE)) {
460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
465 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
468 if (IoBuffer.InputLength > sizeof(threadReq))
471 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
474 /* if LED thread is running(Actively or Inactively) set it state to make inactive */
475 if (Adapter->LEDInfo.led_thread_running) {
476 if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
477 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Activating thread req");
478 Adapter->DriverState = LED_THREAD_ACTIVE;
480 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DeActivating Thread req.....");
481 Adapter->DriverState = LED_THREAD_INACTIVE;
485 wake_up(&Adapter->LEDInfo.notify_led_event);
490 case IOCTL_BCM_GPIO_STATUS_REQUEST: {
493 GPIO_INFO gpio_info = {0};
495 if ((Adapter->IdleMode == TRUE) ||
496 (Adapter->bShutStatus == TRUE) ||
497 (Adapter->bPreparingForLowPowerMode == TRUE))
500 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
503 if (IoBuffer.InputLength > sizeof(gpio_info))
506 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
509 uiBit = gpio_info.uiGpioNumber;
511 /* Set the gpio output register */
512 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
513 (PUINT)ucRead, sizeof(UINT));
515 if (Status != STATUS_SUCCESS) {
516 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
522 case IOCTL_BCM_GPIO_MULTI_REQUEST: {
523 UCHAR ucResetValue[4];
524 GPIO_MULTI_INFO gpio_multi_info[MAX_IDX];
525 PGPIO_MULTI_INFO pgpio_multi_info = (PGPIO_MULTI_INFO)gpio_multi_info;
527 memset(pgpio_multi_info, 0, MAX_IDX * sizeof(GPIO_MULTI_INFO));
529 if ((Adapter->IdleMode == TRUE) ||
530 (Adapter->bShutStatus == TRUE) ||
531 (Adapter->bPreparingForLowPowerMode == TRUE))
534 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
537 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
540 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
543 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_info[WIMAX_IDX].uiGPIOMask) == FALSE) {
544 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
545 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
546 pgpio_multi_info[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
551 /* Set the gpio output register */
552 if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
553 (pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
554 /* Set 1's in GPIO OUTPUT REGISTER */
555 *(UINT *)ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
556 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
557 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
559 if (*(UINT *) ucResetValue)
560 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG,
561 (PUINT)ucResetValue, sizeof(ULONG));
563 if (Status != STATUS_SUCCESS) {
564 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
568 /* Clear to 0's in GPIO OUTPUT REGISTER */
569 *(UINT *)ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
570 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
571 (~(pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
573 if (*(UINT *) ucResetValue)
574 Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)ucResetValue, sizeof(ULONG));
576 if (Status != STATUS_SUCCESS) {
577 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
582 if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
583 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
585 if (Status != STATUS_SUCCESS) {
586 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM to GPIO_PIN_STATE_REGISTER Failed.");
590 pgpio_multi_info[WIMAX_IDX].uiGPIOValue = (*(UINT *)ucResetValue &
591 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
594 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
596 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
597 "Failed while copying Content to IOBufer for user space err:%d", Status);
603 case IOCTL_BCM_GPIO_MODE_REQUEST: {
604 UCHAR ucResetValue[4];
605 GPIO_MULTI_MODE gpio_multi_mode[MAX_IDX];
606 PGPIO_MULTI_MODE pgpio_multi_mode = (PGPIO_MULTI_MODE)gpio_multi_mode;
608 if ((Adapter->IdleMode == TRUE) ||
609 (Adapter->bShutStatus == TRUE) ||
610 (Adapter->bPreparingForLowPowerMode == TRUE))
613 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
616 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
619 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
622 Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
624 if (STATUS_SUCCESS != Status) {
625 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read of GPIO_MODE_REGISTER failed");
629 /* Validating the request */
630 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) == FALSE) {
631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
632 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
633 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
638 if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
639 /* write all OUT's (1's) */
640 *(UINT *) ucResetValue |= (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
641 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
643 /* write all IN's (0's) */
644 *(UINT *) ucResetValue &= ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
645 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
647 /* Currently implemented return the modes of all GPIO's
648 * else needs to bit AND with mask
650 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
652 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(ULONG));
653 if (Status == STATUS_SUCCESS) {
654 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
655 "WRM to GPIO_MODE_REGISTER Done");
657 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
658 "WRM to GPIO_MODE_REGISTER Failed");
663 /* if uiGPIOMask is 0 then return mode register configuration */
664 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
667 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
669 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
670 "Failed while copying Content to IOBufer for user space err:%d", Status);
676 case IOCTL_MAC_ADDR_REQ:
678 case IOCTL_CM_REQUEST:
679 case IOCTL_SS_INFO_REQ:
680 case IOCTL_SEND_CONTROL_MESSAGE:
681 case IOCTL_IDLE_REQ: {
682 PVOID pvBuffer = NULL;
684 /* Copy Ioctl Buffer structure */
685 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
688 /* FIXME: don't accept any length from user */
689 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
693 if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
699 down(&Adapter->LowPowerModeSync);
700 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
701 !Adapter->bPreparingForLowPowerMode,
703 if (Status == -ERESTARTSYS)
706 if (Adapter->bPreparingForLowPowerMode) {
707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
708 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
709 Status = STATUS_FAILURE;
712 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
715 up(&Adapter->LowPowerModeSync);
720 case IOCTL_BCM_BUFFER_DOWNLOAD_START: {
721 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
724 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
728 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
729 "Starting the firmware download PID =0x%x!!!!\n", current->pid);
731 if (!down_trylock(&Adapter->fw_download_sema)) {
732 Adapter->bBinDownloaded = FALSE;
733 Adapter->fw_download_process_pid = current->pid;
734 Adapter->bCfgDownloaded = FALSE;
735 Adapter->fw_download_done = FALSE;
736 netif_carrier_off(Adapter->dev);
737 netif_stop_queue(Adapter->dev);
738 Status = reset_card_proc(Adapter);
740 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
741 up(&Adapter->fw_download_sema);
742 up(&Adapter->NVMRdmWrmLock);
750 up(&Adapter->NVMRdmWrmLock);
754 case IOCTL_BCM_BUFFER_DOWNLOAD: {
755 FIRMWARE_INFO *psFwInfo = NULL;
756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
758 if (!down_trylock(&Adapter->fw_download_sema)) {
759 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
760 "Invalid way to download buffer. Use Start and then call this!!!\n");
765 /* Copy Ioctl Buffer structure */
766 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
769 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
770 "Length for FW DLD is : %lx\n", IoBuffer.InputLength);
772 if (IoBuffer.InputLength > sizeof(FIRMWARE_INFO))
775 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
779 if (copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength))
782 if (!psFwInfo->pvMappedFirmwareAddress ||
783 (psFwInfo->u32FirmwareLength == 0)) {
785 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
786 psFwInfo->u32FirmwareLength);
791 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
793 if (Status != STATUS_SUCCESS) {
794 if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR)
795 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
797 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
799 /* up(&Adapter->fw_download_sema); */
801 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
802 Adapter->DriverState = DRIVER_INIT;
803 Adapter->LEDInfo.bLedInitDone = FALSE;
804 wake_up(&Adapter->LEDInfo.notify_led_event);
811 if (Status != STATUS_SUCCESS)
812 up(&Adapter->fw_download_sema);
814 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
819 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP: {
820 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
823 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
824 "FW download blocked as EEPROM Read/Write is in progress\n");
825 up(&Adapter->fw_download_sema);
829 if (down_trylock(&Adapter->fw_download_sema)) {
830 Adapter->bBinDownloaded = TRUE;
831 Adapter->bCfgDownloaded = TRUE;
832 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
833 Adapter->CurrNumRecvDescs = 0;
834 Adapter->downloadDDR = 0;
836 /* setting the Mips to Run */
837 Status = run_card_proc(Adapter);
840 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
841 up(&Adapter->fw_download_sema);
842 up(&Adapter->NVMRdmWrmLock);
845 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
846 DBG_LVL_ALL, "Firm Download Over...\n");
851 /* Wait for MailBox Interrupt */
852 if (StartInterruptUrb((PS_INTERFACE_ADAPTER)Adapter->pvInterfaceAdapter))
853 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
856 Adapter->waiting_to_fw_download_done = FALSE;
857 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
858 Adapter->waiting_to_fw_download_done, timeout);
859 Adapter->fw_download_process_pid = INVALID_PID;
860 Adapter->fw_download_done = TRUE;
861 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
862 Adapter->CurrNumRecvDescs = 0;
863 Adapter->PrevNumRecvDescs = 0;
864 atomic_set(&Adapter->cntrlpktCnt, 0);
865 Adapter->LinkUpStatus = 0;
866 Adapter->LinkStatus = 0;
868 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
869 Adapter->DriverState = FW_DOWNLOAD_DONE;
870 wake_up(&Adapter->LEDInfo.notify_led_event);
879 up(&Adapter->fw_download_sema);
880 up(&Adapter->NVMRdmWrmLock);
884 case IOCTL_BE_BUCKET_SIZE:
886 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
890 case IOCTL_RTPS_BUCKET_SIZE:
892 if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
896 case IOCTL_CHIP_RESET: {
897 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
899 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
903 down(&Adapter->RxAppControlQueuelock);
904 Status = reset_card_proc(Adapter);
906 up(&Adapter->RxAppControlQueuelock);
907 up(&Adapter->NVMRdmWrmLock);
908 ResetCounters(Adapter);
912 case IOCTL_QOS_THRESHOLD: {
916 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
917 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
918 (unsigned long __user *)arg)) {
926 case IOCTL_DUMP_PACKET_INFO:
927 DumpPackInfo(Adapter);
928 DumpPhsRules(&Adapter->stBCMPhsContext);
929 Status = STATUS_SUCCESS;
932 case IOCTL_GET_PACK_INFO:
933 if (copy_to_user(argp, &Adapter->PackInfo, sizeof(PacketInfo)*NO_OF_QUEUES))
935 Status = STATUS_SUCCESS;
938 case IOCTL_BCM_SWITCH_TRANSFER_MODE: {
940 if (copy_from_user(&uiData, argp, sizeof(UINT)))
944 /* Allow All Packets */
945 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
946 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
948 /* Allow IP only Packets */
949 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
950 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
952 Status = STATUS_SUCCESS;
956 case IOCTL_BCM_GET_DRIVER_VERSION: {
957 /* Copy Ioctl Buffer structure */
958 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
961 if (copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, IoBuffer.OutputLength))
963 Status = STATUS_SUCCESS;
967 case IOCTL_BCM_GET_CURRENT_STATUS: {
968 LINK_STATE link_state;
970 /* Copy Ioctl Buffer structure */
971 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) {
972 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
977 if (IoBuffer.OutputLength != sizeof(link_state)) {
982 memset(&link_state, 0, sizeof(link_state));
983 link_state.bIdleMode = Adapter->IdleMode;
984 link_state.bShutdownMode = Adapter->bShutStatus;
985 link_state.ucLinkStatus = Adapter->LinkStatus;
987 if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) {
988 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
992 Status = STATUS_SUCCESS;
996 case IOCTL_BCM_SET_MAC_TRACING: {
999 /* copy ioctl Buffer structure */
1000 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1003 if (copy_from_user(&tracing_flag, IoBuffer.InputBuffer, sizeof(UINT)))
1007 Adapter->pTarangs->MacTracingEnabled = TRUE;
1009 Adapter->pTarangs->MacTracingEnabled = FALSE;
1013 case IOCTL_BCM_GET_DSX_INDICATION: {
1015 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1018 if (IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt)) {
1019 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1020 "Mismatch req: %lx needed is =0x%zx!!!",
1021 IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
1025 if (copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1028 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId);
1029 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1030 Status = STATUS_SUCCESS;
1034 case IOCTL_BCM_GET_HOST_MIBS: {
1037 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1040 if (IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS)) {
1041 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1042 "Length Check failed %lu %zd\n",
1043 IoBuffer.OutputLength, sizeof(S_MIBS_HOST_STATS_MIBS));
1047 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1048 temp_buff = kzalloc(sizeof(S_MIBS_HOST_STATS_MIBS), GFP_KERNEL);
1050 return STATUS_FAILURE;
1052 Status = ProcessGetHostMibs(Adapter, temp_buff);
1053 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1055 if (Status != STATUS_FAILURE)
1056 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS)))
1063 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
1064 if ((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE == Adapter->IdleMode)) {
1065 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1066 Adapter->bWakeUpDevice = TRUE;
1067 wake_up(&Adapter->process_rx_cntrlpkt);
1070 Status = STATUS_SUCCESS;
1073 case IOCTL_BCM_BULK_WRM: {
1074 PBULKWRM_BUFFER pBulkBuffer;
1076 PCHAR pvBuffer = NULL;
1078 if ((Adapter->IdleMode == TRUE) ||
1079 (Adapter->bShutStatus == TRUE) ||
1080 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1082 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1087 /* Copy Ioctl Buffer structure */
1088 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1091 /* FIXME: restrict length */
1092 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
1096 /* Get WrmBuffer structure */
1097 if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
1103 pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
1105 if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1106 ((ULONG)pBulkBuffer->Register & 0x3)) {
1108 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer->Register);
1113 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1114 if (!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE) &&
1115 ((uiTempVar == EEPROM_REJECT_REG_1) ||
1116 (uiTempVar == EEPROM_REJECT_REG_2) ||
1117 (uiTempVar == EEPROM_REJECT_REG_3) ||
1118 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1119 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
1122 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
1127 if (pBulkBuffer->SwapEndian == FALSE)
1128 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1130 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
1132 if (Status != STATUS_SUCCESS)
1133 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1139 case IOCTL_BCM_GET_NVM_SIZE:
1140 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1143 if (Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH) {
1144 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1148 Status = STATUS_SUCCESS;
1151 case IOCTL_BCM_CAL_INIT: {
1152 UINT uiSectorSize = 0 ;
1153 if (Adapter->eNVMType == NVM_FLASH) {
1154 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1157 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1160 if ((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) {
1161 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1165 if (IsFlash2x(Adapter)) {
1166 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize, sizeof(UINT)))
1169 if ((TRUE == Adapter->bShutStatus) || (TRUE == Adapter->IdleMode)) {
1170 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is in Idle/Shutdown Mode\n");
1174 Adapter->uiSectorSize = uiSectorSize;
1175 BcmUpdateSectorSize(Adapter, Adapter->uiSectorSize);
1178 Status = STATUS_SUCCESS;
1180 Status = STATUS_FAILURE;
1185 case IOCTL_BCM_SET_DEBUG:
1188 USER_BCM_DBG_STATE sUserDebugState;
1190 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1191 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1194 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE)))
1197 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1198 sUserDebugState.OnOff, sUserDebugState.Type);
1199 /* sUserDebugState.Subtype <<= 1; */
1200 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
1201 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
1203 /* Update new 'DebugState' in the Adapter */
1204 Adapter->stDebugState.type |= sUserDebugState.Type;
1205 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1206 * Valid indexes in 'subtype' array: 1,2,4,8
1207 * corresponding to valid Type values. Hence we can use the 'Type' field
1208 * as the index value, ignoring the array entries 0,3,5,6,7 !
1210 if (sUserDebugState.OnOff)
1211 Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
1213 Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
1215 BCM_SHOW_DEBUG_BITMAP(Adapter);
1220 case IOCTL_BCM_NVM_READ:
1221 case IOCTL_BCM_NVM_WRITE: {
1222 NVM_READWRITE stNVMReadWrite;
1223 PUCHAR pReadData = NULL;
1224 ULONG ulDSDMagicNumInUsrBuff = 0;
1225 struct timeval tv0, tv1;
1226 memset(&tv0, 0, sizeof(struct timeval));
1227 memset(&tv1, 0, sizeof(struct timeval));
1228 if ((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0)) {
1229 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1234 if (IsFlash2x(Adapter)) {
1235 if ((Adapter->eActiveDSD != DSD0) &&
1236 (Adapter->eActiveDSD != DSD1) &&
1237 (Adapter->eActiveDSD != DSD2)) {
1239 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No DSD is active..hence NVM Command is blocked");
1240 return STATUS_FAILURE ;
1244 /* Copy Ioctl Buffer structure */
1245 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1248 if (copy_from_user(&stNVMReadWrite,
1249 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1250 sizeof(NVM_READWRITE)))
1254 * Deny the access if the offset crosses the cal area limit.
1257 if ((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) > Adapter->uiNVMDSDSize) {
1258 /* 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); */
1259 Status = STATUS_FAILURE;
1263 pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
1267 if (copy_from_user(pReadData, stNVMReadWrite.pBuffer, stNVMReadWrite.uiNumBytes)) {
1273 do_gettimeofday(&tv0);
1274 if (IOCTL_BCM_NVM_READ == cmd) {
1275 down(&Adapter->NVMRdmWrmLock);
1277 if ((Adapter->IdleMode == TRUE) ||
1278 (Adapter->bShutStatus == TRUE) ||
1279 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1281 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1282 up(&Adapter->NVMRdmWrmLock);
1287 Status = BeceemNVMRead(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
1288 up(&Adapter->NVMRdmWrmLock);
1290 if (Status != STATUS_SUCCESS) {
1295 if (copy_to_user(stNVMReadWrite.pBuffer, pReadData, stNVMReadWrite.uiNumBytes)) {
1300 down(&Adapter->NVMRdmWrmLock);
1302 if ((Adapter->IdleMode == TRUE) ||
1303 (Adapter->bShutStatus == TRUE) ||
1304 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1306 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1307 up(&Adapter->NVMRdmWrmLock);
1312 Adapter->bHeaderChangeAllowed = TRUE;
1313 if (IsFlash2x(Adapter)) {
1316 * DSD section updation will be allowed in two case:-
1317 * 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
1318 * 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
1319 * corrupted then user space program first modify the DSD header with valid DSD sig so
1320 * that this as well as further write may be worthwhile.
1322 * This restriction has been put assuming that if DSD sig is corrupted, DSD
1323 * data won't be considered valid.
1326 Status = BcmFlash2xCorruptSig(Adapter, Adapter->eActiveDSD);
1327 if (Status != STATUS_SUCCESS) {
1328 if (((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize) ||
1329 (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE)) {
1331 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1332 up(&Adapter->NVMRdmWrmLock);
1337 ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
1338 if (ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER) {
1339 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
1340 up(&Adapter->NVMRdmWrmLock);
1347 Status = BeceemNVMWrite(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
1348 if (IsFlash2x(Adapter))
1349 BcmFlash2xWriteSig(Adapter, Adapter->eActiveDSD);
1351 Adapter->bHeaderChangeAllowed = FALSE;
1353 up(&Adapter->NVMRdmWrmLock);
1355 if (Status != STATUS_SUCCESS) {
1361 do_gettimeofday(&tv1);
1362 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);
1365 Status = STATUS_SUCCESS;
1369 case IOCTL_BCM_FLASH2X_SECTION_READ: {
1370 FLASH2X_READWRITE sFlash2xRead = {0};
1371 PUCHAR pReadBuff = NULL ;
1375 UINT ReadOffset = 0;
1376 void __user *OutPutBuff;
1378 if (IsFlash2x(Adapter) != TRUE) {
1379 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1383 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1384 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1387 /* Reading FLASH 2.x READ structure */
1388 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
1391 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xRead.Section);
1392 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%x", sFlash2xRead.offset);
1393 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xRead.numOfBytes);
1394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xRead.bVerify);
1396 /* This was internal to driver for raw read. now it has ben exposed to user space app. */
1397 if (validateFlash2xReadWrite(Adapter, &sFlash2xRead) == FALSE)
1398 return STATUS_FAILURE;
1400 NOB = sFlash2xRead.numOfBytes;
1401 if (NOB > Adapter->uiSectorSize)
1402 BuffSize = Adapter->uiSectorSize;
1406 ReadOffset = sFlash2xRead.offset ;
1407 OutPutBuff = IoBuffer.OutputBuffer;
1408 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
1410 if (pReadBuff == NULL) {
1411 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1414 down(&Adapter->NVMRdmWrmLock);
1416 if ((Adapter->IdleMode == TRUE) ||
1417 (Adapter->bShutStatus == TRUE) ||
1418 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1420 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1421 up(&Adapter->NVMRdmWrmLock);
1427 if (NOB > Adapter->uiSectorSize)
1428 ReadBytes = Adapter->uiSectorSize;
1432 /* Reading the data from Flash 2.x */
1433 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pReadBuff, sFlash2xRead.Section, ReadOffset, ReadBytes);
1435 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Flash 2x read err with Status :%d", Status);
1439 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1441 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1443 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status);
1446 NOB = NOB - ReadBytes;
1448 ReadOffset = ReadOffset + ReadBytes;
1449 OutPutBuff = OutPutBuff + ReadBytes ;
1453 up(&Adapter->NVMRdmWrmLock);
1458 case IOCTL_BCM_FLASH2X_SECTION_WRITE: {
1459 FLASH2X_READWRITE sFlash2xWrite = {0};
1461 void __user *InputAddr;
1464 UINT WriteOffset = 0;
1465 UINT WriteBytes = 0;
1467 if (IsFlash2x(Adapter) != TRUE) {
1468 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1472 /* First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite */
1473 Adapter->bAllDSDWriteAllow = FALSE;
1475 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1477 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1480 /* Reading FLASH 2.x READ structure */
1481 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
1484 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xWrite.Section);
1485 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%d", sFlash2xWrite.offset);
1486 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite.numOfBytes);
1487 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite.bVerify);
1489 if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) && (sFlash2xWrite.Section != VSA2)) {
1490 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Only VSA write is allowed");
1494 if (validateFlash2xReadWrite(Adapter, &sFlash2xWrite) == FALSE)
1495 return STATUS_FAILURE;
1497 InputAddr = sFlash2xWrite.pDataBuff;
1498 WriteOffset = sFlash2xWrite.offset;
1499 NOB = sFlash2xWrite.numOfBytes;
1501 if (NOB > Adapter->uiSectorSize)
1502 BuffSize = Adapter->uiSectorSize;
1506 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1508 if (pWriteBuff == NULL)
1511 /* extracting the remainder of the given offset. */
1512 WriteBytes = Adapter->uiSectorSize;
1513 if (WriteOffset % Adapter->uiSectorSize)
1514 WriteBytes = Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
1516 if (NOB < WriteBytes)
1519 down(&Adapter->NVMRdmWrmLock);
1521 if ((Adapter->IdleMode == TRUE) ||
1522 (Adapter->bShutStatus == TRUE) ||
1523 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1525 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1526 up(&Adapter->NVMRdmWrmLock);
1531 BcmFlash2xCorruptSig(Adapter, sFlash2xWrite.Section);
1533 Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
1535 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status);
1538 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
1540 /* Writing the data from Flash 2.x */
1541 Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pWriteBuff, sFlash2xWrite.Section, WriteOffset, WriteBytes, sFlash2xWrite.bVerify);
1544 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1548 NOB = NOB - WriteBytes;
1550 WriteOffset = WriteOffset + WriteBytes;
1551 InputAddr = InputAddr + WriteBytes;
1552 if (NOB > Adapter->uiSectorSize)
1553 WriteBytes = Adapter->uiSectorSize;
1559 BcmFlash2xWriteSig(Adapter, sFlash2xWrite.Section);
1560 up(&Adapter->NVMRdmWrmLock);
1565 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP: {
1566 PFLASH2X_BITMAP psFlash2xBitMap;
1567 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1569 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1572 if (IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
1575 psFlash2xBitMap = kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
1576 if (psFlash2xBitMap == NULL) {
1577 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory is not available");
1581 /* Reading the Flash Sectio Bit map */
1582 down(&Adapter->NVMRdmWrmLock);
1584 if ((Adapter->IdleMode == TRUE) ||
1585 (Adapter->bShutStatus == TRUE) ||
1586 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1588 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1589 up(&Adapter->NVMRdmWrmLock);
1590 kfree(psFlash2xBitMap);
1594 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1595 up(&Adapter->NVMRdmWrmLock);
1596 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP)))
1599 kfree(psFlash2xBitMap);
1603 case IOCTL_BCM_SET_ACTIVE_SECTION: {
1604 FLASH2X_SECTION_VAL eFlash2xSectionVal = 0;
1605 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1607 if (IsFlash2x(Adapter) != TRUE) {
1608 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1612 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1614 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1618 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1620 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
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);
1635 Status = BcmSetActiveSection(Adapter, eFlash2xSectionVal);
1637 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Failed to make it's priority Highest. Status %d", Status);
1639 up(&Adapter->NVMRdmWrmLock);
1643 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION: {
1644 /* Right Now we are taking care of only DSD */
1645 Adapter->bAllDSDWriteAllow = FALSE;
1646 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1647 Status = STATUS_SUCCESS;
1651 case IOCTL_BCM_COPY_SECTION: {
1652 FLASH2X_COPY_SECTION sCopySectStrut = {0};
1653 Status = STATUS_SUCCESS;
1654 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
1656 Adapter->bAllDSDWriteAllow = FALSE;
1657 if (IsFlash2x(Adapter) != TRUE) {
1658 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1662 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1664 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
1668 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
1670 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
1674 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
1675 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
1676 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
1677 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
1679 if (IsSectionExistInFlash(Adapter, sCopySectStrut.SrcSection) == FALSE) {
1680 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
1684 if (IsSectionExistInFlash(Adapter, sCopySectStrut.DstSection) == FALSE) {
1685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
1689 if (sCopySectStrut.SrcSection == sCopySectStrut.DstSection) {
1690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source and Destination section should be different");
1694 down(&Adapter->NVMRdmWrmLock);
1696 if ((Adapter->IdleMode == TRUE) ||
1697 (Adapter->bShutStatus == TRUE) ||
1698 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1701 up(&Adapter->NVMRdmWrmLock);
1705 if (sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2) {
1706 if (IsNonCDLessDevice(Adapter)) {
1707 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is Non-CDLess hence won't have ISO !!");
1709 } else if (sCopySectStrut.numOfBytes == 0) {
1710 Status = BcmCopyISO(Adapter, sCopySectStrut);
1712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Partial Copy of ISO section is not Allowed..");
1713 Status = STATUS_FAILURE;
1715 up(&Adapter->NVMRdmWrmLock);
1719 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
1720 sCopySectStrut.DstSection, sCopySectStrut.offset, sCopySectStrut.numOfBytes);
1721 up(&Adapter->NVMRdmWrmLock);
1725 case IOCTL_BCM_GET_FLASH_CS_INFO: {
1726 Status = STATUS_SUCCESS;
1727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
1729 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1735 if (Adapter->eNVMType != NVM_FLASH) {
1736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Connected device does not have flash");
1741 if (IsFlash2x(Adapter) == TRUE) {
1742 if (IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
1745 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO)))
1748 if (IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
1751 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO)))
1757 case IOCTL_BCM_SELECT_DSD: {
1759 FLASH2X_SECTION_VAL eFlash2xSectionVal;
1760 eFlash2xSectionVal = NO_SECTION_VAL;
1761 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SELECT_DSD Called");
1763 if (IsFlash2x(Adapter) != TRUE) {
1764 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
1768 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1770 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1773 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
1775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1779 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal);
1780 if ((eFlash2xSectionVal != DSD0) &&
1781 (eFlash2xSectionVal != DSD1) &&
1782 (eFlash2xSectionVal != DSD2)) {
1784 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Passed section<%x> is not DSD section", eFlash2xSectionVal);
1785 return STATUS_FAILURE;
1788 SectOfset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
1789 if (SectOfset == INVALID_OFFSET) {
1790 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
1794 Adapter->bAllDSDWriteAllow = TRUE;
1795 Adapter->ulFlashCalStart = SectOfset;
1796 Adapter->eActiveDSD = eFlash2xSectionVal;
1798 Status = STATUS_SUCCESS;
1801 case IOCTL_BCM_NVM_RAW_READ: {
1802 NVM_READWRITE stNVMRead;
1806 UINT ReadBytes = 0 ;
1808 void __user *OutPutBuff;
1810 if (Adapter->eNVMType != NVM_FLASH) {
1811 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "NVM TYPE is not Flash");
1815 /* Copy Ioctl Buffer structure */
1816 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) {
1817 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
1822 if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(NVM_READWRITE)))
1825 NOB = stNVMRead.uiNumBytes;
1826 /* In Raw-Read max Buff size : 64MB */
1828 if (NOB > DEFAULT_BUFF_SIZE)
1829 BuffSize = DEFAULT_BUFF_SIZE;
1833 ReadOffset = stNVMRead.uiOffset;
1834 OutPutBuff = stNVMRead.pBuffer;
1836 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
1837 if (pReadBuff == NULL) {
1838 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
1842 down(&Adapter->NVMRdmWrmLock);
1844 if ((Adapter->IdleMode == TRUE) ||
1845 (Adapter->bShutStatus == TRUE) ||
1846 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1848 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
1850 up(&Adapter->NVMRdmWrmLock);
1854 Adapter->bFlashRawRead = TRUE;
1857 if (NOB > DEFAULT_BUFF_SIZE)
1858 ReadBytes = DEFAULT_BUFF_SIZE;
1862 /* Reading the data from Flash 2.x */
1863 Status = BeceemNVMRead(Adapter, (PUINT)pReadBuff, ReadOffset, ReadBytes);
1865 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
1869 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
1871 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1873 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status);
1876 NOB = NOB - ReadBytes;
1878 ReadOffset = ReadOffset + ReadBytes;
1879 OutPutBuff = OutPutBuff + ReadBytes;
1882 Adapter->bFlashRawRead = FALSE;
1883 up(&Adapter->NVMRdmWrmLock);
1888 case IOCTL_BCM_CNTRLMSG_MASK: {
1889 ULONG RxCntrlMsgBitMask = 0;
1891 /* Copy Ioctl Buffer structure */
1892 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
1894 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space");
1899 if (IoBuffer.InputLength != sizeof(unsigned long)) {
1904 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
1906 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space");
1910 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
1911 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;
1915 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO: {
1916 DEVICE_DRIVER_INFO DevInfo;
1918 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
1920 DevInfo.MaxRDMBufferSize = BUFFER_4K;
1921 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
1922 DevInfo.u32RxAlignmentCorrection = 0;
1923 DevInfo.u32NVMType = Adapter->eNVMType;
1924 DevInfo.u32InterfaceType = BCM_USB;
1926 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1929 if (IoBuffer.OutputLength < sizeof(DevInfo))
1932 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
1937 case IOCTL_BCM_TIME_SINCE_NET_ENTRY: {
1938 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
1940 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
1942 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1945 if (IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
1948 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
1950 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED)))
1955 case IOCTL_CLOSE_NOTIFICATION:
1956 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_CLOSE_NOTIFICATION");
1960 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
1961 Status = STATUS_FAILURE;
1968 static const struct file_operations bcm_fops = {
1969 .owner = THIS_MODULE,
1970 .open = bcm_char_open,
1971 .release = bcm_char_release,
1972 .read = bcm_char_read,
1973 .unlocked_ioctl = bcm_char_ioctl,
1974 .llseek = no_llseek,
1977 int register_control_device_interface(PMINI_ADAPTER Adapter)
1980 if (Adapter->major > 0)
1981 return Adapter->major;
1983 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
1984 if (Adapter->major < 0) {
1985 pr_err(DRV_NAME ": could not created character device\n");
1986 return Adapter->major;
1989 Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
1990 MKDEV(Adapter->major, 0),
1993 if (IS_ERR(Adapter->pstCreatedClassDevice)) {
1994 pr_err(DRV_NAME ": class device create failed\n");
1995 unregister_chrdev(Adapter->major, DEV_NAME);
1996 return PTR_ERR(Adapter->pstCreatedClassDevice);
2002 void unregister_control_device_interface(PMINI_ADAPTER Adapter)
2004 if (Adapter->major > 0) {
2005 device_destroy(bcm_class, MKDEV(Adapter->major, 0));
2006 unregister_chrdev(Adapter->major, DEV_NAME);