staging/bcm: move BCM_LED_THREAD_STATE_CHANGE_REQ case out to its own function.
[cascardo/linux.git] / drivers / staging / bcm / Bcmchar.c
index fcb19ea..c0b2997 100644 (file)
@@ -310,6 +310,226 @@ static int bcm_char_ioctl_eeprom_reg_read(void __user *argp, struct bcm_mini_ada
        return Status;
 }
 
+static int bcm_char_ioctl_eeprom_reg_write(void __user *argp, struct bcm_mini_adapter *Adapter, UINT cmd)
+{
+       struct bcm_wrm_buffer sWrmBuffer = {0};
+       struct bcm_ioctl_buffer IoBuffer;
+       UINT uiTempVar = 0;
+       INT Status;
+
+       if ((Adapter->IdleMode == TRUE) ||
+               (Adapter->bShutStatus == TRUE) ||
+               (Adapter->bPreparingForLowPowerMode == TRUE)) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
+                               "Device in Idle Mode, Blocking Wrms\n");
+               return -EACCES;
+       }
+
+       /* Copy Ioctl Buffer structure */
+       if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
+               return -EFAULT;
+
+       if (IoBuffer.InputLength > sizeof(sWrmBuffer))
+               return -EINVAL;
+
+       /* Get WrmBuffer structure */
+       if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
+               return -EFAULT;
+
+       if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
+               ((ULONG)sWrmBuffer.Register & 0x3)) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
+                               "WRM Done On invalid Address : %x Access Denied.\n",
+                               (int)sWrmBuffer.Register);
+               return -EINVAL;
+       }
+
+       uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
+       if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
+                       ((uiTempVar == EEPROM_REJECT_REG_1) ||
+                       (uiTempVar == EEPROM_REJECT_REG_2) ||
+                       (uiTempVar == EEPROM_REJECT_REG_3) ||
+                       (uiTempVar == EEPROM_REJECT_REG_4)) &&
+                       (cmd == IOCTL_BCM_REGISTER_WRITE)) {
+
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
+                                       "EEPROM Access Denied, not in VSG Mode\n");
+                       return -EFAULT;
+       }
+
+       Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
+                               (PUINT)sWrmBuffer.Data,
+                               sWrmBuffer.Length);
+
+       if (Status == STATUS_SUCCESS) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG,
+                               DBG_LVL_ALL, "WRM Done\n");
+       } else {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
+                               DBG_LVL_ALL, "WRM Failed\n");
+               Status = -EFAULT;
+       }
+       return Status;
+}
+
+static int bcm_char_ioctl_gpio_set_request(void __user *argp, struct bcm_mini_adapter *Adapter)
+{
+       struct bcm_gpio_info gpio_info = {0};
+       struct bcm_ioctl_buffer IoBuffer;
+       UCHAR ucResetValue[4];
+       UINT value = 0;
+       UINT uiBit = 0;
+       UINT uiOperation = 0;
+       INT Status;
+       int bytes;
+
+       if ((Adapter->IdleMode == TRUE) ||
+               (Adapter->bShutStatus == TRUE) ||
+               (Adapter->bPreparingForLowPowerMode == TRUE)) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
+                               DBG_LVL_ALL,
+                               "GPIO Can't be set/clear in Low power Mode");
+               return -EACCES;
+       }
+
+       if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
+               return -EFAULT;
+
+       if (IoBuffer.InputLength > sizeof(gpio_info))
+               return -EINVAL;
+
+       if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
+               return -EFAULT;
+
+       uiBit  = gpio_info.uiGpioNumber;
+       uiOperation = gpio_info.uiGpioValue;
+       value = (1<<uiBit);
+
+       if (IsReqGpioIsLedInNVM(Adapter, value) == false) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
+                               DBG_LVL_ALL,
+                               "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",
+                               value);
+               return -EINVAL;
+       }
+
+       /* Set - setting 1 */
+       if (uiOperation) {
+               /* Set the gpio output register */
+               Status = wrmaltWithLock(Adapter,
+                                       BCM_GPIO_OUTPUT_SET_REG,
+                                       (PUINT)(&value), sizeof(UINT));
+
+               if (Status == STATUS_SUCCESS) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
+                                       OSAL_DBG, DBG_LVL_ALL,
+                                       "Set the GPIO bit\n");
+               } else {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
+                                       OSAL_DBG, DBG_LVL_ALL,
+                                       "Failed to set the %dth GPIO\n",
+                                       uiBit);
+                       return Status;
+               }
+       } else {
+               /* Set the gpio output register */
+               Status = wrmaltWithLock(Adapter,
+                                       BCM_GPIO_OUTPUT_CLR_REG,
+                                       (PUINT)(&value), sizeof(UINT));
+
+               if (Status == STATUS_SUCCESS) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
+                                       OSAL_DBG, DBG_LVL_ALL,
+                                       "Set the GPIO bit\n");
+               } else {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
+                                       OSAL_DBG, DBG_LVL_ALL,
+                                       "Failed to clear the %dth GPIO\n",
+                                       uiBit);
+                       return Status;
+               }
+       }
+
+       bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
+                              (PUINT)ucResetValue, sizeof(UINT));
+       if (bytes < 0) {
+               Status = bytes;
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
+                               "GPIO_MODE_REGISTER read failed");
+               return Status;
+       } else {
+               Status = STATUS_SUCCESS;
+       }
+
+       /* Set the gpio mode register to output */
+       *(UINT *)ucResetValue |= (1<<uiBit);
+       Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
+                               (PUINT)ucResetValue, sizeof(UINT));
+
+       if (Status == STATUS_SUCCESS) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
+                               DBG_LVL_ALL,
+                               "Set the GPIO to output Mode\n");
+       } else {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
+                               DBG_LVL_ALL,
+                               "Failed to put GPIO in Output Mode\n");
+       }
+
+       return Status;
+}
+
+static int bcm_char_ioctl_led_thread_state_change_req(void __user *argp, struct bcm_mini_adapter *Adapter)
+{
+       struct bcm_user_thread_req threadReq = {0};
+       struct bcm_ioctl_buffer IoBuffer;
+
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
+                       "User made LED thread InActive");
+
+       if ((Adapter->IdleMode == TRUE) ||
+               (Adapter->bShutStatus == TRUE) ||
+               (Adapter->bPreparingForLowPowerMode == TRUE)) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
+                               DBG_LVL_ALL,
+                               "GPIO Can't be set/clear in Low power Mode");
+               return -EACCES;
+       }
+
+       if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
+               return -EFAULT;
+
+       if (IoBuffer.InputLength > sizeof(threadReq))
+               return -EINVAL;
+
+       if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
+               return -EFAULT;
+
+       /* if LED thread is running(Actively or Inactively) set it state to make inactive */
+       if (Adapter->LEDInfo.led_thread_running) {
+               if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
+                                       OSAL_DBG, DBG_LVL_ALL,
+                                       "Activating thread req");
+                       Adapter->DriverState = LED_THREAD_ACTIVE;
+               } else {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
+                                       OSAL_DBG, DBG_LVL_ALL,
+                                       "DeActivating Thread req.....");
+                       Adapter->DriverState = LED_THREAD_INACTIVE;
+               }
+
+               /* signal thread. */
+               wake_up(&Adapter->LEDInfo.notify_led_event);
+       }
+       return STATUS_SUCCESS;
+}
+
+
 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
 {
        struct bcm_tarang_data *pTarang = filp->private_data;
@@ -375,215 +595,17 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
                return Status;
 
        case IOCTL_BCM_REGISTER_WRITE:
-       case IOCTL_BCM_EEPROM_REGISTER_WRITE: {
-               struct bcm_wrm_buffer sWrmBuffer = {0};
-               UINT uiTempVar = 0;
-
-               if ((Adapter->IdleMode == TRUE) ||
-                       (Adapter->bShutStatus == TRUE) ||
-                       (Adapter->bPreparingForLowPowerMode == TRUE)) {
-
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
-                                       "Device in Idle Mode, Blocking Wrms\n");
-                       return -EACCES;
-               }
-
-               /* Copy Ioctl Buffer structure */
-               if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
-                       return -EFAULT;
-
-               if (IoBuffer.InputLength > sizeof(sWrmBuffer))
-                       return -EINVAL;
-
-               /* Get WrmBuffer structure */
-               if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
-                       return -EFAULT;
-
-               if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
-                       ((ULONG)sWrmBuffer.Register & 0x3)) {
-
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
-                                       "WRM Done On invalid Address : %x Access Denied.\n",
-                                       (int)sWrmBuffer.Register);
-                       return -EINVAL;
-               }
-
-               uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
-               if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
-                               ((uiTempVar == EEPROM_REJECT_REG_1) ||
-                               (uiTempVar == EEPROM_REJECT_REG_2) ||
-                               (uiTempVar == EEPROM_REJECT_REG_3) ||
-                               (uiTempVar == EEPROM_REJECT_REG_4)) &&
-                               (cmd == IOCTL_BCM_REGISTER_WRITE)) {
-
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
-                                               "EEPROM Access Denied, not in VSG Mode\n");
-                               return -EFAULT;
-               }
-
-               Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
-                                       (PUINT)sWrmBuffer.Data,
-                                       sWrmBuffer.Length);
-
-               if (Status == STATUS_SUCCESS) {
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG,
-                                       DBG_LVL_ALL, "WRM Done\n");
-               } else {
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
-                                       DBG_LVL_ALL, "WRM Failed\n");
-                       Status = -EFAULT;
-               }
-               break;
-       }
-       case IOCTL_BCM_GPIO_SET_REQUEST: {
-               UCHAR ucResetValue[4];
-               UINT value = 0;
-               UINT uiBit = 0;
-               UINT uiOperation = 0;
-               struct bcm_gpio_info gpio_info = {0};
-
-               if ((Adapter->IdleMode == TRUE) ||
-                       (Adapter->bShutStatus == TRUE) ||
-                       (Adapter->bPreparingForLowPowerMode == TRUE)) {
-
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
-                                       DBG_LVL_ALL,
-                                       "GPIO Can't be set/clear in Low power Mode");
-                       return -EACCES;
-               }
-
-               if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
-                       return -EFAULT;
-
-               if (IoBuffer.InputLength > sizeof(gpio_info))
-                       return -EINVAL;
-
-               if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
-                       return -EFAULT;
-
-               uiBit  = gpio_info.uiGpioNumber;
-               uiOperation = gpio_info.uiGpioValue;
-               value = (1<<uiBit);
-
-               if (IsReqGpioIsLedInNVM(Adapter, value) == false) {
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
-                                       DBG_LVL_ALL,
-                                       "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",
-                                       value);
-                       Status = -EINVAL;
-                       break;
-               }
-
-               /* Set - setting 1 */
-               if (uiOperation) {
-                       /* Set the gpio output register */
-                       Status = wrmaltWithLock(Adapter,
-                                               BCM_GPIO_OUTPUT_SET_REG,
-                                               (PUINT)(&value), sizeof(UINT));
-
-                       if (Status == STATUS_SUCCESS) {
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
-                                               OSAL_DBG, DBG_LVL_ALL,
-                                               "Set the GPIO bit\n");
-                       } else {
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
-                                               OSAL_DBG, DBG_LVL_ALL,
-                                               "Failed to set the %dth GPIO\n",
-                                               uiBit);
-                               break;
-                       }
-               } else {
-                       /* Set the gpio output register */
-                       Status = wrmaltWithLock(Adapter,
-                                               BCM_GPIO_OUTPUT_CLR_REG,
-                                               (PUINT)(&value), sizeof(UINT));
-
-                       if (Status == STATUS_SUCCESS) {
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
-                                               OSAL_DBG, DBG_LVL_ALL,
-                                               "Set the GPIO bit\n");
-                       } else {
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
-                                               OSAL_DBG, DBG_LVL_ALL,
-                                               "Failed to clear the %dth GPIO\n",
-                                               uiBit);
-                               break;
-                       }
-               }
-
-               bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
-                                      (PUINT)ucResetValue, sizeof(UINT));
-               if (bytes < 0) {
-                       Status = bytes;
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
-                                       "GPIO_MODE_REGISTER read failed");
-                       break;
-               } else {
-                       Status = STATUS_SUCCESS;
-               }
-
-               /* Set the gpio mode register to output */
-               *(UINT *)ucResetValue |= (1<<uiBit);
-               Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
-                                       (PUINT)ucResetValue, sizeof(UINT));
-
-               if (Status == STATUS_SUCCESS) {
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
-                                       DBG_LVL_ALL,
-                                       "Set the GPIO to output Mode\n");
-               } else {
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
-                                       DBG_LVL_ALL,
-                                       "Failed to put GPIO in Output Mode\n");
-                       break;
-               }
-       }
-       break;
-
-       case BCM_LED_THREAD_STATE_CHANGE_REQ: {
-               struct bcm_user_thread_req threadReq = {0};
-               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
-                               "User made LED thread InActive");
-
-               if ((Adapter->IdleMode == TRUE) ||
-                       (Adapter->bShutStatus == TRUE) ||
-                       (Adapter->bPreparingForLowPowerMode == TRUE)) {
-
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
-                                       DBG_LVL_ALL,
-                                       "GPIO Can't be set/clear in Low power Mode");
-                       Status = -EACCES;
-                       break;
-               }
-
-               if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
-                       return -EFAULT;
-
-               if (IoBuffer.InputLength > sizeof(threadReq))
-                       return -EINVAL;
-
-               if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
-                       return -EFAULT;
+       case IOCTL_BCM_EEPROM_REGISTER_WRITE:
+               Status = bcm_char_ioctl_eeprom_reg_write(argp, Adapter, cmd);
+               return Status;
 
-               /* if LED thread is running(Actively or Inactively) set it state to make inactive */
-               if (Adapter->LEDInfo.led_thread_running) {
-                       if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
-                                               OSAL_DBG, DBG_LVL_ALL,
-                                               "Activating thread req");
-                               Adapter->DriverState = LED_THREAD_ACTIVE;
-                       } else {
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
-                                               OSAL_DBG, DBG_LVL_ALL,
-                                               "DeActivating Thread req.....");
-                               Adapter->DriverState = LED_THREAD_INACTIVE;
-                       }
+       case IOCTL_BCM_GPIO_SET_REQUEST:
+               Status = bcm_char_ioctl_gpio_set_request(argp, Adapter);
+               return Status;
 
-                       /* signal thread. */
-                       wake_up(&Adapter->LEDInfo.notify_led_event);
-               }
-       }
-       break;
+       case BCM_LED_THREAD_STATE_CHANGE_REQ:
+               Status = bcm_char_ioctl_led_thread_state_change_req(argp, Adapter);
+               return Status;
 
        case IOCTL_BCM_GPIO_STATUS_REQUEST: {
                ULONG uiBit = 0;