Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: dgnc: remove unnecessary comments

TODO file lists task to remove unnecessary comments.

Make initial attempt at removing unnecessary comments. Choose not to
be to vicious in removal. We can remove more once the driver is
cleaned up/tested some more.

For functions with internal linkage, reduce the function comment where
possible. For functions with external linkage, migrate the function
comment to kernel doc format.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tobin C. Harding and committed by
Greg Kroah-Hartman
51061652 2539fc0c

+96 -521
+14 -90
drivers/staging/dgnc/dgnc_cls.c
··· 14 14 */ 15 15 16 16 #include <linux/kernel.h> 17 - #include <linux/sched.h> /* For jiffies, task states */ 18 - #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */ 19 - #include <linux/delay.h> /* For udelay */ 20 - #include <linux/io.h> /* For read[bwl]/write[bwl] */ 21 - #include <linux/serial.h> /* For struct async_serial */ 22 - #include <linux/serial_reg.h> /* For the various UART offsets */ 17 + #include <linux/sched.h> 18 + #include <linux/interrupt.h> 19 + #include <linux/delay.h> 20 + #include <linux/io.h> 21 + #include <linux/serial.h> 22 + #include <linux/serial_reg.h> 23 23 #include <linux/pci.h> 24 24 25 - #include "dgnc_driver.h" /* Driver main header file */ 25 + #include "dgnc_driver.h" 26 26 #include "dgnc_cls.h" 27 27 #include "dgnc_tty.h" 28 28 ··· 273 273 } 274 274 275 275 /* 276 - * cls_clear_break. 277 276 * Determines whether its time to shut off break condition. 278 277 * 279 278 * No locks are assumed to be held when calling this function. ··· 287 288 288 289 spin_lock_irqsave(&ch->ch_lock, flags); 289 290 290 - /* Bail if we aren't currently sending a break. */ 291 291 if (!ch->ch_stop_sending_break) { 292 292 spin_unlock_irqrestore(&ch->ch_lock, flags); 293 293 return; ··· 319 321 320 322 spin_lock_irqsave(&ch->ch_lock, flags); 321 323 322 - /* cache head and tail of queue */ 323 324 head = ch->ch_r_head; 324 325 tail = ch->ch_r_tail; 325 326 326 - /* Store how much space we have left in the queue */ 327 327 qleft = tail - head - 1; 328 328 if (qleft < 0) 329 329 qleft += RQUEUEMASK + 1; ··· 339 343 if (!(linestatus & (UART_LSR_DR))) 340 344 break; 341 345 342 - /* 343 - * Discard character if we are ignoring the error mask. 344 - */ 346 + /* Discard character if we are ignoring the error mask. */ 345 347 if (linestatus & error_mask) { 346 348 linestatus = 0; 347 349 readb(&ch->ch_cls_uart->txrx); ··· 350 356 * If our queue is full, we have no choice but to drop some 351 357 * data. The assumption is that HWFLOW or SWFLOW should have 352 358 * stopped things way way before we got to this point. 353 - * 354 - * I decided that I wanted to ditch the oldest data first, 355 - * I hope thats okay with everyone? Yes? Good. 356 359 */ 357 360 while (qleft < 1) { 358 361 tail = (tail + 1) & RQUEUEMASK; ··· 371 380 if (ch->ch_equeue[head] & UART_LSR_FE) 372 381 ch->ch_err_frame++; 373 382 374 - /* Add to, and flip head if needed */ 375 383 head = (head + 1) & RQUEUEMASK; 376 384 ch->ch_rxcount++; 377 385 } 378 - 379 - /* Write new final heads to channel structure. */ 380 386 381 387 ch->ch_r_head = head & RQUEUEMASK; 382 388 ch->ch_e_head = head & EQUEUEMASK; ··· 414 426 415 427 spin_lock_irqsave(&ch->ch_lock, flags); 416 428 417 - /* No data to write to the UART */ 418 429 if (ch->ch_w_tail == ch->ch_w_head) 419 430 goto exit_unlock; 420 431 ··· 427 440 428 441 n = 32; 429 442 430 - /* cache head and tail of queue */ 431 443 head = ch->ch_w_head & WQUEUEMASK; 432 444 tail = ch->ch_w_tail & WQUEUEMASK; 433 445 qlen = (head - tail) & WQUEUEMASK; 434 446 435 - /* Find minimum of the FIFO space, versus queue length */ 436 447 n = min(n, qlen); 437 448 438 449 while (n > 0) { ··· 509 524 } 510 525 spin_unlock_irqrestore(&ch->ch_lock, flags); 511 526 512 - /* 513 - * Scrub off lower bits. They signify delta's, which I don't 514 - * care about 515 - */ 527 + /* Scrub off lower bits. They signify delta's */ 516 528 signals &= 0xf0; 517 529 518 530 spin_lock_irqsave(&ch->ch_lock, flags); ··· 558 576 while (1) { 559 577 isr = readb(&ch->ch_cls_uart->isr_fcr); 560 578 561 - /* Bail if no pending interrupt on port */ 562 579 if (isr & UART_IIR_NO_INT) 563 580 break; 564 581 565 582 /* Receive Interrupt pending */ 566 583 if (isr & (UART_IIR_RDI | UART_IIR_RDI_TIMEOUT)) { 567 - /* Read data from uart -> queue */ 568 584 cls_copy_data_from_uart_to_queue(ch); 569 585 dgnc_check_queue_flow_control(ch); 570 586 } 571 587 572 588 /* Transmit Hold register empty pending */ 573 589 if (isr & UART_IIR_THRI) { 574 - /* Transfer data (if any) from Write Queue -> UART. */ 575 590 spin_lock_irqsave(&ch->ch_lock, flags); 576 591 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 577 592 spin_unlock_irqrestore(&ch->ch_lock, flags); 578 593 cls_copy_data_from_queue_to_uart(ch); 579 594 } 580 595 581 - /* Parse any modem signal changes */ 582 596 cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr)); 583 597 } 584 598 } ··· 614 636 udelay(10); 615 637 } 616 638 617 - /* 618 - * cls_param() 619 - * Send any/all changes to the line to the UART. 620 - */ 639 + /* Send any/all changes to the line to the UART. */ 621 640 static void cls_param(struct tty_struct *tty) 622 641 { 623 642 unsigned char lcr = 0; ··· 643 668 return; 644 669 645 670 /* If baud rate is zero, flush queues, and set mval to drop DTR. */ 646 - 647 671 if ((ch->ch_c_cflag & (CBAUD)) == 0) { 648 672 ch->ch_r_head = 0; 649 673 ch->ch_r_tail = 0; ··· 752 778 if (!(ch->ch_c_cflag & PARODD)) 753 779 lcr |= UART_LCR_EPAR; 754 780 755 - /* 756 - * Not all platforms support mark/space parity, 757 - * so this will hide behind an ifdef. 758 - */ 759 781 #ifdef CMSPAR 760 782 if (ch->ch_c_cflag & CMSPAR) 761 783 lcr |= UART_LCR_SPAR; ··· 822 852 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) { 823 853 cls_set_cts_flow_control(ch); 824 854 } else if (ch->ch_c_iflag & IXON) { 825 - /* 826 - * If start/stop is set to disable, then we should 827 - * disable flow control 828 - */ 829 855 if ((ch->ch_startc == _POSIX_VDISABLE) || 830 856 (ch->ch_stopc == _POSIX_VDISABLE)) 831 857 cls_set_no_output_flow_control(ch); ··· 834 868 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) { 835 869 cls_set_rts_flow_control(ch); 836 870 } else if (ch->ch_c_iflag & IXOFF) { 837 - /* 838 - * If start/stop is set to disable, then we should disable 839 - * flow control 840 - */ 841 871 if ((ch->ch_startc == _POSIX_VDISABLE) || 842 872 (ch->ch_stopc == _POSIX_VDISABLE)) 843 873 cls_set_no_input_flow_control(ch); ··· 845 883 846 884 cls_assert_modem_signals(ch); 847 885 848 - /* Get current status of the modem signals now */ 849 886 cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr)); 850 887 } 851 888 852 - /* Our board poller function. */ 853 - 889 + /* Board poller function. */ 854 890 static void cls_tasklet(unsigned long data) 855 891 { 856 892 struct dgnc_board *bd = (struct dgnc_board *)data; ··· 861 901 if (!bd || bd->magic != DGNC_BOARD_MAGIC) 862 902 return; 863 903 864 - /* Cache a couple board values */ 865 904 spin_lock_irqsave(&bd->bd_lock, flags); 866 905 state = bd->state; 867 906 ports = bd->nasync; ··· 872 913 */ 873 914 spin_lock_irqsave(&bd->bd_intr_lock, flags); 874 915 875 - /* If board is ready, parse deeper to see if there is anything to do. */ 876 - 877 916 if ((state == BOARD_READY) && (ports > 0)) { 878 - /* Loop on each port */ 879 917 for (i = 0; i < ports; i++) { 880 918 ch = bd->channels[i]; 881 919 ··· 892 936 cls_copy_data_from_queue_to_uart(ch); 893 937 dgnc_wakeup_writes(ch); 894 938 895 - /* Check carrier function. */ 896 - 897 939 dgnc_carrier(ch); 898 940 899 941 /* ··· 906 952 spin_unlock_irqrestore(&bd->bd_intr_lock, flags); 907 953 } 908 954 909 - /* 910 - * cls_intr() 911 - * 912 - * Classic specific interrupt handler. 913 - */ 955 + /* Classic specific interrupt handler. */ 914 956 static irqreturn_t cls_intr(int irq, void *voidbrd) 915 957 { 916 958 struct dgnc_board *brd = voidbrd; ··· 914 964 unsigned char poll_reg; 915 965 unsigned long flags; 916 966 917 - /* 918 - * Check to make sure it didn't receive interrupt with a null board 919 - * associated or a board pointer that wasn't ours. 920 - */ 921 967 if (!brd || brd->magic != DGNC_BOARD_MAGIC) 922 968 return IRQ_NONE; 923 969 924 970 spin_lock_irqsave(&brd->bd_intr_lock, flags); 925 971 926 - /* 927 - * Check the board's global interrupt offset to see if we 928 - * we actually do have an interrupt pending for us. 929 - */ 930 972 poll_reg = readb(brd->re_map_membase + UART_CLASSIC_POLL_ADDR_OFFSET); 931 - 932 - /* If 0, no interrupts pending */ 933 973 if (!poll_reg) { 934 974 spin_unlock_irqrestore(&brd->bd_intr_lock, flags); 935 975 return IRQ_NONE; 936 976 } 937 977 938 - /* Parse each port to find out what caused the interrupt */ 939 978 for (i = 0; i < brd->nasync; i++) 940 979 cls_parse_isr(brd, i); 941 - 942 - /* Schedule tasklet to more in-depth servicing at a better time. */ 943 980 944 981 tasklet_schedule(&brd->helper_tasklet); 945 982 ··· 952 1015 } 953 1016 954 1017 /* 955 - * This function basically goes to sleep for secs, or until 1018 + * This function basically goes to sleep for seconds, or until 956 1019 * it gets signalled that the port has fully drained. 957 1020 */ 958 1021 static int cls_drain(struct tty_struct *tty, uint seconds) ··· 1006 1069 } 1007 1070 } 1008 1071 1009 - /* Inits UART */ 1010 1072 static void cls_uart_init(struct channel_t *ch) 1011 1073 { 1012 1074 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr); ··· 1042 1106 readb(&ch->ch_cls_uart->msr); 1043 1107 } 1044 1108 1045 - /* Turns off UART. */ 1046 - 1047 1109 static void cls_uart_off(struct channel_t *ch) 1048 1110 { 1049 1111 writeb(0, &ch->ch_cls_uart->ier); 1050 1112 } 1051 1113 1052 1114 /* 1053 - * cls_get_uarts_bytes_left. 1054 - * Returns 0 is nothing left in the FIFO, returns 1 otherwise. 1055 - * 1056 1115 * The channel lock MUST be held by the calling function. 1116 + * Returns 0 is nothing left in the FIFO, returns 1 otherwise. 1057 1117 */ 1058 1118 static uint cls_get_uart_bytes_left(struct channel_t *ch) 1059 1119 { ··· 1075 1143 } 1076 1144 1077 1145 /* 1078 - * cls_send_break. 1079 1146 * Starts sending a break thru the UART. 1080 - * 1081 1147 * The channel lock MUST be held by the calling function. 1082 1148 */ 1083 1149 static void cls_send_break(struct channel_t *ch, int msecs) ··· 1084 1154 return; 1085 1155 1086 1156 /* If we receive a time of 0, this means turn off the break. */ 1087 - 1088 1157 if (msecs == 0) { 1089 - /* Turn break off, and unset some variables */ 1090 1158 if (ch->ch_flags & CH_BREAK_SENDING) { 1091 1159 unsigned char temp = readb(&ch->ch_cls_uart->lcr); 1092 1160 ··· 1112 1184 } 1113 1185 1114 1186 /* 1115 - * cls_send_immediate_char. 1116 1187 * Sends a specific character as soon as possible to the UART, 1117 1188 * jumping over any bytes that might be in the write queue. 1118 1189 * ··· 1132 1205 int i = 0; 1133 1206 1134 1207 vpdbase = pci_resource_start(brd->pdev, 3); 1135 - 1136 - /* No VPD */ 1137 1208 if (!vpdbase) 1138 1209 return; 1139 1210 ··· 1140 1215 if (!re_map_vpdbase) 1141 1216 return; 1142 1217 1143 - /* Store the VPD into our buffer */ 1144 1218 for (i = 0; i < 0x40; i++) { 1145 1219 brd->vpd[i] = readb(re_map_vpdbase + i); 1146 1220 pr_info("%x ", brd->vpd[i]);
+8 -77
drivers/staging/dgnc/dgnc_driver.c
··· 30 30 MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line"); 31 31 MODULE_SUPPORTED_DEVICE("dgnc"); 32 32 33 - /* File operations permitted on Control/Management major. */ 34 - 35 33 static const struct file_operations dgnc_board_fops = { 36 34 .owner = THIS_MODULE, 37 35 .unlocked_ioctl = dgnc_mgmt_ioctl, 38 36 .open = dgnc_mgmt_open, 39 37 .release = dgnc_mgmt_close 40 38 }; 41 - 42 - /* Globals */ 43 39 44 40 uint dgnc_num_boards; 45 41 struct dgnc_board *dgnc_board[MAXBOARDS]; ··· 44 48 uint dgnc_major; 45 49 int dgnc_poll_tick = 20; /* Poll interval - 20 ms */ 46 50 47 - /* Static vars. */ 48 - 49 51 static struct class *dgnc_class; 50 - 51 - /* Poller stuff */ 52 52 53 53 static ulong dgnc_poll_time; /* Time of next poll */ 54 54 static uint dgnc_poll_stop; /* Used to tell poller to stop */ ··· 87 95 }; 88 96 89 97 /* Remap PCI memory. */ 90 - 91 98 static int dgnc_do_remap(struct dgnc_board *brd) 92 99 { 93 100 brd->re_map_membase = ioremap(brd->membase, 0x1000); ··· 96 105 return 0; 97 106 } 98 107 99 - /* 100 - * dgnc_found_board() 101 - * 102 - * A board has been found, init it. 103 - */ 108 + 109 + /* A board has been found, initialize it. */ 104 110 static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id) 105 111 { 106 112 struct dgnc_board *brd; ··· 105 117 int i = 0; 106 118 int rc = 0; 107 119 108 - /* get the board structure and prep it */ 109 120 brd = kzalloc(sizeof(*brd), GFP_KERNEL); 110 121 if (!brd) 111 122 return ERR_PTR(-ENOMEM); ··· 155 168 * 4 Memory Mapped UARTs and Status 156 169 */ 157 170 158 - /* get the PCI Base Address Registers */ 159 171 brd->membase = pci_resource_start(pdev, 4); 160 172 161 173 if (!brd->membase) { ··· 175 189 brd->iobase_end = pci_resource_end(pdev, 1); 176 190 brd->iobase = ((unsigned int)(brd->iobase)) & 0xFFFE; 177 191 178 - /* Assign the board_ops struct */ 179 192 brd->bd_ops = &dgnc_cls_ops; 180 193 181 194 brd->bd_uart_offset = 0x8; ··· 219 234 else 220 235 brd->dpatype = T_NEO | T_PCIBUS; 221 236 222 - /* get the PCI Base Address Registers */ 223 237 brd->membase = pci_resource_start(pdev, 0); 224 238 brd->membase_end = pci_resource_end(pdev, 0); 225 239 ··· 227 243 else 228 244 brd->membase &= ~15; 229 245 230 - /* Assign the board_ops struct */ 231 246 brd->bd_ops = &dgnc_neo_ops; 232 247 233 248 brd->bd_uart_offset = 0x200; ··· 252 269 goto failed; 253 270 } 254 271 255 - /* init our poll helper tasklet */ 256 272 tasklet_init(&brd->helper_tasklet, 257 273 brd->bd_ops->tasklet, 258 274 (unsigned long)brd); ··· 288 306 free_irq(brd->irq, brd); 289 307 } 290 308 291 - /* 292 - * Function: 293 - * 294 - * dgnc_poll_handler 295 - * 296 - * Author: 297 - * 298 - * Scott H Kilau 299 - * 300 - * Parameters: 301 - * 302 - * dummy -- ignored 303 - * 304 - * Return Values: 305 - * 306 - * none 307 - * 308 - * Description: 309 - * 310 - * As each timer expires, it determines (a) whether the "transmit" 311 - * waiter needs to be woken up, and (b) whether the poller needs to 312 - * be rescheduled. 313 - */ 314 309 310 + /* 311 + * As each timer expires, it determines (a) whether the "transmit" 312 + * waiter needs to be woken up, and (b) whether the poller needs to 313 + * be rescheduled. 314 + */ 315 315 static void dgnc_poll_handler(ulong dummy) 316 316 { 317 317 struct dgnc_board *brd; ··· 301 337 int i; 302 338 unsigned long new_time; 303 339 304 - /* Go thru each board, kicking off a tasklet for each if needed */ 305 340 for (i = 0; i < dgnc_num_boards; i++) { 306 341 brd = dgnc_board[i]; 307 342 308 343 spin_lock_irqsave(&brd->bd_lock, flags); 309 344 310 - /* If board is in a failed state don't schedule a tasklet */ 311 345 if (brd->state == BOARD_FAILED) { 312 346 spin_unlock_irqrestore(&brd->bd_lock, flags); 313 347 continue; 314 348 } 315 349 316 - /* Schedule a poll helper task */ 317 350 tasklet_schedule(&brd->helper_tasklet); 318 351 319 352 spin_unlock_irqrestore(&brd->bd_lock, flags); ··· 340 379 int rc; 341 380 struct dgnc_board *brd; 342 381 343 - /* wake up and enable device */ 344 382 rc = pci_enable_device(pdev); 345 383 if (rc) 346 384 return -EIO; ··· 347 387 brd = dgnc_found_board(pdev, ent->driver_data); 348 388 if (IS_ERR(brd)) 349 389 return PTR_ERR(brd); 350 - 351 - /* Do tty device initialization. */ 352 390 353 391 rc = dgnc_tty_register(brd); 354 392 if (rc < 0) { ··· 389 431 .id_table = dgnc_pci_tbl, 390 432 }; 391 433 392 - /* Start of driver. */ 393 - 394 434 static int dgnc_start(void) 395 435 { 396 436 int rc = 0; 397 437 unsigned long flags; 398 438 struct device *dev; 399 439 400 - /* make sure timer is initialized before we do anything else */ 401 440 init_timer(&dgnc_poll_timer); 402 441 403 - /* 404 - * Register our base character device into the kernel. 405 - * This allows the download daemon to connect to the downld device 406 - * before any of the boards are init'ed. 407 - * 408 - * Register management/dpa devices 409 - */ 410 442 rc = register_chrdev(0, "dgnc", &dgnc_board_fops); 411 443 if (rc < 0) { 412 444 pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc); ··· 439 491 return rc; 440 492 } 441 493 442 - /* 443 - * dgnc_cleanup_board() 444 - * 445 - * Free all the memory associated with a board 446 - */ 494 + /* Free all the memory associated with a board */ 447 495 static void dgnc_cleanup_board(struct dgnc_board *brd) 448 496 { 449 497 int i = 0; ··· 471 527 brd->re_map_membase = NULL; 472 528 } 473 529 474 - /* Free all allocated channels structs */ 475 530 for (i = 0; i < MAXPORTS ; i++) { 476 531 if (brd->channels[i]) { 477 532 kfree(brd->channels[i]->ch_rqueue); ··· 510 567 } 511 568 } 512 569 513 - /* 514 - * dgnc_cleanup_module() 515 - * 516 - * Module unload. This is where it all ends. 517 - */ 518 570 static void __exit dgnc_cleanup_module(void) 519 571 { 520 572 cleanup(); 521 573 pci_unregister_driver(&dgnc_driver); 522 574 } 523 575 524 - /* 525 - * init_module() 526 - * 527 - * Module load. This is where it all starts. 528 - */ 529 576 static int __init dgnc_init_module(void) 530 577 { 531 578 int rc; 532 579 533 580 /* Initialize global stuff */ 534 - 535 581 rc = dgnc_start(); 536 582 if (rc < 0) 537 583 return rc; 538 584 539 585 /* Find and configure all the cards */ 540 - 541 586 rc = pci_register_driver(&dgnc_driver); 542 587 if (rc) { 543 588 pr_warn("WARNING: dgnc driver load failed. No Digi Neo or Classic boards found.\n");
+9 -20
drivers/staging/dgnc/dgnc_mgmt.c
··· 20 20 21 21 #include <linux/kernel.h> 22 22 #include <linux/ctype.h> 23 - #include <linux/sched.h> /* For jiffies, task states */ 24 - #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */ 23 + #include <linux/sched.h> 24 + #include <linux/interrupt.h> 25 25 #include <linux/serial_reg.h> 26 26 #include <linux/termios.h> 27 - #include <linux/uaccess.h> /* For copy_from_user/copy_to_user */ 27 + #include <linux/uaccess.h> 28 28 29 29 #include "dgnc_driver.h" 30 30 #include "dgnc_pci.h" ··· 33 33 /* Our "in use" variables, to enforce 1 open only */ 34 34 static int dgnc_mgmt_in_use[MAXMGMTDEVICES]; 35 35 36 - /* 37 - * dgnc_mgmt_open() 38 - * 39 - * Open the mgmt/downld/dpa device 36 + /** 37 + * dgnc_mgmt_open() - Open the mgmt/downld/dpa device. 40 38 */ 41 39 int dgnc_mgmt_open(struct inode *inode, struct file *file) 42 40 { ··· 44 46 45 47 spin_lock_irqsave(&dgnc_global_lock, flags); 46 48 47 - /* mgmt device */ 48 49 if (minor >= MAXMGMTDEVICES) { 49 50 rc = -ENXIO; 50 51 goto out; ··· 61 64 return rc; 62 65 } 63 66 64 - /* 65 - * dgnc_mgmt_close() 66 - * 67 - * Open the mgmt/dpa device 67 + /** 68 + * dgnc_mgmt_close() - Close the mgmt/dpa device 68 69 */ 69 70 int dgnc_mgmt_close(struct inode *inode, struct file *file) 70 71 { ··· 72 77 73 78 spin_lock_irqsave(&dgnc_global_lock, flags); 74 79 75 - /* mgmt device */ 76 80 if (minor >= MAXMGMTDEVICES) { 77 81 rc = -ENXIO; 78 82 goto out; ··· 84 90 return rc; 85 91 } 86 92 87 - /* 88 - * dgnc_mgmt_ioctl() 89 - * 90 - * ioctl the mgmt/dpa device 93 + /** 94 + * dgnc_mgmt_ioctl() - Ioctl the mgmt/dpa device. 91 95 */ 92 - 93 96 long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 94 97 { 95 98 unsigned long flags; ··· 167 176 board = ni.board; 168 177 channel = ni.channel; 169 178 170 - /* Verify boundaries on board */ 171 179 if (board >= dgnc_num_boards) 172 180 return -ENODEV; 173 181 174 - /* Verify boundaries on channel */ 175 182 if (channel >= dgnc_board[board]->nasync) 176 183 return -ENODEV; 177 184
+22 -147
drivers/staging/dgnc/dgnc_neo.c
··· 14 14 */ 15 15 16 16 #include <linux/kernel.h> 17 - #include <linux/sched.h> /* For jiffies, task states */ 18 - #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */ 19 - #include <linux/delay.h> /* For udelay */ 20 - #include <linux/io.h> /* For read[bwl]/write[bwl] */ 21 - #include <linux/serial.h> /* For struct async_serial */ 22 - #include <linux/serial_reg.h> /* For the various UART offsets */ 17 + #include <linux/sched.h> 18 + #include <linux/interrupt.h> 19 + #include <linux/delay.h> 20 + #include <linux/io.h> 21 + #include <linux/serial.h> 22 + #include <linux/serial_reg.h> 23 23 24 - #include "dgnc_driver.h" /* Driver main header file */ 25 - #include "dgnc_neo.h" /* Our header file */ 24 + #include "dgnc_driver.h" 25 + #include "dgnc_neo.h" 26 26 #include "dgnc_tty.h" 27 27 28 28 static inline void neo_parse_lsr(struct dgnc_board *brd, uint port); ··· 358 358 } 359 359 360 360 /* No locks are assumed to be held when calling this function. */ 361 - 362 361 static inline void neo_clear_break(struct channel_t *ch, int force) 363 362 { 364 363 unsigned long flags; 365 364 366 365 spin_lock_irqsave(&ch->ch_lock, flags); 367 366 368 - /* Bail if we aren't currently sending a break. */ 369 367 if (!ch->ch_stop_sending_break) { 370 368 spin_unlock_irqrestore(&ch->ch_lock, flags); 371 369 return; 372 370 } 373 371 374 - /* Turn break off, and unset some variables */ 375 372 if (ch->ch_flags & CH_BREAK_SENDING) { 376 373 if (force || 377 374 time_after_eq(jiffies, ch->ch_stop_sending_break)) { ··· 384 387 } 385 388 386 389 /* Parse the ISR register. */ 387 - 388 390 static inline void neo_parse_isr(struct dgnc_board *brd, uint port) 389 391 { 390 392 struct channel_t *ch; ··· 399 403 while (1) { 400 404 isr = readb(&ch->ch_neo_uart->isr_fcr); 401 405 402 - /* Bail if no pending interrupt */ 403 406 if (isr & UART_IIR_NO_INT) 404 407 break; 405 408 ··· 421 426 } 422 427 423 428 if (isr & UART_IIR_THRI) { 424 - /* Transfer data (if any) from Write Queue -> UART. */ 425 429 spin_lock_irqsave(&ch->ch_lock, flags); 426 430 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 427 431 spin_unlock_irqrestore(&ch->ch_lock, flags); ··· 436 442 * one it was, so we can suspend or resume data flow. 437 443 */ 438 444 if (cause == UART_17158_XON_DETECT) { 439 - /* 440 - * Is output stopped right now, if so, 441 - * resume it 442 - */ 445 + /* resume output if stopped */ 443 446 if (brd->channels[port]->ch_flags & CH_STOP) { 444 447 spin_lock_irqsave(&ch->ch_lock, 445 448 flags); ··· 495 504 } 496 505 } 497 506 498 - /* Parse any modem signal changes */ 499 507 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr)); 500 508 } 501 509 } ··· 505 515 int linestatus; 506 516 unsigned long flags; 507 517 508 - /* 509 - * Check to make sure it didn't receive interrupt with a null board 510 - * associated or a board pointer that wasn't ours. 511 - */ 512 518 if (!brd || brd->magic != DGNC_BOARD_MAGIC) 513 519 return; 514 520 ··· 520 534 ch->ch_cached_lsr |= linestatus; 521 535 522 536 if (ch->ch_cached_lsr & UART_LSR_DR) { 523 - /* Read data from uart -> queue */ 524 537 neo_copy_data_from_uart_to_queue(ch); 525 538 spin_lock_irqsave(&ch->ch_lock, flags); 526 539 dgnc_check_queue_flow_control(ch); ··· 556 571 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 557 572 spin_unlock_irqrestore(&ch->ch_lock, flags); 558 573 559 - /* Transfer data (if any) from Write Queue -> UART. */ 560 574 neo_copy_data_from_queue_to_uart(ch); 561 575 } else if (linestatus & UART_17158_TX_AND_FIFO_CLR) { 562 576 spin_lock_irqsave(&ch->ch_lock, flags); 563 577 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 564 578 spin_unlock_irqrestore(&ch->ch_lock, flags); 565 579 566 - /* Transfer data (if any) from Write Queue -> UART. */ 567 580 neo_copy_data_from_queue_to_uart(ch); 568 581 } 569 582 } 570 583 571 - /* 572 - * neo_param() 573 - * Send any/all changes to the line to the UART. 574 - */ 584 + /* Send any/all changes to the line to the UART. */ 575 585 static void neo_param(struct tty_struct *tty) 576 586 { 577 587 unsigned char lcr = 0; ··· 595 615 return; 596 616 597 617 /* If baud rate is zero, flush queues, and set mval to drop DTR. */ 598 - 599 618 if ((ch->ch_c_cflag & (CBAUD)) == 0) { 600 619 ch->ch_r_head = 0; 601 620 ch->ch_r_tail = 0; ··· 703 724 if (!(ch->ch_c_cflag & PARODD)) 704 725 lcr |= UART_LCR_EPAR; 705 726 706 - /* 707 - * Not all platforms support mark/space parity, 708 - * so this will hide behind an ifdef. 709 - */ 710 727 #ifdef CMSPAR 711 728 if (ch->ch_c_cflag & CMSPAR) 712 729 lcr |= UART_LCR_SPAR; ··· 771 796 if (ier != uart_ier) 772 797 writeb(ier, &ch->ch_neo_uart->ier); 773 798 774 - /* Set new start/stop chars */ 775 799 neo_set_new_start_stop_chars(ch); 776 800 777 801 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) { 778 802 neo_set_cts_flow_control(ch); 779 803 } else if (ch->ch_c_iflag & IXON) { 780 - /* 781 - * If start/stop is set to disable, then we should 782 - * disable flow control 783 - */ 784 804 if ((ch->ch_startc == _POSIX_VDISABLE) || 785 805 (ch->ch_stopc == _POSIX_VDISABLE)) 786 806 neo_set_no_output_flow_control(ch); ··· 788 818 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) { 789 819 neo_set_rts_flow_control(ch); 790 820 } else if (ch->ch_c_iflag & IXOFF) { 791 - /* 792 - * If start/stop is set to disable, then we should 793 - * disable flow control 794 - */ 795 821 if ((ch->ch_startc == _POSIX_VDISABLE) || 796 822 (ch->ch_stopc == _POSIX_VDISABLE)) 797 823 neo_set_no_input_flow_control(ch); ··· 809 843 810 844 neo_assert_modem_signals(ch); 811 845 812 - /* Get current status of the modem signals now */ 813 846 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr)); 814 847 } 815 848 816 - /* Our board poller function. */ 817 - 849 + /* Board poller function. */ 818 850 static void neo_tasklet(unsigned long data) 819 851 { 820 852 struct dgnc_board *bd = (struct dgnc_board *)data; ··· 825 861 if (!bd || bd->magic != DGNC_BOARD_MAGIC) 826 862 return; 827 863 828 - /* Cache a couple board values */ 829 864 spin_lock_irqsave(&bd->bd_lock, flags); 830 865 state = bd->state; 831 866 ports = bd->nasync; ··· 836 873 */ 837 874 spin_lock_irqsave(&bd->bd_intr_lock, flags); 838 875 839 - /* If board is ready, parse deeper to see if there is anything to do. */ 840 - 841 876 if ((state == BOARD_READY) && (ports > 0)) { 842 - /* Loop on each port */ 843 877 for (i = 0; i < ports; i++) { 844 878 ch = bd->channels[i]; 845 879 ··· 863 903 neo_copy_data_from_queue_to_uart(ch); 864 904 dgnc_wakeup_writes(ch); 865 905 866 - /* 867 - * Call carrier carrier function, in case something 868 - * has changed. 869 - */ 870 906 dgnc_carrier(ch); 871 907 872 908 /* ··· 874 918 } 875 919 } 876 920 877 - /* Allow interrupt routine to access the interrupt register again */ 878 921 spin_unlock_irqrestore(&bd->bd_intr_lock, flags); 879 922 } 880 923 881 - /* 882 - * dgnc_neo_intr() 883 - * 884 - * Neo specific interrupt handler. 885 - */ 924 + /* Neo specific interrupt handler. */ 886 925 static irqreturn_t neo_intr(int irq, void *voidbrd) 887 926 { 888 927 struct dgnc_board *brd = voidbrd; ··· 888 937 unsigned long flags; 889 938 unsigned long flags2; 890 939 891 - /* 892 - * Check to make sure it didn't receive interrupt with a null board 893 - * associated or a board pointer that wasn't ours. 894 - */ 895 940 if (!brd || brd->magic != DGNC_BOARD_MAGIC) 896 941 return IRQ_NONE; 897 942 ··· 911 964 return IRQ_NONE; 912 965 } 913 966 914 - /* 915 - * At this point, we have at least SOMETHING to service, dig 916 - * further... 917 - */ 918 - 919 - /* Loop on each port */ 920 967 while ((uart_poll & 0xff) != 0) { 921 968 type = uart_poll >> (8 + (port * 3)); 922 969 type &= 0x7; 923 970 924 971 uart_poll &= ~(0x01 << port); 925 972 926 - /* Switch on type of interrupt we have */ 927 973 switch (type) { 928 974 case UART_17158_RXRDY_TIMEOUT: 929 975 /* ··· 924 984 * RX FIFO until it falls below the trigger level. 925 985 */ 926 986 927 - /* Verify the port is in range. */ 928 987 if (port >= brd->nasync) 929 988 break; 930 989 ··· 966 1027 break; 967 1028 968 1029 case UART_17158_MSR: 969 - 970 1030 /* MSR or flow control was seen. */ 971 - 972 1031 neo_parse_isr(brd, port); 973 1032 break; 974 1033 975 1034 default: 976 - /* 977 - * The UART triggered us with a bogus interrupt type. 978 - * It appears the Exar chip, when REALLY bogged down, 979 - * will throw these once and awhile. 980 - * Its harmless, just ignore it and move on. 981 - */ 982 1035 break; 983 1036 } 984 1037 985 1038 port++; 986 1039 } 987 - 988 - /* Schedule tasklet to more in-depth servicing at a better time. */ 989 1040 990 1041 tasklet_schedule(&brd->helper_tasklet); 991 1042 ··· 1028 1099 1029 1100 spin_lock_irqsave(&ch->ch_lock, flags); 1030 1101 1031 - /* cache head and tail of queue */ 1032 1102 head = ch->ch_r_head & RQUEUEMASK; 1033 1103 tail = ch->ch_r_tail & RQUEUEMASK; 1034 1104 1035 - /* Get our cached LSR */ 1036 1105 linestatus = ch->ch_cached_lsr; 1037 1106 ch->ch_cached_lsr = 0; 1038 1107 1039 - /* Store how much space we have left in the queue */ 1040 1108 qleft = tail - head - 1; 1041 1109 if (qleft < 0) 1042 1110 qleft += RQUEUEMASK + 1; 1043 1111 1044 - /* 1045 - * If the UART is not in FIFO mode, force the FIFO copy to 1046 - * NOT be run, by setting total to 0. 1047 - * 1048 - * On the other hand, if the UART IS in FIFO mode, then ask 1049 - * the UART to give us an approximation of data it has RX'ed. 1050 - */ 1051 1112 if (!(ch->ch_flags & CH_FIFO_ENABLED)) { 1113 + /* force the FIFO copy to NOT be run */ 1052 1114 total = 0; 1053 1115 } else { 1054 1116 total = readb(&ch->ch_neo_uart->rfifo); ··· 1058 1138 total -= 3; 1059 1139 } 1060 1140 1061 - /* 1062 - * Finally, bound the copy to make sure we don't overflow 1063 - * our own queue... 1064 - * The byte by byte copy loop below this loop this will 1065 - * deal with the queue overflow possibility. 1066 - */ 1067 1141 total = min(total, qleft); 1068 1142 1069 1143 while (total > 0) { 1070 - /* 1071 - * Grab the linestatus register, we need to check 1072 - * to see if there are any errors in the FIFO. 1073 - */ 1074 1144 linestatus = readb(&ch->ch_neo_uart->lsr); 1075 1145 1076 - /* 1077 - * Break out if there is a FIFO error somewhere. 1078 - * This will allow us to go byte by byte down below, 1079 - * finding the exact location of the error. 1080 - */ 1081 1146 if (linestatus & UART_17158_RX_FIFO_DATA_ERROR) 1082 1147 break; 1083 1148 ··· 1087 1182 1088 1183 linestatus = 0; 1089 1184 1090 - /* Copy data from uart to the queue */ 1091 1185 memcpy_fromio(ch->ch_rqueue + head, 1092 1186 &ch->ch_neo_uart->txrxburst, n); 1093 1187 ··· 1097 1193 */ 1098 1194 memset(ch->ch_equeue + head, 0, n); 1099 1195 1100 - /* Add to and flip head if needed */ 1101 1196 head = (head + n) & RQUEUEMASK; 1102 1197 total -= n; 1103 1198 qleft -= n; ··· 1145 1242 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 1146 1243 } 1147 1244 1148 - /* Discard character if we are ignoring the error mask. */ 1149 - 1150 1245 if (linestatus & error_mask) { 1151 1246 unsigned char discard; 1152 1247 ··· 1154 1253 } 1155 1254 1156 1255 /* 1157 - * If our queue is full, we have no choice but to drop some 1158 - * data. 1159 - * The assumption is that HWFLOW or SWFLOW should have stopped 1160 - * things way way before we got to this point. 1161 - * 1162 - * I decided that I wanted to ditch the oldest data first, 1163 - * I hope thats okay with everyone? Yes? Good. 1256 + * If our queue is full, we have no choice but to drop 1257 + * some data. The assumption is that HWFLOW or SWFLOW 1258 + * should have stopped things way way before we got to 1259 + * this point. 1164 1260 */ 1165 1261 while (qleft < 1) { 1166 1262 tail = (tail + 1) & RQUEUEMASK; ··· 1170 1272 &ch->ch_neo_uart->txrxburst, 1); 1171 1273 ch->ch_equeue[head] = (unsigned char)linestatus; 1172 1274 1173 - /* Ditch any remaining linestatus value. */ 1174 1275 linestatus = 0; 1175 1276 1176 - /* Add to and flip head if needed */ 1177 1277 head = (head + 1) & RQUEUEMASK; 1178 1278 1179 1279 qleft--; 1180 1280 ch->ch_rxcount++; 1181 1281 } 1182 - 1183 - /* Write new final heads to channel structure. */ 1184 1282 1185 1283 ch->ch_r_head = head & RQUEUEMASK; 1186 1284 ch->ch_e_head = head & EQUEUEMASK; ··· 1210 1316 un->un_flags |= UN_EMPTY; 1211 1317 spin_unlock_irqrestore(&ch->ch_lock, flags); 1212 1318 1213 - /* 1214 - * Go to sleep waiting for the tty layer to wake me back up when 1215 - * the empty flag goes away. 1216 - */ 1217 1319 rc = wait_event_interruptible_timeout(un->un_flags_wait, 1218 1320 ((un->un_flags & UN_EMPTY) == 0), 1219 1321 msecs_to_jiffies(seconds * 1000)); ··· 1220 1330 1221 1331 /* 1222 1332 * Flush the WRITE FIFO on the Neo. 1223 - * 1224 - * NOTE: Channel lock MUST be held before calling this function! 1333 + * Channel lock MUST be held before calling this function! 1225 1334 */ 1226 1335 static void neo_flush_uart_write(struct channel_t *ch) 1227 1336 { ··· 1236 1347 1237 1348 for (i = 0; i < 10; i++) { 1238 1349 /* 1239 - * Check to see if the UART feels it completely flushed the 1350 + * Check to see if the UART completely flushed the FIFO 1240 1351 * FIFO. 1241 1352 */ 1242 1353 tmp = readb(&ch->ch_neo_uart->isr_fcr); ··· 1251 1362 1252 1363 /* 1253 1364 * Flush the READ FIFO on the Neo. 1254 - * 1255 - * NOTE: Channel lock MUST be held before calling this function! 1365 + * Channel lock MUST be held before calling this function! 1256 1366 */ 1257 1367 static void neo_flush_uart_read(struct channel_t *ch) 1258 1368 { ··· 1293 1405 1294 1406 spin_lock_irqsave(&ch->ch_lock, flags); 1295 1407 1296 - /* No data to write to the UART */ 1297 1408 if (ch->ch_w_tail == ch->ch_w_head) 1298 1409 goto exit_unlock; 1299 1410 ··· 1301 1414 (ch->ch_flags & CH_BREAK_SENDING)) 1302 1415 goto exit_unlock; 1303 1416 1304 - /* If FIFOs are disabled. Send data directly to txrx register */ 1305 - 1306 1417 if (!(ch->ch_flags & CH_FIFO_ENABLED)) { 1418 + /* Send data directly to txrx register */ 1307 1419 unsigned char lsrbits = readb(&ch->ch_neo_uart->lsr); 1308 1420 1309 - /* Cache the LSR bits for later parsing */ 1310 1421 ch->ch_cached_lsr |= lsrbits; 1311 1422 if (ch->ch_cached_lsr & UART_LSR_THRE) { 1312 1423 ch->ch_cached_lsr &= ~(UART_LSR_THRE); ··· 1362 1477 n = UART_17158_TX_FIFOSIZE - readb(&ch->ch_neo_uart->tfifo); 1363 1478 } 1364 1479 1365 - /* cache head and tail of queue */ 1366 1480 head = ch->ch_w_head & WQUEUEMASK; 1367 1481 tail = ch->ch_w_tail & WQUEUEMASK; 1368 1482 qlen = (head - tail) & WQUEUEMASK; 1369 1483 1370 - /* Find minimum of the FIFO space, versus queue length */ 1371 1484 n = min(n, qlen); 1372 1485 1373 1486 while (n > 0) { ··· 1404 1521 memcpy_toio(&ch->ch_neo_uart->txrxburst, 1405 1522 ch->ch_wqueue + tail, s); 1406 1523 1407 - /* Add and flip queue if needed */ 1408 1524 tail = (tail + s) & WQUEUEMASK; 1409 1525 n -= s; 1410 1526 ch->ch_txcount += s; 1411 1527 len_written += s; 1412 1528 } 1413 1529 1414 - /* Update the final tail */ 1415 1530 ch->ch_w_tail = tail & WQUEUEMASK; 1416 1531 1417 1532 if (len_written > 0) { ··· 1453 1572 } 1454 1573 } 1455 1574 1456 - /* 1457 - * Scrub off lower bits. They signify delta's, which I don't care 1458 - * about 1459 - */ 1575 + /* Scrub off lower bits. They signify delta's */ 1460 1576 msignals &= 0xf0; 1461 1577 1462 1578 if (msignals & UART_MSR_DCD) ··· 1546 1668 } 1547 1669 1548 1670 /* Make the UART completely turn off. */ 1549 - 1550 1671 static void neo_uart_off(struct channel_t *ch) 1551 1672 { 1552 1673 /* Turn off UART enhanced bits */ ··· 1612 1735 } 1613 1736 1614 1737 /* 1615 - * neo_send_immediate_char. 1616 - * 1617 1738 * Sends a specific character as soon as possible to the UART, 1618 1739 * jumping over any bytes that might be in the write queue. 1619 1740 *
+39 -182
drivers/staging/dgnc/dgnc_tty.c
··· 59 59 * 1 stop bit. 60 60 */ 61 61 static const struct ktermios default_termios = { 62 - .c_iflag = (DEFAULT_IFLAGS), /* iflags */ 63 - .c_oflag = (DEFAULT_OFLAGS), /* oflags */ 64 - .c_cflag = (DEFAULT_CFLAGS), /* cflags */ 65 - .c_lflag = (DEFAULT_LFLAGS), /* lflags */ 62 + .c_iflag = (DEFAULT_IFLAGS), 63 + .c_oflag = (DEFAULT_OFLAGS), 64 + .c_cflag = (DEFAULT_CFLAGS), 65 + .c_lflag = (DEFAULT_LFLAGS), 66 66 .c_cc = INIT_C_CC, 67 67 .c_line = 0, 68 68 }; 69 69 70 - /* Our function prototypes */ 71 70 static int dgnc_tty_open(struct tty_struct *tty, struct file *file); 72 71 static void dgnc_tty_close(struct tty_struct *tty, struct file *file); 73 72 static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, ··· 129 130 130 131 /* TTY Initialization/Cleanup Functions */ 131 132 132 - /* 133 - * dgnc_tty_register() 134 - * 135 - * Init the tty subsystem for this board. 133 + /** 134 + * dgnc_tty_register() - Init the tty subsystem for this board. 136 135 */ 137 136 int dgnc_tty_register(struct dgnc_board *brd) 138 137 { ··· 227 230 put_tty_driver(brd->serial_driver); 228 231 } 229 232 230 - /* 231 - * dgnc_tty_init() 233 + /** 234 + * dgnc_tty_init() - Initialize the tty subsystem. 232 235 * 233 - * Init the tty subsystem. Called once per board after board has been 234 - * downloaded and init'ed. 236 + * Called once per board after board has been downloaded and initialized. 235 237 */ 236 238 int dgnc_tty_init(struct dgnc_board *brd) 237 239 { ··· 249 253 brd->nasync = brd->maxports; 250 254 251 255 for (i = 0; i < brd->nasync; i++) { 252 - /* 253 - * Okay to malloc with GFP_KERNEL, we are not at 254 - * interrupt context, and there are no locks held. 255 - */ 256 256 brd->channels[i] = kzalloc(sizeof(*brd->channels[i]), 257 257 GFP_KERNEL); 258 258 if (!brd->channels[i]) { ··· 316 324 return rc; 317 325 } 318 326 319 - /* 320 - * dgnc_cleanup_tty() 327 + /** 328 + * dgnc_cleanup_tty() - Cleanup driver. 321 329 * 322 330 * Uninitialize the TTY portion of this driver. Free all memory and 323 331 * resources. ··· 340 348 put_tty_driver(brd->print_driver); 341 349 } 342 350 343 - /* 344 - * dgnc_wmove - Write data to transmit queue. 345 - * 346 - * ch - Pointer to channel structure. 347 - * buf - Pointer to characters to be moved. 348 - * n - Number of characters to move. 351 + /** 352 + * dgnc_wmove() - Write data to transmit queue. 353 + * @ch: Pointer to channel structure. 354 + * @buf: Pointer to characters to be moved. 355 + * @n: Number of characters to move. 349 356 */ 350 357 static void dgnc_wmove(struct channel_t *ch, char *buf, uint n) 351 358 { ··· 381 390 ch->ch_w_head = head; 382 391 } 383 392 384 - /* 385 - * dgnc_input - Process received data. 386 - * 387 - * ch - Pointer to channel structure. 393 + /** 394 + * dgnc_input() - Process received data. 395 + * @ch: Pointer to channel structure. 388 396 */ 389 397 void dgnc_input(struct channel_t *ch) 390 398 { ··· 412 422 413 423 spin_lock_irqsave(&ch->ch_lock, flags); 414 424 415 - /* 416 - * Figure the number of characters in the buffer. 417 - * Exit immediately if none. 418 - */ 419 425 rmask = RQUEUEMASK; 420 426 head = ch->ch_r_head & rmask; 421 427 tail = ch->ch_r_tail & rmask; ··· 436 450 goto exit_unlock; 437 451 } 438 452 439 - /* If we are throttled, simply don't read any data. */ 440 - 441 453 if (ch->ch_flags & CH_FORCED_STOPI) 442 454 goto exit_unlock; 443 455 444 456 flip_len = TTY_FLIPBUF_SIZE; 445 457 446 - /* Chop down the length, if needed */ 447 458 len = min(data_len, flip_len); 448 459 len = min(len, (N_TTY_BUF_SIZE - 1)); 449 460 450 461 ld = tty_ldisc_ref(tp); 451 - 452 - /* 453 - * If we were unable to get a reference to the ld, 454 - * don't flush our buffer, and act like the ld doesn't 455 - * have any space to put the data right now. 456 - */ 457 462 if (!ld) { 458 463 len = 0; 459 464 } else { 460 - /* 461 - * If ld doesn't have a pointer to a receive_buf function, 462 - * flush the data, then act like the ld doesn't have any 463 - * space to put the data right now. 464 - */ 465 465 if (!ld->ops->receive_buf) { 466 466 ch->ch_r_head = ch->ch_r_tail; 467 467 len = 0; ··· 536 564 tty_ldisc_deref(ld); 537 565 } 538 566 539 - /* 567 + /** 568 + * dgnc_carrier() 569 + * 540 570 * Determines when CARRIER changes state and takes appropriate 541 571 * action. 542 572 */ ··· 628 654 } 629 655 630 656 /* Assign the custom baud rate to the channel structure */ 631 - 632 657 static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate) 633 658 { 634 659 int testdiv; ··· 691 718 { 692 719 int qleft; 693 720 694 - /* Store how much space we have left in the queue */ 695 721 qleft = ch->ch_r_tail - ch->ch_r_head - 1; 696 722 if (qleft < 0) 697 723 qleft += RQUEUEMASK + 1; ··· 857 885 858 886 /* TTY Entry points and helper functions */ 859 887 860 - /* dgnc_tty_open() */ 861 - 862 888 static int dgnc_tty_open(struct tty_struct *tty, struct file *file) 863 889 { 864 890 struct dgnc_board *brd; ··· 875 905 if (major > 255) 876 906 return -ENXIO; 877 907 878 - /* Get board pointer from our array of majors we have allocated */ 879 908 brd = find_board_by_major(major); 880 909 if (!brd) 881 910 return -ENXIO; 882 911 883 - /* 884 - * If board is not yet up to a state of READY, go to 885 - * sleep waiting for it to happen or they cancel the open. 886 - */ 887 912 rc = wait_event_interruptible(brd->state_wait, 888 913 (brd->state & BOARD_READY)); 889 914 if (rc) ··· 886 921 887 922 spin_lock_irqsave(&brd->bd_lock, flags); 888 923 889 - /* If opened device is greater than our number of ports, bail. */ 890 924 if (PORT_NUM(minor) >= brd->nasync) { 891 925 rc = -ENXIO; 892 926 goto err_brd_unlock; ··· 897 933 goto err_brd_unlock; 898 934 } 899 935 900 - /* Drop board lock */ 901 936 spin_unlock_irqrestore(&brd->bd_lock, flags); 902 937 903 - /* Grab channel lock */ 904 938 spin_lock_irqsave(&ch->ch_lock, flags); 905 939 906 940 /* Figure out our type */ ··· 943 981 944 982 spin_lock_irqsave(&ch->ch_lock, flags); 945 983 946 - /* Store our unit into driver_data, so we always have it available. */ 947 984 tty->driver_data = un; 948 985 949 986 /* Initialize tty's */ 950 987 951 988 if (!(un->un_flags & UN_ISOPEN)) { 952 - /* Store important variables. */ 953 - un->un_tty = tty; 989 + un->un_tty = tty; 954 990 955 991 /* Maybe do something here to the TTY struct as well? */ 956 992 } ··· 959 999 */ 960 1000 ch->ch_flags |= (CH_OPENING); 961 1001 962 - /* Drop locks, as malloc with GFP_KERNEL can sleep */ 963 1002 spin_unlock_irqrestore(&ch->ch_lock, flags); 964 1003 965 1004 if (!ch->ch_rqueue) ··· 1019 1060 brd->bd_ops->uart_init(ch); 1020 1061 } 1021 1062 1022 - /* Run param in case we changed anything */ 1023 - 1024 1063 brd->bd_ops->param(tty); 1025 1064 1026 1065 dgnc_carrier(ch); 1027 - 1028 - /* follow protocol for opening port */ 1029 1066 1030 1067 spin_unlock_irqrestore(&ch->ch_lock, flags); 1031 1068 1032 1069 rc = dgnc_block_til_ready(tty, file, ch); 1033 1070 1034 - /* No going back now, increment our unit and channel counters */ 1035 1071 spin_lock_irqsave(&ch->ch_lock, flags); 1036 1072 ch->ch_open_count++; 1037 1073 un->un_open_count++; ··· 1045 1091 return rc; 1046 1092 } 1047 1093 1048 - /* 1049 - * dgnc_block_til_ready() 1050 - * 1051 - * Wait for DCD, if needed. 1052 - */ 1094 + /* Wait for DCD, if needed. */ 1053 1095 static int dgnc_block_til_ready(struct tty_struct *tty, 1054 1096 struct file *file, 1055 1097 struct channel_t *ch) ··· 1063 1113 1064 1114 ch->ch_wopen++; 1065 1115 1066 - /* Loop forever */ 1067 1116 while (1) { 1068 1117 sleep_on_un_flags = 0; 1069 1118 1070 - /* 1071 - * If board has failed somehow during our sleep, 1072 - * bail with error. 1073 - */ 1074 1119 if (ch->ch_bd->state == BOARD_FAILED) { 1075 1120 rc = -ENXIO; 1076 1121 break; 1077 1122 } 1078 1123 1079 - /* If tty was hung up, break out of loop and set error. */ 1080 1124 if (tty_hung_up_p(file)) { 1081 1125 rc = -EAGAIN; 1082 1126 break; ··· 1113 1169 /* 1114 1170 * If there is a signal pending, the user probably 1115 1171 * interrupted (ctrl-c) us. 1116 - * Leave loop with error set. 1117 1172 */ 1118 1173 if (signal_pending(current)) { 1119 1174 rc = -ERESTARTSYS; 1120 1175 break; 1121 1176 } 1122 - 1123 - /* Store the flags before we let go of channel lock */ 1124 1177 1125 1178 if (sleep_on_un_flags) 1126 1179 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags; ··· 1160 1219 return rc; 1161 1220 } 1162 1221 1163 - /* 1164 - * dgnc_tty_hangup() 1165 - * 1166 - * Hangup the port. Like a close, but don't wait for output to drain. 1167 - */ 1222 + /* Hangup the port. Like a close, but don't wait for output to drain. */ 1168 1223 static void dgnc_tty_hangup(struct tty_struct *tty) 1169 1224 { 1170 1225 if (!tty || tty->magic != TTY_MAGIC) ··· 1169 1232 /* flush the transmit queues */ 1170 1233 dgnc_tty_flush_buffer(tty); 1171 1234 } 1172 - 1173 - /* dgnc_tty_close() */ 1174 1235 1175 1236 static void dgnc_tty_close(struct tty_struct *tty, struct file *file) 1176 1237 { ··· 1303 1368 } 1304 1369 1305 1370 /* 1306 - * dgnc_tty_chars_in_buffer() 1307 - * 1308 1371 * Return number of characters that have not been transmitted yet. 1309 1372 * 1310 1373 * This routine is used by the line discipline to determine if there ··· 1348 1415 } 1349 1416 1350 1417 /* 1351 - * dgnc_maxcps_room 1352 - * 1353 1418 * Reduces bytes_available to the max number of characters 1354 1419 * that can be sent currently given the maxcps value, and 1355 1420 * returns the new bytes_available. This only affects printer ··· 1383 1452 return rc; 1384 1453 } 1385 1454 1386 - /* 1387 - * dgnc_tty_write_room() 1388 - * 1389 - * Return room available in Tx buffer 1390 - */ 1455 + /* Return room available in Tx buffer */ 1391 1456 static int dgnc_tty_write_room(struct tty_struct *tty) 1392 1457 { 1393 1458 struct channel_t *ch = NULL; ··· 1440 1513 } 1441 1514 1442 1515 /* 1443 - * dgnc_tty_put_char() 1444 - * 1445 1516 * Put a character into ch->ch_buf 1446 - * 1447 - * - used by the line discipline for OPOST processing 1517 + * Used by the line discipline for OPOST processing 1448 1518 */ 1449 1519 static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c) 1450 1520 { 1451 - /* Simply call tty_write. */ 1452 - 1453 1521 dgnc_tty_write(tty, &c, 1); 1454 1522 return 1; 1455 1523 } 1456 1524 1457 1525 /* 1458 - * dgnc_tty_write() 1459 - * 1460 1526 * Take data from the user or kernel and send it out to the FEP. 1461 1527 * In here exists all the Transparent Print magic as well. 1462 1528 */ ··· 1487 1567 1488 1568 spin_lock_irqsave(&ch->ch_lock, flags); 1489 1569 1490 - /* Get our space available for the channel from the board */ 1491 1570 tmask = WQUEUEMASK; 1492 1571 head = (ch->ch_w_head) & tmask; 1493 1572 tail = (ch->ch_w_tail) & tmask; ··· 1502 1583 if (un->un_type != DGNC_PRINT) 1503 1584 bufcount = dgnc_maxcps_room(ch, bufcount); 1504 1585 1505 - /* 1506 - * Take minimum of what the user wants to send, and the 1507 - * space available in the FEP buffer. 1508 - */ 1509 1586 count = min(count, bufcount); 1510 - 1511 - /* Bail if no space left. */ 1512 - 1513 1587 if (count <= 0) 1514 1588 goto exit_retry; 1515 1589 ··· 1564 1652 1565 1653 spin_unlock_irqrestore(&ch->ch_lock, flags); 1566 1654 1567 - if (count) { 1568 - /* 1569 - * Channel lock is grabbed and then released 1570 - * inside this routine. 1571 - */ 1655 + if (count) 1572 1656 ch->ch_bd->bd_ops->copy_data_from_queue_to_uart(ch); 1573 - } 1574 1657 1575 1658 return count; 1576 1659 ··· 1576 1669 } 1577 1670 1578 1671 /* Return modem signals to ld. */ 1579 - 1580 1672 static int dgnc_tty_tiocmget(struct tty_struct *tty) 1581 1673 { 1582 1674 struct channel_t *ch; ··· 1619 1713 return rc; 1620 1714 } 1621 1715 1622 - /* 1623 - * dgnc_tty_tiocmset() 1624 - * 1625 - * Set modem signals, called by ld. 1626 - */ 1627 - 1716 + /* Set modem signals, called by ld. */ 1628 1717 static int dgnc_tty_tiocmset(struct tty_struct *tty, 1629 1718 unsigned int set, unsigned int clear) 1630 1719 { ··· 1664 1763 return 0; 1665 1764 } 1666 1765 1667 - /* 1668 - * dgnc_tty_send_break() 1669 - * 1670 - * Send a Break, called by ld. 1671 - */ 1766 + /* Send a Break, called by ld. */ 1672 1767 static int dgnc_tty_send_break(struct tty_struct *tty, int msec) 1673 1768 { 1674 1769 struct dgnc_board *bd; ··· 1699 1802 return 0; 1700 1803 } 1701 1804 1702 - /* 1703 - * dgnc_tty_wait_until_sent() 1704 - * 1705 - * wait until data has been transmitted, called by ld. 1706 - */ 1805 + /* wait until data has been transmitted, called by ld. */ 1707 1806 static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout) 1708 1807 { 1709 1808 struct dgnc_board *bd; ··· 1724 1831 bd->bd_ops->drain(tty, 0); 1725 1832 } 1726 1833 1727 - /* 1728 - * dgnc_send_xchar() 1729 - * 1730 - * send a high priority character, called by ld. 1731 - */ 1834 + /* send a high priority character, called by ld. */ 1732 1835 static void dgnc_tty_send_xchar(struct tty_struct *tty, char c) 1733 1836 { 1734 1837 struct dgnc_board *bd; ··· 1753 1864 } 1754 1865 1755 1866 /* Return modem signals to ld. */ 1756 - 1757 1867 static inline int dgnc_get_mstat(struct channel_t *ch) 1758 1868 { 1759 1869 unsigned char mstat; ··· 1787 1899 } 1788 1900 1789 1901 /* Return modem signals to ld. */ 1790 - 1791 1902 static int dgnc_get_modem_info(struct channel_t *ch, 1792 1903 unsigned int __user *value) 1793 1904 { 1794 1905 return put_user(dgnc_get_mstat(ch), value); 1795 1906 } 1796 1907 1797 - /* 1798 - * dgnc_set_modem_info() 1799 - * 1800 - * Set modem signals, called by ld. 1801 - */ 1908 + /* Set modem signals, called by ld. */ 1802 1909 static int dgnc_set_modem_info(struct channel_t *ch, 1803 1910 unsigned int command, 1804 1911 unsigned int __user *value) ··· 1852 1969 return 0; 1853 1970 } 1854 1971 1855 - /* 1856 - * dgnc_tty_digigeta() 1857 - * 1858 - * Ioctl to get the information for ditty. 1859 - */ 1972 + /* Ioctl to get the information for ditty. */ 1860 1973 static int dgnc_tty_digigeta(struct tty_struct *tty, 1861 1974 struct digi_t __user *retinfo) 1862 1975 { ··· 1887 2008 return 0; 1888 2009 } 1889 2010 1890 - /* 1891 - * dgnc_tty_digiseta() 1892 - * 1893 - * Ioctl to set the information for ditty. 1894 - */ 2011 + /* Ioctl to set the information for ditty. */ 1895 2012 static int dgnc_tty_digiseta(struct tty_struct *tty, 1896 2013 struct digi_t __user *new_info) 1897 2014 { ··· 1964 2089 1965 2090 return 0; 1966 2091 } 1967 - 1968 - /* dgnc_set_termios() */ 1969 2092 1970 2093 static void dgnc_tty_set_termios(struct tty_struct *tty, 1971 2094 struct ktermios *old_termios) ··· 2110 2237 } 2111 2238 2112 2239 /* 2113 - * dgnc_tty_flush_chars() 2114 - * 2115 2240 * Flush the cook buffer 2116 2241 * 2117 2242 * Note to self, and any other poor souls who venture here: ··· 2149 2278 spin_unlock_irqrestore(&ch->ch_lock, flags); 2150 2279 } 2151 2280 2152 - /* 2153 - * dgnc_tty_flush_buffer() 2154 - * 2155 - * Flush Tx buffer (make in == out) 2156 - */ 2281 + /* Flush Tx buffer (make in == out) */ 2157 2282 static void dgnc_tty_flush_buffer(struct tty_struct *tty) 2158 2283 { 2159 2284 struct channel_t *ch; ··· 2189 2322 spin_unlock_irqrestore(&ch->ch_lock, flags); 2190 2323 } 2191 2324 2192 - /* 2193 - * dgnc_wake_up_unit() 2194 - * 2195 - * Wakes up processes waiting in the unit's (teminal/printer) wait queue 2196 - */ 2325 + /* Wakes up processes waiting in the unit's (teminal/printer) wait queue */ 2197 2326 static void dgnc_wake_up_unit(struct un_t *unit) 2198 2327 { 2199 2328 unit->un_flags &= ~(UN_LOW | UN_EMPTY); ··· 2198 2335 2199 2336 /* The IOCTL function and all of its helpers */ 2200 2337 2201 - /* 2202 - * dgnc_tty_ioctl() 2203 - * 2204 - * The usual assortment of ioctl's 2205 - */ 2338 + /* The usual assortment of ioctl's */ 2206 2339 static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, 2207 2340 unsigned long arg) 2208 2341 { ··· 2483 2624 case DIGI_SETCUSTOMBAUD: 2484 2625 { 2485 2626 int new_rate; 2486 - /* Let go of locks when accessing user space, could sleep */ 2627 + 2487 2628 spin_unlock_irqrestore(&ch->ch_lock, flags); 2488 2629 rc = get_user(new_rate, (int __user *)arg); 2489 2630 if (rc) ··· 2580 2721 int count; 2581 2722 2582 2723 spin_unlock_irqrestore(&ch->ch_lock, flags); 2583 - 2584 - /* Get data from user first. */ 2585 2724 2586 2725 if (copy_from_user(&buf, uarg, sizeof(buf))) 2587 2726 return -EFAULT;
+4 -5
drivers/staging/dgnc/dgnc_utils.c
··· 2 2 #include <linux/sched/signal.h> 3 3 #include "dgnc_utils.h" 4 4 5 - /* 6 - * dgnc_ms_sleep() 5 + /** 6 + * dgnc_ms_sleep - Put the driver to sleep 7 + * @ms - milliseconds to sleep 7 8 * 8 - * Put the driver to sleep for x ms's 9 - * 10 - * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal. 9 + * Return: 0 if timed out, if interrupted by a signal return signal. 11 10 */ 12 11 int dgnc_ms_sleep(ulong ms) 13 12 {