xref: /openbmc/linux/drivers/s390/net/qeth_core_sys.c (revision 9fb29c73)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *    Copyright IBM Corp. 2007
4  *    Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5  *		 Frank Pavlic <fpavlic@de.ibm.com>,
6  *		 Thomas Spatzier <tspat@de.ibm.com>,
7  *		 Frank Blaschka <frank.blaschka@de.ibm.com>
8  */
9 
10 #define KMSG_COMPONENT "qeth"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 
13 #include <linux/list.h>
14 #include <linux/rwsem.h>
15 #include <asm/ebcdic.h>
16 
17 #include "qeth_core.h"
18 
19 static ssize_t qeth_dev_state_show(struct device *dev,
20 				struct device_attribute *attr, char *buf)
21 {
22 	struct qeth_card *card = dev_get_drvdata(dev);
23 	if (!card)
24 		return -EINVAL;
25 
26 	switch (card->state) {
27 	case CARD_STATE_DOWN:
28 		return sprintf(buf, "DOWN\n");
29 	case CARD_STATE_HARDSETUP:
30 		return sprintf(buf, "HARDSETUP\n");
31 	case CARD_STATE_SOFTSETUP:
32 		return sprintf(buf, "SOFTSETUP\n");
33 	case CARD_STATE_UP:
34 		return sprintf(buf, "UP (LAN %s)\n",
35 			       netif_carrier_ok(card->dev) ? "ONLINE" :
36 							     "OFFLINE");
37 	case CARD_STATE_RECOVER:
38 		return sprintf(buf, "RECOVER\n");
39 	default:
40 		return sprintf(buf, "UNKNOWN\n");
41 	}
42 }
43 
44 static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
45 
46 static ssize_t qeth_dev_chpid_show(struct device *dev,
47 				struct device_attribute *attr, char *buf)
48 {
49 	struct qeth_card *card = dev_get_drvdata(dev);
50 	if (!card)
51 		return -EINVAL;
52 
53 	return sprintf(buf, "%02X\n", card->info.chpid);
54 }
55 
56 static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
57 
58 static ssize_t qeth_dev_if_name_show(struct device *dev,
59 				struct device_attribute *attr, char *buf)
60 {
61 	struct qeth_card *card = dev_get_drvdata(dev);
62 	if (!card)
63 		return -EINVAL;
64 	return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
65 }
66 
67 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
68 
69 static ssize_t qeth_dev_card_type_show(struct device *dev,
70 				struct device_attribute *attr, char *buf)
71 {
72 	struct qeth_card *card = dev_get_drvdata(dev);
73 	if (!card)
74 		return -EINVAL;
75 
76 	return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
77 }
78 
79 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
80 
81 static const char *qeth_get_bufsize_str(struct qeth_card *card)
82 {
83 	if (card->qdio.in_buf_size == 16384)
84 		return "16k";
85 	else if (card->qdio.in_buf_size == 24576)
86 		return "24k";
87 	else if (card->qdio.in_buf_size == 32768)
88 		return "32k";
89 	else if (card->qdio.in_buf_size == 40960)
90 		return "40k";
91 	else
92 		return "64k";
93 }
94 
95 static ssize_t qeth_dev_inbuf_size_show(struct device *dev,
96 				struct device_attribute *attr, char *buf)
97 {
98 	struct qeth_card *card = dev_get_drvdata(dev);
99 	if (!card)
100 		return -EINVAL;
101 
102 	return sprintf(buf, "%s\n", qeth_get_bufsize_str(card));
103 }
104 
105 static DEVICE_ATTR(inbuf_size, 0444, qeth_dev_inbuf_size_show, NULL);
106 
107 static ssize_t qeth_dev_portno_show(struct device *dev,
108 			struct device_attribute *attr, char *buf)
109 {
110 	struct qeth_card *card = dev_get_drvdata(dev);
111 	if (!card)
112 		return -EINVAL;
113 
114 	return sprintf(buf, "%i\n", card->dev->dev_port);
115 }
116 
117 static ssize_t qeth_dev_portno_store(struct device *dev,
118 		struct device_attribute *attr, const char *buf, size_t count)
119 {
120 	struct qeth_card *card = dev_get_drvdata(dev);
121 	char *tmp;
122 	unsigned int portno, limit;
123 	int rc = 0;
124 
125 	if (!card)
126 		return -EINVAL;
127 
128 	mutex_lock(&card->conf_mutex);
129 	if ((card->state != CARD_STATE_DOWN) &&
130 	    (card->state != CARD_STATE_RECOVER)) {
131 		rc = -EPERM;
132 		goto out;
133 	}
134 
135 	portno = simple_strtoul(buf, &tmp, 16);
136 	if (portno > QETH_MAX_PORTNO) {
137 		rc = -EINVAL;
138 		goto out;
139 	}
140 	limit = (card->ssqd.pcnt ? card->ssqd.pcnt - 1 : card->ssqd.pcnt);
141 	if (portno > limit) {
142 		rc = -EINVAL;
143 		goto out;
144 	}
145 	card->dev->dev_port = portno;
146 out:
147 	mutex_unlock(&card->conf_mutex);
148 	return rc ? rc : count;
149 }
150 
151 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
152 
153 static ssize_t qeth_dev_portname_show(struct device *dev,
154 				struct device_attribute *attr, char *buf)
155 {
156 	return sprintf(buf, "no portname required\n");
157 }
158 
159 static ssize_t qeth_dev_portname_store(struct device *dev,
160 		struct device_attribute *attr, const char *buf, size_t count)
161 {
162 	struct qeth_card *card = dev_get_drvdata(dev);
163 
164 	dev_warn_once(&card->gdev->dev,
165 		      "portname is deprecated and is ignored\n");
166 	return count;
167 }
168 
169 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
170 		qeth_dev_portname_store);
171 
172 static ssize_t qeth_dev_prioqing_show(struct device *dev,
173 				struct device_attribute *attr, char *buf)
174 {
175 	struct qeth_card *card = dev_get_drvdata(dev);
176 
177 	if (!card)
178 		return -EINVAL;
179 
180 	switch (card->qdio.do_prio_queueing) {
181 	case QETH_PRIO_Q_ING_PREC:
182 		return sprintf(buf, "%s\n", "by precedence");
183 	case QETH_PRIO_Q_ING_TOS:
184 		return sprintf(buf, "%s\n", "by type of service");
185 	case QETH_PRIO_Q_ING_SKB:
186 		return sprintf(buf, "%s\n", "by skb-priority");
187 	case QETH_PRIO_Q_ING_VLAN:
188 		return sprintf(buf, "%s\n", "by VLAN headers");
189 	default:
190 		return sprintf(buf, "always queue %i\n",
191 			       card->qdio.default_out_queue);
192 	}
193 }
194 
195 static ssize_t qeth_dev_prioqing_store(struct device *dev,
196 		struct device_attribute *attr, const char *buf, size_t count)
197 {
198 	struct qeth_card *card = dev_get_drvdata(dev);
199 	int rc = 0;
200 
201 	if (!card)
202 		return -EINVAL;
203 
204 	mutex_lock(&card->conf_mutex);
205 	if ((card->state != CARD_STATE_DOWN) &&
206 	    (card->state != CARD_STATE_RECOVER)) {
207 		rc = -EPERM;
208 		goto out;
209 	}
210 
211 	/* check if 1920 devices are supported ,
212 	 * if though we have to permit priority queueing
213 	 */
214 	if (card->qdio.no_out_queues == 1) {
215 		card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
216 		rc = -EPERM;
217 		goto out;
218 	}
219 
220 	if (sysfs_streq(buf, "prio_queueing_prec")) {
221 		card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
222 		card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
223 	} else if (sysfs_streq(buf, "prio_queueing_skb")) {
224 		card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_SKB;
225 		card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
226 	} else if (sysfs_streq(buf, "prio_queueing_tos")) {
227 		card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
228 		card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
229 	} else if (sysfs_streq(buf, "prio_queueing_vlan")) {
230 		if (IS_LAYER3(card)) {
231 			rc = -ENOTSUPP;
232 			goto out;
233 		}
234 		card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_VLAN;
235 		card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
236 	} else if (sysfs_streq(buf, "no_prio_queueing:0")) {
237 		card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
238 		card->qdio.default_out_queue = 0;
239 	} else if (sysfs_streq(buf, "no_prio_queueing:1")) {
240 		card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
241 		card->qdio.default_out_queue = 1;
242 	} else if (sysfs_streq(buf, "no_prio_queueing:2")) {
243 		card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
244 		card->qdio.default_out_queue = 2;
245 	} else if (sysfs_streq(buf, "no_prio_queueing:3")) {
246 		if (card->info.type == QETH_CARD_TYPE_IQD) {
247 			rc = -EPERM;
248 			goto out;
249 		}
250 		card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
251 		card->qdio.default_out_queue = 3;
252 	} else if (sysfs_streq(buf, "no_prio_queueing")) {
253 		card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
254 		card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
255 	} else
256 		rc = -EINVAL;
257 out:
258 	mutex_unlock(&card->conf_mutex);
259 	return rc ? rc : count;
260 }
261 
262 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
263 		qeth_dev_prioqing_store);
264 
265 static ssize_t qeth_dev_bufcnt_show(struct device *dev,
266 				struct device_attribute *attr, char *buf)
267 {
268 	struct qeth_card *card = dev_get_drvdata(dev);
269 
270 	if (!card)
271 		return -EINVAL;
272 
273 	return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
274 }
275 
276 static ssize_t qeth_dev_bufcnt_store(struct device *dev,
277 		struct device_attribute *attr, const char *buf, size_t count)
278 {
279 	struct qeth_card *card = dev_get_drvdata(dev);
280 	char *tmp;
281 	int cnt, old_cnt;
282 	int rc = 0;
283 
284 	if (!card)
285 		return -EINVAL;
286 
287 	mutex_lock(&card->conf_mutex);
288 	if ((card->state != CARD_STATE_DOWN) &&
289 	    (card->state != CARD_STATE_RECOVER)) {
290 		rc = -EPERM;
291 		goto out;
292 	}
293 
294 	old_cnt = card->qdio.in_buf_pool.buf_count;
295 	cnt = simple_strtoul(buf, &tmp, 10);
296 	cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
297 		((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
298 	if (old_cnt != cnt) {
299 		rc = qeth_realloc_buffer_pool(card, cnt);
300 	}
301 out:
302 	mutex_unlock(&card->conf_mutex);
303 	return rc ? rc : count;
304 }
305 
306 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
307 		qeth_dev_bufcnt_store);
308 
309 static ssize_t qeth_dev_recover_store(struct device *dev,
310 		struct device_attribute *attr, const char *buf, size_t count)
311 {
312 	struct qeth_card *card = dev_get_drvdata(dev);
313 	char *tmp;
314 	int i;
315 
316 	if (!card)
317 		return -EINVAL;
318 
319 	if (card->state != CARD_STATE_UP)
320 		return -EPERM;
321 
322 	i = simple_strtoul(buf, &tmp, 16);
323 	if (i == 1)
324 		qeth_schedule_recovery(card);
325 
326 	return count;
327 }
328 
329 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
330 
331 static ssize_t qeth_dev_performance_stats_show(struct device *dev,
332 				struct device_attribute *attr, char *buf)
333 {
334 	struct qeth_card *card = dev_get_drvdata(dev);
335 
336 	if (!card)
337 		return -EINVAL;
338 
339 	return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
340 }
341 
342 static ssize_t qeth_dev_performance_stats_store(struct device *dev,
343 		struct device_attribute *attr, const char *buf, size_t count)
344 {
345 	struct qeth_card *card = dev_get_drvdata(dev);
346 	char *tmp;
347 	int i, rc = 0;
348 
349 	if (!card)
350 		return -EINVAL;
351 
352 	mutex_lock(&card->conf_mutex);
353 	i = simple_strtoul(buf, &tmp, 16);
354 	if ((i == 0) || (i == 1)) {
355 		if (i == card->options.performance_stats)
356 			goto out;
357 		card->options.performance_stats = i;
358 		if (i == 0)
359 			memset(&card->perf_stats, 0,
360 				sizeof(struct qeth_perf_stats));
361 		card->perf_stats.initial_rx_packets = card->stats.rx_packets;
362 		card->perf_stats.initial_tx_packets = card->stats.tx_packets;
363 	} else
364 		rc = -EINVAL;
365 out:
366 	mutex_unlock(&card->conf_mutex);
367 	return rc ? rc : count;
368 }
369 
370 static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
371 		   qeth_dev_performance_stats_store);
372 
373 static ssize_t qeth_dev_layer2_show(struct device *dev,
374 		struct device_attribute *attr, char *buf)
375 {
376 	struct qeth_card *card = dev_get_drvdata(dev);
377 
378 	if (!card)
379 		return -EINVAL;
380 
381 	return sprintf(buf, "%i\n", card->options.layer);
382 }
383 
384 static ssize_t qeth_dev_layer2_store(struct device *dev,
385 		struct device_attribute *attr, const char *buf, size_t count)
386 {
387 	struct qeth_card *card = dev_get_drvdata(dev);
388 	struct net_device *ndev;
389 	char *tmp;
390 	int i, rc = 0;
391 	enum qeth_discipline_id newdis;
392 
393 	if (!card)
394 		return -EINVAL;
395 
396 	mutex_lock(&card->discipline_mutex);
397 	if (card->state != CARD_STATE_DOWN) {
398 		rc = -EPERM;
399 		goto out;
400 	}
401 
402 	i = simple_strtoul(buf, &tmp, 16);
403 	switch (i) {
404 	case 0:
405 		newdis = QETH_DISCIPLINE_LAYER3;
406 		break;
407 	case 1:
408 		newdis = QETH_DISCIPLINE_LAYER2;
409 		break;
410 	default:
411 		rc = -EINVAL;
412 		goto out;
413 	}
414 
415 	if (card->options.layer == newdis)
416 		goto out;
417 	if (card->info.layer_enforced) {
418 		/* fixed layer, can't switch */
419 		rc = -EOPNOTSUPP;
420 		goto out;
421 	}
422 
423 	card->info.mac_bits = 0;
424 	if (card->discipline) {
425 		/* start with a new, pristine netdevice: */
426 		ndev = qeth_clone_netdev(card->dev);
427 		if (!ndev) {
428 			rc = -ENOMEM;
429 			goto out;
430 		}
431 
432 		card->discipline->remove(card->gdev);
433 		qeth_core_free_discipline(card);
434 		free_netdev(card->dev);
435 		card->dev = ndev;
436 	}
437 
438 	rc = qeth_core_load_discipline(card, newdis);
439 	if (rc)
440 		goto out;
441 
442 	rc = card->discipline->setup(card->gdev);
443 	if (rc)
444 		qeth_core_free_discipline(card);
445 out:
446 	mutex_unlock(&card->discipline_mutex);
447 	return rc ? rc : count;
448 }
449 
450 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
451 		   qeth_dev_layer2_store);
452 
453 #define ATTR_QETH_ISOLATION_NONE	("none")
454 #define ATTR_QETH_ISOLATION_FWD		("forward")
455 #define ATTR_QETH_ISOLATION_DROP	("drop")
456 
457 static ssize_t qeth_dev_isolation_show(struct device *dev,
458 				struct device_attribute *attr, char *buf)
459 {
460 	struct qeth_card *card = dev_get_drvdata(dev);
461 
462 	if (!card)
463 		return -EINVAL;
464 
465 	switch (card->options.isolation) {
466 	case ISOLATION_MODE_NONE:
467 		return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_NONE);
468 	case ISOLATION_MODE_FWD:
469 		return snprintf(buf, 9, "%s\n", ATTR_QETH_ISOLATION_FWD);
470 	case ISOLATION_MODE_DROP:
471 		return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_DROP);
472 	default:
473 		return snprintf(buf, 5, "%s\n", "N/A");
474 	}
475 }
476 
477 static ssize_t qeth_dev_isolation_store(struct device *dev,
478 		struct device_attribute *attr, const char *buf, size_t count)
479 {
480 	struct qeth_card *card = dev_get_drvdata(dev);
481 	enum qeth_ipa_isolation_modes isolation;
482 	int rc = 0;
483 
484 	if (!card)
485 		return -EINVAL;
486 
487 	mutex_lock(&card->conf_mutex);
488 	if (card->info.type != QETH_CARD_TYPE_OSD &&
489 	    card->info.type != QETH_CARD_TYPE_OSX) {
490 		rc = -EOPNOTSUPP;
491 		dev_err(&card->gdev->dev, "Adapter does not "
492 			"support QDIO data connection isolation\n");
493 		goto out;
494 	}
495 
496 	/* parse input into isolation mode */
497 	if (sysfs_streq(buf, ATTR_QETH_ISOLATION_NONE)) {
498 		isolation = ISOLATION_MODE_NONE;
499 	} else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_FWD)) {
500 		isolation = ISOLATION_MODE_FWD;
501 	} else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_DROP)) {
502 		isolation = ISOLATION_MODE_DROP;
503 	} else {
504 		rc = -EINVAL;
505 		goto out;
506 	}
507 	rc = count;
508 
509 	/* defer IP assist if device is offline (until discipline->set_online)*/
510 	card->options.prev_isolation = card->options.isolation;
511 	card->options.isolation = isolation;
512 	if (qeth_card_hw_is_reachable(card)) {
513 		int ipa_rc = qeth_set_access_ctrl_online(card, 1);
514 		if (ipa_rc != 0)
515 			rc = ipa_rc;
516 	}
517 out:
518 	mutex_unlock(&card->conf_mutex);
519 	return rc;
520 }
521 
522 static DEVICE_ATTR(isolation, 0644, qeth_dev_isolation_show,
523 			qeth_dev_isolation_store);
524 
525 static ssize_t qeth_dev_switch_attrs_show(struct device *dev,
526 				struct device_attribute *attr, char *buf)
527 {
528 	struct qeth_card *card = dev_get_drvdata(dev);
529 	struct qeth_switch_info sw_info;
530 	int	rc = 0;
531 
532 	if (!card)
533 		return -EINVAL;
534 
535 	if (!qeth_card_hw_is_reachable(card))
536 		return sprintf(buf, "n/a\n");
537 
538 	rc = qeth_query_switch_attributes(card, &sw_info);
539 	if (rc)
540 		return rc;
541 
542 	if (!sw_info.capabilities)
543 		rc = sprintf(buf, "unknown");
544 
545 	if (sw_info.capabilities & QETH_SWITCH_FORW_802_1)
546 		rc = sprintf(buf, (sw_info.settings & QETH_SWITCH_FORW_802_1 ?
547 							"[802.1]" : "802.1"));
548 	if (sw_info.capabilities & QETH_SWITCH_FORW_REFL_RELAY)
549 		rc += sprintf(buf + rc,
550 			(sw_info.settings & QETH_SWITCH_FORW_REFL_RELAY ?
551 							" [rr]" : " rr"));
552 	rc += sprintf(buf + rc, "\n");
553 
554 	return rc;
555 }
556 
557 static DEVICE_ATTR(switch_attrs, 0444,
558 		   qeth_dev_switch_attrs_show, NULL);
559 
560 static ssize_t qeth_hw_trap_show(struct device *dev,
561 				struct device_attribute *attr, char *buf)
562 {
563 	struct qeth_card *card = dev_get_drvdata(dev);
564 
565 	if (!card)
566 		return -EINVAL;
567 	if (card->info.hwtrap)
568 		return snprintf(buf, 5, "arm\n");
569 	else
570 		return snprintf(buf, 8, "disarm\n");
571 }
572 
573 static ssize_t qeth_hw_trap_store(struct device *dev,
574 		struct device_attribute *attr, const char *buf, size_t count)
575 {
576 	struct qeth_card *card = dev_get_drvdata(dev);
577 	int rc = 0;
578 	int state = 0;
579 
580 	if (!card)
581 		return -EINVAL;
582 
583 	mutex_lock(&card->conf_mutex);
584 	if (qeth_card_hw_is_reachable(card))
585 		state = 1;
586 
587 	if (sysfs_streq(buf, "arm") && !card->info.hwtrap) {
588 		if (state) {
589 			if (qeth_is_diagass_supported(card,
590 			    QETH_DIAGS_CMD_TRAP)) {
591 				rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM);
592 				if (!rc)
593 					card->info.hwtrap = 1;
594 			} else
595 				rc = -EINVAL;
596 		} else
597 			card->info.hwtrap = 1;
598 	} else if (sysfs_streq(buf, "disarm") && card->info.hwtrap) {
599 		if (state) {
600 			rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
601 			if (!rc)
602 				card->info.hwtrap = 0;
603 		} else
604 			card->info.hwtrap = 0;
605 	} else if (sysfs_streq(buf, "trap") && state && card->info.hwtrap)
606 		rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_CAPTURE);
607 	else
608 		rc = -EINVAL;
609 
610 	mutex_unlock(&card->conf_mutex);
611 	return rc ? rc : count;
612 }
613 
614 static DEVICE_ATTR(hw_trap, 0644, qeth_hw_trap_show,
615 		   qeth_hw_trap_store);
616 
617 static ssize_t qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value)
618 {
619 
620 	if (!card)
621 		return -EINVAL;
622 
623 	return sprintf(buf, "%i\n", value);
624 }
625 
626 static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
627 		const char *buf, size_t count, int *value, int max_value)
628 {
629 	char *tmp;
630 	int i, rc = 0;
631 
632 	if (!card)
633 		return -EINVAL;
634 
635 	mutex_lock(&card->conf_mutex);
636 	if ((card->state != CARD_STATE_DOWN) &&
637 	    (card->state != CARD_STATE_RECOVER)) {
638 		rc = -EPERM;
639 		goto out;
640 	}
641 	i = simple_strtoul(buf, &tmp, 10);
642 	if (i <= max_value)
643 		*value = i;
644 	else
645 		rc = -EINVAL;
646 out:
647 	mutex_unlock(&card->conf_mutex);
648 	return rc ? rc : count;
649 }
650 
651 static ssize_t qeth_dev_blkt_total_show(struct device *dev,
652 				struct device_attribute *attr, char *buf)
653 {
654 	struct qeth_card *card = dev_get_drvdata(dev);
655 
656 	return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
657 }
658 
659 static ssize_t qeth_dev_blkt_total_store(struct device *dev,
660 		struct device_attribute *attr, const char *buf, size_t count)
661 {
662 	struct qeth_card *card = dev_get_drvdata(dev);
663 
664 	return qeth_dev_blkt_store(card, buf, count,
665 				   &card->info.blkt.time_total, 5000);
666 }
667 
668 
669 
670 static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
671 		   qeth_dev_blkt_total_store);
672 
673 static ssize_t qeth_dev_blkt_inter_show(struct device *dev,
674 				struct device_attribute *attr, char *buf)
675 {
676 	struct qeth_card *card = dev_get_drvdata(dev);
677 
678 	return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
679 }
680 
681 static ssize_t qeth_dev_blkt_inter_store(struct device *dev,
682 		struct device_attribute *attr, const char *buf, size_t count)
683 {
684 	struct qeth_card *card = dev_get_drvdata(dev);
685 
686 	return qeth_dev_blkt_store(card, buf, count,
687 				   &card->info.blkt.inter_packet, 1000);
688 }
689 
690 static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
691 		   qeth_dev_blkt_inter_store);
692 
693 static ssize_t qeth_dev_blkt_inter_jumbo_show(struct device *dev,
694 				struct device_attribute *attr, char *buf)
695 {
696 	struct qeth_card *card = dev_get_drvdata(dev);
697 
698 	return qeth_dev_blkt_show(buf, card,
699 				  card->info.blkt.inter_packet_jumbo);
700 }
701 
702 static ssize_t qeth_dev_blkt_inter_jumbo_store(struct device *dev,
703 		struct device_attribute *attr, const char *buf, size_t count)
704 {
705 	struct qeth_card *card = dev_get_drvdata(dev);
706 
707 	return qeth_dev_blkt_store(card, buf, count,
708 				   &card->info.blkt.inter_packet_jumbo, 1000);
709 }
710 
711 static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
712 		   qeth_dev_blkt_inter_jumbo_store);
713 
714 static struct attribute *qeth_blkt_device_attrs[] = {
715 	&dev_attr_total.attr,
716 	&dev_attr_inter.attr,
717 	&dev_attr_inter_jumbo.attr,
718 	NULL,
719 };
720 const struct attribute_group qeth_device_blkt_group = {
721 	.name = "blkt",
722 	.attrs = qeth_blkt_device_attrs,
723 };
724 EXPORT_SYMBOL_GPL(qeth_device_blkt_group);
725 
726 static struct attribute *qeth_device_attrs[] = {
727 	&dev_attr_state.attr,
728 	&dev_attr_chpid.attr,
729 	&dev_attr_if_name.attr,
730 	&dev_attr_card_type.attr,
731 	&dev_attr_inbuf_size.attr,
732 	&dev_attr_portno.attr,
733 	&dev_attr_portname.attr,
734 	&dev_attr_priority_queueing.attr,
735 	&dev_attr_buffer_count.attr,
736 	&dev_attr_recover.attr,
737 	&dev_attr_performance_stats.attr,
738 	&dev_attr_layer2.attr,
739 	&dev_attr_isolation.attr,
740 	&dev_attr_hw_trap.attr,
741 	&dev_attr_switch_attrs.attr,
742 	NULL,
743 };
744 const struct attribute_group qeth_device_attr_group = {
745 	.attrs = qeth_device_attrs,
746 };
747 EXPORT_SYMBOL_GPL(qeth_device_attr_group);
748 
749 const struct attribute_group *qeth_generic_attr_groups[] = {
750 	&qeth_device_attr_group,
751 	&qeth_device_blkt_group,
752 	NULL,
753 };
754 
755 static struct attribute *qeth_osn_device_attrs[] = {
756 	&dev_attr_state.attr,
757 	&dev_attr_chpid.attr,
758 	&dev_attr_if_name.attr,
759 	&dev_attr_card_type.attr,
760 	&dev_attr_buffer_count.attr,
761 	&dev_attr_recover.attr,
762 	NULL,
763 };
764 static struct attribute_group qeth_osn_device_attr_group = {
765 	.attrs = qeth_osn_device_attrs,
766 };
767 const struct attribute_group *qeth_osn_attr_groups[] = {
768 	&qeth_osn_device_attr_group,
769 	NULL,
770 };
771