8253xutl.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:34k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* -*- linux-c -*- */
  2. /* $Id: 8253xutl.c,v 1.3 2002/02/10 22:17:26 martillo Exp $
  3.  * 8253xutl.c: SYNC TTY Driver for the SIEMENS SAB8253X DUSCC.
  4.  *
  5.  * Implementation, modifications and extensions
  6.  * Copyright (C) 2001 By Joachim Martillo, Telford Tools, Inc.
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License
  10.  * as published by the Free Software Foundation; either version
  11.  * 2 of the License, or (at your option) any later version.
  12.  */
  13. /* Standard in kernel modules */
  14. #define DEFINE_VARIABLE
  15. #include <linux/module.h>   /* Specifically, a module */
  16. #include <asm/io.h>
  17. #include <linux/timer.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/tty.h>
  20. #include <linux/tty_flip.h>
  21. #include <linux/mm.h>
  22. #include <linux/version.h>
  23. #include <asm/uaccess.h>
  24. #include "8253xctl.h"
  25. #include "8253x.h"
  26. #include <linux/pci.h>
  27. #include <linux/fs.h>
  28. #include "sp502.h"
  29. #ifdef MODULE
  30. #undef XCONFIG_SERIAL_CONSOLE
  31. #endif
  32. void sab8253x_start_txS(struct sab_port *port)
  33. {
  34. unsigned long flags;
  35. register int count;
  36. register int total;
  37. register int offset;
  38. char temporary[32];
  39. register unsigned int slopspace;
  40. register int sendsize;
  41. unsigned int totaltransmit;
  42. unsigned fifospace;
  43. unsigned loadedcount;
  44. struct tty_struct *tty = port->tty; /* a little gross tty flags whether
  45.        invoked from a tty or the network */
  46. fifospace = port->xmit_fifo_size; /* This code can handle fragmented frames
  47.      although currently none are generated*/
  48. loadedcount = 0;
  49. if(port->sabnext2.transmit == NULL)
  50. {
  51. return;
  52. }
  53. save_flags(flags); 
  54. cli();
  55. if(count = port->sabnext2.transmit->Count, (count & OWNER) == OWN_SAB)
  56. {
  57. count &= ~OWN_SAB; /* OWN_SAB is really 0 but cannot guarantee in the future */
  58. if(port->sabnext2.transmit->HostVaddr)
  59. {
  60. total = (port->sabnext2.transmit->HostVaddr->tail - 
  61.  port->sabnext2.transmit->HostVaddr->data); /* packet size */
  62. }
  63. else
  64. {
  65. total = 0; /* the data is only the crc/trailer */
  66. }
  67. if(tty && (tty->stopped || tty->hw_stopped) && (count == total))
  68. { /* works for frame that only has a trailer (crc) */
  69. port->interrupt_mask1 |= SAB82532_IMR1_XPR;
  70. WRITEB(port, imr1, port->interrupt_mask1);
  71. restore_flags(flags); /* can't send */
  72. return;
  73. }
  74. offset = (total - count); /* offset to data still to send */
  75. port->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS);
  76. WRITEB(port, imr1, port->interrupt_mask1);
  77. port->all_sent = 0;
  78. if(READB(port,star) & SAB82532_STAR_XFW)
  79. {
  80. if(count <= fifospace)
  81. {
  82. port->xmit_cnt = count;
  83. slopspace = 0;
  84. sendsize = 0;
  85. if(port->sabnext2.transmit->sendcrc) 
  86. /* obviously should not happen for async but might use for
  87.    priority transmission */
  88. {
  89. slopspace = fifospace - count;
  90. }
  91. if(slopspace)
  92. {
  93. if(count)
  94. {
  95. memcpy(temporary, &port->sabnext2.transmit->HostVaddr->data[offset], 
  96.        count);
  97. }
  98. sendsize = MIN(slopspace, (4 - port->sabnext2.transmit->crcindex)); 
  99. /* how many bytes to send */
  100. memcpy(&temporary[count], 
  101.        &((unsigned char*)(&port->sabnext2.transmit->crc))
  102.        [port->sabnext2.transmit->crcindex], 
  103.        sendsize);
  104. port->sabnext2.transmit->crcindex += sendsize;
  105. if(port->sabnext2.transmit->crcindex >= 4)
  106. {
  107. port->sabnext2.transmit->sendcrc = 0;
  108. }
  109. port->xmit_buf = temporary;
  110. }
  111. else
  112. {
  113. port->xmit_buf = /* set up wrifefifo variables */
  114. &port->sabnext2.transmit->HostVaddr->data[offset];
  115. }
  116. port->xmit_cnt += sendsize;
  117. count = 0;
  118. }
  119. else
  120. {
  121. count -= fifospace;
  122. port->xmit_cnt = fifospace;
  123. port->xmit_buf = /* set up wrifefifo variables */
  124. &port->sabnext2.transmit->HostVaddr->data[offset];
  125. }
  126. port->xmit_tail= 0;
  127. loadedcount = port->xmit_cnt;
  128. (*port->writefifo)(port);
  129. totaltransmit = Sab8253xCountTransmitDescriptors(port);
  130. if(tty && (totaltransmit < (sab8253xs_listsize/2))) /* only makes sense on a TTY */
  131. {
  132. sab8253x_sched_event(port, SAB8253X_EVENT_WRITE_WAKEUP);
  133. }
  134. if((sab8253xt_listsize - totaltransmit) > (sab8253xt_listsize/2))
  135. {
  136. port->buffergreedy = 0;
  137. }
  138. else
  139. {
  140. port->buffergreedy = 1;
  141. }
  142. port->xmit_buf = NULL; /* this var is used to indicate whether to call kfree */
  143. /* fifospace -= loadedcount;*/
  144. /* Here to make mods to handle arbitrarily fragmented frames look to 8253xtty.c for help */
  145. if ((count <= 0) && (port->sabnext2.transmit->sendcrc == 0))
  146. {
  147. port->sabnext2.transmit->Count = OWN_DRIVER;
  148. if(!tty)
  149. { /* called by network driver */
  150. ++(port->Counters.transmitpacket);
  151. }
  152. #ifdef FREEININTERRUPT /* treat this routine as if taking place in interrupt */
  153. if(port->sabnext2.transmit->HostVaddr)
  154. {
  155. skb_unlink(port->sabnext2.transmit->HostVaddr);
  156. dev_kfree_skb_any(port->sabnext2.transmit->HostVaddr);
  157. port->sabnext2.transmit->HostVaddr = 0; /* no skb */
  158. }
  159. port->sabnext2.transmit->crcindex = 0; /* no single byte */
  160. #endif
  161. sab8253x_cec_wait(port);
  162. WRITEB(port, cmdr, SAB82532_CMDR_XME|SAB82532_CMDR_XTF); /* Terminate the frame */
  163. port->sabnext2.transmit = port->sabnext2.transmit->VNext;
  164. if(!tty && port->tx_full) /* invoked from the network driver */
  165. {
  166. port->tx_full = 0; /* there is a free slot */
  167. switch(port->open_type)
  168. {
  169. case OPEN_SYNC_NET:
  170. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
  171. port->dev->start = 1;
  172. port->dev->tbusy = 0; /* maybe need mark_bh here */
  173. #else
  174. netif_start_queue(port->dev);
  175. #endif
  176. break;
  177. case OPEN_SYNC_CHAR:
  178. wake_up_interruptible(&port->write_wait);
  179. break;
  180. default:
  181. break;
  182. }
  183. }
  184. if((port->sabnext2.transmit->Count & OWNER) == OWN_SAB)
  185. { /* new frame to send */
  186. port->interrupt_mask1 &= ~(SAB82532_IMR1_XPR);
  187. WRITEB(port, imr1, port->interrupt_mask1);
  188. }
  189. else
  190. {
  191. port->interrupt_mask1 |= SAB82532_IMR1_XPR;
  192. WRITEB(port, imr1, port->interrupt_mask1);
  193. if((port->open_type == OPEN_SYNC_CHAR) && port->async_queue)
  194. { /* if indication of transmission is needed by the */
  195. /* application on a per-frame basis kill_fasync */
  196. /* can provide it */
  197. kill_fasync(&port->async_queue, SIGIO, POLL_OUT);
  198. }
  199. }
  200. restore_flags(flags);
  201. return;
  202. }
  203. /* Issue a Transmit FIFO command. */
  204. sab8253x_cec_wait(port);
  205. WRITEB(port, cmdr, SAB82532_CMDR_XTF);
  206. port->sabnext2.transmit->Count = (count|OWN_SAB);
  207. }
  208. port->interrupt_mask1 &= ~(SAB82532_IMR1_XPR); /* more to send */
  209. WRITEB(port, imr1, port->interrupt_mask1);
  210. }
  211. else
  212. { /* nothing to send */
  213. port->interrupt_mask1 |= SAB82532_IMR1_XPR;
  214. WRITEB(port, imr1, port->interrupt_mask1);
  215. }
  216. restore_flags(flags);
  217. return;
  218. }
  219. void sab8253x_transmit_charsS(struct sab_port *port,
  220.       union sab8253x_irq_status *stat)
  221. {
  222. if (stat->sreg.isr1 & SAB82532_ISR1_ALLS) 
  223. {
  224. port->interrupt_mask1 |= SAB82532_IMR1_ALLS;
  225. WRITEB(port, imr1, port->interrupt_mask1);
  226. port->all_sent = 1;
  227. }
  228. sab8253x_start_txS(port);
  229. }
  230. /*
  231.  * This routine is called to set the UART divisor registers to match
  232.  * the specified baud rate for a serial port.
  233.  */
  234. /***************************************************************************
  235.  * sab_baudenh:      Function to compute the "enhanced" baudrate.
  236.  *                
  237.  *
  238.  *     Parameters   : 
  239.  *                  encbaud  2* the baudrate. We use the
  240.  *                           double value so as to support 134.5 (in only)
  241.  *                  clkspeed The board clock speed in Hz.
  242.  *                  bgr      Value of reg BGR for baudrate(output)
  243.  *                  ccr2     Value of reg // CCR2 for baudrate (output)
  244.  *                  ccr4     Value of reg CCR4 for baudrate (output)
  245.  *                  truebaud The actual baudrate achieved (output).
  246.  *
  247.  *
  248.  *     Return value : Return FALSE the parameters could not be computed, 
  249.  *
  250.  *     Prerequisite : The various ports must have been initialized
  251.  *
  252.  *     Remark       : Stolen from the Aurora ase driver.
  253.  *
  254.  *     Author       : fw
  255.  *
  256.  *     Revision     : Oct 9 2000, creation
  257.  ***************************************************************************/
  258. /*
  259.  * Macro to check to see if the high n bits of the given unsigned long
  260.  *  are zero.
  261.  */               
  262. #define HIZERO(x, n)        ( ((unsigned long) ((x) << (n)) >> (n)) == (x))
  263. /* form an n-bit bitmask */
  264. #define NBM(n)                  (~(((~(unsigned long) 0) >> (n)) << (n)))
  265. /* shift x by y bits to right, rounded */
  266. #define ROUND_SHIFT(x, y)       (((unsigned long) (x) + (NBM(y - 1) + 1)) >> (y))
  267. /* perform rounded division */
  268. #define ROUND_DIV(x, y) (((x) + ((y) >> 1)) / (y))
  269. #define ABSDIF(x, y)    ((x) > (y) ? ((x) - (y)) : ((y) - (x))) 
  270. static unsigned int
  271. sab8253x_baudenh(unsigned long encbaud, unsigned long clk_speed,
  272.  unsigned char *bgr, unsigned char *ccr2,
  273.  unsigned long *truebaudp)
  274. {
  275. register unsigned short  tmp;
  276. register unsigned char  ccr2tmp;
  277. unsigned long  power2, mant;
  278. unsigned int  fastclock;
  279. if (encbaud == 0) {
  280. return FALSE;
  281. }
  282. /*
  283.  * Keep dividing quotien by two until it is between the value of 1 and 64,
  284.  *  inclusive.
  285.  */
  286. fastclock = (clk_speed >= 10000000); /* >= 10 MHz */
  287. for (power2 = 0; power2 < 16; power2++) 
  288. {
  289. /* divisor = baud * 2^M * 16 */
  290. if (!HIZERO(encbaud, power2 + 3)) 
  291. {
  292. if (!HIZERO(encbaud, power2)) 
  293. { /* baud rate still too big? */
  294. mant = ROUND_DIV(ROUND_SHIFT(clk_speed, power2 + 3), encbaud);
  295. /* mant = (clk_speed / (8 * 2^M)) / (baud * 2) */
  296. /* = clk_speed / (baud * 16 * 2^M) */
  297. }
  298. else 
  299. {
  300. mant = ROUND_DIV(ROUND_SHIFT(clk_speed, 3), encbaud << power2);
  301. /* mant = (clk_speed / 8) / (baud * 2 * 2^M) */
  302. /* = clk_speed / (baud * 16 * 2^M) */
  303. }
  304. }
  305. else 
  306. {
  307. mant = ROUND_DIV(clk_speed, encbaud << (power2 + 3));
  308. /* mant = clk_speed / (baud * 2 * 8 * 2^M) */
  309. /*     = clk_speed / (baud * 16 * 2^M) */
  310. }
  311. /* mant = clk_speed / (baud * 2^M * 16) */
  312. if (mant < 2
  313.     || (mant <= 64 && (!fastclock || power2 != 0))) 
  314. {
  315. break;
  316. }
  317. }
  318. /*
  319.  * Did we not succeed?  (Baud rate is too small)
  320.  */
  321. if (mant > 64) 
  322. {
  323. return FALSE;
  324. }
  325. /*
  326.  * Now, calculate the true baud rate.
  327.  */
  328. if (mant < 1 || (mant == 1 && power2 == 0)) 
  329. {
  330. /* bgr and ccr2 should be initialized to 0 */
  331. *truebaudp = ROUND_SHIFT(clk_speed, 4);
  332. }
  333. else 
  334. {
  335. *truebaudp = ROUND_DIV(clk_speed, mant << (4 + power2));
  336. /* divisor is not zero because mant is [1, 64] */
  337. mant--; /* now [0, 63] */
  338. /*
  339.  * Encode the N and M values into the bgr and ccr2 registers.
  340.  */
  341. tmp = ((unsigned short) mant) | ((unsigned short) power2 << 6);
  342. ccr2tmp = SAB82532_CCR2_BDF;
  343. if ((tmp & 0x200) != 0) 
  344. {
  345. ccr2tmp |= SAB82532_CCR2_BR9;
  346. }
  347. if ((tmp & 0x100) != 0) 
  348. {
  349. ccr2tmp |= SAB82532_CCR2_BR8;
  350. }
  351. *ccr2 = ccr2tmp | (*ccr2 & ~(SAB82532_CCR2_BDF|SAB82532_CCR2_BR8|SAB82532_CCR2_BR9));
  352. *bgr = (unsigned char) tmp;
  353. }
  354. return TRUE;
  355. }
  356. /*
  357.  * Calculate the standard mode baud divisor using an integral algorithm.
  358.  */
  359. /***************************************************************************
  360.  * sab_baudstd:      Function to compute the "standard " baudrate.
  361.  *                
  362.  *
  363.  *     Parameters   : 
  364.  *                  encbaud  2* the baudrate. We use the
  365.  *                           double value so as to support 134.5 (in only)
  366.  *                  clkspeed The board clock speed in Hz.
  367.  *                  bgr      Value of reg BGR for baudrate(output)
  368.  *                  ccr2     Value of reg CCR2 for baudrate (output)
  369.  *                  ccr4     Value of reg CCR4 for baudrate (output)
  370.  *                  truebaud The actual baudrate achieved (output).
  371.  *
  372.  *
  373.  *     Return value : Return FALSE the parameters could not be computed, 
  374.  *
  375.  *     Prerequisite : The various ports must have been initialized
  376.  *
  377.  *     Remark       : Stolen from the Aurora ase driver.
  378.  *
  379.  *     Author       : fw
  380.  *
  381.  *     Revision     : Oct 9 2000, creation
  382.  ***************************************************************************/
  383. static unsigned int
  384. sab8253x_baudstd(unsigned long encbaud, unsigned long clk_speed,
  385.  unsigned char *bgr, unsigned char *ccr2,
  386.  unsigned long *truebaudp)
  387. {
  388.   register unsigned short  quot;
  389.   register unsigned char  ccr2tmp;
  390.   
  391.   if (encbaud == 0) 
  392.   {
  393.   return FALSE;
  394.   }
  395.   
  396.   /*
  397.    * This divisor algorithm is a little strange.  The
  398.    *  divisors are all multiples of 2, except for the
  399.    *  magic value of 1.
  400.    *
  401.    * What we do is do most of the algorithm for multiples
  402.    *  of 1, and then switch at the last minute to multiples
  403.    *  of 2.
  404.    */
  405.   
  406.   /*
  407.    * Will we lose any information by left shifting encbaud?
  408.    *  If so, then right shift clk_speed instead.
  409.    */
  410.   if (!HIZERO(encbaud, 3)) 
  411.   {
  412.   quot = (unsigned short) ROUND_DIV(ROUND_SHIFT(clk_speed, 3),
  413.     encbaud);
  414.   /* quot = (clk_speed / 8) / (baud * 2) = clk_speed / (16 * baud) */
  415.   }
  416.   else 
  417.   {
  418.   /* encbaud isn't a multiple of 2^29 (baud not mult. of 2^28) */
  419.   quot = (unsigned short) ROUND_DIV(clk_speed, encbaud << 3);
  420.   }
  421.   
  422.   /* quot = clk_speed / (baud * 16) */
  423.   if (quot < 2) 
  424.   {
  425.   /* bgr and ccr2 should be initialized to 0 */
  426.   *truebaudp = ROUND_SHIFT(clk_speed, 4);
  427.   return TRUE;
  428.   }
  429.   
  430.   /*
  431.    * Divide the quotient by two.
  432.    */
  433.   quot = ROUND_SHIFT(quot, 1);
  434.   
  435.   if (quot <= 0x400) 
  436.   {
  437.   /* quot = [1, 0x400]  -> (quot << 5) != 0 */
  438.   *truebaudp = ROUND_DIV(clk_speed, ((unsigned long) quot << 5));
  439.   quot--;
  440.   
  441.   ccr2tmp = SAB82532_CCR2_BDF;
  442.   if ((quot & 0x200) != 0) 
  443.   {
  444.   ccr2tmp |= SAB82532_CCR2_BR9;
  445.   }
  446.   if ((quot & 0x100) != 0) 
  447.   {
  448.   ccr2tmp |=SAB82532_CCR2_BR8;
  449.   }
  450.   
  451.   *ccr2 = ccr2tmp | (*ccr2 & ~(SAB82532_CCR2_BDF|SAB82532_CCR2_BR8|SAB82532_CCR2_BR9));
  452.   *bgr = (unsigned char) quot;
  453.   }
  454.   else 
  455.   { /* the baud rate is too small. */
  456.   return FALSE;
  457.   }
  458.   
  459.   return TRUE;
  460. }
  461. /***************************************************************************
  462.  * sab_baud:      Function to compute the best register value to achieve
  463.  *                a given baudrate.
  464.  *                
  465.  *
  466.  *     Parameters   : 
  467.  *                  port:    The port being used  (in only)
  468.  *                  encbaud: 2* the baudrate. We use the
  469.  *                           double value so as to support 134.5 (in only)
  470.  *                  bgr      Value of reg BGR for baudrate(output)
  471.  *                  ccr2     Value of reg CCR2 for baudrate (output)
  472.  *                  ccr4     Value of reg CCR4 for baudrate (output)
  473.  *                  truebaud The actual baudrate achieved (output).
  474.  *
  475.  *
  476.  *     Return value : Return TRUE if the vaudrate can be set, FALSE otherwise 
  477.  *
  478.  *     Prerequisite : The various ports must have been initialized
  479.  *
  480.  *     Remark       : Stolen from the Aurora ase driver.
  481.  *
  482.  *     Author       : fw
  483.  *
  484.  *     Revision     : Oct 9 2000, creation
  485.  ***************************************************************************/
  486. unsigned int 
  487. sab8253x_baud(sab_port_t *port, unsigned long encbaud,
  488.       unsigned char *bgr, unsigned char *ccr2,
  489.       unsigned char *ccr4, unsigned long *truebaudp)
  490. {
  491. unsigned char  bgr_std, bgr_enh, ccr2_std, ccr2_enh, ccr4_enh;
  492. unsigned int  ok_std, ok_enh;
  493. unsigned long  truebaud_std, truebaud_enh, truebaud,clkspeed;
  494. bgr_std = bgr_enh = 0;
  495. ccr2_std = ccr2_enh = 0;
  496. ccr4_enh = 0;
  497. /*
  498.  * the port/chip/board structure will tell us:
  499.  *  1) clock speed
  500.  *  2) chip revision (to figure out if the enhanced method is
  501.  *     available.
  502.  */
  503. clkspeed = port->chip->c_cim ? port->chip->c_cim->ci_clkspeed :  port->board->b_clkspeed;
  504. #ifdef NODEBUGGING
  505. printk("With clk speed %ld, baud rate = %ldn",clkspeed, encbaud);
  506. #endif
  507. ok_std = sab8253x_baudstd(encbaud, clkspeed, &bgr_std,
  508.   &ccr2_std, &truebaud_std);
  509. #ifdef NODEBUGGING
  510. printk("Std gives bgr = 0x%x, ccr2=0x%x for speed %ldn",bgr_std,ccr2_std,truebaud_std);
  511. #endif
  512. if(port->chip->c_revision >= SAB82532_VSTR_VN_3_2) 
  513. {
  514. ok_enh = sab8253x_baudenh(encbaud, clkspeed,
  515.   &bgr_enh, &ccr2_enh, &truebaud_enh);
  516. #ifdef NODEBUGGING
  517. printk("Enh gives bgr = 0x%x, ccr2=0x%x for speed %ldn",bgr_enh,ccr2_enh,truebaud_enh);
  518. #endif
  519. else 
  520. ok_enh = FALSE;
  521. /*
  522.  * Did both methods return values?
  523.  */
  524. if (ok_std && ok_enh) 
  525. {
  526. /*
  527.  * Find the closest of the two.
  528.  */
  529. if (ABSDIF((truebaud_enh<<1), encbaud) <
  530.     ABSDIF((truebaud_std<<1), encbaud)) 
  531. {
  532. ok_std = FALSE;
  533. }
  534. else 
  535. {
  536. ok_enh = FALSE;
  537. }
  538. }
  539. /*
  540.  * Now return the values.
  541.  */
  542. if (ok_std || ok_enh) 
  543. {
  544. truebaud = ok_std ? truebaud_std : truebaud_enh;
  545. /*
  546.  * If the true baud rate is off by more than 5%, then
  547.  *  we don't support it.
  548.  */
  549. if (ROUND_DIV(ABSDIF((truebaud<<1), encbaud), encbaud) != 0) 
  550. {
  551. /*
  552.  * We're not even in the right ballpark.  This
  553.  *  test is here to deal with overflow conditions.
  554.  */
  555. return FALSE;
  556. }
  557. else if (ROUND_DIV(ABSDIF((truebaud<<1), encbaud) * 100,
  558.    encbaud) >= 5) 
  559. {
  560. return FALSE;
  561. }
  562. *truebaudp = truebaud;
  563. if (ok_enh) 
  564. {
  565. *ccr4 |= SAB82532_CCR4_EBRG;
  566. *ccr2 = ccr2_enh;
  567. *bgr = bgr_enh;
  568. #ifdef DEBUGGING
  569. printk("Enhanced Baud at %ld, ccr4 = 0x%x, ccr2 = 9x%x, bgr = 0x%xn",
  570.        truebaud,*ccr4,*ccr2,*bgr);
  571. #endif
  572. else 
  573. {
  574. *ccr4 &= ~SAB82532_CCR4_EBRG;
  575. *ccr2 = ccr2_std;
  576. *bgr = bgr_std;
  577. #ifdef DEBUGGING
  578. printk("Standard Baud at %ld, ccr4 = 0x%x, ccr2 = 9x%x, bgr = 0x%xn",
  579.        truebaud,*ccr4,*ccr2,*bgr);
  580. #endif
  581. }
  582. return TRUE;
  583. }
  584. else 
  585. {
  586. return FALSE;
  587. }
  588. }
  589. int Sab8253xCountTransmit(SAB_PORT *port)
  590. {
  591. register RING_DESCRIPTOR *rd;
  592. register int total;
  593. register int count;
  594. unsigned long flags;
  595. RING_DESCRIPTOR *start;
  596. if(port->sabnext2.transmit == NULL)
  597. {
  598. return 0;
  599. }
  600. save_flags(flags);
  601. cli();
  602. rd = port->sabnext2.transmit;
  603. start = rd;
  604. total = 0;
  605. while(1)
  606. {
  607. count = rd->Count;
  608. if((count & OWNER) == OWN_DRIVER)
  609. {
  610. break;
  611. }
  612. total += (count & ~OWNER);
  613. if(rd->sendcrc)
  614. {
  615. total += (4 - rd->crcindex);
  616. }
  617. rd = rd->VNext;
  618. if(rd == start)
  619. {
  620. break;
  621. }
  622. }
  623. restore_flags(flags);
  624. return total;
  625. }
  626. int Sab8253xCountTransmitDescriptors(SAB_PORT *port)
  627. {
  628. register RING_DESCRIPTOR *rd;
  629. register int total;
  630. register int count;
  631. unsigned long flags;
  632. RING_DESCRIPTOR *start;
  633. if(port->sabnext2.transmit == NULL)
  634. {
  635. return 0;
  636. }
  637. save_flags(flags);
  638. cli();
  639. rd = port->sabnext2.transmit;
  640. start = rd;
  641. total = 0;
  642. while(1)
  643. {
  644. count = rd->Count;
  645. if((count & OWNER) == OWN_DRIVER)
  646. {
  647. break;
  648. }
  649. ++total;
  650. rd = rd->VNext;
  651. if(rd == start)
  652. {
  653. break;
  654. }
  655. }
  656. restore_flags(flags);
  657. return total;
  658. }
  659. int getccr0configS(struct sab_port *port)
  660. {
  661. return port->ccontrol.ccr0;
  662. }
  663. int getccr1configS(struct sab_port *port)
  664. {
  665. return port->ccontrol.ccr1;
  666. }
  667. int getccr2configS(struct sab_port *port)
  668. {
  669. return port->ccontrol.ccr2;
  670. }
  671. int getccr3configS(struct sab_port *port)
  672. {
  673. return port->ccontrol.ccr3;
  674. }
  675. int getccr4configS(struct sab_port *port)
  676. {
  677. return port->ccontrol.ccr4;
  678. }
  679. int getrlcrconfigS(struct sab_port *port)
  680. {
  681. return port->ccontrol.rlcr;
  682. }
  683. int getmodeS(struct sab_port *port)
  684. {
  685. return port->ccontrol.mode;
  686. }
  687. void sab8253x_init_lineS(struct sab_port *port)
  688. {
  689. unsigned char stat;
  690. if(port->chip->c_cim)
  691. {
  692. if(port->chip->c_cim->ci_type == CIM_SP502)
  693. {
  694. aura_sp502_program(port, SP502_OFF_MODE);
  695. }
  696. }
  697. /*
  698.  * Wait for any commands or immediate characters
  699.  */
  700. sab8253x_cec_wait(port);
  701. #if 0
  702. sab8253x_tec_wait(port); /* I have to think about this one
  703.  * should I assume the line was
  704.  * previously in async mode*/
  705. #endif
  706. /*
  707.  * Clear the FIFO buffers.
  708.  */
  709. WRITEB(port, cmdr, SAB82532_CMDR_RHR);
  710. sab8253x_cec_wait(port);
  711. WRITEB(port,cmdr,SAB82532_CMDR_XRES);
  712. /*
  713.  * Clear the interrupt registers.
  714.  */
  715. stat = READB(port, isr0); /* acks ints */
  716. stat = READB(port, isr1);
  717. /*
  718.  * Now, initialize the UART 
  719.  */
  720. WRITEB(port, ccr0, 0);   /* power-down */
  721. WRITEB(port, ccr0, getccr0configS(port));
  722. WRITEB(port, ccr1, getccr1configS(port));
  723. WRITEB(port, ccr2, getccr2configS(port));
  724. WRITEB(port, ccr3, getccr3configS(port));
  725. WRITEB(port, ccr4, getccr4configS(port)); /* 32 byte receive fifo */
  726. WRITEB(port, mode, getmodeS(port));
  727. WRITEB(port, tic /* really rlcr */, getrlcrconfigS(port));
  728. /* power-up */
  729. switch(port->ccontrol.ccr4 & SAB82532_CCR4_RF02)
  730. {
  731. case SAB82532_CCR4_RF32:
  732. port->recv_fifo_size = 32;
  733. break;
  734. case SAB82532_CCR4_RF16:
  735. port->recv_fifo_size = 16;
  736. break;
  737. case SAB82532_CCR4_RF04:
  738. port->recv_fifo_size = 4;
  739. break;
  740. case SAB82532_CCR4_RF02:
  741. port->recv_fifo_size = 2;
  742. break;
  743. default:
  744. port->recv_fifo_size = 32;
  745. port->ccontrol.ccr4 &= ~SAB82532_CCR4_RF02;
  746. break;
  747. }
  748. if(port->ccontrol.ccr2 & SAB82532_CCR2_TOE)
  749. {
  750. RAISE(port, txclkdir);
  751. }
  752. else
  753. {
  754. LOWER(port, txclkdir);
  755. }
  756. SET_REG_BIT(port,ccr0,SAB82532_CCR0_PU);
  757. if(port->chip->c_cim)
  758. {
  759. if(port->chip->c_cim->ci_type == CIM_SP502)
  760. {
  761. aura_sp502_program(port, port->sigmode);
  762. }
  763. }
  764. }
  765. /* frees up all skbuffs currently */
  766. /* held by driver */
  767. void Sab8253xFreeAllFreeListSKBUFFS(SAB_PORT* priv) /* empty the skbuffer list */
  768. /* either on failed open */
  769. /* or on close*/
  770. {
  771. struct sk_buff* skb;
  772. if(priv->sab8253xbuflist == NULL)
  773. {
  774. return;
  775. }
  776. DEBUGPRINT((KERN_ALERT "sab8253x: freeing %i skbuffs.n", 
  777.     skb_queue_len(priv->sab8253xbuflist)));
  778. while(skb_queue_len(priv->sab8253xbuflist) > 0)
  779. {
  780. skb = skb_dequeue(priv->sab8253xbuflist);
  781. dev_kfree_skb_any(skb);
  782. }
  783. kfree(priv->sab8253xbuflist);
  784. priv->sab8253xbuflist = NULL;
  785. }
  786. int Sab8253xSetUpLists(SAB_PORT *priv)
  787. {
  788. if(priv->sab8253xbuflist)
  789. {
  790. if(priv->sab8253xc_rcvbuflist)
  791. {
  792. return 0;
  793. }
  794. else
  795. {
  796. return -1;
  797. }
  798. return 0;
  799. }
  800. else if(priv->sab8253xc_rcvbuflist)
  801. {
  802. return -1;
  803. }
  804. priv->sab8253xbuflist = (struct sk_buff_head*) kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL);
  805. if(priv->sab8253xbuflist == NULL)
  806. {
  807. return -1;
  808. }
  809. priv->sab8253xc_rcvbuflist = (struct sk_buff_head*) kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL);  
  810. if(priv->sab8253xc_rcvbuflist == NULL)
  811. {
  812. kfree(priv->sab8253xbuflist);
  813. return -1;
  814. }
  815. skb_queue_head_init(priv->sab8253xbuflist);
  816. skb_queue_head_init(priv->sab8253xc_rcvbuflist);
  817. return 0;
  818. }
  819. /* sets up transmit ring and one receive sk_buff */
  820. /* set up transmit and receive
  821.    sk_buff control structures */
  822. int Sab8253xInitDescriptors2(SAB_PORT *priv, int listsize, int rbufsize)
  823. {
  824. RING_DESCRIPTOR *desc;
  825. RING_DESCRIPTOR *xdesc;
  826. if(priv->dcontrol2.transmit != NULL)
  827. {
  828. if(priv->dcontrol2.receive != NULL)
  829. {
  830. return 0;
  831. }
  832. return -1;
  833. }
  834. else if(priv->dcontrol2.receive != NULL)
  835. {
  836. return -1;
  837. }
  838. priv->dcontrol2.transmit = (RING_DESCRIPTOR*) 
  839. kmalloc(sizeof(RING_DESCRIPTOR) * listsize, GFP_KERNEL);
  840. /* dcontrol2 is an historical
  841.    artifact from when the code
  842.    talked to an intelligent controller */
  843. if(priv->dcontrol2.transmit == NULL)
  844. {
  845. return -1;
  846. }
  847. priv->dcontrol2.receive = (RING_DESCRIPTOR*)
  848. kmalloc(sizeof(RING_DESCRIPTOR), GFP_KERNEL); /* only one receive sk_buffer */
  849. if(priv->dcontrol2.receive == NULL)
  850. {
  851. kfree(priv->dcontrol2.transmit);
  852. priv->dcontrol2.transmit = NULL;
  853. return -1;
  854. }
  855. for(xdesc = priv->dcontrol2.transmit; 
  856.     xdesc < &priv->dcontrol2.transmit[listsize - 1];
  857.     xdesc = &xdesc[1]) /* set up transmit descriptors */
  858. {
  859. xdesc->HostVaddr = NULL;
  860. xdesc->VNext = &xdesc[1];
  861. xdesc->Count = 0 | OWN_DRIVER;
  862. xdesc->crc = 0;
  863. xdesc->sendcrc = 0;
  864. xdesc->crcindex = 0;
  865. }
  866. xdesc->HostVaddr = NULL;
  867. xdesc->VNext = priv->dcontrol2.transmit; /* circular list */
  868. xdesc->Count = 0 | OWN_DRIVER;
  869. xdesc->crc = 0;
  870. xdesc->sendcrc = 0;
  871. xdesc->crcindex = 0;
  872. desc = priv->dcontrol2.receive; /* only need one descriptor for receive */
  873. desc->HostVaddr = NULL;
  874. desc->VNext = &desc[0];
  875. desc = priv->dcontrol2.receive;
  876. desc->HostVaddr = dev_alloc_skb(rbufsize);
  877. if(desc->HostVaddr == NULL)
  878. {
  879. printk(KERN_ALERT "Unable to allocate skb_buffers (rx 0).n");
  880. printk(KERN_ALERT "Driver initialization failed.n");
  881. kfree(priv->dcontrol2.transmit);
  882. kfree(priv->dcontrol2.receive);
  883. priv->dcontrol2.transmit = NULL; /* get rid of descriptor ring */
  884. priv->dcontrol2.receive = NULL; /* get rid of descriptor */
  885. /* probably should do some deallocation of sk_buffs*/
  886. /* but will take place in the open */
  887. return -1;
  888. }
  889. skb_queue_head(priv->sab8253xbuflist, (struct sk_buff*) desc->HostVaddr);
  890. desc->Count = rbufsize|OWN_SAB; /* belongs to int handler */
  891. desc->crc = 0;
  892. desc->sendcrc = 0;
  893. desc->crcindex = 0;
  894. /* setup the various pointers */
  895. priv->active2 = priv->dcontrol2; /* insert new skbuff */
  896. priv->sabnext2 = priv->dcontrol2; /* transmit from here */
  897. return 0;
  898. }
  899. /* loads program, waits for PPC */
  900. /* and completes initialization*/
  901. void Sab8253xCleanUpTransceiveN(SAB_PORT* priv)
  902. {
  903. Sab8253xFreeAllFreeListSKBUFFS(priv);
  904. Sab8253xFreeAllReceiveListSKBUFFS(priv);
  905. /* these are also cleaned up in the module cleanup routine */
  906. /* should probably only be done here */
  907. if(priv->dcontrol2.receive)
  908. {
  909. kfree(priv->dcontrol2.receive);
  910. priv->dcontrol2.receive = NULL;
  911. }
  912. if(priv->dcontrol2.transmit)
  913. {
  914. kfree(priv->dcontrol2.transmit);
  915. priv->dcontrol2.transmit = NULL;
  916. }
  917. priv->active2 = priv->dcontrol2;
  918. priv->sabnext2 = priv->dcontrol2; 
  919. }
  920. void Sab8253xFreeAllReceiveListSKBUFFS(SAB_PORT* priv) /* empty the skbuffer list */
  921. /* either on failed open */
  922. /* or on close*/
  923. {
  924. struct sk_buff* skb;
  925. if(priv->sab8253xc_rcvbuflist == NULL)
  926. {
  927. return;
  928. }
  929. DEBUGPRINT((KERN_ALERT "sab8253x: freeing %i skbuffs.n", 
  930.     skb_queue_len(priv->sab8253xc_rcvbuflist)));
  931. while(skb_queue_len(priv->sab8253xc_rcvbuflist) > 0)
  932. {
  933. skb = skb_dequeue(priv->sab8253xc_rcvbuflist);
  934. dev_kfree_skb_any(skb);
  935. }
  936. kfree(priv->sab8253xc_rcvbuflist);
  937. priv->sab8253xc_rcvbuflist = NULL;
  938. }
  939. /*
  940.  * This routine is called to set the UART divisor registers to match
  941.  * the specified baud rate for a serial port.
  942.  */
  943. void sab8253x_change_speedN(struct sab_port *port)
  944. {
  945. unsigned long flags;
  946. unsigned char ccr2=0, ccr4=0, ebrg=0;
  947. int bits = 8;
  948. #ifdef DEBUGGING
  949. printk("Change speed!  ");
  950. #endif
  951. if(!sab8253x_baud(port, (port->baud)*2, &ebrg, &ccr2, &ccr4, &(port->baud))) 
  952. {
  953. printk("Aurora Warning. baudrate %ld could not be set! Using 115200", port->baud);
  954. port->baud = 115200;
  955. sab8253x_baud(port, (port->baud*2), &ebrg, &ccr2, &ccr4, &(port->baud));
  956. }
  957. if (port->baud)
  958. {
  959. port->timeout = (port->xmit_fifo_size * HZ * bits) / port->baud;
  960. port->cec_timeout = port->tec_timeout >> 2;
  961. }
  962. else
  963. {
  964. port->timeout = 0;
  965. port->cec_timeout = SAB8253X_MAX_CEC_DELAY;
  966. }
  967. port->timeout += HZ / 50; /* Add .02 seconds of slop */
  968. save_flags(flags); 
  969. cli();
  970. sab8253x_cec_wait(port);
  971. WRITEB(port, bgr, ebrg);
  972. WRITEB(port, ccr2, READB(port, ccr2) & ~(0xc0)); /* clear out current baud rage */
  973. WRITEB(port, ccr2, READB(port, ccr2) | ccr2);
  974. WRITEB(port, ccr4, (READB(port,ccr4) & ~SAB82532_CCR4_EBRG) | ccr4);
  975. if (port->flags & FLAG8253X_CTS_FLOW) 
  976. {
  977. WRITEB(port, mode, READB(port,mode) & ~(SAB82532_MODE_RTS));
  978. port->interrupt_mask1 &= ~(SAB82532_IMR1_CSC);
  979. WRITEB(port, imr1, port->interrupt_mask1);
  980. else 
  981. {
  982. WRITEB(port, mode, READB(port,mode) | SAB82532_MODE_RTS);
  983. port->interrupt_mask1 |= SAB82532_IMR1_CSC;
  984. WRITEB(port, imr1, port->interrupt_mask1);
  985. }
  986. WRITEB(port, mode, READB(port, mode) | SAB82532_MODE_RAC);
  987. restore_flags(flags);
  988. }
  989. void sab8253x_shutdownN(struct sab_port *port)
  990. {
  991. unsigned long flags;
  992. if (!(port->flags & FLAG8253X_INITIALIZED))
  993. {
  994. return;
  995. }
  996. save_flags(flags); cli(); /* Disable interrupts */
  997. /*
  998.  * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
  999.  * here so the queue might never be waken up
  1000.  */
  1001. wake_up_interruptible(&port->delta_msr_wait);
  1002. /* Disable Interrupts */
  1003. port->interrupt_mask0 = 0xff;
  1004. WRITEB(port, imr0, port->interrupt_mask0);
  1005. port->interrupt_mask1 = 0xff;
  1006. WRITEB(port, imr1, port->interrupt_mask1);
  1007. LOWER(port,rts);
  1008. LOWER(port,dtr);
  1009. /* Disable Receiver */
  1010. CLEAR_REG_BIT(port,mode,SAB82532_MODE_RAC);
  1011. /* Power Down */
  1012. CLEAR_REG_BIT(port,ccr0,SAB82532_CCR0_PU);
  1013. port->flags &= ~FLAG8253X_INITIALIZED;
  1014. restore_flags(flags);
  1015. }
  1016. int sab8253x_block_til_ready(struct tty_struct *tty, struct file * filp,
  1017.      struct sab_port *port)
  1018. {
  1019. DECLARE_WAITQUEUE(wait, current);
  1020. int retval;
  1021. int do_clocal = 0;
  1022. unsigned long flags;
  1023. /*
  1024.  * If the device is in the middle of being closed, then block
  1025.  * until it's done, and then try again.
  1026.  */
  1027. if (tty_hung_up_p(filp) ||
  1028.     (port->flags & FLAG8253X_CLOSING)) 
  1029. {
  1030. if (port->flags & FLAG8253X_CLOSING)
  1031. {
  1032. interruptible_sleep_on(&port->close_wait); /* finish up previous close */
  1033. }
  1034. #ifdef SERIAL_DO_RESTART
  1035. if (port->flags & FLAG8253X_HUP_NOTIFY)
  1036. {
  1037. return -EAGAIN;
  1038. }
  1039. else
  1040. {
  1041. return -ERESTARTSYS;
  1042. }
  1043. #else
  1044. return -EAGAIN;
  1045. #endif
  1046. }
  1047. /*
  1048.  * If this is a callout device, then just make sure the normal
  1049.  * device isn't being used.
  1050.  */
  1051. if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) 
  1052. {
  1053. if (port->flags & FLAG8253X_NORMAL_ACTIVE) 
  1054. {
  1055. return -EBUSY; /* async, sync tty or network driver active */
  1056. }
  1057. if ((port->flags & FLAG8253X_CALLOUT_ACTIVE) &&
  1058.     (port->flags & FLAG8253X_SESSION_LOCKOUT) &&
  1059.     (port->session != current->session))
  1060. {
  1061. return -EBUSY;
  1062. }
  1063. if ((port->flags & FLAG8253X_CALLOUT_ACTIVE) &&
  1064.     (port->flags & FLAG8253X_PGRP_LOCKOUT) &&
  1065.     (port->pgrp != current->pgrp))
  1066. {
  1067. return -EBUSY;
  1068. }
  1069. port->flags |= FLAG8253X_CALLOUT_ACTIVE; /* doing a callout */
  1070. return 0;
  1071. }
  1072. /* sort out async vs sync tty, not call out */
  1073. /*
  1074.  * If non-blocking mode is set, or the port is not enabled,
  1075.  * then make the check up front and then exit.
  1076.  */
  1077. if ((filp->f_flags & O_NONBLOCK) ||
  1078.     (tty->flags & (1 << TTY_IO_ERROR))) 
  1079. {
  1080. if (port->flags & FLAG8253X_CALLOUT_ACTIVE)
  1081. {
  1082. return -EBUSY;
  1083. }
  1084. port->flags |= FLAG8253X_NORMAL_ACTIVE;
  1085. return 0;
  1086. }
  1087. if (port->flags & FLAG8253X_CALLOUT_ACTIVE) 
  1088. {
  1089. if (port->normal_termios.c_cflag & CLOCAL)
  1090. {
  1091. do_clocal = 1;
  1092. }
  1093. else if (tty->termios->c_cflag & CLOCAL)
  1094. {
  1095. do_clocal = 1;
  1096. }
  1097. /*
  1098.  * Block waiting for the carrier detect and the line to become
  1099.  * free (i.e., not in use by the callout).  While we are in
  1100.  * this loop, port->count is dropped by one, so that
  1101.  * sab8253x_close() knows when to free things.  We restore it upon
  1102.  * exit, either normal or abnormal.
  1103.  */
  1104. /* The port decrement logic is probably */
  1105. /* broken -- hence if def'd out -- it does*/
  1106. retval = 0;
  1107. add_wait_queue(&port->open_wait, &wait); /* starts the wait but does not block here */
  1108. port->blocked_open++;
  1109. while (1) 
  1110. {
  1111. save_flags(flags);
  1112. cli();
  1113. if (!(port->flags & FLAG8253X_CALLOUT_ACTIVE) &&
  1114.     (tty->termios->c_cflag & CBAUD)) 
  1115. {
  1116. RAISE(port, dtr);
  1117. RAISE(port, rts); /* maybe not correct for sync */
  1118. /*
  1119.  * ??? Why changing the mode here? 
  1120.  *  port->regs->rw.mode |= SAB82532_MODE_FRTS;
  1121.  *  port->regs->rw.mode &= ~(SAB82532_MODE_RTS);
  1122.  */
  1123. }
  1124. restore_flags(flags);
  1125. current->state = TASK_INTERRUPTIBLE;
  1126. if (tty_hung_up_p(filp) ||
  1127.     !(port->flags & FLAG8253X_INITIALIZED)) 
  1128. {
  1129. #ifdef SERIAL_DO_RESTART
  1130. if (port->flags & FLAG8253X_HUP_NOTIFY)
  1131. {
  1132. retval = -EAGAIN;
  1133. }
  1134. else
  1135. {
  1136. retval = -ERESTARTSYS;
  1137. }
  1138. #else
  1139. retval = -EAGAIN;
  1140. #endif
  1141. break;
  1142. }
  1143. if (!(port->flags & FLAG8253X_CALLOUT_ACTIVE) &&
  1144.     !(port->flags & FLAG8253X_CLOSING) &&
  1145.     (do_clocal || ISON(port,dcd))) 
  1146. {
  1147. break;
  1148. }
  1149. #ifdef DEBUG_OPEN
  1150. printk("sab8253x_block_til_ready:2 flags = 0x%xn",port->flags);
  1151. #endif
  1152. if (signal_pending(current)) 
  1153. {
  1154. retval = -ERESTARTSYS;
  1155. break;
  1156. }
  1157. #ifdef DEBUG_OPEN
  1158. printk("sab8253x_block_til_ready blocking: ttyS%d, count = %d, flags = %x, clocal = %d, vstr = %02xn",
  1159.        port->line, port->count, port->flags, do_clocal, READB(port,vstr));
  1160. #endif
  1161. schedule();
  1162. }
  1163. current->state = TASK_RUNNING;
  1164. remove_wait_queue(&port->open_wait, &wait);
  1165. port->blocked_open--;
  1166. #ifdef DEBUG_OPEN
  1167. printk("sab8253x_block_til_ready after blocking: ttys%d, count = %dn",
  1168.        port->line, port->count);
  1169. #endif
  1170. if (retval)
  1171. {
  1172. return retval;
  1173. }
  1174. port->flags |= FLAG8253X_NORMAL_ACTIVE;
  1175. return 0;
  1176. }
  1177. /*
  1178.  * sab8253x_wait_until_sent() --- wait until the transmitter is empty
  1179.  */
  1180. void sab8253x_wait_until_sent(struct tty_struct *tty, int timeout)
  1181. {
  1182. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1183. unsigned long orig_jiffies, char_time;
  1184. if (sab8253x_serial_paranoia_check(port,tty->device,"sab8253x_wait_until_sent"))
  1185. {
  1186. return;
  1187. }
  1188. orig_jiffies = jiffies;
  1189. /*
  1190.  * Set the check interval to be 1/5 of the estimated time to
  1191.  * send a single character, and make it at least 1.  The check
  1192.  * interval should also be less than the timeout.
  1193.  * 
  1194.  * Note: we have to use pretty tight timings here to satisfy
  1195.  * the NIST-PCTS.
  1196.  */
  1197. char_time = (port->timeout - HZ/50) / port->xmit_fifo_size;
  1198. char_time = char_time / 5;
  1199. if (char_time == 0)
  1200. {
  1201. char_time = 1;
  1202. }
  1203. if (timeout)
  1204. {
  1205. char_time = MIN(char_time, timeout);
  1206. }
  1207. while ((Sab8253xCountTransmit(port) > 0) || !port->all_sent) 
  1208. {
  1209. current->state = TASK_INTERRUPTIBLE;
  1210. schedule_timeout(char_time);
  1211. if (signal_pending(current))
  1212. {
  1213. break;
  1214. }
  1215. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  1216. {
  1217. break;
  1218. }
  1219. }
  1220. }
  1221. void sab8253x_flush_buffer(struct tty_struct *tty)
  1222. {
  1223. struct sab_port *port = (struct sab_port *)tty->driver_data;
  1224. unsigned long flags;
  1225. register RING_DESCRIPTOR *freeme;
  1226. if(sab8253x_serial_paranoia_check(port, tty->device, "sab8253x_flush_buffer"))
  1227. {
  1228. return;
  1229. }
  1230. if(port->sabnext2.transmit == NULL)
  1231. {
  1232. return;
  1233. }
  1234. save_flags(flags); 
  1235. cli(); /* need to turn off ints because mucking
  1236.    with sabnext2 */
  1237. #ifndef FREEININTERRUPT
  1238. freeme = port->active2.transmit;
  1239. do /* just go all around */
  1240. {
  1241. if(freeme->HostVaddr)
  1242. {
  1243. skb_unlink((struct sk_buff*)freeme->HostVaddr);
  1244. dev_kfree_skb_any((struct sk_buff*)freeme->HostVaddr);
  1245. freeme->HostVaddr = NULL;
  1246. }
  1247. freeme->sendcrc = 0;
  1248. freeme->crcindex = 0;
  1249. freeme->Count = OWN_DRIVER;
  1250. freeme = (RING_DESCRIPTOR*) freeme->VNext;
  1251. }
  1252. while(freeme != port->active2.transmit);
  1253. #else  /* buffers only from sabnext2.transmit to active2.transmit */
  1254. while((port->sabnext2.transmit->Count & OWNER) == OWN_SAB) /* clear out stuff waiting to be transmitted */
  1255. {
  1256. freeme = port->sabnext2.transmit;
  1257. if(freeme->HostVaddr)
  1258. {
  1259. skb_unlink((struct sk_buff*)freeme->HostVaddr);
  1260. dev_kfree_skb_any((struct sk_buff*)freeme->HostVaddr);
  1261. freeme->HostVaddr = NULL;
  1262. }
  1263. freeme->sendcrc = 0;
  1264. freeme->crcindex = 0;
  1265. freeme->Count = OWN_DRIVER;
  1266. port->sabnext2.transmit = freeme->VNext;
  1267. }
  1268. #endif
  1269. port->sabnext2.transmit = port->active2.transmit; /* should already be equal to be sure */
  1270. sab8253x_cec_wait(port);
  1271. WRITEB(port,cmdr,SAB82532_CMDR_XRES);
  1272. restore_flags(flags);
  1273. wake_up_interruptible(&tty->write_wait); /* wake up tty driver */
  1274. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  1275.     tty->ldisc.write_wakeup)
  1276. {
  1277. (*tty->ldisc.write_wakeup)(tty);
  1278. }
  1279. }