sonic.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * Header file for sonic.c
  3. *
  4. * (C) Waldorf Electronics, Germany
  5. * Written by Andreas Busse
  6. *
  7. * NOTE: most of the structure definitions here are endian dependent.
  8. * If you want to use this driver on big endian machines, the data
  9. * and pad structure members must be exchanged. Also, the structures
  10. * need to be changed accordingly to the bus size.
  11. *
  12. * 981229 MSch: did just that for the 68k Mac port (32 bit, big endian)
  13. *
  14. * 990611 David Huggins-Daines <dhd@debian.org>: This machine abstraction
  15. * does not cope with 16-bit bus sizes very well. Therefore I have
  16. * rewritten it with ugly macros and evil inlines.
  17. *
  18. * 050625 Finn Thain: introduced more 32-bit cards and dhd's support
  19. * for 16-bit cards (from the mac68k project).
  20. */
  21. #ifndef SONIC_H
  22. #define SONIC_H
  23. /*
  24. * SONIC register offsets
  25. */
  26. #define SONIC_CMD 0x00
  27. #define SONIC_DCR 0x01
  28. #define SONIC_RCR 0x02
  29. #define SONIC_TCR 0x03
  30. #define SONIC_IMR 0x04
  31. #define SONIC_ISR 0x05
  32. #define SONIC_UTDA 0x06
  33. #define SONIC_CTDA 0x07
  34. #define SONIC_URDA 0x0d
  35. #define SONIC_CRDA 0x0e
  36. #define SONIC_EOBC 0x13
  37. #define SONIC_URRA 0x14
  38. #define SONIC_RSA 0x15
  39. #define SONIC_REA 0x16
  40. #define SONIC_RRP 0x17
  41. #define SONIC_RWP 0x18
  42. #define SONIC_RSC 0x2b
  43. #define SONIC_CEP 0x21
  44. #define SONIC_CAP2 0x22
  45. #define SONIC_CAP1 0x23
  46. #define SONIC_CAP0 0x24
  47. #define SONIC_CE 0x25
  48. #define SONIC_CDP 0x26
  49. #define SONIC_CDC 0x27
  50. #define SONIC_WT0 0x29
  51. #define SONIC_WT1 0x2a
  52. #define SONIC_SR 0x28
  53. /* test-only registers */
  54. #define SONIC_TPS 0x08
  55. #define SONIC_TFC 0x09
  56. #define SONIC_TSA0 0x0a
  57. #define SONIC_TSA1 0x0b
  58. #define SONIC_TFS 0x0c
  59. #define SONIC_CRBA0 0x0f
  60. #define SONIC_CRBA1 0x10
  61. #define SONIC_RBWC0 0x11
  62. #define SONIC_RBWC1 0x12
  63. #define SONIC_TTDA 0x20
  64. #define SONIC_MDT 0x2f
  65. #define SONIC_TRBA0 0x19
  66. #define SONIC_TRBA1 0x1a
  67. #define SONIC_TBWC0 0x1b
  68. #define SONIC_TBWC1 0x1c
  69. #define SONIC_LLFA 0x1f
  70. #define SONIC_ADDR0 0x1d
  71. #define SONIC_ADDR1 0x1e
  72. /*
  73. * Error counters
  74. */
  75. #define SONIC_CRCT 0x2c
  76. #define SONIC_FAET 0x2d
  77. #define SONIC_MPT 0x2e
  78. #define SONIC_DCR2 0x3f
  79. /*
  80. * SONIC command bits
  81. */
  82. #define SONIC_CR_LCAM 0x0200
  83. #define SONIC_CR_RRRA 0x0100
  84. #define SONIC_CR_RST 0x0080
  85. #define SONIC_CR_ST 0x0020
  86. #define SONIC_CR_STP 0x0010
  87. #define SONIC_CR_RXEN 0x0008
  88. #define SONIC_CR_RXDIS 0x0004
  89. #define SONIC_CR_TXP 0x0002
  90. #define SONIC_CR_HTX 0x0001
  91. /*
  92. * SONIC data configuration bits
  93. */
  94. #define SONIC_DCR_EXBUS 0x8000
  95. #define SONIC_DCR_LBR 0x2000
  96. #define SONIC_DCR_PO1 0x1000
  97. #define SONIC_DCR_PO0 0x0800
  98. #define SONIC_DCR_SBUS 0x0400
  99. #define SONIC_DCR_USR1 0x0200
  100. #define SONIC_DCR_USR0 0x0100
  101. #define SONIC_DCR_WC1 0x0080
  102. #define SONIC_DCR_WC0 0x0040
  103. #define SONIC_DCR_DW 0x0020
  104. #define SONIC_DCR_BMS 0x0010
  105. #define SONIC_DCR_RFT1 0x0008
  106. #define SONIC_DCR_RFT0 0x0004
  107. #define SONIC_DCR_TFT1 0x0002
  108. #define SONIC_DCR_TFT0 0x0001
  109. /*
  110. * Constants for the SONIC receive control register.
  111. */
  112. #define SONIC_RCR_ERR 0x8000
  113. #define SONIC_RCR_RNT 0x4000
  114. #define SONIC_RCR_BRD 0x2000
  115. #define SONIC_RCR_PRO 0x1000
  116. #define SONIC_RCR_AMC 0x0800
  117. #define SONIC_RCR_LB1 0x0400
  118. #define SONIC_RCR_LB0 0x0200
  119. #define SONIC_RCR_MC 0x0100
  120. #define SONIC_RCR_BC 0x0080
  121. #define SONIC_RCR_LPKT 0x0040
  122. #define SONIC_RCR_CRS 0x0020
  123. #define SONIC_RCR_COL 0x0010
  124. #define SONIC_RCR_CRCR 0x0008
  125. #define SONIC_RCR_FAER 0x0004
  126. #define SONIC_RCR_LBK 0x0002
  127. #define SONIC_RCR_PRX 0x0001
  128. #define SONIC_RCR_LB_OFF 0
  129. #define SONIC_RCR_LB_MAC SONIC_RCR_LB0
  130. #define SONIC_RCR_LB_ENDEC SONIC_RCR_LB1
  131. #define SONIC_RCR_LB_TRANS (SONIC_RCR_LB0 | SONIC_RCR_LB1)
  132. /* default RCR setup */
  133. #define SONIC_RCR_DEFAULT (SONIC_RCR_BRD)
  134. /*
  135. * SONIC Transmit Control register bits
  136. */
  137. #define SONIC_TCR_PINTR 0x8000
  138. #define SONIC_TCR_POWC 0x4000
  139. #define SONIC_TCR_CRCI 0x2000
  140. #define SONIC_TCR_EXDIS 0x1000
  141. #define SONIC_TCR_EXD 0x0400
  142. #define SONIC_TCR_DEF 0x0200
  143. #define SONIC_TCR_NCRS 0x0100
  144. #define SONIC_TCR_CRLS 0x0080
  145. #define SONIC_TCR_EXC 0x0040
  146. #define SONIC_TCR_PMB 0x0008
  147. #define SONIC_TCR_FU 0x0004
  148. #define SONIC_TCR_BCM 0x0002
  149. #define SONIC_TCR_PTX 0x0001
  150. #define SONIC_TCR_DEFAULT 0x0000
  151. /*
  152. * Constants for the SONIC_INTERRUPT_MASK and
  153. * SONIC_INTERRUPT_STATUS registers.
  154. */
  155. #define SONIC_INT_BR 0x4000
  156. #define SONIC_INT_HBL 0x2000
  157. #define SONIC_INT_LCD 0x1000
  158. #define SONIC_INT_PINT 0x0800
  159. #define SONIC_INT_PKTRX 0x0400
  160. #define SONIC_INT_TXDN 0x0200
  161. #define SONIC_INT_TXER 0x0100
  162. #define SONIC_INT_TC 0x0080
  163. #define SONIC_INT_RDE 0x0040
  164. #define SONIC_INT_RBE 0x0020
  165. #define SONIC_INT_RBAE 0x0010
  166. #define SONIC_INT_CRC 0x0008
  167. #define SONIC_INT_FAE 0x0004
  168. #define SONIC_INT_MP 0x0002
  169. #define SONIC_INT_RFO 0x0001
  170. /*
  171. * The interrupts we allow.
  172. */
  173. #define SONIC_IMR_DEFAULT ( SONIC_INT_BR | \
  174. SONIC_INT_LCD | \
  175. SONIC_INT_RFO | \
  176. SONIC_INT_PKTRX | \
  177. SONIC_INT_TXDN | \
  178. SONIC_INT_TXER | \
  179. SONIC_INT_RDE | \
  180. SONIC_INT_RBAE | \
  181. SONIC_INT_CRC | \
  182. SONIC_INT_FAE | \
  183. SONIC_INT_MP)
  184. #define SONIC_EOL 0x0001
  185. #define CAM_DESCRIPTORS 16
  186. /* Offsets in the various DMA buffers accessed by the SONIC */
  187. #define SONIC_BITMODE16 0
  188. #define SONIC_BITMODE32 1
  189. #define SONIC_BUS_SCALE(bitmode) ((bitmode) ? 4 : 2)
  190. /* Note! These are all measured in bus-size units, so use SONIC_BUS_SCALE */
  191. #define SIZEOF_SONIC_RR 4
  192. #define SONIC_RR_BUFADR_L 0
  193. #define SONIC_RR_BUFADR_H 1
  194. #define SONIC_RR_BUFSIZE_L 2
  195. #define SONIC_RR_BUFSIZE_H 3
  196. #define SIZEOF_SONIC_RD 7
  197. #define SONIC_RD_STATUS 0
  198. #define SONIC_RD_PKTLEN 1
  199. #define SONIC_RD_PKTPTR_L 2
  200. #define SONIC_RD_PKTPTR_H 3
  201. #define SONIC_RD_SEQNO 4
  202. #define SONIC_RD_LINK 5
  203. #define SONIC_RD_IN_USE 6
  204. #define SIZEOF_SONIC_TD 8
  205. #define SONIC_TD_STATUS 0
  206. #define SONIC_TD_CONFIG 1
  207. #define SONIC_TD_PKTSIZE 2
  208. #define SONIC_TD_FRAG_COUNT 3
  209. #define SONIC_TD_FRAG_PTR_L 4
  210. #define SONIC_TD_FRAG_PTR_H 5
  211. #define SONIC_TD_FRAG_SIZE 6
  212. #define SONIC_TD_LINK 7
  213. #define SIZEOF_SONIC_CD 4
  214. #define SONIC_CD_ENTRY_POINTER 0
  215. #define SONIC_CD_CAP0 1
  216. #define SONIC_CD_CAP1 2
  217. #define SONIC_CD_CAP2 3
  218. #define SIZEOF_SONIC_CDA ((CAM_DESCRIPTORS * SIZEOF_SONIC_CD) + 1)
  219. #define SONIC_CDA_CAM_ENABLE (CAM_DESCRIPTORS * SIZEOF_SONIC_CD)
  220. /*
  221. * Some tunables for the buffer areas. Power of 2 is required
  222. * the current driver uses one receive buffer for each descriptor.
  223. *
  224. * MSch: use more buffer space for the slow m68k Macs!
  225. */
  226. #define SONIC_NUM_RRS 16 /* number of receive resources */
  227. #define SONIC_NUM_RDS SONIC_NUM_RRS /* number of receive descriptors */
  228. #define SONIC_NUM_TDS 16 /* number of transmit descriptors */
  229. #define SONIC_RDS_MASK (SONIC_NUM_RDS-1)
  230. #define SONIC_TDS_MASK (SONIC_NUM_TDS-1)
  231. #define SONIC_RBSIZE 1520 /* size of one resource buffer */
  232. /* Again, measured in bus size units! */
  233. #define SIZEOF_SONIC_DESC (SIZEOF_SONIC_CDA \
  234. + (SIZEOF_SONIC_TD * SONIC_NUM_TDS) \
  235. + (SIZEOF_SONIC_RD * SONIC_NUM_RDS) \
  236. + (SIZEOF_SONIC_RR * SONIC_NUM_RRS))
  237. /* Information that need to be kept for each board. */
  238. struct sonic_local {
  239. /* Bus size. 0 == 16 bits, 1 == 32 bits. */
  240. int dma_bitmode;
  241. /* Register offset within the longword (independent of endianness,
  242. and varies from one type of Macintosh SONIC to another
  243. (Aarrgh)) */
  244. int reg_offset;
  245. void *descriptors;
  246. /* Crud. These areas have to be within the same 64K. Therefore
  247. we allocate a desriptors page, and point these to places within it. */
  248. void *cda; /* CAM descriptor area */
  249. void *tda; /* Transmit descriptor area */
  250. void *rra; /* Receive resource area */
  251. void *rda; /* Receive descriptor area */
  252. struct sk_buff* volatile rx_skb[SONIC_NUM_RRS]; /* packets to be received */
  253. struct sk_buff* volatile tx_skb[SONIC_NUM_TDS]; /* packets to be transmitted */
  254. unsigned int tx_len[SONIC_NUM_TDS]; /* lengths of tx DMA mappings */
  255. /* Logical DMA addresses on MIPS, bus addresses on m68k
  256. * (so "laddr" is a bit misleading) */
  257. dma_addr_t descriptors_laddr;
  258. u32 cda_laddr; /* logical DMA address of CDA */
  259. u32 tda_laddr; /* logical DMA address of TDA */
  260. u32 rra_laddr; /* logical DMA address of RRA */
  261. u32 rda_laddr; /* logical DMA address of RDA */
  262. dma_addr_t rx_laddr[SONIC_NUM_RRS]; /* logical DMA addresses of rx skbuffs */
  263. dma_addr_t tx_laddr[SONIC_NUM_TDS]; /* logical DMA addresses of tx skbuffs */
  264. unsigned int rra_end;
  265. unsigned int cur_rwp;
  266. unsigned int cur_rx;
  267. unsigned int cur_tx; /* first unacked transmit packet */
  268. unsigned int eol_rx;
  269. unsigned int eol_tx; /* last unacked transmit packet */
  270. unsigned int next_tx; /* next free TD */
  271. struct device *device; /* generic device */
  272. struct net_device_stats stats;
  273. };
  274. #define TX_TIMEOUT (3 * HZ)
  275. /* Index to functions, as function prototypes. */
  276. static int sonic_open(struct net_device *dev);
  277. static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev);
  278. static irqreturn_t sonic_interrupt(int irq, void *dev_id);
  279. static void sonic_rx(struct net_device *dev);
  280. static int sonic_close(struct net_device *dev);
  281. static struct net_device_stats *sonic_get_stats(struct net_device *dev);
  282. static void sonic_multicast_list(struct net_device *dev);
  283. static int sonic_init(struct net_device *dev);
  284. static void sonic_tx_timeout(struct net_device *dev);
  285. /* Internal inlines for reading/writing DMA buffers. Note that bus
  286. size and endianness matter here, whereas they don't for registers,
  287. as far as we can tell. */
  288. /* OpenBSD calls this "SWO". I'd like to think that sonic_buf_put()
  289. is a much better name. */
  290. static inline void sonic_buf_put(void* base, int bitmode,
  291. int offset, __u16 val)
  292. {
  293. if (bitmode)
  294. #ifdef __BIG_ENDIAN
  295. ((__u16 *) base + (offset*2))[1] = val;
  296. #else
  297. ((__u16 *) base + (offset*2))[0] = val;
  298. #endif
  299. else
  300. ((__u16 *) base)[offset] = val;
  301. }
  302. static inline __u16 sonic_buf_get(void* base, int bitmode,
  303. int offset)
  304. {
  305. if (bitmode)
  306. #ifdef __BIG_ENDIAN
  307. return ((volatile __u16 *) base + (offset*2))[1];
  308. #else
  309. return ((volatile __u16 *) base + (offset*2))[0];
  310. #endif
  311. else
  312. return ((volatile __u16 *) base)[offset];
  313. }
  314. /* Inlines that you should actually use for reading/writing DMA buffers */
  315. static inline void sonic_cda_put(struct net_device* dev, int entry,
  316. int offset, __u16 val)
  317. {
  318. struct sonic_local *lp = netdev_priv(dev);
  319. sonic_buf_put(lp->cda, lp->dma_bitmode,
  320. (entry * SIZEOF_SONIC_CD) + offset, val);
  321. }
  322. static inline __u16 sonic_cda_get(struct net_device* dev, int entry,
  323. int offset)
  324. {
  325. struct sonic_local *lp = netdev_priv(dev);
  326. return sonic_buf_get(lp->cda, lp->dma_bitmode,
  327. (entry * SIZEOF_SONIC_CD) + offset);
  328. }
  329. static inline void sonic_set_cam_enable(struct net_device* dev, __u16 val)
  330. {
  331. struct sonic_local *lp = netdev_priv(dev);
  332. sonic_buf_put(lp->cda, lp->dma_bitmode, SONIC_CDA_CAM_ENABLE, val);
  333. }
  334. static inline __u16 sonic_get_cam_enable(struct net_device* dev)
  335. {
  336. struct sonic_local *lp = netdev_priv(dev);
  337. return sonic_buf_get(lp->cda, lp->dma_bitmode, SONIC_CDA_CAM_ENABLE);
  338. }
  339. static inline void sonic_tda_put(struct net_device* dev, int entry,
  340. int offset, __u16 val)
  341. {
  342. struct sonic_local *lp = netdev_priv(dev);
  343. sonic_buf_put(lp->tda, lp->dma_bitmode,
  344. (entry * SIZEOF_SONIC_TD) + offset, val);
  345. }
  346. static inline __u16 sonic_tda_get(struct net_device* dev, int entry,
  347. int offset)
  348. {
  349. struct sonic_local *lp = netdev_priv(dev);
  350. return sonic_buf_get(lp->tda, lp->dma_bitmode,
  351. (entry * SIZEOF_SONIC_TD) + offset);
  352. }
  353. static inline void sonic_rda_put(struct net_device* dev, int entry,
  354. int offset, __u16 val)
  355. {
  356. struct sonic_local *lp = netdev_priv(dev);
  357. sonic_buf_put(lp->rda, lp->dma_bitmode,
  358. (entry * SIZEOF_SONIC_RD) + offset, val);
  359. }
  360. static inline __u16 sonic_rda_get(struct net_device* dev, int entry,
  361. int offset)
  362. {
  363. struct sonic_local *lp = netdev_priv(dev);
  364. return sonic_buf_get(lp->rda, lp->dma_bitmode,
  365. (entry * SIZEOF_SONIC_RD) + offset);
  366. }
  367. static inline void sonic_rra_put(struct net_device* dev, int entry,
  368. int offset, __u16 val)
  369. {
  370. struct sonic_local *lp = netdev_priv(dev);
  371. sonic_buf_put(lp->rra, lp->dma_bitmode,
  372. (entry * SIZEOF_SONIC_RR) + offset, val);
  373. }
  374. static inline __u16 sonic_rra_get(struct net_device* dev, int entry,
  375. int offset)
  376. {
  377. struct sonic_local *lp = netdev_priv(dev);
  378. return sonic_buf_get(lp->rra, lp->dma_bitmode,
  379. (entry * SIZEOF_SONIC_RR) + offset);
  380. }
  381. static const char *version =
  382. "sonic.c:v0.92 20.9.98 tsbogend@alpha.franken.de\n";
  383. #endif /* SONIC_H */