#include <asm/timex.h>
 
 #include <asm/debug.h>
+#include <asm/s390_rdev.h>
 #include <asm/qdio.h>
 
 #include "cio.h"
 /******************** HERE WE GO ***********************************/
 
 static const char version[] = "QDIO base support version 2";
+extern struct bus_type ccw_bus_type;
 
-#ifdef QDIO_PERFORMANCE_STATS
+static int qdio_performance_stats = 0;
 static int proc_perf_file_registration;
 static unsigned long i_p_c, i_p_nc, o_p_c, o_p_nc, ii_p_c, ii_p_nc;
 static struct qdio_perf_stats perf_stats;
-#endif /* QDIO_PERFORMANCE_STATS */
 
 static int hydra_thinints;
 static int is_passthrough = 0;
        QDIO_DBF_TEXT4(0,trace,"sigasync");
        QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.siga_syncs++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats)
+               perf_stats.siga_syncs++;
 
        cc = do_siga_sync(q->schid, gpr2, gpr3);
        if (cc)
        __u32 busy_bit;
        __u64 start_time=0;
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.siga_outs++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats)
+               perf_stats.siga_outs++;
 
        QDIO_DBF_TEXT4(0,trace,"sigaout");
        QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
        QDIO_DBF_TEXT4(0,trace,"sigain");
        QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.siga_ins++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats)
+               perf_stats.siga_ins++;
 
        cc = do_siga_input(q->schid, q->mask);
        
 
        if (unlikely(qdio_reserve_q(q))) {
                qdio_release_q(q);
-#ifdef QDIO_PERFORMANCE_STATS
-               o_p_c++;
-#endif /* QDIO_PERFORMANCE_STATS */
+               if (qdio_performance_stats)
+                       o_p_c++;
                /* as we're sissies, we'll check next time */
                if (likely(!atomic_read(&q->is_in_shutdown))) {
                        qdio_mark_q(q);
                }
                return;
        }
-#ifdef QDIO_PERFORMANCE_STATS
-       o_p_nc++;
-       perf_stats.tl_runs++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats) {
+               o_p_nc++;
+               perf_stats.tl_runs++;
+       }
 
        /* see comment in qdio_kick_outbound_q */
        siga_attempts=atomic_read(&q->busy_siga_counter);
 {
        int i;
 
-#ifdef QDIO_PERFORMANCE_STATS
        static int old_pcis=0;
        static int old_thinints=0;
 
-       if ((old_pcis==perf_stats.pcis)&&(old_thinints==perf_stats.thinints))
-               perf_stats.start_time_inbound=NOW;
-       else
-               old_pcis=perf_stats.pcis;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats) {
+               if ((old_pcis==perf_stats.pcis)&&
+                   (old_thinints==perf_stats.thinints))
+                       perf_stats.start_time_inbound=NOW;
+               else
+                       old_pcis=perf_stats.pcis;
+       }
 
        i=qdio_get_inbound_buffer_frontier(q);
        if ( (i!=GET_SAVED_FRONTIER(q)) ||
        q->siga_error=0;
        q->error_status_flags=0;
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound;
-       perf_stats.inbound_cnt++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats) {
+               perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound;
+               perf_stats.inbound_cnt++;
+       }
 }
 
 static inline void
         */
        if (unlikely(qdio_reserve_q(q))) {
                qdio_release_q(q);
-#ifdef QDIO_PERFORMANCE_STATS
-               ii_p_c++;
-#endif /* QDIO_PERFORMANCE_STATS */
+               if (qdio_performance_stats)
+                       ii_p_c++;
                /* 
                 * as we might just be about to stop polling, we make
                 * sure that we check again at least once more 
                tiqdio_sched_tl();
                return;
        }
-#ifdef QDIO_PERFORMANCE_STATS
-       ii_p_nc++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats)
+               ii_p_nc++;
        if (unlikely(atomic_read(&q->is_in_shutdown))) {
                qdio_unmark_q(q);
                goto out;
                irq_ptr = (struct qdio_irq*)q->irq_ptr;
                for (i=0;i<irq_ptr->no_output_qs;i++) {
                        oq = irq_ptr->output_qs[i];
-#ifdef QDIO_PERFORMANCE_STATS
-                       perf_stats.tl_runs--;
-#endif /* QDIO_PERFORMANCE_STATS */
-                       if (!qdio_is_outbound_q_done(oq))
+                       if (!qdio_is_outbound_q_done(oq)) {
+                               if (qdio_performance_stats)
+                                       perf_stats.tl_runs--;
                                __qdio_outbound_processing(oq);
+                       }
                }
        }
 
 
        if (unlikely(qdio_reserve_q(q))) {
                qdio_release_q(q);
-#ifdef QDIO_PERFORMANCE_STATS
-               i_p_c++;
-#endif /* QDIO_PERFORMANCE_STATS */
+               if (qdio_performance_stats)
+                       i_p_c++;
                /* as we're sissies, we'll check next time */
                if (likely(!atomic_read(&q->is_in_shutdown))) {
                        qdio_mark_q(q);
                }
                return;
        }
-#ifdef QDIO_PERFORMANCE_STATS
-       i_p_nc++;
-       perf_stats.tl_runs++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats) {
+               i_p_nc++;
+               perf_stats.tl_runs++;
+       }
 
 again:
        if (qdio_has_inbound_q_moved(q)) {
 
        if (unlikely(qdio_reserve_q(q))) {
                qdio_release_q(q);
-#ifdef QDIO_PERFORMANCE_STATS
-               ii_p_c++;
-#endif /* QDIO_PERFORMANCE_STATS */
+               if (qdio_performance_stats)
+                       ii_p_c++;
                /* 
                 * as we might just be about to stop polling, we make
                 * sure that we check again at least once more 
 {
        QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.tl_runs++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats)
+               perf_stats.tl_runs++;
 
        tiqdio_inbound_checks();
 }
 {
        QDIO_DBF_TEXT4(0,trace,"thin_int");
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.thinints++;
-       perf_stats.start_time_inbound=NOW;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats) {
+               perf_stats.thinints++;
+               perf_stats.start_time_inbound=NOW;
+       }
 
        /* SVS only when needed:
         * issue SVS to benefit from iqdio interrupt avoidance
        int i;
        struct qdio_q *q;
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.pcis++;
-       perf_stats.start_time_inbound=NOW;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats) {
+               perf_stats.pcis++;
+               perf_stats.start_time_inbound=NOW;
+       }
        for (i=0;i<irq_ptr->no_input_qs;i++) {
                q=irq_ptr->input_qs[i];
                if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
                        qdio_mark_q(q);
                else {
-#ifdef QDIO_PERFORMANCE_STATS
-                       perf_stats.tl_runs--;
-#endif /* QDIO_PERFORMANCE_STATS */
+                       if (qdio_performance_stats)
+                               perf_stats.tl_runs--;
                        __qdio_inbound_processing(q);
                }
        }
                return;
        for (i=0;i<irq_ptr->no_output_qs;i++) {
                q=irq_ptr->output_qs[i];
-#ifdef QDIO_PERFORMANCE_STATS
-               perf_stats.tl_runs--;
-#endif /* QDIO_PERFORMANCE_STATS */
                if (qdio_is_outbound_q_done(q))
                        continue;
+               if (qdio_performance_stats)
+                       perf_stats.tl_runs--;
                if (!irq_ptr->sync_done_on_outb_pcis)
                        SYNC_MEMORY;
                __qdio_outbound_processing(q);
        struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
 
        /* This is the outbound handling of queues */
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.start_time_outbound=NOW;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats)
+               perf_stats.start_time_outbound=NOW;
 
        qdio_do_qdio_fill_output(q,qidx,count,buffers);
 
        used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
 
        if (callflags&QDIO_FLAG_DONT_SIGA) {
-#ifdef QDIO_PERFORMANCE_STATS
-               perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
-               perf_stats.outbound_cnt++;
-#endif /* QDIO_PERFORMANCE_STATS */
+               if (qdio_performance_stats) {
+                       perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
+                       perf_stats.outbound_cnt++;
+               }
                return;
        }
        if (q->is_iqdio_q) {
                                qdio_kick_outbound_q(q);
                        } else {
                                QDIO_DBF_TEXT3(0,trace, "fast-req");
-#ifdef QDIO_PERFORMANCE_STATS
-                               perf_stats.fast_reqs++;
-#endif /* QDIO_PERFORMANCE_STATS */
+                               if (qdio_performance_stats)
+                                       perf_stats.fast_reqs++;
                        }
                }
                /* 
                __qdio_outbound_processing(q);
        }
 
-#ifdef QDIO_PERFORMANCE_STATS
-       perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
-       perf_stats.outbound_cnt++;
-#endif /* QDIO_PERFORMANCE_STATS */
+       if (qdio_performance_stats) {
+               perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
+               perf_stats.outbound_cnt++;
+       }
 }
 
 /* count must be 1 in iqdio */
        return 0;
 }
 
-#ifdef QDIO_PERFORMANCE_STATS
 static int
 qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
                        int buffer_length, int *eof, void *data)
        _OUTP_IT("i_p_nc/c=%lu/%lu\n",i_p_nc,i_p_c);
        _OUTP_IT("ii_p_nc/c=%lu/%lu\n",ii_p_nc,ii_p_c);
        _OUTP_IT("o_p_nc/c=%lu/%lu\n",o_p_nc,o_p_c);
-       _OUTP_IT("Number of tasklet runs (total)                  : %u\n",
+       _OUTP_IT("Number of tasklet runs (total)                  : %lu\n",
                 perf_stats.tl_runs);
        _OUTP_IT("\n");
-       _OUTP_IT("Number of SIGA sync's issued                    : %u\n",
+       _OUTP_IT("Number of SIGA sync's issued                    : %lu\n",
                 perf_stats.siga_syncs);
-       _OUTP_IT("Number of SIGA in's issued                      : %u\n",
+       _OUTP_IT("Number of SIGA in's issued                      : %lu\n",
                 perf_stats.siga_ins);
-       _OUTP_IT("Number of SIGA out's issued                     : %u\n",
+       _OUTP_IT("Number of SIGA out's issued                     : %lu\n",
                 perf_stats.siga_outs);
-       _OUTP_IT("Number of PCIs caught                           : %u\n",
+       _OUTP_IT("Number of PCIs caught                           : %lu\n",
                 perf_stats.pcis);
-       _OUTP_IT("Number of adapter interrupts caught             : %u\n",
+       _OUTP_IT("Number of adapter interrupts caught             : %lu\n",
                 perf_stats.thinints);
-       _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA)  : %u\n",
+       _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA)  : %lu\n",
                 perf_stats.fast_reqs);
        _OUTP_IT("\n");
-       _OUTP_IT("Total time of all inbound actions (us) incl. UL : %u\n",
+       _OUTP_IT("Total time of all inbound actions (us) incl. UL : %lu\n",
                 perf_stats.inbound_time);
-       _OUTP_IT("Number of inbound transfers                     : %u\n",
+       _OUTP_IT("Number of inbound transfers                     : %lu\n",
                 perf_stats.inbound_cnt);
-       _OUTP_IT("Total time of all outbound do_QDIOs (us)        : %u\n",
+       _OUTP_IT("Total time of all outbound do_QDIOs (us)        : %lu\n",
                 perf_stats.outbound_time);
-       _OUTP_IT("Number of do_QDIOs outbound                     : %u\n",
+       _OUTP_IT("Number of do_QDIOs outbound                     : %lu\n",
                 perf_stats.outbound_cnt);
        _OUTP_IT("\n");
 
 }
 
 static struct proc_dir_entry *qdio_perf_proc_file;
-#endif /* QDIO_PERFORMANCE_STATS */
 
 static void
 qdio_add_procfs_entry(void)
 {
-#ifdef QDIO_PERFORMANCE_STATS
         proc_perf_file_registration=0;
        qdio_perf_proc_file=create_proc_entry(QDIO_PERF,
                                              S_IFREG|0444,&proc_root);
                 QDIO_PRINT_WARN("was not able to register perf. " \
                                "proc-file (%i).\n",
                                proc_perf_file_registration);
-#endif /* QDIO_PERFORMANCE_STATS */
 }
 
 static void
 qdio_remove_procfs_entry(void)
 {
-#ifdef QDIO_PERFORMANCE_STATS
        perf_stats.tl_runs=0;
 
         if (!proc_perf_file_registration) /* means if it went ok earlier */
                remove_proc_entry(QDIO_PERF,&proc_root);
-#endif /* QDIO_PERFORMANCE_STATS */
 }
 
+/**
+ * attributes in sysfs
+ *****************************************************************************/
+
+static ssize_t
+qdio_performance_stats_show(struct bus_type *bus, char *buf)
+{
+       return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0);
+}
+
+static ssize_t
+qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count)
+{
+       char *tmp;
+       int i;
+
+       i = simple_strtoul(buf, &tmp, 16);
+       if ((i == 0) || (i == 1)) {
+               if (i == qdio_performance_stats)
+                       return count;
+               qdio_performance_stats = i;
+               if (i==0) {
+                       /* reset perf. stat. info */
+                       i_p_nc = 0;
+                       i_p_c = 0;
+                       ii_p_nc = 0;
+                       ii_p_c = 0;
+                       o_p_nc = 0;
+                       o_p_c = 0;
+                       memset(&perf_stats, 0, sizeof(struct qdio_perf_stats));
+               }
+       } else {
+               QDIO_PRINT_WARN("QDIO performance_stats: write 0 or 1 to this file!\n");
+               return -EINVAL;
+       }
+       return count;
+}
+
+static BUS_ATTR(qdio_performance_stats, 0644, qdio_performance_stats_show,
+                       qdio_performance_stats_store);
+
 static void
 tiqdio_register_thinints(void)
 {
        kfree(indicators);
 }
 
+
 static void
 qdio_unregister_dbf_views(void)
 {
 init_QDIO(void)
 {
        int res;
-#ifdef QDIO_PERFORMANCE_STATS
        void *ptr;
-#endif /* QDIO_PERFORMANCE_STATS */
 
        printk("qdio: loading %s\n",version);
 
                return res;
 
        QDIO_DBF_TEXT0(0,setup,"initQDIO");
+       res = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
 
-#ifdef QDIO_PERFORMANCE_STATS
-               memset((void*)&perf_stats,0,sizeof(perf_stats));
+       memset((void*)&perf_stats,0,sizeof(perf_stats));
        QDIO_DBF_TEXT0(0,setup,"perfstat");
        ptr=&perf_stats;
        QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*));
-#endif /* QDIO_PERFORMANCE_STATS */
 
        qdio_add_procfs_entry();
 
        qdio_release_qdio_memory();
        qdio_unregister_dbf_views();
        mempool_destroy(qdio_mempool_scssc);
-
+       bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
        printk("qdio: %s: module removed\n",version);
 }