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