12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993 |
- /*
- * Copyright 2003 Digi International (www.digi.com)
- * Scott H Kilau <Scott_Kilau at digi dot com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- */
- /************************************************************************
- *
- * This file implements the tty driver functionality for the
- * Neo and ClassicBoard PCI based product lines.
- *
- ************************************************************************
- *
- */
- #include <linux/kernel.h>
- #include <linux/sched.h> /* For jiffies, task states */
- #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
- #include <linux/module.h>
- #include <linux/ctype.h>
- #include <linux/tty.h>
- #include <linux/tty_flip.h>
- #include <linux/types.h>
- #include <linux/serial_reg.h>
- #include <linux/slab.h>
- #include <linux/delay.h> /* For udelay */
- #include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
- #include <linux/pci.h>
- #include "dgnc_driver.h"
- #include "dgnc_tty.h"
- #include "dgnc_neo.h"
- #include "dgnc_cls.h"
- #include "dgnc_sysfs.h"
- #include "dgnc_utils.h"
- /*
- * internal variables
- */
- static struct dgnc_board *dgnc_BoardsByMajor[256];
- static unsigned char *dgnc_TmpWriteBuf;
- /*
- * Default transparent print information.
- */
- static struct digi_t dgnc_digi_init = {
- .digi_flags = DIGI_COOK, /* Flags */
- .digi_maxcps = 100, /* Max CPS */
- .digi_maxchar = 50, /* Max chars in print queue */
- .digi_bufsize = 100, /* Printer buffer size */
- .digi_onlen = 4, /* size of printer on string */
- .digi_offlen = 4, /* size of printer off string */
- .digi_onstr = "\033[5i", /* ANSI printer on string ] */
- .digi_offstr = "\033[4i", /* ANSI printer off string ] */
- .digi_term = "ansi" /* default terminal type */
- };
- /*
- * Define a local default termios struct. All ports will be created
- * with this termios initially.
- *
- * This defines a raw port at 9600 baud, 8 data bits, no parity,
- * 1 stop bit.
- */
- static struct ktermios DgncDefaultTermios = {
- .c_iflag = (DEFAULT_IFLAGS), /* iflags */
- .c_oflag = (DEFAULT_OFLAGS), /* oflags */
- .c_cflag = (DEFAULT_CFLAGS), /* cflags */
- .c_lflag = (DEFAULT_LFLAGS), /* lflags */
- .c_cc = INIT_C_CC,
- .c_line = 0,
- };
- /* Our function prototypes */
- static int dgnc_tty_open(struct tty_struct *tty, struct file *file);
- static void dgnc_tty_close(struct tty_struct *tty, struct file *file);
- static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file,
- struct channel_t *ch);
- static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
- unsigned long arg);
- static int dgnc_tty_digigeta(struct tty_struct *tty,
- struct digi_t __user *retinfo);
- static int dgnc_tty_digiseta(struct tty_struct *tty,
- struct digi_t __user *new_info);
- static int dgnc_tty_write_room(struct tty_struct *tty);
- static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c);
- static int dgnc_tty_chars_in_buffer(struct tty_struct *tty);
- static void dgnc_tty_start(struct tty_struct *tty);
- static void dgnc_tty_stop(struct tty_struct *tty);
- static void dgnc_tty_throttle(struct tty_struct *tty);
- static void dgnc_tty_unthrottle(struct tty_struct *tty);
- static void dgnc_tty_flush_chars(struct tty_struct *tty);
- static void dgnc_tty_flush_buffer(struct tty_struct *tty);
- static void dgnc_tty_hangup(struct tty_struct *tty);
- static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command,
- unsigned int __user *value);
- static int dgnc_get_modem_info(struct channel_t *ch,
- unsigned int __user *value);
- static int dgnc_tty_tiocmget(struct tty_struct *tty);
- static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set,
- unsigned int clear);
- static int dgnc_tty_send_break(struct tty_struct *tty, int msec);
- static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout);
- static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf,
- int count);
- static void dgnc_tty_set_termios(struct tty_struct *tty,
- struct ktermios *old_termios);
- static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
- static const struct tty_operations dgnc_tty_ops = {
- .open = dgnc_tty_open,
- .close = dgnc_tty_close,
- .write = dgnc_tty_write,
- .write_room = dgnc_tty_write_room,
- .flush_buffer = dgnc_tty_flush_buffer,
- .chars_in_buffer = dgnc_tty_chars_in_buffer,
- .flush_chars = dgnc_tty_flush_chars,
- .ioctl = dgnc_tty_ioctl,
- .set_termios = dgnc_tty_set_termios,
- .stop = dgnc_tty_stop,
- .start = dgnc_tty_start,
- .throttle = dgnc_tty_throttle,
- .unthrottle = dgnc_tty_unthrottle,
- .hangup = dgnc_tty_hangup,
- .put_char = dgnc_tty_put_char,
- .tiocmget = dgnc_tty_tiocmget,
- .tiocmset = dgnc_tty_tiocmset,
- .break_ctl = dgnc_tty_send_break,
- .wait_until_sent = dgnc_tty_wait_until_sent,
- .send_xchar = dgnc_tty_send_xchar
- };
- /************************************************************************
- *
- * TTY Initialization/Cleanup Functions
- *
- ************************************************************************/
- /*
- * dgnc_tty_preinit()
- *
- * Initialize any global tty related data before we download any boards.
- */
- int dgnc_tty_preinit(void)
- {
- /*
- * Allocate a buffer for doing the copy from user space to
- * kernel space in dgnc_write(). We only use one buffer and
- * control access to it with a semaphore. If we are paging, we
- * are already in trouble so one buffer won't hurt much anyway.
- *
- * We are okay to sleep in the malloc, as this routine
- * is only called during module load, (not in interrupt context),
- * and with no locks held.
- */
- dgnc_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_KERNEL);
- if (!dgnc_TmpWriteBuf)
- return -ENOMEM;
- return 0;
- }
- /*
- * dgnc_tty_register()
- *
- * Init the tty subsystem for this board.
- */
- int dgnc_tty_register(struct dgnc_board *brd)
- {
- int rc = 0;
- brd->SerialDriver.magic = TTY_DRIVER_MAGIC;
- snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgnc_%d_", brd->boardnum);
- brd->SerialDriver.name = brd->SerialName;
- brd->SerialDriver.name_base = 0;
- brd->SerialDriver.major = 0;
- brd->SerialDriver.minor_start = 0;
- brd->SerialDriver.num = brd->maxports;
- brd->SerialDriver.type = TTY_DRIVER_TYPE_SERIAL;
- brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL;
- brd->SerialDriver.init_termios = DgncDefaultTermios;
- brd->SerialDriver.driver_name = DRVSTR;
- brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW |
- TTY_DRIVER_DYNAMIC_DEV |
- TTY_DRIVER_HARDWARE_BREAK);
- /*
- * The kernel wants space to store pointers to
- * tty_struct's and termios's.
- */
- brd->SerialDriver.ttys = kcalloc(brd->maxports,
- sizeof(*brd->SerialDriver.ttys),
- GFP_KERNEL);
- if (!brd->SerialDriver.ttys)
- return -ENOMEM;
- kref_init(&brd->SerialDriver.kref);
- brd->SerialDriver.termios = kcalloc(brd->maxports,
- sizeof(*brd->SerialDriver.termios),
- GFP_KERNEL);
- if (!brd->SerialDriver.termios)
- return -ENOMEM;
- /*
- * Entry points for driver. Called by the kernel from
- * tty_io.c and n_tty.c.
- */
- tty_set_operations(&brd->SerialDriver, &dgnc_tty_ops);
- if (!brd->dgnc_Major_Serial_Registered) {
- /* Register tty devices */
- rc = tty_register_driver(&brd->SerialDriver);
- if (rc < 0) {
- dev_dbg(&brd->pdev->dev,
- "Can't register tty device (%d)\n", rc);
- return rc;
- }
- brd->dgnc_Major_Serial_Registered = true;
- }
- /*
- * If we're doing transparent print, we have to do all of the above
- * again, separately so we don't get the LD confused about what major
- * we are when we get into the dgnc_tty_open() routine.
- */
- brd->PrintDriver.magic = TTY_DRIVER_MAGIC;
- snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
- brd->PrintDriver.name = brd->PrintName;
- brd->PrintDriver.name_base = 0;
- brd->PrintDriver.major = brd->SerialDriver.major;
- brd->PrintDriver.minor_start = 0x80;
- brd->PrintDriver.num = brd->maxports;
- brd->PrintDriver.type = TTY_DRIVER_TYPE_SERIAL;
- brd->PrintDriver.subtype = SERIAL_TYPE_NORMAL;
- brd->PrintDriver.init_termios = DgncDefaultTermios;
- brd->PrintDriver.driver_name = DRVSTR;
- brd->PrintDriver.flags = (TTY_DRIVER_REAL_RAW |
- TTY_DRIVER_DYNAMIC_DEV |
- TTY_DRIVER_HARDWARE_BREAK);
- /*
- * The kernel wants space to store pointers to
- * tty_struct's and termios's. Must be separated from
- * the Serial Driver so we don't get confused
- */
- brd->PrintDriver.ttys = kcalloc(brd->maxports,
- sizeof(*brd->PrintDriver.ttys),
- GFP_KERNEL);
- if (!brd->PrintDriver.ttys)
- return -ENOMEM;
- kref_init(&brd->PrintDriver.kref);
- brd->PrintDriver.termios = kcalloc(brd->maxports,
- sizeof(*brd->PrintDriver.termios),
- GFP_KERNEL);
- if (!brd->PrintDriver.termios)
- return -ENOMEM;
- /*
- * Entry points for driver. Called by the kernel from
- * tty_io.c and n_tty.c.
- */
- tty_set_operations(&brd->PrintDriver, &dgnc_tty_ops);
- if (!brd->dgnc_Major_TransparentPrint_Registered) {
- /* Register Transparent Print devices */
- rc = tty_register_driver(&brd->PrintDriver);
- if (rc < 0) {
- dev_dbg(&brd->pdev->dev,
- "Can't register Transparent Print device(%d)\n",
- rc);
- return rc;
- }
- brd->dgnc_Major_TransparentPrint_Registered = true;
- }
- dgnc_BoardsByMajor[brd->SerialDriver.major] = brd;
- brd->dgnc_Serial_Major = brd->SerialDriver.major;
- brd->dgnc_TransparentPrint_Major = brd->PrintDriver.major;
- return rc;
- }
- /*
- * dgnc_tty_init()
- *
- * Init the tty subsystem. Called once per board after board has been
- * downloaded and init'ed.
- */
- int dgnc_tty_init(struct dgnc_board *brd)
- {
- int i;
- void __iomem *vaddr;
- struct channel_t *ch;
- if (!brd)
- return -ENXIO;
- /*
- * Initialize board structure elements.
- */
- vaddr = brd->re_map_membase;
- brd->nasync = brd->maxports;
- for (i = 0; i < brd->nasync; i++) {
- /*
- * Okay to malloc with GFP_KERNEL, we are not at
- * interrupt context, and there are no locks held.
- */
- brd->channels[i] = kzalloc(sizeof(*brd->channels[i]),
- GFP_KERNEL);
- if (!brd->channels[i])
- goto err_free_channels;
- }
- ch = brd->channels[0];
- vaddr = brd->re_map_membase;
- /* Set up channel variables */
- for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
- spin_lock_init(&ch->ch_lock);
- /* Store all our magic numbers */
- ch->magic = DGNC_CHANNEL_MAGIC;
- ch->ch_tun.magic = DGNC_UNIT_MAGIC;
- ch->ch_tun.un_ch = ch;
- ch->ch_tun.un_type = DGNC_SERIAL;
- ch->ch_tun.un_dev = i;
- ch->ch_pun.magic = DGNC_UNIT_MAGIC;
- ch->ch_pun.un_ch = ch;
- ch->ch_pun.un_type = DGNC_PRINT;
- ch->ch_pun.un_dev = i + 128;
- if (brd->bd_uart_offset == 0x200)
- ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
- else
- ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
- ch->ch_bd = brd;
- ch->ch_portnum = i;
- ch->ch_digi = dgnc_digi_init;
- /* .25 second delay */
- ch->ch_close_delay = 250;
- init_waitqueue_head(&ch->ch_flags_wait);
- init_waitqueue_head(&ch->ch_tun.un_flags_wait);
- init_waitqueue_head(&ch->ch_pun.un_flags_wait);
- {
- struct device *classp;
- classp = tty_register_device(&brd->SerialDriver, i,
- &ch->ch_bd->pdev->dev);
- ch->ch_tun.un_sysfs = classp;
- dgnc_create_tty_sysfs(&ch->ch_tun, classp);
- classp = tty_register_device(&brd->PrintDriver, i,
- &ch->ch_bd->pdev->dev);
- ch->ch_pun.un_sysfs = classp;
- dgnc_create_tty_sysfs(&ch->ch_pun, classp);
- }
- }
- return 0;
- err_free_channels:
- for (i = i - 1; i >= 0; --i) {
- kfree(brd->channels[i]);
- brd->channels[i] = NULL;
- }
- return -ENOMEM;
- }
- /*
- * dgnc_tty_post_uninit()
- *
- * UnInitialize any global tty related data.
- */
- void dgnc_tty_post_uninit(void)
- {
- kfree(dgnc_TmpWriteBuf);
- dgnc_TmpWriteBuf = NULL;
- }
- /*
- * dgnc_tty_uninit()
- *
- * Uninitialize the TTY portion of this driver. Free all memory and
- * resources.
- */
- void dgnc_tty_uninit(struct dgnc_board *brd)
- {
- int i = 0;
- if (brd->dgnc_Major_Serial_Registered) {
- dgnc_BoardsByMajor[brd->SerialDriver.major] = NULL;
- brd->dgnc_Serial_Major = 0;
- for (i = 0; i < brd->nasync; i++) {
- if (brd->channels[i])
- dgnc_remove_tty_sysfs(brd->channels[i]->
- ch_tun.un_sysfs);
- tty_unregister_device(&brd->SerialDriver, i);
- }
- tty_unregister_driver(&brd->SerialDriver);
- brd->dgnc_Major_Serial_Registered = false;
- }
- if (brd->dgnc_Major_TransparentPrint_Registered) {
- dgnc_BoardsByMajor[brd->PrintDriver.major] = NULL;
- brd->dgnc_TransparentPrint_Major = 0;
- for (i = 0; i < brd->nasync; i++) {
- if (brd->channels[i])
- dgnc_remove_tty_sysfs(brd->channels[i]->
- ch_pun.un_sysfs);
- tty_unregister_device(&brd->PrintDriver, i);
- }
- tty_unregister_driver(&brd->PrintDriver);
- brd->dgnc_Major_TransparentPrint_Registered = false;
- }
- kfree(brd->SerialDriver.ttys);
- brd->SerialDriver.ttys = NULL;
- kfree(brd->SerialDriver.termios);
- brd->SerialDriver.termios = NULL;
- kfree(brd->PrintDriver.ttys);
- brd->PrintDriver.ttys = NULL;
- kfree(brd->PrintDriver.termios);
- brd->PrintDriver.termios = NULL;
- }
- /*=======================================================================
- *
- * dgnc_wmove - Write data to transmit queue.
- *
- * ch - Pointer to channel structure.
- * buf - Poiter to characters to be moved.
- * n - Number of characters to move.
- *
- *=======================================================================*/
- static void dgnc_wmove(struct channel_t *ch, char *buf, uint n)
- {
- int remain;
- uint head;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- head = ch->ch_w_head & WQUEUEMASK;
- /*
- * If the write wraps over the top of the circular buffer,
- * move the portion up to the wrap point, and reset the
- * pointers to the bottom.
- */
- remain = WQUEUESIZE - head;
- if (n >= remain) {
- n -= remain;
- memcpy(ch->ch_wqueue + head, buf, remain);
- head = 0;
- buf += remain;
- }
- if (n > 0) {
- /*
- * Move rest of data.
- */
- remain = n;
- memcpy(ch->ch_wqueue + head, buf, remain);
- head += remain;
- }
- head &= WQUEUEMASK;
- ch->ch_w_head = head;
- }
- /*=======================================================================
- *
- * dgnc_input - Process received data.
- *
- * ch - Pointer to channel structure.
- *
- *=======================================================================*/
- void dgnc_input(struct channel_t *ch)
- {
- struct dgnc_board *bd;
- struct tty_struct *tp;
- struct tty_ldisc *ld = NULL;
- uint rmask;
- ushort head;
- ushort tail;
- int data_len;
- unsigned long flags;
- int flip_len;
- int len = 0;
- int n = 0;
- int s = 0;
- int i = 0;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- tp = ch->ch_tun.un_tty;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /*
- * Figure the number of characters in the buffer.
- * Exit immediately if none.
- */
- rmask = RQUEUEMASK;
- head = ch->ch_r_head & rmask;
- tail = ch->ch_r_tail & rmask;
- data_len = (head - tail) & rmask;
- if (data_len == 0)
- goto exit_unlock;
- /*
- * If the device is not open, or CREAD is off,
- * flush input data and return immediately.
- */
- if (!tp || (tp->magic != TTY_MAGIC) ||
- !(ch->ch_tun.un_flags & UN_ISOPEN) ||
- !(tp->termios.c_cflag & CREAD) ||
- (ch->ch_tun.un_flags & UN_CLOSING)) {
- ch->ch_r_head = tail;
- /* Force queue flow control to be released, if needed */
- dgnc_check_queue_flow_control(ch);
- goto exit_unlock;
- }
- /*
- * If we are throttled, simply don't read any data.
- */
- if (ch->ch_flags & CH_FORCED_STOPI)
- goto exit_unlock;
- flip_len = TTY_FLIPBUF_SIZE;
- /* Chop down the length, if needed */
- len = min(data_len, flip_len);
- len = min(len, (N_TTY_BUF_SIZE - 1));
- ld = tty_ldisc_ref(tp);
- /*
- * If we were unable to get a reference to the ld,
- * don't flush our buffer, and act like the ld doesn't
- * have any space to put the data right now.
- */
- if (!ld) {
- len = 0;
- } else {
- /*
- * If ld doesn't have a pointer to a receive_buf function,
- * flush the data, then act like the ld doesn't have any
- * space to put the data right now.
- */
- if (!ld->ops->receive_buf) {
- ch->ch_r_head = ch->ch_r_tail;
- len = 0;
- }
- }
- if (len <= 0)
- goto exit_unlock;
- /*
- * The tty layer in the kernel has changed in 2.6.16+.
- *
- * The flip buffers in the tty structure are no longer exposed,
- * and probably will be going away eventually.
- *
- * If we are completely raw, we don't need to go through a lot
- * of the tty layers that exist.
- * In this case, we take the shortest and fastest route we
- * can to relay the data to the user.
- *
- * On the other hand, if we are not raw, we need to go through
- * the new 2.6.16+ tty layer, which has its API more well defined.
- */
- len = tty_buffer_request_room(tp->port, len);
- n = len;
- /*
- * n now contains the most amount of data we can copy,
- * bounded either by how much the Linux tty layer can handle,
- * or the amount of data the card actually has pending...
- */
- while (n) {
- s = ((head >= tail) ? head : RQUEUESIZE) - tail;
- s = min(s, n);
- if (s <= 0)
- break;
- /*
- * If conditions are such that ld needs to see all
- * UART errors, we will have to walk each character
- * and error byte and send them to the buffer one at
- * a time.
- */
- if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
- for (i = 0; i < s; i++) {
- if (*(ch->ch_equeue + tail + i) & UART_LSR_BI)
- tty_insert_flip_char(tp->port,
- *(ch->ch_rqueue + tail + i),
- TTY_BREAK);
- else if (*(ch->ch_equeue + tail + i) &
- UART_LSR_PE)
- tty_insert_flip_char(tp->port,
- *(ch->ch_rqueue + tail + i),
- TTY_PARITY);
- else if (*(ch->ch_equeue + tail + i) &
- UART_LSR_FE)
- tty_insert_flip_char(tp->port,
- *(ch->ch_rqueue + tail + i),
- TTY_FRAME);
- else
- tty_insert_flip_char(tp->port,
- *(ch->ch_rqueue + tail + i),
- TTY_NORMAL);
- }
- } else {
- tty_insert_flip_string(tp->port,
- ch->ch_rqueue + tail,
- s);
- }
- tail += s;
- n -= s;
- /* Flip queue if needed */
- tail &= rmask;
- }
- ch->ch_r_tail = tail & rmask;
- ch->ch_e_tail = tail & rmask;
- dgnc_check_queue_flow_control(ch);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- /* Tell the tty layer its okay to "eat" the data now */
- tty_flip_buffer_push(tp->port);
- if (ld)
- tty_ldisc_deref(ld);
- return;
- exit_unlock:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (ld)
- tty_ldisc_deref(ld);
- }
- /************************************************************************
- * Determines when CARRIER changes state and takes appropriate
- * action.
- ************************************************************************/
- void dgnc_carrier(struct channel_t *ch)
- {
- struct dgnc_board *bd;
- int virt_carrier = 0;
- int phys_carrier = 0;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- if (ch->ch_mistat & UART_MSR_DCD)
- phys_carrier = 1;
- if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
- virt_carrier = 1;
- if (ch->ch_c_cflag & CLOCAL)
- virt_carrier = 1;
- /*
- * Test for a VIRTUAL carrier transition to HIGH.
- */
- if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
- /*
- * When carrier rises, wake any threads waiting
- * for carrier in the open routine.
- */
- if (waitqueue_active(&ch->ch_flags_wait))
- wake_up_interruptible(&ch->ch_flags_wait);
- }
- /*
- * Test for a PHYSICAL carrier transition to HIGH.
- */
- if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
- /*
- * When carrier rises, wake any threads waiting
- * for carrier in the open routine.
- */
- if (waitqueue_active(&ch->ch_flags_wait))
- wake_up_interruptible(&ch->ch_flags_wait);
- }
- /*
- * Test for a PHYSICAL transition to low, so long as we aren't
- * currently ignoring physical transitions (which is what "virtual
- * carrier" indicates).
- *
- * The transition of the virtual carrier to low really doesn't
- * matter... it really only means "ignore carrier state", not
- * "make pretend that carrier is there".
- */
- if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
- (phys_carrier == 0)) {
- /*
- * When carrier drops:
- *
- * Drop carrier on all open units.
- *
- * Flush queues, waking up any task waiting in the
- * line discipline.
- *
- * Send a hangup to the control terminal.
- *
- * Enable all select calls.
- */
- if (waitqueue_active(&ch->ch_flags_wait))
- wake_up_interruptible(&ch->ch_flags_wait);
- if (ch->ch_tun.un_open_count > 0)
- tty_hangup(ch->ch_tun.un_tty);
- if (ch->ch_pun.un_open_count > 0)
- tty_hangup(ch->ch_pun.un_tty);
- }
- /*
- * Make sure that our cached values reflect the current reality.
- */
- if (virt_carrier == 1)
- ch->ch_flags |= CH_FCAR;
- else
- ch->ch_flags &= ~CH_FCAR;
- if (phys_carrier == 1)
- ch->ch_flags |= CH_CD;
- else
- ch->ch_flags &= ~CH_CD;
- }
- /*
- * Assign the custom baud rate to the channel structure
- */
- static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate)
- {
- int testdiv;
- int testrate_high;
- int testrate_low;
- int deltahigh;
- int deltalow;
- if (newrate <= 0) {
- ch->ch_custom_speed = 0;
- return;
- }
- /*
- * Since the divisor is stored in a 16-bit integer, we make sure
- * we don't allow any rates smaller than a 16-bit integer would allow.
- * And of course, rates above the dividend won't fly.
- */
- if (newrate && newrate < ((ch->ch_bd->bd_dividend / 0xFFFF) + 1))
- newrate = ((ch->ch_bd->bd_dividend / 0xFFFF) + 1);
- if (newrate && newrate > ch->ch_bd->bd_dividend)
- newrate = ch->ch_bd->bd_dividend;
- if (newrate > 0) {
- testdiv = ch->ch_bd->bd_dividend / newrate;
- /*
- * If we try to figure out what rate the board would use
- * with the test divisor, it will be either equal or higher
- * than the requested baud rate. If we then determine the
- * rate with a divisor one higher, we will get the next lower
- * supported rate below the requested.
- */
- testrate_high = ch->ch_bd->bd_dividend / testdiv;
- testrate_low = ch->ch_bd->bd_dividend / (testdiv + 1);
- /*
- * If the rate for the requested divisor is correct, just
- * use it and be done.
- */
- if (testrate_high != newrate) {
- /*
- * Otherwise, pick the rate that is closer
- * (i.e. whichever rate has a smaller delta).
- */
- deltahigh = testrate_high - newrate;
- deltalow = newrate - testrate_low;
- if (deltahigh < deltalow)
- newrate = testrate_high;
- else
- newrate = testrate_low;
- }
- }
- ch->ch_custom_speed = newrate;
- }
- void dgnc_check_queue_flow_control(struct channel_t *ch)
- {
- int qleft;
- /* Store how much space we have left in the queue */
- qleft = ch->ch_r_tail - ch->ch_r_head - 1;
- if (qleft < 0)
- qleft += RQUEUEMASK + 1;
- /*
- * Check to see if we should enforce flow control on our queue because
- * the ld (or user) isn't reading data out of our queue fast enuf.
- *
- * NOTE: This is done based on what the current flow control of the
- * port is set for.
- *
- * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
- * This will cause the UART's FIFO to back up, and force
- * the RTS signal to be dropped.
- * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
- * the other side, in hopes it will stop sending data to us.
- * 3) NONE - Nothing we can do. We will simply drop any extra data
- * that gets sent into us when the queue fills up.
- */
- if (qleft < 256) {
- /* HWFLOW */
- if (ch->ch_digi.digi_flags & CTSPACE ||
- ch->ch_c_cflag & CRTSCTS) {
- if (!(ch->ch_flags & CH_RECEIVER_OFF)) {
- ch->ch_bd->bd_ops->disable_receiver(ch);
- ch->ch_flags |= (CH_RECEIVER_OFF);
- }
- }
- /* SWFLOW */
- else if (ch->ch_c_iflag & IXOFF) {
- if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
- ch->ch_bd->bd_ops->send_stop_character(ch);
- ch->ch_stops_sent++;
- }
- }
- }
- /*
- * Check to see if we should unenforce flow control because
- * ld (or user) finally read enuf data out of our queue.
- *
- * NOTE: This is done based on what the current flow control of the
- * port is set for.
- *
- * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
- * This will cause the UART's FIFO to raise RTS back up,
- * which will allow the other side to start sending data again.
- * 2) SWFLOW (IXOFF) - Send a start character to
- * the other side, so it will start sending data to us again.
- * 3) NONE - Do nothing. Since we didn't do anything to turn off the
- * other side, we don't need to do anything now.
- */
- if (qleft > (RQUEUESIZE / 2)) {
- /* HWFLOW */
- if (ch->ch_digi.digi_flags & RTSPACE ||
- ch->ch_c_cflag & CRTSCTS) {
- if (ch->ch_flags & CH_RECEIVER_OFF) {
- ch->ch_bd->bd_ops->enable_receiver(ch);
- ch->ch_flags &= ~(CH_RECEIVER_OFF);
- }
- }
- /* SWFLOW */
- else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
- ch->ch_stops_sent = 0;
- ch->ch_bd->bd_ops->send_start_character(ch);
- }
- }
- }
- void dgnc_wakeup_writes(struct channel_t *ch)
- {
- int qlen = 0;
- unsigned long flags;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /*
- * If channel now has space, wake up anyone waiting on the condition.
- */
- qlen = ch->ch_w_head - ch->ch_w_tail;
- if (qlen < 0)
- qlen += WQUEUESIZE;
- if (qlen >= (WQUEUESIZE - 256)) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return;
- }
- if (ch->ch_tun.un_flags & UN_ISOPEN) {
- if ((ch->ch_tun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
- ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- ch->ch_tun.un_tty->ldisc->ops->write_wakeup(ch->ch_tun.un_tty);
- spin_lock_irqsave(&ch->ch_lock, flags);
- }
- wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
- /*
- * If unit is set to wait until empty, check to make sure
- * the queue AND FIFO are both empty.
- */
- if (ch->ch_tun.un_flags & UN_EMPTY) {
- if ((qlen == 0) &&
- (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
- ch->ch_tun.un_flags &= ~(UN_EMPTY);
- /*
- * If RTS Toggle mode is on, whenever
- * the queue and UART is empty, keep RTS low.
- */
- if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
- ch->ch_mostat &= ~(UART_MCR_RTS);
- ch->ch_bd->bd_ops->assert_modem_signals(ch);
- }
- /*
- * If DTR Toggle mode is on, whenever
- * the queue and UART is empty, keep DTR low.
- */
- if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
- ch->ch_mostat &= ~(UART_MCR_DTR);
- ch->ch_bd->bd_ops->assert_modem_signals(ch);
- }
- }
- }
- wake_up_interruptible(&ch->ch_tun.un_flags_wait);
- }
- if (ch->ch_pun.un_flags & UN_ISOPEN) {
- if ((ch->ch_pun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
- ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- ch->ch_pun.un_tty->ldisc->ops->write_wakeup(ch->ch_pun.un_tty);
- spin_lock_irqsave(&ch->ch_lock, flags);
- }
- wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
- /*
- * If unit is set to wait until empty, check to make sure
- * the queue AND FIFO are both empty.
- */
- if (ch->ch_pun.un_flags & UN_EMPTY) {
- if ((qlen == 0) &&
- (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0))
- ch->ch_pun.un_flags &= ~(UN_EMPTY);
- }
- wake_up_interruptible(&ch->ch_pun.un_flags_wait);
- }
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- /************************************************************************
- *
- * TTY Entry points and helper functions
- *
- ************************************************************************/
- /*
- * dgnc_tty_open()
- *
- */
- static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
- {
- struct dgnc_board *brd;
- struct channel_t *ch;
- struct un_t *un;
- uint major = 0;
- uint minor = 0;
- int rc = 0;
- unsigned long flags;
- rc = 0;
- major = MAJOR(tty_devnum(tty));
- minor = MINOR(tty_devnum(tty));
- if (major > 255)
- return -ENXIO;
- /* Get board pointer from our array of majors we have allocated */
- brd = dgnc_BoardsByMajor[major];
- if (!brd)
- return -ENXIO;
- /*
- * If board is not yet up to a state of READY, go to
- * sleep waiting for it to happen or they cancel the open.
- */
- rc = wait_event_interruptible(brd->state_wait,
- (brd->state & BOARD_READY));
- if (rc)
- return rc;
- spin_lock_irqsave(&brd->bd_lock, flags);
- /* If opened device is greater than our number of ports, bail. */
- if (PORT_NUM(minor) >= brd->nasync) {
- spin_unlock_irqrestore(&brd->bd_lock, flags);
- return -ENXIO;
- }
- ch = brd->channels[PORT_NUM(minor)];
- if (!ch) {
- spin_unlock_irqrestore(&brd->bd_lock, flags);
- return -ENXIO;
- }
- /* Drop board lock */
- spin_unlock_irqrestore(&brd->bd_lock, flags);
- /* Grab channel lock */
- spin_lock_irqsave(&ch->ch_lock, flags);
- /* Figure out our type */
- if (!IS_PRINT(minor)) {
- un = &brd->channels[PORT_NUM(minor)]->ch_tun;
- un->un_type = DGNC_SERIAL;
- } else if (IS_PRINT(minor)) {
- un = &brd->channels[PORT_NUM(minor)]->ch_pun;
- un->un_type = DGNC_PRINT;
- } else {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return -ENXIO;
- }
- /*
- * If the port is still in a previous open, and in a state
- * where we simply cannot safely keep going, wait until the
- * state clears.
- */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = wait_event_interruptible(ch->ch_flags_wait,
- ((ch->ch_flags & CH_OPENING) == 0));
- /* If ret is non-zero, user ctrl-c'ed us */
- if (rc)
- return -EINTR;
- /*
- * If either unit is in the middle of the fragile part of close,
- * we just cannot touch the channel safely.
- * Go to sleep, knowing that when the channel can be
- * touched safely, the close routine will signal the
- * ch_flags_wait to wake us back up.
- */
- rc = wait_event_interruptible(ch->ch_flags_wait,
- (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
- UN_CLOSING) == 0));
- /* If ret is non-zero, user ctrl-c'ed us */
- if (rc)
- return -EINTR;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /* Store our unit into driver_data, so we always have it available. */
- tty->driver_data = un;
- /*
- * Initialize tty's
- */
- if (!(un->un_flags & UN_ISOPEN)) {
- /* Store important variables. */
- un->un_tty = tty;
- /* Maybe do something here to the TTY struct as well? */
- }
- /*
- * Allocate channel buffers for read/write/error.
- * Set flag, so we don't get trounced on.
- */
- ch->ch_flags |= (CH_OPENING);
- /* Drop locks, as malloc with GFP_KERNEL can sleep */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (!ch->ch_rqueue)
- ch->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
- if (!ch->ch_equeue)
- ch->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
- if (!ch->ch_wqueue)
- ch->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_flags &= ~(CH_OPENING);
- wake_up_interruptible(&ch->ch_flags_wait);
- /*
- * Initialize if neither terminal or printer is open.
- */
- if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
- /*
- * Flush input queues.
- */
- ch->ch_r_head = 0;
- ch->ch_r_tail = 0;
- ch->ch_e_head = 0;
- ch->ch_e_tail = 0;
- ch->ch_w_head = 0;
- ch->ch_w_tail = 0;
- brd->bd_ops->flush_uart_write(ch);
- brd->bd_ops->flush_uart_read(ch);
- ch->ch_flags = 0;
- ch->ch_cached_lsr = 0;
- ch->ch_stop_sending_break = 0;
- ch->ch_stops_sent = 0;
- ch->ch_c_cflag = tty->termios.c_cflag;
- ch->ch_c_iflag = tty->termios.c_iflag;
- ch->ch_c_oflag = tty->termios.c_oflag;
- ch->ch_c_lflag = tty->termios.c_lflag;
- ch->ch_startc = tty->termios.c_cc[VSTART];
- ch->ch_stopc = tty->termios.c_cc[VSTOP];
- /*
- * Bring up RTS and DTR...
- * Also handle RTS or DTR toggle if set.
- */
- if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
- ch->ch_mostat |= (UART_MCR_RTS);
- if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
- ch->ch_mostat |= (UART_MCR_DTR);
- /* Tell UART to init itself */
- brd->bd_ops->uart_init(ch);
- }
- /*
- * Run param in case we changed anything
- */
- brd->bd_ops->param(tty);
- dgnc_carrier(ch);
- /*
- * follow protocol for opening port
- */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = dgnc_block_til_ready(tty, file, ch);
- /* No going back now, increment our unit and channel counters */
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_open_count++;
- un->un_open_count++;
- un->un_flags |= (UN_ISOPEN);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return rc;
- }
- /*
- * dgnc_block_til_ready()
- *
- * Wait for DCD, if needed.
- */
- static int dgnc_block_til_ready(struct tty_struct *tty,
- struct file *file,
- struct channel_t *ch)
- {
- int retval = 0;
- struct un_t *un = NULL;
- unsigned long flags;
- uint old_flags = 0;
- int sleep_on_un_flags = 0;
- if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
- ch->magic != DGNC_CHANNEL_MAGIC)
- return -ENXIO;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return -ENXIO;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_wopen++;
- /* Loop forever */
- while (1) {
- sleep_on_un_flags = 0;
- /*
- * If board has failed somehow during our sleep,
- * bail with error.
- */
- if (ch->ch_bd->state == BOARD_FAILED) {
- retval = -ENXIO;
- break;
- }
- /* If tty was hung up, break out of loop and set error. */
- if (tty_hung_up_p(file)) {
- retval = -EAGAIN;
- break;
- }
- /*
- * If either unit is in the middle of the fragile part of close,
- * we just cannot touch the channel safely.
- * Go back to sleep, knowing that when the channel can be
- * touched safely, the close routine will signal the
- * ch_wait_flags to wake us back up.
- */
- if (!((ch->ch_tun.un_flags |
- ch->ch_pun.un_flags) &
- UN_CLOSING)) {
- /*
- * Our conditions to leave cleanly and happily:
- * 1) NONBLOCKING on the tty is set.
- * 2) CLOCAL is set.
- * 3) DCD (fake or real) is active.
- */
- if (file->f_flags & O_NONBLOCK)
- break;
- if (tty->flags & (1 << TTY_IO_ERROR)) {
- retval = -EIO;
- break;
- }
- if (ch->ch_flags & CH_CD)
- break;
- if (ch->ch_flags & CH_FCAR)
- break;
- } else {
- sleep_on_un_flags = 1;
- }
- /*
- * If there is a signal pending, the user probably
- * interrupted (ctrl-c) us.
- * Leave loop with error set.
- */
- if (signal_pending(current)) {
- retval = -ERESTARTSYS;
- break;
- }
- /*
- * Store the flags before we let go of channel lock
- */
- if (sleep_on_un_flags)
- old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
- else
- old_flags = ch->ch_flags;
- /*
- * Let go of channel lock before calling schedule.
- * Our poller will get any FEP events and wake us up when DCD
- * eventually goes active.
- */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- /*
- * Wait for something in the flags to change
- * from the current value.
- */
- if (sleep_on_un_flags)
- retval = wait_event_interruptible(un->un_flags_wait,
- (old_flags != (ch->ch_tun.un_flags |
- ch->ch_pun.un_flags)));
- else
- retval = wait_event_interruptible(ch->ch_flags_wait,
- (old_flags != ch->ch_flags));
- /*
- * We got woken up for some reason.
- * Before looping around, grab our channel lock.
- */
- spin_lock_irqsave(&ch->ch_lock, flags);
- }
- ch->ch_wopen--;
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return retval;
- }
- /*
- * dgnc_tty_hangup()
- *
- * Hangup the port. Like a close, but don't wait for output to drain.
- */
- static void dgnc_tty_hangup(struct tty_struct *tty)
- {
- struct un_t *un;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- /* flush the transmit queues */
- dgnc_tty_flush_buffer(tty);
- }
- /*
- * dgnc_tty_close()
- *
- */
- static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /*
- * Determine if this is the last close or not - and if we agree about
- * which type of close it is with the Line Discipline
- */
- if ((tty->count == 1) && (un->un_open_count != 1)) {
- /*
- * Uh, oh. tty->count is 1, which means that the tty
- * structure will be freed. un_open_count should always
- * be one in these conditions. If it's greater than
- * one, we've got real problems, since it means the
- * serial port won't be shutdown.
- */
- dev_dbg(tty->dev,
- "tty->count is 1, un open count is %d\n",
- un->un_open_count);
- un->un_open_count = 1;
- }
- if (un->un_open_count)
- un->un_open_count--;
- else
- dev_dbg(tty->dev,
- "bad serial port open count of %d\n",
- un->un_open_count);
- ch->ch_open_count--;
- if (ch->ch_open_count && un->un_open_count) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return;
- }
- /* OK, its the last close on the unit */
- un->un_flags |= UN_CLOSING;
- tty->closing = 1;
- /*
- * Only officially close channel if count is 0 and
- * DIGI_PRINTER bit is not set.
- */
- if ((ch->ch_open_count == 0) &&
- !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
- ch->ch_flags &= ~(CH_STOPI | CH_FORCED_STOPI);
- /*
- * turn off print device when closing print device.
- */
- if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
- dgnc_wmove(ch, ch->ch_digi.digi_offstr,
- (int)ch->ch_digi.digi_offlen);
- ch->ch_flags &= ~CH_PRON;
- }
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- /* wait for output to drain */
- /* This will also return if we take an interrupt */
- bd->bd_ops->drain(tty, 0);
- dgnc_tty_flush_buffer(tty);
- tty_ldisc_flush(tty);
- spin_lock_irqsave(&ch->ch_lock, flags);
- tty->closing = 0;
- /*
- * If we have HUPCL set, lower DTR and RTS
- */
- if (ch->ch_c_cflag & HUPCL) {
- /* Drop RTS/DTR */
- ch->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
- bd->bd_ops->assert_modem_signals(ch);
- /*
- * Go to sleep to ensure RTS/DTR
- * have been dropped for modems to see it.
- */
- if (ch->ch_close_delay) {
- spin_unlock_irqrestore(&ch->ch_lock,
- flags);
- dgnc_ms_sleep(ch->ch_close_delay);
- spin_lock_irqsave(&ch->ch_lock, flags);
- }
- }
- ch->ch_old_baud = 0;
- /* Turn off UART interrupts for this port */
- ch->ch_bd->bd_ops->uart_off(ch);
- } else {
- /*
- * turn off print device when closing print device.
- */
- if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
- dgnc_wmove(ch, ch->ch_digi.digi_offstr,
- (int)ch->ch_digi.digi_offlen);
- ch->ch_flags &= ~CH_PRON;
- }
- }
- un->un_tty = NULL;
- un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
- wake_up_interruptible(&ch->ch_flags_wait);
- wake_up_interruptible(&un->un_flags_wait);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- /*
- * dgnc_tty_chars_in_buffer()
- *
- * Return number of characters that have not been transmitted yet.
- *
- * This routine is used by the line discipline to determine if there
- * is data waiting to be transmitted/drained/flushed or not.
- */
- static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
- {
- struct channel_t *ch = NULL;
- struct un_t *un = NULL;
- ushort thead;
- ushort ttail;
- uint tmask;
- uint chars = 0;
- unsigned long flags;
- if (!tty)
- return 0;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return 0;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return 0;
- spin_lock_irqsave(&ch->ch_lock, flags);
- tmask = WQUEUEMASK;
- thead = ch->ch_w_head & tmask;
- ttail = ch->ch_w_tail & tmask;
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (ttail == thead) {
- chars = 0;
- } else {
- if (thead >= ttail)
- chars = thead - ttail;
- else
- chars = thead - ttail + WQUEUESIZE;
- }
- return chars;
- }
- /*
- * dgnc_maxcps_room
- *
- * Reduces bytes_available to the max number of characters
- * that can be sent currently given the maxcps value, and
- * returns the new bytes_available. This only affects printer
- * output.
- */
- static int dgnc_maxcps_room(struct tty_struct *tty, int bytes_available)
- {
- struct channel_t *ch = NULL;
- struct un_t *un = NULL;
- if (!tty)
- return bytes_available;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return bytes_available;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return bytes_available;
- /*
- * If its not the Transparent print device, return
- * the full data amount.
- */
- if (un->un_type != DGNC_PRINT)
- return bytes_available;
- if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
- int cps_limit = 0;
- unsigned long current_time = jiffies;
- unsigned long buffer_time = current_time +
- (HZ * ch->ch_digi.digi_bufsize) /
- ch->ch_digi.digi_maxcps;
- if (ch->ch_cpstime < current_time) {
- /* buffer is empty */
- ch->ch_cpstime = current_time; /* reset ch_cpstime */
- cps_limit = ch->ch_digi.digi_bufsize;
- } else if (ch->ch_cpstime < buffer_time) {
- /* still room in the buffer */
- cps_limit = ((buffer_time - ch->ch_cpstime) *
- ch->ch_digi.digi_maxcps) / HZ;
- } else {
- /* no room in the buffer */
- cps_limit = 0;
- }
- bytes_available = min(cps_limit, bytes_available);
- }
- return bytes_available;
- }
- /*
- * dgnc_tty_write_room()
- *
- * Return space available in Tx buffer
- */
- static int dgnc_tty_write_room(struct tty_struct *tty)
- {
- struct channel_t *ch = NULL;
- struct un_t *un = NULL;
- ushort head;
- ushort tail;
- ushort tmask;
- int ret = 0;
- unsigned long flags;
- if (!tty || !dgnc_TmpWriteBuf)
- return 0;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return 0;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return 0;
- spin_lock_irqsave(&ch->ch_lock, flags);
- tmask = WQUEUEMASK;
- head = (ch->ch_w_head) & tmask;
- tail = (ch->ch_w_tail) & tmask;
- ret = tail - head - 1;
- if (ret < 0)
- ret += WQUEUESIZE;
- /* Limit printer to maxcps */
- ret = dgnc_maxcps_room(tty, ret);
- /*
- * If we are printer device, leave space for
- * possibly both the on and off strings.
- */
- if (un->un_type == DGNC_PRINT) {
- if (!(ch->ch_flags & CH_PRON))
- ret -= ch->ch_digi.digi_onlen;
- ret -= ch->ch_digi.digi_offlen;
- } else {
- if (ch->ch_flags & CH_PRON)
- ret -= ch->ch_digi.digi_offlen;
- }
- if (ret < 0)
- ret = 0;
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return ret;
- }
- /*
- * dgnc_tty_put_char()
- *
- * Put a character into ch->ch_buf
- *
- * - used by the line discipline for OPOST processing
- */
- static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c)
- {
- /*
- * Simply call tty_write.
- */
- dgnc_tty_write(tty, &c, 1);
- return 1;
- }
- /*
- * dgnc_tty_write()
- *
- * Take data from the user or kernel and send it out to the FEP.
- * In here exists all the Transparent Print magic as well.
- */
- static int dgnc_tty_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
- {
- struct channel_t *ch = NULL;
- struct un_t *un = NULL;
- int bufcount = 0, n = 0;
- unsigned long flags;
- ushort head;
- ushort tail;
- ushort tmask;
- uint remain;
- if (!tty || !dgnc_TmpWriteBuf)
- return 0;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return 0;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return 0;
- if (!count)
- return 0;
- /*
- * Store original amount of characters passed in.
- * This helps to figure out if we should ask the FEP
- * to send us an event when it has more space available.
- */
- spin_lock_irqsave(&ch->ch_lock, flags);
- /* Get our space available for the channel from the board */
- tmask = WQUEUEMASK;
- head = (ch->ch_w_head) & tmask;
- tail = (ch->ch_w_tail) & tmask;
- bufcount = tail - head - 1;
- if (bufcount < 0)
- bufcount += WQUEUESIZE;
- /*
- * Limit printer output to maxcps overall, with bursts allowed
- * up to bufsize characters.
- */
- bufcount = dgnc_maxcps_room(tty, bufcount);
- /*
- * Take minimum of what the user wants to send, and the
- * space available in the FEP buffer.
- */
- count = min(count, bufcount);
- /*
- * Bail if no space left.
- */
- if (count <= 0)
- goto exit_retry;
- /*
- * Output the printer ON string, if we are in terminal mode, but
- * need to be in printer mode.
- */
- if ((un->un_type == DGNC_PRINT) && !(ch->ch_flags & CH_PRON)) {
- dgnc_wmove(ch, ch->ch_digi.digi_onstr,
- (int)ch->ch_digi.digi_onlen);
- head = (ch->ch_w_head) & tmask;
- ch->ch_flags |= CH_PRON;
- }
- /*
- * On the other hand, output the printer OFF string, if we are
- * currently in printer mode, but need to output to the terminal.
- */
- if ((un->un_type != DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
- dgnc_wmove(ch, ch->ch_digi.digi_offstr,
- (int)ch->ch_digi.digi_offlen);
- head = (ch->ch_w_head) & tmask;
- ch->ch_flags &= ~CH_PRON;
- }
- n = count;
- /*
- * If the write wraps over the top of the circular buffer,
- * move the portion up to the wrap point, and reset the
- * pointers to the bottom.
- */
- remain = WQUEUESIZE - head;
- if (n >= remain) {
- n -= remain;
- memcpy(ch->ch_wqueue + head, buf, remain);
- head = 0;
- buf += remain;
- }
- if (n > 0) {
- /*
- * Move rest of data.
- */
- remain = n;
- memcpy(ch->ch_wqueue + head, buf, remain);
- head += remain;
- }
- if (count) {
- head &= tmask;
- ch->ch_w_head = head;
- }
- /* Update printer buffer empty time. */
- if ((un->un_type == DGNC_PRINT) && (ch->ch_digi.digi_maxcps > 0)
- && (ch->ch_digi.digi_bufsize > 0)) {
- ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
- }
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (count) {
- /*
- * Channel lock is grabbed and then released
- * inside this routine.
- */
- ch->ch_bd->bd_ops->copy_data_from_queue_to_uart(ch);
- }
- return count;
- exit_retry:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- /*
- * Return modem signals to ld.
- */
- static int dgnc_tty_tiocmget(struct tty_struct *tty)
- {
- struct channel_t *ch;
- struct un_t *un;
- int result = -EIO;
- unsigned char mstat = 0;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return result;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return result;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return result;
- spin_lock_irqsave(&ch->ch_lock, flags);
- mstat = (ch->ch_mostat | ch->ch_mistat);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- result = 0;
- if (mstat & UART_MCR_DTR)
- result |= TIOCM_DTR;
- if (mstat & UART_MCR_RTS)
- result |= TIOCM_RTS;
- if (mstat & UART_MSR_CTS)
- result |= TIOCM_CTS;
- if (mstat & UART_MSR_DSR)
- result |= TIOCM_DSR;
- if (mstat & UART_MSR_RI)
- result |= TIOCM_RI;
- if (mstat & UART_MSR_DCD)
- result |= TIOCM_CD;
- return result;
- }
- /*
- * dgnc_tty_tiocmset()
- *
- * Set modem signals, called by ld.
- */
- static int dgnc_tty_tiocmset(struct tty_struct *tty,
- unsigned int set, unsigned int clear)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- int ret = -EIO;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return ret;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return ret;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return ret;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return ret;
- spin_lock_irqsave(&ch->ch_lock, flags);
- if (set & TIOCM_RTS)
- ch->ch_mostat |= UART_MCR_RTS;
- if (set & TIOCM_DTR)
- ch->ch_mostat |= UART_MCR_DTR;
- if (clear & TIOCM_RTS)
- ch->ch_mostat &= ~(UART_MCR_RTS);
- if (clear & TIOCM_DTR)
- ch->ch_mostat &= ~(UART_MCR_DTR);
- ch->ch_bd->bd_ops->assert_modem_signals(ch);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- /*
- * dgnc_tty_send_break()
- *
- * Send a Break, called by ld.
- */
- static int dgnc_tty_send_break(struct tty_struct *tty, int msec)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- int ret = -EIO;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return ret;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return ret;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return ret;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return ret;
- switch (msec) {
- case -1:
- msec = 0xFFFF;
- break;
- case 0:
- msec = 0;
- break;
- default:
- break;
- }
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_bd->bd_ops->send_break(ch, msec);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- /*
- * dgnc_tty_wait_until_sent()
- *
- * wait until data has been transmitted, called by ld.
- */
- static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- bd->bd_ops->drain(tty, 0);
- }
- /*
- * dgnc_send_xchar()
- *
- * send a high priority character, called by ld.
- */
- static void dgnc_tty_send_xchar(struct tty_struct *tty, char c)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- dev_dbg(tty->dev, "dgnc_tty_send_xchar start\n");
- spin_lock_irqsave(&ch->ch_lock, flags);
- bd->bd_ops->send_immediate_char(ch, c);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- dev_dbg(tty->dev, "dgnc_tty_send_xchar finish\n");
- }
- /*
- * Return modem signals to ld.
- */
- static inline int dgnc_get_mstat(struct channel_t *ch)
- {
- unsigned char mstat;
- int result = -EIO;
- unsigned long flags;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -ENXIO;
- spin_lock_irqsave(&ch->ch_lock, flags);
- mstat = (ch->ch_mostat | ch->ch_mistat);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- result = 0;
- if (mstat & UART_MCR_DTR)
- result |= TIOCM_DTR;
- if (mstat & UART_MCR_RTS)
- result |= TIOCM_RTS;
- if (mstat & UART_MSR_CTS)
- result |= TIOCM_CTS;
- if (mstat & UART_MSR_DSR)
- result |= TIOCM_DSR;
- if (mstat & UART_MSR_RI)
- result |= TIOCM_RI;
- if (mstat & UART_MSR_DCD)
- result |= TIOCM_CD;
- return result;
- }
- /*
- * Return modem signals to ld.
- */
- static int dgnc_get_modem_info(struct channel_t *ch,
- unsigned int __user *value)
- {
- int result;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -ENXIO;
- result = dgnc_get_mstat(ch);
- if (result < 0)
- return -ENXIO;
- return put_user(result, value);
- }
- /*
- * dgnc_set_modem_info()
- *
- * Set modem signals, called by ld.
- */
- static int dgnc_set_modem_info(struct tty_struct *tty,
- unsigned int command,
- unsigned int __user *value)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- int ret = -ENXIO;
- unsigned int arg = 0;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return ret;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return ret;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return ret;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return ret;
- ret = get_user(arg, value);
- if (ret)
- return ret;
- switch (command) {
- case TIOCMBIS:
- if (arg & TIOCM_RTS)
- ch->ch_mostat |= UART_MCR_RTS;
- if (arg & TIOCM_DTR)
- ch->ch_mostat |= UART_MCR_DTR;
- break;
- case TIOCMBIC:
- if (arg & TIOCM_RTS)
- ch->ch_mostat &= ~(UART_MCR_RTS);
- if (arg & TIOCM_DTR)
- ch->ch_mostat &= ~(UART_MCR_DTR);
- break;
- case TIOCMSET:
- if (arg & TIOCM_RTS)
- ch->ch_mostat |= UART_MCR_RTS;
- else
- ch->ch_mostat &= ~(UART_MCR_RTS);
- if (arg & TIOCM_DTR)
- ch->ch_mostat |= UART_MCR_DTR;
- else
- ch->ch_mostat &= ~(UART_MCR_DTR);
- break;
- default:
- return -EINVAL;
- }
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_bd->bd_ops->assert_modem_signals(ch);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- /*
- * dgnc_tty_digigeta()
- *
- * Ioctl to get the information for ditty.
- *
- *
- *
- */
- static int dgnc_tty_digigeta(struct tty_struct *tty,
- struct digi_t __user *retinfo)
- {
- struct channel_t *ch;
- struct un_t *un;
- struct digi_t tmp;
- unsigned long flags;
- if (!retinfo)
- return -EFAULT;
- if (!tty || tty->magic != TTY_MAGIC)
- return -EFAULT;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return -EFAULT;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -EFAULT;
- memset(&tmp, 0, sizeof(tmp));
- spin_lock_irqsave(&ch->ch_lock, flags);
- memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
- return -EFAULT;
- return 0;
- }
- /*
- * dgnc_tty_digiseta()
- *
- * Ioctl to set the information for ditty.
- *
- *
- *
- */
- static int dgnc_tty_digiseta(struct tty_struct *tty,
- struct digi_t __user *new_info)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- struct digi_t new_digi;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return -EFAULT;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return -EFAULT;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -EFAULT;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return -EFAULT;
- if (copy_from_user(&new_digi, new_info, sizeof(new_digi)))
- return -EFAULT;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /*
- * Handle transistions to and from RTS Toggle.
- */
- if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
- (new_digi.digi_flags & DIGI_RTS_TOGGLE))
- ch->ch_mostat &= ~(UART_MCR_RTS);
- if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
- !(new_digi.digi_flags & DIGI_RTS_TOGGLE))
- ch->ch_mostat |= (UART_MCR_RTS);
- /*
- * Handle transistions to and from DTR Toggle.
- */
- if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
- (new_digi.digi_flags & DIGI_DTR_TOGGLE))
- ch->ch_mostat &= ~(UART_MCR_DTR);
- if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
- !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
- ch->ch_mostat |= (UART_MCR_DTR);
- memcpy(&ch->ch_digi, &new_digi, sizeof(new_digi));
- if (ch->ch_digi.digi_maxcps < 1)
- ch->ch_digi.digi_maxcps = 1;
- if (ch->ch_digi.digi_maxcps > 10000)
- ch->ch_digi.digi_maxcps = 10000;
- if (ch->ch_digi.digi_bufsize < 10)
- ch->ch_digi.digi_bufsize = 10;
- if (ch->ch_digi.digi_maxchar < 1)
- ch->ch_digi.digi_maxchar = 1;
- if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
- ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
- if (ch->ch_digi.digi_onlen > DIGI_PLEN)
- ch->ch_digi.digi_onlen = DIGI_PLEN;
- if (ch->ch_digi.digi_offlen > DIGI_PLEN)
- ch->ch_digi.digi_offlen = DIGI_PLEN;
- ch->ch_bd->bd_ops->param(tty);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- /*
- * dgnc_set_termios()
- */
- static void dgnc_tty_set_termios(struct tty_struct *tty,
- struct ktermios *old_termios)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_c_cflag = tty->termios.c_cflag;
- ch->ch_c_iflag = tty->termios.c_iflag;
- ch->ch_c_oflag = tty->termios.c_oflag;
- ch->ch_c_lflag = tty->termios.c_lflag;
- ch->ch_startc = tty->termios.c_cc[VSTART];
- ch->ch_stopc = tty->termios.c_cc[VSTOP];
- ch->ch_bd->bd_ops->param(tty);
- dgnc_carrier(ch);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- static void dgnc_tty_throttle(struct tty_struct *tty)
- {
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_flags |= (CH_FORCED_STOPI);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- static void dgnc_tty_unthrottle(struct tty_struct *tty)
- {
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_flags &= ~(CH_FORCED_STOPI);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- static void dgnc_tty_start(struct tty_struct *tty)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_flags &= ~(CH_FORCED_STOP);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- static void dgnc_tty_stop(struct tty_struct *tty)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_flags |= (CH_FORCED_STOP);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- /*
- * dgnc_tty_flush_chars()
- *
- * Flush the cook buffer
- *
- * Note to self, and any other poor souls who venture here:
- *
- * flush in this case DOES NOT mean dispose of the data.
- * instead, it means "stop buffering and send it if you
- * haven't already." Just guess how I figured that out... SRW 2-Jun-98
- *
- * It is also always called in interrupt context - JAR 8-Sept-99
- */
- static void dgnc_tty_flush_chars(struct tty_struct *tty)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /* Do something maybe here */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- /*
- * dgnc_tty_flush_buffer()
- *
- * Flush Tx buffer (make in == out)
- */
- static void dgnc_tty_flush_buffer(struct tty_struct *tty)
- {
- struct channel_t *ch;
- struct un_t *un;
- unsigned long flags;
- if (!tty || tty->magic != TTY_MAGIC)
- return;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_flags &= ~CH_STOP;
- /* Flush our write queue */
- ch->ch_w_head = ch->ch_w_tail;
- /* Flush UARTs transmit FIFO */
- ch->ch_bd->bd_ops->flush_uart_write(ch);
- if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
- ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
- wake_up_interruptible(&ch->ch_tun.un_flags_wait);
- }
- if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
- ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
- wake_up_interruptible(&ch->ch_pun.un_flags_wait);
- }
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- }
- /*****************************************************************************
- *
- * The IOCTL function and all of its helpers
- *
- *****************************************************************************/
- /*
- * dgnc_tty_ioctl()
- *
- * The usual assortment of ioctl's
- */
- static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
- unsigned long arg)
- {
- struct dgnc_board *bd;
- struct channel_t *ch;
- struct un_t *un;
- int rc;
- unsigned long flags;
- void __user *uarg = (void __user *)arg;
- if (!tty || tty->magic != TTY_MAGIC)
- return -ENODEV;
- un = tty->driver_data;
- if (!un || un->magic != DGNC_UNIT_MAGIC)
- return -ENODEV;
- ch = un->un_ch;
- if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -ENODEV;
- bd = ch->ch_bd;
- if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return -ENODEV;
- spin_lock_irqsave(&ch->ch_lock, flags);
- if (un->un_open_count <= 0) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return -EIO;
- }
- switch (cmd) {
- /* Here are all the standard ioctl's that we MUST implement */
- case TCSBRK:
- /*
- * TCSBRK is SVID version: non-zero arg --> no break
- * this behaviour is exploited by tcdrain().
- *
- * According to POSIX.1 spec (7.2.2.1.2) breaks should be
- * between 0.25 and 0.5 seconds so we'll ask for something
- * in the middle: 0.375 seconds.
- */
- rc = tty_check_change(tty);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (rc)
- return rc;
- rc = ch->ch_bd->bd_ops->drain(tty, 0);
- if (rc)
- return -EINTR;
- spin_lock_irqsave(&ch->ch_lock, flags);
- if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
- ch->ch_bd->bd_ops->send_break(ch, 250);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- case TCSBRKP:
- /* support for POSIX tcsendbreak()
- * According to POSIX.1 spec (7.2.2.1.2) breaks should be
- * between 0.25 and 0.5 seconds so we'll ask for something
- * in the middle: 0.375 seconds.
- */
- rc = tty_check_change(tty);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (rc)
- return rc;
- rc = ch->ch_bd->bd_ops->drain(tty, 0);
- if (rc)
- return -EINTR;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_bd->bd_ops->send_break(ch, 250);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- case TIOCSBRK:
- rc = tty_check_change(tty);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (rc)
- return rc;
- rc = ch->ch_bd->bd_ops->drain(tty, 0);
- if (rc)
- return -EINTR;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_bd->bd_ops->send_break(ch, 250);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- case TIOCCBRK:
- /* Do Nothing */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- case TIOCGSOFTCAR:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = put_user(C_CLOCAL(tty) ? 1 : 0,
- (unsigned long __user *)arg);
- return rc;
- case TIOCSSOFTCAR:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = get_user(arg, (unsigned long __user *)arg);
- if (rc)
- return rc;
- spin_lock_irqsave(&ch->ch_lock, flags);
- tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
- (arg ? CLOCAL : 0));
- ch->ch_bd->bd_ops->param(tty);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- case TIOCMGET:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return dgnc_get_modem_info(ch, uarg);
- case TIOCMBIS:
- case TIOCMBIC:
- case TIOCMSET:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return dgnc_set_modem_info(tty, cmd, uarg);
- /*
- * Here are any additional ioctl's that we want to implement
- */
- case TCFLSH:
- /*
- * The linux tty driver doesn't have a flush
- * input routine for the driver, assuming all backed
- * up data is in the line disc. buffers. However,
- * we all know that's not the case. Here, we
- * act on the ioctl, but then lie and say we didn't
- * so the line discipline will process the flush
- * also.
- */
- rc = tty_check_change(tty);
- if (rc) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return rc;
- }
- if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
- ch->ch_r_head = ch->ch_r_tail;
- ch->ch_bd->bd_ops->flush_uart_read(ch);
- /* Force queue flow control to be released, if needed */
- dgnc_check_queue_flow_control(ch);
- }
- if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
- if (!(un->un_type == DGNC_PRINT)) {
- ch->ch_w_head = ch->ch_w_tail;
- ch->ch_bd->bd_ops->flush_uart_write(ch);
- if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
- ch->ch_tun.un_flags &=
- ~(UN_LOW|UN_EMPTY);
- wake_up_interruptible(&ch->ch_tun.un_flags_wait);
- }
- if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
- ch->ch_pun.un_flags &=
- ~(UN_LOW|UN_EMPTY);
- wake_up_interruptible(&ch->ch_pun.un_flags_wait);
- }
- }
- }
- /* pretend we didn't recognize this IOCTL */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return -ENOIOCTLCMD;
- case TCSETSF:
- case TCSETSW:
- /*
- * The linux tty driver doesn't have a flush
- * input routine for the driver, assuming all backed
- * up data is in the line disc. buffers. However,
- * we all know that's not the case. Here, we
- * act on the ioctl, but then lie and say we didn't
- * so the line discipline will process the flush
- * also.
- */
- if (cmd == TCSETSF) {
- /* flush rx */
- ch->ch_flags &= ~CH_STOP;
- ch->ch_r_head = ch->ch_r_tail;
- ch->ch_bd->bd_ops->flush_uart_read(ch);
- /* Force queue flow control to be released, if needed */
- dgnc_check_queue_flow_control(ch);
- }
- /* now wait for all the output to drain */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = ch->ch_bd->bd_ops->drain(tty, 0);
- if (rc)
- return -EINTR;
- /* pretend we didn't recognize this */
- return -ENOIOCTLCMD;
- case TCSETAW:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = ch->ch_bd->bd_ops->drain(tty, 0);
- if (rc)
- return -EINTR;
- /* pretend we didn't recognize this */
- return -ENOIOCTLCMD;
- case TCXONC:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- /* Make the ld do it */
- return -ENOIOCTLCMD;
- case DIGI_GETA:
- /* get information for ditty */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return dgnc_tty_digigeta(tty, uarg);
- case DIGI_SETAW:
- case DIGI_SETAF:
- /* set information for ditty */
- if (cmd == (DIGI_SETAW)) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = ch->ch_bd->bd_ops->drain(tty, 0);
- if (rc)
- return -EINTR;
- spin_lock_irqsave(&ch->ch_lock, flags);
- } else {
- tty_ldisc_flush(tty);
- }
- /* fall thru */
- case DIGI_SETA:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return dgnc_tty_digiseta(tty, uarg);
- case DIGI_LOOPBACK:
- {
- uint loopback = 0;
- /* Let go of locks when accessing user space,
- * could sleep
- */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = get_user(loopback, (unsigned int __user *)arg);
- if (rc)
- return rc;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /* Enable/disable internal loopback for this port */
- if (loopback)
- ch->ch_flags |= CH_LOOPBACK;
- else
- ch->ch_flags &= ~(CH_LOOPBACK);
- ch->ch_bd->bd_ops->param(tty);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- case DIGI_GETCUSTOMBAUD:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = put_user(ch->ch_custom_speed, (unsigned int __user *)arg);
- return rc;
- case DIGI_SETCUSTOMBAUD:
- {
- int new_rate;
- /* Let go of locks when accessing user space, could sleep */
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = get_user(new_rate, (int __user *)arg);
- if (rc)
- return rc;
- spin_lock_irqsave(&ch->ch_lock, flags);
- dgnc_set_custom_speed(ch, new_rate);
- ch->ch_bd->bd_ops->param(tty);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- /*
- * This ioctl allows insertion of a character into the front
- * of any pending data to be transmitted.
- *
- * This ioctl is to satify the "Send Character Immediate"
- * call that the RealPort protocol spec requires.
- */
- case DIGI_REALPORT_SENDIMMEDIATE:
- {
- unsigned char c;
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = get_user(c, (unsigned char __user *)arg);
- if (rc)
- return rc;
- spin_lock_irqsave(&ch->ch_lock, flags);
- ch->ch_bd->bd_ops->send_immediate_char(ch, c);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return 0;
- }
- /*
- * This ioctl returns all the current counts for the port.
- *
- * This ioctl is to satify the "Line Error Counters"
- * call that the RealPort protocol spec requires.
- */
- case DIGI_REALPORT_GETCOUNTERS:
- {
- struct digi_getcounter buf;
- buf.norun = ch->ch_err_overrun;
- buf.noflow = 0; /* The driver doesn't keep this stat */
- buf.nframe = ch->ch_err_frame;
- buf.nparity = ch->ch_err_parity;
- buf.nbreak = ch->ch_err_break;
- buf.rbytes = ch->ch_rxcount;
- buf.tbytes = ch->ch_txcount;
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (copy_to_user(uarg, &buf, sizeof(buf)))
- return -EFAULT;
- return 0;
- }
- /*
- * This ioctl returns all current events.
- *
- * This ioctl is to satify the "Event Reporting"
- * call that the RealPort protocol spec requires.
- */
- case DIGI_REALPORT_GETEVENTS:
- {
- unsigned int events = 0;
- /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
- if (ch->ch_flags & CH_BREAK_SENDING)
- events |= EV_TXB;
- if ((ch->ch_flags & CH_STOP) ||
- (ch->ch_flags & CH_FORCED_STOP))
- events |= (EV_OPU | EV_OPS);
- if ((ch->ch_flags & CH_STOPI) ||
- (ch->ch_flags & CH_FORCED_STOPI))
- events |= (EV_IPU | EV_IPS);
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- rc = put_user(events, (unsigned int __user *)arg);
- return rc;
- }
- /*
- * This ioctl returns TOUT and TIN counters based
- * upon the values passed in by the RealPort Server.
- * It also passes back whether the UART Transmitter is
- * empty as well.
- */
- case DIGI_REALPORT_GETBUFFERS:
- {
- struct digi_getbuffer buf;
- int tdist;
- int count;
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- /*
- * Get data from user first.
- */
- if (copy_from_user(&buf, uarg, sizeof(buf)))
- return -EFAULT;
- spin_lock_irqsave(&ch->ch_lock, flags);
- /*
- * Figure out how much data is in our RX and TX queues.
- */
- buf.rxbuf = (ch->ch_r_head - ch->ch_r_tail) & RQUEUEMASK;
- buf.txbuf = (ch->ch_w_head - ch->ch_w_tail) & WQUEUEMASK;
- /*
- * Is the UART empty? Add that value to whats in our TX queue.
- */
- count = buf.txbuf + ch->ch_bd->bd_ops->get_uart_bytes_left(ch);
- /*
- * Figure out how much data the RealPort Server believes should
- * be in our TX queue.
- */
- tdist = (buf.tIn - buf.tOut) & 0xffff;
- /*
- * If we have more data than the RealPort Server believes we
- * should have, reduce our count to its amount.
- *
- * This count difference CAN happen because the Linux LD can
- * insert more characters into our queue for OPOST processing
- * that the RealPort Server doesn't know about.
- */
- if (buf.txbuf > tdist)
- buf.txbuf = tdist;
- /*
- * Report whether our queue and UART TX are completely empty.
- */
- if (count)
- buf.txdone = 0;
- else
- buf.txdone = 1;
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (copy_to_user(uarg, &buf, sizeof(buf)))
- return -EFAULT;
- return 0;
- }
- default:
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return -ENOIOCTLCMD;
- }
- }
|