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.

e1000.c 115KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713
  1. /**************************************************************************
  2. Etherboot - BOOTP/TFTP Bootstrap Program
  3. Inter Pro 1000 for Etherboot
  4. Drivers are port from Intel's Linux driver e1000-4.3.15
  5. ***************************************************************************/
  6. /*******************************************************************************
  7. Copyright(c) 1999 - 2003 Intel Corporation. All rights reserved.
  8. This program is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your option)
  11. any later version.
  12. This program is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. more details.
  16. You should have received a copy of the GNU General Public License along with
  17. this program; if not, write to the Free Software Foundation, Inc., 59
  18. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. The full GNU General Public License is included in this distribution in the
  20. file called LICENSE.
  21. Contact Information:
  22. Linux NICS <linux.nics@intel.com>
  23. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *******************************************************************************/
  25. /*
  26. * Copyright (C) Archway Digital Solutions.
  27. *
  28. * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
  29. * 2/9/2002
  30. *
  31. * Copyright (C) Linux Networx.
  32. * Massive upgrade to work with the new intel gigabit NICs.
  33. * <ebiederman at lnxi dot com>
  34. *
  35. * Support for 82541ei & 82547ei chips from Intel's Linux driver 5.1.13 added by
  36. * Georg Baum <gbaum@users.sf.net>, sponsored by PetaMem GmbH and linkLINE Communications, Inc.
  37. *
  38. * 01/2004: Updated to Linux driver 5.2.22 by Georg Baum <gbaum@users.sf.net>
  39. */
  40. /* to get some global routines like printf */
  41. #include "etherboot.h"
  42. /* to get the interface to the body of the program */
  43. #include "nic.h"
  44. /* to get the PCI support functions, if this is a PCI NIC */
  45. #include "pci.h"
  46. #include "timer.h"
  47. typedef unsigned char *dma_addr_t;
  48. typedef enum {
  49. FALSE = 0,
  50. TRUE = 1
  51. } boolean_t;
  52. #define DEBUG 0
  53. /* Some pieces of code are disabled with #if 0 ... #endif.
  54. * They are not deleted to show where the etherboot driver differs
  55. * from the linux driver below the function level.
  56. * Some member variables of the hw struct have been eliminated
  57. * and the corresponding inplace checks inserted instead.
  58. * Pieces such as LED handling that we definitely don't need are deleted.
  59. *
  60. * The following defines should not be needed normally,
  61. * but may be helpful for debugging purposes. */
  62. /* Define this if you want to program the transmission control register
  63. * the way the Linux driver does it. */
  64. #undef LINUX_DRIVER_TCTL
  65. /* Define this to behave more like the Linux driver. */
  66. #undef LINUX_DRIVER
  67. #include "e1000_hw.h"
  68. /* NIC specific static variables go here */
  69. static struct nic_operations e1000_operations;
  70. static struct pci_driver e1000_driver;
  71. static struct e1000_hw hw;
  72. static char tx_pool[128 + 16];
  73. static char rx_pool[128 + 16];
  74. static char packet[2096];
  75. static struct e1000_tx_desc *tx_base;
  76. static struct e1000_rx_desc *rx_base;
  77. static int tx_tail;
  78. static int rx_tail, rx_last;
  79. /* Function forward declarations */
  80. static int e1000_setup_link(struct e1000_hw *hw);
  81. static int e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
  82. static int e1000_setup_copper_link(struct e1000_hw *hw);
  83. static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
  84. static void e1000_config_collision_dist(struct e1000_hw *hw);
  85. static int e1000_config_mac_to_phy(struct e1000_hw *hw);
  86. static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
  87. static int e1000_check_for_link(struct e1000_hw *hw);
  88. static int e1000_wait_autoneg(struct e1000_hw *hw);
  89. static void e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed, uint16_t *duplex);
  90. static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *phy_data);
  91. static int e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *phy_data);
  92. static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data);
  93. static int e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data);
  94. static void e1000_phy_hw_reset(struct e1000_hw *hw);
  95. static int e1000_phy_reset(struct e1000_hw *hw);
  96. static int e1000_detect_gig_phy(struct e1000_hw *hw);
  97. static void e1000_irq(struct nic *nic, irq_action_t action);
  98. /* Printing macros... */
  99. #define E1000_ERR(args...) printf("e1000: " args)
  100. #if DEBUG >= 3
  101. #define E1000_DBG(args...) printf("e1000: " args)
  102. #else
  103. #define E1000_DBG(args...)
  104. #endif
  105. #define MSGOUT(S, A, B) printk(S "\n", A, B)
  106. #if DEBUG >= 2
  107. #define DEBUGFUNC(F) DEBUGOUT(F "\n");
  108. #else
  109. #define DEBUGFUNC(F)
  110. #endif
  111. #if DEBUG >= 1
  112. #define DEBUGOUT(S) printf(S)
  113. #define DEBUGOUT1(S,A) printf(S,A)
  114. #define DEBUGOUT2(S,A,B) printf(S,A,B)
  115. #define DEBUGOUT3(S,A,B,C) printf(S,A,B,C)
  116. #define DEBUGOUT7(S,A,B,C,D,E,F,G) printf(S,A,B,C,D,E,F,G)
  117. #else
  118. #define DEBUGOUT(S)
  119. #define DEBUGOUT1(S,A)
  120. #define DEBUGOUT2(S,A,B)
  121. #define DEBUGOUT3(S,A,B,C)
  122. #define DEBUGOUT7(S,A,B,C,D,E,F,G)
  123. #endif
  124. #define E1000_WRITE_REG(a, reg, value) ( \
  125. ((a)->mac_type >= e1000_82543) ? \
  126. (writel((value), ((a)->hw_addr + E1000_##reg))) : \
  127. (writel((value), ((a)->hw_addr + E1000_82542_##reg))))
  128. #define E1000_READ_REG(a, reg) ( \
  129. ((a)->mac_type >= e1000_82543) ? \
  130. readl((a)->hw_addr + E1000_##reg) : \
  131. readl((a)->hw_addr + E1000_82542_##reg))
  132. #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) ( \
  133. ((a)->mac_type >= e1000_82543) ? \
  134. writel((value), ((a)->hw_addr + E1000_##reg + ((offset) << 2))) : \
  135. writel((value), ((a)->hw_addr + E1000_82542_##reg + ((offset) << 2))))
  136. #define E1000_READ_REG_ARRAY(a, reg, offset) ( \
  137. ((a)->mac_type >= e1000_82543) ? \
  138. readl((a)->hw_addr + E1000_##reg + ((offset) << 2)) : \
  139. readl((a)->hw_addr + E1000_82542_##reg + ((offset) << 2)))
  140. #define E1000_WRITE_FLUSH(a) {uint32_t x; x = E1000_READ_REG(a, STATUS);}
  141. uint32_t
  142. e1000_io_read(struct e1000_hw *hw __unused, uint32_t port)
  143. {
  144. return inl(port);
  145. }
  146. void
  147. e1000_io_write(struct e1000_hw *hw __unused, uint32_t port, uint32_t value)
  148. {
  149. outl(value, port);
  150. }
  151. static inline void e1000_pci_set_mwi(struct e1000_hw *hw)
  152. {
  153. pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
  154. }
  155. static inline void e1000_pci_clear_mwi(struct e1000_hw *hw)
  156. {
  157. pci_write_config_word(hw->pdev, PCI_COMMAND,
  158. hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
  159. }
  160. /******************************************************************************
  161. * Raises the EEPROM's clock input.
  162. *
  163. * hw - Struct containing variables accessed by shared code
  164. * eecd - EECD's current value
  165. *****************************************************************************/
  166. static void
  167. e1000_raise_ee_clk(struct e1000_hw *hw,
  168. uint32_t *eecd)
  169. {
  170. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  171. * wait <delay> microseconds.
  172. */
  173. *eecd = *eecd | E1000_EECD_SK;
  174. E1000_WRITE_REG(hw, EECD, *eecd);
  175. E1000_WRITE_FLUSH(hw);
  176. udelay(hw->eeprom.delay_usec);
  177. }
  178. /******************************************************************************
  179. * Lowers the EEPROM's clock input.
  180. *
  181. * hw - Struct containing variables accessed by shared code
  182. * eecd - EECD's current value
  183. *****************************************************************************/
  184. static void
  185. e1000_lower_ee_clk(struct e1000_hw *hw,
  186. uint32_t *eecd)
  187. {
  188. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  189. * wait 50 microseconds.
  190. */
  191. *eecd = *eecd & ~E1000_EECD_SK;
  192. E1000_WRITE_REG(hw, EECD, *eecd);
  193. E1000_WRITE_FLUSH(hw);
  194. udelay(hw->eeprom.delay_usec);
  195. }
  196. /******************************************************************************
  197. * Shift data bits out to the EEPROM.
  198. *
  199. * hw - Struct containing variables accessed by shared code
  200. * data - data to send to the EEPROM
  201. * count - number of bits to shift out
  202. *****************************************************************************/
  203. static void
  204. e1000_shift_out_ee_bits(struct e1000_hw *hw,
  205. uint16_t data,
  206. uint16_t count)
  207. {
  208. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  209. uint32_t eecd;
  210. uint32_t mask;
  211. /* We need to shift "count" bits out to the EEPROM. So, value in the
  212. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  213. * In order to do this, "data" must be broken down into bits.
  214. */
  215. mask = 0x01 << (count - 1);
  216. eecd = E1000_READ_REG(hw, EECD);
  217. if (eeprom->type == e1000_eeprom_microwire) {
  218. eecd &= ~E1000_EECD_DO;
  219. } else if (eeprom->type == e1000_eeprom_spi) {
  220. eecd |= E1000_EECD_DO;
  221. }
  222. do {
  223. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  224. * and then raising and then lowering the clock (the SK bit controls
  225. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  226. * by setting "DI" to "0" and then raising and then lowering the clock.
  227. */
  228. eecd &= ~E1000_EECD_DI;
  229. if(data & mask)
  230. eecd |= E1000_EECD_DI;
  231. E1000_WRITE_REG(hw, EECD, eecd);
  232. E1000_WRITE_FLUSH(hw);
  233. udelay(eeprom->delay_usec);
  234. e1000_raise_ee_clk(hw, &eecd);
  235. e1000_lower_ee_clk(hw, &eecd);
  236. mask = mask >> 1;
  237. } while(mask);
  238. /* We leave the "DI" bit set to "0" when we leave this routine. */
  239. eecd &= ~E1000_EECD_DI;
  240. E1000_WRITE_REG(hw, EECD, eecd);
  241. }
  242. /******************************************************************************
  243. * Shift data bits in from the EEPROM
  244. *
  245. * hw - Struct containing variables accessed by shared code
  246. *****************************************************************************/
  247. static uint16_t
  248. e1000_shift_in_ee_bits(struct e1000_hw *hw,
  249. uint16_t count)
  250. {
  251. uint32_t eecd;
  252. uint32_t i;
  253. uint16_t data;
  254. /* In order to read a register from the EEPROM, we need to shift 'count'
  255. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  256. * input to the EEPROM (setting the SK bit), and then reading the value of
  257. * the "DO" bit. During this "shifting in" process the "DI" bit should
  258. * always be clear.
  259. */
  260. eecd = E1000_READ_REG(hw, EECD);
  261. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  262. data = 0;
  263. for(i = 0; i < count; i++) {
  264. data = data << 1;
  265. e1000_raise_ee_clk(hw, &eecd);
  266. eecd = E1000_READ_REG(hw, EECD);
  267. eecd &= ~(E1000_EECD_DI);
  268. if(eecd & E1000_EECD_DO)
  269. data |= 1;
  270. e1000_lower_ee_clk(hw, &eecd);
  271. }
  272. return data;
  273. }
  274. /******************************************************************************
  275. * Prepares EEPROM for access
  276. *
  277. * hw - Struct containing variables accessed by shared code
  278. *
  279. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  280. * function should be called before issuing a command to the EEPROM.
  281. *****************************************************************************/
  282. static int32_t
  283. e1000_acquire_eeprom(struct e1000_hw *hw)
  284. {
  285. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  286. uint32_t eecd, i=0;
  287. eecd = E1000_READ_REG(hw, EECD);
  288. /* Request EEPROM Access */
  289. if(hw->mac_type > e1000_82544) {
  290. eecd |= E1000_EECD_REQ;
  291. E1000_WRITE_REG(hw, EECD, eecd);
  292. eecd = E1000_READ_REG(hw, EECD);
  293. while((!(eecd & E1000_EECD_GNT)) &&
  294. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  295. i++;
  296. udelay(5);
  297. eecd = E1000_READ_REG(hw, EECD);
  298. }
  299. if(!(eecd & E1000_EECD_GNT)) {
  300. eecd &= ~E1000_EECD_REQ;
  301. E1000_WRITE_REG(hw, EECD, eecd);
  302. DEBUGOUT("Could not acquire EEPROM grant\n");
  303. return -E1000_ERR_EEPROM;
  304. }
  305. }
  306. /* Setup EEPROM for Read/Write */
  307. if (eeprom->type == e1000_eeprom_microwire) {
  308. /* Clear SK and DI */
  309. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  310. E1000_WRITE_REG(hw, EECD, eecd);
  311. /* Set CS */
  312. eecd |= E1000_EECD_CS;
  313. E1000_WRITE_REG(hw, EECD, eecd);
  314. } else if (eeprom->type == e1000_eeprom_spi) {
  315. /* Clear SK and CS */
  316. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  317. E1000_WRITE_REG(hw, EECD, eecd);
  318. udelay(1);
  319. }
  320. return E1000_SUCCESS;
  321. }
  322. /******************************************************************************
  323. * Returns EEPROM to a "standby" state
  324. *
  325. * hw - Struct containing variables accessed by shared code
  326. *****************************************************************************/
  327. static void
  328. e1000_standby_eeprom(struct e1000_hw *hw)
  329. {
  330. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  331. uint32_t eecd;
  332. eecd = E1000_READ_REG(hw, EECD);
  333. if(eeprom->type == e1000_eeprom_microwire) {
  334. /* Deselect EEPROM */
  335. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  336. E1000_WRITE_REG(hw, EECD, eecd);
  337. E1000_WRITE_FLUSH(hw);
  338. udelay(eeprom->delay_usec);
  339. /* Clock high */
  340. eecd |= E1000_EECD_SK;
  341. E1000_WRITE_REG(hw, EECD, eecd);
  342. E1000_WRITE_FLUSH(hw);
  343. udelay(eeprom->delay_usec);
  344. /* Select EEPROM */
  345. eecd |= E1000_EECD_CS;
  346. E1000_WRITE_REG(hw, EECD, eecd);
  347. E1000_WRITE_FLUSH(hw);
  348. udelay(eeprom->delay_usec);
  349. /* Clock low */
  350. eecd &= ~E1000_EECD_SK;
  351. E1000_WRITE_REG(hw, EECD, eecd);
  352. E1000_WRITE_FLUSH(hw);
  353. udelay(eeprom->delay_usec);
  354. } else if(eeprom->type == e1000_eeprom_spi) {
  355. /* Toggle CS to flush commands */
  356. eecd |= E1000_EECD_CS;
  357. E1000_WRITE_REG(hw, EECD, eecd);
  358. E1000_WRITE_FLUSH(hw);
  359. udelay(eeprom->delay_usec);
  360. eecd &= ~E1000_EECD_CS;
  361. E1000_WRITE_REG(hw, EECD, eecd);
  362. E1000_WRITE_FLUSH(hw);
  363. udelay(eeprom->delay_usec);
  364. }
  365. }
  366. /******************************************************************************
  367. * Terminates a command by inverting the EEPROM's chip select pin
  368. *
  369. * hw - Struct containing variables accessed by shared code
  370. *****************************************************************************/
  371. static void
  372. e1000_release_eeprom(struct e1000_hw *hw)
  373. {
  374. uint32_t eecd;
  375. eecd = E1000_READ_REG(hw, EECD);
  376. if (hw->eeprom.type == e1000_eeprom_spi) {
  377. eecd |= E1000_EECD_CS; /* Pull CS high */
  378. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  379. E1000_WRITE_REG(hw, EECD, eecd);
  380. udelay(hw->eeprom.delay_usec);
  381. } else if(hw->eeprom.type == e1000_eeprom_microwire) {
  382. /* cleanup eeprom */
  383. /* CS on Microwire is active-high */
  384. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  385. E1000_WRITE_REG(hw, EECD, eecd);
  386. /* Rising edge of clock */
  387. eecd |= E1000_EECD_SK;
  388. E1000_WRITE_REG(hw, EECD, eecd);
  389. E1000_WRITE_FLUSH(hw);
  390. udelay(hw->eeprom.delay_usec);
  391. /* Falling edge of clock */
  392. eecd &= ~E1000_EECD_SK;
  393. E1000_WRITE_REG(hw, EECD, eecd);
  394. E1000_WRITE_FLUSH(hw);
  395. udelay(hw->eeprom.delay_usec);
  396. }
  397. /* Stop requesting EEPROM access */
  398. if(hw->mac_type > e1000_82544) {
  399. eecd &= ~E1000_EECD_REQ;
  400. E1000_WRITE_REG(hw, EECD, eecd);
  401. }
  402. }
  403. /******************************************************************************
  404. * Reads a 16 bit word from the EEPROM.
  405. *
  406. * hw - Struct containing variables accessed by shared code
  407. *****************************************************************************/
  408. static int32_t
  409. e1000_spi_eeprom_ready(struct e1000_hw *hw)
  410. {
  411. uint16_t retry_count = 0;
  412. uint8_t spi_stat_reg;
  413. /* Read "Status Register" repeatedly until the LSB is cleared. The
  414. * EEPROM will signal that the command has been completed by clearing
  415. * bit 0 of the internal status register. If it's not cleared within
  416. * 5 milliseconds, then error out.
  417. */
  418. retry_count = 0;
  419. do {
  420. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  421. hw->eeprom.opcode_bits);
  422. spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
  423. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  424. break;
  425. udelay(5);
  426. retry_count += 5;
  427. } while(retry_count < EEPROM_MAX_RETRY_SPI);
  428. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  429. * only 0-5mSec on 5V devices)
  430. */
  431. if(retry_count >= EEPROM_MAX_RETRY_SPI) {
  432. DEBUGOUT("SPI EEPROM Status error\n");
  433. return -E1000_ERR_EEPROM;
  434. }
  435. return E1000_SUCCESS;
  436. }
  437. /******************************************************************************
  438. * Reads a 16 bit word from the EEPROM.
  439. *
  440. * hw - Struct containing variables accessed by shared code
  441. * offset - offset of word in the EEPROM to read
  442. * data - word read from the EEPROM
  443. * words - number of words to read
  444. *****************************************************************************/
  445. static int
  446. e1000_read_eeprom(struct e1000_hw *hw,
  447. uint16_t offset,
  448. uint16_t words,
  449. uint16_t *data)
  450. {
  451. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  452. uint32_t i = 0;
  453. DEBUGFUNC("e1000_read_eeprom");
  454. /* A check for invalid values: offset too large, too many words, and not
  455. * enough words.
  456. */
  457. if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
  458. (words == 0)) {
  459. DEBUGOUT("\"words\" parameter out of bounds\n");
  460. return -E1000_ERR_EEPROM;
  461. }
  462. /* Prepare the EEPROM for reading */
  463. if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  464. return -E1000_ERR_EEPROM;
  465. if(eeprom->type == e1000_eeprom_spi) {
  466. uint16_t word_in;
  467. uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
  468. if(e1000_spi_eeprom_ready(hw)) {
  469. e1000_release_eeprom(hw);
  470. return -E1000_ERR_EEPROM;
  471. }
  472. e1000_standby_eeprom(hw);
  473. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  474. if((eeprom->address_bits == 8) && (offset >= 128))
  475. read_opcode |= EEPROM_A8_OPCODE_SPI;
  476. /* Send the READ command (opcode + addr) */
  477. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  478. e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
  479. /* Read the data. The address of the eeprom internally increments with
  480. * each byte (spi) being read, saving on the overhead of eeprom setup
  481. * and tear-down. The address counter will roll over if reading beyond
  482. * the size of the eeprom, thus allowing the entire memory to be read
  483. * starting from any offset. */
  484. for (i = 0; i < words; i++) {
  485. word_in = e1000_shift_in_ee_bits(hw, 16);
  486. data[i] = (word_in >> 8) | (word_in << 8);
  487. }
  488. } else if(eeprom->type == e1000_eeprom_microwire) {
  489. for (i = 0; i < words; i++) {
  490. /* Send the READ command (opcode + addr) */
  491. e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
  492. eeprom->opcode_bits);
  493. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
  494. eeprom->address_bits);
  495. /* Read the data. For microwire, each word requires the overhead
  496. * of eeprom setup and tear-down. */
  497. data[i] = e1000_shift_in_ee_bits(hw, 16);
  498. e1000_standby_eeprom(hw);
  499. }
  500. }
  501. /* End this read operation */
  502. e1000_release_eeprom(hw);
  503. return E1000_SUCCESS;
  504. }
  505. /******************************************************************************
  506. * Verifies that the EEPROM has a valid checksum
  507. *
  508. * hw - Struct containing variables accessed by shared code
  509. *
  510. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  511. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  512. * valid.
  513. *****************************************************************************/
  514. static int
  515. e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  516. {
  517. uint16_t checksum = 0;
  518. uint16_t i, eeprom_data;
  519. DEBUGFUNC("e1000_validate_eeprom_checksum");
  520. for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  521. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  522. DEBUGOUT("EEPROM Read Error\n");
  523. return -E1000_ERR_EEPROM;
  524. }
  525. checksum += eeprom_data;
  526. }
  527. if(checksum == (uint16_t) EEPROM_SUM)
  528. return E1000_SUCCESS;
  529. else {
  530. DEBUGOUT("EEPROM Checksum Invalid\n");
  531. return -E1000_ERR_EEPROM;
  532. }
  533. }
  534. /******************************************************************************
  535. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  536. * second function of dual function devices
  537. *
  538. * hw - Struct containing variables accessed by shared code
  539. *****************************************************************************/
  540. static int
  541. e1000_read_mac_addr(struct e1000_hw *hw)
  542. {
  543. uint16_t offset;
  544. uint16_t eeprom_data;
  545. int i;
  546. DEBUGFUNC("e1000_read_mac_addr");
  547. for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  548. offset = i >> 1;
  549. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  550. DEBUGOUT("EEPROM Read Error\n");
  551. return -E1000_ERR_EEPROM;
  552. }
  553. hw->mac_addr[i] = eeprom_data & 0xff;
  554. hw->mac_addr[i+1] = (eeprom_data >> 8) & 0xff;
  555. }
  556. if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
  557. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
  558. /* Invert the last bit if this is the second device */
  559. hw->mac_addr[5] ^= 1;
  560. return E1000_SUCCESS;
  561. }
  562. /******************************************************************************
  563. * Initializes receive address filters.
  564. *
  565. * hw - Struct containing variables accessed by shared code
  566. *
  567. * Places the MAC address in receive address register 0 and clears the rest
  568. * of the receive addresss registers. Clears the multicast table. Assumes
  569. * the receiver is in reset when the routine is called.
  570. *****************************************************************************/
  571. static void
  572. e1000_init_rx_addrs(struct e1000_hw *hw)
  573. {
  574. uint32_t i;
  575. uint32_t addr_low;
  576. uint32_t addr_high;
  577. DEBUGFUNC("e1000_init_rx_addrs");
  578. /* Setup the receive address. */
  579. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  580. addr_low = (hw->mac_addr[0] |
  581. (hw->mac_addr[1] << 8) |
  582. (hw->mac_addr[2] << 16) | (hw->mac_addr[3] << 24));
  583. addr_high = (hw->mac_addr[4] |
  584. (hw->mac_addr[5] << 8) | E1000_RAH_AV);
  585. E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
  586. E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
  587. /* Zero out the other 15 receive addresses. */
  588. DEBUGOUT("Clearing RAR[1-15]\n");
  589. for(i = 1; i < E1000_RAR_ENTRIES; i++) {
  590. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  591. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  592. }
  593. }
  594. /******************************************************************************
  595. * Clears the VLAN filer table
  596. *
  597. * hw - Struct containing variables accessed by shared code
  598. *****************************************************************************/
  599. static void
  600. e1000_clear_vfta(struct e1000_hw *hw)
  601. {
  602. uint32_t offset;
  603. for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
  604. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
  605. }
  606. /******************************************************************************
  607. * Writes a value to one of the devices registers using port I/O (as opposed to
  608. * memory mapped I/O). Only 82544 and newer devices support port I/O. *
  609. * hw - Struct containing variables accessed by shared code
  610. * offset - offset to write to * value - value to write
  611. *****************************************************************************/
  612. void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value){
  613. uint32_t io_addr = hw->io_base;
  614. uint32_t io_data = hw->io_base + 4;
  615. e1000_io_write(hw, io_addr, offset);
  616. e1000_io_write(hw, io_data, value);
  617. }
  618. /******************************************************************************
  619. * Set the phy type member in the hw struct.
  620. *
  621. * hw - Struct containing variables accessed by shared code
  622. *****************************************************************************/
  623. static int32_t
  624. e1000_set_phy_type(struct e1000_hw *hw)
  625. {
  626. DEBUGFUNC("e1000_set_phy_type");
  627. switch(hw->phy_id) {
  628. case M88E1000_E_PHY_ID:
  629. case M88E1000_I_PHY_ID:
  630. case M88E1011_I_PHY_ID:
  631. hw->phy_type = e1000_phy_m88;
  632. break;
  633. case IGP01E1000_I_PHY_ID:
  634. hw->phy_type = e1000_phy_igp;
  635. break;
  636. default:
  637. /* Should never have loaded on this device */
  638. hw->phy_type = e1000_phy_undefined;
  639. return -E1000_ERR_PHY_TYPE;
  640. }
  641. return E1000_SUCCESS;
  642. }
  643. /******************************************************************************
  644. * IGP phy init script - initializes the GbE PHY
  645. *
  646. * hw - Struct containing variables accessed by shared code
  647. *****************************************************************************/
  648. static void
  649. e1000_phy_init_script(struct e1000_hw *hw)
  650. {
  651. DEBUGFUNC("e1000_phy_init_script");
  652. #if 0
  653. /* See e1000_sw_init() of the Linux driver */
  654. if(hw->phy_init_script) {
  655. #else
  656. if((hw->mac_type == e1000_82541) ||
  657. (hw->mac_type == e1000_82547) ||
  658. (hw->mac_type == e1000_82541_rev_2) ||
  659. (hw->mac_type == e1000_82547_rev_2)) {
  660. #endif
  661. mdelay(20);
  662. e1000_write_phy_reg(hw,0x0000,0x0140);
  663. mdelay(5);
  664. if(hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547) {
  665. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  666. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  667. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  668. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  669. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  670. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  671. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  672. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  673. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  674. } else {
  675. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  676. }
  677. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  678. if(hw->mac_type == e1000_82547) {
  679. uint16_t fused, fine, coarse;
  680. /* Move to analog registers page */
  681. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
  682. if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  683. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
  684. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  685. coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  686. if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  687. coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
  688. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  689. } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  690. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  691. fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  692. (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  693. (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  694. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
  695. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
  696. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  697. }
  698. }
  699. }
  700. }
  701. /******************************************************************************
  702. * Set the mac type member in the hw struct.
  703. *
  704. * hw - Struct containing variables accessed by shared code
  705. *****************************************************************************/
  706. static int
  707. e1000_set_mac_type(struct e1000_hw *hw)
  708. {
  709. DEBUGFUNC("e1000_set_mac_type");
  710. switch (hw->device_id) {
  711. case E1000_DEV_ID_82542:
  712. switch (hw->revision_id) {
  713. case E1000_82542_2_0_REV_ID:
  714. hw->mac_type = e1000_82542_rev2_0;
  715. break;
  716. case E1000_82542_2_1_REV_ID:
  717. hw->mac_type = e1000_82542_rev2_1;
  718. break;
  719. default:
  720. /* Invalid 82542 revision ID */
  721. return -E1000_ERR_MAC_TYPE;
  722. }
  723. break;
  724. case E1000_DEV_ID_82543GC_FIBER:
  725. case E1000_DEV_ID_82543GC_COPPER:
  726. hw->mac_type = e1000_82543;
  727. break;
  728. case E1000_DEV_ID_82544EI_COPPER:
  729. case E1000_DEV_ID_82544EI_FIBER:
  730. case E1000_DEV_ID_82544GC_COPPER:
  731. case E1000_DEV_ID_82544GC_LOM:
  732. hw->mac_type = e1000_82544;
  733. break;
  734. case E1000_DEV_ID_82540EM:
  735. case E1000_DEV_ID_82540EM_LOM:
  736. case E1000_DEV_ID_82540EP:
  737. case E1000_DEV_ID_82540EP_LOM:
  738. case E1000_DEV_ID_82540EP_LP:
  739. hw->mac_type = e1000_82540;
  740. break;
  741. case E1000_DEV_ID_82545EM_COPPER:
  742. case E1000_DEV_ID_82545EM_FIBER:
  743. hw->mac_type = e1000_82545;
  744. break;
  745. case E1000_DEV_ID_82545GM_COPPER:
  746. case E1000_DEV_ID_82545GM_FIBER:
  747. case E1000_DEV_ID_82545GM_SERDES:
  748. hw->mac_type = e1000_82545_rev_3;
  749. break;
  750. case E1000_DEV_ID_82546EB_COPPER:
  751. case E1000_DEV_ID_82546EB_FIBER:
  752. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  753. hw->mac_type = e1000_82546;
  754. break;
  755. case E1000_DEV_ID_82546GB_COPPER:
  756. case E1000_DEV_ID_82546GB_FIBER:
  757. case E1000_DEV_ID_82546GB_SERDES:
  758. hw->mac_type = e1000_82546_rev_3;
  759. break;
  760. case E1000_DEV_ID_82541EI:
  761. case E1000_DEV_ID_82541EI_MOBILE:
  762. hw->mac_type = e1000_82541;
  763. break;
  764. case E1000_DEV_ID_82541ER:
  765. case E1000_DEV_ID_82541GI:
  766. case E1000_DEV_ID_82541GI_MOBILE:
  767. hw->mac_type = e1000_82541_rev_2;
  768. break;
  769. case E1000_DEV_ID_82547EI:
  770. hw->mac_type = e1000_82547;
  771. break;
  772. case E1000_DEV_ID_82547GI:
  773. hw->mac_type = e1000_82547_rev_2;
  774. break;
  775. default:
  776. /* Should never have loaded on this device */
  777. return -E1000_ERR_MAC_TYPE;
  778. }
  779. return E1000_SUCCESS;
  780. }
  781. /*****************************************************************************
  782. * Set media type and TBI compatibility.
  783. *
  784. * hw - Struct containing variables accessed by shared code
  785. * **************************************************************************/
  786. static void
  787. e1000_set_media_type(struct e1000_hw *hw)
  788. {
  789. uint32_t status;
  790. DEBUGFUNC("e1000_set_media_type");
  791. if(hw->mac_type != e1000_82543) {
  792. /* tbi_compatibility is only valid on 82543 */
  793. hw->tbi_compatibility_en = FALSE;
  794. }
  795. switch (hw->device_id) {
  796. case E1000_DEV_ID_82545GM_SERDES:
  797. case E1000_DEV_ID_82546GB_SERDES:
  798. hw->media_type = e1000_media_type_internal_serdes;
  799. break;
  800. default:
  801. if(hw->mac_type >= e1000_82543) {
  802. status = E1000_READ_REG(hw, STATUS);
  803. if(status & E1000_STATUS_TBIMODE) {
  804. hw->media_type = e1000_media_type_fiber;
  805. /* tbi_compatibility not valid on fiber */
  806. hw->tbi_compatibility_en = FALSE;
  807. } else {
  808. hw->media_type = e1000_media_type_copper;
  809. }
  810. } else {
  811. /* This is an 82542 (fiber only) */
  812. hw->media_type = e1000_media_type_fiber;
  813. }
  814. }
  815. }
  816. /******************************************************************************
  817. * Reset the transmit and receive units; mask and clear all interrupts.
  818. *
  819. * hw - Struct containing variables accessed by shared code
  820. *****************************************************************************/
  821. static void
  822. e1000_reset_hw(struct e1000_hw *hw)
  823. {
  824. uint32_t ctrl;
  825. uint32_t ctrl_ext;
  826. uint32_t icr;
  827. uint32_t manc;
  828. DEBUGFUNC("e1000_reset_hw");
  829. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  830. if(hw->mac_type == e1000_82542_rev2_0) {
  831. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  832. e1000_pci_clear_mwi(hw);
  833. }
  834. /* Clear interrupt mask to stop board from generating interrupts */
  835. DEBUGOUT("Masking off all interrupts\n");
  836. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  837. /* Disable the Transmit and Receive units. Then delay to allow
  838. * any pending transactions to complete before we hit the MAC with
  839. * the global reset.
  840. */
  841. E1000_WRITE_REG(hw, RCTL, 0);
  842. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  843. E1000_WRITE_FLUSH(hw);
  844. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  845. hw->tbi_compatibility_on = FALSE;
  846. /* Delay to allow any outstanding PCI transactions to complete before
  847. * resetting the device
  848. */
  849. mdelay(10);
  850. ctrl = E1000_READ_REG(hw, CTRL);
  851. /* Must reset the PHY before resetting the MAC */
  852. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  853. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
  854. mdelay(5);
  855. }
  856. /* Issue a global reset to the MAC. This will reset the chip's
  857. * transmit, receive, DMA, and link units. It will not effect
  858. * the current PCI configuration. The global reset bit is self-
  859. * clearing, and should clear within a microsecond.
  860. */
  861. DEBUGOUT("Issuing a global reset to MAC\n");
  862. switch(hw->mac_type) {
  863. case e1000_82544:
  864. case e1000_82540:
  865. case e1000_82545:
  866. case e1000_82546:
  867. case e1000_82541:
  868. case e1000_82541_rev_2:
  869. /* These controllers can't ack the 64-bit write when issuing the
  870. * reset, so use IO-mapping as a workaround to issue the reset */
  871. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  872. break;
  873. case e1000_82545_rev_3:
  874. case e1000_82546_rev_3:
  875. /* Reset is performed on a shadow of the control register */
  876. E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
  877. break;
  878. default:
  879. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  880. break;
  881. }
  882. /* After MAC reset, force reload of EEPROM to restore power-on settings to
  883. * device. Later controllers reload the EEPROM automatically, so just wait
  884. * for reload to complete.
  885. */
  886. switch(hw->mac_type) {
  887. case e1000_82542_rev2_0:
  888. case e1000_82542_rev2_1:
  889. case e1000_82543:
  890. case e1000_82544:
  891. /* Wait for reset to complete */
  892. udelay(10);
  893. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  894. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  895. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  896. E1000_WRITE_FLUSH(hw);
  897. /* Wait for EEPROM reload */
  898. mdelay(2);
  899. break;
  900. case e1000_82541:
  901. case e1000_82541_rev_2:
  902. case e1000_82547:
  903. case e1000_82547_rev_2:
  904. /* Wait for EEPROM reload */
  905. mdelay(20);
  906. break;
  907. default:
  908. /* Wait for EEPROM reload (it happens automatically) */
  909. mdelay(5);
  910. break;
  911. }
  912. /* Disable HW ARPs on ASF enabled adapters */
  913. if(hw->mac_type >= e1000_82540) {
  914. manc = E1000_READ_REG(hw, MANC);
  915. manc &= ~(E1000_MANC_ARP_EN);
  916. E1000_WRITE_REG(hw, MANC, manc);
  917. }
  918. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  919. e1000_phy_init_script(hw);
  920. }
  921. /* Clear interrupt mask to stop board from generating interrupts */
  922. DEBUGOUT("Masking off all interrupts\n");
  923. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  924. /* Clear any pending interrupt events. */
  925. icr = E1000_READ_REG(hw, ICR);
  926. /* If MWI was previously enabled, reenable it. */
  927. if(hw->mac_type == e1000_82542_rev2_0) {
  928. #ifdef LINUX_DRIVER
  929. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  930. #endif
  931. e1000_pci_set_mwi(hw);
  932. }
  933. }
  934. /******************************************************************************
  935. * Performs basic configuration of the adapter.
  936. *
  937. * hw - Struct containing variables accessed by shared code
  938. *
  939. * Assumes that the controller has previously been reset and is in a
  940. * post-reset uninitialized state. Initializes the receive address registers,
  941. * multicast table, and VLAN filter table. Calls routines to setup link
  942. * configuration and flow control settings. Clears all on-chip counters. Leaves
  943. * the transmit and receive units disabled and uninitialized.
  944. *****************************************************************************/
  945. static int
  946. e1000_init_hw(struct e1000_hw *hw)
  947. {
  948. uint32_t ctrl, status;
  949. uint32_t i;
  950. int32_t ret_val;
  951. uint16_t pcix_cmd_word;
  952. uint16_t pcix_stat_hi_word;
  953. uint16_t cmd_mmrbc;
  954. uint16_t stat_mmrbc;
  955. e1000_bus_type bus_type = e1000_bus_type_unknown;
  956. DEBUGFUNC("e1000_init_hw");
  957. /* Set the media type and TBI compatibility */
  958. e1000_set_media_type(hw);
  959. /* Disabling VLAN filtering. */
  960. DEBUGOUT("Initializing the IEEE VLAN\n");
  961. E1000_WRITE_REG(hw, VET, 0);
  962. e1000_clear_vfta(hw);
  963. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  964. if(hw->mac_type == e1000_82542_rev2_0) {
  965. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  966. e1000_pci_clear_mwi(hw);
  967. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  968. E1000_WRITE_FLUSH(hw);
  969. mdelay(5);
  970. }
  971. /* Setup the receive address. This involves initializing all of the Receive
  972. * Address Registers (RARs 0 - 15).
  973. */
  974. e1000_init_rx_addrs(hw);
  975. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  976. if(hw->mac_type == e1000_82542_rev2_0) {
  977. E1000_WRITE_REG(hw, RCTL, 0);
  978. E1000_WRITE_FLUSH(hw);
  979. mdelay(1);
  980. #ifdef LINUX_DRIVER
  981. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  982. #endif
  983. e1000_pci_set_mwi(hw);
  984. }
  985. /* Zero out the Multicast HASH table */
  986. DEBUGOUT("Zeroing the MTA\n");
  987. for(i = 0; i < E1000_MC_TBL_SIZE; i++)
  988. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  989. #if 0
  990. /* Set the PCI priority bit correctly in the CTRL register. This
  991. * determines if the adapter gives priority to receives, or if it
  992. * gives equal priority to transmits and receives.
  993. */
  994. if(hw->dma_fairness) {
  995. ctrl = E1000_READ_REG(hw, CTRL);
  996. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  997. }
  998. #endif
  999. switch(hw->mac_type) {
  1000. case e1000_82545_rev_3:
  1001. case e1000_82546_rev_3:
  1002. break;
  1003. default:
  1004. if (hw->mac_type >= e1000_82543) {
  1005. /* See e1000_get_bus_info() of the Linux driver */
  1006. status = E1000_READ_REG(hw, STATUS);
  1007. bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  1008. e1000_bus_type_pcix : e1000_bus_type_pci;
  1009. }
  1010. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  1011. if(bus_type == e1000_bus_type_pcix) {
  1012. pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  1013. pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
  1014. cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  1015. PCIX_COMMAND_MMRBC_SHIFT;
  1016. stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  1017. PCIX_STATUS_HI_MMRBC_SHIFT;
  1018. if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  1019. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  1020. if(cmd_mmrbc > stat_mmrbc) {
  1021. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  1022. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  1023. pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER, pcix_cmd_word);
  1024. }
  1025. }
  1026. break;
  1027. }
  1028. /* Call a subroutine to configure the link and setup flow control. */
  1029. ret_val = e1000_setup_link(hw);
  1030. /* Set the transmit descriptor write-back policy */
  1031. if(hw->mac_type > e1000_82544) {
  1032. ctrl = E1000_READ_REG(hw, TXDCTL);
  1033. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  1034. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  1035. }
  1036. #if 0
  1037. /* Clear all of the statistics registers (clear on read). It is
  1038. * important that we do this after we have tried to establish link
  1039. * because the symbol error count will increment wildly if there
  1040. * is no link.
  1041. */
  1042. e1000_clear_hw_cntrs(hw);
  1043. #endif
  1044. return ret_val;
  1045. }
  1046. /******************************************************************************
  1047. * Adjust SERDES output amplitude based on EEPROM setting.
  1048. *
  1049. * hw - Struct containing variables accessed by shared code.
  1050. *****************************************************************************/
  1051. static int32_t
  1052. e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
  1053. {
  1054. uint16_t eeprom_data;
  1055. int32_t ret_val;
  1056. DEBUGFUNC("e1000_adjust_serdes_amplitude");
  1057. if(hw->media_type != e1000_media_type_internal_serdes)
  1058. return E1000_SUCCESS;
  1059. switch(hw->mac_type) {
  1060. case e1000_82545_rev_3:
  1061. case e1000_82546_rev_3:
  1062. break;
  1063. default:
  1064. return E1000_SUCCESS;
  1065. }
  1066. if ((ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
  1067. &eeprom_data))) {
  1068. return ret_val;
  1069. }
  1070. if(eeprom_data != EEPROM_RESERVED_WORD) {
  1071. /* Adjust SERDES output amplitude only. */
  1072. eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
  1073. if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL,
  1074. eeprom_data)))
  1075. return ret_val;
  1076. }
  1077. return E1000_SUCCESS;
  1078. }
  1079. /******************************************************************************
  1080. * Configures flow control and link settings.
  1081. *
  1082. * hw - Struct containing variables accessed by shared code
  1083. *
  1084. * Determines which flow control settings to use. Calls the apropriate media-
  1085. * specific link configuration function. Configures the flow control settings.
  1086. * Assuming the adapter has a valid link partner, a valid link should be
  1087. * established. Assumes the hardware has previously been reset and the
  1088. * transmitter and receiver are not enabled.
  1089. *****************************************************************************/
  1090. static int
  1091. e1000_setup_link(struct e1000_hw *hw)
  1092. {
  1093. uint32_t ctrl_ext;
  1094. int32_t ret_val;
  1095. uint16_t eeprom_data;
  1096. DEBUGFUNC("e1000_setup_link");
  1097. /* Read and store word 0x0F of the EEPROM. This word contains bits
  1098. * that determine the hardware's default PAUSE (flow control) mode,
  1099. * a bit that determines whether the HW defaults to enabling or
  1100. * disabling auto-negotiation, and the direction of the
  1101. * SW defined pins. If there is no SW over-ride of the flow
  1102. * control setting, then the variable hw->fc will
  1103. * be initialized based on a value in the EEPROM.
  1104. */
  1105. if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
  1106. DEBUGOUT("EEPROM Read Error\n");
  1107. return -E1000_ERR_EEPROM;
  1108. }
  1109. if(hw->fc == e1000_fc_default) {
  1110. if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  1111. hw->fc = e1000_fc_none;
  1112. else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  1113. EEPROM_WORD0F_ASM_DIR)
  1114. hw->fc = e1000_fc_tx_pause;
  1115. else
  1116. hw->fc = e1000_fc_full;
  1117. }
  1118. /* We want to save off the original Flow Control configuration just
  1119. * in case we get disconnected and then reconnected into a different
  1120. * hub or switch with different Flow Control capabilities.
  1121. */
  1122. if(hw->mac_type == e1000_82542_rev2_0)
  1123. hw->fc &= (~e1000_fc_tx_pause);
  1124. #if 0
  1125. /* See e1000_sw_init() of the Linux driver */
  1126. if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  1127. #else
  1128. if((hw->mac_type < e1000_82543) && (hw->mac_type >= e1000_82543))
  1129. #endif
  1130. hw->fc &= (~e1000_fc_rx_pause);
  1131. #if 0
  1132. hw->original_fc = hw->fc;
  1133. #endif
  1134. DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
  1135. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  1136. * polarity value for the SW controlled pins, and setup the
  1137. * Extended Device Control reg with that info.
  1138. * This is needed because one of the SW controlled pins is used for
  1139. * signal detection. So this should be done before e1000_setup_pcs_link()
  1140. * or e1000_phy_setup() is called.
  1141. */
  1142. if(hw->mac_type == e1000_82543) {
  1143. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  1144. SWDPIO__EXT_SHIFT);
  1145. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1146. }
  1147. /* Call the necessary subroutine to configure the link. */
  1148. ret_val = (hw->media_type == e1000_media_type_copper) ?
  1149. e1000_setup_copper_link(hw) :
  1150. e1000_setup_fiber_serdes_link(hw);
  1151. if (ret_val < 0) {
  1152. return ret_val;
  1153. }
  1154. /* Initialize the flow control address, type, and PAUSE timer
  1155. * registers to their default values. This is done even if flow
  1156. * control is disabled, because it does not hurt anything to
  1157. * initialize these registers.
  1158. */
  1159. DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
  1160. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  1161. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  1162. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  1163. #if 0
  1164. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  1165. #else
  1166. E1000_WRITE_REG(hw, FCTTV, FC_DEFAULT_TX_TIMER);
  1167. #endif
  1168. /* Set the flow control receive threshold registers. Normally,
  1169. * these registers will be set to a default threshold that may be
  1170. * adjusted later by the driver's runtime code. However, if the
  1171. * ability to transmit pause frames in not enabled, then these
  1172. * registers will be set to 0.
  1173. */
  1174. if(!(hw->fc & e1000_fc_tx_pause)) {
  1175. E1000_WRITE_REG(hw, FCRTL, 0);
  1176. E1000_WRITE_REG(hw, FCRTH, 0);
  1177. } else {
  1178. /* We need to set up the Receive Threshold high and low water marks
  1179. * as well as (optionally) enabling the transmission of XON frames.
  1180. */
  1181. #if 0
  1182. if(hw->fc_send_xon) {
  1183. E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  1184. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1185. } else {
  1186. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  1187. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1188. }
  1189. #else
  1190. E1000_WRITE_REG(hw, FCRTL, (FC_DEFAULT_LO_THRESH | E1000_FCRTL_XONE));
  1191. E1000_WRITE_REG(hw, FCRTH, FC_DEFAULT_HI_THRESH);
  1192. #endif
  1193. }
  1194. return ret_val;
  1195. }
  1196. /******************************************************************************
  1197. * Sets up link for a fiber based or serdes based adapter
  1198. *
  1199. * hw - Struct containing variables accessed by shared code
  1200. *
  1201. * Manipulates Physical Coding Sublayer functions in order to configure
  1202. * link. Assumes the hardware has been previously reset and the transmitter
  1203. * and receiver are not enabled.
  1204. *****************************************************************************/
  1205. static int
  1206. e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
  1207. {
  1208. uint32_t ctrl;
  1209. uint32_t status;
  1210. uint32_t txcw = 0;
  1211. uint32_t i;
  1212. uint32_t signal = 0;
  1213. int32_t ret_val;
  1214. DEBUGFUNC("e1000_setup_fiber_serdes_link");
  1215. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  1216. * set when the optics detect a signal. On older adapters, it will be
  1217. * cleared when there is a signal. This applies to fiber media only.
  1218. * If we're on serdes media, adjust the output amplitude to value set in
  1219. * the EEPROM.
  1220. */
  1221. ctrl = E1000_READ_REG(hw, CTRL);
  1222. if(hw->media_type == e1000_media_type_fiber)
  1223. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  1224. if((ret_val = e1000_adjust_serdes_amplitude(hw)))
  1225. return ret_val;
  1226. /* Take the link out of reset */
  1227. ctrl &= ~(E1000_CTRL_LRST);
  1228. #if 0
  1229. /* Adjust VCO speed to improve BER performance */
  1230. if((ret_val = e1000_set_vco_speed(hw)))
  1231. return ret_val;
  1232. #endif
  1233. e1000_config_collision_dist(hw);
  1234. /* Check for a software override of the flow control settings, and setup
  1235. * the device accordingly. If auto-negotiation is enabled, then software
  1236. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  1237. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  1238. * auto-negotiation is disabled, then software will have to manually
  1239. * configure the two flow control enable bits in the CTRL register.
  1240. *
  1241. * The possible values of the "fc" parameter are:
  1242. * 0: Flow control is completely disabled
  1243. * 1: Rx flow control is enabled (we can receive pause frames, but
  1244. * not send pause frames).
  1245. * 2: Tx flow control is enabled (we can send pause frames but we do
  1246. * not support receiving pause frames).
  1247. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1248. */
  1249. switch (hw->fc) {
  1250. case e1000_fc_none:
  1251. /* Flow control is completely disabled by a software over-ride. */
  1252. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  1253. break;
  1254. case e1000_fc_rx_pause:
  1255. /* RX Flow control is enabled and TX Flow control is disabled by a
  1256. * software over-ride. Since there really isn't a way to advertise
  1257. * that we are capable of RX Pause ONLY, we will advertise that we
  1258. * support both symmetric and asymmetric RX PAUSE. Later, we will
  1259. * disable the adapter's ability to send PAUSE frames.
  1260. */
  1261. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1262. break;
  1263. case e1000_fc_tx_pause:
  1264. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  1265. * software over-ride.
  1266. */
  1267. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  1268. break;
  1269. case e1000_fc_full:
  1270. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  1271. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1272. break;
  1273. default:
  1274. DEBUGOUT("Flow control param set incorrectly\n");
  1275. return -E1000_ERR_CONFIG;
  1276. break;
  1277. }
  1278. /* Since auto-negotiation is enabled, take the link out of reset (the link
  1279. * will be in reset, because we previously reset the chip). This will
  1280. * restart auto-negotiation. If auto-neogtiation is successful then the
  1281. * link-up status bit will be set and the flow control enable bits (RFCE
  1282. * and TFCE) will be set according to their negotiated value.
  1283. */
  1284. DEBUGOUT("Auto-negotiation enabled\n");
  1285. E1000_WRITE_REG(hw, TXCW, txcw);
  1286. E1000_WRITE_REG(hw, CTRL, ctrl);
  1287. E1000_WRITE_FLUSH(hw);
  1288. hw->txcw = txcw;
  1289. mdelay(1);
  1290. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  1291. * indication in the Device Status Register. Time-out if a link isn't
  1292. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  1293. * less than 500 milliseconds even if the other end is doing it in SW).
  1294. * For internal serdes, we just assume a signal is present, then poll.
  1295. */
  1296. if(hw->media_type == e1000_media_type_internal_serdes ||
  1297. (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  1298. DEBUGOUT("Looking for Link\n");
  1299. for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  1300. mdelay(10);
  1301. status = E1000_READ_REG(hw, STATUS);
  1302. if(status & E1000_STATUS_LU) break;
  1303. }
  1304. if(i == (LINK_UP_TIMEOUT / 10)) {
  1305. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  1306. hw->autoneg_failed = 1;
  1307. /* AutoNeg failed to achieve a link, so we'll call
  1308. * e1000_check_for_link. This routine will force the link up if
  1309. * we detect a signal. This will allow us to communicate with
  1310. * non-autonegotiating link partners.
  1311. */
  1312. if((ret_val = e1000_check_for_link(hw))) {
  1313. DEBUGOUT("Error while checking for link\n");
  1314. return ret_val;
  1315. }
  1316. hw->autoneg_failed = 0;
  1317. } else {
  1318. hw->autoneg_failed = 0;
  1319. DEBUGOUT("Valid Link Found\n");
  1320. }
  1321. } else {
  1322. DEBUGOUT("No Signal Detected\n");
  1323. }
  1324. return E1000_SUCCESS;
  1325. }
  1326. /******************************************************************************
  1327. * Detects which PHY is present and the speed and duplex
  1328. *
  1329. * hw - Struct containing variables accessed by shared code
  1330. ******************************************************************************/
  1331. static int
  1332. e1000_setup_copper_link(struct e1000_hw *hw)
  1333. {
  1334. uint32_t ctrl;
  1335. int32_t ret_val;
  1336. uint16_t i;
  1337. uint16_t phy_data;
  1338. DEBUGFUNC("e1000_setup_copper_link");
  1339. ctrl = E1000_READ_REG(hw, CTRL);
  1340. /* With 82543, we need to force speed and duplex on the MAC equal to what
  1341. * the PHY speed and duplex configuration is. In addition, we need to
  1342. * perform a hardware reset on the PHY to take it out of reset.
  1343. */
  1344. if(hw->mac_type > e1000_82543) {
  1345. ctrl |= E1000_CTRL_SLU;
  1346. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1347. E1000_WRITE_REG(hw, CTRL, ctrl);
  1348. } else {
  1349. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  1350. E1000_WRITE_REG(hw, CTRL, ctrl);
  1351. e1000_phy_hw_reset(hw);
  1352. }
  1353. /* Make sure we have a valid PHY */
  1354. if((ret_val = e1000_detect_gig_phy(hw))) {
  1355. DEBUGOUT("Error, did not detect valid phy.\n");
  1356. return ret_val;
  1357. }
  1358. DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
  1359. if(hw->mac_type <= e1000_82543 ||
  1360. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  1361. #if 0
  1362. hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
  1363. hw->phy_reset_disable = FALSE;
  1364. if(!hw->phy_reset_disable) {
  1365. #else
  1366. hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
  1367. #endif
  1368. if (hw->phy_type == e1000_phy_igp) {
  1369. if((ret_val = e1000_phy_reset(hw))) {
  1370. DEBUGOUT("Error Resetting the PHY\n");
  1371. return ret_val;
  1372. }
  1373. /* Wait 10ms for MAC to configure PHY from eeprom settings */
  1374. mdelay(15);
  1375. #if 0
  1376. /* disable lplu d3 during driver init */
  1377. if((ret_val = e1000_set_d3_lplu_state(hw, FALSE))) {
  1378. DEBUGOUT("Error Disabling LPLU D3\n");
  1379. return ret_val;
  1380. }
  1381. /* Configure mdi-mdix settings */
  1382. if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
  1383. &phy_data)))
  1384. return ret_val;
  1385. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  1386. hw->dsp_config_state = e1000_dsp_config_disabled;
  1387. /* Force MDI for IGP B-0 PHY */
  1388. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
  1389. IGP01E1000_PSCR_FORCE_MDI_MDIX);
  1390. hw->mdix = 1;
  1391. } else {
  1392. hw->dsp_config_state = e1000_dsp_config_enabled;
  1393. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1394. switch (hw->mdix) {
  1395. case 1:
  1396. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1397. break;
  1398. case 2:
  1399. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1400. break;
  1401. case 0:
  1402. default:
  1403. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  1404. break;
  1405. }
  1406. }
  1407. if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
  1408. phy_data)))
  1409. return ret_val;
  1410. /* set auto-master slave resolution settings */
  1411. e1000_ms_type phy_ms_setting = hw->master_slave;
  1412. if(hw->ffe_config_state == e1000_ffe_config_active)
  1413. hw->ffe_config_state = e1000_ffe_config_enabled;
  1414. if(hw->dsp_config_state == e1000_dsp_config_activated)
  1415. hw->dsp_config_state = e1000_dsp_config_enabled;
  1416. #endif
  1417. /* when autonegotiation advertisment is only 1000Mbps then we
  1418. * should disable SmartSpeed and enable Auto MasterSlave
  1419. * resolution as hardware default. */
  1420. if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  1421. /* Disable SmartSpeed */
  1422. if((ret_val = e1000_read_phy_reg(hw,
  1423. IGP01E1000_PHY_PORT_CONFIG,
  1424. &phy_data)))
  1425. return ret_val;
  1426. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1427. if((ret_val = e1000_write_phy_reg(hw,
  1428. IGP01E1000_PHY_PORT_CONFIG,
  1429. phy_data)))
  1430. return ret_val;
  1431. /* Set auto Master/Slave resolution process */
  1432. if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  1433. &phy_data)))
  1434. return ret_val;
  1435. phy_data &= ~CR_1000T_MS_ENABLE;
  1436. if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  1437. phy_data)))
  1438. return ret_val;
  1439. }
  1440. if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  1441. &phy_data)))
  1442. return ret_val;
  1443. #if 0
  1444. /* load defaults for future use */
  1445. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  1446. ((phy_data & CR_1000T_MS_VALUE) ?
  1447. e1000_ms_force_master :
  1448. e1000_ms_force_slave) :
  1449. e1000_ms_auto;
  1450. switch (phy_ms_setting) {
  1451. case e1000_ms_force_master:
  1452. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  1453. break;
  1454. case e1000_ms_force_slave:
  1455. phy_data |= CR_1000T_MS_ENABLE;
  1456. phy_data &= ~(CR_1000T_MS_VALUE);
  1457. break;
  1458. case e1000_ms_auto:
  1459. phy_data &= ~CR_1000T_MS_ENABLE;
  1460. default:
  1461. break;
  1462. }
  1463. #endif
  1464. if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  1465. phy_data)))
  1466. return ret_val;
  1467. } else {
  1468. /* Enable CRS on TX. This must be set for half-duplex operation. */
  1469. if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1470. &phy_data)))
  1471. return ret_val;
  1472. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1473. /* Options:
  1474. * MDI/MDI-X = 0 (default)
  1475. * 0 - Auto for all speeds
  1476. * 1 - MDI mode
  1477. * 2 - MDI-X mode
  1478. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  1479. */
  1480. #if 0
  1481. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1482. switch (hw->mdix) {
  1483. case 1:
  1484. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  1485. break;
  1486. case 2:
  1487. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  1488. break;
  1489. case 3:
  1490. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  1491. break;
  1492. case 0:
  1493. default:
  1494. #endif
  1495. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  1496. #if 0
  1497. break;
  1498. }
  1499. #endif
  1500. /* Options:
  1501. * disable_polarity_correction = 0 (default)
  1502. * Automatic Correction for Reversed Cable Polarity
  1503. * 0 - Disabled
  1504. * 1 - Enabled
  1505. */
  1506. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  1507. if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1508. phy_data)))
  1509. return ret_val;
  1510. /* Force TX_CLK in the Extended PHY Specific Control Register
  1511. * to 25MHz clock.
  1512. */
  1513. if((ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  1514. &phy_data)))
  1515. return ret_val;
  1516. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1517. #ifdef LINUX_DRIVER
  1518. if (hw->phy_revision < M88E1011_I_REV_4) {
  1519. #endif
  1520. /* Configure Master and Slave downshift values */
  1521. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  1522. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  1523. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  1524. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  1525. if((ret_val = e1000_write_phy_reg(hw,
  1526. M88E1000_EXT_PHY_SPEC_CTRL,
  1527. phy_data)))
  1528. return ret_val;
  1529. }
  1530. /* SW Reset the PHY so all changes take effect */
  1531. if((ret_val = e1000_phy_reset(hw))) {
  1532. DEBUGOUT("Error Resetting the PHY\n");
  1533. return ret_val;
  1534. #ifdef LINUX_DRIVER
  1535. }
  1536. #endif
  1537. }
  1538. /* Options:
  1539. * autoneg = 1 (default)
  1540. * PHY will advertise value(s) parsed from
  1541. * autoneg_advertised and fc
  1542. * autoneg = 0
  1543. * PHY will be set to 10H, 10F, 100H, or 100F
  1544. * depending on value parsed from forced_speed_duplex.
  1545. */
  1546. /* Is autoneg enabled? This is enabled by default or by software
  1547. * override. If so, call e1000_phy_setup_autoneg routine to parse the
  1548. * autoneg_advertised and fc options. If autoneg is NOT enabled, then
  1549. * the user should have provided a speed/duplex override. If so, then
  1550. * call e1000_phy_force_speed_duplex to parse and set this up.
  1551. */
  1552. /* Perform some bounds checking on the hw->autoneg_advertised
  1553. * parameter. If this variable is zero, then set it to the default.
  1554. */
  1555. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1556. /* If autoneg_advertised is zero, we assume it was not defaulted
  1557. * by the calling code so we set to advertise full capability.
  1558. */
  1559. if(hw->autoneg_advertised == 0)
  1560. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1561. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  1562. if((ret_val = e1000_phy_setup_autoneg(hw))) {
  1563. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  1564. return ret_val;
  1565. }
  1566. DEBUGOUT("Restarting Auto-Neg\n");
  1567. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  1568. * the Auto Neg Restart bit in the PHY control register.
  1569. */
  1570. if((ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data)))
  1571. return ret_val;
  1572. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  1573. if((ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data)))
  1574. return ret_val;
  1575. #if 0
  1576. /* Does the user want to wait for Auto-Neg to complete here, or
  1577. * check at a later time (for example, callback routine).
  1578. */
  1579. if(hw->wait_autoneg_complete) {
  1580. if((ret_val = e1000_wait_autoneg(hw))) {
  1581. DEBUGOUT("Error while waiting for autoneg to complete\n");
  1582. return ret_val;
  1583. }
  1584. }
  1585. #else
  1586. /* If we do not wait for autonegotiation to complete I
  1587. * do not see a valid link status.
  1588. */
  1589. if((ret_val = e1000_wait_autoneg(hw))) {
  1590. DEBUGOUT("Error while waiting for autoneg to complete\n");
  1591. return ret_val;
  1592. }
  1593. #endif
  1594. } /* !hw->phy_reset_disable */
  1595. /* Check link status. Wait up to 100 microseconds for link to become
  1596. * valid.
  1597. */
  1598. for(i = 0; i < 10; i++) {
  1599. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
  1600. return ret_val;
  1601. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
  1602. return ret_val;
  1603. if(phy_data & MII_SR_LINK_STATUS) {
  1604. /* We have link, so we need to finish the config process:
  1605. * 1) Set up the MAC to the current PHY speed/duplex
  1606. * if we are on 82543. If we
  1607. * are on newer silicon, we only need to configure
  1608. * collision distance in the Transmit Control Register.
  1609. * 2) Set up flow control on the MAC to that established with
  1610. * the link partner.
  1611. */
  1612. if(hw->mac_type >= e1000_82544) {
  1613. e1000_config_collision_dist(hw);
  1614. } else {
  1615. if((ret_val = e1000_config_mac_to_phy(hw))) {
  1616. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1617. return ret_val;
  1618. }
  1619. }
  1620. if((ret_val = e1000_config_fc_after_link_up(hw))) {
  1621. DEBUGOUT("Error Configuring Flow Control\n");
  1622. return ret_val;
  1623. }
  1624. #if 0
  1625. if(hw->phy_type == e1000_phy_igp) {
  1626. if((ret_val = e1000_config_dsp_after_link_change(hw, TRUE))) {
  1627. DEBUGOUT("Error Configuring DSP after link up\n");
  1628. return ret_val;
  1629. }
  1630. }
  1631. #endif
  1632. DEBUGOUT("Valid link established!!!\n");
  1633. return E1000_SUCCESS;
  1634. }
  1635. udelay(10);
  1636. }
  1637. DEBUGOUT("Unable to establish link!!!\n");
  1638. return -E1000_ERR_NOLINK;
  1639. }
  1640. /******************************************************************************
  1641. * Configures PHY autoneg and flow control advertisement settings
  1642. *
  1643. * hw - Struct containing variables accessed by shared code
  1644. ******************************************************************************/
  1645. static int
  1646. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  1647. {
  1648. int32_t ret_val;
  1649. uint16_t mii_autoneg_adv_reg;
  1650. uint16_t mii_1000t_ctrl_reg;
  1651. DEBUGFUNC("e1000_phy_setup_autoneg");
  1652. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  1653. if((ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
  1654. &mii_autoneg_adv_reg)))
  1655. return ret_val;
  1656. /* Read the MII 1000Base-T Control Register (Address 9). */
  1657. if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg)))
  1658. return ret_val;
  1659. /* Need to parse both autoneg_advertised and fc and set up
  1660. * the appropriate PHY registers. First we will parse for
  1661. * autoneg_advertised software override. Since we can advertise
  1662. * a plethora of combinations, we need to check each bit
  1663. * individually.
  1664. */
  1665. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  1666. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  1667. * the 1000Base-T Control Register (Address 9).
  1668. */
  1669. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  1670. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  1671. DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
  1672. /* Do we want to advertise 10 Mb Half Duplex? */
  1673. if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
  1674. DEBUGOUT("Advertise 10mb Half duplex\n");
  1675. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  1676. }
  1677. /* Do we want to advertise 10 Mb Full Duplex? */
  1678. if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
  1679. DEBUGOUT("Advertise 10mb Full duplex\n");
  1680. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  1681. }
  1682. /* Do we want to advertise 100 Mb Half Duplex? */
  1683. if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
  1684. DEBUGOUT("Advertise 100mb Half duplex\n");
  1685. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  1686. }
  1687. /* Do we want to advertise 100 Mb Full Duplex? */
  1688. if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
  1689. DEBUGOUT("Advertise 100mb Full duplex\n");
  1690. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  1691. }
  1692. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  1693. if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  1694. DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
  1695. }
  1696. /* Do we want to advertise 1000 Mb Full Duplex? */
  1697. if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  1698. DEBUGOUT("Advertise 1000mb Full duplex\n");
  1699. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  1700. }
  1701. /* Check for a software override of the flow control settings, and
  1702. * setup the PHY advertisement registers accordingly. If
  1703. * auto-negotiation is enabled, then software will have to set the
  1704. * "PAUSE" bits to the correct value in the Auto-Negotiation
  1705. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  1706. *
  1707. * The possible values of the "fc" parameter are:
  1708. * 0: Flow control is completely disabled
  1709. * 1: Rx flow control is enabled (we can receive pause frames
  1710. * but not send pause frames).
  1711. * 2: Tx flow control is enabled (we can send pause frames
  1712. * but we do not support receiving pause frames).
  1713. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1714. * other: No software override. The flow control configuration
  1715. * in the EEPROM is used.
  1716. */
  1717. switch (hw->fc) {
  1718. case e1000_fc_none: /* 0 */
  1719. /* Flow control (RX & TX) is completely disabled by a
  1720. * software over-ride.
  1721. */
  1722. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1723. break;
  1724. case e1000_fc_rx_pause: /* 1 */
  1725. /* RX Flow control is enabled, and TX Flow control is
  1726. * disabled, by a software over-ride.
  1727. */
  1728. /* Since there really isn't a way to advertise that we are
  1729. * capable of RX Pause ONLY, we will advertise that we
  1730. * support both symmetric and asymmetric RX PAUSE. Later
  1731. * (in e1000_config_fc_after_link_up) we will disable the
  1732. *hw's ability to send PAUSE frames.
  1733. */
  1734. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1735. break;
  1736. case e1000_fc_tx_pause: /* 2 */
  1737. /* TX Flow control is enabled, and RX Flow control is
  1738. * disabled, by a software over-ride.
  1739. */
  1740. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  1741. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  1742. break;
  1743. case e1000_fc_full: /* 3 */
  1744. /* Flow control (both RX and TX) is enabled by a software
  1745. * over-ride.
  1746. */
  1747. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1748. break;
  1749. default:
  1750. DEBUGOUT("Flow control param set incorrectly\n");
  1751. return -E1000_ERR_CONFIG;
  1752. }
  1753. if((ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV,
  1754. mii_autoneg_adv_reg)))
  1755. return ret_val;
  1756. DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  1757. if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg)))
  1758. return ret_val;
  1759. return E1000_SUCCESS;
  1760. }
  1761. /******************************************************************************
  1762. * Sets the collision distance in the Transmit Control register
  1763. *
  1764. * hw - Struct containing variables accessed by shared code
  1765. *
  1766. * Link should have been established previously. Reads the speed and duplex
  1767. * information from the Device Status register.
  1768. ******************************************************************************/
  1769. static void
  1770. e1000_config_collision_dist(struct e1000_hw *hw)
  1771. {
  1772. uint32_t tctl;
  1773. tctl = E1000_READ_REG(hw, TCTL);
  1774. tctl &= ~E1000_TCTL_COLD;
  1775. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  1776. E1000_WRITE_REG(hw, TCTL, tctl);
  1777. E1000_WRITE_FLUSH(hw);
  1778. }
  1779. /******************************************************************************
  1780. * Sets MAC speed and duplex settings to reflect the those in the PHY
  1781. *
  1782. * hw - Struct containing variables accessed by shared code
  1783. * mii_reg - data to write to the MII control register
  1784. *
  1785. * The contents of the PHY register containing the needed information need to
  1786. * be passed in.
  1787. ******************************************************************************/
  1788. static int
  1789. e1000_config_mac_to_phy(struct e1000_hw *hw)
  1790. {
  1791. uint32_t ctrl;
  1792. int32_t ret_val;
  1793. uint16_t phy_data;
  1794. DEBUGFUNC("e1000_config_mac_to_phy");
  1795. /* Read the Device Control Register and set the bits to Force Speed
  1796. * and Duplex.
  1797. */
  1798. ctrl = E1000_READ_REG(hw, CTRL);
  1799. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1800. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1801. /* Set up duplex in the Device Control and Transmit Control
  1802. * registers depending on negotiated values.
  1803. */
  1804. if (hw->phy_type == e1000_phy_igp) {
  1805. if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  1806. &phy_data)))
  1807. return ret_val;
  1808. if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
  1809. else ctrl &= ~E1000_CTRL_FD;
  1810. e1000_config_collision_dist(hw);
  1811. /* Set up speed in the Device Control register depending on
  1812. * negotiated values.
  1813. */
  1814. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  1815. IGP01E1000_PSSR_SPEED_1000MBPS)
  1816. ctrl |= E1000_CTRL_SPD_1000;
  1817. else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  1818. IGP01E1000_PSSR_SPEED_100MBPS)
  1819. ctrl |= E1000_CTRL_SPD_100;
  1820. } else {
  1821. if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  1822. &phy_data)))
  1823. return ret_val;
  1824. if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
  1825. else ctrl &= ~E1000_CTRL_FD;
  1826. e1000_config_collision_dist(hw);
  1827. /* Set up speed in the Device Control register depending on
  1828. * negotiated values.
  1829. */
  1830. if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  1831. ctrl |= E1000_CTRL_SPD_1000;
  1832. else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  1833. ctrl |= E1000_CTRL_SPD_100;
  1834. }
  1835. /* Write the configured values back to the Device Control Reg. */
  1836. E1000_WRITE_REG(hw, CTRL, ctrl);
  1837. return E1000_SUCCESS;
  1838. }
  1839. /******************************************************************************
  1840. * Forces the MAC's flow control settings.
  1841. *
  1842. * hw - Struct containing variables accessed by shared code
  1843. *
  1844. * Sets the TFCE and RFCE bits in the device control register to reflect
  1845. * the adapter settings. TFCE and RFCE need to be explicitly set by
  1846. * software when a Copper PHY is used because autonegotiation is managed
  1847. * by the PHY rather than the MAC. Software must also configure these
  1848. * bits when link is forced on a fiber connection.
  1849. *****************************************************************************/
  1850. static int
  1851. e1000_force_mac_fc(struct e1000_hw *hw)
  1852. {
  1853. uint32_t ctrl;
  1854. DEBUGFUNC("e1000_force_mac_fc");
  1855. /* Get the current configuration of the Device Control Register */
  1856. ctrl = E1000_READ_REG(hw, CTRL);
  1857. /* Because we didn't get link via the internal auto-negotiation
  1858. * mechanism (we either forced link or we got link via PHY
  1859. * auto-neg), we have to manually enable/disable transmit an
  1860. * receive flow control.
  1861. *
  1862. * The "Case" statement below enables/disable flow control
  1863. * according to the "hw->fc" parameter.
  1864. *
  1865. * The possible values of the "fc" parameter are:
  1866. * 0: Flow control is completely disabled
  1867. * 1: Rx flow control is enabled (we can receive pause
  1868. * frames but not send pause frames).
  1869. * 2: Tx flow control is enabled (we can send pause frames
  1870. * frames but we do not receive pause frames).
  1871. * 3: Both Rx and TX flow control (symmetric) is enabled.
  1872. * other: No other values should be possible at this point.
  1873. */
  1874. switch (hw->fc) {
  1875. case e1000_fc_none:
  1876. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  1877. break;
  1878. case e1000_fc_rx_pause:
  1879. ctrl &= (~E1000_CTRL_TFCE);
  1880. ctrl |= E1000_CTRL_RFCE;
  1881. break;
  1882. case e1000_fc_tx_pause:
  1883. ctrl &= (~E1000_CTRL_RFCE);
  1884. ctrl |= E1000_CTRL_TFCE;
  1885. break;
  1886. case e1000_fc_full:
  1887. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  1888. break;
  1889. default:
  1890. DEBUGOUT("Flow control param set incorrectly\n");
  1891. return -E1000_ERR_CONFIG;
  1892. }
  1893. /* Disable TX Flow Control for 82542 (rev 2.0) */
  1894. if(hw->mac_type == e1000_82542_rev2_0)
  1895. ctrl &= (~E1000_CTRL_TFCE);
  1896. E1000_WRITE_REG(hw, CTRL, ctrl);
  1897. return E1000_SUCCESS;
  1898. }
  1899. /******************************************************************************
  1900. * Configures flow control settings after link is established
  1901. *
  1902. * hw - Struct containing variables accessed by shared code
  1903. *
  1904. * Should be called immediately after a valid link has been established.
  1905. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  1906. * and autonegotiation is enabled, the MAC flow control settings will be set
  1907. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  1908. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  1909. *****************************************************************************/
  1910. static int
  1911. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  1912. {
  1913. int32_t ret_val;
  1914. uint16_t mii_status_reg;
  1915. uint16_t mii_nway_adv_reg;
  1916. uint16_t mii_nway_lp_ability_reg;
  1917. uint16_t speed;
  1918. uint16_t duplex;
  1919. DEBUGFUNC("e1000_config_fc_after_link_up");
  1920. /* Check for the case where we have fiber media and auto-neg failed
  1921. * so we had to force link. In this case, we need to force the
  1922. * configuration of the MAC to match the "fc" parameter.
  1923. */
  1924. if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
  1925. ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed))) {
  1926. if((ret_val = e1000_force_mac_fc(hw))) {
  1927. DEBUGOUT("Error forcing flow control settings\n");
  1928. return ret_val;
  1929. }
  1930. }
  1931. /* Check for the case where we have copper media and auto-neg is
  1932. * enabled. In this case, we need to check and see if Auto-Neg
  1933. * has completed, and if so, how the PHY and link partner has
  1934. * flow control configured.
  1935. */
  1936. if(hw->media_type == e1000_media_type_copper) {
  1937. /* Read the MII Status Register and check to see if AutoNeg
  1938. * has completed. We read this twice because this reg has
  1939. * some "sticky" (latched) bits.
  1940. */
  1941. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
  1942. return ret_val;
  1943. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
  1944. return ret_val;
  1945. if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  1946. /* The AutoNeg process has completed, so we now need to
  1947. * read both the Auto Negotiation Advertisement Register
  1948. * (Address 4) and the Auto_Negotiation Base Page Ability
  1949. * Register (Address 5) to determine how flow control was
  1950. * negotiated.
  1951. */
  1952. if((ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
  1953. &mii_nway_adv_reg)))
  1954. return ret_val;
  1955. if((ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
  1956. &mii_nway_lp_ability_reg)))
  1957. return ret_val;
  1958. /* Two bits in the Auto Negotiation Advertisement Register
  1959. * (Address 4) and two bits in the Auto Negotiation Base
  1960. * Page Ability Register (Address 5) determine flow control
  1961. * for both the PHY and the link partner. The following
  1962. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1963. * 1999, describes these PAUSE resolution bits and how flow
  1964. * control is determined based upon these settings.
  1965. * NOTE: DC = Don't Care
  1966. *
  1967. * LOCAL DEVICE | LINK PARTNER
  1968. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1969. *-------|---------|-------|---------|--------------------
  1970. * 0 | 0 | DC | DC | e1000_fc_none
  1971. * 0 | 1 | 0 | DC | e1000_fc_none
  1972. * 0 | 1 | 1 | 0 | e1000_fc_none
  1973. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1974. * 1 | 0 | 0 | DC | e1000_fc_none
  1975. * 1 | DC | 1 | DC | e1000_fc_full
  1976. * 1 | 1 | 0 | 0 | e1000_fc_none
  1977. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1978. *
  1979. */
  1980. /* Are both PAUSE bits set to 1? If so, this implies
  1981. * Symmetric Flow Control is enabled at both ends. The
  1982. * ASM_DIR bits are irrelevant per the spec.
  1983. *
  1984. * For Symmetric Flow Control:
  1985. *
  1986. * LOCAL DEVICE | LINK PARTNER
  1987. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1988. *-------|---------|-------|---------|--------------------
  1989. * 1 | DC | 1 | DC | e1000_fc_full
  1990. *
  1991. */
  1992. if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1993. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1994. /* Now we need to check if the user selected RX ONLY
  1995. * of pause frames. In this case, we had to advertise
  1996. * FULL flow control because we could not advertise RX
  1997. * ONLY. Hence, we must now check to see if we need to
  1998. * turn OFF the TRANSMISSION of PAUSE frames.
  1999. */
  2000. #if 0
  2001. if(hw->original_fc == e1000_fc_full) {
  2002. hw->fc = e1000_fc_full;
  2003. #else
  2004. if(hw->fc == e1000_fc_full) {
  2005. #endif
  2006. DEBUGOUT("Flow Control = FULL.\r\n");
  2007. } else {
  2008. hw->fc = e1000_fc_rx_pause;
  2009. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  2010. }
  2011. }
  2012. /* For receiving PAUSE frames ONLY.
  2013. *
  2014. * LOCAL DEVICE | LINK PARTNER
  2015. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  2016. *-------|---------|-------|---------|--------------------
  2017. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  2018. *
  2019. */
  2020. else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  2021. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  2022. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  2023. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  2024. hw->fc = e1000_fc_tx_pause;
  2025. DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
  2026. }
  2027. /* For transmitting PAUSE frames ONLY.
  2028. *
  2029. * LOCAL DEVICE | LINK PARTNER
  2030. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  2031. *-------|---------|-------|---------|--------------------
  2032. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  2033. *
  2034. */
  2035. else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  2036. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  2037. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  2038. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  2039. hw->fc = e1000_fc_rx_pause;
  2040. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  2041. }
  2042. /* Per the IEEE spec, at this point flow control should be
  2043. * disabled. However, we want to consider that we could
  2044. * be connected to a legacy switch that doesn't advertise
  2045. * desired flow control, but can be forced on the link
  2046. * partner. So if we advertised no flow control, that is
  2047. * what we will resolve to. If we advertised some kind of
  2048. * receive capability (Rx Pause Only or Full Flow Control)
  2049. * and the link partner advertised none, we will configure
  2050. * ourselves to enable Rx Flow Control only. We can do
  2051. * this safely for two reasons: If the link partner really
  2052. * didn't want flow control enabled, and we enable Rx, no
  2053. * harm done since we won't be receiving any PAUSE frames
  2054. * anyway. If the intent on the link partner was to have
  2055. * flow control enabled, then by us enabling RX only, we
  2056. * can at least receive pause frames and process them.
  2057. * This is a good idea because in most cases, since we are
  2058. * predominantly a server NIC, more times than not we will
  2059. * be asked to delay transmission of packets than asking
  2060. * our link partner to pause transmission of frames.
  2061. */
  2062. #if 0
  2063. else if(hw->original_fc == e1000_fc_none ||
  2064. hw->original_fc == e1000_fc_tx_pause) {
  2065. #else
  2066. else if(hw->fc == e1000_fc_none)
  2067. DEBUGOUT("Flow Control = NONE.\r\n");
  2068. else if(hw->fc == e1000_fc_tx_pause) {
  2069. #endif
  2070. hw->fc = e1000_fc_none;
  2071. DEBUGOUT("Flow Control = NONE.\r\n");
  2072. } else {
  2073. hw->fc = e1000_fc_rx_pause;
  2074. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  2075. }
  2076. /* Now we need to do one last check... If we auto-
  2077. * negotiated to HALF DUPLEX, flow control should not be
  2078. * enabled per IEEE 802.3 spec.
  2079. */
  2080. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  2081. if(duplex == HALF_DUPLEX)
  2082. hw->fc = e1000_fc_none;
  2083. /* Now we call a subroutine to actually force the MAC
  2084. * controller to use the correct flow control settings.
  2085. */
  2086. if((ret_val = e1000_force_mac_fc(hw))) {
  2087. DEBUGOUT("Error forcing flow control settings\n");
  2088. return ret_val;
  2089. }
  2090. } else {
  2091. DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
  2092. }
  2093. }
  2094. return E1000_SUCCESS;
  2095. }
  2096. /******************************************************************************
  2097. * Checks to see if the link status of the hardware has changed.
  2098. *
  2099. * hw - Struct containing variables accessed by shared code
  2100. *
  2101. * Called by any function that needs to check the link status of the adapter.
  2102. *****************************************************************************/
  2103. static int
  2104. e1000_check_for_link(struct e1000_hw *hw)
  2105. {
  2106. uint32_t rxcw;
  2107. uint32_t ctrl;
  2108. uint32_t status;
  2109. uint32_t rctl;
  2110. uint32_t signal = 0;
  2111. int32_t ret_val;
  2112. uint16_t phy_data;
  2113. uint16_t lp_capability;
  2114. DEBUGFUNC("e1000_check_for_link");
  2115. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  2116. * set when the optics detect a signal. On older adapters, it will be
  2117. * cleared when there is a signal. This applies to fiber media only.
  2118. */
  2119. if(hw->media_type == e1000_media_type_fiber)
  2120. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  2121. ctrl = E1000_READ_REG(hw, CTRL);
  2122. status = E1000_READ_REG(hw, STATUS);
  2123. rxcw = E1000_READ_REG(hw, RXCW);
  2124. /* If we have a copper PHY then we only want to go out to the PHY
  2125. * registers to see if Auto-Neg has completed and/or if our link
  2126. * status has changed. The get_link_status flag will be set if we
  2127. * receive a Link Status Change interrupt or we have Rx Sequence
  2128. * Errors.
  2129. */
  2130. #if 0
  2131. if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  2132. #else
  2133. if(hw->media_type == e1000_media_type_copper) {
  2134. #endif
  2135. /* First we want to see if the MII Status Register reports
  2136. * link. If so, then we want to get the current speed/duplex
  2137. * of the PHY.
  2138. * Read the register twice since the link bit is sticky.
  2139. */
  2140. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
  2141. return ret_val;
  2142. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
  2143. return ret_val;
  2144. if(phy_data & MII_SR_LINK_STATUS) {
  2145. #if 0
  2146. hw->get_link_status = FALSE;
  2147. #endif
  2148. } else {
  2149. /* No link detected */
  2150. return -E1000_ERR_NOLINK;
  2151. }
  2152. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  2153. * have Si on board that is 82544 or newer, Auto
  2154. * Speed Detection takes care of MAC speed/duplex
  2155. * configuration. So we only need to configure Collision
  2156. * Distance in the MAC. Otherwise, we need to force
  2157. * speed/duplex on the MAC to the current PHY speed/duplex
  2158. * settings.
  2159. */
  2160. if(hw->mac_type >= e1000_82544)
  2161. e1000_config_collision_dist(hw);
  2162. else {
  2163. if((ret_val = e1000_config_mac_to_phy(hw))) {
  2164. DEBUGOUT("Error configuring MAC to PHY settings\n");
  2165. return ret_val;
  2166. }
  2167. }
  2168. /* Configure Flow Control now that Auto-Neg has completed. First, we
  2169. * need to restore the desired flow control settings because we may
  2170. * have had to re-autoneg with a different link partner.
  2171. */
  2172. if((ret_val = e1000_config_fc_after_link_up(hw))) {
  2173. DEBUGOUT("Error configuring flow control\n");
  2174. return ret_val;
  2175. }
  2176. /* At this point we know that we are on copper and we have
  2177. * auto-negotiated link. These are conditions for checking the link
  2178. * parter capability register. We use the link partner capability to
  2179. * determine if TBI Compatibility needs to be turned on or off. If
  2180. * the link partner advertises any speed in addition to Gigabit, then
  2181. * we assume that they are GMII-based, and TBI compatibility is not
  2182. * needed. If no other speeds are advertised, we assume the link
  2183. * partner is TBI-based, and we turn on TBI Compatibility.
  2184. */
  2185. if(hw->tbi_compatibility_en) {
  2186. if((ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
  2187. &lp_capability)))
  2188. return ret_val;
  2189. if(lp_capability & (NWAY_LPAR_10T_HD_CAPS |
  2190. NWAY_LPAR_10T_FD_CAPS |
  2191. NWAY_LPAR_100TX_HD_CAPS |
  2192. NWAY_LPAR_100TX_FD_CAPS |
  2193. NWAY_LPAR_100T4_CAPS)) {
  2194. /* If our link partner advertises anything in addition to
  2195. * gigabit, we do not need to enable TBI compatibility.
  2196. */
  2197. if(hw->tbi_compatibility_on) {
  2198. /* If we previously were in the mode, turn it off. */
  2199. rctl = E1000_READ_REG(hw, RCTL);
  2200. rctl &= ~E1000_RCTL_SBP;
  2201. E1000_WRITE_REG(hw, RCTL, rctl);
  2202. hw->tbi_compatibility_on = FALSE;
  2203. }
  2204. } else {
  2205. /* If TBI compatibility is was previously off, turn it on. For
  2206. * compatibility with a TBI link partner, we will store bad
  2207. * packets. Some frames have an additional byte on the end and
  2208. * will look like CRC errors to to the hardware.
  2209. */
  2210. if(!hw->tbi_compatibility_on) {
  2211. hw->tbi_compatibility_on = TRUE;
  2212. rctl = E1000_READ_REG(hw, RCTL);
  2213. rctl |= E1000_RCTL_SBP;
  2214. E1000_WRITE_REG(hw, RCTL, rctl);
  2215. }
  2216. }
  2217. }
  2218. }
  2219. /* If we don't have link (auto-negotiation failed or link partner cannot
  2220. * auto-negotiate), the cable is plugged in (we have signal), and our
  2221. * link partner is not trying to auto-negotiate with us (we are receiving
  2222. * idles or data), we need to force link up. We also need to give
  2223. * auto-negotiation time to complete, in case the cable was just plugged
  2224. * in. The autoneg_failed flag does this.
  2225. */
  2226. else if((((hw->media_type == e1000_media_type_fiber) &&
  2227. ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
  2228. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2229. (!(status & E1000_STATUS_LU)) &&
  2230. (!(rxcw & E1000_RXCW_C))) {
  2231. if(hw->autoneg_failed == 0) {
  2232. hw->autoneg_failed = 1;
  2233. return 0;
  2234. }
  2235. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  2236. /* Disable auto-negotiation in the TXCW register */
  2237. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  2238. /* Force link-up and also force full-duplex. */
  2239. ctrl = E1000_READ_REG(hw, CTRL);
  2240. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  2241. E1000_WRITE_REG(hw, CTRL, ctrl);
  2242. /* Configure Flow Control after forcing link up. */
  2243. if((ret_val = e1000_config_fc_after_link_up(hw))) {
  2244. DEBUGOUT("Error configuring flow control\n");
  2245. return ret_val;
  2246. }
  2247. }
  2248. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  2249. * auto-negotiation in the TXCW register and disable forced link in the
  2250. * Device Control register in an attempt to auto-negotiate with our link
  2251. * partner.
  2252. */
  2253. else if(((hw->media_type == e1000_media_type_fiber) ||
  2254. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2255. (ctrl & E1000_CTRL_SLU) &&
  2256. (rxcw & E1000_RXCW_C)) {
  2257. DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  2258. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  2259. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  2260. }
  2261. #if 0
  2262. /* If we force link for non-auto-negotiation switch, check link status
  2263. * based on MAC synchronization for internal serdes media type.
  2264. */
  2265. else if((hw->media_type == e1000_media_type_internal_serdes) &&
  2266. !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  2267. /* SYNCH bit and IV bit are sticky. */
  2268. udelay(10);
  2269. if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
  2270. if(!(rxcw & E1000_RXCW_IV)) {
  2271. hw->serdes_link_down = FALSE;
  2272. DEBUGOUT("SERDES: Link is up.\n");
  2273. }
  2274. } else {
  2275. hw->serdes_link_down = TRUE;
  2276. DEBUGOUT("SERDES: Link is down.\n");
  2277. }
  2278. }
  2279. #endif
  2280. return E1000_SUCCESS;
  2281. }
  2282. /******************************************************************************
  2283. * Detects the current speed and duplex settings of the hardware.
  2284. *
  2285. * hw - Struct containing variables accessed by shared code
  2286. * speed - Speed of the connection
  2287. * duplex - Duplex setting of the connection
  2288. *****************************************************************************/
  2289. static void
  2290. e1000_get_speed_and_duplex(struct e1000_hw *hw,
  2291. uint16_t *speed,
  2292. uint16_t *duplex)
  2293. {
  2294. uint32_t status;
  2295. DEBUGFUNC("e1000_get_speed_and_duplex");
  2296. if(hw->mac_type >= e1000_82543) {
  2297. status = E1000_READ_REG(hw, STATUS);
  2298. if(status & E1000_STATUS_SPEED_1000) {
  2299. *speed = SPEED_1000;
  2300. DEBUGOUT("1000 Mbs, ");
  2301. } else if(status & E1000_STATUS_SPEED_100) {
  2302. *speed = SPEED_100;
  2303. DEBUGOUT("100 Mbs, ");
  2304. } else {
  2305. *speed = SPEED_10;
  2306. DEBUGOUT("10 Mbs, ");
  2307. }
  2308. if(status & E1000_STATUS_FD) {
  2309. *duplex = FULL_DUPLEX;
  2310. DEBUGOUT("Full Duplex\r\n");
  2311. } else {
  2312. *duplex = HALF_DUPLEX;
  2313. DEBUGOUT(" Half Duplex\r\n");
  2314. }
  2315. } else {
  2316. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  2317. *speed = SPEED_1000;
  2318. *duplex = FULL_DUPLEX;
  2319. }
  2320. }
  2321. /******************************************************************************
  2322. * Blocks until autoneg completes or times out (~4.5 seconds)
  2323. *
  2324. * hw - Struct containing variables accessed by shared code
  2325. ******************************************************************************/
  2326. static int
  2327. e1000_wait_autoneg(struct e1000_hw *hw)
  2328. {
  2329. int32_t ret_val;
  2330. uint16_t i;
  2331. uint16_t phy_data;
  2332. DEBUGFUNC("e1000_wait_autoneg");
  2333. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  2334. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  2335. for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  2336. /* Read the MII Status Register and wait for Auto-Neg
  2337. * Complete bit to be set.
  2338. */
  2339. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
  2340. return ret_val;
  2341. if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
  2342. return ret_val;
  2343. if(phy_data & MII_SR_AUTONEG_COMPLETE) {
  2344. DEBUGOUT("Auto-Neg complete.\n");
  2345. return E1000_SUCCESS;
  2346. }
  2347. mdelay(100);
  2348. }
  2349. DEBUGOUT("Auto-Neg timedout.\n");
  2350. return -E1000_ERR_TIMEOUT;
  2351. }
  2352. /******************************************************************************
  2353. * Raises the Management Data Clock
  2354. *
  2355. * hw - Struct containing variables accessed by shared code
  2356. * ctrl - Device control register's current value
  2357. ******************************************************************************/
  2358. static void
  2359. e1000_raise_mdi_clk(struct e1000_hw *hw,
  2360. uint32_t *ctrl)
  2361. {
  2362. /* Raise the clock input to the Management Data Clock (by setting the MDC
  2363. * bit), and then delay 10 microseconds.
  2364. */
  2365. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  2366. E1000_WRITE_FLUSH(hw);
  2367. udelay(10);
  2368. }
  2369. /******************************************************************************
  2370. * Lowers the Management Data Clock
  2371. *
  2372. * hw - Struct containing variables accessed by shared code
  2373. * ctrl - Device control register's current value
  2374. ******************************************************************************/
  2375. static void
  2376. e1000_lower_mdi_clk(struct e1000_hw *hw,
  2377. uint32_t *ctrl)
  2378. {
  2379. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  2380. * bit), and then delay 10 microseconds.
  2381. */
  2382. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  2383. E1000_WRITE_FLUSH(hw);
  2384. udelay(10);
  2385. }
  2386. /******************************************************************************
  2387. * Shifts data bits out to the PHY
  2388. *
  2389. * hw - Struct containing variables accessed by shared code
  2390. * data - Data to send out to the PHY
  2391. * count - Number of bits to shift out
  2392. *
  2393. * Bits are shifted out in MSB to LSB order.
  2394. ******************************************************************************/
  2395. static void
  2396. e1000_shift_out_mdi_bits(struct e1000_hw *hw,
  2397. uint32_t data,
  2398. uint16_t count)
  2399. {
  2400. uint32_t ctrl;
  2401. uint32_t mask;
  2402. /* We need to shift "count" number of bits out to the PHY. So, the value
  2403. * in the "data" parameter will be shifted out to the PHY one bit at a
  2404. * time. In order to do this, "data" must be broken down into bits.
  2405. */
  2406. mask = 0x01;
  2407. mask <<= (count - 1);
  2408. ctrl = E1000_READ_REG(hw, CTRL);
  2409. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  2410. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  2411. while(mask) {
  2412. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  2413. * then raising and lowering the Management Data Clock. A "0" is
  2414. * shifted out to the PHY by setting the MDIO bit to "0" and then
  2415. * raising and lowering the clock.
  2416. */
  2417. if(data & mask) ctrl |= E1000_CTRL_MDIO;
  2418. else ctrl &= ~E1000_CTRL_MDIO;
  2419. E1000_WRITE_REG(hw, CTRL, ctrl);
  2420. E1000_WRITE_FLUSH(hw);
  2421. udelay(10);
  2422. e1000_raise_mdi_clk(hw, &ctrl);
  2423. e1000_lower_mdi_clk(hw, &ctrl);
  2424. mask = mask >> 1;
  2425. }
  2426. }
  2427. /******************************************************************************
  2428. * Shifts data bits in from the PHY
  2429. *
  2430. * hw - Struct containing variables accessed by shared code
  2431. *
  2432. * Bits are shifted in in MSB to LSB order.
  2433. ******************************************************************************/
  2434. static uint16_t
  2435. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  2436. {
  2437. uint32_t ctrl;
  2438. uint16_t data = 0;
  2439. uint8_t i;
  2440. /* In order to read a register from the PHY, we need to shift in a total
  2441. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  2442. * to avoid contention on the MDIO pin when a read operation is performed.
  2443. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  2444. * by raising the input to the Management Data Clock (setting the MDC bit),
  2445. * and then reading the value of the MDIO bit.
  2446. */
  2447. ctrl = E1000_READ_REG(hw, CTRL);
  2448. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  2449. ctrl &= ~E1000_CTRL_MDIO_DIR;
  2450. ctrl &= ~E1000_CTRL_MDIO;
  2451. E1000_WRITE_REG(hw, CTRL, ctrl);
  2452. E1000_WRITE_FLUSH(hw);
  2453. /* Raise and Lower the clock before reading in the data. This accounts for
  2454. * the turnaround bits. The first clock occurred when we clocked out the
  2455. * last bit of the Register Address.
  2456. */
  2457. e1000_raise_mdi_clk(hw, &ctrl);
  2458. e1000_lower_mdi_clk(hw, &ctrl);
  2459. for(data = 0, i = 0; i < 16; i++) {
  2460. data = data << 1;
  2461. e1000_raise_mdi_clk(hw, &ctrl);
  2462. ctrl = E1000_READ_REG(hw, CTRL);
  2463. /* Check to see if we shifted in a "1". */
  2464. if(ctrl & E1000_CTRL_MDIO) data |= 1;
  2465. e1000_lower_mdi_clk(hw, &ctrl);
  2466. }
  2467. e1000_raise_mdi_clk(hw, &ctrl);
  2468. e1000_lower_mdi_clk(hw, &ctrl);
  2469. return data;
  2470. }
  2471. /*****************************************************************************
  2472. * Reads the value from a PHY register, if the value is on a specific non zero
  2473. * page, sets the page first.
  2474. *
  2475. * hw - Struct containing variables accessed by shared code
  2476. * reg_addr - address of the PHY register to read
  2477. ******************************************************************************/
  2478. static int
  2479. e1000_read_phy_reg(struct e1000_hw *hw,
  2480. uint32_t reg_addr,
  2481. uint16_t *phy_data)
  2482. {
  2483. uint32_t ret_val;
  2484. DEBUGFUNC("e1000_read_phy_reg");
  2485. if(hw->phy_type == e1000_phy_igp &&
  2486. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2487. if((ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2488. (uint16_t)reg_addr)))
  2489. return ret_val;
  2490. }
  2491. ret_val = e1000_read_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
  2492. phy_data);
  2493. return ret_val;
  2494. }
  2495. static int
  2496. e1000_read_phy_reg_ex(struct e1000_hw *hw,
  2497. uint32_t reg_addr,
  2498. uint16_t *phy_data)
  2499. {
  2500. uint32_t i;
  2501. uint32_t mdic = 0;
  2502. const uint32_t phy_addr = 1;
  2503. DEBUGFUNC("e1000_read_phy_reg_ex");
  2504. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2505. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2506. return -E1000_ERR_PARAM;
  2507. }
  2508. if(hw->mac_type > e1000_82543) {
  2509. /* Set up Op-code, Phy Address, and register address in the MDI
  2510. * Control register. The MAC will take care of interfacing with the
  2511. * PHY to retrieve the desired data.
  2512. */
  2513. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  2514. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2515. (E1000_MDIC_OP_READ));
  2516. E1000_WRITE_REG(hw, MDIC, mdic);
  2517. /* Poll the ready bit to see if the MDI read completed */
  2518. for(i = 0; i < 64; i++) {
  2519. udelay(50);
  2520. mdic = E1000_READ_REG(hw, MDIC);
  2521. if(mdic & E1000_MDIC_READY) break;
  2522. }
  2523. if(!(mdic & E1000_MDIC_READY)) {
  2524. DEBUGOUT("MDI Read did not complete\n");
  2525. return -E1000_ERR_PHY;
  2526. }
  2527. if(mdic & E1000_MDIC_ERROR) {
  2528. DEBUGOUT("MDI Error\n");
  2529. return -E1000_ERR_PHY;
  2530. }
  2531. *phy_data = (uint16_t) mdic;
  2532. } else {
  2533. /* We must first send a preamble through the MDIO pin to signal the
  2534. * beginning of an MII instruction. This is done by sending 32
  2535. * consecutive "1" bits.
  2536. */
  2537. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2538. /* Now combine the next few fields that are required for a read
  2539. * operation. We use this method instead of calling the
  2540. * e1000_shift_out_mdi_bits routine five different times. The format of
  2541. * a MII read instruction consists of a shift out of 14 bits and is
  2542. * defined as follows:
  2543. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  2544. * followed by a shift in of 18 bits. This first two bits shifted in
  2545. * are TurnAround bits used to avoid contention on the MDIO pin when a
  2546. * READ operation is performed. These two bits are thrown away
  2547. * followed by a shift in of 16 bits which contains the desired data.
  2548. */
  2549. mdic = ((reg_addr) | (phy_addr << 5) |
  2550. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  2551. e1000_shift_out_mdi_bits(hw, mdic, 14);
  2552. /* Now that we've shifted out the read command to the MII, we need to
  2553. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  2554. * register address.
  2555. */
  2556. *phy_data = e1000_shift_in_mdi_bits(hw);
  2557. }
  2558. return E1000_SUCCESS;
  2559. }
  2560. /******************************************************************************
  2561. * Writes a value to a PHY register
  2562. *
  2563. * hw - Struct containing variables accessed by shared code
  2564. * reg_addr - address of the PHY register to write
  2565. * data - data to write to the PHY
  2566. ******************************************************************************/
  2567. static int
  2568. e1000_write_phy_reg(struct e1000_hw *hw,
  2569. uint32_t reg_addr,
  2570. uint16_t phy_data)
  2571. {
  2572. uint32_t ret_val;
  2573. DEBUGFUNC("e1000_write_phy_reg");
  2574. if(hw->phy_type == e1000_phy_igp &&
  2575. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2576. if((ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2577. (uint16_t)reg_addr)))
  2578. return ret_val;
  2579. }
  2580. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
  2581. phy_data);
  2582. return ret_val;
  2583. }
  2584. static int
  2585. e1000_write_phy_reg_ex(struct e1000_hw *hw,
  2586. uint32_t reg_addr,
  2587. uint16_t phy_data)
  2588. {
  2589. uint32_t i;
  2590. uint32_t mdic = 0;
  2591. const uint32_t phy_addr = 1;
  2592. DEBUGFUNC("e1000_write_phy_reg_ex");
  2593. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2594. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2595. return -E1000_ERR_PARAM;
  2596. }
  2597. if(hw->mac_type > e1000_82543) {
  2598. /* Set up Op-code, Phy Address, register address, and data intended
  2599. * for the PHY register in the MDI Control register. The MAC will take
  2600. * care of interfacing with the PHY to send the desired data.
  2601. */
  2602. mdic = (((uint32_t) phy_data) |
  2603. (reg_addr << E1000_MDIC_REG_SHIFT) |
  2604. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2605. (E1000_MDIC_OP_WRITE));
  2606. E1000_WRITE_REG(hw, MDIC, mdic);
  2607. /* Poll the ready bit to see if the MDI read completed */
  2608. for(i = 0; i < 640; i++) {
  2609. udelay(5);
  2610. mdic = E1000_READ_REG(hw, MDIC);
  2611. if(mdic & E1000_MDIC_READY) break;
  2612. }
  2613. if(!(mdic & E1000_MDIC_READY)) {
  2614. DEBUGOUT("MDI Write did not complete\n");
  2615. return -E1000_ERR_PHY;
  2616. }
  2617. } else {
  2618. /* We'll need to use the SW defined pins to shift the write command
  2619. * out to the PHY. We first send a preamble to the PHY to signal the
  2620. * beginning of the MII instruction. This is done by sending 32
  2621. * consecutive "1" bits.
  2622. */
  2623. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2624. /* Now combine the remaining required fields that will indicate a
  2625. * write operation. We use this method instead of calling the
  2626. * e1000_shift_out_mdi_bits routine for each field in the command. The
  2627. * format of a MII write instruction is as follows:
  2628. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  2629. */
  2630. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  2631. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  2632. mdic <<= 16;
  2633. mdic |= (uint32_t) phy_data;
  2634. e1000_shift_out_mdi_bits(hw, mdic, 32);
  2635. }
  2636. return E1000_SUCCESS;
  2637. }
  2638. /******************************************************************************
  2639. * Returns the PHY to the power-on reset state
  2640. *
  2641. * hw - Struct containing variables accessed by shared code
  2642. ******************************************************************************/
  2643. static void
  2644. e1000_phy_hw_reset(struct e1000_hw *hw)
  2645. {
  2646. uint32_t ctrl, ctrl_ext;
  2647. DEBUGFUNC("e1000_phy_hw_reset");
  2648. DEBUGOUT("Resetting Phy...\n");
  2649. if(hw->mac_type > e1000_82543) {
  2650. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  2651. * bit. Then, take it out of reset.
  2652. */
  2653. ctrl = E1000_READ_REG(hw, CTRL);
  2654. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  2655. E1000_WRITE_FLUSH(hw);
  2656. mdelay(10);
  2657. E1000_WRITE_REG(hw, CTRL, ctrl);
  2658. E1000_WRITE_FLUSH(hw);
  2659. } else {
  2660. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  2661. * bit to put the PHY into reset. Then, take it out of reset.
  2662. */
  2663. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  2664. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  2665. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  2666. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2667. E1000_WRITE_FLUSH(hw);
  2668. mdelay(10);
  2669. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  2670. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2671. E1000_WRITE_FLUSH(hw);
  2672. }
  2673. udelay(150);
  2674. }
  2675. /******************************************************************************
  2676. * Resets the PHY
  2677. *
  2678. * hw - Struct containing variables accessed by shared code
  2679. *
  2680. * Sets bit 15 of the MII Control regiser
  2681. ******************************************************************************/
  2682. static int
  2683. e1000_phy_reset(struct e1000_hw *hw)
  2684. {
  2685. int32_t ret_val;
  2686. uint16_t phy_data;
  2687. DEBUGFUNC("e1000_phy_reset");
  2688. if(hw->mac_type != e1000_82541_rev_2) {
  2689. if((ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data)))
  2690. return ret_val;
  2691. phy_data |= MII_CR_RESET;
  2692. if((ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data)))
  2693. return ret_val;
  2694. udelay(1);
  2695. } else e1000_phy_hw_reset(hw);
  2696. if(hw->phy_type == e1000_phy_igp)
  2697. e1000_phy_init_script(hw);
  2698. return E1000_SUCCESS;
  2699. }
  2700. /******************************************************************************
  2701. * Probes the expected PHY address for known PHY IDs
  2702. *
  2703. * hw - Struct containing variables accessed by shared code
  2704. ******************************************************************************/
  2705. static int
  2706. e1000_detect_gig_phy(struct e1000_hw *hw)
  2707. {
  2708. int32_t phy_init_status, ret_val;
  2709. uint16_t phy_id_high, phy_id_low;
  2710. boolean_t match = FALSE;
  2711. DEBUGFUNC("e1000_detect_gig_phy");
  2712. /* Read the PHY ID Registers to identify which PHY is onboard. */
  2713. if((ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high)))
  2714. return ret_val;
  2715. hw->phy_id = (uint32_t) (phy_id_high << 16);
  2716. udelay(20);
  2717. if((ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low)))
  2718. return ret_val;
  2719. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  2720. #ifdef LINUX_DRIVER
  2721. hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
  2722. #endif
  2723. switch(hw->mac_type) {
  2724. case e1000_82543:
  2725. if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
  2726. break;
  2727. case e1000_82544:
  2728. if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
  2729. break;
  2730. case e1000_82540:
  2731. case e1000_82545:
  2732. case e1000_82545_rev_3:
  2733. case e1000_82546:
  2734. case e1000_82546_rev_3:
  2735. if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
  2736. break;
  2737. case e1000_82541:
  2738. case e1000_82541_rev_2:
  2739. case e1000_82547:
  2740. case e1000_82547_rev_2:
  2741. if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
  2742. break;
  2743. default:
  2744. DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
  2745. return -E1000_ERR_CONFIG;
  2746. }
  2747. phy_init_status = e1000_set_phy_type(hw);
  2748. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  2749. DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
  2750. return E1000_SUCCESS;
  2751. }
  2752. DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
  2753. return -E1000_ERR_PHY;
  2754. }
  2755. /******************************************************************************
  2756. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  2757. * is configured.
  2758. *
  2759. * hw - Struct containing variables accessed by shared code
  2760. *****************************************************************************/
  2761. static void
  2762. e1000_init_eeprom_params(struct e1000_hw *hw)
  2763. {
  2764. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  2765. uint32_t eecd = E1000_READ_REG(hw, EECD);
  2766. uint16_t eeprom_size;
  2767. DEBUGFUNC("e1000_init_eeprom_params");
  2768. switch (hw->mac_type) {
  2769. case e1000_82542_rev2_0:
  2770. case e1000_82542_rev2_1:
  2771. case e1000_82543:
  2772. case e1000_82544:
  2773. eeprom->type = e1000_eeprom_microwire;
  2774. eeprom->word_size = 64;
  2775. eeprom->opcode_bits = 3;
  2776. eeprom->address_bits = 6;
  2777. eeprom->delay_usec = 50;
  2778. break;
  2779. case e1000_82540:
  2780. case e1000_82545:
  2781. case e1000_82545_rev_3:
  2782. case e1000_82546:
  2783. case e1000_82546_rev_3:
  2784. eeprom->type = e1000_eeprom_microwire;
  2785. eeprom->opcode_bits = 3;
  2786. eeprom->delay_usec = 50;
  2787. if(eecd & E1000_EECD_SIZE) {
  2788. eeprom->word_size = 256;
  2789. eeprom->address_bits = 8;
  2790. } else {
  2791. eeprom->word_size = 64;
  2792. eeprom->address_bits = 6;
  2793. }
  2794. break;
  2795. case e1000_82541:
  2796. case e1000_82541_rev_2:
  2797. case e1000_82547:
  2798. case e1000_82547_rev_2:
  2799. if (eecd & E1000_EECD_TYPE) {
  2800. eeprom->type = e1000_eeprom_spi;
  2801. if (eecd & E1000_EECD_ADDR_BITS) {
  2802. eeprom->page_size = 32;
  2803. eeprom->address_bits = 16;
  2804. } else {
  2805. eeprom->page_size = 8;
  2806. eeprom->address_bits = 8;
  2807. }
  2808. } else {
  2809. eeprom->type = e1000_eeprom_microwire;
  2810. eeprom->opcode_bits = 3;
  2811. eeprom->delay_usec = 50;
  2812. if (eecd & E1000_EECD_ADDR_BITS) {
  2813. eeprom->word_size = 256;
  2814. eeprom->address_bits = 8;
  2815. } else {
  2816. eeprom->word_size = 64;
  2817. eeprom->address_bits = 6;
  2818. }
  2819. }
  2820. break;
  2821. default:
  2822. eeprom->type = e1000_eeprom_spi;
  2823. if (eecd & E1000_EECD_ADDR_BITS) {
  2824. eeprom->page_size = 32;
  2825. eeprom->address_bits = 16;
  2826. } else {
  2827. eeprom->page_size = 8;
  2828. eeprom->address_bits = 8;
  2829. }
  2830. break;
  2831. }
  2832. if (eeprom->type == e1000_eeprom_spi) {
  2833. eeprom->opcode_bits = 8;
  2834. eeprom->delay_usec = 1;
  2835. eeprom->word_size = 64;
  2836. if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
  2837. eeprom_size &= EEPROM_SIZE_MASK;
  2838. switch (eeprom_size) {
  2839. case EEPROM_SIZE_16KB:
  2840. eeprom->word_size = 8192;
  2841. break;
  2842. case EEPROM_SIZE_8KB:
  2843. eeprom->word_size = 4096;
  2844. break;
  2845. case EEPROM_SIZE_4KB:
  2846. eeprom->word_size = 2048;
  2847. break;
  2848. case EEPROM_SIZE_2KB:
  2849. eeprom->word_size = 1024;
  2850. break;
  2851. case EEPROM_SIZE_1KB:
  2852. eeprom->word_size = 512;
  2853. break;
  2854. case EEPROM_SIZE_512B:
  2855. eeprom->word_size = 256;
  2856. break;
  2857. case EEPROM_SIZE_128B:
  2858. default:
  2859. break;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. /**
  2865. * e1000_reset - Reset the adapter
  2866. */
  2867. static int
  2868. e1000_reset(struct e1000_hw *hw)
  2869. {
  2870. uint32_t pba;
  2871. /* Repartition Pba for greater than 9k mtu
  2872. * To take effect CTRL.RST is required.
  2873. */
  2874. if(hw->mac_type < e1000_82547) {
  2875. pba = E1000_PBA_48K;
  2876. } else {
  2877. pba = E1000_PBA_30K;
  2878. }
  2879. E1000_WRITE_REG(hw, PBA, pba);
  2880. /* flow control settings */
  2881. #if 0
  2882. hw->fc_high_water = FC_DEFAULT_HI_THRESH;
  2883. hw->fc_low_water = FC_DEFAULT_LO_THRESH;
  2884. hw->fc_pause_time = FC_DEFAULT_TX_TIMER;
  2885. hw->fc_send_xon = 1;
  2886. hw->fc = hw->original_fc;
  2887. #endif
  2888. e1000_reset_hw(hw);
  2889. if(hw->mac_type >= e1000_82544)
  2890. E1000_WRITE_REG(hw, WUC, 0);
  2891. return e1000_init_hw(hw);
  2892. }
  2893. /**
  2894. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  2895. * @adapter: board private structure to initialize
  2896. *
  2897. * e1000_sw_init initializes the Adapter private data structure.
  2898. * Fields are initialized based on PCI device information and
  2899. * OS network device settings (MTU size).
  2900. **/
  2901. static int
  2902. e1000_sw_init(struct pci_device *pdev, struct e1000_hw *hw)
  2903. {
  2904. int result;
  2905. /* PCI config space info */
  2906. pci_read_config_word(pdev, PCI_VENDOR_ID, &hw->vendor_id);
  2907. pci_read_config_word(pdev, PCI_DEVICE_ID, &hw->device_id);
  2908. pci_read_config_byte(pdev, PCI_REVISION, &hw->revision_id);
  2909. #if 0
  2910. pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID,
  2911. &hw->subsystem_vendor_id);
  2912. pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
  2913. #endif
  2914. pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
  2915. /* identify the MAC */
  2916. result = e1000_set_mac_type(hw);
  2917. if (result) {
  2918. E1000_ERR("Unknown MAC Type\n");
  2919. return result;
  2920. }
  2921. /* initialize eeprom parameters */
  2922. e1000_init_eeprom_params(hw);
  2923. #if 0
  2924. if((hw->mac_type == e1000_82541) ||
  2925. (hw->mac_type == e1000_82547) ||
  2926. (hw->mac_type == e1000_82541_rev_2) ||
  2927. (hw->mac_type == e1000_82547_rev_2))
  2928. hw->phy_init_script = 1;
  2929. #endif
  2930. e1000_set_media_type(hw);
  2931. #if 0
  2932. if(hw->mac_type < e1000_82543)
  2933. hw->report_tx_early = 0;
  2934. else
  2935. hw->report_tx_early = 1;
  2936. hw->wait_autoneg_complete = FALSE;
  2937. #endif
  2938. hw->tbi_compatibility_en = TRUE;
  2939. #if 0
  2940. hw->adaptive_ifs = TRUE;
  2941. /* Copper options */
  2942. if(hw->media_type == e1000_media_type_copper) {
  2943. hw->mdix = AUTO_ALL_MODES;
  2944. hw->disable_polarity_correction = FALSE;
  2945. hw->master_slave = E1000_MASTER_SLAVE;
  2946. }
  2947. #endif
  2948. return E1000_SUCCESS;
  2949. }
  2950. static void fill_rx (void)
  2951. {
  2952. struct e1000_rx_desc *rd;
  2953. rx_last = rx_tail;
  2954. rd = rx_base + rx_tail;
  2955. rx_tail = (rx_tail + 1) % 8;
  2956. memset (rd, 0, 16);
  2957. rd->buffer_addr = virt_to_bus(&packet);
  2958. E1000_WRITE_REG (&hw, RDT, rx_tail);
  2959. }
  2960. static void init_descriptor (void)
  2961. {
  2962. unsigned long ptr;
  2963. unsigned long tctl;
  2964. ptr = virt_to_phys(tx_pool);
  2965. if (ptr & 0xf)
  2966. ptr = (ptr + 0x10) & (~0xf);
  2967. tx_base = phys_to_virt(ptr);
  2968. E1000_WRITE_REG (&hw, TDBAL, virt_to_bus(tx_base));
  2969. E1000_WRITE_REG (&hw, TDBAH, 0);
  2970. E1000_WRITE_REG (&hw, TDLEN, 128);
  2971. /* Setup the HW Tx Head and Tail descriptor pointers */
  2972. E1000_WRITE_REG (&hw, TDH, 0);
  2973. E1000_WRITE_REG (&hw, TDT, 0);
  2974. tx_tail = 0;
  2975. /* Program the Transmit Control Register */
  2976. #ifdef LINUX_DRIVER_TCTL
  2977. tctl = E1000_READ_REG(&hw, TCTL);
  2978. tctl &= ~E1000_TCTL_CT;
  2979. tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
  2980. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  2981. #else
  2982. tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
  2983. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT) |
  2984. (E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
  2985. #endif
  2986. E1000_WRITE_REG (&hw, TCTL, tctl);
  2987. e1000_config_collision_dist(&hw);
  2988. rx_tail = 0;
  2989. /* disable receive */
  2990. E1000_WRITE_REG (&hw, RCTL, 0);
  2991. ptr = virt_to_phys(rx_pool);
  2992. if (ptr & 0xf)
  2993. ptr = (ptr + 0x10) & (~0xf);
  2994. rx_base = phys_to_virt(ptr);
  2995. /* Setup the Base and Length of the Rx Descriptor Ring */
  2996. E1000_WRITE_REG (&hw, RDBAL, virt_to_bus(rx_base));
  2997. E1000_WRITE_REG (&hw, RDBAH, 0);
  2998. E1000_WRITE_REG (&hw, RDLEN, 128);
  2999. /* Setup the HW Rx Head and Tail Descriptor Pointers */
  3000. E1000_WRITE_REG (&hw, RDH, 0);
  3001. E1000_WRITE_REG (&hw, RDT, 0);
  3002. E1000_WRITE_REG (&hw, RCTL,
  3003. E1000_RCTL_EN |
  3004. E1000_RCTL_BAM |
  3005. E1000_RCTL_SZ_2048 |
  3006. E1000_RCTL_MPE);
  3007. fill_rx();
  3008. }
  3009. /**************************************************************************
  3010. POLL - Wait for a frame
  3011. ***************************************************************************/
  3012. static int
  3013. e1000_poll (struct nic *nic, int retrieve)
  3014. {
  3015. /* return true if there's an ethernet packet ready to read */
  3016. /* nic->packet should contain data on return */
  3017. /* nic->packetlen should contain length of data */
  3018. struct e1000_rx_desc *rd;
  3019. uint32_t icr;
  3020. rd = rx_base + rx_last;
  3021. if (!rd->status & E1000_RXD_STAT_DD)
  3022. return 0;
  3023. if ( ! retrieve ) return 1;
  3024. // printf("recv: packet %! -> %! len=%d \n", packet+6, packet,rd->Length);
  3025. memcpy (nic->packet, packet, rd->length);
  3026. nic->packetlen = rd->length;
  3027. fill_rx ();
  3028. /* Acknowledge interrupt. */
  3029. icr = E1000_READ_REG(&hw, ICR);
  3030. return 1;
  3031. }
  3032. /**************************************************************************
  3033. TRANSMIT - Transmit a frame
  3034. ***************************************************************************/
  3035. static void
  3036. e1000_transmit (struct nic *nic, const char *d, /* Destination */
  3037. unsigned int type, /* Type */
  3038. unsigned int size, /* size */
  3039. const char *p) /* Packet */
  3040. {
  3041. /* send the packet to destination */
  3042. struct eth_hdr {
  3043. unsigned char dst_addr[ETH_ALEN];
  3044. unsigned char src_addr[ETH_ALEN];
  3045. unsigned short type;
  3046. } hdr;
  3047. struct e1000_tx_desc *txhd; /* header */
  3048. struct e1000_tx_desc *txp; /* payload */
  3049. DEBUGFUNC("send");
  3050. memcpy (&hdr.dst_addr, d, ETH_ALEN);
  3051. memcpy (&hdr.src_addr, nic->node_addr, ETH_ALEN);
  3052. hdr.type = htons (type);
  3053. txhd = tx_base + tx_tail;
  3054. tx_tail = (tx_tail + 1) % 8;
  3055. txp = tx_base + tx_tail;
  3056. tx_tail = (tx_tail + 1) % 8;
  3057. txhd->buffer_addr = virt_to_bus (&hdr);
  3058. txhd->lower.data = sizeof (hdr);
  3059. txhd->upper.data = 0;
  3060. txp->buffer_addr = virt_to_bus(p);
  3061. txp->lower.data = E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS | size;
  3062. txp->upper.data = 0;
  3063. E1000_WRITE_REG (&hw, TDT, tx_tail);
  3064. while (!(txp->upper.data & E1000_TXD_STAT_DD)) {
  3065. udelay(10); /* give the nic a chance to write to the register */
  3066. poll_interruptions();
  3067. }
  3068. DEBUGFUNC("send end");
  3069. }
  3070. /**************************************************************************
  3071. DISABLE - Turn off ethernet interface
  3072. ***************************************************************************/
  3073. static void e1000_disable ( struct nic *nic __unused ) {
  3074. /* Clear the transmit ring */
  3075. E1000_WRITE_REG (&hw, TDH, 0);
  3076. E1000_WRITE_REG (&hw, TDT, 0);
  3077. /* Clear the receive ring */
  3078. E1000_WRITE_REG (&hw, RDH, 0);
  3079. E1000_WRITE_REG (&hw, RDT, 0);
  3080. /* put the card in its initial state */
  3081. switch(hw.mac_type) {
  3082. case e1000_82544:
  3083. case e1000_82540:
  3084. case e1000_82545:
  3085. case e1000_82546:
  3086. case e1000_82541:
  3087. case e1000_82541_rev_2:
  3088. /* These controllers can't ack the 64-bit write when issuing the
  3089. * reset, so use IO-mapping as a workaround to issue the reset */
  3090. E1000_WRITE_REG_IO(&hw, CTRL, E1000_CTRL_RST);
  3091. break;
  3092. case e1000_82545_rev_3:
  3093. case e1000_82546_rev_3:
  3094. /* Reset is performed on a shadow of the control register */
  3095. E1000_WRITE_REG(&hw, CTRL_DUP, E1000_CTRL_RST);
  3096. break;
  3097. default:
  3098. E1000_WRITE_REG(&hw, CTRL, E1000_CTRL_RST);
  3099. break;
  3100. }
  3101. /* Turn off the ethernet interface */
  3102. E1000_WRITE_REG (&hw, RCTL, 0);
  3103. E1000_WRITE_REG (&hw, TCTL, 0);
  3104. mdelay (10);
  3105. /* Unmap my window to the device */
  3106. iounmap(hw.hw_addr);
  3107. }
  3108. /**************************************************************************
  3109. IRQ - Enable, Disable, or Force interrupts
  3110. ***************************************************************************/
  3111. static void e1000_irq(struct nic *nic __unused, irq_action_t action)
  3112. {
  3113. switch ( action ) {
  3114. case DISABLE :
  3115. E1000_WRITE_REG(&hw, IMC, ~0);
  3116. E1000_WRITE_FLUSH(&hw);
  3117. break;
  3118. case ENABLE :
  3119. E1000_WRITE_REG(&hw, IMS,
  3120. E1000_IMS_RXT0 | E1000_IMS_RXSEQ);
  3121. E1000_WRITE_FLUSH(&hw);
  3122. break;
  3123. case FORCE :
  3124. E1000_WRITE_REG(&hw, ICS, E1000_ICS_RXT0);
  3125. break;
  3126. }
  3127. }
  3128. #define IORESOURCE_IO 0x00000100 /* Resource type */
  3129. #define BAR_0 0
  3130. #define BAR_1 1
  3131. #define BAR_5 5
  3132. /**************************************************************************
  3133. PROBE - Look for an adapter, this routine's visible to the outside
  3134. You should omit the last argument struct pci_device * for a non-PCI NIC
  3135. ***************************************************************************/
  3136. static int e1000_probe ( struct dev *dev, struct pci_device *p ) {
  3137. struct nic *nic = nic_device ( dev );
  3138. unsigned long mmio_start, mmio_len;
  3139. int ret_val, i;
  3140. /* Initialize hw with default values */
  3141. memset(&hw, 0, sizeof(hw));
  3142. hw.pdev = p;
  3143. #if 1
  3144. /* Are these variables needed? */
  3145. hw.fc = e1000_fc_none;
  3146. #if 0
  3147. hw.original_fc = e1000_fc_none;
  3148. #endif
  3149. hw.autoneg_failed = 0;
  3150. #if 0
  3151. hw.get_link_status = TRUE;
  3152. #endif
  3153. #endif
  3154. mmio_start = pci_bar_start(p, PCI_BASE_ADDRESS_0);
  3155. mmio_len = pci_bar_size(p, PCI_BASE_ADDRESS_0);
  3156. hw.hw_addr = ioremap(mmio_start, mmio_len);
  3157. for(i = BAR_1; i <= BAR_5; i++) {
  3158. if(pci_bar_size(p, i) == 0)
  3159. continue;
  3160. if(pci_find_capability(p, i) & IORESOURCE_IO) {
  3161. hw.io_base = pci_bar_start(p, i);
  3162. break;
  3163. }
  3164. }
  3165. adjust_pci_device(p);
  3166. nic->ioaddr = p->ioaddr & ~3;
  3167. nic->irqno = p->irq;
  3168. /* From Matt Hortman <mbhortman@acpthinclient.com> */
  3169. /* MAC and Phy settings */
  3170. /* setup the private structure */
  3171. if (e1000_sw_init(p, &hw) < 0) {
  3172. iounmap(hw.hw_addr);
  3173. return 0;
  3174. }
  3175. /* make sure the EEPROM is good */
  3176. if (e1000_validate_eeprom_checksum(&hw) < 0) {
  3177. printf ("The EEPROM Checksum Is Not Valid\n");
  3178. iounmap(hw.hw_addr);
  3179. return 0;
  3180. }
  3181. /* copy the MAC address out of the EEPROM */
  3182. e1000_read_mac_addr(&hw);
  3183. memcpy (nic->node_addr, hw.mac_addr, ETH_ALEN);
  3184. printf("Ethernet addr: %!\n", nic->node_addr);
  3185. /* reset the hardware with the new settings */
  3186. ret_val = e1000_reset(&hw);
  3187. if (ret_val < 0) {
  3188. if ((ret_val == -E1000_ERR_NOLINK) ||
  3189. (ret_val == -E1000_ERR_TIMEOUT)) {
  3190. E1000_ERR("Valid Link not detected\n");
  3191. } else {
  3192. E1000_ERR("Hardware Initialization Failed\n");
  3193. }
  3194. iounmap(hw.hw_addr);
  3195. return 0;
  3196. }
  3197. init_descriptor();
  3198. /* point to NIC specific routines */
  3199. nic->nic_op = &e1000_operations;
  3200. return 1;
  3201. }
  3202. static struct nic_operations e1000_operations = {
  3203. .connect = dummy_connect,
  3204. .poll = e1000_poll,
  3205. .transmit = e1000_transmit,
  3206. .irq = e1000_irq,
  3207. .disable = e1000_disable,
  3208. };
  3209. static struct pci_id e1000_nics[] = {
  3210. PCI_ROM(0x8086, 0x1000, "e1000-82542", "Intel EtherExpressPro1000"),
  3211. PCI_ROM(0x8086, 0x1001, "e1000-82543gc-fiber", "Intel EtherExpressPro1000 82543GC Fiber"),
  3212. PCI_ROM(0x8086, 0x1004, "e1000-82543gc-copper", "Intel EtherExpressPro1000 82543GC Copper"),
  3213. PCI_ROM(0x8086, 0x1008, "e1000-82544ei-copper", "Intel EtherExpressPro1000 82544EI Copper"),
  3214. PCI_ROM(0x8086, 0x1009, "e1000-82544ei-fiber", "Intel EtherExpressPro1000 82544EI Fiber"),
  3215. PCI_ROM(0x8086, 0x100C, "e1000-82544gc-copper", "Intel EtherExpressPro1000 82544GC Copper"),
  3216. PCI_ROM(0x8086, 0x100D, "e1000-82544gc-lom", "Intel EtherExpressPro1000 82544GC LOM"),
  3217. PCI_ROM(0x8086, 0x100E, "e1000-82540em", "Intel EtherExpressPro1000 82540EM"),
  3218. PCI_ROM(0x8086, 0x100F, "e1000-82545em-copper", "Intel EtherExpressPro1000 82545EM Copper"),
  3219. PCI_ROM(0x8086, 0x1010, "e1000-82546eb-copper", "Intel EtherExpressPro1000 82546EB Copper"),
  3220. PCI_ROM(0x8086, 0x1011, "e1000-82545em-fiber", "Intel EtherExpressPro1000 82545EM Fiber"),
  3221. PCI_ROM(0x8086, 0x1012, "e1000-82546eb-fiber", "Intel EtherExpressPro1000 82546EB Copper"),
  3222. PCI_ROM(0x8086, 0x1013, "e1000-82541ei", "Intel EtherExpressPro1000 82541EI"),
  3223. PCI_ROM(0x8086, 0x1015, "e1000-82540em-lom", "Intel EtherExpressPro1000 82540EM LOM"),
  3224. PCI_ROM(0x8086, 0x1016, "e1000-82540ep-lom", "Intel EtherExpressPro1000 82540EP LOM"),
  3225. PCI_ROM(0x8086, 0x1017, "e1000-82540ep", "Intel EtherExpressPro1000 82540EP"),
  3226. PCI_ROM(0x8086, 0x1018, "e1000-82541ep", "Intel EtherExpressPro1000 82541EP"),
  3227. PCI_ROM(0x8086, 0x1019, "e1000-82547ei", "Intel EtherExpressPro1000 82547EI"),
  3228. PCI_ROM(0x8086, 0x101d, "e1000-82546eb-quad-copper", "Intel EtherExpressPro1000 82546EB Quad Copper"),
  3229. PCI_ROM(0x8086, 0x101e, "e1000-82540ep-lp", "Intel EtherExpressPro1000 82540EP LP"),
  3230. PCI_ROM(0x8086, 0x1026, "e1000-82545gm-copper", "Intel EtherExpressPro1000 82545GM Copper"),
  3231. PCI_ROM(0x8086, 0x1027, "e1000-82545gm-fiber", "Intel EtherExpressPro1000 82545GM Fiber"),
  3232. PCI_ROM(0x8086, 0x1028, "e1000-82545gm-serdes", "Intel EtherExpressPro1000 82545GM SERDES"),
  3233. PCI_ROM(0x8086, 0x1075, "e1000-82547gi", "Intel EtherExpressPro1000 82547GI"),
  3234. PCI_ROM(0x8086, 0x1076, "e1000-82541gi", "Intel EtherExpressPro1000 82541GI"),
  3235. PCI_ROM(0x8086, 0x1077, "e1000-82541gi-mobile", "Intel EtherExpressPro1000 82541GI Mobile"),
  3236. PCI_ROM(0x8086, 0x1078, "e1000-82541er", "Intel EtherExpressPro1000 82541ER"),
  3237. PCI_ROM(0x8086, 0x1079, "e1000-82546gb-copper", "Intel EtherExpressPro1000 82546GB Copper"),
  3238. PCI_ROM(0x8086, 0x107a, "e1000-82546gb-fiber", "Intel EtherExpressPro1000 82546GB Fiber"),
  3239. PCI_ROM(0x8086, 0x107b, "e1000-82546gb-serdes", "Intel EtherExpressPro1000 82546GB SERDES"),
  3240. };
  3241. static struct pci_driver e1000_driver =
  3242. PCI_DRIVER ( "E1000", e1000_nics, PCI_NO_CLASS );
  3243. BOOT_DRIVER ( "E1000", find_pci_boot_device, e1000_driver, e1000_probe );