blob: aa9f3fc4544762680b02f445773d36ecf922b5d2 [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
Frank Blaschka4a71df52008-02-15 09:19:42 +010063 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
64}
65
66static 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 Blaschkac4949f02010-05-11 19:34:47 +000071 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +010072
Frank Blaschkac4949f02010-05-11 19:34:47 +000073 mutex_lock(&card->conf_mutex);
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010074 if (sysfs_streq(buf, "no_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010075 route->type = NO_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010076 } else if (sysfs_streq(buf, "primary_connector")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010077 route->type = PRIMARY_CONNECTOR;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010078 } else if (sysfs_streq(buf, "secondary_connector")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010079 route->type = SECONDARY_CONNECTOR;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010080 } else if (sysfs_streq(buf, "primary_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010081 route->type = PRIMARY_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010082 } else if (sysfs_streq(buf, "secondary_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010083 route->type = SECONDARY_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010084 } else if (sysfs_streq(buf, "multicast_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010085 route->type = MULTICAST_ROUTER;
86 } else {
Frank Blaschkac4949f02010-05-11 19:34:47 +000087 rc = -EINVAL;
88 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +010089 }
Eugene Crosserc3521252015-01-16 14:05:47 +010090 if (qeth_card_hw_is_reachable(card) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010091 (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 Blaschkac4949f02010-05-11 19:34:47 +000097out:
Stefan Raspl82e2e782013-03-18 20:04:43 +000098 if (rc)
99 route->type = old_route_type;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000100 mutex_unlock(&card->conf_mutex);
101 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100102}
103
104static 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 Blaschka4a71df52008-02-15 09:19:42 +0100109 return qeth_l3_dev_route_store(card, &card->options.route4,
110 QETH_PROT_IPV4, buf, count);
111}
112
113static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
114 qeth_l3_dev_route4_store);
115
116static 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 Blaschka4a71df52008-02-15 09:19:42 +0100121 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
122}
123
124static 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 Blaschka4a71df52008-02-15 09:19:42 +0100129 return qeth_l3_dev_route_store(card, &card->options.route6,
130 QETH_PROT_IPV6, buf, count);
131}
132
133static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
134 qeth_l3_dev_route6_store);
135
136static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
137 struct device_attribute *attr, char *buf)
138{
139 struct qeth_card *card = dev_get_drvdata(dev);
140
Frank Blaschka4a71df52008-02-15 09:19:42 +0100141 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
142}
143
144static ssize_t qeth_l3_dev_fake_broadcast_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);
148 char *tmp;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000149 int i, rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100150
Frank Blaschkac4949f02010-05-11 19:34:47 +0000151 mutex_lock(&card->conf_mutex);
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100152 if (card->state != CARD_STATE_DOWN) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000153 rc = -EPERM;
154 goto out;
155 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100156
157 i = simple_strtoul(buf, &tmp, 16);
158 if ((i == 0) || (i == 1))
159 card->options.fake_broadcast = i;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000160 else
161 rc = -EINVAL;
162out:
163 mutex_unlock(&card->conf_mutex);
164 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100165}
166
167static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
168 qeth_l3_dev_fake_broadcast_store);
169
Ursula Braun76b11f82010-01-11 02:50:50 +0000170static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
171 struct device_attribute *attr, char *buf)
172{
173 struct qeth_card *card = dev_get_drvdata(dev);
174
Ursula Braun76b11f82010-01-11 02:50:50 +0000175 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
176}
177
178static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
179 struct device_attribute *attr, const char *buf, size_t count)
180{
181 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000182 int rc = 0;
Ursula Braun76b11f82010-01-11 02:50:50 +0000183 unsigned long i;
184
Julian Wiedmann379ac992019-04-25 18:25:57 +0200185 if (!IS_IQD(card))
Ursula Braun76b11f82010-01-11 02:50:50 +0000186 return -EPERM;
Frank Blaschkab3332932011-08-08 01:33:59 +0000187 if (card->options.cq == QETH_CQ_ENABLED)
188 return -EPERM;
Ursula Braun76b11f82010-01-11 02:50:50 +0000189
Frank Blaschkac4949f02010-05-11 19:34:47 +0000190 mutex_lock(&card->conf_mutex);
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100191 if (card->state != CARD_STATE_DOWN) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000192 rc = -EPERM;
193 goto out;
194 }
Ursula Braun76b11f82010-01-11 02:50:50 +0000195
Jingoo Han01787222013-07-22 10:18:15 +0900196 rc = kstrtoul(buf, 16, &i);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000197 if (rc) {
198 rc = -EINVAL;
199 goto out;
200 }
Ursula Braun76b11f82010-01-11 02:50:50 +0000201 switch (i) {
202 case 0:
203 card->options.sniffer = i;
204 break;
205 case 1:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000206 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
Julian Wiedmann1917b472019-10-23 10:03:23 +0200207 if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) {
Ursula Braun76b11f82010-01-11 02:50:50 +0000208 card->options.sniffer = i;
209 if (card->qdio.init_pool.buf_count !=
210 QETH_IN_BUF_COUNT_MAX)
211 qeth_realloc_buffer_pool(card,
212 QETH_IN_BUF_COUNT_MAX);
Ursula Braun76b11f82010-01-11 02:50:50 +0000213 } else
Frank Blaschkac4949f02010-05-11 19:34:47 +0000214 rc = -EPERM;
Ursula Braun6cc31d02011-11-15 02:31:12 +0000215 break;
216 default:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000217 rc = -EINVAL;
Ursula Braun76b11f82010-01-11 02:50:50 +0000218 }
Frank Blaschkac4949f02010-05-11 19:34:47 +0000219out:
220 mutex_unlock(&card->conf_mutex);
221 return rc ? rc : count;
Ursula Braun76b11f82010-01-11 02:50:50 +0000222}
223
224static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
225 qeth_l3_dev_sniffer_store);
226
Frank Blaschkab3332932011-08-08 01:33:59 +0000227static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
228 struct device_attribute *attr, char *buf)
229{
230 struct qeth_card *card = dev_get_drvdata(dev);
231 char tmp_hsuid[9];
232
Julian Wiedmann379ac992019-04-25 18:25:57 +0200233 if (!IS_IQD(card))
Frank Blaschkab3332932011-08-08 01:33:59 +0000234 return -EPERM;
235
Frank Blaschkab3332932011-08-08 01:33:59 +0000236 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
237 EBCASC(tmp_hsuid, 8);
238 return sprintf(buf, "%s\n", tmp_hsuid);
239}
240
241static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
242 struct device_attribute *attr, const char *buf, size_t count)
243{
244 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschkab3332932011-08-08 01:33:59 +0000245 char *tmp;
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100246 int rc;
Frank Blaschkab3332932011-08-08 01:33:59 +0000247
Julian Wiedmann379ac992019-04-25 18:25:57 +0200248 if (!IS_IQD(card))
Frank Blaschkab3332932011-08-08 01:33:59 +0000249 return -EPERM;
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100250 if (card->state != CARD_STATE_DOWN)
Frank Blaschkab3332932011-08-08 01:33:59 +0000251 return -EPERM;
252 if (card->options.sniffer)
253 return -EPERM;
254 if (card->options.cq == QETH_CQ_NOTAVAILABLE)
255 return -EPERM;
256
257 tmp = strsep((char **)&buf, "\n");
258 if (strlen(tmp) > 8)
259 return -EINVAL;
260
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100261 if (card->options.hsuid[0])
Frank Blaschkab3332932011-08-08 01:33:59 +0000262 /* delete old ip address */
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100263 qeth_l3_modify_hsuid(card, false);
Frank Blaschkab3332932011-08-08 01:33:59 +0000264
265 if (strlen(tmp) == 0) {
266 /* delete ip address only */
267 card->options.hsuid[0] = '\0';
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200268 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschkab3332932011-08-08 01:33:59 +0000269 qeth_configure_cq(card, QETH_CQ_DISABLED);
270 return count;
271 }
272
273 if (qeth_configure_cq(card, QETH_CQ_ENABLED))
274 return -EPERM;
275
Kees Cook096a8aa2013-07-03 15:04:55 -0700276 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
277 "%-8s", tmp);
Frank Blaschkab3332932011-08-08 01:33:59 +0000278 ASCEBC(card->options.hsuid, 8);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200279 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
Frank Blaschkab3332932011-08-08 01:33:59 +0000280
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100281 rc = qeth_l3_modify_hsuid(card, true);
Frank Blaschkab3332932011-08-08 01:33:59 +0000282
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100283 return rc ? rc : count;
Frank Blaschkab3332932011-08-08 01:33:59 +0000284}
285
286static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
287 qeth_l3_dev_hsuid_store);
288
289
Frank Blaschka4a71df52008-02-15 09:19:42 +0100290static struct attribute *qeth_l3_device_attrs[] = {
291 &dev_attr_route4.attr,
292 &dev_attr_route6.attr,
293 &dev_attr_fake_broadcast.attr,
Ursula Braun76b11f82010-01-11 02:50:50 +0000294 &dev_attr_sniffer.attr,
Frank Blaschkab3332932011-08-08 01:33:59 +0000295 &dev_attr_hsuid.attr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296 NULL,
297};
298
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530299static const struct attribute_group qeth_l3_device_attr_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100300 .attrs = qeth_l3_device_attrs,
301};
302
303static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
304 struct device_attribute *attr, char *buf)
305{
306 struct qeth_card *card = dev_get_drvdata(dev);
307
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
309}
310
311static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
312 struct device_attribute *attr, const char *buf, size_t count)
313{
314 struct qeth_card *card = dev_get_drvdata(dev);
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100315 bool enable;
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100316 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100317
Frank Blaschkac4949f02010-05-11 19:34:47 +0000318 mutex_lock(&card->conf_mutex);
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100319 if (card->state != CARD_STATE_DOWN) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000320 rc = -EPERM;
321 goto out;
322 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100324 if (sysfs_streq(buf, "toggle")) {
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100325 enable = !card->ipato.enabled;
326 } else if (kstrtobool(buf, &enable)) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000327 rc = -EINVAL;
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100328 goto out;
329 }
330
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100331 if (card->ipato.enabled != enable) {
332 card->ipato.enabled = enable;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100333 mutex_lock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100334 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100335 mutex_unlock(&card->ip_lock);
Julian Wiedmann7fbd9492017-12-13 18:56:29 +0100336 }
Frank Blaschkac4949f02010-05-11 19:34:47 +0000337out:
338 mutex_unlock(&card->conf_mutex);
339 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100340}
341
342static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
343 qeth_l3_dev_ipato_enable_show,
344 qeth_l3_dev_ipato_enable_store);
345
346static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
347 struct device_attribute *attr, char *buf)
348{
349 struct qeth_card *card = dev_get_drvdata(dev);
350
Frank Blaschka4a71df52008-02-15 09:19:42 +0100351 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
352}
353
354static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
355 struct device_attribute *attr,
356 const char *buf, size_t count)
357{
358 struct qeth_card *card = dev_get_drvdata(dev);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100359 bool invert;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000360 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100361
Frank Blaschkac4949f02010-05-11 19:34:47 +0000362 mutex_lock(&card->conf_mutex);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100363 if (sysfs_streq(buf, "toggle")) {
364 invert = !card->ipato.invert4;
365 } else if (kstrtobool(buf, &invert)) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000366 rc = -EINVAL;
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100367 goto out;
368 }
369
370 if (card->ipato.invert4 != invert) {
371 card->ipato.invert4 = invert;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100372 mutex_lock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100373 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100374 mutex_unlock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100375 }
376out:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000377 mutex_unlock(&card->conf_mutex);
378 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100379}
380
381static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
382 qeth_l3_dev_ipato_invert4_show,
383 qeth_l3_dev_ipato_invert4_store);
384
385static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
386 enum qeth_prot_versions proto)
387{
388 struct qeth_ipato_entry *ipatoe;
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100389 int str_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100390
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100391 mutex_lock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100393 char addr_str[40];
394 int entry_len;
395
Frank Blaschka4a71df52008-02-15 09:19:42 +0100396 if (ipatoe->proto != proto)
397 continue;
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100398
399 entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr,
400 addr_str);
401 if (entry_len < 0)
402 continue;
403
404 /* Append /%mask to the entry: */
405 entry_len += 1 + ((proto == QETH_PROT_IPV4) ? 2 : 3);
406 /* Enough room to format %entry\n into null terminated page? */
407 if (entry_len + 1 > PAGE_SIZE - str_len - 1)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100408 break;
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100409
410 entry_len = scnprintf(buf, PAGE_SIZE - str_len,
411 "%s/%i\n", addr_str, ipatoe->mask_bits);
412 str_len += entry_len;
413 buf += entry_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100414 }
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100415 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100416
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100417 return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100418}
419
420static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
421 struct device_attribute *attr, char *buf)
422{
423 struct qeth_card *card = dev_get_drvdata(dev);
424
Frank Blaschka4a71df52008-02-15 09:19:42 +0100425 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
426}
427
428static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
429 u8 *addr, int *mask_bits)
430{
431 const char *start, *end;
432 char *tmp;
433 char buffer[40] = {0, };
434
435 start = buf;
436 /* get address string */
437 end = strchr(start, '/');
438 if (!end || (end - start >= 40)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439 return -EINVAL;
440 }
441 strncpy(buffer, start, end - start);
442 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443 return -EINVAL;
444 }
445 start = end + 1;
446 *mask_bits = simple_strtoul(start, &tmp, 10);
447 if (!strlen(start) ||
448 (tmp == start) ||
449 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450 return -EINVAL;
451 }
452 return 0;
453}
454
455static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
456 struct qeth_card *card, enum qeth_prot_versions proto)
457{
458 struct qeth_ipato_entry *ipatoe;
459 u8 addr[16];
460 int mask_bits;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000461 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100462
Frank Blaschkac4949f02010-05-11 19:34:47 +0000463 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100464 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
465 if (rc)
Frank Blaschkac4949f02010-05-11 19:34:47 +0000466 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100467
468 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
469 if (!ipatoe) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000470 rc = -ENOMEM;
471 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100472 }
473 ipatoe->proto = proto;
474 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
475 ipatoe->mask_bits = mask_bits;
476
477 rc = qeth_l3_add_ipato_entry(card, ipatoe);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000478 if (rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100479 kfree(ipatoe);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000480out:
481 mutex_unlock(&card->conf_mutex);
482 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100483}
484
485static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
486 struct device_attribute *attr, const char *buf, size_t count)
487{
488 struct qeth_card *card = dev_get_drvdata(dev);
489
Frank Blaschka4a71df52008-02-15 09:19:42 +0100490 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
491}
492
493static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
494 qeth_l3_dev_ipato_add4_show,
495 qeth_l3_dev_ipato_add4_store);
496
497static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
498 struct qeth_card *card, enum qeth_prot_versions proto)
499{
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);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000506 if (!rc)
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100507 rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000508 mutex_unlock(&card->conf_mutex);
509 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100510}
511
512static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
513 struct device_attribute *attr, const char *buf, size_t count)
514{
515 struct qeth_card *card = dev_get_drvdata(dev);
516
Frank Blaschka4a71df52008-02-15 09:19:42 +0100517 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
518}
519
520static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
521 qeth_l3_dev_ipato_del4_store);
522
523static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
524 struct device_attribute *attr, char *buf)
525{
526 struct qeth_card *card = dev_get_drvdata(dev);
527
Frank Blaschka4a71df52008-02-15 09:19:42 +0100528 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
529}
530
531static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
532 struct device_attribute *attr, const char *buf, size_t count)
533{
534 struct qeth_card *card = dev_get_drvdata(dev);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100535 bool invert;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000536 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100537
Frank Blaschkac4949f02010-05-11 19:34:47 +0000538 mutex_lock(&card->conf_mutex);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100539 if (sysfs_streq(buf, "toggle")) {
540 invert = !card->ipato.invert6;
541 } else if (kstrtobool(buf, &invert)) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000542 rc = -EINVAL;
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100543 goto out;
544 }
545
546 if (card->ipato.invert6 != invert) {
547 card->ipato.invert6 = invert;
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100548 mutex_lock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100549 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100550 mutex_unlock(&card->ip_lock);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100551 }
552out:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000553 mutex_unlock(&card->conf_mutex);
554 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100555}
556
557static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
558 qeth_l3_dev_ipato_invert6_show,
559 qeth_l3_dev_ipato_invert6_store);
560
561
562static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
563 struct device_attribute *attr, char *buf)
564{
565 struct qeth_card *card = dev_get_drvdata(dev);
566
Frank Blaschka4a71df52008-02-15 09:19:42 +0100567 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
568}
569
570static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
571 struct device_attribute *attr, const char *buf, size_t count)
572{
573 struct qeth_card *card = dev_get_drvdata(dev);
574
Frank Blaschka4a71df52008-02-15 09:19:42 +0100575 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
576}
577
578static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
579 qeth_l3_dev_ipato_add6_show,
580 qeth_l3_dev_ipato_add6_store);
581
582static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
583 struct device_attribute *attr, const char *buf, size_t count)
584{
585 struct qeth_card *card = dev_get_drvdata(dev);
586
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
588}
589
590static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
591 qeth_l3_dev_ipato_del6_store);
592
593static struct attribute *qeth_ipato_device_attrs[] = {
594 &dev_attr_ipato_enable.attr,
595 &dev_attr_ipato_invert4.attr,
596 &dev_attr_ipato_add4.attr,
597 &dev_attr_ipato_del4.attr,
598 &dev_attr_ipato_invert6.attr,
599 &dev_attr_ipato_add6.attr,
600 &dev_attr_ipato_del6.attr,
601 NULL,
602};
603
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530604static const struct attribute_group qeth_device_ipato_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100605 .name = "ipa_takeover",
606 .attrs = qeth_ipato_device_attrs,
607};
608
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100609static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
610 enum qeth_prot_versions proto,
611 enum qeth_ip_types type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100612{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100613 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100614 struct qeth_ipaddr *ipaddr;
Ursula Braune48b9ea2017-01-12 15:48:43 +0100615 int str_len = 0;
Ursula Braune48b9ea2017-01-12 15:48:43 +0100616 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100617
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100618 mutex_lock(&card->ip_lock);
Ursula Braune48b9ea2017-01-12 15:48:43 +0100619 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100620 char addr_str[40];
621 int entry_len;
622
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100623 if (ipaddr->proto != proto || ipaddr->type != type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100624 continue;
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100625
626 entry_len = qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u,
627 addr_str);
628 if (entry_len < 0)
629 continue;
630
631 /* Enough room to format %addr\n into null terminated page? */
632 if (entry_len + 1 > PAGE_SIZE - str_len - 1)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100633 break;
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100634
635 entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n",
636 addr_str);
637 str_len += entry_len;
638 buf += entry_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100639 }
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100640 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100641
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +0100642 return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100643}
644
645static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100646 struct device_attribute *attr,
647 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100649 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
650 QETH_IP_TYPE_VIPA);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651}
652
653static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
654 u8 *addr)
655{
656 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100657 return -EINVAL;
658 }
659 return 0;
660}
661
662static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
663 struct qeth_card *card, enum qeth_prot_versions proto)
664{
665 u8 addr[16] = {0, };
666 int rc;
667
Frank Blaschkac4949f02010-05-11 19:34:47 +0000668 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100669 rc = qeth_l3_parse_vipae(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000670 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100671 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
672 QETH_IP_TYPE_VIPA, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000673 mutex_unlock(&card->conf_mutex);
674 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100675}
676
677static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
678 struct device_attribute *attr, const char *buf, size_t count)
679{
680 struct qeth_card *card = dev_get_drvdata(dev);
681
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
683}
684
685static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
686 qeth_l3_dev_vipa_add4_show,
687 qeth_l3_dev_vipa_add4_store);
688
689static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
690 struct qeth_card *card, enum qeth_prot_versions proto)
691{
692 u8 addr[16];
693 int rc;
694
Frank Blaschkac4949f02010-05-11 19:34:47 +0000695 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100696 rc = qeth_l3_parse_vipae(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000697 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100698 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
699 QETH_IP_TYPE_VIPA, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000700 mutex_unlock(&card->conf_mutex);
701 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702}
703
704static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
705 struct device_attribute *attr, const char *buf, size_t count)
706{
707 struct qeth_card *card = dev_get_drvdata(dev);
708
Frank Blaschka4a71df52008-02-15 09:19:42 +0100709 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
710}
711
712static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
713 qeth_l3_dev_vipa_del4_store);
714
715static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100716 struct device_attribute *attr,
717 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100718{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100719 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
720 QETH_IP_TYPE_VIPA);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100721}
722
723static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
724 struct device_attribute *attr, const char *buf, size_t count)
725{
726 struct qeth_card *card = dev_get_drvdata(dev);
727
Frank Blaschka4a71df52008-02-15 09:19:42 +0100728 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
729}
730
731static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
732 qeth_l3_dev_vipa_add6_show,
733 qeth_l3_dev_vipa_add6_store);
734
735static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
736 struct device_attribute *attr, const char *buf, size_t count)
737{
738 struct qeth_card *card = dev_get_drvdata(dev);
739
Frank Blaschka4a71df52008-02-15 09:19:42 +0100740 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
741}
742
743static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
744 qeth_l3_dev_vipa_del6_store);
745
746static struct attribute *qeth_vipa_device_attrs[] = {
747 &dev_attr_vipa_add4.attr,
748 &dev_attr_vipa_del4.attr,
749 &dev_attr_vipa_add6.attr,
750 &dev_attr_vipa_del6.attr,
751 NULL,
752};
753
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530754static const struct attribute_group qeth_device_vipa_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100755 .name = "vipa",
756 .attrs = qeth_vipa_device_attrs,
757};
758
Frank Blaschka4a71df52008-02-15 09:19:42 +0100759static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100760 struct device_attribute *attr,
761 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100762{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100763 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
764 QETH_IP_TYPE_RXIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100765}
766
767static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
768 u8 *addr)
769{
Kittipon Meesompopaa9bea02017-08-15 17:02:48 +0200770 __be32 ipv4_addr;
771 struct in6_addr ipv6_addr;
772
Frank Blaschka4a71df52008-02-15 09:19:42 +0100773 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100774 return -EINVAL;
775 }
Kittipon Meesompopaa9bea02017-08-15 17:02:48 +0200776 if (proto == QETH_PROT_IPV4) {
777 memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
778 if (ipv4_is_multicast(ipv4_addr)) {
779 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
780 return -EINVAL;
781 }
782 } else if (proto == QETH_PROT_IPV6) {
783 memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
784 if (ipv6_addr_is_multicast(&ipv6_addr)) {
785 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
786 return -EINVAL;
787 }
788 }
789
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 return 0;
791}
792
793static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
794 struct qeth_card *card, enum qeth_prot_versions proto)
795{
796 u8 addr[16] = {0, };
797 int rc;
798
Frank Blaschkac4949f02010-05-11 19:34:47 +0000799 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 rc = qeth_l3_parse_rxipe(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000801 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100802 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
803 QETH_IP_TYPE_RXIP, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000804 mutex_unlock(&card->conf_mutex);
805 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100806}
807
808static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
809 struct device_attribute *attr, const char *buf, size_t count)
810{
811 struct qeth_card *card = dev_get_drvdata(dev);
812
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
814}
815
816static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
817 qeth_l3_dev_rxip_add4_show,
818 qeth_l3_dev_rxip_add4_store);
819
820static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
821 struct qeth_card *card, enum qeth_prot_versions proto)
822{
823 u8 addr[16];
824 int rc;
825
Frank Blaschkac4949f02010-05-11 19:34:47 +0000826 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100827 rc = qeth_l3_parse_rxipe(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000828 if (!rc)
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100829 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
830 QETH_IP_TYPE_RXIP, proto);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000831 mutex_unlock(&card->conf_mutex);
832 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833}
834
835static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
836 struct device_attribute *attr, const char *buf, size_t count)
837{
838 struct qeth_card *card = dev_get_drvdata(dev);
839
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
841}
842
843static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
844 qeth_l3_dev_rxip_del4_store);
845
846static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100847 struct device_attribute *attr,
848 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100849{
Julian Wiedmannd2073ef2017-12-27 17:44:29 +0100850 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
851 QETH_IP_TYPE_RXIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100852}
853
854static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
855 struct device_attribute *attr, const char *buf, size_t count)
856{
857 struct qeth_card *card = dev_get_drvdata(dev);
858
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
860}
861
862static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
863 qeth_l3_dev_rxip_add6_show,
864 qeth_l3_dev_rxip_add6_store);
865
866static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
867 struct device_attribute *attr, const char *buf, size_t count)
868{
869 struct qeth_card *card = dev_get_drvdata(dev);
870
Frank Blaschka4a71df52008-02-15 09:19:42 +0100871 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
872}
873
874static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
875 qeth_l3_dev_rxip_del6_store);
876
877static struct attribute *qeth_rxip_device_attrs[] = {
878 &dev_attr_rxip_add4.attr,
879 &dev_attr_rxip_del4.attr,
880 &dev_attr_rxip_add6.attr,
881 &dev_attr_rxip_del6.attr,
882 NULL,
883};
884
Arvind Yadavcfe9a042017-07-19 12:39:14 +0530885static const struct attribute_group qeth_device_rxip_group = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886 .name = "rxip",
887 .attrs = qeth_rxip_device_attrs,
888};
889
Julian Wiedmannab25a502017-09-18 21:18:19 +0200890static const struct attribute_group *qeth_l3_only_attr_groups[] = {
891 &qeth_l3_device_attr_group,
892 &qeth_device_ipato_group,
893 &qeth_device_vipa_group,
894 &qeth_device_rxip_group,
895 NULL,
896};
897
Frank Blaschka4a71df52008-02-15 09:19:42 +0100898int qeth_l3_create_device_attributes(struct device *dev)
899{
Julian Wiedmannab25a502017-09-18 21:18:19 +0200900 return sysfs_create_groups(&dev->kobj, qeth_l3_only_attr_groups);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100901}
902
903void qeth_l3_remove_device_attributes(struct device *dev)
904{
Julian Wiedmannab25a502017-09-18 21:18:19 +0200905 sysfs_remove_groups(&dev->kobj, qeth_l3_only_attr_groups);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100906}
Ursula Braun79a04e42017-06-06 14:33:49 +0200907
908const struct attribute_group *qeth_l3_attr_groups[] = {
909 &qeth_device_attr_group,
910 &qeth_device_blkt_group,
Julian Wiedmannab25a502017-09-18 21:18:19 +0200911 /* l3 specific, see qeth_l3_only_attr_groups: */
Ursula Braun79a04e42017-06-06 14:33:49 +0200912 &qeth_l3_device_attr_group,
913 &qeth_device_ipato_group,
914 &qeth_device_vipa_group,
915 &qeth_device_rxip_group,
Julian Wiedmannab25a502017-09-18 21:18:19 +0200916 NULL,
Ursula Braun79a04e42017-06-06 14:33:49 +0200917};