3 * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.24 $)
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 <pavlic@de.ibm.com>
14 #include <linux/list.h>
15 #include <linux/rwsem.h>
17 #include <asm/ebcdic.h>
23 /*****************************************************************************/
25 /* /sys-fs stuff UNDER DEVELOPMENT !!! */
27 /*****************************************************************************/
31 qeth_dev_state_show(struct device *dev, char *buf)
33 struct qeth_card *card = dev->driver_data;
37 switch (card->state) {
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");
46 return sprintf(buf, "UP (LAN ONLINE)\n");
48 return sprintf(buf, "UP (LAN OFFLINE)\n");
49 case CARD_STATE_RECOVER:
50 return sprintf(buf, "RECOVER\n");
52 return sprintf(buf, "UNKNOWN\n");
56 static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
59 qeth_dev_chpid_show(struct device *dev, char *buf)
61 struct qeth_card *card = dev->driver_data;
65 return sprintf(buf, "%02X\n", card->info.chpid);
68 static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
71 qeth_dev_if_name_show(struct device *dev, char *buf)
73 struct qeth_card *card = dev->driver_data;
77 return sprintf(buf, "%s\n", card->info.if_name);
80 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
83 qeth_dev_card_type_show(struct device *dev, char *buf)
85 struct qeth_card *card = dev->driver_data;
89 return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
92 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
95 qeth_dev_portno_show(struct device *dev, char *buf)
97 struct qeth_card *card = dev->driver_data;
101 return sprintf(buf, "%i\n", card->info.portno);
105 qeth_dev_portno_store(struct device *dev, const char *buf, size_t count)
107 struct qeth_card *card = dev->driver_data;
114 if ((card->state != CARD_STATE_DOWN) &&
115 (card->state != CARD_STATE_RECOVER))
118 portno = simple_strtoul(buf, &tmp, 16);
119 if ((portno < 0) || (portno > MAX_PORTNO)){
120 PRINT_WARN("portno 0x%X is out of range\n", portno);
124 card->info.portno = portno;
128 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
131 qeth_dev_portname_show(struct device *dev, char *buf)
133 struct qeth_card *card = dev->driver_data;
134 char portname[9] = {0, };
139 if (card->info.portname_required) {
140 memcpy(portname, card->info.portname + 1, 8);
142 return sprintf(buf, "%s\n", portname);
144 return sprintf(buf, "no portname required\n");
148 qeth_dev_portname_store(struct device *dev, const char *buf, size_t count)
150 struct qeth_card *card = dev->driver_data;
157 if ((card->state != CARD_STATE_DOWN) &&
158 (card->state != CARD_STATE_RECOVER))
161 tmp = strsep((char **) &buf, "\n");
162 if ((strlen(tmp) > 8) || (strlen(tmp) < 2))
165 card->info.portname[0] = strlen(tmp);
166 /* for beauty reasons */
167 for (i = 1; i < 9; i++)
168 card->info.portname[i] = ' ';
169 strcpy(card->info.portname + 1, tmp);
170 ASCEBC(card->info.portname + 1, 8);
175 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
176 qeth_dev_portname_store);
179 qeth_dev_checksum_show(struct device *dev, char *buf)
181 struct qeth_card *card = dev->driver_data;
186 return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
190 qeth_dev_checksum_store(struct device *dev, const char *buf, size_t count)
192 struct qeth_card *card = dev->driver_data;
198 if ((card->state != CARD_STATE_DOWN) &&
199 (card->state != CARD_STATE_RECOVER))
202 tmp = strsep((char **) &buf, "\n");
203 if (!strcmp(tmp, "sw_checksumming"))
204 card->options.checksum_type = SW_CHECKSUMMING;
205 else if (!strcmp(tmp, "hw_checksumming"))
206 card->options.checksum_type = HW_CHECKSUMMING;
207 else if (!strcmp(tmp, "no_checksumming"))
208 card->options.checksum_type = NO_CHECKSUMMING;
210 PRINT_WARN("Unknown checksumming type '%s'\n", tmp);
216 static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
217 qeth_dev_checksum_store);
220 qeth_dev_prioqing_show(struct device *dev, char *buf)
222 struct qeth_card *card = dev->driver_data;
227 switch (card->qdio.do_prio_queueing) {
228 case QETH_PRIO_Q_ING_PREC:
229 return sprintf(buf, "%s\n", "by precedence");
230 case QETH_PRIO_Q_ING_TOS:
231 return sprintf(buf, "%s\n", "by type of service");
233 return sprintf(buf, "always queue %i\n",
234 card->qdio.default_out_queue);
239 qeth_dev_prioqing_store(struct device *dev, const char *buf, size_t count)
241 struct qeth_card *card = dev->driver_data;
247 if ((card->state != CARD_STATE_DOWN) &&
248 (card->state != CARD_STATE_RECOVER))
251 tmp = strsep((char **) &buf, "\n");
252 if (!strcmp(tmp, "prio_queueing_prec"))
253 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
254 else if (!strcmp(tmp, "prio_queueing_tos"))
255 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
256 else if (!strcmp(tmp, "no_prio_queueing:0")) {
257 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
258 card->qdio.default_out_queue = 0;
259 } else if (!strcmp(tmp, "no_prio_queueing:1")) {
260 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
261 card->qdio.default_out_queue = 1;
262 } else if (!strcmp(tmp, "no_prio_queueing:2")) {
263 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
264 card->qdio.default_out_queue = 2;
265 } else if (!strcmp(tmp, "no_prio_queueing:3")) {
266 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
267 card->qdio.default_out_queue = 3;
268 } else if (!strcmp(tmp, "no_prio_queueing")) {
269 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
270 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
272 PRINT_WARN("Unknown queueing type '%s'\n", tmp);
278 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
279 qeth_dev_prioqing_store);
282 qeth_dev_bufcnt_show(struct device *dev, char *buf)
284 struct qeth_card *card = dev->driver_data;
289 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
293 qeth_dev_bufcnt_store(struct device *dev, const char *buf, size_t count)
295 struct qeth_card *card = dev->driver_data;
303 if ((card->state != CARD_STATE_DOWN) &&
304 (card->state != CARD_STATE_RECOVER))
307 old_cnt = card->qdio.in_buf_pool.buf_count;
308 cnt = simple_strtoul(buf, &tmp, 10);
309 cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
310 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
311 if (old_cnt != cnt) {
312 if ((rc = qeth_realloc_buffer_pool(card, cnt)))
313 PRINT_WARN("Error (%d) while setting "
314 "buffer count.\n", rc);
319 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
320 qeth_dev_bufcnt_store);
322 static inline ssize_t
323 qeth_dev_route_show(struct qeth_routing_info *route, char *buf)
325 switch (route->type) {
327 return sprintf(buf, "%s\n", "primary router");
328 case SECONDARY_ROUTER:
329 return sprintf(buf, "%s\n", "secondary router");
330 case MULTICAST_ROUTER:
331 return sprintf(buf, "%s\n", "multicast router");
332 case PRIMARY_CONNECTOR:
333 return sprintf(buf, "%s\n", "primary connector");
334 case SECONDARY_CONNECTOR:
335 return sprintf(buf, "%s\n", "secondary connector");
337 return sprintf(buf, "%s\n", "no");
342 qeth_dev_route4_show(struct device *dev, char *buf)
344 struct qeth_card *card = dev->driver_data;
349 return qeth_dev_route_show(&card->options.route4, buf);
352 static inline ssize_t
353 qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
354 enum qeth_prot_versions prot, const char *buf, size_t count)
356 enum qeth_routing_types old_route_type = route->type;
360 tmp = strsep((char **) &buf, "\n");
362 if (!strcmp(tmp, "no_router")){
363 route->type = NO_ROUTER;
364 } else if (!strcmp(tmp, "primary_connector")) {
365 route->type = PRIMARY_CONNECTOR;
366 } else if (!strcmp(tmp, "secondary_connector")) {
367 route->type = SECONDARY_CONNECTOR;
368 } else if (!strcmp(tmp, "multicast_router")) {
369 route->type = MULTICAST_ROUTER;
370 } else if (!strcmp(tmp, "primary_router")) {
371 route->type = PRIMARY_ROUTER;
372 } else if (!strcmp(tmp, "secondary_router")) {
373 route->type = SECONDARY_ROUTER;
374 } else if (!strcmp(tmp, "multicast_router")) {
375 route->type = MULTICAST_ROUTER;
377 PRINT_WARN("Invalid routing type '%s'.\n", tmp);
380 if (((card->state == CARD_STATE_SOFTSETUP) ||
381 (card->state == CARD_STATE_UP)) &&
382 (old_route_type != route->type)){
383 if (prot == QETH_PROT_IPV4)
384 rc = qeth_setrouting_v4(card);
385 else if (prot == QETH_PROT_IPV6)
386 rc = qeth_setrouting_v6(card);
392 qeth_dev_route4_store(struct device *dev, const char *buf, size_t count)
394 struct qeth_card *card = dev->driver_data;
399 return qeth_dev_route_store(card, &card->options.route4,
400 QETH_PROT_IPV4, buf, count);
403 static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
405 #ifdef CONFIG_QETH_IPV6
407 qeth_dev_route6_show(struct device *dev, char *buf)
409 struct qeth_card *card = dev->driver_data;
414 if (!qeth_is_supported(card, IPA_IPV6))
415 return sprintf(buf, "%s\n", "n/a");
417 return qeth_dev_route_show(&card->options.route6, buf);
421 qeth_dev_route6_store(struct device *dev, const char *buf, size_t count)
423 struct qeth_card *card = dev->driver_data;
428 if (!qeth_is_supported(card, IPA_IPV6)){
429 PRINT_WARN("IPv6 not supported for interface %s.\n"
430 "Routing status no changed.\n",
435 return qeth_dev_route_store(card, &card->options.route6,
436 QETH_PROT_IPV6, buf, count);
439 static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
443 qeth_dev_add_hhlen_show(struct device *dev, char *buf)
445 struct qeth_card *card = dev->driver_data;
450 return sprintf(buf, "%i\n", card->options.add_hhlen);
454 qeth_dev_add_hhlen_store(struct device *dev, const char *buf, size_t count)
456 struct qeth_card *card = dev->driver_data;
463 if ((card->state != CARD_STATE_DOWN) &&
464 (card->state != CARD_STATE_RECOVER))
467 i = simple_strtoul(buf, &tmp, 16);
468 if ((i < 0) || (i > MAX_ADD_HHLEN)) {
469 PRINT_WARN("add_hhlen out of range\n");
472 card->options.add_hhlen = i;
477 static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
478 qeth_dev_add_hhlen_store);
481 qeth_dev_fake_ll_show(struct device *dev, char *buf)
483 struct qeth_card *card = dev->driver_data;
488 return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
492 qeth_dev_fake_ll_store(struct device *dev, const char *buf, size_t count)
494 struct qeth_card *card = dev->driver_data;
501 if ((card->state != CARD_STATE_DOWN) &&
502 (card->state != CARD_STATE_RECOVER))
505 i = simple_strtoul(buf, &tmp, 16);
506 if ((i == 0) || (i == 1))
507 card->options.fake_ll = i;
509 PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
515 static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
516 qeth_dev_fake_ll_store);
519 qeth_dev_fake_broadcast_show(struct device *dev, char *buf)
521 struct qeth_card *card = dev->driver_data;
526 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
530 qeth_dev_fake_broadcast_store(struct device *dev, const char *buf, size_t count)
532 struct qeth_card *card = dev->driver_data;
539 if ((card->state != CARD_STATE_DOWN) &&
540 (card->state != CARD_STATE_RECOVER))
543 i = simple_strtoul(buf, &tmp, 16);
544 if ((i == 0) || (i == 1))
545 card->options.fake_broadcast = i;
547 PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
553 static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
554 qeth_dev_fake_broadcast_store);
557 qeth_dev_recover_store(struct device *dev, const char *buf, size_t count)
559 struct qeth_card *card = dev->driver_data;
566 if (card->state != CARD_STATE_UP)
569 i = simple_strtoul(buf, &tmp, 16);
571 qeth_schedule_recovery(card);
576 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
579 qeth_dev_broadcast_mode_show(struct device *dev, char *buf)
581 struct qeth_card *card = dev->driver_data;
586 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
587 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
588 return sprintf(buf, "n/a\n");
590 return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
591 QETH_TR_BROADCAST_ALLRINGS)?
592 "all rings":"local");
596 qeth_dev_broadcast_mode_store(struct device *dev, const char *buf, size_t count)
598 struct qeth_card *card = dev->driver_data;
604 if ((card->state != CARD_STATE_DOWN) &&
605 (card->state != CARD_STATE_RECOVER))
608 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
609 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
610 PRINT_WARN("Device is not a tokenring device!\n");
614 tmp = strsep((char **) &buf, "\n");
616 if (!strcmp(tmp, "local")){
617 card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
619 } else if (!strcmp(tmp, "all_rings")) {
620 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
623 PRINT_WARN("broadcast_mode: invalid mode %s!\n",
630 static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
631 qeth_dev_broadcast_mode_store);
634 qeth_dev_canonical_macaddr_show(struct device *dev, char *buf)
636 struct qeth_card *card = dev->driver_data;
641 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
642 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
643 return sprintf(buf, "n/a\n");
645 return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
646 QETH_TR_MACADDR_CANONICAL)? 1:0);
650 qeth_dev_canonical_macaddr_store(struct device *dev, const char *buf,
653 struct qeth_card *card = dev->driver_data;
660 if ((card->state != CARD_STATE_DOWN) &&
661 (card->state != CARD_STATE_RECOVER))
664 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
665 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
666 PRINT_WARN("Device is not a tokenring device!\n");
670 i = simple_strtoul(buf, &tmp, 16);
671 if ((i == 0) || (i == 1))
672 card->options.macaddr_mode = i?
673 QETH_TR_MACADDR_CANONICAL :
674 QETH_TR_MACADDR_NONCANONICAL;
676 PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
682 static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
683 qeth_dev_canonical_macaddr_store);
685 static struct device_attribute * qeth_device_attrs[] = {
692 &dev_attr_checksumming,
693 &dev_attr_priority_queueing,
694 &dev_attr_buffer_count,
696 #ifdef CONFIG_QETH_IPV6
701 &dev_attr_fake_broadcast,
703 &dev_attr_broadcast_mode,
704 &dev_attr_canonical_macaddr,
708 static struct attribute_group qeth_device_attr_group = {
709 .attrs = (struct attribute **)qeth_device_attrs,
713 #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
714 struct device_attribute dev_attr_##_id = { \
715 .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
721 qeth_dev_ipato_enable_show(struct device *dev, char *buf)
723 struct qeth_card *card = dev->driver_data;
728 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
732 qeth_dev_ipato_enable_store(struct device *dev, const char *buf, size_t count)
734 struct qeth_card *card = dev->driver_data;
740 tmp = strsep((char **) &buf, "\n");
741 if (!strcmp(tmp, "toggle")){
742 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
743 } else if (!strcmp(tmp, "1")){
744 card->ipato.enabled = 1;
745 } else if (!strcmp(tmp, "0")){
746 card->ipato.enabled = 0;
748 PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
755 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
756 qeth_dev_ipato_enable_show,
757 qeth_dev_ipato_enable_store);
760 qeth_dev_ipato_invert4_show(struct device *dev, char *buf)
762 struct qeth_card *card = dev->driver_data;
767 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
771 qeth_dev_ipato_invert4_store(struct device *dev, const char *buf, size_t count)
773 struct qeth_card *card = dev->driver_data;
779 tmp = strsep((char **) &buf, "\n");
780 if (!strcmp(tmp, "toggle")){
781 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
782 } else if (!strcmp(tmp, "1")){
783 card->ipato.invert4 = 1;
784 } else if (!strcmp(tmp, "0")){
785 card->ipato.invert4 = 0;
787 PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
794 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
795 qeth_dev_ipato_invert4_show,
796 qeth_dev_ipato_invert4_store);
798 static inline ssize_t
799 qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
800 enum qeth_prot_versions proto)
802 struct qeth_ipato_entry *ipatoe;
807 spin_lock_irqsave(&card->ip_lock, flags);
808 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
809 if (ipatoe->proto != proto)
811 qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
812 i += sprintf(buf + i, "%s/%i\n", addr_str, ipatoe->mask_bits);
814 spin_unlock_irqrestore(&card->ip_lock, flags);
815 i += sprintf(buf + i, "\n");
821 qeth_dev_ipato_add4_show(struct device *dev, char *buf)
823 struct qeth_card *card = dev->driver_data;
828 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
832 qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
833 u8 *addr, int *mask_bits)
835 const char *start, *end;
837 char buffer[49] = {0, };
840 /* get address string */
841 end = strchr(start, '/');
843 PRINT_WARN("Invalid format for ipato_addx/delx. "
844 "Use <ip addr>/<mask bits>\n");
847 strncpy(buffer, start, end - start);
848 if (qeth_string_to_ipaddr(buffer, proto, addr)){
849 PRINT_WARN("Invalid IP address format!\n");
853 *mask_bits = simple_strtoul(start, &tmp, 10);
858 static inline ssize_t
859 qeth_dev_ipato_add_store(const char *buf, size_t count,
860 struct qeth_card *card, enum qeth_prot_versions proto)
862 struct qeth_ipato_entry *ipatoe;
867 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
870 if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
871 PRINT_WARN("No memory to allocate ipato entry\n");
874 memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
875 ipatoe->proto = proto;
876 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
877 ipatoe->mask_bits = mask_bits;
879 if ((rc = qeth_add_ipato_entry(card, ipatoe))){
888 qeth_dev_ipato_add4_store(struct device *dev, const char *buf, size_t count)
890 struct qeth_card *card = dev->driver_data;
895 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
898 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
899 qeth_dev_ipato_add4_show,
900 qeth_dev_ipato_add4_store);
902 static inline ssize_t
903 qeth_dev_ipato_del_store(const char *buf, size_t count,
904 struct qeth_card *card, enum qeth_prot_versions proto)
910 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
913 qeth_del_ipato_entry(card, proto, addr, mask_bits);
919 qeth_dev_ipato_del4_store(struct device *dev, const char *buf, size_t count)
921 struct qeth_card *card = dev->driver_data;
926 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
929 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
930 qeth_dev_ipato_del4_store);
932 #ifdef CONFIG_QETH_IPV6
934 qeth_dev_ipato_invert6_show(struct device *dev, char *buf)
936 struct qeth_card *card = dev->driver_data;
941 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
945 qeth_dev_ipato_invert6_store(struct device *dev, const char *buf, size_t count)
947 struct qeth_card *card = dev->driver_data;
953 tmp = strsep((char **) &buf, "\n");
954 if (!strcmp(tmp, "toggle")){
955 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
956 } else if (!strcmp(tmp, "1")){
957 card->ipato.invert6 = 1;
958 } else if (!strcmp(tmp, "0")){
959 card->ipato.invert6 = 0;
961 PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
968 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
969 qeth_dev_ipato_invert6_show,
970 qeth_dev_ipato_invert6_store);
974 qeth_dev_ipato_add6_show(struct device *dev, char *buf)
976 struct qeth_card *card = dev->driver_data;
981 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
985 qeth_dev_ipato_add6_store(struct device *dev, const char *buf, size_t count)
987 struct qeth_card *card = dev->driver_data;
992 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
995 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
996 qeth_dev_ipato_add6_show,
997 qeth_dev_ipato_add6_store);
1000 qeth_dev_ipato_del6_store(struct device *dev, const char *buf, size_t count)
1002 struct qeth_card *card = dev->driver_data;
1007 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
1010 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
1011 qeth_dev_ipato_del6_store);
1012 #endif /* CONFIG_QETH_IPV6 */
1014 static struct device_attribute * qeth_ipato_device_attrs[] = {
1015 &dev_attr_ipato_enable,
1016 &dev_attr_ipato_invert4,
1017 &dev_attr_ipato_add4,
1018 &dev_attr_ipato_del4,
1019 #ifdef CONFIG_QETH_IPV6
1020 &dev_attr_ipato_invert6,
1021 &dev_attr_ipato_add6,
1022 &dev_attr_ipato_del6,
1027 static struct attribute_group qeth_device_ipato_group = {
1028 .name = "ipa_takeover",
1029 .attrs = (struct attribute **)qeth_ipato_device_attrs,
1032 static inline ssize_t
1033 qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
1034 enum qeth_prot_versions proto)
1036 struct qeth_ipaddr *ipaddr;
1038 unsigned long flags;
1041 spin_lock_irqsave(&card->ip_lock, flags);
1042 list_for_each_entry(ipaddr, &card->ip_list, entry){
1043 if (ipaddr->proto != proto)
1045 if (ipaddr->type != QETH_IP_TYPE_VIPA)
1047 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1048 i += sprintf(buf + i, "%s\n", addr_str);
1050 spin_unlock_irqrestore(&card->ip_lock, flags);
1051 i += sprintf(buf + i, "\n");
1057 qeth_dev_vipa_add4_show(struct device *dev, char *buf)
1059 struct qeth_card *card = dev->driver_data;
1064 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
1068 qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
1071 if (qeth_string_to_ipaddr(buf, proto, addr)){
1072 PRINT_WARN("Invalid IP address format!\n");
1078 static inline ssize_t
1079 qeth_dev_vipa_add_store(const char *buf, size_t count,
1080 struct qeth_card *card, enum qeth_prot_versions proto)
1082 u8 addr[16] = {0, };
1085 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1088 if ((rc = qeth_add_vipa(card, proto, addr)))
1095 qeth_dev_vipa_add4_store(struct device *dev, const char *buf, size_t count)
1097 struct qeth_card *card = dev->driver_data;
1102 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
1105 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
1106 qeth_dev_vipa_add4_show,
1107 qeth_dev_vipa_add4_store);
1109 static inline ssize_t
1110 qeth_dev_vipa_del_store(const char *buf, size_t count,
1111 struct qeth_card *card, enum qeth_prot_versions proto)
1116 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1119 qeth_del_vipa(card, proto, addr);
1125 qeth_dev_vipa_del4_store(struct device *dev, const char *buf, size_t count)
1127 struct qeth_card *card = dev->driver_data;
1132 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
1135 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
1136 qeth_dev_vipa_del4_store);
1138 #ifdef CONFIG_QETH_IPV6
1140 qeth_dev_vipa_add6_show(struct device *dev, char *buf)
1142 struct qeth_card *card = dev->driver_data;
1147 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
1151 qeth_dev_vipa_add6_store(struct device *dev, const char *buf, size_t count)
1153 struct qeth_card *card = dev->driver_data;
1158 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
1161 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
1162 qeth_dev_vipa_add6_show,
1163 qeth_dev_vipa_add6_store);
1166 qeth_dev_vipa_del6_store(struct device *dev, const char *buf, size_t count)
1168 struct qeth_card *card = dev->driver_data;
1173 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
1176 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
1177 qeth_dev_vipa_del6_store);
1178 #endif /* CONFIG_QETH_IPV6 */
1180 static struct device_attribute * qeth_vipa_device_attrs[] = {
1181 &dev_attr_vipa_add4,
1182 &dev_attr_vipa_del4,
1183 #ifdef CONFIG_QETH_IPV6
1184 &dev_attr_vipa_add6,
1185 &dev_attr_vipa_del6,
1190 static struct attribute_group qeth_device_vipa_group = {
1192 .attrs = (struct attribute **)qeth_vipa_device_attrs,
1195 static inline ssize_t
1196 qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
1197 enum qeth_prot_versions proto)
1199 struct qeth_ipaddr *ipaddr;
1201 unsigned long flags;
1204 spin_lock_irqsave(&card->ip_lock, flags);
1205 list_for_each_entry(ipaddr, &card->ip_list, entry){
1206 if (ipaddr->proto != proto)
1208 if (ipaddr->type != QETH_IP_TYPE_RXIP)
1210 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1211 i += sprintf(buf + i, "%s\n", addr_str);
1213 spin_unlock_irqrestore(&card->ip_lock, flags);
1214 i += sprintf(buf + i, "\n");
1220 qeth_dev_rxip_add4_show(struct device *dev, char *buf)
1222 struct qeth_card *card = dev->driver_data;
1227 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
1231 qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
1234 if (qeth_string_to_ipaddr(buf, proto, addr)){
1235 PRINT_WARN("Invalid IP address format!\n");
1241 static inline ssize_t
1242 qeth_dev_rxip_add_store(const char *buf, size_t count,
1243 struct qeth_card *card, enum qeth_prot_versions proto)
1245 u8 addr[16] = {0, };
1248 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1251 if ((rc = qeth_add_rxip(card, proto, addr)))
1258 qeth_dev_rxip_add4_store(struct device *dev, const char *buf, size_t count)
1260 struct qeth_card *card = dev->driver_data;
1265 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
1268 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
1269 qeth_dev_rxip_add4_show,
1270 qeth_dev_rxip_add4_store);
1272 static inline ssize_t
1273 qeth_dev_rxip_del_store(const char *buf, size_t count,
1274 struct qeth_card *card, enum qeth_prot_versions proto)
1279 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1282 qeth_del_rxip(card, proto, addr);
1288 qeth_dev_rxip_del4_store(struct device *dev, const char *buf, size_t count)
1290 struct qeth_card *card = dev->driver_data;
1295 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
1298 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
1299 qeth_dev_rxip_del4_store);
1301 #ifdef CONFIG_QETH_IPV6
1303 qeth_dev_rxip_add6_show(struct device *dev, char *buf)
1305 struct qeth_card *card = dev->driver_data;
1310 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
1314 qeth_dev_rxip_add6_store(struct device *dev, const char *buf, size_t count)
1316 struct qeth_card *card = dev->driver_data;
1321 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1324 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1325 qeth_dev_rxip_add6_show,
1326 qeth_dev_rxip_add6_store);
1329 qeth_dev_rxip_del6_store(struct device *dev, const char *buf, size_t count)
1331 struct qeth_card *card = dev->driver_data;
1336 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1339 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1340 qeth_dev_rxip_del6_store);
1341 #endif /* CONFIG_QETH_IPV6 */
1343 static struct device_attribute * qeth_rxip_device_attrs[] = {
1344 &dev_attr_rxip_add4,
1345 &dev_attr_rxip_del4,
1346 #ifdef CONFIG_QETH_IPV6
1347 &dev_attr_rxip_add6,
1348 &dev_attr_rxip_del6,
1353 static struct attribute_group qeth_device_rxip_group = {
1355 .attrs = (struct attribute **)qeth_rxip_device_attrs,
1359 qeth_create_device_attributes(struct device *dev)
1363 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1365 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
1366 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1369 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
1370 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1371 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1374 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
1375 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1376 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1377 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1384 qeth_remove_device_attributes(struct device *dev)
1386 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1387 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1388 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1389 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1392 /**********************/
1393 /* DRIVER ATTRIBUTES */
1394 /**********************/
1396 qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1399 const char *start, *end;
1400 char bus_ids[3][BUS_ID_SIZE], *argv[3];
1405 for (i = 0; i < 3; i++) {
1406 static const char delim[] = { ',', ',', '\n' };
1409 if (!(end = strchr(start, delim[i])))
1411 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
1412 strncpy(bus_ids[i], start, len);
1413 bus_ids[i][len] = '\0';
1415 argv[i] = bus_ids[i];
1417 err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
1418 &qeth_ccw_driver, 3, argv);
1426 static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
1429 qeth_driver_snmp_register_show(struct device_driver *ddrv, char *buf)
1436 qeth_driver_snmp_register_store(struct device_driver *ddrv, const char *buf,
1443 static DRIVER_ATTR(snmp_register, 0644, qeth_driver_snmp_register_show,
1444 qeth_driver_snmp_register_store);
1447 qeth_create_driver_attributes(void)
1451 if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
1452 &driver_attr_group)))
1454 return driver_create_file(&qeth_ccwgroup_driver.driver,
1455 &driver_attr_snmp_register);
1459 qeth_remove_driver_attributes(void)
1461 driver_remove_file(&qeth_ccwgroup_driver.driver,
1462 &driver_attr_group);
1463 driver_remove_file(&qeth_ccwgroup_driver.driver,
1464 &driver_attr_snmp_register);