Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

qtnfmac_pcie: use single PCIe driver for all platforms

Single PCIe driver can identify hardware type by reading CHIP ID at
probe time and invoking a correct initialization sequence.

Signed-off-by: Igor Mitsyanko <igor.mitsyanko.os@quantenna.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>

authored by

Igor Mitsyanko and committed by
Kalle Valo
b7da53cd 3419348a

+295 -254
+5 -5
drivers/net/wireless/quantenna/qtnfmac/Kconfig
··· 1 1 config QTNFMAC 2 2 tristate 3 - depends on QTNFMAC_PEARL_PCIE 4 - default m if QTNFMAC_PEARL_PCIE=m 5 - default y if QTNFMAC_PEARL_PCIE=y 3 + depends on QTNFMAC_PCIE 4 + default m if QTNFMAC_PCIE=m 5 + default y if QTNFMAC_PCIE=y 6 6 7 - config QTNFMAC_PEARL_PCIE 7 + config QTNFMAC_PCIE 8 8 tristate "Quantenna QSR10g PCIe support" 9 9 default n 10 10 depends on PCI && CFG80211 ··· 16 16 802.11ac QSR10g (aka Pearl) FullMAC chipset running over PCIe. 17 17 18 18 If you choose to build it as a module, two modules will be built: 19 - qtnfmac.ko and qtnfmac_pearl_pcie.ko. 19 + qtnfmac.ko and qtnfmac_pcie.ko.
+3 -3
drivers/net/wireless/quantenna/qtnfmac/Makefile
··· 19 19 20 20 # 21 21 22 - obj-$(CONFIG_QTNFMAC_PEARL_PCIE) += qtnfmac_pearl_pcie.o 22 + obj-$(CONFIG_QTNFMAC_PCIE) += qtnfmac_pcie.o 23 23 24 - qtnfmac_pearl_pcie-objs += \ 24 + qtnfmac_pcie-objs += \ 25 25 shm_ipc.o \ 26 26 pcie/pcie.o \ 27 27 pcie/pearl_pcie.o 28 28 29 - qtnfmac_pearl_pcie-$(CONFIG_DEBUG_FS) += debug.o 29 + qtnfmac_pcie-$(CONFIG_DEBUG_FS) += debug.o
+197 -86
drivers/net/wireless/quantenna/qtnfmac/pcie/pcie.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 /* Copyright (c) 2018 Quantenna Communications, Inc. All rights reserved. */ 3 3 4 + #include <linux/module.h> 4 5 #include <linux/printk.h> 5 6 #include <linux/pci.h> 6 7 #include <linux/spinlock.h> ··· 16 15 #include "shm_ipc.h" 17 16 #include "core.h" 18 17 #include "debug.h" 19 - 20 - #undef pr_fmt 21 - #define pr_fmt(fmt) "qtnf_pcie: %s: " fmt, __func__ 18 + #include "util.h" 19 + #include "qtn_hw_ids.h" 22 20 23 21 #define QTN_SYSCTL_BAR 0 24 22 #define QTN_SHMEM_BAR 2 25 23 #define QTN_DMA_BAR 3 24 + 25 + #define QTN_PCIE_MAX_FW_BUFSZ (1 * 1024 * 1024) 26 + 27 + static bool use_msi = true; 28 + module_param(use_msi, bool, 0644); 29 + MODULE_PARM_DESC(use_msi, "set 0 to use legacy interrupt"); 30 + 31 + static unsigned int tx_bd_size_param; 32 + module_param(tx_bd_size_param, uint, 0644); 33 + MODULE_PARM_DESC(tx_bd_size_param, "Tx descriptors queue size"); 34 + 35 + static unsigned int rx_bd_size_param = 256; 36 + module_param(rx_bd_size_param, uint, 0644); 37 + MODULE_PARM_DESC(rx_bd_size_param, "Rx descriptors queue size"); 38 + 39 + static u8 flashboot = 1; 40 + module_param(flashboot, byte, 0644); 41 + MODULE_PARM_DESC(flashboot, "set to 0 to use FW binary file on FS"); 42 + 43 + static unsigned int fw_blksize_param = QTN_PCIE_MAX_FW_BUFSZ; 44 + module_param(fw_blksize_param, uint, 0644); 45 + MODULE_PARM_DESC(fw_blksize_param, "firmware loading block size in bytes"); 46 + 47 + #define DRV_NAME "qtnfmac_pcie" 26 48 27 49 int qtnf_pcie_control_tx(struct qtnf_bus *bus, struct sk_buff *skb) 28 50 { ··· 82 58 return 0; 83 59 } 84 60 85 - void qtnf_pcie_bringup_fw_async(struct qtnf_bus *bus) 61 + static void qtnf_pcie_bringup_fw_async(struct qtnf_bus *bus) 86 62 { 87 63 struct qtnf_pcie_bus_priv *priv = get_bus_priv(bus); 88 64 struct pci_dev *pdev = priv->pdev; ··· 96 72 struct qtnf_bus *bus = dev_get_drvdata(s->private); 97 73 struct qtnf_pcie_bus_priv *priv = get_bus_priv(bus); 98 74 99 - seq_printf(s, "%d\n", priv->mps); 75 + seq_printf(s, "%d\n", pcie_get_mps(priv->pdev)); 100 76 101 77 return 0; 102 78 } ··· 128 104 return 0; 129 105 } 130 106 131 - void qtnf_pcie_fw_boot_done(struct qtnf_bus *bus, bool boot_success, 132 - const char *drv_name) 107 + void qtnf_pcie_fw_boot_done(struct qtnf_bus *bus, bool boot_success) 133 108 { 134 109 struct qtnf_pcie_bus_priv *priv = get_bus_priv(bus); 135 110 struct pci_dev *pdev = priv->pdev; ··· 145 122 } 146 123 147 124 if (boot_success) { 148 - qtnf_debugfs_init(bus, drv_name); 125 + qtnf_debugfs_init(bus, DRV_NAME); 149 126 qtnf_debugfs_add_entry(bus, "mps", qtnf_dbg_mps_show); 150 127 qtnf_debugfs_add_entry(bus, "msi_enabled", qtnf_dbg_msi_show); 151 128 qtnf_debugfs_add_entry(bus, "shm_stats", qtnf_dbg_shm_stats); ··· 156 133 put_device(&pdev->dev); 157 134 } 158 135 159 - static void qtnf_tune_pcie_mps(struct qtnf_pcie_bus_priv *priv) 136 + static void qtnf_tune_pcie_mps(struct pci_dev *pdev) 160 137 { 161 - struct pci_dev *pdev = priv->pdev; 162 138 struct pci_dev *parent; 163 139 int mps_p, mps_o, mps_m, mps; 164 140 int ret; ··· 185 163 if (ret) { 186 164 pr_err("failed to set mps to %d, keep using current %d\n", 187 165 mps, mps_o); 188 - priv->mps = mps_o; 189 166 return; 190 167 } 191 168 192 169 pr_debug("set mps to %d (was %d, max %d)\n", mps, mps_o, mps_m); 193 - priv->mps = mps; 194 170 } 195 171 196 172 static void qtnf_pcie_init_irq(struct qtnf_pcie_bus_priv *priv, bool use_msi) ··· 214 194 } 215 195 } 216 196 217 - static void __iomem *qtnf_map_bar(struct qtnf_pcie_bus_priv *priv, u8 index) 197 + static void __iomem *qtnf_map_bar(struct pci_dev *pdev, u8 index) 218 198 { 219 199 void __iomem *vaddr; 220 200 dma_addr_t busaddr; 221 201 size_t len; 222 202 int ret; 223 203 224 - ret = pcim_iomap_regions(priv->pdev, 1 << index, "qtnfmac_pcie"); 204 + ret = pcim_iomap_regions(pdev, 1 << index, "qtnfmac_pcie"); 225 205 if (ret) 226 206 return IOMEM_ERR_PTR(ret); 227 207 228 - busaddr = pci_resource_start(priv->pdev, index); 229 - len = pci_resource_len(priv->pdev, index); 230 - vaddr = pcim_iomap_table(priv->pdev)[index]; 208 + busaddr = pci_resource_start(pdev, index); 209 + len = pci_resource_len(pdev, index); 210 + vaddr = pcim_iomap_table(pdev)[index]; 231 211 if (!vaddr) 232 212 return IOMEM_ERR_PTR(-ENOMEM); 233 213 ··· 235 215 index, vaddr, &busaddr, (int)len); 236 216 237 217 return vaddr; 238 - } 239 - 240 - static int qtnf_pcie_init_memory(struct qtnf_pcie_bus_priv *priv) 241 - { 242 - int ret = -ENOMEM; 243 - 244 - priv->sysctl_bar = qtnf_map_bar(priv, QTN_SYSCTL_BAR); 245 - if (IS_ERR(priv->sysctl_bar)) { 246 - pr_err("failed to map BAR%u\n", QTN_SYSCTL_BAR); 247 - return ret; 248 - } 249 - 250 - priv->dmareg_bar = qtnf_map_bar(priv, QTN_DMA_BAR); 251 - if (IS_ERR(priv->dmareg_bar)) { 252 - pr_err("failed to map BAR%u\n", QTN_DMA_BAR); 253 - return ret; 254 - } 255 - 256 - priv->epmem_bar = qtnf_map_bar(priv, QTN_SHMEM_BAR); 257 - if (IS_ERR(priv->epmem_bar)) { 258 - pr_err("failed to map BAR%u\n", QTN_SHMEM_BAR); 259 - return ret; 260 - } 261 - 262 - return 0; 263 218 } 264 219 265 220 static void qtnf_pcie_control_rx_callback(void *arg, const u8 __iomem *buf, ··· 277 282 ipc_int, &rx_callback); 278 283 } 279 284 280 - int qtnf_pcie_probe(struct pci_dev *pdev, size_t priv_size, 281 - const struct qtnf_bus_ops *bus_ops, u64 dma_mask, 282 - bool use_msi) 285 + static int qtnf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) 283 286 { 284 287 struct qtnf_pcie_bus_priv *pcie_priv; 285 288 struct qtnf_bus *bus; 289 + void __iomem *sysctl_bar; 290 + void __iomem *epmem_bar; 291 + void __iomem *dmareg_bar; 292 + unsigned int chipid; 286 293 int ret; 287 294 288 - bus = devm_kzalloc(&pdev->dev, 289 - sizeof(*bus) + priv_size, GFP_KERNEL); 295 + if (!pci_is_pcie(pdev)) { 296 + pr_err("device %s is not PCI Express\n", pci_name(pdev)); 297 + return -EIO; 298 + } 299 + 300 + qtnf_tune_pcie_mps(pdev); 301 + 302 + ret = pcim_enable_device(pdev); 303 + if (ret) { 304 + pr_err("failed to init PCI device %x\n", pdev->device); 305 + return ret; 306 + } 307 + 308 + pci_set_master(pdev); 309 + 310 + sysctl_bar = qtnf_map_bar(pdev, QTN_SYSCTL_BAR); 311 + if (IS_ERR(sysctl_bar)) { 312 + pr_err("failed to map BAR%u\n", QTN_SYSCTL_BAR); 313 + return ret; 314 + } 315 + 316 + dmareg_bar = qtnf_map_bar(pdev, QTN_DMA_BAR); 317 + if (IS_ERR(dmareg_bar)) { 318 + pr_err("failed to map BAR%u\n", QTN_DMA_BAR); 319 + return ret; 320 + } 321 + 322 + epmem_bar = qtnf_map_bar(pdev, QTN_SHMEM_BAR); 323 + if (IS_ERR(epmem_bar)) { 324 + pr_err("failed to map BAR%u\n", QTN_SHMEM_BAR); 325 + return ret; 326 + } 327 + 328 + chipid = qtnf_chip_id_get(sysctl_bar); 329 + 330 + pr_info("identified device: %s\n", qtnf_chipid_to_string(chipid)); 331 + 332 + switch (chipid) { 333 + case QTN_CHIP_ID_PEARL: 334 + case QTN_CHIP_ID_PEARL_B: 335 + case QTN_CHIP_ID_PEARL_C: 336 + bus = qtnf_pcie_pearl_alloc(pdev); 337 + break; 338 + default: 339 + pr_err("unsupported chip ID 0x%x\n", chipid); 340 + return -ENOTSUPP; 341 + } 342 + 290 343 if (!bus) 291 344 return -ENOMEM; 292 345 293 346 pcie_priv = get_bus_priv(bus); 294 - 295 347 pci_set_drvdata(pdev, bus); 296 - bus->bus_ops = bus_ops; 297 348 bus->dev = &pdev->dev; 298 349 bus->fw_state = QTNF_FW_STATE_RESET; 299 350 pcie_priv->pdev = pdev; 300 351 pcie_priv->tx_stopped = 0; 352 + pcie_priv->rx_bd_num = rx_bd_size_param; 353 + pcie_priv->flashboot = flashboot; 354 + 355 + if (fw_blksize_param > QTN_PCIE_MAX_FW_BUFSZ) 356 + pcie_priv->fw_blksize = QTN_PCIE_MAX_FW_BUFSZ; 357 + else 358 + pcie_priv->fw_blksize = fw_blksize_param; 301 359 302 360 mutex_init(&bus->bus_lock); 303 361 spin_lock_init(&pcie_priv->tx_lock); ··· 365 317 pcie_priv->workqueue = create_singlethread_workqueue("QTNF_PCIE"); 366 318 if (!pcie_priv->workqueue) { 367 319 pr_err("failed to alloc bus workqueue\n"); 368 - ret = -ENODEV; 369 - goto err_init; 320 + return -ENODEV; 321 + } 322 + 323 + ret = dma_set_mask_and_coherent(&pdev->dev, 324 + pcie_priv->dma_mask_get_cb()); 325 + if (ret) { 326 + pr_err("PCIE DMA coherent mask init failed 0x%llx\n", 327 + pcie_priv->dma_mask_get_cb()); 328 + goto error; 370 329 } 371 330 372 331 init_dummy_netdev(&bus->mux_dev); 373 - 374 - if (!pci_is_pcie(pdev)) { 375 - pr_err("device %s is not PCI Express\n", pci_name(pdev)); 376 - ret = -EIO; 377 - goto err_base; 378 - } 379 - 380 - qtnf_tune_pcie_mps(pcie_priv); 381 - 382 - ret = pcim_enable_device(pdev); 383 - if (ret) { 384 - pr_err("failed to init PCI device %x\n", pdev->device); 385 - goto err_base; 386 - } else { 387 - pr_debug("successful init of PCI device %x\n", pdev->device); 388 - } 389 - 390 - ret = dma_set_mask_and_coherent(&pdev->dev, dma_mask); 391 - if (ret) { 392 - pr_err("PCIE DMA coherent mask init failed\n"); 393 - goto err_base; 394 - } 395 - 396 - pci_set_master(pdev); 397 332 qtnf_pcie_init_irq(pcie_priv, use_msi); 398 - 399 - ret = qtnf_pcie_init_memory(pcie_priv); 400 - if (ret < 0) { 401 - pr_err("PCIE memory init failed\n"); 402 - goto err_base; 403 - } 404 - 333 + pcie_priv->sysctl_bar = sysctl_bar; 334 + pcie_priv->dmareg_bar = dmareg_bar; 335 + pcie_priv->epmem_bar = epmem_bar; 405 336 pci_save_state(pdev); 406 337 338 + ret = pcie_priv->probe_cb(bus, tx_bd_size_param); 339 + if (ret) 340 + goto error; 341 + 342 + qtnf_pcie_bringup_fw_async(bus); 407 343 return 0; 408 344 409 - err_base: 345 + error: 410 346 flush_workqueue(pcie_priv->workqueue); 411 347 destroy_workqueue(pcie_priv->workqueue); 412 - err_init: 413 348 pci_set_drvdata(pdev, NULL); 414 - 415 349 return ret; 416 350 } 417 351 ··· 403 373 qtnf_shm_ipc_free(&priv->shm_ipc_ep_out); 404 374 } 405 375 406 - void qtnf_pcie_remove(struct qtnf_bus *bus, struct qtnf_pcie_bus_priv *priv) 376 + static void qtnf_pcie_remove(struct pci_dev *dev) 407 377 { 378 + struct qtnf_pcie_bus_priv *priv; 379 + struct qtnf_bus *bus; 380 + 381 + bus = pci_get_drvdata(dev); 382 + if (!bus) 383 + return; 384 + 385 + priv = get_bus_priv(bus); 386 + 408 387 cancel_work_sync(&bus->fw_work); 409 388 410 389 if (bus->fw_state == QTNF_FW_STATE_ACTIVE || ··· 427 388 428 389 qtnf_pcie_free_shm_ipc(priv); 429 390 qtnf_debugfs_remove(bus); 391 + priv->remove_cb(bus); 430 392 pci_set_drvdata(priv->pdev, NULL); 431 393 } 394 + 395 + #ifdef CONFIG_PM_SLEEP 396 + static int qtnf_pcie_suspend(struct device *dev) 397 + { 398 + struct qtnf_pcie_bus_priv *priv; 399 + struct qtnf_bus *bus; 400 + 401 + bus = pci_get_drvdata(to_pci_dev(dev)); 402 + if (!bus) 403 + return -EFAULT; 404 + 405 + priv = get_bus_priv(bus); 406 + return priv->suspend_cb(bus); 407 + } 408 + 409 + static int qtnf_pcie_resume(struct device *dev) 410 + { 411 + struct qtnf_pcie_bus_priv *priv; 412 + struct qtnf_bus *bus; 413 + 414 + bus = pci_get_drvdata(to_pci_dev(dev)); 415 + if (!bus) 416 + return -EFAULT; 417 + 418 + priv = get_bus_priv(bus); 419 + return priv->resume_cb(bus); 420 + } 421 + 422 + /* Power Management Hooks */ 423 + static SIMPLE_DEV_PM_OPS(qtnf_pcie_pm_ops, qtnf_pcie_suspend, 424 + qtnf_pcie_resume); 425 + #endif 426 + 427 + static const struct pci_device_id qtnf_pcie_devid_table[] = { 428 + { 429 + PCIE_VENDOR_ID_QUANTENNA, PCIE_DEVICE_ID_QTN_PEARL, 430 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 431 + }, 432 + { }, 433 + }; 434 + 435 + MODULE_DEVICE_TABLE(pci, qtnf_pcie_devid_table); 436 + 437 + static struct pci_driver qtnf_pcie_drv_data = { 438 + .name = DRV_NAME, 439 + .id_table = qtnf_pcie_devid_table, 440 + .probe = qtnf_pcie_probe, 441 + .remove = qtnf_pcie_remove, 442 + #ifdef CONFIG_PM_SLEEP 443 + .driver = { 444 + .pm = &qtnf_pcie_pm_ops, 445 + }, 446 + #endif 447 + }; 448 + 449 + static int __init qtnf_pcie_register(void) 450 + { 451 + return pci_register_driver(&qtnf_pcie_drv_data); 452 + } 453 + 454 + static void __exit qtnf_pcie_exit(void) 455 + { 456 + pci_unregister_driver(&qtnf_pcie_drv_data); 457 + } 458 + 459 + module_init(qtnf_pcie_register); 460 + module_exit(qtnf_pcie_exit); 461 + 462 + MODULE_AUTHOR("Quantenna Communications"); 463 + MODULE_DESCRIPTION("Quantenna PCIe bus driver for 802.11 wireless LAN."); 464 + MODULE_LICENSE("GPL");
+11 -8
drivers/net/wireless/quantenna/qtnfmac/pcie/pcie_priv.h
··· 23 23 struct qtnf_pcie_bus_priv { 24 24 struct pci_dev *pdev; 25 25 26 + int (*probe_cb)(struct qtnf_bus *bus, unsigned int tx_bd_size); 27 + void (*remove_cb)(struct qtnf_bus *bus); 28 + int (*suspend_cb)(struct qtnf_bus *bus); 29 + int (*resume_cb)(struct qtnf_bus *bus); 30 + u64 (*dma_mask_get_cb)(void); 31 + 26 32 spinlock_t tx_reclaim_lock; 27 33 spinlock_t tx_lock; 28 - int mps; 29 34 30 35 struct workqueue_struct *workqueue; 31 36 struct tasklet_struct reclaim_tq; ··· 48 43 struct sk_buff **tx_skb; 49 44 struct sk_buff **rx_skb; 50 45 46 + unsigned int fw_blksize; 47 + 51 48 u32 rx_bd_w_index; 52 49 u32 rx_bd_r_index; 53 50 ··· 65 58 66 59 u8 msi_enabled; 67 60 u8 tx_stopped; 61 + bool flashboot; 68 62 }; 69 63 70 64 int qtnf_pcie_control_tx(struct qtnf_bus *bus, struct sk_buff *skb); 71 65 int qtnf_pcie_alloc_skb_array(struct qtnf_pcie_bus_priv *priv); 72 - void qtnf_pcie_bringup_fw_async(struct qtnf_bus *bus); 73 - void qtnf_pcie_fw_boot_done(struct qtnf_bus *bus, bool boot_success, 74 - const char *drv_name); 66 + void qtnf_pcie_fw_boot_done(struct qtnf_bus *bus, bool boot_success); 75 67 void qtnf_pcie_init_shm_ipc(struct qtnf_pcie_bus_priv *priv, 76 68 struct qtnf_shm_ipc_region __iomem *ipc_tx_reg, 77 69 struct qtnf_shm_ipc_region __iomem *ipc_rx_reg, 78 70 const struct qtnf_shm_ipc_int *ipc_int); 79 - int qtnf_pcie_probe(struct pci_dev *pdev, size_t priv_size, 80 - const struct qtnf_bus_ops *bus_ops, u64 dma_mask, 81 - bool use_msi); 82 - void qtnf_pcie_remove(struct qtnf_bus *bus, struct qtnf_pcie_bus_priv *priv); 71 + struct qtnf_bus *qtnf_pcie_pearl_alloc(struct pci_dev *pdev); 83 72 84 73 static inline void qtnf_non_posted_write(u32 val, void __iomem *basereg) 85 74 {
+61 -152
drivers/net/wireless/quantenna/qtnfmac/pcie/pearl_pcie.c
··· 2 2 /* Copyright (c) 2018 Quantenna Communications */ 3 3 4 4 #include <linux/kernel.h> 5 - #include <linux/module.h> 6 5 #include <linux/firmware.h> 7 6 #include <linux/pci.h> 8 7 #include <linux/vmalloc.h> ··· 23 24 #include "shm_ipc.h" 24 25 #include "debug.h" 25 26 26 - static bool use_msi = true; 27 - module_param(use_msi, bool, 0644); 28 - MODULE_PARM_DESC(use_msi, "set 0 to use legacy interrupt"); 29 - 30 - static unsigned int tx_bd_size_param = 32; 31 - module_param(tx_bd_size_param, uint, 0644); 32 - MODULE_PARM_DESC(tx_bd_size_param, "Tx descriptors queue size, power of two"); 33 - 34 - static unsigned int rx_bd_size_param = 256; 35 - module_param(rx_bd_size_param, uint, 0644); 36 - MODULE_PARM_DESC(rx_bd_size_param, "Rx descriptors queue size, power of two"); 37 - 38 - static u8 flashboot = 1; 39 - module_param(flashboot, byte, 0644); 40 - MODULE_PARM_DESC(flashboot, "set to 0 to use FW binary file on FS"); 41 - 42 - #define DRV_NAME "qtnfmac_pearl_pcie" 27 + #define PEARL_TX_BD_SIZE_DEFAULT 32 43 28 44 29 struct qtnf_pearl_bda { 45 30 __le16 bda_len; ··· 398 415 return 0; 399 416 } 400 417 401 - static int qtnf_pcie_pearl_init_xfer(struct qtnf_pcie_pearl_state *ps) 418 + static int qtnf_pcie_pearl_init_xfer(struct qtnf_pcie_pearl_state *ps, 419 + unsigned int tx_bd_size) 402 420 { 403 421 struct qtnf_pcie_bus_priv *priv = &ps->base; 404 422 int ret; 405 423 u32 val; 406 424 407 - priv->tx_bd_num = tx_bd_size_param; 408 - priv->rx_bd_num = rx_bd_size_param; 425 + if (tx_bd_size == 0) 426 + tx_bd_size = PEARL_TX_BD_SIZE_DEFAULT; 427 + 428 + val = tx_bd_size * sizeof(struct qtnf_pearl_tx_bd); 429 + 430 + if (!is_power_of_2(tx_bd_size) || val > PCIE_HHBM_MAX_SIZE) { 431 + pr_warn("bad tx_bd_size value %u\n", tx_bd_size); 432 + priv->tx_bd_num = PEARL_TX_BD_SIZE_DEFAULT; 433 + } else { 434 + priv->tx_bd_num = tx_bd_size; 435 + } 436 + 409 437 priv->rx_bd_w_index = 0; 410 438 priv->rx_bd_r_index = 0; 411 - 412 - if (!priv->tx_bd_num || !is_power_of_2(priv->tx_bd_num)) { 413 - pr_err("tx_bd_size_param %u is not power of two\n", 414 - priv->tx_bd_num); 415 - return -EINVAL; 416 - } 417 - 418 - val = priv->tx_bd_num * sizeof(struct qtnf_pearl_tx_bd); 419 - if (val > PCIE_HHBM_MAX_SIZE) { 420 - pr_err("tx_bd_size_param %u is too large\n", 421 - priv->tx_bd_num); 422 - return -EINVAL; 423 - } 424 439 425 440 if (!priv->rx_bd_num || !is_power_of_2(priv->rx_bd_num)) { 426 441 pr_err("rx_bd_size_param %u is not power of two\n", ··· 987 1006 const char *fwname = QTN_PCI_PEARL_FW_NAME; 988 1007 bool fw_boot_success = false; 989 1008 990 - if (flashboot) { 1009 + if (ps->base.flashboot) { 991 1010 state |= QTN_RC_FW_FLASHBOOT; 992 1011 } else { 993 1012 ret = request_firmware(&fw, fwname, &pdev->dev); ··· 1003 1022 QTN_FW_DL_TIMEOUT_MS)) { 1004 1023 pr_err("card is not ready\n"); 1005 1024 1006 - if (!flashboot) 1025 + if (!ps->base.flashboot) 1007 1026 release_firmware(fw); 1008 1027 1009 1028 goto fw_load_exit; ··· 1011 1030 1012 1031 qtnf_clear_state(&ps->bda->bda_ep_state, QTN_EP_FW_LOADRDY); 1013 1032 1014 - if (flashboot) { 1033 + if (ps->base.flashboot) { 1015 1034 pr_info("booting firmware from flash\n"); 1016 1035 1017 1036 } else { ··· 1042 1061 fw_boot_success = true; 1043 1062 1044 1063 fw_load_exit: 1045 - qtnf_pcie_fw_boot_done(bus, fw_boot_success, DRV_NAME); 1064 + qtnf_pcie_fw_boot_done(bus, fw_boot_success); 1046 1065 1047 1066 if (fw_boot_success) { 1048 1067 qtnf_debugfs_add_entry(bus, "hdp_stats", qtnf_dbg_hdp_stats); ··· 1058 1077 qtnf_en_txdone_irq(ps); 1059 1078 } 1060 1079 1061 - static int qtnf_pearl_check_chip_id(struct qtnf_pcie_pearl_state *ps) 1080 + static u64 qtnf_pearl_dma_mask_get(void) 1062 1081 { 1063 - unsigned int chipid; 1064 - 1065 - chipid = qtnf_chip_id_get(ps->base.sysctl_bar); 1066 - 1067 - switch (chipid) { 1068 - case QTN_CHIP_ID_PEARL: 1069 - case QTN_CHIP_ID_PEARL_B: 1070 - case QTN_CHIP_ID_PEARL_C: 1071 - pr_info("chip ID is 0x%x\n", chipid); 1072 - break; 1073 - default: 1074 - pr_err("incorrect chip ID 0x%x\n", chipid); 1075 - return -ENODEV; 1076 - } 1077 - 1078 - return 0; 1082 + #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 1083 + return DMA_BIT_MASK(64); 1084 + #else 1085 + return DMA_BIT_MASK(32); 1086 + #endif 1079 1087 } 1080 1088 1081 - static int qtnf_pcie_pearl_probe(struct pci_dev *pdev, 1082 - const struct pci_device_id *id) 1089 + static int qtnf_pcie_pearl_probe(struct qtnf_bus *bus, unsigned int tx_bd_size) 1083 1090 { 1084 1091 struct qtnf_shm_ipc_int ipc_int; 1085 - struct qtnf_pcie_pearl_state *ps; 1086 - struct qtnf_bus *bus; 1092 + struct qtnf_pcie_pearl_state *ps = get_bus_priv(bus); 1093 + struct pci_dev *pdev = ps->base.pdev; 1087 1094 int ret; 1088 - u64 dma_mask; 1089 1095 1090 - #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 1091 - dma_mask = DMA_BIT_MASK(64); 1092 - #else 1093 - dma_mask = DMA_BIT_MASK(32); 1094 - #endif 1095 - 1096 - ret = qtnf_pcie_probe(pdev, sizeof(*ps), &qtnf_pcie_pearl_bus_ops, 1097 - dma_mask, use_msi); 1098 - if (ret) 1099 - return ret; 1100 - 1101 - bus = pci_get_drvdata(pdev); 1102 - ps = get_bus_priv(bus); 1103 - 1096 + bus->bus_ops = &qtnf_pcie_pearl_bus_ops; 1104 1097 spin_lock_init(&ps->irq_lock); 1105 - 1106 - tasklet_init(&ps->base.reclaim_tq, qtnf_pearl_reclaim_tasklet_fn, 1107 - (unsigned long)ps); 1108 - netif_napi_add(&bus->mux_dev, &bus->mux_napi, 1109 - qtnf_pcie_pearl_rx_poll, 10); 1110 1098 INIT_WORK(&bus->fw_work, qtnf_pearl_fw_work_handler); 1111 1099 1112 1100 ps->pcie_reg_base = ps->base.dmareg_bar; 1113 1101 ps->bda = ps->base.epmem_bar; 1114 1102 writel(ps->base.msi_enabled, &ps->bda->bda_rc_msi_enabled); 1115 1103 1116 - ipc_int.fn = qtnf_pcie_pearl_ipc_gen_ep_int; 1117 - ipc_int.arg = ps; 1118 - qtnf_pcie_init_shm_ipc(&ps->base, &ps->bda->bda_shm_reg1, 1119 - &ps->bda->bda_shm_reg2, &ipc_int); 1120 - 1121 - ret = qtnf_pearl_check_chip_id(ps); 1122 - if (ret) 1123 - goto error; 1124 - 1125 - ret = qtnf_pcie_pearl_init_xfer(ps); 1104 + ret = qtnf_pcie_pearl_init_xfer(ps, tx_bd_size); 1126 1105 if (ret) { 1127 1106 pr_err("PCIE xfer init failed\n"); 1128 - goto error; 1107 + return ret; 1129 1108 } 1130 1109 1131 1110 /* init default irq settings */ ··· 1096 1155 1097 1156 ret = devm_request_irq(&pdev->dev, pdev->irq, 1098 1157 &qtnf_pcie_pearl_interrupt, 0, 1099 - "qtnf_pcie_irq", (void *)bus); 1158 + "qtnf_pearl_irq", (void *)bus); 1100 1159 if (ret) { 1101 1160 pr_err("failed to request pcie irq %d\n", pdev->irq); 1102 - goto err_xfer; 1161 + qtnf_pearl_free_xfer_buffers(ps); 1162 + return ret; 1103 1163 } 1104 1164 1105 - qtnf_pcie_bringup_fw_async(bus); 1165 + tasklet_init(&ps->base.reclaim_tq, qtnf_pearl_reclaim_tasklet_fn, 1166 + (unsigned long)ps); 1167 + netif_napi_add(&bus->mux_dev, &bus->mux_napi, 1168 + qtnf_pcie_pearl_rx_poll, 10); 1169 + 1170 + ipc_int.fn = qtnf_pcie_pearl_ipc_gen_ep_int; 1171 + ipc_int.arg = ps; 1172 + qtnf_pcie_init_shm_ipc(&ps->base, &ps->bda->bda_shm_reg1, 1173 + &ps->bda->bda_shm_reg2, &ipc_int); 1106 1174 1107 1175 return 0; 1108 - 1109 - err_xfer: 1110 - qtnf_pearl_free_xfer_buffers(ps); 1111 - error: 1112 - qtnf_pcie_remove(bus, &ps->base); 1113 - 1114 - return ret; 1115 1176 } 1116 1177 1117 - static void qtnf_pcie_pearl_remove(struct pci_dev *pdev) 1178 + static void qtnf_pcie_pearl_remove(struct qtnf_bus *bus) 1118 1179 { 1119 - struct qtnf_pcie_pearl_state *ps; 1120 - struct qtnf_bus *bus; 1180 + struct qtnf_pcie_pearl_state *ps = get_bus_priv(bus); 1121 1181 1122 - bus = pci_get_drvdata(pdev); 1123 - if (!bus) 1124 - return; 1125 - 1126 - ps = get_bus_priv(bus); 1127 - 1128 - qtnf_pcie_remove(bus, &ps->base); 1129 1182 qtnf_pearl_reset_ep(ps); 1130 1183 qtnf_pearl_free_xfer_buffers(ps); 1131 1184 } 1132 1185 1133 1186 #ifdef CONFIG_PM_SLEEP 1134 - static int qtnf_pcie_pearl_suspend(struct device *dev) 1187 + static int qtnf_pcie_pearl_suspend(struct qtnf_bus *bus) 1135 1188 { 1136 1189 return -EOPNOTSUPP; 1137 1190 } 1138 1191 1139 - static int qtnf_pcie_pearl_resume(struct device *dev) 1192 + static int qtnf_pcie_pearl_resume(struct qtnf_bus *bus) 1140 1193 { 1141 1194 return 0; 1142 1195 } 1143 - #endif /* CONFIG_PM_SLEEP */ 1144 - 1145 - #ifdef CONFIG_PM_SLEEP 1146 - /* Power Management Hooks */ 1147 - static SIMPLE_DEV_PM_OPS(qtnf_pcie_pearl_pm_ops, qtnf_pcie_pearl_suspend, 1148 - qtnf_pcie_pearl_resume); 1149 1196 #endif 1150 1197 1151 - static const struct pci_device_id qtnf_pcie_devid_table[] = { 1152 - { 1153 - PCIE_VENDOR_ID_QUANTENNA, PCIE_DEVICE_ID_QTN_PEARL, 1154 - PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1155 - }, 1156 - { }, 1157 - }; 1198 + struct qtnf_bus *qtnf_pcie_pearl_alloc(struct pci_dev *pdev) 1199 + { 1200 + struct qtnf_bus *bus; 1201 + struct qtnf_pcie_pearl_state *ps; 1158 1202 1159 - MODULE_DEVICE_TABLE(pci, qtnf_pcie_devid_table); 1203 + bus = devm_kzalloc(&pdev->dev, sizeof(*bus) + sizeof(*ps), GFP_KERNEL); 1204 + if (!bus) 1205 + return NULL; 1160 1206 1161 - static struct pci_driver qtnf_pcie_pearl_drv_data = { 1162 - .name = DRV_NAME, 1163 - .id_table = qtnf_pcie_devid_table, 1164 - .probe = qtnf_pcie_pearl_probe, 1165 - .remove = qtnf_pcie_pearl_remove, 1207 + ps = get_bus_priv(bus); 1208 + ps->base.probe_cb = qtnf_pcie_pearl_probe; 1209 + ps->base.remove_cb = qtnf_pcie_pearl_remove; 1210 + ps->base.dma_mask_get_cb = qtnf_pearl_dma_mask_get; 1166 1211 #ifdef CONFIG_PM_SLEEP 1167 - .driver = { 1168 - .pm = &qtnf_pcie_pearl_pm_ops, 1169 - }, 1212 + ps->base.resume_cb = qtnf_pcie_pearl_resume; 1213 + ps->base.suspend_cb = qtnf_pcie_pearl_suspend; 1170 1214 #endif 1171 - }; 1172 1215 1173 - static int __init qtnf_pcie_pearl_register(void) 1174 - { 1175 - pr_info("register Quantenna QSR10g FullMAC PCIE driver\n"); 1176 - return pci_register_driver(&qtnf_pcie_pearl_drv_data); 1216 + return bus; 1177 1217 } 1178 - 1179 - static void __exit qtnf_pcie_pearl_exit(void) 1180 - { 1181 - pr_info("unregister Quantenna QSR10g FullMAC PCIE driver\n"); 1182 - pci_unregister_driver(&qtnf_pcie_pearl_drv_data); 1183 - } 1184 - 1185 - module_init(qtnf_pcie_pearl_register); 1186 - module_exit(qtnf_pcie_pearl_exit); 1187 - 1188 - MODULE_AUTHOR("Quantenna Communications"); 1189 - MODULE_DESCRIPTION("Quantenna QSR10g PCIe bus driver for 802.11 wireless LAN."); 1190 - MODULE_LICENSE("GPL");
+16
drivers/net/wireless/quantenna/qtnfmac/util.c
··· 15 15 */ 16 16 17 17 #include "util.h" 18 + #include "qtn_hw_ids.h" 18 19 19 20 void qtnf_sta_list_init(struct qtnf_sta_list *list) 20 21 { ··· 117 116 118 117 INIT_LIST_HEAD(&list->head); 119 118 } 119 + 120 + const char *qtnf_chipid_to_string(unsigned long chip_id) 121 + { 122 + switch (chip_id) { 123 + case QTN_CHIP_ID_PEARL: 124 + return "Pearl revA"; 125 + case QTN_CHIP_ID_PEARL_B: 126 + return "Pearl revB"; 127 + case QTN_CHIP_ID_PEARL_C: 128 + return "Pearl revC"; 129 + default: 130 + return "unknown"; 131 + } 132 + } 133 + EXPORT_SYMBOL_GPL(qtnf_chipid_to_string);
+2
drivers/net/wireless/quantenna/qtnfmac/util.h
··· 20 20 #include <linux/kernel.h> 21 21 #include "core.h" 22 22 23 + const char *qtnf_chipid_to_string(unsigned long chip_id); 24 + 23 25 void qtnf_sta_list_init(struct qtnf_sta_list *list); 24 26 25 27 struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,