tsi108_eth.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /***********************************************************************
  2. *
  3. * Copyright (c) 2005 Freescale Semiconductor, Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  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 as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. * Description:
  24. * Ethernet interface for Tundra TSI108 bridge chip
  25. *
  26. ***********************************************************************/
  27. #include <config.h>
  28. #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI) \
  29. && defined(CONFIG_TSI108_ETH)
  30. #if !defined(CONFIG_TSI108_ETH_NUM_PORTS) || (CONFIG_TSI108_ETH_NUM_PORTS > 2)
  31. #error "CONFIG_TSI108_ETH_NUM_PORTS must be defined as 1 or 2"
  32. #endif
  33. #include <common.h>
  34. #include <malloc.h>
  35. #include <net.h>
  36. #include <asm/cache.h>
  37. #ifdef DEBUG
  38. #define TSI108_ETH_DEBUG 7
  39. #else
  40. #define TSI108_ETH_DEBUG 0
  41. #endif
  42. #if TSI108_ETH_DEBUG > 0
  43. #define debug_lev(lev, fmt, args...) \
  44. if (lev <= TSI108_ETH_DEBUG) \
  45. printf ("%s %d: " fmt, __FUNCTION__, __LINE__, ##args)
  46. #else
  47. #define debug_lev(lev, fmt, args...) do{}while(0)
  48. #endif
  49. #define RX_PRINT_ERRORS
  50. #define TX_PRINT_ERRORS
  51. #define ETH_BASE (CFG_TSI108_CSR_BASE + 0x6000)
  52. #define ETH_PORT_OFFSET 0x400
  53. #define __REG32(base, offset) (*((volatile u32 *)((char *)(base) + (offset))))
  54. #define reg_MAC_CONFIG_1(base) __REG32(base, 0x00000000)
  55. #define MAC_CONFIG_1_TX_ENABLE (0x00000001)
  56. #define MAC_CONFIG_1_SYNC_TX_ENABLE (0x00000002)
  57. #define MAC_CONFIG_1_RX_ENABLE (0x00000004)
  58. #define MAC_CONFIG_1_SYNC_RX_ENABLE (0x00000008)
  59. #define MAC_CONFIG_1_TX_FLOW_CONTROL (0x00000010)
  60. #define MAC_CONFIG_1_RX_FLOW_CONTROL (0x00000020)
  61. #define MAC_CONFIG_1_LOOP_BACK (0x00000100)
  62. #define MAC_CONFIG_1_RESET_TX_FUNCTION (0x00010000)
  63. #define MAC_CONFIG_1_RESET_RX_FUNCTION (0x00020000)
  64. #define MAC_CONFIG_1_RESET_TX_MAC (0x00040000)
  65. #define MAC_CONFIG_1_RESET_RX_MAC (0x00080000)
  66. #define MAC_CONFIG_1_SIM_RESET (0x40000000)
  67. #define MAC_CONFIG_1_SOFT_RESET (0x80000000)
  68. #define reg_MAC_CONFIG_2(base) __REG32(base, 0x00000004)
  69. #define MAC_CONFIG_2_FULL_DUPLEX (0x00000001)
  70. #define MAC_CONFIG_2_CRC_ENABLE (0x00000002)
  71. #define MAC_CONFIG_2_PAD_CRC (0x00000004)
  72. #define MAC_CONFIG_2_LENGTH_CHECK (0x00000010)
  73. #define MAC_CONFIG_2_HUGE_FRAME (0x00000020)
  74. #define MAC_CONFIG_2_INTERFACE_MODE(val) (((val) & 0x3) << 8)
  75. #define MAC_CONFIG_2_PREAMBLE_LENGTH(val) (((val) & 0xf) << 12)
  76. #define INTERFACE_MODE_NIBBLE 1 /* 10/100 Mb/s MII) */
  77. #define INTERFACE_MODE_BYTE 2 /* 1000 Mb/s GMII/TBI */
  78. #define reg_MAXIMUM_FRAME_LENGTH(base) __REG32(base, 0x00000010)
  79. #define reg_MII_MGMT_CONFIG(base) __REG32(base, 0x00000020)
  80. #define MII_MGMT_CONFIG_MGMT_CLOCK_SELECT(val) ((val) & 0x7)
  81. #define MII_MGMT_CONFIG_NO_PREAMBLE (0x00000010)
  82. #define MII_MGMT_CONFIG_SCAN_INCREMENT (0x00000020)
  83. #define MII_MGMT_CONFIG_RESET_MGMT (0x80000000)
  84. #define reg_MII_MGMT_COMMAND(base) __REG32(base, 0x00000024)
  85. #define MII_MGMT_COMMAND_READ_CYCLE (0x00000001)
  86. #define MII_MGMT_COMMAND_SCAN_CYCLE (0x00000002)
  87. #define reg_MII_MGMT_ADDRESS(base) __REG32(base, 0x00000028)
  88. #define reg_MII_MGMT_CONTROL(base) __REG32(base, 0x0000002c)
  89. #define reg_MII_MGMT_STATUS(base) __REG32(base, 0x00000030)
  90. #define reg_MII_MGMT_INDICATORS(base) __REG32(base, 0x00000034)
  91. #define MII_MGMT_INDICATORS_BUSY (0x00000001)
  92. #define MII_MGMT_INDICATORS_SCAN (0x00000002)
  93. #define MII_MGMT_INDICATORS_NOT_VALID (0x00000004)
  94. #define reg_INTERFACE_STATUS(base) __REG32(base, 0x0000003c)
  95. #define INTERFACE_STATUS_LINK_FAIL (0x00000008)
  96. #define INTERFACE_STATUS_EXCESS_DEFER (0x00000200)
  97. #define reg_STATION_ADDRESS_1(base) __REG32(base, 0x00000040)
  98. #define reg_STATION_ADDRESS_2(base) __REG32(base, 0x00000044)
  99. #define reg_PORT_CONTROL(base) __REG32(base, 0x00000200)
  100. #define PORT_CONTROL_PRI (0x00000001)
  101. #define PORT_CONTROL_BPT (0x00010000)
  102. #define PORT_CONTROL_SPD (0x00040000)
  103. #define PORT_CONTROL_RBC (0x00080000)
  104. #define PORT_CONTROL_PRB (0x00200000)
  105. #define PORT_CONTROL_DIS (0x00400000)
  106. #define PORT_CONTROL_TBI (0x00800000)
  107. #define PORT_CONTROL_STE (0x10000000)
  108. #define PORT_CONTROL_ZOR (0x20000000)
  109. #define PORT_CONTROL_CLR (0x40000000)
  110. #define PORT_CONTROL_SRT (0x80000000)
  111. #define reg_TX_CONFIG(base) __REG32(base, 0x00000220)
  112. #define TX_CONFIG_START_Q (0x00000003)
  113. #define TX_CONFIG_EHP (0x00400000)
  114. #define TX_CONFIG_CHP (0x00800000)
  115. #define TX_CONFIG_RST (0x80000000)
  116. #define reg_TX_CONTROL(base) __REG32(base, 0x00000224)
  117. #define TX_CONTROL_GO (0x00008000)
  118. #define TX_CONTROL_MP (0x01000000)
  119. #define TX_CONTROL_EAI (0x20000000)
  120. #define TX_CONTROL_ABT (0x40000000)
  121. #define TX_CONTROL_EII (0x80000000)
  122. #define reg_TX_STATUS(base) __REG32(base, 0x00000228)
  123. #define TX_STATUS_QUEUE_USABLE (0x0000000f)
  124. #define TX_STATUS_CURR_Q (0x00000300)
  125. #define TX_STATUS_ACT (0x00008000)
  126. #define TX_STATUS_QUEUE_IDLE (0x000f0000)
  127. #define TX_STATUS_EOQ_PENDING (0x0f000000)
  128. #define reg_TX_EXTENDED_STATUS(base) __REG32(base, 0x0000022c)
  129. #define TX_EXTENDED_STATUS_END_OF_QUEUE_CONDITION (0x0000000f)
  130. #define TX_EXTENDED_STATUS_END_OF_FRAME_CONDITION (0x00000f00)
  131. #define TX_EXTENDED_STATUS_DESCRIPTOR_INTERRUPT_CONDITION (0x000f0000)
  132. #define TX_EXTENDED_STATUS_ERROR_FLAG (0x0f000000)
  133. #define reg_TX_THRESHOLDS(base) __REG32(base, 0x00000230)
  134. #define reg_TX_DIAGNOSTIC_ADDR(base) __REG32(base, 0x00000270)
  135. #define TX_DIAGNOSTIC_ADDR_INDEX (0x0000007f)
  136. #define TX_DIAGNOSTIC_ADDR_DFR (0x40000000)
  137. #define TX_DIAGNOSTIC_ADDR_AI (0x80000000)
  138. #define reg_TX_DIAGNOSTIC_DATA(base) __REG32(base, 0x00000274)
  139. #define reg_TX_ERROR_STATUS(base) __REG32(base, 0x00000278)
  140. #define TX_ERROR_STATUS (0x00000278)
  141. #define TX_ERROR_STATUS_QUEUE_0_ERROR_RESPONSE (0x0000000f)
  142. #define TX_ERROR_STATUS_TEA_ON_QUEUE_0 (0x00000010)
  143. #define TX_ERROR_STATUS_RER_ON_QUEUE_0 (0x00000020)
  144. #define TX_ERROR_STATUS_TER_ON_QUEUE_0 (0x00000040)
  145. #define TX_ERROR_STATUS_DER_ON_QUEUE_0 (0x00000080)
  146. #define TX_ERROR_STATUS_QUEUE_1_ERROR_RESPONSE (0x00000f00)
  147. #define TX_ERROR_STATUS_TEA_ON_QUEUE_1 (0x00001000)
  148. #define TX_ERROR_STATUS_RER_ON_QUEUE_1 (0x00002000)
  149. #define TX_ERROR_STATUS_TER_ON_QUEUE_1 (0x00004000)
  150. #define TX_ERROR_STATUS_DER_ON_QUEUE_1 (0x00008000)
  151. #define TX_ERROR_STATUS_QUEUE_2_ERROR_RESPONSE (0x000f0000)
  152. #define TX_ERROR_STATUS_TEA_ON_QUEUE_2 (0x00100000)
  153. #define TX_ERROR_STATUS_RER_ON_QUEUE_2 (0x00200000)
  154. #define TX_ERROR_STATUS_TER_ON_QUEUE_2 (0x00400000)
  155. #define TX_ERROR_STATUS_DER_ON_QUEUE_2 (0x00800000)
  156. #define TX_ERROR_STATUS_QUEUE_3_ERROR_RESPONSE (0x0f000000)
  157. #define TX_ERROR_STATUS_TEA_ON_QUEUE_3 (0x10000000)
  158. #define TX_ERROR_STATUS_RER_ON_QUEUE_3 (0x20000000)
  159. #define TX_ERROR_STATUS_TER_ON_QUEUE_3 (0x40000000)
  160. #define TX_ERROR_STATUS_DER_ON_QUEUE_3 (0x80000000)
  161. #define reg_TX_QUEUE_0_CONFIG(base) __REG32(base, 0x00000280)
  162. #define TX_QUEUE_0_CONFIG_OCN_PORT (0x0000003f)
  163. #define TX_QUEUE_0_CONFIG_BSWP (0x00000400)
  164. #define TX_QUEUE_0_CONFIG_WSWP (0x00000800)
  165. #define TX_QUEUE_0_CONFIG_AM (0x00004000)
  166. #define TX_QUEUE_0_CONFIG_GVI (0x00008000)
  167. #define TX_QUEUE_0_CONFIG_EEI (0x00010000)
  168. #define TX_QUEUE_0_CONFIG_ELI (0x00020000)
  169. #define TX_QUEUE_0_CONFIG_ENI (0x00040000)
  170. #define TX_QUEUE_0_CONFIG_ESI (0x00080000)
  171. #define TX_QUEUE_0_CONFIG_EDI (0x00100000)
  172. #define reg_TX_QUEUE_0_BUF_CONFIG(base) __REG32(base, 0x00000284)
  173. #define TX_QUEUE_0_BUF_CONFIG_OCN_PORT (0x0000003f)
  174. #define TX_QUEUE_0_BUF_CONFIG_BURST (0x00000300)
  175. #define TX_QUEUE_0_BUF_CONFIG_BSWP (0x00000400)
  176. #define TX_QUEUE_0_BUF_CONFIG_WSWP (0x00000800)
  177. #define OCN_PORT_HLP 0 /* HLP Interface */
  178. #define OCN_PORT_PCI_X 1 /* PCI-X Interface */
  179. #define OCN_PORT_PROCESSOR_MASTER 2 /* Processor Interface (master) */
  180. #define OCN_PORT_PROCESSOR_SLAVE 3 /* Processor Interface (slave) */
  181. #define OCN_PORT_MEMORY 4 /* Memory Controller */
  182. #define OCN_PORT_DMA 5 /* DMA Controller */
  183. #define OCN_PORT_ETHERNET 6 /* Ethernet Controller */
  184. #define OCN_PORT_PRINT 7 /* Print Engine Interface */
  185. #define reg_TX_QUEUE_0_PTR_LOW(base) __REG32(base, 0x00000288)
  186. #define reg_TX_QUEUE_0_PTR_HIGH(base) __REG32(base, 0x0000028c)
  187. #define TX_QUEUE_0_PTR_HIGH_VALID (0x80000000)
  188. #define reg_RX_CONFIG(base) __REG32(base, 0x00000320)
  189. #define RX_CONFIG_DEF_Q (0x00000003)
  190. #define RX_CONFIG_EMF (0x00000100)
  191. #define RX_CONFIG_EUF (0x00000200)
  192. #define RX_CONFIG_BFE (0x00000400)
  193. #define RX_CONFIG_MFE (0x00000800)
  194. #define RX_CONFIG_UFE (0x00001000)
  195. #define RX_CONFIG_SE (0x00002000)
  196. #define RX_CONFIG_ABF (0x00200000)
  197. #define RX_CONFIG_APE (0x00400000)
  198. #define RX_CONFIG_CHP (0x00800000)
  199. #define RX_CONFIG_RST (0x80000000)
  200. #define reg_RX_CONTROL(base) __REG32(base, 0x00000324)
  201. #define GE_E0_RX_CONTROL_QUEUE_ENABLES (0x0000000f)
  202. #define GE_E0_RX_CONTROL_GO (0x00008000)
  203. #define GE_E0_RX_CONTROL_EAI (0x20000000)
  204. #define GE_E0_RX_CONTROL_ABT (0x40000000)
  205. #define GE_E0_RX_CONTROL_EII (0x80000000)
  206. #define reg_RX_EXTENDED_STATUS(base) __REG32(base, 0x0000032c)
  207. #define RX_EXTENDED_STATUS (0x0000032c)
  208. #define RX_EXTENDED_STATUS_EOQ (0x0000000f)
  209. #define RX_EXTENDED_STATUS_EOQ_0 (0x00000001)
  210. #define RX_EXTENDED_STATUS_EOF (0x00000f00)
  211. #define RX_EXTENDED_STATUS_DESCRIPTOR_INTERRUPT_CONDITION (0x000f0000)
  212. #define RX_EXTENDED_STATUS_ERROR_FLAG (0x0f000000)
  213. #define reg_RX_THRESHOLDS(base) __REG32(base, 0x00000330)
  214. #define reg_RX_DIAGNOSTIC_ADDR(base) __REG32(base, 0x00000370)
  215. #define RX_DIAGNOSTIC_ADDR_INDEX (0x0000007f)
  216. #define RX_DIAGNOSTIC_ADDR_DFR (0x40000000)
  217. #define RX_DIAGNOSTIC_ADDR_AI (0x80000000)
  218. #define reg_RX_DIAGNOSTIC_DATA(base) __REG32(base, 0x00000374)
  219. #define reg_RX_QUEUE_0_CONFIG(base) __REG32(base, 0x00000380)
  220. #define RX_QUEUE_0_CONFIG_OCN_PORT (0x0000003f)
  221. #define RX_QUEUE_0_CONFIG_BSWP (0x00000400)
  222. #define RX_QUEUE_0_CONFIG_WSWP (0x00000800)
  223. #define RX_QUEUE_0_CONFIG_AM (0x00004000)
  224. #define RX_QUEUE_0_CONFIG_EEI (0x00010000)
  225. #define RX_QUEUE_0_CONFIG_ELI (0x00020000)
  226. #define RX_QUEUE_0_CONFIG_ENI (0x00040000)
  227. #define RX_QUEUE_0_CONFIG_ESI (0x00080000)
  228. #define RX_QUEUE_0_CONFIG_EDI (0x00100000)
  229. #define reg_RX_QUEUE_0_BUF_CONFIG(base) __REG32(base, 0x00000384)
  230. #define RX_QUEUE_0_BUF_CONFIG_OCN_PORT (0x0000003f)
  231. #define RX_QUEUE_0_BUF_CONFIG_BURST (0x00000300)
  232. #define RX_QUEUE_0_BUF_CONFIG_BSWP (0x00000400)
  233. #define RX_QUEUE_0_BUF_CONFIG_WSWP (0x00000800)
  234. #define reg_RX_QUEUE_0_PTR_LOW(base) __REG32(base, 0x00000388)
  235. #define reg_RX_QUEUE_0_PTR_HIGH(base) __REG32(base, 0x0000038c)
  236. #define RX_QUEUE_0_PTR_HIGH_VALID (0x80000000)
  237. /*
  238. * PHY register definitions
  239. */
  240. /* the first 15 PHY registers are standard. */
  241. #define PHY_CTRL_REG 0 /* Control Register */
  242. #define PHY_STATUS_REG 1 /* Status Regiser */
  243. #define PHY_ID1_REG 2 /* Phy Id Reg (word 1) */
  244. #define PHY_ID2_REG 3 /* Phy Id Reg (word 2) */
  245. #define PHY_AN_ADV_REG 4 /* Autoneg Advertisement */
  246. #define PHY_LP_ABILITY_REG 5 /* Link Partner Ability (Base Page) */
  247. #define PHY_AUTONEG_EXP_REG 6 /* Autoneg Expansion Reg */
  248. #define PHY_NEXT_PAGE_TX_REG 7 /* Next Page TX */
  249. #define PHY_LP_NEXT_PAGE_REG 8 /* Link Partner Next Page */
  250. #define PHY_1000T_CTRL_REG 9 /* 1000Base-T Control Reg */
  251. #define PHY_1000T_STATUS_REG 10 /* 1000Base-T Status Reg */
  252. #define PHY_EXT_STATUS_REG 11 /* Extended Status Reg */
  253. /*
  254. * PHY Register bit masks.
  255. */
  256. #define PHY_CTRL_RESET (1 << 15)
  257. #define PHY_CTRL_LOOPBACK (1 << 14)
  258. #define PHY_CTRL_SPEED0 (1 << 13)
  259. #define PHY_CTRL_AN_EN (1 << 12)
  260. #define PHY_CTRL_PWR_DN (1 << 11)
  261. #define PHY_CTRL_ISOLATE (1 << 10)
  262. #define PHY_CTRL_RESTART_AN (1 << 9)
  263. #define PHY_CTRL_FULL_DUPLEX (1 << 8)
  264. #define PHY_CTRL_CT_EN (1 << 7)
  265. #define PHY_CTRL_SPEED1 (1 << 6)
  266. #define PHY_STAT_100BASE_T4 (1 << 15)
  267. #define PHY_STAT_100BASE_X_FD (1 << 14)
  268. #define PHY_STAT_100BASE_X_HD (1 << 13)
  269. #define PHY_STAT_10BASE_T_FD (1 << 12)
  270. #define PHY_STAT_10BASE_T_HD (1 << 11)
  271. #define PHY_STAT_100BASE_T2_FD (1 << 10)
  272. #define PHY_STAT_100BASE_T2_HD (1 << 9)
  273. #define PHY_STAT_EXT_STAT (1 << 8)
  274. #define PHY_STAT_RESERVED (1 << 7)
  275. #define PHY_STAT_MFPS (1 << 6) /* Management Frames Preamble Suppression */
  276. #define PHY_STAT_AN_COMPLETE (1 << 5)
  277. #define PHY_STAT_REM_FAULT (1 << 4)
  278. #define PHY_STAT_AN_CAP (1 << 3)
  279. #define PHY_STAT_LINK_UP (1 << 2)
  280. #define PHY_STAT_JABBER (1 << 1)
  281. #define PHY_STAT_EXT_CAP (1 << 0)
  282. #define TBI_CONTROL_2 0x11
  283. #define TBI_CONTROL_2_ENABLE_COMMA_DETECT 0x0001
  284. #define TBI_CONTROL_2_ENABLE_WRAP 0x0002
  285. #define TBI_CONTROL_2_G_MII_MODE 0x0010
  286. #define TBI_CONTROL_2_RECEIVE_CLOCK_SELECT 0x0020
  287. #define TBI_CONTROL_2_AUTO_NEGOTIATION_SENSE 0x0100
  288. #define TBI_CONTROL_2_DISABLE_TRANSMIT_RUNNING_DISPARITY 0x1000
  289. #define TBI_CONTROL_2_DISABLE_RECEIVE_RUNNING_DISPARITY 0x2000
  290. #define TBI_CONTROL_2_SHORTCUT_LINK_TIMER 0x4000
  291. #define TBI_CONTROL_2_SOFT_RESET 0x8000
  292. /* marvel specific */
  293. #define MV1111_EXT_CTRL1_REG 16 /* PHY Specific Control Reg */
  294. #define MV1111_SPEC_STAT_REG 17 /* PHY Specific Status Reg */
  295. #define MV1111_EXT_CTRL2_REG 20 /* Extended PHY Specific Control Reg */
  296. /*
  297. * MARVELL 88E1111 PHY register bit masks
  298. */
  299. /* PHY Specific Status Register (MV1111_EXT_CTRL1_REG) */
  300. #define SPEC_STAT_SPEED_MASK (3 << 14)
  301. #define SPEC_STAT_FULL_DUP (1 << 13)
  302. #define SPEC_STAT_PAGE_RCVD (1 << 12)
  303. #define SPEC_STAT_RESOLVED (1 << 11) /* Speed and Duplex Resolved */
  304. #define SPEC_STAT_LINK_UP (1 << 10)
  305. #define SPEC_STAT_CABLE_LEN_MASK (7 << 7)/* Cable Length (100/1000 modes only) */
  306. #define SPEC_STAT_MDIX (1 << 6)
  307. #define SPEC_STAT_POLARITY (1 << 1)
  308. #define SPEC_STAT_JABBER (1 << 0)
  309. #define SPEED_1000 (2 << 14)
  310. #define SPEED_100 (1 << 14)
  311. #define SPEED_10 (0 << 14)
  312. #define TBI_ADDR 0x1E /* Ten Bit Interface address */
  313. /* negotiated link parameters */
  314. #define LINK_SPEED_UNKNOWN 0
  315. #define LINK_SPEED_10 1
  316. #define LINK_SPEED_100 2
  317. #define LINK_SPEED_1000 3
  318. #define LINK_DUPLEX_UNKNOWN 0
  319. #define LINK_DUPLEX_HALF 1
  320. #define LINK_DUPLEX_FULL 2
  321. static unsigned int phy_address[] = { 8, 9 };
  322. #define vuint32 volatile u32
  323. /* TX/RX buffer descriptors. MUST be cache line aligned in memory. (32 byte)
  324. * This structure is accessed by the ethernet DMA engine which means it
  325. * MUST be in LITTLE ENDIAN format */
  326. struct dma_descriptor {
  327. vuint32 start_addr0; /* buffer address, least significant bytes. */
  328. vuint32 start_addr1; /* buffer address, most significant bytes. */
  329. vuint32 next_descr_addr0;/* next descriptor address, least significant bytes. Must be 64-bit aligned. */
  330. vuint32 next_descr_addr1;/* next descriptor address, most significant bytes. */
  331. vuint32 vlan_byte_count;/* VLAN tag(top 2 bytes) and byte countt (bottom 2 bytes). */
  332. vuint32 config_status; /* Configuration/Status. */
  333. vuint32 reserved1; /* reserved to make the descriptor cache line aligned. */
  334. vuint32 reserved2; /* reserved to make the descriptor cache line aligned. */
  335. };
  336. /* last next descriptor address flag */
  337. #define DMA_DESCR_LAST (1 << 31)
  338. /* TX DMA descriptor config status bits */
  339. #define DMA_DESCR_TX_EOF (1 << 0) /* end of frame */
  340. #define DMA_DESCR_TX_SOF (1 << 1) /* start of frame */
  341. #define DMA_DESCR_TX_PFVLAN (1 << 2)
  342. #define DMA_DESCR_TX_HUGE (1 << 3)
  343. #define DMA_DESCR_TX_PAD (1 << 4)
  344. #define DMA_DESCR_TX_CRC (1 << 5)
  345. #define DMA_DESCR_TX_DESCR_INT (1 << 14)
  346. #define DMA_DESCR_TX_RETRY_COUNT 0x000F0000
  347. #define DMA_DESCR_TX_ONE_COLLISION (1 << 20)
  348. #define DMA_DESCR_TX_LATE_COLLISION (1 << 24)
  349. #define DMA_DESCR_TX_UNDERRUN (1 << 25)
  350. #define DMA_DESCR_TX_RETRY_LIMIT (1 << 26)
  351. #define DMA_DESCR_TX_OK (1 << 30)
  352. #define DMA_DESCR_TX_OWNER (1 << 31)
  353. /* RX DMA descriptor status bits */
  354. #define DMA_DESCR_RX_EOF (1 << 0)
  355. #define DMA_DESCR_RX_SOF (1 << 1)
  356. #define DMA_DESCR_RX_VTF (1 << 2)
  357. #define DMA_DESCR_RX_FRAME_IS_TYPE (1 << 3)
  358. #define DMA_DESCR_RX_SHORT_FRAME (1 << 4)
  359. #define DMA_DESCR_RX_HASH_MATCH (1 << 7)
  360. #define DMA_DESCR_RX_BAD_FRAME (1 << 8)
  361. #define DMA_DESCR_RX_OVERRUN (1 << 9)
  362. #define DMA_DESCR_RX_MAX_FRAME_LEN (1 << 11)
  363. #define DMA_DESCR_RX_CRC_ERROR (1 << 12)
  364. #define DMA_DESCR_RX_DESCR_INT (1 << 13)
  365. #define DMA_DESCR_RX_OWNER (1 << 15)
  366. #define RX_BUFFER_SIZE PKTSIZE
  367. #define NUM_RX_DESC PKTBUFSRX
  368. static struct dma_descriptor tx_descriptor __attribute__ ((aligned(32)));
  369. static struct dma_descriptor rx_descr_array[NUM_RX_DESC]
  370. __attribute__ ((aligned(32)));
  371. static struct dma_descriptor *rx_descr_current;
  372. static int tsi108_eth_probe (struct eth_device *dev, bd_t * bis);
  373. static int tsi108_eth_send (struct eth_device *dev,
  374. volatile void *packet, int length);
  375. static int tsi108_eth_recv (struct eth_device *dev);
  376. static void tsi108_eth_halt (struct eth_device *dev);
  377. static unsigned int read_phy (unsigned int base,
  378. unsigned int phy_addr, unsigned int phy_reg);
  379. static void write_phy (unsigned int base,
  380. unsigned int phy_addr,
  381. unsigned int phy_reg, unsigned int phy_data);
  382. #if TSI108_ETH_DEBUG > 100
  383. /*
  384. * print phy debug infomation
  385. */
  386. static void dump_phy_regs (unsigned int phy_addr)
  387. {
  388. int i;
  389. printf ("PHY %d registers\n", phy_addr);
  390. for (i = 0; i <= 30; i++) {
  391. printf ("%2d 0x%04x\n", i, read_phy (ETH_BASE, phy_addr, i));
  392. }
  393. printf ("\n");
  394. }
  395. #else
  396. #define dump_phy_regs(base) do{}while(0)
  397. #endif
  398. #if TSI108_ETH_DEBUG > 100
  399. /*
  400. * print debug infomation
  401. */
  402. static void tx_diag_regs (unsigned int base)
  403. {
  404. int i;
  405. unsigned long dummy;
  406. printf ("TX diagnostics registers\n");
  407. reg_TX_DIAGNOSTIC_ADDR(base) = 0x00 | TX_DIAGNOSTIC_ADDR_AI;
  408. udelay (1000);
  409. dummy = reg_TX_DIAGNOSTIC_DATA(base);
  410. for (i = 0x00; i <= 0x05; i++) {
  411. udelay (1000);
  412. printf ("0x%02x 0x%08x\n", i, reg_TX_DIAGNOSTIC_DATA(base));
  413. }
  414. reg_TX_DIAGNOSTIC_ADDR(base) = 0x40 | TX_DIAGNOSTIC_ADDR_AI;
  415. udelay (1000);
  416. dummy = reg_TX_DIAGNOSTIC_DATA(base);
  417. for (i = 0x40; i <= 0x47; i++) {
  418. udelay (1000);
  419. printf ("0x%02x 0x%08x\n", i, reg_TX_DIAGNOSTIC_DATA(base));
  420. }
  421. printf ("\n");
  422. }
  423. #else
  424. #define tx_diag_regs(base) do{}while(0)
  425. #endif
  426. #if TSI108_ETH_DEBUG > 100
  427. /*
  428. * print debug infomation
  429. */
  430. static void rx_diag_regs (unsigned int base)
  431. {
  432. int i;
  433. unsigned long dummy;
  434. printf ("RX diagnostics registers\n");
  435. reg_RX_DIAGNOSTIC_ADDR(base) = 0x00 | RX_DIAGNOSTIC_ADDR_AI;
  436. udelay (1000);
  437. dummy = reg_RX_DIAGNOSTIC_DATA(base);
  438. for (i = 0x00; i <= 0x05; i++) {
  439. udelay (1000);
  440. printf ("0x%02x 0x%08x\n", i, reg_RX_DIAGNOSTIC_DATA(base));
  441. }
  442. reg_RX_DIAGNOSTIC_ADDR(base) = 0x40 | RX_DIAGNOSTIC_ADDR_AI;
  443. udelay (1000);
  444. dummy = reg_RX_DIAGNOSTIC_DATA(base);
  445. for (i = 0x08; i <= 0x0a; i++) {
  446. udelay (1000);
  447. printf ("0x%02x 0x%08x\n", i, reg_RX_DIAGNOSTIC_DATA(base));
  448. }
  449. printf ("\n");
  450. }
  451. #else
  452. #define rx_diag_regs(base) do{}while(0)
  453. #endif
  454. #if TSI108_ETH_DEBUG > 100
  455. /*
  456. * print debug infomation
  457. */
  458. static void debug_mii_regs (unsigned int base)
  459. {
  460. printf ("MII_MGMT_CONFIG 0x%08x\n", reg_MII_MGMT_CONFIG(base));
  461. printf ("MII_MGMT_COMMAND 0x%08x\n", reg_MII_MGMT_COMMAND(base));
  462. printf ("MII_MGMT_ADDRESS 0x%08x\n", reg_MII_MGMT_ADDRESS(base));
  463. printf ("MII_MGMT_CONTROL 0x%08x\n", reg_MII_MGMT_CONTROL(base));
  464. printf ("MII_MGMT_STATUS 0x%08x\n", reg_MII_MGMT_STATUS(base));
  465. printf ("MII_MGMT_INDICATORS 0x%08x\n", reg_MII_MGMT_INDICATORS(base));
  466. printf ("\n");
  467. }
  468. #else
  469. #define debug_mii_regs(base) do{}while(0)
  470. #endif
  471. /*
  472. * Wait until the phy bus is non-busy
  473. */
  474. static void phy_wait (unsigned int base, unsigned int condition)
  475. {
  476. int timeout;
  477. timeout = 0;
  478. while (reg_MII_MGMT_INDICATORS(base) & condition) {
  479. udelay (10);
  480. if (++timeout > 10000) {
  481. printf ("ERROR: timeout waiting for phy bus (%d)\n",
  482. condition);
  483. break;
  484. }
  485. }
  486. }
  487. /*
  488. * read phy register
  489. */
  490. static unsigned int read_phy (unsigned int base,
  491. unsigned int phy_addr, unsigned int phy_reg)
  492. {
  493. unsigned int value;
  494. phy_wait (base, MII_MGMT_INDICATORS_BUSY);
  495. reg_MII_MGMT_ADDRESS(base) = (phy_addr << 8) | phy_reg;
  496. /* Ensure that the Read Cycle bit is cleared prior to next read cycle */
  497. reg_MII_MGMT_COMMAND(base) = 0;
  498. /* start the read */
  499. reg_MII_MGMT_COMMAND(base) = MII_MGMT_COMMAND_READ_CYCLE;
  500. /* wait for the read to complete */
  501. phy_wait (base,
  502. MII_MGMT_INDICATORS_NOT_VALID | MII_MGMT_INDICATORS_BUSY);
  503. value = reg_MII_MGMT_STATUS(base);
  504. reg_MII_MGMT_COMMAND(base) = 0;
  505. return value;
  506. }
  507. /*
  508. * write phy register
  509. */
  510. static void write_phy (unsigned int base,
  511. unsigned int phy_addr,
  512. unsigned int phy_reg, unsigned int phy_data)
  513. {
  514. phy_wait (base, MII_MGMT_INDICATORS_BUSY);
  515. reg_MII_MGMT_ADDRESS(base) = (phy_addr << 8) | phy_reg;
  516. /* Ensure that the Read Cycle bit is cleared prior to next cycle */
  517. reg_MII_MGMT_COMMAND(base) = 0;
  518. /* start the write */
  519. reg_MII_MGMT_CONTROL(base) = phy_data;
  520. }
  521. /*
  522. * configure the marvell 88e1111 phy
  523. */
  524. static int marvell_88e_phy_config (struct eth_device *dev, int *speed,
  525. int *duplex)
  526. {
  527. unsigned long base;
  528. unsigned long phy_addr;
  529. unsigned int phy_status;
  530. unsigned int phy_spec_status;
  531. int timeout;
  532. int phy_speed;
  533. int phy_duplex;
  534. unsigned int value;
  535. phy_speed = LINK_SPEED_UNKNOWN;
  536. phy_duplex = LINK_DUPLEX_UNKNOWN;
  537. base = dev->iobase;
  538. phy_addr = (unsigned long)dev->priv;
  539. /* Take the PHY out of reset. */
  540. write_phy (ETH_BASE, phy_addr, PHY_CTRL_REG, PHY_CTRL_RESET);
  541. /* Wait for the reset process to complete. */
  542. udelay (10);
  543. timeout = 0;
  544. while ((phy_status =
  545. read_phy (ETH_BASE, phy_addr, PHY_CTRL_REG)) & PHY_CTRL_RESET) {
  546. udelay (10);
  547. if (++timeout > 10000) {
  548. printf ("ERROR: timeout waiting for phy reset\n");
  549. break;
  550. }
  551. }
  552. /* TBI Configuration. */
  553. write_phy (base, TBI_ADDR, TBI_CONTROL_2, TBI_CONTROL_2_G_MII_MODE |
  554. TBI_CONTROL_2_RECEIVE_CLOCK_SELECT);
  555. /* Wait for the link to be established. */
  556. timeout = 0;
  557. do {
  558. udelay (20000);
  559. phy_status = read_phy (ETH_BASE, phy_addr, PHY_STATUS_REG);
  560. if (++timeout > 100) {
  561. debug_lev(1, "ERROR: unable to establish link!!!\n");
  562. break;
  563. }
  564. } while ((phy_status & PHY_STAT_LINK_UP) == 0);
  565. if ((phy_status & PHY_STAT_LINK_UP) == 0)
  566. return 0;
  567. value = 0;
  568. phy_spec_status = read_phy (ETH_BASE, phy_addr, MV1111_SPEC_STAT_REG);
  569. if (phy_spec_status & SPEC_STAT_RESOLVED) {
  570. switch (phy_spec_status & SPEC_STAT_SPEED_MASK) {
  571. case SPEED_1000:
  572. phy_speed = LINK_SPEED_1000;
  573. value |= PHY_CTRL_SPEED1;
  574. break;
  575. case SPEED_100:
  576. phy_speed = LINK_SPEED_100;
  577. value |= PHY_CTRL_SPEED0;
  578. break;
  579. case SPEED_10:
  580. phy_speed = LINK_SPEED_10;
  581. break;
  582. }
  583. if (phy_spec_status & SPEC_STAT_FULL_DUP) {
  584. phy_duplex = LINK_DUPLEX_FULL;
  585. value |= PHY_CTRL_FULL_DUPLEX;
  586. } else
  587. phy_duplex = LINK_DUPLEX_HALF;
  588. }
  589. /* set TBI speed */
  590. write_phy (base, TBI_ADDR, PHY_CTRL_REG, value);
  591. write_phy (base, TBI_ADDR, PHY_AN_ADV_REG, 0x0060);
  592. #if TSI108_ETH_DEBUG > 0
  593. printf ("%s link is up", dev->name);
  594. phy_spec_status = read_phy (ETH_BASE, phy_addr, MV1111_SPEC_STAT_REG);
  595. if (phy_spec_status & SPEC_STAT_RESOLVED) {
  596. switch (phy_speed) {
  597. case LINK_SPEED_1000:
  598. printf (", 1000 Mbps");
  599. break;
  600. case LINK_SPEED_100:
  601. printf (", 100 Mbps");
  602. break;
  603. case LINK_SPEED_10:
  604. printf (", 10 Mbps");
  605. break;
  606. }
  607. if (phy_duplex == LINK_DUPLEX_FULL)
  608. printf (", Full duplex");
  609. else
  610. printf (", Half duplex");
  611. }
  612. printf ("\n");
  613. #endif
  614. dump_phy_regs (TBI_ADDR);
  615. if (speed)
  616. *speed = phy_speed;
  617. if (duplex)
  618. *duplex = phy_duplex;
  619. return 1;
  620. }
  621. /*
  622. * External interface
  623. *
  624. * register the tsi108 ethernet controllers with the multi-ethernet system
  625. */
  626. int tsi108_eth_initialize (bd_t * bis)
  627. {
  628. struct eth_device *dev;
  629. int index;
  630. for (index = 0; index < CONFIG_TSI108_ETH_NUM_PORTS; index++) {
  631. dev = (struct eth_device *)malloc(sizeof(struct eth_device));
  632. sprintf (dev->name, "TSI108_eth%d", index);
  633. dev->iobase = ETH_BASE + (index * ETH_PORT_OFFSET);
  634. dev->priv = (void *)(phy_address[index]);
  635. dev->init = tsi108_eth_probe;
  636. dev->halt = tsi108_eth_halt;
  637. dev->send = tsi108_eth_send;
  638. dev->recv = tsi108_eth_recv;
  639. eth_register(dev);
  640. }
  641. return index;
  642. }
  643. /*
  644. * probe for and initialize a single ethernet interface
  645. */
  646. static int tsi108_eth_probe (struct eth_device *dev, bd_t * bis)
  647. {
  648. unsigned long base;
  649. unsigned long value;
  650. int index;
  651. struct dma_descriptor *tx_descr;
  652. struct dma_descriptor *rx_descr;
  653. int speed;
  654. int duplex;
  655. base = dev->iobase;
  656. reg_PORT_CONTROL(base) = PORT_CONTROL_STE | PORT_CONTROL_BPT;
  657. /* Bring DMA/FIFO out of reset. */
  658. reg_TX_CONFIG(base) = 0x00000000;
  659. reg_RX_CONFIG(base) = 0x00000000;
  660. reg_TX_THRESHOLDS(base) = (192 << 16) | 192;
  661. reg_RX_THRESHOLDS(base) = (192 << 16) | 112;
  662. /* Bring MAC out of reset. */
  663. reg_MAC_CONFIG_1(base) = 0x00000000;
  664. /* DMA MAC configuration. */
  665. reg_MAC_CONFIG_1(base) =
  666. MAC_CONFIG_1_RX_ENABLE | MAC_CONFIG_1_TX_ENABLE;
  667. reg_MII_MGMT_CONFIG(base) = MII_MGMT_CONFIG_NO_PREAMBLE;
  668. reg_MAXIMUM_FRAME_LENGTH(base) = RX_BUFFER_SIZE;
  669. /* Note: Early tsi108 manual did not have correct byte order
  670. * for the station address.*/
  671. reg_STATION_ADDRESS_1(base) = (dev->enetaddr[5] << 24) |
  672. (dev->enetaddr[4] << 16) |
  673. (dev->enetaddr[3] << 8) | (dev->enetaddr[2] << 0);
  674. reg_STATION_ADDRESS_2(base) = (dev->enetaddr[1] << 24) |
  675. (dev->enetaddr[0] << 16);
  676. if (marvell_88e_phy_config(dev, &speed, &duplex) == 0)
  677. return -1;
  678. value =
  679. MAC_CONFIG_2_PREAMBLE_LENGTH(7) | MAC_CONFIG_2_PAD_CRC |
  680. MAC_CONFIG_2_CRC_ENABLE;
  681. if (speed == LINK_SPEED_1000)
  682. value |= MAC_CONFIG_2_INTERFACE_MODE(INTERFACE_MODE_BYTE);
  683. else {
  684. value |= MAC_CONFIG_2_INTERFACE_MODE(INTERFACE_MODE_NIBBLE);
  685. reg_PORT_CONTROL(base) |= PORT_CONTROL_SPD;
  686. }
  687. if (duplex == LINK_DUPLEX_FULL) {
  688. value |= MAC_CONFIG_2_FULL_DUPLEX;
  689. reg_PORT_CONTROL(base) &= ~PORT_CONTROL_BPT;
  690. } else
  691. reg_PORT_CONTROL(base) |= PORT_CONTROL_BPT;
  692. reg_MAC_CONFIG_2(base) = value;
  693. reg_RX_CONFIG(base) = RX_CONFIG_SE;
  694. reg_RX_QUEUE_0_CONFIG(base) = OCN_PORT_MEMORY;
  695. reg_RX_QUEUE_0_BUF_CONFIG(base) = OCN_PORT_MEMORY;
  696. /* initialize the RX DMA descriptors */
  697. rx_descr = &rx_descr_array[0];
  698. rx_descr_current = rx_descr;
  699. for (index = 0; index < NUM_RX_DESC; index++) {
  700. /* make sure the receive buffers are not in cache */
  701. invalidate_dcache_range((unsigned long)NetRxPackets[index],
  702. (unsigned long)NetRxPackets[index] +
  703. RX_BUFFER_SIZE);
  704. rx_descr->start_addr0 =
  705. cpu_to_le32((vuint32) NetRxPackets[index]);
  706. rx_descr->start_addr1 = 0;
  707. rx_descr->next_descr_addr0 =
  708. cpu_to_le32((vuint32) (rx_descr + 1));
  709. rx_descr->next_descr_addr1 = 0;
  710. rx_descr->vlan_byte_count = 0;
  711. rx_descr->config_status = cpu_to_le32((RX_BUFFER_SIZE << 16) |
  712. DMA_DESCR_RX_OWNER);
  713. rx_descr++;
  714. }
  715. rx_descr--;
  716. rx_descr->next_descr_addr0 = 0;
  717. rx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
  718. /* Push the descriptors to RAM so the ethernet DMA can see them */
  719. invalidate_dcache_range((unsigned long)rx_descr_array,
  720. (unsigned long)rx_descr_array +
  721. sizeof(rx_descr_array));
  722. /* enable RX queue */
  723. reg_RX_CONTROL(base) = TX_CONTROL_GO | 0x01;
  724. reg_RX_QUEUE_0_PTR_LOW(base) = (u32) rx_descr_current;
  725. /* enable receive DMA */
  726. reg_RX_QUEUE_0_PTR_HIGH(base) = RX_QUEUE_0_PTR_HIGH_VALID;
  727. reg_TX_QUEUE_0_CONFIG(base) = OCN_PORT_MEMORY;
  728. reg_TX_QUEUE_0_BUF_CONFIG(base) = OCN_PORT_MEMORY;
  729. /* initialize the TX DMA descriptor */
  730. tx_descr = &tx_descriptor;
  731. tx_descr->start_addr0 = 0;
  732. tx_descr->start_addr1 = 0;
  733. tx_descr->next_descr_addr0 = 0;
  734. tx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
  735. tx_descr->vlan_byte_count = 0;
  736. tx_descr->config_status = cpu_to_le32(DMA_DESCR_TX_OK |
  737. DMA_DESCR_TX_SOF |
  738. DMA_DESCR_TX_EOF);
  739. /* enable TX queue */
  740. reg_TX_CONTROL(base) = TX_CONTROL_GO | 0x01;
  741. return 0;
  742. }
  743. /*
  744. * send a packet
  745. */
  746. static int tsi108_eth_send (struct eth_device *dev,
  747. volatile void *packet, int length)
  748. {
  749. unsigned long base;
  750. int timeout;
  751. struct dma_descriptor *tx_descr;
  752. unsigned long status;
  753. base = dev->iobase;
  754. tx_descr = &tx_descriptor;
  755. /* Wait until the last packet has been transmitted. */
  756. timeout = 0;
  757. do {
  758. /* make sure we see the changes made by the DMA engine */
  759. invalidate_dcache_range((unsigned long)tx_descr,
  760. (unsigned long)tx_descr +
  761. sizeof(struct dma_descriptor));
  762. if (timeout != 0)
  763. udelay (15);
  764. if (++timeout > 10000) {
  765. tx_diag_regs(base);
  766. debug_lev(1,
  767. "ERROR: timeout waiting for last transmit packet to be sent\n");
  768. return 0;
  769. }
  770. } while (tx_descr->config_status & cpu_to_le32(DMA_DESCR_TX_OWNER));
  771. status = le32_to_cpu(tx_descr->config_status);
  772. if ((status & DMA_DESCR_TX_OK) == 0) {
  773. #ifdef TX_PRINT_ERRORS
  774. printf ("TX packet error: 0x%08x\n %s%s%s%s\n", status,
  775. status & DMA_DESCR_TX_OK ? "tx error, " : "",
  776. status & DMA_DESCR_TX_RETRY_LIMIT ?
  777. "retry limit reached, " : "",
  778. status & DMA_DESCR_TX_UNDERRUN ? "underrun, " : "",
  779. status & DMA_DESCR_TX_LATE_COLLISION ? "late collision, "
  780. : "");
  781. #endif
  782. }
  783. debug_lev (9, "sending packet %d\n", length);
  784. tx_descr->start_addr0 = cpu_to_le32((vuint32) packet);
  785. tx_descr->start_addr1 = 0;
  786. tx_descr->next_descr_addr0 = 0;
  787. tx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
  788. tx_descr->vlan_byte_count = cpu_to_le32(length);
  789. tx_descr->config_status = cpu_to_le32(DMA_DESCR_TX_OWNER |
  790. DMA_DESCR_TX_CRC |
  791. DMA_DESCR_TX_PAD |
  792. DMA_DESCR_TX_SOF |
  793. DMA_DESCR_TX_EOF);
  794. invalidate_dcache_range((unsigned long)tx_descr,
  795. (unsigned long)tx_descr +
  796. sizeof(struct dma_descriptor));
  797. invalidate_dcache_range((unsigned long)packet,
  798. (unsigned long)packet + length);
  799. reg_TX_QUEUE_0_PTR_LOW(base) = (u32) tx_descr;
  800. reg_TX_QUEUE_0_PTR_HIGH(base) = TX_QUEUE_0_PTR_HIGH_VALID;
  801. return length;
  802. }
  803. /*
  804. * Check for received packets and send them up the protocal stack
  805. */
  806. static int tsi108_eth_recv (struct eth_device *dev)
  807. {
  808. struct dma_descriptor *rx_descr;
  809. unsigned long base;
  810. int length = 0;
  811. unsigned long status;
  812. volatile uchar *buffer;
  813. base = dev->iobase;
  814. /* make sure we see the changes made by the DMA engine */
  815. invalidate_dcache_range ((unsigned long)rx_descr_array,
  816. (unsigned long)rx_descr_array +
  817. sizeof(rx_descr_array));
  818. /* process all of the received packets */
  819. rx_descr = rx_descr_current;
  820. while ((rx_descr->config_status & cpu_to_le32(DMA_DESCR_RX_OWNER)) == 0) {
  821. /* check for error */
  822. status = le32_to_cpu(rx_descr->config_status);
  823. if (status & DMA_DESCR_RX_BAD_FRAME) {
  824. #ifdef RX_PRINT_ERRORS
  825. printf ("RX packet error: 0x%08x\n %s%s%s%s%s%s\n",
  826. status,
  827. status & DMA_DESCR_RX_FRAME_IS_TYPE ? "too big, "
  828. : "",
  829. status & DMA_DESCR_RX_SHORT_FRAME ? "too short, "
  830. : "",
  831. status & DMA_DESCR_RX_BAD_FRAME ? "bad frame, " :
  832. "",
  833. status & DMA_DESCR_RX_OVERRUN ? "overrun, " : "",
  834. status & DMA_DESCR_RX_MAX_FRAME_LEN ?
  835. "max length, " : "",
  836. status & DMA_DESCR_RX_CRC_ERROR ? "CRC error, " :
  837. "");
  838. #endif
  839. } else {
  840. length =
  841. le32_to_cpu(rx_descr->vlan_byte_count) & 0xFFFF;
  842. /*** process packet ***/
  843. buffer =
  844. (volatile uchar
  845. *)(le32_to_cpu (rx_descr->start_addr0));
  846. NetReceive (buffer, length);
  847. invalidate_dcache_range ((unsigned long)buffer,
  848. (unsigned long)buffer +
  849. RX_BUFFER_SIZE);
  850. }
  851. /* Give this buffer back to the DMA engine */
  852. rx_descr->vlan_byte_count = 0;
  853. rx_descr->config_status = cpu_to_le32 ((RX_BUFFER_SIZE << 16) |
  854. DMA_DESCR_RX_OWNER);
  855. /* move descriptor pointer forward */
  856. rx_descr =
  857. (struct dma_descriptor
  858. *)(le32_to_cpu (rx_descr->next_descr_addr0));
  859. if (rx_descr == 0)
  860. rx_descr = &rx_descr_array[0];
  861. }
  862. /* remember where we are for next time */
  863. rx_descr_current = rx_descr;
  864. /* If the DMA engine has reached the end of the queue
  865. * start over at the begining */
  866. if (reg_RX_EXTENDED_STATUS(base) & RX_EXTENDED_STATUS_EOQ_0) {
  867. reg_RX_EXTENDED_STATUS(base) = RX_EXTENDED_STATUS_EOQ_0;
  868. reg_RX_QUEUE_0_PTR_LOW(base) = (u32) & rx_descr_array[0];
  869. reg_RX_QUEUE_0_PTR_HIGH(base) = RX_QUEUE_0_PTR_HIGH_VALID;
  870. }
  871. return length;
  872. }
  873. /*
  874. * disable an ethernet interface
  875. */
  876. static void tsi108_eth_halt (struct eth_device *dev)
  877. {
  878. unsigned long base;
  879. base = dev->iobase;
  880. /* Put DMA/FIFO into reset state. */
  881. reg_TX_CONFIG(base) = TX_CONFIG_RST;
  882. reg_RX_CONFIG(base) = RX_CONFIG_RST;
  883. /* Put MAC into reset state. */
  884. reg_MAC_CONFIG_1(base) = MAC_CONFIG_1_SOFT_RESET;
  885. }
  886. #endif