Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/*
 *      Copyright (C) 1997 Claus-Justus Heine

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; see the file COPYING.  If not, write to
 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

 *
 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-proc.c,v $
 * $Revision: 1.11 $
 * $Date: 1997/10/24 14:47:37 $
 *
 *      This file contains the procfs interface for the
 *      QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
 */

#include <linux/config.h>

#if defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS)

/*  adding proc entries from inside a module is REALLY complicated 
 *  for pre-2.1.28 kernels. I don't want to care about it.
 */

#include <linux/proc_fs.h>

#include <linux/ftape.h>
#if LINUX_VERSION_CODE <= KERNEL_VER(1,2,13) /* bail out */
#error \
Please disable CONFIG_FT_PROC_FS in "MCONFIG" or upgrade to a newer kernel!
#endif
#if LINUX_VERSION_CODE >= KERNEL_VER(2,1,16)
#include <linux/init.h>
#else
#define __initdata
#define __initfunc(__arg) __arg
#endif
#include <linux/qic117.h>


#include "../lowlevel/ftape-io.h"
#include "../lowlevel/ftape-ctl.h"
#include "../lowlevel/ftape-proc.h"
#include "../lowlevel/ftape-tracing.h"

static int ftape_read_proc(char *page, char **start, off_t off,
			   int count, int *eof, void *data);

#if LINUX_VERSION_CODE < KERNEL_VER(2,1,28)

#include <asm/segment.h> /* for memcpy_tofs() */

#if LINUX_VERSION_CODE >= KERNEL_VER(2,1,0)
static long ftape_proc_read(struct inode* inode, struct file* file,
			    char* buf, unsigned long count);
#else
static int ftape_proc_read(struct inode* inode, struct file* file,
			   char* buf, int count);
#endif

#define FT_PROC_REGISTER(parent, child) proc_register_dynamic(parent, child)

/*
 *	Structures for interfacing with the /proc filesystem.
 *	Router creates its own directory /proc/net/router with the folowing
 *	entries:
 *	config		device configuration
 *	status		global device statistics
 *	<device>	entry for each WAN device
 */

/*
 *	Generic /proc/net/ftape/<file> file and inode operations
 */


static struct file_operations ftape_proc_fops =
{
	NULL,			/* lseek   */
	ftape_proc_read,	/* read	   */
	NULL,			/* write   */
	NULL,			/* readdir */
	NULL,			/* select  */
	NULL,			/* ioctl   */
	NULL,			/* mmap	   */
	NULL,			/* no special open code	   */
	NULL,			/* flush */
	NULL,			/* no special release code */
	NULL,			/* can't fsync */
};

static struct inode_operations ftape_proc_inode_operations =
{
	&ftape_proc_fops,
	NULL,			/* create */
	NULL,			/* lookup */
	NULL,			/* link */
	NULL,			/* unlink */
	NULL,			/* symlink */
	NULL,			/* mkdir */
	NULL,			/* rmdir */
	NULL,			/* mknod */
	NULL,			/* rename */
	NULL,			/* readlink */
	NULL,			/* follow_link */
	NULL,			/* get_block */
	NULL,			/* readpage */
	NULL,			/* writepage */
	NULL,			/* flushpage */
	NULL,			/* truncate */
	NULL,			/* permission */
	NULL,			/* smap */
	NULL,			/* revalidate */
};

/*
 * Proc filesystem directory entries.
 */

static int ftape_get_info(char *page, char **start, off_t off,
			  int count, int dummy)
{
	int dummy_eof;

	return ftape_read_proc(page, start, off, count, &dummy_eof, NULL);
}

static struct proc_dir_entry proc_ftape = {
	0,                            /* low_ino    */
	sizeof("ftape")-1,            /* namelen    */
	"ftape",                      /* name       */
	S_IFREG | S_IRUGO,            /* mode       */
	1,                            /* nlink      */
	0,                            /* uid        */
	0,                            /* gid        */
	0,                            /* size       */
	&ftape_proc_inode_operations, /* ops        */
	ftape_get_info,               /* get_info   */
	NULL,                         /* fill_inode */
	NULL,                         /* next       */
	NULL,                         /* parent     */
	NULL,                         /* subdir     */
	NULL                          /* data       */
};

/*  Read ftape proc directory entry.
 */

#define PROC_BLOCK_SIZE	PAGE_SIZE

#if LINUX_VERSION_CODE >= KERNEL_VER(2,1,0)
static long ftape_proc_read(struct inode * inode, struct file * file,
			    char * buf, unsigned long nbytes)
#else
static int ftape_proc_read(struct inode * inode, struct file * file,
			   char * buf, int nbytes)
#endif
{
	char 	*page;
	int	retval=0;
	int	eof=0;
	int	n, count;
	char	*start;
	struct proc_dir_entry * dp;

	if (nbytes < 0)
		return -EINVAL;
	dp = (struct proc_dir_entry *) inode->u.generic_ip;
	if (!(page = (char*) __get_free_page(GFP_KERNEL)))
		return -ENOMEM;

	while ((nbytes > 0) && !eof)
	{
		count = PROC_BLOCK_SIZE <= nbytes ? PROC_BLOCK_SIZE : nbytes;

		start = NULL;
		if (dp->get_info) {
			/*
			 * Handle backwards compatibility with the old net
			 * routines.
			 * 
			 * XXX What gives with the file->f_flags & O_ACCMODE
			 * test?  Seems stupid to me....
			 */
			n = dp->get_info(page, &start, file->f_pos, count,
				 (file->f_flags & O_ACCMODE) == O_RDWR);
			if (n < count)
				eof = 1;
		} else
			break;
			
		if (!start) {
			/*
			 * For proc files that are less than 4k
			 */
			start = page + file->f_pos;
			n -= file->f_pos;
			if (n <= 0)
				break;
			if (n > count)
				n = count;
		}
		if (n == 0)
			break;	/* End of file */
		if (n < 0) {
			if (retval == 0)
				retval = n;
			break;
		}
#if LINUX_VERSION_CODE > KERNEL_VER(2,1,3)
		copy_to_user(buf, start, n);
#else
		memcpy_tofs(buf, start, n);
#endif
		file->f_pos += n;	/* Move down the file */
		nbytes -= n;
		buf += n;
		retval += n;
	}
	free_page((unsigned long) page);
	return retval;
}

#else /* LINUX_VERSION_CODE < KERNEL_VER(2,1,28) */

#define FT_PROC_REGISTER(parent, child) proc_register(parent, child)

/*
 * Proc filesystem directory entries.
 */

static struct proc_dir_entry proc_ftape = {
	0,                   /* low_ino    */
	sizeof("ftape")-1,   /* namelen    */
	"ftape",             /* name       */
	S_IFREG | S_IRUGO,   /* mode       */
	1,                   /* nlink      */
	0,                   /* uid        */
	0,                   /* gid        */
	0,                   /* size       */
	NULL,                /* ops        */
	NULL,                /* get_info   */
	NULL,                /* fill_inode */
	NULL,                /* next       */
	NULL,                /* parent     */
	NULL,                /* subdir     */
	NULL,                /* data       */
	ftape_read_proc,     /* read_proc  */
	NULL                 /* write_proc */
};

#endif

static size_t get_driver_info(char *buf)
{
	const char *debug_level[] = { "bugs"  ,
				      "errors",
				      "warnings",
				      "informational",
				      "noisy",
				      "program flow",
				      "fdc and dma",
				      "data flow",
				      "anything" };

	return sprintf(buf,
		       "version       : %s\n"
		       "used data rate: %d kbit/sec\n"
		       "dma memory    : %d kb\n"
		       "debug messages: %s\n",
		       FTAPE_VERSION,
		       ft_data_rate,
		       FT_BUFF_SIZE * ft_nr_buffers >> 10,
		       debug_level[TRACE_LEVEL]);
}

static size_t get_tapedrive_info(char *buf)
{ 
	return sprintf(buf,
		       "vendor id : 0x%04x\n"
		       "drive name: %s\n"
		       "wind speed: %d ips\n"
		       "wakeup    : %s\n"
		       "max. rate : %d kbit/sec\n",
		       ft_drive_type.vendor_id,
		       ft_drive_type.name,
		       ft_drive_type.speed,
		       ((ft_drive_type.wake_up == no_wake_up)
			? "No wakeup needed" :
			((ft_drive_type.wake_up == wake_up_colorado)
			 ? "Colorado" :
			 ((ft_drive_type.wake_up == wake_up_mountain)
			  ? "Mountain" :
			  ((ft_drive_type.wake_up == wake_up_insight)
			   ? "Motor on" :
			   "Unknown")))),
		       ft_drive_max_rate);
}

static size_t get_cartridge_info(char *buf)
{
	if (ftape_init_drive_needed) {
		return sprintf(buf, "uninitialized\n");
	}
	if (ft_no_tape) {
		return sprintf(buf, "no cartridge inserted\n");
	}
	return sprintf(buf,
		       "segments  : %5d\n"
		       "tracks    : %5d\n"
		       "length    : %5dft\n"
		       "formatted : %3s\n"
		       "writable  : %3s\n"
		       "QIC spec. : QIC-%s\n"
		       "fmt-code  : %1d\n",
		       ft_segments_per_track,
		       ft_tracks_per_tape,
		       ftape_tape_len,
		       (ft_formatted == 1) ? "yes" : "no",
		       (ft_write_protected == 1) ? "no" : "yes",
		       ((ft_qic_std == QIC_TAPE_QIC40) ? "40" :
			((ft_qic_std == QIC_TAPE_QIC80) ? "80" :
			 ((ft_qic_std == QIC_TAPE_QIC3010) ? "3010" :
			  ((ft_qic_std == QIC_TAPE_QIC3020) ? "3020" :
			   "???")))),
		       ft_format_code);
}

static size_t get_controller_info(char *buf)
{
	const char  *fdc_name[] = { "no fdc",
				    "i8272",
				    "i82077",
				    "i82077AA",
				    "Colorado FC-10 or FC-20",
				    "i82078",
				    "i82078_1" };

	return sprintf(buf,
		       "FDC type  : %s\n"
		       "FDC base  : 0x%03x\n"
		       "FDC irq   : %d\n"
		       "FDC dma   : %d\n"
		       "FDC thr.  : %d\n"
		       "max. rate : %d kbit/sec\n",
		       ft_mach2 ? "Mountain MACH-2" : fdc_name[fdc.type],
		       fdc.sra, fdc.irq, fdc.dma,
		       ft_fdc_threshold, ft_fdc_max_rate);
}

static size_t get_history_info(char *buf)
{
        size_t len;

	len  = sprintf(buf,
		       "\nFDC isr statistics\n"
		       " id_am_errors     : %3d\n"
		       " id_crc_errors    : %3d\n"
		       " data_am_errors   : %3d\n"
		       " data_crc_errors  : %3d\n"
		       " overrun_errors   : %3d\n"
		       " no_data_errors   : %3d\n"
		       " retries          : %3d\n",
		       ft_history.id_am_errors,   ft_history.id_crc_errors,
		       ft_history.data_am_errors, ft_history.data_crc_errors,
		       ft_history.overrun_errors, ft_history.no_data_errors,
		       ft_history.retries);
	len += sprintf(buf + len,
		       "\nECC statistics\n"
		       " crc_errors       : %3d\n"
		       " crc_failures     : %3d\n"
		       " ecc_failures     : %3d\n"
		       " sectors corrected: %3d\n",
		       ft_history.crc_errors,   ft_history.crc_failures,
		       ft_history.ecc_failures, ft_history.corrected);
	len += sprintf(buf + len,
		       "\ntape quality statistics\n"
		       " media defects    : %3d\n",
		       ft_history.defects);
	len += sprintf(buf + len,
		       "\ntape motion statistics\n"
		       " repositions      : %3d\n",
		       ft_history.rewinds);
	return len;
}

int ftape_read_proc(char *page, char **start, off_t off,
		    int count, int *eof, void *data)
{
	char *ptr = page;
	size_t len;
	
	ptr += sprintf(ptr, "Kernel Driver\n\n");
	ptr += get_driver_info(ptr);
	ptr += sprintf(ptr, "\nTape Drive\n\n");
	ptr += get_tapedrive_info(ptr);
	ptr += sprintf(ptr, "\nFDC Controller\n\n");
	ptr += get_controller_info(ptr);
	ptr += sprintf(ptr, "\nTape Cartridge\n\n");
	ptr += get_cartridge_info(ptr);
	ptr += sprintf(ptr, "\nHistory Record\n\n");
	ptr += get_history_info(ptr);

	len = strlen(page);
	*start = 0;
	if (off+count >= len) {
		*eof = 1;
	} else {
		*eof = 0;
	}
	return len;
}

int __init ftape_proc_init(void)
{
	return FT_PROC_REGISTER(&proc_root, &proc_ftape);
}

#ifdef MODULE
void ftape_proc_destroy(void)
{
	proc_unregister(&proc_root, proc_ftape.low_ino);
}
#endif

#endif /* defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS) */