@@ -264,15 +264,15 @@ struct gsm_mux {
264
264
bool constipated ; /* Asked by remote to shut up */
265
265
bool has_devices ; /* Devices were registered */
266
266
267
- struct mutex tx_mutex ;
267
+ spinlock_t tx_lock ;
268
268
unsigned int tx_bytes ; /* TX data outstanding */
269
269
#define TX_THRESH_HI 8192
270
270
#define TX_THRESH_LO 2048
271
271
struct list_head tx_ctrl_list ; /* Pending control packets */
272
272
struct list_head tx_data_list ; /* Pending data packets */
273
273
274
274
/* Control messages */
275
- struct delayed_work kick_timeout ; /* Kick TX queuing on timeout */
275
+ struct timer_list kick_timer ; /* Kick TX queuing on timeout */
276
276
struct timer_list t2_timer ; /* Retransmit timer for commands */
277
277
int cretries ; /* Command retry counter */
278
278
struct gsm_control * pending_cmd ;/* Our current pending command */
@@ -700,6 +700,7 @@ static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
700
700
struct gsm_msg * msg ;
701
701
u8 * dp ;
702
702
int ocr ;
703
+ unsigned long flags ;
703
704
704
705
msg = gsm_data_alloc (gsm , addr , 0 , control );
705
706
if (!msg )
@@ -721,10 +722,10 @@ static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
721
722
722
723
gsm_print_packet ("Q->" , addr , cr , control , NULL , 0 );
723
724
724
- mutex_lock (& gsm -> tx_mutex );
725
+ spin_lock_irqsave (& gsm -> tx_lock , flags );
725
726
list_add_tail (& msg -> list , & gsm -> tx_ctrl_list );
726
727
gsm -> tx_bytes += msg -> len ;
727
- mutex_unlock (& gsm -> tx_mutex );
728
+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
728
729
gsmld_write_trigger (gsm );
729
730
730
731
return 0 ;
@@ -749,15 +750,15 @@ static void gsm_dlci_clear_queues(struct gsm_mux *gsm, struct gsm_dlci *dlci)
749
750
spin_unlock_irqrestore (& dlci -> lock , flags );
750
751
751
752
/* Clear data packets in MUX write queue */
752
- mutex_lock (& gsm -> tx_mutex );
753
+ spin_lock_irqsave (& gsm -> tx_lock , flags );
753
754
list_for_each_entry_safe (msg , nmsg , & gsm -> tx_data_list , list ) {
754
755
if (msg -> addr != addr )
755
756
continue ;
756
757
gsm -> tx_bytes -= msg -> len ;
757
758
list_del (& msg -> list );
758
759
kfree (msg );
759
760
}
760
- mutex_unlock (& gsm -> tx_mutex );
761
+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
761
762
}
762
763
763
764
/**
@@ -1028,7 +1029,7 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
1028
1029
gsm -> tx_bytes += msg -> len ;
1029
1030
1030
1031
gsmld_write_trigger (gsm );
1031
- schedule_delayed_work (& gsm -> kick_timeout , 10 * gsm -> t1 * HZ / 100 );
1032
+ mod_timer (& gsm -> kick_timer , jiffies + 10 * gsm -> t1 * HZ / 100 );
1032
1033
}
1033
1034
1034
1035
/**
@@ -1043,9 +1044,10 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
1043
1044
1044
1045
static void gsm_data_queue (struct gsm_dlci * dlci , struct gsm_msg * msg )
1045
1046
{
1046
- mutex_lock (& dlci -> gsm -> tx_mutex );
1047
+ unsigned long flags ;
1048
+ spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
1047
1049
__gsm_data_queue (dlci , msg );
1048
- mutex_unlock (& dlci -> gsm -> tx_mutex );
1050
+ spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
1049
1051
}
1050
1052
1051
1053
/**
@@ -1057,7 +1059,7 @@ static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
1057
1059
* is data. Keep to the MRU of the mux. This path handles the usual tty
1058
1060
* interface which is a byte stream with optional modem data.
1059
1061
*
1060
- * Caller must hold the tx_mutex of the mux.
1062
+ * Caller must hold the tx_lock of the mux.
1061
1063
*/
1062
1064
1063
1065
static int gsm_dlci_data_output (struct gsm_mux * gsm , struct gsm_dlci * dlci )
@@ -1117,7 +1119,7 @@ static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci)
1117
1119
* is data. Keep to the MRU of the mux. This path handles framed data
1118
1120
* queued as skbuffs to the DLCI.
1119
1121
*
1120
- * Caller must hold the tx_mutex of the mux.
1122
+ * Caller must hold the tx_lock of the mux.
1121
1123
*/
1122
1124
1123
1125
static int gsm_dlci_data_output_framed (struct gsm_mux * gsm ,
@@ -1133,7 +1135,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
1133
1135
if (dlci -> adaption == 4 )
1134
1136
overhead = 1 ;
1135
1137
1136
- /* dlci->skb is locked by tx_mutex */
1138
+ /* dlci->skb is locked by tx_lock */
1137
1139
if (dlci -> skb == NULL ) {
1138
1140
dlci -> skb = skb_dequeue_tail (& dlci -> skb_list );
1139
1141
if (dlci -> skb == NULL )
@@ -1187,7 +1189,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
1187
1189
* Push an empty frame in to the transmit queue to update the modem status
1188
1190
* bits and to transmit an optional break.
1189
1191
*
1190
- * Caller must hold the tx_mutex of the mux.
1192
+ * Caller must hold the tx_lock of the mux.
1191
1193
*/
1192
1194
1193
1195
static int gsm_dlci_modem_output (struct gsm_mux * gsm , struct gsm_dlci * dlci ,
@@ -1301,12 +1303,13 @@ static int gsm_dlci_data_sweep(struct gsm_mux *gsm)
1301
1303
1302
1304
static void gsm_dlci_data_kick (struct gsm_dlci * dlci )
1303
1305
{
1306
+ unsigned long flags ;
1304
1307
int sweep ;
1305
1308
1306
1309
if (dlci -> constipated )
1307
1310
return ;
1308
1311
1309
- mutex_lock (& dlci -> gsm -> tx_mutex );
1312
+ spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
1310
1313
/* If we have nothing running then we need to fire up */
1311
1314
sweep = (dlci -> gsm -> tx_bytes < TX_THRESH_LO );
1312
1315
if (dlci -> gsm -> tx_bytes == 0 ) {
@@ -1317,7 +1320,7 @@ static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
1317
1320
}
1318
1321
if (sweep )
1319
1322
gsm_dlci_data_sweep (dlci -> gsm );
1320
- mutex_unlock (& dlci -> gsm -> tx_mutex );
1323
+ spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
1321
1324
}
1322
1325
1323
1326
/*
@@ -1708,7 +1711,7 @@ static struct gsm_control *gsm_control_send(struct gsm_mux *gsm,
1708
1711
unsigned int command , u8 * data , int clen )
1709
1712
{
1710
1713
struct gsm_control * ctrl = kzalloc (sizeof (struct gsm_control ),
1711
- GFP_KERNEL );
1714
+ GFP_ATOMIC );
1712
1715
unsigned long flags ;
1713
1716
if (ctrl == NULL )
1714
1717
return NULL ;
@@ -2019,23 +2022,24 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
2019
2022
}
2020
2023
2021
2024
/**
2022
- * gsm_kick_timeout - transmit if possible
2023
- * @work: work contained in our gsm object
2025
+ * gsm_kick_timer - transmit if possible
2026
+ * @t: timer contained in our gsm object
2024
2027
*
2025
2028
* Transmit data from DLCIs if the queue is empty. We can't rely on
2026
2029
* a tty wakeup except when we filled the pipe so we need to fire off
2027
2030
* new data ourselves in other cases.
2028
2031
*/
2029
- static void gsm_kick_timeout (struct work_struct * work )
2032
+ static void gsm_kick_timer (struct timer_list * t )
2030
2033
{
2031
- struct gsm_mux * gsm = container_of (work , struct gsm_mux , kick_timeout .work );
2034
+ struct gsm_mux * gsm = from_timer (gsm , t , kick_timer );
2035
+ unsigned long flags ;
2032
2036
int sent = 0 ;
2033
2037
2034
- mutex_lock (& gsm -> tx_mutex );
2038
+ spin_lock_irqsave (& gsm -> tx_lock , flags );
2035
2039
/* If we have nothing running then we need to fire up */
2036
2040
if (gsm -> tx_bytes < TX_THRESH_LO )
2037
2041
sent = gsm_dlci_data_sweep (gsm );
2038
- mutex_unlock (& gsm -> tx_mutex );
2042
+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
2039
2043
2040
2044
if (sent && debug & DBG_DATA )
2041
2045
pr_info ("%s TX queue stalled\n" , __func__ );
@@ -2492,7 +2496,7 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc)
2492
2496
}
2493
2497
2494
2498
/* Finish outstanding timers, making sure they are done */
2495
- cancel_delayed_work_sync (& gsm -> kick_timeout );
2499
+ del_timer_sync (& gsm -> kick_timer );
2496
2500
del_timer_sync (& gsm -> t2_timer );
2497
2501
2498
2502
/* Finish writing to ldisc */
@@ -2565,7 +2569,6 @@ static void gsm_free_mux(struct gsm_mux *gsm)
2565
2569
break ;
2566
2570
}
2567
2571
}
2568
- mutex_destroy (& gsm -> tx_mutex );
2569
2572
mutex_destroy (& gsm -> mutex );
2570
2573
kfree (gsm -> txframe );
2571
2574
kfree (gsm -> buf );
@@ -2637,15 +2640,15 @@ static struct gsm_mux *gsm_alloc_mux(void)
2637
2640
}
2638
2641
spin_lock_init (& gsm -> lock );
2639
2642
mutex_init (& gsm -> mutex );
2640
- mutex_init (& gsm -> tx_mutex );
2641
2643
kref_init (& gsm -> ref );
2642
2644
INIT_LIST_HEAD (& gsm -> tx_ctrl_list );
2643
2645
INIT_LIST_HEAD (& gsm -> tx_data_list );
2644
- INIT_DELAYED_WORK (& gsm -> kick_timeout , gsm_kick_timeout );
2646
+ timer_setup (& gsm -> kick_timer , gsm_kick_timer , 0 );
2645
2647
timer_setup (& gsm -> t2_timer , gsm_control_retransmit , 0 );
2646
2648
INIT_WORK (& gsm -> tx_work , gsmld_write_task );
2647
2649
init_waitqueue_head (& gsm -> event );
2648
2650
spin_lock_init (& gsm -> control_lock );
2651
+ spin_lock_init (& gsm -> tx_lock );
2649
2652
2650
2653
gsm -> t1 = T1 ;
2651
2654
gsm -> t2 = T2 ;
@@ -2670,7 +2673,6 @@ static struct gsm_mux *gsm_alloc_mux(void)
2670
2673
}
2671
2674
spin_unlock (& gsm_mux_lock );
2672
2675
if (i == MAX_MUX ) {
2673
- mutex_destroy (& gsm -> tx_mutex );
2674
2676
mutex_destroy (& gsm -> mutex );
2675
2677
kfree (gsm -> txframe );
2676
2678
kfree (gsm -> buf );
@@ -2826,16 +2828,17 @@ static void gsmld_write_trigger(struct gsm_mux *gsm)
2826
2828
static void gsmld_write_task (struct work_struct * work )
2827
2829
{
2828
2830
struct gsm_mux * gsm = container_of (work , struct gsm_mux , tx_work );
2831
+ unsigned long flags ;
2829
2832
int i , ret ;
2830
2833
2831
2834
/* All outstanding control channel and control messages and one data
2832
2835
* frame is sent.
2833
2836
*/
2834
2837
ret = - ENODEV ;
2835
- mutex_lock (& gsm -> tx_mutex );
2838
+ spin_lock_irqsave (& gsm -> tx_lock , flags );
2836
2839
if (gsm -> tty )
2837
2840
ret = gsm_data_kick (gsm );
2838
- mutex_unlock (& gsm -> tx_mutex );
2841
+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
2839
2842
2840
2843
if (ret >= 0 )
2841
2844
for (i = 0 ; i < NUM_DLCI ; i ++ )
@@ -3042,20 +3045,21 @@ static ssize_t gsmld_write(struct tty_struct *tty, struct file *file,
3042
3045
const unsigned char * buf , size_t nr )
3043
3046
{
3044
3047
struct gsm_mux * gsm = tty -> disc_data ;
3048
+ unsigned long flags ;
3045
3049
int space ;
3046
3050
int ret ;
3047
3051
3048
3052
if (!gsm )
3049
3053
return - ENODEV ;
3050
3054
3051
3055
ret = - ENOBUFS ;
3052
- mutex_lock (& gsm -> tx_mutex );
3056
+ spin_lock_irqsave (& gsm -> tx_lock , flags );
3053
3057
space = tty_write_room (tty );
3054
3058
if (space >= nr )
3055
3059
ret = tty -> ops -> write (tty , buf , nr );
3056
3060
else
3057
3061
set_bit (TTY_DO_WRITE_WAKEUP , & tty -> flags );
3058
- mutex_unlock (& gsm -> tx_mutex );
3062
+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
3059
3063
3060
3064
return ret ;
3061
3065
}
@@ -3352,13 +3356,14 @@ static struct tty_ldisc_ops tty_ldisc_packet = {
3352
3356
static void gsm_modem_upd_via_data (struct gsm_dlci * dlci , u8 brk )
3353
3357
{
3354
3358
struct gsm_mux * gsm = dlci -> gsm ;
3359
+ unsigned long flags ;
3355
3360
3356
3361
if (dlci -> state != DLCI_OPEN || dlci -> adaption != 2 )
3357
3362
return ;
3358
3363
3359
- mutex_lock (& gsm -> tx_mutex );
3364
+ spin_lock_irqsave (& gsm -> tx_lock , flags );
3360
3365
gsm_dlci_modem_output (gsm , dlci , brk );
3361
- mutex_unlock (& gsm -> tx_mutex );
3366
+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
3362
3367
}
3363
3368
3364
3369
/**
0 commit comments