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