Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: PCIE specific handling |
| 3 | * |
| 4 | * Copyright (C) 2011, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/firmware.h> |
| 21 | |
| 22 | #include "decl.h" |
| 23 | #include "ioctl.h" |
| 24 | #include "util.h" |
| 25 | #include "fw.h" |
| 26 | #include "main.h" |
| 27 | #include "wmm.h" |
| 28 | #include "11n.h" |
| 29 | #include "pcie.h" |
| 30 | |
| 31 | #define PCIE_VERSION "1.0" |
| 32 | #define DRV_NAME "Marvell mwifiex PCIe" |
| 33 | |
| 34 | static u8 user_rmmod; |
| 35 | |
| 36 | static struct mwifiex_if_ops pcie_ops; |
| 37 | |
| 38 | static struct semaphore add_remove_card_sem; |
| 39 | static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter); |
| 40 | static int mwifiex_pcie_resume(struct pci_dev *pdev); |
| 41 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 42 | static int |
| 43 | mwifiex_map_pci_memory(struct mwifiex_adapter *adapter, struct sk_buff *skb, |
| 44 | int size, int flags) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 45 | { |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 46 | struct pcie_service_card *card = adapter->card; |
| 47 | dma_addr_t buf_pa; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 48 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 49 | buf_pa = pci_map_single(card->dev, skb->data, size, flags); |
| 50 | if (pci_dma_mapping_error(card->dev, buf_pa)) { |
| 51 | dev_err(adapter->dev, "failed to map pci memory!\n"); |
| 52 | return -1; |
| 53 | } |
| 54 | memcpy(skb->cb, &buf_pa, sizeof(dma_addr_t)); |
| 55 | return 0; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
| 59 | * This function reads sleep cookie and checks if FW is ready |
| 60 | */ |
| 61 | static bool mwifiex_pcie_ok_to_access_hw(struct mwifiex_adapter *adapter) |
| 62 | { |
| 63 | u32 *cookie_addr; |
| 64 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 65 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
| 66 | |
| 67 | if (!reg->sleep_cookie) |
| 68 | return true; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 69 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 70 | if (card->sleep_cookie_vbase) { |
| 71 | cookie_addr = (u32 *)card->sleep_cookie_vbase; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 72 | dev_dbg(adapter->dev, "info: ACCESS_HW: sleep cookie=0x%x\n", |
| 73 | *cookie_addr); |
| 74 | if (*cookie_addr == FW_AWAKE_COOKIE) |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * This function probes an mwifiex device and registers it. It allocates |
| 83 | * the card structure, enables PCIE function number and initiates the |
| 84 | * device registration and initialization procedure by adding a logical |
| 85 | * interface. |
| 86 | */ |
| 87 | static int mwifiex_pcie_probe(struct pci_dev *pdev, |
| 88 | const struct pci_device_id *ent) |
| 89 | { |
| 90 | struct pcie_service_card *card; |
| 91 | |
| 92 | pr_debug("info: vendor=0x%4.04X device=0x%4.04X rev=%d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 93 | pdev->vendor, pdev->device, pdev->revision); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 94 | |
| 95 | card = kzalloc(sizeof(struct pcie_service_card), GFP_KERNEL); |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 96 | if (!card) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 97 | return -ENOMEM; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 98 | |
| 99 | card->dev = pdev; |
| 100 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 101 | if (ent->driver_data) { |
| 102 | struct mwifiex_pcie_device *data = (void *)ent->driver_data; |
| 103 | card->pcie.firmware = data->firmware; |
| 104 | card->pcie.reg = data->reg; |
| 105 | card->pcie.blksz_fw_dl = data->blksz_fw_dl; |
| 106 | } |
| 107 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 108 | if (mwifiex_add_card(card, &add_remove_card_sem, &pcie_ops, |
| 109 | MWIFIEX_PCIE)) { |
| 110 | pr_err("%s failed\n", __func__); |
| 111 | kfree(card); |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * This function removes the interface and frees up the card structure. |
| 120 | */ |
| 121 | static void mwifiex_pcie_remove(struct pci_dev *pdev) |
| 122 | { |
| 123 | struct pcie_service_card *card; |
| 124 | struct mwifiex_adapter *adapter; |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 125 | struct mwifiex_private *priv; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 126 | int i; |
| 127 | |
| 128 | card = pci_get_drvdata(pdev); |
| 129 | if (!card) |
| 130 | return; |
| 131 | |
| 132 | adapter = card->adapter; |
| 133 | if (!adapter || !adapter->priv_num) |
| 134 | return; |
| 135 | |
Amitkumar Karwar | 59a4cc2 | 2012-04-09 20:06:57 -0700 | [diff] [blame] | 136 | /* In case driver is removed when asynchronous FW load is in progress */ |
| 137 | wait_for_completion(&adapter->fw_load); |
| 138 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 139 | if (user_rmmod) { |
| 140 | #ifdef CONFIG_PM |
| 141 | if (adapter->is_suspended) |
| 142 | mwifiex_pcie_resume(pdev); |
| 143 | #endif |
| 144 | |
| 145 | for (i = 0; i < adapter->priv_num; i++) |
| 146 | if ((GET_BSS_ROLE(adapter->priv[i]) == |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 147 | MWIFIEX_BSS_ROLE_STA) && |
| 148 | adapter->priv[i]->media_connected) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 149 | mwifiex_deauthenticate(adapter->priv[i], NULL); |
| 150 | |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 151 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 152 | |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 153 | mwifiex_disable_auto_ds(priv); |
| 154 | |
| 155 | mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | mwifiex_remove_card(card->adapter, &add_remove_card_sem); |
| 159 | kfree(card); |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Kernel needs to suspend all functions separately. Therefore all |
| 164 | * registered functions must have drivers with suspend and resume |
| 165 | * methods. Failing that the kernel simply removes the whole card. |
| 166 | * |
| 167 | * If already not suspended, this function allocates and sends a host |
| 168 | * sleep activate request to the firmware and turns off the traffic. |
| 169 | */ |
| 170 | static int mwifiex_pcie_suspend(struct pci_dev *pdev, pm_message_t state) |
| 171 | { |
| 172 | struct mwifiex_adapter *adapter; |
| 173 | struct pcie_service_card *card; |
| 174 | int hs_actived, i; |
| 175 | |
| 176 | if (pdev) { |
| 177 | card = (struct pcie_service_card *) pci_get_drvdata(pdev); |
Avinash Patil | 83f0c6d | 2013-01-21 21:04:10 -0800 | [diff] [blame] | 178 | if (!card || !card->adapter) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 179 | pr_err("Card or adapter structure is not valid\n"); |
| 180 | return 0; |
| 181 | } |
| 182 | } else { |
| 183 | pr_err("PCIE device is not specified\n"); |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | adapter = card->adapter; |
| 188 | |
| 189 | hs_actived = mwifiex_enable_hs(adapter); |
| 190 | |
| 191 | /* Indicate device suspended */ |
| 192 | adapter->is_suspended = true; |
| 193 | |
| 194 | for (i = 0; i < adapter->priv_num; i++) |
| 195 | netif_carrier_off(adapter->priv[i]->netdev); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Kernel needs to suspend all functions separately. Therefore all |
| 202 | * registered functions must have drivers with suspend and resume |
| 203 | * methods. Failing that the kernel simply removes the whole card. |
| 204 | * |
| 205 | * If already not resumed, this function turns on the traffic and |
| 206 | * sends a host sleep cancel request to the firmware. |
| 207 | */ |
| 208 | static int mwifiex_pcie_resume(struct pci_dev *pdev) |
| 209 | { |
| 210 | struct mwifiex_adapter *adapter; |
| 211 | struct pcie_service_card *card; |
| 212 | int i; |
| 213 | |
| 214 | if (pdev) { |
| 215 | card = (struct pcie_service_card *) pci_get_drvdata(pdev); |
| 216 | if (!card || !card->adapter) { |
| 217 | pr_err("Card or adapter structure is not valid\n"); |
| 218 | return 0; |
| 219 | } |
| 220 | } else { |
| 221 | pr_err("PCIE device is not specified\n"); |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | adapter = card->adapter; |
| 226 | |
| 227 | if (!adapter->is_suspended) { |
| 228 | dev_warn(adapter->dev, "Device already resumed\n"); |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | adapter->is_suspended = false; |
| 233 | |
| 234 | for (i = 0; i < adapter->priv_num; i++) |
| 235 | if (adapter->priv[i]->media_connected) |
| 236 | netif_carrier_on(adapter->priv[i]->netdev); |
| 237 | |
| 238 | mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 239 | MWIFIEX_ASYNC_CMD); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 244 | static DEFINE_PCI_DEVICE_TABLE(mwifiex_ids) = { |
| 245 | { |
| 246 | PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8766P, |
| 247 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 248 | .driver_data = (unsigned long) &mwifiex_pcie8766, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 249 | }, |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 250 | { |
| 251 | PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8897, |
| 252 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
| 253 | .driver_data = (unsigned long) &mwifiex_pcie8897, |
| 254 | }, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 255 | {}, |
| 256 | }; |
| 257 | |
| 258 | MODULE_DEVICE_TABLE(pci, mwifiex_ids); |
| 259 | |
| 260 | /* PCI Device Driver */ |
| 261 | static struct pci_driver __refdata mwifiex_pcie = { |
| 262 | .name = "mwifiex_pcie", |
| 263 | .id_table = mwifiex_ids, |
| 264 | .probe = mwifiex_pcie_probe, |
| 265 | .remove = mwifiex_pcie_remove, |
| 266 | #ifdef CONFIG_PM |
| 267 | /* Power Management Hooks */ |
| 268 | .suspend = mwifiex_pcie_suspend, |
| 269 | .resume = mwifiex_pcie_resume, |
| 270 | #endif |
| 271 | }; |
| 272 | |
| 273 | /* |
| 274 | * This function writes data into PCIE card register. |
| 275 | */ |
| 276 | static int mwifiex_write_reg(struct mwifiex_adapter *adapter, int reg, u32 data) |
| 277 | { |
| 278 | struct pcie_service_card *card = adapter->card; |
| 279 | |
| 280 | iowrite32(data, card->pci_mmap1 + reg); |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * This function reads data from PCIE card register. |
| 287 | */ |
| 288 | static int mwifiex_read_reg(struct mwifiex_adapter *adapter, int reg, u32 *data) |
| 289 | { |
| 290 | struct pcie_service_card *card = adapter->card; |
| 291 | |
| 292 | *data = ioread32(card->pci_mmap1 + reg); |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * This function wakes up the card. |
| 299 | * |
| 300 | * A host power up command is written to the card configuration |
| 301 | * register to wake up the card. |
| 302 | */ |
| 303 | static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter) |
| 304 | { |
| 305 | int i = 0; |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 306 | struct pcie_service_card *card = adapter->card; |
| 307 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 308 | |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 309 | while (reg->sleep_cookie && mwifiex_pcie_ok_to_access_hw(adapter)) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 310 | i++; |
Yogesh Ashok Powar | e7891ba | 2012-03-12 19:35:11 -0700 | [diff] [blame] | 311 | usleep_range(10, 20); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 312 | /* 50ms max wait */ |
| 313 | if (i == 50000) |
| 314 | break; |
| 315 | } |
| 316 | |
| 317 | dev_dbg(adapter->dev, "event: Wakeup device...\n"); |
| 318 | |
| 319 | /* Enable interrupts or any chip access will wakeup device */ |
| 320 | if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK, HOST_INTR_MASK)) { |
| 321 | dev_warn(adapter->dev, "Enable host interrupt failed\n"); |
| 322 | return -1; |
| 323 | } |
| 324 | |
| 325 | dev_dbg(adapter->dev, "PCIE wakeup: Setting PS_STATE_AWAKE\n"); |
| 326 | adapter->ps_state = PS_STATE_AWAKE; |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * This function is called after the card has woken up. |
| 333 | * |
| 334 | * The card configuration register is reset. |
| 335 | */ |
| 336 | static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter) |
| 337 | { |
| 338 | dev_dbg(adapter->dev, "cmd: Wakeup device completed\n"); |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | * This function disables the host interrupt. |
| 345 | * |
| 346 | * The host interrupt mask is read, the disable bit is reset and |
| 347 | * written back to the card host interrupt mask register. |
| 348 | */ |
| 349 | static int mwifiex_pcie_disable_host_int(struct mwifiex_adapter *adapter) |
| 350 | { |
| 351 | if (mwifiex_pcie_ok_to_access_hw(adapter)) { |
| 352 | if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK, |
| 353 | 0x00000000)) { |
| 354 | dev_warn(adapter->dev, "Disable host interrupt failed\n"); |
| 355 | return -1; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * This function enables the host interrupt. |
| 364 | * |
| 365 | * The host interrupt enable mask is written to the card |
| 366 | * host interrupt mask register. |
| 367 | */ |
| 368 | static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter) |
| 369 | { |
| 370 | if (mwifiex_pcie_ok_to_access_hw(adapter)) { |
| 371 | /* Simply write the mask to the register */ |
| 372 | if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK, |
| 373 | HOST_INTR_MASK)) { |
| 374 | dev_warn(adapter->dev, "Enable host interrupt failed\n"); |
| 375 | return -1; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | /* |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 383 | * This function initializes TX buffer ring descriptors |
| 384 | */ |
| 385 | static int mwifiex_init_txq_ring(struct mwifiex_adapter *adapter) |
| 386 | { |
| 387 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 388 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 389 | struct mwifiex_pcie_buf_desc *desc; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 390 | struct mwifiex_pfu_buf_desc *desc2; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 391 | int i; |
| 392 | |
| 393 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { |
| 394 | card->tx_buf_list[i] = NULL; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 395 | if (reg->pfu_enabled) { |
| 396 | card->txbd_ring[i] = (void *)card->txbd_ring_vbase + |
| 397 | (sizeof(*desc2) * i); |
| 398 | desc2 = card->txbd_ring[i]; |
| 399 | memset(desc2, 0, sizeof(*desc2)); |
| 400 | } else { |
| 401 | card->txbd_ring[i] = (void *)card->txbd_ring_vbase + |
| 402 | (sizeof(*desc) * i); |
| 403 | desc = card->txbd_ring[i]; |
| 404 | memset(desc, 0, sizeof(*desc)); |
| 405 | } |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /* This function initializes RX buffer ring descriptors. Each SKB is allocated |
| 412 | * here and after mapping PCI memory, its physical address is assigned to |
| 413 | * PCIE Rx buffer descriptor's physical address. |
| 414 | */ |
| 415 | static int mwifiex_init_rxq_ring(struct mwifiex_adapter *adapter) |
| 416 | { |
| 417 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 418 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 419 | struct sk_buff *skb; |
| 420 | struct mwifiex_pcie_buf_desc *desc; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 421 | struct mwifiex_pfu_buf_desc *desc2; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 422 | dma_addr_t buf_pa; |
| 423 | int i; |
| 424 | |
| 425 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { |
| 426 | /* Allocate skb here so that firmware can DMA data from it */ |
| 427 | skb = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE); |
| 428 | if (!skb) { |
| 429 | dev_err(adapter->dev, |
| 430 | "Unable to allocate skb for RX ring.\n"); |
| 431 | kfree(card->rxbd_ring_vbase); |
| 432 | return -ENOMEM; |
| 433 | } |
| 434 | |
| 435 | if (mwifiex_map_pci_memory(adapter, skb, |
| 436 | MWIFIEX_RX_DATA_BUF_SIZE, |
| 437 | PCI_DMA_FROMDEVICE)) |
| 438 | return -1; |
| 439 | |
| 440 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 441 | |
| 442 | dev_dbg(adapter->dev, |
| 443 | "info: RX ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n", |
| 444 | skb, skb->len, skb->data, (u32)buf_pa, |
| 445 | (u32)((u64)buf_pa >> 32)); |
| 446 | |
| 447 | card->rx_buf_list[i] = skb; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 448 | if (reg->pfu_enabled) { |
| 449 | card->rxbd_ring[i] = (void *)card->rxbd_ring_vbase + |
| 450 | (sizeof(*desc2) * i); |
| 451 | desc2 = card->rxbd_ring[i]; |
| 452 | desc2->paddr = buf_pa; |
| 453 | desc2->len = (u16)skb->len; |
| 454 | desc2->frag_len = (u16)skb->len; |
| 455 | desc2->flags = reg->ring_flag_eop | reg->ring_flag_sop; |
| 456 | desc2->offset = 0; |
| 457 | } else { |
| 458 | card->rxbd_ring[i] = (void *)(card->rxbd_ring_vbase + |
| 459 | (sizeof(*desc) * i)); |
| 460 | desc = card->rxbd_ring[i]; |
| 461 | desc->paddr = buf_pa; |
| 462 | desc->len = (u16)skb->len; |
| 463 | desc->flags = 0; |
| 464 | } |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | /* This function initializes event buffer ring descriptors. Each SKB is |
| 471 | * allocated here and after mapping PCI memory, its physical address is assigned |
| 472 | * to PCIE Rx buffer descriptor's physical address |
| 473 | */ |
| 474 | static int mwifiex_pcie_init_evt_ring(struct mwifiex_adapter *adapter) |
| 475 | { |
| 476 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 477 | struct mwifiex_evt_buf_desc *desc; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 478 | struct sk_buff *skb; |
| 479 | dma_addr_t buf_pa; |
| 480 | int i; |
| 481 | |
| 482 | for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) { |
| 483 | /* Allocate skb here so that firmware can DMA data from it */ |
| 484 | skb = dev_alloc_skb(MAX_EVENT_SIZE); |
| 485 | if (!skb) { |
| 486 | dev_err(adapter->dev, |
| 487 | "Unable to allocate skb for EVENT buf.\n"); |
| 488 | kfree(card->evtbd_ring_vbase); |
| 489 | return -ENOMEM; |
| 490 | } |
| 491 | skb_put(skb, MAX_EVENT_SIZE); |
| 492 | |
| 493 | if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE, |
| 494 | PCI_DMA_FROMDEVICE)) |
| 495 | return -1; |
| 496 | |
| 497 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 498 | |
| 499 | dev_dbg(adapter->dev, |
| 500 | "info: EVT ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n", |
| 501 | skb, skb->len, skb->data, (u32)buf_pa, |
| 502 | (u32)((u64)buf_pa >> 32)); |
| 503 | |
| 504 | card->evt_buf_list[i] = skb; |
| 505 | card->evtbd_ring[i] = (void *)(card->evtbd_ring_vbase + |
| 506 | (sizeof(*desc) * i)); |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 507 | desc = card->evtbd_ring[i]; |
| 508 | desc->paddr = buf_pa; |
| 509 | desc->len = (u16)skb->len; |
| 510 | desc->flags = 0; |
| 511 | } |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /* This function cleans up TX buffer rings. If any of the buffer list has valid |
| 517 | * SKB address, associated SKB is freed. |
| 518 | */ |
| 519 | static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter) |
| 520 | { |
| 521 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 522 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 523 | struct sk_buff *skb; |
| 524 | struct mwifiex_pcie_buf_desc *desc; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 525 | struct mwifiex_pfu_buf_desc *desc2; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 526 | int i; |
| 527 | |
| 528 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 529 | if (reg->pfu_enabled) { |
| 530 | desc2 = card->txbd_ring[i]; |
| 531 | if (card->tx_buf_list[i]) { |
| 532 | skb = card->tx_buf_list[i]; |
| 533 | pci_unmap_single(card->dev, desc2->paddr, |
| 534 | skb->len, PCI_DMA_TODEVICE); |
| 535 | dev_kfree_skb_any(skb); |
| 536 | } |
| 537 | memset(desc2, 0, sizeof(*desc2)); |
| 538 | } else { |
| 539 | desc = card->txbd_ring[i]; |
| 540 | if (card->tx_buf_list[i]) { |
| 541 | skb = card->tx_buf_list[i]; |
| 542 | pci_unmap_single(card->dev, desc->paddr, |
| 543 | skb->len, PCI_DMA_TODEVICE); |
| 544 | dev_kfree_skb_any(skb); |
| 545 | } |
| 546 | memset(desc, 0, sizeof(*desc)); |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 547 | } |
| 548 | card->tx_buf_list[i] = NULL; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | /* This function cleans up RX buffer rings. If any of the buffer list has valid |
| 555 | * SKB address, associated SKB is freed. |
| 556 | */ |
| 557 | static void mwifiex_cleanup_rxq_ring(struct mwifiex_adapter *adapter) |
| 558 | { |
| 559 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 560 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 561 | struct mwifiex_pcie_buf_desc *desc; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 562 | struct mwifiex_pfu_buf_desc *desc2; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 563 | struct sk_buff *skb; |
| 564 | int i; |
| 565 | |
| 566 | for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 567 | if (reg->pfu_enabled) { |
| 568 | desc2 = card->rxbd_ring[i]; |
| 569 | if (card->rx_buf_list[i]) { |
| 570 | skb = card->rx_buf_list[i]; |
| 571 | pci_unmap_single(card->dev, desc2->paddr, |
| 572 | skb->len, PCI_DMA_TODEVICE); |
| 573 | dev_kfree_skb_any(skb); |
| 574 | } |
| 575 | memset(desc2, 0, sizeof(*desc2)); |
| 576 | } else { |
| 577 | desc = card->rxbd_ring[i]; |
| 578 | if (card->rx_buf_list[i]) { |
| 579 | skb = card->rx_buf_list[i]; |
| 580 | pci_unmap_single(card->dev, desc->paddr, |
| 581 | skb->len, PCI_DMA_TODEVICE); |
| 582 | dev_kfree_skb_any(skb); |
| 583 | } |
| 584 | memset(desc, 0, sizeof(*desc)); |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 585 | } |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 586 | card->rx_buf_list[i] = NULL; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | /* This function cleans up event buffer rings. If any of the buffer list has |
| 593 | * valid SKB address, associated SKB is freed. |
| 594 | */ |
| 595 | static void mwifiex_cleanup_evt_ring(struct mwifiex_adapter *adapter) |
| 596 | { |
| 597 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 598 | struct mwifiex_evt_buf_desc *desc; |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 599 | struct sk_buff *skb; |
| 600 | int i; |
| 601 | |
| 602 | for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) { |
| 603 | desc = card->evtbd_ring[i]; |
| 604 | if (card->evt_buf_list[i]) { |
| 605 | skb = card->evt_buf_list[i]; |
| 606 | pci_unmap_single(card->dev, desc->paddr, MAX_EVENT_SIZE, |
| 607 | PCI_DMA_FROMDEVICE); |
| 608 | dev_kfree_skb_any(skb); |
| 609 | } |
| 610 | card->evt_buf_list[i] = NULL; |
| 611 | memset(desc, 0, sizeof(*desc)); |
| 612 | } |
| 613 | |
| 614 | return; |
| 615 | } |
| 616 | |
| 617 | /* This function creates buffer descriptor ring for TX |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 618 | */ |
| 619 | static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter) |
| 620 | { |
| 621 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 622 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 623 | |
| 624 | /* |
| 625 | * driver maintaines the write pointer and firmware maintaines the read |
| 626 | * pointer. The write pointer starts at 0 (zero) while the read pointer |
| 627 | * starts at zero with rollover bit set |
| 628 | */ |
| 629 | card->txbd_wrptr = 0; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 630 | |
| 631 | if (reg->pfu_enabled) |
| 632 | card->txbd_rdptr = 0; |
| 633 | else |
| 634 | card->txbd_rdptr |= reg->tx_rollover_ind; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 635 | |
| 636 | /* allocate shared memory for the BD ring and divide the same in to |
| 637 | several descriptors */ |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 638 | if (reg->pfu_enabled) |
| 639 | card->txbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) * |
| 640 | MWIFIEX_MAX_TXRX_BD; |
| 641 | else |
| 642 | card->txbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) * |
| 643 | MWIFIEX_MAX_TXRX_BD; |
| 644 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 645 | dev_dbg(adapter->dev, "info: txbd_ring: Allocating %d bytes\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 646 | card->txbd_ring_size); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 647 | card->txbd_ring_vbase = pci_alloc_consistent(card->dev, |
| 648 | card->txbd_ring_size, |
| 649 | &card->txbd_ring_pbase); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 650 | if (!card->txbd_ring_vbase) { |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 651 | dev_err(adapter->dev, |
| 652 | "allocate consistent memory (%d bytes) failed!\n", |
| 653 | card->txbd_ring_size); |
Amitkumar Karwar | 8c53e42 | 2011-12-08 20:41:03 -0800 | [diff] [blame] | 654 | return -ENOMEM; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 655 | } |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 656 | dev_dbg(adapter->dev, |
| 657 | "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n", |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 658 | card->txbd_ring_vbase, (unsigned int)card->txbd_ring_pbase, |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 659 | (u32)((u64)card->txbd_ring_pbase >> 32), card->txbd_ring_size); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 660 | |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 661 | return mwifiex_init_txq_ring(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter) |
| 665 | { |
| 666 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 667 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 668 | |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 669 | mwifiex_cleanup_txq_ring(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 670 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 671 | if (card->txbd_ring_vbase) |
| 672 | pci_free_consistent(card->dev, card->txbd_ring_size, |
| 673 | card->txbd_ring_vbase, |
| 674 | card->txbd_ring_pbase); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 675 | card->txbd_ring_size = 0; |
| 676 | card->txbd_wrptr = 0; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 677 | card->txbd_rdptr = 0 | reg->tx_rollover_ind; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 678 | card->txbd_ring_vbase = NULL; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 679 | card->txbd_ring_pbase = 0; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | * This function creates buffer descriptor ring for RX |
| 686 | */ |
| 687 | static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) |
| 688 | { |
| 689 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 690 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 691 | |
| 692 | /* |
| 693 | * driver maintaines the read pointer and firmware maintaines the write |
| 694 | * pointer. The write pointer starts at 0 (zero) while the read pointer |
| 695 | * starts at zero with rollover bit set |
| 696 | */ |
| 697 | card->rxbd_wrptr = 0; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 698 | card->rxbd_rdptr = reg->rx_rollover_ind; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 699 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 700 | if (reg->pfu_enabled) |
| 701 | card->rxbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) * |
| 702 | MWIFIEX_MAX_TXRX_BD; |
| 703 | else |
| 704 | card->rxbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) * |
| 705 | MWIFIEX_MAX_TXRX_BD; |
| 706 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 707 | dev_dbg(adapter->dev, "info: rxbd_ring: Allocating %d bytes\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 708 | card->rxbd_ring_size); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 709 | card->rxbd_ring_vbase = pci_alloc_consistent(card->dev, |
| 710 | card->rxbd_ring_size, |
| 711 | &card->rxbd_ring_pbase); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 712 | if (!card->rxbd_ring_vbase) { |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 713 | dev_err(adapter->dev, |
| 714 | "allocate consistent memory (%d bytes) failed!\n", |
| 715 | card->rxbd_ring_size); |
Amitkumar Karwar | 8c53e42 | 2011-12-08 20:41:03 -0800 | [diff] [blame] | 716 | return -ENOMEM; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 717 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 718 | |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 719 | dev_dbg(adapter->dev, |
| 720 | "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n", |
| 721 | card->rxbd_ring_vbase, (u32)card->rxbd_ring_pbase, |
| 722 | (u32)((u64)card->rxbd_ring_pbase >> 32), |
| 723 | card->rxbd_ring_size); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 724 | |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 725 | return mwifiex_init_rxq_ring(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /* |
| 729 | * This function deletes Buffer descriptor ring for RX |
| 730 | */ |
| 731 | static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter) |
| 732 | { |
| 733 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 734 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 735 | |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 736 | mwifiex_cleanup_rxq_ring(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 737 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 738 | if (card->rxbd_ring_vbase) |
| 739 | pci_free_consistent(card->dev, card->rxbd_ring_size, |
| 740 | card->rxbd_ring_vbase, |
| 741 | card->rxbd_ring_pbase); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 742 | card->rxbd_ring_size = 0; |
| 743 | card->rxbd_wrptr = 0; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 744 | card->rxbd_rdptr = 0 | reg->rx_rollover_ind; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 745 | card->rxbd_ring_vbase = NULL; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 746 | card->rxbd_ring_pbase = 0; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | * This function creates buffer descriptor ring for Events |
| 753 | */ |
| 754 | static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) |
| 755 | { |
| 756 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 757 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 758 | |
| 759 | /* |
| 760 | * driver maintaines the read pointer and firmware maintaines the write |
| 761 | * pointer. The write pointer starts at 0 (zero) while the read pointer |
| 762 | * starts at zero with rollover bit set |
| 763 | */ |
| 764 | card->evtbd_wrptr = 0; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 765 | card->evtbd_rdptr = reg->evt_rollover_ind; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 766 | |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 767 | card->evtbd_ring_size = sizeof(struct mwifiex_evt_buf_desc) * |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 768 | MWIFIEX_MAX_EVT_BD; |
| 769 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 770 | dev_dbg(adapter->dev, "info: evtbd_ring: Allocating %d bytes\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 771 | card->evtbd_ring_size); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 772 | card->evtbd_ring_vbase = pci_alloc_consistent(card->dev, |
| 773 | card->evtbd_ring_size, |
| 774 | &card->evtbd_ring_pbase); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 775 | if (!card->evtbd_ring_vbase) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 776 | dev_err(adapter->dev, |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 777 | "allocate consistent memory (%d bytes) failed!\n", |
| 778 | card->evtbd_ring_size); |
Amitkumar Karwar | 8c53e42 | 2011-12-08 20:41:03 -0800 | [diff] [blame] | 779 | return -ENOMEM; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 780 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 781 | |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 782 | dev_dbg(adapter->dev, |
| 783 | "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n", |
| 784 | card->evtbd_ring_vbase, (u32)card->evtbd_ring_pbase, |
| 785 | (u32)((u64)card->evtbd_ring_pbase >> 32), |
| 786 | card->evtbd_ring_size); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 787 | |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 788 | return mwifiex_pcie_init_evt_ring(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /* |
| 792 | * This function deletes Buffer descriptor ring for Events |
| 793 | */ |
| 794 | static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter) |
| 795 | { |
| 796 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 797 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 798 | |
Avinash Patil | 0732484 | 2013-02-08 18:18:07 -0800 | [diff] [blame] | 799 | mwifiex_cleanup_evt_ring(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 800 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 801 | if (card->evtbd_ring_vbase) |
| 802 | pci_free_consistent(card->dev, card->evtbd_ring_size, |
| 803 | card->evtbd_ring_vbase, |
| 804 | card->evtbd_ring_pbase); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 805 | card->evtbd_wrptr = 0; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 806 | card->evtbd_rdptr = 0 | reg->evt_rollover_ind; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 807 | card->evtbd_ring_size = 0; |
| 808 | card->evtbd_ring_vbase = NULL; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 809 | card->evtbd_ring_pbase = 0; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | * This function allocates a buffer for CMDRSP |
| 816 | */ |
| 817 | static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter) |
| 818 | { |
| 819 | struct pcie_service_card *card = adapter->card; |
| 820 | struct sk_buff *skb; |
| 821 | |
| 822 | /* Allocate memory for receiving command response data */ |
| 823 | skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE); |
| 824 | if (!skb) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 825 | dev_err(adapter->dev, |
| 826 | "Unable to allocate skb for command response data.\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 827 | return -ENOMEM; |
| 828 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 829 | skb_put(skb, MWIFIEX_UPLD_SIZE); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 830 | if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE, |
| 831 | PCI_DMA_FROMDEVICE)) |
| 832 | return -1; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 833 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 834 | card->cmdrsp_buf = skb; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | /* |
| 840 | * This function deletes a buffer for CMDRSP |
| 841 | */ |
| 842 | static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter) |
| 843 | { |
| 844 | struct pcie_service_card *card; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 845 | dma_addr_t buf_pa; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 846 | |
| 847 | if (!adapter) |
| 848 | return 0; |
| 849 | |
| 850 | card = adapter->card; |
| 851 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 852 | if (card && card->cmdrsp_buf) { |
| 853 | MWIFIEX_SKB_PACB(card->cmdrsp_buf, &buf_pa); |
| 854 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, |
| 855 | PCI_DMA_FROMDEVICE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 856 | dev_kfree_skb_any(card->cmdrsp_buf); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 857 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 858 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 859 | if (card && card->cmd_buf) { |
| 860 | MWIFIEX_SKB_PACB(card->cmd_buf, &buf_pa); |
| 861 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_SIZE_OF_CMD_BUFFER, |
| 862 | PCI_DMA_TODEVICE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 863 | dev_kfree_skb_any(card->cmd_buf); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 864 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * This function allocates a buffer for sleep cookie |
| 870 | */ |
| 871 | static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter) |
| 872 | { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 873 | struct pcie_service_card *card = adapter->card; |
| 874 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 875 | card->sleep_cookie_vbase = pci_alloc_consistent(card->dev, sizeof(u32), |
| 876 | &card->sleep_cookie_pbase); |
| 877 | if (!card->sleep_cookie_vbase) { |
| 878 | dev_err(adapter->dev, "pci_alloc_consistent failed!\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 879 | return -ENOMEM; |
| 880 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 881 | /* Init val of Sleep Cookie */ |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 882 | *(u32 *)card->sleep_cookie_vbase = FW_AWAKE_COOKIE; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 883 | |
| 884 | dev_dbg(adapter->dev, "alloc_scook: sleep cookie=0x%x\n", |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 885 | *((u32 *)card->sleep_cookie_vbase)); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 886 | |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | * This function deletes buffer for sleep cookie |
| 892 | */ |
| 893 | static int mwifiex_pcie_delete_sleep_cookie_buf(struct mwifiex_adapter *adapter) |
| 894 | { |
| 895 | struct pcie_service_card *card; |
| 896 | |
| 897 | if (!adapter) |
| 898 | return 0; |
| 899 | |
| 900 | card = adapter->card; |
| 901 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 902 | if (card && card->sleep_cookie_vbase) { |
| 903 | pci_free_consistent(card->dev, sizeof(u32), |
| 904 | card->sleep_cookie_vbase, |
| 905 | card->sleep_cookie_pbase); |
| 906 | card->sleep_cookie_vbase = NULL; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
Avinash Patil | fbd7e7a | 2013-01-03 21:21:31 -0800 | [diff] [blame] | 912 | /* This function flushes the TX buffer descriptor ring |
| 913 | * This function defined as handler is also called while cleaning TXRX |
| 914 | * during disconnect/ bss stop. |
| 915 | */ |
| 916 | static int mwifiex_clean_pcie_ring_buf(struct mwifiex_adapter *adapter) |
| 917 | { |
| 918 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 919 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | fbd7e7a | 2013-01-03 21:21:31 -0800 | [diff] [blame] | 920 | u32 rdptr; |
| 921 | |
| 922 | /* Read the TX ring read pointer set by firmware */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 923 | if (mwifiex_read_reg(adapter, reg->tx_rdptr, &rdptr)) { |
Avinash Patil | fbd7e7a | 2013-01-03 21:21:31 -0800 | [diff] [blame] | 924 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 925 | "Flush TXBD: failed to read reg->tx_rdptr\n"); |
Avinash Patil | fbd7e7a | 2013-01-03 21:21:31 -0800 | [diff] [blame] | 926 | return -1; |
| 927 | } |
| 928 | |
| 929 | if (!mwifiex_pcie_txbd_empty(card, rdptr)) { |
| 930 | card->txbd_flush = 1; |
| 931 | /* write pointer already set at last send |
| 932 | * send dnld-rdy intr again, wait for completion. |
| 933 | */ |
| 934 | if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT, |
| 935 | CPU_INTR_DNLD_RDY)) { |
| 936 | dev_err(adapter->dev, |
| 937 | "failed to assert dnld-rdy interrupt.\n"); |
| 938 | return -1; |
| 939 | } |
| 940 | } |
| 941 | return 0; |
| 942 | } |
| 943 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 944 | /* |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 945 | * This function unmaps and frees downloaded data buffer |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 946 | */ |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 947 | static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 948 | { |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 949 | struct sk_buff *skb; |
| 950 | dma_addr_t buf_pa; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 951 | u32 wrdoneidx, rdptr, num_tx_buffs, unmap_count = 0; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 952 | struct mwifiex_pcie_buf_desc *desc; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 953 | struct mwifiex_pfu_buf_desc *desc2; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 954 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 955 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 956 | |
| 957 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
| 958 | mwifiex_pm_wakeup_card(adapter); |
| 959 | |
| 960 | /* Read the TX ring read pointer set by firmware */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 961 | if (mwifiex_read_reg(adapter, reg->tx_rdptr, &rdptr)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 962 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 963 | "SEND COMP: failed to read reg->tx_rdptr\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 964 | return -1; |
| 965 | } |
| 966 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 967 | dev_dbg(adapter->dev, "SEND COMP: rdptr_prev=0x%x, rdptr=0x%x\n", |
| 968 | card->txbd_rdptr, rdptr); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 969 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 970 | num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 971 | /* free from previous txbd_rdptr to current txbd_rdptr */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 972 | while (((card->txbd_rdptr & reg->tx_mask) != |
| 973 | (rdptr & reg->tx_mask)) || |
| 974 | ((card->txbd_rdptr & reg->tx_rollover_ind) != |
| 975 | (rdptr & reg->tx_rollover_ind))) { |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 976 | wrdoneidx = (card->txbd_rdptr & reg->tx_mask) >> |
| 977 | reg->tx_start_ptr; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 978 | |
| 979 | skb = card->tx_buf_list[wrdoneidx]; |
| 980 | if (skb) { |
| 981 | dev_dbg(adapter->dev, |
| 982 | "SEND COMP: Detach skb %p at txbd_rdidx=%d\n", |
| 983 | skb, wrdoneidx); |
| 984 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 985 | pci_unmap_single(card->dev, buf_pa, skb->len, |
| 986 | PCI_DMA_TODEVICE); |
| 987 | |
| 988 | unmap_count++; |
| 989 | |
| 990 | if (card->txbd_flush) |
| 991 | mwifiex_write_data_complete(adapter, skb, 0, |
| 992 | -1); |
| 993 | else |
| 994 | mwifiex_write_data_complete(adapter, skb, 0, 0); |
| 995 | } |
| 996 | |
| 997 | card->tx_buf_list[wrdoneidx] = NULL; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 998 | |
| 999 | if (reg->pfu_enabled) { |
| 1000 | desc2 = (void *)card->txbd_ring[wrdoneidx]; |
| 1001 | memset(desc2, 0, sizeof(*desc2)); |
| 1002 | } else { |
| 1003 | desc = card->txbd_ring[wrdoneidx]; |
| 1004 | memset(desc, 0, sizeof(*desc)); |
| 1005 | } |
| 1006 | switch (card->dev->device) { |
| 1007 | case PCIE_DEVICE_ID_MARVELL_88W8766P: |
| 1008 | card->txbd_rdptr++; |
| 1009 | break; |
| 1010 | case PCIE_DEVICE_ID_MARVELL_88W8897: |
| 1011 | card->txbd_rdptr += reg->ring_tx_start_ptr; |
| 1012 | break; |
| 1013 | } |
| 1014 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1015 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1016 | if ((card->txbd_rdptr & reg->tx_mask) == num_tx_buffs) |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1017 | card->txbd_rdptr = ((card->txbd_rdptr & |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1018 | reg->tx_rollover_ind) ^ |
| 1019 | reg->tx_rollover_ind); |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | if (unmap_count) |
| 1023 | adapter->data_sent = false; |
| 1024 | |
| 1025 | if (card->txbd_flush) { |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1026 | if (((card->txbd_wrptr & reg->tx_mask) == |
| 1027 | (card->txbd_rdptr & reg->tx_mask)) && |
| 1028 | ((card->txbd_wrptr & reg->tx_rollover_ind) != |
| 1029 | (card->txbd_rdptr & reg->tx_rollover_ind))) |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1030 | card->txbd_flush = 0; |
| 1031 | else |
| 1032 | mwifiex_clean_pcie_ring_buf(adapter); |
| 1033 | } |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | /* This function sends data buffer to device. First 4 bytes of payload |
| 1039 | * are filled with payload length and payload type. Then this payload |
| 1040 | * is mapped to PCI device memory. Tx ring pointers are advanced accordingly. |
| 1041 | * Download ready interrupt to FW is deffered if Tx ring is not full and |
| 1042 | * additional payload can be accomodated. |
| 1043 | */ |
| 1044 | static int |
| 1045 | mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb, |
| 1046 | struct mwifiex_tx_param *tx_param) |
| 1047 | { |
| 1048 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1049 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1050 | u32 wrindx, num_tx_buffs, rx_val; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1051 | int ret; |
| 1052 | dma_addr_t buf_pa; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 1053 | struct mwifiex_pcie_buf_desc *desc; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1054 | struct mwifiex_pfu_buf_desc *desc2; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1055 | __le16 *tmp; |
| 1056 | |
| 1057 | if (!(skb->data && skb->len)) { |
| 1058 | dev_err(adapter->dev, "%s(): invalid parameter <%p, %#x>\n", |
| 1059 | __func__, skb->data, skb->len); |
| 1060 | return -1; |
| 1061 | } |
| 1062 | |
| 1063 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
| 1064 | mwifiex_pm_wakeup_card(adapter); |
| 1065 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1066 | num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1067 | dev_dbg(adapter->dev, "info: SEND DATA: <Rd: %#x, Wr: %#x>\n", |
| 1068 | card->txbd_rdptr, card->txbd_wrptr); |
| 1069 | if (mwifiex_pcie_txbd_not_full(card)) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1070 | u8 *payload; |
| 1071 | |
| 1072 | adapter->data_sent = true; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1073 | payload = skb->data; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1074 | tmp = (__le16 *)&payload[0]; |
| 1075 | *tmp = cpu_to_le16((u16)skb->len); |
| 1076 | tmp = (__le16 *)&payload[2]; |
| 1077 | *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA); |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1078 | |
| 1079 | if (mwifiex_map_pci_memory(adapter, skb, skb->len , |
| 1080 | PCI_DMA_TODEVICE)) |
| 1081 | return -1; |
| 1082 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1083 | wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1084 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 1085 | card->tx_buf_list[wrindx] = skb; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1086 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1087 | if (reg->pfu_enabled) { |
| 1088 | desc2 = (void *)card->txbd_ring[wrindx]; |
| 1089 | desc2->paddr = buf_pa; |
| 1090 | desc2->len = (u16)skb->len; |
| 1091 | desc2->frag_len = (u16)skb->len; |
| 1092 | desc2->offset = 0; |
| 1093 | desc2->flags = MWIFIEX_BD_FLAG_FIRST_DESC | |
| 1094 | MWIFIEX_BD_FLAG_LAST_DESC; |
| 1095 | } else { |
| 1096 | desc = card->txbd_ring[wrindx]; |
| 1097 | desc->paddr = buf_pa; |
| 1098 | desc->len = (u16)skb->len; |
| 1099 | desc->flags = MWIFIEX_BD_FLAG_FIRST_DESC | |
| 1100 | MWIFIEX_BD_FLAG_LAST_DESC; |
| 1101 | } |
| 1102 | |
| 1103 | switch (card->dev->device) { |
| 1104 | case PCIE_DEVICE_ID_MARVELL_88W8766P: |
| 1105 | card->txbd_wrptr++; |
| 1106 | break; |
| 1107 | case PCIE_DEVICE_ID_MARVELL_88W8897: |
| 1108 | card->txbd_wrptr += reg->ring_tx_start_ptr; |
| 1109 | break; |
| 1110 | } |
| 1111 | |
| 1112 | if ((card->txbd_wrptr & reg->tx_mask) == num_tx_buffs) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1113 | card->txbd_wrptr = ((card->txbd_wrptr & |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1114 | reg->tx_rollover_ind) ^ |
| 1115 | reg->tx_rollover_ind); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1116 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1117 | rx_val = card->rxbd_rdptr & reg->rx_wrap_mask; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1118 | /* Write the TX ring write pointer in to reg->tx_wrptr */ |
| 1119 | if (mwifiex_write_reg(adapter, reg->tx_wrptr, |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1120 | card->txbd_wrptr | rx_val)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1121 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1122 | "SEND DATA: failed to write reg->tx_wrptr\n"); |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1123 | ret = -1; |
| 1124 | goto done_unmap; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1125 | } |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1126 | if ((mwifiex_pcie_txbd_not_full(card)) && |
| 1127 | tx_param->next_pkt_len) { |
| 1128 | /* have more packets and TxBD still can hold more */ |
| 1129 | dev_dbg(adapter->dev, |
| 1130 | "SEND DATA: delay dnld-rdy interrupt.\n"); |
| 1131 | adapter->data_sent = false; |
| 1132 | } else { |
| 1133 | /* Send the TX ready interrupt */ |
| 1134 | if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT, |
| 1135 | CPU_INTR_DNLD_RDY)) { |
| 1136 | dev_err(adapter->dev, |
| 1137 | "SEND DATA: failed to assert dnld-rdy interrupt.\n"); |
| 1138 | ret = -1; |
| 1139 | goto done_unmap; |
| 1140 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1141 | } |
| 1142 | dev_dbg(adapter->dev, "info: SEND DATA: Updated <Rd: %#x, Wr: " |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1143 | "%#x> and sent packet to firmware successfully\n", |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1144 | card->txbd_rdptr, card->txbd_wrptr); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1145 | } else { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1146 | dev_dbg(adapter->dev, |
| 1147 | "info: TX Ring full, can't send packets to fw\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1148 | adapter->data_sent = true; |
| 1149 | /* Send the TX ready interrupt */ |
| 1150 | if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT, |
| 1151 | CPU_INTR_DNLD_RDY)) |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1152 | dev_err(adapter->dev, |
| 1153 | "SEND DATA: failed to assert door-bell intr\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1154 | return -EBUSY; |
| 1155 | } |
| 1156 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1157 | return -EINPROGRESS; |
| 1158 | done_unmap: |
| 1159 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 1160 | pci_unmap_single(card->dev, buf_pa, skb->len, PCI_DMA_TODEVICE); |
| 1161 | card->tx_buf_list[wrindx] = NULL; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1162 | if (reg->pfu_enabled) |
| 1163 | memset(desc2, 0, sizeof(*desc2)); |
| 1164 | else |
| 1165 | memset(desc, 0, sizeof(*desc)); |
| 1166 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1167 | return ret; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /* |
| 1171 | * This function handles received buffer ring and |
| 1172 | * dispatches packets to upper |
| 1173 | */ |
| 1174 | static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter) |
| 1175 | { |
| 1176 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1177 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1178 | u32 wrptr, rd_index, tx_val; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1179 | dma_addr_t buf_pa; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1180 | int ret = 0; |
| 1181 | struct sk_buff *skb_tmp = NULL; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 1182 | struct mwifiex_pcie_buf_desc *desc; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1183 | struct mwifiex_pfu_buf_desc *desc2; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1184 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1185 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
| 1186 | mwifiex_pm_wakeup_card(adapter); |
| 1187 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1188 | /* Read the RX ring Write pointer set by firmware */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1189 | if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1190 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1191 | "RECV DATA: failed to read reg->rx_wrptr\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1192 | ret = -1; |
| 1193 | goto done; |
| 1194 | } |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1195 | card->rxbd_wrptr = wrptr; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1196 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1197 | while (((wrptr & reg->rx_mask) != |
| 1198 | (card->rxbd_rdptr & reg->rx_mask)) || |
| 1199 | ((wrptr & reg->rx_rollover_ind) == |
| 1200 | (card->rxbd_rdptr & reg->rx_rollover_ind))) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1201 | struct sk_buff *skb_data; |
| 1202 | u16 rx_len; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1203 | __le16 pkt_len; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1204 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1205 | rd_index = card->rxbd_rdptr & reg->rx_mask; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1206 | skb_data = card->rx_buf_list[rd_index]; |
| 1207 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1208 | MWIFIEX_SKB_PACB(skb_data, &buf_pa); |
| 1209 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_RX_DATA_BUF_SIZE, |
| 1210 | PCI_DMA_FROMDEVICE); |
| 1211 | card->rx_buf_list[rd_index] = NULL; |
| 1212 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1213 | /* Get data length from interface header - |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1214 | * first 2 bytes for len, next 2 bytes is for type |
| 1215 | */ |
| 1216 | pkt_len = *((__le16 *)skb_data->data); |
| 1217 | rx_len = le16_to_cpu(pkt_len); |
| 1218 | skb_put(skb_data, rx_len); |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1219 | dev_dbg(adapter->dev, |
| 1220 | "info: RECV DATA: Rd=%#x, Wr=%#x, Len=%d\n", |
| 1221 | card->rxbd_rdptr, wrptr, rx_len); |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1222 | skb_pull(skb_data, INTF_HEADER_LEN); |
| 1223 | mwifiex_handle_rx_packet(adapter, skb_data); |
| 1224 | |
| 1225 | skb_tmp = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1226 | if (!skb_tmp) { |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1227 | dev_err(adapter->dev, |
| 1228 | "Unable to allocate skb.\n"); |
| 1229 | return -ENOMEM; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1232 | if (mwifiex_map_pci_memory(adapter, skb_tmp, |
| 1233 | MWIFIEX_RX_DATA_BUF_SIZE, |
| 1234 | PCI_DMA_FROMDEVICE)) |
| 1235 | return -1; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1236 | |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1237 | MWIFIEX_SKB_PACB(skb_tmp, &buf_pa); |
| 1238 | |
| 1239 | dev_dbg(adapter->dev, |
| 1240 | "RECV DATA: Attach new sk_buff %p at rxbd_rdidx=%d\n", |
| 1241 | skb_tmp, rd_index); |
| 1242 | card->rx_buf_list[rd_index] = skb_tmp; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1243 | |
| 1244 | if (reg->pfu_enabled) { |
| 1245 | desc2 = (void *)card->rxbd_ring[rd_index]; |
| 1246 | desc2->paddr = buf_pa; |
| 1247 | desc2->len = skb_tmp->len; |
| 1248 | desc2->frag_len = skb_tmp->len; |
| 1249 | desc2->offset = 0; |
| 1250 | desc2->flags = reg->ring_flag_sop | reg->ring_flag_eop; |
| 1251 | } else { |
| 1252 | desc = card->rxbd_ring[rd_index]; |
| 1253 | desc->paddr = buf_pa; |
| 1254 | desc->len = skb_tmp->len; |
| 1255 | desc->flags = 0; |
| 1256 | } |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1257 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1258 | if ((++card->rxbd_rdptr & reg->rx_mask) == |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1259 | MWIFIEX_MAX_TXRX_BD) { |
| 1260 | card->rxbd_rdptr = ((card->rxbd_rdptr & |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1261 | reg->rx_rollover_ind) ^ |
| 1262 | reg->rx_rollover_ind); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1263 | } |
| 1264 | dev_dbg(adapter->dev, "info: RECV DATA: <Rd: %#x, Wr: %#x>\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1265 | card->rxbd_rdptr, wrptr); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1266 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1267 | tx_val = card->txbd_wrptr & reg->tx_wrap_mask; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1268 | /* Write the RX ring read pointer in to reg->rx_rdptr */ |
| 1269 | if (mwifiex_write_reg(adapter, reg->rx_rdptr, |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1270 | card->rxbd_rdptr | tx_val)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1271 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1272 | "RECV DATA: failed to write reg->rx_rdptr\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1273 | ret = -1; |
| 1274 | goto done; |
| 1275 | } |
| 1276 | |
| 1277 | /* Read the RX ring Write pointer set by firmware */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1278 | if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1279 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1280 | "RECV DATA: failed to read reg->rx_wrptr\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1281 | ret = -1; |
| 1282 | goto done; |
| 1283 | } |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1284 | dev_dbg(adapter->dev, |
| 1285 | "info: RECV DATA: Rcvd packet from fw successfully\n"); |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 1286 | card->rxbd_wrptr = wrptr; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | done: |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1290 | return ret; |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | * This function downloads the boot command to device |
| 1295 | */ |
| 1296 | static int |
| 1297 | mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) |
| 1298 | { |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1299 | dma_addr_t buf_pa; |
| 1300 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1301 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1302 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1303 | if (!(skb->data && skb->len)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1304 | dev_err(adapter->dev, |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1305 | "Invalid parameter in %s <%p. len %d>\n", |
| 1306 | __func__, skb->data, skb->len); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1307 | return -1; |
| 1308 | } |
| 1309 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1310 | if (mwifiex_map_pci_memory(adapter, skb, skb->len , PCI_DMA_TODEVICE)) |
| 1311 | return -1; |
| 1312 | |
| 1313 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 1314 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1315 | /* Write the lower 32bits of the physical address to low command |
| 1316 | * address scratch register |
| 1317 | */ |
| 1318 | if (mwifiex_write_reg(adapter, reg->cmd_addr_lo, (u32)buf_pa)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1319 | dev_err(adapter->dev, |
| 1320 | "%s: failed to write download command to boot code.\n", |
| 1321 | __func__); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1322 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, |
| 1323 | PCI_DMA_TODEVICE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1324 | return -1; |
| 1325 | } |
| 1326 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1327 | /* Write the upper 32bits of the physical address to high command |
| 1328 | * address scratch register |
| 1329 | */ |
| 1330 | if (mwifiex_write_reg(adapter, reg->cmd_addr_hi, |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1331 | (u32)((u64)buf_pa >> 32))) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1332 | dev_err(adapter->dev, |
| 1333 | "%s: failed to write download command to boot code.\n", |
| 1334 | __func__); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1335 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, |
| 1336 | PCI_DMA_TODEVICE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1337 | return -1; |
| 1338 | } |
| 1339 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1340 | /* Write the command length to cmd_size scratch register */ |
| 1341 | if (mwifiex_write_reg(adapter, reg->cmd_size, skb->len)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1342 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1343 | "%s: failed to write command len to cmd_size scratch reg\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1344 | __func__); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1345 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, |
| 1346 | PCI_DMA_TODEVICE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1347 | return -1; |
| 1348 | } |
| 1349 | |
| 1350 | /* Ring the door bell */ |
| 1351 | if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT, |
| 1352 | CPU_INTR_DOOR_BELL)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1353 | dev_err(adapter->dev, |
| 1354 | "%s: failed to assert door-bell intr\n", __func__); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1355 | pci_unmap_single(card->dev, buf_pa, |
| 1356 | MWIFIEX_UPLD_SIZE, PCI_DMA_TODEVICE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1357 | return -1; |
| 1358 | } |
| 1359 | |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Avinash Patil | c6d1d87 | 2013-01-03 21:21:29 -0800 | [diff] [blame] | 1363 | /* This function init rx port in firmware which in turn enables to receive data |
| 1364 | * from device before transmitting any packet. |
| 1365 | */ |
| 1366 | static int mwifiex_pcie_init_fw_port(struct mwifiex_adapter *adapter) |
| 1367 | { |
| 1368 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1369 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1370 | int tx_wrap = card->txbd_wrptr & reg->tx_wrap_mask; |
Avinash Patil | c6d1d87 | 2013-01-03 21:21:29 -0800 | [diff] [blame] | 1371 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1372 | /* Write the RX ring read pointer in to reg->rx_rdptr */ |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 1373 | if (mwifiex_write_reg(adapter, reg->rx_rdptr, card->rxbd_rdptr | |
| 1374 | tx_wrap)) { |
Avinash Patil | c6d1d87 | 2013-01-03 21:21:29 -0800 | [diff] [blame] | 1375 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1376 | "RECV DATA: failed to write reg->rx_rdptr\n"); |
Avinash Patil | c6d1d87 | 2013-01-03 21:21:29 -0800 | [diff] [blame] | 1377 | return -1; |
| 1378 | } |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
| 1382 | /* This function downloads commands to the device |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1383 | */ |
| 1384 | static int |
| 1385 | mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) |
| 1386 | { |
| 1387 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1388 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1389 | int ret = 0; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1390 | dma_addr_t cmd_buf_pa, cmdrsp_buf_pa; |
| 1391 | u8 *payload = (u8 *)skb->data; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1392 | |
| 1393 | if (!(skb->data && skb->len)) { |
| 1394 | dev_err(adapter->dev, "Invalid parameter in %s <%p, %#x>\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1395 | __func__, skb->data, skb->len); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1396 | return -1; |
| 1397 | } |
| 1398 | |
| 1399 | /* Make sure a command response buffer is available */ |
| 1400 | if (!card->cmdrsp_buf) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1401 | dev_err(adapter->dev, |
| 1402 | "No response buffer available, send command failed\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1403 | return -EBUSY; |
| 1404 | } |
| 1405 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1406 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
| 1407 | mwifiex_pm_wakeup_card(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1408 | |
| 1409 | adapter->cmd_sent = true; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1410 | |
| 1411 | *(__le16 *)&payload[0] = cpu_to_le16((u16)skb->len); |
| 1412 | *(__le16 *)&payload[2] = cpu_to_le16(MWIFIEX_TYPE_CMD); |
| 1413 | |
| 1414 | if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE)) |
| 1415 | return -1; |
| 1416 | |
| 1417 | card->cmd_buf = skb; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1418 | |
| 1419 | /* To send a command, the driver will: |
| 1420 | 1. Write the 64bit physical address of the data buffer to |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1421 | cmd response address low + cmd response address high |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1422 | 2. Ring the door bell (i.e. set the door bell interrupt) |
| 1423 | |
| 1424 | In response to door bell interrupt, the firmware will perform |
| 1425 | the DMA of the command packet (first header to obtain the total |
| 1426 | length and then rest of the command). |
| 1427 | */ |
| 1428 | |
| 1429 | if (card->cmdrsp_buf) { |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1430 | MWIFIEX_SKB_PACB(card->cmdrsp_buf, &cmdrsp_buf_pa); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1431 | /* Write the lower 32bits of the cmdrsp buffer physical |
| 1432 | address */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1433 | if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo, |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1434 | (u32)cmdrsp_buf_pa)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1435 | dev_err(adapter->dev, |
| 1436 | "Failed to write download cmd to boot code.\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1437 | ret = -1; |
| 1438 | goto done; |
| 1439 | } |
| 1440 | /* Write the upper 32bits of the cmdrsp buffer physical |
| 1441 | address */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1442 | if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi, |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1443 | (u32)((u64)cmdrsp_buf_pa >> 32))) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1444 | dev_err(adapter->dev, |
| 1445 | "Failed to write download cmd to boot code.\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1446 | ret = -1; |
| 1447 | goto done; |
| 1448 | } |
| 1449 | } |
| 1450 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1451 | MWIFIEX_SKB_PACB(card->cmd_buf, &cmd_buf_pa); |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1452 | /* Write the lower 32bits of the physical address to reg->cmd_addr_lo */ |
| 1453 | if (mwifiex_write_reg(adapter, reg->cmd_addr_lo, |
| 1454 | (u32)cmd_buf_pa)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1455 | dev_err(adapter->dev, |
| 1456 | "Failed to write download cmd to boot code.\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1457 | ret = -1; |
| 1458 | goto done; |
| 1459 | } |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1460 | /* Write the upper 32bits of the physical address to reg->cmd_addr_hi */ |
| 1461 | if (mwifiex_write_reg(adapter, reg->cmd_addr_hi, |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1462 | (u32)((u64)cmd_buf_pa >> 32))) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1463 | dev_err(adapter->dev, |
| 1464 | "Failed to write download cmd to boot code.\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1465 | ret = -1; |
| 1466 | goto done; |
| 1467 | } |
| 1468 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1469 | /* Write the command length to reg->cmd_size */ |
| 1470 | if (mwifiex_write_reg(adapter, reg->cmd_size, |
| 1471 | card->cmd_buf->len)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1472 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1473 | "Failed to write cmd len to reg->cmd_size\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1474 | ret = -1; |
| 1475 | goto done; |
| 1476 | } |
| 1477 | |
| 1478 | /* Ring the door bell */ |
| 1479 | if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT, |
| 1480 | CPU_INTR_DOOR_BELL)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1481 | dev_err(adapter->dev, |
| 1482 | "Failed to assert door-bell intr\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1483 | ret = -1; |
| 1484 | goto done; |
| 1485 | } |
| 1486 | |
| 1487 | done: |
| 1488 | if (ret) |
| 1489 | adapter->cmd_sent = false; |
| 1490 | |
| 1491 | return 0; |
| 1492 | } |
| 1493 | |
| 1494 | /* |
| 1495 | * This function handles command complete interrupt |
| 1496 | */ |
| 1497 | static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter) |
| 1498 | { |
| 1499 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1500 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1501 | struct sk_buff *skb = card->cmdrsp_buf; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1502 | int count = 0; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1503 | u16 rx_len; |
| 1504 | __le16 pkt_len; |
| 1505 | dma_addr_t buf_pa; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1506 | |
| 1507 | dev_dbg(adapter->dev, "info: Rx CMD Response\n"); |
| 1508 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1509 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 1510 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, |
| 1511 | PCI_DMA_FROMDEVICE); |
| 1512 | |
| 1513 | pkt_len = *((__le16 *)skb->data); |
| 1514 | rx_len = le16_to_cpu(pkt_len); |
| 1515 | skb_trim(skb, rx_len); |
| 1516 | skb_pull(skb, INTF_HEADER_LEN); |
| 1517 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1518 | if (!adapter->curr_cmd) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1519 | if (adapter->ps_state == PS_STATE_SLEEP_CFM) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1520 | mwifiex_process_sleep_confirm_resp(adapter, skb->data, |
| 1521 | skb->len); |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 1522 | while (reg->sleep_cookie && (count++ < 10) && |
| 1523 | mwifiex_pcie_ok_to_access_hw(adapter)) |
Yogesh Ashok Powar | e7891ba | 2012-03-12 19:35:11 -0700 | [diff] [blame] | 1524 | usleep_range(50, 60); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1525 | } else { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1526 | dev_err(adapter->dev, |
| 1527 | "There is no command but got cmdrsp\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1528 | } |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1529 | memcpy(adapter->upld_buf, skb->data, |
| 1530 | min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len)); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1531 | if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE, |
| 1532 | PCI_DMA_FROMDEVICE)) |
| 1533 | return -1; |
| 1534 | |
| 1535 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1536 | } else if (mwifiex_pcie_ok_to_access_hw(adapter)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1537 | adapter->curr_cmd->resp_skb = skb; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1538 | adapter->cmd_resp_received = true; |
| 1539 | /* Take the pointer and set it to CMD node and will |
| 1540 | return in the response complete callback */ |
| 1541 | card->cmdrsp_buf = NULL; |
| 1542 | |
| 1543 | /* Clear the cmd-rsp buffer address in scratch registers. This |
| 1544 | will prevent firmware from writing to the same response |
| 1545 | buffer again. */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1546 | if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo, 0)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1547 | dev_err(adapter->dev, |
| 1548 | "cmd_done: failed to clear cmd_rsp_addr_lo\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1549 | return -1; |
| 1550 | } |
| 1551 | /* Write the upper 32bits of the cmdrsp buffer physical |
| 1552 | address */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1553 | if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi, 0)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1554 | dev_err(adapter->dev, |
| 1555 | "cmd_done: failed to clear cmd_rsp_addr_hi\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1556 | return -1; |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
| 1563 | /* |
| 1564 | * Command Response processing complete handler |
| 1565 | */ |
| 1566 | static int mwifiex_pcie_cmdrsp_complete(struct mwifiex_adapter *adapter, |
| 1567 | struct sk_buff *skb) |
| 1568 | { |
| 1569 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1570 | dma_addr_t buf_pa; |
| 1571 | struct sk_buff *skb_tmp; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1572 | |
| 1573 | if (skb) { |
| 1574 | card->cmdrsp_buf = skb; |
| 1575 | skb_push(card->cmdrsp_buf, INTF_HEADER_LEN); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1576 | if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE, |
| 1577 | PCI_DMA_FROMDEVICE)) |
| 1578 | return -1; |
| 1579 | } |
| 1580 | |
| 1581 | skb_tmp = card->cmd_buf; |
| 1582 | if (skb_tmp) { |
| 1583 | MWIFIEX_SKB_PACB(skb_tmp, &buf_pa); |
| 1584 | pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE, |
| 1585 | PCI_DMA_FROMDEVICE); |
| 1586 | card->cmd_buf = NULL; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | return 0; |
| 1590 | } |
| 1591 | |
| 1592 | /* |
| 1593 | * This function handles firmware event ready interrupt |
| 1594 | */ |
| 1595 | static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter) |
| 1596 | { |
| 1597 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1598 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1599 | u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; |
| 1600 | u32 wrptr, event; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1601 | dma_addr_t buf_pa; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 1602 | struct mwifiex_evt_buf_desc *desc; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1603 | |
| 1604 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
| 1605 | mwifiex_pm_wakeup_card(adapter); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1606 | |
| 1607 | if (adapter->event_received) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1608 | dev_dbg(adapter->dev, "info: Event being processed, " |
| 1609 | "do not process this interrupt just yet\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | if (rdptr >= MWIFIEX_MAX_EVT_BD) { |
| 1614 | dev_dbg(adapter->dev, "info: Invalid read pointer...\n"); |
| 1615 | return -1; |
| 1616 | } |
| 1617 | |
| 1618 | /* Read the event ring write pointer set by firmware */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1619 | if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1620 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1621 | "EventReady: failed to read reg->evt_wrptr\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1622 | return -1; |
| 1623 | } |
| 1624 | |
| 1625 | dev_dbg(adapter->dev, "info: EventReady: Initial <Rd: 0x%x, Wr: 0x%x>", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1626 | card->evtbd_rdptr, wrptr); |
| 1627 | if (((wrptr & MWIFIEX_EVTBD_MASK) != (card->evtbd_rdptr |
| 1628 | & MWIFIEX_EVTBD_MASK)) || |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1629 | ((wrptr & reg->evt_rollover_ind) == |
| 1630 | (card->evtbd_rdptr & reg->evt_rollover_ind))) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1631 | struct sk_buff *skb_cmd; |
| 1632 | __le16 data_len = 0; |
| 1633 | u16 evt_len; |
| 1634 | |
| 1635 | dev_dbg(adapter->dev, "info: Read Index: %d\n", rdptr); |
| 1636 | skb_cmd = card->evt_buf_list[rdptr]; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1637 | MWIFIEX_SKB_PACB(skb_cmd, &buf_pa); |
| 1638 | pci_unmap_single(card->dev, buf_pa, MAX_EVENT_SIZE, |
| 1639 | PCI_DMA_FROMDEVICE); |
| 1640 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1641 | /* Take the pointer and set it to event pointer in adapter |
| 1642 | and will return back after event handling callback */ |
| 1643 | card->evt_buf_list[rdptr] = NULL; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 1644 | desc = card->evtbd_ring[rdptr]; |
| 1645 | memset(desc, 0, sizeof(*desc)); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1646 | |
| 1647 | event = *(u32 *) &skb_cmd->data[INTF_HEADER_LEN]; |
| 1648 | adapter->event_cause = event; |
| 1649 | /* The first 4bytes will be the event transfer header |
| 1650 | len is 2 bytes followed by type which is 2 bytes */ |
| 1651 | memcpy(&data_len, skb_cmd->data, sizeof(__le16)); |
| 1652 | evt_len = le16_to_cpu(data_len); |
| 1653 | |
| 1654 | skb_pull(skb_cmd, INTF_HEADER_LEN); |
| 1655 | dev_dbg(adapter->dev, "info: Event length: %d\n", evt_len); |
| 1656 | |
| 1657 | if ((evt_len > 0) && (evt_len < MAX_EVENT_SIZE)) |
| 1658 | memcpy(adapter->event_body, skb_cmd->data + |
| 1659 | MWIFIEX_EVENT_HEADER_LEN, evt_len - |
| 1660 | MWIFIEX_EVENT_HEADER_LEN); |
| 1661 | |
| 1662 | adapter->event_received = true; |
| 1663 | adapter->event_skb = skb_cmd; |
| 1664 | |
| 1665 | /* Do not update the event read pointer here, wait till the |
| 1666 | buffer is released. This is just to make things simpler, |
| 1667 | we need to find a better method of managing these buffers. |
| 1668 | */ |
| 1669 | } |
| 1670 | |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
| 1674 | /* |
| 1675 | * Event processing complete handler |
| 1676 | */ |
| 1677 | static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter, |
| 1678 | struct sk_buff *skb) |
| 1679 | { |
| 1680 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1681 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1682 | int ret = 0; |
| 1683 | u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; |
| 1684 | u32 wrptr; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1685 | dma_addr_t buf_pa; |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 1686 | struct mwifiex_evt_buf_desc *desc; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1687 | |
| 1688 | if (!skb) |
| 1689 | return 0; |
| 1690 | |
Dan Carpenter | 1eb54c8 | 2011-11-07 19:31:47 -0800 | [diff] [blame] | 1691 | if (rdptr >= MWIFIEX_MAX_EVT_BD) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1692 | dev_err(adapter->dev, "event_complete: Invalid rdptr 0x%x\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1693 | rdptr); |
Amitkumar Karwar | 8c53e42 | 2011-12-08 20:41:03 -0800 | [diff] [blame] | 1694 | return -EINVAL; |
Dan Carpenter | 1eb54c8 | 2011-11-07 19:31:47 -0800 | [diff] [blame] | 1695 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1696 | |
| 1697 | /* Read the event ring write pointer set by firmware */ |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1698 | if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1699 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1700 | "event_complete: failed to read reg->evt_wrptr\n"); |
Amitkumar Karwar | 8c53e42 | 2011-12-08 20:41:03 -0800 | [diff] [blame] | 1701 | return -1; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | if (!card->evt_buf_list[rdptr]) { |
| 1705 | skb_push(skb, INTF_HEADER_LEN); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1706 | if (mwifiex_map_pci_memory(adapter, skb, |
| 1707 | MAX_EVENT_SIZE, |
| 1708 | PCI_DMA_FROMDEVICE)) |
| 1709 | return -1; |
| 1710 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1711 | card->evt_buf_list[rdptr] = skb; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1712 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
Avinash Patil | e05dc3e | 2013-02-08 18:18:08 -0800 | [diff] [blame] | 1713 | desc = card->evtbd_ring[rdptr]; |
| 1714 | desc->paddr = buf_pa; |
| 1715 | desc->len = (u16)skb->len; |
| 1716 | desc->flags = 0; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1717 | skb = NULL; |
| 1718 | } else { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1719 | dev_dbg(adapter->dev, |
| 1720 | "info: ERROR: buf still valid at index %d, <%p, %p>\n", |
| 1721 | rdptr, card->evt_buf_list[rdptr], skb); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | if ((++card->evtbd_rdptr & MWIFIEX_EVTBD_MASK) == MWIFIEX_MAX_EVT_BD) { |
| 1725 | card->evtbd_rdptr = ((card->evtbd_rdptr & |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1726 | reg->evt_rollover_ind) ^ |
| 1727 | reg->evt_rollover_ind); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | dev_dbg(adapter->dev, "info: Updated <Rd: 0x%x, Wr: 0x%x>", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1731 | card->evtbd_rdptr, wrptr); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1732 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1733 | /* Write the event ring read pointer in to reg->evt_rdptr */ |
| 1734 | if (mwifiex_write_reg(adapter, reg->evt_rdptr, |
| 1735 | card->evtbd_rdptr)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1736 | dev_err(adapter->dev, |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1737 | "event_complete: failed to read reg->evt_rdptr\n"); |
Amitkumar Karwar | 8c53e42 | 2011-12-08 20:41:03 -0800 | [diff] [blame] | 1738 | return -1; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1741 | dev_dbg(adapter->dev, "info: Check Events Again\n"); |
| 1742 | ret = mwifiex_pcie_process_event_ready(adapter); |
| 1743 | |
| 1744 | return ret; |
| 1745 | } |
| 1746 | |
| 1747 | /* |
| 1748 | * This function downloads the firmware to the card. |
| 1749 | * |
| 1750 | * Firmware is downloaded to the card in blocks. Every block download |
| 1751 | * is tested for CRC errors, and retried a number of times before |
| 1752 | * returning failure. |
| 1753 | */ |
| 1754 | static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, |
| 1755 | struct mwifiex_fw_image *fw) |
| 1756 | { |
| 1757 | int ret; |
| 1758 | u8 *firmware = fw->fw_buf; |
| 1759 | u32 firmware_len = fw->fw_len; |
| 1760 | u32 offset = 0; |
| 1761 | struct sk_buff *skb; |
| 1762 | u32 txlen, tx_blocks = 0, tries, len; |
| 1763 | u32 block_retry_cnt = 0; |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1764 | dma_addr_t buf_pa; |
| 1765 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1766 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1767 | |
| 1768 | if (!firmware || !firmware_len) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1769 | dev_err(adapter->dev, |
| 1770 | "No firmware image found! Terminating download\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1771 | return -1; |
| 1772 | } |
| 1773 | |
| 1774 | dev_dbg(adapter->dev, "info: Downloading FW image (%d bytes)\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1775 | firmware_len); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1776 | |
| 1777 | if (mwifiex_pcie_disable_host_int(adapter)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1778 | dev_err(adapter->dev, |
| 1779 | "%s: Disabling interrupts failed.\n", __func__); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1780 | return -1; |
| 1781 | } |
| 1782 | |
| 1783 | skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE); |
| 1784 | if (!skb) { |
| 1785 | ret = -ENOMEM; |
| 1786 | goto done; |
| 1787 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1788 | |
| 1789 | /* Perform firmware data transfer */ |
| 1790 | do { |
| 1791 | u32 ireg_intr = 0; |
| 1792 | |
| 1793 | /* More data? */ |
| 1794 | if (offset >= firmware_len) |
| 1795 | break; |
| 1796 | |
| 1797 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1798 | ret = mwifiex_read_reg(adapter, reg->cmd_size, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1799 | &len); |
| 1800 | if (ret) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1801 | dev_warn(adapter->dev, |
| 1802 | "Failed reading len from boot code\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1803 | goto done; |
| 1804 | } |
| 1805 | if (len) |
| 1806 | break; |
Yogesh Ashok Powar | e7891ba | 2012-03-12 19:35:11 -0700 | [diff] [blame] | 1807 | usleep_range(10, 20); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | if (!len) { |
| 1811 | break; |
| 1812 | } else if (len > MWIFIEX_UPLD_SIZE) { |
| 1813 | pr_err("FW download failure @ %d, invalid length %d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1814 | offset, len); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1815 | ret = -1; |
| 1816 | goto done; |
| 1817 | } |
| 1818 | |
| 1819 | txlen = len; |
| 1820 | |
| 1821 | if (len & BIT(0)) { |
| 1822 | block_retry_cnt++; |
| 1823 | if (block_retry_cnt > MAX_WRITE_IOMEM_RETRY) { |
| 1824 | pr_err("FW download failure @ %d, over max " |
| 1825 | "retry count\n", offset); |
| 1826 | ret = -1; |
| 1827 | goto done; |
| 1828 | } |
| 1829 | dev_err(adapter->dev, "FW CRC error indicated by the " |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1830 | "helper: len = 0x%04X, txlen = %d\n", |
| 1831 | len, txlen); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1832 | len &= ~BIT(0); |
| 1833 | /* Setting this to 0 to resend from same offset */ |
| 1834 | txlen = 0; |
| 1835 | } else { |
| 1836 | block_retry_cnt = 0; |
| 1837 | /* Set blocksize to transfer - checking for |
| 1838 | last block */ |
| 1839 | if (firmware_len - offset < txlen) |
| 1840 | txlen = firmware_len - offset; |
| 1841 | |
| 1842 | dev_dbg(adapter->dev, "."); |
| 1843 | |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1844 | tx_blocks = (txlen + card->pcie.blksz_fw_dl - 1) / |
| 1845 | card->pcie.blksz_fw_dl; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1846 | |
| 1847 | /* Copy payload to buffer */ |
| 1848 | memmove(skb->data, &firmware[offset], txlen); |
| 1849 | } |
| 1850 | |
| 1851 | skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len); |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1852 | skb_trim(skb, tx_blocks * card->pcie.blksz_fw_dl); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1853 | |
| 1854 | /* Send the boot command to device */ |
| 1855 | if (mwifiex_pcie_send_boot_cmd(adapter, skb)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1856 | dev_err(adapter->dev, |
| 1857 | "Failed to send firmware download command\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1858 | ret = -1; |
| 1859 | goto done; |
| 1860 | } |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1861 | |
| 1862 | MWIFIEX_SKB_PACB(skb, &buf_pa); |
| 1863 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1864 | /* Wait for the command done interrupt */ |
| 1865 | do { |
| 1866 | if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS, |
| 1867 | &ireg_intr)) { |
| 1868 | dev_err(adapter->dev, "%s: Failed to read " |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1869 | "interrupt status during fw dnld.\n", |
| 1870 | __func__); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1871 | pci_unmap_single(card->dev, buf_pa, skb->len, |
| 1872 | PCI_DMA_TODEVICE); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1873 | ret = -1; |
| 1874 | goto done; |
| 1875 | } |
| 1876 | } while ((ireg_intr & CPU_INTR_DOOR_BELL) == |
| 1877 | CPU_INTR_DOOR_BELL); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 1878 | |
| 1879 | pci_unmap_single(card->dev, buf_pa, skb->len, |
| 1880 | PCI_DMA_TODEVICE); |
| 1881 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1882 | offset += txlen; |
| 1883 | } while (true); |
| 1884 | |
| 1885 | dev_dbg(adapter->dev, "info:\nFW download over, size %d bytes\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1886 | offset); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1887 | |
| 1888 | ret = 0; |
| 1889 | |
| 1890 | done: |
| 1891 | dev_kfree_skb_any(skb); |
| 1892 | return ret; |
| 1893 | } |
| 1894 | |
| 1895 | /* |
| 1896 | * This function checks the firmware status in card. |
| 1897 | * |
| 1898 | * The winner interface is also determined by this function. |
| 1899 | */ |
| 1900 | static int |
| 1901 | mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num) |
| 1902 | { |
| 1903 | int ret = 0; |
| 1904 | u32 firmware_stat, winner_status; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1905 | struct pcie_service_card *card = adapter->card; |
| 1906 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1907 | u32 tries; |
| 1908 | |
| 1909 | /* Mask spurios interrupts */ |
| 1910 | if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS_MASK, |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1911 | HOST_INTR_MASK)) { |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1912 | dev_warn(adapter->dev, "Write register failed\n"); |
| 1913 | return -1; |
| 1914 | } |
| 1915 | |
| 1916 | dev_dbg(adapter->dev, "Setting driver ready signature\n"); |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1917 | if (mwifiex_write_reg(adapter, reg->drv_rdy, |
| 1918 | FIRMWARE_READY_PCIE)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1919 | dev_err(adapter->dev, |
| 1920 | "Failed to write driver ready signature\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1921 | return -1; |
| 1922 | } |
| 1923 | |
| 1924 | /* Wait for firmware initialization event */ |
| 1925 | for (tries = 0; tries < poll_num; tries++) { |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1926 | if (mwifiex_read_reg(adapter, reg->fw_status, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1927 | &firmware_stat)) |
| 1928 | ret = -1; |
| 1929 | else |
| 1930 | ret = 0; |
| 1931 | if (ret) |
| 1932 | continue; |
| 1933 | if (firmware_stat == FIRMWARE_READY_PCIE) { |
| 1934 | ret = 0; |
| 1935 | break; |
| 1936 | } else { |
| 1937 | mdelay(100); |
| 1938 | ret = -1; |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | if (ret) { |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 1943 | if (mwifiex_read_reg(adapter, reg->fw_status, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1944 | &winner_status)) |
| 1945 | ret = -1; |
| 1946 | else if (!winner_status) { |
| 1947 | dev_err(adapter->dev, "PCI-E is the winner\n"); |
| 1948 | adapter->winner = 1; |
| 1949 | ret = -1; |
| 1950 | } else { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1951 | dev_err(adapter->dev, |
| 1952 | "PCI-E is not the winner <%#x,%d>, exit dnld\n", |
| 1953 | ret, adapter->winner); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1954 | ret = 0; |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | return ret; |
| 1959 | } |
| 1960 | |
| 1961 | /* |
| 1962 | * This function reads the interrupt status from card. |
| 1963 | */ |
| 1964 | static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter) |
| 1965 | { |
| 1966 | u32 pcie_ireg; |
| 1967 | unsigned long flags; |
| 1968 | |
| 1969 | if (!mwifiex_pcie_ok_to_access_hw(adapter)) |
| 1970 | return; |
| 1971 | |
| 1972 | if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS, &pcie_ireg)) { |
| 1973 | dev_warn(adapter->dev, "Read register failed\n"); |
| 1974 | return; |
| 1975 | } |
| 1976 | |
| 1977 | if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) { |
| 1978 | |
| 1979 | mwifiex_pcie_disable_host_int(adapter); |
| 1980 | |
| 1981 | /* Clear the pending interrupts */ |
| 1982 | if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS, |
| 1983 | ~pcie_ireg)) { |
| 1984 | dev_warn(adapter->dev, "Write register failed\n"); |
| 1985 | return; |
| 1986 | } |
| 1987 | spin_lock_irqsave(&adapter->int_lock, flags); |
| 1988 | adapter->int_status |= pcie_ireg; |
| 1989 | spin_unlock_irqrestore(&adapter->int_lock, flags); |
| 1990 | |
| 1991 | if (pcie_ireg & HOST_INTR_CMD_DONE) { |
| 1992 | if ((adapter->ps_state == PS_STATE_SLEEP_CFM) || |
| 1993 | (adapter->ps_state == PS_STATE_SLEEP)) { |
| 1994 | mwifiex_pcie_enable_host_int(adapter); |
| 1995 | if (mwifiex_write_reg(adapter, |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 1996 | PCIE_CPU_INT_EVENT, |
| 1997 | CPU_INTR_SLEEP_CFM_DONE) |
| 1998 | ) { |
| 1999 | dev_warn(adapter->dev, |
| 2000 | "Write register failed\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2001 | return; |
| 2002 | |
| 2003 | } |
| 2004 | } |
| 2005 | } else if (!adapter->pps_uapsd_mode && |
| 2006 | adapter->ps_state == PS_STATE_SLEEP) { |
| 2007 | /* Potentially for PCIe we could get other |
| 2008 | * interrupts like shared. Don't change power |
| 2009 | * state until cookie is set */ |
| 2010 | if (mwifiex_pcie_ok_to_access_hw(adapter)) |
| 2011 | adapter->ps_state = PS_STATE_AWAKE; |
| 2012 | } |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | /* |
| 2017 | * Interrupt handler for PCIe root port |
| 2018 | * |
| 2019 | * This function reads the interrupt status from firmware and assigns |
| 2020 | * the main process in workqueue which will handle the interrupt. |
| 2021 | */ |
| 2022 | static irqreturn_t mwifiex_pcie_interrupt(int irq, void *context) |
| 2023 | { |
| 2024 | struct pci_dev *pdev = (struct pci_dev *)context; |
| 2025 | struct pcie_service_card *card; |
| 2026 | struct mwifiex_adapter *adapter; |
| 2027 | |
| 2028 | if (!pdev) { |
| 2029 | pr_debug("info: %s: pdev is NULL\n", (u8 *)pdev); |
| 2030 | goto exit; |
| 2031 | } |
| 2032 | |
| 2033 | card = (struct pcie_service_card *) pci_get_drvdata(pdev); |
| 2034 | if (!card || !card->adapter) { |
| 2035 | pr_debug("info: %s: card=%p adapter=%p\n", __func__, card, |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 2036 | card ? card->adapter : NULL); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2037 | goto exit; |
| 2038 | } |
| 2039 | adapter = card->adapter; |
| 2040 | |
| 2041 | if (adapter->surprise_removed) |
| 2042 | goto exit; |
| 2043 | |
| 2044 | mwifiex_interrupt_status(adapter); |
| 2045 | queue_work(adapter->workqueue, &adapter->main_work); |
| 2046 | |
| 2047 | exit: |
| 2048 | return IRQ_HANDLED; |
| 2049 | } |
| 2050 | |
| 2051 | /* |
| 2052 | * This function checks the current interrupt status. |
| 2053 | * |
| 2054 | * The following interrupts are checked and handled by this function - |
| 2055 | * - Data sent |
| 2056 | * - Command sent |
| 2057 | * - Command received |
| 2058 | * - Packets received |
| 2059 | * - Events received |
| 2060 | * |
| 2061 | * In case of Rx packets received, the packets are uploaded from card to |
| 2062 | * host and processed accordingly. |
| 2063 | */ |
| 2064 | static int mwifiex_process_int_status(struct mwifiex_adapter *adapter) |
| 2065 | { |
| 2066 | int ret; |
Avinash Patil | 659c478 | 2013-01-03 21:21:28 -0800 | [diff] [blame] | 2067 | u32 pcie_ireg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2068 | unsigned long flags; |
| 2069 | |
| 2070 | spin_lock_irqsave(&adapter->int_lock, flags); |
| 2071 | /* Clear out unused interrupts */ |
Avinash Patil | 659c478 | 2013-01-03 21:21:28 -0800 | [diff] [blame] | 2072 | pcie_ireg = adapter->int_status; |
| 2073 | adapter->int_status = 0; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2074 | spin_unlock_irqrestore(&adapter->int_lock, flags); |
| 2075 | |
Avinash Patil | 659c478 | 2013-01-03 21:21:28 -0800 | [diff] [blame] | 2076 | while (pcie_ireg & HOST_INTR_MASK) { |
| 2077 | if (pcie_ireg & HOST_INTR_DNLD_DONE) { |
| 2078 | pcie_ireg &= ~HOST_INTR_DNLD_DONE; |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 2079 | dev_dbg(adapter->dev, "info: TX DNLD Done\n"); |
| 2080 | ret = mwifiex_pcie_send_data_complete(adapter); |
| 2081 | if (ret) |
| 2082 | return ret; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2083 | } |
Avinash Patil | 659c478 | 2013-01-03 21:21:28 -0800 | [diff] [blame] | 2084 | if (pcie_ireg & HOST_INTR_UPLD_RDY) { |
| 2085 | pcie_ireg &= ~HOST_INTR_UPLD_RDY; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2086 | dev_dbg(adapter->dev, "info: Rx DATA\n"); |
| 2087 | ret = mwifiex_pcie_process_recv_data(adapter); |
| 2088 | if (ret) |
| 2089 | return ret; |
| 2090 | } |
Avinash Patil | 659c478 | 2013-01-03 21:21:28 -0800 | [diff] [blame] | 2091 | if (pcie_ireg & HOST_INTR_EVENT_RDY) { |
| 2092 | pcie_ireg &= ~HOST_INTR_EVENT_RDY; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2093 | dev_dbg(adapter->dev, "info: Rx EVENT\n"); |
| 2094 | ret = mwifiex_pcie_process_event_ready(adapter); |
| 2095 | if (ret) |
| 2096 | return ret; |
| 2097 | } |
| 2098 | |
Avinash Patil | 659c478 | 2013-01-03 21:21:28 -0800 | [diff] [blame] | 2099 | if (pcie_ireg & HOST_INTR_CMD_DONE) { |
| 2100 | pcie_ireg &= ~HOST_INTR_CMD_DONE; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2101 | if (adapter->cmd_sent) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 2102 | dev_dbg(adapter->dev, |
| 2103 | "info: CMD sent Interrupt\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2104 | adapter->cmd_sent = false; |
| 2105 | } |
| 2106 | /* Handle command response */ |
| 2107 | ret = mwifiex_pcie_process_cmd_complete(adapter); |
| 2108 | if (ret) |
| 2109 | return ret; |
| 2110 | } |
| 2111 | |
| 2112 | if (mwifiex_pcie_ok_to_access_hw(adapter)) { |
| 2113 | if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS, |
| 2114 | &pcie_ireg)) { |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 2115 | dev_warn(adapter->dev, |
| 2116 | "Read register failed\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2117 | return -1; |
| 2118 | } |
| 2119 | |
| 2120 | if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) { |
| 2121 | if (mwifiex_write_reg(adapter, |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 2122 | PCIE_HOST_INT_STATUS, |
| 2123 | ~pcie_ireg)) { |
| 2124 | dev_warn(adapter->dev, |
| 2125 | "Write register failed\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2126 | return -1; |
| 2127 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | } |
| 2131 | } |
| 2132 | dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n", |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 2133 | adapter->cmd_sent, adapter->data_sent); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2134 | mwifiex_pcie_enable_host_int(adapter); |
| 2135 | |
| 2136 | return 0; |
| 2137 | } |
| 2138 | |
| 2139 | /* |
| 2140 | * This function downloads data from driver to card. |
| 2141 | * |
| 2142 | * Both commands and data packets are transferred to the card by this |
| 2143 | * function. |
| 2144 | * |
| 2145 | * This function adds the PCIE specific header to the front of the buffer |
| 2146 | * before transferring. The header contains the length of the packet and |
| 2147 | * the type. The firmware handles the packets based upon this set type. |
| 2148 | */ |
| 2149 | static int mwifiex_pcie_host_to_card(struct mwifiex_adapter *adapter, u8 type, |
| 2150 | struct sk_buff *skb, |
| 2151 | struct mwifiex_tx_param *tx_param) |
| 2152 | { |
Dan Carpenter | fa161cb | 2011-11-07 19:31:45 -0800 | [diff] [blame] | 2153 | if (!skb) { |
| 2154 | dev_err(adapter->dev, "Passed NULL skb to %s\n", __func__); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2155 | return -1; |
| 2156 | } |
| 2157 | |
| 2158 | if (type == MWIFIEX_TYPE_DATA) |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 2159 | return mwifiex_pcie_send_data(adapter, skb, tx_param); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2160 | else if (type == MWIFIEX_TYPE_CMD) |
| 2161 | return mwifiex_pcie_send_cmd(adapter, skb); |
| 2162 | |
| 2163 | return 0; |
| 2164 | } |
| 2165 | |
| 2166 | /* |
| 2167 | * This function initializes the PCI-E host memory space, WCB rings, etc. |
| 2168 | * |
| 2169 | * The following initializations steps are followed - |
| 2170 | * - Allocate TXBD ring buffers |
| 2171 | * - Allocate RXBD ring buffers |
| 2172 | * - Allocate event BD ring buffers |
| 2173 | * - Allocate command response ring buffer |
| 2174 | * - Allocate sleep cookie buffer |
| 2175 | */ |
| 2176 | static int mwifiex_pcie_init(struct mwifiex_adapter *adapter) |
| 2177 | { |
| 2178 | struct pcie_service_card *card = adapter->card; |
| 2179 | int ret; |
| 2180 | struct pci_dev *pdev = card->dev; |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 2181 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2182 | |
| 2183 | pci_set_drvdata(pdev, card); |
| 2184 | |
| 2185 | ret = pci_enable_device(pdev); |
| 2186 | if (ret) |
| 2187 | goto err_enable_dev; |
| 2188 | |
| 2189 | pci_set_master(pdev); |
| 2190 | |
| 2191 | dev_dbg(adapter->dev, "try set_consistent_dma_mask(32)\n"); |
| 2192 | ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 2193 | if (ret) { |
| 2194 | dev_err(adapter->dev, "set_dma_mask(32) failed\n"); |
| 2195 | goto err_set_dma_mask; |
| 2196 | } |
| 2197 | |
| 2198 | ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 2199 | if (ret) { |
| 2200 | dev_err(adapter->dev, "set_consistent_dma_mask(64) failed\n"); |
| 2201 | goto err_set_dma_mask; |
| 2202 | } |
| 2203 | |
| 2204 | ret = pci_request_region(pdev, 0, DRV_NAME); |
| 2205 | if (ret) { |
| 2206 | dev_err(adapter->dev, "req_reg(0) error\n"); |
| 2207 | goto err_req_region0; |
| 2208 | } |
| 2209 | card->pci_mmap = pci_iomap(pdev, 0, 0); |
| 2210 | if (!card->pci_mmap) { |
| 2211 | dev_err(adapter->dev, "iomap(0) error\n"); |
Alexey Khoroshilov | 3220712 | 2013-01-26 00:56:03 +0400 | [diff] [blame] | 2212 | ret = -EIO; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2213 | goto err_iomap0; |
| 2214 | } |
| 2215 | ret = pci_request_region(pdev, 2, DRV_NAME); |
| 2216 | if (ret) { |
| 2217 | dev_err(adapter->dev, "req_reg(2) error\n"); |
| 2218 | goto err_req_region2; |
| 2219 | } |
| 2220 | card->pci_mmap1 = pci_iomap(pdev, 2, 0); |
| 2221 | if (!card->pci_mmap1) { |
| 2222 | dev_err(adapter->dev, "iomap(2) error\n"); |
Alexey Khoroshilov | 3220712 | 2013-01-26 00:56:03 +0400 | [diff] [blame] | 2223 | ret = -EIO; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2224 | goto err_iomap2; |
| 2225 | } |
| 2226 | |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 2227 | dev_dbg(adapter->dev, |
| 2228 | "PCI memory map Virt0: %p PCI memory map Virt2: %p\n", |
| 2229 | card->pci_mmap, card->pci_mmap1); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2230 | |
| 2231 | card->cmdrsp_buf = NULL; |
| 2232 | ret = mwifiex_pcie_create_txbd_ring(adapter); |
| 2233 | if (ret) |
| 2234 | goto err_cre_txbd; |
| 2235 | ret = mwifiex_pcie_create_rxbd_ring(adapter); |
| 2236 | if (ret) |
| 2237 | goto err_cre_rxbd; |
| 2238 | ret = mwifiex_pcie_create_evtbd_ring(adapter); |
| 2239 | if (ret) |
| 2240 | goto err_cre_evtbd; |
| 2241 | ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter); |
| 2242 | if (ret) |
| 2243 | goto err_alloc_cmdbuf; |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 2244 | if (reg->sleep_cookie) { |
| 2245 | ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter); |
| 2246 | if (ret) |
| 2247 | goto err_alloc_cookie; |
| 2248 | } else { |
| 2249 | card->sleep_cookie_vbase = NULL; |
| 2250 | } |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2251 | return ret; |
| 2252 | |
| 2253 | err_alloc_cookie: |
| 2254 | mwifiex_pcie_delete_cmdrsp_buf(adapter); |
| 2255 | err_alloc_cmdbuf: |
| 2256 | mwifiex_pcie_delete_evtbd_ring(adapter); |
| 2257 | err_cre_evtbd: |
| 2258 | mwifiex_pcie_delete_rxbd_ring(adapter); |
| 2259 | err_cre_rxbd: |
| 2260 | mwifiex_pcie_delete_txbd_ring(adapter); |
| 2261 | err_cre_txbd: |
| 2262 | pci_iounmap(pdev, card->pci_mmap1); |
| 2263 | err_iomap2: |
| 2264 | pci_release_region(pdev, 2); |
| 2265 | err_req_region2: |
| 2266 | pci_iounmap(pdev, card->pci_mmap); |
| 2267 | err_iomap0: |
| 2268 | pci_release_region(pdev, 0); |
| 2269 | err_req_region0: |
| 2270 | err_set_dma_mask: |
| 2271 | pci_disable_device(pdev); |
| 2272 | err_enable_dev: |
| 2273 | pci_set_drvdata(pdev, NULL); |
| 2274 | return ret; |
| 2275 | } |
| 2276 | |
| 2277 | /* |
| 2278 | * This function cleans up the allocated card buffers. |
| 2279 | * |
| 2280 | * The following are freed by this function - |
| 2281 | * - TXBD ring buffers |
| 2282 | * - RXBD ring buffers |
| 2283 | * - Event BD ring buffers |
| 2284 | * - Command response ring buffer |
| 2285 | * - Sleep cookie buffer |
| 2286 | */ |
| 2287 | static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter) |
| 2288 | { |
| 2289 | struct pcie_service_card *card = adapter->card; |
| 2290 | struct pci_dev *pdev = card->dev; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 2291 | const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2292 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2293 | if (user_rmmod) { |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 2294 | dev_dbg(adapter->dev, "Clearing driver ready signature\n"); |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 2295 | if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000)) |
Yogesh Ashok Powar | f57c1ed | 2012-03-13 19:22:37 -0700 | [diff] [blame] | 2296 | dev_err(adapter->dev, |
| 2297 | "Failed to write driver not-ready signature\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | if (pdev) { |
| 2301 | pci_iounmap(pdev, card->pci_mmap); |
| 2302 | pci_iounmap(pdev, card->pci_mmap1); |
| 2303 | |
| 2304 | pci_release_regions(pdev); |
| 2305 | pci_disable_device(pdev); |
| 2306 | pci_set_drvdata(pdev, NULL); |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | /* |
| 2311 | * This function registers the PCIE device. |
| 2312 | * |
| 2313 | * PCIE IRQ is claimed, block size is set and driver data is initialized. |
| 2314 | */ |
| 2315 | static int mwifiex_register_dev(struct mwifiex_adapter *adapter) |
| 2316 | { |
| 2317 | int ret; |
| 2318 | struct pcie_service_card *card = adapter->card; |
| 2319 | struct pci_dev *pdev = card->dev; |
| 2320 | |
| 2321 | /* save adapter pointer in card */ |
| 2322 | card->adapter = adapter; |
| 2323 | |
| 2324 | ret = request_irq(pdev->irq, mwifiex_pcie_interrupt, IRQF_SHARED, |
| 2325 | "MRVL_PCIE", pdev); |
| 2326 | if (ret) { |
| 2327 | pr_err("request_irq failed: ret=%d\n", ret); |
| 2328 | adapter->card = NULL; |
| 2329 | return -1; |
| 2330 | } |
| 2331 | |
| 2332 | adapter->dev = &pdev->dev; |
Avinash Patil | dd04e6a | 2013-02-08 18:18:06 -0800 | [diff] [blame] | 2333 | strcpy(adapter->fw_name, card->pcie.firmware); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2334 | |
| 2335 | return 0; |
| 2336 | } |
| 2337 | |
| 2338 | /* |
| 2339 | * This function unregisters the PCIE device. |
| 2340 | * |
| 2341 | * The PCIE IRQ is released, the function is disabled and driver |
| 2342 | * data is set to null. |
| 2343 | */ |
| 2344 | static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter) |
| 2345 | { |
| 2346 | struct pcie_service_card *card = adapter->card; |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 2347 | const struct mwifiex_pcie_card_reg *reg; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2348 | |
| 2349 | if (card) { |
| 2350 | dev_dbg(adapter->dev, "%s(): calling free_irq()\n", __func__); |
| 2351 | free_irq(card->dev->irq, card->dev); |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 2352 | |
Avinash Patil | 52301a8 | 2013-02-12 14:38:32 -0800 | [diff] [blame^] | 2353 | reg = card->pcie.reg; |
| 2354 | if (reg->sleep_cookie) |
| 2355 | mwifiex_pcie_delete_sleep_cookie_buf(adapter); |
| 2356 | |
Avinash Patil | fc33146 | 2013-01-03 21:21:30 -0800 | [diff] [blame] | 2357 | mwifiex_pcie_delete_cmdrsp_buf(adapter); |
| 2358 | mwifiex_pcie_delete_evtbd_ring(adapter); |
| 2359 | mwifiex_pcie_delete_rxbd_ring(adapter); |
| 2360 | mwifiex_pcie_delete_txbd_ring(adapter); |
| 2361 | card->cmdrsp_buf = NULL; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | static struct mwifiex_if_ops pcie_ops = { |
| 2366 | .init_if = mwifiex_pcie_init, |
| 2367 | .cleanup_if = mwifiex_pcie_cleanup, |
| 2368 | .check_fw_status = mwifiex_check_fw_status, |
| 2369 | .prog_fw = mwifiex_prog_fw_w_helper, |
| 2370 | .register_dev = mwifiex_register_dev, |
| 2371 | .unregister_dev = mwifiex_unregister_dev, |
| 2372 | .enable_int = mwifiex_pcie_enable_host_int, |
| 2373 | .process_int_status = mwifiex_process_int_status, |
| 2374 | .host_to_card = mwifiex_pcie_host_to_card, |
| 2375 | .wakeup = mwifiex_pm_wakeup_card, |
| 2376 | .wakeup_complete = mwifiex_pm_wakeup_card_complete, |
| 2377 | |
| 2378 | /* PCIE specific */ |
| 2379 | .cmdrsp_complete = mwifiex_pcie_cmdrsp_complete, |
| 2380 | .event_complete = mwifiex_pcie_event_complete, |
| 2381 | .update_mp_end_port = NULL, |
| 2382 | .cleanup_mpa_buf = NULL, |
Avinash Patil | c6d1d87 | 2013-01-03 21:21:29 -0800 | [diff] [blame] | 2383 | .init_fw_port = mwifiex_pcie_init_fw_port, |
Avinash Patil | fbd7e7a | 2013-01-03 21:21:31 -0800 | [diff] [blame] | 2384 | .clean_pcie_ring = mwifiex_clean_pcie_ring_buf, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2385 | }; |
| 2386 | |
| 2387 | /* |
| 2388 | * This function initializes the PCIE driver module. |
| 2389 | * |
| 2390 | * This initiates the semaphore and registers the device with |
| 2391 | * PCIE bus. |
| 2392 | */ |
| 2393 | static int mwifiex_pcie_init_module(void) |
| 2394 | { |
| 2395 | int ret; |
| 2396 | |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 2397 | pr_debug("Marvell PCIe Driver\n"); |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2398 | |
| 2399 | sema_init(&add_remove_card_sem, 1); |
| 2400 | |
| 2401 | /* Clear the flag in case user removes the card. */ |
| 2402 | user_rmmod = 0; |
| 2403 | |
| 2404 | ret = pci_register_driver(&mwifiex_pcie); |
| 2405 | if (ret) |
| 2406 | pr_err("Driver register failed!\n"); |
| 2407 | else |
| 2408 | pr_debug("info: Driver registered successfully!\n"); |
| 2409 | |
| 2410 | return ret; |
| 2411 | } |
| 2412 | |
| 2413 | /* |
| 2414 | * This function cleans up the PCIE driver. |
| 2415 | * |
| 2416 | * The following major steps are followed for cleanup - |
| 2417 | * - Resume the device if its suspended |
| 2418 | * - Disconnect the device if connected |
| 2419 | * - Shutdown the firmware |
| 2420 | * - Unregister the device from PCIE bus. |
| 2421 | */ |
| 2422 | static void mwifiex_pcie_cleanup_module(void) |
| 2423 | { |
| 2424 | if (!down_interruptible(&add_remove_card_sem)) |
| 2425 | up(&add_remove_card_sem); |
| 2426 | |
| 2427 | /* Set the flag as user is removing this module. */ |
| 2428 | user_rmmod = 1; |
| 2429 | |
| 2430 | pci_unregister_driver(&mwifiex_pcie); |
| 2431 | } |
| 2432 | |
| 2433 | module_init(mwifiex_pcie_init_module); |
| 2434 | module_exit(mwifiex_pcie_cleanup_module); |
| 2435 | |
| 2436 | MODULE_AUTHOR("Marvell International Ltd."); |
| 2437 | MODULE_DESCRIPTION("Marvell WiFi-Ex PCI-Express Driver version " PCIE_VERSION); |
| 2438 | MODULE_VERSION(PCIE_VERSION); |
| 2439 | MODULE_LICENSE("GPL v2"); |
Avinash Patil | ca8f211 | 2013-02-08 18:18:09 -0800 | [diff] [blame] | 2440 | MODULE_FIRMWARE(PCIE8766_DEFAULT_FW_NAME); |
| 2441 | MODULE_FIRMWARE(PCIE8897_DEFAULT_FW_NAME); |