28
28
* SUCH DAMAGE.
29
29
*
30
30
* $Id: ng_h4.c,v 1.10 2005/10/31 17:57:43 max Exp $
31
- * $FreeBSD: src /sys/netgraph/bluetooth/drivers/h4/ng_h4.c,v 1.17 2007/08/13 17:19:28 emax Exp $
31
+ * $FreeBSD: head /sys/netgraph/bluetooth/drivers/h4/ng_h4.c 243882 2012-12-05 08:04:20Z glebius $
32
32
*
33
33
* Based on:
34
34
* ---------
53
53
#include <sys/ttycom.h>
54
54
#include <net/if.h>
55
55
#include <net/if_var.h>
56
- #include " ng_message.h"
57
- #include " netgraph.h"
58
- #include " ng_parse.h"
59
- #include " bluetooth/include/ng_bluetooth.h"
60
- #include " bluetooth/include/ng_hci.h"
61
- #include " bluetooth/include/ng_h4.h"
62
- #include " bluetooth/drivers/h4/ng_h4_var.h"
63
- #include " bluetooth/drivers/h4/ng_h4_prse.h"
56
+ #include <netgraph7/ ng_message.h>
57
+ #include <netgraph7/ netgraph.h>
58
+ #include <netgraph7/ ng_parse.h>
59
+ #include <netgraph7/ bluetooth/include/ng_bluetooth.h>
60
+ #include <netgraph7/ bluetooth/include/ng_hci.h>
61
+ #include <netgraph7/ bluetooth/include/ng_h4.h>
62
+ #include <netgraph7/ bluetooth/drivers/h4/ng_h4_var.h>
63
+ #include <netgraph7/ bluetooth/drivers/h4/ng_h4_prse.h>
64
64
65
65
/*****************************************************************************
66
66
*****************************************************************************
@@ -90,7 +90,7 @@ static int ng_h4_write (struct tty *, struct uio *, int);
90
90
static int ng_h4_input (int , struct tty * );
91
91
static int ng_h4_start (struct tty * );
92
92
static int ng_h4_ioctl (struct tty * , u_long , caddr_t ,
93
- int , struct thread * );
93
+ int , struct ucred * );
94
94
95
95
/* Line discipline descriptor */
96
96
static struct linesw ng_h4_disc = {
@@ -172,8 +172,7 @@ ng_h4_open(struct cdev *dev, struct tty *tp)
172
172
sc -> want = 1 ;
173
173
sc -> got = 0 ;
174
174
175
- mtx_init (& sc -> outq .ifq_mtx , "ng_h4 node+queue" , NULL , MTX_DEF );
176
- IFQ_SET_MAXLEN (& sc -> outq , NG_H4_DEFAULTQLEN );
175
+ sc -> outq .ifq_maxlen = NG_H4_DEFAULTQLEN ;
177
176
ng_callout_init (& sc -> timo );
178
177
179
178
NG_H4_LOCK (sc );
@@ -185,7 +184,6 @@ ng_h4_open(struct cdev *dev, struct tty *tp)
185
184
186
185
kprintf ("%s: Unable to create new node!\n" , __func__ );
187
186
188
- mtx_destroy (& sc -> outq .ifq_mtx );
189
187
bzero (sc , sizeof (* sc ));
190
188
kfree (sc , M_NETGRAPH_H4 );
191
189
@@ -203,7 +201,6 @@ ng_h4_open(struct cdev *dev, struct tty *tp)
203
201
kprintf ("%s: %s - node name exists?\n" , __func__ , name );
204
202
205
203
NG_NODE_UNREF (sc -> node );
206
- mtx_destroy (& sc -> outq .ifq_mtx );
207
204
bzero (sc , sizeof (* sc ));
208
205
kfree (sc , M_NETGRAPH_H4 );
209
206
@@ -213,7 +210,7 @@ ng_h4_open(struct cdev *dev, struct tty *tp)
213
210
214
211
/* Set back pointers */
215
212
NG_NODE_SET_PRIVATE (sc -> node , sc );
216
- tp -> t_lsc = (caddr_t ) sc ;
213
+ tp -> t_sc = (caddr_t ) sc ;
217
214
218
215
/* The node has to be a WRITER because data can change node status */
219
216
NG_NODE_FORCE_WRITER (sc -> node );
@@ -243,7 +240,7 @@ ng_h4_open(struct cdev *dev, struct tty *tp)
243
240
static int
244
241
ng_h4_close (struct tty * tp , int flag )
245
242
{
246
- ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_lsc ;
243
+ ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_sc ;
247
244
248
245
lwkt_gettoken (& tty_token );
249
246
ttyflush (tp , FREAD | FWRITE );
@@ -255,7 +252,7 @@ ng_h4_close(struct tty *tp, int flag)
255
252
if (callout_pending (& sc -> timo ))
256
253
ng_uncallout (& sc -> timo , sc -> node );
257
254
258
- tp -> t_lsc = NULL ;
255
+ tp -> t_sc = NULL ;
259
256
sc -> dying = 1 ;
260
257
261
258
NG_H4_UNLOCK (sc );
@@ -293,9 +290,9 @@ ng_h4_write(struct tty *tp, struct uio *uio, int flag)
293
290
294
291
static int
295
292
ng_h4_ioctl (struct tty * tp , u_long cmd , caddr_t data , int flag ,
296
- struct thread * td )
293
+ struct ucred * cred )
297
294
{
298
- ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_lsc ;
295
+ ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_sc ;
299
296
int error = 0 ;
300
297
301
298
if (sc == NULL )
@@ -341,7 +338,7 @@ ng_h4_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
341
338
static int
342
339
ng_h4_input (int c , struct tty * tp )
343
340
{
344
- ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_lsc ;
341
+ ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_sc ;
345
342
346
343
lwkt_gettoken (& tty_token );
347
344
if (sc == NULL || tp != sc -> tp ||
@@ -582,7 +579,7 @@ ng_h4_input(int c, struct tty *tp)
582
579
static int
583
580
ng_h4_start (struct tty * tp )
584
581
{
585
- ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_lsc ;
582
+ ng_h4_info_p sc = (ng_h4_info_p ) tp -> t_sc ;
586
583
struct mbuf * m = NULL ;
587
584
int size ;
588
585
@@ -637,7 +634,8 @@ ng_h4_start(struct tty *tp)
637
634
* being called in lieu of ttstart and must do what it would.
638
635
*/
639
636
640
- tt_oproc (sc -> tp );
637
+ if (tp -> t_oproc != NULL )
638
+ (* tp -> t_oproc ) (tp );
641
639
642
640
/*
643
641
* This timeout is needed for operation on a pseudo-tty, because the
@@ -646,7 +644,7 @@ ng_h4_start(struct tty *tp)
646
644
647
645
NG_H4_LOCK (sc );
648
646
649
- if (!IFQ_IS_EMPTY (& sc -> outq ) && !callout_pending (& sc -> timo ))
647
+ if (!IF_QEMPTY (& sc -> outq ) && !callout_pending (& sc -> timo ))
650
648
ng_callout (& sc -> timo , sc -> node , NULL , 1 ,
651
649
ng_h4_process_timeout , NULL , 0 );
652
650
@@ -741,7 +739,7 @@ ng_h4_disconnect(hook_p hook)
741
739
if (callout_pending (& sc -> timo ))
742
740
ng_uncallout (& sc -> timo , sc -> node );
743
741
744
- _IF_DRAIN (& sc -> outq );
742
+ IF_DRAIN (& sc -> outq );
745
743
746
744
sc -> state = NG_H4_W4_PKT_IND ;
747
745
sc -> want = 1 ;
@@ -779,10 +777,9 @@ ng_h4_shutdown(node_p node)
779
777
780
778
NG_NODE_SET_PRIVATE (node , NULL );
781
779
782
- _IF_DRAIN (& sc -> outq );
780
+ IF_DRAIN (& sc -> outq );
783
781
784
782
NG_NODE_UNREF (node );
785
- mtx_destroy (& sc -> outq .ifq_mtx );
786
783
bzero (sc , sizeof (* sc ));
787
784
kfree (sc , M_NETGRAPH_H4 );
788
785
@@ -812,12 +809,12 @@ ng_h4_rcvdata(hook_p hook, item_p item)
812
809
813
810
NG_H4_LOCK (sc );
814
811
815
- if (_IF_QFULL (& sc -> outq )) {
812
+ if (IF_QFULL (& sc -> outq )) {
816
813
NG_H4_ERR ("%s: %s - dropping mbuf, len=%d\n" , __func__ ,
817
814
NG_NODE_NAME (sc -> node ), m -> m_pkthdr .len );
818
815
819
816
NG_H4_STAT_OERROR (sc -> stat );
820
- _IF_DROP (& sc -> outq );
817
+ IF_DROP (& sc -> outq );
821
818
822
819
NG_H4_UNLOCK (sc );
823
820
@@ -829,20 +826,17 @@ ng_h4_rcvdata(hook_p hook, item_p item)
829
826
NG_H4_INFO ("%s: %s - queue mbuf, len=%d\n" , __func__ ,
830
827
NG_NODE_NAME (sc -> node ), m -> m_pkthdr .len );
831
828
832
- _IF_ENQUEUE (& sc -> outq , m );
833
- qlen = _IF_QLEN (& sc -> outq );
829
+ IF_ENQUEUE (& sc -> outq , m );
830
+ qlen = IF_QLEN (& sc -> outq );
834
831
835
832
NG_H4_UNLOCK (sc );
836
833
837
834
/*
838
835
* If qlen > 1, then we should already have a scheduled callout
839
836
*/
840
837
841
- if (qlen == 1 ) {
842
- mtx_lock (& Giant );
838
+ if (qlen == 1 )
843
839
ng_h4_start (sc -> tp );
844
- mtx_unlock (& Giant );
845
- }
846
840
847
841
return (0 );
848
842
} /* ng_h4_rcvdata */
@@ -881,7 +875,7 @@ ng_h4_rcvmsg(node_p node, item_p item, hook_p lasthook)
881
875
(sc -> hook != NULL )? NG_H4_HOOK : "" ,
882
876
sc -> debug ,
883
877
sc -> state ,
884
- _IF_QLEN (& sc -> outq ),
878
+ IF_QLEN (& sc -> outq ),
885
879
sc -> outq .ifq_maxlen ,
886
880
sc -> got ,
887
881
sc -> want );
@@ -896,7 +890,7 @@ ng_h4_rcvmsg(node_p node, item_p item, hook_p lasthook)
896
890
case NGM_H4_COOKIE :
897
891
switch (msg -> header .cmd ) {
898
892
case NGM_H4_NODE_RESET :
899
- _IF_DRAIN (& sc -> outq );
893
+ IF_DRAIN (& sc -> outq );
900
894
sc -> state = NG_H4_W4_PKT_IND ;
901
895
sc -> want = 1 ;
902
896
sc -> got = 0 ;
@@ -946,8 +940,8 @@ ng_h4_rcvmsg(node_p node, item_p item, hook_p lasthook)
946
940
else if (* ((ng_h4_node_qlen_ep * )(msg -> data )) <= 0 )
947
941
error = EINVAL ;
948
942
else
949
- IFQ_SET_MAXLEN ( & sc -> outq ,
950
- * ((ng_h4_node_qlen_ep * )(msg -> data ))) ;
943
+ sc -> outq . ifq_maxlen =
944
+ * ((ng_h4_node_qlen_ep * )(msg -> data ));
951
945
break ;
952
946
953
947
case NGM_H4_NODE_GET_STAT :
@@ -993,9 +987,7 @@ ng_h4_process_timeout(node_p node, hook_p hook, void *arg1, int arg2)
993
987
{
994
988
ng_h4_info_p sc = (ng_h4_info_p ) NG_NODE_PRIVATE (node );
995
989
996
- mtx_lock (& Giant );
997
990
ng_h4_start (sc -> tp );
998
- mtx_unlock (& Giant );
999
991
} /* ng_h4_process_timeout */
1000
992
1001
993
/*
@@ -1011,9 +1003,9 @@ ng_h4_mod_event(module_t mod, int event, void *data)
1011
1003
switch (event ) {
1012
1004
case MOD_LOAD :
1013
1005
/* Register line discipline */
1014
- mtx_lock ( & Giant );
1015
- ng_h4_ldisc = ldisc_register (H4DISC , & ng_h4_disc );
1016
- mtx_unlock ( & Giant );
1006
+ crit_enter ( );
1007
+ ng_h4_ldisc = ldisc_register (BTUARTDISC , & ng_h4_disc );
1008
+ crit_exit ( );
1017
1009
1018
1010
if (ng_h4_ldisc < 0 ) {
1019
1011
kprintf ("%s: can't register H4 line discipline\n" ,
@@ -1024,9 +1016,9 @@ ng_h4_mod_event(module_t mod, int event, void *data)
1024
1016
1025
1017
case MOD_UNLOAD :
1026
1018
/* Unregister line discipline */
1027
- mtx_lock ( & Giant );
1019
+ crit_enter ( );
1028
1020
ldisc_deregister (ng_h4_ldisc );
1029
- mtx_unlock ( & Giant );
1021
+ crit_exit ( );
1030
1022
break ;
1031
1023
1032
1024
default :
0 commit comments