3 * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.40 $)
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.40 $";
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, 10);
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);
698 qeth_dev_layer2_show(struct device *dev, char *buf)
700 struct qeth_card *card = dev->driver_data;
705 return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
709 qeth_dev_layer2_store(struct device *dev, const char *buf, size_t count)
711 struct qeth_card *card = dev->driver_data;
718 if ((card->state != CARD_STATE_DOWN) &&
719 (card->state != CARD_STATE_RECOVER))
722 i = simple_strtoul(buf, &tmp, 16);
723 if ((i == 0) || (i == 1))
724 card->options.layer2 = i;
726 PRINT_WARN("layer2: write 0 or 1 to this file!\n");
732 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
733 qeth_dev_layer2_store);
735 static struct device_attribute * qeth_device_attrs[] = {
742 &dev_attr_checksumming,
743 &dev_attr_priority_queueing,
744 &dev_attr_buffer_count,
746 #ifdef CONFIG_QETH_IPV6
751 &dev_attr_fake_broadcast,
753 &dev_attr_broadcast_mode,
754 &dev_attr_canonical_macaddr,
759 static struct attribute_group qeth_device_attr_group = {
760 .attrs = (struct attribute **)qeth_device_attrs,
764 #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
765 struct device_attribute dev_attr_##_id = { \
766 .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
772 qeth_check_layer2(struct qeth_card *card)
774 if (card->options.layer2)
781 qeth_dev_ipato_enable_show(struct device *dev, char *buf)
783 struct qeth_card *card = dev->driver_data;
788 if (qeth_check_layer2(card))
790 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
794 qeth_dev_ipato_enable_store(struct device *dev, const char *buf, size_t count)
796 struct qeth_card *card = dev->driver_data;
802 if ((card->state != CARD_STATE_DOWN) &&
803 (card->state != CARD_STATE_RECOVER))
806 if (qeth_check_layer2(card))
809 tmp = strsep((char **) &buf, "\n");
810 if (!strcmp(tmp, "toggle")){
811 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
812 } else if (!strcmp(tmp, "1")){
813 card->ipato.enabled = 1;
814 } else if (!strcmp(tmp, "0")){
815 card->ipato.enabled = 0;
817 PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
824 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
825 qeth_dev_ipato_enable_show,
826 qeth_dev_ipato_enable_store);
829 qeth_dev_ipato_invert4_show(struct device *dev, char *buf)
831 struct qeth_card *card = dev->driver_data;
836 if (qeth_check_layer2(card))
839 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
843 qeth_dev_ipato_invert4_store(struct device *dev, const char *buf, size_t count)
845 struct qeth_card *card = dev->driver_data;
851 if (qeth_check_layer2(card))
854 tmp = strsep((char **) &buf, "\n");
855 if (!strcmp(tmp, "toggle")){
856 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
857 } else if (!strcmp(tmp, "1")){
858 card->ipato.invert4 = 1;
859 } else if (!strcmp(tmp, "0")){
860 card->ipato.invert4 = 0;
862 PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
869 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
870 qeth_dev_ipato_invert4_show,
871 qeth_dev_ipato_invert4_store);
873 static inline ssize_t
874 qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
875 enum qeth_prot_versions proto)
877 struct qeth_ipato_entry *ipatoe;
880 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
883 if (qeth_check_layer2(card))
886 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
887 /* add strlen for "/<mask>\n" */
888 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
889 spin_lock_irqsave(&card->ip_lock, flags);
890 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
891 if (ipatoe->proto != proto)
893 /* String must not be longer than PAGE_SIZE. So we check if
894 * string length gets near PAGE_SIZE. Then we can savely display
895 * the next IPv6 address (worst case, compared to IPv4) */
896 if ((PAGE_SIZE - i) <= entry_len)
898 qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
899 i += snprintf(buf + i, PAGE_SIZE - i,
900 "%s/%i\n", addr_str, ipatoe->mask_bits);
902 spin_unlock_irqrestore(&card->ip_lock, flags);
903 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
909 qeth_dev_ipato_add4_show(struct device *dev, char *buf)
911 struct qeth_card *card = dev->driver_data;
916 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
920 qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
921 u8 *addr, int *mask_bits)
923 const char *start, *end;
925 char buffer[49] = {0, };
928 /* get address string */
929 end = strchr(start, '/');
931 PRINT_WARN("Invalid format for ipato_addx/delx. "
932 "Use <ip addr>/<mask bits>\n");
935 strncpy(buffer, start, end - start);
936 if (qeth_string_to_ipaddr(buffer, proto, addr)){
937 PRINT_WARN("Invalid IP address format!\n");
941 *mask_bits = simple_strtoul(start, &tmp, 10);
946 static inline ssize_t
947 qeth_dev_ipato_add_store(const char *buf, size_t count,
948 struct qeth_card *card, enum qeth_prot_versions proto)
950 struct qeth_ipato_entry *ipatoe;
955 if (qeth_check_layer2(card))
957 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
960 if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
961 PRINT_WARN("No memory to allocate ipato entry\n");
964 memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
965 ipatoe->proto = proto;
966 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
967 ipatoe->mask_bits = mask_bits;
969 if ((rc = qeth_add_ipato_entry(card, ipatoe))){
978 qeth_dev_ipato_add4_store(struct device *dev, const char *buf, size_t count)
980 struct qeth_card *card = dev->driver_data;
985 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
988 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
989 qeth_dev_ipato_add4_show,
990 qeth_dev_ipato_add4_store);
992 static inline ssize_t
993 qeth_dev_ipato_del_store(const char *buf, size_t count,
994 struct qeth_card *card, enum qeth_prot_versions proto)
1000 if (qeth_check_layer2(card))
1002 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1005 qeth_del_ipato_entry(card, proto, addr, mask_bits);
1011 qeth_dev_ipato_del4_store(struct device *dev, const char *buf, size_t count)
1013 struct qeth_card *card = dev->driver_data;
1018 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
1021 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
1022 qeth_dev_ipato_del4_store);
1024 #ifdef CONFIG_QETH_IPV6
1026 qeth_dev_ipato_invert6_show(struct device *dev, char *buf)
1028 struct qeth_card *card = dev->driver_data;
1033 if (qeth_check_layer2(card))
1036 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
1040 qeth_dev_ipato_invert6_store(struct device *dev, const char *buf, size_t count)
1042 struct qeth_card *card = dev->driver_data;
1048 if (qeth_check_layer2(card))
1051 tmp = strsep((char **) &buf, "\n");
1052 if (!strcmp(tmp, "toggle")){
1053 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
1054 } else if (!strcmp(tmp, "1")){
1055 card->ipato.invert6 = 1;
1056 } else if (!strcmp(tmp, "0")){
1057 card->ipato.invert6 = 0;
1059 PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
1066 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
1067 qeth_dev_ipato_invert6_show,
1068 qeth_dev_ipato_invert6_store);
1072 qeth_dev_ipato_add6_show(struct device *dev, char *buf)
1074 struct qeth_card *card = dev->driver_data;
1079 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
1083 qeth_dev_ipato_add6_store(struct device *dev, const char *buf, size_t count)
1085 struct qeth_card *card = dev->driver_data;
1090 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
1093 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
1094 qeth_dev_ipato_add6_show,
1095 qeth_dev_ipato_add6_store);
1098 qeth_dev_ipato_del6_store(struct device *dev, const char *buf, size_t count)
1100 struct qeth_card *card = dev->driver_data;
1105 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
1108 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
1109 qeth_dev_ipato_del6_store);
1110 #endif /* CONFIG_QETH_IPV6 */
1112 static struct device_attribute * qeth_ipato_device_attrs[] = {
1113 &dev_attr_ipato_enable,
1114 &dev_attr_ipato_invert4,
1115 &dev_attr_ipato_add4,
1116 &dev_attr_ipato_del4,
1117 #ifdef CONFIG_QETH_IPV6
1118 &dev_attr_ipato_invert6,
1119 &dev_attr_ipato_add6,
1120 &dev_attr_ipato_del6,
1125 static struct attribute_group qeth_device_ipato_group = {
1126 .name = "ipa_takeover",
1127 .attrs = (struct attribute **)qeth_ipato_device_attrs,
1130 static inline ssize_t
1131 qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
1132 enum qeth_prot_versions proto)
1134 struct qeth_ipaddr *ipaddr;
1136 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1137 unsigned long flags;
1140 if (qeth_check_layer2(card))
1143 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1144 entry_len += 2; /* \n + terminator */
1145 spin_lock_irqsave(&card->ip_lock, flags);
1146 list_for_each_entry(ipaddr, &card->ip_list, entry){
1147 if (ipaddr->proto != proto)
1149 if (ipaddr->type != QETH_IP_TYPE_VIPA)
1151 /* String must not be longer than PAGE_SIZE. So we check if
1152 * string length gets near PAGE_SIZE. Then we can savely display
1153 * the next IPv6 address (worst case, compared to IPv4) */
1154 if ((PAGE_SIZE - i) <= entry_len)
1156 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1157 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1159 spin_unlock_irqrestore(&card->ip_lock, flags);
1160 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1166 qeth_dev_vipa_add4_show(struct device *dev, char *buf)
1168 struct qeth_card *card = dev->driver_data;
1173 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
1177 qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
1180 if (qeth_string_to_ipaddr(buf, proto, addr)){
1181 PRINT_WARN("Invalid IP address format!\n");
1187 static inline ssize_t
1188 qeth_dev_vipa_add_store(const char *buf, size_t count,
1189 struct qeth_card *card, enum qeth_prot_versions proto)
1191 u8 addr[16] = {0, };
1194 if (qeth_check_layer2(card))
1196 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1199 if ((rc = qeth_add_vipa(card, proto, addr)))
1206 qeth_dev_vipa_add4_store(struct device *dev, const char *buf, size_t count)
1208 struct qeth_card *card = dev->driver_data;
1213 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
1216 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
1217 qeth_dev_vipa_add4_show,
1218 qeth_dev_vipa_add4_store);
1220 static inline ssize_t
1221 qeth_dev_vipa_del_store(const char *buf, size_t count,
1222 struct qeth_card *card, enum qeth_prot_versions proto)
1227 if (qeth_check_layer2(card))
1229 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1232 qeth_del_vipa(card, proto, addr);
1238 qeth_dev_vipa_del4_store(struct device *dev, const char *buf, size_t count)
1240 struct qeth_card *card = dev->driver_data;
1245 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
1248 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
1249 qeth_dev_vipa_del4_store);
1251 #ifdef CONFIG_QETH_IPV6
1253 qeth_dev_vipa_add6_show(struct device *dev, char *buf)
1255 struct qeth_card *card = dev->driver_data;
1260 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
1264 qeth_dev_vipa_add6_store(struct device *dev, const char *buf, size_t count)
1266 struct qeth_card *card = dev->driver_data;
1271 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
1274 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
1275 qeth_dev_vipa_add6_show,
1276 qeth_dev_vipa_add6_store);
1279 qeth_dev_vipa_del6_store(struct device *dev, const char *buf, size_t count)
1281 struct qeth_card *card = dev->driver_data;
1286 if (qeth_check_layer2(card))
1289 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
1292 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
1293 qeth_dev_vipa_del6_store);
1294 #endif /* CONFIG_QETH_IPV6 */
1296 static struct device_attribute * qeth_vipa_device_attrs[] = {
1297 &dev_attr_vipa_add4,
1298 &dev_attr_vipa_del4,
1299 #ifdef CONFIG_QETH_IPV6
1300 &dev_attr_vipa_add6,
1301 &dev_attr_vipa_del6,
1306 static struct attribute_group qeth_device_vipa_group = {
1308 .attrs = (struct attribute **)qeth_vipa_device_attrs,
1311 static inline ssize_t
1312 qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
1313 enum qeth_prot_versions proto)
1315 struct qeth_ipaddr *ipaddr;
1317 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1318 unsigned long flags;
1321 if (qeth_check_layer2(card))
1324 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1325 entry_len += 2; /* \n + terminator */
1326 spin_lock_irqsave(&card->ip_lock, flags);
1327 list_for_each_entry(ipaddr, &card->ip_list, entry){
1328 if (ipaddr->proto != proto)
1330 if (ipaddr->type != QETH_IP_TYPE_RXIP)
1332 /* String must not be longer than PAGE_SIZE. So we check if
1333 * string length gets near PAGE_SIZE. Then we can savely display
1334 * the next IPv6 address (worst case, compared to IPv4) */
1335 if ((PAGE_SIZE - i) <= entry_len)
1337 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1338 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1340 spin_unlock_irqrestore(&card->ip_lock, flags);
1341 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1347 qeth_dev_rxip_add4_show(struct device *dev, char *buf)
1349 struct qeth_card *card = dev->driver_data;
1354 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
1358 qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
1361 if (qeth_string_to_ipaddr(buf, proto, addr)){
1362 PRINT_WARN("Invalid IP address format!\n");
1368 static inline ssize_t
1369 qeth_dev_rxip_add_store(const char *buf, size_t count,
1370 struct qeth_card *card, enum qeth_prot_versions proto)
1372 u8 addr[16] = {0, };
1375 if (qeth_check_layer2(card))
1377 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1380 if ((rc = qeth_add_rxip(card, proto, addr)))
1387 qeth_dev_rxip_add4_store(struct device *dev, const char *buf, size_t count)
1389 struct qeth_card *card = dev->driver_data;
1394 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
1397 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
1398 qeth_dev_rxip_add4_show,
1399 qeth_dev_rxip_add4_store);
1401 static inline ssize_t
1402 qeth_dev_rxip_del_store(const char *buf, size_t count,
1403 struct qeth_card *card, enum qeth_prot_versions proto)
1408 if (qeth_check_layer2(card))
1410 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1413 qeth_del_rxip(card, proto, addr);
1419 qeth_dev_rxip_del4_store(struct device *dev, const char *buf, size_t count)
1421 struct qeth_card *card = dev->driver_data;
1426 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
1429 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
1430 qeth_dev_rxip_del4_store);
1432 #ifdef CONFIG_QETH_IPV6
1434 qeth_dev_rxip_add6_show(struct device *dev, char *buf)
1436 struct qeth_card *card = dev->driver_data;
1441 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
1445 qeth_dev_rxip_add6_store(struct device *dev, const char *buf, size_t count)
1447 struct qeth_card *card = dev->driver_data;
1452 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1455 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1456 qeth_dev_rxip_add6_show,
1457 qeth_dev_rxip_add6_store);
1460 qeth_dev_rxip_del6_store(struct device *dev, const char *buf, size_t count)
1462 struct qeth_card *card = dev->driver_data;
1467 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1470 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1471 qeth_dev_rxip_del6_store);
1472 #endif /* CONFIG_QETH_IPV6 */
1474 static struct device_attribute * qeth_rxip_device_attrs[] = {
1475 &dev_attr_rxip_add4,
1476 &dev_attr_rxip_del4,
1477 #ifdef CONFIG_QETH_IPV6
1478 &dev_attr_rxip_add6,
1479 &dev_attr_rxip_del6,
1484 static struct attribute_group qeth_device_rxip_group = {
1486 .attrs = (struct attribute **)qeth_rxip_device_attrs,
1490 qeth_create_device_attributes(struct device *dev)
1494 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1496 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
1497 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1500 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
1501 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1502 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1505 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
1506 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1507 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1508 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1515 qeth_remove_device_attributes(struct device *dev)
1517 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1518 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1519 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1520 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1523 /**********************/
1524 /* DRIVER ATTRIBUTES */
1525 /**********************/
1527 qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1530 const char *start, *end;
1531 char bus_ids[3][BUS_ID_SIZE], *argv[3];
1536 for (i = 0; i < 3; i++) {
1537 static const char delim[] = { ',', ',', '\n' };
1540 if (!(end = strchr(start, delim[i])))
1542 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
1543 strncpy(bus_ids[i], start, len);
1544 bus_ids[i][len] = '\0';
1546 argv[i] = bus_ids[i];
1548 err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
1549 &qeth_ccw_driver, 3, argv);
1557 static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
1560 qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
1567 tmp = strsep((char **) &buf, "\n");
1568 if (!strncmp(tmp, "unregister", 10)){
1569 if ((rc = qeth_notifier_unregister(current)))
1574 signum = simple_strtoul(tmp, &tmp2, 10);
1575 if ((signum < 0) || (signum > 32)){
1576 PRINT_WARN("Signal number %d is out of range\n", signum);
1579 if ((rc = qeth_notifier_register(current, signum)))
1585 static DRIVER_ATTR(notifier_register, 0200, 0,
1586 qeth_driver_notifier_register_store);
1589 qeth_create_driver_attributes(void)
1593 if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
1594 &driver_attr_group)))
1596 return driver_create_file(&qeth_ccwgroup_driver.driver,
1597 &driver_attr_notifier_register);
1601 qeth_remove_driver_attributes(void)
1603 driver_remove_file(&qeth_ccwgroup_driver.driver,
1604 &driver_attr_group);
1605 driver_remove_file(&qeth_ccwgroup_driver.driver,
1606 &driver_attr_notifier_register);