Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Zac Livingston | 866b0e2 | 2013-10-23 18:14:17 -0600 | [diff] [blame] | 3 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * nss_init.c |
| 19 | * NSS init APIs |
| 20 | * |
| 21 | */ |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 22 | #include "nss_core.h" |
Pamidipati, Vijay | 7f413b5 | 2013-09-24 19:07:12 +0530 | [diff] [blame] | 23 | #include "nss_pm.h" |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 24 | #include "nss_tx_rx_common.h" |
Pamidipati, Vijay | 7f413b5 | 2013-09-24 19:07:12 +0530 | [diff] [blame] | 25 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 26 | #include <nss_hal.h> |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 27 | #include <nss_clocks.h> |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/platform_device.h> |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 31 | #include <linux/proc_fs.h> |
| 32 | #include <linux/device.h> |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 33 | #include <mach/msm_nss.h> |
| 34 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 35 | #include <linux/sysctl.h> |
| 36 | #include <linux/regulator/consumer.h> |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 37 | #include <linux/clk.h> |
Thomas Wu | 4900896 | 2014-04-02 14:50:47 -0700 | [diff] [blame] | 38 | #include <linux/firmware.h> |
| 39 | |
| 40 | /* |
| 41 | * Macros |
| 42 | */ |
| 43 | #define MIN_IMG_SIZE 64*1024 |
| 44 | #define NETAP0_IMAGE "qcom-nss0.bin" |
| 45 | #define NETAP1_IMAGE "qcom-nss1.bin" |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 46 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 47 | /* |
| 48 | * Global declarations |
| 49 | */ |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 50 | int nss_ctl_redirect __read_mostly = 0; |
Sakthi Vignesh Radhakrishnan | 10132a8 | 2014-02-21 11:41:42 -0800 | [diff] [blame^] | 51 | int nss_ctl_debug __read_mostly = 1; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 52 | |
| 53 | /* |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 54 | * PM client handle |
| 55 | */ |
| 56 | static void *pm_client; |
| 57 | |
| 58 | /* |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 59 | * Handler to send NSS messages |
| 60 | */ |
| 61 | void *nss_freq_change_context; |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 62 | struct clk *nss_core0_clk; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 63 | |
| 64 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 65 | * Top level nss context structure |
| 66 | */ |
| 67 | struct nss_top_instance nss_top_main; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 68 | struct nss_cmd_buffer nss_cmd_buf; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 69 | struct nss_runtime_sampling nss_runtime_samples; |
| 70 | struct workqueue_struct *nss_wq; |
| 71 | |
| 72 | /* |
| 73 | * Work Queue to handle messages to Kernel |
| 74 | */ |
| 75 | nss_work_t *nss_work; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * File local/Static variables/functions |
| 79 | */ |
| 80 | |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 81 | static const struct net_device_ops nss_netdev_ops; |
| 82 | static const struct ethtool_ops nss_ethtool_ops; |
| 83 | |
| 84 | /* |
| 85 | * nss_dummy_netdev_setup() |
| 86 | * Dummy setup for net_device handler |
| 87 | */ |
| 88 | static void nss_dummy_netdev_setup(struct net_device *ndev) |
| 89 | { |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 90 | |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 91 | } |
| 92 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 93 | /* |
| 94 | * nss_handle_irq() |
| 95 | * HLOS interrupt handler for nss interrupts |
| 96 | */ |
| 97 | static irqreturn_t nss_handle_irq (int irq, void *ctx) |
| 98 | { |
| 99 | struct int_ctx_instance *int_ctx = (struct int_ctx_instance *) ctx; |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 100 | struct nss_ctx_instance *nss_ctx = int_ctx->nss_ctx; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 101 | |
| 102 | /* |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 103 | * Mask interrupt until our bottom half re-enables it |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 104 | */ |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 105 | nss_hal_disable_interrupt(nss_ctx->nmap, int_ctx->irq, |
| 106 | int_ctx->shift_factor, NSS_HAL_SUPPORTED_INTERRUPTS); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * Schedule tasklet to process interrupt cause |
| 110 | */ |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 111 | napi_schedule(&int_ctx->napi); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 112 | return IRQ_HANDLED; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * nss_probe() |
| 117 | * HLOS device probe callback |
| 118 | */ |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 119 | static int __devinit nss_probe(struct platform_device *nss_dev) |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 120 | { |
| 121 | struct nss_top_instance *nss_top = &nss_top_main; |
| 122 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[nss_dev->id]; |
| 123 | struct nss_platform_data *npd = (struct nss_platform_data *) nss_dev->dev.platform_data; |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 124 | struct netdev_priv_instance *ndev_priv; |
| 125 | int i, err = 0; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 126 | |
Thomas Wu | 4900896 | 2014-04-02 14:50:47 -0700 | [diff] [blame] | 127 | const struct firmware *nss_fw = NULL; |
| 128 | int rc = -ENODEV; |
| 129 | void __iomem *load_mem; |
| 130 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 131 | nss_ctx->nss_top = nss_top; |
| 132 | nss_ctx->id = nss_dev->id; |
| 133 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 134 | nss_info("%p: NSS_DEV_ID %s \n", nss_ctx, dev_name(&nss_dev->dev)); |
| 135 | |
Radha krishna Simha Jiguru | 27bff9a | 2014-03-18 16:31:34 +0530 | [diff] [blame] | 136 | /* |
| 137 | * F/W load from NSS Driver |
| 138 | */ |
| 139 | if (nss_dev->id == 0) { |
| 140 | rc = request_firmware(&nss_fw, NETAP0_IMAGE, &(nss_dev->dev)); |
| 141 | } else if (nss_dev->id == 1) { |
| 142 | rc = request_firmware(&nss_fw, NETAP1_IMAGE, &(nss_dev->dev)); |
| 143 | } else { |
| 144 | nss_warning("%p: Invalid nss context \n", nss_ctx); |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Check if the file read is successful |
| 149 | */ |
| 150 | if (rc) { |
| 151 | nss_warning("%p: request_firmware failed with err code: %d", nss_ctx, rc); |
| 152 | err = rc; |
| 153 | goto err_init_0; |
| 154 | } else { |
| 155 | if (nss_fw->size < MIN_IMG_SIZE) { |
| 156 | nss_warning("%p: nss firmware is deprecated, size:%d", nss_ctx, nss_fw->size); |
| 157 | } |
| 158 | load_mem = ioremap_nocache(npd->load_addr, nss_fw->size); |
| 159 | |
| 160 | if (load_mem == NULL) { |
| 161 | nss_warning("%p: ioremap_nocache failed: %x", nss_ctx, npd->load_addr); |
| 162 | release_firmware(nss_fw); |
| 163 | goto err_init_0; |
| 164 | } else { |
| 165 | memcpy_toio(load_mem, nss_fw->data, nss_fw->size); |
| 166 | release_firmware(nss_fw); |
| 167 | iounmap(load_mem); |
| 168 | printk("nss_driver - fw of size %d bytes copied to load addr: %x", nss_fw->size, npd->load_addr); |
| 169 | } |
| 170 | } |
| 171 | |
Sol Kavy | 4013e28 | 2014-04-06 15:57:00 -0700 | [diff] [blame] | 172 | /* |
Thomas Wu | 4900896 | 2014-04-02 14:50:47 -0700 | [diff] [blame] | 173 | * F/W load from NSS Driver |
| 174 | */ |
| 175 | if (nss_dev->id == 0) { |
| 176 | rc = request_firmware(&nss_fw, NETAP0_IMAGE, &(nss_dev->dev)); |
| 177 | } else if (nss_dev->id == 1) { |
| 178 | rc = request_firmware(&nss_fw, NETAP1_IMAGE, &(nss_dev->dev)); |
| 179 | } else { |
| 180 | nss_warning("%p: Invalid nss context \n", nss_ctx); |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Check if the file read is successful |
| 185 | */ |
| 186 | if (rc) { |
| 187 | nss_warning("%p: request_firmware failed with err code: %d", nss_ctx, rc); |
| 188 | err = rc; |
| 189 | goto err_init_0; |
| 190 | } else { |
| 191 | if (nss_fw->size < MIN_IMG_SIZE) { |
| 192 | nss_warning("%p: nss firmware is deprecated, size:%d", nss_ctx, nss_fw->size); |
| 193 | } |
| 194 | load_mem = ioremap_nocache(npd->load_addr, nss_fw->size); |
| 195 | |
| 196 | if (load_mem == NULL) { |
| 197 | nss_warning("%p: ioremap_nocache failed: %x", nss_ctx, npd->load_addr); |
| 198 | release_firmware(nss_fw); |
| 199 | goto err_init_0; |
| 200 | } else { |
| 201 | memcpy_toio(load_mem, nss_fw->data, nss_fw->size); |
| 202 | release_firmware(nss_fw); |
| 203 | iounmap(load_mem); |
| 204 | printk("nss_driver - fw of size %d bytes copied to load addr: %x", nss_fw->size, npd->load_addr); |
| 205 | } |
| 206 | } |
| 207 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 208 | /* |
| 209 | * Both NSS cores controlled by same regulator, Hook only Once |
| 210 | */ |
| 211 | if (!nss_dev->id) { |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 212 | nss_core0_clk = clk_get(&nss_dev->dev, "nss_core_clk"); |
| 213 | if (IS_ERR(nss_core0_clk)) { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 214 | |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 215 | err = PTR_ERR(nss_core0_clk); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 216 | nss_info("%p: Regulator %s get failed, err=%d\n", nss_ctx, dev_name(&nss_dev->dev), err); |
| 217 | return err; |
| 218 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 219 | } |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 220 | clk_set_rate(nss_core0_clk, NSS_FREQ_550); |
| 221 | clk_prepare(nss_core0_clk); |
| 222 | clk_enable(nss_core0_clk); |
Thomas Wu | 0a0a9c9 | 2013-11-21 15:28:19 -0800 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * Check if turbo is supported |
| 226 | */ |
| 227 | if (npd->turbo_frequency) { |
| 228 | /* |
| 229 | * Turbo is supported |
| 230 | */ |
| 231 | printk("nss_driver - Turbo Support %d\n", npd->turbo_frequency); |
| 232 | nss_runtime_samples.freq_scale_sup_max = NSS_MAX_CPU_SCALES; |
Pamidipati, Vijay | f9b5a27 | 2014-01-22 14:24:10 +0530 | [diff] [blame] | 233 | nss_pm_set_turbo(); |
Thomas Wu | 0a0a9c9 | 2013-11-21 15:28:19 -0800 | [diff] [blame] | 234 | } else { |
| 235 | printk("nss_driver - Turbo No Support %d\n", npd->turbo_frequency); |
| 236 | nss_runtime_samples.freq_scale_sup_max = NSS_MAX_CPU_SCALES - 1; |
| 237 | } |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 240 | /* |
Sakthi Vignesh Radhakrishnan | d923e34 | 2013-12-09 11:53:03 -0800 | [diff] [blame] | 241 | * Get load address of NSS firmware |
| 242 | */ |
| 243 | nss_info("%p: Setting NSS%d Firmware load address to %x\n", nss_ctx, nss_dev->id, npd->load_addr); |
| 244 | nss_top->nss[nss_dev->id].load = npd->load_addr; |
| 245 | |
| 246 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 247 | * Get virtual and physical memory addresses for nss logical/hardware address maps |
| 248 | */ |
| 249 | |
| 250 | /* |
| 251 | * Virtual address of CSM space |
| 252 | */ |
| 253 | nss_ctx->nmap = npd->nmap; |
| 254 | nss_assert(nss_ctx->nmap); |
| 255 | |
| 256 | /* |
| 257 | * Physical address of CSM space |
| 258 | */ |
| 259 | nss_ctx->nphys = npd->nphys; |
| 260 | nss_assert(nss_ctx->nphys); |
| 261 | |
| 262 | /* |
| 263 | * Virtual address of logical registers space |
| 264 | */ |
| 265 | nss_ctx->vmap = npd->vmap; |
| 266 | nss_assert(nss_ctx->vmap); |
| 267 | |
| 268 | /* |
| 269 | * Physical address of logical registers space |
| 270 | */ |
| 271 | nss_ctx->vphys = npd->vphys; |
| 272 | nss_assert(nss_ctx->vphys); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 273 | nss_info("%d:ctx=%p, vphys=%x, vmap=%x, nphys=%x, nmap=%x", |
| 274 | nss_dev->id, nss_ctx, nss_ctx->vphys, nss_ctx->vmap, nss_ctx->nphys, nss_ctx->nmap); |
| 275 | |
| 276 | /* |
| 277 | * Register netdevice handlers |
| 278 | */ |
| 279 | nss_ctx->int_ctx[0].ndev = alloc_netdev(sizeof(struct netdev_priv_instance), |
| 280 | "qca-nss-dev%d", nss_dummy_netdev_setup); |
| 281 | if (nss_ctx->int_ctx[0].ndev == NULL) { |
| 282 | nss_warning("%p: Could not allocate net_device #0", nss_ctx); |
| 283 | err = -ENOMEM; |
| 284 | goto err_init_0; |
| 285 | } |
| 286 | |
| 287 | nss_ctx->int_ctx[0].ndev->netdev_ops = &nss_netdev_ops; |
| 288 | nss_ctx->int_ctx[0].ndev->ethtool_ops = &nss_ethtool_ops; |
| 289 | err = register_netdev(nss_ctx->int_ctx[0].ndev); |
| 290 | if (err) { |
| 291 | nss_warning("%p: Could not register net_device #0", nss_ctx); |
| 292 | goto err_init_1; |
| 293 | } |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 294 | |
| 295 | /* |
| 296 | * request for IRQs |
| 297 | * |
| 298 | * WARNING: CPU affinities should be set using OS supported methods |
| 299 | */ |
| 300 | nss_ctx->int_ctx[0].nss_ctx = nss_ctx; |
| 301 | nss_ctx->int_ctx[0].shift_factor = 0; |
| 302 | nss_ctx->int_ctx[0].irq = npd->irq[0]; |
| 303 | err = request_irq(npd->irq[0], nss_handle_irq, IRQF_DISABLED, "nss", &nss_ctx->int_ctx[0]); |
| 304 | if (err) { |
| 305 | nss_warning("%d: IRQ0 request failed", nss_dev->id); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 306 | goto err_init_2; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /* |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 310 | * Register NAPI for NSS core interrupt #0 |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 311 | */ |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 312 | ndev_priv = netdev_priv(nss_ctx->int_ctx[0].ndev); |
| 313 | ndev_priv->int_ctx = &nss_ctx->int_ctx[0]; |
| 314 | netif_napi_add(nss_ctx->int_ctx[0].ndev, &nss_ctx->int_ctx[0].napi, nss_core_handle_napi, 64); |
| 315 | napi_enable(&nss_ctx->int_ctx[0].napi); |
| 316 | nss_ctx->int_ctx[0].napi_active = true; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 317 | |
| 318 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 319 | * Check if second interrupt is supported on this nss core |
| 320 | */ |
| 321 | if (npd->num_irq > 1) { |
| 322 | nss_info("%d: This NSS core supports two interrupts", nss_dev->id); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * Register netdevice handlers |
| 326 | */ |
| 327 | nss_ctx->int_ctx[1].ndev = alloc_netdev(sizeof(struct netdev_priv_instance), |
| 328 | "qca-nss-dev%d", nss_dummy_netdev_setup); |
| 329 | if (nss_ctx->int_ctx[1].ndev == NULL) { |
| 330 | nss_warning("%p: Could not allocate net_device #1", nss_ctx); |
| 331 | err = -ENOMEM; |
| 332 | goto err_init_3; |
| 333 | } |
| 334 | |
| 335 | nss_ctx->int_ctx[1].ndev->netdev_ops = &nss_netdev_ops; |
| 336 | nss_ctx->int_ctx[1].ndev->ethtool_ops = &nss_ethtool_ops; |
| 337 | err = register_netdev(nss_ctx->int_ctx[1].ndev); |
| 338 | if (err) { |
| 339 | nss_warning("%p: Could not register net_device #1", nss_ctx); |
| 340 | goto err_init_4; |
| 341 | } |
| 342 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 343 | nss_ctx->int_ctx[1].nss_ctx = nss_ctx; |
| 344 | nss_ctx->int_ctx[1].shift_factor = 15; |
| 345 | nss_ctx->int_ctx[1].irq = npd->irq[1]; |
| 346 | err = request_irq(npd->irq[1], nss_handle_irq, IRQF_DISABLED, "nss", &nss_ctx->int_ctx[1]); |
| 347 | if (err) { |
| 348 | nss_warning("%d: IRQ1 request failed for nss", nss_dev->id); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 349 | goto err_init_5; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /* |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 353 | * Register NAPI for NSS core interrupt #1 |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 354 | */ |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 355 | ndev_priv = netdev_priv(nss_ctx->int_ctx[1].ndev); |
| 356 | ndev_priv->int_ctx = &nss_ctx->int_ctx[1]; |
| 357 | netif_napi_add(nss_ctx->int_ctx[1].ndev, &nss_ctx->int_ctx[1].napi, nss_core_handle_napi, 64); |
| 358 | napi_enable(&nss_ctx->int_ctx[1].napi); |
| 359 | nss_ctx->int_ctx[1].napi_active = true; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | spin_lock_bh(&(nss_top->lock)); |
| 363 | |
| 364 | /* |
| 365 | * Check functionalities are supported by this NSS core |
| 366 | */ |
Murat Sezgin | 7a70542 | 2014-01-30 16:09:22 -0800 | [diff] [blame] | 367 | if (npd->shaping_enabled == NSS_FEATURE_ENABLED) { |
| 368 | nss_top->shaping_handler_id = nss_dev->id; |
| 369 | printk(KERN_INFO "%p: NSS Shaping is enabled, handler id: %u", __func__, nss_top->shaping_handler_id); |
| 370 | } |
| 371 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 372 | if (npd->ipv4_enabled == NSS_FEATURE_ENABLED) { |
| 373 | nss_top->ipv4_handler_id = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 374 | nss_ipv4_register_handler(); |
| 375 | nss_pppoe_register_handler(); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 376 | nss_eth_rx_register_handler(); |
| 377 | nss_n2h_register_handler(); |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 378 | nss_virt_if_register_handler(); |
Tushar Mathur | a3e0305 | 2014-04-07 20:17:28 +0530 | [diff] [blame] | 379 | nss_lag_register_handler(); |
Sol Kavy | 4013e28 | 2014-04-06 15:57:00 -0700 | [diff] [blame] | 380 | for (i = 0; i < NSS_MAX_VIRTUAL_INTERFACES; i++) { |
| 381 | nss_top->virt_if_handler_id[i] = nss_dev->id; |
| 382 | } |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | if (npd->ipv6_enabled == NSS_FEATURE_ENABLED) { |
| 386 | nss_top->ipv6_handler_id = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 387 | nss_ipv6_register_handler(); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 388 | } |
| 389 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 390 | if (npd->crypto_enabled == NSS_FEATURE_ENABLED) { |
| 391 | nss_top->crypto_handler_id = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 392 | nss_crypto_register_handler(); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | if (npd->ipsec_enabled == NSS_FEATURE_ENABLED) { |
| 396 | nss_top->ipsec_handler_id = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 397 | nss_ipsec_register_handler(); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | if (npd->wlan_enabled == NSS_FEATURE_ENABLED) { |
| 401 | nss_top->wlan_handler_id = nss_dev->id; |
| 402 | } |
| 403 | |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 404 | if (npd->tun6rd_enabled == NSS_FEATURE_ENABLED) { |
| 405 | nss_top->tun6rd_handler_id = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 406 | nss_tun6rd_register_handler(); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 407 | } |
| 408 | |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 409 | if (npd->tunipip6_enabled == NSS_FEATURE_ENABLED) { |
| 410 | nss_top->tunipip6_handler_id = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 411 | nss_tunipip6_register_handler(); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 412 | } |
| 413 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 414 | if (npd->gmac_enabled[0] == NSS_FEATURE_ENABLED) { |
| 415 | nss_top->phys_if_handler_id[0] = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 416 | nss_phys_if_register_handler(0); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | if (npd->gmac_enabled[1] == NSS_FEATURE_ENABLED) { |
| 420 | nss_top->phys_if_handler_id[1] = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 421 | nss_phys_if_register_handler(1); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | if (npd->gmac_enabled[2] == NSS_FEATURE_ENABLED) { |
| 425 | nss_top->phys_if_handler_id[2] = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 426 | nss_phys_if_register_handler(2); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | if (npd->gmac_enabled[3] == NSS_FEATURE_ENABLED) { |
| 430 | nss_top->phys_if_handler_id[3] = nss_dev->id; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 431 | nss_phys_if_register_handler(3); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 432 | } |
| 433 | |
Thomas Wu | 168ca26 | 2014-03-21 16:20:27 -0700 | [diff] [blame] | 434 | nss_core_freq_register_handler(); |
| 435 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 436 | nss_top->frequency_handler_id = nss_dev->id; |
| 437 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 438 | spin_unlock_bh(&(nss_top->lock)); |
| 439 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 440 | /* |
| 441 | * Initialize decongestion callbacks to NULL |
| 442 | */ |
| 443 | for (i = 0; i< NSS_MAX_CLIENTS; i++) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 444 | nss_ctx->queue_decongestion_callback[i] = 0; |
| 445 | nss_ctx->queue_decongestion_ctx[i] = 0; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | spin_lock_init(&(nss_ctx->decongest_cb_lock)); |
| 449 | nss_ctx->magic = NSS_CTX_MAGIC; |
| 450 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 451 | nss_info("%p: Reseting NSS core %d now", nss_ctx, nss_ctx->id); |
| 452 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 453 | /* |
| 454 | * Enable clocks and bring NSS core out of reset |
| 455 | */ |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 456 | nss_hal_core_reset(nss_dev->id, nss_ctx->nmap, nss_ctx->load, nss_top->clk_src); |
| 457 | |
| 458 | /* |
| 459 | * Enable interrupts for NSS core |
| 460 | */ |
| 461 | nss_hal_enable_interrupt(nss_ctx->nmap, nss_ctx->int_ctx[0].irq, |
| 462 | nss_ctx->int_ctx[0].shift_factor, NSS_HAL_SUPPORTED_INTERRUPTS); |
| 463 | |
| 464 | if (npd->num_irq > 1) { |
| 465 | nss_hal_enable_interrupt(nss_ctx->nmap, nss_ctx->int_ctx[1].irq, |
| 466 | nss_ctx->int_ctx[1].shift_factor, NSS_HAL_SUPPORTED_INTERRUPTS); |
| 467 | } |
| 468 | |
Radhakrishna Jiguru | b7346cf | 2013-12-16 13:08:43 +0530 | [diff] [blame] | 469 | /* |
| 470 | * Initialize max buffer size for NSS core |
| 471 | */ |
| 472 | nss_ctx->max_buf_size = NSS_NBUF_PAYLOAD_SIZE; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 473 | nss_info("%p: All resources initialized and nss core%d has been brought out of reset", nss_ctx, nss_dev->id); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 474 | goto err_init_0; |
| 475 | |
| 476 | err_init_5: |
| 477 | unregister_netdev(nss_ctx->int_ctx[1].ndev); |
| 478 | err_init_4: |
| 479 | free_netdev(nss_ctx->int_ctx[1].ndev); |
| 480 | err_init_3: |
| 481 | free_irq(npd->irq[0], &nss_ctx->int_ctx[0]); |
| 482 | err_init_2: |
| 483 | unregister_netdev(nss_ctx->int_ctx[0].ndev); |
| 484 | err_init_1: |
| 485 | free_netdev(nss_ctx->int_ctx[0].ndev); |
| 486 | err_init_0: |
| 487 | return err; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /* |
| 491 | * nss_remove() |
| 492 | * HLOS device remove callback |
| 493 | */ |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 494 | static int __devexit nss_remove(struct platform_device *nss_dev) |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 495 | { |
| 496 | struct nss_top_instance *nss_top = &nss_top_main; |
| 497 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[nss_dev->id]; |
| 498 | |
| 499 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 500 | * Clean-up debugfs |
| 501 | */ |
| 502 | nss_stats_clean(); |
| 503 | |
| 504 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 505 | * Disable interrupts and bottom halves in HLOS |
| 506 | * Disable interrupts from NSS to HLOS |
| 507 | */ |
| 508 | nss_hal_disable_interrupt(nss_ctx->nmap, nss_ctx->int_ctx[0].irq, |
| 509 | nss_ctx->int_ctx[0].shift_factor, NSS_HAL_SUPPORTED_INTERRUPTS); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 510 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 511 | free_irq(nss_ctx->int_ctx[0].irq, &nss_ctx->int_ctx[0]); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 512 | unregister_netdev(nss_ctx->int_ctx[0].ndev); |
| 513 | free_netdev(nss_ctx->int_ctx[0].ndev); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 514 | |
| 515 | /* |
| 516 | * Check if second interrupt is supported |
| 517 | * If so then clear resources for second interrupt as well |
| 518 | */ |
| 519 | if (nss_ctx->int_ctx[1].irq) { |
| 520 | nss_hal_disable_interrupt(nss_ctx->nmap, nss_ctx->int_ctx[1].irq, |
| 521 | nss_ctx->int_ctx[1].shift_factor, NSS_HAL_SUPPORTED_INTERRUPTS); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 522 | free_irq(nss_ctx->int_ctx[1].irq, &nss_ctx->int_ctx[1]); |
Abhishek Rastogi | 271eee7 | 2013-07-29 21:08:36 +0530 | [diff] [blame] | 523 | unregister_netdev(nss_ctx->int_ctx[1].ndev); |
| 524 | free_netdev(nss_ctx->int_ctx[1].ndev); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | nss_info("%p: All resources freed for nss core%d", nss_ctx, nss_dev->id); |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * nss_driver |
| 533 | * Platform driver structure for NSS |
| 534 | */ |
| 535 | struct platform_driver nss_driver = { |
| 536 | .probe = nss_probe, |
| 537 | .remove = __devexit_p(nss_remove), |
| 538 | .driver = { |
| 539 | .name = "qca-nss", |
| 540 | .owner = THIS_MODULE, |
| 541 | }, |
| 542 | }; |
| 543 | |
| 544 | /* |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 545 | * nss_reset_frequency_stats_samples() |
| 546 | * Reset all frequency sampling state when auto scaling is turned off. |
| 547 | */ |
| 548 | static void nss_reset_frequency_stats_samples (void) |
| 549 | { |
| 550 | nss_runtime_samples.buffer_index = 0; |
| 551 | nss_runtime_samples.sum = 0; |
| 552 | nss_runtime_samples.average = 0; |
| 553 | nss_runtime_samples.sample_count = 0; |
| 554 | nss_runtime_samples.message_rate_limit = 0; |
| 555 | nss_runtime_samples.freq_scale_rate_limit_up = 0; |
| 556 | nss_runtime_samples.freq_scale_rate_limit_down = 0; |
| 557 | } |
| 558 | |
| 559 | /* |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 560 | *************************************************************************************************** |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 561 | * nss_wq_function() is used to queue up requests to change NSS frequencies. |
| 562 | * The function will take care of NSS notices and also control clock. |
| 563 | * The auto rate algorithmn will queue up requests or the procfs may also queue up these requests. |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 564 | *************************************************************************************************** |
| 565 | */ |
| 566 | |
| 567 | /* |
| 568 | * nss_wq_function() |
| 569 | * Added to Handle BH requests to kernel |
| 570 | */ |
| 571 | void nss_wq_function (struct work_struct *work) |
| 572 | { |
| 573 | nss_work_t *my_work = (nss_work_t *)work; |
| 574 | |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 575 | nss_freq_change(nss_freq_change_context, my_work->frequency, my_work->stats_enable, 0); |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 576 | clk_set_rate(nss_core0_clk, my_work->frequency); |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 577 | nss_freq_change(nss_freq_change_context, my_work->frequency, my_work->stats_enable, 1); |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 578 | |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 579 | if(!pm_client) { |
| 580 | goto out; |
| 581 | } |
| 582 | |
| 583 | if (my_work->frequency == NSS_FREQ_733) { |
| 584 | nss_pm_set_perf_level(pm_client, NSS_PM_PERF_LEVEL_TURBO); |
| 585 | } else if ((my_work->frequency == NSS_FREQ_275) || (my_work->frequency == NSS_FREQ_550)) { |
| 586 | nss_pm_set_perf_level(pm_client, NSS_PM_PERF_LEVEL_NOMINAL); |
| 587 | } else { |
| 588 | nss_pm_set_perf_level(pm_client, NSS_PM_PERF_LEVEL_IDLE); |
| 589 | } |
| 590 | out: |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 591 | kfree((void *)work); |
| 592 | } |
| 593 | |
| 594 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 595 | * nss_current_freq_handler() |
| 596 | * Handle Userspace Frequency Change Requests |
| 597 | */ |
| 598 | static int nss_current_freq_handler (ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 599 | { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 600 | int ret; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 601 | |
| 602 | BUG_ON(!nss_wq); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 603 | |
| 604 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 605 | |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 606 | if (!write) { |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 607 | printk("Frequency Set to %d\n", nss_cmd_buf.current_freq); |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 608 | return ret; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 609 | } |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 610 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 611 | /* Turn off Auto Scale */ |
| 612 | nss_cmd_buf.auto_scale = 0; |
| 613 | nss_runtime_samples.freq_scale_ready = 0; |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 614 | |
Thomas Wu | 0a0a9c9 | 2013-11-21 15:28:19 -0800 | [diff] [blame] | 615 | /* If support NSS freq is in the table send the new frequency request to NSS or If No Turbo and ask for turbo freq */ |
| 616 | if (((nss_cmd_buf.current_freq != NSS_FREQ_110) && (nss_cmd_buf.current_freq != NSS_FREQ_275) && (nss_cmd_buf.current_freq != NSS_FREQ_550) && (nss_cmd_buf.current_freq != NSS_FREQ_733)) || ((nss_runtime_samples.freq_scale_sup_max != NSS_MAX_CPU_SCALES) && (nss_cmd_buf.current_freq == NSS_FREQ_733))) { |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 617 | printk("Frequency not found. Please check Frequency Table\n"); |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 618 | return ret; |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 619 | } |
| 620 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 621 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_KERNEL); |
| 622 | if (!nss_work) { |
| 623 | nss_info("NSS Freq WQ kmalloc fail"); |
| 624 | return ret; |
| 625 | } |
| 626 | INIT_WORK((struct work_struct *)nss_work, nss_wq_function); |
| 627 | nss_work->frequency = nss_cmd_buf.current_freq; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 628 | nss_work->stats_enable = 0; |
| 629 | |
| 630 | /* Ensure we start with a fresh set of samples later */ |
| 631 | nss_reset_frequency_stats_samples(); |
| 632 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 633 | queue_work(nss_wq, (struct work_struct *)nss_work); |
| 634 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 635 | return ret; |
| 636 | } |
| 637 | |
| 638 | /* |
| 639 | * nss_auto_scale_handler() |
| 640 | * Enables or Disable Auto Scaling |
| 641 | */ |
| 642 | static int nss_auto_scale_handler (ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 643 | { |
| 644 | int ret; |
| 645 | |
| 646 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 647 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 648 | if (!write) { |
| 649 | return ret; |
| 650 | } |
| 651 | |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 652 | if (nss_cmd_buf.auto_scale != 1) { |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 653 | /* |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 654 | * Is auto scaling currently enabled? If so, send the command to |
| 655 | * disable stats reporting to NSS |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 656 | */ |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 657 | if (nss_runtime_samples.freq_scale_ready != 0) { |
| 658 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
| 659 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_KERNEL); |
| 660 | if (!nss_work) { |
| 661 | nss_info("NSS Freq WQ kmalloc fail"); |
| 662 | return ret; |
| 663 | } |
| 664 | INIT_WORK((struct work_struct *)nss_work, nss_wq_function); |
| 665 | nss_work->frequency = nss_cmd_buf.current_freq; |
| 666 | nss_work->stats_enable = 0; |
| 667 | queue_work(nss_wq, (struct work_struct *)nss_work); |
| 668 | nss_runtime_samples.freq_scale_ready = 0; |
| 669 | |
| 670 | /* |
| 671 | * The current samples would be stale later when scaling is |
| 672 | * enabled again, hence reset them |
| 673 | */ |
| 674 | nss_reset_frequency_stats_samples(); |
| 675 | } |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 676 | return ret; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 677 | } |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 678 | |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 679 | /* |
| 680 | * Auto Scaling is already being done |
| 681 | */ |
| 682 | if (nss_runtime_samples.freq_scale_ready == 1) { |
| 683 | return ret; |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | * Setup default values - Middle of Freq Scale Band |
| 688 | */ |
| 689 | nss_runtime_samples.freq_scale_index = 1; |
| 690 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
| 691 | |
| 692 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_KERNEL); |
| 693 | if (!nss_work) { |
| 694 | nss_info("NSS Freq WQ kmalloc fail"); |
| 695 | return ret; |
| 696 | } |
| 697 | INIT_WORK((struct work_struct *)nss_work, nss_wq_function); |
| 698 | nss_work->frequency = nss_cmd_buf.current_freq; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 699 | nss_work->stats_enable = 1; |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 700 | queue_work(nss_wq, (struct work_struct *)nss_work); |
| 701 | |
| 702 | nss_runtime_samples.freq_scale_ready = 1; |
| 703 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 704 | return ret; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * nss_get_freq_table_handler() |
| 709 | * Display Support Freq and Ex how to Change. |
| 710 | */ |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 711 | static int nss_get_freq_table_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 712 | { |
| 713 | int ret; |
| 714 | |
| 715 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 716 | |
Thomas Wu | 0a0a9c9 | 2013-11-21 15:28:19 -0800 | [diff] [blame] | 717 | if (nss_runtime_samples.freq_scale_sup_max != NSS_MAX_CPU_SCALES) { |
| 718 | printk("Frequency Supported - 110Mhz 275Mhz 550Mhz\n"); |
| 719 | printk("Ex. To Change Frequency - echo 110000000 > current_freq \n"); |
| 720 | |
| 721 | return ret; |
| 722 | } |
| 723 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 724 | printk("Frequency Supported - 110Mhz 275Mhz 550Mhz 733Mhz \n"); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 725 | printk("Ex. To Change Frequency - echo 110000000 > current_freq \n"); |
| 726 | |
| 727 | return ret; |
| 728 | } |
| 729 | |
| 730 | /* |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 731 | * nss_get_average_inst_handler() |
| 732 | * Display AVG Inst Per Ms. |
| 733 | */ |
| 734 | static int nss_get_average_inst_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 735 | { |
| 736 | int ret; |
| 737 | |
| 738 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 739 | |
| 740 | if (!ret && !write) { |
| 741 | printk("Current Inst Per Ms %x\n", nss_runtime_samples.average); |
| 742 | } |
| 743 | |
| 744 | return ret; |
| 745 | } |
| 746 | |
| 747 | /* |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 748 | * nss_debug_handler() |
| 749 | * Enable NSS debug output |
| 750 | */ |
| 751 | static int nss_debug_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 752 | { |
| 753 | int ret; |
| 754 | |
| 755 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 756 | if (!ret) { |
| 757 | if ((write) && (nss_ctl_debug != 0)) { |
| 758 | printk("Enabling NSS SPI Debug\n"); |
| 759 | nss_hal_debug_enable(); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | return ret; |
| 764 | } |
| 765 | |
| 766 | /* |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 767 | * nss_coredump_handler() |
| 768 | * Send Signal To Coredump NSS Cores |
| 769 | */ |
| 770 | static int nss_coredump_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 771 | { |
| 772 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) nss_freq_change_context; |
| 773 | int ret; |
| 774 | |
| 775 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 776 | if (!ret) { |
| 777 | if ((write) && (nss_ctl_debug != 0)) { |
| 778 | printk("Coredumping to DDR\n"); |
| 779 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, NSS_REGS_H2N_INTR_STATUS_COREDUMP_START); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 787 | * sysctl-tuning infrastructure. |
| 788 | */ |
| 789 | static ctl_table nss_freq_table[] = { |
| 790 | { |
| 791 | .procname = "current_freq", |
| 792 | .data = &nss_cmd_buf.current_freq, |
| 793 | .maxlen = sizeof(int), |
| 794 | .mode = 0644, |
| 795 | .proc_handler = &nss_current_freq_handler, |
| 796 | }, |
| 797 | { |
| 798 | .procname = "freq_table", |
| 799 | .data = &nss_cmd_buf.max_freq, |
| 800 | .maxlen = sizeof(int), |
| 801 | .mode = 0644, |
| 802 | .proc_handler = &nss_get_freq_table_handler, |
| 803 | }, |
| 804 | { |
| 805 | .procname = "auto_scale", |
| 806 | .data = &nss_cmd_buf.auto_scale, |
| 807 | .maxlen = sizeof(int), |
| 808 | .mode = 0644, |
| 809 | .proc_handler = &nss_auto_scale_handler, |
| 810 | }, |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 811 | { |
| 812 | .procname = "inst_per_sec", |
| 813 | .data = &nss_cmd_buf.average_inst, |
| 814 | .maxlen = sizeof(int), |
| 815 | .mode = 0644, |
| 816 | .proc_handler = &nss_get_average_inst_handler, |
| 817 | }, |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 818 | { } |
| 819 | }; |
| 820 | |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 821 | static ctl_table nss_general_table[] = { |
| 822 | { |
| 823 | .procname = "redirect", |
| 824 | .data = &nss_ctl_redirect, |
| 825 | .maxlen = sizeof(int), |
| 826 | .mode = 0644, |
| 827 | .proc_handler = proc_dointvec, |
| 828 | }, |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 829 | { |
| 830 | .procname = "debug", |
| 831 | .data = &nss_ctl_debug, |
| 832 | .maxlen = sizeof(int), |
| 833 | .mode = 0644, |
| 834 | .proc_handler = &nss_debug_handler, |
| 835 | }, |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 836 | { |
| 837 | .procname = "coredump", |
| 838 | .data = &nss_cmd_buf.coredump, |
| 839 | .maxlen = sizeof(int), |
| 840 | .mode = 0644, |
| 841 | .proc_handler = &nss_coredump_handler, |
| 842 | }, |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 843 | { } |
| 844 | }; |
| 845 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 846 | static ctl_table nss_clock_dir[] = { |
| 847 | { |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 848 | .procname = "clock", |
| 849 | .mode = 0555, |
| 850 | .child = nss_freq_table, |
| 851 | }, |
| 852 | { |
| 853 | .procname = "general", |
| 854 | .mode = 0555, |
| 855 | .child = nss_general_table, |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 856 | }, |
| 857 | { } |
| 858 | }; |
| 859 | |
| 860 | static ctl_table nss_root_dir[] = { |
| 861 | { |
| 862 | .procname = "nss", |
| 863 | .mode = 0555, |
| 864 | .child = nss_clock_dir, |
| 865 | }, |
| 866 | { } |
| 867 | }; |
| 868 | |
| 869 | static ctl_table nss_root[] = { |
| 870 | { |
| 871 | .procname = "dev", |
| 872 | .mode = 0555, |
| 873 | .child = nss_root_dir, |
| 874 | }, |
| 875 | { } |
| 876 | }; |
| 877 | |
| 878 | static struct ctl_table_header *nss_dev_header; |
| 879 | |
| 880 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 881 | * nss_init() |
| 882 | * Registers nss driver |
| 883 | */ |
| 884 | static int __init nss_init(void) |
| 885 | { |
| 886 | nss_info("Init NSS driver"); |
| 887 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 888 | nss_freq_change_context = nss_get_frequency_mgr(); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 889 | /* |
| 890 | * Perform clock init common to all NSS cores |
| 891 | */ |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 892 | nss_hal_common_reset(&(nss_top_main.clk_src)); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 893 | |
| 894 | /* |
| 895 | * Enable spin locks |
| 896 | */ |
| 897 | spin_lock_init(&(nss_top_main.lock)); |
| 898 | spin_lock_init(&(nss_top_main.stats_lock)); |
| 899 | |
| 900 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 901 | * Enable NSS statistics |
| 902 | */ |
| 903 | nss_stats_init(); |
| 904 | |
| 905 | /* |
Sakthi Vignesh Radhakrishnan | 10132a8 | 2014-02-21 11:41:42 -0800 | [diff] [blame^] | 906 | * TODO: Remove before commit |
| 907 | */ |
| 908 | nss_hal_debug_enable(); |
| 909 | |
| 910 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 911 | * Register sysctl table. |
| 912 | */ |
| 913 | nss_dev_header = register_sysctl_table(nss_root); |
| 914 | |
| 915 | /* |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 916 | * Setup Runtime Sample values |
| 917 | */ |
| 918 | nss_runtime_samples.freq_scale[0].frequency = NSS_FREQ_110; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 919 | nss_runtime_samples.freq_scale[0].minimum = NSS_FREQ_110_MIN; |
| 920 | nss_runtime_samples.freq_scale[0].maximum = NSS_FREQ_110_MAX; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 921 | nss_runtime_samples.freq_scale[1].frequency = NSS_FREQ_550; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 922 | nss_runtime_samples.freq_scale[1].minimum = NSS_FREQ_550_MIN; |
| 923 | nss_runtime_samples.freq_scale[1].maximum = NSS_FREQ_550_MAX; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 924 | nss_runtime_samples.freq_scale[2].frequency = NSS_FREQ_733; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 925 | nss_runtime_samples.freq_scale[2].minimum = NSS_FREQ_733_MIN; |
| 926 | nss_runtime_samples.freq_scale[2].maximum = NSS_FREQ_733_MAX; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 927 | nss_runtime_samples.freq_scale_index = 1; |
| 928 | nss_runtime_samples.freq_scale_ready = 0; |
Thomas Wu | 9681f7e | 2013-11-06 13:12:57 -0800 | [diff] [blame] | 929 | nss_runtime_samples.freq_scale_rate_limit_up = 0; |
| 930 | nss_runtime_samples.freq_scale_rate_limit_down = 0; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 931 | nss_runtime_samples.buffer_index = 0; |
| 932 | nss_runtime_samples.sum = 0; |
| 933 | nss_runtime_samples.sample_count = 0; |
| 934 | nss_runtime_samples.average = 0; |
| 935 | nss_runtime_samples.message_rate_limit = 0; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 936 | nss_runtime_samples.initialized = 0; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 937 | |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 938 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
| 939 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 940 | /* |
| 941 | * Initial Workqueue |
| 942 | */ |
| 943 | nss_wq = create_workqueue("nss_freq_queue"); |
| 944 | |
| 945 | /* |
Pamidipati, Vijay | 7f413b5 | 2013-09-24 19:07:12 +0530 | [diff] [blame] | 946 | * Initialize NSS Bus PM module |
| 947 | */ |
| 948 | nss_pm_init(); |
| 949 | |
| 950 | /* |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 951 | * Register with Bus driver |
| 952 | */ |
| 953 | pm_client = nss_pm_client_register(NSS_PM_CLIENT_NETAP); |
| 954 | if (!pm_client) { |
| 955 | nss_warning("Error registering with PM driver"); |
| 956 | } |
| 957 | |
| 958 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 959 | * Register platform_driver |
| 960 | */ |
| 961 | return platform_driver_register(&nss_driver); |
| 962 | } |
| 963 | |
| 964 | /* |
| 965 | * nss_cleanup() |
| 966 | * Unregisters nss driver |
| 967 | */ |
| 968 | static void __exit nss_cleanup(void) |
| 969 | { |
| 970 | nss_info("Exit NSS driver"); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 971 | |
| 972 | if (nss_dev_header) |
| 973 | unregister_sysctl_table(nss_dev_header); |
| 974 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 975 | platform_driver_unregister(&nss_driver); |
| 976 | } |
| 977 | |
| 978 | module_init(nss_init); |
| 979 | module_exit(nss_cleanup); |
| 980 | |
| 981 | MODULE_DESCRIPTION("QCA NSS Driver"); |
| 982 | MODULE_AUTHOR("Qualcomm Atheros Inc"); |
| 983 | MODULE_LICENSE("Dual BSD/GPL"); |