blob: c6204520114e6c264ea88654f324885ad4a2abb2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Frank Blaschka4a71df52008-02-15 09:19:42 +01002/*
Frank Blaschka4a71df52008-02-15 09:19:42 +01003 * 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 Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000011#include <asm/ebcdic.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020012#include <linux/hashtable.h>
Julian Wiedmann556fd272017-12-20 20:11:09 +010013#include <linux/inet.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010014#include "qeth_l3.h"
15
16#define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
17struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
18
Julian Wiedmann556fd272017-12-20 20:11:09 +010019static 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 Blaschka4a71df52008-02-15 09:19:42 +010030static 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
58static 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
63 if (!card)
64 return -EINVAL;
65
66 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
67}
68
69static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
70 struct qeth_routing_info *route, enum qeth_prot_versions prot,
71 const char *buf, size_t count)
72{
73 enum qeth_routing_types old_route_type = route->type;
Frank Blaschkac4949f02010-05-11 19:34:47 +000074 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +010075
Frank Blaschkac4949f02010-05-11 19:34:47 +000076 mutex_lock(&card->conf_mutex);
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010077 if (sysfs_streq(buf, "no_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010078 route->type = NO_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010079 } else if (sysfs_streq(buf, "primary_connector")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010080 route->type = PRIMARY_CONNECTOR;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010081 } else if (sysfs_streq(buf, "secondary_connector")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010082 route->type = SECONDARY_CONNECTOR;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010083 } else if (sysfs_streq(buf, "primary_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010084 route->type = PRIMARY_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010085 } else if (sysfs_streq(buf, "secondary_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010086 route->type = SECONDARY_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010087 } else if (sysfs_streq(buf, "multicast_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010088 route->type = MULTICAST_ROUTER;
89 } else {
Frank Blaschkac4949f02010-05-11 19:34:47 +000090 rc = -EINVAL;
91 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +010092 }
Eugene Crosserc3521252015-01-16 14:05:47 +010093 if (qeth_card_hw_is_reachable(card) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010094 (old_route_type != route->type)) {
95 if (prot == QETH_PROT_IPV4)
96 rc = qeth_l3_setrouting_v4(card);
97 else if (prot == QETH_PROT_IPV6)
98 rc = qeth_l3_setrouting_v6(card);
99 }
Frank Blaschkac4949f02010-05-11 19:34:47 +0000100out:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000101 if (rc)
102 route->type = old_route_type;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000103 mutex_unlock(&card->conf_mutex);
104 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100105}
106
107static ssize_t qeth_l3_dev_route4_store(struct device *dev,
108 struct device_attribute *attr, const char *buf, size_t count)
109{
110 struct qeth_card *card = dev_get_drvdata(dev);
111
112 if (!card)
113 return -EINVAL;
114
115 return qeth_l3_dev_route_store(card, &card->options.route4,
116 QETH_PROT_IPV4, buf, count);
117}
118
119static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
120 qeth_l3_dev_route4_store);
121
122static ssize_t qeth_l3_dev_route6_show(struct device *dev,
123 struct device_attribute *attr, char *buf)
124{
125 struct qeth_card *card = dev_get_drvdata(dev);
126
127 if (!card)
128 return -EINVAL;
129
Frank Blaschka4a71df52008-02-15 09:19:42 +0100130 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
131}
132
133static ssize_t qeth_l3_dev_route6_store(struct device *dev,
134 struct device_attribute *attr, const char *buf, size_t count)
135{
136 struct qeth_card *card = dev_get_drvdata(dev);
137
138 if (!card)
139 return -EINVAL;
140
Frank Blaschka4a71df52008-02-15 09:19:42 +0100141 return qeth_l3_dev_route_store(card, &card->options.route6,
142 QETH_PROT_IPV6, buf, count);
143}
144
145static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
146 qeth_l3_dev_route6_store);
147
148static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
149 struct device_attribute *attr, char *buf)
150{
151 struct qeth_card *card = dev_get_drvdata(dev);
152
153 if (!card)
154 return -EINVAL;
155
156 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
157}
158
159static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
160 struct device_attribute *attr, const char *buf, size_t count)
161{
162 struct qeth_card *card = dev_get_drvdata(dev);
163 char *tmp;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000164 int i, rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100165
166 if (!card)
167 return -EINVAL;
168
Frank Blaschkac4949f02010-05-11 19:34:47 +0000169 mutex_lock(&card->conf_mutex);
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100170 if (card->state != CARD_STATE_DOWN) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000171 rc = -EPERM;
172 goto out;
173 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100174
175 i = simple_strtoul(buf, &tmp, 16);
176 if ((i == 0) || (i == 1))
177 card->options.fake_broadcast = i;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000178 else
179 rc = -EINVAL;
180out:
181 mutex_unlock(&card->conf_mutex);
182 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100183}
184
185static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
186 qeth_l3_dev_fake_broadcast_store);
187
Ursula Braun76b11f82010-01-11 02:50:50 +0000188static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
189 struct device_attribute *attr, char *buf)
190{
191 struct qeth_card *card = dev_get_drvdata(dev);
192
193 if (!card)
194 return -EINVAL;
195
196 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
197}
198
199static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
200 struct device_attribute *attr, const char *buf, size_t count)
201{
202 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000203 int rc = 0;
Ursula Braun76b11f82010-01-11 02:50:50 +0000204 unsigned long i;
205
206 if (!card)
207 return -EINVAL;
208
Julian Wiedmann379ac992019-04-25 18:25:57 +0200209 if (!IS_IQD(card))
Ursula Braun76b11f82010-01-11 02:50:50 +0000210 return -EPERM;
Frank Blaschkab3332932011-08-08 01:33:59 +0000211 if (card->options.cq == QETH_CQ_ENABLED)
212 return -EPERM;
Ursula Braun76b11f82010-01-11 02:50:50 +0000213
Frank Blaschkac4949f02010-05-11 19:34:47 +0000214 mutex_lock(&card->conf_mutex);
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100215 if (card->state != CARD_STATE_DOWN) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000216 rc = -EPERM;
217 goto out;
218 }
Ursula Braun76b11f82010-01-11 02:50:50 +0000219
Jingoo Han01787222013-07-22 10:18:15 +0900220 rc = kstrtoul(buf, 16, &i);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000221 if (rc) {
222 rc = -EINVAL;
223 goto out;
224 }
Ursula Braun76b11f82010-01-11 02:50:50 +0000225 switch (i) {
226 case 0:
227 card->options.sniffer = i;
228 break;
229 case 1:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000230 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
Julian Wiedmann1917b472019-10-23 10:03:23 +0200231 if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) {
Ursula Braun76b11f82010-01-11 02:50:50 +0000232 card->options.sniffer = i;
233 if (card->qdio.init_pool.buf_count !=
234 QETH_IN_BUF_COUNT_MAX)
235 qeth_realloc_buffer_pool(card,
236 QETH_IN_BUF_COUNT_MAX);
Ursula Braun76b11f82010-01-11 02:50:50 +0000237 } else
Frank Blaschkac4949f02010-05-11 19:34:47 +0000238 rc = -EPERM;
Ursula Braun6cc31d02011-11-15 02:31:12 +0000239 break;
240 default:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000241 rc = -EINVAL;
Ursula Braun76b11f82010-01-11 02:50:50 +0000242 }
Frank Blaschkac4949f02010-05-11 19:34:47 +0000243out:
244 mutex_unlock(&card->conf_mutex);
245 return rc ? rc : count;
Ursula Braun76b11f82010-01-11 02:50:50 +0000246}
247
248static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
249 qeth_l3_dev_sniffer_store);
250
Frank Blaschkab3332932011-08-08 01:33:59 +0000251
252static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
253 struct device_attribute *attr, char *buf)
254{
255 struct qeth_card *card = dev_get_drvdata(dev);
256 char tmp_hsuid[9];
257
258 if (!card)
259 return -EINVAL;
260
Julian Wiedmann379ac992019-04-25 18:25:57 +0200261 if (!IS_IQD(card))
Frank Blaschkab3332932011-08-08 01:33:59 +0000262 return -EPERM;
263
Frank Blaschkab3332932011-08-08 01:33:59 +0000264 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
265 EBCASC(tmp_hsuid, 8);
266 return sprintf(buf, "%s\n", tmp_hsuid);
267}
268
269static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
270 struct device_attribute *attr, const char *buf, size_t count)
271{
272 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschkab3332932011-08-08 01:33:59 +0000273 char *tmp;
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100274 int rc;
Frank Blaschkab3332932011-08-08 01:33:59 +0000275
276 if (!card)
277 return -EINVAL;
278
Julian Wiedmann379ac992019-04-25 18:25:57 +0200279 if (!IS_IQD(card))
Frank Blaschkab3332932011-08-08 01:33:59 +0000280 return -EPERM;
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100281 if (card->state != CARD_STATE_DOWN)
Frank Blaschkab3332932011-08-08 01:33:59 +0000282 return -EPERM;
283 if (card->options.sniffer)
284 return -EPERM;
285 if (card->options.cq == QETH_CQ_NOTAVAILABLE)
286 return -EPERM;
287
288 tmp = strsep((char **)&buf, "\n");
289 if (strlen(tmp) > 8)
290 return -EINVAL;
291
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100292 if (card->options.hsuid[0])
Frank Blaschkab3332932011-08-08 01:33:59 +0000293 /* delete old ip address */
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100294 qeth_l3_modify_hsuid(card, false);
Frank Blaschkab3332932011-08-08 01:33:59 +0000295
296 if (strlen(tmp) == 0) {
297 /* delete ip address only */
298 card->options.hsuid[0] = '\0';
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200299 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschkab3332932011-08-08 01:33:59 +0000300 qeth_configure_cq(card, QETH_CQ_DISABLED);
301 return count;
302 }
303
304 if (qeth_configure_cq(card, QETH_CQ_ENABLED))
305 return -EPERM;
306
Kees Cook096a8aa2013-07-03 15:04:55 -0700307 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
308 "%-8s", tmp);
Frank Blaschkab3332932011-08-08 01:33:59 +0000309 ASCEBC(card->options.hsuid, 8);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200310 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschkab3332932011-08-08 01:33:59 +0000311
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100312 rc = qeth_l3_modify_hsuid(card, true);
Frank Blaschkab3332932011-08-08 01:33:59 +0000313
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100314 return rc ? rc : count;
Frank Blaschkab3332932011-08-08 01:33:59 +0000315}
316
317static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
318 qeth_l3_dev_hsuid_store);
319
320
Frank Blaschka4a71df52008-02-15 09:19:42 +0100321static struct attribute *qeth_l3_device_attrs[] = {
322 &dev_attr_route4.attr,
323 &dev_attr_route6.attr,
324 &dev_attr_fake_broadcast.attr,
Ursula Braun76b11f82010-01-11 02:50:50 +0000325 &dev_attr_sniffer.attr,
Frank Blaschkab3332932011-08-08 01:33:59 +0000326 &dev_attr_hsuid.attr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327 NULL,
328};
329
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530330static const struct attribute_group qeth_l3_device_attr_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100331 .attrs = qeth_l3_device_attrs,
332};
333
334static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
335 struct device_attribute *attr, char *buf)
336{
337 struct qeth_card *card = dev_get_drvdata(dev);
338
339 if (!card)
340 return -EINVAL;
341
342 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
343}
344
345static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
346 struct device_attribute *attr, const char *buf, size_t count)
347{
348 struct qeth_card *card = dev_get_drvdata(dev);
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100349 bool enable;
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100350 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100351
352 if (!card)
353 return -EINVAL;
354
Frank Blaschkac4949f02010-05-11 19:34:47 +0000355 mutex_lock(&card->conf_mutex);
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100356 if (card->state != CARD_STATE_DOWN) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000357 rc = -EPERM;
358 goto out;
359 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100360
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100361 if (sysfs_streq(buf, "toggle")) {
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100362 enable = !card->ipato.enabled;
363 } else if (kstrtobool(buf, &enable)) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000364 rc = -EINVAL;
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100365 goto out;
366 }
367
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100368 if (card->ipato.enabled != enable) {
369 card->ipato.enabled = enable;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100370 mutex_lock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100371 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100372 mutex_unlock(&card->ip_lock);
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100373 }
Frank Blaschkac4949f02010-05-11 19:34:47 +0000374out:
375 mutex_unlock(&card->conf_mutex);
376 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100377}
378
379static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
380 qeth_l3_dev_ipato_enable_show,
381 qeth_l3_dev_ipato_enable_store);
382
383static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
384 struct device_attribute *attr, char *buf)
385{
386 struct qeth_card *card = dev_get_drvdata(dev);
387
388 if (!card)
389 return -EINVAL;
390
391 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
392}
393
394static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
395 struct device_attribute *attr,
396 const char *buf, size_t count)
397{
398 struct qeth_card *card = dev_get_drvdata(dev);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100399 bool invert;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000400 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401
402 if (!card)
403 return -EINVAL;
404
Frank Blaschkac4949f02010-05-11 19:34:47 +0000405 mutex_lock(&card->conf_mutex);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100406 if (sysfs_streq(buf, "toggle")) {
407 invert = !card->ipato.invert4;
408 } else if (kstrtobool(buf, &invert)) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000409 rc = -EINVAL;
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100410 goto out;
411 }
412
413 if (card->ipato.invert4 != invert) {
414 card->ipato.invert4 = invert;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100415 mutex_lock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100416 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100417 mutex_unlock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100418 }
419out:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000420 mutex_unlock(&card->conf_mutex);
421 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422}
423
424static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
425 qeth_l3_dev_ipato_invert4_show,
426 qeth_l3_dev_ipato_invert4_store);
427
428static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
429 enum qeth_prot_versions proto)
430{
431 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100432 char addr_str[40];
433 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
434 int i = 0;
435
436 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
437 /* add strlen for "/<mask>\n" */
438 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100439 mutex_lock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
441 if (ipatoe->proto != proto)
442 continue;
443 /* String must not be longer than PAGE_SIZE. So we check if
444 * string length gets near PAGE_SIZE. Then we can savely display
445 * the next IPv6 address (worst case, compared to IPv4) */
446 if ((PAGE_SIZE - i) <= entry_len)
447 break;
448 qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
449 i += snprintf(buf + i, PAGE_SIZE - i,
450 "%s/%i\n", addr_str, ipatoe->mask_bits);
451 }
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100452 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100453 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
454
455 return i;
456}
457
458static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
459 struct device_attribute *attr, char *buf)
460{
461 struct qeth_card *card = dev_get_drvdata(dev);
462
463 if (!card)
464 return -EINVAL;
465
466 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
467}
468
469static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
470 u8 *addr, int *mask_bits)
471{
472 const char *start, *end;
473 char *tmp;
474 char buffer[40] = {0, };
475
476 start = buf;
477 /* get address string */
478 end = strchr(start, '/');
479 if (!end || (end - start >= 40)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100480 return -EINVAL;
481 }
482 strncpy(buffer, start, end - start);
483 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100484 return -EINVAL;
485 }
486 start = end + 1;
487 *mask_bits = simple_strtoul(start, &tmp, 10);
488 if (!strlen(start) ||
489 (tmp == start) ||
490 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100491 return -EINVAL;
492 }
493 return 0;
494}
495
496static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
497 struct qeth_card *card, enum qeth_prot_versions proto)
498{
499 struct qeth_ipato_entry *ipatoe;
500 u8 addr[16];
501 int mask_bits;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000502 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100503
Frank Blaschkac4949f02010-05-11 19:34:47 +0000504 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100505 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
506 if (rc)
Frank Blaschkac4949f02010-05-11 19:34:47 +0000507 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100508
509 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
510 if (!ipatoe) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000511 rc = -ENOMEM;
512 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100513 }
514 ipatoe->proto = proto;
515 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
516 ipatoe->mask_bits = mask_bits;
517
518 rc = qeth_l3_add_ipato_entry(card, ipatoe);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000519 if (rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100520 kfree(ipatoe);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000521out:
522 mutex_unlock(&card->conf_mutex);
523 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100524}
525
526static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
527 struct device_attribute *attr, const char *buf, size_t count)
528{
529 struct qeth_card *card = dev_get_drvdata(dev);
530
531 if (!card)
532 return -EINVAL;
533
534 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
535}
536
537static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
538 qeth_l3_dev_ipato_add4_show,
539 qeth_l3_dev_ipato_add4_store);
540
541static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
542 struct qeth_card *card, enum qeth_prot_versions proto)
543{
544 u8 addr[16];
545 int mask_bits;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000546 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547
Frank Blaschkac4949f02010-05-11 19:34:47 +0000548 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100549 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000550 if (!rc)
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100551 rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000552 mutex_unlock(&card->conf_mutex);
553 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100554}
555
556static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
557 struct device_attribute *attr, const char *buf, size_t count)
558{
559 struct qeth_card *card = dev_get_drvdata(dev);
560
561 if (!card)
562 return -EINVAL;
563
564 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
565}
566
567static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
568 qeth_l3_dev_ipato_del4_store);
569
570static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
571 struct device_attribute *attr, char *buf)
572{
573 struct qeth_card *card = dev_get_drvdata(dev);
574
575 if (!card)
576 return -EINVAL;
577
578 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
579}
580
581static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
582 struct device_attribute *attr, const char *buf, size_t count)
583{
584 struct qeth_card *card = dev_get_drvdata(dev);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100585 bool invert;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000586 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587
588 if (!card)
589 return -EINVAL;
590
Frank Blaschkac4949f02010-05-11 19:34:47 +0000591 mutex_lock(&card->conf_mutex);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100592 if (sysfs_streq(buf, "toggle")) {
593 invert = !card->ipato.invert6;
594 } else if (kstrtobool(buf, &invert)) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000595 rc = -EINVAL;
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100596 goto out;
597 }
598
599 if (card->ipato.invert6 != invert) {
600 card->ipato.invert6 = invert;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100601 mutex_lock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100602 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100603 mutex_unlock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100604 }
605out:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000606 mutex_unlock(&card->conf_mutex);
607 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100608}
609
610static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
611 qeth_l3_dev_ipato_invert6_show,
612 qeth_l3_dev_ipato_invert6_store);
613
614
615static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
616 struct device_attribute *attr, char *buf)
617{
618 struct qeth_card *card = dev_get_drvdata(dev);
619
620 if (!card)
621 return -EINVAL;
622
623 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
624}
625
626static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
627 struct device_attribute *attr, const char *buf, size_t count)
628{
629 struct qeth_card *card = dev_get_drvdata(dev);
630
631 if (!card)
632 return -EINVAL;
633
634 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
635}
636
637static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
638 qeth_l3_dev_ipato_add6_show,
639 qeth_l3_dev_ipato_add6_store);
640
641static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
642 struct device_attribute *attr, const char *buf, size_t count)
643{
644 struct qeth_card *card = dev_get_drvdata(dev);
645
646 if (!card)
647 return -EINVAL;
648
649 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
650}
651
652static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
653 qeth_l3_dev_ipato_del6_store);
654
655static struct attribute *qeth_ipato_device_attrs[] = {
656 &dev_attr_ipato_enable.attr,
657 &dev_attr_ipato_invert4.attr,
658 &dev_attr_ipato_add4.attr,
659 &dev_attr_ipato_del4.attr,
660 &dev_attr_ipato_invert6.attr,
661 &dev_attr_ipato_add6.attr,
662 &dev_attr_ipato_del6.attr,
663 NULL,
664};
665
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530666static const struct attribute_group qeth_device_ipato_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100667 .name = "ipa_takeover",
668 .attrs = qeth_ipato_device_attrs,
669};
670
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100671static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
672 enum qeth_prot_versions proto,
673 enum qeth_ip_types type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100675 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100676 struct qeth_ipaddr *ipaddr;
677 char addr_str[40];
Ursula Braune48b9ea2017-01-12 15:48:43 +0100678 int str_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100679 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
Ursula Braune48b9ea2017-01-12 15:48:43 +0100680 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100682 if (!card)
683 return -EINVAL;
684
Frank Blaschka4a71df52008-02-15 09:19:42 +0100685 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
686 entry_len += 2; /* \n + terminator */
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100687 mutex_lock(&card->ip_lock);
Ursula Braune48b9ea2017-01-12 15:48:43 +0100688 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100689 if (ipaddr->proto != proto || ipaddr->type != type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100690 continue;
691 /* String must not be longer than PAGE_SIZE. So we check if
692 * string length gets near PAGE_SIZE. Then we can savely display
693 * the next IPv6 address (worst case, compared to IPv4) */
Ursula Braune48b9ea2017-01-12 15:48:43 +0100694 if ((PAGE_SIZE - str_len) <= entry_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100695 break;
696 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
697 addr_str);
Ursula Braune48b9ea2017-01-12 15:48:43 +0100698 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "%s\n",
699 addr_str);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700 }
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100701 mutex_unlock(&card->ip_lock);
Ursula Braune48b9ea2017-01-12 15:48:43 +0100702 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100703
Ursula Braune48b9ea2017-01-12 15:48:43 +0100704 return str_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100705}
706
707static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100708 struct device_attribute *attr,
709 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100710{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100711 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
712 QETH_IP_TYPE_VIPA);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100713}
714
715static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
716 u8 *addr)
717{
718 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100719 return -EINVAL;
720 }
721 return 0;
722}
723
724static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
725 struct qeth_card *card, enum qeth_prot_versions proto)
726{
727 u8 addr[16] = {0, };
728 int rc;
729
Frank Blaschkac4949f02010-05-11 19:34:47 +0000730 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731 rc = qeth_l3_parse_vipae(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000732 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100733 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
734 QETH_IP_TYPE_VIPA, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000735 mutex_unlock(&card->conf_mutex);
736 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100737}
738
739static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
740 struct device_attribute *attr, const char *buf, size_t count)
741{
742 struct qeth_card *card = dev_get_drvdata(dev);
743
744 if (!card)
745 return -EINVAL;
746
747 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
748}
749
750static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
751 qeth_l3_dev_vipa_add4_show,
752 qeth_l3_dev_vipa_add4_store);
753
754static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
755 struct qeth_card *card, enum qeth_prot_versions proto)
756{
757 u8 addr[16];
758 int rc;
759
Frank Blaschkac4949f02010-05-11 19:34:47 +0000760 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100761 rc = qeth_l3_parse_vipae(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000762 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100763 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
764 QETH_IP_TYPE_VIPA, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000765 mutex_unlock(&card->conf_mutex);
766 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100767}
768
769static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
770 struct device_attribute *attr, const char *buf, size_t count)
771{
772 struct qeth_card *card = dev_get_drvdata(dev);
773
774 if (!card)
775 return -EINVAL;
776
777 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
778}
779
780static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
781 qeth_l3_dev_vipa_del4_store);
782
783static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100784 struct device_attribute *attr,
785 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100787 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
788 QETH_IP_TYPE_VIPA);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100789}
790
791static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
792 struct device_attribute *attr, const char *buf, size_t count)
793{
794 struct qeth_card *card = dev_get_drvdata(dev);
795
796 if (!card)
797 return -EINVAL;
798
799 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
800}
801
802static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
803 qeth_l3_dev_vipa_add6_show,
804 qeth_l3_dev_vipa_add6_store);
805
806static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
807 struct device_attribute *attr, const char *buf, size_t count)
808{
809 struct qeth_card *card = dev_get_drvdata(dev);
810
811 if (!card)
812 return -EINVAL;
813
814 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
815}
816
817static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
818 qeth_l3_dev_vipa_del6_store);
819
820static struct attribute *qeth_vipa_device_attrs[] = {
821 &dev_attr_vipa_add4.attr,
822 &dev_attr_vipa_del4.attr,
823 &dev_attr_vipa_add6.attr,
824 &dev_attr_vipa_del6.attr,
825 NULL,
826};
827
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530828static const struct attribute_group qeth_device_vipa_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829 .name = "vipa",
830 .attrs = qeth_vipa_device_attrs,
831};
832
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100834 struct device_attribute *attr,
835 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100837 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
838 QETH_IP_TYPE_RXIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100839}
840
841static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
842 u8 *addr)
843{
Kittipon Meesompopaa9bea02017-08-15 17:02:48 +0200844 __be32 ipv4_addr;
845 struct in6_addr ipv6_addr;
846
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 return -EINVAL;
849 }
Kittipon Meesompopaa9bea02017-08-15 17:02:48 +0200850 if (proto == QETH_PROT_IPV4) {
851 memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
852 if (ipv4_is_multicast(ipv4_addr)) {
853 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
854 return -EINVAL;
855 }
856 } else if (proto == QETH_PROT_IPV6) {
857 memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
858 if (ipv6_addr_is_multicast(&ipv6_addr)) {
859 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
860 return -EINVAL;
861 }
862 }
863
Frank Blaschka4a71df52008-02-15 09:19:42 +0100864 return 0;
865}
866
867static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
868 struct qeth_card *card, enum qeth_prot_versions proto)
869{
870 u8 addr[16] = {0, };
871 int rc;
872
Frank Blaschkac4949f02010-05-11 19:34:47 +0000873 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100874 rc = qeth_l3_parse_rxipe(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000875 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100876 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
877 QETH_IP_TYPE_RXIP, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000878 mutex_unlock(&card->conf_mutex);
879 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880}
881
882static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
883 struct device_attribute *attr, const char *buf, size_t count)
884{
885 struct qeth_card *card = dev_get_drvdata(dev);
886
887 if (!card)
888 return -EINVAL;
889
890 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
891}
892
893static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
894 qeth_l3_dev_rxip_add4_show,
895 qeth_l3_dev_rxip_add4_store);
896
897static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
898 struct qeth_card *card, enum qeth_prot_versions proto)
899{
900 u8 addr[16];
901 int rc;
902
Frank Blaschkac4949f02010-05-11 19:34:47 +0000903 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904 rc = qeth_l3_parse_rxipe(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000905 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100906 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
907 QETH_IP_TYPE_RXIP, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000908 mutex_unlock(&card->conf_mutex);
909 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910}
911
912static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
913 struct device_attribute *attr, const char *buf, size_t count)
914{
915 struct qeth_card *card = dev_get_drvdata(dev);
916
917 if (!card)
918 return -EINVAL;
919
920 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
921}
922
923static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
924 qeth_l3_dev_rxip_del4_store);
925
926static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100927 struct device_attribute *attr,
928 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100930 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
931 QETH_IP_TYPE_RXIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932}
933
934static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
935 struct device_attribute *attr, const char *buf, size_t count)
936{
937 struct qeth_card *card = dev_get_drvdata(dev);
938
939 if (!card)
940 return -EINVAL;
941
942 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
943}
944
945static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
946 qeth_l3_dev_rxip_add6_show,
947 qeth_l3_dev_rxip_add6_store);
948
949static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
950 struct device_attribute *attr, const char *buf, size_t count)
951{
952 struct qeth_card *card = dev_get_drvdata(dev);
953
954 if (!card)
955 return -EINVAL;
956
957 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
958}
959
960static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
961 qeth_l3_dev_rxip_del6_store);
962
963static struct attribute *qeth_rxip_device_attrs[] = {
964 &dev_attr_rxip_add4.attr,
965 &dev_attr_rxip_del4.attr,
966 &dev_attr_rxip_add6.attr,
967 &dev_attr_rxip_del6.attr,
968 NULL,
969};
970
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530971static const struct attribute_group qeth_device_rxip_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972 .name = "rxip",
973 .attrs = qeth_rxip_device_attrs,
974};
975
Julian Wiedmannab25a502017-09-18 21:18:19 +0200976static const struct attribute_group *qeth_l3_only_attr_groups[] = {
977 &qeth_l3_device_attr_group,
978 &qeth_device_ipato_group,
979 &qeth_device_vipa_group,
980 &qeth_device_rxip_group,
981 NULL,
982};
983
Frank Blaschka4a71df52008-02-15 09:19:42 +0100984int qeth_l3_create_device_attributes(struct device *dev)
985{
Julian Wiedmannab25a502017-09-18 21:18:19 +0200986 return sysfs_create_groups(&dev->kobj, qeth_l3_only_attr_groups);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100987}
988
989void qeth_l3_remove_device_attributes(struct device *dev)
990{
Julian Wiedmannab25a502017-09-18 21:18:19 +0200991 sysfs_remove_groups(&dev->kobj, qeth_l3_only_attr_groups);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100992}
Ursula Braun79a04e42017-06-06 14:33:49 +0200993
994const struct attribute_group *qeth_l3_attr_groups[] = {
995 &qeth_device_attr_group,
996 &qeth_device_blkt_group,
Julian Wiedmannab25a502017-09-18 21:18:19 +0200997 /* l3 specific, see qeth_l3_only_attr_groups: */
Ursula Braun79a04e42017-06-06 14:33:49 +0200998 &qeth_l3_device_attr_group,
999 &qeth_device_ipato_group,
1000 &qeth_device_vipa_group,
1001 &qeth_device_rxip_group,
Julian Wiedmannab25a502017-09-18 21:18:19 +02001002 NULL,
Ursula Braun79a04e42017-06-06 14:33:49 +02001003};