3 * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.32 $)
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 const char *VERSION_QETH_SYS_C = "$Revision: 1.32 $";
25 /*****************************************************************************/
27 /* /sys-fs stuff UNDER DEVELOPMENT !!! */
29 /*****************************************************************************/
33 qeth_dev_state_show(struct device *dev, char *buf)
35 struct qeth_card *card = dev->driver_data;
39 switch (card->state) {
41 return sprintf(buf, "DOWN\n");
42 case CARD_STATE_HARDSETUP:
43 return sprintf(buf, "HARDSETUP\n");
44 case CARD_STATE_SOFTSETUP:
45 return sprintf(buf, "SOFTSETUP\n");
48 return sprintf(buf, "UP (LAN ONLINE)\n");
50 return sprintf(buf, "UP (LAN OFFLINE)\n");
51 case CARD_STATE_RECOVER:
52 return sprintf(buf, "RECOVER\n");
54 return sprintf(buf, "UNKNOWN\n");
58 static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
61 qeth_dev_chpid_show(struct device *dev, char *buf)
63 struct qeth_card *card = dev->driver_data;
67 return sprintf(buf, "%02X\n", card->info.chpid);
70 static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
73 qeth_dev_if_name_show(struct device *dev, char *buf)
75 struct qeth_card *card = dev->driver_data;
79 return sprintf(buf, "%s\n", card->info.if_name);
82 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
85 qeth_dev_card_type_show(struct device *dev, char *buf)
87 struct qeth_card *card = dev->driver_data;
91 return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
94 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
97 qeth_dev_portno_show(struct device *dev, char *buf)
99 struct qeth_card *card = dev->driver_data;
103 return sprintf(buf, "%i\n", card->info.portno);
107 qeth_dev_portno_store(struct device *dev, const char *buf, size_t count)
109 struct qeth_card *card = dev->driver_data;
116 if ((card->state != CARD_STATE_DOWN) &&
117 (card->state != CARD_STATE_RECOVER))
120 portno = simple_strtoul(buf, &tmp, 16);
121 if ((portno < 0) || (portno > MAX_PORTNO)){
122 PRINT_WARN("portno 0x%X is out of range\n", portno);
126 card->info.portno = portno;
130 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
133 qeth_dev_portname_show(struct device *dev, char *buf)
135 struct qeth_card *card = dev->driver_data;
136 char portname[9] = {0, };
141 if (card->info.portname_required) {
142 memcpy(portname, card->info.portname + 1, 8);
144 return sprintf(buf, "%s\n", portname);
146 return sprintf(buf, "no portname required\n");
150 qeth_dev_portname_store(struct device *dev, const char *buf, size_t count)
152 struct qeth_card *card = dev->driver_data;
159 if ((card->state != CARD_STATE_DOWN) &&
160 (card->state != CARD_STATE_RECOVER))
163 tmp = strsep((char **) &buf, "\n");
164 if ((strlen(tmp) > 8) || (strlen(tmp) < 2))
167 card->info.portname[0] = strlen(tmp);
168 /* for beauty reasons */
169 for (i = 1; i < 9; i++)
170 card->info.portname[i] = ' ';
171 strcpy(card->info.portname + 1, tmp);
172 ASCEBC(card->info.portname + 1, 8);
177 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
178 qeth_dev_portname_store);
181 qeth_dev_checksum_show(struct device *dev, char *buf)
183 struct qeth_card *card = dev->driver_data;
188 return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
192 qeth_dev_checksum_store(struct device *dev, const char *buf, size_t count)
194 struct qeth_card *card = dev->driver_data;
200 if ((card->state != CARD_STATE_DOWN) &&
201 (card->state != CARD_STATE_RECOVER))
204 tmp = strsep((char **) &buf, "\n");
205 if (!strcmp(tmp, "sw_checksumming"))
206 card->options.checksum_type = SW_CHECKSUMMING;
207 else if (!strcmp(tmp, "hw_checksumming"))
208 card->options.checksum_type = HW_CHECKSUMMING;
209 else if (!strcmp(tmp, "no_checksumming"))
210 card->options.checksum_type = NO_CHECKSUMMING;
212 PRINT_WARN("Unknown checksumming type '%s'\n", tmp);
218 static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
219 qeth_dev_checksum_store);
222 qeth_dev_prioqing_show(struct device *dev, char *buf)
224 struct qeth_card *card = dev->driver_data;
229 switch (card->qdio.do_prio_queueing) {
230 case QETH_PRIO_Q_ING_PREC:
231 return sprintf(buf, "%s\n", "by precedence");
232 case QETH_PRIO_Q_ING_TOS:
233 return sprintf(buf, "%s\n", "by type of service");
235 return sprintf(buf, "always queue %i\n",
236 card->qdio.default_out_queue);
241 qeth_dev_prioqing_store(struct device *dev, const char *buf, size_t count)
243 struct qeth_card *card = dev->driver_data;
249 if ((card->state != CARD_STATE_DOWN) &&
250 (card->state != CARD_STATE_RECOVER))
253 tmp = strsep((char **) &buf, "\n");
254 if (!strcmp(tmp, "prio_queueing_prec"))
255 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
256 else if (!strcmp(tmp, "prio_queueing_tos"))
257 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
258 else if (!strcmp(tmp, "no_prio_queueing:0")) {
259 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
260 card->qdio.default_out_queue = 0;
261 } else if (!strcmp(tmp, "no_prio_queueing:1")) {
262 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
263 card->qdio.default_out_queue = 1;
264 } else if (!strcmp(tmp, "no_prio_queueing:2")) {
265 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
266 card->qdio.default_out_queue = 2;
267 } else if (!strcmp(tmp, "no_prio_queueing:3")) {
268 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
269 card->qdio.default_out_queue = 3;
270 } else if (!strcmp(tmp, "no_prio_queueing")) {
271 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
272 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
274 PRINT_WARN("Unknown queueing type '%s'\n", tmp);
280 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
281 qeth_dev_prioqing_store);
284 qeth_dev_bufcnt_show(struct device *dev, char *buf)
286 struct qeth_card *card = dev->driver_data;
291 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
295 qeth_dev_bufcnt_store(struct device *dev, const char *buf, size_t count)
297 struct qeth_card *card = dev->driver_data;
305 if ((card->state != CARD_STATE_DOWN) &&
306 (card->state != CARD_STATE_RECOVER))
309 old_cnt = card->qdio.in_buf_pool.buf_count;
310 cnt = simple_strtoul(buf, &tmp, 10);
311 cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
312 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
313 if (old_cnt != cnt) {
314 if ((rc = qeth_realloc_buffer_pool(card, cnt)))
315 PRINT_WARN("Error (%d) while setting "
316 "buffer count.\n", rc);
321 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
322 qeth_dev_bufcnt_store);
324 static inline ssize_t
325 qeth_dev_route_show(struct qeth_card *card, struct qeth_routing_info *route,
328 switch (route->type) {
330 return sprintf(buf, "%s\n", "primary router");
331 case SECONDARY_ROUTER:
332 return sprintf(buf, "%s\n", "secondary router");
333 case MULTICAST_ROUTER:
334 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
335 return sprintf(buf, "%s\n", "multicast router+");
337 return sprintf(buf, "%s\n", "multicast router");
338 case PRIMARY_CONNECTOR:
339 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
340 return sprintf(buf, "%s\n", "primary connector+");
342 return sprintf(buf, "%s\n", "primary connector");
343 case SECONDARY_CONNECTOR:
344 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
345 return sprintf(buf, "%s\n", "secondary connector+");
347 return sprintf(buf, "%s\n", "secondary connector");
349 return sprintf(buf, "%s\n", "no");
354 qeth_dev_route4_show(struct device *dev, char *buf)
356 struct qeth_card *card = dev->driver_data;
361 return qeth_dev_route_show(card, &card->options.route4, buf);
364 static inline ssize_t
365 qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
366 enum qeth_prot_versions prot, const char *buf, size_t count)
368 enum qeth_routing_types old_route_type = route->type;
372 tmp = strsep((char **) &buf, "\n");
374 if (!strcmp(tmp, "no_router")){
375 route->type = NO_ROUTER;
376 } else if (!strcmp(tmp, "primary_connector")) {
377 route->type = PRIMARY_CONNECTOR;
378 } else if (!strcmp(tmp, "secondary_connector")) {
379 route->type = SECONDARY_CONNECTOR;
380 } else if (!strcmp(tmp, "multicast_router")) {
381 route->type = MULTICAST_ROUTER;
382 } else if (!strcmp(tmp, "primary_router")) {
383 route->type = PRIMARY_ROUTER;
384 } else if (!strcmp(tmp, "secondary_router")) {
385 route->type = SECONDARY_ROUTER;
386 } else if (!strcmp(tmp, "multicast_router")) {
387 route->type = MULTICAST_ROUTER;
389 PRINT_WARN("Invalid routing type '%s'.\n", tmp);
392 if (((card->state == CARD_STATE_SOFTSETUP) ||
393 (card->state == CARD_STATE_UP)) &&
394 (old_route_type != route->type)){
395 if (prot == QETH_PROT_IPV4)
396 rc = qeth_setrouting_v4(card);
397 else if (prot == QETH_PROT_IPV6)
398 rc = qeth_setrouting_v6(card);
404 qeth_dev_route4_store(struct device *dev, const char *buf, size_t count)
406 struct qeth_card *card = dev->driver_data;
411 return qeth_dev_route_store(card, &card->options.route4,
412 QETH_PROT_IPV4, buf, count);
415 static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
417 #ifdef CONFIG_QETH_IPV6
419 qeth_dev_route6_show(struct device *dev, char *buf)
421 struct qeth_card *card = dev->driver_data;
426 if (!qeth_is_supported(card, IPA_IPV6))
427 return sprintf(buf, "%s\n", "n/a");
429 return qeth_dev_route_show(card, &card->options.route6, buf);
433 qeth_dev_route6_store(struct device *dev, const char *buf, size_t count)
435 struct qeth_card *card = dev->driver_data;
440 if (!qeth_is_supported(card, IPA_IPV6)){
441 PRINT_WARN("IPv6 not supported for interface %s.\n"
442 "Routing status no changed.\n",
447 return qeth_dev_route_store(card, &card->options.route6,
448 QETH_PROT_IPV6, buf, count);
451 static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
455 qeth_dev_add_hhlen_show(struct device *dev, char *buf)
457 struct qeth_card *card = dev->driver_data;
462 return sprintf(buf, "%i\n", card->options.add_hhlen);
466 qeth_dev_add_hhlen_store(struct device *dev, const char *buf, size_t count)
468 struct qeth_card *card = dev->driver_data;
475 if ((card->state != CARD_STATE_DOWN) &&
476 (card->state != CARD_STATE_RECOVER))
479 i = simple_strtoul(buf, &tmp, 16);
480 if ((i < 0) || (i > MAX_ADD_HHLEN)) {
481 PRINT_WARN("add_hhlen out of range\n");
484 card->options.add_hhlen = i;
489 static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
490 qeth_dev_add_hhlen_store);
493 qeth_dev_fake_ll_show(struct device *dev, char *buf)
495 struct qeth_card *card = dev->driver_data;
500 return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
504 qeth_dev_fake_ll_store(struct device *dev, const char *buf, size_t count)
506 struct qeth_card *card = dev->driver_data;
513 if ((card->state != CARD_STATE_DOWN) &&
514 (card->state != CARD_STATE_RECOVER))
517 i = simple_strtoul(buf, &tmp, 16);
518 if ((i == 0) || (i == 1))
519 card->options.fake_ll = i;
521 PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
527 static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
528 qeth_dev_fake_ll_store);
531 qeth_dev_fake_broadcast_show(struct device *dev, char *buf)
533 struct qeth_card *card = dev->driver_data;
538 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
542 qeth_dev_fake_broadcast_store(struct device *dev, const char *buf, size_t count)
544 struct qeth_card *card = dev->driver_data;
551 if ((card->state != CARD_STATE_DOWN) &&
552 (card->state != CARD_STATE_RECOVER))
555 i = simple_strtoul(buf, &tmp, 16);
556 if ((i == 0) || (i == 1))
557 card->options.fake_broadcast = i;
559 PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
565 static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
566 qeth_dev_fake_broadcast_store);
569 qeth_dev_recover_store(struct device *dev, const char *buf, size_t count)
571 struct qeth_card *card = dev->driver_data;
578 if (card->state != CARD_STATE_UP)
581 i = simple_strtoul(buf, &tmp, 16);
583 qeth_schedule_recovery(card);
588 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
591 qeth_dev_broadcast_mode_show(struct device *dev, char *buf)
593 struct qeth_card *card = dev->driver_data;
598 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
599 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
600 return sprintf(buf, "n/a\n");
602 return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
603 QETH_TR_BROADCAST_ALLRINGS)?
604 "all rings":"local");
608 qeth_dev_broadcast_mode_store(struct device *dev, const char *buf, size_t count)
610 struct qeth_card *card = dev->driver_data;
616 if ((card->state != CARD_STATE_DOWN) &&
617 (card->state != CARD_STATE_RECOVER))
620 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
621 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
622 PRINT_WARN("Device is not a tokenring device!\n");
626 tmp = strsep((char **) &buf, "\n");
628 if (!strcmp(tmp, "local")){
629 card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
631 } else if (!strcmp(tmp, "all_rings")) {
632 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
635 PRINT_WARN("broadcast_mode: invalid mode %s!\n",
642 static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
643 qeth_dev_broadcast_mode_store);
646 qeth_dev_canonical_macaddr_show(struct device *dev, char *buf)
648 struct qeth_card *card = dev->driver_data;
653 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
654 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
655 return sprintf(buf, "n/a\n");
657 return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
658 QETH_TR_MACADDR_CANONICAL)? 1:0);
662 qeth_dev_canonical_macaddr_store(struct device *dev, const char *buf,
665 struct qeth_card *card = dev->driver_data;
672 if ((card->state != CARD_STATE_DOWN) &&
673 (card->state != CARD_STATE_RECOVER))
676 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
677 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
678 PRINT_WARN("Device is not a tokenring device!\n");
682 i = simple_strtoul(buf, &tmp, 16);
683 if ((i == 0) || (i == 1))
684 card->options.macaddr_mode = i?
685 QETH_TR_MACADDR_CANONICAL :
686 QETH_TR_MACADDR_NONCANONICAL;
688 PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
694 static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
695 qeth_dev_canonical_macaddr_store);
697 static struct device_attribute * qeth_device_attrs[] = {
704 &dev_attr_checksumming,
705 &dev_attr_priority_queueing,
706 &dev_attr_buffer_count,
708 #ifdef CONFIG_QETH_IPV6
713 &dev_attr_fake_broadcast,
715 &dev_attr_broadcast_mode,
716 &dev_attr_canonical_macaddr,
720 static struct attribute_group qeth_device_attr_group = {
721 .attrs = (struct attribute **)qeth_device_attrs,
725 #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
726 struct device_attribute dev_attr_##_id = { \
727 .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
733 qeth_dev_ipato_enable_show(struct device *dev, char *buf)
735 struct qeth_card *card = dev->driver_data;
740 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
744 qeth_dev_ipato_enable_store(struct device *dev, const char *buf, size_t count)
746 struct qeth_card *card = dev->driver_data;
752 if ((card->state != CARD_STATE_DOWN) &&
753 (card->state != CARD_STATE_RECOVER))
756 tmp = strsep((char **) &buf, "\n");
757 if (!strcmp(tmp, "toggle")){
758 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
759 } else if (!strcmp(tmp, "1")){
760 card->ipato.enabled = 1;
761 } else if (!strcmp(tmp, "0")){
762 card->ipato.enabled = 0;
764 PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
771 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
772 qeth_dev_ipato_enable_show,
773 qeth_dev_ipato_enable_store);
776 qeth_dev_ipato_invert4_show(struct device *dev, char *buf)
778 struct qeth_card *card = dev->driver_data;
783 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
787 qeth_dev_ipato_invert4_store(struct device *dev, const char *buf, size_t count)
789 struct qeth_card *card = dev->driver_data;
795 tmp = strsep((char **) &buf, "\n");
796 if (!strcmp(tmp, "toggle")){
797 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
798 } else if (!strcmp(tmp, "1")){
799 card->ipato.invert4 = 1;
800 } else if (!strcmp(tmp, "0")){
801 card->ipato.invert4 = 0;
803 PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
810 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
811 qeth_dev_ipato_invert4_show,
812 qeth_dev_ipato_invert4_store);
814 static inline ssize_t
815 qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
816 enum qeth_prot_versions proto)
818 struct qeth_ipato_entry *ipatoe;
823 spin_lock_irqsave(&card->ip_lock, flags);
824 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
825 if (ipatoe->proto != proto)
827 qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
828 i += sprintf(buf + i, "%s/%i\n", addr_str, ipatoe->mask_bits);
830 spin_unlock_irqrestore(&card->ip_lock, flags);
831 i += sprintf(buf + i, "\n");
837 qeth_dev_ipato_add4_show(struct device *dev, char *buf)
839 struct qeth_card *card = dev->driver_data;
844 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
848 qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
849 u8 *addr, int *mask_bits)
851 const char *start, *end;
853 char buffer[49] = {0, };
856 /* get address string */
857 end = strchr(start, '/');
859 PRINT_WARN("Invalid format for ipato_addx/delx. "
860 "Use <ip addr>/<mask bits>\n");
863 strncpy(buffer, start, end - start);
864 if (qeth_string_to_ipaddr(buffer, proto, addr)){
865 PRINT_WARN("Invalid IP address format!\n");
869 *mask_bits = simple_strtoul(start, &tmp, 10);
874 static inline ssize_t
875 qeth_dev_ipato_add_store(const char *buf, size_t count,
876 struct qeth_card *card, enum qeth_prot_versions proto)
878 struct qeth_ipato_entry *ipatoe;
883 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
886 if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
887 PRINT_WARN("No memory to allocate ipato entry\n");
890 memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
891 ipatoe->proto = proto;
892 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
893 ipatoe->mask_bits = mask_bits;
895 if ((rc = qeth_add_ipato_entry(card, ipatoe))){
904 qeth_dev_ipato_add4_store(struct device *dev, const char *buf, size_t count)
906 struct qeth_card *card = dev->driver_data;
911 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
914 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
915 qeth_dev_ipato_add4_show,
916 qeth_dev_ipato_add4_store);
918 static inline ssize_t
919 qeth_dev_ipato_del_store(const char *buf, size_t count,
920 struct qeth_card *card, enum qeth_prot_versions proto)
926 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
929 qeth_del_ipato_entry(card, proto, addr, mask_bits);
935 qeth_dev_ipato_del4_store(struct device *dev, const char *buf, size_t count)
937 struct qeth_card *card = dev->driver_data;
942 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
945 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
946 qeth_dev_ipato_del4_store);
948 #ifdef CONFIG_QETH_IPV6
950 qeth_dev_ipato_invert6_show(struct device *dev, char *buf)
952 struct qeth_card *card = dev->driver_data;
957 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
961 qeth_dev_ipato_invert6_store(struct device *dev, const char *buf, size_t count)
963 struct qeth_card *card = dev->driver_data;
969 tmp = strsep((char **) &buf, "\n");
970 if (!strcmp(tmp, "toggle")){
971 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
972 } else if (!strcmp(tmp, "1")){
973 card->ipato.invert6 = 1;
974 } else if (!strcmp(tmp, "0")){
975 card->ipato.invert6 = 0;
977 PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
984 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
985 qeth_dev_ipato_invert6_show,
986 qeth_dev_ipato_invert6_store);
990 qeth_dev_ipato_add6_show(struct device *dev, char *buf)
992 struct qeth_card *card = dev->driver_data;
997 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
1001 qeth_dev_ipato_add6_store(struct device *dev, const char *buf, size_t count)
1003 struct qeth_card *card = dev->driver_data;
1008 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
1011 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
1012 qeth_dev_ipato_add6_show,
1013 qeth_dev_ipato_add6_store);
1016 qeth_dev_ipato_del6_store(struct device *dev, const char *buf, size_t count)
1018 struct qeth_card *card = dev->driver_data;
1023 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
1026 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
1027 qeth_dev_ipato_del6_store);
1028 #endif /* CONFIG_QETH_IPV6 */
1030 static struct device_attribute * qeth_ipato_device_attrs[] = {
1031 &dev_attr_ipato_enable,
1032 &dev_attr_ipato_invert4,
1033 &dev_attr_ipato_add4,
1034 &dev_attr_ipato_del4,
1035 #ifdef CONFIG_QETH_IPV6
1036 &dev_attr_ipato_invert6,
1037 &dev_attr_ipato_add6,
1038 &dev_attr_ipato_del6,
1043 static struct attribute_group qeth_device_ipato_group = {
1044 .name = "ipa_takeover",
1045 .attrs = (struct attribute **)qeth_ipato_device_attrs,
1048 static inline ssize_t
1049 qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
1050 enum qeth_prot_versions proto)
1052 struct qeth_ipaddr *ipaddr;
1054 unsigned long flags;
1057 spin_lock_irqsave(&card->ip_lock, flags);
1058 list_for_each_entry(ipaddr, &card->ip_list, entry){
1059 if (ipaddr->proto != proto)
1061 if (ipaddr->type != QETH_IP_TYPE_VIPA)
1063 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1064 i += sprintf(buf + i, "%s\n", addr_str);
1066 spin_unlock_irqrestore(&card->ip_lock, flags);
1067 i += sprintf(buf + i, "\n");
1073 qeth_dev_vipa_add4_show(struct device *dev, char *buf)
1075 struct qeth_card *card = dev->driver_data;
1080 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
1084 qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
1087 if (qeth_string_to_ipaddr(buf, proto, addr)){
1088 PRINT_WARN("Invalid IP address format!\n");
1094 static inline ssize_t
1095 qeth_dev_vipa_add_store(const char *buf, size_t count,
1096 struct qeth_card *card, enum qeth_prot_versions proto)
1098 u8 addr[16] = {0, };
1101 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1104 if ((rc = qeth_add_vipa(card, proto, addr)))
1111 qeth_dev_vipa_add4_store(struct device *dev, const char *buf, size_t count)
1113 struct qeth_card *card = dev->driver_data;
1118 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
1121 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
1122 qeth_dev_vipa_add4_show,
1123 qeth_dev_vipa_add4_store);
1125 static inline ssize_t
1126 qeth_dev_vipa_del_store(const char *buf, size_t count,
1127 struct qeth_card *card, enum qeth_prot_versions proto)
1132 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1135 qeth_del_vipa(card, proto, addr);
1141 qeth_dev_vipa_del4_store(struct device *dev, const char *buf, size_t count)
1143 struct qeth_card *card = dev->driver_data;
1148 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
1151 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
1152 qeth_dev_vipa_del4_store);
1154 #ifdef CONFIG_QETH_IPV6
1156 qeth_dev_vipa_add6_show(struct device *dev, char *buf)
1158 struct qeth_card *card = dev->driver_data;
1163 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
1167 qeth_dev_vipa_add6_store(struct device *dev, const char *buf, size_t count)
1169 struct qeth_card *card = dev->driver_data;
1174 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
1177 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
1178 qeth_dev_vipa_add6_show,
1179 qeth_dev_vipa_add6_store);
1182 qeth_dev_vipa_del6_store(struct device *dev, const char *buf, size_t count)
1184 struct qeth_card *card = dev->driver_data;
1189 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
1192 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
1193 qeth_dev_vipa_del6_store);
1194 #endif /* CONFIG_QETH_IPV6 */
1196 static struct device_attribute * qeth_vipa_device_attrs[] = {
1197 &dev_attr_vipa_add4,
1198 &dev_attr_vipa_del4,
1199 #ifdef CONFIG_QETH_IPV6
1200 &dev_attr_vipa_add6,
1201 &dev_attr_vipa_del6,
1206 static struct attribute_group qeth_device_vipa_group = {
1208 .attrs = (struct attribute **)qeth_vipa_device_attrs,
1211 static inline ssize_t
1212 qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
1213 enum qeth_prot_versions proto)
1215 struct qeth_ipaddr *ipaddr;
1217 unsigned long flags;
1220 spin_lock_irqsave(&card->ip_lock, flags);
1221 list_for_each_entry(ipaddr, &card->ip_list, entry){
1222 if (ipaddr->proto != proto)
1224 if (ipaddr->type != QETH_IP_TYPE_RXIP)
1226 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1227 i += sprintf(buf + i, "%s\n", addr_str);
1229 spin_unlock_irqrestore(&card->ip_lock, flags);
1230 i += sprintf(buf + i, "\n");
1236 qeth_dev_rxip_add4_show(struct device *dev, char *buf)
1238 struct qeth_card *card = dev->driver_data;
1243 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
1247 qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
1250 if (qeth_string_to_ipaddr(buf, proto, addr)){
1251 PRINT_WARN("Invalid IP address format!\n");
1257 static inline ssize_t
1258 qeth_dev_rxip_add_store(const char *buf, size_t count,
1259 struct qeth_card *card, enum qeth_prot_versions proto)
1261 u8 addr[16] = {0, };
1264 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1267 if ((rc = qeth_add_rxip(card, proto, addr)))
1274 qeth_dev_rxip_add4_store(struct device *dev, const char *buf, size_t count)
1276 struct qeth_card *card = dev->driver_data;
1281 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
1284 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
1285 qeth_dev_rxip_add4_show,
1286 qeth_dev_rxip_add4_store);
1288 static inline ssize_t
1289 qeth_dev_rxip_del_store(const char *buf, size_t count,
1290 struct qeth_card *card, enum qeth_prot_versions proto)
1295 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1298 qeth_del_rxip(card, proto, addr);
1304 qeth_dev_rxip_del4_store(struct device *dev, const char *buf, size_t count)
1306 struct qeth_card *card = dev->driver_data;
1311 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
1314 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
1315 qeth_dev_rxip_del4_store);
1317 #ifdef CONFIG_QETH_IPV6
1319 qeth_dev_rxip_add6_show(struct device *dev, char *buf)
1321 struct qeth_card *card = dev->driver_data;
1326 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
1330 qeth_dev_rxip_add6_store(struct device *dev, const char *buf, size_t count)
1332 struct qeth_card *card = dev->driver_data;
1337 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1340 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1341 qeth_dev_rxip_add6_show,
1342 qeth_dev_rxip_add6_store);
1345 qeth_dev_rxip_del6_store(struct device *dev, const char *buf, size_t count)
1347 struct qeth_card *card = dev->driver_data;
1352 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1355 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1356 qeth_dev_rxip_del6_store);
1357 #endif /* CONFIG_QETH_IPV6 */
1359 static struct device_attribute * qeth_rxip_device_attrs[] = {
1360 &dev_attr_rxip_add4,
1361 &dev_attr_rxip_del4,
1362 #ifdef CONFIG_QETH_IPV6
1363 &dev_attr_rxip_add6,
1364 &dev_attr_rxip_del6,
1369 static struct attribute_group qeth_device_rxip_group = {
1371 .attrs = (struct attribute **)qeth_rxip_device_attrs,
1375 qeth_create_device_attributes(struct device *dev)
1379 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1381 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
1382 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1385 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
1386 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1387 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1390 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
1391 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1392 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1393 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1400 qeth_remove_device_attributes(struct device *dev)
1402 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1403 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1404 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1405 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1408 /**********************/
1409 /* DRIVER ATTRIBUTES */
1410 /**********************/
1412 qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1415 const char *start, *end;
1416 char bus_ids[3][BUS_ID_SIZE], *argv[3];
1421 for (i = 0; i < 3; i++) {
1422 static const char delim[] = { ',', ',', '\n' };
1425 if (!(end = strchr(start, delim[i])))
1427 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
1428 strncpy(bus_ids[i], start, len);
1429 bus_ids[i][len] = '\0';
1431 argv[i] = bus_ids[i];
1433 err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
1434 &qeth_ccw_driver, 3, argv);
1442 static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
1445 qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
1452 tmp = strsep((char **) &buf, "\n");
1453 if (!strncmp(tmp, "unregister", 10)){
1454 if ((rc = qeth_notifier_unregister(current)))
1459 signum = simple_strtoul(tmp, &tmp2, 10);
1460 if ((signum < 0) || (signum > 32)){
1461 PRINT_WARN("Signal number %d is out of range\n", signum);
1464 if ((rc = qeth_notifier_register(current, signum)))
1470 static DRIVER_ATTR(notifier_register, 0200, 0,
1471 qeth_driver_notifier_register_store);
1474 qeth_create_driver_attributes(void)
1478 if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
1479 &driver_attr_group)))
1481 return driver_create_file(&qeth_ccwgroup_driver.driver,
1482 &driver_attr_notifier_register);
1486 qeth_remove_driver_attributes(void)
1488 driver_remove_file(&qeth_ccwgroup_driver.driver,
1489 &driver_attr_group);
1490 driver_remove_file(&qeth_ccwgroup_driver.driver,
1491 &driver_attr_notifier_register);