hd64572.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * Hitachi (now Renesas) SCA-II HD64572 driver for Linux
  3. *
  4. * Copyright (C) 1998-2008 Krzysztof Halasa <khc@pm.waw.pl>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of version 2 of the GNU General Public License
  8. * as published by the Free Software Foundation.
  9. *
  10. * Source of information: HD64572 SCA-II User's Manual
  11. *
  12. * We use the following SCA memory map:
  13. *
  14. * Packet buffer descriptor rings - starting from card->rambase:
  15. * rx_ring_buffers * sizeof(pkt_desc) = logical channel #0 RX ring
  16. * tx_ring_buffers * sizeof(pkt_desc) = logical channel #0 TX ring
  17. * rx_ring_buffers * sizeof(pkt_desc) = logical channel #1 RX ring (if used)
  18. * tx_ring_buffers * sizeof(pkt_desc) = logical channel #1 TX ring (if used)
  19. *
  20. * Packet data buffers - starting from card->rambase + buff_offset:
  21. * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers
  22. * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers
  23. * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers (if used)
  24. * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers (if used)
  25. */
  26. #include <linux/bitops.h>
  27. #include <linux/errno.h>
  28. #include <linux/fcntl.h>
  29. #include <linux/hdlc.h>
  30. #include <linux/in.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/ioport.h>
  33. #include <linux/jiffies.h>
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/string.h>
  39. #include <linux/types.h>
  40. #include <asm/io.h>
  41. #include <asm/uaccess.h>
  42. #include "hd64572.h"
  43. #define NAPI_WEIGHT 16
  44. #define get_msci(port) (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET)
  45. #define get_dmac_rx(port) (port->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
  46. #define get_dmac_tx(port) (port->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
  47. #define sca_in(reg, card) readb(card->scabase + (reg))
  48. #define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
  49. #define sca_inw(reg, card) readw(card->scabase + (reg))
  50. #define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
  51. #define sca_inl(reg, card) readl(card->scabase + (reg))
  52. #define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
  53. static int sca_poll(struct napi_struct *napi, int budget);
  54. static inline port_t* dev_to_port(struct net_device *dev)
  55. {
  56. return dev_to_hdlc(dev)->priv;
  57. }
  58. static inline void enable_intr(port_t *port)
  59. {
  60. /* enable DMIB and MSCI RXINTA interrupts */
  61. sca_outl(sca_inl(IER0, port->card) |
  62. (port->chan ? 0x08002200 : 0x00080022), IER0, port->card);
  63. }
  64. static inline void disable_intr(port_t *port)
  65. {
  66. sca_outl(sca_inl(IER0, port->card) &
  67. (port->chan ? 0x00FF00FF : 0xFF00FF00), IER0, port->card);
  68. }
  69. static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit)
  70. {
  71. u16 rx_buffs = port->card->rx_ring_buffers;
  72. u16 tx_buffs = port->card->tx_ring_buffers;
  73. desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc.
  74. return port->chan * (rx_buffs + tx_buffs) + transmit * rx_buffs + desc;
  75. }
  76. static inline u16 desc_offset(port_t *port, u16 desc, int transmit)
  77. {
  78. /* Descriptor offset always fits in 16 bits */
  79. return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc);
  80. }
  81. static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc,
  82. int transmit)
  83. {
  84. return (pkt_desc __iomem *)(port->card->rambase +
  85. desc_offset(port, desc, transmit));
  86. }
  87. static inline u32 buffer_offset(port_t *port, u16 desc, int transmit)
  88. {
  89. return port->card->buff_offset +
  90. desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU;
  91. }
  92. static inline void sca_set_carrier(port_t *port)
  93. {
  94. if (!(sca_in(get_msci(port) + ST3, port->card) & ST3_DCD)) {
  95. #ifdef DEBUG_LINK
  96. printk(KERN_DEBUG "%s: sca_set_carrier on\n",
  97. port->netdev.name);
  98. #endif
  99. netif_carrier_on(port->netdev);
  100. } else {
  101. #ifdef DEBUG_LINK
  102. printk(KERN_DEBUG "%s: sca_set_carrier off\n",
  103. port->netdev.name);
  104. #endif
  105. netif_carrier_off(port->netdev);
  106. }
  107. }
  108. static void sca_init_port(port_t *port)
  109. {
  110. card_t *card = port->card;
  111. u16 dmac_rx = get_dmac_rx(port), dmac_tx = get_dmac_tx(port);
  112. int transmit, i;
  113. port->rxin = 0;
  114. port->txin = 0;
  115. port->txlast = 0;
  116. for (transmit = 0; transmit < 2; transmit++) {
  117. u16 buffs = transmit ? card->tx_ring_buffers
  118. : card->rx_ring_buffers;
  119. for (i = 0; i < buffs; i++) {
  120. pkt_desc __iomem *desc = desc_address(port, i, transmit);
  121. u16 chain_off = desc_offset(port, i + 1, transmit);
  122. u32 buff_off = buffer_offset(port, i, transmit);
  123. writel(chain_off, &desc->cp);
  124. writel(buff_off, &desc->bp);
  125. writew(0, &desc->len);
  126. writeb(0, &desc->stat);
  127. }
  128. }
  129. /* DMA disable - to halt state */
  130. sca_out(0, DSR_RX(port->chan), card);
  131. sca_out(0, DSR_TX(port->chan), card);
  132. /* software ABORT - to initial state */
  133. sca_out(DCR_ABORT, DCR_RX(port->chan), card);
  134. sca_out(DCR_ABORT, DCR_TX(port->chan), card);
  135. /* current desc addr */
  136. sca_outl(desc_offset(port, 0, 0), dmac_rx + CDAL, card);
  137. sca_outl(desc_offset(port, card->tx_ring_buffers - 1, 0),
  138. dmac_rx + EDAL, card);
  139. sca_outl(desc_offset(port, 0, 1), dmac_tx + CDAL, card);
  140. sca_outl(desc_offset(port, 0, 1), dmac_tx + EDAL, card);
  141. /* clear frame end interrupt counter */
  142. sca_out(DCR_CLEAR_EOF, DCR_RX(port->chan), card);
  143. sca_out(DCR_CLEAR_EOF, DCR_TX(port->chan), card);
  144. /* Receive */
  145. sca_outw(HDLC_MAX_MRU, dmac_rx + BFLL, card); /* set buffer length */
  146. sca_out(0x14, DMR_RX(port->chan), card); /* Chain mode, Multi-frame */
  147. sca_out(DIR_EOME, DIR_RX(port->chan), card); /* enable interrupts */
  148. sca_out(DSR_DE, DSR_RX(port->chan), card); /* DMA enable */
  149. /* Transmit */
  150. sca_out(0x14, DMR_TX(port->chan), card); /* Chain mode, Multi-frame */
  151. sca_out(DIR_EOME, DIR_TX(port->chan), card); /* enable interrupts */
  152. sca_set_carrier(port);
  153. netif_napi_add(port->netdev, &port->napi, sca_poll, NAPI_WEIGHT);
  154. }
  155. /* MSCI interrupt service */
  156. static inline void sca_msci_intr(port_t *port)
  157. {
  158. u16 msci = get_msci(port);
  159. card_t* card = port->card;
  160. if (sca_in(msci + ST1, card) & ST1_CDCD) {
  161. /* Reset MSCI CDCD status bit */
  162. sca_out(ST1_CDCD, msci + ST1, card);
  163. sca_set_carrier(port);
  164. }
  165. }
  166. static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
  167. u16 rxin)
  168. {
  169. struct net_device *dev = port->netdev;
  170. struct sk_buff *skb;
  171. u16 len;
  172. u32 buff;
  173. len = readw(&desc->len);
  174. skb = dev_alloc_skb(len);
  175. if (!skb) {
  176. dev->stats.rx_dropped++;
  177. return;
  178. }
  179. buff = buffer_offset(port, rxin, 0);
  180. memcpy_fromio(skb->data, card->rambase + buff, len);
  181. skb_put(skb, len);
  182. #ifdef DEBUG_PKT
  183. printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len);
  184. debug_frame(skb);
  185. #endif
  186. dev->stats.rx_packets++;
  187. dev->stats.rx_bytes += skb->len;
  188. skb->protocol = hdlc_type_trans(skb, dev);
  189. netif_receive_skb(skb);
  190. }
  191. /* Receive DMA service */
  192. static inline int sca_rx_done(port_t *port, int budget)
  193. {
  194. struct net_device *dev = port->netdev;
  195. u16 dmac = get_dmac_rx(port);
  196. card_t *card = port->card;
  197. u8 stat = sca_in(DSR_RX(port->chan), card); /* read DMA Status */
  198. int received = 0;
  199. /* Reset DSR status bits */
  200. sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
  201. DSR_RX(port->chan), card);
  202. if (stat & DSR_BOF)
  203. /* Dropped one or more frames */
  204. dev->stats.rx_over_errors++;
  205. while (received < budget) {
  206. u32 desc_off = desc_offset(port, port->rxin, 0);
  207. pkt_desc __iomem *desc;
  208. u32 cda = sca_inl(dmac + CDAL, card);
  209. if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc)))
  210. break; /* No frame received */
  211. desc = desc_address(port, port->rxin, 0);
  212. stat = readb(&desc->stat);
  213. if (!(stat & ST_RX_EOM))
  214. port->rxpart = 1; /* partial frame received */
  215. else if ((stat & ST_ERROR_MASK) || port->rxpart) {
  216. dev->stats.rx_errors++;
  217. if (stat & ST_RX_OVERRUN)
  218. dev->stats.rx_fifo_errors++;
  219. else if ((stat & (ST_RX_SHORT | ST_RX_ABORT |
  220. ST_RX_RESBIT)) || port->rxpart)
  221. dev->stats.rx_frame_errors++;
  222. else if (stat & ST_RX_CRC)
  223. dev->stats.rx_crc_errors++;
  224. if (stat & ST_RX_EOM)
  225. port->rxpart = 0; /* received last fragment */
  226. } else {
  227. sca_rx(card, port, desc, port->rxin);
  228. received++;
  229. }
  230. /* Set new error descriptor address */
  231. sca_outl(desc_off, dmac + EDAL, card);
  232. port->rxin = (port->rxin + 1) % card->rx_ring_buffers;
  233. }
  234. /* make sure RX DMA is enabled */
  235. sca_out(DSR_DE, DSR_RX(port->chan), card);
  236. return received;
  237. }
  238. /* Transmit DMA service */
  239. static inline void sca_tx_done(port_t *port)
  240. {
  241. struct net_device *dev = port->netdev;
  242. card_t* card = port->card;
  243. u8 stat;
  244. unsigned count = 0;
  245. spin_lock(&port->lock);
  246. stat = sca_in(DSR_TX(port->chan), card); /* read DMA Status */
  247. /* Reset DSR status bits */
  248. sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
  249. DSR_TX(port->chan), card);
  250. while (1) {
  251. pkt_desc __iomem *desc = desc_address(port, port->txlast, 1);
  252. u8 stat = readb(&desc->stat);
  253. if (!(stat & ST_TX_OWNRSHP))
  254. break; /* not yet transmitted */
  255. if (stat & ST_TX_UNDRRUN) {
  256. dev->stats.tx_errors++;
  257. dev->stats.tx_fifo_errors++;
  258. } else {
  259. dev->stats.tx_packets++;
  260. dev->stats.tx_bytes += readw(&desc->len);
  261. }
  262. writeb(0, &desc->stat); /* Free descriptor */
  263. count++;
  264. port->txlast = (port->txlast + 1) % card->tx_ring_buffers;
  265. }
  266. if (count)
  267. netif_wake_queue(dev);
  268. spin_unlock(&port->lock);
  269. }
  270. static int sca_poll(struct napi_struct *napi, int budget)
  271. {
  272. port_t *port = container_of(napi, port_t, napi);
  273. u32 isr0 = sca_inl(ISR0, port->card);
  274. int received = 0;
  275. if (isr0 & (port->chan ? 0x08000000 : 0x00080000))
  276. sca_msci_intr(port);
  277. if (isr0 & (port->chan ? 0x00002000 : 0x00000020))
  278. sca_tx_done(port);
  279. if (isr0 & (port->chan ? 0x00000200 : 0x00000002))
  280. received = sca_rx_done(port, budget);
  281. if (received < budget) {
  282. napi_complete(napi);
  283. enable_intr(port);
  284. }
  285. return received;
  286. }
  287. static irqreturn_t sca_intr(int irq, void *dev_id)
  288. {
  289. card_t *card = dev_id;
  290. u32 isr0 = sca_inl(ISR0, card);
  291. int i, handled = 0;
  292. for (i = 0; i < 2; i++) {
  293. port_t *port = get_port(card, i);
  294. if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) {
  295. handled = 1;
  296. disable_intr(port);
  297. napi_schedule(&port->napi);
  298. }
  299. }
  300. return IRQ_RETVAL(handled);
  301. }
  302. static void sca_set_port(port_t *port)
  303. {
  304. card_t* card = port->card;
  305. u16 msci = get_msci(port);
  306. u8 md2 = sca_in(msci + MD2, card);
  307. unsigned int tmc, br = 10, brv = 1024;
  308. if (port->settings.clock_rate > 0) {
  309. /* Try lower br for better accuracy*/
  310. do {
  311. br--;
  312. brv >>= 1; /* brv = 2^9 = 512 max in specs */
  313. /* Baud Rate = CLOCK_BASE / TMC / 2^BR */
  314. tmc = CLOCK_BASE / brv / port->settings.clock_rate;
  315. }while (br > 1 && tmc <= 128);
  316. if (tmc < 1) {
  317. tmc = 1;
  318. br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */
  319. brv = 1;
  320. } else if (tmc > 255)
  321. tmc = 256; /* tmc=0 means 256 - low baud rates */
  322. port->settings.clock_rate = CLOCK_BASE / brv / tmc;
  323. } else {
  324. br = 9; /* Minimum clock rate */
  325. tmc = 256; /* 8bit = 0 */
  326. port->settings.clock_rate = CLOCK_BASE / (256 * 512);
  327. }
  328. port->rxs = (port->rxs & ~CLK_BRG_MASK) | br;
  329. port->txs = (port->txs & ~CLK_BRG_MASK) | br;
  330. port->tmc = tmc;
  331. /* baud divisor - time constant*/
  332. sca_out(port->tmc, msci + TMCR, card);
  333. sca_out(port->tmc, msci + TMCT, card);
  334. /* Set BRG bits */
  335. sca_out(port->rxs, msci + RXS, card);
  336. sca_out(port->txs, msci + TXS, card);
  337. if (port->settings.loopback)
  338. md2 |= MD2_LOOPBACK;
  339. else
  340. md2 &= ~MD2_LOOPBACK;
  341. sca_out(md2, msci + MD2, card);
  342. }
  343. static void sca_open(struct net_device *dev)
  344. {
  345. port_t *port = dev_to_port(dev);
  346. card_t* card = port->card;
  347. u16 msci = get_msci(port);
  348. u8 md0, md2;
  349. switch(port->encoding) {
  350. case ENCODING_NRZ: md2 = MD2_NRZ; break;
  351. case ENCODING_NRZI: md2 = MD2_NRZI; break;
  352. case ENCODING_FM_MARK: md2 = MD2_FM_MARK; break;
  353. case ENCODING_FM_SPACE: md2 = MD2_FM_SPACE; break;
  354. default: md2 = MD2_MANCHESTER;
  355. }
  356. if (port->settings.loopback)
  357. md2 |= MD2_LOOPBACK;
  358. switch(port->parity) {
  359. case PARITY_CRC16_PR0: md0 = MD0_HDLC | MD0_CRC_16_0; break;
  360. case PARITY_CRC16_PR1: md0 = MD0_HDLC | MD0_CRC_16; break;
  361. case PARITY_CRC32_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU32; break;
  362. case PARITY_CRC16_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU; break;
  363. default: md0 = MD0_HDLC | MD0_CRC_NONE;
  364. }
  365. sca_out(CMD_RESET, msci + CMD, card);
  366. sca_out(md0, msci + MD0, card);
  367. sca_out(0x00, msci + MD1, card); /* no address field check */
  368. sca_out(md2, msci + MD2, card);
  369. sca_out(0x7E, msci + IDL, card); /* flag character 0x7E */
  370. /* Skip the rest of underrun frame */
  371. sca_out(CTL_IDLE | CTL_URCT | CTL_URSKP, msci + CTL, card);
  372. sca_out(0x0F, msci + RNR, card); /* +1=RX DMA activation condition */
  373. sca_out(0x3C, msci + TFS, card); /* +1 = TX start */
  374. sca_out(0x38, msci + TCR, card); /* =Critical TX DMA activ condition */
  375. sca_out(0x38, msci + TNR0, card); /* =TX DMA activation condition */
  376. sca_out(0x3F, msci + TNR1, card); /* +1=TX DMA deactivation condition*/
  377. /* We're using the following interrupts:
  378. - RXINTA (DCD changes only)
  379. - DMIB (EOM - single frame transfer complete)
  380. */
  381. sca_outl(IE0_RXINTA | IE0_CDCD, msci + IE0, card);
  382. sca_out(port->tmc, msci + TMCR, card);
  383. sca_out(port->tmc, msci + TMCT, card);
  384. sca_out(port->rxs, msci + RXS, card);
  385. sca_out(port->txs, msci + TXS, card);
  386. sca_out(CMD_TX_ENABLE, msci + CMD, card);
  387. sca_out(CMD_RX_ENABLE, msci + CMD, card);
  388. sca_set_carrier(port);
  389. enable_intr(port);
  390. napi_enable(&port->napi);
  391. netif_start_queue(dev);
  392. }
  393. static void sca_close(struct net_device *dev)
  394. {
  395. port_t *port = dev_to_port(dev);
  396. /* reset channel */
  397. sca_out(CMD_RESET, get_msci(port) + CMD, port->card);
  398. disable_intr(port);
  399. napi_disable(&port->napi);
  400. netif_stop_queue(dev);
  401. }
  402. static int sca_attach(struct net_device *dev, unsigned short encoding,
  403. unsigned short parity)
  404. {
  405. if (encoding != ENCODING_NRZ &&
  406. encoding != ENCODING_NRZI &&
  407. encoding != ENCODING_FM_MARK &&
  408. encoding != ENCODING_FM_SPACE &&
  409. encoding != ENCODING_MANCHESTER)
  410. return -EINVAL;
  411. if (parity != PARITY_NONE &&
  412. parity != PARITY_CRC16_PR0 &&
  413. parity != PARITY_CRC16_PR1 &&
  414. parity != PARITY_CRC32_PR1_CCITT &&
  415. parity != PARITY_CRC16_PR1_CCITT)
  416. return -EINVAL;
  417. dev_to_port(dev)->encoding = encoding;
  418. dev_to_port(dev)->parity = parity;
  419. return 0;
  420. }
  421. #ifdef DEBUG_RINGS
  422. static void sca_dump_rings(struct net_device *dev)
  423. {
  424. port_t *port = dev_to_port(dev);
  425. card_t *card = port->card;
  426. u16 cnt;
  427. printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive",
  428. sca_inl(get_dmac_rx(port) + CDAL, card),
  429. sca_inl(get_dmac_rx(port) + EDAL, card),
  430. sca_in(DSR_RX(port->chan), card), port->rxin,
  431. sca_in(DSR_RX(port->chan), card) & DSR_DE ? "" : "in");
  432. for (cnt = 0; cnt < port->card->rx_ring_buffers; cnt++)
  433. pr_cont(" %02X", readb(&(desc_address(port, cnt, 0)->stat)));
  434. pr_cont("\n");
  435. printk(KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u "
  436. "last=%u %sactive",
  437. sca_inl(get_dmac_tx(port) + CDAL, card),
  438. sca_inl(get_dmac_tx(port) + EDAL, card),
  439. sca_in(DSR_TX(port->chan), card), port->txin, port->txlast,
  440. sca_in(DSR_TX(port->chan), card) & DSR_DE ? "" : "in");
  441. for (cnt = 0; cnt < port->card->tx_ring_buffers; cnt++)
  442. pr_cont(" %02X", readb(&(desc_address(port, cnt, 1)->stat)));
  443. pr_cont("\n");
  444. printk(KERN_DEBUG "MSCI: MD: %02x %02x %02x,"
  445. " ST: %02x %02x %02x %02x %02x, FST: %02x CST: %02x %02x\n",
  446. sca_in(get_msci(port) + MD0, card),
  447. sca_in(get_msci(port) + MD1, card),
  448. sca_in(get_msci(port) + MD2, card),
  449. sca_in(get_msci(port) + ST0, card),
  450. sca_in(get_msci(port) + ST1, card),
  451. sca_in(get_msci(port) + ST2, card),
  452. sca_in(get_msci(port) + ST3, card),
  453. sca_in(get_msci(port) + ST4, card),
  454. sca_in(get_msci(port) + FST, card),
  455. sca_in(get_msci(port) + CST0, card),
  456. sca_in(get_msci(port) + CST1, card));
  457. printk(KERN_DEBUG "ILAR: %02x ISR: %08x %08x\n", sca_in(ILAR, card),
  458. sca_inl(ISR0, card), sca_inl(ISR1, card));
  459. }
  460. #endif /* DEBUG_RINGS */
  461. static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev)
  462. {
  463. port_t *port = dev_to_port(dev);
  464. card_t *card = port->card;
  465. pkt_desc __iomem *desc;
  466. u32 buff, len;
  467. spin_lock_irq(&port->lock);
  468. desc = desc_address(port, port->txin + 1, 1);
  469. BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */
  470. #ifdef DEBUG_PKT
  471. printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len);
  472. debug_frame(skb);
  473. #endif
  474. desc = desc_address(port, port->txin, 1);
  475. buff = buffer_offset(port, port->txin, 1);
  476. len = skb->len;
  477. memcpy_toio(card->rambase + buff, skb->data, len);
  478. writew(len, &desc->len);
  479. writeb(ST_TX_EOM, &desc->stat);
  480. port->txin = (port->txin + 1) % card->tx_ring_buffers;
  481. sca_outl(desc_offset(port, port->txin, 1),
  482. get_dmac_tx(port) + EDAL, card);
  483. sca_out(DSR_DE, DSR_TX(port->chan), card); /* Enable TX DMA */
  484. desc = desc_address(port, port->txin + 1, 1);
  485. if (readb(&desc->stat)) /* allow 1 packet gap */
  486. netif_stop_queue(dev);
  487. spin_unlock_irq(&port->lock);
  488. dev_kfree_skb(skb);
  489. return NETDEV_TX_OK;
  490. }
  491. static u32 sca_detect_ram(card_t *card, u8 __iomem *rambase, u32 ramsize)
  492. {
  493. /* Round RAM size to 32 bits, fill from end to start */
  494. u32 i = ramsize &= ~3;
  495. do {
  496. i -= 4;
  497. writel(i ^ 0x12345678, rambase + i);
  498. } while (i > 0);
  499. for (i = 0; i < ramsize ; i += 4) {
  500. if (readl(rambase + i) != (i ^ 0x12345678))
  501. break;
  502. }
  503. return i;
  504. }
  505. static void sca_init(card_t *card, int wait_states)
  506. {
  507. sca_out(wait_states, WCRL, card); /* Wait Control */
  508. sca_out(wait_states, WCRM, card);
  509. sca_out(wait_states, WCRH, card);
  510. sca_out(0, DMER, card); /* DMA Master disable */
  511. sca_out(0x03, PCR, card); /* DMA priority */
  512. sca_out(0, DSR_RX(0), card); /* DMA disable - to halt state */
  513. sca_out(0, DSR_TX(0), card);
  514. sca_out(0, DSR_RX(1), card);
  515. sca_out(0, DSR_TX(1), card);
  516. sca_out(DMER_DME, DMER, card); /* DMA Master enable */
  517. }