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