@@ -248,15 +248,15 @@ struct gsm_mux {
248
248
bool constipated ; /* Asked by remote to shut up */
249
249
bool has_devices ; /* Devices were registered */
250
250
251
- spinlock_t tx_lock ;
251
+ struct mutex tx_mutex ;
252
252
unsigned int tx_bytes ; /* TX data outstanding */
253
253
#define TX_THRESH_HI 8192
254
254
#define TX_THRESH_LO 2048
255
255
struct list_head tx_ctrl_list ; /* Pending control packets */
256
256
struct list_head tx_data_list ; /* Pending data packets */
257
257
258
258
/* Control messages */
259
- struct timer_list kick_timer ; /* Kick TX queuing on timeout */
259
+ struct delayed_work kick_timeout ; /* Kick TX queuing on timeout */
260
260
struct timer_list t2_timer ; /* Retransmit timer for commands */
261
261
int cretries ; /* Command retry counter */
262
262
struct gsm_control * pending_cmd ;/* Our current pending command */
@@ -680,7 +680,6 @@ static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
680
680
struct gsm_msg * msg ;
681
681
u8 * dp ;
682
682
int ocr ;
683
- unsigned long flags ;
684
683
685
684
msg = gsm_data_alloc (gsm , addr , 0 , control );
686
685
if (!msg )
@@ -702,10 +701,10 @@ static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
702
701
703
702
gsm_print_packet ("Q->" , addr , cr , control , NULL , 0 );
704
703
705
- spin_lock_irqsave (& gsm -> tx_lock , flags );
704
+ mutex_lock (& gsm -> tx_mutex );
706
705
list_add_tail (& msg -> list , & gsm -> tx_ctrl_list );
707
706
gsm -> tx_bytes += msg -> len ;
708
- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
707
+ mutex_unlock (& gsm -> tx_mutex );
709
708
gsmld_write_trigger (gsm );
710
709
711
710
return 0 ;
@@ -730,15 +729,15 @@ static void gsm_dlci_clear_queues(struct gsm_mux *gsm, struct gsm_dlci *dlci)
730
729
spin_unlock_irqrestore (& dlci -> lock , flags );
731
730
732
731
/* Clear data packets in MUX write queue */
733
- spin_lock_irqsave (& gsm -> tx_lock , flags );
732
+ mutex_lock (& gsm -> tx_mutex );
734
733
list_for_each_entry_safe (msg , nmsg , & gsm -> tx_data_list , list ) {
735
734
if (msg -> addr != addr )
736
735
continue ;
737
736
gsm -> tx_bytes -= msg -> len ;
738
737
list_del (& msg -> list );
739
738
kfree (msg );
740
739
}
741
- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
740
+ mutex_unlock (& gsm -> tx_mutex );
742
741
}
743
742
744
743
/**
@@ -1009,7 +1008,7 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
1009
1008
gsm -> tx_bytes += msg -> len ;
1010
1009
1011
1010
gsmld_write_trigger (gsm );
1012
- mod_timer (& gsm -> kick_timer , jiffies + 10 * gsm -> t1 * HZ / 100 );
1011
+ schedule_delayed_work (& gsm -> kick_timeout , 10 * gsm -> t1 * HZ / 100 );
1013
1012
}
1014
1013
1015
1014
/**
@@ -1024,10 +1023,9 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
1024
1023
1025
1024
static void gsm_data_queue (struct gsm_dlci * dlci , struct gsm_msg * msg )
1026
1025
{
1027
- unsigned long flags ;
1028
- spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
1026
+ mutex_lock (& dlci -> gsm -> tx_mutex );
1029
1027
__gsm_data_queue (dlci , msg );
1030
- spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
1028
+ mutex_unlock (& dlci -> gsm -> tx_mutex );
1031
1029
}
1032
1030
1033
1031
/**
@@ -1039,7 +1037,7 @@ static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
1039
1037
* is data. Keep to the MRU of the mux. This path handles the usual tty
1040
1038
* interface which is a byte stream with optional modem data.
1041
1039
*
1042
- * Caller must hold the tx_lock of the mux.
1040
+ * Caller must hold the tx_mutex of the mux.
1043
1041
*/
1044
1042
1045
1043
static int gsm_dlci_data_output (struct gsm_mux * gsm , struct gsm_dlci * dlci )
@@ -1099,7 +1097,7 @@ static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci)
1099
1097
* is data. Keep to the MRU of the mux. This path handles framed data
1100
1098
* queued as skbuffs to the DLCI.
1101
1099
*
1102
- * Caller must hold the tx_lock of the mux.
1100
+ * Caller must hold the tx_mutex of the mux.
1103
1101
*/
1104
1102
1105
1103
static int gsm_dlci_data_output_framed (struct gsm_mux * gsm ,
@@ -1115,7 +1113,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
1115
1113
if (dlci -> adaption == 4 )
1116
1114
overhead = 1 ;
1117
1115
1118
- /* dlci->skb is locked by tx_lock */
1116
+ /* dlci->skb is locked by tx_mutex */
1119
1117
if (dlci -> skb == NULL ) {
1120
1118
dlci -> skb = skb_dequeue_tail (& dlci -> skb_list );
1121
1119
if (dlci -> skb == NULL )
@@ -1169,7 +1167,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
1169
1167
* Push an empty frame in to the transmit queue to update the modem status
1170
1168
* bits and to transmit an optional break.
1171
1169
*
1172
- * Caller must hold the tx_lock of the mux.
1170
+ * Caller must hold the tx_mutex of the mux.
1173
1171
*/
1174
1172
1175
1173
static int gsm_dlci_modem_output (struct gsm_mux * gsm , struct gsm_dlci * dlci ,
@@ -1283,13 +1281,12 @@ static int gsm_dlci_data_sweep(struct gsm_mux *gsm)
1283
1281
1284
1282
static void gsm_dlci_data_kick (struct gsm_dlci * dlci )
1285
1283
{
1286
- unsigned long flags ;
1287
1284
int sweep ;
1288
1285
1289
1286
if (dlci -> constipated )
1290
1287
return ;
1291
1288
1292
- spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
1289
+ mutex_lock (& dlci -> gsm -> tx_mutex );
1293
1290
/* If we have nothing running then we need to fire up */
1294
1291
sweep = (dlci -> gsm -> tx_bytes < TX_THRESH_LO );
1295
1292
if (dlci -> gsm -> tx_bytes == 0 ) {
@@ -1300,7 +1297,7 @@ static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
1300
1297
}
1301
1298
if (sweep )
1302
1299
gsm_dlci_data_sweep (dlci -> gsm );
1303
- spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
1300
+ mutex_unlock (& dlci -> gsm -> tx_mutex );
1304
1301
}
1305
1302
1306
1303
/*
@@ -1984,24 +1981,23 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
1984
1981
}
1985
1982
1986
1983
/**
1987
- * gsm_kick_timer - transmit if possible
1988
- * @t: timer contained in our gsm object
1984
+ * gsm_kick_timeout - transmit if possible
1985
+ * @work: work contained in our gsm object
1989
1986
*
1990
1987
* Transmit data from DLCIs if the queue is empty. We can't rely on
1991
1988
* a tty wakeup except when we filled the pipe so we need to fire off
1992
1989
* new data ourselves in other cases.
1993
1990
*/
1994
- static void gsm_kick_timer (struct timer_list * t )
1991
+ static void gsm_kick_timeout (struct work_struct * work )
1995
1992
{
1996
- struct gsm_mux * gsm = from_timer (gsm , t , kick_timer );
1997
- unsigned long flags ;
1993
+ struct gsm_mux * gsm = container_of (work , struct gsm_mux , kick_timeout .work );
1998
1994
int sent = 0 ;
1999
1995
2000
- spin_lock_irqsave (& gsm -> tx_lock , flags );
1996
+ mutex_lock (& gsm -> tx_mutex );
2001
1997
/* If we have nothing running then we need to fire up */
2002
1998
if (gsm -> tx_bytes < TX_THRESH_LO )
2003
1999
sent = gsm_dlci_data_sweep (gsm );
2004
- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
2000
+ mutex_unlock (& gsm -> tx_mutex );
2005
2001
2006
2002
if (sent && debug & 4 )
2007
2003
pr_info ("%s TX queue stalled\n" , __func__ );
@@ -2458,7 +2454,7 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc)
2458
2454
}
2459
2455
2460
2456
/* Finish outstanding timers, making sure they are done */
2461
- del_timer_sync (& gsm -> kick_timer );
2457
+ cancel_delayed_work_sync (& gsm -> kick_timeout );
2462
2458
del_timer_sync (& gsm -> t2_timer );
2463
2459
2464
2460
/* Finish writing to ldisc */
@@ -2501,13 +2497,6 @@ static int gsm_activate_mux(struct gsm_mux *gsm)
2501
2497
if (dlci == NULL )
2502
2498
return - ENOMEM ;
2503
2499
2504
- timer_setup (& gsm -> kick_timer , gsm_kick_timer , 0 );
2505
- timer_setup (& gsm -> t2_timer , gsm_control_retransmit , 0 );
2506
- INIT_WORK (& gsm -> tx_work , gsmld_write_task );
2507
- init_waitqueue_head (& gsm -> event );
2508
- spin_lock_init (& gsm -> control_lock );
2509
- spin_lock_init (& gsm -> tx_lock );
2510
-
2511
2500
if (gsm -> encoding == 0 )
2512
2501
gsm -> receive = gsm0_receive ;
2513
2502
else
@@ -2538,6 +2527,7 @@ static void gsm_free_mux(struct gsm_mux *gsm)
2538
2527
break ;
2539
2528
}
2540
2529
}
2530
+ mutex_destroy (& gsm -> tx_mutex );
2541
2531
mutex_destroy (& gsm -> mutex );
2542
2532
kfree (gsm -> txframe );
2543
2533
kfree (gsm -> buf );
@@ -2609,9 +2599,15 @@ static struct gsm_mux *gsm_alloc_mux(void)
2609
2599
}
2610
2600
spin_lock_init (& gsm -> lock );
2611
2601
mutex_init (& gsm -> mutex );
2602
+ mutex_init (& gsm -> tx_mutex );
2612
2603
kref_init (& gsm -> ref );
2613
2604
INIT_LIST_HEAD (& gsm -> tx_ctrl_list );
2614
2605
INIT_LIST_HEAD (& gsm -> tx_data_list );
2606
+ INIT_DELAYED_WORK (& gsm -> kick_timeout , gsm_kick_timeout );
2607
+ timer_setup (& gsm -> t2_timer , gsm_control_retransmit , 0 );
2608
+ INIT_WORK (& gsm -> tx_work , gsmld_write_task );
2609
+ init_waitqueue_head (& gsm -> event );
2610
+ spin_lock_init (& gsm -> control_lock );
2615
2611
2616
2612
gsm -> t1 = T1 ;
2617
2613
gsm -> t2 = T2 ;
@@ -2636,6 +2632,7 @@ static struct gsm_mux *gsm_alloc_mux(void)
2636
2632
}
2637
2633
spin_unlock (& gsm_mux_lock );
2638
2634
if (i == MAX_MUX ) {
2635
+ mutex_destroy (& gsm -> tx_mutex );
2639
2636
mutex_destroy (& gsm -> mutex );
2640
2637
kfree (gsm -> txframe );
2641
2638
kfree (gsm -> buf );
@@ -2791,17 +2788,16 @@ static void gsmld_write_trigger(struct gsm_mux *gsm)
2791
2788
static void gsmld_write_task (struct work_struct * work )
2792
2789
{
2793
2790
struct gsm_mux * gsm = container_of (work , struct gsm_mux , tx_work );
2794
- unsigned long flags ;
2795
2791
int i , ret ;
2796
2792
2797
2793
/* All outstanding control channel and control messages and one data
2798
2794
* frame is sent.
2799
2795
*/
2800
2796
ret = - ENODEV ;
2801
- spin_lock_irqsave (& gsm -> tx_lock , flags );
2797
+ mutex_lock (& gsm -> tx_mutex );
2802
2798
if (gsm -> tty )
2803
2799
ret = gsm_data_kick (gsm );
2804
- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
2800
+ mutex_unlock (& gsm -> tx_mutex );
2805
2801
2806
2802
if (ret >= 0 )
2807
2803
for (i = 0 ; i < NUM_DLCI ; i ++ )
@@ -2858,7 +2854,8 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
2858
2854
flags = * fp ++ ;
2859
2855
switch (flags ) {
2860
2856
case TTY_NORMAL :
2861
- gsm -> receive (gsm , * cp );
2857
+ if (gsm -> receive )
2858
+ gsm -> receive (gsm , * cp );
2862
2859
break ;
2863
2860
case TTY_OVERRUN :
2864
2861
case TTY_BREAK :
@@ -2946,10 +2943,6 @@ static int gsmld_open(struct tty_struct *tty)
2946
2943
2947
2944
gsmld_attach_gsm (tty , gsm );
2948
2945
2949
- timer_setup (& gsm -> kick_timer , gsm_kick_timer , 0 );
2950
- timer_setup (& gsm -> t2_timer , gsm_control_retransmit , 0 );
2951
- INIT_WORK (& gsm -> tx_work , gsmld_write_task );
2952
-
2953
2946
return 0 ;
2954
2947
}
2955
2948
@@ -3012,21 +3005,20 @@ static ssize_t gsmld_write(struct tty_struct *tty, struct file *file,
3012
3005
const unsigned char * buf , size_t nr )
3013
3006
{
3014
3007
struct gsm_mux * gsm = tty -> disc_data ;
3015
- unsigned long flags ;
3016
3008
int space ;
3017
3009
int ret ;
3018
3010
3019
3011
if (!gsm )
3020
3012
return - ENODEV ;
3021
3013
3022
3014
ret = - ENOBUFS ;
3023
- spin_lock_irqsave (& gsm -> tx_lock , flags );
3015
+ mutex_lock (& gsm -> tx_mutex );
3024
3016
space = tty_write_room (tty );
3025
3017
if (space >= nr )
3026
3018
ret = tty -> ops -> write (tty , buf , nr );
3027
3019
else
3028
3020
set_bit (TTY_DO_WRITE_WAKEUP , & tty -> flags );
3029
- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
3021
+ mutex_unlock (& gsm -> tx_mutex );
3030
3022
3031
3023
return ret ;
3032
3024
}
@@ -3323,14 +3315,13 @@ static struct tty_ldisc_ops tty_ldisc_packet = {
3323
3315
static void gsm_modem_upd_via_data (struct gsm_dlci * dlci , u8 brk )
3324
3316
{
3325
3317
struct gsm_mux * gsm = dlci -> gsm ;
3326
- unsigned long flags ;
3327
3318
3328
3319
if (dlci -> state != DLCI_OPEN || dlci -> adaption != 2 )
3329
3320
return ;
3330
3321
3331
- spin_lock_irqsave (& gsm -> tx_lock , flags );
3322
+ mutex_lock (& gsm -> tx_mutex );
3332
3323
gsm_dlci_modem_output (gsm , dlci , brk );
3333
- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
3324
+ mutex_unlock (& gsm -> tx_mutex );
3334
3325
}
3335
3326
3336
3327
/**
0 commit comments