blob: c1f3187f37ea650220f2b066cbd1b48e28a4d0a8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
Heiko Carstense018ba12006-02-01 03:06:31 -08003 * linux/drivers/s390/net/qeth_sys.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Linux on zSeries OSA Express and HiperSockets support
6 * This file contains code related to sysfs.
7 *
8 * Copyright 2000,2003 IBM Corporation
9 *
10 * Author(s): Thomas Spatzier <tspat@de.ibm.com>
Frank Pavlic13877802005-11-10 13:51:42 +010011 * Frank Pavlic <fpavlic@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
13 */
14#include <linux/list.h>
15#include <linux/rwsem.h>
16
17#include <asm/ebcdic.h>
18
19#include "qeth.h"
20#include "qeth_mpc.h"
21#include "qeth_fs.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*****************************************************************************/
24/* */
25/* /sys-fs stuff UNDER DEVELOPMENT !!! */
26/* */
27/*****************************************************************************/
28//low/high watermark
29
30static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -040031qeth_dev_state_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
33 struct qeth_card *card = dev->driver_data;
34 if (!card)
35 return -EINVAL;
36
37 switch (card->state) {
38 case CARD_STATE_DOWN:
39 return sprintf(buf, "DOWN\n");
40 case CARD_STATE_HARDSETUP:
41 return sprintf(buf, "HARDSETUP\n");
42 case CARD_STATE_SOFTSETUP:
43 return sprintf(buf, "SOFTSETUP\n");
44 case CARD_STATE_UP:
45 if (card->lan_online)
46 return sprintf(buf, "UP (LAN ONLINE)\n");
47 else
48 return sprintf(buf, "UP (LAN OFFLINE)\n");
49 case CARD_STATE_RECOVER:
50 return sprintf(buf, "RECOVER\n");
51 default:
52 return sprintf(buf, "UNKNOWN\n");
53 }
54}
55
56static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
57
58static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -040059qeth_dev_chpid_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 struct qeth_card *card = dev->driver_data;
62 if (!card)
63 return -EINVAL;
64
65 return sprintf(buf, "%02X\n", card->info.chpid);
66}
67
68static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
69
70static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -040071qeth_dev_if_name_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 struct qeth_card *card = dev->driver_data;
74 if (!card)
75 return -EINVAL;
76 return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
77}
78
79static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
80
81static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -040082qeth_dev_card_type_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 struct qeth_card *card = dev->driver_data;
85 if (!card)
86 return -EINVAL;
87
88 return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
89}
90
91static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
92
93static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -040094qeth_dev_portno_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 struct qeth_card *card = dev->driver_data;
97 if (!card)
98 return -EINVAL;
99
100 return sprintf(buf, "%i\n", card->info.portno);
101}
102
103static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400104qeth_dev_portno_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
106 struct qeth_card *card = dev->driver_data;
107 char *tmp;
108 unsigned int portno;
109
110 if (!card)
111 return -EINVAL;
112
113 if ((card->state != CARD_STATE_DOWN) &&
114 (card->state != CARD_STATE_RECOVER))
115 return -EPERM;
116
117 portno = simple_strtoul(buf, &tmp, 16);
Frank Pavlic1380fee2006-03-22 16:03:41 +0100118 if (portno > MAX_PORTNO){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 PRINT_WARN("portno 0x%X is out of range\n", portno);
120 return -EINVAL;
121 }
122
123 card->info.portno = portno;
124 return count;
125}
126
127static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
128
129static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400130qeth_dev_portname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 struct qeth_card *card = dev->driver_data;
133 char portname[9] = {0, };
134
135 if (!card)
136 return -EINVAL;
137
138 if (card->info.portname_required) {
139 memcpy(portname, card->info.portname + 1, 8);
140 EBCASC(portname, 8);
141 return sprintf(buf, "%s\n", portname);
142 } else
143 return sprintf(buf, "no portname required\n");
144}
145
146static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400147qeth_dev_portname_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 struct qeth_card *card = dev->driver_data;
150 char *tmp;
151 int i;
152
153 if (!card)
154 return -EINVAL;
155
156 if ((card->state != CARD_STATE_DOWN) &&
157 (card->state != CARD_STATE_RECOVER))
158 return -EPERM;
159
160 tmp = strsep((char **) &buf, "\n");
Frank Pavlic6c6b3e72005-12-13 08:21:47 +0100161 if ((strlen(tmp) > 8) || (strlen(tmp) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return -EINVAL;
163
164 card->info.portname[0] = strlen(tmp);
165 /* for beauty reasons */
166 for (i = 1; i < 9; i++)
167 card->info.portname[i] = ' ';
168 strcpy(card->info.portname + 1, tmp);
169 ASCEBC(card->info.portname + 1, 8);
170
171 return count;
172}
173
174static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
175 qeth_dev_portname_store);
176
177static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400178qeth_dev_checksum_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
180 struct qeth_card *card = dev->driver_data;
181
182 if (!card)
183 return -EINVAL;
184
185 return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
186}
187
188static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400189qeth_dev_checksum_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
191 struct qeth_card *card = dev->driver_data;
192 char *tmp;
193
194 if (!card)
195 return -EINVAL;
196
197 if ((card->state != CARD_STATE_DOWN) &&
198 (card->state != CARD_STATE_RECOVER))
199 return -EPERM;
200
201 tmp = strsep((char **) &buf, "\n");
202 if (!strcmp(tmp, "sw_checksumming"))
203 card->options.checksum_type = SW_CHECKSUMMING;
204 else if (!strcmp(tmp, "hw_checksumming"))
205 card->options.checksum_type = HW_CHECKSUMMING;
206 else if (!strcmp(tmp, "no_checksumming"))
207 card->options.checksum_type = NO_CHECKSUMMING;
208 else {
209 PRINT_WARN("Unknown checksumming type '%s'\n", tmp);
210 return -EINVAL;
211 }
212 return count;
213}
214
215static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
216 qeth_dev_checksum_store);
217
218static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400219qeth_dev_prioqing_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 struct qeth_card *card = dev->driver_data;
222
223 if (!card)
224 return -EINVAL;
225
226 switch (card->qdio.do_prio_queueing) {
227 case QETH_PRIO_Q_ING_PREC:
228 return sprintf(buf, "%s\n", "by precedence");
229 case QETH_PRIO_Q_ING_TOS:
230 return sprintf(buf, "%s\n", "by type of service");
231 default:
232 return sprintf(buf, "always queue %i\n",
233 card->qdio.default_out_queue);
234 }
235}
236
237static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400238qeth_dev_prioqing_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 struct qeth_card *card = dev->driver_data;
241 char *tmp;
242
243 if (!card)
244 return -EINVAL;
245
246 if ((card->state != CARD_STATE_DOWN) &&
247 (card->state != CARD_STATE_RECOVER))
248 return -EPERM;
249
250 /* check if 1920 devices are supported ,
251 * if though we have to permit priority queueing
252 */
253 if (card->qdio.no_out_queues == 1) {
254 PRINT_WARN("Priority queueing disabled due "
255 "to hardware limitations!\n");
256 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
257 return -EPERM;
258 }
259
260 tmp = strsep((char **) &buf, "\n");
261 if (!strcmp(tmp, "prio_queueing_prec"))
262 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
263 else if (!strcmp(tmp, "prio_queueing_tos"))
264 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
265 else if (!strcmp(tmp, "no_prio_queueing:0")) {
266 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
267 card->qdio.default_out_queue = 0;
268 } else if (!strcmp(tmp, "no_prio_queueing:1")) {
269 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
270 card->qdio.default_out_queue = 1;
271 } else if (!strcmp(tmp, "no_prio_queueing:2")) {
272 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
273 card->qdio.default_out_queue = 2;
274 } else if (!strcmp(tmp, "no_prio_queueing:3")) {
275 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
276 card->qdio.default_out_queue = 3;
277 } else if (!strcmp(tmp, "no_prio_queueing")) {
278 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
279 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
280 } else {
281 PRINT_WARN("Unknown queueing type '%s'\n", tmp);
282 return -EINVAL;
283 }
284 return count;
285}
286
287static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
288 qeth_dev_prioqing_store);
289
290static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400291qeth_dev_bufcnt_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
293 struct qeth_card *card = dev->driver_data;
294
295 if (!card)
296 return -EINVAL;
297
298 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
299}
300
301static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400302qeth_dev_bufcnt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
304 struct qeth_card *card = dev->driver_data;
305 char *tmp;
306 int cnt, old_cnt;
307 int rc;
308
309 if (!card)
310 return -EINVAL;
311
312 if ((card->state != CARD_STATE_DOWN) &&
313 (card->state != CARD_STATE_RECOVER))
314 return -EPERM;
315
316 old_cnt = card->qdio.in_buf_pool.buf_count;
317 cnt = simple_strtoul(buf, &tmp, 10);
318 cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
319 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
320 if (old_cnt != cnt) {
321 if ((rc = qeth_realloc_buffer_pool(card, cnt)))
322 PRINT_WARN("Error (%d) while setting "
323 "buffer count.\n", rc);
324 }
325 return count;
326}
327
328static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
329 qeth_dev_bufcnt_store);
330
331static inline ssize_t
332qeth_dev_route_show(struct qeth_card *card, struct qeth_routing_info *route,
333 char *buf)
334{
335 switch (route->type) {
336 case PRIMARY_ROUTER:
337 return sprintf(buf, "%s\n", "primary router");
338 case SECONDARY_ROUTER:
339 return sprintf(buf, "%s\n", "secondary router");
340 case MULTICAST_ROUTER:
341 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
342 return sprintf(buf, "%s\n", "multicast router+");
343 else
344 return sprintf(buf, "%s\n", "multicast router");
345 case PRIMARY_CONNECTOR:
346 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
347 return sprintf(buf, "%s\n", "primary connector+");
348 else
349 return sprintf(buf, "%s\n", "primary connector");
350 case SECONDARY_CONNECTOR:
351 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
352 return sprintf(buf, "%s\n", "secondary connector+");
353 else
354 return sprintf(buf, "%s\n", "secondary connector");
355 default:
356 return sprintf(buf, "%s\n", "no");
357 }
358}
359
360static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400361qeth_dev_route4_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
363 struct qeth_card *card = dev->driver_data;
364
365 if (!card)
366 return -EINVAL;
367
368 return qeth_dev_route_show(card, &card->options.route4, buf);
369}
370
371static inline ssize_t
372qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
373 enum qeth_prot_versions prot, const char *buf, size_t count)
374{
375 enum qeth_routing_types old_route_type = route->type;
376 char *tmp;
377 int rc;
378
379 tmp = strsep((char **) &buf, "\n");
380
381 if (!strcmp(tmp, "no_router")){
382 route->type = NO_ROUTER;
383 } else if (!strcmp(tmp, "primary_connector")) {
384 route->type = PRIMARY_CONNECTOR;
385 } else if (!strcmp(tmp, "secondary_connector")) {
386 route->type = SECONDARY_CONNECTOR;
387 } else if (!strcmp(tmp, "multicast_router")) {
388 route->type = MULTICAST_ROUTER;
389 } else if (!strcmp(tmp, "primary_router")) {
390 route->type = PRIMARY_ROUTER;
391 } else if (!strcmp(tmp, "secondary_router")) {
392 route->type = SECONDARY_ROUTER;
393 } else if (!strcmp(tmp, "multicast_router")) {
394 route->type = MULTICAST_ROUTER;
395 } else {
396 PRINT_WARN("Invalid routing type '%s'.\n", tmp);
397 return -EINVAL;
398 }
399 if (((card->state == CARD_STATE_SOFTSETUP) ||
400 (card->state == CARD_STATE_UP)) &&
401 (old_route_type != route->type)){
402 if (prot == QETH_PROT_IPV4)
403 rc = qeth_setrouting_v4(card);
404 else if (prot == QETH_PROT_IPV6)
405 rc = qeth_setrouting_v6(card);
406 }
407 return count;
408}
409
410static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400411qeth_dev_route4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
413 struct qeth_card *card = dev->driver_data;
414
415 if (!card)
416 return -EINVAL;
417
418 return qeth_dev_route_store(card, &card->options.route4,
419 QETH_PROT_IPV4, buf, count);
420}
421
422static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
423
424#ifdef CONFIG_QETH_IPV6
425static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400426qeth_dev_route6_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
428 struct qeth_card *card = dev->driver_data;
429
430 if (!card)
431 return -EINVAL;
432
433 if (!qeth_is_supported(card, IPA_IPV6))
434 return sprintf(buf, "%s\n", "n/a");
435
436 return qeth_dev_route_show(card, &card->options.route6, buf);
437}
438
439static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400440qeth_dev_route6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
442 struct qeth_card *card = dev->driver_data;
443
444 if (!card)
445 return -EINVAL;
446
447 if (!qeth_is_supported(card, IPA_IPV6)){
448 PRINT_WARN("IPv6 not supported for interface %s.\n"
449 "Routing status no changed.\n",
450 QETH_CARD_IFNAME(card));
451 return -ENOTSUPP;
452 }
453
454 return qeth_dev_route_store(card, &card->options.route6,
455 QETH_PROT_IPV6, buf, count);
456}
457
458static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
459#endif
460
461static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400462qeth_dev_add_hhlen_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
464 struct qeth_card *card = dev->driver_data;
465
466 if (!card)
467 return -EINVAL;
468
469 return sprintf(buf, "%i\n", card->options.add_hhlen);
470}
471
472static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400473qeth_dev_add_hhlen_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
475 struct qeth_card *card = dev->driver_data;
476 char *tmp;
477 int i;
478
479 if (!card)
480 return -EINVAL;
481
482 if ((card->state != CARD_STATE_DOWN) &&
483 (card->state != CARD_STATE_RECOVER))
484 return -EPERM;
485
486 i = simple_strtoul(buf, &tmp, 10);
487 if ((i < 0) || (i > MAX_ADD_HHLEN)) {
488 PRINT_WARN("add_hhlen out of range\n");
489 return -EINVAL;
490 }
491 card->options.add_hhlen = i;
492
493 return count;
494}
495
496static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
497 qeth_dev_add_hhlen_store);
498
499static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400500qeth_dev_fake_ll_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 struct qeth_card *card = dev->driver_data;
503
504 if (!card)
505 return -EINVAL;
506
507 return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
508}
509
510static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400511qeth_dev_fake_ll_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
513 struct qeth_card *card = dev->driver_data;
514 char *tmp;
515 int i;
516
517 if (!card)
518 return -EINVAL;
519
520 if ((card->state != CARD_STATE_DOWN) &&
521 (card->state != CARD_STATE_RECOVER))
522 return -EPERM;
523
524 i = simple_strtoul(buf, &tmp, 16);
525 if ((i != 0) && (i != 1)) {
526 PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
527 return -EINVAL;
528 }
529 card->options.fake_ll = i;
530 return count;
531}
532
533static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
534 qeth_dev_fake_ll_store);
535
536static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400537qeth_dev_fake_broadcast_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 struct qeth_card *card = dev->driver_data;
540
541 if (!card)
542 return -EINVAL;
543
544 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
545}
546
547static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400548qeth_dev_fake_broadcast_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 struct qeth_card *card = dev->driver_data;
551 char *tmp;
552 int i;
553
554 if (!card)
555 return -EINVAL;
556
557 if ((card->state != CARD_STATE_DOWN) &&
558 (card->state != CARD_STATE_RECOVER))
559 return -EPERM;
560
561 i = simple_strtoul(buf, &tmp, 16);
562 if ((i == 0) || (i == 1))
563 card->options.fake_broadcast = i;
564 else {
565 PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
566 return -EINVAL;
567 }
568 return count;
569}
570
571static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
572 qeth_dev_fake_broadcast_store);
573
574static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400575qeth_dev_recover_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 struct qeth_card *card = dev->driver_data;
578 char *tmp;
579 int i;
580
581 if (!card)
582 return -EINVAL;
583
584 if (card->state != CARD_STATE_UP)
585 return -EPERM;
586
587 i = simple_strtoul(buf, &tmp, 16);
588 if (i == 1)
589 qeth_schedule_recovery(card);
590
591 return count;
592}
593
594static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
595
596static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400597qeth_dev_broadcast_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
599 struct qeth_card *card = dev->driver_data;
600
601 if (!card)
602 return -EINVAL;
603
604 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
605 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
606 return sprintf(buf, "n/a\n");
607
608 return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
609 QETH_TR_BROADCAST_ALLRINGS)?
610 "all rings":"local");
611}
612
613static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400614qeth_dev_broadcast_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
616 struct qeth_card *card = dev->driver_data;
617 char *tmp;
618
619 if (!card)
620 return -EINVAL;
621
622 if ((card->state != CARD_STATE_DOWN) &&
623 (card->state != CARD_STATE_RECOVER))
624 return -EPERM;
625
626 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
627 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
628 PRINT_WARN("Device is not a tokenring device!\n");
629 return -EINVAL;
630 }
631
632 tmp = strsep((char **) &buf, "\n");
633
634 if (!strcmp(tmp, "local")){
635 card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
636 return count;
637 } else if (!strcmp(tmp, "all_rings")) {
638 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
639 return count;
640 } else {
641 PRINT_WARN("broadcast_mode: invalid mode %s!\n",
642 tmp);
643 return -EINVAL;
644 }
645 return count;
646}
647
648static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
649 qeth_dev_broadcast_mode_store);
650
651static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400652qeth_dev_canonical_macaddr_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
654 struct qeth_card *card = dev->driver_data;
655
656 if (!card)
657 return -EINVAL;
658
659 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
660 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
661 return sprintf(buf, "n/a\n");
662
663 return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
664 QETH_TR_MACADDR_CANONICAL)? 1:0);
665}
666
667static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400668qeth_dev_canonical_macaddr_store(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 size_t count)
670{
671 struct qeth_card *card = dev->driver_data;
672 char *tmp;
673 int i;
674
675 if (!card)
676 return -EINVAL;
677
678 if ((card->state != CARD_STATE_DOWN) &&
679 (card->state != CARD_STATE_RECOVER))
680 return -EPERM;
681
682 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
683 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
684 PRINT_WARN("Device is not a tokenring device!\n");
685 return -EINVAL;
686 }
687
688 i = simple_strtoul(buf, &tmp, 16);
689 if ((i == 0) || (i == 1))
690 card->options.macaddr_mode = i?
691 QETH_TR_MACADDR_CANONICAL :
692 QETH_TR_MACADDR_NONCANONICAL;
693 else {
694 PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
695 return -EINVAL;
696 }
697 return count;
698}
699
700static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
701 qeth_dev_canonical_macaddr_store);
702
703static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400704qeth_dev_layer2_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
706 struct qeth_card *card = dev->driver_data;
707
708 if (!card)
709 return -EINVAL;
710
711 return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
712}
713
714static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400715qeth_dev_layer2_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
717 struct qeth_card *card = dev->driver_data;
718 char *tmp;
719 int i;
720
721 if (!card)
722 return -EINVAL;
Frank Pavlicf3d242e2005-09-14 18:05:31 +0200723 if (card->info.type == QETH_CARD_TYPE_IQD) {
724 PRINT_WARN("Layer2 on Hipersockets is not supported! \n");
725 return -EPERM;
726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 if (((card->state != CARD_STATE_DOWN) &&
Frank Pavlicf3d242e2005-09-14 18:05:31 +0200729 (card->state != CARD_STATE_RECOVER)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 return -EPERM;
731
732 i = simple_strtoul(buf, &tmp, 16);
733 if ((i == 0) || (i == 1))
734 card->options.layer2 = i;
735 else {
736 PRINT_WARN("layer2: write 0 or 1 to this file!\n");
737 return -EINVAL;
738 }
739 return count;
740}
741
742static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
743 qeth_dev_layer2_store);
744
745static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400746qeth_dev_large_send_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
748 struct qeth_card *card = dev->driver_data;
749
750 if (!card)
751 return -EINVAL;
752
753 switch (card->options.large_send) {
754 case QETH_LARGE_SEND_NO:
755 return sprintf(buf, "%s\n", "no");
756 case QETH_LARGE_SEND_EDDP:
757 return sprintf(buf, "%s\n", "EDDP");
758 case QETH_LARGE_SEND_TSO:
759 return sprintf(buf, "%s\n", "TSO");
760 default:
761 return sprintf(buf, "%s\n", "N/A");
762 }
763}
764
765static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400766qeth_dev_large_send_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
768 struct qeth_card *card = dev->driver_data;
769 enum qeth_large_send_types type;
770 int rc = 0;
771 char *tmp;
772
773 if (!card)
774 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 tmp = strsep((char **) &buf, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (!strcmp(tmp, "no")){
777 type = QETH_LARGE_SEND_NO;
778 } else if (!strcmp(tmp, "EDDP")) {
779 type = QETH_LARGE_SEND_EDDP;
780 } else if (!strcmp(tmp, "TSO")) {
781 type = QETH_LARGE_SEND_TSO;
782 } else {
783 PRINT_WARN("large_send: invalid mode %s!\n", tmp);
784 return -EINVAL;
785 }
786 if (card->options.large_send == type)
787 return count;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400788 if ((rc = qeth_set_large_send(card, type)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 return count;
791}
792
793static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
794 qeth_dev_large_send_store);
795
796static ssize_t
797qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value )
798{
799
800 if (!card)
801 return -EINVAL;
802
803 return sprintf(buf, "%i\n", value);
804}
805
806static ssize_t
807qeth_dev_blkt_store(struct qeth_card *card, const char *buf, size_t count,
808 int *value, int max_value)
809{
810 char *tmp;
811 int i;
812
813 if (!card)
814 return -EINVAL;
815
816 if ((card->state != CARD_STATE_DOWN) &&
817 (card->state != CARD_STATE_RECOVER))
818 return -EPERM;
819
820 i = simple_strtoul(buf, &tmp, 10);
821 if (i <= max_value) {
822 *value = i;
823 } else {
824 PRINT_WARN("blkt total time: write values between"
825 " 0 and %d to this file!\n", max_value);
826 return -EINVAL;
827 }
828 return count;
829}
830
831static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400832qeth_dev_blkt_total_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
834 struct qeth_card *card = dev->driver_data;
835
836 return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
837}
838
839
840static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400841qeth_dev_blkt_total_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
843 struct qeth_card *card = dev->driver_data;
844
845 return qeth_dev_blkt_store(card, buf, count,
846 &card->info.blkt.time_total,1000);
847}
848
849
850
851static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
852 qeth_dev_blkt_total_store);
853
854static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400855qeth_dev_blkt_inter_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
857 struct qeth_card *card = dev->driver_data;
858
859 return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
860}
861
862
863static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400864qeth_dev_blkt_inter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
866 struct qeth_card *card = dev->driver_data;
867
868 return qeth_dev_blkt_store(card, buf, count,
869 &card->info.blkt.inter_packet,100);
870}
871
872static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
873 qeth_dev_blkt_inter_store);
874
875static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400876qeth_dev_blkt_inter_jumbo_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
878 struct qeth_card *card = dev->driver_data;
879
880 return qeth_dev_blkt_show(buf, card,
881 card->info.blkt.inter_packet_jumbo);
882}
883
884
885static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400886qeth_dev_blkt_inter_jumbo_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
888 struct qeth_card *card = dev->driver_data;
889
890 return qeth_dev_blkt_store(card, buf, count,
891 &card->info.blkt.inter_packet_jumbo,100);
892}
893
894static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
895 qeth_dev_blkt_inter_jumbo_store);
896
897static struct device_attribute * qeth_blkt_device_attrs[] = {
898 &dev_attr_total,
899 &dev_attr_inter,
900 &dev_attr_inter_jumbo,
901 NULL,
902};
903
904static struct attribute_group qeth_device_blkt_group = {
905 .name = "blkt",
906 .attrs = (struct attribute **)qeth_blkt_device_attrs,
907};
908
909static struct device_attribute * qeth_device_attrs[] = {
910 &dev_attr_state,
911 &dev_attr_chpid,
912 &dev_attr_if_name,
913 &dev_attr_card_type,
914 &dev_attr_portno,
915 &dev_attr_portname,
916 &dev_attr_checksumming,
917 &dev_attr_priority_queueing,
918 &dev_attr_buffer_count,
919 &dev_attr_route4,
920#ifdef CONFIG_QETH_IPV6
921 &dev_attr_route6,
922#endif
923 &dev_attr_add_hhlen,
924 &dev_attr_fake_ll,
925 &dev_attr_fake_broadcast,
926 &dev_attr_recover,
927 &dev_attr_broadcast_mode,
928 &dev_attr_canonical_macaddr,
929 &dev_attr_layer2,
930 &dev_attr_large_send,
931 NULL,
932};
933
934static struct attribute_group qeth_device_attr_group = {
935 .attrs = (struct attribute **)qeth_device_attrs,
936};
937
Ursula Braun500f83a2005-09-30 10:19:19 +0200938static struct device_attribute * qeth_osn_device_attrs[] = {
939 &dev_attr_state,
940 &dev_attr_chpid,
941 &dev_attr_if_name,
942 &dev_attr_card_type,
943 &dev_attr_buffer_count,
944 &dev_attr_recover,
945 NULL,
946};
947
948static struct attribute_group qeth_osn_device_attr_group = {
949 .attrs = (struct attribute **)qeth_osn_device_attrs,
950};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952#define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
953struct device_attribute dev_attr_##_id = { \
954 .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
955 .show = _show, \
956 .store = _store, \
957};
958
959int
960qeth_check_layer2(struct qeth_card *card)
961{
962 if (card->options.layer2)
963 return -EPERM;
964 return 0;
965}
966
967
968static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400969qeth_dev_ipato_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 struct qeth_card *card = dev->driver_data;
972
973 if (!card)
974 return -EINVAL;
975
976 if (qeth_check_layer2(card))
977 return -EPERM;
978 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
979}
980
981static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400982qeth_dev_ipato_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
984 struct qeth_card *card = dev->driver_data;
985 char *tmp;
986
987 if (!card)
988 return -EINVAL;
989
990 if ((card->state != CARD_STATE_DOWN) &&
991 (card->state != CARD_STATE_RECOVER))
992 return -EPERM;
993
994 if (qeth_check_layer2(card))
995 return -EPERM;
996
997 tmp = strsep((char **) &buf, "\n");
998 if (!strcmp(tmp, "toggle")){
999 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
1000 } else if (!strcmp(tmp, "1")){
1001 card->ipato.enabled = 1;
1002 } else if (!strcmp(tmp, "0")){
1003 card->ipato.enabled = 0;
1004 } else {
1005 PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
1006 "this file\n");
1007 return -EINVAL;
1008 }
1009 return count;
1010}
1011
1012static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
1013 qeth_dev_ipato_enable_show,
1014 qeth_dev_ipato_enable_store);
1015
1016static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001017qeth_dev_ipato_invert4_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
1019 struct qeth_card *card = dev->driver_data;
1020
1021 if (!card)
1022 return -EINVAL;
1023
1024 if (qeth_check_layer2(card))
1025 return -EPERM;
1026
1027 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
1028}
1029
1030static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001031qeth_dev_ipato_invert4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 struct qeth_card *card = dev->driver_data;
1034 char *tmp;
1035
1036 if (!card)
1037 return -EINVAL;
1038
1039 if (qeth_check_layer2(card))
1040 return -EPERM;
1041
1042 tmp = strsep((char **) &buf, "\n");
1043 if (!strcmp(tmp, "toggle")){
1044 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
1045 } else if (!strcmp(tmp, "1")){
1046 card->ipato.invert4 = 1;
1047 } else if (!strcmp(tmp, "0")){
1048 card->ipato.invert4 = 0;
1049 } else {
1050 PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
1051 "this file\n");
1052 return -EINVAL;
1053 }
1054 return count;
1055}
1056
1057static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
1058 qeth_dev_ipato_invert4_show,
1059 qeth_dev_ipato_invert4_store);
1060
1061static inline ssize_t
1062qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
1063 enum qeth_prot_versions proto)
1064{
1065 struct qeth_ipato_entry *ipatoe;
1066 unsigned long flags;
1067 char addr_str[40];
1068 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1069 int i = 0;
1070
1071 if (qeth_check_layer2(card))
1072 return -EPERM;
1073
1074 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1075 /* add strlen for "/<mask>\n" */
1076 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
1077 spin_lock_irqsave(&card->ip_lock, flags);
1078 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
1079 if (ipatoe->proto != proto)
1080 continue;
1081 /* String must not be longer than PAGE_SIZE. So we check if
1082 * string length gets near PAGE_SIZE. Then we can savely display
1083 * the next IPv6 address (worst case, compared to IPv4) */
1084 if ((PAGE_SIZE - i) <= entry_len)
1085 break;
1086 qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
1087 i += snprintf(buf + i, PAGE_SIZE - i,
1088 "%s/%i\n", addr_str, ipatoe->mask_bits);
1089 }
1090 spin_unlock_irqrestore(&card->ip_lock, flags);
1091 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1092
1093 return i;
1094}
1095
1096static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001097qeth_dev_ipato_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
1099 struct qeth_card *card = dev->driver_data;
1100
1101 if (!card)
1102 return -EINVAL;
1103
1104 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
1105}
1106
1107static inline int
1108qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
1109 u8 *addr, int *mask_bits)
1110{
1111 const char *start, *end;
1112 char *tmp;
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001113 char buffer[40] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 start = buf;
1116 /* get address string */
1117 end = strchr(start, '/');
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001118 if (!end || (end - start >= 40)){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 PRINT_WARN("Invalid format for ipato_addx/delx. "
1120 "Use <ip addr>/<mask bits>\n");
1121 return -EINVAL;
1122 }
1123 strncpy(buffer, start, end - start);
1124 if (qeth_string_to_ipaddr(buffer, proto, addr)){
1125 PRINT_WARN("Invalid IP address format!\n");
1126 return -EINVAL;
1127 }
1128 start = end + 1;
1129 *mask_bits = simple_strtoul(start, &tmp, 10);
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001130 if (!strlen(start) ||
1131 (tmp == start) ||
1132 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
1133 PRINT_WARN("Invalid mask bits for ipato_addx/delx !\n");
1134 return -EINVAL;
1135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 return 0;
1137}
1138
1139static inline ssize_t
1140qeth_dev_ipato_add_store(const char *buf, size_t count,
1141 struct qeth_card *card, enum qeth_prot_versions proto)
1142{
1143 struct qeth_ipato_entry *ipatoe;
1144 u8 addr[16];
1145 int mask_bits;
1146 int rc;
1147
1148 if (qeth_check_layer2(card))
1149 return -EPERM;
1150 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1151 return rc;
1152
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001153 if (!(ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 PRINT_WARN("No memory to allocate ipato entry\n");
1155 return -ENOMEM;
1156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 ipatoe->proto = proto;
1158 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
1159 ipatoe->mask_bits = mask_bits;
1160
1161 if ((rc = qeth_add_ipato_entry(card, ipatoe))){
1162 kfree(ipatoe);
1163 return rc;
1164 }
1165
1166 return count;
1167}
1168
1169static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001170qeth_dev_ipato_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
1172 struct qeth_card *card = dev->driver_data;
1173
1174 if (!card)
1175 return -EINVAL;
1176
1177 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
1178}
1179
1180static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
1181 qeth_dev_ipato_add4_show,
1182 qeth_dev_ipato_add4_store);
1183
1184static inline ssize_t
1185qeth_dev_ipato_del_store(const char *buf, size_t count,
1186 struct qeth_card *card, enum qeth_prot_versions proto)
1187{
1188 u8 addr[16];
1189 int mask_bits;
1190 int rc;
1191
1192 if (qeth_check_layer2(card))
1193 return -EPERM;
1194 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1195 return rc;
1196
1197 qeth_del_ipato_entry(card, proto, addr, mask_bits);
1198
1199 return count;
1200}
1201
1202static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001203qeth_dev_ipato_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
1205 struct qeth_card *card = dev->driver_data;
1206
1207 if (!card)
1208 return -EINVAL;
1209
1210 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
1211}
1212
1213static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
1214 qeth_dev_ipato_del4_store);
1215
1216#ifdef CONFIG_QETH_IPV6
1217static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001218qeth_dev_ipato_invert6_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
1220 struct qeth_card *card = dev->driver_data;
1221
1222 if (!card)
1223 return -EINVAL;
1224
1225 if (qeth_check_layer2(card))
1226 return -EPERM;
1227
1228 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
1229}
1230
1231static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001232qeth_dev_ipato_invert6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
1234 struct qeth_card *card = dev->driver_data;
1235 char *tmp;
1236
1237 if (!card)
1238 return -EINVAL;
1239
1240 if (qeth_check_layer2(card))
1241 return -EPERM;
1242
1243 tmp = strsep((char **) &buf, "\n");
1244 if (!strcmp(tmp, "toggle")){
1245 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
1246 } else if (!strcmp(tmp, "1")){
1247 card->ipato.invert6 = 1;
1248 } else if (!strcmp(tmp, "0")){
1249 card->ipato.invert6 = 0;
1250 } else {
1251 PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
1252 "this file\n");
1253 return -EINVAL;
1254 }
1255 return count;
1256}
1257
1258static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
1259 qeth_dev_ipato_invert6_show,
1260 qeth_dev_ipato_invert6_store);
1261
1262
1263static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001264qeth_dev_ipato_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
1266 struct qeth_card *card = dev->driver_data;
1267
1268 if (!card)
1269 return -EINVAL;
1270
1271 return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
1272}
1273
1274static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001275qeth_dev_ipato_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
1277 struct qeth_card *card = dev->driver_data;
1278
1279 if (!card)
1280 return -EINVAL;
1281
1282 return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
1283}
1284
1285static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
1286 qeth_dev_ipato_add6_show,
1287 qeth_dev_ipato_add6_store);
1288
1289static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001290qeth_dev_ipato_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291{
1292 struct qeth_card *card = dev->driver_data;
1293
1294 if (!card)
1295 return -EINVAL;
1296
1297 return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
1298}
1299
1300static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
1301 qeth_dev_ipato_del6_store);
1302#endif /* CONFIG_QETH_IPV6 */
1303
1304static struct device_attribute * qeth_ipato_device_attrs[] = {
1305 &dev_attr_ipato_enable,
1306 &dev_attr_ipato_invert4,
1307 &dev_attr_ipato_add4,
1308 &dev_attr_ipato_del4,
1309#ifdef CONFIG_QETH_IPV6
1310 &dev_attr_ipato_invert6,
1311 &dev_attr_ipato_add6,
1312 &dev_attr_ipato_del6,
1313#endif
1314 NULL,
1315};
1316
1317static struct attribute_group qeth_device_ipato_group = {
1318 .name = "ipa_takeover",
1319 .attrs = (struct attribute **)qeth_ipato_device_attrs,
1320};
1321
1322static inline ssize_t
1323qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
1324 enum qeth_prot_versions proto)
1325{
1326 struct qeth_ipaddr *ipaddr;
1327 char addr_str[40];
1328 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1329 unsigned long flags;
1330 int i = 0;
1331
1332 if (qeth_check_layer2(card))
1333 return -EPERM;
1334
1335 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1336 entry_len += 2; /* \n + terminator */
1337 spin_lock_irqsave(&card->ip_lock, flags);
1338 list_for_each_entry(ipaddr, &card->ip_list, entry){
1339 if (ipaddr->proto != proto)
1340 continue;
1341 if (ipaddr->type != QETH_IP_TYPE_VIPA)
1342 continue;
1343 /* String must not be longer than PAGE_SIZE. So we check if
1344 * string length gets near PAGE_SIZE. Then we can savely display
1345 * the next IPv6 address (worst case, compared to IPv4) */
1346 if ((PAGE_SIZE - i) <= entry_len)
1347 break;
1348 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1349 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1350 }
1351 spin_unlock_irqrestore(&card->ip_lock, flags);
1352 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1353
1354 return i;
1355}
1356
1357static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001358qeth_dev_vipa_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
1360 struct qeth_card *card = dev->driver_data;
1361
1362 if (!card)
1363 return -EINVAL;
1364
1365 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
1366}
1367
1368static inline int
1369qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
1370 u8 *addr)
1371{
1372 if (qeth_string_to_ipaddr(buf, proto, addr)){
1373 PRINT_WARN("Invalid IP address format!\n");
1374 return -EINVAL;
1375 }
1376 return 0;
1377}
1378
1379static inline ssize_t
1380qeth_dev_vipa_add_store(const char *buf, size_t count,
1381 struct qeth_card *card, enum qeth_prot_versions proto)
1382{
1383 u8 addr[16] = {0, };
1384 int rc;
1385
1386 if (qeth_check_layer2(card))
1387 return -EPERM;
1388 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1389 return rc;
1390
1391 if ((rc = qeth_add_vipa(card, proto, addr)))
1392 return rc;
1393
1394 return count;
1395}
1396
1397static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001398qeth_dev_vipa_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
1400 struct qeth_card *card = dev->driver_data;
1401
1402 if (!card)
1403 return -EINVAL;
1404
1405 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
1406}
1407
1408static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
1409 qeth_dev_vipa_add4_show,
1410 qeth_dev_vipa_add4_store);
1411
1412static inline ssize_t
1413qeth_dev_vipa_del_store(const char *buf, size_t count,
1414 struct qeth_card *card, enum qeth_prot_versions proto)
1415{
1416 u8 addr[16];
1417 int rc;
1418
1419 if (qeth_check_layer2(card))
1420 return -EPERM;
1421 if ((rc = qeth_parse_vipae(buf, proto, addr)))
1422 return rc;
1423
1424 qeth_del_vipa(card, proto, addr);
1425
1426 return count;
1427}
1428
1429static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001430qeth_dev_vipa_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
1432 struct qeth_card *card = dev->driver_data;
1433
1434 if (!card)
1435 return -EINVAL;
1436
1437 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
1438}
1439
1440static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
1441 qeth_dev_vipa_del4_store);
1442
1443#ifdef CONFIG_QETH_IPV6
1444static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001445qeth_dev_vipa_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
1447 struct qeth_card *card = dev->driver_data;
1448
1449 if (!card)
1450 return -EINVAL;
1451
1452 return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
1453}
1454
1455static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001456qeth_dev_vipa_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457{
1458 struct qeth_card *card = dev->driver_data;
1459
1460 if (!card)
1461 return -EINVAL;
1462
1463 return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
1464}
1465
1466static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
1467 qeth_dev_vipa_add6_show,
1468 qeth_dev_vipa_add6_store);
1469
1470static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001471qeth_dev_vipa_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
1473 struct qeth_card *card = dev->driver_data;
1474
1475 if (!card)
1476 return -EINVAL;
1477
1478 if (qeth_check_layer2(card))
1479 return -EPERM;
1480
1481 return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
1482}
1483
1484static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
1485 qeth_dev_vipa_del6_store);
1486#endif /* CONFIG_QETH_IPV6 */
1487
1488static struct device_attribute * qeth_vipa_device_attrs[] = {
1489 &dev_attr_vipa_add4,
1490 &dev_attr_vipa_del4,
1491#ifdef CONFIG_QETH_IPV6
1492 &dev_attr_vipa_add6,
1493 &dev_attr_vipa_del6,
1494#endif
1495 NULL,
1496};
1497
1498static struct attribute_group qeth_device_vipa_group = {
1499 .name = "vipa",
1500 .attrs = (struct attribute **)qeth_vipa_device_attrs,
1501};
1502
1503static inline ssize_t
1504qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
1505 enum qeth_prot_versions proto)
1506{
1507 struct qeth_ipaddr *ipaddr;
1508 char addr_str[40];
1509 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
1510 unsigned long flags;
1511 int i = 0;
1512
1513 if (qeth_check_layer2(card))
1514 return -EPERM;
1515
1516 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
1517 entry_len += 2; /* \n + terminator */
1518 spin_lock_irqsave(&card->ip_lock, flags);
1519 list_for_each_entry(ipaddr, &card->ip_list, entry){
1520 if (ipaddr->proto != proto)
1521 continue;
1522 if (ipaddr->type != QETH_IP_TYPE_RXIP)
1523 continue;
1524 /* String must not be longer than PAGE_SIZE. So we check if
1525 * string length gets near PAGE_SIZE. Then we can savely display
1526 * the next IPv6 address (worst case, compared to IPv4) */
1527 if ((PAGE_SIZE - i) <= entry_len)
1528 break;
1529 qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
1530 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
1531 }
1532 spin_unlock_irqrestore(&card->ip_lock, flags);
1533 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
1534
1535 return i;
1536}
1537
1538static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001539qeth_dev_rxip_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
1541 struct qeth_card *card = dev->driver_data;
1542
1543 if (!card)
1544 return -EINVAL;
1545
1546 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
1547}
1548
1549static inline int
1550qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
1551 u8 *addr)
1552{
1553 if (qeth_string_to_ipaddr(buf, proto, addr)){
1554 PRINT_WARN("Invalid IP address format!\n");
1555 return -EINVAL;
1556 }
1557 return 0;
1558}
1559
1560static inline ssize_t
1561qeth_dev_rxip_add_store(const char *buf, size_t count,
1562 struct qeth_card *card, enum qeth_prot_versions proto)
1563{
1564 u8 addr[16] = {0, };
1565 int rc;
1566
1567 if (qeth_check_layer2(card))
1568 return -EPERM;
1569 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1570 return rc;
1571
1572 if ((rc = qeth_add_rxip(card, proto, addr)))
1573 return rc;
1574
1575 return count;
1576}
1577
1578static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001579qeth_dev_rxip_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
1581 struct qeth_card *card = dev->driver_data;
1582
1583 if (!card)
1584 return -EINVAL;
1585
1586 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
1587}
1588
1589static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
1590 qeth_dev_rxip_add4_show,
1591 qeth_dev_rxip_add4_store);
1592
1593static inline ssize_t
1594qeth_dev_rxip_del_store(const char *buf, size_t count,
1595 struct qeth_card *card, enum qeth_prot_versions proto)
1596{
1597 u8 addr[16];
1598 int rc;
1599
1600 if (qeth_check_layer2(card))
1601 return -EPERM;
1602 if ((rc = qeth_parse_rxipe(buf, proto, addr)))
1603 return rc;
1604
1605 qeth_del_rxip(card, proto, addr);
1606
1607 return count;
1608}
1609
1610static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001611qeth_dev_rxip_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
1613 struct qeth_card *card = dev->driver_data;
1614
1615 if (!card)
1616 return -EINVAL;
1617
1618 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
1619}
1620
1621static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
1622 qeth_dev_rxip_del4_store);
1623
1624#ifdef CONFIG_QETH_IPV6
1625static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001626qeth_dev_rxip_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627{
1628 struct qeth_card *card = dev->driver_data;
1629
1630 if (!card)
1631 return -EINVAL;
1632
1633 return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
1634}
1635
1636static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001637qeth_dev_rxip_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
1639 struct qeth_card *card = dev->driver_data;
1640
1641 if (!card)
1642 return -EINVAL;
1643
1644 return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1645}
1646
1647static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1648 qeth_dev_rxip_add6_show,
1649 qeth_dev_rxip_add6_store);
1650
1651static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -04001652qeth_dev_rxip_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
1654 struct qeth_card *card = dev->driver_data;
1655
1656 if (!card)
1657 return -EINVAL;
1658
1659 return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1660}
1661
1662static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1663 qeth_dev_rxip_del6_store);
1664#endif /* CONFIG_QETH_IPV6 */
1665
1666static struct device_attribute * qeth_rxip_device_attrs[] = {
1667 &dev_attr_rxip_add4,
1668 &dev_attr_rxip_del4,
1669#ifdef CONFIG_QETH_IPV6
1670 &dev_attr_rxip_add6,
1671 &dev_attr_rxip_del6,
1672#endif
1673 NULL,
1674};
1675
1676static struct attribute_group qeth_device_rxip_group = {
1677 .name = "rxip",
1678 .attrs = (struct attribute **)qeth_rxip_device_attrs,
1679};
1680
1681int
1682qeth_create_device_attributes(struct device *dev)
1683{
1684 int ret;
Ursula Braun500f83a2005-09-30 10:19:19 +02001685 struct qeth_card *card = dev->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Ursula Braun500f83a2005-09-30 10:19:19 +02001687 if (card->info.type == QETH_CARD_TYPE_OSN)
1688 return sysfs_create_group(&dev->kobj,
1689 &qeth_osn_device_attr_group);
Jeff Garzike82b0f22006-05-26 21:58:38 -04001690
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1692 return ret;
1693 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
1694 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1695 return ret;
1696 }
1697 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
1698 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1699 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1700 return ret;
1701 }
1702 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
1703 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1704 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1705 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 return ret;
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001707 }
1708 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group))){
1709 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1710 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1711 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1712 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1713 return ret;
1714 }
1715 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
1718void
1719qeth_remove_device_attributes(struct device *dev)
1720{
Ursula Braun500f83a2005-09-30 10:19:19 +02001721 struct qeth_card *card = dev->driver_data;
1722
1723 if (card->info.type == QETH_CARD_TYPE_OSN)
1724 return sysfs_remove_group(&dev->kobj,
1725 &qeth_osn_device_attr_group);
Jeff Garzike82b0f22006-05-26 21:58:38 -04001726
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1728 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1729 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1730 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1731 sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
1732}
1733
1734/**********************/
1735/* DRIVER ATTRIBUTES */
1736/**********************/
1737static ssize_t
1738qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1739 size_t count)
1740{
1741 const char *start, *end;
1742 char bus_ids[3][BUS_ID_SIZE], *argv[3];
1743 int i;
1744 int err;
1745
1746 start = buf;
1747 for (i = 0; i < 3; i++) {
1748 static const char delim[] = { ',', ',', '\n' };
1749 int len;
1750
1751 if (!(end = strchr(start, delim[i])))
1752 return -EINVAL;
1753 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
1754 strncpy(bus_ids[i], start, len);
1755 bus_ids[i][len] = '\0';
1756 start = end + 1;
1757 argv[i] = bus_ids[i];
1758 }
1759 err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
1760 &qeth_ccw_driver, 3, argv);
1761 if (err)
1762 return err;
1763 else
1764 return count;
1765}
1766
1767
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001768static DRIVER_ATTR(group, 0200, NULL, qeth_driver_group_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770static ssize_t
1771qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
1772 size_t count)
1773{
1774 int rc;
1775 int signum;
1776 char *tmp, *tmp2;
1777
1778 tmp = strsep((char **) &buf, "\n");
1779 if (!strncmp(tmp, "unregister", 10)){
1780 if ((rc = qeth_notifier_unregister(current)))
1781 return rc;
1782 return count;
1783 }
1784
1785 signum = simple_strtoul(tmp, &tmp2, 10);
1786 if ((signum < 0) || (signum > 32)){
1787 PRINT_WARN("Signal number %d is out of range\n", signum);
1788 return -EINVAL;
1789 }
1790 if ((rc = qeth_notifier_register(current, signum)))
1791 return rc;
1792
1793 return count;
1794}
1795
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001796static DRIVER_ATTR(notifier_register, 0200, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 qeth_driver_notifier_register_store);
1798
1799int
1800qeth_create_driver_attributes(void)
1801{
1802 int rc;
1803
1804 if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
1805 &driver_attr_group)))
1806 return rc;
1807 return driver_create_file(&qeth_ccwgroup_driver.driver,
1808 &driver_attr_notifier_register);
1809}
1810
1811void
1812qeth_remove_driver_attributes(void)
1813{
1814 driver_remove_file(&qeth_ccwgroup_driver.driver,
1815 &driver_attr_group);
1816 driver_remove_file(&qeth_ccwgroup_driver.driver,
1817 &driver_attr_notifier_register);
1818}