You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435
  1. /* $Id$
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002 Jeff Garzik (jgarzik@mandrakesoft.com)
  6. * Copyright (C) 2003 Eric Biederman (ebiederman@lnxi.com) [etherboot port]
  7. */
  8. FILE_LICENCE ( GPL2_ONLY );
  9. /* 11-13-2003 timlegge Fix Issue with NetGear GA302T
  10. * 11-18-2003 ebiederm Generalize NetGear Fix to what the code was supposed to be.
  11. * 01-06-2005 Alf (Frederic Olivie) Add Dell bcm 5751 (0x1677) support
  12. * 04-15-2005 Martin Vogt Add Fujitsu Siemens Computer (FSC) 0x1734 bcm 5751 0x105d support
  13. */
  14. #include "etherboot.h"
  15. #include "nic.h"
  16. #include <errno.h>
  17. #include <ipxe/pci.h>
  18. #include <ipxe/ethernet.h>
  19. #include "string.h"
  20. #include <mii.h>
  21. #include "tg3.h"
  22. #define SUPPORT_COPPER_PHY 1
  23. #define SUPPORT_FIBER_PHY 1
  24. #define SUPPORT_LINK_REPORT 1
  25. #define SUPPORT_PARTNO_STR 1
  26. #define SUPPORT_PHY_STR 1
  27. static struct tg3 tg3;
  28. /* These numbers seem to be hard coded in the NIC firmware somehow.
  29. * You can't change the ring sizes, but you can change where you place
  30. * them in the NIC onboard memory.
  31. */
  32. #define TG3_RX_RING_SIZE 512
  33. #define TG3_DEF_RX_RING_PENDING 20 /* RX_RING_PENDING seems to be o.k. at 20 and 200 */
  34. #define TG3_RX_RCB_RING_SIZE 1024
  35. /* (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ? \
  36. 512 : 1024) */
  37. #define TG3_TX_RING_SIZE 512
  38. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  39. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_RING_SIZE)
  40. #define TG3_RX_RCB_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_RCB_RING_SIZE)
  41. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * TG3_TX_RING_SIZE)
  42. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  43. #define PREV_TX(N) (((N) - 1) & (TG3_TX_RING_SIZE - 1))
  44. #define RX_PKT_BUF_SZ (1536 + 2 + 64)
  45. struct eth_frame {
  46. uint8_t dst_addr[ETH_ALEN];
  47. uint8_t src_addr[ETH_ALEN];
  48. uint16_t type;
  49. uint8_t data [ETH_FRAME_LEN - ETH_HLEN];
  50. };
  51. struct bss {
  52. struct tg3_rx_buffer_desc rx_std[TG3_RX_RING_SIZE];
  53. struct tg3_rx_buffer_desc rx_rcb[TG3_RX_RCB_RING_SIZE];
  54. struct tg3_tx_buffer_desc tx_ring[TG3_TX_RING_SIZE];
  55. struct tg3_hw_status hw_status;
  56. struct tg3_hw_stats hw_stats;
  57. unsigned char rx_bufs[TG3_DEF_RX_RING_PENDING][RX_PKT_BUF_SZ];
  58. struct eth_frame tx_frame[2];
  59. } tg3_bss __shared;
  60. /**
  61. * pci_save_state - save the PCI configuration space of a device before suspending
  62. * @dev: - PCI device that we're dealing with
  63. * @buffer: - buffer to hold config space context
  64. *
  65. * @buffer must be large enough to hold the entire PCI 2.2 config space
  66. * (>= 64 bytes).
  67. */
  68. static int pci_save_state(struct pci_device *dev, uint32_t *buffer)
  69. {
  70. int i;
  71. for (i = 0; i < 16; i++)
  72. pci_read_config_dword(dev, i * 4,&buffer[i]);
  73. return 0;
  74. }
  75. /**
  76. * pci_restore_state - Restore the saved state of a PCI device
  77. * @dev: - PCI device that we're dealing with
  78. * @buffer: - saved PCI config space
  79. *
  80. */
  81. static int pci_restore_state(struct pci_device *dev, uint32_t *buffer)
  82. {
  83. int i;
  84. for (i = 0; i < 16; i++)
  85. pci_write_config_dword(dev,i * 4, buffer[i]);
  86. return 0;
  87. }
  88. static void tg3_write_indirect_reg32(uint32_t off, uint32_t val)
  89. {
  90. pci_write_config_dword(tg3.pdev, TG3PCI_REG_BASE_ADDR, off);
  91. pci_write_config_dword(tg3.pdev, TG3PCI_REG_DATA, val);
  92. }
  93. #define tw32(reg,val) tg3_write_indirect_reg32((reg),(val))
  94. #define tw32_mailbox(reg, val) writel(((val) & 0xffffffff), tg3.regs + (reg))
  95. #define tw16(reg,val) writew(((val) & 0xffff), tg3.regs + (reg))
  96. #define tw8(reg,val) writeb(((val) & 0xff), tg3.regs + (reg))
  97. #define tr32(reg) readl(tg3.regs + (reg))
  98. #define tr16(reg) readw(tg3.regs + (reg))
  99. #define tr8(reg) readb(tg3.regs + (reg))
  100. static void tw32_carefully(uint32_t reg, uint32_t val)
  101. {
  102. tw32(reg, val);
  103. tr32(reg);
  104. udelay(100);
  105. }
  106. static void tw32_mailbox2(uint32_t reg, uint32_t val)
  107. {
  108. tw32_mailbox(reg, val);
  109. tr32(reg);
  110. }
  111. static void tg3_write_mem(uint32_t off, uint32_t val)
  112. {
  113. pci_write_config_dword(tg3.pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  114. pci_write_config_dword(tg3.pdev, TG3PCI_MEM_WIN_DATA, val);
  115. /* Always leave this as zero. */
  116. pci_write_config_dword(tg3.pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  117. }
  118. static void tg3_read_mem(uint32_t off, uint32_t *val)
  119. {
  120. pci_write_config_dword(tg3.pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  121. pci_read_config_dword(tg3.pdev, TG3PCI_MEM_WIN_DATA, val);
  122. /* Always leave this as zero. */
  123. pci_write_config_dword(tg3.pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  124. }
  125. static void tg3_disable_ints(struct tg3 *tp)
  126. {
  127. tw32(TG3PCI_MISC_HOST_CTRL,
  128. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  129. tw32_mailbox2(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  130. }
  131. static void tg3_switch_clocks(struct tg3 *tp)
  132. {
  133. uint32_t orig_clock_ctrl, clock_ctrl;
  134. clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  135. orig_clock_ctrl = clock_ctrl;
  136. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | CLOCK_CTRL_CLKRUN_OENABLE | 0x1f);
  137. tp->pci_clock_ctrl = clock_ctrl;
  138. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) &&
  139. (!((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  140. && (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) &&
  141. (orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE)!=0) {
  142. tw32_carefully(TG3PCI_CLOCK_CTRL,
  143. clock_ctrl | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK));
  144. tw32_carefully(TG3PCI_CLOCK_CTRL,
  145. clock_ctrl | (CLOCK_CTRL_ALTCLK));
  146. }
  147. tw32_carefully(TG3PCI_CLOCK_CTRL, clock_ctrl);
  148. }
  149. #define PHY_BUSY_LOOPS 5000
  150. static int tg3_readphy(struct tg3 *tp, int reg, uint32_t *val)
  151. {
  152. uint32_t frame_val;
  153. int loops, ret;
  154. tw32_carefully(MAC_MI_MODE, tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL);
  155. *val = 0xffffffff;
  156. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  157. MI_COM_PHY_ADDR_MASK);
  158. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  159. MI_COM_REG_ADDR_MASK);
  160. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  161. tw32_carefully(MAC_MI_COM, frame_val);
  162. loops = PHY_BUSY_LOOPS;
  163. while (loops-- > 0) {
  164. udelay(10);
  165. frame_val = tr32(MAC_MI_COM);
  166. if ((frame_val & MI_COM_BUSY) == 0) {
  167. udelay(5);
  168. frame_val = tr32(MAC_MI_COM);
  169. break;
  170. }
  171. }
  172. ret = -EBUSY;
  173. if (loops > 0) {
  174. *val = frame_val & MI_COM_DATA_MASK;
  175. ret = 0;
  176. }
  177. tw32_carefully(MAC_MI_MODE, tp->mi_mode);
  178. return ret;
  179. }
  180. static int tg3_writephy(struct tg3 *tp, int reg, uint32_t val)
  181. {
  182. uint32_t frame_val;
  183. int loops, ret;
  184. tw32_carefully(MAC_MI_MODE, tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL);
  185. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  186. MI_COM_PHY_ADDR_MASK);
  187. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  188. MI_COM_REG_ADDR_MASK);
  189. frame_val |= (val & MI_COM_DATA_MASK);
  190. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  191. tw32_carefully(MAC_MI_COM, frame_val);
  192. loops = PHY_BUSY_LOOPS;
  193. while (loops-- > 0) {
  194. udelay(10);
  195. frame_val = tr32(MAC_MI_COM);
  196. if ((frame_val & MI_COM_BUSY) == 0) {
  197. udelay(5);
  198. frame_val = tr32(MAC_MI_COM);
  199. break;
  200. }
  201. }
  202. ret = -EBUSY;
  203. if (loops > 0)
  204. ret = 0;
  205. tw32_carefully(MAC_MI_MODE, tp->mi_mode);
  206. return ret;
  207. }
  208. static int tg3_writedsp(struct tg3 *tp, uint16_t addr, uint16_t val)
  209. {
  210. int err;
  211. err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, addr);
  212. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val);
  213. return err;
  214. }
  215. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  216. {
  217. uint32_t val;
  218. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  219. return;
  220. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007);
  221. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  222. tg3_writephy(tp, MII_TG3_AUX_CTRL, (val | (1 << 15) | (1 << 4)));
  223. }
  224. static int tg3_bmcr_reset(struct tg3 *tp)
  225. {
  226. uint32_t phy_control;
  227. int limit, err;
  228. /* OK, reset it, and poll the BMCR_RESET bit until it
  229. * clears or we time out.
  230. */
  231. phy_control = BMCR_RESET;
  232. err = tg3_writephy(tp, MII_BMCR, phy_control);
  233. if (err != 0)
  234. return -EBUSY;
  235. limit = 5000;
  236. while (limit--) {
  237. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  238. if (err != 0)
  239. return -EBUSY;
  240. if ((phy_control & BMCR_RESET) == 0) {
  241. udelay(40);
  242. break;
  243. }
  244. udelay(10);
  245. }
  246. if (limit <= 0)
  247. return -EBUSY;
  248. return 0;
  249. }
  250. static int tg3_wait_macro_done(struct tg3 *tp)
  251. {
  252. int limit = 100;
  253. while (limit--) {
  254. uint32_t tmp32;
  255. tg3_readphy(tp, 0x16, &tmp32);
  256. if ((tmp32 & 0x1000) == 0)
  257. break;
  258. }
  259. if (limit <= 0)
  260. return -EBUSY;
  261. return 0;
  262. }
  263. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  264. {
  265. static const uint32_t test_pat[4][6] = {
  266. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  267. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  268. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  269. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  270. };
  271. int chan;
  272. for (chan = 0; chan < 4; chan++) {
  273. int i;
  274. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  275. (chan * 0x2000) | 0x0200);
  276. tg3_writephy(tp, 0x16, 0x0002);
  277. for (i = 0; i < 6; i++)
  278. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  279. test_pat[chan][i]);
  280. tg3_writephy(tp, 0x16, 0x0202);
  281. if (tg3_wait_macro_done(tp)) {
  282. *resetp = 1;
  283. return -EBUSY;
  284. }
  285. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  286. (chan * 0x2000) | 0x0200);
  287. tg3_writephy(tp, 0x16, 0x0082);
  288. if (tg3_wait_macro_done(tp)) {
  289. *resetp = 1;
  290. return -EBUSY;
  291. }
  292. tg3_writephy(tp, 0x16, 0x0802);
  293. if (tg3_wait_macro_done(tp)) {
  294. *resetp = 1;
  295. return -EBUSY;
  296. }
  297. for (i = 0; i < 6; i += 2) {
  298. uint32_t low, high;
  299. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low);
  300. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high);
  301. if (tg3_wait_macro_done(tp)) {
  302. *resetp = 1;
  303. return -EBUSY;
  304. }
  305. low &= 0x7fff;
  306. high &= 0x000f;
  307. if (low != test_pat[chan][i] ||
  308. high != test_pat[chan][i+1]) {
  309. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  310. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  311. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  312. return -EBUSY;
  313. }
  314. }
  315. }
  316. return 0;
  317. }
  318. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  319. {
  320. int chan;
  321. for (chan = 0; chan < 4; chan++) {
  322. int i;
  323. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  324. (chan * 0x2000) | 0x0200);
  325. tg3_writephy(tp, 0x16, 0x0002);
  326. for (i = 0; i < 6; i++)
  327. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  328. tg3_writephy(tp, 0x16, 0x0202);
  329. if (tg3_wait_macro_done(tp))
  330. return -EBUSY;
  331. }
  332. return 0;
  333. }
  334. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  335. {
  336. uint32_t reg32, phy9_orig;
  337. int retries, do_phy_reset, err;
  338. retries = 10;
  339. do_phy_reset = 1;
  340. do {
  341. if (do_phy_reset) {
  342. err = tg3_bmcr_reset(tp);
  343. if (err)
  344. return err;
  345. do_phy_reset = 0;
  346. }
  347. /* Disable transmitter and interrupt. */
  348. tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32);
  349. reg32 |= 0x3000;
  350. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  351. /* Set full-duplex, 1000 mbps. */
  352. tg3_writephy(tp, MII_BMCR,
  353. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  354. /* Set to master mode. */
  355. tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig);
  356. tg3_writephy(tp, MII_TG3_CTRL,
  357. (MII_TG3_CTRL_AS_MASTER |
  358. MII_TG3_CTRL_ENABLE_AS_MASTER));
  359. /* Enable SM_DSP_CLOCK and 6dB. */
  360. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  361. /* Block the PHY control access. */
  362. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  363. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  364. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  365. if (!err)
  366. break;
  367. } while (--retries);
  368. err = tg3_phy_reset_chanpat(tp);
  369. if (err)
  370. return err;
  371. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  372. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  373. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  374. tg3_writephy(tp, 0x16, 0x0000);
  375. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  376. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  377. tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32);
  378. reg32 &= ~0x3000;
  379. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  380. return err;
  381. }
  382. /* This will reset the tigon3 PHY if there is no valid
  383. * link.
  384. */
  385. static int tg3_phy_reset(struct tg3 *tp)
  386. {
  387. uint32_t phy_status;
  388. int err;
  389. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  390. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  391. if (err != 0)
  392. return -EBUSY;
  393. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) ||
  394. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  395. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  396. err = tg3_phy_reset_5703_4_5(tp);
  397. if (err)
  398. return err;
  399. goto out;
  400. }
  401. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  402. // Taken from Broadcom's source code
  403. tg3_writephy(tp, 0x18, 0x0c00);
  404. tg3_writephy(tp, 0x17, 0x000a);
  405. tg3_writephy(tp, 0x15, 0x310b);
  406. tg3_writephy(tp, 0x17, 0x201f);
  407. tg3_writephy(tp, 0x15, 0x9506);
  408. tg3_writephy(tp, 0x17, 0x401f);
  409. tg3_writephy(tp, 0x15, 0x14e2);
  410. tg3_writephy(tp, 0x18, 0x0400);
  411. }
  412. err = tg3_bmcr_reset(tp);
  413. if (err)
  414. return err;
  415. out:
  416. tg3_phy_set_wirespeed(tp);
  417. return 0;
  418. }
  419. static void tg3_set_power_state_0(struct tg3 *tp)
  420. {
  421. uint16_t power_control;
  422. int pm = tp->pm_cap;
  423. /* Make sure register accesses (indirect or otherwise)
  424. * will function correctly.
  425. */
  426. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl);
  427. pci_read_config_word(tp->pdev, pm + PCI_PM_CTRL, &power_control);
  428. power_control |= PCI_PM_CTRL_PME_STATUS;
  429. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  430. power_control |= 0;
  431. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  432. tw32_carefully(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  433. return;
  434. }
  435. #if SUPPORT_LINK_REPORT
  436. static void tg3_link_report(struct tg3 *tp)
  437. {
  438. if (!tp->carrier_ok) {
  439. printf("Link is down.\n");
  440. } else {
  441. printf("Link is up at %d Mbps, %s duplex. %s %s %s\n",
  442. (tp->link_config.active_speed == SPEED_1000 ?
  443. 1000 :
  444. (tp->link_config.active_speed == SPEED_100 ?
  445. 100 : 10)),
  446. (tp->link_config.active_duplex == DUPLEX_FULL ?
  447. "full" : "half"),
  448. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "TX" : "",
  449. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "RX" : "",
  450. (tp->tg3_flags & (TG3_FLAG_TX_PAUSE |TG3_FLAG_RX_PAUSE)) ? "flow control" : "");
  451. }
  452. }
  453. #else
  454. #define tg3_link_report(tp)
  455. #endif
  456. static void tg3_setup_flow_control(struct tg3 *tp, uint32_t local_adv, uint32_t remote_adv)
  457. {
  458. uint32_t new_tg3_flags = 0;
  459. if (local_adv & ADVERTISE_PAUSE_CAP) {
  460. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  461. if (remote_adv & LPA_PAUSE_CAP)
  462. new_tg3_flags |=
  463. (TG3_FLAG_RX_PAUSE |
  464. TG3_FLAG_TX_PAUSE);
  465. else if (remote_adv & LPA_PAUSE_ASYM)
  466. new_tg3_flags |=
  467. (TG3_FLAG_RX_PAUSE);
  468. } else {
  469. if (remote_adv & LPA_PAUSE_CAP)
  470. new_tg3_flags |=
  471. (TG3_FLAG_RX_PAUSE |
  472. TG3_FLAG_TX_PAUSE);
  473. }
  474. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  475. if ((remote_adv & LPA_PAUSE_CAP) &&
  476. (remote_adv & LPA_PAUSE_ASYM))
  477. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  478. }
  479. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  480. tp->tg3_flags |= new_tg3_flags;
  481. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  482. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  483. else
  484. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  485. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  486. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  487. else
  488. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  489. }
  490. #if SUPPORT_COPPER_PHY
  491. static void tg3_aux_stat_to_speed_duplex(
  492. struct tg3 *tp __unused, uint32_t val, uint8_t *speed, uint8_t *duplex)
  493. {
  494. static const uint8_t map[] = {
  495. [0] = (SPEED_INVALID << 2) | DUPLEX_INVALID,
  496. [MII_TG3_AUX_STAT_10HALF >> 8] = (SPEED_10 << 2) | DUPLEX_HALF,
  497. [MII_TG3_AUX_STAT_10FULL >> 8] = (SPEED_10 << 2) | DUPLEX_FULL,
  498. [MII_TG3_AUX_STAT_100HALF >> 8] = (SPEED_100 << 2) | DUPLEX_HALF,
  499. [MII_TG3_AUX_STAT_100_4 >> 8] = (SPEED_INVALID << 2) | DUPLEX_INVALID,
  500. [MII_TG3_AUX_STAT_100FULL >> 8] = (SPEED_100 << 2) | DUPLEX_FULL,
  501. [MII_TG3_AUX_STAT_1000HALF >> 8] = (SPEED_1000 << 2) | DUPLEX_HALF,
  502. [MII_TG3_AUX_STAT_1000FULL >> 8] = (SPEED_1000 << 2) | DUPLEX_FULL,
  503. };
  504. uint8_t result;
  505. result = map[(val & MII_TG3_AUX_STAT_SPDMASK) >> 8];
  506. *speed = result >> 2;
  507. *duplex = result & 3;
  508. }
  509. static int tg3_phy_copper_begin(struct tg3 *tp)
  510. {
  511. uint32_t new_adv;
  512. tp->link_config.advertising =
  513. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  514. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  515. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  516. ADVERTISED_Autoneg | ADVERTISED_MII);
  517. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY) {
  518. tp->link_config.advertising &=
  519. ~(ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  520. }
  521. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  522. if (tp->link_config.advertising & ADVERTISED_10baseT_Half) {
  523. new_adv |= ADVERTISE_10HALF;
  524. }
  525. if (tp->link_config.advertising & ADVERTISED_10baseT_Full) {
  526. new_adv |= ADVERTISE_10FULL;
  527. }
  528. if (tp->link_config.advertising & ADVERTISED_100baseT_Half) {
  529. new_adv |= ADVERTISE_100HALF;
  530. }
  531. if (tp->link_config.advertising & ADVERTISED_100baseT_Full) {
  532. new_adv |= ADVERTISE_100FULL;
  533. }
  534. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  535. if (tp->link_config.advertising &
  536. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  537. new_adv = 0;
  538. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) {
  539. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  540. }
  541. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) {
  542. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  543. }
  544. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  545. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  546. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) {
  547. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  548. MII_TG3_CTRL_ENABLE_AS_MASTER);
  549. }
  550. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  551. } else {
  552. tg3_writephy(tp, MII_TG3_CTRL, 0);
  553. }
  554. tg3_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
  555. return 0;
  556. }
  557. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  558. {
  559. int err;
  560. /* Turn off tap power management. */
  561. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c20);
  562. err |= tg3_writedsp(tp, 0x0012, 0x1804);
  563. err |= tg3_writedsp(tp, 0x0013, 0x1204);
  564. err |= tg3_writedsp(tp, 0x8006, 0x0132);
  565. err |= tg3_writedsp(tp, 0x8006, 0x0232);
  566. err |= tg3_writedsp(tp, 0x201f, 0x0a20);
  567. udelay(40);
  568. return err;
  569. }
  570. static int tg3_setup_copper_phy(struct tg3 *tp)
  571. {
  572. int current_link_up;
  573. uint32_t bmsr, dummy;
  574. int i, err;
  575. tw32_carefully(MAC_STATUS,
  576. (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED
  577. | MAC_STATUS_LNKSTATE_CHANGED));
  578. tp->mi_mode = MAC_MI_MODE_BASE;
  579. tw32_carefully(MAC_MI_MODE, tp->mi_mode);
  580. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  581. /* Some third-party PHYs need to be reset on link going
  582. * down.
  583. */
  584. if ( ( (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) ||
  585. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  586. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)) &&
  587. (tp->carrier_ok)) {
  588. tg3_readphy(tp, MII_BMSR, &bmsr);
  589. tg3_readphy(tp, MII_BMSR, &bmsr);
  590. if (!(bmsr & BMSR_LSTATUS))
  591. tg3_phy_reset(tp);
  592. }
  593. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  594. tg3_readphy(tp, MII_BMSR, &bmsr);
  595. tg3_readphy(tp, MII_BMSR, &bmsr);
  596. if (!(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  597. bmsr = 0;
  598. if (!(bmsr & BMSR_LSTATUS)) {
  599. err = tg3_init_5401phy_dsp(tp);
  600. if (err)
  601. return err;
  602. tg3_readphy(tp, MII_BMSR, &bmsr);
  603. for (i = 0; i < 1000; i++) {
  604. udelay(10);
  605. tg3_readphy(tp, MII_BMSR, &bmsr);
  606. if (bmsr & BMSR_LSTATUS) {
  607. udelay(40);
  608. break;
  609. }
  610. }
  611. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  612. !(bmsr & BMSR_LSTATUS) &&
  613. tp->link_config.active_speed == SPEED_1000) {
  614. err = tg3_phy_reset(tp);
  615. if (!err)
  616. err = tg3_init_5401phy_dsp(tp);
  617. if (err)
  618. return err;
  619. }
  620. }
  621. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  622. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  623. /* 5701 {A0,B0} CRC bug workaround */
  624. tg3_writephy(tp, 0x15, 0x0a75);
  625. tg3_writephy(tp, 0x1c, 0x8c68);
  626. tg3_writephy(tp, 0x1c, 0x8d68);
  627. tg3_writephy(tp, 0x1c, 0x8c68);
  628. }
  629. /* Clear pending interrupts... */
  630. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  631. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  632. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  633. if (tp->led_mode == led_mode_three_link)
  634. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  635. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  636. else
  637. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  638. current_link_up = 0;
  639. tg3_readphy(tp, MII_BMSR, &bmsr);
  640. tg3_readphy(tp, MII_BMSR, &bmsr);
  641. if (bmsr & BMSR_LSTATUS) {
  642. uint32_t aux_stat, bmcr;
  643. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  644. for (i = 0; i < 2000; i++) {
  645. udelay(10);
  646. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  647. if (aux_stat)
  648. break;
  649. }
  650. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  651. &tp->link_config.active_speed,
  652. &tp->link_config.active_duplex);
  653. tg3_readphy(tp, MII_BMCR, &bmcr);
  654. tg3_readphy(tp, MII_BMCR, &bmcr);
  655. if (bmcr & BMCR_ANENABLE) {
  656. uint32_t gig_ctrl;
  657. current_link_up = 1;
  658. /* Force autoneg restart if we are exiting
  659. * low power mode.
  660. */
  661. tg3_readphy(tp, MII_TG3_CTRL, &gig_ctrl);
  662. if (!(gig_ctrl & (MII_TG3_CTRL_ADV_1000_HALF |
  663. MII_TG3_CTRL_ADV_1000_FULL))) {
  664. current_link_up = 0;
  665. }
  666. } else {
  667. current_link_up = 0;
  668. }
  669. }
  670. if (current_link_up == 1 &&
  671. (tp->link_config.active_duplex == DUPLEX_FULL)) {
  672. uint32_t local_adv, remote_adv;
  673. tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  674. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  675. tg3_readphy(tp, MII_LPA, &remote_adv);
  676. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  677. /* If we are not advertising full pause capability,
  678. * something is wrong. Bring the link down and reconfigure.
  679. */
  680. if (local_adv != ADVERTISE_PAUSE_CAP) {
  681. current_link_up = 0;
  682. } else {
  683. tg3_setup_flow_control(tp, local_adv, remote_adv);
  684. }
  685. }
  686. if (current_link_up == 0) {
  687. uint32_t tmp;
  688. tg3_phy_copper_begin(tp);
  689. tg3_readphy(tp, MII_BMSR, &tmp);
  690. tg3_readphy(tp, MII_BMSR, &tmp);
  691. if (tmp & BMSR_LSTATUS)
  692. current_link_up = 1;
  693. }
  694. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  695. if (current_link_up == 1) {
  696. if (tp->link_config.active_speed == SPEED_100 ||
  697. tp->link_config.active_speed == SPEED_10)
  698. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  699. else
  700. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  701. } else
  702. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  703. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  704. if (tp->link_config.active_duplex == DUPLEX_HALF)
  705. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  706. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  707. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  708. if ((tp->led_mode == led_mode_link10) ||
  709. (current_link_up == 1 &&
  710. tp->link_config.active_speed == SPEED_10))
  711. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  712. } else {
  713. if (current_link_up == 1)
  714. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  715. tw32(MAC_LED_CTRL, LED_CTRL_PHY_MODE_1);
  716. }
  717. /* ??? Without this setting Netgear GA302T PHY does not
  718. * ??? send/receive packets...
  719. * With this other PHYs cannot bring up the link
  720. */
  721. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  722. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  723. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  724. tw32_carefully(MAC_MI_MODE, tp->mi_mode);
  725. }
  726. tw32_carefully(MAC_MODE, tp->mac_mode);
  727. /* Link change polled. */
  728. tw32_carefully(MAC_EVENT, 0);
  729. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  730. current_link_up == 1 &&
  731. tp->link_config.active_speed == SPEED_1000 &&
  732. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  733. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  734. udelay(120);
  735. tw32_carefully(MAC_STATUS,
  736. (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED));
  737. tg3_write_mem(
  738. NIC_SRAM_FIRMWARE_MBOX,
  739. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  740. }
  741. if (current_link_up != tp->carrier_ok) {
  742. tp->carrier_ok = current_link_up;
  743. tg3_link_report(tp);
  744. }
  745. return 0;
  746. }
  747. #else
  748. #define tg3_setup_copper_phy(TP) (-EINVAL)
  749. #endif /* SUPPORT_COPPER_PHY */
  750. #if SUPPORT_FIBER_PHY
  751. struct tg3_fiber_aneginfo {
  752. int state;
  753. #define ANEG_STATE_UNKNOWN 0
  754. #define ANEG_STATE_AN_ENABLE 1
  755. #define ANEG_STATE_RESTART_INIT 2
  756. #define ANEG_STATE_RESTART 3
  757. #define ANEG_STATE_DISABLE_LINK_OK 4
  758. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  759. #define ANEG_STATE_ABILITY_DETECT 6
  760. #define ANEG_STATE_ACK_DETECT_INIT 7
  761. #define ANEG_STATE_ACK_DETECT 8
  762. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  763. #define ANEG_STATE_COMPLETE_ACK 10
  764. #define ANEG_STATE_IDLE_DETECT_INIT 11
  765. #define ANEG_STATE_IDLE_DETECT 12
  766. #define ANEG_STATE_LINK_OK 13
  767. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  768. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  769. uint32_t flags;
  770. #define MR_AN_ENABLE 0x00000001
  771. #define MR_RESTART_AN 0x00000002
  772. #define MR_AN_COMPLETE 0x00000004
  773. #define MR_PAGE_RX 0x00000008
  774. #define MR_NP_LOADED 0x00000010
  775. #define MR_TOGGLE_TX 0x00000020
  776. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  777. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  778. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  779. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  780. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  781. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  782. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  783. #define MR_TOGGLE_RX 0x00002000
  784. #define MR_NP_RX 0x00004000
  785. #define MR_LINK_OK 0x80000000
  786. unsigned long link_time, cur_time;
  787. uint32_t ability_match_cfg;
  788. int ability_match_count;
  789. char ability_match, idle_match, ack_match;
  790. uint32_t txconfig, rxconfig;
  791. #define ANEG_CFG_NP 0x00000080
  792. #define ANEG_CFG_ACK 0x00000040
  793. #define ANEG_CFG_RF2 0x00000020
  794. #define ANEG_CFG_RF1 0x00000010
  795. #define ANEG_CFG_PS2 0x00000001
  796. #define ANEG_CFG_PS1 0x00008000
  797. #define ANEG_CFG_HD 0x00004000
  798. #define ANEG_CFG_FD 0x00002000
  799. #define ANEG_CFG_INVAL 0x00001f06
  800. };
  801. #define ANEG_OK 0
  802. #define ANEG_DONE 1
  803. #define ANEG_TIMER_ENAB 2
  804. #define ANEG_FAILED -1
  805. #define ANEG_STATE_SETTLE_TIME 10000
  806. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  807. struct tg3_fiber_aneginfo *ap)
  808. {
  809. unsigned long delta;
  810. uint32_t rx_cfg_reg;
  811. int ret;
  812. if (ap->state == ANEG_STATE_UNKNOWN) {
  813. ap->rxconfig = 0;
  814. ap->link_time = 0;
  815. ap->cur_time = 0;
  816. ap->ability_match_cfg = 0;
  817. ap->ability_match_count = 0;
  818. ap->ability_match = 0;
  819. ap->idle_match = 0;
  820. ap->ack_match = 0;
  821. }
  822. ap->cur_time++;
  823. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  824. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  825. if (rx_cfg_reg != ap->ability_match_cfg) {
  826. ap->ability_match_cfg = rx_cfg_reg;
  827. ap->ability_match = 0;
  828. ap->ability_match_count = 0;
  829. } else {
  830. if (++ap->ability_match_count > 1) {
  831. ap->ability_match = 1;
  832. ap->ability_match_cfg = rx_cfg_reg;
  833. }
  834. }
  835. if (rx_cfg_reg & ANEG_CFG_ACK)
  836. ap->ack_match = 1;
  837. else
  838. ap->ack_match = 0;
  839. ap->idle_match = 0;
  840. } else {
  841. ap->idle_match = 1;
  842. ap->ability_match_cfg = 0;
  843. ap->ability_match_count = 0;
  844. ap->ability_match = 0;
  845. ap->ack_match = 0;
  846. rx_cfg_reg = 0;
  847. }
  848. ap->rxconfig = rx_cfg_reg;
  849. ret = ANEG_OK;
  850. switch(ap->state) {
  851. case ANEG_STATE_UNKNOWN:
  852. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  853. ap->state = ANEG_STATE_AN_ENABLE;
  854. /* fallthru */
  855. case ANEG_STATE_AN_ENABLE:
  856. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  857. if (ap->flags & MR_AN_ENABLE) {
  858. ap->link_time = 0;
  859. ap->cur_time = 0;
  860. ap->ability_match_cfg = 0;
  861. ap->ability_match_count = 0;
  862. ap->ability_match = 0;
  863. ap->idle_match = 0;
  864. ap->ack_match = 0;
  865. ap->state = ANEG_STATE_RESTART_INIT;
  866. } else {
  867. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  868. }
  869. break;
  870. case ANEG_STATE_RESTART_INIT:
  871. ap->link_time = ap->cur_time;
  872. ap->flags &= ~(MR_NP_LOADED);
  873. ap->txconfig = 0;
  874. tw32(MAC_TX_AUTO_NEG, 0);
  875. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  876. tw32_carefully(MAC_MODE, tp->mac_mode);
  877. ret = ANEG_TIMER_ENAB;
  878. ap->state = ANEG_STATE_RESTART;
  879. /* fallthru */
  880. case ANEG_STATE_RESTART:
  881. delta = ap->cur_time - ap->link_time;
  882. if (delta > ANEG_STATE_SETTLE_TIME) {
  883. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  884. } else {
  885. ret = ANEG_TIMER_ENAB;
  886. }
  887. break;
  888. case ANEG_STATE_DISABLE_LINK_OK:
  889. ret = ANEG_DONE;
  890. break;
  891. case ANEG_STATE_ABILITY_DETECT_INIT:
  892. ap->flags &= ~(MR_TOGGLE_TX);
  893. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  894. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  895. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  896. tw32_carefully(MAC_MODE, tp->mac_mode);
  897. ap->state = ANEG_STATE_ABILITY_DETECT;
  898. break;
  899. case ANEG_STATE_ABILITY_DETECT:
  900. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  901. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  902. }
  903. break;
  904. case ANEG_STATE_ACK_DETECT_INIT:
  905. ap->txconfig |= ANEG_CFG_ACK;
  906. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  907. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  908. tw32_carefully(MAC_MODE, tp->mac_mode);
  909. ap->state = ANEG_STATE_ACK_DETECT;
  910. /* fallthru */
  911. case ANEG_STATE_ACK_DETECT:
  912. if (ap->ack_match != 0) {
  913. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  914. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  915. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  916. } else {
  917. ap->state = ANEG_STATE_AN_ENABLE;
  918. }
  919. } else if (ap->ability_match != 0 &&
  920. ap->rxconfig == 0) {
  921. ap->state = ANEG_STATE_AN_ENABLE;
  922. }
  923. break;
  924. case ANEG_STATE_COMPLETE_ACK_INIT:
  925. if (ap->rxconfig & ANEG_CFG_INVAL) {
  926. ret = ANEG_FAILED;
  927. break;
  928. }
  929. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  930. MR_LP_ADV_HALF_DUPLEX |
  931. MR_LP_ADV_SYM_PAUSE |
  932. MR_LP_ADV_ASYM_PAUSE |
  933. MR_LP_ADV_REMOTE_FAULT1 |
  934. MR_LP_ADV_REMOTE_FAULT2 |
  935. MR_LP_ADV_NEXT_PAGE |
  936. MR_TOGGLE_RX |
  937. MR_NP_RX);
  938. if (ap->rxconfig & ANEG_CFG_FD)
  939. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  940. if (ap->rxconfig & ANEG_CFG_HD)
  941. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  942. if (ap->rxconfig & ANEG_CFG_PS1)
  943. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  944. if (ap->rxconfig & ANEG_CFG_PS2)
  945. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  946. if (ap->rxconfig & ANEG_CFG_RF1)
  947. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  948. if (ap->rxconfig & ANEG_CFG_RF2)
  949. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  950. if (ap->rxconfig & ANEG_CFG_NP)
  951. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  952. ap->link_time = ap->cur_time;
  953. ap->flags ^= (MR_TOGGLE_TX);
  954. if (ap->rxconfig & 0x0008)
  955. ap->flags |= MR_TOGGLE_RX;
  956. if (ap->rxconfig & ANEG_CFG_NP)
  957. ap->flags |= MR_NP_RX;
  958. ap->flags |= MR_PAGE_RX;
  959. ap->state = ANEG_STATE_COMPLETE_ACK;
  960. ret = ANEG_TIMER_ENAB;
  961. break;
  962. case ANEG_STATE_COMPLETE_ACK:
  963. if (ap->ability_match != 0 &&
  964. ap->rxconfig == 0) {
  965. ap->state = ANEG_STATE_AN_ENABLE;
  966. break;
  967. }
  968. delta = ap->cur_time - ap->link_time;
  969. if (delta > ANEG_STATE_SETTLE_TIME) {
  970. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  971. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  972. } else {
  973. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  974. !(ap->flags & MR_NP_RX)) {
  975. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  976. } else {
  977. ret = ANEG_FAILED;
  978. }
  979. }
  980. }
  981. break;
  982. case ANEG_STATE_IDLE_DETECT_INIT:
  983. ap->link_time = ap->cur_time;
  984. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  985. tw32_carefully(MAC_MODE, tp->mac_mode);
  986. ap->state = ANEG_STATE_IDLE_DETECT;
  987. ret = ANEG_TIMER_ENAB;
  988. break;
  989. case ANEG_STATE_IDLE_DETECT:
  990. if (ap->ability_match != 0 &&
  991. ap->rxconfig == 0) {
  992. ap->state = ANEG_STATE_AN_ENABLE;
  993. break;
  994. }
  995. delta = ap->cur_time - ap->link_time;
  996. if (delta > ANEG_STATE_SETTLE_TIME) {
  997. /* XXX another gem from the Broadcom driver :( */
  998. ap->state = ANEG_STATE_LINK_OK;
  999. }
  1000. break;
  1001. case ANEG_STATE_LINK_OK:
  1002. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  1003. ret = ANEG_DONE;
  1004. break;
  1005. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  1006. /* ??? unimplemented */
  1007. break;
  1008. case ANEG_STATE_NEXT_PAGE_WAIT:
  1009. /* ??? unimplemented */
  1010. break;
  1011. default:
  1012. ret = ANEG_FAILED;
  1013. break;
  1014. };
  1015. return ret;
  1016. }
  1017. static int tg3_setup_fiber_phy(struct tg3 *tp)
  1018. {
  1019. uint32_t orig_pause_cfg;
  1020. uint16_t orig_active_speed;
  1021. uint8_t orig_active_duplex;
  1022. int current_link_up;
  1023. int i;
  1024. orig_pause_cfg =
  1025. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  1026. TG3_FLAG_TX_PAUSE));
  1027. orig_active_speed = tp->link_config.active_speed;
  1028. orig_active_duplex = tp->link_config.active_duplex;
  1029. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  1030. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  1031. tw32_carefully(MAC_MODE, tp->mac_mode);
  1032. /* Reset when initting first time or we have a link. */
  1033. if (!(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) ||
  1034. (tr32(MAC_STATUS) & MAC_STATUS_PCS_SYNCED)) {
  1035. /* Set PLL lock range. */
  1036. tg3_writephy(tp, 0x16, 0x8007);
  1037. /* SW reset */
  1038. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  1039. /* Wait for reset to complete. */
  1040. mdelay(5);
  1041. /* Config mode; select PMA/Ch 1 regs. */
  1042. tg3_writephy(tp, 0x10, 0x8411);
  1043. /* Enable auto-lock and comdet, select txclk for tx. */
  1044. tg3_writephy(tp, 0x11, 0x0a10);
  1045. tg3_writephy(tp, 0x18, 0x00a0);
  1046. tg3_writephy(tp, 0x16, 0x41ff);
  1047. /* Assert and deassert POR. */
  1048. tg3_writephy(tp, 0x13, 0x0400);
  1049. udelay(40);
  1050. tg3_writephy(tp, 0x13, 0x0000);
  1051. tg3_writephy(tp, 0x11, 0x0a50);
  1052. udelay(40);
  1053. tg3_writephy(tp, 0x11, 0x0a10);
  1054. /* Wait for signal to stabilize */
  1055. mdelay(150);
  1056. /* Deselect the channel register so we can read the PHYID
  1057. * later.
  1058. */
  1059. tg3_writephy(tp, 0x10, 0x8011);
  1060. }
  1061. /* Disable link change interrupt. */
  1062. tw32_carefully(MAC_EVENT, 0);
  1063. current_link_up = 0;
  1064. if (tr32(MAC_STATUS) & MAC_STATUS_PCS_SYNCED) {
  1065. if (!(tp->tg3_flags & TG3_FLAG_GOT_SERDES_FLOWCTL)) {
  1066. struct tg3_fiber_aneginfo aninfo;
  1067. int status = ANEG_FAILED;
  1068. unsigned int tick;
  1069. uint32_t tmp;
  1070. memset(&aninfo, 0, sizeof(aninfo));
  1071. aninfo.flags |= (MR_AN_ENABLE);
  1072. tw32(MAC_TX_AUTO_NEG, 0);
  1073. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  1074. tw32_carefully(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  1075. tw32_carefully(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  1076. aninfo.state = ANEG_STATE_UNKNOWN;
  1077. aninfo.cur_time = 0;
  1078. tick = 0;
  1079. while (++tick < 195000) {
  1080. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  1081. if (status == ANEG_DONE ||
  1082. status == ANEG_FAILED)
  1083. break;
  1084. udelay(1);
  1085. }
  1086. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1087. tw32_carefully(MAC_MODE, tp->mac_mode);
  1088. if (status == ANEG_DONE &&
  1089. (aninfo.flags &
  1090. (MR_AN_COMPLETE | MR_LINK_OK |
  1091. MR_LP_ADV_FULL_DUPLEX))) {
  1092. uint32_t local_adv, remote_adv;
  1093. local_adv = ADVERTISE_PAUSE_CAP;
  1094. remote_adv = 0;
  1095. if (aninfo.flags & MR_LP_ADV_SYM_PAUSE)
  1096. remote_adv |= LPA_PAUSE_CAP;
  1097. if (aninfo.flags & MR_LP_ADV_ASYM_PAUSE)
  1098. remote_adv |= LPA_PAUSE_ASYM;
  1099. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1100. tp->tg3_flags |=
  1101. TG3_FLAG_GOT_SERDES_FLOWCTL;
  1102. current_link_up = 1;
  1103. }
  1104. for (i = 0; i < 60; i++) {
  1105. udelay(20);
  1106. tw32_carefully(MAC_STATUS,
  1107. (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED));
  1108. if ((tr32(MAC_STATUS) &
  1109. (MAC_STATUS_SYNC_CHANGED |
  1110. MAC_STATUS_CFG_CHANGED)) == 0)
  1111. break;
  1112. }
  1113. if (current_link_up == 0 &&
  1114. (tr32(MAC_STATUS) & MAC_STATUS_PCS_SYNCED)) {
  1115. current_link_up = 1;
  1116. }
  1117. } else {
  1118. /* Forcing 1000FD link up. */
  1119. current_link_up = 1;
  1120. }
  1121. }
  1122. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1123. tw32_carefully(MAC_MODE, tp->mac_mode);
  1124. tp->hw_status->status =
  1125. (SD_STATUS_UPDATED |
  1126. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  1127. for (i = 0; i < 100; i++) {
  1128. udelay(20);
  1129. tw32_carefully(MAC_STATUS,
  1130. (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED));
  1131. if ((tr32(MAC_STATUS) &
  1132. (MAC_STATUS_SYNC_CHANGED |
  1133. MAC_STATUS_CFG_CHANGED)) == 0)
  1134. break;
  1135. }
  1136. if ((tr32(MAC_STATUS) & MAC_STATUS_PCS_SYNCED) == 0)
  1137. current_link_up = 0;
  1138. if (current_link_up == 1) {
  1139. tp->link_config.active_speed = SPEED_1000;
  1140. tp->link_config.active_duplex = DUPLEX_FULL;
  1141. } else {
  1142. tp->link_config.active_speed = SPEED_INVALID;
  1143. tp->link_config.active_duplex = DUPLEX_INVALID;
  1144. }
  1145. if (current_link_up != tp->carrier_ok) {
  1146. tp->carrier_ok = current_link_up;
  1147. tg3_link_report(tp);
  1148. } else {
  1149. uint32_t now_pause_cfg =
  1150. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  1151. TG3_FLAG_TX_PAUSE);
  1152. if (orig_pause_cfg != now_pause_cfg ||
  1153. orig_active_speed != tp->link_config.active_speed ||
  1154. orig_active_duplex != tp->link_config.active_duplex)
  1155. tg3_link_report(tp);
  1156. }
  1157. if ((tr32(MAC_STATUS) & MAC_STATUS_PCS_SYNCED) == 0) {
  1158. tw32_carefully(MAC_MODE, tp->mac_mode | MAC_MODE_LINK_POLARITY);
  1159. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  1160. tw32_carefully(MAC_MODE, tp->mac_mode);
  1161. }
  1162. }
  1163. return 0;
  1164. }
  1165. #else
  1166. #define tg3_setup_fiber_phy(TP) (-EINVAL)
  1167. #endif /* SUPPORT_FIBER_PHY */
  1168. static int tg3_setup_phy(struct tg3 *tp)
  1169. {
  1170. int err;
  1171. if (tp->phy_id == PHY_ID_SERDES) {
  1172. err = tg3_setup_fiber_phy(tp);
  1173. } else {
  1174. err = tg3_setup_copper_phy(tp);
  1175. }
  1176. if (tp->link_config.active_speed == SPEED_1000 &&
  1177. tp->link_config.active_duplex == DUPLEX_HALF)
  1178. tw32(MAC_TX_LENGTHS,
  1179. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  1180. (6 << TX_LENGTHS_IPG_SHIFT) |
  1181. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  1182. else
  1183. tw32(MAC_TX_LENGTHS,
  1184. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  1185. (6 << TX_LENGTHS_IPG_SHIFT) |
  1186. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  1187. return err;
  1188. }
  1189. #define MAX_WAIT_CNT 1000
  1190. /* To stop a block, clear the enable bit and poll till it
  1191. * clears.
  1192. */
  1193. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, uint32_t enable_bit)
  1194. {
  1195. unsigned int i;
  1196. uint32_t val;
  1197. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  1198. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  1199. switch(ofs) {
  1200. case RCVLSC_MODE:
  1201. case DMAC_MODE:
  1202. case MBFREE_MODE:
  1203. case BUFMGR_MODE:
  1204. case MEMARB_MODE:
  1205. /* We can't enable/disable these bits of the
  1206. * 5705 or 5787, just say success.
  1207. */
  1208. return 0;
  1209. default:
  1210. break;
  1211. }
  1212. }
  1213. val = tr32(ofs);
  1214. val &= ~enable_bit;
  1215. tw32(ofs, val);
  1216. tr32(ofs);
  1217. for (i = 0; i < MAX_WAIT_CNT; i++) {
  1218. udelay(100);
  1219. val = tr32(ofs);
  1220. if ((val & enable_bit) == 0)
  1221. break;
  1222. }
  1223. if (i == MAX_WAIT_CNT) {
  1224. printf( "tg3_stop_block timed out, ofs=%#lx enable_bit=%3x\n",
  1225. ofs, enable_bit );
  1226. return -ENODEV;
  1227. }
  1228. return 0;
  1229. }
  1230. static int tg3_abort_hw(struct tg3 *tp)
  1231. {
  1232. int i, err;
  1233. uint32_t val;
  1234. tg3_disable_ints(tp);
  1235. tp->rx_mode &= ~RX_MODE_ENABLE;
  1236. tw32_carefully(MAC_RX_MODE, tp->rx_mode);
  1237. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE);
  1238. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  1239. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE);
  1240. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE);
  1241. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE);
  1242. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE);
  1243. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE);
  1244. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE);
  1245. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  1246. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE);
  1247. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  1248. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE);
  1249. if (err)
  1250. goto out;
  1251. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  1252. tw32_carefully(MAC_MODE, tp->mac_mode);
  1253. tp->tx_mode &= ~TX_MODE_ENABLE;
  1254. tw32_carefully(MAC_TX_MODE, tp->tx_mode);
  1255. for (i = 0; i < MAX_WAIT_CNT; i++) {
  1256. udelay(100);
  1257. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  1258. break;
  1259. }
  1260. if (i >= MAX_WAIT_CNT) {
  1261. printf("tg3_abort_hw timed out TX_MODE_ENABLE will not clear MAC_TX_MODE=%x\n",
  1262. (unsigned int) tr32(MAC_TX_MODE));
  1263. return -ENODEV;
  1264. }
  1265. err = tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE);
  1266. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE);
  1267. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE);
  1268. val = tr32(FTQ_RESET);
  1269. val |= FTQ_RESET_DMA_READ_QUEUE | FTQ_RESET_DMA_HIGH_PRI_READ |
  1270. FTQ_RESET_SEND_BD_COMPLETION | FTQ_RESET_DMA_WRITE |
  1271. FTQ_RESET_DMA_HIGH_PRI_WRITE | FTQ_RESET_SEND_DATA_COMPLETION |
  1272. FTQ_RESET_HOST_COALESCING | FTQ_RESET_MAC_TX |
  1273. FTQ_RESET_RX_BD_COMPLETE | FTQ_RESET_RX_LIST_PLCMT |
  1274. FTQ_RESET_RX_DATA_COMPLETION;
  1275. tw32(FTQ_RESET, val);
  1276. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE);
  1277. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE);
  1278. if (err)
  1279. goto out;
  1280. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  1281. out:
  1282. return err;
  1283. }
  1284. static void tg3_chip_reset(struct tg3 *tp)
  1285. {
  1286. uint32_t val;
  1287. if (!(tp->tg3_flags2 & TG3_FLG2_SUN_5704)) {
  1288. /* Force NVRAM to settle.
  1289. * This deals with a chip bug which can result in EEPROM
  1290. * corruption.
  1291. */
  1292. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  1293. int i;
  1294. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  1295. for (i = 0; i < 100000; i++) {
  1296. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  1297. break;
  1298. udelay(10);
  1299. }
  1300. }
  1301. }
  1302. /* In Etherboot we don't need to worry about the 5701
  1303. * REG_WRITE_BUG because we do all register writes indirectly.
  1304. */
  1305. // Alf: here patched
  1306. /* do the reset */
  1307. val = GRC_MISC_CFG_CORECLK_RESET;
  1308. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  1309. if (tr32(0x7e2c) == 0x60) {
  1310. tw32(0x7e2c, 0x20);
  1311. }
  1312. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  1313. tw32(GRC_MISC_CFG, (1 << 29));
  1314. val |= (1 << 29);
  1315. }
  1316. }
  1317. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)
  1318. || (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  1319. || (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)) {
  1320. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  1321. }
  1322. // Alf : Please VALIDATE THIS.
  1323. // It is necessary in my case (5751) to prevent a reboot, but
  1324. // I have no idea about a side effect on any other version.
  1325. // It appears to be what's done in tigon3.c from Broadcom
  1326. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  1327. tw32(GRC_MISC_CFG, 0x20000000) ;
  1328. val |= 0x20000000 ;
  1329. }
  1330. tw32(GRC_MISC_CFG, val);
  1331. /* Flush PCI posted writes. The normal MMIO registers
  1332. * are inaccessible at this time so this is the only
  1333. * way to make this reliably. I tried to use indirect
  1334. * register read/write but this upset some 5701 variants.
  1335. */
  1336. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  1337. udelay(120);
  1338. /* Re-enable indirect register accesses. */
  1339. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  1340. tp->misc_host_ctrl);
  1341. /* Set MAX PCI retry to zero. */
  1342. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  1343. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  1344. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  1345. val |= PCISTATE_RETRY_SAME_DMA;
  1346. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  1347. pci_restore_state(tp->pdev, tp->pci_cfg_state);
  1348. /* Make sure PCI-X relaxed ordering bit is clear. */
  1349. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  1350. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  1351. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  1352. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  1353. if (((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0) &&
  1354. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  1355. tp->pci_clock_ctrl |=
  1356. (CLOCK_CTRL_FORCE_CLKRUN | CLOCK_CTRL_CLKRUN_OENABLE);
  1357. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  1358. }
  1359. tw32(TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl);
  1360. }
  1361. static void tg3_stop_fw(struct tg3 *tp)
  1362. {
  1363. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  1364. uint32_t val;
  1365. int i;
  1366. tg3_write_mem(NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  1367. val = tr32(GRC_RX_CPU_EVENT);
  1368. val |= (1 << 14);
  1369. tw32(GRC_RX_CPU_EVENT, val);
  1370. /* Wait for RX cpu to ACK the event. */
  1371. for (i = 0; i < 100; i++) {
  1372. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  1373. break;
  1374. udelay(1);
  1375. }
  1376. }
  1377. }
  1378. static int tg3_restart_fw(struct tg3 *tp, uint32_t state)
  1379. {
  1380. uint32_t val;
  1381. int i;
  1382. tg3_write_mem(NIC_SRAM_FIRMWARE_MBOX,
  1383. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  1384. /* Wait for firmware initialization to complete. */
  1385. for (i = 0; i < 100000; i++) {
  1386. tg3_read_mem(NIC_SRAM_FIRMWARE_MBOX, &val);
  1387. if (val == (uint32_t) ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1388. break;
  1389. udelay(10);
  1390. }
  1391. if (i >= 100000 &&
  1392. !(tp->tg3_flags2 & TG3_FLG2_SUN_5704) &&
  1393. !(GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)) {
  1394. printf ( "Firmware will not restart magic=%#x\n",
  1395. val );
  1396. return -ENODEV;
  1397. }
  1398. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1399. state = DRV_STATE_SUSPEND;
  1400. }
  1401. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  1402. (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)) {
  1403. // Enable PCIE bug fix
  1404. tg3_read_mem(0x7c00, &val);
  1405. tg3_write_mem(0x7c00, val | 0x02000000);
  1406. }
  1407. tg3_write_mem(NIC_SRAM_FW_DRV_STATE_MBOX, state);
  1408. return 0;
  1409. }
  1410. static int tg3_halt(struct tg3 *tp)
  1411. {
  1412. tg3_stop_fw(tp);
  1413. tg3_abort_hw(tp);
  1414. tg3_chip_reset(tp);
  1415. return tg3_restart_fw(tp, DRV_STATE_UNLOAD);
  1416. }
  1417. static void __tg3_set_mac_addr(struct tg3 *tp)
  1418. {
  1419. uint32_t addr_high, addr_low;
  1420. int i;
  1421. addr_high = ((tp->nic->node_addr[0] << 8) |
  1422. tp->nic->node_addr[1]);
  1423. addr_low = ((tp->nic->node_addr[2] << 24) |
  1424. (tp->nic->node_addr[3] << 16) |
  1425. (tp->nic->node_addr[4] << 8) |
  1426. (tp->nic->node_addr[5] << 0));
  1427. for (i = 0; i < 4; i++) {
  1428. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  1429. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  1430. }
  1431. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  1432. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  1433. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705)) {
  1434. for(i = 0; i < 12; i++) {
  1435. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  1436. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  1437. }
  1438. }
  1439. addr_high = (tp->nic->node_addr[0] +
  1440. tp->nic->node_addr[1] +
  1441. tp->nic->node_addr[2] +
  1442. tp->nic->node_addr[3] +
  1443. tp->nic->node_addr[4] +
  1444. tp->nic->node_addr[5]) &
  1445. TX_BACKOFF_SEED_MASK;
  1446. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  1447. }
  1448. static void tg3_set_bdinfo(struct tg3 *tp, uint32_t bdinfo_addr,
  1449. dma_addr_t mapping, uint32_t maxlen_flags,
  1450. uint32_t nic_addr)
  1451. {
  1452. tg3_write_mem((bdinfo_addr +
  1453. TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  1454. ((uint64_t) mapping >> 32));
  1455. tg3_write_mem((bdinfo_addr +
  1456. TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  1457. ((uint64_t) mapping & 0xffffffff));
  1458. tg3_write_mem((bdinfo_addr +
  1459. TG3_BDINFO_MAXLEN_FLAGS),
  1460. maxlen_flags);
  1461. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  1462. tg3_write_mem((bdinfo_addr + TG3_BDINFO_NIC_ADDR), nic_addr);
  1463. }
  1464. }
  1465. static void tg3_init_rings(struct tg3 *tp)
  1466. {
  1467. unsigned i;
  1468. /* Zero out the tg3 variables */
  1469. memset(&tg3_bss, 0, sizeof(tg3_bss));
  1470. tp->rx_std = &tg3_bss.rx_std[0];
  1471. tp->rx_rcb = &tg3_bss.rx_rcb[0];
  1472. tp->tx_ring = &tg3_bss.tx_ring[0];
  1473. tp->hw_status = &tg3_bss.hw_status;
  1474. tp->hw_stats = &tg3_bss.hw_stats;
  1475. tp->mac_mode = 0;
  1476. /* Initialize tx/rx rings for packet processing.
  1477. *
  1478. * The chip has been shut down and the driver detached from
  1479. * the networking, so no interrupts or new tx packets will
  1480. * end up in the driver.
  1481. */
  1482. /* Initialize invariants of the rings, we only set this
  1483. * stuff once. This works because the card does not
  1484. * write into the rx buffer posting rings.
  1485. */
  1486. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  1487. struct tg3_rx_buffer_desc *rxd;
  1488. rxd = &tp->rx_std[i];
  1489. rxd->idx_len = (RX_PKT_BUF_SZ - 2 - 64) << RXD_LEN_SHIFT;
  1490. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  1491. rxd->opaque = (RXD_OPAQUE_RING_STD | (i << RXD_OPAQUE_INDEX_SHIFT));
  1492. /* Note where the receive buffer for the ring is placed */
  1493. rxd->addr_hi = 0;
  1494. rxd->addr_lo = virt_to_bus(
  1495. &tg3_bss.rx_bufs[i%TG3_DEF_RX_RING_PENDING][2]);
  1496. }
  1497. }
  1498. #define TG3_WRITE_SETTINGS(TABLE) \
  1499. do { \
  1500. const uint32_t *_table, *_end; \
  1501. _table = TABLE; \
  1502. _end = _table + sizeof(TABLE)/sizeof(TABLE[0]); \
  1503. for(; _table < _end; _table += 2) { \
  1504. tw32(_table[0], _table[1]); \
  1505. } \
  1506. } while(0)
  1507. /* initialize/reset the tg3 */
  1508. static int tg3_setup_hw(struct tg3 *tp)
  1509. {
  1510. uint32_t val, rdmac_mode;
  1511. int i, err, limit;
  1512. /* Simply don't support setups with extremly buggy firmware in etherboot */
  1513. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  1514. printf("Error 5701_A0 firmware bug detected\n");
  1515. return -EINVAL;
  1516. }
  1517. tg3_disable_ints(tp);
  1518. /* Originally this was all in tg3_init_hw */
  1519. /* Force the chip into D0. */
  1520. tg3_set_power_state_0(tp);
  1521. tg3_switch_clocks(tp);
  1522. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  1523. // This should go somewhere else
  1524. #define T3_PCIE_CAPABILITY_ID_REG 0xD0
  1525. #define T3_PCIE_CAPABILITY_ID 0x10
  1526. #define T3_PCIE_CAPABILITY_REG 0xD2
  1527. /* Originally this was all in tg3_reset_hw */
  1528. tg3_stop_fw(tp);
  1529. /* No need to call tg3_abort_hw here, it is called before tg3_setup_hw. */
  1530. tg3_chip_reset(tp);
  1531. tw32(GRC_MODE, tp->grc_mode); /* Redundant? */
  1532. err = tg3_restart_fw(tp, DRV_STATE_START);
  1533. if (err)
  1534. return err;
  1535. if (tp->phy_id == PHY_ID_SERDES) {
  1536. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  1537. }
  1538. tw32_carefully(MAC_MODE, tp->mac_mode);
  1539. /* This works around an issue with Athlon chipsets on
  1540. * B3 tigon3 silicon. This bit has no effect on any
  1541. * other revision.
  1542. * Alf: Except 5750 ! (which reboots)
  1543. */
  1544. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  1545. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  1546. tw32_carefully(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  1547. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  1548. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  1549. val = tr32(TG3PCI_PCISTATE);
  1550. val |= PCISTATE_RETRY_SAME_DMA;
  1551. tw32(TG3PCI_PCISTATE, val);
  1552. }
  1553. /* Descriptor ring init may make accesses to the
  1554. * NIC SRAM area to setup the TX descriptors, so we
  1555. * can only do this after the hardware has been
  1556. * successfully reset.
  1557. */
  1558. tg3_init_rings(tp);
  1559. /* Clear statistics/status block in chip */
  1560. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  1561. for (i = NIC_SRAM_STATS_BLK;
  1562. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  1563. i += sizeof(uint32_t)) {
  1564. tg3_write_mem(i, 0);
  1565. udelay(40);
  1566. }
  1567. }
  1568. /* This value is determined during the probe time DMA
  1569. * engine test, tg3_setup_dma.
  1570. */
  1571. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  1572. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  1573. GRC_MODE_4X_NIC_SEND_RINGS |
  1574. GRC_MODE_NO_TX_PHDR_CSUM |
  1575. GRC_MODE_NO_RX_PHDR_CSUM);
  1576. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  1577. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  1578. tp->grc_mode |= GRC_MODE_NO_RX_PHDR_CSUM;
  1579. tw32(GRC_MODE,
  1580. tp->grc_mode |
  1581. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  1582. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  1583. tw32(GRC_MISC_CFG,
  1584. (65 << GRC_MISC_CFG_PRESCALAR_SHIFT));
  1585. /* Initialize MBUF/DESC pool. */
  1586. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  1587. /* Do nothing. */
  1588. } else if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) &&
  1589. (tp->pci_chip_rev_id != CHIPREV_ID_5721)) {
  1590. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  1591. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  1592. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  1593. else
  1594. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  1595. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  1596. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  1597. }
  1598. if (!(tp->tg3_flags & TG3_FLAG_JUMBO_ENABLE)) {
  1599. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  1600. tp->bufmgr_config.mbuf_read_dma_low_water);
  1601. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  1602. tp->bufmgr_config.mbuf_mac_rx_low_water);
  1603. tw32(BUFMGR_MB_HIGH_WATER,
  1604. tp->bufmgr_config.mbuf_high_water);
  1605. } else {
  1606. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  1607. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  1608. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  1609. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  1610. tw32(BUFMGR_MB_HIGH_WATER,
  1611. tp->bufmgr_config.mbuf_high_water_jumbo);
  1612. }
  1613. tw32(BUFMGR_DMA_LOW_WATER,
  1614. tp->bufmgr_config.dma_low_water);
  1615. tw32(BUFMGR_DMA_HIGH_WATER,
  1616. tp->bufmgr_config.dma_high_water);
  1617. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  1618. for (i = 0; i < 2000; i++) {
  1619. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  1620. break;
  1621. udelay(10);
  1622. }
  1623. if (i >= 2000) {
  1624. printf("tg3_setup_hw cannot enable BUFMGR\n");
  1625. return -ENODEV;
  1626. }
  1627. tw32(FTQ_RESET, 0xffffffff);
  1628. tw32(FTQ_RESET, 0x00000000);
  1629. for (i = 0; i < 2000; i++) {
  1630. if (tr32(FTQ_RESET) == 0x00000000)
  1631. break;
  1632. udelay(10);
  1633. }
  1634. if (i >= 2000) {
  1635. printf("tg3_setup_hw cannot reset FTQ\n");
  1636. return -ENODEV;
  1637. }
  1638. /* Initialize TG3_BDINFO's at:
  1639. * RCVDBDI_STD_BD: standard eth size rx ring
  1640. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  1641. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  1642. *
  1643. * like so:
  1644. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  1645. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  1646. * ring attribute flags
  1647. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  1648. *
  1649. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  1650. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  1651. *
  1652. * ??? No space allocated for mini receive ring? :(
  1653. *
  1654. * The size of each ring is fixed in the firmware, but the location is
  1655. * configurable.
  1656. */
  1657. {
  1658. static const uint32_t table_all[] = {
  1659. /* Setup replenish thresholds. */
  1660. RCVBDI_STD_THRESH, TG3_DEF_RX_RING_PENDING / 8,
  1661. /* Etherboot lives below 4GB */
  1662. RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, 0,
  1663. RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, NIC_SRAM_RX_BUFFER_DESC,
  1664. };
  1665. static const uint32_t table_not_5705[] = {
  1666. /* Buffer maximum length */
  1667. RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT,
  1668. /* Disable the mini frame rx ring */
  1669. RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, BDINFO_FLAGS_DISABLED,
  1670. /* Disable the jumbo frame rx ring */
  1671. RCVBDI_JUMBO_THRESH, 0,
  1672. RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, BDINFO_FLAGS_DISABLED,
  1673. };
  1674. TG3_WRITE_SETTINGS(table_all);
  1675. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  1676. virt_to_bus(tp->rx_std));
  1677. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  1678. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  1679. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  1680. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  1681. } else {
  1682. TG3_WRITE_SETTINGS(table_not_5705);
  1683. }
  1684. }
  1685. /* There is only one send ring on 5705 and 5787, no need to explicitly
  1686. * disable the others.
  1687. */
  1688. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  1689. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) {
  1690. /* Clear out send RCB ring in SRAM. */
  1691. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  1692. tg3_write_mem(i + TG3_BDINFO_MAXLEN_FLAGS, BDINFO_FLAGS_DISABLED);
  1693. }
  1694. tp->tx_prod = 0;
  1695. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  1696. tw32_mailbox2(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  1697. tg3_set_bdinfo(tp,
  1698. NIC_SRAM_SEND_RCB,
  1699. virt_to_bus(tp->tx_ring),
  1700. (TG3_TX_RING_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT),
  1701. NIC_SRAM_TX_BUFFER_DESC);
  1702. /* There is only one receive return ring on 5705 and 5787, no need to
  1703. * explicitly disable the others.
  1704. */
  1705. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  1706. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) {
  1707. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK; i += TG3_BDINFO_SIZE) {
  1708. tg3_write_mem(i + TG3_BDINFO_MAXLEN_FLAGS,
  1709. BDINFO_FLAGS_DISABLED);
  1710. }
  1711. }
  1712. tp->rx_rcb_ptr = 0;
  1713. tw32_mailbox2(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  1714. tg3_set_bdinfo(tp,
  1715. NIC_SRAM_RCV_RET_RCB,
  1716. virt_to_bus(tp->rx_rcb),
  1717. (TG3_RX_RCB_RING_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT),
  1718. 0);
  1719. tp->rx_std_ptr = TG3_DEF_RX_RING_PENDING;
  1720. tw32_mailbox2(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  1721. tp->rx_std_ptr);
  1722. tw32_mailbox2(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW, 0);
  1723. /* Initialize MAC address and backoff seed. */
  1724. __tg3_set_mac_addr(tp);
  1725. /* Calculate RDMAC_MODE setting early, we need it to determine
  1726. * the RCVLPC_STATE_ENABLE mask.
  1727. */
  1728. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  1729. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  1730. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  1731. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  1732. RDMAC_MODE_LNGREAD_ENAB);
  1733. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  1734. rdmac_mode |= RDMAC_MODE_SPLIT_ENABLE;
  1735. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  1736. if (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) {
  1737. if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  1738. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  1739. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  1740. }
  1741. }
  1742. }
  1743. /* Setup host coalescing engine. */
  1744. tw32(HOSTCC_MODE, 0);
  1745. for (i = 0; i < 2000; i++) {
  1746. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  1747. break;
  1748. udelay(10);
  1749. }
  1750. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  1751. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  1752. tw32_carefully(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  1753. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  1754. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  1755. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  1756. GRC_LCLCTRL_GPIO_OUTPUT1);
  1757. tw32_carefully(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  1758. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  1759. tr32(MAILBOX_INTERRUPT_0);
  1760. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  1761. tw32_carefully(DMAC_MODE, DMAC_MODE_ENABLE);
  1762. }
  1763. val = ( WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  1764. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  1765. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  1766. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  1767. WDMAC_MODE_LNGREAD_ENAB);
  1768. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) &&
  1769. ((tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) != 0) &&
  1770. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  1771. val |= WDMAC_MODE_RX_ACCEL;
  1772. }
  1773. /* Host coalescing bug fix */
  1774. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  1775. val |= (1 << 29);
  1776. tw32_carefully(WDMAC_MODE, val);
  1777. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  1778. val = tr32(TG3PCI_X_CAPS);
  1779. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  1780. val &= PCIX_CAPS_BURST_MASK;
  1781. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  1782. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1783. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  1784. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  1785. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  1786. val |= (tp->split_mode_max_reqs <<
  1787. PCIX_CAPS_SPLIT_SHIFT);
  1788. }
  1789. tw32(TG3PCI_X_CAPS, val);
  1790. }
  1791. tw32_carefully(RDMAC_MODE, rdmac_mode);
  1792. {
  1793. static const uint32_t table_all[] = {
  1794. /* MTU + ethernet header + FCS + optional VLAN tag */
  1795. MAC_RX_MTU_SIZE, ETH_MAX_MTU + ETH_HLEN + 8,
  1796. /* The slot time is changed by tg3_setup_phy if we
  1797. * run at gigabit with half duplex.
  1798. */
  1799. MAC_TX_LENGTHS,
  1800. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  1801. (6 << TX_LENGTHS_IPG_SHIFT) |
  1802. (32 << TX_LENGTHS_SLOT_TIME_SHIFT),
  1803. /* Receive rules. */
  1804. MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS,
  1805. RCVLPC_CONFIG, 0x0181,
  1806. /* Receive/send statistics. */
  1807. RCVLPC_STATS_ENABLE, 0xffffff,
  1808. RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE,
  1809. SNDDATAI_STATSENAB, 0xffffff,
  1810. SNDDATAI_STATSCTRL, (SNDDATAI_SCTRL_ENABLE |SNDDATAI_SCTRL_FASTUPD),
  1811. /* Host coalescing engine */
  1812. HOSTCC_RXCOL_TICKS, 0,
  1813. HOSTCC_TXCOL_TICKS, LOW_TXCOL_TICKS,
  1814. HOSTCC_RXMAX_FRAMES, 1,
  1815. HOSTCC_TXMAX_FRAMES, LOW_RXMAX_FRAMES,
  1816. HOSTCC_RXCOAL_MAXF_INT, 1,
  1817. HOSTCC_TXCOAL_MAXF_INT, 0,
  1818. /* Status/statistics block address. */
  1819. /* Etherboot lives below 4GB, so HIGH == 0 */
  1820. HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, 0,
  1821. /* No need to enable 32byte coalesce mode. */
  1822. HOSTCC_MODE, HOSTCC_MODE_ENABLE | 0,
  1823. RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE,
  1824. RCVLPC_MODE, RCVLPC_MODE_ENABLE,
  1825. RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE,
  1826. SNDDATAC_MODE, SNDDATAC_MODE_ENABLE,
  1827. SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE,
  1828. RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB,
  1829. RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ,
  1830. SNDDATAI_MODE, SNDDATAI_MODE_ENABLE,
  1831. SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE,
  1832. SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE,
  1833. /* Accept all multicast frames. */
  1834. MAC_HASH_REG_0, 0xffffffff,
  1835. MAC_HASH_REG_1, 0xffffffff,
  1836. MAC_HASH_REG_2, 0xffffffff,
  1837. MAC_HASH_REG_3, 0xffffffff,
  1838. };
  1839. static const uint32_t table_not_5705[] = {
  1840. /* Host coalescing engine */
  1841. HOSTCC_RXCOAL_TICK_INT, 0,
  1842. HOSTCC_TXCOAL_TICK_INT, 0,
  1843. /* Status/statistics block address. */
  1844. /* Etherboot lives below 4GB, so HIGH == 0 */
  1845. HOSTCC_STAT_COAL_TICKS, DEFAULT_STAT_COAL_TICKS,
  1846. HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, 0,
  1847. HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK,
  1848. HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK,
  1849. RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE,
  1850. MBFREE_MODE, MBFREE_MODE_ENABLE,
  1851. };
  1852. TG3_WRITE_SETTINGS(table_all);
  1853. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  1854. virt_to_bus(tp->hw_stats));
  1855. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  1856. virt_to_bus(tp->hw_status));
  1857. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  1858. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) {
  1859. TG3_WRITE_SETTINGS(table_not_5705);
  1860. }
  1861. }
  1862. tp->tx_mode = TX_MODE_ENABLE;
  1863. tw32_carefully(MAC_TX_MODE, tp->tx_mode);
  1864. tp->rx_mode = RX_MODE_ENABLE;
  1865. tw32_carefully(MAC_RX_MODE, tp->rx_mode);
  1866. tp->mi_mode = MAC_MI_MODE_BASE;
  1867. tw32_carefully(MAC_MI_MODE, tp->mi_mode);
  1868. tw32(MAC_LED_CTRL, 0);
  1869. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  1870. if (tp->phy_id == PHY_ID_SERDES) {
  1871. tw32_carefully(MAC_RX_MODE, RX_MODE_RESET);
  1872. }
  1873. tp->rx_mode |= RX_MODE_KEEP_VLAN_TAG; /* drop tagged vlan packets */
  1874. tw32_carefully(MAC_RX_MODE, tp->rx_mode);
  1875. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  1876. tw32(MAC_SERDES_CFG, 0x616000);
  1877. /* Prevent chip from dropping frames when flow control
  1878. * is enabled.
  1879. */
  1880. tw32(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  1881. tr32(MAC_LOW_WMARK_MAX_RX_FRAME);
  1882. err = tg3_setup_phy(tp);
  1883. /* Ignore CRC stats */
  1884. /* Initialize receive rules. */
  1885. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  1886. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  1887. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  1888. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  1889. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)
  1890. || (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750))
  1891. limit = 8;
  1892. else
  1893. limit = 16;
  1894. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  1895. limit -= 4;
  1896. switch (limit) {
  1897. case 16: tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  1898. case 15: tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  1899. case 14: tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  1900. case 13: tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  1901. case 12: tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  1902. case 11: tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  1903. case 10: tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  1904. case 9: tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  1905. case 8: tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  1906. case 7: tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  1907. case 6: tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  1908. case 5: tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  1909. case 4: /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  1910. case 3: /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  1911. case 2:
  1912. case 1:
  1913. default:
  1914. break;
  1915. };
  1916. return err;
  1917. }
  1918. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  1919. static void tg3_nvram_init(struct tg3 *tp)
  1920. {
  1921. tw32(GRC_EEPROM_ADDR,
  1922. (EEPROM_ADDR_FSM_RESET |
  1923. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  1924. EEPROM_ADDR_CLKPERD_SHIFT)));
  1925. mdelay(1);
  1926. /* Enable seeprom accesses. */
  1927. tw32_carefully(GRC_LOCAL_CTRL,
  1928. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  1929. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  1930. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  1931. uint32_t nvcfg1 = tr32(NVRAM_CFG1);
  1932. tp->tg3_flags |= TG3_FLAG_NVRAM;
  1933. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  1934. if (nvcfg1 & NVRAM_CFG1_BUFFERED_MODE)
  1935. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  1936. } else {
  1937. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  1938. tw32(NVRAM_CFG1, nvcfg1);
  1939. }
  1940. } else {
  1941. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  1942. }
  1943. }
  1944. static int tg3_nvram_read_using_eeprom(
  1945. struct tg3 *tp __unused, uint32_t offset, uint32_t *val)
  1946. {
  1947. uint32_t tmp;
  1948. int i;
  1949. if (offset > EEPROM_ADDR_ADDR_MASK ||
  1950. (offset % 4) != 0) {
  1951. return -EINVAL;
  1952. }
  1953. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  1954. EEPROM_ADDR_DEVID_MASK |
  1955. EEPROM_ADDR_READ);
  1956. tw32(GRC_EEPROM_ADDR,
  1957. tmp |
  1958. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  1959. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  1960. EEPROM_ADDR_ADDR_MASK) |
  1961. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  1962. for (i = 0; i < 10000; i++) {
  1963. tmp = tr32(GRC_EEPROM_ADDR);
  1964. if (tmp & EEPROM_ADDR_COMPLETE)
  1965. break;
  1966. udelay(100);
  1967. }
  1968. if (!(tmp & EEPROM_ADDR_COMPLETE)) {
  1969. return -EBUSY;
  1970. }
  1971. *val = tr32(GRC_EEPROM_DATA);
  1972. return 0;
  1973. }
  1974. static int tg3_nvram_read(struct tg3 *tp, uint32_t offset, uint32_t *val)
  1975. {
  1976. int i, saw_done_clear;
  1977. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  1978. return tg3_nvram_read_using_eeprom(tp, offset, val);
  1979. if (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED)
  1980. offset = ((offset / NVRAM_BUFFERED_PAGE_SIZE) <<
  1981. NVRAM_BUFFERED_PAGE_POS) +
  1982. (offset % NVRAM_BUFFERED_PAGE_SIZE);
  1983. if (offset > NVRAM_ADDR_MSK)
  1984. return -EINVAL;
  1985. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  1986. for (i = 0; i < 1000; i++) {
  1987. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  1988. break;
  1989. udelay(20);
  1990. }
  1991. tw32(NVRAM_ADDR, offset);
  1992. tw32(NVRAM_CMD,
  1993. NVRAM_CMD_RD | NVRAM_CMD_GO |
  1994. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  1995. /* Wait for done bit to clear then set again. */
  1996. saw_done_clear = 0;
  1997. for (i = 0; i < 1000; i++) {
  1998. udelay(10);
  1999. if (!saw_done_clear &&
  2000. !(tr32(NVRAM_CMD) & NVRAM_CMD_DONE))
  2001. saw_done_clear = 1;
  2002. else if (saw_done_clear &&
  2003. (tr32(NVRAM_CMD) & NVRAM_CMD_DONE))
  2004. break;
  2005. }
  2006. if (i >= 1000) {
  2007. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  2008. return -EBUSY;
  2009. }
  2010. *val = bswap_32(tr32(NVRAM_RDDATA));
  2011. tw32(NVRAM_SWARB, 0x20);
  2012. return 0;
  2013. }
  2014. struct subsys_tbl_ent {
  2015. uint16_t subsys_vendor, subsys_devid;
  2016. uint32_t phy_id;
  2017. };
  2018. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  2019. /* Broadcom boards. */
  2020. { 0x14e4, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  2021. { 0x14e4, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  2022. { 0x14e4, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  2023. { 0x14e4, 0x0003, PHY_ID_SERDES }, /* BCM95700A9 */
  2024. { 0x14e4, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  2025. { 0x14e4, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  2026. { 0x14e4, 0x0007, PHY_ID_SERDES }, /* BCM95701A7 */
  2027. { 0x14e4, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  2028. { 0x14e4, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  2029. { 0x14e4, 0x0009, PHY_ID_BCM5701 }, /* BCM95703Ax1 */
  2030. { 0x14e4, 0x8009, PHY_ID_BCM5701 }, /* BCM95703Ax2 */
  2031. /* 3com boards. */
  2032. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  2033. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  2034. /* { PCI_VENDOR_ID_3COM, 0x1002, PHY_ID_XXX }, 3C996CT */
  2035. /* { PCI_VENDOR_ID_3COM, 0x1003, PHY_ID_XXX }, 3C997T */
  2036. { PCI_VENDOR_ID_3COM, 0x1004, PHY_ID_SERDES }, /* 3C996SX */
  2037. /* { PCI_VENDOR_ID_3COM, 0x1005, PHY_ID_XXX }, 3C997SZ */
  2038. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  2039. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  2040. /* DELL boards. */
  2041. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  2042. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  2043. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  2044. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  2045. { PCI_VENDOR_ID_DELL, 0x0179, PHY_ID_BCM5751 }, /* EtherXpress */
  2046. /* Fujitsu Siemens Computer */
  2047. { PCI_VENDOR_ID_FSC, 0x105d, PHY_ID_BCM5751 }, /* Futro C200 */
  2048. /* Compaq boards. */
  2049. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  2050. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  2051. { PCI_VENDOR_ID_COMPAQ, 0x007d, PHY_ID_SERDES }, /* CHANGELING */
  2052. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  2053. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 } /* NC7780_2 */
  2054. };
  2055. static int tg3_phy_probe(struct tg3 *tp)
  2056. {
  2057. uint32_t eeprom_phy_id, hw_phy_id_1, hw_phy_id_2;
  2058. uint32_t hw_phy_id, hw_phy_id_masked;
  2059. enum phy_led_mode eeprom_led_mode;
  2060. uint32_t val;
  2061. unsigned i;
  2062. int eeprom_signature_found, err;
  2063. tp->phy_id = PHY_ID_INVALID;
  2064. for (i = 0; i < sizeof(subsys_id_to_phy_id)/sizeof(subsys_id_to_phy_id[0]); i++) {
  2065. if ((subsys_id_to_phy_id[i].subsys_vendor == tp->subsystem_vendor) &&
  2066. (subsys_id_to_phy_id[i].subsys_devid == tp->subsystem_device)) {
  2067. tp->phy_id = subsys_id_to_phy_id[i].phy_id;
  2068. break;
  2069. }
  2070. }
  2071. eeprom_phy_id = PHY_ID_INVALID;
  2072. eeprom_led_mode = led_mode_auto;
  2073. eeprom_signature_found = 0;
  2074. tg3_read_mem(NIC_SRAM_DATA_SIG, &val);
  2075. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  2076. uint32_t nic_cfg;
  2077. tg3_read_mem(NIC_SRAM_DATA_CFG, &nic_cfg);
  2078. tp->nic_sram_data_cfg = nic_cfg;
  2079. eeprom_signature_found = 1;
  2080. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  2081. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) {
  2082. eeprom_phy_id = PHY_ID_SERDES;
  2083. } else {
  2084. uint32_t nic_phy_id;
  2085. tg3_read_mem(NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  2086. if (nic_phy_id != 0) {
  2087. uint32_t id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  2088. uint32_t id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  2089. eeprom_phy_id = (id1 >> 16) << 10;
  2090. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  2091. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  2092. }
  2093. }
  2094. switch (nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK) {
  2095. case NIC_SRAM_DATA_CFG_LED_TRIPLE_SPD:
  2096. eeprom_led_mode = led_mode_three_link;
  2097. break;
  2098. case NIC_SRAM_DATA_CFG_LED_LINK_SPD:
  2099. eeprom_led_mode = led_mode_link10;
  2100. break;
  2101. default:
  2102. eeprom_led_mode = led_mode_auto;
  2103. break;
  2104. };
  2105. if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) ||
  2106. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  2107. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) &&
  2108. (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP)) {
  2109. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  2110. }
  2111. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE)
  2112. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  2113. if (nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)
  2114. tp->tg3_flags |= TG3_FLAG_SERDES_WOL_CAP;
  2115. }
  2116. /* Now read the physical PHY_ID from the chip and verify
  2117. * that it is sane. If it doesn't look good, we fall back
  2118. * to either the hard-coded table based PHY_ID and failing
  2119. * that the value found in the eeprom area.
  2120. */
  2121. err = tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  2122. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  2123. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  2124. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  2125. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  2126. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  2127. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  2128. tp->phy_id = hw_phy_id;
  2129. } else {
  2130. /* phy_id currently holds the value found in the
  2131. * subsys_id_to_phy_id[] table or PHY_ID_INVALID
  2132. * if a match was not found there.
  2133. */
  2134. if (tp->phy_id == PHY_ID_INVALID) {
  2135. if (!eeprom_signature_found ||
  2136. !KNOWN_PHY_ID(eeprom_phy_id & PHY_ID_MASK))
  2137. return -ENODEV;
  2138. tp->phy_id = eeprom_phy_id;
  2139. }
  2140. }
  2141. err = tg3_phy_reset(tp);
  2142. if (err)
  2143. return err;
  2144. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  2145. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  2146. uint32_t mii_tg3_ctrl;
  2147. /* These chips, when reset, only advertise 10Mb
  2148. * capabilities. Fix that.
  2149. */
  2150. err = tg3_writephy(tp, MII_ADVERTISE,
  2151. (ADVERTISE_CSMA |
  2152. ADVERTISE_PAUSE_CAP |
  2153. ADVERTISE_10HALF |
  2154. ADVERTISE_10FULL |
  2155. ADVERTISE_100HALF |
  2156. ADVERTISE_100FULL));
  2157. mii_tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  2158. MII_TG3_CTRL_ADV_1000_FULL |
  2159. MII_TG3_CTRL_AS_MASTER |
  2160. MII_TG3_CTRL_ENABLE_AS_MASTER);
  2161. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  2162. mii_tg3_ctrl = 0;
  2163. err |= tg3_writephy(tp, MII_TG3_CTRL, mii_tg3_ctrl);
  2164. err |= tg3_writephy(tp, MII_BMCR,
  2165. (BMCR_ANRESTART | BMCR_ANENABLE));
  2166. }
  2167. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  2168. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  2169. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  2170. tg3_writedsp(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  2171. }
  2172. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  2173. tg3_writephy(tp, 0x1c, 0x8d68);
  2174. tg3_writephy(tp, 0x1c, 0x8d68);
  2175. }
  2176. /* Enable Ethernet@WireSpeed */
  2177. tg3_phy_set_wirespeed(tp);
  2178. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  2179. err = tg3_init_5401phy_dsp(tp);
  2180. }
  2181. /* Determine the PHY led mode.
  2182. * Be careful if this gets set wrong it can result in an inability to
  2183. * establish a link.
  2184. */
  2185. if (tp->phy_id == PHY_ID_SERDES) {
  2186. tp->led_mode = led_mode_three_link;
  2187. }
  2188. else if (tp->subsystem_vendor == PCI_VENDOR_ID_DELL) {
  2189. tp->led_mode = led_mode_link10;
  2190. } else {
  2191. tp->led_mode = led_mode_three_link;
  2192. if (eeprom_signature_found &&
  2193. eeprom_led_mode != led_mode_auto)
  2194. tp->led_mode = eeprom_led_mode;
  2195. }
  2196. if (tp->phy_id == PHY_ID_SERDES)
  2197. tp->link_config.advertising =
  2198. (ADVERTISED_1000baseT_Half |
  2199. ADVERTISED_1000baseT_Full |
  2200. ADVERTISED_Autoneg |
  2201. ADVERTISED_FIBRE);
  2202. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  2203. tp->link_config.advertising &=
  2204. ~(ADVERTISED_1000baseT_Half |
  2205. ADVERTISED_1000baseT_Full);
  2206. return err;
  2207. }
  2208. #if SUPPORT_PARTNO_STR
  2209. static void tg3_read_partno(struct tg3 *tp)
  2210. {
  2211. unsigned char vpd_data[256];
  2212. int i;
  2213. for (i = 0; i < 256; i += 4) {
  2214. uint32_t tmp;
  2215. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  2216. goto out_not_found;
  2217. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  2218. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  2219. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  2220. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  2221. }
  2222. /* Now parse and find the part number. */
  2223. for (i = 0; i < 256; ) {
  2224. unsigned char val = vpd_data[i];
  2225. int block_end;
  2226. if (val == 0x82 || val == 0x91) {
  2227. i = (i + 3 +
  2228. (vpd_data[i + 1] +
  2229. (vpd_data[i + 2] << 8)));
  2230. continue;
  2231. }
  2232. if (val != 0x90)
  2233. goto out_not_found;
  2234. block_end = (i + 3 +
  2235. (vpd_data[i + 1] +
  2236. (vpd_data[i + 2] << 8)));
  2237. i += 3;
  2238. while (i < block_end) {
  2239. if (vpd_data[i + 0] == 'P' &&
  2240. vpd_data[i + 1] == 'N') {
  2241. int partno_len = vpd_data[i + 2];
  2242. if (partno_len > 24)
  2243. goto out_not_found;
  2244. memcpy(tp->board_part_number,
  2245. &vpd_data[i + 3],
  2246. partno_len);
  2247. /* Success. */
  2248. return;
  2249. }
  2250. }
  2251. /* Part number not found. */
  2252. goto out_not_found;
  2253. }
  2254. out_not_found:
  2255. memcpy(tp->board_part_number, "none", sizeof("none"));
  2256. }
  2257. #else
  2258. #define tg3_read_partno(TP) ((TP)->board_part_number[0] = '\0')
  2259. #endif
  2260. static int tg3_get_invariants(struct tg3 *tp)
  2261. {
  2262. uint32_t misc_ctrl_reg;
  2263. uint32_t pci_state_reg, grc_misc_cfg;
  2264. uint16_t pci_cmd;
  2265. uint8_t pci_latency;
  2266. uint32_t val ;
  2267. int err;
  2268. /* Read the subsystem vendor and device ids */
  2269. pci_read_config_word(tp->pdev, PCI_SUBSYSTEM_VENDOR_ID, &tp->subsystem_vendor);
  2270. pci_read_config_word(tp->pdev, PCI_SUBSYSTEM_ID, &tp->subsystem_device);
  2271. /* The sun_5704 code needs infrastructure etherboot does have
  2272. * ignore it for now.
  2273. */
  2274. /* If we have an AMD 762 or Intel ICH/ICH0 chipset, write
  2275. * reordering to the mailbox registers done by the host
  2276. * controller can cause major troubles. We read back from
  2277. * every mailbox register write to force the writes to be
  2278. * posted to the chip in order.
  2279. *
  2280. * TG3_FLAG_MBOX_WRITE_REORDER has been forced on.
  2281. */
  2282. /* Force memory write invalidate off. If we leave it on,
  2283. * then on 5700_BX chips we have to enable a workaround.
  2284. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundry
  2285. * to match the cacheline size. The Broadcom driver have this
  2286. * workaround but turns MWI off all the times so never uses
  2287. * it. This seems to suggest that the workaround is insufficient.
  2288. */
  2289. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  2290. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  2291. /* Also, force SERR#/PERR# in PCI command. */
  2292. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  2293. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  2294. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  2295. * has the register indirect write enable bit set before
  2296. * we try to access any of the MMIO registers. It is also
  2297. * critical that the PCI-X hw workaround situation is decided
  2298. * before that as well.
  2299. */
  2300. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, &misc_ctrl_reg);
  2301. tp->pci_chip_rev_id = (misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT);
  2302. /* Initialize misc host control in PCI block. */
  2303. tp->misc_host_ctrl |= (misc_ctrl_reg &
  2304. MISC_HOST_CTRL_CHIPREV);
  2305. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  2306. tp->misc_host_ctrl);
  2307. pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, &pci_latency);
  2308. if (pci_latency < 64) {
  2309. pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, 64);
  2310. }
  2311. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &pci_state_reg);
  2312. /* If this is a 5700 BX chipset, and we are in PCI-X
  2313. * mode, enable register write workaround.
  2314. *
  2315. * The workaround is to use indirect register accesses
  2316. * for all chip writes not to mailbox registers.
  2317. *
  2318. * In etherboot to simplify things we just always use this work around.
  2319. */
  2320. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  2321. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  2322. }
  2323. /* Back to back register writes can cause problems on the 5701,
  2324. * the workaround is to read back all reg writes except those to
  2325. * mailbox regs.
  2326. * In etherboot we always use indirect register accesses so
  2327. * we don't see this.
  2328. */
  2329. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  2330. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  2331. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  2332. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  2333. /* Chip-specific fixup from Broadcom driver */
  2334. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  2335. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  2336. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  2337. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  2338. }
  2339. /* determine if it is PCIE system */
  2340. // Alf : I have no idea what this is about...
  2341. // But it's definitely usefull
  2342. val = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  2343. if (val)
  2344. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  2345. /* Force the chip into D0. */
  2346. tg3_set_power_state_0(tp);
  2347. /* Etherboot does not ask the tg3 to do checksums */
  2348. /* Etherboot does not ask the tg3 to do jumbo frames */
  2349. /* Ehterboot does not ask the tg3 to use WakeOnLan. */
  2350. /* A few boards don't want Ethernet@WireSpeed phy feature */
  2351. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  2352. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  2353. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  2354. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  2355. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1))) {
  2356. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  2357. }
  2358. /* Avoid tagged irq status etherboot does not use irqs */
  2359. /* Only 5701 and later support tagged irq status mode.
  2360. * Also, 5788 chips cannot use tagged irq status.
  2361. *
  2362. * However, since etherboot does not use irqs avoid tagged irqs
  2363. * status because the interrupt condition is more difficult to
  2364. * fully clear in that mode.
  2365. */
  2366. /* Since some 5700_AX && 5700_BX have problems with 32BYTE
  2367. * coalesce_mode, and the rest work fine anything set.
  2368. * Don't enable HOST_CC_MODE_32BYTE in etherboot.
  2369. */
  2370. /* Initialize MAC MI mode, polling disabled. */
  2371. tw32_carefully(MAC_MI_MODE, tp->mi_mode);
  2372. /* Initialize data/descriptor byte/word swapping. */
  2373. tw32(GRC_MODE, tp->grc_mode);
  2374. tg3_switch_clocks(tp);
  2375. /* Clear this out for sanity. */
  2376. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  2377. /* Etherboot does not need to check if the PCIX_TARGET_HWBUG
  2378. * is needed. It always uses it.
  2379. */
  2380. udelay(50);
  2381. tg3_nvram_init(tp);
  2382. /* The TX descriptors will reside in main memory.
  2383. */
  2384. /* See which board we are using.
  2385. */
  2386. grc_misc_cfg = tr32(GRC_MISC_CFG);
  2387. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  2388. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  2389. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5704CIOBE) {
  2390. tp->tg3_flags |= TG3_FLAG_SPLIT_MODE;
  2391. tp->split_mode_max_reqs = SPLIT_MODE_5704_MAX_REQ;
  2392. }
  2393. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  2394. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  2395. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  2396. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  2397. #define PCI_DEVICE_ID_TIGON3_5901 0x170d
  2398. #define PCI_DEVICE_ID_TIGON3_5901_2 0x170e
  2399. /* these are limited to 10/100 only */
  2400. if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) &&
  2401. ((grc_misc_cfg == 0x8000) || (grc_misc_cfg == 0x4000))) ||
  2402. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  2403. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM) &&
  2404. ((tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901) ||
  2405. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2)))) {
  2406. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  2407. }
  2408. err = tg3_phy_probe(tp);
  2409. if (err) {
  2410. printf("phy probe failed, err %d\n", err);
  2411. }
  2412. tg3_read_partno(tp);
  2413. /* 5700 BX chips need to have their TX producer index mailboxes
  2414. * written twice to workaround a bug.
  2415. * In etherboot we do this unconditionally to simplify things.
  2416. */
  2417. /* 5700 chips can get confused if TX buffers straddle the
  2418. * 4GB address boundary in some cases.
  2419. *
  2420. * In etherboot we can ignore the problem as etherboot lives below 4GB.
  2421. */
  2422. /* In etherboot wake-on-lan is unconditionally disabled */
  2423. return err;
  2424. }
  2425. static int tg3_get_device_address(struct tg3 *tp)
  2426. {
  2427. struct nic *nic = tp->nic;
  2428. uint32_t hi, lo, mac_offset;
  2429. if (PCI_FUNC(tp->pdev->devfn) == 0)
  2430. mac_offset = 0x7c;
  2431. else
  2432. mac_offset = 0xcc;
  2433. /* First try to get it from MAC address mailbox. */
  2434. tg3_read_mem(NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  2435. if ((hi >> 16) == 0x484b) {
  2436. nic->node_addr[0] = (hi >> 8) & 0xff;
  2437. nic->node_addr[1] = (hi >> 0) & 0xff;
  2438. tg3_read_mem(NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  2439. nic->node_addr[2] = (lo >> 24) & 0xff;
  2440. nic->node_addr[3] = (lo >> 16) & 0xff;
  2441. nic->node_addr[4] = (lo >> 8) & 0xff;
  2442. nic->node_addr[5] = (lo >> 0) & 0xff;
  2443. }
  2444. /* Next, try NVRAM. */
  2445. else if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  2446. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  2447. nic->node_addr[0] = ((hi >> 16) & 0xff);
  2448. nic->node_addr[1] = ((hi >> 24) & 0xff);
  2449. nic->node_addr[2] = ((lo >> 0) & 0xff);
  2450. nic->node_addr[3] = ((lo >> 8) & 0xff);
  2451. nic->node_addr[4] = ((lo >> 16) & 0xff);
  2452. nic->node_addr[5] = ((lo >> 24) & 0xff);
  2453. }
  2454. /* Finally just fetch it out of the MAC control regs. */
  2455. else {
  2456. hi = tr32(MAC_ADDR_0_HIGH);
  2457. lo = tr32(MAC_ADDR_0_LOW);
  2458. nic->node_addr[5] = lo & 0xff;
  2459. nic->node_addr[4] = (lo >> 8) & 0xff;
  2460. nic->node_addr[3] = (lo >> 16) & 0xff;
  2461. nic->node_addr[2] = (lo >> 24) & 0xff;
  2462. nic->node_addr[1] = hi & 0xff;
  2463. nic->node_addr[0] = (hi >> 8) & 0xff;
  2464. }
  2465. return 0;
  2466. }
  2467. static int tg3_setup_dma(struct tg3 *tp)
  2468. {
  2469. tw32(TG3PCI_CLOCK_CTRL, 0);
  2470. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) == 0) {
  2471. tp->dma_rwctrl =
  2472. (0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  2473. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT) |
  2474. (0x7 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  2475. (0x7 << DMA_RWCTRL_READ_WATER_SHIFT) |
  2476. (0x0f << DMA_RWCTRL_MIN_DMA_SHIFT);
  2477. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  2478. tp->dma_rwctrl &= ~(DMA_RWCTRL_MIN_DMA << DMA_RWCTRL_MIN_DMA_SHIFT);
  2479. }
  2480. } else {
  2481. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  2482. tp->dma_rwctrl =
  2483. (0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  2484. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT) |
  2485. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  2486. (0x7 << DMA_RWCTRL_READ_WATER_SHIFT) |
  2487. (0x00 << DMA_RWCTRL_MIN_DMA_SHIFT);
  2488. else
  2489. tp->dma_rwctrl =
  2490. (0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  2491. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT) |
  2492. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  2493. (0x3 << DMA_RWCTRL_READ_WATER_SHIFT) |
  2494. (0x0f << DMA_RWCTRL_MIN_DMA_SHIFT);
  2495. /* Wheee, some more chip bugs... */
  2496. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) ||
  2497. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)) {
  2498. uint32_t ccval = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  2499. if ((ccval == 0x6) || (ccval == 0x7)) {
  2500. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  2501. }
  2502. }
  2503. }
  2504. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) ||
  2505. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)) {
  2506. tp->dma_rwctrl &= ~(DMA_RWCTRL_MIN_DMA << DMA_RWCTRL_MIN_DMA_SHIFT);
  2507. }
  2508. /*
  2509. Alf : Tried that, but it does not work. Should be this way though :-(
  2510. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  2511. tp->dma_rwctrl |= 0x001f0000;
  2512. }
  2513. */
  2514. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  2515. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  2516. return 0;
  2517. }
  2518. static void tg3_init_link_config(struct tg3 *tp)
  2519. {
  2520. tp->link_config.advertising =
  2521. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  2522. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  2523. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  2524. ADVERTISED_Autoneg | ADVERTISED_MII);
  2525. tp->carrier_ok = 0;
  2526. tp->link_config.active_speed = SPEED_INVALID;
  2527. tp->link_config.active_duplex = DUPLEX_INVALID;
  2528. }
  2529. #if SUPPORT_PHY_STR
  2530. static const char * tg3_phy_string(struct tg3 *tp)
  2531. {
  2532. switch (tp->phy_id & PHY_ID_MASK) {
  2533. case PHY_ID_BCM5400: return "5400";
  2534. case PHY_ID_BCM5401: return "5401";
  2535. case PHY_ID_BCM5411: return "5411";
  2536. case PHY_ID_BCM5701: return "5701";
  2537. case PHY_ID_BCM5703: return "5703";
  2538. case PHY_ID_BCM5704: return "5704";
  2539. case PHY_ID_BCM5705: return "5705";
  2540. case PHY_ID_BCM5750: return "5750";
  2541. case PHY_ID_BCM5751: return "5751";
  2542. case PHY_ID_BCM5787: return "5787";
  2543. case PHY_ID_BCM8002: return "8002/serdes";
  2544. case PHY_ID_SERDES: return "serdes";
  2545. default: return "unknown";
  2546. };
  2547. }
  2548. #else
  2549. #define tg3_phy_string(TP) "?"
  2550. #endif
  2551. static void tg3_poll_link(struct tg3 *tp)
  2552. {
  2553. uint32_t mac_stat;
  2554. mac_stat = tr32(MAC_STATUS);
  2555. if (tp->phy_id == PHY_ID_SERDES) {
  2556. if (tp->carrier_ok?
  2557. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED):
  2558. (mac_stat & MAC_STATUS_PCS_SYNCED)) {
  2559. tw32_carefully(MAC_MODE, tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK);
  2560. tw32_carefully(MAC_MODE, tp->mac_mode);
  2561. tg3_setup_phy(tp);
  2562. }
  2563. }
  2564. else {
  2565. if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) {
  2566. tg3_setup_phy(tp);
  2567. }
  2568. }
  2569. }
  2570. /**************************************************************************
  2571. POLL - Wait for a frame
  2572. ***************************************************************************/
  2573. static void tg3_ack_irqs(struct tg3 *tp)
  2574. {
  2575. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  2576. /*
  2577. * writing any value to intr-mbox-0 clears PCI INTA# and
  2578. * chip-internal interrupt pending events.
  2579. * writing non-zero to intr-mbox-0 additional tells the
  2580. * NIC to stop sending us irqs, engaging "in-intr-handler"
  2581. * event coalescing.
  2582. */
  2583. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  2584. 0x00000001);
  2585. /*
  2586. * Flush PCI write. This also guarantees that our
  2587. * status block has been flushed to host memory.
  2588. */
  2589. tr32(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW);
  2590. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  2591. }
  2592. }
  2593. static int tg3_poll(struct nic *nic, int retrieve)
  2594. {
  2595. /* return true if there's an ethernet packet ready to read */
  2596. /* nic->packet should contain data on return */
  2597. /* nic->packetlen should contain length of data */
  2598. struct tg3 *tp = &tg3;
  2599. int result;
  2600. result = 0;
  2601. if ( (tp->hw_status->idx[0].rx_producer != tp->rx_rcb_ptr) && !retrieve )
  2602. return 1;
  2603. tg3_ack_irqs(tp);
  2604. if (tp->hw_status->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2605. struct tg3_rx_buffer_desc *desc;
  2606. unsigned int len;
  2607. desc = &tp->rx_rcb[tp->rx_rcb_ptr];
  2608. if ((desc->opaque & RXD_OPAQUE_RING_MASK) == RXD_OPAQUE_RING_STD) {
  2609. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2610. nic->packetlen = len;
  2611. memcpy(nic->packet, bus_to_virt(desc->addr_lo), len);
  2612. result = 1;
  2613. }
  2614. tp->rx_rcb_ptr = (tp->rx_rcb_ptr + 1) % TG3_RX_RCB_RING_SIZE;
  2615. /* ACK the status ring */
  2616. tw32_mailbox2(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, tp->rx_rcb_ptr);
  2617. /* Refill RX ring. */
  2618. if (result) {
  2619. tp->rx_std_ptr = (tp->rx_std_ptr + 1) % TG3_RX_RING_SIZE;
  2620. tw32_mailbox2(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW, tp->rx_std_ptr);
  2621. }
  2622. }
  2623. tg3_poll_link(tp);
  2624. return result;
  2625. }
  2626. /**************************************************************************
  2627. TRANSMIT - Transmit a frame
  2628. ***************************************************************************/
  2629. #if 0
  2630. static void tg3_set_txd(struct tg3 *tp, int entry,
  2631. dma_addr_t mapping, int len, uint32_t flags,
  2632. uint32_t mss_and_is_end)
  2633. {
  2634. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  2635. int is_end = (mss_and_is_end & 0x1);
  2636. if (is_end) {
  2637. flags |= TXD_FLAG_END;
  2638. }
  2639. txd->addr_hi = 0;
  2640. txd->addr_lo = mapping & 0xffffffff;
  2641. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  2642. txd->vlan_tag = 0 << TXD_VLAN_TAG_SHIFT;
  2643. }
  2644. #endif
  2645. static void tg3_transmit(struct nic *nic, const char *dst_addr,
  2646. unsigned int type, unsigned int size, const char *packet)
  2647. {
  2648. static int frame_idx;
  2649. struct eth_frame *frame;
  2650. /* send the packet to destination */
  2651. struct tg3_tx_buffer_desc *txd;
  2652. struct tg3 *tp;
  2653. uint32_t entry;
  2654. int i;
  2655. /* Wait until there is a free packet frame */
  2656. tp = &tg3;
  2657. i = 0;
  2658. entry = tp->tx_prod;
  2659. while((tp->hw_status->idx[0].tx_consumer != entry) &&
  2660. (tp->hw_status->idx[0].tx_consumer != PREV_TX(entry))) {
  2661. mdelay(10); /* give the nick a chance */
  2662. if (++i > 500) { /* timeout 5s for transmit */
  2663. printf("transmit timed out\n");
  2664. tg3_halt(tp);
  2665. tg3_setup_hw(tp);
  2666. return;
  2667. }
  2668. }
  2669. if (i != 0) {
  2670. printf("#");
  2671. }
  2672. /* Copy the packet to the our local buffer */
  2673. frame = &tg3_bss.tx_frame[frame_idx];
  2674. memcpy(frame->dst_addr, dst_addr, ETH_ALEN);
  2675. memcpy(frame->src_addr, nic->node_addr, ETH_ALEN);
  2676. frame->type = htons(type);
  2677. memset(frame->data, 0, sizeof(frame->data));
  2678. memcpy(frame->data, packet, size);
  2679. /* Setup the ring buffer entry to transmit */
  2680. txd = &tp->tx_ring[entry];
  2681. txd->addr_hi = 0; /* Etherboot runs under 4GB */
  2682. txd->addr_lo = virt_to_bus(frame);
  2683. txd->len_flags = ((size + ETH_HLEN) << TXD_LEN_SHIFT) | TXD_FLAG_END;
  2684. txd->vlan_tag = 0 << TXD_VLAN_TAG_SHIFT;
  2685. /* Advance to the next entry */
  2686. entry = NEXT_TX(entry);
  2687. frame_idx ^= 1;
  2688. /* Packets are ready, update Tx producer idx local and on card */
  2689. tw32_mailbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  2690. tw32_mailbox2((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  2691. tp->tx_prod = entry;
  2692. }
  2693. /**************************************************************************
  2694. DISABLE - Turn off ethernet interface
  2695. ***************************************************************************/
  2696. static void tg3_disable ( struct nic *nic __unused ) {
  2697. struct tg3 *tp = &tg3;
  2698. /* put the card in its initial state */
  2699. /* This function serves 3 purposes.
  2700. * This disables DMA and interrupts so we don't receive
  2701. * unexpected packets or interrupts from the card after
  2702. * etherboot has finished.
  2703. * This frees resources so etherboot may use
  2704. * this driver on another interface
  2705. * This allows etherboot to reinitialize the interface
  2706. * if something is something goes wrong.
  2707. */
  2708. tg3_halt(tp);
  2709. tp->tg3_flags &= ~(TG3_FLAG_INIT_COMPLETE|TG3_FLAG_GOT_SERDES_FLOWCTL);
  2710. tp->carrier_ok = 0;
  2711. iounmap((void *)tp->regs);
  2712. }
  2713. /**************************************************************************
  2714. IRQ - Enable, Disable, or Force interrupts
  2715. ***************************************************************************/
  2716. static void tg3_irq(struct nic *nic __unused, irq_action_t action __unused)
  2717. {
  2718. switch ( action ) {
  2719. case DISABLE :
  2720. break;
  2721. case ENABLE :
  2722. break;
  2723. case FORCE :
  2724. break;
  2725. }
  2726. }
  2727. static struct nic_operations tg3_operations = {
  2728. .connect = dummy_connect,
  2729. .poll = tg3_poll,
  2730. .transmit = tg3_transmit,
  2731. .irq = tg3_irq,
  2732. };
  2733. /**************************************************************************
  2734. PROBE - Look for an adapter, this routine's visible to the outside
  2735. You should omit the last argument struct pci_device * for a non-PCI NIC
  2736. ***************************************************************************/
  2737. static int tg3_probe ( struct nic *nic, struct pci_device *pdev ) {
  2738. struct tg3 *tp = &tg3;
  2739. unsigned long tg3reg_base, tg3reg_len;
  2740. int i, err, pm_cap;
  2741. memset(tp, 0, sizeof(*tp));
  2742. adjust_pci_device(pdev);
  2743. nic->irqno = 0;
  2744. nic->ioaddr = pdev->ioaddr;
  2745. /* Find power-management capability. */
  2746. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  2747. if (pm_cap == 0) {
  2748. printf("Cannot find PowerManagement capability, aborting.\n");
  2749. return 0;
  2750. }
  2751. tg3reg_base = pci_bar_start(pdev, PCI_BASE_ADDRESS_0);
  2752. if (tg3reg_base == -1UL) {
  2753. printf("Unuseable bar\n");
  2754. return 0;
  2755. }
  2756. tg3reg_len = pci_bar_size(pdev, PCI_BASE_ADDRESS_0);
  2757. tp->pdev = pdev;
  2758. tp->nic = nic;
  2759. tp->pm_cap = pm_cap;
  2760. tp->rx_mode = 0;
  2761. tp->tx_mode = 0;
  2762. tp->mi_mode = MAC_MI_MODE_BASE;
  2763. tp->tg3_flags = 0 & ~TG3_FLAG_INIT_COMPLETE;
  2764. /* The word/byte swap controls here control register access byte
  2765. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  2766. * setting below.
  2767. */
  2768. tp->misc_host_ctrl =
  2769. MISC_HOST_CTRL_MASK_PCI_INT |
  2770. MISC_HOST_CTRL_WORD_SWAP |
  2771. MISC_HOST_CTRL_INDIR_ACCESS |
  2772. MISC_HOST_CTRL_PCISTATE_RW;
  2773. /* The NONFRM (non-frame) byte/word swap controls take effect
  2774. * on descriptor entries, anything which isn't packet data.
  2775. *
  2776. * The StrongARM chips on the board (one for tx, one for rx)
  2777. * are running in big-endian mode.
  2778. */
  2779. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  2780. GRC_MODE_WSWAP_NONFRM_DATA);
  2781. #if __BYTE_ORDER == __BIG_ENDIAN
  2782. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  2783. #endif
  2784. tp->regs = (unsigned long) ioremap(tg3reg_base, tg3reg_len);
  2785. if (tp->regs == 0UL) {
  2786. printf("Cannot map device registers, aborting\n");
  2787. return 0;
  2788. }
  2789. tg3_init_link_config(tp);
  2790. err = tg3_get_invariants(tp);
  2791. if (err) {
  2792. printf("Problem fetching invariants of chip, aborting.\n");
  2793. goto err_out_iounmap;
  2794. }
  2795. err = tg3_get_device_address(tp);
  2796. if (err) {
  2797. printf("Could not obtain valid ethernet address, aborting.\n");
  2798. goto err_out_iounmap;
  2799. }
  2800. DBG ( "Ethernet addr: %s\n", eth_ntoa ( nic->node_addr ) );
  2801. tg3_setup_dma(tp);
  2802. /* Now that we have fully setup the chip, save away a snapshot
  2803. * of the PCI config space. We need to restore this after
  2804. * GRC_MISC_CFG core clock resets and some resume events.
  2805. */
  2806. pci_save_state(tp->pdev, tp->pci_cfg_state);
  2807. printf("Tigon3 [partno(%s) rev %hx PHY(%s)] (PCI%s:%s:%s)\n",
  2808. tp->board_part_number,
  2809. tp->pci_chip_rev_id,
  2810. tg3_phy_string(tp),
  2811. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ? "X" : ""),
  2812. ((tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED) ?
  2813. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ? "133MHz" : "66MHz") :
  2814. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ? "100MHz" : "33MHz")),
  2815. ((tp->tg3_flags & TG3_FLAG_PCI_32BIT) ? "32-bit" : "64-bit"));
  2816. err = tg3_setup_hw(tp);
  2817. if (err) {
  2818. goto err_out_disable;
  2819. }
  2820. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  2821. /* Wait for a reasonable time for the link to come up */
  2822. tg3_poll_link(tp);
  2823. for(i = 0; !tp->carrier_ok && (i < VALID_LINK_TIMEOUT*100); i++) {
  2824. mdelay(1);
  2825. tg3_poll_link(tp);
  2826. }
  2827. if (!tp->carrier_ok){
  2828. printf("Valid link not established\n");
  2829. goto err_out_disable;
  2830. }
  2831. nic->nic_op = &tg3_operations;
  2832. return 1;
  2833. err_out_iounmap:
  2834. iounmap((void *)tp->regs);
  2835. return 0;
  2836. err_out_disable:
  2837. tg3_disable(nic);
  2838. return 0;
  2839. }
  2840. static struct pci_device_id tg3_nics[] = {
  2841. PCI_ROM(0x14e4, 0x1644, "tg3-5700", "Broadcom Tigon 3 5700", 0),
  2842. PCI_ROM(0x14e4, 0x1645, "tg3-5701", "Broadcom Tigon 3 5701", 0),
  2843. PCI_ROM(0x14e4, 0x1646, "tg3-5702", "Broadcom Tigon 3 5702", 0),
  2844. PCI_ROM(0x14e4, 0x1647, "tg3-5703", "Broadcom Tigon 3 5703", 0),
  2845. PCI_ROM(0x14e4, 0x1648, "tg3-5704", "Broadcom Tigon 3 5704", 0),
  2846. PCI_ROM(0x14e4, 0x164d, "tg3-5702FE", "Broadcom Tigon 3 5702FE", 0),
  2847. PCI_ROM(0x14e4, 0x1653, "tg3-5705", "Broadcom Tigon 3 5705", 0),
  2848. PCI_ROM(0x14e4, 0x1654, "tg3-5705_2", "Broadcom Tigon 3 5705_2", 0),
  2849. PCI_ROM(0x14e4, 0x1659, "tg3-5721", "Broadcom Tigon 3 5721", 0),
  2850. PCI_ROM(0x14e4, 0x165d, "tg3-5705M", "Broadcom Tigon 3 5705M", 0),
  2851. PCI_ROM(0x14e4, 0x165e, "tg3-5705M_2", "Broadcom Tigon 3 5705M_2", 0),
  2852. PCI_ROM(0x14e4, 0x1677, "tg3-5751", "Broadcom Tigon 3 5751", 0),
  2853. PCI_ROM(0x14e4, 0x167a, "tg3-5754", "Broadcom Tigon 3 5754", 0),
  2854. PCI_ROM(0x14e4, 0x1693, "tg3-5787", "Broadcom Tigon 3 5787", 0),
  2855. PCI_ROM(0x14e4, 0x1696, "tg3-5782", "Broadcom Tigon 3 5782", 0),
  2856. PCI_ROM(0x14e4, 0x169a, "tg3-5786", "Broadcom Tigon 3 5786", 0),
  2857. PCI_ROM(0x14e4, 0x169c, "tg3-5788", "Broadcom Tigon 3 5788", 0),
  2858. PCI_ROM(0x14e4, 0x169d, "tg3-5789", "Broadcom Tigon 3 5789", 0),
  2859. PCI_ROM(0x14e4, 0x16a6, "tg3-5702X", "Broadcom Tigon 3 5702X", 0),
  2860. PCI_ROM(0x14e4, 0x16a7, "tg3-5703X", "Broadcom Tigon 3 5703X", 0),
  2861. PCI_ROM(0x14e4, 0x16a8, "tg3-5704S", "Broadcom Tigon 3 5704S", 0),
  2862. PCI_ROM(0x14e4, 0x16c6, "tg3-5702A3", "Broadcom Tigon 3 5702A3", 0),
  2863. PCI_ROM(0x14e4, 0x16c7, "tg3-5703A3", "Broadcom Tigon 3 5703A3", 0),
  2864. PCI_ROM(0x14e4, 0x170d, "tg3-5901", "Broadcom Tigon 3 5901", 0),
  2865. PCI_ROM(0x14e4, 0x170e, "tg3-5901_2", "Broadcom Tigon 3 5901_2", 0),
  2866. PCI_ROM(0x1148, 0x4400, "tg3-9DXX", "Syskonnect 9DXX", 0),
  2867. PCI_ROM(0x1148, 0x4500, "tg3-9MXX", "Syskonnect 9MXX", 0),
  2868. PCI_ROM(0x173b, 0x03e8, "tg3-ac1000", "Altima AC1000", 0),
  2869. PCI_ROM(0x173b, 0x03e9, "tg3-ac1001", "Altima AC1001", 0),
  2870. PCI_ROM(0x173b, 0x03ea, "tg3-ac9100", "Altima AC9100", 0),
  2871. PCI_ROM(0x173b, 0x03eb, "tg3-ac1003", "Altima AC1003", 0),
  2872. PCI_ROM(0x0e11, 0x00ca, "tg3-hp", "HP Tigon 3", 0),
  2873. };
  2874. PCI_DRIVER ( tg3_driver, tg3_nics, PCI_NO_CLASS );
  2875. DRIVER ( "TG3", nic_driver, pci_driver, tg3_driver,
  2876. tg3_probe, tg3_disable );
  2877. /*
  2878. * Local variables:
  2879. * c-basic-offset: 8
  2880. * c-indent-level: 8
  2881. * tab-width: 8
  2882. * End:
  2883. */