NTFS: Add a missing call to flush_dcache_mft_record_page() in
[linux-2.6/cjktty.git] / drivers / s390 / net / qeth_sys.c
blobf2a076a2b2f1b26469f28282c8153b412df2c727
1 /*
3 * linux/drivers/s390/net/qeth_sys.c
5 * Linux on zSeries OSA Express and HiperSockets support
6 * This file contains code related to sysfs.
8 * Copyright 2000,2003 IBM Corporation
10 * Author(s): Thomas Spatzier <tspat@de.ibm.com>
11 * Frank Pavlic <fpavlic@de.ibm.com>
14 #include <linux/list.h>
15 #include <linux/rwsem.h>
17 #include <asm/ebcdic.h>
19 #include "qeth.h"
20 #include "qeth_mpc.h"
21 #include "qeth_fs.h"
23 /*****************************************************************************/
24 /* */
25 /* /sys-fs stuff UNDER DEVELOPMENT !!! */
26 /* */
27 /*****************************************************************************/
28 //low/high watermark
30 static ssize_t
31 qeth_dev_state_show(struct device *dev, struct device_attribute *attr, char *buf)
33 struct qeth_card *card = dev->driver_data;
34 if (!card)
35 return -EINVAL;
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");
56 static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
58 static ssize_t
59 qeth_dev_chpid_show(struct device *dev, struct device_attribute *attr, char *buf)
61 struct qeth_card *card = dev->driver_data;
62 if (!card)
63 return -EINVAL;
65 return sprintf(buf, "%02X\n", card->info.chpid);
68 static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
70 static ssize_t
71 qeth_dev_if_name_show(struct device *dev, struct device_attribute *attr, char *buf)
73 struct qeth_card *card = dev->driver_data;
74 if (!card)
75 return -EINVAL;
76 return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
79 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
81 static ssize_t
82 qeth_dev_card_type_show(struct device *dev, struct device_attribute *attr, char *buf)
84 struct qeth_card *card = dev->driver_data;
85 if (!card)
86 return -EINVAL;
88 return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
91 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
93 static ssize_t
94 qeth_dev_portno_show(struct device *dev, struct device_attribute *attr, char *buf)
96 struct qeth_card *card = dev->driver_data;
97 if (!card)
98 return -EINVAL;
100 return sprintf(buf, "%i\n", card->info.portno);
103 static ssize_t
104 qeth_dev_portno_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
106 struct qeth_card *card = dev->driver_data;
107 char *tmp;
108 unsigned int portno;
110 if (!card)
111 return -EINVAL;
113 if ((card->state != CARD_STATE_DOWN) &&
114 (card->state != CARD_STATE_RECOVER))
115 return -EPERM;
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;
123 card->info.portno = portno;
124 return count;
127 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
129 static ssize_t
130 qeth_dev_portname_show(struct device *dev, struct device_attribute *attr, char *buf)
132 struct qeth_card *card = dev->driver_data;
133 char portname[9] = {0, };
135 if (!card)
136 return -EINVAL;
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");
146 static ssize_t
147 qeth_dev_portname_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
149 struct qeth_card *card = dev->driver_data;
150 char *tmp;
151 int i;
153 if (!card)
154 return -EINVAL;
156 if ((card->state != CARD_STATE_DOWN) &&
157 (card->state != CARD_STATE_RECOVER))
158 return -EPERM;
160 tmp = strsep((char **) &buf, "\n");
161 if ((strlen(tmp) > 8) || (strlen(tmp) == 0))
162 return -EINVAL;
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);
171 return count;
174 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
175 qeth_dev_portname_store);
177 static ssize_t
178 qeth_dev_checksum_show(struct device *dev, struct device_attribute *attr, char *buf)
180 struct qeth_card *card = dev->driver_data;
182 if (!card)
183 return -EINVAL;
185 return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
188 static ssize_t
189 qeth_dev_checksum_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
191 struct qeth_card *card = dev->driver_data;
192 char *tmp;
194 if (!card)
195 return -EINVAL;
197 if ((card->state != CARD_STATE_DOWN) &&
198 (card->state != CARD_STATE_RECOVER))
199 return -EPERM;
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;
212 return count;
215 static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
216 qeth_dev_checksum_store);
218 static ssize_t
219 qeth_dev_prioqing_show(struct device *dev, struct device_attribute *attr, char *buf)
221 struct qeth_card *card = dev->driver_data;
223 if (!card)
224 return -EINVAL;
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);
237 static ssize_t
238 qeth_dev_prioqing_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
240 struct qeth_card *card = dev->driver_data;
241 char *tmp;
243 if (!card)
244 return -EINVAL;
246 if ((card->state != CARD_STATE_DOWN) &&
247 (card->state != CARD_STATE_RECOVER))
248 return -EPERM;
250 /* check if 1920 devices are supported ,
251 * if though we have to permit priority queueing
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;
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;
284 return count;
287 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
288 qeth_dev_prioqing_store);
290 static ssize_t
291 qeth_dev_bufcnt_show(struct device *dev, struct device_attribute *attr, char *buf)
293 struct qeth_card *card = dev->driver_data;
295 if (!card)
296 return -EINVAL;
298 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
301 static ssize_t
302 qeth_dev_bufcnt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
304 struct qeth_card *card = dev->driver_data;
305 char *tmp;
306 int cnt, old_cnt;
307 int rc;
309 if (!card)
310 return -EINVAL;
312 if ((card->state != CARD_STATE_DOWN) &&
313 (card->state != CARD_STATE_RECOVER))
314 return -EPERM;
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);
325 return count;
328 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
329 qeth_dev_bufcnt_store);
331 static inline ssize_t
332 qeth_dev_route_show(struct qeth_card *card, struct qeth_routing_info *route,
333 char *buf)
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");
360 static ssize_t
361 qeth_dev_route4_show(struct device *dev, struct device_attribute *attr, char *buf)
363 struct qeth_card *card = dev->driver_data;
365 if (!card)
366 return -EINVAL;
368 return qeth_dev_route_show(card, &card->options.route4, buf);
371 static inline 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)
375 enum qeth_routing_types old_route_type = route->type;
376 char *tmp;
377 int rc;
379 tmp = strsep((char **) &buf, "\n");
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;
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);
407 return count;
410 static ssize_t
411 qeth_dev_route4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
413 struct qeth_card *card = dev->driver_data;
415 if (!card)
416 return -EINVAL;
418 return qeth_dev_route_store(card, &card->options.route4,
419 QETH_PROT_IPV4, buf, count);
422 static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
424 #ifdef CONFIG_QETH_IPV6
425 static ssize_t
426 qeth_dev_route6_show(struct device *dev, struct device_attribute *attr, char *buf)
428 struct qeth_card *card = dev->driver_data;
430 if (!card)
431 return -EINVAL;
433 if (!qeth_is_supported(card, IPA_IPV6))
434 return sprintf(buf, "%s\n", "n/a");
436 return qeth_dev_route_show(card, &card->options.route6, buf);
439 static ssize_t
440 qeth_dev_route6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
442 struct qeth_card *card = dev->driver_data;
444 if (!card)
445 return -EINVAL;
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;
454 return qeth_dev_route_store(card, &card->options.route6,
455 QETH_PROT_IPV6, buf, count);
458 static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
459 #endif
461 static ssize_t
462 qeth_dev_add_hhlen_show(struct device *dev, struct device_attribute *attr, char *buf)
464 struct qeth_card *card = dev->driver_data;
466 if (!card)
467 return -EINVAL;
469 return sprintf(buf, "%i\n", card->options.add_hhlen);
472 static ssize_t
473 qeth_dev_add_hhlen_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
475 struct qeth_card *card = dev->driver_data;
476 char *tmp;
477 int i;
479 if (!card)
480 return -EINVAL;
482 if ((card->state != CARD_STATE_DOWN) &&
483 (card->state != CARD_STATE_RECOVER))
484 return -EPERM;
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;
491 card->options.add_hhlen = i;
493 return count;
496 static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
497 qeth_dev_add_hhlen_store);
499 static ssize_t
500 qeth_dev_fake_ll_show(struct device *dev, struct device_attribute *attr, char *buf)
502 struct qeth_card *card = dev->driver_data;
504 if (!card)
505 return -EINVAL;
507 return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
510 static ssize_t
511 qeth_dev_fake_ll_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
513 struct qeth_card *card = dev->driver_data;
514 char *tmp;
515 int i;
517 if (!card)
518 return -EINVAL;
520 if ((card->state != CARD_STATE_DOWN) &&
521 (card->state != CARD_STATE_RECOVER))
522 return -EPERM;
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;
529 card->options.fake_ll = i;
530 return count;
533 static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
534 qeth_dev_fake_ll_store);
536 static ssize_t
537 qeth_dev_fake_broadcast_show(struct device *dev, struct device_attribute *attr, char *buf)
539 struct qeth_card *card = dev->driver_data;
541 if (!card)
542 return -EINVAL;
544 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
547 static ssize_t
548 qeth_dev_fake_broadcast_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
550 struct qeth_card *card = dev->driver_data;
551 char *tmp;
552 int i;
554 if (!card)
555 return -EINVAL;
557 if ((card->state != CARD_STATE_DOWN) &&
558 (card->state != CARD_STATE_RECOVER))
559 return -EPERM;
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;
568 return count;
571 static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
572 qeth_dev_fake_broadcast_store);
574 static ssize_t
575 qeth_dev_recover_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
577 struct qeth_card *card = dev->driver_data;
578 char *tmp;
579 int i;
581 if (!card)
582 return -EINVAL;
584 if (card->state != CARD_STATE_UP)
585 return -EPERM;
587 i = simple_strtoul(buf, &tmp, 16);
588 if (i == 1)
589 qeth_schedule_recovery(card);
591 return count;
594 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
596 static ssize_t
597 qeth_dev_broadcast_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
599 struct qeth_card *card = dev->driver_data;
601 if (!card)
602 return -EINVAL;
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");
608 return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
609 QETH_TR_BROADCAST_ALLRINGS)?
610 "all rings":"local");
613 static ssize_t
614 qeth_dev_broadcast_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
616 struct qeth_card *card = dev->driver_data;
617 char *tmp;
619 if (!card)
620 return -EINVAL;
622 if ((card->state != CARD_STATE_DOWN) &&
623 (card->state != CARD_STATE_RECOVER))
624 return -EPERM;
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;
632 tmp = strsep((char **) &buf, "\n");
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;
645 return count;
648 static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
649 qeth_dev_broadcast_mode_store);
651 static ssize_t
652 qeth_dev_canonical_macaddr_show(struct device *dev, struct device_attribute *attr, char *buf)
654 struct qeth_card *card = dev->driver_data;
656 if (!card)
657 return -EINVAL;
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");
663 return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
664 QETH_TR_MACADDR_CANONICAL)? 1:0);
667 static ssize_t
668 qeth_dev_canonical_macaddr_store(struct device *dev, struct device_attribute *attr, const char *buf,
669 size_t count)
671 struct qeth_card *card = dev->driver_data;
672 char *tmp;
673 int i;
675 if (!card)
676 return -EINVAL;
678 if ((card->state != CARD_STATE_DOWN) &&
679 (card->state != CARD_STATE_RECOVER))
680 return -EPERM;
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;
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;
697 return count;
700 static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
701 qeth_dev_canonical_macaddr_store);
703 static ssize_t
704 qeth_dev_layer2_show(struct device *dev, struct device_attribute *attr, char *buf)
706 struct qeth_card *card = dev->driver_data;
708 if (!card)
709 return -EINVAL;
711 return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
714 static ssize_t
715 qeth_dev_layer2_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
717 struct qeth_card *card = dev->driver_data;
718 char *tmp;
719 int i;
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;
728 if (((card->state != CARD_STATE_DOWN) &&
729 (card->state != CARD_STATE_RECOVER)))
730 return -EPERM;
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;
739 return count;
742 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
743 qeth_dev_layer2_store);
745 static ssize_t
746 qeth_dev_large_send_show(struct device *dev, struct device_attribute *attr, char *buf)
748 struct qeth_card *card = dev->driver_data;
750 if (!card)
751 return -EINVAL;
753 switch (card->options.large_send) {
754 case QETH_LARGE_SEND_NO:
755 return sprintf(buf, "%s\n", "no");
756 case QETH_LARGE_SEND_EDDP:
757 return sprintf(buf, "%s\n", "EDDP");
758 case QETH_LARGE_SEND_TSO:
759 return sprintf(buf, "%s\n", "TSO");
760 default:
761 return sprintf(buf, "%s\n", "N/A");
765 static ssize_t
766 qeth_dev_large_send_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
768 struct qeth_card *card = dev->driver_data;
769 enum qeth_large_send_types type;
770 int rc = 0;
771 char *tmp;
773 if (!card)
774 return -EINVAL;
775 tmp = strsep((char **) &buf, "\n");
776 if (!strcmp(tmp, "no")){
777 type = QETH_LARGE_SEND_NO;
778 } else if (!strcmp(tmp, "EDDP")) {
779 type = QETH_LARGE_SEND_EDDP;
780 } else if (!strcmp(tmp, "TSO")) {
781 type = QETH_LARGE_SEND_TSO;
782 } else {
783 PRINT_WARN("large_send: invalid mode %s!\n", tmp);
784 return -EINVAL;
786 if (card->options.large_send == type)
787 return count;
788 if ((rc = qeth_set_large_send(card, type)))
789 return rc;
790 return count;
793 static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
794 qeth_dev_large_send_store);
796 static ssize_t
797 qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value )
800 if (!card)
801 return -EINVAL;
803 return sprintf(buf, "%i\n", value);
806 static ssize_t
807 qeth_dev_blkt_store(struct qeth_card *card, const char *buf, size_t count,
808 int *value, int max_value)
810 char *tmp;
811 int i;
813 if (!card)
814 return -EINVAL;
816 if ((card->state != CARD_STATE_DOWN) &&
817 (card->state != CARD_STATE_RECOVER))
818 return -EPERM;
820 i = simple_strtoul(buf, &tmp, 10);
821 if (i <= max_value) {
822 *value = i;
823 } else {
824 PRINT_WARN("blkt total time: write values between"
825 " 0 and %d to this file!\n", max_value);
826 return -EINVAL;
828 return count;
831 static ssize_t
832 qeth_dev_blkt_total_show(struct device *dev, struct device_attribute *attr, char *buf)
834 struct qeth_card *card = dev->driver_data;
836 return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
840 static ssize_t
841 qeth_dev_blkt_total_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
843 struct qeth_card *card = dev->driver_data;
845 return qeth_dev_blkt_store(card, buf, count,
846 &card->info.blkt.time_total,1000);
851 static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
852 qeth_dev_blkt_total_store);
854 static ssize_t
855 qeth_dev_blkt_inter_show(struct device *dev, struct device_attribute *attr, char *buf)
857 struct qeth_card *card = dev->driver_data;
859 return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
863 static ssize_t
864 qeth_dev_blkt_inter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
866 struct qeth_card *card = dev->driver_data;
868 return qeth_dev_blkt_store(card, buf, count,
869 &card->info.blkt.inter_packet,100);
872 static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
873 qeth_dev_blkt_inter_store);
875 static ssize_t
876 qeth_dev_blkt_inter_jumbo_show(struct device *dev, struct device_attribute *attr, char *buf)
878 struct qeth_card *card = dev->driver_data;
880 return qeth_dev_blkt_show(buf, card,
881 card->info.blkt.inter_packet_jumbo);
885 static ssize_t
886 qeth_dev_blkt_inter_jumbo_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
888 struct qeth_card *card = dev->driver_data;
890 return qeth_dev_blkt_store(card, buf, count,
891 &card->info.blkt.inter_packet_jumbo,100);
894 static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
895 qeth_dev_blkt_inter_jumbo_store);
897 static struct device_attribute * qeth_blkt_device_attrs[] = {
898 &dev_attr_total,
899 &dev_attr_inter,
900 &dev_attr_inter_jumbo,
901 NULL,
904 static struct attribute_group qeth_device_blkt_group = {
905 .name = "blkt",
906 .attrs = (struct attribute **)qeth_blkt_device_attrs,
909 static struct device_attribute * qeth_device_attrs[] = {
910 &dev_attr_state,
911 &dev_attr_chpid,
912 &dev_attr_if_name,
913 &dev_attr_card_type,
914 &dev_attr_portno,
915 &dev_attr_portname,
916 &dev_attr_checksumming,
917 &dev_attr_priority_queueing,
918 &dev_attr_buffer_count,
919 &dev_attr_route4,
920 #ifdef CONFIG_QETH_IPV6
921 &dev_attr_route6,
922 #endif
923 &dev_attr_add_hhlen,
924 &dev_attr_fake_ll,
925 &dev_attr_fake_broadcast,
926 &dev_attr_recover,
927 &dev_attr_broadcast_mode,
928 &dev_attr_canonical_macaddr,
929 &dev_attr_layer2,
930 &dev_attr_large_send,
931 NULL,
934 static struct attribute_group qeth_device_attr_group = {
935 .attrs = (struct attribute **)qeth_device_attrs,
938 static struct device_attribute * qeth_osn_device_attrs[] = {
939 &dev_attr_state,
940 &dev_attr_chpid,
941 &dev_attr_if_name,
942 &dev_attr_card_type,
943 &dev_attr_buffer_count,
944 &dev_attr_recover,
945 NULL,
948 static struct attribute_group qeth_osn_device_attr_group = {
949 .attrs = (struct attribute **)qeth_osn_device_attrs,
952 #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
953 struct device_attribute dev_attr_##_id = { \
954 .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
955 .show = _show, \
956 .store = _store, \
960 qeth_check_layer2(struct qeth_card *card)
962 if (card->options.layer2)
963 return -EPERM;
964 return 0;
968 static ssize_t
969 qeth_dev_ipato_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
971 struct qeth_card *card = dev->driver_data;
973 if (!card)
974 return -EINVAL;
976 if (qeth_check_layer2(card))
977 return -EPERM;
978 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
981 static ssize_t
982 qeth_dev_ipato_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
984 struct qeth_card *card = dev->driver_data;
985 char *tmp;
987 if (!card)
988 return -EINVAL;
990 if ((card->state != CARD_STATE_DOWN) &&
991 (card->state != CARD_STATE_RECOVER))
992 return -EPERM;
994 if (qeth_check_layer2(card))
995 return -EPERM;
997 tmp = strsep((char **) &buf, "\n");
998 if (!strcmp(tmp, "toggle")){
999 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
1000 } else if (!strcmp(tmp, "1")){
1001 card->ipato.enabled = 1;
1002 } else if (!strcmp(tmp, "0")){
1003 card->ipato.enabled = 0;
1004 } else {
1005 PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
1006 "this file\n");
1007 return -EINVAL;
1009 return count;
1012 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
1013 qeth_dev_ipato_enable_show,
1014 qeth_dev_ipato_enable_store);
1016 static ssize_t
1017 qeth_dev_ipato_invert4_show(struct device *dev, struct device_attribute *attr, char *buf)
1019 struct qeth_card *card = dev->driver_data;
1021 if (!card)
1022 return -EINVAL;
1024 if (qeth_check_layer2(card))
1025 return -EPERM;
1027 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
1030 static ssize_t
1031 qeth_dev_ipato_invert4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1033 struct qeth_card *card = dev->driver_data;
1034 char *tmp;
1036 if (!card)
1037 return -EINVAL;
1039 if (qeth_check_layer2(card))
1040 return -EPERM;
1042 tmp = strsep((char **) &buf, "\n");
1043 if (!strcmp(tmp, "toggle")){
1044 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
1045 } else if (!strcmp(tmp, "1")){
1046 card->ipato.invert4 = 1;
1047 } else if (!strcmp(tmp, "0")){
1048 card->ipato.invert4 = 0;
1049 } else {
1050 PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
1051 "this file\n");
1052 return -EINVAL;
1054 return count;
1057 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
1058 qeth_dev_ipato_invert4_show,
1059 qeth_dev_ipato_invert4_store);
1061 static inline ssize_t
1062 qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
1063 enum qeth_prot_versions proto)
1065 struct qeth_ipato_entry *ipatoe;
1066 unsigned long flags;
1067 char addr_str[40];
1068 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1069 int i = 0;
1071 if (qeth_check_layer2(card))
1072 return -EPERM;
1074 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1075 /* add strlen for "/<mask>\n" */
1076 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
1077 spin_lock_irqsave(&card->ip_lock, flags);
1078 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
1079 if (ipatoe->proto != proto)
1080 continue;
1081 /* String must not be longer than PAGE_SIZE. So we check if
1082 * string length gets near PAGE_SIZE. Then we can savely display
1083 * the next IPv6 address (worst case, compared to IPv4) */
1084 if ((PAGE_SIZE - i) <= entry_len)
1085 break;
1086 qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
1087 i += snprintf(buf + i, PAGE_SIZE - i,
1088 "%s/%i\n", addr_str, ipatoe->mask_bits);
1090 spin_unlock_irqrestore(&card->ip_lock, flags);
1091 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1093 return i;
1096 static ssize_t
1097 qeth_dev_ipato_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
1099 struct qeth_card *card = dev->driver_data;
1101 if (!card)
1102 return -EINVAL;
1104 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
1107 static inline int
1108 qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
1109 u8 *addr, int *mask_bits)
1111 const char *start, *end;
1112 char *tmp;
1113 char buffer[49] = {0, };
1115 start = buf;
1116 /* get address string */
1117 end = strchr(start, '/');
1118 if (!end || (end-start >= 49)){
1119 PRINT_WARN("Invalid format for ipato_addx/delx. "
1120 "Use <ip addr>/<mask bits>\n");
1121 return -EINVAL;
1123 strncpy(buffer, start, end - start);
1124 if (qeth_string_to_ipaddr(buffer, proto, addr)){
1125 PRINT_WARN("Invalid IP address format!\n");
1126 return -EINVAL;
1128 start = end + 1;
1129 *mask_bits = simple_strtoul(start, &tmp, 10);
1131 return 0;
1134 static inline ssize_t
1135 qeth_dev_ipato_add_store(const char *buf, size_t count,
1136 struct qeth_card *card, enum qeth_prot_versions proto)
1138 struct qeth_ipato_entry *ipatoe;
1139 u8 addr[16];
1140 int mask_bits;
1141 int rc;
1143 if (qeth_check_layer2(card))
1144 return -EPERM;
1145 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1146 return rc;
1148 if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
1149 PRINT_WARN("No memory to allocate ipato entry\n");
1150 return -ENOMEM;
1152 memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
1153 ipatoe->proto = proto;
1154 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
1155 ipatoe->mask_bits = mask_bits;
1157 if ((rc = qeth_add_ipato_entry(card, ipatoe))){
1158 kfree(ipatoe);
1159 return rc;
1162 return count;
1165 static ssize_t
1166 qeth_dev_ipato_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1168 struct qeth_card *card = dev->driver_data;
1170 if (!card)
1171 return -EINVAL;
1173 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
1176 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
1177 qeth_dev_ipato_add4_show,
1178 qeth_dev_ipato_add4_store);
1180 static inline ssize_t
1181 qeth_dev_ipato_del_store(const char *buf, size_t count,
1182 struct qeth_card *card, enum qeth_prot_versions proto)
1184 u8 addr[16];
1185 int mask_bits;
1186 int rc;
1188 if (qeth_check_layer2(card))
1189 return -EPERM;
1190 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1191 return rc;
1193 qeth_del_ipato_entry(card, proto, addr, mask_bits);
1195 return count;
1198 static ssize_t
1199 qeth_dev_ipato_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1201 struct qeth_card *card = dev->driver_data;
1203 if (!card)
1204 return -EINVAL;
1206 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
1209 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
1210 qeth_dev_ipato_del4_store);
1212 #ifdef CONFIG_QETH_IPV6
1213 static ssize_t
1214 qeth_dev_ipato_invert6_show(struct device *dev, struct device_attribute *attr, char *buf)
1216 struct qeth_card *card = dev->driver_data;
1218 if (!card)
1219 return -EINVAL;
1221 if (qeth_check_layer2(card))
1222 return -EPERM;
1224 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
1227 static ssize_t
1228 qeth_dev_ipato_invert6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1230 struct qeth_card *card = dev->driver_data;
1231 char *tmp;
1233 if (!card)
1234 return -EINVAL;
1236 if (qeth_check_layer2(card))
1237 return -EPERM;
1239 tmp = strsep((char **) &buf, "\n");
1240 if (!strcmp(tmp, "toggle")){
1241 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
1242 } else if (!strcmp(tmp, "1")){
1243 card->ipato.invert6 = 1;
1244 } else if (!strcmp(tmp, "0")){
1245 card->ipato.invert6 = 0;
1246 } else {
1247 PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
1248 "this file\n");
1249 return -EINVAL;
1251 return count;
1254 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
1255 qeth_dev_ipato_invert6_show,
1256 qeth_dev_ipato_invert6_store);
1259 static ssize_t
1260 qeth_dev_ipato_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
1262 struct qeth_card *card = dev->driver_data;
1264 if (!card)
1265 return -EINVAL;
1267 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
1270 static ssize_t
1271 qeth_dev_ipato_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1273 struct qeth_card *card = dev->driver_data;
1275 if (!card)
1276 return -EINVAL;
1278 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
1281 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
1282 qeth_dev_ipato_add6_show,
1283 qeth_dev_ipato_add6_store);
1285 static ssize_t
1286 qeth_dev_ipato_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1288 struct qeth_card *card = dev->driver_data;
1290 if (!card)
1291 return -EINVAL;
1293 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
1296 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
1297 qeth_dev_ipato_del6_store);
1298 #endif /* CONFIG_QETH_IPV6 */
1300 static struct device_attribute * qeth_ipato_device_attrs[] = {
1301 &dev_attr_ipato_enable,
1302 &dev_attr_ipato_invert4,
1303 &dev_attr_ipato_add4,
1304 &dev_attr_ipato_del4,
1305 #ifdef CONFIG_QETH_IPV6
1306 &dev_attr_ipato_invert6,
1307 &dev_attr_ipato_add6,
1308 &dev_attr_ipato_del6,
1309 #endif
1310 NULL,
1313 static struct attribute_group qeth_device_ipato_group = {
1314 .name = "ipa_takeover",
1315 .attrs = (struct attribute **)qeth_ipato_device_attrs,
1318 static inline ssize_t
1319 qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
1320 enum qeth_prot_versions proto)
1322 struct qeth_ipaddr *ipaddr;
1323 char addr_str[40];
1324 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1325 unsigned long flags;
1326 int i = 0;
1328 if (qeth_check_layer2(card))
1329 return -EPERM;
1331 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1332 entry_len += 2; /* \n + terminator */
1333 spin_lock_irqsave(&card->ip_lock, flags);
1334 list_for_each_entry(ipaddr, &card->ip_list, entry){
1335 if (ipaddr->proto != proto)
1336 continue;
1337 if (ipaddr->type != QETH_IP_TYPE_VIPA)
1338 continue;
1339 /* String must not be longer than PAGE_SIZE. So we check if
1340 * string length gets near PAGE_SIZE. Then we can savely display
1341 * the next IPv6 address (worst case, compared to IPv4) */
1342 if ((PAGE_SIZE - i) <= entry_len)
1343 break;
1344 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1345 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1347 spin_unlock_irqrestore(&card->ip_lock, flags);
1348 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1350 return i;
1353 static ssize_t
1354 qeth_dev_vipa_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
1356 struct qeth_card *card = dev->driver_data;
1358 if (!card)
1359 return -EINVAL;
1361 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
1364 static inline int
1365 qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
1366 u8 *addr)
1368 if (qeth_string_to_ipaddr(buf, proto, addr)){
1369 PRINT_WARN("Invalid IP address format!\n");
1370 return -EINVAL;
1372 return 0;
1375 static inline ssize_t
1376 qeth_dev_vipa_add_store(const char *buf, size_t count,
1377 struct qeth_card *card, enum qeth_prot_versions proto)
1379 u8 addr[16] = {0, };
1380 int rc;
1382 if (qeth_check_layer2(card))
1383 return -EPERM;
1384 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1385 return rc;
1387 if ((rc = qeth_add_vipa(card, proto, addr)))
1388 return rc;
1390 return count;
1393 static ssize_t
1394 qeth_dev_vipa_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1396 struct qeth_card *card = dev->driver_data;
1398 if (!card)
1399 return -EINVAL;
1401 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
1404 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
1405 qeth_dev_vipa_add4_show,
1406 qeth_dev_vipa_add4_store);
1408 static inline ssize_t
1409 qeth_dev_vipa_del_store(const char *buf, size_t count,
1410 struct qeth_card *card, enum qeth_prot_versions proto)
1412 u8 addr[16];
1413 int rc;
1415 if (qeth_check_layer2(card))
1416 return -EPERM;
1417 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1418 return rc;
1420 qeth_del_vipa(card, proto, addr);
1422 return count;
1425 static ssize_t
1426 qeth_dev_vipa_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1428 struct qeth_card *card = dev->driver_data;
1430 if (!card)
1431 return -EINVAL;
1433 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
1436 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
1437 qeth_dev_vipa_del4_store);
1439 #ifdef CONFIG_QETH_IPV6
1440 static ssize_t
1441 qeth_dev_vipa_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
1443 struct qeth_card *card = dev->driver_data;
1445 if (!card)
1446 return -EINVAL;
1448 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
1451 static ssize_t
1452 qeth_dev_vipa_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1454 struct qeth_card *card = dev->driver_data;
1456 if (!card)
1457 return -EINVAL;
1459 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
1462 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
1463 qeth_dev_vipa_add6_show,
1464 qeth_dev_vipa_add6_store);
1466 static ssize_t
1467 qeth_dev_vipa_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1469 struct qeth_card *card = dev->driver_data;
1471 if (!card)
1472 return -EINVAL;
1474 if (qeth_check_layer2(card))
1475 return -EPERM;
1477 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
1480 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
1481 qeth_dev_vipa_del6_store);
1482 #endif /* CONFIG_QETH_IPV6 */
1484 static struct device_attribute * qeth_vipa_device_attrs[] = {
1485 &dev_attr_vipa_add4,
1486 &dev_attr_vipa_del4,
1487 #ifdef CONFIG_QETH_IPV6
1488 &dev_attr_vipa_add6,
1489 &dev_attr_vipa_del6,
1490 #endif
1491 NULL,
1494 static struct attribute_group qeth_device_vipa_group = {
1495 .name = "vipa",
1496 .attrs = (struct attribute **)qeth_vipa_device_attrs,
1499 static inline ssize_t
1500 qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
1501 enum qeth_prot_versions proto)
1503 struct qeth_ipaddr *ipaddr;
1504 char addr_str[40];
1505 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1506 unsigned long flags;
1507 int i = 0;
1509 if (qeth_check_layer2(card))
1510 return -EPERM;
1512 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1513 entry_len += 2; /* \n + terminator */
1514 spin_lock_irqsave(&card->ip_lock, flags);
1515 list_for_each_entry(ipaddr, &card->ip_list, entry){
1516 if (ipaddr->proto != proto)
1517 continue;
1518 if (ipaddr->type != QETH_IP_TYPE_RXIP)
1519 continue;
1520 /* String must not be longer than PAGE_SIZE. So we check if
1521 * string length gets near PAGE_SIZE. Then we can savely display
1522 * the next IPv6 address (worst case, compared to IPv4) */
1523 if ((PAGE_SIZE - i) <= entry_len)
1524 break;
1525 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1526 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1528 spin_unlock_irqrestore(&card->ip_lock, flags);
1529 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1531 return i;
1534 static ssize_t
1535 qeth_dev_rxip_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
1537 struct qeth_card *card = dev->driver_data;
1539 if (!card)
1540 return -EINVAL;
1542 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
1545 static inline int
1546 qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
1547 u8 *addr)
1549 if (qeth_string_to_ipaddr(buf, proto, addr)){
1550 PRINT_WARN("Invalid IP address format!\n");
1551 return -EINVAL;
1553 return 0;
1556 static inline ssize_t
1557 qeth_dev_rxip_add_store(const char *buf, size_t count,
1558 struct qeth_card *card, enum qeth_prot_versions proto)
1560 u8 addr[16] = {0, };
1561 int rc;
1563 if (qeth_check_layer2(card))
1564 return -EPERM;
1565 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1566 return rc;
1568 if ((rc = qeth_add_rxip(card, proto, addr)))
1569 return rc;
1571 return count;
1574 static ssize_t
1575 qeth_dev_rxip_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1577 struct qeth_card *card = dev->driver_data;
1579 if (!card)
1580 return -EINVAL;
1582 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
1585 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
1586 qeth_dev_rxip_add4_show,
1587 qeth_dev_rxip_add4_store);
1589 static inline ssize_t
1590 qeth_dev_rxip_del_store(const char *buf, size_t count,
1591 struct qeth_card *card, enum qeth_prot_versions proto)
1593 u8 addr[16];
1594 int rc;
1596 if (qeth_check_layer2(card))
1597 return -EPERM;
1598 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1599 return rc;
1601 qeth_del_rxip(card, proto, addr);
1603 return count;
1606 static ssize_t
1607 qeth_dev_rxip_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1609 struct qeth_card *card = dev->driver_data;
1611 if (!card)
1612 return -EINVAL;
1614 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
1617 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
1618 qeth_dev_rxip_del4_store);
1620 #ifdef CONFIG_QETH_IPV6
1621 static ssize_t
1622 qeth_dev_rxip_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
1624 struct qeth_card *card = dev->driver_data;
1626 if (!card)
1627 return -EINVAL;
1629 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
1632 static ssize_t
1633 qeth_dev_rxip_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1635 struct qeth_card *card = dev->driver_data;
1637 if (!card)
1638 return -EINVAL;
1640 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1643 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1644 qeth_dev_rxip_add6_show,
1645 qeth_dev_rxip_add6_store);
1647 static ssize_t
1648 qeth_dev_rxip_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1650 struct qeth_card *card = dev->driver_data;
1652 if (!card)
1653 return -EINVAL;
1655 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1658 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1659 qeth_dev_rxip_del6_store);
1660 #endif /* CONFIG_QETH_IPV6 */
1662 static struct device_attribute * qeth_rxip_device_attrs[] = {
1663 &dev_attr_rxip_add4,
1664 &dev_attr_rxip_del4,
1665 #ifdef CONFIG_QETH_IPV6
1666 &dev_attr_rxip_add6,
1667 &dev_attr_rxip_del6,
1668 #endif
1669 NULL,
1672 static struct attribute_group qeth_device_rxip_group = {
1673 .name = "rxip",
1674 .attrs = (struct attribute **)qeth_rxip_device_attrs,
1678 qeth_create_device_attributes(struct device *dev)
1680 int ret;
1681 struct qeth_card *card = dev->driver_data;
1683 if (card->info.type == QETH_CARD_TYPE_OSN)
1684 return sysfs_create_group(&dev->kobj,
1685 &qeth_osn_device_attr_group);
1687 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1688 return ret;
1689 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
1690 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1691 return ret;
1693 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
1694 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1695 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1696 return ret;
1698 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
1699 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1700 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1701 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1703 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group)))
1704 return ret;
1706 return ret;
1709 void
1710 qeth_remove_device_attributes(struct device *dev)
1712 struct qeth_card *card = dev->driver_data;
1714 if (card->info.type == QETH_CARD_TYPE_OSN)
1715 return sysfs_remove_group(&dev->kobj,
1716 &qeth_osn_device_attr_group);
1718 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1719 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1720 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1721 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1722 sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
1725 /**********************/
1726 /* DRIVER ATTRIBUTES */
1727 /**********************/
1728 static ssize_t
1729 qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1730 size_t count)
1732 const char *start, *end;
1733 char bus_ids[3][BUS_ID_SIZE], *argv[3];
1734 int i;
1735 int err;
1737 start = buf;
1738 for (i = 0; i < 3; i++) {
1739 static const char delim[] = { ',', ',', '\n' };
1740 int len;
1742 if (!(end = strchr(start, delim[i])))
1743 return -EINVAL;
1744 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
1745 strncpy(bus_ids[i], start, len);
1746 bus_ids[i][len] = '\0';
1747 start = end + 1;
1748 argv[i] = bus_ids[i];
1750 err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
1751 &qeth_ccw_driver, 3, argv);
1752 if (err)
1753 return err;
1754 else
1755 return count;
1759 static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
1761 static ssize_t
1762 qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
1763 size_t count)
1765 int rc;
1766 int signum;
1767 char *tmp, *tmp2;
1769 tmp = strsep((char **) &buf, "\n");
1770 if (!strncmp(tmp, "unregister", 10)){
1771 if ((rc = qeth_notifier_unregister(current)))
1772 return rc;
1773 return count;
1776 signum = simple_strtoul(tmp, &tmp2, 10);
1777 if ((signum < 0) || (signum > 32)){
1778 PRINT_WARN("Signal number %d is out of range\n", signum);
1779 return -EINVAL;
1781 if ((rc = qeth_notifier_register(current, signum)))
1782 return rc;
1784 return count;
1787 static DRIVER_ATTR(notifier_register, 0200, 0,
1788 qeth_driver_notifier_register_store);
1791 qeth_create_driver_attributes(void)
1793 int rc;
1795 if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
1796 &driver_attr_group)))
1797 return rc;
1798 return driver_create_file(&qeth_ccwgroup_driver.driver,
1799 &driver_attr_notifier_register);
1802 void
1803 qeth_remove_driver_attributes(void)
1805 driver_remove_file(&qeth_ccwgroup_driver.driver,
1806 &driver_attr_group);
1807 driver_remove_file(&qeth_ccwgroup_driver.driver,
1808 &driver_attr_notifier_register);