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 114KB

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