hd64570.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. * Hitachi SCA HD64570 driver for Linux
  3. *
  4. * Copyright (C) 1998-2003 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: Hitachi HD64570 SCA User's Manual
  11. *
  12. * We use the following SCA memory map:
  13. *
  14. * Packet buffer descriptor rings - starting from winbase or win0base:
  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 winbase + 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 "hd64570.h"
  43. #define get_msci(port) (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET)
  44. #define get_dmac_rx(port) (phy_node(port) ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
  45. #define get_dmac_tx(port) (phy_node(port) ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
  46. #define SCA_INTR_MSCI(node) (node ? 0x10 : 0x01)
  47. #define SCA_INTR_DMAC_RX(node) (node ? 0x20 : 0x02)
  48. #define SCA_INTR_DMAC_TX(node) (node ? 0x40 : 0x04)
  49. static inline struct net_device *port_to_dev(port_t *port)
  50. {
  51. return port->dev;
  52. }
  53. static inline int sca_intr_status(card_t *card)
  54. {
  55. u8 result = 0;
  56. u8 isr0 = sca_in(ISR0, card);
  57. u8 isr1 = sca_in(ISR1, card);
  58. if (isr1 & 0x03) result |= SCA_INTR_DMAC_RX(0);
  59. if (isr1 & 0x0C) result |= SCA_INTR_DMAC_TX(0);
  60. if (isr1 & 0x30) result |= SCA_INTR_DMAC_RX(1);
  61. if (isr1 & 0xC0) result |= SCA_INTR_DMAC_TX(1);
  62. if (isr0 & 0x0F) result |= SCA_INTR_MSCI(0);
  63. if (isr0 & 0xF0) result |= SCA_INTR_MSCI(1);
  64. if (!(result & SCA_INTR_DMAC_TX(0)))
  65. if (sca_in(DSR_TX(0), card) & DSR_EOM)
  66. result |= SCA_INTR_DMAC_TX(0);
  67. if (!(result & SCA_INTR_DMAC_TX(1)))
  68. if (sca_in(DSR_TX(1), card) & DSR_EOM)
  69. result |= SCA_INTR_DMAC_TX(1);
  70. return result;
  71. }
  72. static inline port_t* dev_to_port(struct net_device *dev)
  73. {
  74. return dev_to_hdlc(dev)->priv;
  75. }
  76. static inline u16 next_desc(port_t *port, u16 desc, int transmit)
  77. {
  78. return (desc + 1) % (transmit ? port_to_card(port)->tx_ring_buffers
  79. : port_to_card(port)->rx_ring_buffers);
  80. }
  81. static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit)
  82. {
  83. u16 rx_buffs = port_to_card(port)->rx_ring_buffers;
  84. u16 tx_buffs = port_to_card(port)->tx_ring_buffers;
  85. desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc.
  86. return log_node(port) * (rx_buffs + tx_buffs) +
  87. transmit * rx_buffs + desc;
  88. }
  89. static inline u16 desc_offset(port_t *port, u16 desc, int transmit)
  90. {
  91. /* Descriptor offset always fits in 16 bits */
  92. return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc);
  93. }
  94. static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc,
  95. int transmit)
  96. {
  97. #ifdef PAGE0_ALWAYS_MAPPED
  98. return (pkt_desc __iomem *)(win0base(port_to_card(port))
  99. + desc_offset(port, desc, transmit));
  100. #else
  101. return (pkt_desc __iomem *)(winbase(port_to_card(port))
  102. + desc_offset(port, desc, transmit));
  103. #endif
  104. }
  105. static inline u32 buffer_offset(port_t *port, u16 desc, int transmit)
  106. {
  107. return port_to_card(port)->buff_offset +
  108. desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU;
  109. }
  110. static inline void sca_set_carrier(port_t *port)
  111. {
  112. if (!(sca_in(get_msci(port) + ST3, port_to_card(port)) & ST3_DCD)) {
  113. #ifdef DEBUG_LINK
  114. printk(KERN_DEBUG "%s: sca_set_carrier on\n",
  115. port_to_dev(port)->name);
  116. #endif
  117. netif_carrier_on(port_to_dev(port));
  118. } else {
  119. #ifdef DEBUG_LINK
  120. printk(KERN_DEBUG "%s: sca_set_carrier off\n",
  121. port_to_dev(port)->name);
  122. #endif
  123. netif_carrier_off(port_to_dev(port));
  124. }
  125. }
  126. static void sca_init_port(port_t *port)
  127. {
  128. card_t *card = port_to_card(port);
  129. int transmit, i;
  130. port->rxin = 0;
  131. port->txin = 0;
  132. port->txlast = 0;
  133. #ifndef PAGE0_ALWAYS_MAPPED
  134. openwin(card, 0);
  135. #endif
  136. for (transmit = 0; transmit < 2; transmit++) {
  137. u16 dmac = transmit ? get_dmac_tx(port) : get_dmac_rx(port);
  138. u16 buffs = transmit ? card->tx_ring_buffers
  139. : card->rx_ring_buffers;
  140. for (i = 0; i < buffs; i++) {
  141. pkt_desc __iomem *desc = desc_address(port, i, transmit);
  142. u16 chain_off = desc_offset(port, i + 1, transmit);
  143. u32 buff_off = buffer_offset(port, i, transmit);
  144. writew(chain_off, &desc->cp);
  145. writel(buff_off, &desc->bp);
  146. writew(0, &desc->len);
  147. writeb(0, &desc->stat);
  148. }
  149. /* DMA disable - to halt state */
  150. sca_out(0, transmit ? DSR_TX(phy_node(port)) :
  151. DSR_RX(phy_node(port)), card);
  152. /* software ABORT - to initial state */
  153. sca_out(DCR_ABORT, transmit ? DCR_TX(phy_node(port)) :
  154. DCR_RX(phy_node(port)), card);
  155. /* current desc addr */
  156. sca_out(0, dmac + CPB, card); /* pointer base */
  157. sca_outw(desc_offset(port, 0, transmit), dmac + CDAL, card);
  158. if (!transmit)
  159. sca_outw(desc_offset(port, buffs - 1, transmit),
  160. dmac + EDAL, card);
  161. else
  162. sca_outw(desc_offset(port, 0, transmit), dmac + EDAL,
  163. card);
  164. /* clear frame end interrupt counter */
  165. sca_out(DCR_CLEAR_EOF, transmit ? DCR_TX(phy_node(port)) :
  166. DCR_RX(phy_node(port)), card);
  167. if (!transmit) { /* Receive */
  168. /* set buffer length */
  169. sca_outw(HDLC_MAX_MRU, dmac + BFLL, card);
  170. /* Chain mode, Multi-frame */
  171. sca_out(0x14, DMR_RX(phy_node(port)), card);
  172. sca_out(DIR_EOME | DIR_BOFE, DIR_RX(phy_node(port)),
  173. card);
  174. /* DMA enable */
  175. sca_out(DSR_DE, DSR_RX(phy_node(port)), card);
  176. } else { /* Transmit */
  177. /* Chain mode, Multi-frame */
  178. sca_out(0x14, DMR_TX(phy_node(port)), card);
  179. /* enable underflow interrupts */
  180. sca_out(DIR_BOFE, DIR_TX(phy_node(port)), card);
  181. }
  182. }
  183. sca_set_carrier(port);
  184. }
  185. #ifdef NEED_SCA_MSCI_INTR
  186. /* MSCI interrupt service */
  187. static inline void sca_msci_intr(port_t *port)
  188. {
  189. u16 msci = get_msci(port);
  190. card_t* card = port_to_card(port);
  191. u8 stat = sca_in(msci + ST1, card); /* read MSCI ST1 status */
  192. /* Reset MSCI TX underrun and CDCD status bit */
  193. sca_out(stat & (ST1_UDRN | ST1_CDCD), msci + ST1, card);
  194. if (stat & ST1_UDRN) {
  195. /* TX Underrun error detected */
  196. port_to_dev(port)->stats.tx_errors++;
  197. port_to_dev(port)->stats.tx_fifo_errors++;
  198. }
  199. if (stat & ST1_CDCD)
  200. sca_set_carrier(port);
  201. }
  202. #endif
  203. static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
  204. u16 rxin)
  205. {
  206. struct net_device *dev = port_to_dev(port);
  207. struct sk_buff *skb;
  208. u16 len;
  209. u32 buff;
  210. u32 maxlen;
  211. u8 page;
  212. len = readw(&desc->len);
  213. skb = dev_alloc_skb(len);
  214. if (!skb) {
  215. dev->stats.rx_dropped++;
  216. return;
  217. }
  218. buff = buffer_offset(port, rxin, 0);
  219. page = buff / winsize(card);
  220. buff = buff % winsize(card);
  221. maxlen = winsize(card) - buff;
  222. openwin(card, page);
  223. if (len > maxlen) {
  224. memcpy_fromio(skb->data, winbase(card) + buff, maxlen);
  225. openwin(card, page + 1);
  226. memcpy_fromio(skb->data + maxlen, winbase(card), len - maxlen);
  227. } else
  228. memcpy_fromio(skb->data, winbase(card) + buff, len);
  229. #ifndef PAGE0_ALWAYS_MAPPED
  230. openwin(card, 0); /* select pkt_desc table page back */
  231. #endif
  232. skb_put(skb, len);
  233. #ifdef DEBUG_PKT
  234. printk(KERN_DEBUG "%s RX(%i):", dev->name, skb->len);
  235. debug_frame(skb);
  236. #endif
  237. dev->stats.rx_packets++;
  238. dev->stats.rx_bytes += skb->len;
  239. skb->protocol = hdlc_type_trans(skb, dev);
  240. netif_rx(skb);
  241. }
  242. /* Receive DMA interrupt service */
  243. static inline void sca_rx_intr(port_t *port)
  244. {
  245. struct net_device *dev = port_to_dev(port);
  246. u16 dmac = get_dmac_rx(port);
  247. card_t *card = port_to_card(port);
  248. u8 stat = sca_in(DSR_RX(phy_node(port)), card); /* read DMA Status */
  249. /* Reset DSR status bits */
  250. sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
  251. DSR_RX(phy_node(port)), card);
  252. if (stat & DSR_BOF)
  253. /* Dropped one or more frames */
  254. dev->stats.rx_over_errors++;
  255. while (1) {
  256. u32 desc_off = desc_offset(port, port->rxin, 0);
  257. pkt_desc __iomem *desc;
  258. u32 cda = sca_inw(dmac + CDAL, card);
  259. if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc)))
  260. break; /* No frame received */
  261. desc = desc_address(port, port->rxin, 0);
  262. stat = readb(&desc->stat);
  263. if (!(stat & ST_RX_EOM))
  264. port->rxpart = 1; /* partial frame received */
  265. else if ((stat & ST_ERROR_MASK) || port->rxpart) {
  266. dev->stats.rx_errors++;
  267. if (stat & ST_RX_OVERRUN)
  268. dev->stats.rx_fifo_errors++;
  269. else if ((stat & (ST_RX_SHORT | ST_RX_ABORT |
  270. ST_RX_RESBIT)) || port->rxpart)
  271. dev->stats.rx_frame_errors++;
  272. else if (stat & ST_RX_CRC)
  273. dev->stats.rx_crc_errors++;
  274. if (stat & ST_RX_EOM)
  275. port->rxpart = 0; /* received last fragment */
  276. } else
  277. sca_rx(card, port, desc, port->rxin);
  278. /* Set new error descriptor address */
  279. sca_outw(desc_off, dmac + EDAL, card);
  280. port->rxin = next_desc(port, port->rxin, 0);
  281. }
  282. /* make sure RX DMA is enabled */
  283. sca_out(DSR_DE, DSR_RX(phy_node(port)), card);
  284. }
  285. /* Transmit DMA interrupt service */
  286. static inline void sca_tx_intr(port_t *port)
  287. {
  288. struct net_device *dev = port_to_dev(port);
  289. u16 dmac = get_dmac_tx(port);
  290. card_t* card = port_to_card(port);
  291. u8 stat;
  292. spin_lock(&port->lock);
  293. stat = sca_in(DSR_TX(phy_node(port)), card); /* read DMA Status */
  294. /* Reset DSR status bits */
  295. sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
  296. DSR_TX(phy_node(port)), card);
  297. while (1) {
  298. pkt_desc __iomem *desc;
  299. u32 desc_off = desc_offset(port, port->txlast, 1);
  300. u32 cda = sca_inw(dmac + CDAL, card);
  301. if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc)))
  302. break; /* Transmitter is/will_be sending this frame */
  303. desc = desc_address(port, port->txlast, 1);
  304. dev->stats.tx_packets++;
  305. dev->stats.tx_bytes += readw(&desc->len);
  306. writeb(0, &desc->stat); /* Free descriptor */
  307. port->txlast = next_desc(port, port->txlast, 1);
  308. }
  309. netif_wake_queue(dev);
  310. spin_unlock(&port->lock);
  311. }
  312. static irqreturn_t sca_intr(int irq, void* dev_id)
  313. {
  314. card_t *card = dev_id;
  315. int i;
  316. u8 stat;
  317. int handled = 0;
  318. u8 page = sca_get_page(card);
  319. while((stat = sca_intr_status(card)) != 0) {
  320. handled = 1;
  321. for (i = 0; i < 2; i++) {
  322. port_t *port = get_port(card, i);
  323. if (port) {
  324. if (stat & SCA_INTR_MSCI(i))
  325. sca_msci_intr(port);
  326. if (stat & SCA_INTR_DMAC_RX(i))
  327. sca_rx_intr(port);
  328. if (stat & SCA_INTR_DMAC_TX(i))
  329. sca_tx_intr(port);
  330. }
  331. }
  332. }
  333. openwin(card, page); /* Restore original page */
  334. return IRQ_RETVAL(handled);
  335. }
  336. static void sca_set_port(port_t *port)
  337. {
  338. card_t* card = port_to_card(port);
  339. u16 msci = get_msci(port);
  340. u8 md2 = sca_in(msci + MD2, card);
  341. unsigned int tmc, br = 10, brv = 1024;
  342. if (port->settings.clock_rate > 0) {
  343. /* Try lower br for better accuracy*/
  344. do {
  345. br--;
  346. brv >>= 1; /* brv = 2^9 = 512 max in specs */
  347. /* Baud Rate = CLOCK_BASE / TMC / 2^BR */
  348. tmc = CLOCK_BASE / brv / port->settings.clock_rate;
  349. }while (br > 1 && tmc <= 128);
  350. if (tmc < 1) {
  351. tmc = 1;
  352. br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */
  353. brv = 1;
  354. } else if (tmc > 255)
  355. tmc = 256; /* tmc=0 means 256 - low baud rates */
  356. port->settings.clock_rate = CLOCK_BASE / brv / tmc;
  357. } else {
  358. br = 9; /* Minimum clock rate */
  359. tmc = 256; /* 8bit = 0 */
  360. port->settings.clock_rate = CLOCK_BASE / (256 * 512);
  361. }
  362. port->rxs = (port->rxs & ~CLK_BRG_MASK) | br;
  363. port->txs = (port->txs & ~CLK_BRG_MASK) | br;
  364. port->tmc = tmc;
  365. /* baud divisor - time constant*/
  366. sca_out(port->tmc, msci + TMC, card);
  367. /* Set BRG bits */
  368. sca_out(port->rxs, msci + RXS, card);
  369. sca_out(port->txs, msci + TXS, card);
  370. if (port->settings.loopback)
  371. md2 |= MD2_LOOPBACK;
  372. else
  373. md2 &= ~MD2_LOOPBACK;
  374. sca_out(md2, msci + MD2, card);
  375. }
  376. static void sca_open(struct net_device *dev)
  377. {
  378. port_t *port = dev_to_port(dev);
  379. card_t* card = port_to_card(port);
  380. u16 msci = get_msci(port);
  381. u8 md0, md2;
  382. switch(port->encoding) {
  383. case ENCODING_NRZ: md2 = MD2_NRZ; break;
  384. case ENCODING_NRZI: md2 = MD2_NRZI; break;
  385. case ENCODING_FM_MARK: md2 = MD2_FM_MARK; break;
  386. case ENCODING_FM_SPACE: md2 = MD2_FM_SPACE; break;
  387. default: md2 = MD2_MANCHESTER;
  388. }
  389. if (port->settings.loopback)
  390. md2 |= MD2_LOOPBACK;
  391. switch(port->parity) {
  392. case PARITY_CRC16_PR0: md0 = MD0_HDLC | MD0_CRC_16_0; break;
  393. case PARITY_CRC16_PR1: md0 = MD0_HDLC | MD0_CRC_16; break;
  394. case PARITY_CRC16_PR0_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU_0; break;
  395. case PARITY_CRC16_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU; break;
  396. default: md0 = MD0_HDLC | MD0_CRC_NONE;
  397. }
  398. sca_out(CMD_RESET, msci + CMD, card);
  399. sca_out(md0, msci + MD0, card);
  400. sca_out(0x00, msci + MD1, card); /* no address field check */
  401. sca_out(md2, msci + MD2, card);
  402. sca_out(0x7E, msci + IDL, card); /* flag character 0x7E */
  403. sca_out(CTL_IDLE, msci + CTL, card);
  404. /* Allow at least 8 bytes before requesting RX DMA operation */
  405. /* TX with higher priority and possibly with shorter transfers */
  406. sca_out(0x07, msci + RRC, card); /* +1=RXRDY/DMA activation condition*/
  407. sca_out(0x10, msci + TRC0, card); /* = TXRDY/DMA activation condition*/
  408. sca_out(0x14, msci + TRC1, card); /* +1=TXRDY/DMA deactiv condition */
  409. /* We're using the following interrupts:
  410. - TXINT (DMAC completed all transmisions, underrun or DCD change)
  411. - all DMA interrupts
  412. */
  413. sca_set_carrier(port);
  414. /* MSCI TX INT and RX INT A IRQ enable */
  415. sca_out(IE0_TXINT | IE0_RXINTA, msci + IE0, card);
  416. sca_out(IE1_UDRN | IE1_CDCD, msci + IE1, card);
  417. sca_out(sca_in(IER0, card) | (phy_node(port) ? 0xC0 : 0x0C),
  418. IER0, card); /* TXINT and RXINT */
  419. /* enable DMA IRQ */
  420. sca_out(sca_in(IER1, card) | (phy_node(port) ? 0xF0 : 0x0F),
  421. IER1, card);
  422. sca_out(port->tmc, msci + TMC, card); /* Restore registers */
  423. sca_out(port->rxs, msci + RXS, card);
  424. sca_out(port->txs, msci + TXS, card);
  425. sca_out(CMD_TX_ENABLE, msci + CMD, card);
  426. sca_out(CMD_RX_ENABLE, msci + CMD, card);
  427. netif_start_queue(dev);
  428. }
  429. static void sca_close(struct net_device *dev)
  430. {
  431. port_t *port = dev_to_port(dev);
  432. card_t* card = port_to_card(port);
  433. /* reset channel */
  434. sca_out(CMD_RESET, get_msci(port) + CMD, port_to_card(port));
  435. /* disable MSCI interrupts */
  436. sca_out(sca_in(IER0, card) & (phy_node(port) ? 0x0F : 0xF0),
  437. IER0, card);
  438. /* disable DMA interrupts */
  439. sca_out(sca_in(IER1, card) & (phy_node(port) ? 0x0F : 0xF0),
  440. IER1, card);
  441. netif_stop_queue(dev);
  442. }
  443. static int sca_attach(struct net_device *dev, unsigned short encoding,
  444. unsigned short parity)
  445. {
  446. if (encoding != ENCODING_NRZ &&
  447. encoding != ENCODING_NRZI &&
  448. encoding != ENCODING_FM_MARK &&
  449. encoding != ENCODING_FM_SPACE &&
  450. encoding != ENCODING_MANCHESTER)
  451. return -EINVAL;
  452. if (parity != PARITY_NONE &&
  453. parity != PARITY_CRC16_PR0 &&
  454. parity != PARITY_CRC16_PR1 &&
  455. parity != PARITY_CRC16_PR0_CCITT &&
  456. parity != PARITY_CRC16_PR1_CCITT)
  457. return -EINVAL;
  458. dev_to_port(dev)->encoding = encoding;
  459. dev_to_port(dev)->parity = parity;
  460. return 0;
  461. }
  462. #ifdef DEBUG_RINGS
  463. static void sca_dump_rings(struct net_device *dev)
  464. {
  465. port_t *port = dev_to_port(dev);
  466. card_t *card = port_to_card(port);
  467. u16 cnt;
  468. #ifndef PAGE0_ALWAYS_MAPPED
  469. u8 page = sca_get_page(card);
  470. openwin(card, 0);
  471. #endif
  472. printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive",
  473. sca_inw(get_dmac_rx(port) + CDAL, card),
  474. sca_inw(get_dmac_rx(port) + EDAL, card),
  475. sca_in(DSR_RX(phy_node(port)), card), port->rxin,
  476. sca_in(DSR_RX(phy_node(port)), card) & DSR_DE ? "" : "in");
  477. for (cnt = 0; cnt < port_to_card(port)->rx_ring_buffers; cnt++)
  478. pr_cont(" %02X", readb(&(desc_address(port, cnt, 0)->stat)));
  479. pr_cont("\n");
  480. printk(KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u "
  481. "last=%u %sactive",
  482. sca_inw(get_dmac_tx(port) + CDAL, card),
  483. sca_inw(get_dmac_tx(port) + EDAL, card),
  484. sca_in(DSR_TX(phy_node(port)), card), port->txin, port->txlast,
  485. sca_in(DSR_TX(phy_node(port)), card) & DSR_DE ? "" : "in");
  486. for (cnt = 0; cnt < port_to_card(port)->tx_ring_buffers; cnt++)
  487. pr_cont(" %02X", readb(&(desc_address(port, cnt, 1)->stat)));
  488. pr_cont("\n");
  489. printk(KERN_DEBUG "MSCI: MD: %02x %02x %02x, ST: %02x %02x %02x %02x,"
  490. " FST: %02x CST: %02x %02x\n",
  491. sca_in(get_msci(port) + MD0, card),
  492. sca_in(get_msci(port) + MD1, card),
  493. sca_in(get_msci(port) + MD2, card),
  494. sca_in(get_msci(port) + ST0, card),
  495. sca_in(get_msci(port) + ST1, card),
  496. sca_in(get_msci(port) + ST2, card),
  497. sca_in(get_msci(port) + ST3, card),
  498. sca_in(get_msci(port) + FST, card),
  499. sca_in(get_msci(port) + CST0, card),
  500. sca_in(get_msci(port) + CST1, card));
  501. printk(KERN_DEBUG "ISR: %02x %02x %02x\n", sca_in(ISR0, card),
  502. sca_in(ISR1, card), sca_in(ISR2, card));
  503. #ifndef PAGE0_ALWAYS_MAPPED
  504. openwin(card, page); /* Restore original page */
  505. #endif
  506. }
  507. #endif /* DEBUG_RINGS */
  508. static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev)
  509. {
  510. port_t *port = dev_to_port(dev);
  511. card_t *card = port_to_card(port);
  512. pkt_desc __iomem *desc;
  513. u32 buff, len;
  514. u8 page;
  515. u32 maxlen;
  516. spin_lock_irq(&port->lock);
  517. desc = desc_address(port, port->txin + 1, 1);
  518. BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */
  519. #ifdef DEBUG_PKT
  520. printk(KERN_DEBUG "%s TX(%i):", dev->name, skb->len);
  521. debug_frame(skb);
  522. #endif
  523. desc = desc_address(port, port->txin, 1);
  524. buff = buffer_offset(port, port->txin, 1);
  525. len = skb->len;
  526. page = buff / winsize(card);
  527. buff = buff % winsize(card);
  528. maxlen = winsize(card) - buff;
  529. openwin(card, page);
  530. if (len > maxlen) {
  531. memcpy_toio(winbase(card) + buff, skb->data, maxlen);
  532. openwin(card, page + 1);
  533. memcpy_toio(winbase(card), skb->data + maxlen, len - maxlen);
  534. } else
  535. memcpy_toio(winbase(card) + buff, skb->data, len);
  536. #ifndef PAGE0_ALWAYS_MAPPED
  537. openwin(card, 0); /* select pkt_desc table page back */
  538. #endif
  539. writew(len, &desc->len);
  540. writeb(ST_TX_EOM, &desc->stat);
  541. port->txin = next_desc(port, port->txin, 1);
  542. sca_outw(desc_offset(port, port->txin, 1),
  543. get_dmac_tx(port) + EDAL, card);
  544. sca_out(DSR_DE, DSR_TX(phy_node(port)), card); /* Enable TX DMA */
  545. desc = desc_address(port, port->txin + 1, 1);
  546. if (readb(&desc->stat)) /* allow 1 packet gap */
  547. netif_stop_queue(dev);
  548. spin_unlock_irq(&port->lock);
  549. dev_kfree_skb(skb);
  550. return NETDEV_TX_OK;
  551. }
  552. #ifdef NEED_DETECT_RAM
  553. static u32 sca_detect_ram(card_t *card, u8 __iomem *rambase, u32 ramsize)
  554. {
  555. /* Round RAM size to 32 bits, fill from end to start */
  556. u32 i = ramsize &= ~3;
  557. u32 size = winsize(card);
  558. openwin(card, (i - 4) / size); /* select last window */
  559. do {
  560. i -= 4;
  561. if ((i + 4) % size == 0)
  562. openwin(card, i / size);
  563. writel(i ^ 0x12345678, rambase + i % size);
  564. } while (i > 0);
  565. for (i = 0; i < ramsize ; i += 4) {
  566. if (i % size == 0)
  567. openwin(card, i / size);
  568. if (readl(rambase + i % size) != (i ^ 0x12345678))
  569. break;
  570. }
  571. return i;
  572. }
  573. #endif /* NEED_DETECT_RAM */
  574. static void sca_init(card_t *card, int wait_states)
  575. {
  576. sca_out(wait_states, WCRL, card); /* Wait Control */
  577. sca_out(wait_states, WCRM, card);
  578. sca_out(wait_states, WCRH, card);
  579. sca_out(0, DMER, card); /* DMA Master disable */
  580. sca_out(0x03, PCR, card); /* DMA priority */
  581. sca_out(0, DSR_RX(0), card); /* DMA disable - to halt state */
  582. sca_out(0, DSR_TX(0), card);
  583. sca_out(0, DSR_RX(1), card);
  584. sca_out(0, DSR_TX(1), card);
  585. sca_out(DMER_DME, DMER, card); /* DMA Master enable */
  586. }