tsi108_eth.c 31 KB

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