aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/tipc
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2010-01-11 10:17:12 -0500
committerJens Axboe <jens.axboe@oracle.com>2010-01-11 10:17:12 -0500
commit23978161f90e5a3200ad6ac9b0d534911e4cbb28 (patch)
tree39a9bbd37416cce9dc4aff6bd6d9948e56cbec0e /include/net/tipc
parent875feb63b9567442be73efbcc9a8470e376d6423 (diff)
drivers/block/drbd/drbd_receiver.c: correct NULL test
Test the just-allocated value for NULL rather than some other value. The semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression x,y; statement S; @@ x = \(kmalloc\|kcalloc\|kzalloc\)(...); ( if ((x) == NULL) S | if ( - y + x == NULL) S ) // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Cc: Lars Ellenberg <drbd-dev@lists.linbit.com> Cc: Philipp Reisner <philipp.reisner@linbit.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'include/net/tipc')
0 files changed, 0 insertions, 0 deletions
p includes' href='/cgit/cgit.cgi/litmus-rt.git/commit/drivers/firewire/fw-transaction.c?h=v2.6.34-rc1&id=e8ca97021c8eb127bb04aec4e2420e1d66be371d'>e8ca97021c8e
3038e353cfaf
3038e353cfaf
e8ca97021c8e







3038e353cfaf
77c9a5daa9c4
3038e353cfaf
a77754a75d58



















a7ea67823af4


77c9a5daa9c4



a77754a75d58


3038e353cfaf
53dca51175cc
a38a00fdef98
3038e353cfaf
730c32f58ba8
3038e353cfaf


730c32f58ba8

5c40cbfefa82
1e626fdcef61
730c32f58ba8


3038e353cfaf

730c32f58ba8
5c40cbfefa82
a38a00fdef98
730c32f58ba8



3038e353cfaf

c781c06d119d



53dca51175cc

730c32f58ba8
c781c06d119d

730c32f58ba8
c781c06d119d

730c32f58ba8



c781c06d119d



730c32f58ba8
a38a00fdef98
730c32f58ba8


5c40cbfefa82
























53dca51175cc

3038e353cfaf





a38a00fdef98
3038e353cfaf






a38a00fdef98
3038e353cfaf

a38a00fdef98
e5f49c3b837f
3038e353cfaf
a38a00fdef98
3038e353cfaf

c781c06d119d



a38a00fdef98
3038e353cfaf



53dca51175cc
b9549bc6803d
36bfe49d0764
3038e353cfaf


18e9b10fcdc0











3038e353cfaf
8f9f963e5d98
3038e353cfaf




a77754a75d58


b9549bc6803d
3038e353cfaf
a77754a75d58
3038e353cfaf












a77754a75d58

3038e353cfaf











a77754a75d58

3038e353cfaf


5b189bf3633c


3038e353cfaf
18e9b10fcdc0
3038e353cfaf

730c32f58ba8
19593ffdb6da
3038e353cfaf

7906054f0d59
















3038e353cfaf























dbe7f76dd6e7
3038e353cfaf
907293d78872
3038e353cfaf







18e9b10fcdc0


3038e353cfaf
53dca51175cc



3038e353cfaf

b9549bc6803d
3038e353cfaf
c781c06d119d
c781c06d119d


3038e353cfaf


7906054f0d59

3038e353cfaf




1e119fa9950d
3038e353cfaf
5c40cbfefa82




3038e353cfaf


1e119fa9950d


3038e353cfaf

e9aeb46c93a8



3038e353cfaf



1e119fa9950d






















53dca51175cc
ba27e1f7bf22
1e119fa9950d



5c40cbfefa82
1e119fa9950d
ba27e1f7bf22
1e119fa9950d
ba27e1f7bf22
1e119fa9950d
5c40cbfefa82
1e119fa9950d




c0220d686b92

ae1e53557911


3038e353cfaf
c0220d686b92
3038e353cfaf

c0220d686b92






83db801ce8c6

3038e353cfaf
ae1e53557911
2a0a2590498b



c0220d686b92








ae1e53557911
c0220d686b92
3038e353cfaf

53dca51175cc

3038e353cfaf











db5d247ae811






53dca51175cc

3038e353cfaf



db5d247ae811
3038e353cfaf








21ebcd1224d0
5af4e5eab30d
db8be076cad4




21ebcd1224d0
5af4e5eab30d
21ebcd1224d0
cca6097713c6

21ebcd1224d0
5af4e5eab30d
db8be076cad4
3038e353cfaf
db5d247ae811





3038e353cfaf
3e0b5f0d7cb5








1415d9189e8c

db5d247ae811
1415d9189e8c

db5d247ae811

3038e353cfaf
53dca51175cc

3038e353cfaf




3e0b5f0d7cb5






3038e353cfaf

3e0b5f0d7cb5
3038e353cfaf
db5d247ae811





3038e353cfaf
3e0b5f0d7cb5
3038e353cfaf










3038e353cfaf


44be21b63e0c
3038e353cfaf
3038e353cfaf







3038e353cfaf



36bfe49d0764
3038e353cfaf




53dca51175cc

3038e353cfaf






53dca51175cc

3038e353cfaf


a77754a75d58




3038e353cfaf

a77754a75d58


36bfe49d0764
a77754a75d58

3038e353cfaf




a77754a75d58
3038e353cfaf





a77754a75d58
93c4cceb963e



3038e353cfaf





a77754a75d58
3038e353cfaf
a77754a75d58

3038e353cfaf
36bfe49d0764

3038e353cfaf


5b189bf3633c
3038e353cfaf
1d1dc5e83f32
19593ffdb6da
3038e353cfaf
93c4cceb963e
3038e353cfaf
53dca51175cc
3038e353cfaf


2639a6fb268e
3038e353cfaf
a77754a75d58
3038e353cfaf

2639a6fb268e
3038e353cfaf




2639a6fb268e
a77754a75d58
3038e353cfaf








a77754a75d58
3038e353cfaf


0bf607c5b4ed

3038e353cfaf


2d826cc5c791
3038e353cfaf


2639a6fb268e








730c32f58ba8
3038e353cfaf
2639a6fb268e
93c4cceb963e
3038e353cfaf
6e2e8424d310
3038e353cfaf
2d826cc5c791
3038e353cfaf



53dca51175cc

3038e353cfaf
db5d247ae811


a7ea67823af4


9c9bdf4d5073
3038e353cfaf
9c9bdf4d5073
3038e353cfaf
36bfe49d0764





3038e353cfaf


3038e353cfaf

db5d247ae811



3038e353cfaf

3038e353cfaf
2639a6fb268e
3038e353cfaf
a77754a75d58

478b233eda81
3038e353cfaf





c781c06d119d

3038e353cfaf


c781c06d119d

3038e353cfaf





2639a6fb268e
3038e353cfaf


db5d247ae811


































































3038e353cfaf

53dca51175cc
3038e353cfaf






a77754a75d58




3038e353cfaf



5c40cbfefa82
753a8970f685
3038e353cfaf





32b46093a076

3038e353cfaf


c781c06d119d



3038e353cfaf


2639a6fb268e
3038e353cfaf









93c4cceb963e
a77754a75d58
3038e353cfaf








5c40cbfefa82

10a4c735515a





3038e353cfaf

3038e353cfaf

ae57988f68ac
cca6097713c6

473d28c730e2
53dca51175cc



473d28c730e2
cb7c96da3651
473d28c730e2











cb7c96da3651
473d28c730e2




85cb9b68640c
473d28c730e2


ae57988f68ac
cca6097713c6

d60d7f1d5ce8
53dca51175cc



d60d7f1d5ce8
15f0d833f63d
d60d7f1d5ce8
e534fe16b987
d60d7f1d5ce8


168cf9af699e

d60d7f1d5ce8
168cf9af699e
e534fe16b987










d60d7f1d5ce8





c781c06d119d

d60d7f1d5ce8


c781c06d119d

d60d7f1d5ce8




e534fe16b987
168cf9af699e


d60d7f1d5ce8
e534fe16b987
d60d7f1d5ce8

e534fe16b987

d60d7f1d5ce8






3038e353cfaf



937f687969f7
3038e353cfaf
937f687969f7
3038e353cfaf




937f687969f7
3038e353cfaf

937f687969f7










3038e353cfaf
937f687969f7







3038e353cfaf

3038e353cfaf

2dbd7d7e2327
3038e353cfaf
2dbd7d7e2327


3038e353cfaf
a3aca3dabbcf





c490a6dec6cc



3038e353cfaf





a3aca3dabbcf
3038e353cfaf
d6053e08f552
3038e353cfaf



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
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064

                                  

















                                                                          
                      
                             

                         
                           


                                     
                      
                          
                         
                       







                           
 
                 
 



















                                                              


                                                                      



                                   


                                                                                
 
                                                                
                                                             
 
                                 


                                              

                                                               
                                                
                                                                  


                              

                                                   
                                                  
                                                        
                                                                    



                         

 



                                                                    

                                                             
 

                                                                     
                                                                   

                           



                                                                         



                                                                          
 
                                                                     


                                     
























                                                                        

                                                                        





                                                                
                                                           






                                                 
                                                       

                            
                                                             
                      
                            
                                                             

                      



                                                                 
                                                   



                      
                                                                            
                                                                             
                                                                        


                      











                                                        
                           
                                          




                                           


                                       
                                                   
                           
                                                                            












                                                    

                                                         











                                                

                                                         


                                           


                                                          
         
        

                                        
                        
                                       

 
















                                                      























                                                                      
                                                                  
                                         
                                                                          







                                                                          


                                                                              
   



                                                                               

                            
                   
 
          


                                                                     


                                              

                                       




                                                                         
                                    
                           




                                                                           


                                         


                                                                  

                                                        



                                                         



                                                     






















                                                                             
                                                                            
                                                    



                                           
                                                    
                                 
                            
                                                                           
                                                                           
                                     
                                                       




                                  

                                           


                                                                          
 
                                   

 






                                                       

                                                                   
 
                                            



                                                      








                                                               
 
                                        

 

                                                                         











                                                               






                                                                          

                                                                         



                                                  
                                                                  








                                             
                                                      
                                                                   




                                                                   
                                                  
                                                                   
                                              

                                                              
                                                     
                                                                   
                 
 





                                                                     
   








                                                                            

                                                   
  

                                                                    

                                                                   
   

                                                                       




                                         






                                                    

                                                        
                                        
                                                                  





                                                                           
                                    
                                                         










                                                                             


                                           
                                                                 
   







                                                                       



                                              
                              




                    

                                                                    






                                                                    

                                                                      


                                                               




                                                                      

                             


                                                
                             

                                       




                                         
                                                                          





                                             
                                                                  



                                                              





                                             
                                                               
                                     

                                                              
                                             

                                                  


                      
                                                          
         
 
                                         
 
                                
 
                                                               


                                   
                             
 
                                                       

                                         
                                     




                                       
                                  
                                                              








                                        
                                                              


                      

                                                                               


                            
                                                                 


                            








                                                                 
                                  
                                                            
                              
                                 
                 
                                                    
 
                                                                      



                       

                                                            
 


                                                                    


                                                                          
                               
                       
         
 





                                                                             


                                                              

                                



                                                                       

                                           
                            
                                       
 

                                                           
                                                      





                                                                            

                                                                   


                                                                    

                                                    





                                                                     
                                                                          


                                                                         


































































                                                                           

                                      
                                                                       






                                                      




                                                           



                                                                  
                                                
                                                                  





                                                   

                                                                          


                       



                                                                     


                                         
                                             









                                       
                                  
                                                                   








                                                                       

                                                





                                                                         

                                                                      

                                       
                                                           

                                                               
 



                                                                                 
 
                  











                                                                     
                                                            




                                                        
                                        


                                                      
                                                        

                                                         
 



                                                                              
 
                                              
                               
                                   


                            

                                                                                
                    
                                                 










                                                                            





                                       

                                                                    


                                                                     

                                




                                            
 


                                                                        
                
                                            

                      

                                               






                                                   



                                                        
                                                
                                        
                   




                                             
                                             

  










                                                        
                          







                                                       

  

                                    
                
 


                                         
 





                                                                       



                                                                         





                                        
                                                     
                                     
                                    



                             
/*
 * Core IEEE1394 transaction logic
 *
 * Copyright (C) 2004-2006 Kristian Hoegsberg <krh@bitplanet.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <linux/bug.h>
#include <linux/completion.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/firewire.h>
#include <linux/firewire-constants.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/idr.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/types.h>

#include <asm/byteorder.h>

#include "core.h"

#define HEADER_PRI(pri)			((pri) << 0)
#define HEADER_TCODE(tcode)		((tcode) << 4)
#define HEADER_RETRY(retry)		((retry) << 8)
#define HEADER_TLABEL(tlabel)		((tlabel) << 10)
#define HEADER_DESTINATION(destination)	((destination) << 16)
#define HEADER_SOURCE(source)		((source) << 16)
#define HEADER_RCODE(rcode)		((rcode) << 12)
#define HEADER_OFFSET_HIGH(offset_high)	((offset_high) << 0)
#define HEADER_DATA_LENGTH(length)	((length) << 16)
#define HEADER_EXTENDED_TCODE(tcode)	((tcode) << 0)

#define HEADER_GET_TCODE(q)		(((q) >> 4) & 0x0f)
#define HEADER_GET_TLABEL(q)		(((q) >> 10) & 0x3f)
#define HEADER_GET_RCODE(q)		(((q) >> 12) & 0x0f)
#define HEADER_GET_DESTINATION(q)	(((q) >> 16) & 0xffff)
#define HEADER_GET_SOURCE(q)		(((q) >> 16) & 0xffff)
#define HEADER_GET_OFFSET_HIGH(q)	(((q) >> 0) & 0xffff)
#define HEADER_GET_DATA_LENGTH(q)	(((q) >> 16) & 0xffff)
#define HEADER_GET_EXTENDED_TCODE(q)	(((q) >> 0) & 0xffff)

#define HEADER_DESTINATION_IS_BROADCAST(q) \
	(((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f))

#define PHY_PACKET_CONFIG	0x0
#define PHY_PACKET_LINK_ON	0x1
#define PHY_PACKET_SELF_ID	0x2

#define PHY_CONFIG_GAP_COUNT(gap_count)	(((gap_count) << 16) | (1 << 22))
#define PHY_CONFIG_ROOT_ID(node_id)	((((node_id) & 0x3f) << 24) | (1 << 23))
#define PHY_IDENTIFIER(id)		((id) << 30)

static int close_transaction(struct fw_transaction *transaction,
			     struct fw_card *card, int rcode)
{
	struct fw_transaction *t;
	unsigned long flags;

	spin_lock_irqsave(&card->lock, flags);
	list_for_each_entry(t, &card->transaction_list, link) {
		if (t == transaction) {
			list_del_init(&t->link);
			card->tlabel_mask &= ~(1ULL << t->tlabel);
			break;
		}
	}
	spin_unlock_irqrestore(&card->lock, flags);

	if (&t->link != &card->transaction_list) {
		del_timer_sync(&t->split_timeout_timer);
		t->callback(card, rcode, NULL, 0, t->callback_data);
		return 0;
	}

	return -ENOENT;
}

/*
 * Only valid for transactions that are potentially pending (ie have
 * been sent).
 */
int fw_cancel_transaction(struct fw_card *card,
			  struct fw_transaction *transaction)
{
	/*
	 * Cancel the packet transmission if it's still queued.  That
	 * will call the packet transmission callback which cancels
	 * the transaction.
	 */

	if (card->driver->cancel_packet(card, &transaction->packet) == 0)
		return 0;

	/*
	 * If the request packet has already been sent, we need to see
	 * if the transaction is still pending and remove it in that case.
	 */

	return close_transaction(transaction, card, RCODE_CANCELLED);
}
EXPORT_SYMBOL(fw_cancel_transaction);

static void split_transaction_timeout_callback(unsigned long data)
{
	struct fw_transaction *t = (struct fw_transaction *)data;
	struct fw_card *card = t->card;
	unsigned long flags;

	spin_lock_irqsave(&card->lock, flags);
	if (list_empty(&t->link)) {
		spin_unlock_irqrestore(&card->lock, flags);
		return;
	}
	list_del(&t->link);
	card->tlabel_mask &= ~(1ULL << t->tlabel);
	spin_unlock_irqrestore(&card->lock, flags);

	card->driver->cancel_packet(card, &t->packet);

	/*
	 * At this point cancel_packet will never call the transaction
	 * callback, since we just took the transaction out of the list.
	 * So do it here.
	 */
	t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data);
}

static void transmit_complete_callback(struct fw_packet *packet,
				       struct fw_card *card, int status)
{
	struct fw_transaction *t =
	    container_of(packet, struct fw_transaction, packet);

	switch (status) {
	case ACK_COMPLETE:
		close_transaction(t, card, RCODE_COMPLETE);
		break;
	case ACK_PENDING:
		t->timestamp = packet->timestamp;
		break;
	case ACK_BUSY_X:
	case ACK_BUSY_A:
	case ACK_BUSY_B:
		close_transaction(t, card, RCODE_BUSY);
		break;
	case ACK_DATA_ERROR:
		close_transaction(t, card, RCODE_DATA_ERROR);
		break;
	case ACK_TYPE_ERROR:
		close_transaction(t, card, RCODE_TYPE_ERROR);
		break;
	default:
		/*
		 * In this case the ack is really a juju specific
		 * rcode, so just forward that to the callback.
		 */
		close_transaction(t, card, status);
		break;
	}
}

static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
		int destination_id, int source_id, int generation, int speed,
		unsigned long long offset, void *payload, size_t length)
{
	int ext_tcode;

	if (tcode == TCODE_STREAM_DATA) {
		packet->header[0] =
			HEADER_DATA_LENGTH(length) |
			destination_id |
			HEADER_TCODE(TCODE_STREAM_DATA);
		packet->header_length = 4;
		packet->payload = payload;
		packet->payload_length = length;

		goto common;
	}

	if (tcode > 0x10) {
		ext_tcode = tcode & ~0x10;
		tcode = TCODE_LOCK_REQUEST;
	} else
		ext_tcode = 0;

	packet->header[0] =
		HEADER_RETRY(RETRY_X) |
		HEADER_TLABEL(tlabel) |
		HEADER_TCODE(tcode) |
		HEADER_DESTINATION(destination_id);
	packet->header[1] =
		HEADER_OFFSET_HIGH(offset >> 32) | HEADER_SOURCE(source_id);
	packet->header[2] =
		offset;

	switch (tcode) {
	case TCODE_WRITE_QUADLET_REQUEST:
		packet->header[3] = *(u32 *)payload;
		packet->header_length = 16;
		packet->payload_length = 0;
		break;

	case TCODE_LOCK_REQUEST:
	case TCODE_WRITE_BLOCK_REQUEST:
		packet->header[3] =
			HEADER_DATA_LENGTH(length) |
			HEADER_EXTENDED_TCODE(ext_tcode);
		packet->header_length = 16;
		packet->payload = payload;
		packet->payload_length = length;
		break;

	case TCODE_READ_QUADLET_REQUEST:
		packet->header_length = 12;
		packet->payload_length = 0;
		break;

	case TCODE_READ_BLOCK_REQUEST:
		packet->header[3] =
			HEADER_DATA_LENGTH(length) |
			HEADER_EXTENDED_TCODE(ext_tcode);
		packet->header_length = 16;
		packet->payload_length = 0;
		break;

	default:
		WARN(1, KERN_ERR "wrong tcode %d", tcode);
	}
 common:
	packet->speed = speed;
	packet->generation = generation;
	packet->ack = 0;
	packet->payload_mapped = false;
}

static int allocate_tlabel(struct fw_card *card)
{
	int tlabel;

	tlabel = card->current_tlabel;
	while (card->tlabel_mask & (1ULL << tlabel)) {
		tlabel = (tlabel + 1) & 0x3f;
		if (tlabel == card->current_tlabel)
			return -EBUSY;
	}

	card->current_tlabel = (tlabel + 1) & 0x3f;
	card->tlabel_mask |= 1ULL << tlabel;

	return tlabel;
}

/**
 * This function provides low-level access to the IEEE1394 transaction
 * logic.  Most C programs would use either fw_read(), fw_write() or
 * fw_lock() instead - those function are convenience wrappers for
 * this function.  The fw_send_request() function is primarily
 * provided as a flexible, one-stop entry point for languages bindings
 * and protocol bindings.
 *
 * FIXME: Document this function further, in particular the possible
 * values for rcode in the callback.  In short, we map ACK_COMPLETE to
 * RCODE_COMPLETE, internal errors set errno and set rcode to
 * RCODE_SEND_ERROR (which is out of range for standard ieee1394
 * rcodes).  All other rcodes are forwarded unchanged.  For all
 * errors, payload is NULL, length is 0.
 *
 * Can not expect the callback to be called before the function
 * returns, though this does happen in some cases (ACK_COMPLETE and
 * errors).
 *
 * The payload is only used for write requests and must not be freed
 * until the callback has been called.
 *
 * @param card the card from which to send the request
 * @param tcode the tcode for this transaction.  Do not use
 *   TCODE_LOCK_REQUEST directly, instead use TCODE_LOCK_MASK_SWAP
 *   etc. to specify tcode and ext_tcode.
 * @param node_id the destination node ID (bus ID and PHY ID concatenated)
 * @param generation the generation for which node_id is valid
 * @param speed the speed to use for sending the request
 * @param offset the 48 bit offset on the destination node
 * @param payload the data payload for the request subaction
 * @param length the length in bytes of the data to read
 * @param callback function to be called when the transaction is completed
 * @param callback_data pointer to arbitrary data, which will be
 *   passed to the callback
 *
 * In case of asynchronous stream packets i.e. TCODE_STREAM_DATA, the caller
 * needs to synthesize @destination_id with fw_stream_packet_destination_id().
 */
void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode,
		     int destination_id, int generation, int speed,
		     unsigned long long offset, void *payload, size_t length,
		     fw_transaction_callback_t callback, void *callback_data)
{
	unsigned long flags;
	int tlabel;

	/*
	 * Allocate tlabel from the bitmap and put the transaction on
	 * the list while holding the card spinlock.
	 */

	spin_lock_irqsave(&card->lock, flags);

	tlabel = allocate_tlabel(card);
	if (tlabel < 0) {
		spin_unlock_irqrestore(&card->lock, flags);
		callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data);
		return;
	}

	t->node_id = destination_id;
	t->tlabel = tlabel;
	t->card = card;
	setup_timer(&t->split_timeout_timer,
		    split_transaction_timeout_callback, (unsigned long)t);
	/* FIXME: start this timer later, relative to t->timestamp */
	mod_timer(&t->split_timeout_timer, jiffies + DIV_ROUND_UP(HZ, 10));
	t->callback = callback;
	t->callback_data = callback_data;

	fw_fill_request(&t->packet, tcode, t->tlabel,
			destination_id, card->node_id, generation,
			speed, offset, payload, length);
	t->packet.callback = transmit_complete_callback;

	list_add_tail(&t->link, &card->transaction_list);

	spin_unlock_irqrestore(&card->lock, flags);

	card->driver->send_request(card, &t->packet);
}
EXPORT_SYMBOL(fw_send_request);

struct transaction_callback_data {
	struct completion done;
	void *payload;
	int rcode;
};

static void transaction_callback(struct fw_card *card, int rcode,
				 void *payload, size_t length, void *data)
{
	struct transaction_callback_data *d = data;

	if (rcode == RCODE_COMPLETE)
		memcpy(d->payload, payload, length);
	d->rcode = rcode;
	complete(&d->done);
}

/**
 * fw_run_transaction - send request and sleep until transaction is completed
 *
 * Returns the RCODE.
 */
int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
		       int generation, int speed, unsigned long long offset,
		       void *payload, size_t length)
{
	struct transaction_callback_data d;
	struct fw_transaction t;

	init_timer_on_stack(&t.split_timeout_timer);
	init_completion(&d.done);
	d.payload = payload;
	fw_send_request(card, &t, tcode, destination_id, generation, speed,
			offset, payload, length, transaction_callback, &d);
	wait_for_completion(&d.done);
	destroy_timer_on_stack(&t.split_timeout_timer);

	return d.rcode;
}
EXPORT_SYMBOL(fw_run_transaction);

static DEFINE_MUTEX(phy_config_mutex);
static DECLARE_COMPLETION(phy_config_done);

static void transmit_phy_packet_callback(struct fw_packet *packet,
					 struct fw_card *card, int status)
{
	complete(&phy_config_done);
}

static struct fw_packet phy_config_packet = {
	.header_length	= 8,
	.payload_length	= 0,
	.speed		= SCODE_100,
	.callback	= transmit_phy_packet_callback,
};

void fw_send_phy_config(struct fw_card *card,
			int node_id, int generation, int gap_count)
{
	long timeout = DIV_ROUND_UP(HZ, 10);
	u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG) |
		   PHY_CONFIG_ROOT_ID(node_id) |
		   PHY_CONFIG_GAP_COUNT(gap_count);

	mutex_lock(&phy_config_mutex);

	phy_config_packet.header[0] = data;