4 * Utility definitions for configfs support in USB Ethernet functions
6 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
7 * http://www.samsung.com
9 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
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.
16 #ifndef __U_ETHER_CONFIGFS_H
17 #define __U_ETHER_CONFIGFS_H
19 #define USB_ETHERNET_CONFIGFS_ITEM(_f_) \
20 static void _f_##_attr_release(struct config_item *item) \
22 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
24 usb_put_function_instance(&opts->func_inst); \
27 static struct configfs_item_operations _f_##_item_ops = { \
28 .release = _f_##_attr_release, \
31 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(_f_) \
32 static ssize_t _f_##_opts_dev_addr_show(struct config_item *item, \
35 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
38 mutex_lock(&opts->lock); \
39 result = gether_get_dev_addr(opts->net, page, PAGE_SIZE); \
40 mutex_unlock(&opts->lock); \
45 static ssize_t _f_##_opts_dev_addr_store(struct config_item *item, \
46 const char *page, size_t len)\
48 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
51 mutex_lock(&opts->lock); \
53 mutex_unlock(&opts->lock); \
57 ret = gether_set_dev_addr(opts->net, page); \
58 mutex_unlock(&opts->lock); \
64 CONFIGFS_ATTR(_f_##_opts_, dev_addr)
66 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(_f_) \
67 static ssize_t _f_##_opts_host_addr_show(struct config_item *item, \
70 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
73 mutex_lock(&opts->lock); \
74 result = gether_get_host_addr(opts->net, page, PAGE_SIZE); \
75 mutex_unlock(&opts->lock); \
80 static ssize_t _f_##_opts_host_addr_store(struct config_item *item, \
81 const char *page, size_t len)\
83 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
86 mutex_lock(&opts->lock); \
88 mutex_unlock(&opts->lock); \
92 ret = gether_set_host_addr(opts->net, page); \
93 mutex_unlock(&opts->lock); \
99 CONFIGFS_ATTR(_f_##_opts_, host_addr)
101 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(_f_) \
102 static ssize_t _f_##_opts_qmult_show(struct config_item *item, \
105 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
108 mutex_lock(&opts->lock); \
109 qmult = gether_get_qmult(opts->net); \
110 mutex_unlock(&opts->lock); \
111 return sprintf(page, "%d", qmult); \
114 static ssize_t _f_##_opts_qmult_store(struct config_item *item, \
115 const char *page, size_t len)\
117 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
121 mutex_lock(&opts->lock); \
122 if (opts->refcnt) { \
127 ret = kstrtou8(page, 0, &val); \
131 gether_set_qmult(opts->net, val); \
134 mutex_unlock(&opts->lock); \
138 CONFIGFS_ATTR(_f_##_opts_, qmult)
140 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(_f_) \
141 static ssize_t _f_##_opts_ifname_show(struct config_item *item, \
144 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
147 mutex_lock(&opts->lock); \
148 ret = gether_get_ifname(opts->net, page, PAGE_SIZE); \
149 mutex_unlock(&opts->lock); \
154 CONFIGFS_ATTR_RO(_f_##_opts_, ifname)
156 #endif /* __U_ETHER_CONFIGFS_H */