Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/drivers/uwb/i1480/i1480u-wlp/sysfs.c (Version 2.6.31.13) and /linux/drivers/uwb/i1480/i1480u-wlp/sysfs.c (Version 2.6.11.8)


  1 /*                                                  1 
  2  * WUSB Wire Adapter: WLP interface               
  3  * Sysfs interfaces                               
  4  *                                                
  5  * Copyright (C) 2005-2006 Intel Corporation      
  6  * Inaky Perez-Gonzalez <inaky.perez-gonzalez@    
  7  *                                                
  8  * This program is free software; you can redi    
  9  * modify it under the terms of the GNU Genera    
 10  * 2 as published by the Free Software Foundat    
 11  *                                                
 12  * This program is distributed in the hope tha    
 13  * but WITHOUT ANY WARRANTY; without even the     
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR    
 15  * GNU General Public License for more details    
 16  *                                                
 17  * You should have received a copy of the GNU     
 18  * along with this program; if not, write to t    
 19  * Foundation, Inc., 51 Franklin Street, Fifth    
 20  * 02110-1301, USA.                               
 21  *                                                
 22  *                                                
 23  * FIXME: docs                                    
 24  */                                               
 25                                                   
 26 #include <linux/netdevice.h>                      
 27 #include <linux/etherdevice.h>                    
 28 #include <linux/device.h>                         
 29                                                   
 30 #include "i1480u-wlp.h"                           
 31                                                   
 32                                                   
 33 /**                                               
 34  *                                                
 35  * @dev: Class device from the net_device; ass    
 36  *                                                
 37  * Yes, I don't lock--we assume it is refcount    
 38  * single byte value that is kind of atomic to    
 39  */                                               
 40 ssize_t uwb_phy_rate_show(const struct wlp_opt    
 41 {                                                 
 42         return sprintf(buf, "%u\n",               
 43                        wlp_tx_hdr_phy_rate(&op    
 44 }                                                 
 45 EXPORT_SYMBOL_GPL(uwb_phy_rate_show);             
 46                                                   
 47                                                   
 48 ssize_t uwb_phy_rate_store(struct wlp_options     
 49                            const char *buf, si    
 50 {                                                 
 51         ssize_t result;                           
 52         unsigned rate;                            
 53                                                   
 54         result = sscanf(buf, "%u\n", &rate);      
 55         if (result != 1) {                        
 56                 result = -EINVAL;                 
 57                 goto out;                         
 58         }                                         
 59         result = -EINVAL;                         
 60         if (rate >= UWB_PHY_RATE_INVALID)         
 61                 goto out;                         
 62         wlp_tx_hdr_set_phy_rate(&options->def_    
 63         result = 0;                               
 64 out:                                              
 65         return result < 0 ? result : size;        
 66 }                                                 
 67 EXPORT_SYMBOL_GPL(uwb_phy_rate_store);            
 68                                                   
 69                                                   
 70 ssize_t uwb_rts_cts_show(const struct wlp_opti    
 71 {                                                 
 72         return sprintf(buf, "%u\n",               
 73                        wlp_tx_hdr_rts_cts(&opt    
 74 }                                                 
 75 EXPORT_SYMBOL_GPL(uwb_rts_cts_show);              
 76                                                   
 77                                                   
 78 ssize_t uwb_rts_cts_store(struct wlp_options *    
 79                           const char *buf, siz    
 80 {                                                 
 81         ssize_t result;                           
 82         unsigned value;                           
 83                                                   
 84         result = sscanf(buf, "%u\n", &value);     
 85         if (result != 1) {                        
 86                 result = -EINVAL;                 
 87                 goto out;                         
 88         }                                         
 89         result = -EINVAL;                         
 90         wlp_tx_hdr_set_rts_cts(&options->def_t    
 91         result = 0;                               
 92 out:                                              
 93         return result < 0 ? result : size;        
 94 }                                                 
 95 EXPORT_SYMBOL_GPL(uwb_rts_cts_store);             
 96                                                   
 97                                                   
 98 ssize_t uwb_ack_policy_show(const struct wlp_o    
 99 {                                                 
100         return sprintf(buf, "%u\n",               
101                        wlp_tx_hdr_ack_policy(&    
102 }                                                 
103 EXPORT_SYMBOL_GPL(uwb_ack_policy_show);           
104                                                   
105                                                   
106 ssize_t uwb_ack_policy_store(struct wlp_option    
107                              const char *buf,     
108 {                                                 
109         ssize_t result;                           
110         unsigned value;                           
111                                                   
112         result = sscanf(buf, "%u\n", &value);     
113         if (result != 1 || value > UWB_ACK_B_R    
114                 result = -EINVAL;                 
115                 goto out;                         
116         }                                         
117         wlp_tx_hdr_set_ack_policy(&options->de    
118         result = 0;                               
119 out:                                              
120         return result < 0 ? result : size;        
121 }                                                 
122 EXPORT_SYMBOL_GPL(uwb_ack_policy_store);          
123                                                   
124                                                   
125 /**                                               
126  * Show the PCA base priority.                    
127  *                                                
128  * We can access without locking, as the value    
129  * to other values.                               
130  */                                               
131 ssize_t uwb_pca_base_priority_show(const struc    
132                                    char *buf)     
133 {                                                 
134         return sprintf(buf, "%u\n",               
135                        options->pca_base_prior    
136 }                                                 
137 EXPORT_SYMBOL_GPL(uwb_pca_base_priority_show);    
138                                                   
139                                                   
140 /**                                               
141  * Set the PCA base priority.                     
142  *                                                
143  * We can access without locking, as the value    
144  * to other values.                               
145  */                                               
146 ssize_t uwb_pca_base_priority_store(struct wlp    
147                                     const char    
148 {                                                 
149         ssize_t result = -EINVAL;                 
150         u8 pca_base_priority;                     
151                                                   
152         result = sscanf(buf, "%hhu\n", &pca_ba    
153         if (result != 1) {                        
154                 result = -EINVAL;                 
155                 goto out;                         
156         }                                         
157         result = -EINVAL;                         
158         if (pca_base_priority >= 8)               
159                 goto out;                         
160         options->pca_base_priority = pca_base_    
161         /* Update TX header if we are currentl    
162         if (result >= 0 && (wlp_tx_hdr_deliver    
163                 wlp_tx_hdr_set_delivery_id_typ    
164         result = 0;                               
165 out:                                              
166         return result < 0 ? result : size;        
167 }                                                 
168 EXPORT_SYMBOL_GPL(uwb_pca_base_priority_store)    
169                                                   
170 /**                                               
171  * Show current inflight values                   
172  *                                                
173  * Will print the current MAX and THRESHOLD va    
174  * control. In addition it will report how man    
175  * to be restarted since the last time this qu    
176  */                                               
177 static ssize_t wlp_tx_inflight_show(struct i14    
178                                     char *buf)    
179 {                                                 
180         ssize_t result;                           
181         unsigned long sec_elapsed = (jiffies -    
182         unsigned long restart_count = atomic_r    
183                                                   
184         result = scnprintf(buf, PAGE_SIZE, "%l    
185                            "#read: threshold m    
186                            "seconds restarts/s    
187                            "#write: threshold     
188                            inflight->threshold    
189                            atomic_read(&inflig    
190                            restart_count, sec_    
191                            sec_elapsed == 0 ?     
192         inflight->restart_ts = jiffies;           
193         atomic_set(&inflight->restart_count, 0    
194         return result;                            
195 }                                                 
196                                                   
197 static                                            
198 ssize_t wlp_tx_inflight_store(struct i1480u_tx    
199                                 const char *bu    
200 {                                                 
201         unsigned long in_threshold, in_max;       
202         ssize_t result;                           
203         result = sscanf(buf, "%lu %lu", &in_th    
204         if (result != 2)                          
205                 return -EINVAL;                   
206         if (in_max <= in_threshold)               
207                 return -EINVAL;                   
208         inflight->max = in_max;                   
209         inflight->threshold = in_threshold;       
210         return size;                              
211 }                                                 
212 /*                                                
213  * Glue (or function adaptors) for accesing in    
214  *                                                
215  * [we need this indirection because the PCI d    
216  * same]                                          
217  *                                                
218  * Linux 2.6.21 changed how 'struct netdevice'    
219  * having a 'struct class_dev' to having a 'st    
220  * quite of a pain.                               
221  *                                                
222  * So we try to abstract that here. i1480u_SHO    
223  * create adaptors for extracting the 'struct     
224  * dev' and calling a function for doing a sys    
225  * them factorized already). i1480u_ATTR creat    
226  * (CLASS_DEVICE_ATTR or DEVICE_ATTR) and i148    
227  * class_device_attr_NAME or device_attr_NAME     
228  */                                               
229                                                   
230 #define i1480u_SHOW(name, fn, param)              
231 static ssize_t i1480u_show_##name(struct devic    
232                                   struct devic    
233                                   char *buf)      
234 {                                                 
235         struct i1480u *i1480u = netdev_priv(to    
236         return fn(&i1480u->param, buf);           
237 }                                                 
238                                                   
239 #define i1480u_STORE(name, fn, param)             
240 static ssize_t i1480u_store_##name(struct devi    
241                                    struct devi    
242                                    const char     
243 {                                                 
244         struct i1480u *i1480u = netdev_priv(to    
245         return fn(&i1480u->param, buf, size);     
246 }                                                 
247                                                   
248 #define i1480u_ATTR(name, perm) static DEVICE_    
249                                              i    
250                                              i    
251                                                   
252 #define i1480u_ATTR_SHOW(name) static DEVICE_A    
253                                         S_IRUG    
254                                         i1480u    
255                                                   
256 #define i1480u_ATTR_NAME(a) (dev_attr_##a)        
257                                                   
258                                                   
259 /*                                                
260  * Sysfs adaptors                                 
261  */                                               
262 i1480u_SHOW(uwb_phy_rate, uwb_phy_rate_show, o    
263 i1480u_STORE(uwb_phy_rate, uwb_phy_rate_store,    
264 i1480u_ATTR(uwb_phy_rate, S_IRUGO | S_IWUSR);     
265                                                   
266 i1480u_SHOW(uwb_rts_cts, uwb_rts_cts_show, opt    
267 i1480u_STORE(uwb_rts_cts, uwb_rts_cts_store, o    
268 i1480u_ATTR(uwb_rts_cts, S_IRUGO | S_IWUSR);      
269                                                   
270 i1480u_SHOW(uwb_ack_policy, uwb_ack_policy_sho    
271 i1480u_STORE(uwb_ack_policy, uwb_ack_policy_st    
272 i1480u_ATTR(uwb_ack_policy, S_IRUGO | S_IWUSR)    
273                                                   
274 i1480u_SHOW(uwb_pca_base_priority, uwb_pca_bas    
275 i1480u_STORE(uwb_pca_base_priority, uwb_pca_ba    
276 i1480u_ATTR(uwb_pca_base_priority, S_IRUGO | S    
277                                                   
278 i1480u_SHOW(wlp_eda, wlp_eda_show, wlp);          
279 i1480u_STORE(wlp_eda, wlp_eda_store, wlp);        
280 i1480u_ATTR(wlp_eda, S_IRUGO | S_IWUSR);          
281                                                   
282 i1480u_SHOW(wlp_uuid, wlp_uuid_show, wlp);        
283 i1480u_STORE(wlp_uuid, wlp_uuid_store, wlp);      
284 i1480u_ATTR(wlp_uuid, S_IRUGO | S_IWUSR);         
285                                                   
286 i1480u_SHOW(wlp_dev_name, wlp_dev_name_show, w    
287 i1480u_STORE(wlp_dev_name, wlp_dev_name_store,    
288 i1480u_ATTR(wlp_dev_name, S_IRUGO | S_IWUSR);     
289                                                   
290 i1480u_SHOW(wlp_dev_manufacturer, wlp_dev_manu    
291 i1480u_STORE(wlp_dev_manufacturer, wlp_dev_man    
292 i1480u_ATTR(wlp_dev_manufacturer, S_IRUGO | S_    
293                                                   
294 i1480u_SHOW(wlp_dev_model_name, wlp_dev_model_    
295 i1480u_STORE(wlp_dev_model_name, wlp_dev_model    
296 i1480u_ATTR(wlp_dev_model_name, S_IRUGO | S_IW    
297                                                   
298 i1480u_SHOW(wlp_dev_model_nr, wlp_dev_model_nr    
299 i1480u_STORE(wlp_dev_model_nr, wlp_dev_model_n    
300 i1480u_ATTR(wlp_dev_model_nr, S_IRUGO | S_IWUS    
301                                                   
302 i1480u_SHOW(wlp_dev_serial, wlp_dev_serial_sho    
303 i1480u_STORE(wlp_dev_serial, wlp_dev_serial_st    
304 i1480u_ATTR(wlp_dev_serial, S_IRUGO | S_IWUSR)    
305                                                   
306 i1480u_SHOW(wlp_dev_prim_category, wlp_dev_pri    
307 i1480u_STORE(wlp_dev_prim_category, wlp_dev_pr    
308 i1480u_ATTR(wlp_dev_prim_category, S_IRUGO | S    
309                                                   
310 i1480u_SHOW(wlp_dev_prim_OUI, wlp_dev_prim_OUI    
311 i1480u_STORE(wlp_dev_prim_OUI, wlp_dev_prim_OU    
312 i1480u_ATTR(wlp_dev_prim_OUI, S_IRUGO | S_IWUS    
313                                                   
314 i1480u_SHOW(wlp_dev_prim_OUI_sub, wlp_dev_prim    
315 i1480u_STORE(wlp_dev_prim_OUI_sub, wlp_dev_pri    
316 i1480u_ATTR(wlp_dev_prim_OUI_sub, S_IRUGO | S_    
317                                                   
318 i1480u_SHOW(wlp_dev_prim_subcat, wlp_dev_prim_    
319 i1480u_STORE(wlp_dev_prim_subcat, wlp_dev_prim    
320 i1480u_ATTR(wlp_dev_prim_subcat, S_IRUGO | S_I    
321                                                   
322 i1480u_SHOW(wlp_neighborhood, wlp_neighborhood    
323 i1480u_ATTR_SHOW(wlp_neighborhood);               
324                                                   
325 i1480u_SHOW(wss_activate, wlp_wss_activate_sho    
326 i1480u_STORE(wss_activate, wlp_wss_activate_st    
327 i1480u_ATTR(wss_activate, S_IRUGO | S_IWUSR);     
328                                                   
329 /*                                                
330  * Show the (min, max, avg) Line Quality Estim    
331  * the last 256 received WLP frames (ECMA-368     
332  *                                                
333  * [the -7dB that have to be substracted from     
334  * are already taken into account].               
335  */                                               
336 i1480u_SHOW(wlp_lqe, stats_show, lqe_stats);      
337 i1480u_STORE(wlp_lqe, stats_store, lqe_stats);    
338 i1480u_ATTR(wlp_lqe, S_IRUGO | S_IWUSR);          
339                                                   
340 /*                                                
341  * Show the Receive Signal Strength Indicator     
342  * received WLP frames (ECMA-368 13.3). Still     
343  * this value is, but is kind of a percentage     
344  * at the antenna.                                
345  */                                               
346 i1480u_SHOW(wlp_rssi, stats_show, rssi_stats);    
347 i1480u_STORE(wlp_rssi, stats_store, rssi_stats    
348 i1480u_ATTR(wlp_rssi, S_IRUGO | S_IWUSR);         
349                                                   
350 /**                                               
351  * We maintain a basic flow control counter. "    
352  * outstanding. Only allow "max"                  
353  * TX URBs to be outstanding. If this value is    
354  * stopped. The queue will be restarted when t    
355  * "threshold" URBs outstanding.                  
356  */                                               
357 i1480u_SHOW(wlp_tx_inflight, wlp_tx_inflight_s    
358 i1480u_STORE(wlp_tx_inflight, wlp_tx_inflight_    
359 i1480u_ATTR(wlp_tx_inflight, S_IRUGO | S_IWUSR    
360                                                   
361 static struct attribute *i1480u_attrs[] = {       
362         &i1480u_ATTR_NAME(uwb_phy_rate).attr,     
363         &i1480u_ATTR_NAME(uwb_rts_cts).attr,      
364         &i1480u_ATTR_NAME(uwb_ack_policy).attr    
365         &i1480u_ATTR_NAME(uwb_pca_base_priorit    
366         &i1480u_ATTR_NAME(wlp_lqe).attr,          
367         &i1480u_ATTR_NAME(wlp_rssi).attr,         
368         &i1480u_ATTR_NAME(wlp_eda).attr,          
369         &i1480u_ATTR_NAME(wlp_uuid).attr,         
370         &i1480u_ATTR_NAME(wlp_dev_name).attr,     
371         &i1480u_ATTR_NAME(wlp_dev_manufacturer    
372         &i1480u_ATTR_NAME(wlp_dev_model_name).    
373         &i1480u_ATTR_NAME(wlp_dev_model_nr).at    
374         &i1480u_ATTR_NAME(wlp_dev_serial).attr    
375         &i1480u_ATTR_NAME(wlp_dev_prim_categor    
376         &i1480u_ATTR_NAME(wlp_dev_prim_OUI).at    
377         &i1480u_ATTR_NAME(wlp_dev_prim_OUI_sub    
378         &i1480u_ATTR_NAME(wlp_dev_prim_subcat)    
379         &i1480u_ATTR_NAME(wlp_neighborhood).at    
380         &i1480u_ATTR_NAME(wss_activate).attr,     
381         &i1480u_ATTR_NAME(wlp_tx_inflight).att    
382         NULL,                                     
383 };                                                
384                                                   
385 static struct attribute_group i1480u_attr_grou    
386         .name = NULL,   /* we want them in the    
387         .attrs = i1480u_attrs,                    
388 };                                                
389                                                   
390 int i1480u_sysfs_setup(struct i1480u *i1480u)     
391 {                                                 
392         int result;                               
393         struct device *dev = &i1480u->usb_ifac    
394         result = sysfs_create_group(&i1480u->n    
395                                     &i1480u_at    
396         if (result < 0)                           
397                 dev_err(dev, "cannot initializ    
398                         result);                  
399         return result;                            
400 }                                                 
401                                                   
402                                                   
403 void i1480u_sysfs_release(struct i1480u *i1480    
404 {                                                 
405         sysfs_remove_group(&i1480u->net_dev->d    
406                            &i1480u_attr_group)    
407 }                                                 
408                                                   
  This page was automatically generated by the LXR engine.