blob: 4f47289fcf7cee45e93e8f9171a19390f91ee49f [file] [log] [blame]
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +02001/*
2 * u_ether_configfs.h
3 *
4 * Utility definitions for configfs support in USB Ethernet functions
5 *
6 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
7 * http://www.samsung.com
8 *
9 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#ifndef __U_ETHER_CONFIGFS_H
17#define __U_ETHER_CONFIGFS_H
18
19#define USB_ETHERNET_CONFIGFS_ITEM(_f_) \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020020 static void _f_##_attr_release(struct config_item *item) \
21 { \
22 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
23 \
24 usb_put_function_instance(&opts->func_inst); \
25 } \
26 \
27 static struct configfs_item_operations _f_##_item_ops = { \
28 .release = _f_##_attr_release, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020029 }
30
31#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(_f_) \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020032 static ssize_t _f_##_opts_dev_addr_show(struct config_item *item, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020033 char *page) \
34 { \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020035 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020036 int result; \
37 \
38 mutex_lock(&opts->lock); \
39 result = gether_get_dev_addr(opts->net, page, PAGE_SIZE); \
40 mutex_unlock(&opts->lock); \
41 \
42 return result; \
43 } \
44 \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020045 static ssize_t _f_##_opts_dev_addr_store(struct config_item *item, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020046 const char *page, size_t len)\
47 { \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020048 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020049 int ret; \
50 \
51 mutex_lock(&opts->lock); \
52 if (opts->refcnt) { \
53 mutex_unlock(&opts->lock); \
54 return -EBUSY; \
55 } \
56 \
57 ret = gether_set_dev_addr(opts->net, page); \
58 mutex_unlock(&opts->lock); \
59 if (!ret) \
60 ret = len; \
61 return ret; \
62 } \
63 \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020064 CONFIGFS_ATTR(_f_##_opts_, dev_addr)
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020065
66#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(_f_) \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020067 static ssize_t _f_##_opts_host_addr_show(struct config_item *item, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020068 char *page) \
69 { \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020070 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020071 int result; \
72 \
73 mutex_lock(&opts->lock); \
74 result = gether_get_host_addr(opts->net, page, PAGE_SIZE); \
75 mutex_unlock(&opts->lock); \
76 \
77 return result; \
78 } \
79 \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020080 static ssize_t _f_##_opts_host_addr_store(struct config_item *item, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020081 const char *page, size_t len)\
82 { \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020083 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +020084 int ret; \
85 \
86 mutex_lock(&opts->lock); \
87 if (opts->refcnt) { \
88 mutex_unlock(&opts->lock); \
89 return -EBUSY; \
90 } \
91 \
92 ret = gether_set_host_addr(opts->net, page); \
93 mutex_unlock(&opts->lock); \
94 if (!ret) \
95 ret = len; \
96 return ret; \
97 } \
98 \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +020099 CONFIGFS_ATTR(_f_##_opts_, host_addr)
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200100
101#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(_f_) \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200102 static ssize_t _f_##_opts_qmult_show(struct config_item *item, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200103 char *page) \
104 { \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200105 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200106 unsigned qmult; \
107 \
108 mutex_lock(&opts->lock); \
109 qmult = gether_get_qmult(opts->net); \
110 mutex_unlock(&opts->lock); \
111 return sprintf(page, "%d", qmult); \
112 } \
113 \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200114 static ssize_t _f_##_opts_qmult_store(struct config_item *item, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200115 const char *page, size_t len)\
116 { \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200117 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200118 u8 val; \
119 int ret; \
120 \
121 mutex_lock(&opts->lock); \
122 if (opts->refcnt) { \
123 ret = -EBUSY; \
124 goto out; \
125 } \
126 \
127 ret = kstrtou8(page, 0, &val); \
128 if (ret) \
129 goto out; \
130 \
131 gether_set_qmult(opts->net, val); \
132 ret = len; \
133out: \
134 mutex_unlock(&opts->lock); \
135 return ret; \
136 } \
137 \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200138 CONFIGFS_ATTR(_f_##_opts_, qmult)
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200139
140#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(_f_) \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200141 static ssize_t _f_##_opts_ifname_show(struct config_item *item, \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200142 char *page) \
143 { \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200144 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200145 int ret; \
146 \
147 mutex_lock(&opts->lock); \
148 ret = gether_get_ifname(opts->net, page, PAGE_SIZE); \
149 mutex_unlock(&opts->lock); \
150 \
151 return ret; \
152 } \
153 \
Christoph Hellwigf9a63da2015-10-03 15:32:42 +0200154 CONFIGFS_ATTR_RO(_f_##_opts_, ifname)
Andrzej Pietrasiewiczaa83c6a2013-05-23 10:32:02 +0200155
156#endif /* __U_ETHER_CONFIGFS_H */