staging/bcm: move IOCTL_BCM_EEPROM_REGISTER_READ case out to its own function.
[cascardo/linux.git] / drivers / staging / bcm / Bcmchar.c
index f1b6de0..fcb19ea 100644 (file)
@@ -150,6 +150,166 @@ static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
        return PktLen;
 }
 
+static int bcm_char_ioctl_reg_read_private(void __user *argp, struct bcm_mini_adapter *Adapter)
+{
+       struct bcm_rdm_buffer sRdmBuffer = {0};
+       struct bcm_ioctl_buffer IoBuffer;
+       PCHAR temp_buff;
+       INT Status = STATUS_FAILURE;
+       UINT Bufflen;
+       u16 temp_value;
+       int bytes;
+
+       /* Copy Ioctl Buffer structure */
+       if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
+               return -EFAULT;
+
+       if (IoBuffer.InputLength > sizeof(sRdmBuffer))
+               return -EINVAL;
+
+       if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
+               return -EFAULT;
+
+       if (IoBuffer.OutputLength > USHRT_MAX ||
+               IoBuffer.OutputLength == 0) {
+               return -EINVAL;
+       }
+
+       Bufflen = IoBuffer.OutputLength;
+       temp_value = 4 - (Bufflen % 4);
+       Bufflen += temp_value % 4;
+
+       temp_buff = kmalloc(Bufflen, GFP_KERNEL);
+       if (!temp_buff)
+               return -ENOMEM;
+
+       bytes = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
+                       (PUINT)temp_buff, Bufflen);
+       if (bytes > 0) {
+               Status = STATUS_SUCCESS;
+               if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
+                       kfree(temp_buff);
+                       return -EFAULT;
+               }
+       } else {
+               Status = bytes;
+       }
+
+       kfree(temp_buff);
+       return Status;
+}
+
+static int bcm_char_ioctl_reg_write_private(void __user *argp, struct bcm_mini_adapter *Adapter)
+{
+       struct bcm_wrm_buffer sWrmBuffer = {0};
+       struct bcm_ioctl_buffer IoBuffer;
+       UINT uiTempVar = 0;
+       INT Status;
+
+       /* 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;
+
+       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))) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
+                               "EEPROM Access Denied, not in VSG Mode\n");
+               return -EFAULT;
+       }
+
+       Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
+                       (PUINT)sWrmBuffer.Data, sizeof(ULONG));
+
+       if (Status == STATUS_SUCCESS) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, 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_eeprom_reg_read(void __user *argp, struct bcm_mini_adapter *Adapter)
+{
+       struct bcm_rdm_buffer sRdmBuffer = {0};
+       struct bcm_ioctl_buffer IoBuffer;
+       PCHAR temp_buff = NULL;
+       UINT uiTempVar = 0;
+       INT Status;
+       int bytes;
+
+       if ((Adapter->IdleMode == TRUE) ||
+               (Adapter->bShutStatus == TRUE) ||
+               (Adapter->bPreparingForLowPowerMode == TRUE)) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
+                               "Device in Idle Mode, Blocking Rdms\n");
+               return -EACCES;
+       }
+
+       /* Copy Ioctl Buffer structure */
+       if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
+               return -EFAULT;
+
+       if (IoBuffer.InputLength > sizeof(sRdmBuffer))
+               return -EINVAL;
+
+       if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
+               return -EFAULT;
+
+       if (IoBuffer.OutputLength > USHRT_MAX ||
+               IoBuffer.OutputLength == 0) {
+               return -EINVAL;
+       }
+
+       temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
+       if (!temp_buff)
+               return STATUS_FAILURE;
+
+       if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
+               ((ULONG)sRdmBuffer.Register & 0x3)) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
+                               "RDM Done On invalid Address : %x Access Denied.\n",
+                               (int)sRdmBuffer.Register);
+
+               kfree(temp_buff);
+               return -EINVAL;
+       }
+
+       uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
+       bytes = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
+                              (PUINT)temp_buff, IoBuffer.OutputLength);
+
+       if (bytes > 0) {
+               Status = STATUS_SUCCESS;
+               if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
+                       kfree(temp_buff);
+                       return -EFAULT;
+               }
+       } else {
+               Status = bytes;
+       }
+
+       kfree(temp_buff);
+       return Status;
+}
+
 static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
 {
        struct bcm_tarang_data *pTarang = filp->private_data;
@@ -201,153 +361,19 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
 
        switch (cmd) {
        /* Rdms for Swin Idle... */
-       case IOCTL_BCM_REGISTER_READ_PRIVATE: {
-               struct bcm_rdm_buffer sRdmBuffer = {0};
-               PCHAR temp_buff;
-               UINT Bufflen;
-               u16 temp_value;
-
-               /* Copy Ioctl Buffer structure */
-               if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
-                       return -EFAULT;
-
-               if (IoBuffer.InputLength > sizeof(sRdmBuffer))
-                       return -EINVAL;
-
-               if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
-                       return -EFAULT;
-
-               if (IoBuffer.OutputLength > USHRT_MAX ||
-                       IoBuffer.OutputLength == 0) {
-                       return -EINVAL;
-               }
-
-               Bufflen = IoBuffer.OutputLength;
-               temp_value = 4 - (Bufflen % 4);
-               Bufflen += temp_value % 4;
-
-               temp_buff = kmalloc(Bufflen, GFP_KERNEL);
-               if (!temp_buff)
-                       return -ENOMEM;
-
-               bytes = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
-                               (PUINT)temp_buff, Bufflen);
-               if (bytes > 0) {
-                       Status = STATUS_SUCCESS;
-                       if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
-                               kfree(temp_buff);
-                               return -EFAULT;
-                       }
-               } else {
-                       Status = bytes;
-               }
-
-               kfree(temp_buff);
-               break;
-       }
-
-       case IOCTL_BCM_REGISTER_WRITE_PRIVATE: {
-               struct bcm_wrm_buffer sWrmBuffer = {0};
-               UINT uiTempVar = 0;
-               /* 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;
-
-               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))) {
-
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
-                                       "EEPROM Access Denied, not in VSG Mode\n");
-                       return -EFAULT;
-               }
-
-               Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
-                               (PUINT)sWrmBuffer.Data, sizeof(ULONG));
+       case IOCTL_BCM_REGISTER_READ_PRIVATE:
+               Status = bcm_char_ioctl_reg_read_private(argp, Adapter);
+               return Status;
 
-               if (Status == STATUS_SUCCESS) {
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, 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_REGISTER_WRITE_PRIVATE:
+               Status = bcm_char_ioctl_reg_write_private(argp, Adapter);
+               return Status;
 
        case IOCTL_BCM_REGISTER_READ:
-       case IOCTL_BCM_EEPROM_REGISTER_READ: {
-               struct bcm_rdm_buffer sRdmBuffer = {0};
-               PCHAR temp_buff = NULL;
-               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 Rdms\n");
-                       return -EACCES;
-               }
-
-               /* Copy Ioctl Buffer structure */
-               if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
-                       return -EFAULT;
-
-               if (IoBuffer.InputLength > sizeof(sRdmBuffer))
-                       return -EINVAL;
-
-               if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
-                       return -EFAULT;
-
-               if (IoBuffer.OutputLength > USHRT_MAX ||
-                       IoBuffer.OutputLength == 0) {
-                       return -EINVAL;
-               }
-
-               temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
-               if (!temp_buff)
-                       return STATUS_FAILURE;
-
-               if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
-                       ((ULONG)sRdmBuffer.Register & 0x3)) {
-
-                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
-                                       "RDM Done On invalid Address : %x Access Denied.\n",
-                                       (int)sRdmBuffer.Register);
-
-                       kfree(temp_buff);
-                       return -EINVAL;
-               }
-
-               uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
-               bytes = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
-                                      (PUINT)temp_buff, IoBuffer.OutputLength);
-
-               if (bytes > 0) {
-                       Status = STATUS_SUCCESS;
-                       if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
-                               kfree(temp_buff);
-                               return -EFAULT;
-                       }
-               } else {
-                       Status = bytes;
-               }
+       case IOCTL_BCM_EEPROM_REGISTER_READ:
+               Status = bcm_char_ioctl_eeprom_reg_read(argp, Adapter);
+               return Status;
 
-               kfree(temp_buff);
-               break;
-       }
        case IOCTL_BCM_REGISTER_WRITE:
        case IOCTL_BCM_EEPROM_REGISTER_WRITE: {
                struct bcm_wrm_buffer sWrmBuffer = {0};