Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Intel Wireless WiMAX Connection 2400m |
| 3 | * Linux driver model glue for the SDIO device, reset & fw upload |
| 4 | * |
| 5 | * |
| 6 | * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com> |
| 7 | * Dirk Brandewie <dirk.j.brandewie@intel.com> |
| 8 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> |
| 9 | * Yanir Lubetkin <yanirx.lubetkin@intel.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License version |
| 13 | * 2 as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 23 | * 02110-1301, USA. |
| 24 | * |
| 25 | * |
| 26 | * See i2400m-sdio.h for a general description of this driver. |
| 27 | * |
| 28 | * This file implements driver model glue, and hook ups for the |
| 29 | * generic driver to implement the bus-specific functions (device |
| 30 | * communication setup/tear down, firmware upload and resetting). |
| 31 | * |
| 32 | * ROADMAP |
| 33 | * |
| 34 | * i2400m_probe() |
| 35 | * alloc_netdev() |
| 36 | * i2400ms_netdev_setup() |
| 37 | * i2400ms_init() |
| 38 | * i2400m_netdev_setup() |
| 39 | * i2400ms_enable_function() |
| 40 | * i2400m_setup() |
| 41 | * |
| 42 | * i2400m_remove() |
| 43 | * i2400m_release() |
| 44 | * free_netdev(net_dev) |
| 45 | * |
| 46 | * i2400ms_bus_reset() Called by i2400m->bus_reset |
| 47 | * __i2400ms_reset() |
| 48 | * __i2400ms_send_barker() |
| 49 | * |
| 50 | * i2400ms_bus_dev_start() Called by i2400m_dev_start() [who is |
| 51 | * i2400ms_tx_setup() called by i2400m_setup()] |
| 52 | * i2400ms_rx_setup() |
| 53 | * |
| 54 | * i2400ms_bus_dev_stop() Called by i2400m_dev_stop() [who is |
| 55 | * i2400ms_rx_release() is called by i2400m_release()] |
| 56 | * i2400ms_tx_release() |
| 57 | * |
| 58 | */ |
| 59 | |
| 60 | #include <linux/debugfs.h> |
Tomas Winkler | 51def0b | 2009-07-22 14:06:56 +0000 | [diff] [blame] | 61 | #include <linux/mmc/sdio_ids.h> |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 62 | #include <linux/mmc/sdio.h> |
| 63 | #include <linux/mmc/sdio_func.h> |
| 64 | #include "i2400m-sdio.h" |
| 65 | #include <linux/wimax/i2400m.h> |
| 66 | |
| 67 | #define D_SUBMODULE main |
| 68 | #include "sdio-debug-levels.h" |
| 69 | |
| 70 | /* IOE WiMAX function timeout in seconds */ |
| 71 | static int ioe_timeout = 2; |
| 72 | module_param(ioe_timeout, int, 0); |
| 73 | |
Inaky Perez-Gonzalez | 4c2b1a1 | 2009-09-02 15:36:05 -0700 | [diff] [blame] | 74 | static char i2400ms_debug_params[128]; |
| 75 | module_param_string(debug, i2400ms_debug_params, sizeof(i2400ms_debug_params), |
| 76 | 0644); |
| 77 | MODULE_PARM_DESC(debug, |
| 78 | "String of space-separated NAME:VALUE pairs, where NAMEs " |
| 79 | "are the different debug submodules and VALUE are the " |
| 80 | "initial debug value to set."); |
| 81 | |
Inaky Perez-Gonzalez | 1039abb | 2009-02-28 23:42:47 +0000 | [diff] [blame] | 82 | /* Our firmware file name list */ |
| 83 | static const char *i2400ms_bus_fw_names[] = { |
| 84 | #define I2400MS_FW_FILE_NAME "i2400m-fw-sdio-1.3.sbcf" |
| 85 | I2400MS_FW_FILE_NAME, |
| 86 | NULL |
| 87 | }; |
| 88 | |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 89 | |
Dirk Brandewie | 1c0b2dd | 2009-05-21 11:56:35 -0700 | [diff] [blame] | 90 | static const struct i2400m_poke_table i2400ms_pokes[] = { |
| 91 | I2400M_FW_POKE(0x6BE260, 0x00000088), |
| 92 | I2400M_FW_POKE(0x080550, 0x00000005), |
| 93 | I2400M_FW_POKE(0xAE0000, 0x00000000), |
| 94 | I2400M_FW_POKE(0x000000, 0x00000000), /* MUST be 0 terminated or bad |
| 95 | * things will happen */ |
| 96 | }; |
| 97 | |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 98 | /* |
| 99 | * Enable the SDIO function |
| 100 | * |
| 101 | * Tries to enable the SDIO function; might fail if it is still not |
| 102 | * ready (in some hardware, the SDIO WiMAX function is only enabled |
| 103 | * when we ask it to explicitly doing). Tries until a timeout is |
| 104 | * reached. |
| 105 | * |
Inaky Perez-Gonzalez | c77ca95 | 2009-08-31 17:57:56 -0700 | [diff] [blame] | 106 | * The @maxtries argument indicates how many times (at most) it should |
| 107 | * be tried to enable the function. 0 means forever. This acts along |
| 108 | * with the timeout (ie: it'll stop trying as soon as the maximum |
| 109 | * number of tries is reached _or_ as soon as the timeout is reached). |
| 110 | * |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 111 | * The reverse of this is...sdio_disable_function() |
| 112 | * |
| 113 | * Returns: 0 if the SDIO function was enabled, < 0 errno code on |
| 114 | * error (-ENODEV when it was unable to enable the function). |
| 115 | */ |
| 116 | static |
Inaky Perez-Gonzalez | c77ca95 | 2009-08-31 17:57:56 -0700 | [diff] [blame] | 117 | int i2400ms_enable_function(struct sdio_func *func, unsigned maxtries) |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 118 | { |
| 119 | u64 timeout; |
| 120 | int err; |
| 121 | struct device *dev = &func->dev; |
Inaky Perez-Gonzalez | c77ca95 | 2009-08-31 17:57:56 -0700 | [diff] [blame] | 122 | unsigned tries = 0; |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 123 | |
| 124 | d_fnstart(3, dev, "(func %p)\n", func); |
| 125 | /* Setup timeout (FIXME: This needs to read the CIS table to |
| 126 | * get a real timeout) and then wait for the device to signal |
| 127 | * it is ready */ |
| 128 | timeout = get_jiffies_64() + ioe_timeout * HZ; |
| 129 | err = -ENODEV; |
| 130 | while (err != 0 && time_before64(get_jiffies_64(), timeout)) { |
| 131 | sdio_claim_host(func); |
Cindy H Kao | f2696fb | 2009-08-17 19:17:58 -0700 | [diff] [blame] | 132 | /* |
| 133 | * There is a sillicon bug on the IWMC3200, where the |
| 134 | * IOE timeout will cause problems on Moorestown |
| 135 | * platforms (system hang). We explicitly overwrite |
| 136 | * func->enable_timeout here to work around the issue. |
| 137 | */ |
| 138 | if (func->device == SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX) |
| 139 | func->enable_timeout = IWMC3200_IOR_TIMEOUT; |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 140 | err = sdio_enable_func(func); |
| 141 | if (0 == err) { |
| 142 | sdio_release_host(func); |
| 143 | d_printf(2, dev, "SDIO function enabled\n"); |
| 144 | goto function_enabled; |
| 145 | } |
| 146 | d_printf(2, dev, "SDIO function failed to enable: %d\n", err); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 147 | sdio_release_host(func); |
Inaky Perez-Gonzalez | c77ca95 | 2009-08-31 17:57:56 -0700 | [diff] [blame] | 148 | if (maxtries > 0 && ++tries >= maxtries) { |
| 149 | err = -ETIME; |
| 150 | break; |
| 151 | } |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 152 | msleep(I2400MS_INIT_SLEEP_INTERVAL); |
| 153 | } |
| 154 | /* If timed out, device is not there yet -- get -ENODEV so |
| 155 | * the device driver core will retry later on. */ |
| 156 | if (err == -ETIME) { |
| 157 | dev_err(dev, "Can't enable WiMAX function; " |
| 158 | " has the function been enabled?\n"); |
| 159 | err = -ENODEV; |
| 160 | } |
| 161 | function_enabled: |
| 162 | d_fnend(3, dev, "(func %p) = %d\n", func, err); |
| 163 | return err; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /* |
| 168 | * Setup driver resources needed to communicate with the device |
| 169 | * |
| 170 | * The fw needs some time to settle, and it was just uploaded, |
| 171 | * so give it a break first. I'd prefer to just wait for the device to |
| 172 | * send something, but seems the poking we do to enable SDIO stuff |
| 173 | * interferes with it, so just give it a break before starting... |
| 174 | */ |
| 175 | static |
| 176 | int i2400ms_bus_dev_start(struct i2400m *i2400m) |
| 177 | { |
| 178 | int result; |
| 179 | struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m); |
| 180 | struct sdio_func *func = i2400ms->func; |
| 181 | struct device *dev = &func->dev; |
| 182 | |
| 183 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); |
| 184 | msleep(200); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 185 | result = i2400ms_tx_setup(i2400ms); |
| 186 | if (result < 0) |
| 187 | goto error_tx_setup; |
| 188 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); |
| 189 | return result; |
| 190 | |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 191 | error_tx_setup: |
Inaky Perez-Gonzalez | 16820c1 | 2009-05-07 01:02:39 -0700 | [diff] [blame] | 192 | i2400ms_tx_release(i2400ms); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 193 | d_fnend(3, dev, "(i2400m %p) = void\n", i2400m); |
| 194 | return result; |
| 195 | } |
| 196 | |
| 197 | |
| 198 | static |
| 199 | void i2400ms_bus_dev_stop(struct i2400m *i2400m) |
| 200 | { |
| 201 | struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m); |
| 202 | struct sdio_func *func = i2400ms->func; |
| 203 | struct device *dev = &func->dev; |
| 204 | |
| 205 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 206 | i2400ms_tx_release(i2400ms); |
| 207 | d_fnend(3, dev, "(i2400m %p) = void\n", i2400m); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /* |
| 212 | * Sends a barker buffer to the device |
| 213 | * |
| 214 | * This helper will allocate a kmalloced buffer and use it to transmit |
| 215 | * (then free it). Reason for this is that the SDIO host controller |
| 216 | * expects alignment (unknown exactly which) which the stack won't |
| 217 | * really provide and certain arches/host-controller combinations |
| 218 | * cannot use stack/vmalloc/text areas for DMA transfers. |
| 219 | */ |
| 220 | static |
| 221 | int __i2400ms_send_barker(struct i2400ms *i2400ms, |
| 222 | const __le32 *barker, size_t barker_size) |
| 223 | { |
| 224 | int ret; |
| 225 | struct sdio_func *func = i2400ms->func; |
| 226 | struct device *dev = &func->dev; |
| 227 | void *buffer; |
| 228 | |
| 229 | ret = -ENOMEM; |
| 230 | buffer = kmalloc(I2400MS_BLK_SIZE, GFP_KERNEL); |
| 231 | if (buffer == NULL) |
| 232 | goto error_kzalloc; |
| 233 | |
| 234 | memcpy(buffer, barker, barker_size); |
| 235 | sdio_claim_host(func); |
| 236 | ret = sdio_memcpy_toio(func, 0, buffer, I2400MS_BLK_SIZE); |
| 237 | sdio_release_host(func); |
| 238 | |
| 239 | if (ret < 0) |
| 240 | d_printf(0, dev, "E: barker error: %d\n", ret); |
| 241 | |
| 242 | kfree(buffer); |
| 243 | error_kzalloc: |
| 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | /* |
| 249 | * Reset a device at different levels (warm, cold or bus) |
| 250 | * |
| 251 | * @i2400ms: device descriptor |
| 252 | * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS) |
| 253 | * |
| 254 | * FIXME: not tested -- need to confirm expected effects |
| 255 | * |
| 256 | * Warm and cold resets get an SDIO reset if they fail (unimplemented) |
| 257 | * |
| 258 | * Warm reset: |
| 259 | * |
| 260 | * The device will be fully reset internally, but won't be |
Dirk Brandewie | 81b182a | 2009-07-24 09:04:33 -0700 | [diff] [blame] | 261 | * disconnected from the bus (so no reenumeration will |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 262 | * happen). Firmware upload will be neccessary. |
| 263 | * |
Dirk Brandewie | 81b182a | 2009-07-24 09:04:33 -0700 | [diff] [blame] | 264 | * The device will send a reboot barker that will trigger the driver |
| 265 | * to reinitialize the state via __i2400m_dev_reset_handle. |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 266 | * |
Dirk Brandewie | 81b182a | 2009-07-24 09:04:33 -0700 | [diff] [blame] | 267 | * |
| 268 | * Cold and bus reset: |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 269 | * |
| 270 | * The device will be fully reset internally, disconnected from the |
Dirk Brandewie | 81b182a | 2009-07-24 09:04:33 -0700 | [diff] [blame] | 271 | * bus an a reenumeration will happen. Firmware upload will be |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 272 | * neccessary. Thus, we don't do any locking or struct |
| 273 | * reinitialization, as we are going to be fully disconnected and |
| 274 | * reenumerated. |
| 275 | * |
| 276 | * Note we need to return -ENODEV if a warm reset was requested and we |
| 277 | * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset() |
| 278 | * and wimax_dev->op_reset. |
| 279 | * |
| 280 | * WARNING: no driver state saved/fixed |
| 281 | */ |
| 282 | static |
| 283 | int i2400ms_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt) |
| 284 | { |
Dirk Brandewie | 10b1de6 | 2009-05-12 07:54:00 -0700 | [diff] [blame] | 285 | int result = 0; |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 286 | struct i2400ms *i2400ms = |
| 287 | container_of(i2400m, struct i2400ms, i2400m); |
| 288 | struct device *dev = i2400m_dev(i2400m); |
| 289 | static const __le32 i2400m_WARM_BOOT_BARKER[4] = { |
Harvey Harrison | ee43777 | 2009-02-01 00:43:54 -0800 | [diff] [blame] | 290 | cpu_to_le32(I2400M_WARM_RESET_BARKER), |
| 291 | cpu_to_le32(I2400M_WARM_RESET_BARKER), |
| 292 | cpu_to_le32(I2400M_WARM_RESET_BARKER), |
| 293 | cpu_to_le32(I2400M_WARM_RESET_BARKER), |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 294 | }; |
| 295 | static const __le32 i2400m_COLD_BOOT_BARKER[4] = { |
Harvey Harrison | ee43777 | 2009-02-01 00:43:54 -0800 | [diff] [blame] | 296 | cpu_to_le32(I2400M_COLD_RESET_BARKER), |
| 297 | cpu_to_le32(I2400M_COLD_RESET_BARKER), |
| 298 | cpu_to_le32(I2400M_COLD_RESET_BARKER), |
| 299 | cpu_to_le32(I2400M_COLD_RESET_BARKER), |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | if (rt == I2400M_RT_WARM) |
| 303 | result = __i2400ms_send_barker(i2400ms, i2400m_WARM_BOOT_BARKER, |
| 304 | sizeof(i2400m_WARM_BOOT_BARKER)); |
| 305 | else if (rt == I2400M_RT_COLD) |
| 306 | result = __i2400ms_send_barker(i2400ms, i2400m_COLD_BOOT_BARKER, |
| 307 | sizeof(i2400m_COLD_BOOT_BARKER)); |
| 308 | else if (rt == I2400M_RT_BUS) { |
| 309 | do_bus_reset: |
Dirk Brandewie | 10b1de6 | 2009-05-12 07:54:00 -0700 | [diff] [blame] | 310 | /* call netif_tx_disable() before sending IOE disable, |
| 311 | * so that all the tx from network layer are stopped |
| 312 | * while IOE is being reset. Make sure it is called |
| 313 | * only after register_netdev() was issued. |
| 314 | */ |
| 315 | if (i2400m->wimax_dev.net_dev->reg_state == NETREG_REGISTERED) |
| 316 | netif_tx_disable(i2400m->wimax_dev.net_dev); |
| 317 | |
Inaky Perez-Gonzalez | 16820c1 | 2009-05-07 01:02:39 -0700 | [diff] [blame] | 318 | i2400ms_rx_release(i2400ms); |
Dirk Brandewie | 10b1de6 | 2009-05-12 07:54:00 -0700 | [diff] [blame] | 319 | sdio_claim_host(i2400ms->func); |
| 320 | sdio_disable_func(i2400ms->func); |
| 321 | sdio_release_host(i2400ms->func); |
| 322 | |
| 323 | /* Wait for the device to settle */ |
| 324 | msleep(40); |
| 325 | |
Inaky Perez-Gonzalez | c77ca95 | 2009-08-31 17:57:56 -0700 | [diff] [blame] | 326 | result = i2400ms_enable_function(i2400ms->func, 0); |
Inaky Perez-Gonzalez | 16820c1 | 2009-05-07 01:02:39 -0700 | [diff] [blame] | 327 | if (result >= 0) |
| 328 | i2400ms_rx_setup(i2400ms); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 329 | } else |
| 330 | BUG(); |
| 331 | if (result < 0 && rt != I2400M_RT_BUS) { |
| 332 | dev_err(dev, "%s reset failed (%d); trying SDIO reset\n", |
| 333 | rt == I2400M_RT_WARM ? "warm" : "cold", result); |
| 334 | rt = I2400M_RT_BUS; |
| 335 | goto do_bus_reset; |
| 336 | } |
| 337 | return result; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | static |
| 342 | void i2400ms_netdev_setup(struct net_device *net_dev) |
| 343 | { |
| 344 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); |
| 345 | struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m); |
| 346 | i2400ms_init(i2400ms); |
| 347 | i2400m_netdev_setup(net_dev); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | /* |
| 352 | * Debug levels control; see debug.h |
| 353 | */ |
| 354 | struct d_level D_LEVEL[] = { |
| 355 | D_SUBMODULE_DEFINE(main), |
| 356 | D_SUBMODULE_DEFINE(tx), |
| 357 | D_SUBMODULE_DEFINE(rx), |
| 358 | D_SUBMODULE_DEFINE(fw), |
| 359 | }; |
| 360 | size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL); |
| 361 | |
| 362 | |
| 363 | #define __debugfs_register(prefix, name, parent) \ |
| 364 | do { \ |
| 365 | result = d_level_register_debugfs(prefix, name, parent); \ |
| 366 | if (result < 0) \ |
| 367 | goto error; \ |
| 368 | } while (0) |
| 369 | |
| 370 | |
| 371 | static |
| 372 | int i2400ms_debugfs_add(struct i2400ms *i2400ms) |
| 373 | { |
| 374 | int result; |
| 375 | struct dentry *dentry = i2400ms->i2400m.wimax_dev.debugfs_dentry; |
| 376 | |
| 377 | dentry = debugfs_create_dir("i2400m-usb", dentry); |
| 378 | result = PTR_ERR(dentry); |
| 379 | if (IS_ERR(dentry)) { |
| 380 | if (result == -ENODEV) |
| 381 | result = 0; /* No debugfs support */ |
| 382 | goto error; |
| 383 | } |
| 384 | i2400ms->debugfs_dentry = dentry; |
| 385 | __debugfs_register("dl_", main, dentry); |
| 386 | __debugfs_register("dl_", tx, dentry); |
| 387 | __debugfs_register("dl_", rx, dentry); |
| 388 | __debugfs_register("dl_", fw, dentry); |
| 389 | |
| 390 | return 0; |
| 391 | |
| 392 | error: |
| 393 | debugfs_remove_recursive(i2400ms->debugfs_dentry); |
| 394 | return result; |
| 395 | } |
| 396 | |
| 397 | |
Marcel Holtmann | 384912e | 2009-08-31 21:08:19 +0000 | [diff] [blame] | 398 | static struct device_type i2400ms_type = { |
| 399 | .name = "wimax", |
| 400 | }; |
| 401 | |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 402 | /* |
| 403 | * Probe a i2400m interface and register it |
| 404 | * |
| 405 | * @func: SDIO function |
| 406 | * @id: SDIO device ID |
| 407 | * @returns: 0 if ok, < 0 errno code on error. |
| 408 | * |
| 409 | * Alloc a net device, initialize the bus-specific details and then |
| 410 | * calls the bus-generic initialization routine. That will register |
| 411 | * the wimax and netdev devices, upload the firmware [using |
| 412 | * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the |
| 413 | * communication with the device and then will start to talk to it to |
| 414 | * finnish setting it up. |
| 415 | * |
| 416 | * Initialization is tricky; some instances of the hw are packed with |
| 417 | * others in a way that requires a third driver that enables the WiMAX |
| 418 | * function. In those cases, we can't enable the SDIO function and |
| 419 | * we'll return with -ENODEV. When the driver that enables the WiMAX |
| 420 | * function does its thing, it has to do a bus_rescan_devices() on the |
| 421 | * SDIO bus so this driver is called again to enumerate the WiMAX |
| 422 | * function. |
| 423 | */ |
| 424 | static |
| 425 | int i2400ms_probe(struct sdio_func *func, |
| 426 | const struct sdio_device_id *id) |
| 427 | { |
| 428 | int result; |
| 429 | struct net_device *net_dev; |
| 430 | struct device *dev = &func->dev; |
| 431 | struct i2400m *i2400m; |
| 432 | struct i2400ms *i2400ms; |
| 433 | |
| 434 | /* Allocate instance [calls i2400m_netdev_setup() on it]. */ |
| 435 | result = -ENOMEM; |
| 436 | net_dev = alloc_netdev(sizeof(*i2400ms), "wmx%d", |
| 437 | i2400ms_netdev_setup); |
| 438 | if (net_dev == NULL) { |
| 439 | dev_err(dev, "no memory for network device instance\n"); |
| 440 | goto error_alloc_netdev; |
| 441 | } |
| 442 | SET_NETDEV_DEV(net_dev, dev); |
Marcel Holtmann | 384912e | 2009-08-31 21:08:19 +0000 | [diff] [blame] | 443 | SET_NETDEV_DEVTYPE(net_dev, &i2400ms_type); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 444 | i2400m = net_dev_to_i2400m(net_dev); |
| 445 | i2400ms = container_of(i2400m, struct i2400ms, i2400m); |
| 446 | i2400m->wimax_dev.net_dev = net_dev; |
| 447 | i2400ms->func = func; |
| 448 | sdio_set_drvdata(func, i2400ms); |
| 449 | |
| 450 | i2400m->bus_tx_block_size = I2400MS_BLK_SIZE; |
| 451 | i2400m->bus_pl_size_max = I2400MS_PL_SIZE_MAX; |
| 452 | i2400m->bus_dev_start = i2400ms_bus_dev_start; |
| 453 | i2400m->bus_dev_stop = i2400ms_bus_dev_stop; |
| 454 | i2400m->bus_tx_kick = i2400ms_bus_tx_kick; |
| 455 | i2400m->bus_reset = i2400ms_bus_reset; |
Inaky Perez-Gonzalez | ecddfd5 | 2009-06-03 16:13:14 +0800 | [diff] [blame] | 456 | /* The iwmc3200-wimax sometimes requires the driver to try |
| 457 | * hard when we paint it into a corner. */ |
Dirk Brandewie | c308365 | 2009-08-13 13:48:29 -0700 | [diff] [blame] | 458 | i2400m->bus_bm_retries = I2400M_SDIO_BOOT_RETRIES; |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 459 | i2400m->bus_bm_cmd_send = i2400ms_bus_bm_cmd_send; |
| 460 | i2400m->bus_bm_wait_for_ack = i2400ms_bus_bm_wait_for_ack; |
Inaky Perez-Gonzalez | 1039abb | 2009-02-28 23:42:47 +0000 | [diff] [blame] | 461 | i2400m->bus_fw_names = i2400ms_bus_fw_names; |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 462 | i2400m->bus_bm_mac_addr_impaired = 1; |
Dirk Brandewie | 1c0b2dd | 2009-05-21 11:56:35 -0700 | [diff] [blame] | 463 | i2400m->bus_bm_pokes_table = &i2400ms_pokes[0]; |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 464 | |
Inaky Perez-Gonzalez | a0a4c4c | 2009-04-30 14:39:21 -0700 | [diff] [blame] | 465 | sdio_claim_host(func); |
| 466 | result = sdio_set_block_size(func, I2400MS_BLK_SIZE); |
| 467 | sdio_release_host(func); |
| 468 | if (result < 0) { |
| 469 | dev_err(dev, "Failed to set block size: %d\n", result); |
| 470 | goto error_set_blk_size; |
| 471 | } |
| 472 | |
Inaky Perez-Gonzalez | c77ca95 | 2009-08-31 17:57:56 -0700 | [diff] [blame] | 473 | result = i2400ms_enable_function(i2400ms->func, 1); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 474 | if (result < 0) { |
| 475 | dev_err(dev, "Cannot enable SDIO function: %d\n", result); |
| 476 | goto error_func_enable; |
| 477 | } |
| 478 | |
Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 479 | /* |
| 480 | * Before we are enabling the device interrupt register, make |
| 481 | * sure the buffer used during bootmode operation is setup so |
| 482 | * when the first D2H data interrupt comes, the memory is |
| 483 | * available for copying the D2H data. |
| 484 | */ |
| 485 | result = i2400m_bm_buf_alloc(i2400m); |
| 486 | if (result < 0) { |
| 487 | dev_err(dev, "cannot allocate SDIO bootmode buffer\n"); |
| 488 | goto error_bootmode_buf_setup; |
| 489 | } |
| 490 | |
Inaky Perez-Gonzalez | 16820c1 | 2009-05-07 01:02:39 -0700 | [diff] [blame] | 491 | result = i2400ms_rx_setup(i2400ms); |
| 492 | if (result < 0) |
| 493 | goto error_rx_setup; |
| 494 | |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 495 | result = i2400m_setup(i2400m, I2400M_BRI_NO_REBOOT); |
| 496 | if (result < 0) { |
| 497 | dev_err(dev, "cannot setup device: %d\n", result); |
| 498 | goto error_setup; |
| 499 | } |
| 500 | |
| 501 | result = i2400ms_debugfs_add(i2400ms); |
| 502 | if (result < 0) { |
| 503 | dev_err(dev, "cannot create SDIO debugfs: %d\n", |
| 504 | result); |
| 505 | goto error_debugfs_add; |
| 506 | } |
| 507 | return 0; |
| 508 | |
| 509 | error_debugfs_add: |
| 510 | i2400m_release(i2400m); |
| 511 | error_setup: |
Inaky Perez-Gonzalez | 16820c1 | 2009-05-07 01:02:39 -0700 | [diff] [blame] | 512 | i2400ms_rx_release(i2400ms); |
| 513 | error_rx_setup: |
Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 514 | i2400m_bm_buf_free(i2400m); |
| 515 | error_bootmode_buf_setup: |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 516 | sdio_claim_host(func); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 517 | sdio_disable_func(func); |
| 518 | sdio_release_host(func); |
| 519 | error_func_enable: |
Inaky Perez-Gonzalez | a0a4c4c | 2009-04-30 14:39:21 -0700 | [diff] [blame] | 520 | error_set_blk_size: |
| 521 | sdio_set_drvdata(func, NULL); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 522 | free_netdev(net_dev); |
| 523 | error_alloc_netdev: |
| 524 | return result; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | static |
| 529 | void i2400ms_remove(struct sdio_func *func) |
| 530 | { |
| 531 | struct device *dev = &func->dev; |
| 532 | struct i2400ms *i2400ms = sdio_get_drvdata(func); |
| 533 | struct i2400m *i2400m = &i2400ms->i2400m; |
| 534 | struct net_device *net_dev = i2400m->wimax_dev.net_dev; |
| 535 | |
| 536 | d_fnstart(3, dev, "SDIO func %p\n", func); |
| 537 | debugfs_remove_recursive(i2400ms->debugfs_dentry); |
Inaky Perez-Gonzalez | 16820c1 | 2009-05-07 01:02:39 -0700 | [diff] [blame] | 538 | i2400ms_rx_release(i2400ms); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 539 | i2400m_release(i2400m); |
| 540 | sdio_set_drvdata(func, NULL); |
| 541 | sdio_claim_host(func); |
| 542 | sdio_disable_func(func); |
| 543 | sdio_release_host(func); |
| 544 | free_netdev(net_dev); |
| 545 | d_fnend(3, dev, "SDIO func %p\n", func); |
| 546 | } |
| 547 | |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 548 | static |
| 549 | const struct sdio_device_id i2400ms_sdio_ids[] = { |
Tomas Winkler | 51def0b | 2009-07-22 14:06:56 +0000 | [diff] [blame] | 550 | /* Intel: i2400m WiMAX (iwmc3200) over SDIO */ |
| 551 | { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL, |
| 552 | SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX) }, |
Cindy H Kao | f8fc329 | 2009-09-04 17:38:46 -0700 | [diff] [blame^] | 553 | { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL, |
| 554 | SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX_2G5) }, |
Tomas Winkler | 51def0b | 2009-07-22 14:06:56 +0000 | [diff] [blame] | 555 | { /* end: all zeroes */ }, |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 556 | }; |
| 557 | MODULE_DEVICE_TABLE(sdio, i2400ms_sdio_ids); |
| 558 | |
| 559 | |
| 560 | static |
| 561 | struct sdio_driver i2400m_sdio_driver = { |
| 562 | .name = KBUILD_MODNAME, |
| 563 | .probe = i2400ms_probe, |
| 564 | .remove = i2400ms_remove, |
| 565 | .id_table = i2400ms_sdio_ids, |
| 566 | }; |
| 567 | |
| 568 | |
| 569 | static |
| 570 | int __init i2400ms_driver_init(void) |
| 571 | { |
Inaky Perez-Gonzalez | 4c2b1a1 | 2009-09-02 15:36:05 -0700 | [diff] [blame] | 572 | d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400ms_debug_params, |
| 573 | "i2400m_sdio.debug"); |
Inaky Perez-Gonzalez | a084882 | 2008-12-20 16:57:55 -0800 | [diff] [blame] | 574 | return sdio_register_driver(&i2400m_sdio_driver); |
| 575 | } |
| 576 | module_init(i2400ms_driver_init); |
| 577 | |
| 578 | |
| 579 | static |
| 580 | void __exit i2400ms_driver_exit(void) |
| 581 | { |
| 582 | flush_scheduled_work(); /* for the stuff we schedule */ |
| 583 | sdio_unregister_driver(&i2400m_sdio_driver); |
| 584 | } |
| 585 | module_exit(i2400ms_driver_exit); |
| 586 | |
| 587 | |
| 588 | MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>"); |
| 589 | MODULE_DESCRIPTION("Intel 2400M WiMAX networking for SDIO"); |
| 590 | MODULE_LICENSE("GPL"); |
| 591 | MODULE_FIRMWARE(I2400MS_FW_FILE_NAME); |