upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / drivers / s390 / net / qeth_sys.c
1 /*
2  *
3  * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.40 $)
4  *
5  * Linux on zSeries OSA Express and HiperSockets support
6  * This file contains code related to sysfs.
7  *
8  * Copyright 2000,2003 IBM Corporation
9  *
10  * Author(s): Thomas Spatzier <tspat@de.ibm.com>
11  *            Frank Pavlic <pavlic@de.ibm.com>
12  *
13  */
14 #include <linux/list.h>
15 #include <linux/rwsem.h>
16
17 #include <asm/ebcdic.h>
18
19 #include "qeth.h"
20 #include "qeth_mpc.h"
21 #include "qeth_fs.h"
22
23 const char *VERSION_QETH_SYS_C = "$Revision: 1.40 $";
24
25 /*****************************************************************************/
26 /*                                                                           */
27 /*          /sys-fs stuff UNDER DEVELOPMENT !!!                              */
28 /*                                                                           */
29 /*****************************************************************************/
30 //low/high watermark
31
32 static ssize_t
33 qeth_dev_state_show(struct device *dev, char *buf)
34 {
35         struct qeth_card *card = dev->driver_data;
36         if (!card)
37                 return -EINVAL;
38
39         switch (card->state) {
40         case CARD_STATE_DOWN:
41                 return sprintf(buf, "DOWN\n");
42         case CARD_STATE_HARDSETUP:
43                 return sprintf(buf, "HARDSETUP\n");
44         case CARD_STATE_SOFTSETUP:
45                 return sprintf(buf, "SOFTSETUP\n");
46         case CARD_STATE_UP:
47                 if (card->lan_online)
48                 return sprintf(buf, "UP (LAN ONLINE)\n");
49                 else
50                         return sprintf(buf, "UP (LAN OFFLINE)\n");
51         case CARD_STATE_RECOVER:
52                 return sprintf(buf, "RECOVER\n");
53         default:
54                 return sprintf(buf, "UNKNOWN\n");
55         }
56 }
57
58 static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
59
60 static ssize_t
61 qeth_dev_chpid_show(struct device *dev, char *buf)
62 {
63         struct qeth_card *card = dev->driver_data;
64         if (!card)
65                 return -EINVAL;
66
67         return sprintf(buf, "%02X\n", card->info.chpid);
68 }
69
70 static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
71
72 static ssize_t
73 qeth_dev_if_name_show(struct device *dev, char *buf)
74 {
75         struct qeth_card *card = dev->driver_data;
76         if (!card)
77                 return -EINVAL;
78
79         return sprintf(buf, "%s\n", card->info.if_name);
80 }
81
82 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
83
84 static ssize_t
85 qeth_dev_card_type_show(struct device *dev, char *buf)
86 {
87         struct qeth_card *card = dev->driver_data;
88         if (!card)
89                 return -EINVAL;
90
91         return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
92 }
93
94 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
95
96 static ssize_t
97 qeth_dev_portno_show(struct device *dev, char *buf)
98 {
99         struct qeth_card *card = dev->driver_data;
100         if (!card)
101                 return -EINVAL;
102
103         return sprintf(buf, "%i\n", card->info.portno);
104 }
105
106 static ssize_t
107 qeth_dev_portno_store(struct device *dev, const char *buf, size_t count)
108 {
109         struct qeth_card *card = dev->driver_data;
110         char *tmp;
111         unsigned int portno;
112
113         if (!card)
114                 return -EINVAL;
115
116         if ((card->state != CARD_STATE_DOWN) &&
117             (card->state != CARD_STATE_RECOVER))
118                 return -EPERM;
119
120         portno = simple_strtoul(buf, &tmp, 16);
121         if ((portno < 0) || (portno > MAX_PORTNO)){
122                 PRINT_WARN("portno 0x%X is out of range\n", portno);
123                 return -EINVAL;
124         }
125
126         card->info.portno = portno;
127         return count;
128 }
129
130 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
131
132 static ssize_t
133 qeth_dev_portname_show(struct device *dev, char *buf)
134 {
135         struct qeth_card *card = dev->driver_data;
136         char portname[9] = {0, };
137
138         if (!card)
139                 return -EINVAL;
140
141         if (card->info.portname_required) {
142                 memcpy(portname, card->info.portname + 1, 8);
143                 EBCASC(portname, 8);
144                 return sprintf(buf, "%s\n", portname);
145         } else
146                 return sprintf(buf, "no portname required\n");
147 }
148
149 static ssize_t
150 qeth_dev_portname_store(struct device *dev, const char *buf, size_t count)
151 {
152         struct qeth_card *card = dev->driver_data;
153         char *tmp;
154         int i;
155
156         if (!card)
157                 return -EINVAL;
158
159         if ((card->state != CARD_STATE_DOWN) &&
160             (card->state != CARD_STATE_RECOVER))
161                 return -EPERM;
162
163         tmp = strsep((char **) &buf, "\n");
164         if ((strlen(tmp) > 8) || (strlen(tmp) < 2))
165                 return -EINVAL;
166
167         card->info.portname[0] = strlen(tmp);
168         /* for beauty reasons */
169         for (i = 1; i < 9; i++)
170                 card->info.portname[i] = ' ';
171         strcpy(card->info.portname + 1, tmp);
172         ASCEBC(card->info.portname + 1, 8);
173
174         return count;
175 }
176
177 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
178                 qeth_dev_portname_store);
179
180 static ssize_t
181 qeth_dev_checksum_show(struct device *dev, char *buf)
182 {
183         struct qeth_card *card = dev->driver_data;
184
185         if (!card)
186                 return -EINVAL;
187
188         return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
189 }
190
191 static ssize_t
192 qeth_dev_checksum_store(struct device *dev, const char *buf, size_t count)
193 {
194         struct qeth_card *card = dev->driver_data;
195         char *tmp;
196
197         if (!card)
198                 return -EINVAL;
199
200         if ((card->state != CARD_STATE_DOWN) &&
201             (card->state != CARD_STATE_RECOVER))
202                 return -EPERM;
203
204         tmp = strsep((char **) &buf, "\n");
205         if (!strcmp(tmp, "sw_checksumming"))
206                 card->options.checksum_type = SW_CHECKSUMMING;
207         else if (!strcmp(tmp, "hw_checksumming"))
208                 card->options.checksum_type = HW_CHECKSUMMING;
209         else if (!strcmp(tmp, "no_checksumming"))
210                 card->options.checksum_type = NO_CHECKSUMMING;
211         else {
212                 PRINT_WARN("Unknown checksumming type '%s'\n", tmp);
213                 return -EINVAL;
214         }
215         return count;
216 }
217
218 static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
219                 qeth_dev_checksum_store);
220
221 static ssize_t
222 qeth_dev_prioqing_show(struct device *dev, char *buf)
223 {
224         struct qeth_card *card = dev->driver_data;
225
226         if (!card)
227                 return -EINVAL;
228
229         switch (card->qdio.do_prio_queueing) {
230         case QETH_PRIO_Q_ING_PREC:
231                 return sprintf(buf, "%s\n", "by precedence");
232         case QETH_PRIO_Q_ING_TOS:
233                 return sprintf(buf, "%s\n", "by type of service");
234         default:
235                 return sprintf(buf, "always queue %i\n",
236                                card->qdio.default_out_queue);
237         }
238 }
239
240 static ssize_t
241 qeth_dev_prioqing_store(struct device *dev, const char *buf, size_t count)
242 {
243         struct qeth_card *card = dev->driver_data;
244         char *tmp;
245
246         if (!card)
247                 return -EINVAL;
248
249         if ((card->state != CARD_STATE_DOWN) &&
250             (card->state != CARD_STATE_RECOVER))
251                 return -EPERM;
252
253         tmp = strsep((char **) &buf, "\n");
254         if (!strcmp(tmp, "prio_queueing_prec"))
255                 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
256         else if (!strcmp(tmp, "prio_queueing_tos"))
257                 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
258         else if (!strcmp(tmp, "no_prio_queueing:0")) {
259                 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
260                 card->qdio.default_out_queue = 0;
261         } else if (!strcmp(tmp, "no_prio_queueing:1")) {
262                 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
263                 card->qdio.default_out_queue = 1;
264         } else if (!strcmp(tmp, "no_prio_queueing:2")) {
265                 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
266                 card->qdio.default_out_queue = 2;
267         } else if (!strcmp(tmp, "no_prio_queueing:3")) {
268                 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
269                 card->qdio.default_out_queue = 3;
270         } else if (!strcmp(tmp, "no_prio_queueing")) {
271                 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
272                 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
273         } else {
274                 PRINT_WARN("Unknown queueing type '%s'\n", tmp);
275                 return -EINVAL;
276         }
277         return count;
278 }
279
280 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
281                 qeth_dev_prioqing_store);
282
283 static ssize_t
284 qeth_dev_bufcnt_show(struct device *dev, char *buf)
285 {
286         struct qeth_card *card = dev->driver_data;
287
288         if (!card)
289                 return -EINVAL;
290
291         return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
292 }
293
294 static ssize_t
295 qeth_dev_bufcnt_store(struct device *dev, const char *buf, size_t count)
296 {
297         struct qeth_card *card = dev->driver_data;
298         char *tmp;
299         int cnt, old_cnt;
300         int rc;
301
302         if (!card)
303                 return -EINVAL;
304
305         if ((card->state != CARD_STATE_DOWN) &&
306             (card->state != CARD_STATE_RECOVER))
307                 return -EPERM;
308
309         old_cnt = card->qdio.in_buf_pool.buf_count;
310         cnt = simple_strtoul(buf, &tmp, 10);
311         cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
312                 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
313         if (old_cnt != cnt) {
314                 if ((rc = qeth_realloc_buffer_pool(card, cnt)))
315                         PRINT_WARN("Error (%d) while setting "
316                                    "buffer count.\n", rc);
317         }
318         return count;
319 }
320
321 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
322                 qeth_dev_bufcnt_store);
323
324 static inline ssize_t
325 qeth_dev_route_show(struct qeth_card *card, struct qeth_routing_info *route,
326                     char *buf)
327 {
328         switch (route->type) {
329         case PRIMARY_ROUTER:
330                 return sprintf(buf, "%s\n", "primary router");
331         case SECONDARY_ROUTER:
332                 return sprintf(buf, "%s\n", "secondary router");
333         case MULTICAST_ROUTER:
334                 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
335                         return sprintf(buf, "%s\n", "multicast router+");
336                 else
337                         return sprintf(buf, "%s\n", "multicast router");
338         case PRIMARY_CONNECTOR:
339                 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
340                         return sprintf(buf, "%s\n", "primary connector+");
341                 else
342                         return sprintf(buf, "%s\n", "primary connector");
343         case SECONDARY_CONNECTOR:
344                 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
345                         return sprintf(buf, "%s\n", "secondary connector+");
346                 else
347                         return sprintf(buf, "%s\n", "secondary connector");
348         default:
349                 return sprintf(buf, "%s\n", "no");
350         }
351 }
352
353 static ssize_t
354 qeth_dev_route4_show(struct device *dev, char *buf)
355 {
356         struct qeth_card *card = dev->driver_data;
357
358         if (!card)
359                 return -EINVAL;
360
361         return qeth_dev_route_show(card, &card->options.route4, buf);
362 }
363
364 static inline ssize_t
365 qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
366                 enum qeth_prot_versions prot, const char *buf, size_t count)
367 {
368         enum qeth_routing_types old_route_type = route->type;
369         char *tmp;
370         int rc;
371
372         tmp = strsep((char **) &buf, "\n");
373
374         if (!strcmp(tmp, "no_router")){
375                 route->type = NO_ROUTER;
376         } else if (!strcmp(tmp, "primary_connector")) {
377                 route->type = PRIMARY_CONNECTOR;
378         } else if (!strcmp(tmp, "secondary_connector")) {
379                 route->type = SECONDARY_CONNECTOR;
380         } else if (!strcmp(tmp, "multicast_router")) {
381                 route->type = MULTICAST_ROUTER;
382         } else if (!strcmp(tmp, "primary_router")) {
383                 route->type = PRIMARY_ROUTER;
384         } else if (!strcmp(tmp, "secondary_router")) {
385                 route->type = SECONDARY_ROUTER;
386         } else if (!strcmp(tmp, "multicast_router")) {
387                 route->type = MULTICAST_ROUTER;
388         } else {
389                 PRINT_WARN("Invalid routing type '%s'.\n", tmp);
390                 return -EINVAL;
391         }
392         if (((card->state == CARD_STATE_SOFTSETUP) ||
393              (card->state == CARD_STATE_UP)) &&
394             (old_route_type != route->type)){
395                 if (prot == QETH_PROT_IPV4)
396                         rc = qeth_setrouting_v4(card);
397                 else if (prot == QETH_PROT_IPV6)
398                         rc = qeth_setrouting_v6(card);
399         }
400         return count;
401 }
402
403 static ssize_t
404 qeth_dev_route4_store(struct device *dev, const char *buf, size_t count)
405 {
406         struct qeth_card *card = dev->driver_data;
407
408         if (!card)
409                 return -EINVAL;
410
411         return qeth_dev_route_store(card, &card->options.route4,
412                                     QETH_PROT_IPV4, buf, count);
413 }
414
415 static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
416
417 #ifdef CONFIG_QETH_IPV6
418 static ssize_t
419 qeth_dev_route6_show(struct device *dev, char *buf)
420 {
421         struct qeth_card *card = dev->driver_data;
422
423         if (!card)
424                 return -EINVAL;
425
426         if (!qeth_is_supported(card, IPA_IPV6))
427                 return sprintf(buf, "%s\n", "n/a");
428
429         return qeth_dev_route_show(card, &card->options.route6, buf);
430 }
431
432 static ssize_t
433 qeth_dev_route6_store(struct device *dev, const char *buf, size_t count)
434 {
435         struct qeth_card *card = dev->driver_data;
436
437         if (!card)
438                 return -EINVAL;
439
440         if (!qeth_is_supported(card, IPA_IPV6)){
441                 PRINT_WARN("IPv6 not supported for interface %s.\n"
442                            "Routing status no changed.\n",
443                            card->info.if_name);
444                 return -ENOTSUPP;
445         }
446
447         return qeth_dev_route_store(card, &card->options.route6,
448                                     QETH_PROT_IPV6, buf, count);
449 }
450
451 static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
452 #endif
453
454 static ssize_t
455 qeth_dev_add_hhlen_show(struct device *dev, char *buf)
456 {
457         struct qeth_card *card = dev->driver_data;
458
459         if (!card)
460                 return -EINVAL;
461
462         return sprintf(buf, "%i\n", card->options.add_hhlen);
463 }
464
465 static ssize_t
466 qeth_dev_add_hhlen_store(struct device *dev, const char *buf, size_t count)
467 {
468         struct qeth_card *card = dev->driver_data;
469         char *tmp;
470         int i;
471
472         if (!card)
473                 return -EINVAL;
474
475         if ((card->state != CARD_STATE_DOWN) &&
476             (card->state != CARD_STATE_RECOVER))
477                 return -EPERM;
478
479         i = simple_strtoul(buf, &tmp, 10);
480         if ((i < 0) || (i > MAX_ADD_HHLEN)) {
481                 PRINT_WARN("add_hhlen out of range\n");
482                 return -EINVAL;
483         }
484         card->options.add_hhlen = i;
485
486         return count;
487 }
488
489 static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
490                    qeth_dev_add_hhlen_store);
491
492 static ssize_t
493 qeth_dev_fake_ll_show(struct device *dev, char *buf)
494 {
495         struct qeth_card *card = dev->driver_data;
496
497         if (!card)
498                 return -EINVAL;
499
500         return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
501 }
502
503 static ssize_t
504 qeth_dev_fake_ll_store(struct device *dev, const char *buf, size_t count)
505 {
506         struct qeth_card *card = dev->driver_data;
507         char *tmp;
508         int i;
509
510         if (!card)
511                 return -EINVAL;
512
513         if ((card->state != CARD_STATE_DOWN) &&
514             (card->state != CARD_STATE_RECOVER))
515                 return -EPERM;
516
517         i = simple_strtoul(buf, &tmp, 16);
518         if ((i == 0) || (i == 1))
519                 card->options.fake_ll = i;
520         else {
521                 PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
522                 return -EINVAL;
523         }
524         return count;
525 }
526
527 static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
528                    qeth_dev_fake_ll_store);
529
530 static ssize_t
531 qeth_dev_fake_broadcast_show(struct device *dev, char *buf)
532 {
533         struct qeth_card *card = dev->driver_data;
534
535         if (!card)
536                 return -EINVAL;
537
538         return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
539 }
540
541 static ssize_t
542 qeth_dev_fake_broadcast_store(struct device *dev, const char *buf, size_t count)
543 {
544         struct qeth_card *card = dev->driver_data;
545         char *tmp;
546         int i;
547
548         if (!card)
549                 return -EINVAL;
550
551         if ((card->state != CARD_STATE_DOWN) &&
552             (card->state != CARD_STATE_RECOVER))
553                 return -EPERM;
554
555         i = simple_strtoul(buf, &tmp, 16);
556         if ((i == 0) || (i == 1))
557                 card->options.fake_broadcast = i;
558         else {
559                 PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
560                 return -EINVAL;
561         }
562         return count;
563 }
564
565 static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
566                    qeth_dev_fake_broadcast_store);
567
568 static ssize_t
569 qeth_dev_recover_store(struct device *dev, const char *buf, size_t count)
570 {
571         struct qeth_card *card = dev->driver_data;
572         char *tmp;
573         int i;
574
575         if (!card)
576                 return -EINVAL;
577
578         if (card->state != CARD_STATE_UP)
579                 return -EPERM;
580
581         i = simple_strtoul(buf, &tmp, 16);
582         if (i == 1)
583                 qeth_schedule_recovery(card);
584
585         return count;
586 }
587
588 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
589
590 static ssize_t
591 qeth_dev_broadcast_mode_show(struct device *dev, char *buf)
592 {
593         struct qeth_card *card = dev->driver_data;
594
595         if (!card)
596                 return -EINVAL;
597
598         if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
599               (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
600                 return sprintf(buf, "n/a\n");
601
602         return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
603                                      QETH_TR_BROADCAST_ALLRINGS)?
604                        "all rings":"local");
605 }
606
607 static ssize_t
608 qeth_dev_broadcast_mode_store(struct device *dev, const char *buf, size_t count)
609 {
610         struct qeth_card *card = dev->driver_data;
611         char *tmp;
612
613         if (!card)
614                 return -EINVAL;
615
616         if ((card->state != CARD_STATE_DOWN) &&
617             (card->state != CARD_STATE_RECOVER))
618                 return -EPERM;
619
620         if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
621               (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
622                 PRINT_WARN("Device is not a tokenring device!\n");
623                 return -EINVAL;
624         }
625
626         tmp = strsep((char **) &buf, "\n");
627
628         if (!strcmp(tmp, "local")){
629                 card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
630                 return count;
631         } else if (!strcmp(tmp, "all_rings")) {
632                 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
633                 return count;
634         } else {
635                 PRINT_WARN("broadcast_mode: invalid mode %s!\n",
636                            tmp);
637                 return -EINVAL;
638         }
639         return count;
640 }
641
642 static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
643                    qeth_dev_broadcast_mode_store);
644
645 static ssize_t
646 qeth_dev_canonical_macaddr_show(struct device *dev, char *buf)
647 {
648         struct qeth_card *card = dev->driver_data;
649
650         if (!card)
651                 return -EINVAL;
652
653         if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
654               (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
655                 return sprintf(buf, "n/a\n");
656
657         return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
658                                      QETH_TR_MACADDR_CANONICAL)? 1:0);
659 }
660
661 static ssize_t
662 qeth_dev_canonical_macaddr_store(struct device *dev, const char *buf,
663                                   size_t count)
664 {
665         struct qeth_card *card = dev->driver_data;
666         char *tmp;
667         int i;
668
669         if (!card)
670                 return -EINVAL;
671
672         if ((card->state != CARD_STATE_DOWN) &&
673             (card->state != CARD_STATE_RECOVER))
674                 return -EPERM;
675
676         if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
677               (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
678                 PRINT_WARN("Device is not a tokenring device!\n");
679                 return -EINVAL;
680         }
681
682         i = simple_strtoul(buf, &tmp, 16);
683         if ((i == 0) || (i == 1))
684                 card->options.macaddr_mode = i?
685                         QETH_TR_MACADDR_CANONICAL :
686                         QETH_TR_MACADDR_NONCANONICAL;
687         else {
688                 PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
689                 return -EINVAL;
690         }
691         return count;
692 }
693
694 static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
695                    qeth_dev_canonical_macaddr_store);
696
697 static ssize_t
698 qeth_dev_layer2_show(struct device *dev, char *buf)
699 {
700         struct qeth_card *card = dev->driver_data;
701
702         if (!card)
703                 return -EINVAL;
704
705         return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
706 }
707
708 static ssize_t
709 qeth_dev_layer2_store(struct device *dev, const char *buf, size_t count)
710 {
711         struct qeth_card *card = dev->driver_data;
712         char *tmp;
713         int i;
714
715         if (!card)
716                 return -EINVAL;
717
718         if ((card->state != CARD_STATE_DOWN) &&
719             (card->state != CARD_STATE_RECOVER))
720                 return -EPERM;
721
722         i = simple_strtoul(buf, &tmp, 16);
723         if ((i == 0) || (i == 1))
724                 card->options.layer2 = i;
725         else {
726                 PRINT_WARN("layer2: write 0 or 1 to this file!\n");
727                 return -EINVAL;
728         }
729         return count;
730 }
731
732 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
733                    qeth_dev_layer2_store);
734
735 static struct device_attribute * qeth_device_attrs[] = {
736         &dev_attr_state,
737         &dev_attr_chpid,
738         &dev_attr_if_name,
739         &dev_attr_card_type,
740         &dev_attr_portno,
741         &dev_attr_portname,
742         &dev_attr_checksumming,
743         &dev_attr_priority_queueing,
744         &dev_attr_buffer_count,
745         &dev_attr_route4,
746 #ifdef CONFIG_QETH_IPV6
747         &dev_attr_route6,
748 #endif
749         &dev_attr_add_hhlen,
750         &dev_attr_fake_ll,
751         &dev_attr_fake_broadcast,
752         &dev_attr_recover,
753         &dev_attr_broadcast_mode,
754         &dev_attr_canonical_macaddr,
755         &dev_attr_layer2,
756         NULL,
757 };
758
759 static struct attribute_group qeth_device_attr_group = {
760         .attrs = (struct attribute **)qeth_device_attrs,
761 };
762
763
764 #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store)                       \
765 struct device_attribute dev_attr_##_id = {                                   \
766         .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
767         .show   = _show,                                                     \
768         .store  = _store,                                                    \
769 };
770
771 int
772 qeth_check_layer2(struct qeth_card *card)
773 {
774         if (card->options.layer2)
775                 return -EPERM;
776         return 0;
777 }
778
779
780 static ssize_t
781 qeth_dev_ipato_enable_show(struct device *dev, char *buf)
782 {
783         struct qeth_card *card = dev->driver_data;
784
785         if (!card)
786                 return -EINVAL;
787
788         if (qeth_check_layer2(card))
789                 return -EPERM;
790         return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
791 }
792
793 static ssize_t
794 qeth_dev_ipato_enable_store(struct device *dev, const char *buf, size_t count)
795 {
796         struct qeth_card *card = dev->driver_data;
797         char *tmp;
798
799         if (!card)
800                 return -EINVAL;
801
802         if ((card->state != CARD_STATE_DOWN) &&
803             (card->state != CARD_STATE_RECOVER))
804                 return -EPERM;
805
806         if (qeth_check_layer2(card))
807                 return -EPERM;
808
809         tmp = strsep((char **) &buf, "\n");
810         if (!strcmp(tmp, "toggle")){
811                 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
812         } else if (!strcmp(tmp, "1")){
813                 card->ipato.enabled = 1;
814         } else if (!strcmp(tmp, "0")){
815                 card->ipato.enabled = 0;
816         } else {
817                 PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
818                            "this file\n");
819                 return -EINVAL;
820         }
821         return count;
822 }
823
824 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
825                         qeth_dev_ipato_enable_show,
826                         qeth_dev_ipato_enable_store);
827
828 static ssize_t
829 qeth_dev_ipato_invert4_show(struct device *dev, char *buf)
830 {
831         struct qeth_card *card = dev->driver_data;
832
833         if (!card)
834                 return -EINVAL;
835
836         if (qeth_check_layer2(card))
837                 return -EPERM;
838
839         return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
840 }
841
842 static ssize_t
843 qeth_dev_ipato_invert4_store(struct device *dev, const char *buf, size_t count)
844 {
845         struct qeth_card *card = dev->driver_data;
846         char *tmp;
847
848         if (!card)
849                 return -EINVAL;
850
851         if (qeth_check_layer2(card))
852                 return -EPERM;
853
854         tmp = strsep((char **) &buf, "\n");
855         if (!strcmp(tmp, "toggle")){
856                 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
857         } else if (!strcmp(tmp, "1")){
858                 card->ipato.invert4 = 1;
859         } else if (!strcmp(tmp, "0")){
860                 card->ipato.invert4 = 0;
861         } else {
862                 PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
863                            "this file\n");
864                 return -EINVAL;
865         }
866         return count;
867 }
868
869 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
870                         qeth_dev_ipato_invert4_show,
871                         qeth_dev_ipato_invert4_store);
872
873 static inline ssize_t
874 qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
875                         enum qeth_prot_versions proto)
876 {
877         struct qeth_ipato_entry *ipatoe;
878         unsigned long flags;
879         char addr_str[40];
880         int entry_len; /* length of 1 entry string, differs between v4 and v6 */
881         int i = 0;
882
883         if (qeth_check_layer2(card))
884                 return -EPERM;
885
886         entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
887         /* add strlen for "/<mask>\n" */
888         entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
889         spin_lock_irqsave(&card->ip_lock, flags);
890         list_for_each_entry(ipatoe, &card->ipato.entries, entry){
891                 if (ipatoe->proto != proto)
892                         continue;
893                 /* String must not be longer than PAGE_SIZE. So we check if
894                  * string length gets near PAGE_SIZE. Then we can savely display
895                  * the next IPv6 address (worst case, compared to IPv4) */
896                 if ((PAGE_SIZE - i) <= entry_len)
897                         break;
898                 qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
899                 i += snprintf(buf + i, PAGE_SIZE - i,
900                               "%s/%i\n", addr_str, ipatoe->mask_bits);
901         }
902         spin_unlock_irqrestore(&card->ip_lock, flags);
903         i += snprintf(buf + i, PAGE_SIZE - i, "\n");
904
905         return i;
906 }
907
908 static ssize_t
909 qeth_dev_ipato_add4_show(struct device *dev, char *buf)
910 {
911         struct qeth_card *card = dev->driver_data;
912
913         if (!card)
914                 return -EINVAL;
915
916         return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
917 }
918
919 static inline int
920 qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
921                   u8 *addr, int *mask_bits)
922 {
923         const char *start, *end;
924         char *tmp;
925         char buffer[49] = {0, };
926
927         start = buf;
928         /* get address string */
929         end = strchr(start, '/');
930         if (!end){
931                 PRINT_WARN("Invalid format for ipato_addx/delx. "
932                            "Use <ip addr>/<mask bits>\n");
933                 return -EINVAL;
934         }
935         strncpy(buffer, start, end - start);
936         if (qeth_string_to_ipaddr(buffer, proto, addr)){
937                 PRINT_WARN("Invalid IP address format!\n");
938                 return -EINVAL;
939         }
940         start = end + 1;
941         *mask_bits = simple_strtoul(start, &tmp, 10);
942
943         return 0;
944 }
945
946 static inline ssize_t
947 qeth_dev_ipato_add_store(const char *buf, size_t count,
948                          struct qeth_card *card, enum qeth_prot_versions proto)
949 {
950         struct qeth_ipato_entry *ipatoe;
951         u8 addr[16];
952         int mask_bits;
953         int rc;
954
955         if (qeth_check_layer2(card))
956                 return -EPERM;
957         if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
958                 return rc;
959
960         if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
961                 PRINT_WARN("No memory to allocate ipato entry\n");
962                 return -ENOMEM;
963         }
964         memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
965         ipatoe->proto = proto;
966         memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
967         ipatoe->mask_bits = mask_bits;
968
969         if ((rc = qeth_add_ipato_entry(card, ipatoe))){
970                 kfree(ipatoe);
971                 return rc;
972         }
973
974         return count;
975 }
976
977 static ssize_t
978 qeth_dev_ipato_add4_store(struct device *dev, const char *buf, size_t count)
979 {
980         struct qeth_card *card = dev->driver_data;
981
982         if (!card)
983                 return -EINVAL;
984
985         return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
986 }
987
988 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
989                         qeth_dev_ipato_add4_show,
990                         qeth_dev_ipato_add4_store);
991
992 static inline ssize_t
993 qeth_dev_ipato_del_store(const char *buf, size_t count,
994                          struct qeth_card *card, enum qeth_prot_versions proto)
995 {
996         u8 addr[16];
997         int mask_bits;
998         int rc;
999
1000         if (qeth_check_layer2(card))
1001                 return -EPERM;
1002         if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1003                 return rc;
1004
1005         qeth_del_ipato_entry(card, proto, addr, mask_bits);
1006
1007         return count;
1008 }
1009
1010 static ssize_t
1011 qeth_dev_ipato_del4_store(struct device *dev, const char *buf, size_t count)
1012 {
1013         struct qeth_card *card = dev->driver_data;
1014
1015         if (!card)
1016                 return -EINVAL;
1017
1018         return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
1019 }
1020
1021 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
1022                         qeth_dev_ipato_del4_store);
1023
1024 #ifdef CONFIG_QETH_IPV6
1025 static ssize_t
1026 qeth_dev_ipato_invert6_show(struct device *dev, char *buf)
1027 {
1028         struct qeth_card *card = dev->driver_data;
1029
1030         if (!card)
1031                 return -EINVAL;
1032
1033         if (qeth_check_layer2(card))
1034                 return -EPERM;
1035
1036         return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
1037 }
1038
1039 static ssize_t
1040 qeth_dev_ipato_invert6_store(struct device *dev, const char *buf, size_t count)
1041 {
1042         struct qeth_card *card = dev->driver_data;
1043         char *tmp;
1044
1045         if (!card)
1046                 return -EINVAL;
1047
1048         if (qeth_check_layer2(card))
1049                 return -EPERM;
1050
1051         tmp = strsep((char **) &buf, "\n");
1052         if (!strcmp(tmp, "toggle")){
1053                 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
1054         } else if (!strcmp(tmp, "1")){
1055                 card->ipato.invert6 = 1;
1056         } else if (!strcmp(tmp, "0")){
1057                 card->ipato.invert6 = 0;
1058         } else {
1059                 PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
1060                            "this file\n");
1061                 return -EINVAL;
1062         }
1063         return count;
1064 }
1065
1066 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
1067                         qeth_dev_ipato_invert6_show,
1068                         qeth_dev_ipato_invert6_store);
1069
1070
1071 static ssize_t
1072 qeth_dev_ipato_add6_show(struct device *dev, char *buf)
1073 {
1074         struct qeth_card *card = dev->driver_data;
1075
1076         if (!card)
1077                 return -EINVAL;
1078
1079         return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
1080 }
1081
1082 static ssize_t
1083 qeth_dev_ipato_add6_store(struct device *dev, const char *buf, size_t count)
1084 {
1085         struct qeth_card *card = dev->driver_data;
1086
1087         if (!card)
1088                 return -EINVAL;
1089
1090         return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
1091 }
1092
1093 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
1094                         qeth_dev_ipato_add6_show,
1095                         qeth_dev_ipato_add6_store);
1096
1097 static ssize_t
1098 qeth_dev_ipato_del6_store(struct device *dev, const char *buf, size_t count)
1099 {
1100         struct qeth_card *card = dev->driver_data;
1101
1102         if (!card)
1103                 return -EINVAL;
1104
1105         return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
1106 }
1107
1108 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
1109                         qeth_dev_ipato_del6_store);
1110 #endif /* CONFIG_QETH_IPV6 */
1111
1112 static struct device_attribute * qeth_ipato_device_attrs[] = {
1113         &dev_attr_ipato_enable,
1114         &dev_attr_ipato_invert4,
1115         &dev_attr_ipato_add4,
1116         &dev_attr_ipato_del4,
1117 #ifdef CONFIG_QETH_IPV6
1118         &dev_attr_ipato_invert6,
1119         &dev_attr_ipato_add6,
1120         &dev_attr_ipato_del6,
1121 #endif
1122         NULL,
1123 };
1124
1125 static struct attribute_group qeth_device_ipato_group = {
1126         .name = "ipa_takeover",
1127         .attrs = (struct attribute **)qeth_ipato_device_attrs,
1128 };
1129
1130 static inline ssize_t
1131 qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
1132                         enum qeth_prot_versions proto)
1133 {
1134         struct qeth_ipaddr *ipaddr;
1135         char addr_str[40];
1136         int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1137         unsigned long flags;
1138         int i = 0;
1139
1140         if (qeth_check_layer2(card))
1141                 return -EPERM;
1142
1143         entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1144         entry_len += 2; /* \n + terminator */
1145         spin_lock_irqsave(&card->ip_lock, flags);
1146         list_for_each_entry(ipaddr, &card->ip_list, entry){
1147                 if (ipaddr->proto != proto)
1148                         continue;
1149                 if (ipaddr->type != QETH_IP_TYPE_VIPA)
1150                         continue;
1151                 /* String must not be longer than PAGE_SIZE. So we check if
1152                  * string length gets near PAGE_SIZE. Then we can savely display
1153                  * the next IPv6 address (worst case, compared to IPv4) */
1154                 if ((PAGE_SIZE - i) <= entry_len)
1155                         break;
1156                 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1157                 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1158         }
1159         spin_unlock_irqrestore(&card->ip_lock, flags);
1160         i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1161
1162         return i;
1163 }
1164
1165 static ssize_t
1166 qeth_dev_vipa_add4_show(struct device *dev, char *buf)
1167 {
1168         struct qeth_card *card = dev->driver_data;
1169
1170         if (!card)
1171                 return -EINVAL;
1172
1173         return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
1174 }
1175
1176 static inline int
1177 qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
1178                  u8 *addr)
1179 {
1180         if (qeth_string_to_ipaddr(buf, proto, addr)){
1181                 PRINT_WARN("Invalid IP address format!\n");
1182                 return -EINVAL;
1183         }
1184         return 0;
1185 }
1186
1187 static inline ssize_t
1188 qeth_dev_vipa_add_store(const char *buf, size_t count,
1189                          struct qeth_card *card, enum qeth_prot_versions proto)
1190 {
1191         u8 addr[16] = {0, };
1192         int rc;
1193
1194         if (qeth_check_layer2(card))
1195                 return -EPERM;
1196         if ((rc = qeth_parse_vipae(buf, proto, addr)))
1197                 return rc;
1198
1199         if ((rc = qeth_add_vipa(card, proto, addr)))
1200                 return rc;
1201
1202         return count;
1203 }
1204
1205 static ssize_t
1206 qeth_dev_vipa_add4_store(struct device *dev, const char *buf, size_t count)
1207 {
1208         struct qeth_card *card = dev->driver_data;
1209
1210         if (!card)
1211                 return -EINVAL;
1212
1213         return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
1214 }
1215
1216 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
1217                         qeth_dev_vipa_add4_show,
1218                         qeth_dev_vipa_add4_store);
1219
1220 static inline ssize_t
1221 qeth_dev_vipa_del_store(const char *buf, size_t count,
1222                          struct qeth_card *card, enum qeth_prot_versions proto)
1223 {
1224         u8 addr[16];
1225         int rc;
1226
1227         if (qeth_check_layer2(card))
1228                 return -EPERM;
1229         if ((rc = qeth_parse_vipae(buf, proto, addr)))
1230                 return rc;
1231
1232         qeth_del_vipa(card, proto, addr);
1233
1234         return count;
1235 }
1236
1237 static ssize_t
1238 qeth_dev_vipa_del4_store(struct device *dev, const char *buf, size_t count)
1239 {
1240         struct qeth_card *card = dev->driver_data;
1241
1242         if (!card)
1243                 return -EINVAL;
1244
1245         return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
1246 }
1247
1248 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
1249                         qeth_dev_vipa_del4_store);
1250
1251 #ifdef CONFIG_QETH_IPV6
1252 static ssize_t
1253 qeth_dev_vipa_add6_show(struct device *dev, char *buf)
1254 {
1255         struct qeth_card *card = dev->driver_data;
1256
1257         if (!card)
1258                 return -EINVAL;
1259
1260         return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
1261 }
1262
1263 static ssize_t
1264 qeth_dev_vipa_add6_store(struct device *dev, const char *buf, size_t count)
1265 {
1266         struct qeth_card *card = dev->driver_data;
1267
1268         if (!card)
1269                 return -EINVAL;
1270
1271         return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
1272 }
1273
1274 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
1275                         qeth_dev_vipa_add6_show,
1276                         qeth_dev_vipa_add6_store);
1277
1278 static ssize_t
1279 qeth_dev_vipa_del6_store(struct device *dev, const char *buf, size_t count)
1280 {
1281         struct qeth_card *card = dev->driver_data;
1282
1283         if (!card)
1284                 return -EINVAL;
1285
1286         if (qeth_check_layer2(card))
1287                 return -EPERM;
1288
1289         return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
1290 }
1291
1292 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
1293                         qeth_dev_vipa_del6_store);
1294 #endif /* CONFIG_QETH_IPV6 */
1295
1296 static struct device_attribute * qeth_vipa_device_attrs[] = {
1297         &dev_attr_vipa_add4,
1298         &dev_attr_vipa_del4,
1299 #ifdef CONFIG_QETH_IPV6
1300         &dev_attr_vipa_add6,
1301         &dev_attr_vipa_del6,
1302 #endif
1303         NULL,
1304 };
1305
1306 static struct attribute_group qeth_device_vipa_group = {
1307         .name = "vipa",
1308         .attrs = (struct attribute **)qeth_vipa_device_attrs,
1309 };
1310
1311 static inline ssize_t
1312 qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
1313                        enum qeth_prot_versions proto)
1314 {
1315         struct qeth_ipaddr *ipaddr;
1316         char addr_str[40];
1317         int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1318         unsigned long flags;
1319         int i = 0;
1320
1321         if (qeth_check_layer2(card))
1322                 return -EPERM;
1323
1324         entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1325         entry_len += 2; /* \n + terminator */
1326         spin_lock_irqsave(&card->ip_lock, flags);
1327         list_for_each_entry(ipaddr, &card->ip_list, entry){
1328                 if (ipaddr->proto != proto)
1329                         continue;
1330                 if (ipaddr->type != QETH_IP_TYPE_RXIP)
1331                         continue;
1332                 /* String must not be longer than PAGE_SIZE. So we check if
1333                  * string length gets near PAGE_SIZE. Then we can savely display
1334                  * the next IPv6 address (worst case, compared to IPv4) */
1335                 if ((PAGE_SIZE - i) <= entry_len)
1336                         break;
1337                 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1338                 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1339         }
1340         spin_unlock_irqrestore(&card->ip_lock, flags);
1341         i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1342
1343         return i;
1344 }
1345
1346 static ssize_t
1347 qeth_dev_rxip_add4_show(struct device *dev, char *buf)
1348 {
1349         struct qeth_card *card = dev->driver_data;
1350
1351         if (!card)
1352                 return -EINVAL;
1353
1354         return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
1355 }
1356
1357 static inline int
1358 qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
1359                  u8 *addr)
1360 {
1361         if (qeth_string_to_ipaddr(buf, proto, addr)){
1362                 PRINT_WARN("Invalid IP address format!\n");
1363                 return -EINVAL;
1364         }
1365         return 0;
1366 }
1367
1368 static inline ssize_t
1369 qeth_dev_rxip_add_store(const char *buf, size_t count,
1370                         struct qeth_card *card, enum qeth_prot_versions proto)
1371 {
1372         u8 addr[16] = {0, };
1373         int rc;
1374
1375         if (qeth_check_layer2(card))
1376                 return -EPERM;
1377         if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1378                 return rc;
1379
1380         if ((rc = qeth_add_rxip(card, proto, addr)))
1381                 return rc;
1382
1383         return count;
1384 }
1385
1386 static ssize_t
1387 qeth_dev_rxip_add4_store(struct device *dev, const char *buf, size_t count)
1388 {
1389         struct qeth_card *card = dev->driver_data;
1390
1391         if (!card)
1392                 return -EINVAL;
1393
1394         return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
1395 }
1396
1397 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
1398                         qeth_dev_rxip_add4_show,
1399                         qeth_dev_rxip_add4_store);
1400
1401 static inline ssize_t
1402 qeth_dev_rxip_del_store(const char *buf, size_t count,
1403                         struct qeth_card *card, enum qeth_prot_versions proto)
1404 {
1405         u8 addr[16];
1406         int rc;
1407
1408         if (qeth_check_layer2(card))
1409                 return -EPERM;
1410         if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1411                 return rc;
1412
1413         qeth_del_rxip(card, proto, addr);
1414
1415         return count;
1416 }
1417
1418 static ssize_t
1419 qeth_dev_rxip_del4_store(struct device *dev, const char *buf, size_t count)
1420 {
1421         struct qeth_card *card = dev->driver_data;
1422
1423         if (!card)
1424                 return -EINVAL;
1425
1426         return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
1427 }
1428
1429 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
1430                         qeth_dev_rxip_del4_store);
1431
1432 #ifdef CONFIG_QETH_IPV6
1433 static ssize_t
1434 qeth_dev_rxip_add6_show(struct device *dev, char *buf)
1435 {
1436         struct qeth_card *card = dev->driver_data;
1437
1438         if (!card)
1439                 return -EINVAL;
1440
1441         return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
1442 }
1443
1444 static ssize_t
1445 qeth_dev_rxip_add6_store(struct device *dev, const char *buf, size_t count)
1446 {
1447         struct qeth_card *card = dev->driver_data;
1448
1449         if (!card)
1450                 return -EINVAL;
1451
1452         return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1453 }
1454
1455 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1456                         qeth_dev_rxip_add6_show,
1457                         qeth_dev_rxip_add6_store);
1458
1459 static ssize_t
1460 qeth_dev_rxip_del6_store(struct device *dev, const char *buf, size_t count)
1461 {
1462         struct qeth_card *card = dev->driver_data;
1463
1464         if (!card)
1465                 return -EINVAL;
1466
1467         return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1468 }
1469
1470 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1471                         qeth_dev_rxip_del6_store);
1472 #endif /* CONFIG_QETH_IPV6 */
1473
1474 static struct device_attribute * qeth_rxip_device_attrs[] = {
1475         &dev_attr_rxip_add4,
1476         &dev_attr_rxip_del4,
1477 #ifdef CONFIG_QETH_IPV6
1478         &dev_attr_rxip_add6,
1479         &dev_attr_rxip_del6,
1480 #endif
1481         NULL,
1482 };
1483
1484 static struct attribute_group qeth_device_rxip_group = {
1485         .name = "rxip",
1486         .attrs = (struct attribute **)qeth_rxip_device_attrs,
1487 };
1488
1489 int
1490 qeth_create_device_attributes(struct device *dev)
1491 {
1492         int ret;
1493
1494         if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1495                 return ret;
1496         if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
1497                 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1498                 return ret;
1499         }
1500         if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
1501                 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1502                 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1503                 return ret;
1504         }
1505         if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
1506                 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1507                 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1508                 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1509         }
1510
1511         return ret;
1512 }
1513
1514 void
1515 qeth_remove_device_attributes(struct device *dev)
1516 {
1517         sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1518         sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1519         sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1520         sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1521 }
1522
1523 /**********************/
1524 /* DRIVER ATTRIBUTES  */
1525 /**********************/
1526 static ssize_t
1527 qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1528                         size_t count)
1529 {
1530         const char *start, *end;
1531         char bus_ids[3][BUS_ID_SIZE], *argv[3];
1532         int i;
1533         int err;
1534
1535         start = buf;
1536         for (i = 0; i < 3; i++) {
1537                 static const char delim[] = { ',', ',', '\n' };
1538                 int len;
1539
1540                 if (!(end = strchr(start, delim[i])))
1541                         return -EINVAL;
1542                 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
1543                 strncpy(bus_ids[i], start, len);
1544                 bus_ids[i][len] = '\0';
1545                 start = end + 1;
1546                 argv[i] = bus_ids[i];
1547         }
1548         err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
1549                         &qeth_ccw_driver, 3, argv);
1550         if (err)
1551                 return err;
1552         else
1553                 return count;
1554 }
1555
1556
1557 static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
1558
1559 static ssize_t
1560 qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
1561                                 size_t count)
1562 {
1563         int rc;
1564         int signum;
1565         char *tmp, *tmp2;
1566
1567         tmp = strsep((char **) &buf, "\n");
1568         if (!strncmp(tmp, "unregister", 10)){
1569                 if ((rc = qeth_notifier_unregister(current)))
1570                         return rc;
1571                 return count;
1572         }
1573
1574         signum = simple_strtoul(tmp, &tmp2, 10);
1575         if ((signum < 0) || (signum > 32)){
1576                 PRINT_WARN("Signal number %d is out of range\n", signum);
1577                 return -EINVAL;
1578         }
1579         if ((rc = qeth_notifier_register(current, signum)))
1580                 return rc;
1581
1582         return count;
1583 }
1584
1585 static DRIVER_ATTR(notifier_register, 0200, 0,
1586                    qeth_driver_notifier_register_store);
1587
1588 int
1589 qeth_create_driver_attributes(void)
1590 {
1591         int rc;
1592
1593         if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
1594                                      &driver_attr_group)))
1595                 return rc;
1596         return driver_create_file(&qeth_ccwgroup_driver.driver,
1597                                   &driver_attr_notifier_register);
1598 }
1599
1600 void
1601 qeth_remove_driver_attributes(void)
1602 {
1603         driver_remove_file(&qeth_ccwgroup_driver.driver,
1604                         &driver_attr_group);
1605         driver_remove_file(&qeth_ccwgroup_driver.driver,
1606                         &driver_attr_notifier_register);
1607 }