[REFACTOR] rename sspt_procs* --> sspt_proc*
[kernel/swap-modules.git] / driver / device_driver.c
1 ////////////////////////////////////////////////////////////////////////////////////
2 //
3 //      FILE:           device_driver.c
4 //
5 //      DESCRIPTION:
6 //      This file is C source for SWAP driver.
7 //
8 //      SEE ALSO:       device_driver.h
9 //      AUTHOR:         L.Komkov, S.Dianov, S.Grekhov, A.Gerenkov
10 //      COMPANY NAME:   Samsung Research Center in Moscow
11 //      DEPT NAME:      Advanced Software Group
12 //      CREATED:        2008.02.15
13 //      VERSION:        1.0
14 //      REVISION DATE:  2008.12.03
15 //
16 ////////////////////////////////////////////////////////////////////////////////////
17
18 #include "module.h"
19 #include "device_driver.h"      // device driver
20 #include "handlers_core.h"
21 #include <linux/notifier.h>
22 #include "sspt/sspt_proc.h"
23
24 #ifdef OVERHEAD_DEBUG
25 extern unsigned long swap_sum_time;
26 extern unsigned long swap_sum_hit;
27 #endif
28
29
30 extern unsigned long imi_sum_time;
31 extern unsigned long imi_sum_hit;
32
33
34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
35 static BLOCKING_NOTIFIER_HEAD(swap_notifier_list);
36 #endif
37 pid_t gl_nNotifyTgid;
38 EXPORT_SYMBOL_GPL(gl_nNotifyTgid);
39
40 static DECLARE_WAIT_QUEUE_HEAD (notification_waiters_queue);
41 static volatile unsigned notification_count;
42
43 static int device_mmap (struct file *filp, struct vm_area_struct *vma);
44 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
45 static int device_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
46 #else
47 static long device_ioctl (struct file *file, unsigned int cmd, unsigned long arg);
48 #endif
49 static int device_open(struct inode *, struct file *);
50 static int device_release(struct inode *, struct file *);
51 static ssize_t device_read(struct file *, char __user *, size_t, loff_t *);
52 static ssize_t device_write(struct file *, const char __user *, size_t, loff_t *);
53
54 static int gl_nDeviceOpened = 0;
55 static struct file_operations device_fops = {
56         .owner = THIS_MODULE,
57         .mmap = device_mmap,
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
59         .ioctl = device_ioctl,
60 #else
61         .unlocked_ioctl = device_ioctl,
62 #endif
63         .read = device_read,
64         .write = device_write,
65         .open = device_open,
66         .release = device_release
67 };
68
69 typedef void (* dbi_module_callback)(void);
70
71 int device_init (void)
72 {
73         int nReserved = 0;
74         nReserved = register_chrdev(0, device_name, &device_fops);
75         if(nReserved < 0)
76         {
77                 unregister_chrdev(nReserved, device_name);
78                 EPRINTF("Cannot register character device!");
79                 return -1;
80         }
81         EPRINTF("New device node with major number [%d], was created\n", nReserved);
82         device_major = nReserved;
83         return 0;
84 }
85
86 void device_down (void)
87 {
88         unregister_chrdev(device_major, device_name);
89 }
90
91 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
92 void swap_register_notify (struct notifier_block *nb)
93 {
94         blocking_notifier_chain_register(&swap_notifier_list, nb);
95 }
96 EXPORT_SYMBOL_GPL(swap_register_notify);
97
98 void swap_unregister_notify (struct notifier_block *nb)
99 {
100         blocking_notifier_chain_unregister(&swap_notifier_list, nb);
101 }
102 EXPORT_SYMBOL_GPL(swap_unregister_notify);
103 #endif
104
105 void notify_user (event_id_t event_id)
106 {
107         ec_info.events_counters[event_id] += 1;
108
109         if (EVENT_EC_PROBE_RECORD == event_id)
110         {
111                 // EC_PROBE_RECORD events happen to often. To reduce overhead user
112                 // space will be notified only once per each EVENTS_AGGREGATION_USEC
113                 static uint64_t timestamp_usec = 0;
114
115                 uint64_t current_usec;
116                 uint64_t delta_usec;
117
118                 struct timeval tv;
119
120                 do_gettimeofday (&tv);
121                 current_usec = 1000000ULL * (unsigned) tv.tv_sec + (unsigned) tv.tv_usec;
122
123                 if (current_usec < timestamp_usec)
124                 {
125                         // Note: time from do_gettimeofday() may go backward
126                         EPRINTF ("current_usec=%llu timestamp_usec=%llu", current_usec, timestamp_usec);
127                 }
128                 else
129                 {
130                         delta_usec = current_usec - timestamp_usec;
131                         if (EVENTS_AGGREGATION_USEC > delta_usec)
132                         {
133                                 // wait the time left
134 #if defined(__DEBUG)
135                                 unsigned UNUSED left_usec = EVENTS_AGGREGATION_USEC - delta_usec;
136 #endif /* defined(__DEBUG) */
137                                 return; // supress notification
138                         }
139                 }
140                 timestamp_usec = current_usec;  // remember new time for the future use
141         } else if (EVENT_EC_START_CONDITION_SEEN == event_id) {
142                 return;         // supress notification
143         } else if (EVENT_EC_STOP_CONDITION_SEEN == event_id) {
144                 return;         // supress notification
145         }
146
147         ++notification_count;
148         wake_up_interruptible (&notification_waiters_queue);
149 }
150
151 static int device_mmap (struct file *filp UNUSED, struct vm_area_struct *vma)
152 {
153         if(!p_buffer) {
154                 EPRINTF("Null pointer to buffer!");
155                 return -1;
156         }
157         return remap_vmalloc_range (vma, p_buffer, 0);
158 }
159
160 static int device_open(struct inode *inode, struct file *file)
161 {
162         /*if (gl_nDeviceOpened)
163                 return -EBUSY;*/
164         gl_nDeviceOpened++;
165         // TODO
166         try_module_get(THIS_MODULE);
167         return 0;
168 }
169
170 static int device_release(struct inode *inode, struct file *file)
171 {
172         gl_nDeviceOpened--;
173         module_put(THIS_MODULE);
174
175         return 0;
176 }
177
178 static ssize_t device_read(struct file *filp, char __user *buffer, size_t length, loff_t * offset)
179 {
180         EPRINTF("Operation <<read>> not supported!");
181         return -1;
182 }
183
184 static ssize_t device_write(struct file *filp, const char __user *buff, size_t len, loff_t * off)
185 {
186         EPRINTF("Operation <<write>> not supported!");
187         return -1;
188 }
189
190 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
191 static int device_ioctl (struct inode *inode UNUSED, struct file *file UNUSED, unsigned int cmd, unsigned long arg)
192 #else
193 static long device_ioctl (struct file *file UNUSED, unsigned int cmd, unsigned long arg)
194 #endif
195 {
196         unsigned long spinlock_flags = 0L;
197         int result = -1;
198     void __user * arg_pointer = (void __user *) arg;
199 //      DPRINTF("Command=%d", cmd);
200         switch (cmd)
201         {
202         case EC_IOCTL_SET_EC_MODE:
203                 {
204                         ioctl_general_t param;
205                         unsigned long nIgnoredBytes = 0;
206                         memset(&param, '0', sizeof(ioctl_general_t));
207                         nIgnoredBytes = copy_from_user (&param, arg_pointer, sizeof(ioctl_general_t));
208                         if (nIgnoredBytes > 0) {
209                                 result = -1;
210                                 break;
211                         }
212                         if(SetECMode(param.m_unsignedLong) == -1) {
213                                 result = -1;
214                                 break;
215                         }
216                         result = 0;
217                         DPRINTF("Set EC Mode = %lu", param.m_unsignedLong);
218                         break;
219                 }
220         case EC_IOCTL_GET_EC_MODE:
221                 {
222                         ioctl_general_t param;
223                         unsigned long nIgnoredBytes = 0;
224                         memset(&param, '0', sizeof(ioctl_general_t));
225                         param.m_unsignedLong = GetECMode();
226                         nIgnoredBytes = copy_to_user (arg_pointer, &param, sizeof (ioctl_general_t));
227                         if (nIgnoredBytes > 0) {
228                                 result = -1;
229                                 break;
230                         }
231                         result = 0;
232 //                      DPRINTF("Get EC Mode = %lu", param.m_unsignedLong);  // Frequent call
233                         break;
234                 }
235         case EC_IOCTL_SET_BUFFER_SIZE:
236                 {
237                         ioctl_general_t param;
238                         unsigned long nIgnoredBytes = 0;
239                         memset(&param, '0', sizeof(ioctl_general_t));
240                         nIgnoredBytes = copy_from_user (&param, arg_pointer, sizeof(ioctl_general_t));
241                         if (nIgnoredBytes > 0) {
242                                 result = -1;
243                                 break;
244                         }
245                         if (SetBufferSize(param.m_unsignedLong) == -1) {
246                                 result = -1;
247                                 break;
248                         }
249                         result = 0;
250                         DPRINTF("Set Buffer Size = %lu", param.m_unsignedLong);
251                         break;
252                 }
253         case EC_IOCTL_GET_BUFFER_SIZE:
254                 {
255                         ioctl_general_t param;
256                         unsigned long nIgnoredBytes = 0;
257                         memset(&param, '0', sizeof(ioctl_general_t));
258                         param.m_unsignedLong = GetBufferSize();
259                         nIgnoredBytes = copy_to_user (arg_pointer, &param, sizeof (ioctl_general_t));
260                         if (nIgnoredBytes > 0) {
261                                 result = -1;
262                                 break;
263                         }
264                         result = 0;
265                         DPRINTF("Get Buffer Size = %lu", param.m_unsignedLong);
266                         break;
267                 }
268         case EC_IOCTL_RESET_BUFFER:
269                 {
270                         if (ResetBuffer() == -1) {
271                                 result = -1;
272                                 break;
273                         }
274                         result = 0;
275                         DPRINTF("Reset Buffer");
276                         break;
277                 }
278         case EC_IOCTL_GET_EC_INFO:
279                 {
280                         if (copy_ec_info_to_user_space ((ec_info_t *) arg) != 0) {
281                                 result = -1;
282                                 break;
283                         }
284                         result = 0;
285 //                      DPRINTF("Get Buffer Status"); // Frequent call
286                         break;
287                 }
288         case EC_IOCTL_CONSUME_BUFFER:
289                 {
290                         static ec_info_t ec_info_copy;
291                         int nIgnoredBytes = 0;
292
293                         nIgnoredBytes = copy_from_user (&ec_info_copy, (const void __user *) arg, sizeof (ec_info_t));
294                         if(nIgnoredBytes > 0)
295                         {
296                                 EPRINTF ("copy_from_user(%08X,%08X)=%d", (unsigned) arg, (unsigned) &ec_info_copy, nIgnoredBytes);
297                                 result = -1;
298                                 break;
299                         }
300
301                         spin_lock_irqsave (&ec_spinlock, spinlock_flags);
302
303                         // Original buffer
304                         if(ec_info.after_last > ec_info.first) {
305                                 ec_info.buffer_effect = ec_info.buffer_size;
306                         }
307                         if (ec_info.after_last == ec_info.buffer_effect) {
308                                  ec_info.first = 0;
309                         } else {
310                                  ec_info.first = ec_info_copy.after_last;
311                         }
312                         ec_info.trace_size = ec_info.trace_size - ec_info_copy.trace_size;
313
314                         spin_unlock_irqrestore (&ec_spinlock, spinlock_flags);
315                         result = 0;
316 //                      DPRINTF("Consume Buffer"); // Frequent call
317                         break;
318                 }
319         case EC_IOCTL_ADD_PROBE:
320                 {
321                         unsigned long addr = arg;
322                         result = add_probe(addr);
323
324                         break;
325                 }
326         //@AGv: remove_probe expects probe address instead of name
327         /*case EC_IOCTL_REMOVE_PROBE:
328                 {
329                         char *probe_name = (char *) arg;
330                         result = remove_probe (probe_name);
331
332                         break;
333                 }*/
334         case EC_IOCTL_SET_APPDEPS:
335         {
336                 size_t size;
337                 result = copy_from_user(&size, arg_pointer, sizeof(size_t));
338                 if (result) {
339                         EPRINTF("Cannot copy deps size!");
340                         result = -1;
341                         break;
342                 }
343                 DPRINTF("Deps size has been copied (%d)", size);
344
345                 if (size == 0) {
346                         DPRINTF("Deps are size of 0");
347                         break;
348                 }
349
350                 deps = vmalloc(size);
351                 if (deps == NULL) {
352                         EPRINTF("Cannot alloc mem for deps!");
353                         result = -1;
354                         break;
355                 }
356                 DPRINTF("Mem for deps has been allocated");
357
358                 result = copy_from_user(deps, arg_pointer, size);
359                 if (result) {
360                         EPRINTF("Cannot copy deps!");
361                         result = -1;
362                         break;
363                 }
364                 DPRINTF("Deps has been copied successfully");
365
366                 break;
367         }
368         case EC_IOCTL_SET_PID:
369         {
370                 unsigned int _pid;
371
372                 result = copy_from_user(&_pid, arg_pointer, sizeof(unsigned int));
373                 if (result) {
374                         EPRINTF("Cannot copy pid!");
375                         result = -1;
376                         break;
377                 }
378
379                 inst_pid = _pid;
380
381                 DPRINTF("EC_IOCTL_SET_PID pid:%d", inst_pid);
382
383                 break;
384         }
385         case EC_IOCTL_SET_PROFILEBUNDLE:
386         {
387                 size_t size;
388
389                 result = copy_from_user(&size, arg_pointer, sizeof(size_t));
390                 if (result) {
391                         EPRINTF("Cannot copy bundle size!");
392                         result = -1;
393                         break;
394                 }
395                 DPRINTF("Bundle size has been copied");
396
397                 bundle = vmalloc(size);
398                 if (bundle == NULL) {
399                         EPRINTF("Cannot alloc mem for bundle!");
400                         result = -1;
401                         break;
402                 }
403                 DPRINTF("Mem for bundle has been alloced");
404
405                 result = copy_from_user(bundle, arg_pointer, size);
406                 if (result) {
407                         EPRINTF("Cannot copy bundle!");
408                         result = -1;
409                         break;
410                 }
411                 DPRINTF("Bundle has been copied successfully");
412
413                 if (link_bundle() == -1 || has_last_error() == -1) {
414                         EPRINTF("Cannot link profile bundle!");
415                         result = -1;
416                         break;
417                 }
418
419                 break;
420         }
421         case EC_IOCTL_RESET_PROBES:
422                 {
423                         result = reset_probes();
424
425                         break;
426                 }
427         case EC_IOCTL_UPDATE_CONDS:
428                 {
429                         int args_cnt, i;
430                         struct cond *c, *c_tmp, *p_cond;
431                         unsigned char *p_data;
432                         int err;
433                         result = 0;
434                         err = copy_from_user(&args_cnt, arg_pointer, sizeof(int));
435                         if (err) {
436                                 result = -1;
437                                 break;
438                         }
439                         /* first, delete all the conds */
440                         list_for_each_entry_safe(c, c_tmp, &cond_list.list, list) {
441                                 list_del(&c->list);
442                                 kfree(c);
443                         }
444                         /* second, add new conds */
445                         p_data = (unsigned char *)(arg + sizeof(int));
446                         for (i = 0; i < args_cnt; i++) {
447                                 p_cond = kmalloc(sizeof(struct cond), GFP_KERNEL);
448                                 if (!p_cond) {
449                                         DPRINTF("Cannot alloc cond!");
450                                         result = -1;
451                                         break;
452                                 }
453                                 err = copy_from_user(&p_cond->tmpl, (const void __user *)p_data,
454                                                 sizeof(struct event_tmpl));
455                                 if (err) {
456                                         DPRINTF("Cannot copy cond from user!");
457                                         result = -1;
458                                         break;
459                                 }
460                                 p_cond->applied = 0;
461                                 list_add(&(p_cond->list), &(cond_list.list));
462                                 p_data += sizeof(struct event_tmpl);
463                         }
464                         break;
465                 }
466         case EC_IOCTL_ATTACH:
467                 {
468                         unsigned long dbi_flags;
469                         struct dbi_modules_handlers *local_mh;
470                         struct dbi_modules_handlers_info *local_mhi;
471                         int j;
472                         dbi_module_callback dmc_start;
473
474                         // call "start"-callback for all modules according module priority
475                         local_mh = get_dbi_modules_handlers();
476                         spin_lock_irqsave(&local_mh->lock, dbi_flags);
477                         for (j = 0; j <= MAX_PRIORITY; j++) {
478                                 list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
479                                         if (local_mhi->dbi_module_priority_start == j) {
480                                                 if (local_mhi->dbi_module_callback_start != NULL) {
481                                                         printk("Started module callback (start) %s\n", local_mhi->dbi_module->name);
482                                                         dmc_start = (dbi_module_callback )local_mhi->dbi_module_callback_start;
483                                                         dmc_start();
484                                                 }
485                                         }
486                                 }
487                         }
488                         spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
489
490                         result = ec_user_attach ();
491 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
492                         DPRINTF("EC_IOCTL_ATTACH calling notification chain");
493                         blocking_notifier_call_chain(&swap_notifier_list, EC_IOCTL_ATTACH, (void*)NULL);
494 #endif
495                         DPRINTF("Attach Probes");
496                         break;
497                 }
498         case EC_IOCTL_ACTIVATE:
499                 result = ec_user_activate ();
500                 DPRINTF("Activate Probes");
501                 break;
502         case EC_IOCTL_STOP_AND_DETACH:
503         {
504                 unsigned long nIgnoredBytes = 0;
505                 unsigned long dbi_flags;
506                 struct dbi_modules_handlers *local_mh;
507                 struct dbi_modules_handlers_info *local_mhi;
508                 unsigned int local_module_refcount = 0;
509                 int j;
510                 dbi_module_callback dmc_stop;
511
512 #ifdef OVERHEAD_DEBUG
513                 printk("\nswap_sum_time = %ld in kprobe_handler()\n", swap_sum_time);
514                 printk("swap_sum_hit = %ld in kprobe_handler()\n", swap_sum_hit);
515                 swap_sum_time = 0;
516                 swap_sum_hit = 0;
517 #endif
518
519                 printk("\n### imi_sum_time = %ld in install_mapped_ips()\n", imi_sum_time);
520                 printk("### imi_sum_hit = %ld in install_mapped_ips()\n", imi_sum_hit);
521
522                 if (imi_sum_hit != 0) {
523                         printk("### time = %ld in install_mapped_ips()\n", imi_sum_time/imi_sum_hit);
524                 }
525
526                 imi_sum_time = 0;
527                 imi_sum_hit = 0;
528
529                 local_mh = get_dbi_modules_handlers();
530                 if(ec_user_stop() != 0) {
531                         result = -1;
532                         goto sad_cleanup;
533                 }
534                 nIgnoredBytes = copy_ec_info_to_user_space ((ec_info_t*)arg);
535                 if(nIgnoredBytes > 0) {
536                         result = -1;
537                         goto sad_cleanup;
538                 }
539
540                 sspt_proc_free_all();
541
542                 vfree(bundle);
543                 result = 0;
544                 DPRINTF("Stop and Detach Probes");
545 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
546                 DPRINTF("EC_IOCTL_STOP_AND_DETACH calling notification chain");
547                 blocking_notifier_call_chain(&swap_notifier_list, EC_IOCTL_STOP_AND_DETACH, (void*)&gl_nNotifyTgid);
548 #endif
549                 // call "stop"-callback for all modules according module priority
550                 spin_lock_irqsave(&local_mh->lock, dbi_flags);
551                 for (j = 0; j <= MAX_PRIORITY; j++) {
552                         list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
553                                 if (local_mhi->dbi_module_priority_stop == j) {
554                                         if (local_mhi->dbi_module_callback_stop != NULL) {
555                                                 printk("Started module callback (stop) %s\n", local_mhi->dbi_module->name);
556                                                 dmc_stop = (dbi_module_callback )local_mhi->dbi_module_callback_stop;
557                                                 dmc_stop();
558                                         }
559                                 }
560                         }
561                 }
562                 spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
563 sad_cleanup:
564                 spin_lock_irqsave(&local_mh->lock, dbi_flags);
565                 list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
566                         local_module_refcount = module_refcount(local_mhi->dbi_module);
567                         if (local_module_refcount == 1) {
568                                 module_put(local_mhi->dbi_module);
569                         }
570                         else if (local_module_refcount > 1) {
571                                 printk("local_module_refcount too much - force set refcount to zero\n");
572                                 while (local_module_refcount--)
573                                         module_put(local_mhi->dbi_module);
574                         }
575                 }
576                 spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
577                 break;
578         }
579         case EC_IOCTL_US_EVENT:
580                 {
581                         ioctl_us_event_t ioctl_args;
582                         result = copy_from_user (&ioctl_args, (const void __user *) arg, sizeof (ioctl_args));
583                         if (result)
584                         {
585                                 result = -1;
586                                 EPRINTF ("copy_from_user() failure");
587                         }
588                         else
589                         {
590                                 if(ioctl_args.len == 0){
591                                         result = -EINVAL;
592                                         EPRINTF ("invalid event length!");
593                                 }
594                                 else {
595                                         char *buf = kmalloc(ioctl_args.len, GFP_KERNEL);
596                                         if(!buf){
597                                                 result = -ENOMEM;
598                                                 EPRINTF ("failed to alloc mem for event!");
599                                         }
600                                         else {
601                                                 result = copy_from_user (buf, (const void __user *) ioctl_args.data, ioctl_args.len);
602                                                 if (result){
603                                                         result = -1;
604                                                         EPRINTF ("failed to copy event from user space!");
605                                                 }
606                                                 else
607                                                         result = put_us_event(buf, ioctl_args.len);
608                                                 kfree(buf);
609                                         }
610                                 }
611                         }
612 //                      DPRINTF("User Space Event"); // Frequent call
613                         break;
614                 }
615
616         case EC_IOCTL_SET_EVENT_MASK:
617                 {
618                         int mask;
619                         result = copy_from_user (&mask, arg_pointer, sizeof (mask));
620                         if (result)
621                         {
622                                 result = -EFAULT;
623                                 break;
624                         }
625
626                         result = set_event_mask (mask);
627                         if (result)
628                         {
629                                 break;
630                         }
631                         DPRINTF("Set Event Mask = %d", mask);
632                         break;
633                 }
634
635         case EC_IOCTL_GET_EVENT_MASK:
636                 {
637                         int mask = 0;
638                         result = get_event_mask(&mask);
639                         if (result)
640                         {
641                                 result = -EFAULT;
642                         }
643                         result = copy_to_user (arg_pointer, &mask, sizeof (mask));
644                         if (result)
645                         {
646                                 result = -EFAULT;
647                         }
648                         DPRINTF("Get Event Mask = %d", mask);
649                         break;
650                 }
651
652         case EC_IOCTL_GET_PREDEF_UPROBES:
653                 {
654                         result = get_predef_uprobes((ioctl_predef_uprobes_info_t *)arg);
655                         if (result)
656                         {
657                                 result = -EFAULT;
658                         }
659                         DPRINTF("Get Predefined User Space Probes");
660                         break;
661                 }
662
663         case EC_IOCTL_GET_PREDEF_UPROBES_SIZE:
664                 {
665                         int size = 0;
666                         result = get_predef_uprobes_size(&size);
667                         if (result)
668                         {
669                                 result = -EFAULT;
670                         }
671                         result = copy_to_user (arg_pointer, &size, sizeof (size));
672                         if (result)
673                         {
674                                 result = -EFAULT;
675                         }
676                         DPRINTF("Get Size of Predefined User Space Probes");
677                         break;
678                 }
679         case EC_IOCTL_GET_LAST_ERROR:
680                 {
681                         result = get_last_error((void*)arg);
682                         DPRINTF("Get last error buffer");
683                         break;
684                 }
685         default:
686                 EPRINTF ("Unknown driver command = %u", cmd);
687                 result = -EINVAL;
688                 break;
689         }
690
691         return result;
692 }