aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/hisax/hisax_fcpcipnp.c
blob: dbcca287ee2c5b7dcffddd4684385918ac47361b (plain) (blame)
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
/*
 * Driver for AVM Fritz!PCI, Fritz!PCI v2, Fritz!PnP ISDN cards
 *
 * Author       Kai Germaschewski
 * Copyright    2001 by Kai Germaschewski  <kai.germaschewski@gmx.de>
 *              2001 by Karsten Keil       <keil@isdn4linux.de>
 * 
 * based upon Karsten Keil's original avm_pci.c driver
 *
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
 *
 * Thanks to Wizard Computersysteme GmbH, Bremervoerde and
 *           SoHaNet Technology GmbH, Berlin
 * for supporting the development of this driver
 */


/* TODO:
 *
 * o POWER PC
 * o clean up debugging
 * o tx_skb at PH_DEACTIVATE time
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/isapnp.h>
#include <linux/kmod.h>
#include <linux/slab.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/delay.h>

#include <asm/io.h>

#include "hisax_fcpcipnp.h"

// debugging cruft
#define __debug_variable debug
#include "hisax_debug.h"

#ifdef CONFIG_HISAX_DEBUG
static int debug = 0;
/* static int hdlcfifosize = 32; */
module_param(debug, int, 0);
/* module_param(hdlcfifosize, int, 0); */
#endif

MODULE_AUTHOR("Kai Germaschewski <kai.germaschewski@gmx.de>/Karsten Keil <kkeil@suse.de>");
MODULE_DESCRIPTION("AVM Fritz!PCI/PnP ISDN driver");

static struct pci_device_id fcpci_ids[] = {
	{ .vendor      = PCI_VENDOR_ID_AVM,
	  .device      = PCI_DEVICE_ID_AVM_A1,
	  .subvendor   = PCI_ANY_ID,
	  .subdevice   = PCI_ANY_ID,
	  .driver_data = (unsigned long) "Fritz!Card PCI",
	},
	{ .vendor      = PCI_VENDOR_ID_AVM,
	  .device      = PCI_DEVICE_ID_AVM_A1_V2,
	  .subvendor   = PCI_ANY_ID,
	  .subdevice   = PCI_ANY_ID,
	  .driver_data = (unsigned long) "Fritz!Card PCI v2" },
	{}
};

MODULE_DEVICE_TABLE(pci, fcpci_ids);

#ifdef __ISAPNP__
static struct pnp_device_id fcpnp_ids[] __devinitdata = {
	{ 
		.id		= "AVM0900",
		.driver_data	= (unsigned long) "Fritz!Card PnP",
	},
};

MODULE_DEVICE_TABLE(isapnp, fcpnp_ids);
#endif

static int protocol = 2;       /* EURO-ISDN Default */
module_param(protocol, int, 0);
MODULE_LICENSE("GPL");

// ----------------------------------------------------------------------

#define  AVM_INDEX              0x04
#define  AVM_DATA               0x10

#define	 AVM_IDX_HDLC_1		0x00
#define	 AVM_IDX_HDLC_2		0x01
#define	 AVM_IDX_ISAC_FIFO	0x02
#define	 AVM_IDX_ISAC_REG_LOW	0x04
#define	 AVM_IDX_ISAC_REG_HIGH	0x06

#define  AVM_STATUS0            0x02

#define  AVM_STATUS0_IRQ_ISAC	0x01
#define  AVM_STATUS0_IRQ_HDLC	0x02
#define  AVM_STATUS0_IRQ_TIMER	0x04
#define  AVM_STATUS0_IRQ_MASK	0x07

#define  AVM_STATUS0_RESET	0x01
#define  AVM_STATUS0_DIS_TIMER	0x02
#define  AVM_STATUS0_RES_TIMER	0x04
#define  AVM_STATUS0_ENA_IRQ	0x08
#define  AVM_STATUS0_TESTBIT	0x10

#define  AVM_STATUS1            0x03
#define  AVM_STATUS1_ENA_IOM	0x80

#define  HDLC_FIFO		0x0
#define  HDLC_STATUS		0x4
#define  HDLC_CTRL		0x4

#define  HDLC_MODE_ITF_FLG	0x01
#define  HDLC_MODE_TRANS	0x02
#define  HDLC_MODE_CCR_7	0x04
#define  HDLC_MODE_CCR_16	0x08
#define  HDLC_MODE_TESTLOOP	0x80

#define  HDLC_INT_XPR		0x80
#define  HDLC_INT_XDU		0x40
#define  HDLC_INT_RPR		0x20
#define  HDLC_INT_MASK		0xE0

#define  HDLC_STAT_RME		0x01
#define  HDLC_STAT_RDO		0x10
#define  HDLC_STAT_CRCVFRRAB	0x0E
#define  HDLC_STAT_CRCVFR	0x06
#define  HDLC_STAT_RML_MASK	0xff00

#define  HDLC_CMD_XRS		0x80
#define  HDLC_CMD_XME		0x01
#define  HDLC_CMD_RRS		0x20
#define  HDLC_CMD_XML_MASK	0xff00

#define  AVM_HDLC_FIFO_1        0x10
#define  AVM_HDLC_FIFO_2        0x18

#define  AVM_HDLC_STATUS_1      0x14
#define  AVM_HDLC_STATUS_2      0x1c

#define  AVM_ISACSX_INDEX       0x04
#define  AVM_ISACSX_DATA        0x08

// ----------------------------------------------------------------------
// Fritz!PCI

static unsigned char fcpci_read_isac(struct isac *isac, unsigned char offset)
{
	struct fritz_adapter *adapter = isac->priv;
	unsigned char idx = (offset > 0x2f) ? 
		AVM_IDX_ISAC_REG_HIGH : AVM_IDX_ISAC_REG_LOW;
	unsigned char val;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outb(idx, adapter->io + AVM_INDEX);
	val = inb(adapter->io + AVM_DATA + (offset & 0xf));
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
	DBG(0x1000, " port %#x, value %#x",
	    offset, val);
	return val;
}

static void fcpci_write_isac(struct isac *isac, unsigned char offset,
			     unsigned char value)
{
	struct fritz_adapter *adapter = isac->priv;
	unsigned char idx = (offset > 0x2f) ? 
		AVM_IDX_ISAC_REG_HIGH : AVM_IDX_ISAC_REG_LOW;
	unsigned long flags;

	DBG(0x1000, " port %#x, value %#x",
	    offset, value);
	spin_lock_irqsave(&adapter->hw_lock, flags);
	outb(idx, adapter->io + AVM_INDEX);
	outb(value, adapter->io + AVM_DATA + (offset & 0xf));
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

static void fcpci_read_isac_fifo(struct isac *isac, unsigned char * data, 
				 int size)
{
	struct fritz_adapter *adapter = isac->priv;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outb(AVM_IDX_ISAC_FIFO, adapter->io + AVM_INDEX);
	insb(adapter->io + AVM_DATA, data, size);
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

static void fcpci_write_isac_fifo(struct isac *isac, unsigned char * data, 
				  int size)
{
	struct fritz_adapter *adapter = isac->priv;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outb(AVM_IDX_ISAC_FIFO, adapter->io + AVM_INDEX);
	outsb(adapter->io + AVM_DATA, data, size);
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

static u32 fcpci_read_hdlc_status(struct fritz_adapter *adapter, int nr)
{
	u32 val;
	int idx = nr ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outl(idx, adapter->io + AVM_INDEX);
	val = inl(adapter->io + AVM_DATA + HDLC_STATUS);
	spin_unlock_irqrestore(&adapter->hw_lock, flags);
	return val;
}

static void __fcpci_write_ctrl(struct fritz_bcs *bcs, int which)
{
	struct fritz_adapter *adapter = bcs->adapter;
	int idx = bcs->channel ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;

	DBG(0x40, "hdlc %c wr%x ctrl %x",
	    'A' + bcs->channel, which, bcs->ctrl.ctrl);

	outl(idx, adapter->io + AVM_INDEX);
	outl(bcs->ctrl.ctrl, adapter->io + AVM_DATA + HDLC_CTRL);
}

static void fcpci_write_ctrl(struct fritz_bcs *bcs, int which)
{
	struct fritz_adapter *adapter = bcs->adapter;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	__fcpci_write_ctrl(bcs, which);
	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

// ----------------------------------------------------------------------
// Fritz!PCI v2

static unsigned char fcpci2_read_isac(struct isac *isac, unsigned char offset)
{
	struct fritz_adapter *adapter = isac->priv;
	unsigned char val;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outl(offset, adapter->io + AVM_ISACSX_INDEX);
	val = inl(adapter->io + AVM_ISACSX_DATA);
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
	DBG(0x1000, " port %#x, value %#x",
	    offset, val);

	return val;
}

static void fcpci2_write_isac(struct isac *isac, unsigned char offset, 
			      unsigned char value)
{
	struct fritz_adapter *adapter = isac->priv;
	unsigned long flags;

	DBG(0x1000, " port %#x, value %#x",
	    offset, value);
	spin_lock_irqsave(&adapter->hw_lock, flags);
	outl(offset, adapter->io + AVM_ISACSX_INDEX);
	outl(value, adapter->io + AVM_ISACSX_DATA);
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

static void fcpci2_read_isac_fifo(struct isac *isac, unsigned char * data, 
				  int size)
{
	struct fritz_adapter *adapter = isac->priv;
	int i;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outl(0, adapter->io + AVM_ISACSX_INDEX);
	for (i = 0; i < size; i++)
		data[i] = inl(adapter->io + AVM_ISACSX_DATA);
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

static void fcpci2_write_isac_fifo(struct isac *isac, unsigned char * data, 
				   int size)
{
	struct fritz_adapter *adapter = isac->priv;
	int i;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outl(0, adapter->io + AVM_ISACSX_INDEX);
	for (i = 0; i < size; i++)
		outl(data[i], adapter->io + AVM_ISACSX_DATA);
 	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

static u32 fcpci2_read_hdlc_status(struct fritz_adapter *adapter, int nr)
{
	int offset = nr ? AVM_HDLC_STATUS_2 : AVM_HDLC_STATUS_1;

	return inl(adapter->io + offset);
}

static void fcpci2_write_ctrl(struct fritz_bcs *bcs, int which)
{
	struct fritz_adapter *adapter = bcs->adapter;
	int offset = bcs->channel ? AVM_HDLC_STATUS_2 : AVM_HDLC_STATUS_1;

	DBG(0x40, "hdlc %c wr%x ctrl %x",
	    'A' + bcs->channel, which, bcs->ctrl.ctrl);

	outl(bcs->ctrl.ctrl, adapter->io + offset);
}

// ----------------------------------------------------------------------
// Fritz!PnP (ISAC access as for Fritz!PCI)

static u32 fcpnp_read_hdlc_status(struct fritz_adapter *adapter, int nr)
{
	unsigned char idx = nr ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;
	u32 val;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	outb(idx, adapter->io + AVM_INDEX);
	val = inb(adapter->io + AVM_DATA + HDLC_STATUS);
	if (val & HDLC_INT_RPR)
		val |= inb(adapter->io + AVM_DATA + HDLC_STATUS + 1) << 8;
	spin_unlock_irqrestore(&adapter->hw_lock, flags);
	return val;
}

static void __fcpnp_write_ctrl(struct fritz_bcs *bcs, int which)
{
	struct fritz_adapter *adapter = bcs->adapter;
	unsigned char idx = bcs->channel ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;

	DBG(0x40, "hdlc %c wr%x ctrl %x",
	    'A' + bcs->channel, which, bcs->ctrl.ctrl);

	outb(idx, adapter->io + AVM_INDEX);
	if (which & 4)
		outb(bcs->ctrl.sr.mode, 
		     adapter->io + AVM_DATA + HDLC_STATUS + 2);
	if (which & 2)
		outb(bcs->ctrl.sr.xml, 
		     adapter->io + AVM_DATA + HDLC_STATUS + 1);
	if (which & 1)
		outb(bcs->ctrl.sr.cmd,
		     adapter->io + AVM_DATA + HDLC_STATUS + 0);
}

static void fcpnp_write_ctrl(struct fritz_bcs *bcs, int which)
{
	struct fritz_adapter *adapter = bcs->adapter;
	unsigned long flags;

	spin_lock_irqsave(&adapter->hw_lock, flags);
	__fcpnp_write_ctrl(bcs, which);
	spin_unlock_irqrestore(&adapter->hw_lock, flags);
}

// ----------------------------------------------------------------------

static inline void B_L1L2(struct fritz_bcs *bcs, int pr, void *arg)
{
	struct hisax_if *ifc = (struct hisax_if *) &bcs->b_if;

	DBG(2, "pr %#x", pr);
	ifc->l1l2(ifc, pr, arg);
}

static void hdlc_fill_fifo(struct fritz_bcs *bcs)
{
	struct fritz_adapter *adapter = bcs->adapter;
	struct sk_buff *skb = bcs->tx_skb;
	int count;
	unsigned long flags;
	unsigned char *p;

	DBG(0x40, "hdlc_fill_fifo");

	BUG_ON(skb->len == 0);

	bcs->ctrl.sr.cmd &= ~HDLC_CMD_XME;
	if (bcs->tx_skb->len > bcs->fifo_size) {
		count = bcs->fifo_size;
	} else {
		count = bcs->tx_skb->len;
		if (bcs->mode != L1_MODE_TRANS)
			bcs->ctrl.sr.cmd |= HDLC_CMD_XME;
	}
	DBG(0x40, "hdlc_fill_fifo %d/%d", count, bcs->tx_skb->len);
	p = bcs->tx_skb->data;
	skb_pull(bcs->tx_skb, count);
	bcs->tx_cnt += count;
	bcs->ctrl.sr.xml = ((count == bcs->fifo_size) ? 0 : count);

	switch (adapter->type) {
	case AVM_FRITZ_PCI:
		spin_lock_irqsave(&adapter->hw_lock, flags);
		// sets the correct AVM_INDEX, too
		__fcpci_write_ctrl(bcs, 3);
		outsl(adapter->io + AVM_DATA + HDLC_FIFO,
		      p, (count + 3) / 4);
		spin_unlock_irqrestore(&adapter->hw_lock, flags);
		break;
	case AVM_FRITZ_PCIV2:
		fcpci2_write_ctrl(bcs, 3);
		outsl(adapter->io + 
		      (bcs->channel ? AVM_HDLC_FIFO_2 : AVM_HDLC_FIFO_1),
		      p, (count + 3) / 4);
		break;
	case AVM_FRITZ_PNP:
		spin_lock_irqsave(&adapter->hw_lock, flags);
		// sets the correct AVM_INDEX, too
		__fcpnp_write_ctrl(bcs, 3);
		outsb(adapter->io + AVM_DATA, p, count);
		spin_unlock_irqrestore(&adapter->hw_lock, flags);
		break;
	}
}

static inline void hdlc_empty_fifo(struct fritz_bcs *bcs, int count)
{
	struct fritz_adapter *adapter = bcs->adapter;
	unsigned char *p;
	unsigned char idx = bcs->channel ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;

	DBG(0x10, "hdlc_empty_fifo %d", count);
	if (bcs->rcvidx + count > HSCX_BUFMAX) {
		DBG(0x10, "hdlc_empty_fifo: incoming packet too large");
		return;
	}
	p = bcs->rcvbuf + bcs->rcvidx;
	bcs->rcvidx += count;
	switch (adapter->type) {
	case AVM_FRITZ_PCI:
		spin_lock(&adapter->hw_lock);
		outl(idx, adapter->io + AVM_INDEX);
		insl(adapter->io + AVM_DATA + HDLC_FIFO, 
		     p, (count + 3) / 4);
		spin_unlock(&adapter->hw_lock);
		break;
	case AVM_FRITZ_PCIV2:
		insl(adapter->io + 
		     (bcs->channel ? AVM_HDLC_FIFO_2 : AVM_HDLC_FIFO_1),
		     p, (count + 3) / 4);
		break;
	case AVM_FRITZ_PNP:
		spin_lock(&adapter->hw_lock);
		outb(idx, adapter->io + AVM_INDEX);
		insb(adapter->io + AVM_DATA, p, count);
		spin_unlock(&adapter->hw_lock);
		break;
	}
}

static inline void hdlc_rpr_irq(struct fritz_bcs *bcs, u32 stat)
{
	struct fritz_adapter *adapter = bcs->adapter;
	struct sk_buff *skb;
	int len;

	if (stat & HDLC_STAT_RDO) {
		DBG(0x10, "RDO");
		bcs->ctrl.sr.xml = 0;
		bcs->ctrl.sr.cmd |= HDLC_CMD_RRS;
		adapter->write_ctrl(bcs, 1);
		bcs->ctrl.sr.cmd &= ~HDLC_CMD_RRS;
		adapter->write_ctrl(bcs, 1);
		bcs->rcvidx = 0;
		return;
	}

	len = (stat & HDLC_STAT_RML_MASK) >> 8;
	if (len == 0)
		len = bcs->fifo_size;

	hdlc_empty_fifo(bcs, len);

	if ((stat & HDLC_STAT_RME) || (bcs->mode == L1_MODE_TRANS)) {
		if (((stat & HDLC_STAT_CRCVFRRAB)== HDLC_STAT_CRCVFR) ||
		    (bcs->mode == L1_MODE_TRANS)) {
			skb = dev_alloc_skb(bcs->rcvidx);
			if (!skb) {
				printk(KERN_WARNING "HDLC: receive out of memory\n");
			} else {
				memcpy(skb_put(skb, bcs->rcvidx), bcs->rcvbuf,
				       bcs->rcvidx);
				DBG_SKB(1, skb);
				B_L1L2(bcs, PH_DATA | INDICATION, skb);
			}
			bcs->rcvidx = 0;
		} else {
			DBG(0x10, "ch%d invalid frame %#x",
			    bcs->channel, stat);
			bcs->rcvidx = 0;
		}
	}
}

static inline void hdlc_xdu_irq(struct fritz_bcs *bcs)
{
	struct fritz_adapter *adapter = bcs->adapter;
	

	/* Here we lost an TX interrupt, so
	 * restart transmitting the whole frame.
	 */
	bcs->ctrl.sr.xml = 0;
	bcs->ctrl.sr.cmd |= HDLC_CMD_XRS;
	adapter->write_ctrl(bcs, 1);
	bcs->ctrl.sr.cmd &= ~HDLC_CMD_XRS;

	if (!bcs->tx_skb) {
		DBG(0x10, "XDU without skb");
		adapter->write_ctrl(bcs, 1);
		return;
	}
	/* only hdlc restarts the frame, transparent mode must continue */
	if (bcs->mode == L1_MODE_HDLC) {
		skb_push(bcs->tx_skb, bcs->tx_cnt);
		bcs->tx_cnt = 0;
	}
}

static inline void hdlc_xpr_irq(struct fritz_bcs *bcs)
{
	struct sk_buff *skb;

	skb = bcs->tx_skb;
	if (!skb)
		return;

	if (skb->len) {
		hdlc_fill_fifo(bcs);
		return;
	}
	bcs->tx_cnt = 0;
	bcs->tx_skb = NULL;
	B_L1L2(bcs, PH_DATA | CONFIRM, (void *) skb->truesize);
	dev_kfree_skb_irq(skb);
}

static void hdlc_irq_one(struct fritz_bcs *bcs, u32 stat)
{
	DBG(0x10, "ch%d stat %#x", bcs->channel, stat);
	if (stat & HDLC_INT_RPR) {
		DBG(0x10, "RPR");
		hdlc_rpr_irq(bcs, stat);
	}
	if (stat & HDLC_INT_XDU) {
		DBG(0x10, "XDU");
		hdlc_xdu_irq(bcs);
		hdlc_xpr_irq(bcs);
		return;
	}
	if (stat & HDLC_INT_XPR) {
		DBG(0x10, "XPR");
		hdlc_xpr_irq(bcs);
	}
}

static inline void hdlc_irq(struct fritz_adapter *adapter)
{
	int nr;
	u32 stat;

	for (nr = 0; nr < 2; nr++) {
		stat = adapter->read_hdlc_status(adapter, nr);
		DBG(0x10, "HDLC %c stat %#x", 'A' + nr, stat);
		if (stat & HDLC_INT_MASK)
			hdlc_irq_one(&adapter->bcs[nr], stat);
	}
}

static void modehdlc(struct fritz_bcs *bcs, int mode)
{
	struct fritz_adapter *adapter = bcs->adapter;
	
	DBG(0x40, "hdlc %c mode %d --> %d",
	    'A' + bcs->channel, bcs->mode, mode);

	if (bcs->mode == mode)
		return;

	bcs->fifo_size = 32;
	bcs->ctrl.ctrl = 0;
	bcs->ctrl.sr.cmd  = HDLC_CMD_XRS | HDLC_CMD_RRS;
	switch (mode) {
	case L1_MODE_NULL:
		bcs->ctrl.sr.mode = HDLC_MODE_TRANS;
		adapter->write_ctrl(bcs, 5);
		break;
	case L1_MODE_TRANS:
	case L1_MODE_HDLC:
		bcs->rcvidx = 0;
		bcs->tx_cnt = 0;
		bcs->tx_skb = NULL;
		if (mode == L1_MODE_TRANS) {
			bcs->ctrl.sr.mode = HDLC_MODE_TRANS;
		} else {
			bcs->ctrl.sr.mode = HDLC_MODE_ITF_FLG;
		}
		adapter->write_ctrl(bcs, 5);
		bcs->ctrl.sr.cmd = HDLC_CMD_XRS;
		adapter->write_ctrl(bcs, 1);
		bcs->ctrl.sr.cmd = 0;
		break;
	}
	bcs->mode = mode;
}

static void fritz_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
{
	struct fritz_bcs *bcs = ifc->priv;
	struct sk_buff *skb = arg;
	int mode;

	DBG(0x10, "pr %#x", pr);

	switch (pr) {
	case PH_DATA | REQUEST:
		BUG_ON(bcs->tx_skb);
		bcs->tx_skb = skb;
		DBG_SKB(1, skb);
		hdlc_fill_fifo(bcs);
		break;
	case PH_ACTIVATE | REQUEST:
		mode = (int) arg;
		DBG(4,"B%d,PH_ACTIVATE_REQUEST %d", bcs->channel + 1, mode);
		modehdlc(bcs, mode);
		B_L1L2(bcs, PH_ACTIVATE | INDICATION, NULL);
		break;
	case PH_DEACTIVATE | REQUEST:
		DBG(4,"B%d,PH_DEACTIVATE_REQUEST", bcs->channel + 1);
		modehdlc(bcs, L1_MODE_NULL);
		B_L1L2(bcs, PH_DEACTIVATE | INDICATION, NULL);
		break;
	}
}

// ----------------------------------------------------------------------

static irqreturn_t
fcpci2_irq(int intno, void *dev, struct pt_regs *regs)
{
	struct fritz_adapter *adapter = dev;
	unsigned char val;

	val = inb(adapter->io + AVM_STATUS0);
	if (!(val & AVM_STATUS0_IRQ_MASK))
		/* hopefully a shared  IRQ reqest */
		return IRQ_NONE;
	DBG(2, "STATUS0 %#x", val);
	if (val & AVM_STATUS0_IRQ_ISAC)
		isacsx_irq(&adapter->isac);
	if (val & AVM_STATUS0_IRQ_HDLC)
		hdlc_irq(adapter);
	if (val & AVM_STATUS0_IRQ_ISAC)
		isacsx_irq(&adapter->isac);
	return IRQ_HANDLED;
}

static irqreturn_t
fcpci_irq(int intno, void *dev, struct pt_regs *regs)
{
	struct fritz_adapter *adapter = dev;
	unsigned char sval;

	sval = inb(adapter->io + 2);
	if ((sval & AVM_STATUS0_IRQ_MASK) == AVM_STATUS0_IRQ_MASK)
		/* possibly a shared  IRQ reqest */
		return IRQ_NONE;
	DBG(2, "sval %#x", sval);
	if (!(sval & AVM_STATUS0_IRQ_ISAC))
		isac_irq(&adapter->isac);

	if (!(sval & AVM_STATUS0_IRQ_HDLC))
		hdlc_irq(adapter);
	return IRQ_HANDLED;
}

// ----------------------------------------------------------------------

static inline void fcpci2_init(struct fritz_adapter *adapter)
{
	outb(AVM_STATUS0_RES_TIMER, adapter->io + AVM_STATUS0);
	outb(AVM_STATUS0_ENA_IRQ, adapter->io + AVM_STATUS0);

}

static inline void fcpci_init(struct fritz_adapter *adapter)
{
	outb(AVM_STATUS0_DIS_TIMER | AVM_STATUS0_RES_TIMER | 
	     AVM_STATUS0_ENA_IRQ, adapter->io + AVM_STATUS0);

	outb(AVM_STATUS1_ENA_IOM | adapter->irq, 
	     adapter->io + AVM_STATUS1);
	mdelay(10);
}

// ----------------------------------------------------------------------

static int __devinit fcpcipnp_setup(struct fritz_adapter *adapter)
{
	u32 val = 0;
	int retval;

	DBG(1,"");

	isac_init(&adapter->isac); // FIXME is this okay now

	retval = -EBUSY;
	if (!request_region(adapter->io, 32, "fcpcipnp"))
		goto err;

	switch (adapter->type) {
	case AVM_FRITZ_PCIV2:
		retval = request_irq(adapter->irq, fcpci2_irq, SA_SHIRQ, 
				     "fcpcipnp", adapter);
		break;
	case AVM_FRITZ_PCI:
		retval = request_irq(adapter->irq, fcpci_irq, SA_SHIRQ,
				     "fcpcipnp", adapter);
		break;
	case AVM_FRITZ_PNP:
		retval = request_irq(adapter->irq, fcpci_irq, 0,
				     "fcpcipnp", adapter);
		break;
	}
	if (retval)
		goto err_region;

	switch (adapter->type) {
	case AVM_FRITZ_PCIV2:
	case AVM_FRITZ_PCI:
		val = inl(adapter->io);
		break;
	case AVM_FRITZ_PNP:
		val = inb(adapter->io);
		val |= inb(adapter->io + 1) << 8;
		break;
	}

	DBG(1, "stat %#x Class %X Rev %d",
	    val, val & 0xff, (val>>8) & 0xff);

	spin_lock_init(&adapter->hw_lock);
	adapter->isac.priv = adapter;
	switch (adapter->type) {
	case AVM_FRITZ_PCIV2:
		adapter->isac.read_isac       = &fcpci2_read_isac;
		adapter->isac.write_isac      = &fcpci2_write_isac;
		adapter->isac.read_isac_fifo  = &fcpci2_read_isac_fifo;
		adapter->isac.write_isac_fifo = &fcpci2_write_isac_fifo;

		adapter->read_hdlc_status     = &fcpci2_read_hdlc_status;
		adapter->write_ctrl           = &fcpci2_write_ctrl;
		break;
	case AVM_FRITZ_PCI:
		adapter->isac.read_isac       = &fcpci_read_isac;
		adapter->isac.write_isac      = &fcpci_write_isac;
		adapter->isac.read_isac_fifo  = &fcpci_read_isac_fifo;
		adapter->isac.write_isac_fifo = &fcpci_write_isac_fifo;

		adapter->read_hdlc_status     = &fcpci_read_hdlc_status;
		adapter->write_ctrl           = &fcpci_write_ctrl;
		break;
	case AVM_FRITZ_PNP:
		adapter->isac.read_isac       = &fcpci_read_isac;
		adapter->isac.write_isac      = &fcpci_write_isac;
		adapter->isac.read_isac_fifo  = &fcpci_read_isac_fifo;
		adapter->isac.write_isac_fifo = &fcpci_write_isac_fifo;

		adapter->read_hdlc_status     = &fcpnp_read_hdlc_status;
		adapter->write_ctrl           = &fcpnp_write_ctrl;
		break;
	}

	// Reset
	outb(0, adapter->io + AVM_STATUS0);
	mdelay(10);
	outb(AVM_STATUS0_RESET, adapter->io + AVM_STATUS0);
	mdelay(10);
	outb(0, adapter->io + AVM_STATUS0);
	mdelay(10);

	switch (adapter->type) {
	case AVM_FRITZ_PCIV2:
		fcpci2_init(adapter);
		isacsx_setup(&adapter->isac);
		break;
	case AVM_FRITZ_PCI:
	case AVM_FRITZ_PNP:
		fcpci_init(adapter);
		isac_setup(&adapter->isac);
		break;
	}
	val = adapter->read_hdlc_status(adapter, 0);
	DBG(0x20, "HDLC A STA %x", val);
	val = adapter->read_hdlc_status(adapter, 1);
	DBG(0x20, "HDLC B STA %x", val);

	adapter->bcs[0].mode = -1;
	adapter->bcs[1].mode = -1;
	modehdlc(&adapter->bcs[0], L1_MODE_NULL);
	modehdlc(&adapter->bcs[1], L1_MODE_NULL);

	return 0;

 err_region:
	release_region(adapter->io, 32);
 err:
	return retval;
}

static void __devexit fcpcipnp_release(struct fritz_adapter *adapter)
{
	DBG(1,"");

	outb(0, adapter->io + AVM_STATUS0);
	free_irq(adapter->irq, adapter);
	release_region(adapter->io, 32);
}

// ----------------------------------------------------------------------

static struct fritz_adapter * __devinit 
new_adapter(void)
{
	struct fritz_adapter *adapter;
	struct hisax_b_if *b_if[2];
	int i;

	adapter = kmalloc(sizeof(struct fritz_adapter), GFP_KERNEL);
	if (!adapter)
		return NULL;

	memset(adapter, 0, sizeof(struct fritz_adapter));

	adapter->isac.hisax_d_if.owner = THIS_MODULE;
	adapter->isac.hisax_d_if.ifc.priv = &adapter->isac;
	adapter->isac.hisax_d_if.ifc.l2l1 = isac_d_l2l1;
	
	for (i = 0; i < 2; i++) {
		adapter->bcs[i].adapter = adapter;
		adapter->bcs[i].channel = i;
		adapter->bcs[i].b_if.ifc.priv = &adapter->bcs[i];
		adapter->bcs[i].b_if.ifc.l2l1 = fritz_b_l2l1;
	}

	for (i = 0; i < 2; i++)
		b_if[i] = &adapter->bcs[i].b_if;

	hisax_register(&adapter->isac.hisax_d_if, b_if, "fcpcipnp", protocol);

	return adapter;
}

static void delete_adapter(struct fritz_adapter *adapter)
{
	hisax_unregister(&adapter->isac.hisax_d_if);
	kfree(adapter);
}

static int __devinit fcpci_probe(struct pci_dev *pdev,
				 const struct pci_device_id *ent)
{
	struct fritz_adapter *adapter;
	int retval;

	retval = -ENOMEM;
	adapter = new_adapter();
	if (!adapter)
		goto err;

	pci_set_drvdata(pdev, adapter);

	if (pdev->device == PCI_DEVICE_ID_AVM_A1_V2) 
		adapter->type = AVM_FRITZ_PCIV2;
	else
		adapter->type = AVM_FRITZ_PCI;

	retval = pci_enable_device(pdev);
	if (retval)
		goto err_free;

	adapter->io = pci_resource_start(pdev, 1);
	adapter->irq = pdev->irq;

	printk(KERN_INFO "hisax_fcpcipnp: found adapter %s at %s\n",
	       (char *) ent->driver_data, pci_name(pdev));

	retval = fcpcipnp_setup(adapter);
	if (retval)
		goto err_free;

	return 0;
	
 err_free:
	delete_adapter(adapter);
 err:
	return retval;
}

#ifdef __ISAPNP__
static int __devinit fcpnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
{
	struct fritz_adapter *adapter;
	int retval;

	if (!pdev)
		return(-ENODEV);

	retval = -ENOMEM;
	adapter = new_adapter();
	if (!adapter)
		goto err;

	pnp_set_drvdata(pdev, adapter);

	adapter->type = AVM_FRITZ_PNP;

	pnp_disable_dev(pdev);
	retval = pnp_activate_dev(pdev);
	if (retval < 0) {
		printk(KERN_WARNING "%s: pnp_activate_dev(%s) ret(%d)\n", __FUNCTION__,
			(char *)dev_id->driver_data, retval);
		goto err_free;
	}
	adapter->io = pnp_port_start(pdev, 0);
	adapter->irq = pnp_irq(pdev, 0);

	printk(KERN_INFO "hisax_fcpcipnp: found adapter %s at IO %#x irq %d\n",
	       (char *) dev_id->driver_data, adapter->io, adapter->irq);

	retval = fcpcipnp_setup(adapter);
	if (retval)
		goto err_free;

	return 0;
	
 err_free:
	delete_adapter(adapter);
 err:
	return retval;
}

static void __devexit fcpnp_remove(struct pnp_dev *pdev)
{
	struct fritz_adapter *adapter = pnp_get_drvdata(pdev);

	if (adapter) {
		fcpcipnp_release(adapter);
		delete_adapter(adapter);
	}
	pnp_disable_dev(pdev);
}

static struct pnp_driver fcpnp_driver = {
	.name		= "fcpnp",
	.probe		= fcpnp_probe,
	.remove		= __devexit_p(fcpnp_remove),
	.id_table	= fcpnp_ids,
};
#endif

static void __devexit fcpci_remove(struct pci_dev *pdev)
{
	struct fritz_adapter *adapter = pci_get_drvdata(pdev);

	fcpcipnp_release(adapter);
	pci_disable_device(pdev);
	delete_adapter(adapter);
}

static struct pci_driver fcpci_driver = {
	.name		= "fcpci",
	.probe		= fcpci_probe,
	.remove		= __devexit_p(fcpci_remove),
	.id_table	= fcpci_ids,
};

static int __init hisax_fcpcipnp_init(void)
{
	int retval;

	printk(KERN_INFO "hisax_fcpcipnp: Fritz!Card PCI/PCIv2/PnP ISDN driver v0.0.1\n");

	retval = pci_register_driver(&fcpci_driver);
	if (retval)
		goto out;
#ifdef __ISAPNP__
	retval = pnp_register_driver(&fcpnp_driver);
	if (retval < 0)
		goto out_unregister_pci;
#endif
	return 0;

 out_unregister_pci:
	pci_unregister_driver(&fcpci_driver);
 out:
	return retval;
}

static void __exit hisax_fcpcipnp_exit(void)
{
#ifdef __ISAPNP__
	pnp_unregister_driver(&fcpnp_driver);
#endif
	pci_unregister_driver(&fcpci_driver);
}

module_init(hisax_fcpcipnp_init);
module_exit(hisax_fcpcipnp_exit);
n> unsigned long arg) { struct net_device *dev; struct ifreq32 ifr32; int err; if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32))) return -EFAULT; dev = dev_get_by_index(ifr32.ifr_ifindex); if (!dev) return -ENODEV; strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name)); dev_put(dev); err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32)); return (err ? -EFAULT : 0); } static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ifconf32 ifc32; struct ifconf ifc; struct ifconf __user *uifc; struct ifreq32 __user *ifr32; struct ifreq __user *ifr; unsigned int i, j; int err; if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32))) return -EFAULT; if (ifc32.ifcbuf == 0) { ifc32.ifc_len = 0; ifc.ifc_len = 0; ifc.ifc_req = NULL; uifc = compat_alloc_user_space(sizeof(struct ifconf)); } else { size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) * sizeof (struct ifreq); uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); ifc.ifc_len = len; ifr = ifc.ifc_req = (void __user *)(uifc + 1); ifr32 = compat_ptr(ifc32.ifcbuf); for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) { if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32))) return -EFAULT; ifr++; ifr32++; } } if (copy_to_user(uifc, &ifc, sizeof(struct ifconf))) return -EFAULT; err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc); if (err) return err; if (copy_from_user(&ifc, uifc, sizeof(struct ifconf))) return -EFAULT; ifr = ifc.ifc_req; ifr32 = compat_ptr(ifc32.ifcbuf); for (i = 0, j = 0; i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len; i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) { if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32))) return -EFAULT; ifr32++; ifr++; } if (ifc32.ifcbuf == 0) { /* Translate from 64-bit structure multiple to * a 32-bit one. */ i = ifc.ifc_len; i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32)); ifc32.ifc_len = i; } else { ifc32.ifc_len = i; } if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32))) return -EFAULT; return 0; } static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ifreq __user *ifr; struct ifreq32 __user *ifr32; u32 data; void __user *datap; ifr = compat_alloc_user_space(sizeof(*ifr)); ifr32 = compat_ptr(arg); if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) return -EFAULT; if (get_user(data, &ifr32->ifr_ifru.ifru_data)) return -EFAULT; datap = compat_ptr(data); if (put_user(datap, &ifr->ifr_ifru.ifru_data)) return -EFAULT; return sys_ioctl(fd, cmd, (unsigned long) ifr); } static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ifreq kifr; struct ifreq __user *uifr; struct ifreq32 __user *ifr32 = compat_ptr(arg); mm_segment_t old_fs; int err; u32 data; void __user *datap; switch (cmd) { case SIOCBONDENSLAVE: case SIOCBONDRELEASE: case SIOCBONDSETHWADDR: case SIOCBONDCHANGEACTIVE: if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32))) return -EFAULT; old_fs = get_fs(); set_fs (KERNEL_DS); err = sys_ioctl (fd, cmd, (unsigned long)&kifr); set_fs (old_fs); return err; case SIOCBONDSLAVEINFOQUERY: case SIOCBONDINFOQUERY: uifr = compat_alloc_user_space(sizeof(*uifr)); if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) return -EFAULT; if (get_user(data, &ifr32->ifr_ifru.ifru_data)) return -EFAULT; datap = compat_ptr(data); if (put_user(datap, &uifr->ifr_ifru.ifru_data)) return -EFAULT; return sys_ioctl (fd, cmd, (unsigned long)uifr); default: return -EINVAL; }; } int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ifreq __user *u_ifreq64; struct ifreq32 __user *u_ifreq32 = compat_ptr(arg); char tmp_buf[IFNAMSIZ]; void __user *data64; u32 data32; if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]), IFNAMSIZ)) return -EFAULT; if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data)) return -EFAULT; data64 = compat_ptr(data32); u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64)); /* Don't check these user accesses, just let that get trapped * in the ioctl handler instead. */ if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], IFNAMSIZ)) return -EFAULT; if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data)) return -EFAULT; return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64); } static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ifreq ifr; struct ifreq32 __user *uifr32; struct ifmap32 __user *uifmap32; mm_segment_t old_fs; int err; uifr32 = compat_ptr(arg); uifmap32 = &uifr32->ifr_ifru.ifru_map; switch (cmd) { case SIOCSIFMAP: err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name)); err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq); err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma); err |= __get_user(ifr.ifr_map.port, &uifmap32->port); if (err) return -EFAULT; break; default: if (copy_from_user(&ifr, uifr32, sizeof(*uifr32))) return -EFAULT; break; } old_fs = get_fs(); set_fs (KERNEL_DS); err = sys_ioctl (fd, cmd, (unsigned long)&ifr); set_fs (old_fs); if (!err) { switch (cmd) { /* TUNSETIFF is defined as _IOW, it should be _IORW * as the data is copied back to user space, but that * cannot be fixed without breaking all existing apps. */ case TUNSETIFF: case SIOCGIFFLAGS: case SIOCGIFMETRIC: case SIOCGIFMTU: case SIOCGIFMEM: case SIOCGIFHWADDR: case SIOCGIFINDEX: case SIOCGIFADDR: case SIOCGIFBRDADDR: case SIOCGIFDSTADDR: case SIOCGIFNETMASK: case SIOCGIFTXQLEN: if (copy_to_user(uifr32, &ifr, sizeof(*uifr32))) return -EFAULT; break; case SIOCGIFMAP: err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name)); err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq); err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma); err |= __put_user(ifr.ifr_map.port, &uifmap32->port); if (err) err = -EFAULT; break; } } return err; } struct rtentry32 { u32 rt_pad1; struct sockaddr rt_dst; /* target address */ struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ struct sockaddr rt_genmask; /* target network mask (IP) */ unsigned short rt_flags; short rt_pad2; u32 rt_pad3; unsigned char rt_tos; unsigned char rt_class; short rt_pad4; short rt_metric; /* +1 for binary compatibility! */ /* char * */ u32 rt_dev; /* forcing the device at add */ u32 rt_mtu; /* per route MTU/Window */ u32 rt_window; /* Window clamping */ unsigned short rt_irtt; /* Initial RTT */ }; struct in6_rtmsg32 { struct in6_addr rtmsg_dst; struct in6_addr rtmsg_src; struct in6_addr rtmsg_gateway; u32 rtmsg_type; u16 rtmsg_dst_len; u16 rtmsg_src_len; u32 rtmsg_metric; u32 rtmsg_info; u32 rtmsg_flags; s32 rtmsg_ifindex; }; static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { int ret; void *r = NULL; struct in6_rtmsg r6; struct rtentry r4; char devname[16]; u32 rtdev; mm_segment_t old_fs = get_fs(); struct socket *mysock = sockfd_lookup(fd, &ret); if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */ struct in6_rtmsg32 __user *ur6 = compat_ptr(arg); ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst), 3 * sizeof(struct in6_addr)); ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type)); ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric)); ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info)); ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags)); ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); r = (void *) &r6; } else { /* ipv4 */ struct rtentry32 __user *ur4 = compat_ptr(arg); ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst), 3 * sizeof(struct sockaddr)); ret |= __get_user (r4.rt_flags, &(ur4->rt_flags)); ret |= __get_user (r4.rt_metric, &(ur4->rt_metric)); ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu)); ret |= __get_user (r4.rt_window, &(ur4->rt_window)); ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt)); ret |= __get_user (rtdev, &(ur4->rt_dev)); if (rtdev) { ret |= copy_from_user (devname, compat_ptr(rtdev), 15); r4.rt_dev = devname; devname[15] = 0; } else r4.rt_dev = NULL; r = (void *) &r4; } if (ret) { ret = -EFAULT; goto out; } set_fs (KERNEL_DS); ret = sys_ioctl (fd, cmd, (unsigned long) r); set_fs (old_fs); out: if (mysock) sockfd_put(mysock); return ret; } #endif struct hd_geometry32 { unsigned char heads; unsigned char sectors; unsigned short cylinders; u32 start; }; static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); struct hd_geometry geo; struct hd_geometry32 __user *ugeo; int err; set_fs (KERNEL_DS); err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo); set_fs (old_fs); ugeo = compat_ptr(arg); if (!err) { err = copy_to_user (ugeo, &geo, 4); err |= __put_user (geo.start, &ugeo->start); } return err ? -EFAULT : 0; } static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); unsigned long kval; unsigned int __user *uvp; int error; set_fs(KERNEL_DS); error = sys_ioctl(fd, cmd, (long)&kval); set_fs(old_fs); if(error == 0) { uvp = compat_ptr(arg); if(put_user(kval, uvp)) error = -EFAULT; } return error; } typedef struct sg_io_hdr32 { compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ compat_int_t dxfer_direction; /* [i] data transfer direction */ unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ unsigned char mx_sb_len; /* [i] max length to write to sbp */ unsigned short iovec_count; /* [i] 0 implies no scatter gather */ compat_uint_t dxfer_len; /* [i] byte count of data transfer */ compat_uint_t dxferp; /* [i], [*io] points to data transfer memory or scatter gather list */ compat_uptr_t cmdp; /* [i], [*i] points to command to perform */ compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */ compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */ compat_int_t pack_id; /* [i->o] unused internally (normally) */ compat_uptr_t usr_ptr; /* [i->o] unused internally */ unsigned char status; /* [o] scsi status */ unsigned char masked_status; /* [o] shifted, masked scsi status */ unsigned char msg_status; /* [o] messaging level data (optional) */ unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ unsigned short host_status; /* [o] errors from host adapter */ unsigned short driver_status; /* [o] errors from software driver */ compat_int_t resid; /* [o] dxfer_len - actual_transferred */ compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */ compat_uint_t info; /* [o] auxiliary information */ } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */ typedef struct sg_iovec32 { compat_uint_t iov_base; compat_uint_t iov_len; } sg_iovec32_t; static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count) { sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1); sg_iovec32_t __user *iov32 = dxferp; int i; for (i = 0; i < iovec_count; i++) { u32 base, len; if (get_user(base, &iov32[i].iov_base) || get_user(len, &iov32[i].iov_len) || put_user(compat_ptr(base), &iov[i].iov_base) || put_user(len, &iov[i].iov_len)) return -EFAULT; } if (put_user(iov, &sgio->dxferp)) return -EFAULT; return 0; } static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { sg_io_hdr_t __user *sgio; sg_io_hdr32_t __user *sgio32; u16 iovec_count; u32 data; void __user *dxferp; int err; sgio32 = compat_ptr(arg); if (get_user(iovec_count, &sgio32->iovec_count)) return -EFAULT; { void __user *top = compat_alloc_user_space(0); void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) + (iovec_count * sizeof(sg_iovec_t))); if (new > top) return -EINVAL; sgio = new; } /* Ok, now construct. */ if (copy_in_user(&sgio->interface_id, &sgio32->interface_id, (2 * sizeof(int)) + (2 * sizeof(unsigned char)) + (1 * sizeof(unsigned short)) + (1 * sizeof(unsigned int)))) return -EFAULT; if (get_user(data, &sgio32->dxferp)) return -EFAULT; dxferp = compat_ptr(data); if (iovec_count) { if (sg_build_iovec(sgio, dxferp, iovec_count)) return -EFAULT; } else { if (put_user(dxferp, &sgio->dxferp)) return -EFAULT; } { unsigned char __user *cmdp; unsigned char __user *sbp; if (get_user(data, &sgio32->cmdp)) return -EFAULT; cmdp = compat_ptr(data); if (get_user(data, &sgio32->sbp)) return -EFAULT; sbp = compat_ptr(data); if (put_user(cmdp, &sgio->cmdp) || put_user(sbp, &sgio->sbp)) return -EFAULT; } if (copy_in_user(&sgio->timeout, &sgio32->timeout, 3 * sizeof(int))) return -EFAULT; if (get_user(data, &sgio32->usr_ptr)) return -EFAULT; if (put_user(compat_ptr(data), &sgio->usr_ptr)) return -EFAULT; if (copy_in_user(&sgio->status, &sgio32->status, (4 * sizeof(unsigned char)) + (2 * sizeof(unsigned (short))) + (3 * sizeof(int)))) return -EFAULT; err = sys_ioctl(fd, cmd, (unsigned long) sgio); if (err >= 0) { void __user *datap; if (copy_in_user(&sgio32->pack_id, &sgio->pack_id, sizeof(int)) || get_user(datap, &sgio->usr_ptr) || put_user((u32)(unsigned long)datap, &sgio32->usr_ptr) || copy_in_user(&sgio32->status, &sgio->status, (4 * sizeof(unsigned char)) + (2 * sizeof(unsigned short)) + (3 * sizeof(int)))) err = -EFAULT; } return err; } struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */ char req_state; char orphan; char sg_io_owned; char problem; int pack_id; compat_uptr_t usr_ptr; unsigned int duration; int unused; }; static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { int err, i; sg_req_info_t __user *r; struct compat_sg_req_info __user *o = (void __user *)arg; r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE); err = sys_ioctl(fd,cmd,(unsigned long)r); if (err < 0) return err; for (i = 0; i < SG_MAX_QUEUE; i++) { void __user *ptr; int d; if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) || get_user(ptr, &r[i].usr_ptr) || get_user(d, &r[i].duration) || put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) || put_user(d, &o[i].duration)) return -EFAULT; } return err; } struct sock_fprog32 { unsigned short len; compat_caddr_t filter; }; #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32) #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32) static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg); struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog)); void __user *fptr64; u32 fptr32; u16 flen; if (get_user(flen, &u_fprog32->len) || get_user(fptr32, &u_fprog32->filter)) return -EFAULT; fptr64 = compat_ptr(fptr32); if (put_user(flen, &u_fprog64->len) || put_user(fptr64, &u_fprog64->filter)) return -EFAULT; if (cmd == PPPIOCSPASS32) cmd = PPPIOCSPASS; else cmd = PPPIOCSACTIVE; return sys_ioctl(fd, cmd, (unsigned long) u_fprog64); } struct ppp_option_data32 { compat_caddr_t ptr; u32 length; compat_int_t transmit; }; #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32) struct ppp_idle32 { compat_time_t xmit_idle; compat_time_t recv_idle; }; #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32) static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ppp_idle __user *idle; struct ppp_idle32 __user *idle32; __kernel_time_t xmit, recv; int err; idle = compat_alloc_user_space(sizeof(*idle)); idle32 = compat_ptr(arg); err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle); if (!err) { if (get_user(xmit, &idle->xmit_idle) || get_user(recv, &idle->recv_idle) || put_user(xmit, &idle32->xmit_idle) || put_user(recv, &idle32->recv_idle)) err = -EFAULT; } return err; } static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ppp_option_data __user *odata; struct ppp_option_data32 __user *odata32; __u32 data; void __user *datap; odata = compat_alloc_user_space(sizeof(*odata)); odata32 = compat_ptr(arg); if (get_user(data, &odata32->ptr)) return -EFAULT; datap = compat_ptr(data); if (put_user(datap, &odata->ptr)) return -EFAULT; if (copy_in_user(&odata->length, &odata32->length, sizeof(__u32) + sizeof(int))) return -EFAULT; return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata); } static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { int err; switch (cmd) { case PPPIOCGIDLE32: err = ppp_gidle(fd, cmd, arg); break; case PPPIOCSCOMPRESS32: err = ppp_scompress(fd, cmd, arg); break; default: do { static int count; if (++count <= 20) printk("ppp_ioctl: Unknown cmd fd(%d) " "cmd(%08x) arg(%08x)\n", (int)fd, (unsigned int)cmd, (unsigned int)arg); } while(0); err = -EINVAL; break; }; return err; } struct mtget32 { compat_long_t mt_type; compat_long_t mt_resid; compat_long_t mt_dsreg; compat_long_t mt_gstat; compat_long_t mt_erreg; compat_daddr_t mt_fileno; compat_daddr_t mt_blkno; }; #define MTIOCGET32 _IOR('m', 2, struct mtget32) struct mtpos32 { compat_long_t mt_blkno; }; #define MTIOCPOS32 _IOR('m', 3, struct mtpos32) static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); struct mtget get; struct mtget32 __user *umget32; struct mtpos pos; struct mtpos32 __user *upos32; unsigned long kcmd; void *karg; int err = 0; switch(cmd) { case MTIOCPOS32: kcmd = MTIOCPOS; karg = &pos; break; case MTIOCGET32: kcmd = MTIOCGET; karg = &get; break; default: do { static int count; if (++count <= 20) printk("mt_ioctl: Unknown cmd fd(%d) " "cmd(%08x) arg(%08x)\n", (int)fd, (unsigned int)cmd, (unsigned int)arg); } while(0); return -EINVAL; } set_fs (KERNEL_DS); err = sys_ioctl (fd, kcmd, (unsigned long)karg); set_fs (old_fs); if (err) return err; switch (cmd) { case MTIOCPOS32: upos32 = compat_ptr(arg); err = __put_user(pos.mt_blkno, &upos32->mt_blkno); break; case MTIOCGET32: umget32 = compat_ptr(arg); err = __put_user(get.mt_type, &umget32->mt_type); err |= __put_user(get.mt_resid, &umget32->mt_resid); err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg); err |= __put_user(get.mt_gstat, &umget32->mt_gstat); err |= __put_user(get.mt_erreg, &umget32->mt_erreg); err |= __put_user(get.mt_fileno, &umget32->mt_fileno); err |= __put_user(get.mt_blkno, &umget32->mt_blkno); break; } return err ? -EFAULT: 0; } struct cdrom_read_audio32 { union cdrom_addr addr; u8 addr_format; compat_int_t nframes; compat_caddr_t buf; }; struct cdrom_generic_command32 { unsigned char cmd[CDROM_PACKET_SIZE]; compat_caddr_t buffer; compat_uint_t buflen; compat_int_t stat; compat_caddr_t sense; unsigned char data_direction; compat_int_t quiet; compat_int_t timeout; compat_caddr_t reserved[1]; }; static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg) { struct cdrom_read_audio __user *cdread_audio; struct cdrom_read_audio32 __user *cdread_audio32; __u32 data; void __user *datap; cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio)); cdread_audio32 = compat_ptr(arg); if (copy_in_user(&cdread_audio->addr, &cdread_audio32->addr, (sizeof(*cdread_audio32) - sizeof(compat_caddr_t)))) return -EFAULT; if (get_user(data, &cdread_audio32->buf)) return -EFAULT; datap = compat_ptr(data); if (put_user(datap, &cdread_audio->buf)) return -EFAULT; return sys_ioctl(fd, cmd, (unsigned long) cdread_audio); } static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg) { struct cdrom_generic_command __user *cgc; struct cdrom_generic_command32 __user *cgc32; u32 data; unsigned char dir; int itmp; cgc = compat_alloc_user_space(sizeof(*cgc)); cgc32 = compat_ptr(arg); if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) || get_user(data, &cgc32->buffer) || put_user(compat_ptr(data), &cgc->buffer) || copy_in_user(&cgc->buflen, &cgc32->buflen, (sizeof(unsigned int) + sizeof(int))) || get_user(data, &cgc32->sense) || put_user(compat_ptr(data), &cgc->sense) || get_user(dir, &cgc32->data_direction) || put_user(dir, &cgc->data_direction) || get_user(itmp, &cgc32->quiet) || put_user(itmp, &cgc->quiet) || get_user(itmp, &cgc32->timeout) || put_user(itmp, &cgc->timeout) || get_user(data, &cgc32->reserved[0]) || put_user(compat_ptr(data), &cgc->reserved[0])) return -EFAULT; return sys_ioctl(fd, cmd, (unsigned long) cgc); } static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { int err; switch(cmd) { case CDROMREADAUDIO: err = cdrom_do_read_audio(fd, cmd, arg); break; case CDROM_SEND_PACKET: err = cdrom_do_generic_command(fd, cmd, arg); break; default: do { static int count; if (++count <= 20) printk("cdrom_ioctl: Unknown cmd fd(%d) " "cmd(%08x) arg(%08x)\n", (int)fd, (unsigned int)cmd, (unsigned int)arg); } while(0); err = -EINVAL; break; }; return err; } struct loop_info32 { compat_int_t lo_number; /* ioctl r/o */ compat_dev_t lo_device; /* ioctl r/o */ compat_ulong_t lo_inode; /* ioctl r/o */ compat_dev_t lo_rdevice; /* ioctl r/o */ compat_int_t lo_offset; compat_int_t lo_encrypt_type; compat_int_t lo_encrypt_key_size; /* ioctl w/o */ compat_int_t lo_flags; /* ioctl r/o */ char lo_name[LO_NAME_SIZE]; unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ compat_ulong_t lo_init[2]; char reserved[4]; }; static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); struct loop_info l; struct loop_info32 __user *ul; int err = -EINVAL; ul = compat_ptr(arg); switch(cmd) { case LOOP_SET_STATUS: err = get_user(l.lo_number, &ul->lo_number); err |= __get_user(l.lo_device, &ul->lo_device); err |= __get_user(l.lo_inode, &ul->lo_inode); err |= __get_user(l.lo_rdevice, &ul->lo_rdevice); err |= __copy_from_user(&l.lo_offset, &ul->lo_offset, 8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset); if (err) { err = -EFAULT; } else { set_fs (KERNEL_DS); err = sys_ioctl (fd, cmd, (unsigned long)&l); set_fs (old_fs); } break; case LOOP_GET_STATUS: set_fs (KERNEL_DS); err = sys_ioctl (fd, cmd, (unsigned long)&l); set_fs (old_fs); if (!err) { err = put_user(l.lo_number, &ul->lo_number); err |= __put_user(l.lo_device, &ul->lo_device); err |= __put_user(l.lo_inode, &ul->lo_inode); err |= __put_user(l.lo_rdevice, &ul->lo_rdevice); err |= __copy_to_user(&ul->lo_offset, &l.lo_offset, (unsigned long)l.lo_init - (unsigned long)&l.lo_offset); if (err) err = -EFAULT; } break; default: { static int count; if (++count <= 20) printk("%s: Unknown loop ioctl cmd, fd(%d) " "cmd(%08x) arg(%08lx)\n", __FUNCTION__, fd, cmd, arg); } } return err; } extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg); #ifdef CONFIG_VT static int vt_check(struct file *file) { struct tty_struct *tty; struct inode *inode = file->f_dentry->d_inode; if (file->f_op->ioctl != tty_ioctl) return -EINVAL; tty = (struct tty_struct *)file->private_data; if (tty_paranoia_check(tty, inode, "tty_ioctl")) return -EINVAL; if (tty->driver->ioctl != vt_ioctl) return -EINVAL; /* * To have permissions to do most of the vt ioctls, we either have * to be the owner of the tty, or super-user. */ if (current->signal->tty == tty || capable(CAP_SYS_ADMIN)) return 1; return 0; } struct consolefontdesc32 { unsigned short charcount; /* characters in font (256 or 512) */ unsigned short charheight; /* scan lines per character (1-32) */ compat_caddr_t chardata; /* font data in expanded form */ }; static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) { struct consolefontdesc32 __user *user_cfd = compat_ptr(arg); struct console_font_op op; compat_caddr_t data; int i, perm; perm = vt_check(file); if (perm < 0) return perm; switch (cmd) { case PIO_FONTX: if (!perm) return -EPERM; op.op = KD_FONT_OP_SET; op.flags = 0; op.width = 8; if (get_user(op.height, &user_cfd->charheight) || get_user(op.charcount, &user_cfd->charcount) || get_user(data, &user_cfd->chardata)) return -EFAULT; op.data = compat_ptr(data); return con_font_op(vc_cons[fg_console].d, &op); case GIO_FONTX: op.op = KD_FONT_OP_GET; op.flags = 0; op.width = 8; if (get_user(op.height, &user_cfd->charheight) || get_user(op.charcount, &user_cfd->charcount) || get_user(data, &user_cfd->chardata)) return -EFAULT; if (!data) return 0; op.data = compat_ptr(data); i = con_font_op(vc_cons[fg_console].d, &op); if (i) return i; if (put_user(op.height, &user_cfd->charheight) || put_user(op.charcount, &user_cfd->charcount) || put_user((compat_caddr_t)(unsigned long)op.data, &user_cfd->chardata)) return -EFAULT; return 0; } return -EINVAL; } struct console_font_op32 { compat_uint_t op; /* operation code KD_FONT_OP_* */ compat_uint_t flags; /* KD_FONT_FLAG_* */ compat_uint_t width, height; /* font size */ compat_uint_t charcount; compat_caddr_t data; /* font data with height fixed to 32 */ }; static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) { struct console_font_op op; struct console_font_op32 __user *fontop = compat_ptr(arg); int perm = vt_check(file), i; struct vc_data *vc; if (perm < 0) return perm; if (copy_from_user(&op, fontop, sizeof(struct console_font_op32))) return -EFAULT; if (!perm && op.op != KD_FONT_OP_GET) return -EPERM; op.data = compat_ptr(((struct console_font_op32 *)&op)->data); op.flags |= KD_FONT_FLAG_OLD; vc = ((struct tty_struct *)file->private_data)->driver_data; i = con_font_op(vc, &op); if (i) return i; ((struct console_font_op32 *)&op)->data = (unsigned long)op.data; if (copy_to_user(fontop, &op, sizeof(struct console_font_op32))) return -EFAULT; return 0; } struct unimapdesc32 { unsigned short entry_ct; compat_caddr_t entries; }; static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) { struct unimapdesc32 tmp; struct unimapdesc32 __user *user_ud = compat_ptr(arg); int perm = vt_check(file); if (perm < 0) return perm; if (copy_from_user(&tmp, user_ud, sizeof tmp)) return -EFAULT; switch (cmd) { case PIO_UNIMAP: if (!perm) return -EPERM; return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries)); case GIO_UNIMAP: return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries)); } return 0; } #endif /* CONFIG_VT */ static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); __kernel_uid_t kuid; int err; cmd = SMB_IOC_GETMOUNTUID; set_fs(KERNEL_DS); err = sys_ioctl(fd, cmd, (unsigned long)&kuid); set_fs(old_fs); if (err >= 0) err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg)); return err; } struct atmif_sioc32 { compat_int_t number; compat_int_t length; compat_caddr_t arg; }; struct atm_iobuf32 { compat_int_t length; compat_caddr_t buffer; }; #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32) #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32) #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32) #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32) #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32) #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32) #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32) #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32) #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32) #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32) #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32) #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32) #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32) #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32) #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32) #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32) #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32) static struct { unsigned int cmd32; unsigned int cmd; } atm_ioctl_map[] = { { ATM_GETLINKRATE32, ATM_GETLINKRATE }, { ATM_GETNAMES32, ATM_GETNAMES }, { ATM_GETTYPE32, ATM_GETTYPE }, { ATM_GETESI32, ATM_GETESI }, { ATM_GETADDR32, ATM_GETADDR }, { ATM_RSTADDR32, ATM_RSTADDR }, { ATM_ADDADDR32, ATM_ADDADDR }, { ATM_DELADDR32, ATM_DELADDR }, { ATM_GETCIRANGE32, ATM_GETCIRANGE }, { ATM_SETCIRANGE32, ATM_SETCIRANGE }, { ATM_SETESI32, ATM_SETESI }, { ATM_SETESIF32, ATM_SETESIF }, { ATM_GETSTAT32, ATM_GETSTAT }, { ATM_GETSTATZ32, ATM_GETSTATZ }, { ATM_GETLOOP32, ATM_GETLOOP }, { ATM_SETLOOP32, ATM_SETLOOP }, { ATM_QUERYLOOP32, ATM_QUERYLOOP } }; #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map) static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg) { struct atm_iobuf __user *iobuf; struct atm_iobuf32 __user *iobuf32; u32 data; void __user *datap; int len, err; iobuf = compat_alloc_user_space(sizeof(*iobuf)); iobuf32 = compat_ptr(arg); if (get_user(len, &iobuf32->length) || get_user(data, &iobuf32->buffer)) return -EFAULT; datap = compat_ptr(data); if (put_user(len, &iobuf->length) || put_user(datap, &iobuf->buffer)) return -EFAULT; err = sys_ioctl(fd, cmd, (unsigned long)iobuf); if (!err) { if (copy_in_user(&iobuf32->length, &iobuf->length, sizeof(int))) err = -EFAULT; } return err; } static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg) { struct atmif_sioc __user *sioc; struct atmif_sioc32 __user *sioc32; u32 data; void __user *datap; int err; sioc = compat_alloc_user_space(sizeof(*sioc)); sioc32 = compat_ptr(arg); if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) || get_user(data, &sioc32->arg)) return -EFAULT; datap = compat_ptr(data); if (put_user(datap, &sioc->arg)) return -EFAULT; err = sys_ioctl(fd, cmd, (unsigned long) sioc); if (!err) { if (copy_in_user(&sioc32->length, &sioc->length, sizeof(int))) err = -EFAULT; } return err; } static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg) { int i; unsigned int cmd = 0; switch (cmd32) { case SONET_GETSTAT: case SONET_GETSTATZ: case SONET_GETDIAG: case SONET_SETDIAG: case SONET_CLRDIAG: case SONET_SETFRAMING: case SONET_GETFRAMING: case SONET_GETFRSENSE: return do_atmif_sioc(fd, cmd32, arg); } for (i = 0; i < NR_ATM_IOCTL; i++) { if (cmd32 == atm_ioctl_map[i].cmd32) { cmd = atm_ioctl_map[i].cmd; break; } } if (i == NR_ATM_IOCTL) return -EINVAL; switch (cmd) { case ATM_GETNAMES: return do_atm_iobuf(fd, cmd, arg); case ATM_GETLINKRATE: case ATM_GETTYPE: case ATM_GETESI: case ATM_GETADDR: case ATM_RSTADDR: case ATM_ADDADDR: case ATM_DELADDR: case ATM_GETCIRANGE: case ATM_SETCIRANGE: case ATM_SETESI: case ATM_SETESIF: case ATM_GETSTAT: case ATM_GETSTATZ: case ATM_GETLOOP: case ATM_SETLOOP: case ATM_QUERYLOOP: return do_atmif_sioc(fd, cmd, arg); } return -EINVAL; } static __attribute_used__ int ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg) { return -EINVAL; } static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg) { /* The mkswap binary hard codes it to Intel value :-((( */ return w_long(fd, BLKGETSIZE, arg); } struct blkpg_ioctl_arg32 { compat_int_t op; compat_int_t flags; compat_int_t datalen; compat_caddr_t data; }; static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg); struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); compat_caddr_t udata; compat_int_t n; int err; err = get_user(n, &ua32->op); err |= put_user(n, &a->op); err |= get_user(n, &ua32->flags); err |= put_user(n, &a->flags); err |= get_user(n, &ua32->datalen); err |= put_user(n, &a->datalen); err |= get_user(udata, &ua32->data); err |= put_user(compat_ptr(udata), &a->data); if (err) return err; return sys_ioctl(fd, cmd, (unsigned long)a); } static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg) { return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg); } /* Fix sizeof(sizeof()) breakage */ #define BLKBSZGET_32 _IOR(0x12,112,int) #define BLKBSZSET_32 _IOW(0x12,113,int) #define BLKGETSIZE64_32 _IOR(0x12,114,int) static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg) { return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg)); } static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg) { return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg)); } static int do_blkgetsize64(unsigned int fd, unsigned int cmd, unsigned long arg) { return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg)); } /* Bluetooth ioctls */ #define HCIUARTSETPROTO _IOW('U', 200, int) #define HCIUARTGETPROTO _IOR('U', 201, int) #define BNEPCONNADD _IOW('B', 200, int) #define BNEPCONNDEL _IOW('B', 201, int) #define BNEPGETCONNLIST _IOR('B', 210, int) #define BNEPGETCONNINFO _IOR('B', 211, int) #define CMTPCONNADD _IOW('C', 200, int) #define CMTPCONNDEL _IOW('C', 201, int) #define CMTPGETCONNLIST _IOR('C', 210, int) #define CMTPGETCONNINFO _IOR('C', 211, int) #define HIDPCONNADD _IOW('H', 200, int) #define HIDPCONNDEL _IOW('H', 201, int) #define HIDPGETCONNLIST _IOR('H', 210, int) #define HIDPGETCONNINFO _IOR('H', 211, int) struct floppy_struct32 { compat_uint_t size; compat_uint_t sect; compat_uint_t head; compat_uint_t track; compat_uint_t stretch; unsigned char gap; unsigned char rate; unsigned char spec1; unsigned char fmt_gap; const compat_caddr_t name; }; struct floppy_drive_params32 { char cmos; compat_ulong_t max_dtr; compat_ulong_t hlt; compat_ulong_t hut; compat_ulong_t srt; compat_ulong_t spinup; compat_ulong_t spindown; unsigned char spindown_offset; unsigned char select_delay; unsigned char rps; unsigned char tracks; compat_ulong_t timeout; unsigned char interleave_sect; struct floppy_max_errors max_errors; char flags; char read_track; short autodetect[8]; compat_int_t checkfreq; compat_int_t native_format; }; struct floppy_drive_struct32 { signed char flags; compat_ulong_t spinup_date; compat_ulong_t select_date; compat_ulong_t first_read_date; short probed_format; short track; short maxblock; short maxtrack; compat_int_t generation; compat_int_t keep_data; compat_int_t fd_ref; compat_int_t fd_device; compat_int_t last_checked; compat_caddr_t dmabuf; compat_int_t bufblocks; }; struct floppy_fdc_state32 { compat_int_t spec1; compat_int_t spec2; compat_int_t dtr; unsigned char version; unsigned char dor; compat_ulong_t address; unsigned int rawcmd:2; unsigned int reset:1; unsigned int need_configure:1; unsigned int perp_mode:2; unsigned int has_fifo:1; unsigned int driver_version; unsigned char track[4]; }; struct floppy_write_errors32 { unsigned int write_errors; compat_ulong_t first_error_sector; compat_int_t first_error_generation; compat_ulong_t last_error_sector; compat_int_t last_error_generation; compat_uint_t badness; }; #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32) #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32) #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32) #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32) #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32) #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32) #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32) #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32) #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32) static struct { unsigned int cmd32; unsigned int cmd; } fd_ioctl_trans_table[] = { { FDSETPRM32, FDSETPRM }, { FDDEFPRM32, FDDEFPRM }, { FDGETPRM32, FDGETPRM }, { FDSETDRVPRM32, FDSETDRVPRM }, { FDGETDRVPRM32, FDGETDRVPRM }, { FDGETDRVSTAT32, FDGETDRVSTAT }, { FDPOLLDRVSTAT32, FDPOLLDRVSTAT }, { FDGETFDCSTAT32, FDGETFDCSTAT }, { FDWERRORGET32, FDWERRORGET } }; #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table) static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); void *karg = NULL; unsigned int kcmd = 0; int i, err; for (i = 0; i < NR_FD_IOCTL_TRANS; i++) if (cmd == fd_ioctl_trans_table[i].cmd32) { kcmd = fd_ioctl_trans_table[i].cmd; break; } if (!kcmd) return -EINVAL; switch (cmd) { case FDSETPRM32: case FDDEFPRM32: case FDGETPRM32: { compat_uptr_t name; struct floppy_struct32 __user *uf; struct floppy_struct *f; uf = compat_ptr(arg); f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL); if (!karg) return -ENOMEM; if (cmd == FDGETPRM32) break; err = __get_user(f->size, &uf->size); err |= __get_user(f->sect, &uf->sect); err |= __get_user(f->head, &uf->head); err |= __get_user(f->track, &uf->track); err |= __get_user(f->stretch, &uf->stretch); err |= __get_user(f->gap, &uf->gap); err |= __get_user(f->rate, &uf->rate); err |= __get_user(f->spec1, &uf->spec1); err |= __get_user(f->fmt_gap, &uf->fmt_gap); err |= __get_user(name, &uf->name); f->name = compat_ptr(name); if (err) { err = -EFAULT; goto out; } break; } case FDSETDRVPRM32: case FDGETDRVPRM32: { struct floppy_drive_params32 __user *uf; struct floppy_drive_params *f; uf = compat_ptr(arg); f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL); if (!karg) return -ENOMEM; if (cmd == FDGETDRVPRM32) break; err = __get_user(f->cmos, &uf->cmos); err |= __get_user(f->max_dtr, &uf->max_dtr); err |= __get_user(f->hlt, &uf->hlt); err |= __get_user(f->hut, &uf->hut); err |= __get_user(f->srt, &uf->srt); err |= __get_user(f->spinup, &uf->spinup); err |= __get_user(f->spindown, &uf->spindown); err |= __get_user(f->spindown_offset, &uf->spindown_offset); err |= __get_user(f->select_delay, &uf->select_delay); err |= __get_user(f->rps, &uf->rps); err |= __get_user(f->tracks, &uf->tracks); err |= __get_user(f->timeout, &uf->timeout); err |= __get_user(f->interleave_sect, &uf->interleave_sect); err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors)); err |= __get_user(f->flags, &uf->flags); err |= __get_user(f->read_track, &uf->read_track); err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect)); err |= __get_user(f->checkfreq, &uf->checkfreq); err |= __get_user(f->native_format, &uf->native_format); if (err) { err = -EFAULT; goto out; } break; } case FDGETDRVSTAT32: case FDPOLLDRVSTAT32: karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL); if (!karg) return -ENOMEM; break; case FDGETFDCSTAT32: karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL); if (!karg) return -ENOMEM; break; case FDWERRORGET32: karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL); if (!karg) return -ENOMEM; break; default: return -EINVAL; } set_fs (KERNEL_DS); err = sys_ioctl (fd, kcmd, (unsigned long)karg); set_fs (old_fs); if (err) goto out; switch (cmd) { case FDGETPRM32: { struct floppy_struct *f = karg; struct floppy_struct32 __user *uf = compat_ptr(arg); err = __put_user(f->size, &uf->size); err |= __put_user(f->sect, &uf->sect); err |= __put_user(f->head, &uf->head); err |= __put_user(f->track, &uf->track); err |= __put_user(f->stretch, &uf->stretch); err |= __put_user(f->gap, &uf->gap); err |= __put_user(f->rate, &uf->rate); err |= __put_user(f->spec1, &uf->spec1); err |= __put_user(f->fmt_gap, &uf->fmt_gap); err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name); break; } case FDGETDRVPRM32: { struct floppy_drive_params32 __user *uf; struct floppy_drive_params *f = karg; uf = compat_ptr(arg); err = __put_user(f->cmos, &uf->cmos); err |= __put_user(f->max_dtr, &uf->max_dtr); err |= __put_user(f->hlt, &uf->hlt); err |= __put_user(f->hut, &uf->hut); err |= __put_user(f->srt, &uf->srt); err |= __put_user(f->spinup, &uf->spinup); err |= __put_user(f->spindown, &uf->spindown); err |= __put_user(f->spindown_offset, &uf->spindown_offset); err |= __put_user(f->select_delay, &uf->select_delay); err |= __put_user(f->rps, &uf->rps); err |= __put_user(f->tracks, &uf->tracks); err |= __put_user(f->timeout, &uf->timeout); err |= __put_user(f->interleave_sect, &uf->interleave_sect); err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors)); err |= __put_user(f->flags, &uf->flags); err |= __put_user(f->read_track, &uf->read_track); err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect)); err |= __put_user(f->checkfreq, &uf->checkfreq); err |= __put_user(f->native_format, &uf->native_format); break; } case FDGETDRVSTAT32: case FDPOLLDRVSTAT32: { struct floppy_drive_struct32 __user *uf; struct floppy_drive_struct *f = karg; uf = compat_ptr(arg); err = __put_user(f->flags, &uf->flags); err |= __put_user(f->spinup_date, &uf->spinup_date); err |= __put_user(f->select_date, &uf->select_date); err |= __put_user(f->first_read_date, &uf->first_read_date); err |= __put_user(f->probed_format, &uf->probed_format); err |= __put_user(f->track, &uf->track); err |= __put_user(f->maxblock, &uf->maxblock); err |= __put_user(f->maxtrack, &uf->maxtrack); err |= __put_user(f->generation, &uf->generation); err |= __put_user(f->keep_data, &uf->keep_data); err |= __put_user(f->fd_ref, &uf->fd_ref); err |= __put_user(f->fd_device, &uf->fd_device); err |= __put_user(f->last_checked, &uf->last_checked); err |= __put_user((u64)f->dmabuf, &uf->dmabuf); err |= __put_user((u64)f->bufblocks, &uf->bufblocks); break; } case FDGETFDCSTAT32: { struct floppy_fdc_state32 __user *uf; struct floppy_fdc_state *f = karg; uf = compat_ptr(arg); err = __put_user(f->spec1, &uf->spec1); err |= __put_user(f->spec2, &uf->spec2); err |= __put_user(f->dtr, &uf->dtr); err |= __put_user(f->version, &uf->version); err |= __put_user(f->dor, &uf->dor); err |= __put_user(f->address, &uf->address); err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address), (char *)&f->address + sizeof(f->address), sizeof(int)); err |= __put_user(f->driver_version, &uf->driver_version); err |= __copy_to_user(uf->track, f->track, sizeof(f->track)); break; } case FDWERRORGET32: { struct floppy_write_errors32 __user *uf; struct floppy_write_errors *f = karg; uf = compat_ptr(arg); err = __put_user(f->write_errors, &uf->write_errors); err |= __put_user(f->first_error_sector, &uf->first_error_sector); err |= __put_user(f->first_error_generation, &uf->first_error_generation); err |= __put_user(f->last_error_sector, &uf->last_error_sector); err |= __put_user(f->last_error_generation, &uf->last_error_generation); err |= __put_user(f->badness, &uf->badness); break; } default: break; } if (err) err = -EFAULT; out: kfree(karg); return err; } struct mtd_oob_buf32 { u_int32_t start; u_int32_t length; compat_caddr_t ptr; /* unsigned char* */ }; #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32) #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32) static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg) { struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf)); struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg); u32 data; char __user *datap; unsigned int real_cmd; int err; real_cmd = (cmd == MEMREADOOB32) ? MEMREADOOB : MEMWRITEOOB; if (copy_in_user(&buf->start, &buf32->start, 2 * sizeof(u32)) || get_user(data, &buf32->ptr)) return -EFAULT; datap = compat_ptr(data); if (put_user(datap, &buf->ptr)) return -EFAULT; err = sys_ioctl(fd, real_cmd, (unsigned long) buf); if (!err) { if (copy_in_user(&buf32->start, &buf->start, 2 * sizeof(u32))) err = -EFAULT; } return err; } #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2]) #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2]) static long put_dirent32 (struct dirent *d, struct compat_dirent __user *d32) { if (!access_ok(VERIFY_WRITE, d32, sizeof(struct compat_dirent))) return -EFAULT; __put_user(d->d_ino, &d32->d_ino); __put_user(d->d_off, &d32->d_off); __put_user(d->d_reclen, &d32->d_reclen); if (__copy_to_user(d32->d_name, d->d_name, d->d_reclen)) return -EFAULT; return 0; } static int vfat_ioctl32(unsigned fd, unsigned cmd, unsigned long arg) { struct compat_dirent __user *p = compat_ptr(arg); int ret; mm_segment_t oldfs = get_fs(); struct dirent d[2]; switch(cmd) { case VFAT_IOCTL_READDIR_BOTH32: cmd = VFAT_IOCTL_READDIR_BOTH; break; case VFAT_IOCTL_READDIR_SHORT32: cmd = VFAT_IOCTL_READDIR_SHORT; break; } set_fs(KERNEL_DS); ret = sys_ioctl(fd,cmd,(unsigned long)&d); set_fs(oldfs); if (ret >= 0) { ret |= put_dirent32(&d[0], p); ret |= put_dirent32(&d[1], p + 1); } return ret; } #define REISERFS_IOC_UNPACK32 _IOW(0xCD,1,int) static int reiserfs_ioctl32(unsigned fd, unsigned cmd, unsigned long ptr) { if (cmd == REISERFS_IOC_UNPACK32) cmd = REISERFS_IOC_UNPACK; return sys_ioctl(fd,cmd,ptr); } struct raw32_config_request { compat_int_t raw_minor; __u64 block_major; __u64 block_minor; } __attribute__((packed)); static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req) { int ret; if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request))) return -EFAULT; ret = __get_user(req->raw_minor, &user_req->raw_minor); ret |= __get_user(req->block_major, &user_req->block_major); ret |= __get_user(req->block_minor, &user_req->block_minor); return ret ? -EFAULT : 0; } static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req) { int ret; if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request))) return -EFAULT; ret = __put_user(req->raw_minor, &user_req->raw_minor); ret |= __put_user(req->block_major, &user_req->block_major); ret |= __put_user(req->block_minor, &user_req->block_minor); return ret ? -EFAULT : 0; } static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg) { int ret; switch (cmd) { case RAW_SETBIND: case RAW_GETBIND: { struct raw_config_request req; struct raw32_config_request __user *user_req = compat_ptr(arg); mm_segment_t oldfs = get_fs(); if ((ret = get_raw32_request(&req, user_req))) return ret; set_fs(KERNEL_DS); ret = sys_ioctl(fd,cmd,(unsigned long)&req); set_fs(oldfs); if ((!ret) && (cmd == RAW_GETBIND)) { ret = set_raw32_request(&req, user_req); } break; } default: ret = sys_ioctl(fd, cmd, arg); break; } return ret; } struct serial_struct32 { compat_int_t type; compat_int_t line; compat_uint_t port; compat_int_t irq; compat_int_t flags; compat_int_t xmit_fifo_size; compat_int_t custom_divisor; compat_int_t baud_base; unsigned short close_delay; char io_type; char reserved_char[1]; compat_int_t hub6; unsigned short closing_wait; /* time to wait before closing */ unsigned short closing_wait2; /* no longer used... */ compat_uint_t iomem_base; unsigned short iomem_reg_shift; unsigned int port_high; /* compat_ulong_t iomap_base FIXME */ compat_int_t reserved[1]; }; static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg) { typedef struct serial_struct SS; typedef struct serial_struct32 SS32; struct serial_struct32 __user *ss32 = compat_ptr(arg); int err; struct serial_struct ss; mm_segment_t oldseg = get_fs(); __u32 udata; if (cmd == TIOCSSERIAL) { if (!access_ok(VERIFY_READ, ss32, sizeof(SS32))) return -EFAULT; if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base))) return -EFAULT; __get_user(udata, &ss32->iomem_base); ss.iomem_base = compat_ptr(udata); __get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift); __get_user(ss.port_high, &ss32->port_high); ss.iomap_base = 0UL; } set_fs(KERNEL_DS); err = sys_ioctl(fd,cmd,(unsigned long)(&ss)); set_fs(oldseg); if (cmd == TIOCGSERIAL && err >= 0) { if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32))) return -EFAULT; if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base))) return -EFAULT; __put_user((unsigned long)ss.iomem_base >> 32 ? 0xffffffff : (unsigned)(unsigned long)ss.iomem_base, &ss32->iomem_base); __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift); __put_user(ss.port_high, &ss32->port_high); } return err; } struct usbdevfs_ctrltransfer32 { u8 bRequestType; u8 bRequest; u16 wValue; u16 wIndex; u16 wLength; u32 timeout; /* in milliseconds */ compat_caddr_t data; }; #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32) static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg) { struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg); struct usbdevfs_ctrltransfer __user *p; __u32 udata; p = compat_alloc_user_space(sizeof(*p)); if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) || get_user(udata, &p32->data) || put_user(compat_ptr(udata), &p->data)) return -EFAULT; return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p); } struct usbdevfs_bulktransfer32 { compat_uint_t ep; compat_uint_t len; compat_uint_t timeout; /* in milliseconds */ compat_caddr_t data; }; #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32) static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg) { struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg); struct usbdevfs_bulktransfer __user *p; compat_uint_t n; compat_caddr_t addr; p = compat_alloc_user_space(sizeof(*p)); if (get_user(n, &p32->ep) || put_user(n, &p->ep) || get_user(n, &p32->len) || put_user(n, &p->len) || get_user(n, &p32->timeout) || put_user(n, &p->timeout) || get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data)) return -EFAULT; return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p); } /* * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY * are handled in usbdevfs core. -Christopher Li */ struct usbdevfs_disconnectsignal32 { compat_int_t signr; compat_caddr_t context; }; #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32) static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg) { struct usbdevfs_disconnectsignal kdis; struct usbdevfs_disconnectsignal32 __user *udis; mm_segment_t old_fs; u32 uctx; int err; udis = compat_ptr(arg); if (get_user(kdis.signr, &udis->signr) || __get_user(uctx, &udis->context)) return -EFAULT; kdis.context = compat_ptr(uctx); old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis); set_fs(old_fs); return err; } /* * I2C layer ioctls */ struct i2c_msg32 { u16 addr; u16 flags; u16 len; compat_caddr_t buf; }; struct i2c_rdwr_ioctl_data32 { compat_caddr_t msgs; /* struct i2c_msg __user *msgs */ u32 nmsgs; }; struct i2c_smbus_ioctl_data32 { u8 read_write; u8 command; u32 size; compat_caddr_t data; /* union i2c_smbus_data *data */ }; struct i2c_rdwr_aligned { struct i2c_rdwr_ioctl_data cmd; struct i2c_msg msgs[0]; }; static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg); struct i2c_rdwr_aligned __user *tdata; struct i2c_msg __user *tmsgs; struct i2c_msg32 __user *umsgs; compat_caddr_t datap; int nmsgs, i; if (get_user(nmsgs, &udata->nmsgs)) return -EFAULT; if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) return -EINVAL; if (get_user(datap, &udata->msgs)) return -EFAULT; umsgs = compat_ptr(datap); tdata = compat_alloc_user_space(sizeof(*tdata) + nmsgs * sizeof(struct i2c_msg)); tmsgs = &tdata->msgs[0]; if (put_user(nmsgs, &tdata->cmd.nmsgs) || put_user(tmsgs, &tdata->cmd.msgs)) return -EFAULT; for (i = 0; i < nmsgs; i++) { if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16))) return -EFAULT; if (get_user(datap, &umsgs[i].buf) || put_user(compat_ptr(datap), &tmsgs[i].buf)) return -EFAULT; } return sys_ioctl(fd, cmd, (unsigned long)tdata); } static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { struct i2c_smbus_ioctl_data __user *tdata; struct i2c_smbus_ioctl_data32 __user *udata; compat_caddr_t datap; tdata = compat_alloc_user_space(sizeof(*tdata)); if (tdata == NULL) return -ENOMEM; if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata))) return -EFAULT; udata = compat_ptr(arg); if (!access_ok(VERIFY_READ, udata, sizeof(*udata))) return -EFAULT; if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8))) return -EFAULT; if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32))) return -EFAULT; if (__get_user(datap, &udata->data) || __put_user(compat_ptr(datap), &tdata->data)) return -EFAULT; return sys_ioctl(fd, cmd, (unsigned long)tdata); } struct compat_iw_point { compat_caddr_t pointer; __u16 length; __u16 flags; }; static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { struct iwreq __user *iwr; struct iwreq __user *iwr_u; struct iw_point __user *iwp; struct compat_iw_point __user *iwp_u; compat_caddr_t pointer; __u16 length, flags; iwr_u = compat_ptr(arg); iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data; iwr = compat_alloc_user_space(sizeof(*iwr)); if (iwr == NULL) return -ENOMEM; iwp = &iwr->u.data; if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr))) return -EFAULT; if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0], &iwr_u->ifr_ifrn.ifrn_name[0], sizeof(iwr->ifr_ifrn.ifrn_name))) return -EFAULT; if (__get_user(pointer, &iwp_u->pointer) || __get_user(length, &iwp_u->length) || __get_user(flags, &iwp_u->flags)) return -EFAULT; if (__put_user(compat_ptr(pointer), &iwp->pointer) || __put_user(length, &iwp->length) || __put_user(flags, &iwp->flags)) return -EFAULT; return sys_ioctl(fd, cmd, (unsigned long) iwr); } /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE * for some operations; this forces use of the newer bridge-utils that * use compatiable ioctls */ static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { u32 tmp; if (get_user(tmp, (u32 __user *) arg)) return -EFAULT; if (tmp == BRCTL_GET_VERSION) return BRCTL_VERSION + 1; return -EINVAL; } #define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t) #define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t) #define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t) #define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t) static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg) { mm_segment_t oldfs = get_fs(); compat_ulong_t val32; unsigned long kval; int ret; switch (cmd) { case RTC_IRQP_READ32: case RTC_EPOCH_READ32: set_fs(KERNEL_DS); ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ? RTC_IRQP_READ : RTC_EPOCH_READ, (unsigned long)&kval); set_fs(oldfs); if (ret) return ret; val32 = kval; return put_user(val32, (unsigned int __user *)arg); case RTC_IRQP_SET32: return sys_ioctl(fd, RTC_IRQP_SET, arg); case RTC_EPOCH_SET32: return sys_ioctl(fd, RTC_EPOCH_SET, arg); default: /* unreached */ return -ENOIOCTLCMD; } } #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE) struct ncp_ioctl_request_32 { u32 function; u32 size; compat_caddr_t data; }; struct ncp_fs_info_v2_32 { s32 version; u32 mounted_uid; u32 connection; u32 buffer_size; u32 volume_number; u32 directory_id; u32 dummy1; u32 dummy2; u32 dummy3; }; struct ncp_objectname_ioctl_32 { s32 auth_type; u32 object_name_len; compat_caddr_t object_name; /* an userspace data, in most cases user name */ }; struct ncp_privatedata_ioctl_32 { u32 len; compat_caddr_t data; /* ~1000 for NDS */ }; #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32) #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, u32) #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32) #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32) #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32) #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32) #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32) static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ncp_ioctl_request_32 n32; struct ncp_ioctl_request __user *p = compat_alloc_user_space(sizeof(*p)); if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)) || put_user(n32.function, &p->function) || put_user(n32.size, &p->size) || put_user(compat_ptr(n32.data), &p->data)) return -EFAULT; return sys_ioctl(fd, NCP_IOC_NCPREQUEST, (unsigned long)p); } static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); __kernel_uid_t kuid; int err; cmd = NCP_IOC_GETMOUNTUID2; set_fs(KERNEL_DS); err = sys_ioctl(fd, cmd, (unsigned long)&kuid); set_fs(old_fs); if (!err) err = put_user(kuid, (unsigned int __user *) compat_ptr(arg)); return err; } static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg) { mm_segment_t old_fs = get_fs(); struct ncp_fs_info_v2_32 n32; struct ncp_fs_info_v2 n; int err; if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32))) return -EFAULT; if (n32.version != NCP_GET_FS_INFO_VERSION_V2) return -EINVAL; n.version = NCP_GET_FS_INFO_VERSION_V2; set_fs(KERNEL_DS); err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n); set_fs(old_fs); if (!err) { n32.version = n.version; n32.mounted_uid = n.mounted_uid; n32.connection = n.connection; n32.buffer_size = n.buffer_size; n32.volume_number = n.volume_number; n32.directory_id = n.directory_id; n32.dummy1 = n.dummy1; n32.dummy2 = n.dummy2; n32.dummy3 = n.dummy3; err = copy_to_user(compat_ptr(arg), &n32, sizeof(n32)) ? -EFAULT : 0; } return err; } static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg); struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p)); s32 auth_type; u32 name_len; int err; if (copy_from_user(&n32, p32, sizeof(n32)) || put_user(n32.object_name_len, &p->object_name_len) || put_user(compat_ptr(n32.object_name), &p->object_name)) return -EFAULT; err = sys_ioctl(fd, NCP_IOC_GETOBJECTNAME, (unsigned long)p); if (err) return err; if (get_user(auth_type, &p->auth_type) || put_user(auth_type, &p32->auth_type) || get_user(name_len, &p->object_name_len) || put_user(name_len, &p32->object_name_len)) return -EFAULT; return 0; } static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg); struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p)); if (copy_from_user(&n32, p32, sizeof(n32)) || put_user(n32.auth_type, &p->auth_type) || put_user(n32.object_name_len, &p->object_name_len) || put_user(compat_ptr(n32.object_name), &p->object_name)) return -EFAULT; return sys_ioctl(fd, NCP_IOC_SETOBJECTNAME, (unsigned long)p); } static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ncp_privatedata_ioctl_32 n32, __user *p32 = compat_ptr(arg); struct ncp_privatedata_ioctl __user *p = compat_alloc_user_space(sizeof(*p)); u32 len; int err; if (copy_from_user(&n32, p32, sizeof(n32)) || put_user(n32.len, &p->len) || put_user(compat_ptr(n32.data), &p->data)) return -EFAULT; err = sys_ioctl(fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)p); if (err) return err; if (get_user(len, &p->len) || put_user(len, &p32->len)) return -EFAULT; return 0; } static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg) { struct ncp_privatedata_ioctl_32 n32; struct ncp_privatedata_ioctl_32 __user *p32 = compat_ptr(arg); struct ncp_privatedata_ioctl __user *p = compat_alloc_user_space(sizeof(*p)); if (copy_from_user(&n32, p32, sizeof(n32)) || put_user(n32.len, &p->len) || put_user(compat_ptr(n32.data), &p->data)) return -EFAULT; return sys_ioctl(fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)p); } #endif static int lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg) { struct compat_timeval __user *tc = (struct compat_timeval __user *)arg; struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval)); struct timeval ts; if (get_user(ts.tv_sec, &tc->tv_sec) || get_user(ts.tv_usec, &tc->tv_usec) || put_user(ts.tv_sec, &tn->tv_sec) || put_user(ts.tv_usec, &tn->tv_usec)) return -EFAULT; return sys_ioctl(fd, cmd, (unsigned long)tn); } #define HANDLE_IOCTL(cmd,handler) \ { (cmd), (ioctl_trans_handler_t)(handler) }, /* pointer to compatible structure or no argument */ #define COMPATIBLE_IOCTL(cmd) \ { (cmd), do_ioctl32_pointer }, /* argument is an unsigned long integer, not a pointer */ #define ULONG_IOCTL(cmd) \ { (cmd), (ioctl_trans_handler_t)sys_ioctl }, struct ioctl_trans ioctl_start[] = { #include <linux/compat_ioctl.h> HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob) HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob) #ifdef CONFIG_NET HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32) HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf) HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc) HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc) HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc) HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc) HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc) HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc) HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc) HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc) HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc) HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc) HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc) HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc) HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc) HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc) HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc) HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc) HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc) /* ioctls used by appletalk ddp.c */ HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc) HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc) HANDLE_IOCTL(SIOCSARP, dev_ifsioc) HANDLE_IOCTL(SIOCDARP, dev_ifsioc) HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc) HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc) HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc) HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc) HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc) HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc) HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc) HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc) HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc) HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc) HANDLE_IOCTL(TUNSETIFF, dev_ifsioc) HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl) HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl) HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl) HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl) HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl) HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl) HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl) HANDLE_IOCTL(SIOCADDRT, routing_ioctl) HANDLE_IOCTL(SIOCDELRT, routing_ioctl) HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc) HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc) /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */ HANDLE_IOCTL(SIOCRTMSG, ret_einval) HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp) #endif HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo) HANDLE_IOCTL(BLKRAGET, w_long) HANDLE_IOCTL(BLKGETSIZE, w_long) HANDLE_IOCTL(0x1260, broken_blkgetsize) HANDLE_IOCTL(BLKFRAGET, w_long) HANDLE_IOCTL(BLKSECTGET, w_long) HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans) HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans) HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans) HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans) HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans) HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans) HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans) HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans) HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans) HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans) HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans) HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans) HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans) HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans) HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans) HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans) HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans) HANDLE_IOCTL(SG_IO,sg_ioctl_trans) HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans) HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans) HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans) HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans) HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans) HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans) HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans) HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans) HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans) HANDLE_IOCTL(LOOP_SET_STATUS, loop_status) HANDLE_IOCTL(LOOP_GET_STATUS, loop_status) #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int) HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout) #ifdef CONFIG_VT HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl) HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl) HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl) HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl) HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl) #endif HANDLE_IOCTL(EXT2_IOC32_GETFLAGS, do_ext2_ioctl) HANDLE_IOCTL(EXT2_IOC32_SETFLAGS, do_ext2_ioctl) HANDLE_IOCTL(EXT2_IOC32_GETVERSION, do_ext2_ioctl) HANDLE_IOCTL(EXT2_IOC32_SETVERSION, do_ext2_ioctl) HANDLE_IOCTL(EXT3_IOC32_GETVERSION, do_ext3_ioctl) HANDLE_IOCTL(EXT3_IOC32_SETVERSION, do_ext3_ioctl) HANDLE_IOCTL(EXT3_IOC32_GETRSVSZ, do_ext3_ioctl) HANDLE_IOCTL(EXT3_IOC32_SETRSVSZ, do_ext3_ioctl) HANDLE_IOCTL(EXT3_IOC32_GROUP_EXTEND, do_ext3_ioctl) COMPATIBLE_IOCTL(EXT3_IOC_GROUP_ADD) #ifdef CONFIG_JBD_DEBUG HANDLE_IOCTL(EXT3_IOC32_WAIT_FOR_READONLY, do_ext3_ioctl) #endif /* One SMB ioctl needs translations. */ #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t) HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid) HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl) HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl) HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl) HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl) HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl) HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl) HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl) HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl) HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl) HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl) HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl) HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl) HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl) HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl) HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl) HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl) HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl) HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl) /* block stuff */ HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget) HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset) HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64) /* vfat */ HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32) HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32) HANDLE_IOCTL(REISERFS_IOC_UNPACK32, reiserfs_ioctl32) /* Raw devices */ HANDLE_IOCTL(RAW_SETBIND, raw_ioctl) HANDLE_IOCTL(RAW_GETBIND, raw_ioctl) /* Serial */ HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl) HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl) #ifdef TIOCGLTC COMPATIBLE_IOCTL(TIOCGLTC) COMPATIBLE_IOCTL(TIOCSLTC) #endif #ifdef TIOCSTART /* * For these two we have defintions in ioctls.h and/or termios.h on * some architectures but no actual implemention. Some applications * like bash call them if they are defined in the headers, so we provide * entries here to avoid syslog message spew. */ COMPATIBLE_IOCTL(TIOCSTART) COMPATIBLE_IOCTL(TIOCSTOP) #endif /* Usbdevfs */ HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control) HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk) HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal) COMPATIBLE_IOCTL(USBDEVFS_IOCTL32) /* i2c */ HANDLE_IOCTL(I2C_FUNCS, w_long) HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl) HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl) /* wireless */ HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl) HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl) HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl) HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl) HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl) HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl) HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl) HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl) HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl) HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl) HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl) HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl) HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl) HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl) HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl) HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl) HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl) HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl) HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl) #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE) HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest) HANDLE_IOCTL(NCP_IOC_GETMOUNTUID2_32, do_ncp_getmountuid2) HANDLE_IOCTL(NCP_IOC_GET_FS_INFO_V2_32, do_ncp_getfsinfo2) HANDLE_IOCTL(NCP_IOC_GETOBJECTNAME_32, do_ncp_getobjectname) HANDLE_IOCTL(NCP_IOC_SETOBJECTNAME_32, do_ncp_setobjectname) HANDLE_IOCTL(NCP_IOC_GETPRIVATEDATA_32, do_ncp_getprivatedata) HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata) #endif /* dvb */ HANDLE_IOCTL(DMX_GET_EVENT, do_dmx_get_event) HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event) HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture) HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette) /* parport */ COMPATIBLE_IOCTL(LPTIME) COMPATIBLE_IOCTL(LPCHAR) COMPATIBLE_IOCTL(LPABORTOPEN) COMPATIBLE_IOCTL(LPCAREFUL) COMPATIBLE_IOCTL(LPWAIT) COMPATIBLE_IOCTL(LPSETIRQ) COMPATIBLE_IOCTL(LPGETSTATUS) COMPATIBLE_IOCTL(LPGETSTATUS) COMPATIBLE_IOCTL(LPRESET) /*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/ COMPATIBLE_IOCTL(LPGETFLAGS) HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans) }; int ioctl_table_size = ARRAY_SIZE(ioctl_start);