blob: 65645b11fc19763295c52fa96fd49608c465ed78 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
Frank Blaschka4a71df52008-02-15 09:19:42 +01002 * Copyright IBM Corp. 2007
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
8
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Frank Blaschkab3332932011-08-08 01:33:59 +000010#include <asm/ebcdic.h>
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +020011#include <linux/hashtable.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010012#include "qeth_l3.h"
13
14#define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
15struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
16
Frank Blaschka4a71df52008-02-15 09:19:42 +010017static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
18 struct qeth_routing_info *route, char *buf)
19{
20 switch (route->type) {
21 case PRIMARY_ROUTER:
22 return sprintf(buf, "%s\n", "primary router");
23 case SECONDARY_ROUTER:
24 return sprintf(buf, "%s\n", "secondary router");
25 case MULTICAST_ROUTER:
26 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
27 return sprintf(buf, "%s\n", "multicast router+");
28 else
29 return sprintf(buf, "%s\n", "multicast router");
30 case PRIMARY_CONNECTOR:
31 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
32 return sprintf(buf, "%s\n", "primary connector+");
33 else
34 return sprintf(buf, "%s\n", "primary connector");
35 case SECONDARY_CONNECTOR:
36 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
37 return sprintf(buf, "%s\n", "secondary connector+");
38 else
39 return sprintf(buf, "%s\n", "secondary connector");
40 default:
41 return sprintf(buf, "%s\n", "no");
42 }
43}
44
45static ssize_t qeth_l3_dev_route4_show(struct device *dev,
46 struct device_attribute *attr, char *buf)
47{
48 struct qeth_card *card = dev_get_drvdata(dev);
49
50 if (!card)
51 return -EINVAL;
52
53 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
54}
55
56static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
57 struct qeth_routing_info *route, enum qeth_prot_versions prot,
58 const char *buf, size_t count)
59{
60 enum qeth_routing_types old_route_type = route->type;
Frank Blaschkac4949f02010-05-11 19:34:47 +000061 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +010062
Frank Blaschkac4949f02010-05-11 19:34:47 +000063 mutex_lock(&card->conf_mutex);
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010064 if (sysfs_streq(buf, "no_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010065 route->type = NO_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010066 } else if (sysfs_streq(buf, "primary_connector")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010067 route->type = PRIMARY_CONNECTOR;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010068 } else if (sysfs_streq(buf, "secondary_connector")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010069 route->type = SECONDARY_CONNECTOR;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010070 } else if (sysfs_streq(buf, "primary_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010071 route->type = PRIMARY_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010072 } else if (sysfs_streq(buf, "secondary_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010073 route->type = SECONDARY_ROUTER;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +010074 } else if (sysfs_streq(buf, "multicast_router")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010075 route->type = MULTICAST_ROUTER;
76 } else {
Frank Blaschkac4949f02010-05-11 19:34:47 +000077 rc = -EINVAL;
78 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +010079 }
Eugene Crosserc3521252015-01-16 14:05:47 +010080 if (qeth_card_hw_is_reachable(card) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010081 (old_route_type != route->type)) {
82 if (prot == QETH_PROT_IPV4)
83 rc = qeth_l3_setrouting_v4(card);
84 else if (prot == QETH_PROT_IPV6)
85 rc = qeth_l3_setrouting_v6(card);
86 }
Frank Blaschkac4949f02010-05-11 19:34:47 +000087out:
Stefan Raspl82e2e782013-03-18 20:04:43 +000088 if (rc)
89 route->type = old_route_type;
Frank Blaschkac4949f02010-05-11 19:34:47 +000090 mutex_unlock(&card->conf_mutex);
91 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +010092}
93
94static ssize_t qeth_l3_dev_route4_store(struct device *dev,
95 struct device_attribute *attr, const char *buf, size_t count)
96{
97 struct qeth_card *card = dev_get_drvdata(dev);
98
99 if (!card)
100 return -EINVAL;
101
102 return qeth_l3_dev_route_store(card, &card->options.route4,
103 QETH_PROT_IPV4, buf, count);
104}
105
106static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
107 qeth_l3_dev_route4_store);
108
109static ssize_t qeth_l3_dev_route6_show(struct device *dev,
110 struct device_attribute *attr, char *buf)
111{
112 struct qeth_card *card = dev_get_drvdata(dev);
113
114 if (!card)
115 return -EINVAL;
116
Frank Blaschka4a71df52008-02-15 09:19:42 +0100117 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
118}
119
120static ssize_t qeth_l3_dev_route6_store(struct device *dev,
121 struct device_attribute *attr, const char *buf, size_t count)
122{
123 struct qeth_card *card = dev_get_drvdata(dev);
124
125 if (!card)
126 return -EINVAL;
127
Frank Blaschka4a71df52008-02-15 09:19:42 +0100128 return qeth_l3_dev_route_store(card, &card->options.route6,
129 QETH_PROT_IPV6, buf, count);
130}
131
132static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
133 qeth_l3_dev_route6_store);
134
135static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
136 struct device_attribute *attr, char *buf)
137{
138 struct qeth_card *card = dev_get_drvdata(dev);
139
140 if (!card)
141 return -EINVAL;
142
143 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
144}
145
146static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
147 struct device_attribute *attr, const char *buf, size_t count)
148{
149 struct qeth_card *card = dev_get_drvdata(dev);
150 char *tmp;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000151 int i, rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100152
153 if (!card)
154 return -EINVAL;
155
Frank Blaschkac4949f02010-05-11 19:34:47 +0000156 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100157 if ((card->state != CARD_STATE_DOWN) &&
Frank Blaschkac4949f02010-05-11 19:34:47 +0000158 (card->state != CARD_STATE_RECOVER)) {
159 rc = -EPERM;
160 goto out;
161 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100162
163 i = simple_strtoul(buf, &tmp, 16);
164 if ((i == 0) || (i == 1))
165 card->options.fake_broadcast = i;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000166 else
167 rc = -EINVAL;
168out:
169 mutex_unlock(&card->conf_mutex);
170 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100171}
172
173static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
174 qeth_l3_dev_fake_broadcast_store);
175
Ursula Braun76b11f82010-01-11 02:50:50 +0000176static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
177 struct device_attribute *attr, char *buf)
178{
179 struct qeth_card *card = dev_get_drvdata(dev);
180
181 if (!card)
182 return -EINVAL;
183
184 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
185}
186
187static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
188 struct device_attribute *attr, const char *buf, size_t count)
189{
190 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000191 int rc = 0;
Ursula Braun76b11f82010-01-11 02:50:50 +0000192 unsigned long i;
193
194 if (!card)
195 return -EINVAL;
196
197 if (card->info.type != QETH_CARD_TYPE_IQD)
198 return -EPERM;
Frank Blaschkab3332932011-08-08 01:33:59 +0000199 if (card->options.cq == QETH_CQ_ENABLED)
200 return -EPERM;
Ursula Braun76b11f82010-01-11 02:50:50 +0000201
Frank Blaschkac4949f02010-05-11 19:34:47 +0000202 mutex_lock(&card->conf_mutex);
Ursula Braun76b11f82010-01-11 02:50:50 +0000203 if ((card->state != CARD_STATE_DOWN) &&
Frank Blaschkac4949f02010-05-11 19:34:47 +0000204 (card->state != CARD_STATE_RECOVER)) {
205 rc = -EPERM;
206 goto out;
207 }
Ursula Braun76b11f82010-01-11 02:50:50 +0000208
Jingoo Han01787222013-07-22 10:18:15 +0900209 rc = kstrtoul(buf, 16, &i);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000210 if (rc) {
211 rc = -EINVAL;
212 goto out;
213 }
Ursula Braun76b11f82010-01-11 02:50:50 +0000214 switch (i) {
215 case 0:
216 card->options.sniffer = i;
217 break;
218 case 1:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000219 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
Ursula Braun76b11f82010-01-11 02:50:50 +0000220 if (card->ssqd.qdioac2 & QETH_SNIFF_AVAIL) {
221 card->options.sniffer = i;
222 if (card->qdio.init_pool.buf_count !=
223 QETH_IN_BUF_COUNT_MAX)
224 qeth_realloc_buffer_pool(card,
225 QETH_IN_BUF_COUNT_MAX);
Ursula Braun76b11f82010-01-11 02:50:50 +0000226 } else
Frank Blaschkac4949f02010-05-11 19:34:47 +0000227 rc = -EPERM;
Ursula Braun6cc31d02011-11-15 02:31:12 +0000228 break;
229 default:
Frank Blaschkac4949f02010-05-11 19:34:47 +0000230 rc = -EINVAL;
Ursula Braun76b11f82010-01-11 02:50:50 +0000231 }
Frank Blaschkac4949f02010-05-11 19:34:47 +0000232out:
233 mutex_unlock(&card->conf_mutex);
234 return rc ? rc : count;
Ursula Braun76b11f82010-01-11 02:50:50 +0000235}
236
237static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
238 qeth_l3_dev_sniffer_store);
239
Frank Blaschkab3332932011-08-08 01:33:59 +0000240
241static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
242 struct device_attribute *attr, char *buf)
243{
244 struct qeth_card *card = dev_get_drvdata(dev);
245 char tmp_hsuid[9];
246
247 if (!card)
248 return -EINVAL;
249
250 if (card->info.type != QETH_CARD_TYPE_IQD)
251 return -EPERM;
252
253 if (card->state == CARD_STATE_DOWN)
254 return -EPERM;
255
256 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
257 EBCASC(tmp_hsuid, 8);
258 return sprintf(buf, "%s\n", tmp_hsuid);
259}
260
261static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
262 struct device_attribute *attr, const char *buf, size_t count)
263{
264 struct qeth_card *card = dev_get_drvdata(dev);
265 struct qeth_ipaddr *addr;
266 char *tmp;
267 int i;
268
269 if (!card)
270 return -EINVAL;
271
272 if (card->info.type != QETH_CARD_TYPE_IQD)
273 return -EPERM;
274 if (card->state != CARD_STATE_DOWN &&
275 card->state != CARD_STATE_RECOVER)
276 return -EPERM;
277 if (card->options.sniffer)
278 return -EPERM;
279 if (card->options.cq == QETH_CQ_NOTAVAILABLE)
280 return -EPERM;
281
282 tmp = strsep((char **)&buf, "\n");
283 if (strlen(tmp) > 8)
284 return -EINVAL;
285
286 if (card->options.hsuid[0]) {
287 /* delete old ip address */
288 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200289 if (!addr)
Frank Blaschkab3332932011-08-08 01:33:59 +0000290 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200291
292 addr->u.a6.addr.s6_addr32[0] = 0xfe800000;
293 addr->u.a6.addr.s6_addr32[1] = 0x00000000;
294 for (i = 8; i < 16; i++)
295 addr->u.a6.addr.s6_addr[i] =
296 card->options.hsuid[i - 8];
297 addr->u.a6.pfxlen = 0;
298 addr->type = QETH_IP_TYPE_NORMAL;
299
300 qeth_l3_delete_ip(card, addr);
301 kfree(addr);
Frank Blaschkab3332932011-08-08 01:33:59 +0000302 }
303
304 if (strlen(tmp) == 0) {
305 /* delete ip address only */
306 card->options.hsuid[0] = '\0';
307 if (card->dev)
308 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
309 qeth_configure_cq(card, QETH_CQ_DISABLED);
310 return count;
311 }
312
313 if (qeth_configure_cq(card, QETH_CQ_ENABLED))
314 return -EPERM;
315
Kees Cook096a8aa2013-07-03 15:04:55 -0700316 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
317 "%-8s", tmp);
Frank Blaschkab3332932011-08-08 01:33:59 +0000318 ASCEBC(card->options.hsuid, 8);
319 if (card->dev)
320 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
321
322 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
323 if (addr != NULL) {
324 addr->u.a6.addr.s6_addr32[0] = 0xfe800000;
325 addr->u.a6.addr.s6_addr32[1] = 0x00000000;
326 for (i = 8; i < 16; i++)
327 addr->u.a6.addr.s6_addr[i] = card->options.hsuid[i - 8];
328 addr->u.a6.pfxlen = 0;
329 addr->type = QETH_IP_TYPE_NORMAL;
330 } else
331 return -ENOMEM;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200332 qeth_l3_add_ip(card, addr);
333 kfree(addr);
Frank Blaschkab3332932011-08-08 01:33:59 +0000334
335 return count;
336}
337
338static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
339 qeth_l3_dev_hsuid_store);
340
341
Frank Blaschka4a71df52008-02-15 09:19:42 +0100342static struct attribute *qeth_l3_device_attrs[] = {
343 &dev_attr_route4.attr,
344 &dev_attr_route6.attr,
345 &dev_attr_fake_broadcast.attr,
Ursula Braun76b11f82010-01-11 02:50:50 +0000346 &dev_attr_sniffer.attr,
Frank Blaschkab3332932011-08-08 01:33:59 +0000347 &dev_attr_hsuid.attr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100348 NULL,
349};
350
351static struct attribute_group qeth_l3_device_attr_group = {
352 .attrs = qeth_l3_device_attrs,
353};
354
355static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
356 struct device_attribute *attr, char *buf)
357{
358 struct qeth_card *card = dev_get_drvdata(dev);
359
360 if (!card)
361 return -EINVAL;
362
363 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
364}
365
366static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
367 struct device_attribute *attr, const char *buf, size_t count)
368{
369 struct qeth_card *card = dev_get_drvdata(dev);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200370 struct qeth_ipaddr *addr;
371 int i, rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372
373 if (!card)
374 return -EINVAL;
375
Frank Blaschkac4949f02010-05-11 19:34:47 +0000376 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100377 if ((card->state != CARD_STATE_DOWN) &&
Frank Blaschkac4949f02010-05-11 19:34:47 +0000378 (card->state != CARD_STATE_RECOVER)) {
379 rc = -EPERM;
380 goto out;
381 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100382
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100383 if (sysfs_streq(buf, "toggle")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100384 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100385 } else if (sysfs_streq(buf, "1")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100386 card->ipato.enabled = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200387 hash_for_each(card->ip_htable, i, addr, hnode) {
388 if ((addr->type == QETH_IP_TYPE_NORMAL) &&
389 qeth_l3_is_addr_covered_by_ipato(card, addr))
390 addr->set_flags |=
Klaus-Dieter Wacker62982632010-07-22 23:15:03 +0000391 QETH_IPA_SETIP_TAKEOVER_FLAG;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200392 }
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100393 } else if (sysfs_streq(buf, "0")) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394 card->ipato.enabled = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200395 hash_for_each(card->ip_htable, i, addr, hnode) {
396 if (addr->set_flags &
397 QETH_IPA_SETIP_TAKEOVER_FLAG)
398 addr->set_flags &=
399 ~QETH_IPA_SETIP_TAKEOVER_FLAG;
400 }
Frank Blaschkac4949f02010-05-11 19:34:47 +0000401 } else
402 rc = -EINVAL;
403out:
404 mutex_unlock(&card->conf_mutex);
405 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406}
407
408static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
409 qeth_l3_dev_ipato_enable_show,
410 qeth_l3_dev_ipato_enable_store);
411
412static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
413 struct device_attribute *attr, char *buf)
414{
415 struct qeth_card *card = dev_get_drvdata(dev);
416
417 if (!card)
418 return -EINVAL;
419
420 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
421}
422
423static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
424 struct device_attribute *attr,
425 const char *buf, size_t count)
426{
427 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000428 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100429
430 if (!card)
431 return -EINVAL;
432
Frank Blaschkac4949f02010-05-11 19:34:47 +0000433 mutex_lock(&card->conf_mutex);
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100434 if (sysfs_streq(buf, "toggle"))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100436 else if (sysfs_streq(buf, "1"))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 card->ipato.invert4 = 1;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100438 else if (sysfs_streq(buf, "0"))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439 card->ipato.invert4 = 0;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100440 else
Frank Blaschkac4949f02010-05-11 19:34:47 +0000441 rc = -EINVAL;
442 mutex_unlock(&card->conf_mutex);
443 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100444}
445
446static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
447 qeth_l3_dev_ipato_invert4_show,
448 qeth_l3_dev_ipato_invert4_store);
449
450static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
451 enum qeth_prot_versions proto)
452{
453 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100454 char addr_str[40];
455 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
456 int i = 0;
457
458 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
459 /* add strlen for "/<mask>\n" */
460 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200461 spin_lock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100462 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
463 if (ipatoe->proto != proto)
464 continue;
465 /* String must not be longer than PAGE_SIZE. So we check if
466 * string length gets near PAGE_SIZE. Then we can savely display
467 * the next IPv6 address (worst case, compared to IPv4) */
468 if ((PAGE_SIZE - i) <= entry_len)
469 break;
470 qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
471 i += snprintf(buf + i, PAGE_SIZE - i,
472 "%s/%i\n", addr_str, ipatoe->mask_bits);
473 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200474 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100475 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
476
477 return i;
478}
479
480static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
481 struct device_attribute *attr, char *buf)
482{
483 struct qeth_card *card = dev_get_drvdata(dev);
484
485 if (!card)
486 return -EINVAL;
487
488 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
489}
490
491static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
492 u8 *addr, int *mask_bits)
493{
494 const char *start, *end;
495 char *tmp;
496 char buffer[40] = {0, };
497
498 start = buf;
499 /* get address string */
500 end = strchr(start, '/');
501 if (!end || (end - start >= 40)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100502 return -EINVAL;
503 }
504 strncpy(buffer, start, end - start);
505 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100506 return -EINVAL;
507 }
508 start = end + 1;
509 *mask_bits = simple_strtoul(start, &tmp, 10);
510 if (!strlen(start) ||
511 (tmp == start) ||
512 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100513 return -EINVAL;
514 }
515 return 0;
516}
517
518static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
519 struct qeth_card *card, enum qeth_prot_versions proto)
520{
521 struct qeth_ipato_entry *ipatoe;
522 u8 addr[16];
523 int mask_bits;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000524 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525
Frank Blaschkac4949f02010-05-11 19:34:47 +0000526 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100527 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
528 if (rc)
Frank Blaschkac4949f02010-05-11 19:34:47 +0000529 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100530
531 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
532 if (!ipatoe) {
Frank Blaschkac4949f02010-05-11 19:34:47 +0000533 rc = -ENOMEM;
534 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100535 }
536 ipatoe->proto = proto;
537 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
538 ipatoe->mask_bits = mask_bits;
539
540 rc = qeth_l3_add_ipato_entry(card, ipatoe);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000541 if (rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100542 kfree(ipatoe);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000543out:
544 mutex_unlock(&card->conf_mutex);
545 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100546}
547
548static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
549 struct device_attribute *attr, const char *buf, size_t count)
550{
551 struct qeth_card *card = dev_get_drvdata(dev);
552
553 if (!card)
554 return -EINVAL;
555
556 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
557}
558
559static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
560 qeth_l3_dev_ipato_add4_show,
561 qeth_l3_dev_ipato_add4_store);
562
563static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
564 struct qeth_card *card, enum qeth_prot_versions proto)
565{
566 u8 addr[16];
567 int mask_bits;
Frank Blaschkac4949f02010-05-11 19:34:47 +0000568 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100569
Frank Blaschkac4949f02010-05-11 19:34:47 +0000570 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100571 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000572 if (!rc)
573 qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
574 mutex_unlock(&card->conf_mutex);
575 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100576}
577
578static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
579 struct device_attribute *attr, const char *buf, size_t count)
580{
581 struct qeth_card *card = dev_get_drvdata(dev);
582
583 if (!card)
584 return -EINVAL;
585
586 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
587}
588
589static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
590 qeth_l3_dev_ipato_del4_store);
591
592static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
593 struct device_attribute *attr, char *buf)
594{
595 struct qeth_card *card = dev_get_drvdata(dev);
596
597 if (!card)
598 return -EINVAL;
599
600 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
601}
602
603static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
604 struct device_attribute *attr, const char *buf, size_t count)
605{
606 struct qeth_card *card = dev_get_drvdata(dev);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000607 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100608
609 if (!card)
610 return -EINVAL;
611
Frank Blaschkac4949f02010-05-11 19:34:47 +0000612 mutex_lock(&card->conf_mutex);
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100613 if (sysfs_streq(buf, "toggle"))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100614 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100615 else if (sysfs_streq(buf, "1"))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616 card->ipato.invert6 = 1;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100617 else if (sysfs_streq(buf, "0"))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618 card->ipato.invert6 = 0;
Eugene Crosser7e846d6b2015-01-16 14:05:48 +0100619 else
Frank Blaschkac4949f02010-05-11 19:34:47 +0000620 rc = -EINVAL;
621 mutex_unlock(&card->conf_mutex);
622 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100623}
624
625static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
626 qeth_l3_dev_ipato_invert6_show,
627 qeth_l3_dev_ipato_invert6_store);
628
629
630static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
631 struct device_attribute *attr, char *buf)
632{
633 struct qeth_card *card = dev_get_drvdata(dev);
634
635 if (!card)
636 return -EINVAL;
637
638 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
639}
640
641static ssize_t qeth_l3_dev_ipato_add6_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_add_store(buf, count, card, QETH_PROT_IPV6);
650}
651
652static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
653 qeth_l3_dev_ipato_add6_show,
654 qeth_l3_dev_ipato_add6_store);
655
656static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
657 struct device_attribute *attr, const char *buf, size_t count)
658{
659 struct qeth_card *card = dev_get_drvdata(dev);
660
661 if (!card)
662 return -EINVAL;
663
664 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
665}
666
667static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
668 qeth_l3_dev_ipato_del6_store);
669
670static struct attribute *qeth_ipato_device_attrs[] = {
671 &dev_attr_ipato_enable.attr,
672 &dev_attr_ipato_invert4.attr,
673 &dev_attr_ipato_add4.attr,
674 &dev_attr_ipato_del4.attr,
675 &dev_attr_ipato_invert6.attr,
676 &dev_attr_ipato_add6.attr,
677 &dev_attr_ipato_del6.attr,
678 NULL,
679};
680
681static struct attribute_group qeth_device_ipato_group = {
682 .name = "ipa_takeover",
683 .attrs = qeth_ipato_device_attrs,
684};
685
686static ssize_t qeth_l3_dev_vipa_add_show(char *buf, struct qeth_card *card,
687 enum qeth_prot_versions proto)
688{
689 struct qeth_ipaddr *ipaddr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200690 struct hlist_node *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100691 char addr_str[40];
692 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100693 int i = 0;
694
695 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
696 entry_len += 2; /* \n + terminator */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200697 spin_lock_bh(&card->ip_lock);
698 hash_for_each_safe(card->ip_htable, i, tmp, ipaddr, hnode) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 if (ipaddr->proto != proto)
700 continue;
701 if (ipaddr->type != QETH_IP_TYPE_VIPA)
702 continue;
703 /* String must not be longer than PAGE_SIZE. So we check if
704 * string length gets near PAGE_SIZE. Then we can savely display
705 * the next IPv6 address (worst case, compared to IPv4) */
706 if ((PAGE_SIZE - i) <= entry_len)
707 break;
708 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
709 addr_str);
710 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
711 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200712 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100713 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
714
715 return i;
716}
717
718static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
719 struct device_attribute *attr, char *buf)
720{
721 struct qeth_card *card = dev_get_drvdata(dev);
722
723 if (!card)
724 return -EINVAL;
725
726 return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
727}
728
729static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
730 u8 *addr)
731{
732 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100733 return -EINVAL;
734 }
735 return 0;
736}
737
738static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
739 struct qeth_card *card, enum qeth_prot_versions proto)
740{
741 u8 addr[16] = {0, };
742 int rc;
743
Frank Blaschkac4949f02010-05-11 19:34:47 +0000744 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100745 rc = qeth_l3_parse_vipae(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000746 if (!rc)
747 rc = qeth_l3_add_vipa(card, proto, addr);
748 mutex_unlock(&card->conf_mutex);
749 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100750}
751
752static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
753 struct device_attribute *attr, const char *buf, size_t count)
754{
755 struct qeth_card *card = dev_get_drvdata(dev);
756
757 if (!card)
758 return -EINVAL;
759
760 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
761}
762
763static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
764 qeth_l3_dev_vipa_add4_show,
765 qeth_l3_dev_vipa_add4_store);
766
767static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
768 struct qeth_card *card, enum qeth_prot_versions proto)
769{
770 u8 addr[16];
771 int rc;
772
Frank Blaschkac4949f02010-05-11 19:34:47 +0000773 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100774 rc = qeth_l3_parse_vipae(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000775 if (!rc)
776 qeth_l3_del_vipa(card, proto, addr);
777 mutex_unlock(&card->conf_mutex);
778 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779}
780
781static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
782 struct device_attribute *attr, const char *buf, size_t count)
783{
784 struct qeth_card *card = dev_get_drvdata(dev);
785
786 if (!card)
787 return -EINVAL;
788
789 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
790}
791
792static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
793 qeth_l3_dev_vipa_del4_store);
794
795static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
796 struct device_attribute *attr, char *buf)
797{
798 struct qeth_card *card = dev_get_drvdata(dev);
799
800 if (!card)
801 return -EINVAL;
802
803 return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
804}
805
806static ssize_t qeth_l3_dev_vipa_add6_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_add_store(buf, count, card, QETH_PROT_IPV6);
815}
816
817static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
818 qeth_l3_dev_vipa_add6_show,
819 qeth_l3_dev_vipa_add6_store);
820
821static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
822 struct device_attribute *attr, const char *buf, size_t count)
823{
824 struct qeth_card *card = dev_get_drvdata(dev);
825
826 if (!card)
827 return -EINVAL;
828
829 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
830}
831
832static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
833 qeth_l3_dev_vipa_del6_store);
834
835static struct attribute *qeth_vipa_device_attrs[] = {
836 &dev_attr_vipa_add4.attr,
837 &dev_attr_vipa_del4.attr,
838 &dev_attr_vipa_add6.attr,
839 &dev_attr_vipa_del6.attr,
840 NULL,
841};
842
843static struct attribute_group qeth_device_vipa_group = {
844 .name = "vipa",
845 .attrs = qeth_vipa_device_attrs,
846};
847
848static ssize_t qeth_l3_dev_rxip_add_show(char *buf, struct qeth_card *card,
849 enum qeth_prot_versions proto)
850{
851 struct qeth_ipaddr *ipaddr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200852 struct hlist_node *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853 char addr_str[40];
854 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 int i = 0;
856
857 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
858 entry_len += 2; /* \n + terminator */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200859 spin_lock_bh(&card->ip_lock);
860 hash_for_each_safe(card->ip_htable, i, tmp, ipaddr, hnode) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100861 if (ipaddr->proto != proto)
862 continue;
863 if (ipaddr->type != QETH_IP_TYPE_RXIP)
864 continue;
865 /* String must not be longer than PAGE_SIZE. So we check if
866 * string length gets near PAGE_SIZE. Then we can savely display
867 * the next IPv6 address (worst case, compared to IPv4) */
868 if ((PAGE_SIZE - i) <= entry_len)
869 break;
870 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
871 addr_str);
872 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
873 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200874 spin_unlock_bh(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100875 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
876
877 return i;
878}
879
880static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
881 struct device_attribute *attr, char *buf)
882{
883 struct qeth_card *card = dev_get_drvdata(dev);
884
885 if (!card)
886 return -EINVAL;
887
888 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
889}
890
891static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
892 u8 *addr)
893{
894 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100895 return -EINVAL;
896 }
897 return 0;
898}
899
900static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
901 struct qeth_card *card, enum qeth_prot_versions proto)
902{
903 u8 addr[16] = {0, };
904 int rc;
905
Frank Blaschkac4949f02010-05-11 19:34:47 +0000906 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 rc = qeth_l3_parse_rxipe(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000908 if (!rc)
909 rc = qeth_l3_add_rxip(card, proto, addr);
910 mutex_unlock(&card->conf_mutex);
911 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912}
913
914static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
915 struct device_attribute *attr, const char *buf, size_t count)
916{
917 struct qeth_card *card = dev_get_drvdata(dev);
918
919 if (!card)
920 return -EINVAL;
921
922 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
923}
924
925static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
926 qeth_l3_dev_rxip_add4_show,
927 qeth_l3_dev_rxip_add4_store);
928
929static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
930 struct qeth_card *card, enum qeth_prot_versions proto)
931{
932 u8 addr[16];
933 int rc;
934
Frank Blaschkac4949f02010-05-11 19:34:47 +0000935 mutex_lock(&card->conf_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100936 rc = qeth_l3_parse_rxipe(buf, proto, addr);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000937 if (!rc)
938 qeth_l3_del_rxip(card, proto, addr);
939 mutex_unlock(&card->conf_mutex);
940 return rc ? rc : count;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941}
942
943static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
944 struct device_attribute *attr, const char *buf, size_t count)
945{
946 struct qeth_card *card = dev_get_drvdata(dev);
947
948 if (!card)
949 return -EINVAL;
950
951 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
952}
953
954static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
955 qeth_l3_dev_rxip_del4_store);
956
957static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
958 struct device_attribute *attr, char *buf)
959{
960 struct qeth_card *card = dev_get_drvdata(dev);
961
962 if (!card)
963 return -EINVAL;
964
965 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
966}
967
968static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
969 struct device_attribute *attr, const char *buf, size_t count)
970{
971 struct qeth_card *card = dev_get_drvdata(dev);
972
973 if (!card)
974 return -EINVAL;
975
976 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
977}
978
979static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
980 qeth_l3_dev_rxip_add6_show,
981 qeth_l3_dev_rxip_add6_store);
982
983static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
984 struct device_attribute *attr, const char *buf, size_t count)
985{
986 struct qeth_card *card = dev_get_drvdata(dev);
987
988 if (!card)
989 return -EINVAL;
990
991 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
992}
993
994static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
995 qeth_l3_dev_rxip_del6_store);
996
997static struct attribute *qeth_rxip_device_attrs[] = {
998 &dev_attr_rxip_add4.attr,
999 &dev_attr_rxip_del4.attr,
1000 &dev_attr_rxip_add6.attr,
1001 &dev_attr_rxip_del6.attr,
1002 NULL,
1003};
1004
1005static struct attribute_group qeth_device_rxip_group = {
1006 .name = "rxip",
1007 .attrs = qeth_rxip_device_attrs,
1008};
1009
1010int qeth_l3_create_device_attributes(struct device *dev)
1011{
1012 int ret;
1013
1014 ret = sysfs_create_group(&dev->kobj, &qeth_l3_device_attr_group);
1015 if (ret)
1016 return ret;
1017
1018 ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group);
1019 if (ret) {
1020 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1021 return ret;
1022 }
1023
1024 ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group);
1025 if (ret) {
1026 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1027 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1028 return ret;
1029 }
1030
1031 ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group);
1032 if (ret) {
1033 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1034 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1035 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1036 return ret;
1037 }
1038 return 0;
1039}
1040
1041void qeth_l3_remove_device_attributes(struct device *dev)
1042{
1043 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1044 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1045 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1046 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1047}