Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * GPL LICENSE SUMMARY |
| 4 | * |
| 5 | * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 19 | * USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/init.h> |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 33 | #include <linux/sched.h> |
Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 34 | |
| 35 | #include "iwl-dev.h" |
| 36 | #include "iwl-core.h" |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 37 | #include "iwl-io.h" |
Wey-Yi Guy | 19e6cda | 2010-03-16 17:41:23 -0700 | [diff] [blame^] | 38 | #include "iwl-agn-hw.h" |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * ucode |
| 42 | */ |
| 43 | static int iwlagn_load_section(struct iwl_priv *priv, const char *name, |
| 44 | struct fw_desc *image, u32 dst_addr) |
| 45 | { |
| 46 | dma_addr_t phy_addr = image->p_addr; |
| 47 | u32 byte_cnt = image->len; |
| 48 | int ret; |
| 49 | |
| 50 | priv->ucode_write_complete = 0; |
| 51 | |
| 52 | iwl_write_direct32(priv, |
| 53 | FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), |
| 54 | FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE); |
| 55 | |
| 56 | iwl_write_direct32(priv, |
| 57 | FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr); |
| 58 | |
| 59 | iwl_write_direct32(priv, |
| 60 | FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL), |
| 61 | phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK); |
| 62 | |
| 63 | iwl_write_direct32(priv, |
| 64 | FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), |
| 65 | (iwl_get_dma_hi_addr(phy_addr) |
| 66 | << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt); |
| 67 | |
| 68 | iwl_write_direct32(priv, |
| 69 | FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL), |
| 70 | 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM | |
| 71 | 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX | |
| 72 | FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID); |
| 73 | |
| 74 | iwl_write_direct32(priv, |
| 75 | FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), |
| 76 | FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | |
| 77 | FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE | |
| 78 | FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD); |
| 79 | |
| 80 | IWL_DEBUG_INFO(priv, "%s uCode section being loaded...\n", name); |
| 81 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 82 | priv->ucode_write_complete, 5 * HZ); |
| 83 | if (ret == -ERESTARTSYS) { |
| 84 | IWL_ERR(priv, "Could not load the %s uCode section due " |
| 85 | "to interrupt\n", name); |
| 86 | return ret; |
| 87 | } |
| 88 | if (!ret) { |
| 89 | IWL_ERR(priv, "Could not load the %s uCode section\n", |
| 90 | name); |
| 91 | return -ETIMEDOUT; |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int iwlagn_load_given_ucode(struct iwl_priv *priv, |
| 98 | struct fw_desc *inst_image, |
| 99 | struct fw_desc *data_image) |
| 100 | { |
| 101 | int ret = 0; |
| 102 | |
| 103 | ret = iwlagn_load_section(priv, "INST", inst_image, |
Wey-Yi Guy | 19e6cda | 2010-03-16 17:41:23 -0700 | [diff] [blame^] | 104 | IWLAGN_RTC_INST_LOWER_BOUND); |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 105 | if (ret) |
| 106 | return ret; |
| 107 | |
| 108 | return iwlagn_load_section(priv, "DATA", data_image, |
Wey-Yi Guy | 19e6cda | 2010-03-16 17:41:23 -0700 | [diff] [blame^] | 109 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | int iwlagn_load_ucode(struct iwl_priv *priv) |
| 113 | { |
| 114 | int ret = 0; |
| 115 | |
| 116 | /* check whether init ucode should be loaded, or rather runtime ucode */ |
| 117 | if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) { |
| 118 | IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n"); |
| 119 | ret = iwlagn_load_given_ucode(priv, |
| 120 | &priv->ucode_init, &priv->ucode_init_data); |
| 121 | if (!ret) { |
| 122 | IWL_DEBUG_INFO(priv, "Init ucode load complete.\n"); |
| 123 | priv->ucode_type = UCODE_INIT; |
| 124 | } |
| 125 | } else { |
| 126 | IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. " |
| 127 | "Loading runtime ucode...\n"); |
| 128 | ret = iwlagn_load_given_ucode(priv, |
| 129 | &priv->ucode_code, &priv->ucode_data); |
| 130 | if (!ret) { |
| 131 | IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n"); |
| 132 | priv->ucode_type = UCODE_RT; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return ret; |
| 137 | } |
Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 138 | |
| 139 | #define IWL_UCODE_GET(item) \ |
| 140 | static u32 iwlagn_ucode_get_##item(const struct iwl_ucode_header *ucode,\ |
| 141 | u32 api_ver) \ |
| 142 | { \ |
| 143 | if (api_ver <= 2) \ |
| 144 | return le32_to_cpu(ucode->u.v1.item); \ |
| 145 | return le32_to_cpu(ucode->u.v2.item); \ |
| 146 | } |
| 147 | |
| 148 | static u32 iwlagn_ucode_get_header_size(u32 api_ver) |
| 149 | { |
| 150 | if (api_ver <= 2) |
| 151 | return UCODE_HEADER_SIZE(1); |
| 152 | return UCODE_HEADER_SIZE(2); |
| 153 | } |
| 154 | |
| 155 | static u32 iwlagn_ucode_get_build(const struct iwl_ucode_header *ucode, |
| 156 | u32 api_ver) |
| 157 | { |
| 158 | if (api_ver <= 2) |
| 159 | return 0; |
| 160 | return le32_to_cpu(ucode->u.v2.build); |
| 161 | } |
| 162 | |
| 163 | static u8 *iwlagn_ucode_get_data(const struct iwl_ucode_header *ucode, |
| 164 | u32 api_ver) |
| 165 | { |
| 166 | if (api_ver <= 2) |
| 167 | return (u8 *) ucode->u.v1.data; |
| 168 | return (u8 *) ucode->u.v2.data; |
| 169 | } |
| 170 | |
| 171 | IWL_UCODE_GET(inst_size); |
| 172 | IWL_UCODE_GET(data_size); |
| 173 | IWL_UCODE_GET(init_size); |
| 174 | IWL_UCODE_GET(init_data_size); |
| 175 | IWL_UCODE_GET(boot_size); |
| 176 | |
| 177 | struct iwl_ucode_ops iwlagn_ucode = { |
| 178 | .get_header_size = iwlagn_ucode_get_header_size, |
| 179 | .get_build = iwlagn_ucode_get_build, |
| 180 | .get_inst_size = iwlagn_ucode_get_inst_size, |
| 181 | .get_data_size = iwlagn_ucode_get_data_size, |
| 182 | .get_init_size = iwlagn_ucode_get_init_size, |
| 183 | .get_init_data_size = iwlagn_ucode_get_init_data_size, |
| 184 | .get_boot_size = iwlagn_ucode_get_boot_size, |
| 185 | .get_data = iwlagn_ucode_get_data, |
| 186 | }; |