@@ -248,15 +248,15 @@ struct gsm_mux {
248248 bool constipated ; /* Asked by remote to shut up */
249249 bool has_devices ; /* Devices were registered */
250250
251- spinlock_t tx_lock ;
251+ struct mutex tx_mutex ;
252252 unsigned int tx_bytes ; /* TX data outstanding */
253253#define TX_THRESH_HI 8192
254254#define TX_THRESH_LO 2048
255255 struct list_head tx_ctrl_list ; /* Pending control packets */
256256 struct list_head tx_data_list ; /* Pending data packets */
257257
258258 /* Control messages */
259- struct timer_list kick_timer ; /* Kick TX queuing on timeout */
259+ struct delayed_work kick_timeout ; /* Kick TX queuing on timeout */
260260 struct timer_list t2_timer ; /* Retransmit timer for commands */
261261 int cretries ; /* Command retry counter */
262262 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)
680680 struct gsm_msg * msg ;
681681 u8 * dp ;
682682 int ocr ;
683- unsigned long flags ;
684683
685684 msg = gsm_data_alloc (gsm , addr , 0 , control );
686685 if (!msg )
@@ -702,10 +701,10 @@ static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
702701
703702 gsm_print_packet ("Q->" , addr , cr , control , NULL , 0 );
704703
705- spin_lock_irqsave (& gsm -> tx_lock , flags );
704+ mutex_lock (& gsm -> tx_mutex );
706705 list_add_tail (& msg -> list , & gsm -> tx_ctrl_list );
707706 gsm -> tx_bytes += msg -> len ;
708- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
707+ mutex_unlock (& gsm -> tx_mutex );
709708 gsmld_write_trigger (gsm );
710709
711710 return 0 ;
@@ -730,15 +729,15 @@ static void gsm_dlci_clear_queues(struct gsm_mux *gsm, struct gsm_dlci *dlci)
730729 spin_unlock_irqrestore (& dlci -> lock , flags );
731730
732731 /* Clear data packets in MUX write queue */
733- spin_lock_irqsave (& gsm -> tx_lock , flags );
732+ mutex_lock (& gsm -> tx_mutex );
734733 list_for_each_entry_safe (msg , nmsg , & gsm -> tx_data_list , list ) {
735734 if (msg -> addr != addr )
736735 continue ;
737736 gsm -> tx_bytes -= msg -> len ;
738737 list_del (& msg -> list );
739738 kfree (msg );
740739 }
741- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
740+ mutex_unlock (& gsm -> tx_mutex );
742741}
743742
744743/**
@@ -1009,7 +1008,7 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
10091008 gsm -> tx_bytes += msg -> len ;
10101009
10111010 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 );
10131012}
10141013
10151014/**
@@ -1024,10 +1023,9 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
10241023
10251024static void gsm_data_queue (struct gsm_dlci * dlci , struct gsm_msg * msg )
10261025{
1027- unsigned long flags ;
1028- spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
1026+ mutex_lock (& dlci -> gsm -> tx_mutex );
10291027 __gsm_data_queue (dlci , msg );
1030- spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
1028+ mutex_unlock (& dlci -> gsm -> tx_mutex );
10311029}
10321030
10331031/**
@@ -1039,7 +1037,7 @@ static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
10391037 * is data. Keep to the MRU of the mux. This path handles the usual tty
10401038 * interface which is a byte stream with optional modem data.
10411039 *
1042- * Caller must hold the tx_lock of the mux.
1040+ * Caller must hold the tx_mutex of the mux.
10431041 */
10441042
10451043static 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)
10991097 * is data. Keep to the MRU of the mux. This path handles framed data
11001098 * queued as skbuffs to the DLCI.
11011099 *
1102- * Caller must hold the tx_lock of the mux.
1100+ * Caller must hold the tx_mutex of the mux.
11031101 */
11041102
11051103static 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,
11151113 if (dlci -> adaption == 4 )
11161114 overhead = 1 ;
11171115
1118- /* dlci->skb is locked by tx_lock */
1116+ /* dlci->skb is locked by tx_mutex */
11191117 if (dlci -> skb == NULL ) {
11201118 dlci -> skb = skb_dequeue_tail (& dlci -> skb_list );
11211119 if (dlci -> skb == NULL )
@@ -1169,7 +1167,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
11691167 * Push an empty frame in to the transmit queue to update the modem status
11701168 * bits and to transmit an optional break.
11711169 *
1172- * Caller must hold the tx_lock of the mux.
1170+ * Caller must hold the tx_mutex of the mux.
11731171 */
11741172
11751173static 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)
12831281
12841282static void gsm_dlci_data_kick (struct gsm_dlci * dlci )
12851283{
1286- unsigned long flags ;
12871284 int sweep ;
12881285
12891286 if (dlci -> constipated )
12901287 return ;
12911288
1292- spin_lock_irqsave (& dlci -> gsm -> tx_lock , flags );
1289+ mutex_lock (& dlci -> gsm -> tx_mutex );
12931290 /* If we have nothing running then we need to fire up */
12941291 sweep = (dlci -> gsm -> tx_bytes < TX_THRESH_LO );
12951292 if (dlci -> gsm -> tx_bytes == 0 ) {
@@ -1300,7 +1297,7 @@ static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
13001297 }
13011298 if (sweep )
13021299 gsm_dlci_data_sweep (dlci -> gsm );
1303- spin_unlock_irqrestore (& dlci -> gsm -> tx_lock , flags );
1300+ mutex_unlock (& dlci -> gsm -> tx_mutex );
13041301}
13051302
13061303/*
@@ -1984,24 +1981,23 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
19841981}
19851982
19861983/**
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
19891986 *
19901987 * Transmit data from DLCIs if the queue is empty. We can't rely on
19911988 * a tty wakeup except when we filled the pipe so we need to fire off
19921989 * new data ourselves in other cases.
19931990 */
1994- static void gsm_kick_timer (struct timer_list * t )
1991+ static void gsm_kick_timeout (struct work_struct * work )
19951992{
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 );
19981994 int sent = 0 ;
19991995
2000- spin_lock_irqsave (& gsm -> tx_lock , flags );
1996+ mutex_lock (& gsm -> tx_mutex );
20011997 /* If we have nothing running then we need to fire up */
20021998 if (gsm -> tx_bytes < TX_THRESH_LO )
20031999 sent = gsm_dlci_data_sweep (gsm );
2004- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
2000+ mutex_unlock (& gsm -> tx_mutex );
20052001
20062002 if (sent && debug & 4 )
20072003 pr_info ("%s TX queue stalled\n" , __func__ );
@@ -2458,7 +2454,7 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc)
24582454 }
24592455
24602456 /* Finish outstanding timers, making sure they are done */
2461- del_timer_sync (& gsm -> kick_timer );
2457+ cancel_delayed_work_sync (& gsm -> kick_timeout );
24622458 del_timer_sync (& gsm -> t2_timer );
24632459
24642460 /* Finish writing to ldisc */
@@ -2501,13 +2497,6 @@ static int gsm_activate_mux(struct gsm_mux *gsm)
25012497 if (dlci == NULL )
25022498 return - ENOMEM ;
25032499
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-
25112500 if (gsm -> encoding == 0 )
25122501 gsm -> receive = gsm0_receive ;
25132502 else
@@ -2538,6 +2527,7 @@ static void gsm_free_mux(struct gsm_mux *gsm)
25382527 break ;
25392528 }
25402529 }
2530+ mutex_destroy (& gsm -> tx_mutex );
25412531 mutex_destroy (& gsm -> mutex );
25422532 kfree (gsm -> txframe );
25432533 kfree (gsm -> buf );
@@ -2609,9 +2599,15 @@ static struct gsm_mux *gsm_alloc_mux(void)
26092599 }
26102600 spin_lock_init (& gsm -> lock );
26112601 mutex_init (& gsm -> mutex );
2602+ mutex_init (& gsm -> tx_mutex );
26122603 kref_init (& gsm -> ref );
26132604 INIT_LIST_HEAD (& gsm -> tx_ctrl_list );
26142605 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 );
26152611
26162612 gsm -> t1 = T1 ;
26172613 gsm -> t2 = T2 ;
@@ -2636,6 +2632,7 @@ static struct gsm_mux *gsm_alloc_mux(void)
26362632 }
26372633 spin_unlock (& gsm_mux_lock );
26382634 if (i == MAX_MUX ) {
2635+ mutex_destroy (& gsm -> tx_mutex );
26392636 mutex_destroy (& gsm -> mutex );
26402637 kfree (gsm -> txframe );
26412638 kfree (gsm -> buf );
@@ -2791,17 +2788,16 @@ static void gsmld_write_trigger(struct gsm_mux *gsm)
27912788static void gsmld_write_task (struct work_struct * work )
27922789{
27932790 struct gsm_mux * gsm = container_of (work , struct gsm_mux , tx_work );
2794- unsigned long flags ;
27952791 int i , ret ;
27962792
27972793 /* All outstanding control channel and control messages and one data
27982794 * frame is sent.
27992795 */
28002796 ret = - ENODEV ;
2801- spin_lock_irqsave (& gsm -> tx_lock , flags );
2797+ mutex_lock (& gsm -> tx_mutex );
28022798 if (gsm -> tty )
28032799 ret = gsm_data_kick (gsm );
2804- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
2800+ mutex_unlock (& gsm -> tx_mutex );
28052801
28062802 if (ret >= 0 )
28072803 for (i = 0 ; i < NUM_DLCI ; i ++ )
@@ -2858,7 +2854,8 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
28582854 flags = * fp ++ ;
28592855 switch (flags ) {
28602856 case TTY_NORMAL :
2861- gsm -> receive (gsm , * cp );
2857+ if (gsm -> receive )
2858+ gsm -> receive (gsm , * cp );
28622859 break ;
28632860 case TTY_OVERRUN :
28642861 case TTY_BREAK :
@@ -2946,10 +2943,6 @@ static int gsmld_open(struct tty_struct *tty)
29462943
29472944 gsmld_attach_gsm (tty , gsm );
29482945
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-
29532946 return 0 ;
29542947}
29552948
@@ -3012,21 +3005,20 @@ static ssize_t gsmld_write(struct tty_struct *tty, struct file *file,
30123005 const unsigned char * buf , size_t nr )
30133006{
30143007 struct gsm_mux * gsm = tty -> disc_data ;
3015- unsigned long flags ;
30163008 int space ;
30173009 int ret ;
30183010
30193011 if (!gsm )
30203012 return - ENODEV ;
30213013
30223014 ret = - ENOBUFS ;
3023- spin_lock_irqsave (& gsm -> tx_lock , flags );
3015+ mutex_lock (& gsm -> tx_mutex );
30243016 space = tty_write_room (tty );
30253017 if (space >= nr )
30263018 ret = tty -> ops -> write (tty , buf , nr );
30273019 else
30283020 set_bit (TTY_DO_WRITE_WAKEUP , & tty -> flags );
3029- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
3021+ mutex_unlock (& gsm -> tx_mutex );
30303022
30313023 return ret ;
30323024}
@@ -3323,14 +3315,13 @@ static struct tty_ldisc_ops tty_ldisc_packet = {
33233315static void gsm_modem_upd_via_data (struct gsm_dlci * dlci , u8 brk )
33243316{
33253317 struct gsm_mux * gsm = dlci -> gsm ;
3326- unsigned long flags ;
33273318
33283319 if (dlci -> state != DLCI_OPEN || dlci -> adaption != 2 )
33293320 return ;
33303321
3331- spin_lock_irqsave (& gsm -> tx_lock , flags );
3322+ mutex_lock (& gsm -> tx_mutex );
33323323 gsm_dlci_modem_output (gsm , dlci , brk );
3333- spin_unlock_irqrestore (& gsm -> tx_lock , flags );
3324+ mutex_unlock (& gsm -> tx_mutex );
33343325}
33353326
33363327/**
0 commit comments