| 1 | /* |
| 2 | * Copyright 2010-2017 Intel Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License, version 2, |
| 6 | * as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * Disclaimer: The codes contained in these modules may be specific to |
| 14 | * the Intel Software Development Platform codenamed Knights Ferry, |
| 15 | * and the Intel product codenamed Knights Corner, and are not backward |
| 16 | * compatible with other Intel products. Additionally, Intel will NOT |
| 17 | * support the codes or instruction set in future products. |
| 18 | * |
| 19 | * Intel offers no warranty of any kind regarding the code. This code is |
| 20 | * licensed on an "AS IS" basis and Intel is not obligated to provide |
| 21 | * any support, assistance, installation, training, or other services |
| 22 | * of any kind. Intel is also not obligated to provide any updates, |
| 23 | * enhancements or extensions. Intel specifically disclaims any warranty |
| 24 | * of merchantability, non-infringement, fitness for any particular |
| 25 | * purpose, and any other warranty. |
| 26 | * |
| 27 | * Further, Intel disclaims all liability of any kind, including but |
| 28 | * not limited to liability for infringement of any proprietary rights, |
| 29 | * relating to the use of the code, even if Intel is notified of the |
| 30 | * possibility of such liability. Except as expressly stated in an Intel |
| 31 | * license agreement provided with this code and agreed upon with Intel, |
| 32 | * no license, express or implied, by estoppel or otherwise, to any |
| 33 | * intellectual property rights is granted herein. |
| 34 | */ |
| 35 | |
| 36 | #include <mic/micscif.h> |
| 37 | |
| 38 | unsigned long scif_get_maxid(void); |
| 39 | static ssize_t show_scif_maxid(struct device *dev, struct device_attribute *attr, char *buf) |
| 40 | { |
| 41 | return snprintf(buf, PAGE_SIZE, "%d\n", ms_info.mi_maxid); |
| 42 | } |
| 43 | static DEVICE_ATTR(maxnode, S_IRUGO, show_scif_maxid, NULL); |
| 44 | |
| 45 | unsigned long scif_get_total(void); |
| 46 | static ssize_t show_scif_total(struct device *dev, struct device_attribute *attr, char *buf) |
| 47 | { |
| 48 | return snprintf(buf, PAGE_SIZE, "%d\n", ms_info.mi_total); |
| 49 | } |
| 50 | static DEVICE_ATTR(total, S_IRUGO, show_scif_total, NULL); |
| 51 | |
| 52 | unsigned long scif_get_nodes(void); |
| 53 | static ssize_t show_scif_nodes(struct device *dev, struct device_attribute *attr, char *buf) |
| 54 | { |
| 55 | int len = 0; |
| 56 | int node; |
| 57 | |
| 58 | len += snprintf(buf + len, PAGE_SIZE, "%d:", ms_info.mi_total); |
| 59 | len += snprintf(buf + len, PAGE_SIZE, "%d", ms_info.mi_nodeid); |
| 60 | |
| 61 | for (node = 0; node <= ms_info.mi_maxid; node++) { |
| 62 | if (scif_dev[node].sd_state == SCIFDEV_RUNNING || |
| 63 | scif_dev[node].sd_state == SCIFDEV_SLEEPING || |
| 64 | is_self_scifdev(&scif_dev[node])) { |
| 65 | len += snprintf(buf + len, PAGE_SIZE, ",%d", scif_dev[node].sd_node); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | len += snprintf(buf + len, PAGE_SIZE, "\n"); |
| 70 | return len; |
| 71 | } |
| 72 | static DEVICE_ATTR(nodes, S_IRUGO, show_scif_nodes, NULL); |
| 73 | |
| 74 | static ssize_t show_watchdog_to(struct device *dev, |
| 75 | struct device_attribute *attr, |
| 76 | char *buf) |
| 77 | { |
| 78 | return snprintf(buf, PAGE_SIZE, "%d\n", ms_info.mi_watchdog_to); |
| 79 | } |
| 80 | |
| 81 | static ssize_t store_watchdog_to(struct device *dev, |
| 82 | struct device_attribute *attr, |
| 83 | const char *buf, |
| 84 | size_t count) |
| 85 | { |
| 86 | int i, ret; |
| 87 | |
| 88 | if (sscanf(buf, "%d", &i) != 1) |
| 89 | goto invalid; |
| 90 | |
| 91 | if (i <= 0) |
| 92 | goto invalid; |
| 93 | |
| 94 | ms_info.mi_watchdog_to = i; |
| 95 | ret = strlen(buf); |
| 96 | printk("Current watchdog timeout %d seconds\n", ms_info.mi_watchdog_to); |
| 97 | goto bail; |
| 98 | |
| 99 | invalid: |
| 100 | printk(KERN_ERR "Attempt to set invalid watchdog timeout\n"); |
| 101 | ret = -EINVAL; |
| 102 | bail: |
| 103 | return ret; |
| 104 | } |
| 105 | static DEVICE_ATTR(watchdog_to, S_IRUGO | S_IWUSR, show_watchdog_to, store_watchdog_to); |
| 106 | |
| 107 | static ssize_t show_watchdog_enabled(struct device *dev, |
| 108 | struct device_attribute *attr, |
| 109 | char *buf) |
| 110 | { |
| 111 | return snprintf(buf, PAGE_SIZE, "%d\n", ms_info.mi_watchdog_enabled); |
| 112 | } |
| 113 | |
| 114 | static ssize_t store_watchdog_enabled(struct device *dev, |
| 115 | struct device_attribute *attr, |
| 116 | const char *buf, |
| 117 | size_t count) |
| 118 | { |
| 119 | int i, ret; |
| 120 | #ifndef _MIC_SCIF_ |
| 121 | struct micscif_dev *scifdev; |
| 122 | int node; |
| 123 | #endif |
| 124 | |
| 125 | if (sscanf(buf, "%d", &i) != 1) |
| 126 | goto invalid; |
| 127 | |
| 128 | if (i < 0) |
| 129 | goto invalid; |
| 130 | |
| 131 | if (i && !ms_info.mi_watchdog_enabled) { |
| 132 | ms_info.mi_watchdog_enabled = 1; |
| 133 | #ifndef _MIC_SCIF_ |
| 134 | for (node = 1; node <= ms_info.mi_maxid; node++) { |
| 135 | scifdev = &scif_dev[node]; |
| 136 | if (scifdev->sd_ln_wq) |
| 137 | queue_delayed_work(scifdev->sd_ln_wq, |
| 138 | &scifdev->sd_watchdog_work, NODE_ALIVE_TIMEOUT); |
| 139 | } |
| 140 | #endif |
| 141 | } |
| 142 | |
| 143 | if (!i) |
| 144 | ms_info.mi_watchdog_enabled = 0; |
| 145 | |
| 146 | ret = strlen(buf); |
| 147 | printk("Watchdog timeout enabled = %d\n", ms_info.mi_watchdog_enabled); |
| 148 | goto bail; |
| 149 | invalid: |
| 150 | ret = -EINVAL; |
| 151 | bail: |
| 152 | return ret; |
| 153 | } |
| 154 | static DEVICE_ATTR(watchdog_enabled, S_IRUGO | S_IWUSR, show_watchdog_enabled, store_watchdog_enabled); |
| 155 | |
| 156 | static ssize_t show_watchdog_auto_reboot(struct device *dev, |
| 157 | struct device_attribute *attr, |
| 158 | char *buf) |
| 159 | { |
| 160 | return snprintf(buf, PAGE_SIZE, "%d\n", ms_info.mi_watchdog_auto_reboot); |
| 161 | } |
| 162 | |
| 163 | static ssize_t store_watchdog_auto_reboot(struct device *dev, |
| 164 | struct device_attribute *attr, |
| 165 | const char *buf, |
| 166 | size_t count) |
| 167 | { |
| 168 | int i, ret; |
| 169 | |
| 170 | if (sscanf(buf, "%d", &i) != 1) |
| 171 | goto invalid; |
| 172 | |
| 173 | if (i < 0) |
| 174 | goto invalid; |
| 175 | |
| 176 | if (i && !ms_info.mi_watchdog_auto_reboot) |
| 177 | ms_info.mi_watchdog_auto_reboot = 1; |
| 178 | |
| 179 | if (!i) |
| 180 | ms_info.mi_watchdog_auto_reboot = 0; |
| 181 | |
| 182 | ret = strlen(buf); |
| 183 | printk("Watchdog auto reboot enabled = %d\n", ms_info.mi_watchdog_auto_reboot); |
| 184 | goto bail; |
| 185 | invalid: |
| 186 | ret = -EINVAL; |
| 187 | bail: |
| 188 | return ret; |
| 189 | } |
| 190 | static DEVICE_ATTR(watchdog_auto_reboot, S_IRUGO | S_IWUSR, show_watchdog_auto_reboot, store_watchdog_auto_reboot); |
| 191 | |
| 192 | static ssize_t show_proxy_dma_threshold(struct device *dev, |
| 193 | struct device_attribute *attr, |
| 194 | char *buf) |
| 195 | { |
| 196 | return snprintf(buf, PAGE_SIZE, "%lld\n", ms_info.mi_proxy_dma_threshold); |
| 197 | } |
| 198 | |
| 199 | static ssize_t store_proxy_dma_threshold(struct device *dev, |
| 200 | struct device_attribute *attr, |
| 201 | const char *buf, |
| 202 | size_t count) |
| 203 | { |
| 204 | int ret; |
| 205 | uint64_t i; |
| 206 | |
| 207 | if (sscanf(buf, "%lld", &i) != 1) |
| 208 | goto invalid; |
| 209 | |
| 210 | ms_info.mi_proxy_dma_threshold = i; |
| 211 | ret = strlen(buf); |
| 212 | printk("P2P proxy DMA Threshold = %lld bytes\n", ms_info.mi_proxy_dma_threshold); |
| 213 | goto bail; |
| 214 | invalid: |
| 215 | ret = -EINVAL; |
| 216 | bail: |
| 217 | return ret; |
| 218 | } |
| 219 | static DEVICE_ATTR(proxy_dma_threshold, S_IRUGO | S_IWUSR, show_proxy_dma_threshold, store_proxy_dma_threshold); |
| 220 | |
| 221 | static struct attribute *scif_attributes[] = { |
| 222 | &dev_attr_maxnode.attr, |
| 223 | &dev_attr_total.attr, |
| 224 | &dev_attr_nodes.attr, |
| 225 | &dev_attr_watchdog_to.attr, |
| 226 | &dev_attr_watchdog_enabled.attr, |
| 227 | &dev_attr_watchdog_auto_reboot.attr, |
| 228 | &dev_attr_proxy_dma_threshold.attr, |
| 229 | NULL |
| 230 | }; |
| 231 | |
| 232 | struct attribute_group scif_attr_group = { |
| 233 | .attrs = scif_attributes |
| 234 | }; |