diff options
Diffstat (limited to 'drivers/isdn/gigaset/common.c')
-rw-r--r-- | drivers/isdn/gigaset/common.c | 210 |
1 files changed, 164 insertions, 46 deletions
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c index e4141bf8b2f..1d2ae2e05e0 100644 --- a/drivers/isdn/gigaset/common.c +++ b/drivers/isdn/gigaset/common.c | |||
@@ -22,6 +22,12 @@ | |||
22 | #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers" | 22 | #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers" |
23 | #define DRIVER_DESC "Driver for Gigaset 307x" | 23 | #define DRIVER_DESC "Driver for Gigaset 307x" |
24 | 24 | ||
25 | #ifdef CONFIG_GIGASET_DEBUG | ||
26 | #define DRIVER_DESC_DEBUG " (debug build)" | ||
27 | #else | ||
28 | #define DRIVER_DESC_DEBUG "" | ||
29 | #endif | ||
30 | |||
25 | /* Module parameters */ | 31 | /* Module parameters */ |
26 | int gigaset_debuglevel = DEBUG_DEFAULT; | 32 | int gigaset_debuglevel = DEBUG_DEFAULT; |
27 | EXPORT_SYMBOL_GPL(gigaset_debuglevel); | 33 | EXPORT_SYMBOL_GPL(gigaset_debuglevel); |
@@ -32,6 +38,17 @@ MODULE_PARM_DESC(debug, "debug level"); | |||
32 | #define VALID_MINOR 0x01 | 38 | #define VALID_MINOR 0x01 |
33 | #define VALID_ID 0x02 | 39 | #define VALID_ID 0x02 |
34 | 40 | ||
41 | /** | ||
42 | * gigaset_dbg_buffer() - dump data in ASCII and hex for debugging | ||
43 | * @level: debugging level. | ||
44 | * @msg: message prefix. | ||
45 | * @len: number of bytes to dump. | ||
46 | * @buf: data to dump. | ||
47 | * | ||
48 | * If the current debugging level includes one of the bits set in @level, | ||
49 | * @len bytes starting at @buf are logged to dmesg at KERN_DEBUG prio, | ||
50 | * prefixed by the text @msg. | ||
51 | */ | ||
35 | void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, | 52 | void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, |
36 | size_t len, const unsigned char *buf) | 53 | size_t len, const unsigned char *buf) |
37 | { | 54 | { |
@@ -190,6 +207,32 @@ int gigaset_get_channel(struct bc_state *bcs) | |||
190 | return 1; | 207 | return 1; |
191 | } | 208 | } |
192 | 209 | ||
210 | struct bc_state *gigaset_get_free_channel(struct cardstate *cs) | ||
211 | { | ||
212 | unsigned long flags; | ||
213 | int i; | ||
214 | |||
215 | spin_lock_irqsave(&cs->lock, flags); | ||
216 | if (!try_module_get(cs->driver->owner)) { | ||
217 | gig_dbg(DEBUG_ANY, | ||
218 | "could not get module for allocating channel"); | ||
219 | spin_unlock_irqrestore(&cs->lock, flags); | ||
220 | return NULL; | ||
221 | } | ||
222 | for (i = 0; i < cs->channels; ++i) | ||
223 | if (!cs->bcs[i].use_count) { | ||
224 | ++cs->bcs[i].use_count; | ||
225 | cs->bcs[i].busy = 1; | ||
226 | spin_unlock_irqrestore(&cs->lock, flags); | ||
227 | gig_dbg(DEBUG_ANY, "allocated channel %d", i); | ||
228 | return cs->bcs + i; | ||
229 | } | ||
230 | module_put(cs->driver->owner); | ||
231 | spin_unlock_irqrestore(&cs->lock, flags); | ||
232 | gig_dbg(DEBUG_ANY, "no free channel"); | ||
233 | return NULL; | ||
234 | } | ||
235 | |||
193 | void gigaset_free_channel(struct bc_state *bcs) | 236 | void gigaset_free_channel(struct bc_state *bcs) |
194 | { | 237 | { |
195 | unsigned long flags; | 238 | unsigned long flags; |
@@ -274,6 +317,20 @@ static void clear_events(struct cardstate *cs) | |||
274 | spin_unlock_irqrestore(&cs->ev_lock, flags); | 317 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
275 | } | 318 | } |
276 | 319 | ||
320 | /** | ||
321 | * gigaset_add_event() - add event to device event queue | ||
322 | * @cs: device descriptor structure. | ||
323 | * @at_state: connection state structure. | ||
324 | * @type: event type. | ||
325 | * @ptr: pointer parameter for event. | ||
326 | * @parameter: integer parameter for event. | ||
327 | * @arg: pointer parameter for event. | ||
328 | * | ||
329 | * Allocate an event queue entry from the device's event queue, and set it up | ||
330 | * with the parameters given. | ||
331 | * | ||
332 | * Return value: added event | ||
333 | */ | ||
277 | struct event_t *gigaset_add_event(struct cardstate *cs, | 334 | struct event_t *gigaset_add_event(struct cardstate *cs, |
278 | struct at_state_t *at_state, int type, | 335 | struct at_state_t *at_state, int type, |
279 | void *ptr, int parameter, void *arg) | 336 | void *ptr, int parameter, void *arg) |
@@ -398,6 +455,15 @@ static void make_invalid(struct cardstate *cs, unsigned mask) | |||
398 | spin_unlock_irqrestore(&drv->lock, flags); | 455 | spin_unlock_irqrestore(&drv->lock, flags); |
399 | } | 456 | } |
400 | 457 | ||
458 | /** | ||
459 | * gigaset_freecs() - free all associated ressources of a device | ||
460 | * @cs: device descriptor structure. | ||
461 | * | ||
462 | * Stops all tasklets and timers, unregisters the device from all | ||
463 | * subsystems it was registered to, deallocates the device structure | ||
464 | * @cs and all structures referenced from it. | ||
465 | * Operations on the device should be stopped before calling this. | ||
466 | */ | ||
401 | void gigaset_freecs(struct cardstate *cs) | 467 | void gigaset_freecs(struct cardstate *cs) |
402 | { | 468 | { |
403 | int i; | 469 | int i; |
@@ -423,6 +489,12 @@ void gigaset_freecs(struct cardstate *cs) | |||
423 | 489 | ||
424 | switch (cs->cs_init) { | 490 | switch (cs->cs_init) { |
425 | default: | 491 | default: |
492 | /* clear B channel structures */ | ||
493 | for (i = 0; i < cs->channels; ++i) { | ||
494 | gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i); | ||
495 | gigaset_freebcs(cs->bcs + i); | ||
496 | } | ||
497 | |||
426 | /* clear device sysfs */ | 498 | /* clear device sysfs */ |
427 | gigaset_free_dev_sysfs(cs); | 499 | gigaset_free_dev_sysfs(cs); |
428 | 500 | ||
@@ -437,22 +509,16 @@ void gigaset_freecs(struct cardstate *cs) | |||
437 | case 2: /* error in initcshw */ | 509 | case 2: /* error in initcshw */ |
438 | /* Deregister from LL */ | 510 | /* Deregister from LL */ |
439 | make_invalid(cs, VALID_ID); | 511 | make_invalid(cs, VALID_ID); |
440 | gig_dbg(DEBUG_INIT, "clearing iif"); | 512 | gigaset_isdn_unregister(cs); |
441 | gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD); | ||
442 | 513 | ||
443 | /* fall through */ | 514 | /* fall through */ |
444 | case 1: /* error when regestering to LL */ | 515 | case 1: /* error when registering to LL */ |
445 | gig_dbg(DEBUG_INIT, "clearing at_state"); | 516 | gig_dbg(DEBUG_INIT, "clearing at_state"); |
446 | clear_at_state(&cs->at_state); | 517 | clear_at_state(&cs->at_state); |
447 | dealloc_at_states(cs); | 518 | dealloc_at_states(cs); |
448 | 519 | ||
449 | /* fall through */ | 520 | /* fall through */ |
450 | case 0: /* error in one call to initbcs */ | 521 | case 0: /* error in basic setup */ |
451 | for (i = 0; i < cs->channels; ++i) { | ||
452 | gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i); | ||
453 | gigaset_freebcs(cs->bcs + i); | ||
454 | } | ||
455 | |||
456 | clear_events(cs); | 522 | clear_events(cs); |
457 | gig_dbg(DEBUG_INIT, "freeing inbuf"); | 523 | gig_dbg(DEBUG_INIT, "freeing inbuf"); |
458 | kfree(cs->inbuf); | 524 | kfree(cs->inbuf); |
@@ -506,7 +572,12 @@ static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs, | |||
506 | inbuf->inputstate = inputstate; | 572 | inbuf->inputstate = inputstate; |
507 | } | 573 | } |
508 | 574 | ||
509 | /* append received bytes to inbuf */ | 575 | /** |
576 | * gigaset_fill_inbuf() - append received data to input buffer | ||
577 | * @inbuf: buffer structure. | ||
578 | * @src: received data. | ||
579 | * @numbytes: number of bytes received. | ||
580 | */ | ||
510 | int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, | 581 | int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, |
511 | unsigned numbytes) | 582 | unsigned numbytes) |
512 | { | 583 | { |
@@ -575,11 +646,14 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs, | |||
575 | if (cs->ignoreframes) { | 646 | if (cs->ignoreframes) { |
576 | bcs->inputstate |= INS_skip_frame; | 647 | bcs->inputstate |= INS_skip_frame; |
577 | bcs->skb = NULL; | 648 | bcs->skb = NULL; |
578 | } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) | 649 | } else { |
579 | skb_reserve(bcs->skb, HW_HDR_LEN); | 650 | bcs->skb = dev_alloc_skb(SBUFSIZE + cs->hw_hdr_len); |
580 | else { | 651 | if (bcs->skb != NULL) |
581 | pr_err("out of memory\n"); | 652 | skb_reserve(bcs->skb, cs->hw_hdr_len); |
582 | bcs->inputstate |= INS_skip_frame; | 653 | else { |
654 | pr_err("out of memory\n"); | ||
655 | bcs->inputstate |= INS_skip_frame; | ||
656 | } | ||
583 | } | 657 | } |
584 | 658 | ||
585 | bcs->channel = channel; | 659 | bcs->channel = channel; |
@@ -606,20 +680,22 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs, | |||
606 | return NULL; | 680 | return NULL; |
607 | } | 681 | } |
608 | 682 | ||
609 | /* gigaset_initcs | 683 | /** |
684 | * gigaset_initcs() - initialize device structure | ||
685 | * @drv: hardware driver the device belongs to | ||
686 | * @channels: number of B channels supported by device | ||
687 | * @onechannel: !=0 if B channel data and AT commands share one | ||
688 | * communication channel (M10x), | ||
689 | * ==0 if B channels have separate communication channels (base) | ||
690 | * @ignoreframes: number of frames to ignore after setting up B channel | ||
691 | * @cidmode: !=0: start in CallID mode | ||
692 | * @modulename: name of driver module for LL registration | ||
693 | * | ||
610 | * Allocate and initialize cardstate structure for Gigaset driver | 694 | * Allocate and initialize cardstate structure for Gigaset driver |
611 | * Calls hardware dependent gigaset_initcshw() function | 695 | * Calls hardware dependent gigaset_initcshw() function |
612 | * Calls B channel initialization function gigaset_initbcs() for each B channel | 696 | * Calls B channel initialization function gigaset_initbcs() for each B channel |
613 | * parameters: | 697 | * |
614 | * drv hardware driver the device belongs to | 698 | * Return value: |
615 | * channels number of B channels supported by device | ||
616 | * onechannel !=0: B channel data and AT commands share one | ||
617 | * communication channel | ||
618 | * ==0: B channels have separate communication channels | ||
619 | * ignoreframes number of frames to ignore after setting up B channel | ||
620 | * cidmode !=0: start in CallID mode | ||
621 | * modulename name of driver module (used for I4L registration) | ||
622 | * return value: | ||
623 | * pointer to cardstate structure | 699 | * pointer to cardstate structure |
624 | */ | 700 | */ |
625 | struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, | 701 | struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, |
@@ -679,14 +755,6 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, | |||
679 | cs->mode = M_UNKNOWN; | 755 | cs->mode = M_UNKNOWN; |
680 | cs->mstate = MS_UNINITIALIZED; | 756 | cs->mstate = MS_UNINITIALIZED; |
681 | 757 | ||
682 | for (i = 0; i < channels; ++i) { | ||
683 | gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i); | ||
684 | if (!gigaset_initbcs(cs->bcs + i, cs, i)) { | ||
685 | pr_err("could not allocate channel %d data\n", i); | ||
686 | goto error; | ||
687 | } | ||
688 | } | ||
689 | |||
690 | ++cs->cs_init; | 758 | ++cs->cs_init; |
691 | 759 | ||
692 | gig_dbg(DEBUG_INIT, "setting up at_state"); | 760 | gig_dbg(DEBUG_INIT, "setting up at_state"); |
@@ -711,7 +779,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, | |||
711 | cs->cmdbytes = 0; | 779 | cs->cmdbytes = 0; |
712 | 780 | ||
713 | gig_dbg(DEBUG_INIT, "setting up iif"); | 781 | gig_dbg(DEBUG_INIT, "setting up iif"); |
714 | if (!gigaset_register_to_LL(cs, modulename)) { | 782 | if (!gigaset_isdn_register(cs, modulename)) { |
715 | pr_err("error registering ISDN device\n"); | 783 | pr_err("error registering ISDN device\n"); |
716 | goto error; | 784 | goto error; |
717 | } | 785 | } |
@@ -730,6 +798,15 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, | |||
730 | /* set up device sysfs */ | 798 | /* set up device sysfs */ |
731 | gigaset_init_dev_sysfs(cs); | 799 | gigaset_init_dev_sysfs(cs); |
732 | 800 | ||
801 | /* set up channel data structures */ | ||
802 | for (i = 0; i < channels; ++i) { | ||
803 | gig_dbg(DEBUG_INIT, "setting up bcs[%d]", i); | ||
804 | if (!gigaset_initbcs(cs->bcs + i, cs, i)) { | ||
805 | pr_err("could not allocate channel %d data\n", i); | ||
806 | goto error; | ||
807 | } | ||
808 | } | ||
809 | |||
733 | spin_lock_irqsave(&cs->lock, flags); | 810 | spin_lock_irqsave(&cs->lock, flags); |
734 | cs->running = 1; | 811 | cs->running = 1; |
735 | spin_unlock_irqrestore(&cs->lock, flags); | 812 | spin_unlock_irqrestore(&cs->lock, flags); |
@@ -837,6 +914,17 @@ static void cleanup_cs(struct cardstate *cs) | |||
837 | } | 914 | } |
838 | 915 | ||
839 | 916 | ||
917 | /** | ||
918 | * gigaset_start() - start device operations | ||
919 | * @cs: device descriptor structure. | ||
920 | * | ||
921 | * Prepares the device for use by setting up communication parameters, | ||
922 | * scheduling an EV_START event to initiate device initialization, and | ||
923 | * waiting for completion of the initialization. | ||
924 | * | ||
925 | * Return value: | ||
926 | * 1 - success, 0 - error | ||
927 | */ | ||
840 | int gigaset_start(struct cardstate *cs) | 928 | int gigaset_start(struct cardstate *cs) |
841 | { | 929 | { |
842 | unsigned long flags; | 930 | unsigned long flags; |
@@ -879,9 +967,15 @@ error: | |||
879 | } | 967 | } |
880 | EXPORT_SYMBOL_GPL(gigaset_start); | 968 | EXPORT_SYMBOL_GPL(gigaset_start); |
881 | 969 | ||
882 | /* gigaset_shutdown | 970 | /** |
883 | * check if a device is associated to the cardstate structure and stop it | 971 | * gigaset_shutdown() - shut down device operations |
884 | * return value: 0 if ok, -1 if no device was associated | 972 | * @cs: device descriptor structure. |
973 | * | ||
974 | * Deactivates the device by scheduling an EV_SHUTDOWN event and | ||
975 | * waiting for completion of the shutdown. | ||
976 | * | ||
977 | * Return value: | ||
978 | * 0 - success, -1 - error (no device associated) | ||
885 | */ | 979 | */ |
886 | int gigaset_shutdown(struct cardstate *cs) | 980 | int gigaset_shutdown(struct cardstate *cs) |
887 | { | 981 | { |
@@ -912,6 +1006,13 @@ exit: | |||
912 | } | 1006 | } |
913 | EXPORT_SYMBOL_GPL(gigaset_shutdown); | 1007 | EXPORT_SYMBOL_GPL(gigaset_shutdown); |
914 | 1008 | ||
1009 | /** | ||
1010 | * gigaset_stop() - stop device operations | ||
1011 | * @cs: device descriptor structure. | ||
1012 | * | ||
1013 | * Stops operations on the device by scheduling an EV_STOP event and | ||
1014 | * waiting for completion of the shutdown. | ||
1015 | */ | ||
915 | void gigaset_stop(struct cardstate *cs) | 1016 | void gigaset_stop(struct cardstate *cs) |
916 | { | 1017 | { |
917 | mutex_lock(&cs->mutex); | 1018 | mutex_lock(&cs->mutex); |
@@ -1020,6 +1121,14 @@ struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty) | |||
1020 | return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start); | 1121 | return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start); |
1021 | } | 1122 | } |
1022 | 1123 | ||
1124 | /** | ||
1125 | * gigaset_freedriver() - free all associated ressources of a driver | ||
1126 | * @drv: driver descriptor structure. | ||
1127 | * | ||
1128 | * Unregisters the driver from the system and deallocates the driver | ||
1129 | * structure @drv and all structures referenced from it. | ||
1130 | * All devices should be shut down before calling this. | ||
1131 | */ | ||
1023 | void gigaset_freedriver(struct gigaset_driver *drv) | 1132 | void gigaset_freedriver(struct gigaset_driver *drv) |
1024 | { | 1133 | { |
1025 | unsigned long flags; | 1134 | unsigned long flags; |
@@ -1035,14 +1144,16 @@ void gigaset_freedriver(struct gigaset_driver *drv) | |||
1035 | } | 1144 | } |
1036 | EXPORT_SYMBOL_GPL(gigaset_freedriver); | 1145 | EXPORT_SYMBOL_GPL(gigaset_freedriver); |
1037 | 1146 | ||
1038 | /* gigaset_initdriver | 1147 | /** |
1148 | * gigaset_initdriver() - initialize driver structure | ||
1149 | * @minor: First minor number | ||
1150 | * @minors: Number of minors this driver can handle | ||
1151 | * @procname: Name of the driver | ||
1152 | * @devname: Name of the device files (prefix without minor number) | ||
1153 | * | ||
1039 | * Allocate and initialize gigaset_driver structure. Initialize interface. | 1154 | * Allocate and initialize gigaset_driver structure. Initialize interface. |
1040 | * parameters: | 1155 | * |
1041 | * minor First minor number | 1156 | * Return value: |
1042 | * minors Number of minors this driver can handle | ||
1043 | * procname Name of the driver | ||
1044 | * devname Name of the device files (prefix without minor number) | ||
1045 | * return value: | ||
1046 | * Pointer to the gigaset_driver structure on success, NULL on failure. | 1157 | * Pointer to the gigaset_driver structure on success, NULL on failure. |
1047 | */ | 1158 | */ |
1048 | struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, | 1159 | struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, |
@@ -1095,6 +1206,13 @@ error: | |||
1095 | } | 1206 | } |
1096 | EXPORT_SYMBOL_GPL(gigaset_initdriver); | 1207 | EXPORT_SYMBOL_GPL(gigaset_initdriver); |
1097 | 1208 | ||
1209 | /** | ||
1210 | * gigaset_blockdriver() - block driver | ||
1211 | * @drv: driver descriptor structure. | ||
1212 | * | ||
1213 | * Prevents the driver from attaching new devices, in preparation for | ||
1214 | * deregistration. | ||
1215 | */ | ||
1098 | void gigaset_blockdriver(struct gigaset_driver *drv) | 1216 | void gigaset_blockdriver(struct gigaset_driver *drv) |
1099 | { | 1217 | { |
1100 | drv->blocked = 1; | 1218 | drv->blocked = 1; |
@@ -1110,7 +1228,7 @@ static int __init gigaset_init_module(void) | |||
1110 | if (gigaset_debuglevel == 1) | 1228 | if (gigaset_debuglevel == 1) |
1111 | gigaset_debuglevel = DEBUG_DEFAULT; | 1229 | gigaset_debuglevel = DEBUG_DEFAULT; |
1112 | 1230 | ||
1113 | pr_info(DRIVER_DESC "\n"); | 1231 | pr_info(DRIVER_DESC DRIVER_DESC_DEBUG "\n"); |
1114 | return 0; | 1232 | return 0; |
1115 | } | 1233 | } |
1116 | 1234 | ||