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