powerpc: use consistent types in mktree
[zen-stable.git] / drivers / s390 / net / qeth_core_sys.c
blob568465d7517fea77fde3a1c3562cd896ae31cb13
1 /*
2 * drivers/s390/net/qeth_core_sys.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
11 #include <linux/list.h>
12 #include <linux/rwsem.h>
13 #include <asm/ebcdic.h>
15 #include "qeth_core.h"
17 static ssize_t qeth_dev_state_show(struct device *dev,
18 struct device_attribute *attr, char *buf)
20 struct qeth_card *card = dev_get_drvdata(dev);
21 if (!card)
22 return -EINVAL;
24 switch (card->state) {
25 case CARD_STATE_DOWN:
26 return sprintf(buf, "DOWN\n");
27 case CARD_STATE_HARDSETUP:
28 return sprintf(buf, "HARDSETUP\n");
29 case CARD_STATE_SOFTSETUP:
30 return sprintf(buf, "SOFTSETUP\n");
31 case CARD_STATE_UP:
32 if (card->lan_online)
33 return sprintf(buf, "UP (LAN ONLINE)\n");
34 else
35 return sprintf(buf, "UP (LAN OFFLINE)\n");
36 case CARD_STATE_RECOVER:
37 return sprintf(buf, "RECOVER\n");
38 default:
39 return sprintf(buf, "UNKNOWN\n");
43 static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
45 static ssize_t qeth_dev_chpid_show(struct device *dev,
46 struct device_attribute *attr, char *buf)
48 struct qeth_card *card = dev_get_drvdata(dev);
49 if (!card)
50 return -EINVAL;
52 return sprintf(buf, "%02X\n", card->info.chpid);
55 static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
57 static ssize_t qeth_dev_if_name_show(struct device *dev,
58 struct device_attribute *attr, char *buf)
60 struct qeth_card *card = dev_get_drvdata(dev);
61 if (!card)
62 return -EINVAL;
63 return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
66 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
68 static ssize_t qeth_dev_card_type_show(struct device *dev,
69 struct device_attribute *attr, char *buf)
71 struct qeth_card *card = dev_get_drvdata(dev);
72 if (!card)
73 return -EINVAL;
75 return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
78 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
80 static inline const char *qeth_get_bufsize_str(struct qeth_card *card)
82 if (card->qdio.in_buf_size == 16384)
83 return "16k";
84 else if (card->qdio.in_buf_size == 24576)
85 return "24k";
86 else if (card->qdio.in_buf_size == 32768)
87 return "32k";
88 else if (card->qdio.in_buf_size == 40960)
89 return "40k";
90 else
91 return "64k";
94 static ssize_t qeth_dev_inbuf_size_show(struct device *dev,
95 struct device_attribute *attr, char *buf)
97 struct qeth_card *card = dev_get_drvdata(dev);
98 if (!card)
99 return -EINVAL;
101 return sprintf(buf, "%s\n", qeth_get_bufsize_str(card));
104 static DEVICE_ATTR(inbuf_size, 0444, qeth_dev_inbuf_size_show, NULL);
106 static ssize_t qeth_dev_portno_show(struct device *dev,
107 struct device_attribute *attr, char *buf)
109 struct qeth_card *card = dev_get_drvdata(dev);
110 if (!card)
111 return -EINVAL;
113 return sprintf(buf, "%i\n", card->info.portno);
116 static ssize_t qeth_dev_portno_store(struct device *dev,
117 struct device_attribute *attr, const char *buf, size_t count)
119 struct qeth_card *card = dev_get_drvdata(dev);
120 char *tmp;
121 unsigned int portno;
123 if (!card)
124 return -EINVAL;
126 if ((card->state != CARD_STATE_DOWN) &&
127 (card->state != CARD_STATE_RECOVER))
128 return -EPERM;
130 portno = simple_strtoul(buf, &tmp, 16);
131 if (portno > QETH_MAX_PORTNO) {
132 return -EINVAL;
135 card->info.portno = portno;
136 return count;
139 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
141 static ssize_t qeth_dev_portname_show(struct device *dev,
142 struct device_attribute *attr, char *buf)
144 struct qeth_card *card = dev_get_drvdata(dev);
145 char portname[9] = {0, };
147 if (!card)
148 return -EINVAL;
150 if (card->info.portname_required) {
151 memcpy(portname, card->info.portname + 1, 8);
152 EBCASC(portname, 8);
153 return sprintf(buf, "%s\n", portname);
154 } else
155 return sprintf(buf, "no portname required\n");
158 static ssize_t qeth_dev_portname_store(struct device *dev,
159 struct device_attribute *attr, const char *buf, size_t count)
161 struct qeth_card *card = dev_get_drvdata(dev);
162 char *tmp;
163 int i;
165 if (!card)
166 return -EINVAL;
168 if ((card->state != CARD_STATE_DOWN) &&
169 (card->state != CARD_STATE_RECOVER))
170 return -EPERM;
172 tmp = strsep((char **) &buf, "\n");
173 if ((strlen(tmp) > 8) || (strlen(tmp) == 0))
174 return -EINVAL;
176 card->info.portname[0] = strlen(tmp);
177 /* for beauty reasons */
178 for (i = 1; i < 9; i++)
179 card->info.portname[i] = ' ';
180 strcpy(card->info.portname + 1, tmp);
181 ASCEBC(card->info.portname + 1, 8);
183 return count;
186 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
187 qeth_dev_portname_store);
189 static ssize_t qeth_dev_prioqing_show(struct device *dev,
190 struct device_attribute *attr, char *buf)
192 struct qeth_card *card = dev_get_drvdata(dev);
194 if (!card)
195 return -EINVAL;
197 switch (card->qdio.do_prio_queueing) {
198 case QETH_PRIO_Q_ING_PREC:
199 return sprintf(buf, "%s\n", "by precedence");
200 case QETH_PRIO_Q_ING_TOS:
201 return sprintf(buf, "%s\n", "by type of service");
202 default:
203 return sprintf(buf, "always queue %i\n",
204 card->qdio.default_out_queue);
208 static ssize_t qeth_dev_prioqing_store(struct device *dev,
209 struct device_attribute *attr, const char *buf, size_t count)
211 struct qeth_card *card = dev_get_drvdata(dev);
212 char *tmp;
214 if (!card)
215 return -EINVAL;
217 if ((card->state != CARD_STATE_DOWN) &&
218 (card->state != CARD_STATE_RECOVER))
219 return -EPERM;
221 /* check if 1920 devices are supported ,
222 * if though we have to permit priority queueing
224 if (card->qdio.no_out_queues == 1) {
225 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
226 return -EPERM;
229 tmp = strsep((char **) &buf, "\n");
230 if (!strcmp(tmp, "prio_queueing_prec"))
231 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
232 else if (!strcmp(tmp, "prio_queueing_tos"))
233 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
234 else if (!strcmp(tmp, "no_prio_queueing:0")) {
235 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
236 card->qdio.default_out_queue = 0;
237 } else if (!strcmp(tmp, "no_prio_queueing:1")) {
238 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
239 card->qdio.default_out_queue = 1;
240 } else if (!strcmp(tmp, "no_prio_queueing:2")) {
241 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
242 card->qdio.default_out_queue = 2;
243 } else if (!strcmp(tmp, "no_prio_queueing:3")) {
244 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
245 card->qdio.default_out_queue = 3;
246 } else if (!strcmp(tmp, "no_prio_queueing")) {
247 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
248 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
249 } else {
250 return -EINVAL;
252 return count;
255 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
256 qeth_dev_prioqing_store);
258 static ssize_t qeth_dev_bufcnt_show(struct device *dev,
259 struct device_attribute *attr, char *buf)
261 struct qeth_card *card = dev_get_drvdata(dev);
263 if (!card)
264 return -EINVAL;
266 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
269 static ssize_t qeth_dev_bufcnt_store(struct device *dev,
270 struct device_attribute *attr, const char *buf, size_t count)
272 struct qeth_card *card = dev_get_drvdata(dev);
273 char *tmp;
274 int cnt, old_cnt;
275 int rc;
277 if (!card)
278 return -EINVAL;
280 if ((card->state != CARD_STATE_DOWN) &&
281 (card->state != CARD_STATE_RECOVER))
282 return -EPERM;
284 old_cnt = card->qdio.in_buf_pool.buf_count;
285 cnt = simple_strtoul(buf, &tmp, 10);
286 cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
287 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
288 if (old_cnt != cnt) {
289 rc = qeth_realloc_buffer_pool(card, cnt);
291 return count;
294 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
295 qeth_dev_bufcnt_store);
297 static ssize_t qeth_dev_recover_store(struct device *dev,
298 struct device_attribute *attr, const char *buf, size_t count)
300 struct qeth_card *card = dev_get_drvdata(dev);
301 char *tmp;
302 int i;
304 if (!card)
305 return -EINVAL;
307 if (card->state != CARD_STATE_UP)
308 return -EPERM;
310 i = simple_strtoul(buf, &tmp, 16);
311 if (i == 1)
312 qeth_schedule_recovery(card);
314 return count;
317 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
319 static ssize_t qeth_dev_performance_stats_show(struct device *dev,
320 struct device_attribute *attr, char *buf)
322 struct qeth_card *card = dev_get_drvdata(dev);
324 if (!card)
325 return -EINVAL;
327 return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
330 static ssize_t qeth_dev_performance_stats_store(struct device *dev,
331 struct device_attribute *attr, const char *buf, size_t count)
333 struct qeth_card *card = dev_get_drvdata(dev);
334 char *tmp;
335 int i;
337 if (!card)
338 return -EINVAL;
340 i = simple_strtoul(buf, &tmp, 16);
341 if ((i == 0) || (i == 1)) {
342 if (i == card->options.performance_stats)
343 return count;
344 card->options.performance_stats = i;
345 if (i == 0)
346 memset(&card->perf_stats, 0,
347 sizeof(struct qeth_perf_stats));
348 card->perf_stats.initial_rx_packets = card->stats.rx_packets;
349 card->perf_stats.initial_tx_packets = card->stats.tx_packets;
350 } else {
351 return -EINVAL;
353 return count;
356 static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
357 qeth_dev_performance_stats_store);
359 static ssize_t qeth_dev_layer2_show(struct device *dev,
360 struct device_attribute *attr, char *buf)
362 struct qeth_card *card = dev_get_drvdata(dev);
364 if (!card)
365 return -EINVAL;
367 return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
370 static ssize_t qeth_dev_layer2_store(struct device *dev,
371 struct device_attribute *attr, const char *buf, size_t count)
373 struct qeth_card *card = dev_get_drvdata(dev);
374 char *tmp;
375 int i, rc;
376 enum qeth_discipline_id newdis;
378 if (!card)
379 return -EINVAL;
381 if (((card->state != CARD_STATE_DOWN) &&
382 (card->state != CARD_STATE_RECOVER)))
383 return -EPERM;
385 i = simple_strtoul(buf, &tmp, 16);
386 switch (i) {
387 case 0:
388 newdis = QETH_DISCIPLINE_LAYER3;
389 break;
390 case 1:
391 newdis = QETH_DISCIPLINE_LAYER2;
392 break;
393 default:
394 return -EINVAL;
397 if (card->options.layer2 == newdis) {
398 return count;
399 } else {
400 if (card->discipline.ccwgdriver) {
401 card->discipline.ccwgdriver->remove(card->gdev);
402 qeth_core_free_discipline(card);
406 rc = qeth_core_load_discipline(card, newdis);
407 if (rc)
408 return rc;
410 rc = card->discipline.ccwgdriver->probe(card->gdev);
411 if (rc)
412 return rc;
413 return count;
416 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
417 qeth_dev_layer2_store);
419 static ssize_t qeth_dev_large_send_show(struct device *dev,
420 struct device_attribute *attr, char *buf)
422 struct qeth_card *card = dev_get_drvdata(dev);
424 if (!card)
425 return -EINVAL;
427 switch (card->options.large_send) {
428 case QETH_LARGE_SEND_NO:
429 return sprintf(buf, "%s\n", "no");
430 case QETH_LARGE_SEND_TSO:
431 return sprintf(buf, "%s\n", "TSO");
432 default:
433 return sprintf(buf, "%s\n", "N/A");
437 static ssize_t qeth_dev_large_send_store(struct device *dev,
438 struct device_attribute *attr, const char *buf, size_t count)
440 struct qeth_card *card = dev_get_drvdata(dev);
441 enum qeth_large_send_types type;
442 int rc = 0;
443 char *tmp;
445 if (!card)
446 return -EINVAL;
447 tmp = strsep((char **) &buf, "\n");
448 if (!strcmp(tmp, "no")) {
449 type = QETH_LARGE_SEND_NO;
450 } else if (!strcmp(tmp, "TSO")) {
451 type = QETH_LARGE_SEND_TSO;
452 } else {
453 return -EINVAL;
455 if (card->options.large_send == type)
456 return count;
457 rc = qeth_set_large_send(card, type);
458 if (rc)
459 return rc;
460 return count;
463 static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
464 qeth_dev_large_send_store);
466 static ssize_t qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value)
469 if (!card)
470 return -EINVAL;
472 return sprintf(buf, "%i\n", value);
475 static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
476 const char *buf, size_t count, int *value, int max_value)
478 char *tmp;
479 int i;
481 if (!card)
482 return -EINVAL;
484 if ((card->state != CARD_STATE_DOWN) &&
485 (card->state != CARD_STATE_RECOVER))
486 return -EPERM;
488 i = simple_strtoul(buf, &tmp, 10);
489 if (i <= max_value) {
490 *value = i;
491 } else {
492 return -EINVAL;
494 return count;
497 static ssize_t qeth_dev_blkt_total_show(struct device *dev,
498 struct device_attribute *attr, char *buf)
500 struct qeth_card *card = dev_get_drvdata(dev);
502 return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
505 static ssize_t qeth_dev_blkt_total_store(struct device *dev,
506 struct device_attribute *attr, const char *buf, size_t count)
508 struct qeth_card *card = dev_get_drvdata(dev);
510 return qeth_dev_blkt_store(card, buf, count,
511 &card->info.blkt.time_total, 1000);
516 static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
517 qeth_dev_blkt_total_store);
519 static ssize_t qeth_dev_blkt_inter_show(struct device *dev,
520 struct device_attribute *attr, char *buf)
522 struct qeth_card *card = dev_get_drvdata(dev);
524 return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
527 static ssize_t qeth_dev_blkt_inter_store(struct device *dev,
528 struct device_attribute *attr, const char *buf, size_t count)
530 struct qeth_card *card = dev_get_drvdata(dev);
532 return qeth_dev_blkt_store(card, buf, count,
533 &card->info.blkt.inter_packet, 100);
536 static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
537 qeth_dev_blkt_inter_store);
539 static ssize_t qeth_dev_blkt_inter_jumbo_show(struct device *dev,
540 struct device_attribute *attr, char *buf)
542 struct qeth_card *card = dev_get_drvdata(dev);
544 return qeth_dev_blkt_show(buf, card,
545 card->info.blkt.inter_packet_jumbo);
548 static ssize_t qeth_dev_blkt_inter_jumbo_store(struct device *dev,
549 struct device_attribute *attr, const char *buf, size_t count)
551 struct qeth_card *card = dev_get_drvdata(dev);
553 return qeth_dev_blkt_store(card, buf, count,
554 &card->info.blkt.inter_packet_jumbo, 100);
557 static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
558 qeth_dev_blkt_inter_jumbo_store);
560 static struct attribute *qeth_blkt_device_attrs[] = {
561 &dev_attr_total.attr,
562 &dev_attr_inter.attr,
563 &dev_attr_inter_jumbo.attr,
564 NULL,
567 static struct attribute_group qeth_device_blkt_group = {
568 .name = "blkt",
569 .attrs = qeth_blkt_device_attrs,
572 static struct attribute *qeth_device_attrs[] = {
573 &dev_attr_state.attr,
574 &dev_attr_chpid.attr,
575 &dev_attr_if_name.attr,
576 &dev_attr_card_type.attr,
577 &dev_attr_inbuf_size.attr,
578 &dev_attr_portno.attr,
579 &dev_attr_portname.attr,
580 &dev_attr_priority_queueing.attr,
581 &dev_attr_buffer_count.attr,
582 &dev_attr_recover.attr,
583 &dev_attr_performance_stats.attr,
584 &dev_attr_layer2.attr,
585 &dev_attr_large_send.attr,
586 NULL,
589 static struct attribute_group qeth_device_attr_group = {
590 .attrs = qeth_device_attrs,
593 static struct attribute *qeth_osn_device_attrs[] = {
594 &dev_attr_state.attr,
595 &dev_attr_chpid.attr,
596 &dev_attr_if_name.attr,
597 &dev_attr_card_type.attr,
598 &dev_attr_buffer_count.attr,
599 &dev_attr_recover.attr,
600 NULL,
603 static struct attribute_group qeth_osn_device_attr_group = {
604 .attrs = qeth_osn_device_attrs,
607 int qeth_core_create_device_attributes(struct device *dev)
609 int ret;
610 ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group);
611 if (ret)
612 return ret;
613 ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group);
614 if (ret)
615 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
617 return 0;
620 void qeth_core_remove_device_attributes(struct device *dev)
622 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
623 sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
626 int qeth_core_create_osn_attributes(struct device *dev)
628 return sysfs_create_group(&dev->kobj, &qeth_osn_device_attr_group);
631 void qeth_core_remove_osn_attributes(struct device *dev)
633 sysfs_remove_group(&dev->kobj, &qeth_osn_device_attr_group);
634 return;