3 * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.49 $)
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.49 $";
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;
78 return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
81 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
84 qeth_dev_card_type_show(struct device *dev, char *buf)
86 struct qeth_card *card = dev->driver_data;
90 return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
93 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
96 qeth_dev_portno_show(struct device *dev, char *buf)
98 struct qeth_card *card = dev->driver_data;
102 return sprintf(buf, "%i\n", card->info.portno);
106 qeth_dev_portno_store(struct device *dev, const char *buf, size_t count)
108 struct qeth_card *card = dev->driver_data;
115 if ((card->state != CARD_STATE_DOWN) &&
116 (card->state != CARD_STATE_RECOVER))
119 portno = simple_strtoul(buf, &tmp, 16);
120 if ((portno < 0) || (portno > MAX_PORTNO)){
121 PRINT_WARN("portno 0x%X is out of range\n", portno);
125 card->info.portno = portno;
129 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
132 qeth_dev_portname_show(struct device *dev, char *buf)
134 struct qeth_card *card = dev->driver_data;
135 char portname[9] = {0, };
140 if (card->info.portname_required) {
141 memcpy(portname, card->info.portname + 1, 8);
143 return sprintf(buf, "%s\n", portname);
145 return sprintf(buf, "no portname required\n");
149 qeth_dev_portname_store(struct device *dev, const char *buf, size_t count)
151 struct qeth_card *card = dev->driver_data;
158 if ((card->state != CARD_STATE_DOWN) &&
159 (card->state != CARD_STATE_RECOVER))
162 tmp = strsep((char **) &buf, "\n");
163 if ((strlen(tmp) > 8) || (strlen(tmp) < 2))
166 card->info.portname[0] = strlen(tmp);
167 /* for beauty reasons */
168 for (i = 1; i < 9; i++)
169 card->info.portname[i] = ' ';
170 strcpy(card->info.portname + 1, tmp);
171 ASCEBC(card->info.portname + 1, 8);
176 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
177 qeth_dev_portname_store);
180 qeth_dev_checksum_show(struct device *dev, char *buf)
182 struct qeth_card *card = dev->driver_data;
187 return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
191 qeth_dev_checksum_store(struct device *dev, const char *buf, size_t count)
193 struct qeth_card *card = dev->driver_data;
199 if ((card->state != CARD_STATE_DOWN) &&
200 (card->state != CARD_STATE_RECOVER))
203 tmp = strsep((char **) &buf, "\n");
204 if (!strcmp(tmp, "sw_checksumming"))
205 card->options.checksum_type = SW_CHECKSUMMING;
206 else if (!strcmp(tmp, "hw_checksumming"))
207 card->options.checksum_type = HW_CHECKSUMMING;
208 else if (!strcmp(tmp, "no_checksumming"))
209 card->options.checksum_type = NO_CHECKSUMMING;
211 PRINT_WARN("Unknown checksumming type '%s'\n", tmp);
217 static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
218 qeth_dev_checksum_store);
221 qeth_dev_prioqing_show(struct device *dev, char *buf)
223 struct qeth_card *card = dev->driver_data;
228 switch (card->qdio.do_prio_queueing) {
229 case QETH_PRIO_Q_ING_PREC:
230 return sprintf(buf, "%s\n", "by precedence");
231 case QETH_PRIO_Q_ING_TOS:
232 return sprintf(buf, "%s\n", "by type of service");
234 return sprintf(buf, "always queue %i\n",
235 card->qdio.default_out_queue);
240 qeth_dev_prioqing_store(struct device *dev, const char *buf, size_t count)
242 struct qeth_card *card = dev->driver_data;
248 if ((card->state != CARD_STATE_DOWN) &&
249 (card->state != CARD_STATE_RECOVER))
252 tmp = strsep((char **) &buf, "\n");
253 if (!strcmp(tmp, "prio_queueing_prec"))
254 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
255 else if (!strcmp(tmp, "prio_queueing_tos"))
256 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
257 else if (!strcmp(tmp, "no_prio_queueing:0")) {
258 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
259 card->qdio.default_out_queue = 0;
260 } else if (!strcmp(tmp, "no_prio_queueing:1")) {
261 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
262 card->qdio.default_out_queue = 1;
263 } else if (!strcmp(tmp, "no_prio_queueing:2")) {
264 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
265 card->qdio.default_out_queue = 2;
266 } else if (!strcmp(tmp, "no_prio_queueing:3")) {
267 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
268 card->qdio.default_out_queue = 3;
269 } else if (!strcmp(tmp, "no_prio_queueing")) {
270 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
271 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
273 PRINT_WARN("Unknown queueing type '%s'\n", tmp);
279 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
280 qeth_dev_prioqing_store);
283 qeth_dev_bufcnt_show(struct device *dev, char *buf)
285 struct qeth_card *card = dev->driver_data;
290 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
294 qeth_dev_bufcnt_store(struct device *dev, const char *buf, size_t count)
296 struct qeth_card *card = dev->driver_data;
304 if ((card->state != CARD_STATE_DOWN) &&
305 (card->state != CARD_STATE_RECOVER))
308 old_cnt = card->qdio.in_buf_pool.buf_count;
309 cnt = simple_strtoul(buf, &tmp, 10);
310 cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
311 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
312 if (old_cnt != cnt) {
313 if ((rc = qeth_realloc_buffer_pool(card, cnt)))
314 PRINT_WARN("Error (%d) while setting "
315 "buffer count.\n", rc);
320 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
321 qeth_dev_bufcnt_store);
323 static inline ssize_t
324 qeth_dev_route_show(struct qeth_card *card, struct qeth_routing_info *route,
327 switch (route->type) {
329 return sprintf(buf, "%s\n", "primary router");
330 case SECONDARY_ROUTER:
331 return sprintf(buf, "%s\n", "secondary router");
332 case MULTICAST_ROUTER:
333 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
334 return sprintf(buf, "%s\n", "multicast router+");
336 return sprintf(buf, "%s\n", "multicast router");
337 case PRIMARY_CONNECTOR:
338 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
339 return sprintf(buf, "%s\n", "primary connector+");
341 return sprintf(buf, "%s\n", "primary connector");
342 case SECONDARY_CONNECTOR:
343 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
344 return sprintf(buf, "%s\n", "secondary connector+");
346 return sprintf(buf, "%s\n", "secondary connector");
348 return sprintf(buf, "%s\n", "no");
353 qeth_dev_route4_show(struct device *dev, char *buf)
355 struct qeth_card *card = dev->driver_data;
360 return qeth_dev_route_show(card, &card->options.route4, buf);
363 static inline ssize_t
364 qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
365 enum qeth_prot_versions prot, const char *buf, size_t count)
367 enum qeth_routing_types old_route_type = route->type;
371 tmp = strsep((char **) &buf, "\n");
373 if (!strcmp(tmp, "no_router")){
374 route->type = NO_ROUTER;
375 } else if (!strcmp(tmp, "primary_connector")) {
376 route->type = PRIMARY_CONNECTOR;
377 } else if (!strcmp(tmp, "secondary_connector")) {
378 route->type = SECONDARY_CONNECTOR;
379 } else if (!strcmp(tmp, "multicast_router")) {
380 route->type = MULTICAST_ROUTER;
381 } else if (!strcmp(tmp, "primary_router")) {
382 route->type = PRIMARY_ROUTER;
383 } else if (!strcmp(tmp, "secondary_router")) {
384 route->type = SECONDARY_ROUTER;
385 } else if (!strcmp(tmp, "multicast_router")) {
386 route->type = MULTICAST_ROUTER;
388 PRINT_WARN("Invalid routing type '%s'.\n", tmp);
391 if (((card->state == CARD_STATE_SOFTSETUP) ||
392 (card->state == CARD_STATE_UP)) &&
393 (old_route_type != route->type)){
394 if (prot == QETH_PROT_IPV4)
395 rc = qeth_setrouting_v4(card);
396 else if (prot == QETH_PROT_IPV6)
397 rc = qeth_setrouting_v6(card);
403 qeth_dev_route4_store(struct device *dev, const char *buf, size_t count)
405 struct qeth_card *card = dev->driver_data;
410 return qeth_dev_route_store(card, &card->options.route4,
411 QETH_PROT_IPV4, buf, count);
414 static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
416 #ifdef CONFIG_QETH_IPV6
418 qeth_dev_route6_show(struct device *dev, char *buf)
420 struct qeth_card *card = dev->driver_data;
425 if (!qeth_is_supported(card, IPA_IPV6))
426 return sprintf(buf, "%s\n", "n/a");
428 return qeth_dev_route_show(card, &card->options.route6, buf);
432 qeth_dev_route6_store(struct device *dev, const char *buf, size_t count)
434 struct qeth_card *card = dev->driver_data;
439 if (!qeth_is_supported(card, IPA_IPV6)){
440 PRINT_WARN("IPv6 not supported for interface %s.\n"
441 "Routing status no changed.\n",
442 QETH_CARD_IFNAME(card));
446 return qeth_dev_route_store(card, &card->options.route6,
447 QETH_PROT_IPV6, buf, count);
450 static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
454 qeth_dev_add_hhlen_show(struct device *dev, char *buf)
456 struct qeth_card *card = dev->driver_data;
461 return sprintf(buf, "%i\n", card->options.add_hhlen);
465 qeth_dev_add_hhlen_store(struct device *dev, const char *buf, size_t count)
467 struct qeth_card *card = dev->driver_data;
474 if ((card->state != CARD_STATE_DOWN) &&
475 (card->state != CARD_STATE_RECOVER))
478 i = simple_strtoul(buf, &tmp, 10);
479 if ((i < 0) || (i > MAX_ADD_HHLEN)) {
480 PRINT_WARN("add_hhlen out of range\n");
483 card->options.add_hhlen = i;
488 static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
489 qeth_dev_add_hhlen_store);
492 qeth_dev_fake_ll_show(struct device *dev, char *buf)
494 struct qeth_card *card = dev->driver_data;
499 return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
503 qeth_dev_fake_ll_store(struct device *dev, const char *buf, size_t count)
505 struct qeth_card *card = dev->driver_data;
512 if ((card->state != CARD_STATE_DOWN) &&
513 (card->state != CARD_STATE_RECOVER))
516 i = simple_strtoul(buf, &tmp, 16);
517 if ((i != 0) && (i != 1)) {
518 PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
521 card->options.fake_ll = i;
525 static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
526 qeth_dev_fake_ll_store);
529 qeth_dev_fake_broadcast_show(struct device *dev, char *buf)
531 struct qeth_card *card = dev->driver_data;
536 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
540 qeth_dev_fake_broadcast_store(struct device *dev, const char *buf, size_t count)
542 struct qeth_card *card = dev->driver_data;
549 if ((card->state != CARD_STATE_DOWN) &&
550 (card->state != CARD_STATE_RECOVER))
553 i = simple_strtoul(buf, &tmp, 16);
554 if ((i == 0) || (i == 1))
555 card->options.fake_broadcast = i;
557 PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
563 static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
564 qeth_dev_fake_broadcast_store);
567 qeth_dev_recover_store(struct device *dev, const char *buf, size_t count)
569 struct qeth_card *card = dev->driver_data;
576 if (card->state != CARD_STATE_UP)
579 i = simple_strtoul(buf, &tmp, 16);
581 qeth_schedule_recovery(card);
586 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
589 qeth_dev_broadcast_mode_show(struct device *dev, char *buf)
591 struct qeth_card *card = dev->driver_data;
596 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
597 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
598 return sprintf(buf, "n/a\n");
600 return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
601 QETH_TR_BROADCAST_ALLRINGS)?
602 "all rings":"local");
606 qeth_dev_broadcast_mode_store(struct device *dev, const char *buf, size_t count)
608 struct qeth_card *card = dev->driver_data;
614 if ((card->state != CARD_STATE_DOWN) &&
615 (card->state != CARD_STATE_RECOVER))
618 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
619 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
620 PRINT_WARN("Device is not a tokenring device!\n");
624 tmp = strsep((char **) &buf, "\n");
626 if (!strcmp(tmp, "local")){
627 card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
629 } else if (!strcmp(tmp, "all_rings")) {
630 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
633 PRINT_WARN("broadcast_mode: invalid mode %s!\n",
640 static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
641 qeth_dev_broadcast_mode_store);
644 qeth_dev_canonical_macaddr_show(struct device *dev, char *buf)
646 struct qeth_card *card = dev->driver_data;
651 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
652 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
653 return sprintf(buf, "n/a\n");
655 return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
656 QETH_TR_MACADDR_CANONICAL)? 1:0);
660 qeth_dev_canonical_macaddr_store(struct device *dev, const char *buf,
663 struct qeth_card *card = dev->driver_data;
670 if ((card->state != CARD_STATE_DOWN) &&
671 (card->state != CARD_STATE_RECOVER))
674 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
675 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
676 PRINT_WARN("Device is not a tokenring device!\n");
680 i = simple_strtoul(buf, &tmp, 16);
681 if ((i == 0) || (i == 1))
682 card->options.macaddr_mode = i?
683 QETH_TR_MACADDR_CANONICAL :
684 QETH_TR_MACADDR_NONCANONICAL;
686 PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
692 static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
693 qeth_dev_canonical_macaddr_store);
696 qeth_dev_layer2_show(struct device *dev, char *buf)
698 struct qeth_card *card = dev->driver_data;
703 return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
707 qeth_dev_layer2_store(struct device *dev, const char *buf, size_t count)
709 struct qeth_card *card = dev->driver_data;
716 if (((card->state != CARD_STATE_DOWN) &&
717 (card->state != CARD_STATE_RECOVER)) ||
718 (card->info.type != QETH_CARD_TYPE_OSAE))
721 i = simple_strtoul(buf, &tmp, 16);
722 if ((i == 0) || (i == 1))
723 card->options.layer2 = i;
725 PRINT_WARN("layer2: write 0 or 1 to this file!\n");
731 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
732 qeth_dev_layer2_store);
734 static struct device_attribute * qeth_device_attrs[] = {
741 &dev_attr_checksumming,
742 &dev_attr_priority_queueing,
743 &dev_attr_buffer_count,
745 #ifdef CONFIG_QETH_IPV6
750 &dev_attr_fake_broadcast,
752 &dev_attr_broadcast_mode,
753 &dev_attr_canonical_macaddr,
758 static struct attribute_group qeth_device_attr_group = {
759 .attrs = (struct attribute **)qeth_device_attrs,
763 #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
764 struct device_attribute dev_attr_##_id = { \
765 .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
771 qeth_check_layer2(struct qeth_card *card)
773 if (card->options.layer2)
780 qeth_dev_ipato_enable_show(struct device *dev, char *buf)
782 struct qeth_card *card = dev->driver_data;
787 if (qeth_check_layer2(card))
789 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
793 qeth_dev_ipato_enable_store(struct device *dev, const char *buf, size_t count)
795 struct qeth_card *card = dev->driver_data;
801 if ((card->state != CARD_STATE_DOWN) &&
802 (card->state != CARD_STATE_RECOVER))
805 if (qeth_check_layer2(card))
808 tmp = strsep((char **) &buf, "\n");
809 if (!strcmp(tmp, "toggle")){
810 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
811 } else if (!strcmp(tmp, "1")){
812 card->ipato.enabled = 1;
813 } else if (!strcmp(tmp, "0")){
814 card->ipato.enabled = 0;
816 PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
823 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
824 qeth_dev_ipato_enable_show,
825 qeth_dev_ipato_enable_store);
828 qeth_dev_ipato_invert4_show(struct device *dev, char *buf)
830 struct qeth_card *card = dev->driver_data;
835 if (qeth_check_layer2(card))
838 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
842 qeth_dev_ipato_invert4_store(struct device *dev, const char *buf, size_t count)
844 struct qeth_card *card = dev->driver_data;
850 if (qeth_check_layer2(card))
853 tmp = strsep((char **) &buf, "\n");
854 if (!strcmp(tmp, "toggle")){
855 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
856 } else if (!strcmp(tmp, "1")){
857 card->ipato.invert4 = 1;
858 } else if (!strcmp(tmp, "0")){
859 card->ipato.invert4 = 0;
861 PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
868 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
869 qeth_dev_ipato_invert4_show,
870 qeth_dev_ipato_invert4_store);
872 static inline ssize_t
873 qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
874 enum qeth_prot_versions proto)
876 struct qeth_ipato_entry *ipatoe;
879 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
882 if (qeth_check_layer2(card))
885 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
886 /* add strlen for "/<mask>\n" */
887 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
888 spin_lock_irqsave(&card->ip_lock, flags);
889 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
890 if (ipatoe->proto != proto)
892 /* String must not be longer than PAGE_SIZE. So we check if
893 * string length gets near PAGE_SIZE. Then we can savely display
894 * the next IPv6 address (worst case, compared to IPv4) */
895 if ((PAGE_SIZE - i) <= entry_len)
897 qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
898 i += snprintf(buf + i, PAGE_SIZE - i,
899 "%s/%i\n", addr_str, ipatoe->mask_bits);
901 spin_unlock_irqrestore(&card->ip_lock, flags);
902 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
908 qeth_dev_ipato_add4_show(struct device *dev, char *buf)
910 struct qeth_card *card = dev->driver_data;
915 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
919 qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
920 u8 *addr, int *mask_bits)
922 const char *start, *end;
924 char buffer[49] = {0, };
927 /* get address string */
928 end = strchr(start, '/');
930 PRINT_WARN("Invalid format for ipato_addx/delx. "
931 "Use <ip addr>/<mask bits>\n");
934 strncpy(buffer, start, end - start);
935 if (qeth_string_to_ipaddr(buffer, proto, addr)){
936 PRINT_WARN("Invalid IP address format!\n");
940 *mask_bits = simple_strtoul(start, &tmp, 10);
945 static inline ssize_t
946 qeth_dev_ipato_add_store(const char *buf, size_t count,
947 struct qeth_card *card, enum qeth_prot_versions proto)
949 struct qeth_ipato_entry *ipatoe;
954 if (qeth_check_layer2(card))
956 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
959 if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
960 PRINT_WARN("No memory to allocate ipato entry\n");
963 memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
964 ipatoe->proto = proto;
965 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
966 ipatoe->mask_bits = mask_bits;
968 if ((rc = qeth_add_ipato_entry(card, ipatoe))){
977 qeth_dev_ipato_add4_store(struct device *dev, const char *buf, size_t count)
979 struct qeth_card *card = dev->driver_data;
984 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
987 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
988 qeth_dev_ipato_add4_show,
989 qeth_dev_ipato_add4_store);
991 static inline ssize_t
992 qeth_dev_ipato_del_store(const char *buf, size_t count,
993 struct qeth_card *card, enum qeth_prot_versions proto)
999 if (qeth_check_layer2(card))
1001 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1004 qeth_del_ipato_entry(card, proto, addr, mask_bits);
1010 qeth_dev_ipato_del4_store(struct device *dev, const char *buf, size_t count)
1012 struct qeth_card *card = dev->driver_data;
1017 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
1020 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
1021 qeth_dev_ipato_del4_store);
1023 #ifdef CONFIG_QETH_IPV6
1025 qeth_dev_ipato_invert6_show(struct device *dev, char *buf)
1027 struct qeth_card *card = dev->driver_data;
1032 if (qeth_check_layer2(card))
1035 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
1039 qeth_dev_ipato_invert6_store(struct device *dev, const char *buf, size_t count)
1041 struct qeth_card *card = dev->driver_data;
1047 if (qeth_check_layer2(card))
1050 tmp = strsep((char **) &buf, "\n");
1051 if (!strcmp(tmp, "toggle")){
1052 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
1053 } else if (!strcmp(tmp, "1")){
1054 card->ipato.invert6 = 1;
1055 } else if (!strcmp(tmp, "0")){
1056 card->ipato.invert6 = 0;
1058 PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
1065 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
1066 qeth_dev_ipato_invert6_show,
1067 qeth_dev_ipato_invert6_store);
1071 qeth_dev_ipato_add6_show(struct device *dev, char *buf)
1073 struct qeth_card *card = dev->driver_data;
1078 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
1082 qeth_dev_ipato_add6_store(struct device *dev, const char *buf, size_t count)
1084 struct qeth_card *card = dev->driver_data;
1089 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
1092 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
1093 qeth_dev_ipato_add6_show,
1094 qeth_dev_ipato_add6_store);
1097 qeth_dev_ipato_del6_store(struct device *dev, const char *buf, size_t count)
1099 struct qeth_card *card = dev->driver_data;
1104 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
1107 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
1108 qeth_dev_ipato_del6_store);
1109 #endif /* CONFIG_QETH_IPV6 */
1111 static struct device_attribute * qeth_ipato_device_attrs[] = {
1112 &dev_attr_ipato_enable,
1113 &dev_attr_ipato_invert4,
1114 &dev_attr_ipato_add4,
1115 &dev_attr_ipato_del4,
1116 #ifdef CONFIG_QETH_IPV6
1117 &dev_attr_ipato_invert6,
1118 &dev_attr_ipato_add6,
1119 &dev_attr_ipato_del6,
1124 static struct attribute_group qeth_device_ipato_group = {
1125 .name = "ipa_takeover",
1126 .attrs = (struct attribute **)qeth_ipato_device_attrs,
1129 static inline ssize_t
1130 qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
1131 enum qeth_prot_versions proto)
1133 struct qeth_ipaddr *ipaddr;
1135 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1136 unsigned long flags;
1139 if (qeth_check_layer2(card))
1142 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1143 entry_len += 2; /* \n + terminator */
1144 spin_lock_irqsave(&card->ip_lock, flags);
1145 list_for_each_entry(ipaddr, &card->ip_list, entry){
1146 if (ipaddr->proto != proto)
1148 if (ipaddr->type != QETH_IP_TYPE_VIPA)
1150 /* String must not be longer than PAGE_SIZE. So we check if
1151 * string length gets near PAGE_SIZE. Then we can savely display
1152 * the next IPv6 address (worst case, compared to IPv4) */
1153 if ((PAGE_SIZE - i) <= entry_len)
1155 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1156 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1158 spin_unlock_irqrestore(&card->ip_lock, flags);
1159 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1165 qeth_dev_vipa_add4_show(struct device *dev, char *buf)
1167 struct qeth_card *card = dev->driver_data;
1172 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
1176 qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
1179 if (qeth_string_to_ipaddr(buf, proto, addr)){
1180 PRINT_WARN("Invalid IP address format!\n");
1186 static inline ssize_t
1187 qeth_dev_vipa_add_store(const char *buf, size_t count,
1188 struct qeth_card *card, enum qeth_prot_versions proto)
1190 u8 addr[16] = {0, };
1193 if (qeth_check_layer2(card))
1195 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1198 if ((rc = qeth_add_vipa(card, proto, addr)))
1205 qeth_dev_vipa_add4_store(struct device *dev, const char *buf, size_t count)
1207 struct qeth_card *card = dev->driver_data;
1212 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
1215 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
1216 qeth_dev_vipa_add4_show,
1217 qeth_dev_vipa_add4_store);
1219 static inline ssize_t
1220 qeth_dev_vipa_del_store(const char *buf, size_t count,
1221 struct qeth_card *card, enum qeth_prot_versions proto)
1226 if (qeth_check_layer2(card))
1228 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1231 qeth_del_vipa(card, proto, addr);
1237 qeth_dev_vipa_del4_store(struct device *dev, const char *buf, size_t count)
1239 struct qeth_card *card = dev->driver_data;
1244 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
1247 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
1248 qeth_dev_vipa_del4_store);
1250 #ifdef CONFIG_QETH_IPV6
1252 qeth_dev_vipa_add6_show(struct device *dev, char *buf)
1254 struct qeth_card *card = dev->driver_data;
1259 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
1263 qeth_dev_vipa_add6_store(struct device *dev, const char *buf, size_t count)
1265 struct qeth_card *card = dev->driver_data;
1270 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
1273 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
1274 qeth_dev_vipa_add6_show,
1275 qeth_dev_vipa_add6_store);
1278 qeth_dev_vipa_del6_store(struct device *dev, const char *buf, size_t count)
1280 struct qeth_card *card = dev->driver_data;
1285 if (qeth_check_layer2(card))
1288 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
1291 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
1292 qeth_dev_vipa_del6_store);
1293 #endif /* CONFIG_QETH_IPV6 */
1295 static struct device_attribute * qeth_vipa_device_attrs[] = {
1296 &dev_attr_vipa_add4,
1297 &dev_attr_vipa_del4,
1298 #ifdef CONFIG_QETH_IPV6
1299 &dev_attr_vipa_add6,
1300 &dev_attr_vipa_del6,
1305 static struct attribute_group qeth_device_vipa_group = {
1307 .attrs = (struct attribute **)qeth_vipa_device_attrs,
1310 static inline ssize_t
1311 qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
1312 enum qeth_prot_versions proto)
1314 struct qeth_ipaddr *ipaddr;
1316 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1317 unsigned long flags;
1320 if (qeth_check_layer2(card))
1323 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1324 entry_len += 2; /* \n + terminator */
1325 spin_lock_irqsave(&card->ip_lock, flags);
1326 list_for_each_entry(ipaddr, &card->ip_list, entry){
1327 if (ipaddr->proto != proto)
1329 if (ipaddr->type != QETH_IP_TYPE_RXIP)
1331 /* String must not be longer than PAGE_SIZE. So we check if
1332 * string length gets near PAGE_SIZE. Then we can savely display
1333 * the next IPv6 address (worst case, compared to IPv4) */
1334 if ((PAGE_SIZE - i) <= entry_len)
1336 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1337 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1339 spin_unlock_irqrestore(&card->ip_lock, flags);
1340 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1346 qeth_dev_rxip_add4_show(struct device *dev, char *buf)
1348 struct qeth_card *card = dev->driver_data;
1353 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
1357 qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
1360 if (qeth_string_to_ipaddr(buf, proto, addr)){
1361 PRINT_WARN("Invalid IP address format!\n");
1367 static inline ssize_t
1368 qeth_dev_rxip_add_store(const char *buf, size_t count,
1369 struct qeth_card *card, enum qeth_prot_versions proto)
1371 u8 addr[16] = {0, };
1374 if (qeth_check_layer2(card))
1376 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1379 if ((rc = qeth_add_rxip(card, proto, addr)))
1386 qeth_dev_rxip_add4_store(struct device *dev, const char *buf, size_t count)
1388 struct qeth_card *card = dev->driver_data;
1393 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
1396 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
1397 qeth_dev_rxip_add4_show,
1398 qeth_dev_rxip_add4_store);
1400 static inline ssize_t
1401 qeth_dev_rxip_del_store(const char *buf, size_t count,
1402 struct qeth_card *card, enum qeth_prot_versions proto)
1407 if (qeth_check_layer2(card))
1409 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1412 qeth_del_rxip(card, proto, addr);
1418 qeth_dev_rxip_del4_store(struct device *dev, const char *buf, size_t count)
1420 struct qeth_card *card = dev->driver_data;
1425 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
1428 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
1429 qeth_dev_rxip_del4_store);
1431 #ifdef CONFIG_QETH_IPV6
1433 qeth_dev_rxip_add6_show(struct device *dev, char *buf)
1435 struct qeth_card *card = dev->driver_data;
1440 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
1444 qeth_dev_rxip_add6_store(struct device *dev, const char *buf, size_t count)
1446 struct qeth_card *card = dev->driver_data;
1451 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1454 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1455 qeth_dev_rxip_add6_show,
1456 qeth_dev_rxip_add6_store);
1459 qeth_dev_rxip_del6_store(struct device *dev, const char *buf, size_t count)
1461 struct qeth_card *card = dev->driver_data;
1466 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1469 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1470 qeth_dev_rxip_del6_store);
1471 #endif /* CONFIG_QETH_IPV6 */
1473 static struct device_attribute * qeth_rxip_device_attrs[] = {
1474 &dev_attr_rxip_add4,
1475 &dev_attr_rxip_del4,
1476 #ifdef CONFIG_QETH_IPV6
1477 &dev_attr_rxip_add6,
1478 &dev_attr_rxip_del6,
1483 static struct attribute_group qeth_device_rxip_group = {
1485 .attrs = (struct attribute **)qeth_rxip_device_attrs,
1489 qeth_create_device_attributes(struct device *dev)
1493 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1495 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
1496 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1499 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
1500 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1501 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1504 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
1505 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1506 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1507 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1514 qeth_remove_device_attributes(struct device *dev)
1516 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1517 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1518 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1519 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1522 /**********************/
1523 /* DRIVER ATTRIBUTES */
1524 /**********************/
1526 qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1529 const char *start, *end;
1530 char bus_ids[3][BUS_ID_SIZE], *argv[3];
1535 for (i = 0; i < 3; i++) {
1536 static const char delim[] = { ',', ',', '\n' };
1539 if (!(end = strchr(start, delim[i])))
1541 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
1542 strncpy(bus_ids[i], start, len);
1543 bus_ids[i][len] = '\0';
1545 argv[i] = bus_ids[i];
1547 err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
1548 &qeth_ccw_driver, 3, argv);
1556 static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
1559 qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
1566 tmp = strsep((char **) &buf, "\n");
1567 if (!strncmp(tmp, "unregister", 10)){
1568 if ((rc = qeth_notifier_unregister(current)))
1573 signum = simple_strtoul(tmp, &tmp2, 10);
1574 if ((signum < 0) || (signum > 32)){
1575 PRINT_WARN("Signal number %d is out of range\n", signum);
1578 if ((rc = qeth_notifier_register(current, signum)))
1584 static DRIVER_ATTR(notifier_register, 0200, 0,
1585 qeth_driver_notifier_register_store);
1588 qeth_create_driver_attributes(void)
1592 if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
1593 &driver_attr_group)))
1595 return driver_create_file(&qeth_ccwgroup_driver.driver,
1596 &driver_attr_notifier_register);
1600 qeth_remove_driver_attributes(void)
1602 driver_remove_file(&qeth_ccwgroup_driver.driver,
1603 &driver_attr_group);
1604 driver_remove_file(&qeth_ccwgroup_driver.driver,
1605 &driver_attr_notifier_register);