tsi108_eth.c 34 KB

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