Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2 | /* |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3 | * Copyright IBM Corp. 2007 |
| 4 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com>, |
| 5 | * Frank Pavlic <fpavlic@de.ibm.com>, |
| 6 | * Thomas Spatzier <tspat@de.ibm.com>, |
| 7 | * Frank Blaschka <frank.blaschka@de.ibm.com> |
| 8 | */ |
| 9 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 11 | #include <asm/ebcdic.h> |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 12 | #include <linux/hashtable.h> |
Julian Wiedmann | 556fd27 | 2017-12-20 20:11:09 +0100 | [diff] [blame] | 13 | #include <linux/inet.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 14 | #include "qeth_l3.h" |
| 15 | |
| 16 | #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \ |
| 17 | struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store) |
| 18 | |
Julian Wiedmann | 556fd27 | 2017-12-20 20:11:09 +0100 | [diff] [blame] | 19 | static int qeth_l3_string_to_ipaddr(const char *buf, |
| 20 | enum qeth_prot_versions proto, u8 *addr) |
| 21 | { |
| 22 | const char *end; |
| 23 | |
| 24 | if ((proto == QETH_PROT_IPV4 && !in4_pton(buf, -1, addr, -1, &end)) || |
| 25 | (proto == QETH_PROT_IPV6 && !in6_pton(buf, -1, addr, -1, &end))) |
| 26 | return -EINVAL; |
| 27 | return 0; |
| 28 | } |
| 29 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 30 | static ssize_t qeth_l3_dev_route_show(struct qeth_card *card, |
| 31 | struct qeth_routing_info *route, char *buf) |
| 32 | { |
| 33 | switch (route->type) { |
| 34 | case PRIMARY_ROUTER: |
| 35 | return sprintf(buf, "%s\n", "primary router"); |
| 36 | case SECONDARY_ROUTER: |
| 37 | return sprintf(buf, "%s\n", "secondary router"); |
| 38 | case MULTICAST_ROUTER: |
| 39 | if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO) |
| 40 | return sprintf(buf, "%s\n", "multicast router+"); |
| 41 | else |
| 42 | return sprintf(buf, "%s\n", "multicast router"); |
| 43 | case PRIMARY_CONNECTOR: |
| 44 | if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO) |
| 45 | return sprintf(buf, "%s\n", "primary connector+"); |
| 46 | else |
| 47 | return sprintf(buf, "%s\n", "primary connector"); |
| 48 | case SECONDARY_CONNECTOR: |
| 49 | if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO) |
| 50 | return sprintf(buf, "%s\n", "secondary connector+"); |
| 51 | else |
| 52 | return sprintf(buf, "%s\n", "secondary connector"); |
| 53 | default: |
| 54 | return sprintf(buf, "%s\n", "no"); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | static ssize_t qeth_l3_dev_route4_show(struct device *dev, |
| 59 | struct device_attribute *attr, char *buf) |
| 60 | { |
| 61 | struct qeth_card *card = dev_get_drvdata(dev); |
| 62 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 63 | return qeth_l3_dev_route_show(card, &card->options.route4, buf); |
| 64 | } |
| 65 | |
| 66 | static ssize_t qeth_l3_dev_route_store(struct qeth_card *card, |
| 67 | struct qeth_routing_info *route, enum qeth_prot_versions prot, |
| 68 | const char *buf, size_t count) |
| 69 | { |
| 70 | enum qeth_routing_types old_route_type = route->type; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 71 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 72 | |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 73 | mutex_lock(&card->conf_mutex); |
Eugene Crosser | 7e846d6b | 2015-01-16 14:05:48 +0100 | [diff] [blame] | 74 | if (sysfs_streq(buf, "no_router")) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 75 | route->type = NO_ROUTER; |
Eugene Crosser | 7e846d6b | 2015-01-16 14:05:48 +0100 | [diff] [blame] | 76 | } else if (sysfs_streq(buf, "primary_connector")) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 77 | route->type = PRIMARY_CONNECTOR; |
Eugene Crosser | 7e846d6b | 2015-01-16 14:05:48 +0100 | [diff] [blame] | 78 | } else if (sysfs_streq(buf, "secondary_connector")) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 79 | route->type = SECONDARY_CONNECTOR; |
Eugene Crosser | 7e846d6b | 2015-01-16 14:05:48 +0100 | [diff] [blame] | 80 | } else if (sysfs_streq(buf, "primary_router")) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 81 | route->type = PRIMARY_ROUTER; |
Eugene Crosser | 7e846d6b | 2015-01-16 14:05:48 +0100 | [diff] [blame] | 82 | } else if (sysfs_streq(buf, "secondary_router")) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 83 | route->type = SECONDARY_ROUTER; |
Eugene Crosser | 7e846d6b | 2015-01-16 14:05:48 +0100 | [diff] [blame] | 84 | } else if (sysfs_streq(buf, "multicast_router")) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 85 | route->type = MULTICAST_ROUTER; |
| 86 | } else { |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 87 | rc = -EINVAL; |
| 88 | goto out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 89 | } |
Eugene Crosser | c352125 | 2015-01-16 14:05:47 +0100 | [diff] [blame] | 90 | if (qeth_card_hw_is_reachable(card) && |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 91 | (old_route_type != route->type)) { |
| 92 | if (prot == QETH_PROT_IPV4) |
| 93 | rc = qeth_l3_setrouting_v4(card); |
| 94 | else if (prot == QETH_PROT_IPV6) |
| 95 | rc = qeth_l3_setrouting_v6(card); |
| 96 | } |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 97 | out: |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 98 | if (rc) |
| 99 | route->type = old_route_type; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 100 | mutex_unlock(&card->conf_mutex); |
| 101 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static ssize_t qeth_l3_dev_route4_store(struct device *dev, |
| 105 | struct device_attribute *attr, const char *buf, size_t count) |
| 106 | { |
| 107 | struct qeth_card *card = dev_get_drvdata(dev); |
| 108 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 109 | return qeth_l3_dev_route_store(card, &card->options.route4, |
| 110 | QETH_PROT_IPV4, buf, count); |
| 111 | } |
| 112 | |
| 113 | static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show, |
| 114 | qeth_l3_dev_route4_store); |
| 115 | |
| 116 | static ssize_t qeth_l3_dev_route6_show(struct device *dev, |
| 117 | struct device_attribute *attr, char *buf) |
| 118 | { |
| 119 | struct qeth_card *card = dev_get_drvdata(dev); |
| 120 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 121 | return qeth_l3_dev_route_show(card, &card->options.route6, buf); |
| 122 | } |
| 123 | |
| 124 | static ssize_t qeth_l3_dev_route6_store(struct device *dev, |
| 125 | struct device_attribute *attr, const char *buf, size_t count) |
| 126 | { |
| 127 | struct qeth_card *card = dev_get_drvdata(dev); |
| 128 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 129 | return qeth_l3_dev_route_store(card, &card->options.route6, |
| 130 | QETH_PROT_IPV6, buf, count); |
| 131 | } |
| 132 | |
| 133 | static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show, |
| 134 | qeth_l3_dev_route6_store); |
| 135 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 136 | static ssize_t qeth_l3_dev_sniffer_show(struct device *dev, |
| 137 | struct device_attribute *attr, char *buf) |
| 138 | { |
| 139 | struct qeth_card *card = dev_get_drvdata(dev); |
| 140 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 141 | return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0); |
| 142 | } |
| 143 | |
| 144 | static ssize_t qeth_l3_dev_sniffer_store(struct device *dev, |
| 145 | struct device_attribute *attr, const char *buf, size_t count) |
| 146 | { |
| 147 | struct qeth_card *card = dev_get_drvdata(dev); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 148 | int rc = 0; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 149 | unsigned long i; |
| 150 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 151 | if (!IS_IQD(card)) |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 152 | return -EPERM; |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 153 | if (card->options.cq == QETH_CQ_ENABLED) |
| 154 | return -EPERM; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 155 | |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 156 | mutex_lock(&card->conf_mutex); |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 157 | if (card->state != CARD_STATE_DOWN) { |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 158 | rc = -EPERM; |
| 159 | goto out; |
| 160 | } |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 161 | |
Jingoo Han | 0178722 | 2013-07-22 10:18:15 +0900 | [diff] [blame] | 162 | rc = kstrtoul(buf, 16, &i); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 163 | if (rc) { |
| 164 | rc = -EINVAL; |
| 165 | goto out; |
| 166 | } |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 167 | switch (i) { |
| 168 | case 0: |
| 169 | card->options.sniffer = i; |
| 170 | break; |
| 171 | case 1: |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 172 | qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd); |
Julian Wiedmann | 1917b47 | 2019-10-23 10:03:23 +0200 | [diff] [blame] | 173 | if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) { |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 174 | card->options.sniffer = i; |
Julian Wiedmann | 5d4f785 | 2020-03-11 18:07:11 +0100 | [diff] [blame] | 175 | qeth_resize_buffer_pool(card, QETH_IN_BUF_COUNT_MAX); |
| 176 | } else { |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 177 | rc = -EPERM; |
Julian Wiedmann | 5d4f785 | 2020-03-11 18:07:11 +0100 | [diff] [blame] | 178 | } |
| 179 | |
Ursula Braun | 6cc31d0 | 2011-11-15 02:31:12 +0000 | [diff] [blame] | 180 | break; |
| 181 | default: |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 182 | rc = -EINVAL; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 183 | } |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 184 | out: |
| 185 | mutex_unlock(&card->conf_mutex); |
| 186 | return rc ? rc : count; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show, |
| 190 | qeth_l3_dev_sniffer_store); |
| 191 | |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 192 | static ssize_t qeth_l3_dev_hsuid_show(struct device *dev, |
| 193 | struct device_attribute *attr, char *buf) |
| 194 | { |
| 195 | struct qeth_card *card = dev_get_drvdata(dev); |
| 196 | char tmp_hsuid[9]; |
| 197 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 198 | if (!IS_IQD(card)) |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 199 | return -EPERM; |
| 200 | |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 201 | memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid)); |
| 202 | EBCASC(tmp_hsuid, 8); |
| 203 | return sprintf(buf, "%s\n", tmp_hsuid); |
| 204 | } |
| 205 | |
| 206 | static ssize_t qeth_l3_dev_hsuid_store(struct device *dev, |
| 207 | struct device_attribute *attr, const char *buf, size_t count) |
| 208 | { |
| 209 | struct qeth_card *card = dev_get_drvdata(dev); |
Julian Wiedmann | 5b6c7b5 | 2019-12-23 15:03:22 +0100 | [diff] [blame] | 210 | int rc = 0; |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 211 | char *tmp; |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 212 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 213 | if (!IS_IQD(card)) |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 214 | return -EPERM; |
Julian Wiedmann | 5b6c7b5 | 2019-12-23 15:03:22 +0100 | [diff] [blame] | 215 | |
| 216 | mutex_lock(&card->conf_mutex); |
| 217 | if (card->state != CARD_STATE_DOWN) { |
| 218 | rc = -EPERM; |
| 219 | goto out; |
| 220 | } |
| 221 | |
| 222 | if (card->options.sniffer) { |
| 223 | rc = -EPERM; |
| 224 | goto out; |
| 225 | } |
| 226 | |
| 227 | if (card->options.cq == QETH_CQ_NOTAVAILABLE) { |
| 228 | rc = -EPERM; |
| 229 | goto out; |
| 230 | } |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 231 | |
| 232 | tmp = strsep((char **)&buf, "\n"); |
Julian Wiedmann | 5b6c7b5 | 2019-12-23 15:03:22 +0100 | [diff] [blame] | 233 | if (strlen(tmp) > 8) { |
| 234 | rc = -EINVAL; |
| 235 | goto out; |
| 236 | } |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 237 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 238 | if (card->options.hsuid[0]) |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 239 | /* delete old ip address */ |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 240 | qeth_l3_modify_hsuid(card, false); |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 241 | |
| 242 | if (strlen(tmp) == 0) { |
| 243 | /* delete ip address only */ |
| 244 | card->options.hsuid[0] = '\0'; |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 245 | memcpy(card->dev->perm_addr, card->options.hsuid, 9); |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 246 | qeth_configure_cq(card, QETH_CQ_DISABLED); |
Julian Wiedmann | 5b6c7b5 | 2019-12-23 15:03:22 +0100 | [diff] [blame] | 247 | goto out; |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Julian Wiedmann | 5b6c7b5 | 2019-12-23 15:03:22 +0100 | [diff] [blame] | 250 | if (qeth_configure_cq(card, QETH_CQ_ENABLED)) { |
| 251 | rc = -EPERM; |
| 252 | goto out; |
| 253 | } |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 254 | |
Kees Cook | 096a8aa | 2013-07-03 15:04:55 -0700 | [diff] [blame] | 255 | snprintf(card->options.hsuid, sizeof(card->options.hsuid), |
| 256 | "%-8s", tmp); |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 257 | ASCEBC(card->options.hsuid, 8); |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 258 | memcpy(card->dev->perm_addr, card->options.hsuid, 9); |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 259 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 260 | rc = qeth_l3_modify_hsuid(card, true); |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 261 | |
Julian Wiedmann | 5b6c7b5 | 2019-12-23 15:03:22 +0100 | [diff] [blame] | 262 | out: |
| 263 | mutex_unlock(&card->conf_mutex); |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 264 | return rc ? rc : count; |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show, |
| 268 | qeth_l3_dev_hsuid_store); |
| 269 | |
| 270 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 271 | static struct attribute *qeth_l3_device_attrs[] = { |
| 272 | &dev_attr_route4.attr, |
| 273 | &dev_attr_route6.attr, |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 274 | &dev_attr_sniffer.attr, |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 275 | &dev_attr_hsuid.attr, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 276 | NULL, |
| 277 | }; |
| 278 | |
Arvind Yadav | cfe9a04 | 2017-07-19 12:39:14 +0530 | [diff] [blame] | 279 | static const struct attribute_group qeth_l3_device_attr_group = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 280 | .attrs = qeth_l3_device_attrs, |
| 281 | }; |
| 282 | |
| 283 | static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev, |
| 284 | struct device_attribute *attr, char *buf) |
| 285 | { |
| 286 | struct qeth_card *card = dev_get_drvdata(dev); |
| 287 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 288 | return sprintf(buf, "%i\n", card->ipato.enabled? 1:0); |
| 289 | } |
| 290 | |
| 291 | static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev, |
| 292 | struct device_attribute *attr, const char *buf, size_t count) |
| 293 | { |
| 294 | struct qeth_card *card = dev_get_drvdata(dev); |
Julian Wiedmann | 7fbd949 | 2017-12-13 18:56:29 +0100 | [diff] [blame] | 295 | bool enable; |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 296 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 297 | |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 298 | mutex_lock(&card->conf_mutex); |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 299 | if (card->state != CARD_STATE_DOWN) { |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 300 | rc = -EPERM; |
| 301 | goto out; |
| 302 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 303 | |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 304 | mutex_lock(&card->ip_lock); |
Eugene Crosser | 7e846d6b | 2015-01-16 14:05:48 +0100 | [diff] [blame] | 305 | if (sysfs_streq(buf, "toggle")) { |
Julian Wiedmann | 7fbd949 | 2017-12-13 18:56:29 +0100 | [diff] [blame] | 306 | enable = !card->ipato.enabled; |
| 307 | } else if (kstrtobool(buf, &enable)) { |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 308 | rc = -EINVAL; |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 309 | goto unlock_ip; |
Julian Wiedmann | 7fbd949 | 2017-12-13 18:56:29 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 312 | if (card->ipato.enabled != enable) { |
| 313 | card->ipato.enabled = enable; |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 314 | qeth_l3_update_ipato(card); |
Julian Wiedmann | 7fbd949 | 2017-12-13 18:56:29 +0100 | [diff] [blame] | 315 | } |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 316 | |
| 317 | unlock_ip: |
| 318 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 319 | out: |
| 320 | mutex_unlock(&card->conf_mutex); |
| 321 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static QETH_DEVICE_ATTR(ipato_enable, enable, 0644, |
| 325 | qeth_l3_dev_ipato_enable_show, |
| 326 | qeth_l3_dev_ipato_enable_store); |
| 327 | |
| 328 | static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev, |
| 329 | struct device_attribute *attr, char *buf) |
| 330 | { |
| 331 | struct qeth_card *card = dev_get_drvdata(dev); |
| 332 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 333 | return sprintf(buf, "%i\n", card->ipato.invert4? 1:0); |
| 334 | } |
| 335 | |
| 336 | static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev, |
| 337 | struct device_attribute *attr, |
| 338 | const char *buf, size_t count) |
| 339 | { |
| 340 | struct qeth_card *card = dev_get_drvdata(dev); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 341 | bool invert; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 342 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 343 | |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 344 | mutex_lock(&card->ip_lock); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 345 | if (sysfs_streq(buf, "toggle")) { |
| 346 | invert = !card->ipato.invert4; |
| 347 | } else if (kstrtobool(buf, &invert)) { |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 348 | rc = -EINVAL; |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 349 | goto out; |
| 350 | } |
| 351 | |
| 352 | if (card->ipato.invert4 != invert) { |
| 353 | card->ipato.invert4 = invert; |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 354 | qeth_l3_update_ipato(card); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 355 | } |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 356 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 357 | out: |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 358 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 359 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644, |
| 363 | qeth_l3_dev_ipato_invert4_show, |
| 364 | qeth_l3_dev_ipato_invert4_store); |
| 365 | |
| 366 | static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card, |
| 367 | enum qeth_prot_versions proto) |
| 368 | { |
| 369 | struct qeth_ipato_entry *ipatoe; |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 370 | int str_len = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 371 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 372 | mutex_lock(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 373 | list_for_each_entry(ipatoe, &card->ipato.entries, entry) { |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 374 | char addr_str[40]; |
| 375 | int entry_len; |
| 376 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 377 | if (ipatoe->proto != proto) |
| 378 | continue; |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 379 | |
| 380 | entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr, |
| 381 | addr_str); |
| 382 | if (entry_len < 0) |
| 383 | continue; |
| 384 | |
| 385 | /* Append /%mask to the entry: */ |
| 386 | entry_len += 1 + ((proto == QETH_PROT_IPV4) ? 2 : 3); |
| 387 | /* Enough room to format %entry\n into null terminated page? */ |
| 388 | if (entry_len + 1 > PAGE_SIZE - str_len - 1) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 389 | break; |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 390 | |
| 391 | entry_len = scnprintf(buf, PAGE_SIZE - str_len, |
| 392 | "%s/%i\n", addr_str, ipatoe->mask_bits); |
| 393 | str_len += entry_len; |
| 394 | buf += entry_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 395 | } |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 396 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 397 | |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 398 | return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev, |
| 402 | struct device_attribute *attr, char *buf) |
| 403 | { |
| 404 | struct qeth_card *card = dev_get_drvdata(dev); |
| 405 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 406 | return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4); |
| 407 | } |
| 408 | |
| 409 | static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto, |
Julian Wiedmann | ab29c48 | 2020-09-23 10:36:55 +0200 | [diff] [blame] | 410 | u8 *addr, unsigned int *mask_bits) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 411 | { |
Julian Wiedmann | ab29c48 | 2020-09-23 10:36:55 +0200 | [diff] [blame] | 412 | char *sep; |
Julian Wiedmann | bcdfdf0 | 2020-09-23 10:36:54 +0200 | [diff] [blame] | 413 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 414 | |
Julian Wiedmann | bcdfdf0 | 2020-09-23 10:36:54 +0200 | [diff] [blame] | 415 | /* Expected input pattern: %addr/%mask */ |
| 416 | sep = strnchr(buf, 40, '/'); |
| 417 | if (!sep) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 418 | return -EINVAL; |
Julian Wiedmann | bcdfdf0 | 2020-09-23 10:36:54 +0200 | [diff] [blame] | 419 | |
| 420 | /* Terminate the %addr sub-string, and parse it: */ |
| 421 | *sep = '\0'; |
| 422 | rc = qeth_l3_string_to_ipaddr(buf, proto, addr); |
| 423 | if (rc) |
| 424 | return rc; |
| 425 | |
Julian Wiedmann | ab29c48 | 2020-09-23 10:36:55 +0200 | [diff] [blame] | 426 | rc = kstrtouint(sep + 1, 10, mask_bits); |
| 427 | if (rc) |
| 428 | return rc; |
| 429 | |
| 430 | if (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 431 | return -EINVAL; |
Julian Wiedmann | ab29c48 | 2020-09-23 10:36:55 +0200 | [diff] [blame] | 432 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count, |
| 437 | struct qeth_card *card, enum qeth_prot_versions proto) |
| 438 | { |
| 439 | struct qeth_ipato_entry *ipatoe; |
Julian Wiedmann | ab29c48 | 2020-09-23 10:36:55 +0200 | [diff] [blame] | 440 | unsigned int mask_bits; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 441 | u8 addr[16]; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 442 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 443 | |
| 444 | rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits); |
| 445 | if (rc) |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 446 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 447 | |
| 448 | ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL); |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 449 | if (!ipatoe) |
| 450 | return -ENOMEM; |
| 451 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 452 | ipatoe->proto = proto; |
| 453 | memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16); |
| 454 | ipatoe->mask_bits = mask_bits; |
| 455 | |
| 456 | rc = qeth_l3_add_ipato_entry(card, ipatoe); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 457 | if (rc) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 458 | kfree(ipatoe); |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 459 | |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 460 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev, |
| 464 | struct device_attribute *attr, const char *buf, size_t count) |
| 465 | { |
| 466 | struct qeth_card *card = dev_get_drvdata(dev); |
| 467 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 468 | return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4); |
| 469 | } |
| 470 | |
| 471 | static QETH_DEVICE_ATTR(ipato_add4, add4, 0644, |
| 472 | qeth_l3_dev_ipato_add4_show, |
| 473 | qeth_l3_dev_ipato_add4_store); |
| 474 | |
| 475 | static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count, |
| 476 | struct qeth_card *card, enum qeth_prot_versions proto) |
| 477 | { |
Julian Wiedmann | ab29c48 | 2020-09-23 10:36:55 +0200 | [diff] [blame] | 478 | unsigned int mask_bits; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 479 | u8 addr[16]; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 480 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 481 | |
| 482 | rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 483 | if (!rc) |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 484 | rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 485 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev, |
| 489 | struct device_attribute *attr, const char *buf, size_t count) |
| 490 | { |
| 491 | struct qeth_card *card = dev_get_drvdata(dev); |
| 492 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 493 | return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4); |
| 494 | } |
| 495 | |
| 496 | static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL, |
| 497 | qeth_l3_dev_ipato_del4_store); |
| 498 | |
| 499 | static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev, |
| 500 | struct device_attribute *attr, char *buf) |
| 501 | { |
| 502 | struct qeth_card *card = dev_get_drvdata(dev); |
| 503 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 504 | return sprintf(buf, "%i\n", card->ipato.invert6? 1:0); |
| 505 | } |
| 506 | |
| 507 | static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev, |
| 508 | struct device_attribute *attr, const char *buf, size_t count) |
| 509 | { |
| 510 | struct qeth_card *card = dev_get_drvdata(dev); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 511 | bool invert; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 512 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 513 | |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 514 | mutex_lock(&card->ip_lock); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 515 | if (sysfs_streq(buf, "toggle")) { |
| 516 | invert = !card->ipato.invert6; |
| 517 | } else if (kstrtobool(buf, &invert)) { |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 518 | rc = -EINVAL; |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 519 | goto out; |
| 520 | } |
| 521 | |
| 522 | if (card->ipato.invert6 != invert) { |
| 523 | card->ipato.invert6 = invert; |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 524 | qeth_l3_update_ipato(card); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 525 | } |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 526 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 527 | out: |
Julian Wiedmann | d6e6426 | 2020-09-23 10:36:53 +0200 | [diff] [blame] | 528 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 529 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644, |
| 533 | qeth_l3_dev_ipato_invert6_show, |
| 534 | qeth_l3_dev_ipato_invert6_store); |
| 535 | |
| 536 | |
| 537 | static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev, |
| 538 | struct device_attribute *attr, char *buf) |
| 539 | { |
| 540 | struct qeth_card *card = dev_get_drvdata(dev); |
| 541 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 542 | return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6); |
| 543 | } |
| 544 | |
| 545 | static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev, |
| 546 | struct device_attribute *attr, const char *buf, size_t count) |
| 547 | { |
| 548 | struct qeth_card *card = dev_get_drvdata(dev); |
| 549 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 550 | return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6); |
| 551 | } |
| 552 | |
| 553 | static QETH_DEVICE_ATTR(ipato_add6, add6, 0644, |
| 554 | qeth_l3_dev_ipato_add6_show, |
| 555 | qeth_l3_dev_ipato_add6_store); |
| 556 | |
| 557 | static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev, |
| 558 | struct device_attribute *attr, const char *buf, size_t count) |
| 559 | { |
| 560 | struct qeth_card *card = dev_get_drvdata(dev); |
| 561 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 562 | return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6); |
| 563 | } |
| 564 | |
| 565 | static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL, |
| 566 | qeth_l3_dev_ipato_del6_store); |
| 567 | |
| 568 | static struct attribute *qeth_ipato_device_attrs[] = { |
| 569 | &dev_attr_ipato_enable.attr, |
| 570 | &dev_attr_ipato_invert4.attr, |
| 571 | &dev_attr_ipato_add4.attr, |
| 572 | &dev_attr_ipato_del4.attr, |
| 573 | &dev_attr_ipato_invert6.attr, |
| 574 | &dev_attr_ipato_add6.attr, |
| 575 | &dev_attr_ipato_del6.attr, |
| 576 | NULL, |
| 577 | }; |
| 578 | |
Arvind Yadav | cfe9a04 | 2017-07-19 12:39:14 +0530 | [diff] [blame] | 579 | static const struct attribute_group qeth_device_ipato_group = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 580 | .name = "ipa_takeover", |
| 581 | .attrs = qeth_ipato_device_attrs, |
| 582 | }; |
| 583 | |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 584 | static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf, |
| 585 | enum qeth_prot_versions proto, |
| 586 | enum qeth_ip_types type) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 587 | { |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 588 | struct qeth_card *card = dev_get_drvdata(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 589 | struct qeth_ipaddr *ipaddr; |
Ursula Braun | e48b9ea | 2017-01-12 15:48:43 +0100 | [diff] [blame] | 590 | int str_len = 0; |
Ursula Braun | e48b9ea | 2017-01-12 15:48:43 +0100 | [diff] [blame] | 591 | int i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 592 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 593 | mutex_lock(&card->ip_lock); |
Ursula Braun | e48b9ea | 2017-01-12 15:48:43 +0100 | [diff] [blame] | 594 | hash_for_each(card->ip_htable, i, ipaddr, hnode) { |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 595 | char addr_str[40]; |
| 596 | int entry_len; |
| 597 | |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 598 | if (ipaddr->proto != proto || ipaddr->type != type) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 599 | continue; |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 600 | |
| 601 | entry_len = qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u, |
| 602 | addr_str); |
| 603 | if (entry_len < 0) |
| 604 | continue; |
| 605 | |
| 606 | /* Enough room to format %addr\n into null terminated page? */ |
| 607 | if (entry_len + 1 > PAGE_SIZE - str_len - 1) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 608 | break; |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 609 | |
| 610 | entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n", |
| 611 | addr_str); |
| 612 | str_len += entry_len; |
| 613 | buf += entry_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 614 | } |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 615 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 616 | |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 617 | return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev, |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 621 | struct device_attribute *attr, |
| 622 | char *buf) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 623 | { |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 624 | return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4, |
| 625 | QETH_IP_TYPE_VIPA); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 626 | } |
| 627 | |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 628 | static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add, |
| 629 | size_t count, enum qeth_prot_versions proto) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 630 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 631 | struct qeth_card *card = dev_get_drvdata(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 632 | u8 addr[16] = {0, }; |
| 633 | int rc; |
| 634 | |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 635 | rc = qeth_l3_string_to_ipaddr(buf, proto, addr); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 636 | if (!rc) |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 637 | rc = qeth_l3_modify_rxip_vipa(card, add, addr, |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 638 | QETH_IP_TYPE_VIPA, proto); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 639 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev, |
| 643 | struct device_attribute *attr, const char *buf, size_t count) |
| 644 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 645 | return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static QETH_DEVICE_ATTR(vipa_add4, add4, 0644, |
| 649 | qeth_l3_dev_vipa_add4_show, |
| 650 | qeth_l3_dev_vipa_add4_store); |
| 651 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 652 | static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev, |
| 653 | struct device_attribute *attr, const char *buf, size_t count) |
| 654 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 655 | return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL, |
| 659 | qeth_l3_dev_vipa_del4_store); |
| 660 | |
| 661 | static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev, |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 662 | struct device_attribute *attr, |
| 663 | char *buf) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 664 | { |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 665 | return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6, |
| 666 | QETH_IP_TYPE_VIPA); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev, |
| 670 | struct device_attribute *attr, const char *buf, size_t count) |
| 671 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 672 | return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static QETH_DEVICE_ATTR(vipa_add6, add6, 0644, |
| 676 | qeth_l3_dev_vipa_add6_show, |
| 677 | qeth_l3_dev_vipa_add6_store); |
| 678 | |
| 679 | static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev, |
| 680 | struct device_attribute *attr, const char *buf, size_t count) |
| 681 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 682 | return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL, |
| 686 | qeth_l3_dev_vipa_del6_store); |
| 687 | |
| 688 | static struct attribute *qeth_vipa_device_attrs[] = { |
| 689 | &dev_attr_vipa_add4.attr, |
| 690 | &dev_attr_vipa_del4.attr, |
| 691 | &dev_attr_vipa_add6.attr, |
| 692 | &dev_attr_vipa_del6.attr, |
| 693 | NULL, |
| 694 | }; |
| 695 | |
Arvind Yadav | cfe9a04 | 2017-07-19 12:39:14 +0530 | [diff] [blame] | 696 | static const struct attribute_group qeth_device_vipa_group = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 697 | .name = "vipa", |
| 698 | .attrs = qeth_vipa_device_attrs, |
| 699 | }; |
| 700 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 701 | static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev, |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 702 | struct device_attribute *attr, |
| 703 | char *buf) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 704 | { |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 705 | return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4, |
| 706 | QETH_IP_TYPE_RXIP); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto, |
| 710 | u8 *addr) |
| 711 | { |
Kittipon Meesompop | aa9bea0 | 2017-08-15 17:02:48 +0200 | [diff] [blame] | 712 | __be32 ipv4_addr; |
| 713 | struct in6_addr ipv6_addr; |
| 714 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 715 | if (qeth_l3_string_to_ipaddr(buf, proto, addr)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 716 | return -EINVAL; |
| 717 | } |
Kittipon Meesompop | aa9bea0 | 2017-08-15 17:02:48 +0200 | [diff] [blame] | 718 | if (proto == QETH_PROT_IPV4) { |
| 719 | memcpy(&ipv4_addr, addr, sizeof(ipv4_addr)); |
| 720 | if (ipv4_is_multicast(ipv4_addr)) { |
| 721 | QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n"); |
| 722 | return -EINVAL; |
| 723 | } |
| 724 | } else if (proto == QETH_PROT_IPV6) { |
| 725 | memcpy(&ipv6_addr, addr, sizeof(ipv6_addr)); |
| 726 | if (ipv6_addr_is_multicast(&ipv6_addr)) { |
| 727 | QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n"); |
| 728 | return -EINVAL; |
| 729 | } |
| 730 | } |
| 731 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 732 | return 0; |
| 733 | } |
| 734 | |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 735 | static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add, |
| 736 | size_t count, enum qeth_prot_versions proto) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 737 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 738 | struct qeth_card *card = dev_get_drvdata(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 739 | u8 addr[16] = {0, }; |
| 740 | int rc; |
| 741 | |
| 742 | rc = qeth_l3_parse_rxipe(buf, proto, addr); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 743 | if (!rc) |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 744 | rc = qeth_l3_modify_rxip_vipa(card, add, addr, |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 745 | QETH_IP_TYPE_RXIP, proto); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 746 | return rc ? rc : count; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev, |
| 750 | struct device_attribute *attr, const char *buf, size_t count) |
| 751 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 752 | return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | static QETH_DEVICE_ATTR(rxip_add4, add4, 0644, |
| 756 | qeth_l3_dev_rxip_add4_show, |
| 757 | qeth_l3_dev_rxip_add4_store); |
| 758 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 759 | static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev, |
| 760 | struct device_attribute *attr, const char *buf, size_t count) |
| 761 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 762 | return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL, |
| 766 | qeth_l3_dev_rxip_del4_store); |
| 767 | |
| 768 | static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev, |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 769 | struct device_attribute *attr, |
| 770 | char *buf) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 771 | { |
Julian Wiedmann | d2073ef | 2017-12-27 17:44:29 +0100 | [diff] [blame] | 772 | return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6, |
| 773 | QETH_IP_TYPE_RXIP); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev, |
| 777 | struct device_attribute *attr, const char *buf, size_t count) |
| 778 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 779 | return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | static QETH_DEVICE_ATTR(rxip_add6, add6, 0644, |
| 783 | qeth_l3_dev_rxip_add6_show, |
| 784 | qeth_l3_dev_rxip_add6_store); |
| 785 | |
| 786 | static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev, |
| 787 | struct device_attribute *attr, const char *buf, size_t count) |
| 788 | { |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 789 | return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL, |
| 793 | qeth_l3_dev_rxip_del6_store); |
| 794 | |
| 795 | static struct attribute *qeth_rxip_device_attrs[] = { |
| 796 | &dev_attr_rxip_add4.attr, |
| 797 | &dev_attr_rxip_del4.attr, |
| 798 | &dev_attr_rxip_add6.attr, |
| 799 | &dev_attr_rxip_del6.attr, |
| 800 | NULL, |
| 801 | }; |
| 802 | |
Arvind Yadav | cfe9a04 | 2017-07-19 12:39:14 +0530 | [diff] [blame] | 803 | static const struct attribute_group qeth_device_rxip_group = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 804 | .name = "rxip", |
| 805 | .attrs = qeth_rxip_device_attrs, |
| 806 | }; |
| 807 | |
Julian Wiedmann | ab25a50 | 2017-09-18 21:18:19 +0200 | [diff] [blame] | 808 | static const struct attribute_group *qeth_l3_only_attr_groups[] = { |
| 809 | &qeth_l3_device_attr_group, |
| 810 | &qeth_device_ipato_group, |
| 811 | &qeth_device_vipa_group, |
| 812 | &qeth_device_rxip_group, |
| 813 | NULL, |
| 814 | }; |
| 815 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 816 | int qeth_l3_create_device_attributes(struct device *dev) |
| 817 | { |
Julian Wiedmann | ab25a50 | 2017-09-18 21:18:19 +0200 | [diff] [blame] | 818 | return sysfs_create_groups(&dev->kobj, qeth_l3_only_attr_groups); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | void qeth_l3_remove_device_attributes(struct device *dev) |
| 822 | { |
Julian Wiedmann | ab25a50 | 2017-09-18 21:18:19 +0200 | [diff] [blame] | 823 | sysfs_remove_groups(&dev->kobj, qeth_l3_only_attr_groups); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 824 | } |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 825 | |
| 826 | const struct attribute_group *qeth_l3_attr_groups[] = { |
| 827 | &qeth_device_attr_group, |
| 828 | &qeth_device_blkt_group, |
Julian Wiedmann | ab25a50 | 2017-09-18 21:18:19 +0200 | [diff] [blame] | 829 | /* l3 specific, see qeth_l3_only_attr_groups: */ |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 830 | &qeth_l3_device_attr_group, |
| 831 | &qeth_device_ipato_group, |
| 832 | &qeth_device_vipa_group, |
| 833 | &qeth_device_rxip_group, |
Julian Wiedmann | ab25a50 | 2017-09-18 21:18:19 +0200 | [diff] [blame] | 834 | NULL, |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 835 | }; |