aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/gigaset/interface.c')
-rw-r--r--drivers/isdn/gigaset/interface.c158
1 files changed, 34 insertions, 124 deletions
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index ee0a549a933a..8f8814afce86 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -146,13 +146,10 @@ static const struct tty_operations if_ops = {
146static int if_open(struct tty_struct *tty, struct file *filp) 146static int if_open(struct tty_struct *tty, struct file *filp)
147{ 147{
148 struct cardstate *cs; 148 struct cardstate *cs;
149 unsigned long flags;
150 149
151 gig_dbg(DEBUG_IF, "%d+%d: %s()", 150 gig_dbg(DEBUG_IF, "%d+%d: %s()",
152 tty->driver->minor_start, tty->index, __func__); 151 tty->driver->minor_start, tty->index, __func__);
153 152
154 tty->driver_data = NULL;
155
156 cs = gigaset_get_cs_by_tty(tty); 153 cs = gigaset_get_cs_by_tty(tty);
157 if (!cs || !try_module_get(cs->driver->owner)) 154 if (!cs || !try_module_get(cs->driver->owner))
158 return -ENODEV; 155 return -ENODEV;
@@ -163,12 +160,10 @@ static int if_open(struct tty_struct *tty, struct file *filp)
163 } 160 }
164 tty->driver_data = cs; 161 tty->driver_data = cs;
165 162
166 ++cs->open_count; 163 ++cs->port.count;
167 164
168 if (cs->open_count == 1) { 165 if (cs->port.count == 1) {
169 spin_lock_irqsave(&cs->lock, flags); 166 tty_port_tty_set(&cs->port, tty);
170 cs->tty = tty;
171 spin_unlock_irqrestore(&cs->lock, flags);
172 tty->low_latency = 1; 167 tty->low_latency = 1;
173 } 168 }
174 169
@@ -178,12 +173,10 @@ static int if_open(struct tty_struct *tty, struct file *filp)
178 173
179static void if_close(struct tty_struct *tty, struct file *filp) 174static void if_close(struct tty_struct *tty, struct file *filp)
180{ 175{
181 struct cardstate *cs; 176 struct cardstate *cs = tty->driver_data;
182 unsigned long flags;
183 177
184 cs = (struct cardstate *) tty->driver_data; 178 if (!cs) { /* happens if we didn't find cs in open */
185 if (!cs) { 179 printk(KERN_DEBUG "%s: no cardstate\n", __func__);
186 pr_err("%s: no cardstate\n", __func__);
187 return; 180 return;
188 } 181 }
189 182
@@ -193,15 +186,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
193 186
194 if (!cs->connected) 187 if (!cs->connected)
195 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ 188 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
196 else if (!cs->open_count) 189 else if (!cs->port.count)
197 dev_warn(cs->dev, "%s: device not opened\n", __func__); 190 dev_warn(cs->dev, "%s: device not opened\n", __func__);
198 else { 191 else if (!--cs->port.count)
199 if (!--cs->open_count) { 192 tty_port_tty_set(&cs->port, NULL);
200 spin_lock_irqsave(&cs->lock, flags);
201 cs->tty = NULL;
202 spin_unlock_irqrestore(&cs->lock, flags);
203 }
204 }
205 193
206 mutex_unlock(&cs->mutex); 194 mutex_unlock(&cs->mutex);
207 195
@@ -211,18 +199,12 @@ static void if_close(struct tty_struct *tty, struct file *filp)
211static int if_ioctl(struct tty_struct *tty, 199static int if_ioctl(struct tty_struct *tty,
212 unsigned int cmd, unsigned long arg) 200 unsigned int cmd, unsigned long arg)
213{ 201{
214 struct cardstate *cs; 202 struct cardstate *cs = tty->driver_data;
215 int retval = -ENODEV; 203 int retval = -ENODEV;
216 int int_arg; 204 int int_arg;
217 unsigned char buf[6]; 205 unsigned char buf[6];
218 unsigned version[4]; 206 unsigned version[4];
219 207
220 cs = (struct cardstate *) tty->driver_data;
221 if (!cs) {
222 pr_err("%s: no cardstate\n", __func__);
223 return -ENODEV;
224 }
225
226 gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd); 208 gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
227 209
228 if (mutex_lock_interruptible(&cs->mutex)) 210 if (mutex_lock_interruptible(&cs->mutex))
@@ -231,9 +213,7 @@ static int if_ioctl(struct tty_struct *tty,
231 if (!cs->connected) { 213 if (!cs->connected) {
232 gig_dbg(DEBUG_IF, "not connected"); 214 gig_dbg(DEBUG_IF, "not connected");
233 retval = -ENODEV; 215 retval = -ENODEV;
234 } else if (!cs->open_count) 216 } else {
235 dev_warn(cs->dev, "%s: device not opened\n", __func__);
236 else {
237 retval = 0; 217 retval = 0;
238 switch (cmd) { 218 switch (cmd) {
239 case GIGASET_REDIR: 219 case GIGASET_REDIR:
@@ -285,15 +265,9 @@ static int if_ioctl(struct tty_struct *tty,
285 265
286static int if_tiocmget(struct tty_struct *tty) 266static int if_tiocmget(struct tty_struct *tty)
287{ 267{
288 struct cardstate *cs; 268 struct cardstate *cs = tty->driver_data;
289 int retval; 269 int retval;
290 270
291 cs = (struct cardstate *) tty->driver_data;
292 if (!cs) {
293 pr_err("%s: no cardstate\n", __func__);
294 return -ENODEV;
295 }
296
297 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 271 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
298 272
299 if (mutex_lock_interruptible(&cs->mutex)) 273 if (mutex_lock_interruptible(&cs->mutex))
@@ -309,16 +283,10 @@ static int if_tiocmget(struct tty_struct *tty)
309static int if_tiocmset(struct tty_struct *tty, 283static int if_tiocmset(struct tty_struct *tty,
310 unsigned int set, unsigned int clear) 284 unsigned int set, unsigned int clear)
311{ 285{
312 struct cardstate *cs; 286 struct cardstate *cs = tty->driver_data;
313 int retval; 287 int retval;
314 unsigned mc; 288 unsigned mc;
315 289
316 cs = (struct cardstate *) tty->driver_data;
317 if (!cs) {
318 pr_err("%s: no cardstate\n", __func__);
319 return -ENODEV;
320 }
321
322 gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)", 290 gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
323 cs->minor_index, __func__, set, clear); 291 cs->minor_index, __func__, set, clear);
324 292
@@ -341,16 +309,10 @@ static int if_tiocmset(struct tty_struct *tty,
341 309
342static int if_write(struct tty_struct *tty, const unsigned char *buf, int count) 310static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
343{ 311{
344 struct cardstate *cs; 312 struct cardstate *cs = tty->driver_data;
345 struct cmdbuf_t *cb; 313 struct cmdbuf_t *cb;
346 int retval; 314 int retval;
347 315
348 cs = (struct cardstate *) tty->driver_data;
349 if (!cs) {
350 pr_err("%s: no cardstate\n", __func__);
351 return -ENODEV;
352 }
353
354 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 316 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
355 317
356 if (mutex_lock_interruptible(&cs->mutex)) 318 if (mutex_lock_interruptible(&cs->mutex))
@@ -361,11 +323,6 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
361 retval = -ENODEV; 323 retval = -ENODEV;
362 goto done; 324 goto done;
363 } 325 }
364 if (!cs->open_count) {
365 dev_warn(cs->dev, "%s: device not opened\n", __func__);
366 retval = -ENODEV;
367 goto done;
368 }
369 if (cs->mstate != MS_LOCKED) { 326 if (cs->mstate != MS_LOCKED) {
370 dev_warn(cs->dev, "can't write to unlocked device\n"); 327 dev_warn(cs->dev, "can't write to unlocked device\n");
371 retval = -EBUSY; 328 retval = -EBUSY;
@@ -397,15 +354,9 @@ done:
397 354
398static int if_write_room(struct tty_struct *tty) 355static int if_write_room(struct tty_struct *tty)
399{ 356{
400 struct cardstate *cs; 357 struct cardstate *cs = tty->driver_data;
401 int retval = -ENODEV; 358 int retval = -ENODEV;
402 359
403 cs = (struct cardstate *) tty->driver_data;
404 if (!cs) {
405 pr_err("%s: no cardstate\n", __func__);
406 return -ENODEV;
407 }
408
409 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 360 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
410 361
411 if (mutex_lock_interruptible(&cs->mutex)) 362 if (mutex_lock_interruptible(&cs->mutex))
@@ -414,9 +365,7 @@ static int if_write_room(struct tty_struct *tty)
414 if (!cs->connected) { 365 if (!cs->connected) {
415 gig_dbg(DEBUG_IF, "not connected"); 366 gig_dbg(DEBUG_IF, "not connected");
416 retval = -ENODEV; 367 retval = -ENODEV;
417 } else if (!cs->open_count) 368 } else if (cs->mstate != MS_LOCKED) {
418 dev_warn(cs->dev, "%s: device not opened\n", __func__);
419 else if (cs->mstate != MS_LOCKED) {
420 dev_warn(cs->dev, "can't write to unlocked device\n"); 369 dev_warn(cs->dev, "can't write to unlocked device\n");
421 retval = -EBUSY; 370 retval = -EBUSY;
422 } else 371 } else
@@ -429,23 +378,15 @@ static int if_write_room(struct tty_struct *tty)
429 378
430static int if_chars_in_buffer(struct tty_struct *tty) 379static int if_chars_in_buffer(struct tty_struct *tty)
431{ 380{
432 struct cardstate *cs; 381 struct cardstate *cs = tty->driver_data;
433 int retval = 0; 382 int retval = 0;
434 383
435 cs = (struct cardstate *) tty->driver_data;
436 if (!cs) {
437 pr_err("%s: no cardstate\n", __func__);
438 return 0;
439 }
440
441 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 384 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
442 385
443 mutex_lock(&cs->mutex); 386 mutex_lock(&cs->mutex);
444 387
445 if (!cs->connected) 388 if (!cs->connected)
446 gig_dbg(DEBUG_IF, "not connected"); 389 gig_dbg(DEBUG_IF, "not connected");
447 else if (!cs->open_count)
448 dev_warn(cs->dev, "%s: device not opened\n", __func__);
449 else if (cs->mstate != MS_LOCKED) 390 else if (cs->mstate != MS_LOCKED)
450 dev_warn(cs->dev, "can't write to unlocked device\n"); 391 dev_warn(cs->dev, "can't write to unlocked device\n");
451 else 392 else
@@ -458,13 +399,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
458 399
459static void if_throttle(struct tty_struct *tty) 400static void if_throttle(struct tty_struct *tty)
460{ 401{
461 struct cardstate *cs; 402 struct cardstate *cs = tty->driver_data;
462
463 cs = (struct cardstate *) tty->driver_data;
464 if (!cs) {
465 pr_err("%s: no cardstate\n", __func__);
466 return;
467 }
468 403
469 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 404 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
470 405
@@ -472,8 +407,6 @@ static void if_throttle(struct tty_struct *tty)
472 407
473 if (!cs->connected) 408 if (!cs->connected)
474 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ 409 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
475 else if (!cs->open_count)
476 dev_warn(cs->dev, "%s: device not opened\n", __func__);
477 else 410 else
478 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); 411 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
479 412
@@ -482,13 +415,7 @@ static void if_throttle(struct tty_struct *tty)
482 415
483static void if_unthrottle(struct tty_struct *tty) 416static void if_unthrottle(struct tty_struct *tty)
484{ 417{
485 struct cardstate *cs; 418 struct cardstate *cs = tty->driver_data;
486
487 cs = (struct cardstate *) tty->driver_data;
488 if (!cs) {
489 pr_err("%s: no cardstate\n", __func__);
490 return;
491 }
492 419
493 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 420 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
494 421
@@ -496,8 +423,6 @@ static void if_unthrottle(struct tty_struct *tty)
496 423
497 if (!cs->connected) 424 if (!cs->connected)
498 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ 425 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
499 else if (!cs->open_count)
500 dev_warn(cs->dev, "%s: device not opened\n", __func__);
501 else 426 else
502 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); 427 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
503 428
@@ -506,18 +431,12 @@ static void if_unthrottle(struct tty_struct *tty)
506 431
507static void if_set_termios(struct tty_struct *tty, struct ktermios *old) 432static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
508{ 433{
509 struct cardstate *cs; 434 struct cardstate *cs = tty->driver_data;
510 unsigned int iflag; 435 unsigned int iflag;
511 unsigned int cflag; 436 unsigned int cflag;
512 unsigned int old_cflag; 437 unsigned int old_cflag;
513 unsigned int control_state, new_state; 438 unsigned int control_state, new_state;
514 439
515 cs = (struct cardstate *) tty->driver_data;
516 if (!cs) {
517 pr_err("%s: no cardstate\n", __func__);
518 return;
519 }
520
521 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 440 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
522 441
523 mutex_lock(&cs->mutex); 442 mutex_lock(&cs->mutex);
@@ -527,11 +446,6 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
527 goto out; 446 goto out;
528 } 447 }
529 448
530 if (!cs->open_count) {
531 dev_warn(cs->dev, "%s: device not opened\n", __func__);
532 goto out;
533 }
534
535 iflag = tty->termios->c_iflag; 449 iflag = tty->termios->c_iflag;
536 cflag = tty->termios->c_cflag; 450 cflag = tty->termios->c_cflag;
537 old_cflag = old ? old->c_cflag : cflag; 451 old_cflag = old ? old->c_cflag : cflag;
@@ -588,10 +502,13 @@ out:
588/* wakeup tasklet for the write operation */ 502/* wakeup tasklet for the write operation */
589static void if_wake(unsigned long data) 503static void if_wake(unsigned long data)
590{ 504{
591 struct cardstate *cs = (struct cardstate *) data; 505 struct cardstate *cs = (struct cardstate *)data;
506 struct tty_struct *tty = tty_port_tty_get(&cs->port);
592 507
593 if (cs->tty) 508 if (tty) {
594 tty_wakeup(cs->tty); 509 tty_wakeup(tty);
510 tty_kref_put(tty);
511 }
595} 512}
596 513
597/*** interface to common ***/ 514/*** interface to common ***/
@@ -644,18 +561,16 @@ void gigaset_if_free(struct cardstate *cs)
644void gigaset_if_receive(struct cardstate *cs, 561void gigaset_if_receive(struct cardstate *cs,
645 unsigned char *buffer, size_t len) 562 unsigned char *buffer, size_t len)
646{ 563{
647 unsigned long flags; 564 struct tty_struct *tty = tty_port_tty_get(&cs->port);
648 struct tty_struct *tty;
649 565
650 spin_lock_irqsave(&cs->lock, flags); 566 if (tty == NULL) {
651 tty = cs->tty;
652 if (tty == NULL)
653 gig_dbg(DEBUG_IF, "receive on closed device"); 567 gig_dbg(DEBUG_IF, "receive on closed device");
654 else { 568 return;
655 tty_insert_flip_string(tty, buffer, len);
656 tty_flip_buffer_push(tty);
657 } 569 }
658 spin_unlock_irqrestore(&cs->lock, flags); 570
571 tty_insert_flip_string(tty, buffer, len);
572 tty_flip_buffer_push(tty);
573 tty_kref_put(tty);
659} 574}
660EXPORT_SYMBOL_GPL(gigaset_if_receive); 575EXPORT_SYMBOL_GPL(gigaset_if_receive);
661 576
@@ -669,17 +584,15 @@ EXPORT_SYMBOL_GPL(gigaset_if_receive);
669void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, 584void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
670 const char *devname) 585 const char *devname)
671{ 586{
672 unsigned minors = drv->minors;
673 int ret; 587 int ret;
674 struct tty_driver *tty; 588 struct tty_driver *tty;
675 589
676 drv->have_tty = 0; 590 drv->have_tty = 0;
677 591
678 drv->tty = tty = alloc_tty_driver(minors); 592 drv->tty = tty = alloc_tty_driver(drv->minors);
679 if (tty == NULL) 593 if (tty == NULL)
680 goto enomem; 594 goto enomem;
681 595
682 tty->magic = TTY_DRIVER_MAGIC,
683 tty->type = TTY_DRIVER_TYPE_SERIAL, 596 tty->type = TTY_DRIVER_TYPE_SERIAL,
684 tty->subtype = SERIAL_TYPE_NORMAL, 597 tty->subtype = SERIAL_TYPE_NORMAL,
685 tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 598 tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
@@ -687,9 +600,6 @@ void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
687 tty->driver_name = procname; 600 tty->driver_name = procname;
688 tty->name = devname; 601 tty->name = devname;
689 tty->minor_start = drv->minor; 602 tty->minor_start = drv->minor;
690 tty->num = drv->minors;
691
692 tty->owner = THIS_MODULE;
693 603
694 tty->init_termios = tty_std_termios; 604 tty->init_termios = tty_std_termios;
695 tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 605 tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;