diff options
Diffstat (limited to 'drivers/staging/vt6656/main_usb.c')
-rw-r--r-- | drivers/staging/vt6656/main_usb.c | 230 |
1 files changed, 141 insertions, 89 deletions
diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index ccafcc2c87ac..856ba97aec4f 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -109,33 +109,38 @@ static void vnt_set_options(struct vnt_private *priv) */ static int vnt_init_registers(struct vnt_private *priv) { + int ret = 0; struct vnt_cmd_card_init *init_cmd = &priv->init_command; struct vnt_rsp_card_init *init_rsp = &priv->init_response; u8 antenna; int ii; - int status = STATUS_SUCCESS; u8 tmp; u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0; dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n", DEVICE_INIT_COLD, priv->packet_type); - if (!vnt_check_firmware_version(priv)) { - if (vnt_download_firmware(priv) == true) { - if (vnt_firmware_branch_to_sram(priv) == false) { - dev_dbg(&priv->usb->dev, - " vnt_firmware_branch_to_sram fail\n"); - return false; - } - } else { - dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n"); - return false; + ret = vnt_check_firmware_version(priv); + if (ret) { + ret = vnt_download_firmware(priv); + if (ret) { + dev_dbg(&priv->usb->dev, + "Could not download firmware: %d.\n", ret); + goto end; + } + + ret = vnt_firmware_branch_to_sram(priv); + if (ret) { + dev_dbg(&priv->usb->dev, + "Could not branch to SRAM: %d.\n", ret); + goto end; } } - if (!vnt_vt3184_init(priv)) { + ret = vnt_vt3184_init(priv); + if (ret) { dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n"); - return false; + goto end; } init_cmd->init_class = DEVICE_INIT_COLD; @@ -146,28 +151,27 @@ static int vnt_init_registers(struct vnt_private *priv) init_cmd->long_retry_limit = priv->long_retry_limit; /* issue card_init command to device */ - status = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0, - sizeof(struct vnt_cmd_card_init), - (u8 *)init_cmd); - if (status != STATUS_SUCCESS) { + ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0, + sizeof(struct vnt_cmd_card_init), + (u8 *)init_cmd); + if (ret) { dev_dbg(&priv->usb->dev, "Issue Card init fail\n"); - return false; + goto end; } - status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0, - sizeof(struct vnt_rsp_card_init), - (u8 *)init_rsp); - if (status != STATUS_SUCCESS) { - dev_dbg(&priv->usb->dev, - "Cardinit request in status fail!\n"); - return false; + ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0, + sizeof(struct vnt_rsp_card_init), + (u8 *)init_rsp); + if (ret) { + dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n"); + goto end; } /* local ID for AES functions */ - status = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID, - MESSAGE_REQUEST_MACREG, 1, &priv->local_id); - if (status != STATUS_SUCCESS) - return false; + ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID, + MESSAGE_REQUEST_MACREG, 1, &priv->local_id); + if (ret) + goto end; /* do MACbSoftwareReset in MACvInitialize */ @@ -253,7 +257,9 @@ static int vnt_init_registers(struct vnt_private *priv) } /* Set initial antenna mode */ - vnt_set_antenna_mode(priv, priv->rx_antenna_mode); + ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode); + if (ret) + goto end; /* get Auto Fall Back type */ priv->auto_fb_ctrl = AUTO_FB_0; @@ -275,33 +281,41 @@ static int vnt_init_registers(struct vnt_private *priv) /* CR255, enable TX/RX IQ and * DC compensation mode */ - vnt_control_out_u8(priv, - MESSAGE_REQUEST_BBREG, - 0xff, - 0x03); + ret = vnt_control_out_u8(priv, + MESSAGE_REQUEST_BBREG, + 0xff, 0x03); + if (ret) + goto end; + /* CR251, TX I/Q Imbalance Calibration */ - vnt_control_out_u8(priv, - MESSAGE_REQUEST_BBREG, - 0xfb, - calib_tx_iq); + ret = vnt_control_out_u8(priv, + MESSAGE_REQUEST_BBREG, + 0xfb, calib_tx_iq); + if (ret) + goto end; + /* CR252, TX DC-Offset Calibration */ - vnt_control_out_u8(priv, - MESSAGE_REQUEST_BBREG, - 0xfC, - calib_tx_dc); + ret = vnt_control_out_u8(priv, + MESSAGE_REQUEST_BBREG, + 0xfC, calib_tx_dc); + if (ret) + goto end; + /* CR253, RX I/Q Imbalance Calibration */ - vnt_control_out_u8(priv, - MESSAGE_REQUEST_BBREG, - 0xfd, - calib_rx_iq); + ret = vnt_control_out_u8(priv, + MESSAGE_REQUEST_BBREG, + 0xfd, calib_rx_iq); + if (ret) + goto end; } else { /* CR255, turn off * BB Calibration compensation */ - vnt_control_out_u8(priv, - MESSAGE_REQUEST_BBREG, - 0xff, - 0x0); + ret = vnt_control_out_u8(priv, + MESSAGE_REQUEST_BBREG, + 0xff, 0x0); + if (ret) + goto end; } } } @@ -323,37 +337,52 @@ static int vnt_init_registers(struct vnt_private *priv) else priv->short_slot_time = false; - vnt_set_short_slot_time(priv); + ret = vnt_set_short_slot_time(priv); + if (ret) + goto end; priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL]; if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) { - status = vnt_control_in(priv, MESSAGE_TYPE_READ, - MAC_REG_GPIOCTL1, - MESSAGE_REQUEST_MACREG, 1, &tmp); - - if (status != STATUS_SUCCESS) - return false; + ret = vnt_control_in(priv, MESSAGE_TYPE_READ, + MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, + 1, &tmp); + if (ret) + goto end; + + if ((tmp & GPIO3_DATA) == 0) { + ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, + GPIO3_INTMD); + } else { + ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, + GPIO3_INTMD); + } - if ((tmp & GPIO3_DATA) == 0) - vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, - GPIO3_INTMD); - else - vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, - GPIO3_INTMD); + if (ret) + goto end; } - vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38); - vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW); + ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38); + if (ret) + goto end; + + ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW); + if (ret) + goto end; - vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01); + ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01); + if (ret) + goto end; - vnt_radio_power_on(priv); + ret = vnt_radio_power_on(priv); + if (ret) + goto end; dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n"); - return true; +end: + return ret; } static void vnt_free_tx_bufs(struct vnt_private *priv) @@ -363,6 +392,9 @@ static void vnt_free_tx_bufs(struct vnt_private *priv) for (ii = 0; ii < priv->num_tx_context; ii++) { tx_context = priv->tx_context[ii]; + if (!tx_context) + continue; + /* deallocate URBs */ if (tx_context->urb) { usb_kill_urb(tx_context->urb); @@ -402,16 +434,19 @@ static void vnt_free_int_bufs(struct vnt_private *priv) kfree(priv->int_buf.data_buf); } -static bool vnt_alloc_bufs(struct vnt_private *priv) +static int vnt_alloc_bufs(struct vnt_private *priv) { + int ret = 0; struct vnt_usb_send_context *tx_context; struct vnt_rcb *rcb; int ii; for (ii = 0; ii < priv->num_tx_context; ii++) { tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL); - if (!tx_context) + if (!tx_context) { + ret = -ENOMEM; goto free_tx; + } priv->tx_context[ii] = tx_context; tx_context->priv = priv; @@ -419,16 +454,20 @@ static bool vnt_alloc_bufs(struct vnt_private *priv) /* allocate URBs */ tx_context->urb = usb_alloc_urb(0, GFP_KERNEL); - if (!tx_context->urb) + if (!tx_context->urb) { + ret = -ENOMEM; goto free_tx; + } tx_context->in_use = false; } for (ii = 0; ii < priv->num_rcb; ii++) { priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL); - if (!priv->rcb[ii]) + if (!priv->rcb[ii]) { + ret = -ENOMEM; goto free_rx_tx; + } rcb = priv->rcb[ii]; @@ -436,39 +475,46 @@ static bool vnt_alloc_bufs(struct vnt_private *priv) /* allocate URBs */ rcb->urb = usb_alloc_urb(0, GFP_KERNEL); - if (!rcb->urb) + if (!rcb->urb) { + ret = -ENOMEM; goto free_rx_tx; + } rcb->skb = dev_alloc_skb(priv->rx_buf_sz); - if (!rcb->skb) + if (!rcb->skb) { + ret = -ENOMEM; goto free_rx_tx; + } rcb->in_use = false; /* submit rx urb */ - if (vnt_submit_rx_urb(priv, rcb)) + ret = vnt_submit_rx_urb(priv, rcb); + if (ret) goto free_rx_tx; } priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL); - if (!priv->interrupt_urb) + if (!priv->interrupt_urb) { + ret = -ENOMEM; goto free_rx_tx; + } priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); if (!priv->int_buf.data_buf) { - usb_free_urb(priv->interrupt_urb); - goto free_rx_tx; + ret = -ENOMEM; + goto free_rx_tx_urb; } - return true; + return 0; +free_rx_tx_urb: + usb_free_urb(priv->interrupt_urb); free_rx_tx: vnt_free_rx_bufs(priv); - free_tx: vnt_free_tx_bufs(priv); - - return false; + return ret; } static void vnt_tx_80211(struct ieee80211_hw *hw, @@ -483,28 +529,34 @@ static void vnt_tx_80211(struct ieee80211_hw *hw, static int vnt_start(struct ieee80211_hw *hw) { + int ret = 0; struct vnt_private *priv = hw->priv; priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; - if (!vnt_alloc_bufs(priv)) { + ret = vnt_alloc_bufs(priv); + if (ret) { dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n"); - return -ENOMEM; + goto err; } clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); - if (vnt_init_registers(priv) == false) { + ret = vnt_init_registers(priv); + if (ret) { dev_dbg(&priv->usb->dev, " init register fail\n"); goto free_all; } - if (vnt_key_init_table(priv)) + ret = vnt_key_init_table(priv); + if (ret) goto free_all; priv->int_interval = 1; /* bInterval is set to 1 */ - vnt_int_start_interrupt(priv); + ret = vnt_int_start_interrupt(priv); + if (ret) + goto free_all; ieee80211_wake_queues(hw); @@ -517,8 +569,8 @@ free_all: usb_kill_urb(priv->interrupt_urb); usb_free_urb(priv->interrupt_urb); - - return -ENOMEM; +err: + return ret; } static void vnt_stop(struct ieee80211_hw *hw) |