@@ -264,15 +264,15 @@ struct gsm_mux {
264264 bool constipated ; /* Asked by remote to shut up */
265265 bool has_devices ; /* Devices were registered */
266266
267- struct mutex tx_mutex ;
267+ spinlock_t tx_lock ;
268268 unsigned int tx_bytes ; /* TX data outstanding */
269269#define TX_THRESH_HI 8192
270270#define TX_THRESH_LO 2048
271271 struct list_head tx_ctrl_list ; /* Pending control packets */
272272 struct list_head tx_data_list ; /* Pending data packets */
273273
274274 /* Control messages */
275- struct delayed_work kick_timeout ; /* Kick TX queuing on timeout */
275+ struct timer_list kick_timer ; /* Kick TX queuing on timeout */
276276 struct timer_list t2_timer ; /* Retransmit timer for commands */
277277 int cretries ; /* Command retry counter */
278278 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)
700700 struct gsm_msg * msg ;
701701 u8 * dp ;
702702 int ocr ;
703+ unsigned long flags ;
703704
704705 msg = gsm_data_alloc (gsm , addr , 0 , control );
705706 if (!msg )
@@ -721,10 +722,10 @@ static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
721722
722723 gsm_print_packet ("Q->" , addr , cr , control , NULL , 0 );
723724
724- mutex_lock (& gsm -> tx_mutex );
725+ spin_lock_irqsave (& gsm -> tx_lock , flags );
725726 list_add_tail (& msg -> list , & gsm -> tx_ctrl_list );
726727 gsm -> tx_bytes += msg -> len ;
727- mutex_unlock (& gsm -> tx_mutex );
728+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
728729 gsmld_write_trigger (gsm );
729730
730731 return 0 ;
@@ -749,15 +750,15 @@ static void gsm_dlci_clear_queues(struct gsm_mux *gsm, struct gsm_dlci *dlci)
749750 spin_unlock_irqrestore (& dlci -> lock , flags );
750751
751752 /* Clear data packets in MUX write queue */
752- mutex_lock (& gsm -> tx_mutex );
753+ spin_lock_irqsave (& gsm -> tx_lock , flags );
753754 list_for_each_entry_safe (msg , nmsg , & gsm -> tx_data_list , list ) {
754755 if (msg -> addr != addr )
755756 continue ;
756757 gsm -> tx_bytes -= msg -> len ;
757758 list_del (& msg -> list );
758759 kfree (msg );
759760 }
760- mutex_unlock (& gsm -> tx_mutex );
761+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
761762}
762763
763764/**
@@ -1028,7 +1029,7 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
10281029 gsm -> tx_bytes += msg -> len ;
10291030
10301031 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 );
10321033}
10331034
10341035/**
@@ -1043,9 +1044,10 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
10431044
10441045static void gsm_data_queue (struct gsm_dlci * dlci , struct gsm_msg * msg )
10451046{
1046- mutex_lock (& dlci -> gsm -> tx_mutex );
1047+ unsigned long flags ;
1048+ spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
10471049 __gsm_data_queue (dlci , msg );
1048- mutex_unlock (& dlci -> gsm -> tx_mutex );
1050+ spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
10491051}
10501052
10511053/**
@@ -1057,7 +1059,7 @@ static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
10571059 * is data. Keep to the MRU of the mux. This path handles the usual tty
10581060 * interface which is a byte stream with optional modem data.
10591061 *
1060- * Caller must hold the tx_mutex of the mux.
1062+ * Caller must hold the tx_lock of the mux.
10611063 */
10621064
10631065static 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)
11171119 * is data. Keep to the MRU of the mux. This path handles framed data
11181120 * queued as skbuffs to the DLCI.
11191121 *
1120- * Caller must hold the tx_mutex of the mux.
1122+ * Caller must hold the tx_lock of the mux.
11211123 */
11221124
11231125static 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,
11331135 if (dlci -> adaption == 4 )
11341136 overhead = 1 ;
11351137
1136- /* dlci->skb is locked by tx_mutex */
1138+ /* dlci->skb is locked by tx_lock */
11371139 if (dlci -> skb == NULL ) {
11381140 dlci -> skb = skb_dequeue_tail (& dlci -> skb_list );
11391141 if (dlci -> skb == NULL )
@@ -1187,7 +1189,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
11871189 * Push an empty frame in to the transmit queue to update the modem status
11881190 * bits and to transmit an optional break.
11891191 *
1190- * Caller must hold the tx_mutex of the mux.
1192+ * Caller must hold the tx_lock of the mux.
11911193 */
11921194
11931195static 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)
13011303
13021304static void gsm_dlci_data_kick (struct gsm_dlci * dlci )
13031305{
1306+ unsigned long flags ;
13041307 int sweep ;
13051308
13061309 if (dlci -> constipated )
13071310 return ;
13081311
1309- mutex_lock (& dlci -> gsm -> tx_mutex );
1312+ spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
13101313 /* If we have nothing running then we need to fire up */
13111314 sweep = (dlci -> gsm -> tx_bytes < TX_THRESH_LO );
13121315 if (dlci -> gsm -> tx_bytes == 0 ) {
@@ -1317,7 +1320,7 @@ static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
13171320 }
13181321 if (sweep )
13191322 gsm_dlci_data_sweep (dlci -> gsm );
1320- mutex_unlock (& dlci -> gsm -> tx_mutex );
1323+ spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
13211324}
13221325
13231326/*
@@ -1708,7 +1711,7 @@ static struct gsm_control *gsm_control_send(struct gsm_mux *gsm,
17081711 unsigned int command , u8 * data , int clen )
17091712{
17101713 struct gsm_control * ctrl = kzalloc (sizeof (struct gsm_control ),
1711- GFP_KERNEL );
1714+ GFP_ATOMIC );
17121715 unsigned long flags ;
17131716 if (ctrl == NULL )
17141717 return NULL ;
@@ -2019,23 +2022,24 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
20192022}
20202023
20212024/**
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
20242027 *
20252028 * Transmit data from DLCIs if the queue is empty. We can't rely on
20262029 * a tty wakeup except when we filled the pipe so we need to fire off
20272030 * new data ourselves in other cases.
20282031 */
2029- static void gsm_kick_timeout (struct work_struct * work )
2032+ static void gsm_kick_timer (struct timer_list * t )
20302033{
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 ;
20322036 int sent = 0 ;
20332037
2034- mutex_lock (& gsm -> tx_mutex );
2038+ spin_lock_irqsave (& gsm -> tx_lock , flags );
20352039 /* If we have nothing running then we need to fire up */
20362040 if (gsm -> tx_bytes < TX_THRESH_LO )
20372041 sent = gsm_dlci_data_sweep (gsm );
2038- mutex_unlock (& gsm -> tx_mutex );
2042+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
20392043
20402044 if (sent && debug & DBG_DATA )
20412045 pr_info ("%s TX queue stalled\n" , __func__ );
@@ -2492,7 +2496,7 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc)
24922496 }
24932497
24942498 /* Finish outstanding timers, making sure they are done */
2495- cancel_delayed_work_sync (& gsm -> kick_timeout );
2499+ del_timer_sync (& gsm -> kick_timer );
24962500 del_timer_sync (& gsm -> t2_timer );
24972501
24982502 /* Finish writing to ldisc */
@@ -2565,7 +2569,6 @@ static void gsm_free_mux(struct gsm_mux *gsm)
25652569 break ;
25662570 }
25672571 }
2568- mutex_destroy (& gsm -> tx_mutex );
25692572 mutex_destroy (& gsm -> mutex );
25702573 kfree (gsm -> txframe );
25712574 kfree (gsm -> buf );
@@ -2637,15 +2640,15 @@ static struct gsm_mux *gsm_alloc_mux(void)
26372640 }
26382641 spin_lock_init (& gsm -> lock );
26392642 mutex_init (& gsm -> mutex );
2640- mutex_init (& gsm -> tx_mutex );
26412643 kref_init (& gsm -> ref );
26422644 INIT_LIST_HEAD (& gsm -> tx_ctrl_list );
26432645 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 );
26452647 timer_setup (& gsm -> t2_timer , gsm_control_retransmit , 0 );
26462648 INIT_WORK (& gsm -> tx_work , gsmld_write_task );
26472649 init_waitqueue_head (& gsm -> event );
26482650 spin_lock_init (& gsm -> control_lock );
2651+ spin_lock_init (& gsm -> tx_lock );
26492652
26502653 gsm -> t1 = T1 ;
26512654 gsm -> t2 = T2 ;
@@ -2670,7 +2673,6 @@ static struct gsm_mux *gsm_alloc_mux(void)
26702673 }
26712674 spin_unlock (& gsm_mux_lock );
26722675 if (i == MAX_MUX ) {
2673- mutex_destroy (& gsm -> tx_mutex );
26742676 mutex_destroy (& gsm -> mutex );
26752677 kfree (gsm -> txframe );
26762678 kfree (gsm -> buf );
@@ -2826,16 +2828,17 @@ static void gsmld_write_trigger(struct gsm_mux *gsm)
28262828static void gsmld_write_task (struct work_struct * work )
28272829{
28282830 struct gsm_mux * gsm = container_of (work , struct gsm_mux , tx_work );
2831+ unsigned long flags ;
28292832 int i , ret ;
28302833
28312834 /* All outstanding control channel and control messages and one data
28322835 * frame is sent.
28332836 */
28342837 ret = - ENODEV ;
2835- mutex_lock (& gsm -> tx_mutex );
2838+ spin_lock_irqsave (& gsm -> tx_lock , flags );
28362839 if (gsm -> tty )
28372840 ret = gsm_data_kick (gsm );
2838- mutex_unlock (& gsm -> tx_mutex );
2841+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
28392842
28402843 if (ret >= 0 )
28412844 for (i = 0 ; i < NUM_DLCI ; i ++ )
@@ -3042,20 +3045,21 @@ static ssize_t gsmld_write(struct tty_struct *tty, struct file *file,
30423045 const unsigned char * buf , size_t nr )
30433046{
30443047 struct gsm_mux * gsm = tty -> disc_data ;
3048+ unsigned long flags ;
30453049 int space ;
30463050 int ret ;
30473051
30483052 if (!gsm )
30493053 return - ENODEV ;
30503054
30513055 ret = - ENOBUFS ;
3052- mutex_lock (& gsm -> tx_mutex );
3056+ spin_lock_irqsave (& gsm -> tx_lock , flags );
30533057 space = tty_write_room (tty );
30543058 if (space >= nr )
30553059 ret = tty -> ops -> write (tty , buf , nr );
30563060 else
30573061 set_bit (TTY_DO_WRITE_WAKEUP , & tty -> flags );
3058- mutex_unlock (& gsm -> tx_mutex );
3062+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
30593063
30603064 return ret ;
30613065}
@@ -3352,13 +3356,14 @@ static struct tty_ldisc_ops tty_ldisc_packet = {
33523356static void gsm_modem_upd_via_data (struct gsm_dlci * dlci , u8 brk )
33533357{
33543358 struct gsm_mux * gsm = dlci -> gsm ;
3359+ unsigned long flags ;
33553360
33563361 if (dlci -> state != DLCI_OPEN || dlci -> adaption != 2 )
33573362 return ;
33583363
3359- mutex_lock (& gsm -> tx_mutex );
3364+ spin_lock_irqsave (& gsm -> tx_lock , flags );
33603365 gsm_dlci_modem_output (gsm , dlci , brk );
3361- mutex_unlock (& gsm -> tx_mutex );
3366+ spin_unlock_irqrestore (& gsm -> tx_lock , flags );
33623367}
33633368
33643369/**
0 commit comments