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