ixgbe_common.c 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2012 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include <linux/netdevice.h>
  24. #include "ixgbe.h"
  25. #include "ixgbe_common.h"
  26. #include "ixgbe_phy.h"
  27. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
  28. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
  29. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
  30. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
  31. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
  32. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  33. u16 count);
  34. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
  35. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  36. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  37. static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
  38. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
  39. static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg);
  40. static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  41. u16 words, u16 *data);
  42. static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  43. u16 words, u16 *data);
  44. static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
  45. u16 offset);
  46. static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw);
  47. /**
  48. * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
  49. * control
  50. * @hw: pointer to hardware structure
  51. *
  52. * There are several phys that do not support autoneg flow control. This
  53. * function check the device id to see if the associated phy supports
  54. * autoneg flow control.
  55. **/
  56. static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
  57. {
  58. switch (hw->device_id) {
  59. case IXGBE_DEV_ID_X540T:
  60. case IXGBE_DEV_ID_X540T1:
  61. return 0;
  62. case IXGBE_DEV_ID_82599_T3_LOM:
  63. return 0;
  64. default:
  65. return IXGBE_ERR_FC_NOT_SUPPORTED;
  66. }
  67. }
  68. /**
  69. * ixgbe_setup_fc - Set up flow control
  70. * @hw: pointer to hardware structure
  71. *
  72. * Called at init time to set up flow control.
  73. **/
  74. static s32 ixgbe_setup_fc(struct ixgbe_hw *hw)
  75. {
  76. s32 ret_val = 0;
  77. u32 reg = 0, reg_bp = 0;
  78. u16 reg_cu = 0;
  79. bool got_lock = false;
  80. /*
  81. * Validate the requested mode. Strict IEEE mode does not allow
  82. * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
  83. */
  84. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  85. hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
  86. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  87. goto out;
  88. }
  89. /*
  90. * 10gig parts do not have a word in the EEPROM to determine the
  91. * default flow control setting, so we explicitly set it to full.
  92. */
  93. if (hw->fc.requested_mode == ixgbe_fc_default)
  94. hw->fc.requested_mode = ixgbe_fc_full;
  95. /*
  96. * Set up the 1G and 10G flow control advertisement registers so the
  97. * HW will be able to do fc autoneg once the cable is plugged in. If
  98. * we link at 10G, the 1G advertisement is harmless and vice versa.
  99. */
  100. switch (hw->phy.media_type) {
  101. case ixgbe_media_type_fiber:
  102. case ixgbe_media_type_backplane:
  103. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  104. reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  105. break;
  106. case ixgbe_media_type_copper:
  107. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  108. MDIO_MMD_AN, &reg_cu);
  109. break;
  110. default:
  111. break;
  112. }
  113. /*
  114. * The possible values of fc.requested_mode are:
  115. * 0: Flow control is completely disabled
  116. * 1: Rx flow control is enabled (we can receive pause frames,
  117. * but not send pause frames).
  118. * 2: Tx flow control is enabled (we can send pause frames but
  119. * we do not support receiving pause frames).
  120. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  121. * other: Invalid.
  122. */
  123. switch (hw->fc.requested_mode) {
  124. case ixgbe_fc_none:
  125. /* Flow control completely disabled by software override. */
  126. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  127. if (hw->phy.media_type == ixgbe_media_type_backplane)
  128. reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
  129. IXGBE_AUTOC_ASM_PAUSE);
  130. else if (hw->phy.media_type == ixgbe_media_type_copper)
  131. reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
  132. break;
  133. case ixgbe_fc_tx_pause:
  134. /*
  135. * Tx Flow control is enabled, and Rx Flow control is
  136. * disabled by software override.
  137. */
  138. reg |= IXGBE_PCS1GANA_ASM_PAUSE;
  139. reg &= ~IXGBE_PCS1GANA_SYM_PAUSE;
  140. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  141. reg_bp |= IXGBE_AUTOC_ASM_PAUSE;
  142. reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE;
  143. } else if (hw->phy.media_type == ixgbe_media_type_copper) {
  144. reg_cu |= IXGBE_TAF_ASM_PAUSE;
  145. reg_cu &= ~IXGBE_TAF_SYM_PAUSE;
  146. }
  147. break;
  148. case ixgbe_fc_rx_pause:
  149. /*
  150. * Rx Flow control is enabled and Tx Flow control is
  151. * disabled by software override. Since there really
  152. * isn't a way to advertise that we are capable of RX
  153. * Pause ONLY, we will advertise that we support both
  154. * symmetric and asymmetric Rx PAUSE, as such we fall
  155. * through to the fc_full statement. Later, we will
  156. * disable the adapter's ability to send PAUSE frames.
  157. */
  158. case ixgbe_fc_full:
  159. /* Flow control (both Rx and Tx) is enabled by SW override. */
  160. reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE;
  161. if (hw->phy.media_type == ixgbe_media_type_backplane)
  162. reg_bp |= IXGBE_AUTOC_SYM_PAUSE |
  163. IXGBE_AUTOC_ASM_PAUSE;
  164. else if (hw->phy.media_type == ixgbe_media_type_copper)
  165. reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE;
  166. break;
  167. default:
  168. hw_dbg(hw, "Flow control param set incorrectly\n");
  169. ret_val = IXGBE_ERR_CONFIG;
  170. goto out;
  171. break;
  172. }
  173. if (hw->mac.type != ixgbe_mac_X540) {
  174. /*
  175. * Enable auto-negotiation between the MAC & PHY;
  176. * the MAC will advertise clause 37 flow control.
  177. */
  178. IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
  179. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
  180. /* Disable AN timeout */
  181. if (hw->fc.strict_ieee)
  182. reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
  183. IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
  184. hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
  185. }
  186. /*
  187. * AUTOC restart handles negotiation of 1G and 10G on backplane
  188. * and copper. There is no need to set the PCS1GCTL register.
  189. *
  190. */
  191. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  192. /* Need the SW/FW semaphore around AUTOC writes if 82599 and
  193. * LESM is on, likewise reset_pipeline requries the lock as
  194. * it also writes AUTOC.
  195. */
  196. if ((hw->mac.type == ixgbe_mac_82599EB) &&
  197. ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  198. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  199. IXGBE_GSSR_MAC_CSR_SM);
  200. if (ret_val)
  201. goto out;
  202. got_lock = true;
  203. }
  204. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
  205. if (hw->mac.type == ixgbe_mac_82599EB)
  206. ixgbe_reset_pipeline_82599(hw);
  207. if (got_lock)
  208. hw->mac.ops.release_swfw_sync(hw,
  209. IXGBE_GSSR_MAC_CSR_SM);
  210. } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
  211. (ixgbe_device_supports_autoneg_fc(hw) == 0)) {
  212. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  213. MDIO_MMD_AN, reg_cu);
  214. }
  215. hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
  216. out:
  217. return ret_val;
  218. }
  219. /**
  220. * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
  221. * @hw: pointer to hardware structure
  222. *
  223. * Starts the hardware by filling the bus info structure and media type, clears
  224. * all on chip counters, initializes receive address registers, multicast
  225. * table, VLAN filter table, calls routine to set up link and flow control
  226. * settings, and leaves transmit and receive units disabled and uninitialized
  227. **/
  228. s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
  229. {
  230. u32 ctrl_ext;
  231. /* Set the media type */
  232. hw->phy.media_type = hw->mac.ops.get_media_type(hw);
  233. /* Identify the PHY */
  234. hw->phy.ops.identify(hw);
  235. /* Clear the VLAN filter table */
  236. hw->mac.ops.clear_vfta(hw);
  237. /* Clear statistics registers */
  238. hw->mac.ops.clear_hw_cntrs(hw);
  239. /* Set No Snoop Disable */
  240. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  241. ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
  242. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  243. IXGBE_WRITE_FLUSH(hw);
  244. /* Setup flow control */
  245. ixgbe_setup_fc(hw);
  246. /* Clear adapter stopped flag */
  247. hw->adapter_stopped = false;
  248. return 0;
  249. }
  250. /**
  251. * ixgbe_start_hw_gen2 - Init sequence for common device family
  252. * @hw: pointer to hw structure
  253. *
  254. * Performs the init sequence common to the second generation
  255. * of 10 GbE devices.
  256. * Devices in the second generation:
  257. * 82599
  258. * X540
  259. **/
  260. s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
  261. {
  262. u32 i;
  263. u32 regval;
  264. /* Clear the rate limiters */
  265. for (i = 0; i < hw->mac.max_tx_queues; i++) {
  266. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
  267. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
  268. }
  269. IXGBE_WRITE_FLUSH(hw);
  270. /* Disable relaxed ordering */
  271. for (i = 0; i < hw->mac.max_tx_queues; i++) {
  272. regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
  273. regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
  274. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
  275. }
  276. for (i = 0; i < hw->mac.max_rx_queues; i++) {
  277. regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  278. regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
  279. IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
  280. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
  281. }
  282. return 0;
  283. }
  284. /**
  285. * ixgbe_init_hw_generic - Generic hardware initialization
  286. * @hw: pointer to hardware structure
  287. *
  288. * Initialize the hardware by resetting the hardware, filling the bus info
  289. * structure and media type, clears all on chip counters, initializes receive
  290. * address registers, multicast table, VLAN filter table, calls routine to set
  291. * up link and flow control settings, and leaves transmit and receive units
  292. * disabled and uninitialized
  293. **/
  294. s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
  295. {
  296. s32 status;
  297. /* Reset the hardware */
  298. status = hw->mac.ops.reset_hw(hw);
  299. if (status == 0) {
  300. /* Start the HW */
  301. status = hw->mac.ops.start_hw(hw);
  302. }
  303. return status;
  304. }
  305. /**
  306. * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
  307. * @hw: pointer to hardware structure
  308. *
  309. * Clears all hardware statistics counters by reading them from the hardware
  310. * Statistics counters are clear on read.
  311. **/
  312. s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
  313. {
  314. u16 i = 0;
  315. IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  316. IXGBE_READ_REG(hw, IXGBE_ILLERRC);
  317. IXGBE_READ_REG(hw, IXGBE_ERRBC);
  318. IXGBE_READ_REG(hw, IXGBE_MSPDC);
  319. for (i = 0; i < 8; i++)
  320. IXGBE_READ_REG(hw, IXGBE_MPC(i));
  321. IXGBE_READ_REG(hw, IXGBE_MLFC);
  322. IXGBE_READ_REG(hw, IXGBE_MRFC);
  323. IXGBE_READ_REG(hw, IXGBE_RLEC);
  324. IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  325. IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  326. if (hw->mac.type >= ixgbe_mac_82599EB) {
  327. IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  328. IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  329. } else {
  330. IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  331. IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  332. }
  333. for (i = 0; i < 8; i++) {
  334. IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  335. IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  336. if (hw->mac.type >= ixgbe_mac_82599EB) {
  337. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  338. IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  339. } else {
  340. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  341. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  342. }
  343. }
  344. if (hw->mac.type >= ixgbe_mac_82599EB)
  345. for (i = 0; i < 8; i++)
  346. IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
  347. IXGBE_READ_REG(hw, IXGBE_PRC64);
  348. IXGBE_READ_REG(hw, IXGBE_PRC127);
  349. IXGBE_READ_REG(hw, IXGBE_PRC255);
  350. IXGBE_READ_REG(hw, IXGBE_PRC511);
  351. IXGBE_READ_REG(hw, IXGBE_PRC1023);
  352. IXGBE_READ_REG(hw, IXGBE_PRC1522);
  353. IXGBE_READ_REG(hw, IXGBE_GPRC);
  354. IXGBE_READ_REG(hw, IXGBE_BPRC);
  355. IXGBE_READ_REG(hw, IXGBE_MPRC);
  356. IXGBE_READ_REG(hw, IXGBE_GPTC);
  357. IXGBE_READ_REG(hw, IXGBE_GORCL);
  358. IXGBE_READ_REG(hw, IXGBE_GORCH);
  359. IXGBE_READ_REG(hw, IXGBE_GOTCL);
  360. IXGBE_READ_REG(hw, IXGBE_GOTCH);
  361. if (hw->mac.type == ixgbe_mac_82598EB)
  362. for (i = 0; i < 8; i++)
  363. IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  364. IXGBE_READ_REG(hw, IXGBE_RUC);
  365. IXGBE_READ_REG(hw, IXGBE_RFC);
  366. IXGBE_READ_REG(hw, IXGBE_ROC);
  367. IXGBE_READ_REG(hw, IXGBE_RJC);
  368. IXGBE_READ_REG(hw, IXGBE_MNGPRC);
  369. IXGBE_READ_REG(hw, IXGBE_MNGPDC);
  370. IXGBE_READ_REG(hw, IXGBE_MNGPTC);
  371. IXGBE_READ_REG(hw, IXGBE_TORL);
  372. IXGBE_READ_REG(hw, IXGBE_TORH);
  373. IXGBE_READ_REG(hw, IXGBE_TPR);
  374. IXGBE_READ_REG(hw, IXGBE_TPT);
  375. IXGBE_READ_REG(hw, IXGBE_PTC64);
  376. IXGBE_READ_REG(hw, IXGBE_PTC127);
  377. IXGBE_READ_REG(hw, IXGBE_PTC255);
  378. IXGBE_READ_REG(hw, IXGBE_PTC511);
  379. IXGBE_READ_REG(hw, IXGBE_PTC1023);
  380. IXGBE_READ_REG(hw, IXGBE_PTC1522);
  381. IXGBE_READ_REG(hw, IXGBE_MPTC);
  382. IXGBE_READ_REG(hw, IXGBE_BPTC);
  383. for (i = 0; i < 16; i++) {
  384. IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  385. IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  386. if (hw->mac.type >= ixgbe_mac_82599EB) {
  387. IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  388. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
  389. IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  390. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
  391. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  392. } else {
  393. IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  394. IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  395. }
  396. }
  397. if (hw->mac.type == ixgbe_mac_X540) {
  398. if (hw->phy.id == 0)
  399. hw->phy.ops.identify(hw);
  400. hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECL, MDIO_MMD_PCS, &i);
  401. hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECH, MDIO_MMD_PCS, &i);
  402. hw->phy.ops.read_reg(hw, IXGBE_LDPCECL, MDIO_MMD_PCS, &i);
  403. hw->phy.ops.read_reg(hw, IXGBE_LDPCECH, MDIO_MMD_PCS, &i);
  404. }
  405. return 0;
  406. }
  407. /**
  408. * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
  409. * @hw: pointer to hardware structure
  410. * @pba_num: stores the part number string from the EEPROM
  411. * @pba_num_size: part number string buffer length
  412. *
  413. * Reads the part number string from the EEPROM.
  414. **/
  415. s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
  416. u32 pba_num_size)
  417. {
  418. s32 ret_val;
  419. u16 data;
  420. u16 pba_ptr;
  421. u16 offset;
  422. u16 length;
  423. if (pba_num == NULL) {
  424. hw_dbg(hw, "PBA string buffer was null\n");
  425. return IXGBE_ERR_INVALID_ARGUMENT;
  426. }
  427. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
  428. if (ret_val) {
  429. hw_dbg(hw, "NVM Read Error\n");
  430. return ret_val;
  431. }
  432. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
  433. if (ret_val) {
  434. hw_dbg(hw, "NVM Read Error\n");
  435. return ret_val;
  436. }
  437. /*
  438. * if data is not ptr guard the PBA must be in legacy format which
  439. * means pba_ptr is actually our second data word for the PBA number
  440. * and we can decode it into an ascii string
  441. */
  442. if (data != IXGBE_PBANUM_PTR_GUARD) {
  443. hw_dbg(hw, "NVM PBA number is not stored as string\n");
  444. /* we will need 11 characters to store the PBA */
  445. if (pba_num_size < 11) {
  446. hw_dbg(hw, "PBA string buffer too small\n");
  447. return IXGBE_ERR_NO_SPACE;
  448. }
  449. /* extract hex string from data and pba_ptr */
  450. pba_num[0] = (data >> 12) & 0xF;
  451. pba_num[1] = (data >> 8) & 0xF;
  452. pba_num[2] = (data >> 4) & 0xF;
  453. pba_num[3] = data & 0xF;
  454. pba_num[4] = (pba_ptr >> 12) & 0xF;
  455. pba_num[5] = (pba_ptr >> 8) & 0xF;
  456. pba_num[6] = '-';
  457. pba_num[7] = 0;
  458. pba_num[8] = (pba_ptr >> 4) & 0xF;
  459. pba_num[9] = pba_ptr & 0xF;
  460. /* put a null character on the end of our string */
  461. pba_num[10] = '\0';
  462. /* switch all the data but the '-' to hex char */
  463. for (offset = 0; offset < 10; offset++) {
  464. if (pba_num[offset] < 0xA)
  465. pba_num[offset] += '0';
  466. else if (pba_num[offset] < 0x10)
  467. pba_num[offset] += 'A' - 0xA;
  468. }
  469. return 0;
  470. }
  471. ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
  472. if (ret_val) {
  473. hw_dbg(hw, "NVM Read Error\n");
  474. return ret_val;
  475. }
  476. if (length == 0xFFFF || length == 0) {
  477. hw_dbg(hw, "NVM PBA number section invalid length\n");
  478. return IXGBE_ERR_PBA_SECTION;
  479. }
  480. /* check if pba_num buffer is big enough */
  481. if (pba_num_size < (((u32)length * 2) - 1)) {
  482. hw_dbg(hw, "PBA string buffer too small\n");
  483. return IXGBE_ERR_NO_SPACE;
  484. }
  485. /* trim pba length from start of string */
  486. pba_ptr++;
  487. length--;
  488. for (offset = 0; offset < length; offset++) {
  489. ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
  490. if (ret_val) {
  491. hw_dbg(hw, "NVM Read Error\n");
  492. return ret_val;
  493. }
  494. pba_num[offset * 2] = (u8)(data >> 8);
  495. pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
  496. }
  497. pba_num[offset * 2] = '\0';
  498. return 0;
  499. }
  500. /**
  501. * ixgbe_get_mac_addr_generic - Generic get MAC address
  502. * @hw: pointer to hardware structure
  503. * @mac_addr: Adapter MAC address
  504. *
  505. * Reads the adapter's MAC address from first Receive Address Register (RAR0)
  506. * A reset of the adapter must be performed prior to calling this function
  507. * in order for the MAC address to have been loaded from the EEPROM into RAR0
  508. **/
  509. s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
  510. {
  511. u32 rar_high;
  512. u32 rar_low;
  513. u16 i;
  514. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
  515. rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
  516. for (i = 0; i < 4; i++)
  517. mac_addr[i] = (u8)(rar_low >> (i*8));
  518. for (i = 0; i < 2; i++)
  519. mac_addr[i+4] = (u8)(rar_high >> (i*8));
  520. return 0;
  521. }
  522. /**
  523. * ixgbe_get_bus_info_generic - Generic set PCI bus info
  524. * @hw: pointer to hardware structure
  525. *
  526. * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
  527. **/
  528. s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
  529. {
  530. struct ixgbe_adapter *adapter = hw->back;
  531. struct ixgbe_mac_info *mac = &hw->mac;
  532. u16 link_status;
  533. hw->bus.type = ixgbe_bus_type_pci_express;
  534. /* Get the negotiated link width and speed from PCI config space */
  535. pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
  536. &link_status);
  537. switch (link_status & IXGBE_PCI_LINK_WIDTH) {
  538. case IXGBE_PCI_LINK_WIDTH_1:
  539. hw->bus.width = ixgbe_bus_width_pcie_x1;
  540. break;
  541. case IXGBE_PCI_LINK_WIDTH_2:
  542. hw->bus.width = ixgbe_bus_width_pcie_x2;
  543. break;
  544. case IXGBE_PCI_LINK_WIDTH_4:
  545. hw->bus.width = ixgbe_bus_width_pcie_x4;
  546. break;
  547. case IXGBE_PCI_LINK_WIDTH_8:
  548. hw->bus.width = ixgbe_bus_width_pcie_x8;
  549. break;
  550. default:
  551. hw->bus.width = ixgbe_bus_width_unknown;
  552. break;
  553. }
  554. switch (link_status & IXGBE_PCI_LINK_SPEED) {
  555. case IXGBE_PCI_LINK_SPEED_2500:
  556. hw->bus.speed = ixgbe_bus_speed_2500;
  557. break;
  558. case IXGBE_PCI_LINK_SPEED_5000:
  559. hw->bus.speed = ixgbe_bus_speed_5000;
  560. break;
  561. default:
  562. hw->bus.speed = ixgbe_bus_speed_unknown;
  563. break;
  564. }
  565. mac->ops.set_lan_id(hw);
  566. return 0;
  567. }
  568. /**
  569. * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
  570. * @hw: pointer to the HW structure
  571. *
  572. * Determines the LAN function id by reading memory-mapped registers
  573. * and swaps the port value if requested.
  574. **/
  575. void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
  576. {
  577. struct ixgbe_bus_info *bus = &hw->bus;
  578. u32 reg;
  579. reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
  580. bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
  581. bus->lan_id = bus->func;
  582. /* check for a port swap */
  583. reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
  584. if (reg & IXGBE_FACTPS_LFS)
  585. bus->func ^= 0x1;
  586. }
  587. /**
  588. * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
  589. * @hw: pointer to hardware structure
  590. *
  591. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  592. * disables transmit and receive units. The adapter_stopped flag is used by
  593. * the shared code and drivers to determine if the adapter is in a stopped
  594. * state and should not touch the hardware.
  595. **/
  596. s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
  597. {
  598. u32 reg_val;
  599. u16 i;
  600. /*
  601. * Set the adapter_stopped flag so other driver functions stop touching
  602. * the hardware
  603. */
  604. hw->adapter_stopped = true;
  605. /* Disable the receive unit */
  606. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, 0);
  607. /* Clear interrupt mask to stop interrupts from being generated */
  608. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  609. /* Clear any pending interrupts, flush previous writes */
  610. IXGBE_READ_REG(hw, IXGBE_EICR);
  611. /* Disable the transmit unit. Each queue must be disabled. */
  612. for (i = 0; i < hw->mac.max_tx_queues; i++)
  613. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
  614. /* Disable the receive unit by stopping each queue */
  615. for (i = 0; i < hw->mac.max_rx_queues; i++) {
  616. reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  617. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  618. reg_val |= IXGBE_RXDCTL_SWFLSH;
  619. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
  620. }
  621. /* flush all queues disables */
  622. IXGBE_WRITE_FLUSH(hw);
  623. usleep_range(1000, 2000);
  624. /*
  625. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  626. * access and verify no pending requests
  627. */
  628. return ixgbe_disable_pcie_master(hw);
  629. }
  630. /**
  631. * ixgbe_led_on_generic - Turns on the software controllable LEDs.
  632. * @hw: pointer to hardware structure
  633. * @index: led number to turn on
  634. **/
  635. s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
  636. {
  637. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  638. /* To turn on the LED, set mode to ON. */
  639. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  640. led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
  641. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  642. IXGBE_WRITE_FLUSH(hw);
  643. return 0;
  644. }
  645. /**
  646. * ixgbe_led_off_generic - Turns off the software controllable LEDs.
  647. * @hw: pointer to hardware structure
  648. * @index: led number to turn off
  649. **/
  650. s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
  651. {
  652. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  653. /* To turn off the LED, set mode to OFF. */
  654. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  655. led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
  656. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  657. IXGBE_WRITE_FLUSH(hw);
  658. return 0;
  659. }
  660. /**
  661. * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
  662. * @hw: pointer to hardware structure
  663. *
  664. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  665. * ixgbe_hw struct in order to set up EEPROM access.
  666. **/
  667. s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
  668. {
  669. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  670. u32 eec;
  671. u16 eeprom_size;
  672. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  673. eeprom->type = ixgbe_eeprom_none;
  674. /* Set default semaphore delay to 10ms which is a well
  675. * tested value */
  676. eeprom->semaphore_delay = 10;
  677. /* Clear EEPROM page size, it will be initialized as needed */
  678. eeprom->word_page_size = 0;
  679. /*
  680. * Check for EEPROM present first.
  681. * If not present leave as none
  682. */
  683. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  684. if (eec & IXGBE_EEC_PRES) {
  685. eeprom->type = ixgbe_eeprom_spi;
  686. /*
  687. * SPI EEPROM is assumed here. This code would need to
  688. * change if a future EEPROM is not SPI.
  689. */
  690. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  691. IXGBE_EEC_SIZE_SHIFT);
  692. eeprom->word_size = 1 << (eeprom_size +
  693. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  694. }
  695. if (eec & IXGBE_EEC_ADDR_SIZE)
  696. eeprom->address_bits = 16;
  697. else
  698. eeprom->address_bits = 8;
  699. hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
  700. "%d\n", eeprom->type, eeprom->word_size,
  701. eeprom->address_bits);
  702. }
  703. return 0;
  704. }
  705. /**
  706. * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
  707. * @hw: pointer to hardware structure
  708. * @offset: offset within the EEPROM to write
  709. * @words: number of words
  710. * @data: 16 bit word(s) to write to EEPROM
  711. *
  712. * Reads 16 bit word(s) from EEPROM through bit-bang method
  713. **/
  714. s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  715. u16 words, u16 *data)
  716. {
  717. s32 status = 0;
  718. u16 i, count;
  719. hw->eeprom.ops.init_params(hw);
  720. if (words == 0) {
  721. status = IXGBE_ERR_INVALID_ARGUMENT;
  722. goto out;
  723. }
  724. if (offset + words > hw->eeprom.word_size) {
  725. status = IXGBE_ERR_EEPROM;
  726. goto out;
  727. }
  728. /*
  729. * The EEPROM page size cannot be queried from the chip. We do lazy
  730. * initialization. It is worth to do that when we write large buffer.
  731. */
  732. if ((hw->eeprom.word_page_size == 0) &&
  733. (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
  734. ixgbe_detect_eeprom_page_size_generic(hw, offset);
  735. /*
  736. * We cannot hold synchronization semaphores for too long
  737. * to avoid other entity starvation. However it is more efficient
  738. * to read in bursts than synchronizing access for each word.
  739. */
  740. for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
  741. count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
  742. IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
  743. status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
  744. count, &data[i]);
  745. if (status != 0)
  746. break;
  747. }
  748. out:
  749. return status;
  750. }
  751. /**
  752. * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
  753. * @hw: pointer to hardware structure
  754. * @offset: offset within the EEPROM to be written to
  755. * @words: number of word(s)
  756. * @data: 16 bit word(s) to be written to the EEPROM
  757. *
  758. * If ixgbe_eeprom_update_checksum is not called after this function, the
  759. * EEPROM will most likely contain an invalid checksum.
  760. **/
  761. static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  762. u16 words, u16 *data)
  763. {
  764. s32 status;
  765. u16 word;
  766. u16 page_size;
  767. u16 i;
  768. u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
  769. /* Prepare the EEPROM for writing */
  770. status = ixgbe_acquire_eeprom(hw);
  771. if (status == 0) {
  772. if (ixgbe_ready_eeprom(hw) != 0) {
  773. ixgbe_release_eeprom(hw);
  774. status = IXGBE_ERR_EEPROM;
  775. }
  776. }
  777. if (status == 0) {
  778. for (i = 0; i < words; i++) {
  779. ixgbe_standby_eeprom(hw);
  780. /* Send the WRITE ENABLE command (8 bit opcode ) */
  781. ixgbe_shift_out_eeprom_bits(hw,
  782. IXGBE_EEPROM_WREN_OPCODE_SPI,
  783. IXGBE_EEPROM_OPCODE_BITS);
  784. ixgbe_standby_eeprom(hw);
  785. /*
  786. * Some SPI eeproms use the 8th address bit embedded
  787. * in the opcode
  788. */
  789. if ((hw->eeprom.address_bits == 8) &&
  790. ((offset + i) >= 128))
  791. write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  792. /* Send the Write command (8-bit opcode + addr) */
  793. ixgbe_shift_out_eeprom_bits(hw, write_opcode,
  794. IXGBE_EEPROM_OPCODE_BITS);
  795. ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
  796. hw->eeprom.address_bits);
  797. page_size = hw->eeprom.word_page_size;
  798. /* Send the data in burst via SPI*/
  799. do {
  800. word = data[i];
  801. word = (word >> 8) | (word << 8);
  802. ixgbe_shift_out_eeprom_bits(hw, word, 16);
  803. if (page_size == 0)
  804. break;
  805. /* do not wrap around page */
  806. if (((offset + i) & (page_size - 1)) ==
  807. (page_size - 1))
  808. break;
  809. } while (++i < words);
  810. ixgbe_standby_eeprom(hw);
  811. usleep_range(10000, 20000);
  812. }
  813. /* Done with writing - release the EEPROM */
  814. ixgbe_release_eeprom(hw);
  815. }
  816. return status;
  817. }
  818. /**
  819. * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
  820. * @hw: pointer to hardware structure
  821. * @offset: offset within the EEPROM to be written to
  822. * @data: 16 bit word to be written to the EEPROM
  823. *
  824. * If ixgbe_eeprom_update_checksum is not called after this function, the
  825. * EEPROM will most likely contain an invalid checksum.
  826. **/
  827. s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
  828. {
  829. s32 status;
  830. hw->eeprom.ops.init_params(hw);
  831. if (offset >= hw->eeprom.word_size) {
  832. status = IXGBE_ERR_EEPROM;
  833. goto out;
  834. }
  835. status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
  836. out:
  837. return status;
  838. }
  839. /**
  840. * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
  841. * @hw: pointer to hardware structure
  842. * @offset: offset within the EEPROM to be read
  843. * @words: number of word(s)
  844. * @data: read 16 bit words(s) from EEPROM
  845. *
  846. * Reads 16 bit word(s) from EEPROM through bit-bang method
  847. **/
  848. s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  849. u16 words, u16 *data)
  850. {
  851. s32 status = 0;
  852. u16 i, count;
  853. hw->eeprom.ops.init_params(hw);
  854. if (words == 0) {
  855. status = IXGBE_ERR_INVALID_ARGUMENT;
  856. goto out;
  857. }
  858. if (offset + words > hw->eeprom.word_size) {
  859. status = IXGBE_ERR_EEPROM;
  860. goto out;
  861. }
  862. /*
  863. * We cannot hold synchronization semaphores for too long
  864. * to avoid other entity starvation. However it is more efficient
  865. * to read in bursts than synchronizing access for each word.
  866. */
  867. for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
  868. count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
  869. IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
  870. status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
  871. count, &data[i]);
  872. if (status != 0)
  873. break;
  874. }
  875. out:
  876. return status;
  877. }
  878. /**
  879. * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
  880. * @hw: pointer to hardware structure
  881. * @offset: offset within the EEPROM to be read
  882. * @words: number of word(s)
  883. * @data: read 16 bit word(s) from EEPROM
  884. *
  885. * Reads 16 bit word(s) from EEPROM through bit-bang method
  886. **/
  887. static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  888. u16 words, u16 *data)
  889. {
  890. s32 status;
  891. u16 word_in;
  892. u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
  893. u16 i;
  894. /* Prepare the EEPROM for reading */
  895. status = ixgbe_acquire_eeprom(hw);
  896. if (status == 0) {
  897. if (ixgbe_ready_eeprom(hw) != 0) {
  898. ixgbe_release_eeprom(hw);
  899. status = IXGBE_ERR_EEPROM;
  900. }
  901. }
  902. if (status == 0) {
  903. for (i = 0; i < words; i++) {
  904. ixgbe_standby_eeprom(hw);
  905. /*
  906. * Some SPI eeproms use the 8th address bit embedded
  907. * in the opcode
  908. */
  909. if ((hw->eeprom.address_bits == 8) &&
  910. ((offset + i) >= 128))
  911. read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  912. /* Send the READ command (opcode + addr) */
  913. ixgbe_shift_out_eeprom_bits(hw, read_opcode,
  914. IXGBE_EEPROM_OPCODE_BITS);
  915. ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
  916. hw->eeprom.address_bits);
  917. /* Read the data. */
  918. word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
  919. data[i] = (word_in >> 8) | (word_in << 8);
  920. }
  921. /* End this read operation */
  922. ixgbe_release_eeprom(hw);
  923. }
  924. return status;
  925. }
  926. /**
  927. * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
  928. * @hw: pointer to hardware structure
  929. * @offset: offset within the EEPROM to be read
  930. * @data: read 16 bit value from EEPROM
  931. *
  932. * Reads 16 bit value from EEPROM through bit-bang method
  933. **/
  934. s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  935. u16 *data)
  936. {
  937. s32 status;
  938. hw->eeprom.ops.init_params(hw);
  939. if (offset >= hw->eeprom.word_size) {
  940. status = IXGBE_ERR_EEPROM;
  941. goto out;
  942. }
  943. status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
  944. out:
  945. return status;
  946. }
  947. /**
  948. * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
  949. * @hw: pointer to hardware structure
  950. * @offset: offset of word in the EEPROM to read
  951. * @words: number of word(s)
  952. * @data: 16 bit word(s) from the EEPROM
  953. *
  954. * Reads a 16 bit word(s) from the EEPROM using the EERD register.
  955. **/
  956. s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
  957. u16 words, u16 *data)
  958. {
  959. u32 eerd;
  960. s32 status = 0;
  961. u32 i;
  962. hw->eeprom.ops.init_params(hw);
  963. if (words == 0) {
  964. status = IXGBE_ERR_INVALID_ARGUMENT;
  965. goto out;
  966. }
  967. if (offset >= hw->eeprom.word_size) {
  968. status = IXGBE_ERR_EEPROM;
  969. goto out;
  970. }
  971. for (i = 0; i < words; i++) {
  972. eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) +
  973. IXGBE_EEPROM_RW_REG_START;
  974. IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
  975. status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
  976. if (status == 0) {
  977. data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
  978. IXGBE_EEPROM_RW_REG_DATA);
  979. } else {
  980. hw_dbg(hw, "Eeprom read timed out\n");
  981. goto out;
  982. }
  983. }
  984. out:
  985. return status;
  986. }
  987. /**
  988. * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
  989. * @hw: pointer to hardware structure
  990. * @offset: offset within the EEPROM to be used as a scratch pad
  991. *
  992. * Discover EEPROM page size by writing marching data at given offset.
  993. * This function is called only when we are writing a new large buffer
  994. * at given offset so the data would be overwritten anyway.
  995. **/
  996. static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
  997. u16 offset)
  998. {
  999. u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
  1000. s32 status = 0;
  1001. u16 i;
  1002. for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
  1003. data[i] = i;
  1004. hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
  1005. status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
  1006. IXGBE_EEPROM_PAGE_SIZE_MAX, data);
  1007. hw->eeprom.word_page_size = 0;
  1008. if (status != 0)
  1009. goto out;
  1010. status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
  1011. if (status != 0)
  1012. goto out;
  1013. /*
  1014. * When writing in burst more than the actual page size
  1015. * EEPROM address wraps around current page.
  1016. */
  1017. hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
  1018. hw_dbg(hw, "Detected EEPROM page size = %d words.",
  1019. hw->eeprom.word_page_size);
  1020. out:
  1021. return status;
  1022. }
  1023. /**
  1024. * ixgbe_read_eerd_generic - Read EEPROM word using EERD
  1025. * @hw: pointer to hardware structure
  1026. * @offset: offset of word in the EEPROM to read
  1027. * @data: word read from the EEPROM
  1028. *
  1029. * Reads a 16 bit word from the EEPROM using the EERD register.
  1030. **/
  1031. s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
  1032. {
  1033. return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
  1034. }
  1035. /**
  1036. * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
  1037. * @hw: pointer to hardware structure
  1038. * @offset: offset of word in the EEPROM to write
  1039. * @words: number of words
  1040. * @data: word(s) write to the EEPROM
  1041. *
  1042. * Write a 16 bit word(s) to the EEPROM using the EEWR register.
  1043. **/
  1044. s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
  1045. u16 words, u16 *data)
  1046. {
  1047. u32 eewr;
  1048. s32 status = 0;
  1049. u16 i;
  1050. hw->eeprom.ops.init_params(hw);
  1051. if (words == 0) {
  1052. status = IXGBE_ERR_INVALID_ARGUMENT;
  1053. goto out;
  1054. }
  1055. if (offset >= hw->eeprom.word_size) {
  1056. status = IXGBE_ERR_EEPROM;
  1057. goto out;
  1058. }
  1059. for (i = 0; i < words; i++) {
  1060. eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
  1061. (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
  1062. IXGBE_EEPROM_RW_REG_START;
  1063. status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
  1064. if (status != 0) {
  1065. hw_dbg(hw, "Eeprom write EEWR timed out\n");
  1066. goto out;
  1067. }
  1068. IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
  1069. status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
  1070. if (status != 0) {
  1071. hw_dbg(hw, "Eeprom write EEWR timed out\n");
  1072. goto out;
  1073. }
  1074. }
  1075. out:
  1076. return status;
  1077. }
  1078. /**
  1079. * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
  1080. * @hw: pointer to hardware structure
  1081. * @offset: offset of word in the EEPROM to write
  1082. * @data: word write to the EEPROM
  1083. *
  1084. * Write a 16 bit word to the EEPROM using the EEWR register.
  1085. **/
  1086. s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
  1087. {
  1088. return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
  1089. }
  1090. /**
  1091. * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
  1092. * @hw: pointer to hardware structure
  1093. * @ee_reg: EEPROM flag for polling
  1094. *
  1095. * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
  1096. * read or write is done respectively.
  1097. **/
  1098. static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
  1099. {
  1100. u32 i;
  1101. u32 reg;
  1102. s32 status = IXGBE_ERR_EEPROM;
  1103. for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
  1104. if (ee_reg == IXGBE_NVM_POLL_READ)
  1105. reg = IXGBE_READ_REG(hw, IXGBE_EERD);
  1106. else
  1107. reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
  1108. if (reg & IXGBE_EEPROM_RW_REG_DONE) {
  1109. status = 0;
  1110. break;
  1111. }
  1112. udelay(5);
  1113. }
  1114. return status;
  1115. }
  1116. /**
  1117. * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
  1118. * @hw: pointer to hardware structure
  1119. *
  1120. * Prepares EEPROM for access using bit-bang method. This function should
  1121. * be called before issuing a command to the EEPROM.
  1122. **/
  1123. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
  1124. {
  1125. s32 status = 0;
  1126. u32 eec;
  1127. u32 i;
  1128. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
  1129. status = IXGBE_ERR_SWFW_SYNC;
  1130. if (status == 0) {
  1131. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1132. /* Request EEPROM Access */
  1133. eec |= IXGBE_EEC_REQ;
  1134. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1135. for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
  1136. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1137. if (eec & IXGBE_EEC_GNT)
  1138. break;
  1139. udelay(5);
  1140. }
  1141. /* Release if grant not acquired */
  1142. if (!(eec & IXGBE_EEC_GNT)) {
  1143. eec &= ~IXGBE_EEC_REQ;
  1144. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1145. hw_dbg(hw, "Could not acquire EEPROM grant\n");
  1146. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  1147. status = IXGBE_ERR_EEPROM;
  1148. }
  1149. /* Setup EEPROM for Read/Write */
  1150. if (status == 0) {
  1151. /* Clear CS and SK */
  1152. eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
  1153. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1154. IXGBE_WRITE_FLUSH(hw);
  1155. udelay(1);
  1156. }
  1157. }
  1158. return status;
  1159. }
  1160. /**
  1161. * ixgbe_get_eeprom_semaphore - Get hardware semaphore
  1162. * @hw: pointer to hardware structure
  1163. *
  1164. * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
  1165. **/
  1166. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
  1167. {
  1168. s32 status = IXGBE_ERR_EEPROM;
  1169. u32 timeout = 2000;
  1170. u32 i;
  1171. u32 swsm;
  1172. /* Get SMBI software semaphore between device drivers first */
  1173. for (i = 0; i < timeout; i++) {
  1174. /*
  1175. * If the SMBI bit is 0 when we read it, then the bit will be
  1176. * set and we have the semaphore
  1177. */
  1178. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1179. if (!(swsm & IXGBE_SWSM_SMBI)) {
  1180. status = 0;
  1181. break;
  1182. }
  1183. udelay(50);
  1184. }
  1185. if (i == timeout) {
  1186. hw_dbg(hw, "Driver can't access the Eeprom - SMBI Semaphore "
  1187. "not granted.\n");
  1188. /*
  1189. * this release is particularly important because our attempts
  1190. * above to get the semaphore may have succeeded, and if there
  1191. * was a timeout, we should unconditionally clear the semaphore
  1192. * bits to free the driver to make progress
  1193. */
  1194. ixgbe_release_eeprom_semaphore(hw);
  1195. udelay(50);
  1196. /*
  1197. * one last try
  1198. * If the SMBI bit is 0 when we read it, then the bit will be
  1199. * set and we have the semaphore
  1200. */
  1201. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1202. if (!(swsm & IXGBE_SWSM_SMBI))
  1203. status = 0;
  1204. }
  1205. /* Now get the semaphore between SW/FW through the SWESMBI bit */
  1206. if (status == 0) {
  1207. for (i = 0; i < timeout; i++) {
  1208. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1209. /* Set the SW EEPROM semaphore bit to request access */
  1210. swsm |= IXGBE_SWSM_SWESMBI;
  1211. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  1212. /*
  1213. * If we set the bit successfully then we got the
  1214. * semaphore.
  1215. */
  1216. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1217. if (swsm & IXGBE_SWSM_SWESMBI)
  1218. break;
  1219. udelay(50);
  1220. }
  1221. /*
  1222. * Release semaphores and return error if SW EEPROM semaphore
  1223. * was not granted because we don't have access to the EEPROM
  1224. */
  1225. if (i >= timeout) {
  1226. hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
  1227. "not granted.\n");
  1228. ixgbe_release_eeprom_semaphore(hw);
  1229. status = IXGBE_ERR_EEPROM;
  1230. }
  1231. } else {
  1232. hw_dbg(hw, "Software semaphore SMBI between device drivers "
  1233. "not granted.\n");
  1234. }
  1235. return status;
  1236. }
  1237. /**
  1238. * ixgbe_release_eeprom_semaphore - Release hardware semaphore
  1239. * @hw: pointer to hardware structure
  1240. *
  1241. * This function clears hardware semaphore bits.
  1242. **/
  1243. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
  1244. {
  1245. u32 swsm;
  1246. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1247. /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
  1248. swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
  1249. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  1250. IXGBE_WRITE_FLUSH(hw);
  1251. }
  1252. /**
  1253. * ixgbe_ready_eeprom - Polls for EEPROM ready
  1254. * @hw: pointer to hardware structure
  1255. **/
  1256. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
  1257. {
  1258. s32 status = 0;
  1259. u16 i;
  1260. u8 spi_stat_reg;
  1261. /*
  1262. * Read "Status Register" repeatedly until the LSB is cleared. The
  1263. * EEPROM will signal that the command has been completed by clearing
  1264. * bit 0 of the internal status register. If it's not cleared within
  1265. * 5 milliseconds, then error out.
  1266. */
  1267. for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
  1268. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
  1269. IXGBE_EEPROM_OPCODE_BITS);
  1270. spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
  1271. if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
  1272. break;
  1273. udelay(5);
  1274. ixgbe_standby_eeprom(hw);
  1275. }
  1276. /*
  1277. * On some parts, SPI write time could vary from 0-20mSec on 3.3V
  1278. * devices (and only 0-5mSec on 5V devices)
  1279. */
  1280. if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
  1281. hw_dbg(hw, "SPI EEPROM Status error\n");
  1282. status = IXGBE_ERR_EEPROM;
  1283. }
  1284. return status;
  1285. }
  1286. /**
  1287. * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
  1288. * @hw: pointer to hardware structure
  1289. **/
  1290. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
  1291. {
  1292. u32 eec;
  1293. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1294. /* Toggle CS to flush commands */
  1295. eec |= IXGBE_EEC_CS;
  1296. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1297. IXGBE_WRITE_FLUSH(hw);
  1298. udelay(1);
  1299. eec &= ~IXGBE_EEC_CS;
  1300. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1301. IXGBE_WRITE_FLUSH(hw);
  1302. udelay(1);
  1303. }
  1304. /**
  1305. * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
  1306. * @hw: pointer to hardware structure
  1307. * @data: data to send to the EEPROM
  1308. * @count: number of bits to shift out
  1309. **/
  1310. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  1311. u16 count)
  1312. {
  1313. u32 eec;
  1314. u32 mask;
  1315. u32 i;
  1316. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1317. /*
  1318. * Mask is used to shift "count" bits of "data" out to the EEPROM
  1319. * one bit at a time. Determine the starting bit based on count
  1320. */
  1321. mask = 0x01 << (count - 1);
  1322. for (i = 0; i < count; i++) {
  1323. /*
  1324. * A "1" is shifted out to the EEPROM by setting bit "DI" to a
  1325. * "1", and then raising and then lowering the clock (the SK
  1326. * bit controls the clock input to the EEPROM). A "0" is
  1327. * shifted out to the EEPROM by setting "DI" to "0" and then
  1328. * raising and then lowering the clock.
  1329. */
  1330. if (data & mask)
  1331. eec |= IXGBE_EEC_DI;
  1332. else
  1333. eec &= ~IXGBE_EEC_DI;
  1334. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1335. IXGBE_WRITE_FLUSH(hw);
  1336. udelay(1);
  1337. ixgbe_raise_eeprom_clk(hw, &eec);
  1338. ixgbe_lower_eeprom_clk(hw, &eec);
  1339. /*
  1340. * Shift mask to signify next bit of data to shift in to the
  1341. * EEPROM
  1342. */
  1343. mask = mask >> 1;
  1344. }
  1345. /* We leave the "DI" bit set to "0" when we leave this routine. */
  1346. eec &= ~IXGBE_EEC_DI;
  1347. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1348. IXGBE_WRITE_FLUSH(hw);
  1349. }
  1350. /**
  1351. * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
  1352. * @hw: pointer to hardware structure
  1353. **/
  1354. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
  1355. {
  1356. u32 eec;
  1357. u32 i;
  1358. u16 data = 0;
  1359. /*
  1360. * In order to read a register from the EEPROM, we need to shift
  1361. * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
  1362. * the clock input to the EEPROM (setting the SK bit), and then reading
  1363. * the value of the "DO" bit. During this "shifting in" process the
  1364. * "DI" bit should always be clear.
  1365. */
  1366. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1367. eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
  1368. for (i = 0; i < count; i++) {
  1369. data = data << 1;
  1370. ixgbe_raise_eeprom_clk(hw, &eec);
  1371. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1372. eec &= ~(IXGBE_EEC_DI);
  1373. if (eec & IXGBE_EEC_DO)
  1374. data |= 1;
  1375. ixgbe_lower_eeprom_clk(hw, &eec);
  1376. }
  1377. return data;
  1378. }
  1379. /**
  1380. * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
  1381. * @hw: pointer to hardware structure
  1382. * @eec: EEC register's current value
  1383. **/
  1384. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  1385. {
  1386. /*
  1387. * Raise the clock input to the EEPROM
  1388. * (setting the SK bit), then delay
  1389. */
  1390. *eec = *eec | IXGBE_EEC_SK;
  1391. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  1392. IXGBE_WRITE_FLUSH(hw);
  1393. udelay(1);
  1394. }
  1395. /**
  1396. * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
  1397. * @hw: pointer to hardware structure
  1398. * @eecd: EECD's current value
  1399. **/
  1400. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  1401. {
  1402. /*
  1403. * Lower the clock input to the EEPROM (clearing the SK bit), then
  1404. * delay
  1405. */
  1406. *eec = *eec & ~IXGBE_EEC_SK;
  1407. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  1408. IXGBE_WRITE_FLUSH(hw);
  1409. udelay(1);
  1410. }
  1411. /**
  1412. * ixgbe_release_eeprom - Release EEPROM, release semaphores
  1413. * @hw: pointer to hardware structure
  1414. **/
  1415. static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
  1416. {
  1417. u32 eec;
  1418. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1419. eec |= IXGBE_EEC_CS; /* Pull CS high */
  1420. eec &= ~IXGBE_EEC_SK; /* Lower SCK */
  1421. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1422. IXGBE_WRITE_FLUSH(hw);
  1423. udelay(1);
  1424. /* Stop requesting EEPROM access */
  1425. eec &= ~IXGBE_EEC_REQ;
  1426. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1427. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  1428. /*
  1429. * Delay before attempt to obtain semaphore again to allow FW
  1430. * access. semaphore_delay is in ms we need us for usleep_range
  1431. */
  1432. usleep_range(hw->eeprom.semaphore_delay * 1000,
  1433. hw->eeprom.semaphore_delay * 2000);
  1434. }
  1435. /**
  1436. * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
  1437. * @hw: pointer to hardware structure
  1438. **/
  1439. u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
  1440. {
  1441. u16 i;
  1442. u16 j;
  1443. u16 checksum = 0;
  1444. u16 length = 0;
  1445. u16 pointer = 0;
  1446. u16 word = 0;
  1447. /* Include 0x0-0x3F in the checksum */
  1448. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  1449. if (hw->eeprom.ops.read(hw, i, &word) != 0) {
  1450. hw_dbg(hw, "EEPROM read failed\n");
  1451. break;
  1452. }
  1453. checksum += word;
  1454. }
  1455. /* Include all data from pointers except for the fw pointer */
  1456. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  1457. hw->eeprom.ops.read(hw, i, &pointer);
  1458. /* Make sure the pointer seems valid */
  1459. if (pointer != 0xFFFF && pointer != 0) {
  1460. hw->eeprom.ops.read(hw, pointer, &length);
  1461. if (length != 0xFFFF && length != 0) {
  1462. for (j = pointer+1; j <= pointer+length; j++) {
  1463. hw->eeprom.ops.read(hw, j, &word);
  1464. checksum += word;
  1465. }
  1466. }
  1467. }
  1468. }
  1469. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  1470. return checksum;
  1471. }
  1472. /**
  1473. * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
  1474. * @hw: pointer to hardware structure
  1475. * @checksum_val: calculated checksum
  1476. *
  1477. * Performs checksum calculation and validates the EEPROM checksum. If the
  1478. * caller does not need checksum_val, the value can be NULL.
  1479. **/
  1480. s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
  1481. u16 *checksum_val)
  1482. {
  1483. s32 status;
  1484. u16 checksum;
  1485. u16 read_checksum = 0;
  1486. /*
  1487. * Read the first word from the EEPROM. If this times out or fails, do
  1488. * not continue or we could be in for a very long wait while every
  1489. * EEPROM read fails
  1490. */
  1491. status = hw->eeprom.ops.read(hw, 0, &checksum);
  1492. if (status == 0) {
  1493. checksum = hw->eeprom.ops.calc_checksum(hw);
  1494. hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
  1495. /*
  1496. * Verify read checksum from EEPROM is the same as
  1497. * calculated checksum
  1498. */
  1499. if (read_checksum != checksum)
  1500. status = IXGBE_ERR_EEPROM_CHECKSUM;
  1501. /* If the user cares, return the calculated checksum */
  1502. if (checksum_val)
  1503. *checksum_val = checksum;
  1504. } else {
  1505. hw_dbg(hw, "EEPROM read failed\n");
  1506. }
  1507. return status;
  1508. }
  1509. /**
  1510. * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
  1511. * @hw: pointer to hardware structure
  1512. **/
  1513. s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
  1514. {
  1515. s32 status;
  1516. u16 checksum;
  1517. /*
  1518. * Read the first word from the EEPROM. If this times out or fails, do
  1519. * not continue or we could be in for a very long wait while every
  1520. * EEPROM read fails
  1521. */
  1522. status = hw->eeprom.ops.read(hw, 0, &checksum);
  1523. if (status == 0) {
  1524. checksum = hw->eeprom.ops.calc_checksum(hw);
  1525. status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
  1526. checksum);
  1527. } else {
  1528. hw_dbg(hw, "EEPROM read failed\n");
  1529. }
  1530. return status;
  1531. }
  1532. /**
  1533. * ixgbe_validate_mac_addr - Validate MAC address
  1534. * @mac_addr: pointer to MAC address.
  1535. *
  1536. * Tests a MAC address to ensure it is a valid Individual Address
  1537. **/
  1538. s32 ixgbe_validate_mac_addr(u8 *mac_addr)
  1539. {
  1540. s32 status = 0;
  1541. /* Make sure it is not a multicast address */
  1542. if (IXGBE_IS_MULTICAST(mac_addr))
  1543. status = IXGBE_ERR_INVALID_MAC_ADDR;
  1544. /* Not a broadcast address */
  1545. else if (IXGBE_IS_BROADCAST(mac_addr))
  1546. status = IXGBE_ERR_INVALID_MAC_ADDR;
  1547. /* Reject the zero address */
  1548. else if (is_zero_ether_addr(mac_addr))
  1549. status = IXGBE_ERR_INVALID_MAC_ADDR;
  1550. return status;
  1551. }
  1552. /**
  1553. * ixgbe_set_rar_generic - Set Rx address register
  1554. * @hw: pointer to hardware structure
  1555. * @index: Receive address register to write
  1556. * @addr: Address to put into receive address register
  1557. * @vmdq: VMDq "set" or "pool" index
  1558. * @enable_addr: set flag that address is active
  1559. *
  1560. * Puts an ethernet address into a receive address register.
  1561. **/
  1562. s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
  1563. u32 enable_addr)
  1564. {
  1565. u32 rar_low, rar_high;
  1566. u32 rar_entries = hw->mac.num_rar_entries;
  1567. /* Make sure we are using a valid rar index range */
  1568. if (index >= rar_entries) {
  1569. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1570. return IXGBE_ERR_INVALID_ARGUMENT;
  1571. }
  1572. /* setup VMDq pool selection before this RAR gets enabled */
  1573. hw->mac.ops.set_vmdq(hw, index, vmdq);
  1574. /*
  1575. * HW expects these in little endian so we reverse the byte
  1576. * order from network order (big endian) to little endian
  1577. */
  1578. rar_low = ((u32)addr[0] |
  1579. ((u32)addr[1] << 8) |
  1580. ((u32)addr[2] << 16) |
  1581. ((u32)addr[3] << 24));
  1582. /*
  1583. * Some parts put the VMDq setting in the extra RAH bits,
  1584. * so save everything except the lower 16 bits that hold part
  1585. * of the address and the address valid bit.
  1586. */
  1587. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1588. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1589. rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
  1590. if (enable_addr != 0)
  1591. rar_high |= IXGBE_RAH_AV;
  1592. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
  1593. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1594. return 0;
  1595. }
  1596. /**
  1597. * ixgbe_clear_rar_generic - Remove Rx address register
  1598. * @hw: pointer to hardware structure
  1599. * @index: Receive address register to write
  1600. *
  1601. * Clears an ethernet address from a receive address register.
  1602. **/
  1603. s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
  1604. {
  1605. u32 rar_high;
  1606. u32 rar_entries = hw->mac.num_rar_entries;
  1607. /* Make sure we are using a valid rar index range */
  1608. if (index >= rar_entries) {
  1609. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1610. return IXGBE_ERR_INVALID_ARGUMENT;
  1611. }
  1612. /*
  1613. * Some parts put the VMDq setting in the extra RAH bits,
  1614. * so save everything except the lower 16 bits that hold part
  1615. * of the address and the address valid bit.
  1616. */
  1617. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1618. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1619. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
  1620. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1621. /* clear VMDq pool/queue selection for this RAR */
  1622. hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
  1623. return 0;
  1624. }
  1625. /**
  1626. * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
  1627. * @hw: pointer to hardware structure
  1628. *
  1629. * Places the MAC address in receive address register 0 and clears the rest
  1630. * of the receive address registers. Clears the multicast table. Assumes
  1631. * the receiver is in reset when the routine is called.
  1632. **/
  1633. s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
  1634. {
  1635. u32 i;
  1636. u32 rar_entries = hw->mac.num_rar_entries;
  1637. /*
  1638. * If the current mac address is valid, assume it is a software override
  1639. * to the permanent address.
  1640. * Otherwise, use the permanent address from the eeprom.
  1641. */
  1642. if (ixgbe_validate_mac_addr(hw->mac.addr) ==
  1643. IXGBE_ERR_INVALID_MAC_ADDR) {
  1644. /* Get the MAC address from the RAR0 for later reference */
  1645. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  1646. hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
  1647. } else {
  1648. /* Setup the receive address. */
  1649. hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
  1650. hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
  1651. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  1652. /* clear VMDq pool/queue selection for RAR 0 */
  1653. hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
  1654. }
  1655. hw->addr_ctrl.overflow_promisc = 0;
  1656. hw->addr_ctrl.rar_used_count = 1;
  1657. /* Zero out the other receive addresses. */
  1658. hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
  1659. for (i = 1; i < rar_entries; i++) {
  1660. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1661. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1662. }
  1663. /* Clear the MTA */
  1664. hw->addr_ctrl.mta_in_use = 0;
  1665. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1666. hw_dbg(hw, " Clearing MTA\n");
  1667. for (i = 0; i < hw->mac.mcft_size; i++)
  1668. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1669. if (hw->mac.ops.init_uta_tables)
  1670. hw->mac.ops.init_uta_tables(hw);
  1671. return 0;
  1672. }
  1673. /**
  1674. * ixgbe_mta_vector - Determines bit-vector in multicast table to set
  1675. * @hw: pointer to hardware structure
  1676. * @mc_addr: the multicast address
  1677. *
  1678. * Extracts the 12 bits, from a multicast address, to determine which
  1679. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  1680. * incoming rx multicast addresses, to determine the bit-vector to check in
  1681. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  1682. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  1683. * to mc_filter_type.
  1684. **/
  1685. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  1686. {
  1687. u32 vector = 0;
  1688. switch (hw->mac.mc_filter_type) {
  1689. case 0: /* use bits [47:36] of the address */
  1690. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  1691. break;
  1692. case 1: /* use bits [46:35] of the address */
  1693. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  1694. break;
  1695. case 2: /* use bits [45:34] of the address */
  1696. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  1697. break;
  1698. case 3: /* use bits [43:32] of the address */
  1699. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  1700. break;
  1701. default: /* Invalid mc_filter_type */
  1702. hw_dbg(hw, "MC filter type param set incorrectly\n");
  1703. break;
  1704. }
  1705. /* vector can only be 12-bits or boundary will be exceeded */
  1706. vector &= 0xFFF;
  1707. return vector;
  1708. }
  1709. /**
  1710. * ixgbe_set_mta - Set bit-vector in multicast table
  1711. * @hw: pointer to hardware structure
  1712. * @hash_value: Multicast address hash value
  1713. *
  1714. * Sets the bit-vector in the multicast table.
  1715. **/
  1716. static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
  1717. {
  1718. u32 vector;
  1719. u32 vector_bit;
  1720. u32 vector_reg;
  1721. hw->addr_ctrl.mta_in_use++;
  1722. vector = ixgbe_mta_vector(hw, mc_addr);
  1723. hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
  1724. /*
  1725. * The MTA is a register array of 128 32-bit registers. It is treated
  1726. * like an array of 4096 bits. We want to set bit
  1727. * BitArray[vector_value]. So we figure out what register the bit is
  1728. * in, read it, OR in the new bit, then write back the new value. The
  1729. * register is determined by the upper 7 bits of the vector value and
  1730. * the bit within that register are determined by the lower 5 bits of
  1731. * the value.
  1732. */
  1733. vector_reg = (vector >> 5) & 0x7F;
  1734. vector_bit = vector & 0x1F;
  1735. hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
  1736. }
  1737. /**
  1738. * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
  1739. * @hw: pointer to hardware structure
  1740. * @netdev: pointer to net device structure
  1741. *
  1742. * The given list replaces any existing list. Clears the MC addrs from receive
  1743. * address registers and the multicast table. Uses unused receive address
  1744. * registers for the first multicast addresses, and hashes the rest into the
  1745. * multicast table.
  1746. **/
  1747. s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
  1748. struct net_device *netdev)
  1749. {
  1750. struct netdev_hw_addr *ha;
  1751. u32 i;
  1752. /*
  1753. * Set the new number of MC addresses that we are being requested to
  1754. * use.
  1755. */
  1756. hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
  1757. hw->addr_ctrl.mta_in_use = 0;
  1758. /* Clear mta_shadow */
  1759. hw_dbg(hw, " Clearing MTA\n");
  1760. memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
  1761. /* Update mta shadow */
  1762. netdev_for_each_mc_addr(ha, netdev) {
  1763. hw_dbg(hw, " Adding the multicast addresses:\n");
  1764. ixgbe_set_mta(hw, ha->addr);
  1765. }
  1766. /* Enable mta */
  1767. for (i = 0; i < hw->mac.mcft_size; i++)
  1768. IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
  1769. hw->mac.mta_shadow[i]);
  1770. if (hw->addr_ctrl.mta_in_use > 0)
  1771. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
  1772. IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
  1773. hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
  1774. return 0;
  1775. }
  1776. /**
  1777. * ixgbe_enable_mc_generic - Enable multicast address in RAR
  1778. * @hw: pointer to hardware structure
  1779. *
  1780. * Enables multicast address in RAR and the use of the multicast hash table.
  1781. **/
  1782. s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
  1783. {
  1784. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1785. if (a->mta_in_use > 0)
  1786. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
  1787. hw->mac.mc_filter_type);
  1788. return 0;
  1789. }
  1790. /**
  1791. * ixgbe_disable_mc_generic - Disable multicast address in RAR
  1792. * @hw: pointer to hardware structure
  1793. *
  1794. * Disables multicast address in RAR and the use of the multicast hash table.
  1795. **/
  1796. s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
  1797. {
  1798. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1799. if (a->mta_in_use > 0)
  1800. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1801. return 0;
  1802. }
  1803. /**
  1804. * ixgbe_fc_enable_generic - Enable flow control
  1805. * @hw: pointer to hardware structure
  1806. *
  1807. * Enable flow control according to the current settings.
  1808. **/
  1809. s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw)
  1810. {
  1811. s32 ret_val = 0;
  1812. u32 mflcn_reg, fccfg_reg;
  1813. u32 reg;
  1814. u32 fcrtl, fcrth;
  1815. int i;
  1816. /*
  1817. * Validate the water mark configuration for packet buffer 0. Zero
  1818. * water marks indicate that the packet buffer was not configured
  1819. * and the watermarks for packet buffer 0 should always be configured.
  1820. */
  1821. if (!hw->fc.low_water ||
  1822. !hw->fc.high_water[0] ||
  1823. !hw->fc.pause_time) {
  1824. hw_dbg(hw, "Invalid water mark configuration\n");
  1825. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1826. goto out;
  1827. }
  1828. /* Negotiate the fc mode to use */
  1829. ixgbe_fc_autoneg(hw);
  1830. /* Disable any previous flow control settings */
  1831. mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  1832. mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
  1833. fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  1834. fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
  1835. /*
  1836. * The possible values of fc.current_mode are:
  1837. * 0: Flow control is completely disabled
  1838. * 1: Rx flow control is enabled (we can receive pause frames,
  1839. * but not send pause frames).
  1840. * 2: Tx flow control is enabled (we can send pause frames but
  1841. * we do not support receiving pause frames).
  1842. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1843. * other: Invalid.
  1844. */
  1845. switch (hw->fc.current_mode) {
  1846. case ixgbe_fc_none:
  1847. /*
  1848. * Flow control is disabled by software override or autoneg.
  1849. * The code below will actually disable it in the HW.
  1850. */
  1851. break;
  1852. case ixgbe_fc_rx_pause:
  1853. /*
  1854. * Rx Flow control is enabled and Tx Flow control is
  1855. * disabled by software override. Since there really
  1856. * isn't a way to advertise that we are capable of RX
  1857. * Pause ONLY, we will advertise that we support both
  1858. * symmetric and asymmetric Rx PAUSE. Later, we will
  1859. * disable the adapter's ability to send PAUSE frames.
  1860. */
  1861. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1862. break;
  1863. case ixgbe_fc_tx_pause:
  1864. /*
  1865. * Tx Flow control is enabled, and Rx Flow control is
  1866. * disabled by software override.
  1867. */
  1868. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1869. break;
  1870. case ixgbe_fc_full:
  1871. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1872. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1873. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1874. break;
  1875. default:
  1876. hw_dbg(hw, "Flow control param set incorrectly\n");
  1877. ret_val = IXGBE_ERR_CONFIG;
  1878. goto out;
  1879. break;
  1880. }
  1881. /* Set 802.3x based flow control settings. */
  1882. mflcn_reg |= IXGBE_MFLCN_DPF;
  1883. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
  1884. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
  1885. fcrtl = (hw->fc.low_water << 10) | IXGBE_FCRTL_XONE;
  1886. /* Set up and enable Rx high/low water mark thresholds, enable XON. */
  1887. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  1888. if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
  1889. hw->fc.high_water[i]) {
  1890. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
  1891. fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
  1892. } else {
  1893. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
  1894. /*
  1895. * In order to prevent Tx hangs when the internal Tx
  1896. * switch is enabled we must set the high water mark
  1897. * to the maximum FCRTH value. This allows the Tx
  1898. * switch to function even under heavy Rx workloads.
  1899. */
  1900. fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
  1901. }
  1902. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
  1903. }
  1904. /* Configure pause time (2 TCs per register) */
  1905. reg = hw->fc.pause_time * 0x00010001;
  1906. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  1907. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  1908. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  1909. out:
  1910. return ret_val;
  1911. }
  1912. /**
  1913. * ixgbe_negotiate_fc - Negotiate flow control
  1914. * @hw: pointer to hardware structure
  1915. * @adv_reg: flow control advertised settings
  1916. * @lp_reg: link partner's flow control settings
  1917. * @adv_sym: symmetric pause bit in advertisement
  1918. * @adv_asm: asymmetric pause bit in advertisement
  1919. * @lp_sym: symmetric pause bit in link partner advertisement
  1920. * @lp_asm: asymmetric pause bit in link partner advertisement
  1921. *
  1922. * Find the intersection between advertised settings and link partner's
  1923. * advertised settings
  1924. **/
  1925. static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
  1926. u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
  1927. {
  1928. if ((!(adv_reg)) || (!(lp_reg)))
  1929. return IXGBE_ERR_FC_NOT_NEGOTIATED;
  1930. if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
  1931. /*
  1932. * Now we need to check if the user selected Rx ONLY
  1933. * of pause frames. In this case, we had to advertise
  1934. * FULL flow control because we could not advertise RX
  1935. * ONLY. Hence, we must now check to see if we need to
  1936. * turn OFF the TRANSMISSION of PAUSE frames.
  1937. */
  1938. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1939. hw->fc.current_mode = ixgbe_fc_full;
  1940. hw_dbg(hw, "Flow Control = FULL.\n");
  1941. } else {
  1942. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1943. hw_dbg(hw, "Flow Control=RX PAUSE frames only\n");
  1944. }
  1945. } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
  1946. (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
  1947. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1948. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1949. } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
  1950. !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
  1951. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1952. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1953. } else {
  1954. hw->fc.current_mode = ixgbe_fc_none;
  1955. hw_dbg(hw, "Flow Control = NONE.\n");
  1956. }
  1957. return 0;
  1958. }
  1959. /**
  1960. * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
  1961. * @hw: pointer to hardware structure
  1962. *
  1963. * Enable flow control according on 1 gig fiber.
  1964. **/
  1965. static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
  1966. {
  1967. u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
  1968. s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
  1969. /*
  1970. * On multispeed fiber at 1g, bail out if
  1971. * - link is up but AN did not complete, or if
  1972. * - link is up and AN completed but timed out
  1973. */
  1974. linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
  1975. if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
  1976. (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1))
  1977. goto out;
  1978. pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1979. pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
  1980. ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
  1981. pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
  1982. IXGBE_PCS1GANA_ASM_PAUSE,
  1983. IXGBE_PCS1GANA_SYM_PAUSE,
  1984. IXGBE_PCS1GANA_ASM_PAUSE);
  1985. out:
  1986. return ret_val;
  1987. }
  1988. /**
  1989. * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
  1990. * @hw: pointer to hardware structure
  1991. *
  1992. * Enable flow control according to IEEE clause 37.
  1993. **/
  1994. static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
  1995. {
  1996. u32 links2, anlp1_reg, autoc_reg, links;
  1997. s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
  1998. /*
  1999. * On backplane, bail out if
  2000. * - backplane autoneg was not completed, or if
  2001. * - we are 82599 and link partner is not AN enabled
  2002. */
  2003. links = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2004. if ((links & IXGBE_LINKS_KX_AN_COMP) == 0)
  2005. goto out;
  2006. if (hw->mac.type == ixgbe_mac_82599EB) {
  2007. links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
  2008. if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0)
  2009. goto out;
  2010. }
  2011. /*
  2012. * Read the 10g AN autoc and LP ability registers and resolve
  2013. * local flow control settings accordingly
  2014. */
  2015. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2016. anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
  2017. ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
  2018. anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
  2019. IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
  2020. out:
  2021. return ret_val;
  2022. }
  2023. /**
  2024. * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
  2025. * @hw: pointer to hardware structure
  2026. *
  2027. * Enable flow control according to IEEE clause 37.
  2028. **/
  2029. static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
  2030. {
  2031. u16 technology_ability_reg = 0;
  2032. u16 lp_technology_ability_reg = 0;
  2033. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  2034. MDIO_MMD_AN,
  2035. &technology_ability_reg);
  2036. hw->phy.ops.read_reg(hw, MDIO_AN_LPA,
  2037. MDIO_MMD_AN,
  2038. &lp_technology_ability_reg);
  2039. return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
  2040. (u32)lp_technology_ability_reg,
  2041. IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
  2042. IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
  2043. }
  2044. /**
  2045. * ixgbe_fc_autoneg - Configure flow control
  2046. * @hw: pointer to hardware structure
  2047. *
  2048. * Compares our advertised flow control capabilities to those advertised by
  2049. * our link partner, and determines the proper flow control mode to use.
  2050. **/
  2051. void ixgbe_fc_autoneg(struct ixgbe_hw *hw)
  2052. {
  2053. s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
  2054. ixgbe_link_speed speed;
  2055. bool link_up;
  2056. /*
  2057. * AN should have completed when the cable was plugged in.
  2058. * Look for reasons to bail out. Bail out if:
  2059. * - FC autoneg is disabled, or if
  2060. * - link is not up.
  2061. *
  2062. * Since we're being called from an LSC, link is already known to be up.
  2063. * So use link_up_wait_to_complete=false.
  2064. */
  2065. if (hw->fc.disable_fc_autoneg)
  2066. goto out;
  2067. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2068. if (!link_up)
  2069. goto out;
  2070. switch (hw->phy.media_type) {
  2071. /* Autoneg flow control on fiber adapters */
  2072. case ixgbe_media_type_fiber:
  2073. if (speed == IXGBE_LINK_SPEED_1GB_FULL)
  2074. ret_val = ixgbe_fc_autoneg_fiber(hw);
  2075. break;
  2076. /* Autoneg flow control on backplane adapters */
  2077. case ixgbe_media_type_backplane:
  2078. ret_val = ixgbe_fc_autoneg_backplane(hw);
  2079. break;
  2080. /* Autoneg flow control on copper adapters */
  2081. case ixgbe_media_type_copper:
  2082. if (ixgbe_device_supports_autoneg_fc(hw) == 0)
  2083. ret_val = ixgbe_fc_autoneg_copper(hw);
  2084. break;
  2085. default:
  2086. break;
  2087. }
  2088. out:
  2089. if (ret_val == 0) {
  2090. hw->fc.fc_was_autonegged = true;
  2091. } else {
  2092. hw->fc.fc_was_autonegged = false;
  2093. hw->fc.current_mode = hw->fc.requested_mode;
  2094. }
  2095. }
  2096. /**
  2097. * ixgbe_disable_pcie_master - Disable PCI-express master access
  2098. * @hw: pointer to hardware structure
  2099. *
  2100. * Disables PCI-Express master access and verifies there are no pending
  2101. * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
  2102. * bit hasn't caused the master requests to be disabled, else 0
  2103. * is returned signifying master requests disabled.
  2104. **/
  2105. static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
  2106. {
  2107. struct ixgbe_adapter *adapter = hw->back;
  2108. s32 status = 0;
  2109. u32 i;
  2110. u16 value;
  2111. /* Always set this bit to ensure any future transactions are blocked */
  2112. IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
  2113. /* Exit if master requests are blocked */
  2114. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
  2115. goto out;
  2116. /* Poll for master request bit to clear */
  2117. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  2118. udelay(100);
  2119. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
  2120. goto out;
  2121. }
  2122. /*
  2123. * Two consecutive resets are required via CTRL.RST per datasheet
  2124. * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
  2125. * of this need. The first reset prevents new master requests from
  2126. * being issued by our device. We then must wait 1usec or more for any
  2127. * remaining completions from the PCIe bus to trickle in, and then reset
  2128. * again to clear out any effects they may have had on our device.
  2129. */
  2130. hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
  2131. hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  2132. /*
  2133. * Before proceeding, make sure that the PCIe block does not have
  2134. * transactions pending.
  2135. */
  2136. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  2137. udelay(100);
  2138. pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
  2139. &value);
  2140. if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
  2141. goto out;
  2142. }
  2143. hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
  2144. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  2145. out:
  2146. return status;
  2147. }
  2148. /**
  2149. * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
  2150. * @hw: pointer to hardware structure
  2151. * @mask: Mask to specify which semaphore to acquire
  2152. *
  2153. * Acquires the SWFW semaphore through the GSSR register for the specified
  2154. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  2155. **/
  2156. s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  2157. {
  2158. u32 gssr;
  2159. u32 swmask = mask;
  2160. u32 fwmask = mask << 5;
  2161. s32 timeout = 200;
  2162. while (timeout) {
  2163. /*
  2164. * SW EEPROM semaphore bit is used for access to all
  2165. * SW_FW_SYNC/GSSR bits (not just EEPROM)
  2166. */
  2167. if (ixgbe_get_eeprom_semaphore(hw))
  2168. return IXGBE_ERR_SWFW_SYNC;
  2169. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  2170. if (!(gssr & (fwmask | swmask)))
  2171. break;
  2172. /*
  2173. * Firmware currently using resource (fwmask) or other software
  2174. * thread currently using resource (swmask)
  2175. */
  2176. ixgbe_release_eeprom_semaphore(hw);
  2177. usleep_range(5000, 10000);
  2178. timeout--;
  2179. }
  2180. if (!timeout) {
  2181. hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
  2182. return IXGBE_ERR_SWFW_SYNC;
  2183. }
  2184. gssr |= swmask;
  2185. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  2186. ixgbe_release_eeprom_semaphore(hw);
  2187. return 0;
  2188. }
  2189. /**
  2190. * ixgbe_release_swfw_sync - Release SWFW semaphore
  2191. * @hw: pointer to hardware structure
  2192. * @mask: Mask to specify which semaphore to release
  2193. *
  2194. * Releases the SWFW semaphore through the GSSR register for the specified
  2195. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  2196. **/
  2197. void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  2198. {
  2199. u32 gssr;
  2200. u32 swmask = mask;
  2201. ixgbe_get_eeprom_semaphore(hw);
  2202. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  2203. gssr &= ~swmask;
  2204. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  2205. ixgbe_release_eeprom_semaphore(hw);
  2206. }
  2207. /**
  2208. * ixgbe_disable_rx_buff_generic - Stops the receive data path
  2209. * @hw: pointer to hardware structure
  2210. *
  2211. * Stops the receive data path and waits for the HW to internally
  2212. * empty the Rx security block.
  2213. **/
  2214. s32 ixgbe_disable_rx_buff_generic(struct ixgbe_hw *hw)
  2215. {
  2216. #define IXGBE_MAX_SECRX_POLL 40
  2217. int i;
  2218. int secrxreg;
  2219. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2220. secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
  2221. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2222. for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
  2223. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
  2224. if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
  2225. break;
  2226. else
  2227. /* Use interrupt-safe sleep just in case */
  2228. udelay(1000);
  2229. }
  2230. /* For informational purposes only */
  2231. if (i >= IXGBE_MAX_SECRX_POLL)
  2232. hw_dbg(hw, "Rx unit being enabled before security "
  2233. "path fully disabled. Continuing with init.\n");
  2234. return 0;
  2235. }
  2236. /**
  2237. * ixgbe_enable_rx_buff - Enables the receive data path
  2238. * @hw: pointer to hardware structure
  2239. *
  2240. * Enables the receive data path
  2241. **/
  2242. s32 ixgbe_enable_rx_buff_generic(struct ixgbe_hw *hw)
  2243. {
  2244. int secrxreg;
  2245. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2246. secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
  2247. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2248. IXGBE_WRITE_FLUSH(hw);
  2249. return 0;
  2250. }
  2251. /**
  2252. * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
  2253. * @hw: pointer to hardware structure
  2254. * @regval: register value to write to RXCTRL
  2255. *
  2256. * Enables the Rx DMA unit
  2257. **/
  2258. s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
  2259. {
  2260. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  2261. return 0;
  2262. }
  2263. /**
  2264. * ixgbe_blink_led_start_generic - Blink LED based on index.
  2265. * @hw: pointer to hardware structure
  2266. * @index: led number to blink
  2267. **/
  2268. s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
  2269. {
  2270. ixgbe_link_speed speed = 0;
  2271. bool link_up = false;
  2272. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2273. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  2274. s32 ret_val = 0;
  2275. /*
  2276. * Link must be up to auto-blink the LEDs;
  2277. * Force it if link is down.
  2278. */
  2279. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2280. if (!link_up) {
  2281. /* Need the SW/FW semaphore around AUTOC writes if 82599 and
  2282. * LESM is on.
  2283. */
  2284. bool got_lock = false;
  2285. if ((hw->mac.type == ixgbe_mac_82599EB) &&
  2286. ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  2287. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  2288. IXGBE_GSSR_MAC_CSR_SM);
  2289. if (ret_val)
  2290. goto out;
  2291. got_lock = true;
  2292. }
  2293. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  2294. autoc_reg |= IXGBE_AUTOC_FLU;
  2295. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  2296. IXGBE_WRITE_FLUSH(hw);
  2297. if (got_lock)
  2298. hw->mac.ops.release_swfw_sync(hw,
  2299. IXGBE_GSSR_MAC_CSR_SM);
  2300. usleep_range(10000, 20000);
  2301. }
  2302. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  2303. led_reg |= IXGBE_LED_BLINK(index);
  2304. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  2305. IXGBE_WRITE_FLUSH(hw);
  2306. out:
  2307. return ret_val;
  2308. }
  2309. /**
  2310. * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
  2311. * @hw: pointer to hardware structure
  2312. * @index: led number to stop blinking
  2313. **/
  2314. s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
  2315. {
  2316. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2317. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  2318. s32 ret_val = 0;
  2319. bool got_lock = false;
  2320. /* Need the SW/FW semaphore around AUTOC writes if 82599 and
  2321. * LESM is on.
  2322. */
  2323. if ((hw->mac.type == ixgbe_mac_82599EB) &&
  2324. ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  2325. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  2326. IXGBE_GSSR_MAC_CSR_SM);
  2327. if (ret_val)
  2328. goto out;
  2329. got_lock = true;
  2330. }
  2331. autoc_reg &= ~IXGBE_AUTOC_FLU;
  2332. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  2333. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  2334. if (hw->mac.type == ixgbe_mac_82599EB)
  2335. ixgbe_reset_pipeline_82599(hw);
  2336. if (got_lock)
  2337. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  2338. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  2339. led_reg &= ~IXGBE_LED_BLINK(index);
  2340. led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  2341. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  2342. IXGBE_WRITE_FLUSH(hw);
  2343. out:
  2344. return ret_val;
  2345. }
  2346. /**
  2347. * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
  2348. * @hw: pointer to hardware structure
  2349. * @san_mac_offset: SAN MAC address offset
  2350. *
  2351. * This function will read the EEPROM location for the SAN MAC address
  2352. * pointer, and returns the value at that location. This is used in both
  2353. * get and set mac_addr routines.
  2354. **/
  2355. static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
  2356. u16 *san_mac_offset)
  2357. {
  2358. /*
  2359. * First read the EEPROM pointer to see if the MAC addresses are
  2360. * available.
  2361. */
  2362. hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
  2363. return 0;
  2364. }
  2365. /**
  2366. * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
  2367. * @hw: pointer to hardware structure
  2368. * @san_mac_addr: SAN MAC address
  2369. *
  2370. * Reads the SAN MAC address from the EEPROM, if it's available. This is
  2371. * per-port, so set_lan_id() must be called before reading the addresses.
  2372. * set_lan_id() is called by identify_sfp(), but this cannot be relied
  2373. * upon for non-SFP connections, so we must call it here.
  2374. **/
  2375. s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
  2376. {
  2377. u16 san_mac_data, san_mac_offset;
  2378. u8 i;
  2379. /*
  2380. * First read the EEPROM pointer to see if the MAC addresses are
  2381. * available. If they're not, no point in calling set_lan_id() here.
  2382. */
  2383. ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
  2384. if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
  2385. /*
  2386. * No addresses available in this EEPROM. It's not an
  2387. * error though, so just wipe the local address and return.
  2388. */
  2389. for (i = 0; i < 6; i++)
  2390. san_mac_addr[i] = 0xFF;
  2391. goto san_mac_addr_out;
  2392. }
  2393. /* make sure we know which port we need to program */
  2394. hw->mac.ops.set_lan_id(hw);
  2395. /* apply the port offset to the address offset */
  2396. (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
  2397. (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
  2398. for (i = 0; i < 3; i++) {
  2399. hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
  2400. san_mac_addr[i * 2] = (u8)(san_mac_data);
  2401. san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
  2402. san_mac_offset++;
  2403. }
  2404. san_mac_addr_out:
  2405. return 0;
  2406. }
  2407. /**
  2408. * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
  2409. * @hw: pointer to hardware structure
  2410. *
  2411. * Read PCIe configuration space, and get the MSI-X vector count from
  2412. * the capabilities table.
  2413. **/
  2414. u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
  2415. {
  2416. struct ixgbe_adapter *adapter = hw->back;
  2417. u16 msix_count = 1;
  2418. u16 max_msix_count;
  2419. u16 pcie_offset;
  2420. switch (hw->mac.type) {
  2421. case ixgbe_mac_82598EB:
  2422. pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS;
  2423. max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598;
  2424. break;
  2425. case ixgbe_mac_82599EB:
  2426. case ixgbe_mac_X540:
  2427. pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS;
  2428. max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
  2429. break;
  2430. default:
  2431. return msix_count;
  2432. }
  2433. pci_read_config_word(adapter->pdev, pcie_offset, &msix_count);
  2434. msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
  2435. /* MSI-X count is zero-based in HW */
  2436. msix_count++;
  2437. if (msix_count > max_msix_count)
  2438. msix_count = max_msix_count;
  2439. return msix_count;
  2440. }
  2441. /**
  2442. * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
  2443. * @hw: pointer to hardware struct
  2444. * @rar: receive address register index to disassociate
  2445. * @vmdq: VMDq pool index to remove from the rar
  2446. **/
  2447. s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  2448. {
  2449. u32 mpsar_lo, mpsar_hi;
  2450. u32 rar_entries = hw->mac.num_rar_entries;
  2451. /* Make sure we are using a valid rar index range */
  2452. if (rar >= rar_entries) {
  2453. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  2454. return IXGBE_ERR_INVALID_ARGUMENT;
  2455. }
  2456. mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  2457. mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  2458. if (!mpsar_lo && !mpsar_hi)
  2459. goto done;
  2460. if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
  2461. if (mpsar_lo) {
  2462. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  2463. mpsar_lo = 0;
  2464. }
  2465. if (mpsar_hi) {
  2466. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  2467. mpsar_hi = 0;
  2468. }
  2469. } else if (vmdq < 32) {
  2470. mpsar_lo &= ~(1 << vmdq);
  2471. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
  2472. } else {
  2473. mpsar_hi &= ~(1 << (vmdq - 32));
  2474. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
  2475. }
  2476. /* was that the last pool using this rar? */
  2477. if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
  2478. hw->mac.ops.clear_rar(hw, rar);
  2479. done:
  2480. return 0;
  2481. }
  2482. /**
  2483. * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
  2484. * @hw: pointer to hardware struct
  2485. * @rar: receive address register index to associate with a VMDq index
  2486. * @vmdq: VMDq pool index
  2487. **/
  2488. s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  2489. {
  2490. u32 mpsar;
  2491. u32 rar_entries = hw->mac.num_rar_entries;
  2492. /* Make sure we are using a valid rar index range */
  2493. if (rar >= rar_entries) {
  2494. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  2495. return IXGBE_ERR_INVALID_ARGUMENT;
  2496. }
  2497. if (vmdq < 32) {
  2498. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  2499. mpsar |= 1 << vmdq;
  2500. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
  2501. } else {
  2502. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  2503. mpsar |= 1 << (vmdq - 32);
  2504. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
  2505. }
  2506. return 0;
  2507. }
  2508. /**
  2509. * This function should only be involved in the IOV mode.
  2510. * In IOV mode, Default pool is next pool after the number of
  2511. * VFs advertized and not 0.
  2512. * MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index]
  2513. *
  2514. * ixgbe_set_vmdq_san_mac - Associate default VMDq pool index with a rx address
  2515. * @hw: pointer to hardware struct
  2516. * @vmdq: VMDq pool index
  2517. **/
  2518. s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq)
  2519. {
  2520. u32 rar = hw->mac.san_mac_rar_index;
  2521. if (vmdq < 32) {
  2522. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 1 << vmdq);
  2523. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  2524. } else {
  2525. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  2526. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 1 << (vmdq - 32));
  2527. }
  2528. return 0;
  2529. }
  2530. /**
  2531. * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
  2532. * @hw: pointer to hardware structure
  2533. **/
  2534. s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
  2535. {
  2536. int i;
  2537. for (i = 0; i < 128; i++)
  2538. IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
  2539. return 0;
  2540. }
  2541. /**
  2542. * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
  2543. * @hw: pointer to hardware structure
  2544. * @vlan: VLAN id to write to VLAN filter
  2545. *
  2546. * return the VLVF index where this VLAN id should be placed
  2547. *
  2548. **/
  2549. static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
  2550. {
  2551. u32 bits = 0;
  2552. u32 first_empty_slot = 0;
  2553. s32 regindex;
  2554. /* short cut the special case */
  2555. if (vlan == 0)
  2556. return 0;
  2557. /*
  2558. * Search for the vlan id in the VLVF entries. Save off the first empty
  2559. * slot found along the way
  2560. */
  2561. for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
  2562. bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
  2563. if (!bits && !(first_empty_slot))
  2564. first_empty_slot = regindex;
  2565. else if ((bits & 0x0FFF) == vlan)
  2566. break;
  2567. }
  2568. /*
  2569. * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
  2570. * in the VLVF. Else use the first empty VLVF register for this
  2571. * vlan id.
  2572. */
  2573. if (regindex >= IXGBE_VLVF_ENTRIES) {
  2574. if (first_empty_slot)
  2575. regindex = first_empty_slot;
  2576. else {
  2577. hw_dbg(hw, "No space in VLVF.\n");
  2578. regindex = IXGBE_ERR_NO_SPACE;
  2579. }
  2580. }
  2581. return regindex;
  2582. }
  2583. /**
  2584. * ixgbe_set_vfta_generic - Set VLAN filter table
  2585. * @hw: pointer to hardware structure
  2586. * @vlan: VLAN id to write to VLAN filter
  2587. * @vind: VMDq output index that maps queue to VLAN id in VFVFB
  2588. * @vlan_on: boolean flag to turn on/off VLAN in VFVF
  2589. *
  2590. * Turn on/off specified VLAN in the VLAN filter table.
  2591. **/
  2592. s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  2593. bool vlan_on)
  2594. {
  2595. s32 regindex;
  2596. u32 bitindex;
  2597. u32 vfta;
  2598. u32 bits;
  2599. u32 vt;
  2600. u32 targetbit;
  2601. bool vfta_changed = false;
  2602. if (vlan > 4095)
  2603. return IXGBE_ERR_PARAM;
  2604. /*
  2605. * this is a 2 part operation - first the VFTA, then the
  2606. * VLVF and VLVFB if VT Mode is set
  2607. * We don't write the VFTA until we know the VLVF part succeeded.
  2608. */
  2609. /* Part 1
  2610. * The VFTA is a bitstring made up of 128 32-bit registers
  2611. * that enable the particular VLAN id, much like the MTA:
  2612. * bits[11-5]: which register
  2613. * bits[4-0]: which bit in the register
  2614. */
  2615. regindex = (vlan >> 5) & 0x7F;
  2616. bitindex = vlan & 0x1F;
  2617. targetbit = (1 << bitindex);
  2618. vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  2619. if (vlan_on) {
  2620. if (!(vfta & targetbit)) {
  2621. vfta |= targetbit;
  2622. vfta_changed = true;
  2623. }
  2624. } else {
  2625. if ((vfta & targetbit)) {
  2626. vfta &= ~targetbit;
  2627. vfta_changed = true;
  2628. }
  2629. }
  2630. /* Part 2
  2631. * If VT Mode is set
  2632. * Either vlan_on
  2633. * make sure the vlan is in VLVF
  2634. * set the vind bit in the matching VLVFB
  2635. * Or !vlan_on
  2636. * clear the pool bit and possibly the vind
  2637. */
  2638. vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  2639. if (vt & IXGBE_VT_CTL_VT_ENABLE) {
  2640. s32 vlvf_index;
  2641. vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
  2642. if (vlvf_index < 0)
  2643. return vlvf_index;
  2644. if (vlan_on) {
  2645. /* set the pool bit */
  2646. if (vind < 32) {
  2647. bits = IXGBE_READ_REG(hw,
  2648. IXGBE_VLVFB(vlvf_index*2));
  2649. bits |= (1 << vind);
  2650. IXGBE_WRITE_REG(hw,
  2651. IXGBE_VLVFB(vlvf_index*2),
  2652. bits);
  2653. } else {
  2654. bits = IXGBE_READ_REG(hw,
  2655. IXGBE_VLVFB((vlvf_index*2)+1));
  2656. bits |= (1 << (vind-32));
  2657. IXGBE_WRITE_REG(hw,
  2658. IXGBE_VLVFB((vlvf_index*2)+1),
  2659. bits);
  2660. }
  2661. } else {
  2662. /* clear the pool bit */
  2663. if (vind < 32) {
  2664. bits = IXGBE_READ_REG(hw,
  2665. IXGBE_VLVFB(vlvf_index*2));
  2666. bits &= ~(1 << vind);
  2667. IXGBE_WRITE_REG(hw,
  2668. IXGBE_VLVFB(vlvf_index*2),
  2669. bits);
  2670. bits |= IXGBE_READ_REG(hw,
  2671. IXGBE_VLVFB((vlvf_index*2)+1));
  2672. } else {
  2673. bits = IXGBE_READ_REG(hw,
  2674. IXGBE_VLVFB((vlvf_index*2)+1));
  2675. bits &= ~(1 << (vind-32));
  2676. IXGBE_WRITE_REG(hw,
  2677. IXGBE_VLVFB((vlvf_index*2)+1),
  2678. bits);
  2679. bits |= IXGBE_READ_REG(hw,
  2680. IXGBE_VLVFB(vlvf_index*2));
  2681. }
  2682. }
  2683. /*
  2684. * If there are still bits set in the VLVFB registers
  2685. * for the VLAN ID indicated we need to see if the
  2686. * caller is requesting that we clear the VFTA entry bit.
  2687. * If the caller has requested that we clear the VFTA
  2688. * entry bit but there are still pools/VFs using this VLAN
  2689. * ID entry then ignore the request. We're not worried
  2690. * about the case where we're turning the VFTA VLAN ID
  2691. * entry bit on, only when requested to turn it off as
  2692. * there may be multiple pools and/or VFs using the
  2693. * VLAN ID entry. In that case we cannot clear the
  2694. * VFTA bit until all pools/VFs using that VLAN ID have also
  2695. * been cleared. This will be indicated by "bits" being
  2696. * zero.
  2697. */
  2698. if (bits) {
  2699. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
  2700. (IXGBE_VLVF_VIEN | vlan));
  2701. if (!vlan_on) {
  2702. /* someone wants to clear the vfta entry
  2703. * but some pools/VFs are still using it.
  2704. * Ignore it. */
  2705. vfta_changed = false;
  2706. }
  2707. }
  2708. else
  2709. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
  2710. }
  2711. if (vfta_changed)
  2712. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
  2713. return 0;
  2714. }
  2715. /**
  2716. * ixgbe_clear_vfta_generic - Clear VLAN filter table
  2717. * @hw: pointer to hardware structure
  2718. *
  2719. * Clears the VLAN filer table, and the VMDq index associated with the filter
  2720. **/
  2721. s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
  2722. {
  2723. u32 offset;
  2724. for (offset = 0; offset < hw->mac.vft_size; offset++)
  2725. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  2726. for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
  2727. IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
  2728. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
  2729. IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
  2730. }
  2731. return 0;
  2732. }
  2733. /**
  2734. * ixgbe_check_mac_link_generic - Determine link and speed status
  2735. * @hw: pointer to hardware structure
  2736. * @speed: pointer to link speed
  2737. * @link_up: true when link is up
  2738. * @link_up_wait_to_complete: bool used to wait for link up or not
  2739. *
  2740. * Reads the links register to determine if link is up and the current speed
  2741. **/
  2742. s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  2743. bool *link_up, bool link_up_wait_to_complete)
  2744. {
  2745. u32 links_reg, links_orig;
  2746. u32 i;
  2747. /* clear the old state */
  2748. links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2749. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2750. if (links_orig != links_reg) {
  2751. hw_dbg(hw, "LINKS changed from %08X to %08X\n",
  2752. links_orig, links_reg);
  2753. }
  2754. if (link_up_wait_to_complete) {
  2755. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  2756. if (links_reg & IXGBE_LINKS_UP) {
  2757. *link_up = true;
  2758. break;
  2759. } else {
  2760. *link_up = false;
  2761. }
  2762. msleep(100);
  2763. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2764. }
  2765. } else {
  2766. if (links_reg & IXGBE_LINKS_UP)
  2767. *link_up = true;
  2768. else
  2769. *link_up = false;
  2770. }
  2771. if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2772. IXGBE_LINKS_SPEED_10G_82599)
  2773. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  2774. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2775. IXGBE_LINKS_SPEED_1G_82599)
  2776. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  2777. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2778. IXGBE_LINKS_SPEED_100_82599)
  2779. *speed = IXGBE_LINK_SPEED_100_FULL;
  2780. else
  2781. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  2782. return 0;
  2783. }
  2784. /**
  2785. * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
  2786. * the EEPROM
  2787. * @hw: pointer to hardware structure
  2788. * @wwnn_prefix: the alternative WWNN prefix
  2789. * @wwpn_prefix: the alternative WWPN prefix
  2790. *
  2791. * This function will read the EEPROM from the alternative SAN MAC address
  2792. * block to check the support for the alternative WWNN/WWPN prefix support.
  2793. **/
  2794. s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
  2795. u16 *wwpn_prefix)
  2796. {
  2797. u16 offset, caps;
  2798. u16 alt_san_mac_blk_offset;
  2799. /* clear output first */
  2800. *wwnn_prefix = 0xFFFF;
  2801. *wwpn_prefix = 0xFFFF;
  2802. /* check if alternative SAN MAC is supported */
  2803. hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
  2804. &alt_san_mac_blk_offset);
  2805. if ((alt_san_mac_blk_offset == 0) ||
  2806. (alt_san_mac_blk_offset == 0xFFFF))
  2807. goto wwn_prefix_out;
  2808. /* check capability in alternative san mac address block */
  2809. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
  2810. hw->eeprom.ops.read(hw, offset, &caps);
  2811. if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
  2812. goto wwn_prefix_out;
  2813. /* get the corresponding prefix for WWNN/WWPN */
  2814. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
  2815. hw->eeprom.ops.read(hw, offset, wwnn_prefix);
  2816. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
  2817. hw->eeprom.ops.read(hw, offset, wwpn_prefix);
  2818. wwn_prefix_out:
  2819. return 0;
  2820. }
  2821. /**
  2822. * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
  2823. * @hw: pointer to hardware structure
  2824. * @enable: enable or disable switch for anti-spoofing
  2825. * @pf: Physical Function pool - do not enable anti-spoofing for the PF
  2826. *
  2827. **/
  2828. void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
  2829. {
  2830. int j;
  2831. int pf_target_reg = pf >> 3;
  2832. int pf_target_shift = pf % 8;
  2833. u32 pfvfspoof = 0;
  2834. if (hw->mac.type == ixgbe_mac_82598EB)
  2835. return;
  2836. if (enable)
  2837. pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
  2838. /*
  2839. * PFVFSPOOF register array is size 8 with 8 bits assigned to
  2840. * MAC anti-spoof enables in each register array element.
  2841. */
  2842. for (j = 0; j < pf_target_reg; j++)
  2843. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
  2844. /*
  2845. * The PF should be allowed to spoof so that it can support
  2846. * emulation mode NICs. Do not set the bits assigned to the PF
  2847. */
  2848. pfvfspoof &= (1 << pf_target_shift) - 1;
  2849. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
  2850. /*
  2851. * Remaining pools belong to the PF so they do not need to have
  2852. * anti-spoofing enabled.
  2853. */
  2854. for (j++; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
  2855. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), 0);
  2856. }
  2857. /**
  2858. * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
  2859. * @hw: pointer to hardware structure
  2860. * @enable: enable or disable switch for VLAN anti-spoofing
  2861. * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
  2862. *
  2863. **/
  2864. void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
  2865. {
  2866. int vf_target_reg = vf >> 3;
  2867. int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
  2868. u32 pfvfspoof;
  2869. if (hw->mac.type == ixgbe_mac_82598EB)
  2870. return;
  2871. pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
  2872. if (enable)
  2873. pfvfspoof |= (1 << vf_target_shift);
  2874. else
  2875. pfvfspoof &= ~(1 << vf_target_shift);
  2876. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
  2877. }
  2878. /**
  2879. * ixgbe_get_device_caps_generic - Get additional device capabilities
  2880. * @hw: pointer to hardware structure
  2881. * @device_caps: the EEPROM word with the extra device capabilities
  2882. *
  2883. * This function will read the EEPROM location for the device capabilities,
  2884. * and return the word through device_caps.
  2885. **/
  2886. s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
  2887. {
  2888. hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
  2889. return 0;
  2890. }
  2891. /**
  2892. * ixgbe_set_rxpba_generic - Initialize RX packet buffer
  2893. * @hw: pointer to hardware structure
  2894. * @num_pb: number of packet buffers to allocate
  2895. * @headroom: reserve n KB of headroom
  2896. * @strategy: packet buffer allocation strategy
  2897. **/
  2898. void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw,
  2899. int num_pb,
  2900. u32 headroom,
  2901. int strategy)
  2902. {
  2903. u32 pbsize = hw->mac.rx_pb_size;
  2904. int i = 0;
  2905. u32 rxpktsize, txpktsize, txpbthresh;
  2906. /* Reserve headroom */
  2907. pbsize -= headroom;
  2908. if (!num_pb)
  2909. num_pb = 1;
  2910. /* Divide remaining packet buffer space amongst the number
  2911. * of packet buffers requested using supplied strategy.
  2912. */
  2913. switch (strategy) {
  2914. case (PBA_STRATEGY_WEIGHTED):
  2915. /* pba_80_48 strategy weight first half of packet buffer with
  2916. * 5/8 of the packet buffer space.
  2917. */
  2918. rxpktsize = ((pbsize * 5 * 2) / (num_pb * 8));
  2919. pbsize -= rxpktsize * (num_pb / 2);
  2920. rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
  2921. for (; i < (num_pb / 2); i++)
  2922. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
  2923. /* Fall through to configure remaining packet buffers */
  2924. case (PBA_STRATEGY_EQUAL):
  2925. /* Divide the remaining Rx packet buffer evenly among the TCs */
  2926. rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
  2927. for (; i < num_pb; i++)
  2928. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
  2929. break;
  2930. default:
  2931. break;
  2932. }
  2933. /*
  2934. * Setup Tx packet buffer and threshold equally for all TCs
  2935. * TXPBTHRESH register is set in K so divide by 1024 and subtract
  2936. * 10 since the largest packet we support is just over 9K.
  2937. */
  2938. txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
  2939. txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
  2940. for (i = 0; i < num_pb; i++) {
  2941. IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
  2942. IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
  2943. }
  2944. /* Clear unused TCs, if any, to zero buffer size*/
  2945. for (; i < IXGBE_MAX_PB; i++) {
  2946. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
  2947. IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
  2948. IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
  2949. }
  2950. }
  2951. /**
  2952. * ixgbe_calculate_checksum - Calculate checksum for buffer
  2953. * @buffer: pointer to EEPROM
  2954. * @length: size of EEPROM to calculate a checksum for
  2955. *
  2956. * Calculates the checksum for some buffer on a specified length. The
  2957. * checksum calculated is returned.
  2958. **/
  2959. static u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
  2960. {
  2961. u32 i;
  2962. u8 sum = 0;
  2963. if (!buffer)
  2964. return 0;
  2965. for (i = 0; i < length; i++)
  2966. sum += buffer[i];
  2967. return (u8) (0 - sum);
  2968. }
  2969. /**
  2970. * ixgbe_host_interface_command - Issue command to manageability block
  2971. * @hw: pointer to the HW structure
  2972. * @buffer: contains the command to write and where the return status will
  2973. * be placed
  2974. * @length: length of buffer, must be multiple of 4 bytes
  2975. *
  2976. * Communicates with the manageability block. On success return 0
  2977. * else return IXGBE_ERR_HOST_INTERFACE_COMMAND.
  2978. **/
  2979. static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
  2980. u32 length)
  2981. {
  2982. u32 hicr, i, bi;
  2983. u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
  2984. u8 buf_len, dword_len;
  2985. s32 ret_val = 0;
  2986. if (length == 0 || length & 0x3 ||
  2987. length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
  2988. hw_dbg(hw, "Buffer length failure.\n");
  2989. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  2990. goto out;
  2991. }
  2992. /* Check that the host interface is enabled. */
  2993. hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
  2994. if ((hicr & IXGBE_HICR_EN) == 0) {
  2995. hw_dbg(hw, "IXGBE_HOST_EN bit disabled.\n");
  2996. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  2997. goto out;
  2998. }
  2999. /* Calculate length in DWORDs */
  3000. dword_len = length >> 2;
  3001. /*
  3002. * The device driver writes the relevant command block
  3003. * into the ram area.
  3004. */
  3005. for (i = 0; i < dword_len; i++)
  3006. IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
  3007. i, cpu_to_le32(buffer[i]));
  3008. /* Setting this bit tells the ARC that a new command is pending. */
  3009. IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
  3010. for (i = 0; i < IXGBE_HI_COMMAND_TIMEOUT; i++) {
  3011. hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
  3012. if (!(hicr & IXGBE_HICR_C))
  3013. break;
  3014. usleep_range(1000, 2000);
  3015. }
  3016. /* Check command successful completion. */
  3017. if (i == IXGBE_HI_COMMAND_TIMEOUT ||
  3018. (!(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))) {
  3019. hw_dbg(hw, "Command has failed with no status valid.\n");
  3020. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3021. goto out;
  3022. }
  3023. /* Calculate length in DWORDs */
  3024. dword_len = hdr_size >> 2;
  3025. /* first pull in the header so we know the buffer length */
  3026. for (bi = 0; bi < dword_len; bi++) {
  3027. buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
  3028. le32_to_cpus(&buffer[bi]);
  3029. }
  3030. /* If there is any thing in data position pull it in */
  3031. buf_len = ((struct ixgbe_hic_hdr *)buffer)->buf_len;
  3032. if (buf_len == 0)
  3033. goto out;
  3034. if (length < (buf_len + hdr_size)) {
  3035. hw_dbg(hw, "Buffer not large enough for reply message.\n");
  3036. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3037. goto out;
  3038. }
  3039. /* Calculate length in DWORDs, add 3 for odd lengths */
  3040. dword_len = (buf_len + 3) >> 2;
  3041. /* Pull in the rest of the buffer (bi is where we left off)*/
  3042. for (; bi <= dword_len; bi++) {
  3043. buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
  3044. le32_to_cpus(&buffer[bi]);
  3045. }
  3046. out:
  3047. return ret_val;
  3048. }
  3049. /**
  3050. * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
  3051. * @hw: pointer to the HW structure
  3052. * @maj: driver version major number
  3053. * @min: driver version minor number
  3054. * @build: driver version build number
  3055. * @sub: driver version sub build number
  3056. *
  3057. * Sends driver version number to firmware through the manageability
  3058. * block. On success return 0
  3059. * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
  3060. * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
  3061. **/
  3062. s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
  3063. u8 build, u8 sub)
  3064. {
  3065. struct ixgbe_hic_drv_info fw_cmd;
  3066. int i;
  3067. s32 ret_val = 0;
  3068. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM) != 0) {
  3069. ret_val = IXGBE_ERR_SWFW_SYNC;
  3070. goto out;
  3071. }
  3072. fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
  3073. fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
  3074. fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
  3075. fw_cmd.port_num = (u8)hw->bus.func;
  3076. fw_cmd.ver_maj = maj;
  3077. fw_cmd.ver_min = min;
  3078. fw_cmd.ver_build = build;
  3079. fw_cmd.ver_sub = sub;
  3080. fw_cmd.hdr.checksum = 0;
  3081. fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
  3082. (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
  3083. fw_cmd.pad = 0;
  3084. fw_cmd.pad2 = 0;
  3085. for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
  3086. ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
  3087. sizeof(fw_cmd));
  3088. if (ret_val != 0)
  3089. continue;
  3090. if (fw_cmd.hdr.cmd_or_resp.ret_status ==
  3091. FW_CEM_RESP_STATUS_SUCCESS)
  3092. ret_val = 0;
  3093. else
  3094. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3095. break;
  3096. }
  3097. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
  3098. out:
  3099. return ret_val;
  3100. }
  3101. /**
  3102. * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
  3103. * @hw: pointer to the hardware structure
  3104. *
  3105. * The 82599 and x540 MACs can experience issues if TX work is still pending
  3106. * when a reset occurs. This function prevents this by flushing the PCIe
  3107. * buffers on the system.
  3108. **/
  3109. void ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
  3110. {
  3111. u32 gcr_ext, hlreg0;
  3112. /*
  3113. * If double reset is not requested then all transactions should
  3114. * already be clear and as such there is no work to do
  3115. */
  3116. if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
  3117. return;
  3118. /*
  3119. * Set loopback enable to prevent any transmits from being sent
  3120. * should the link come up. This assumes that the RXCTRL.RXEN bit
  3121. * has already been cleared.
  3122. */
  3123. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3124. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
  3125. /* initiate cleaning flow for buffers in the PCIe transaction layer */
  3126. gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  3127. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
  3128. gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
  3129. /* Flush all writes and allow 20usec for all transactions to clear */
  3130. IXGBE_WRITE_FLUSH(hw);
  3131. udelay(20);
  3132. /* restore previous register values */
  3133. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3134. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3135. }
  3136. static const u8 ixgbe_emc_temp_data[4] = {
  3137. IXGBE_EMC_INTERNAL_DATA,
  3138. IXGBE_EMC_DIODE1_DATA,
  3139. IXGBE_EMC_DIODE2_DATA,
  3140. IXGBE_EMC_DIODE3_DATA
  3141. };
  3142. static const u8 ixgbe_emc_therm_limit[4] = {
  3143. IXGBE_EMC_INTERNAL_THERM_LIMIT,
  3144. IXGBE_EMC_DIODE1_THERM_LIMIT,
  3145. IXGBE_EMC_DIODE2_THERM_LIMIT,
  3146. IXGBE_EMC_DIODE3_THERM_LIMIT
  3147. };
  3148. /**
  3149. * ixgbe_get_ets_data - Extracts the ETS bit data
  3150. * @hw: pointer to hardware structure
  3151. * @ets_cfg: extected ETS data
  3152. * @ets_offset: offset of ETS data
  3153. *
  3154. * Returns error code.
  3155. **/
  3156. static s32 ixgbe_get_ets_data(struct ixgbe_hw *hw, u16 *ets_cfg,
  3157. u16 *ets_offset)
  3158. {
  3159. s32 status = 0;
  3160. status = hw->eeprom.ops.read(hw, IXGBE_ETS_CFG, ets_offset);
  3161. if (status)
  3162. goto out;
  3163. if ((*ets_offset == 0x0000) || (*ets_offset == 0xFFFF)) {
  3164. status = IXGBE_NOT_IMPLEMENTED;
  3165. goto out;
  3166. }
  3167. status = hw->eeprom.ops.read(hw, *ets_offset, ets_cfg);
  3168. if (status)
  3169. goto out;
  3170. if ((*ets_cfg & IXGBE_ETS_TYPE_MASK) != IXGBE_ETS_TYPE_EMC_SHIFTED) {
  3171. status = IXGBE_NOT_IMPLEMENTED;
  3172. goto out;
  3173. }
  3174. out:
  3175. return status;
  3176. }
  3177. /**
  3178. * ixgbe_get_thermal_sensor_data - Gathers thermal sensor data
  3179. * @hw: pointer to hardware structure
  3180. *
  3181. * Returns the thermal sensor data structure
  3182. **/
  3183. s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw)
  3184. {
  3185. s32 status = 0;
  3186. u16 ets_offset;
  3187. u16 ets_cfg;
  3188. u16 ets_sensor;
  3189. u8 num_sensors;
  3190. u8 i;
  3191. struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  3192. /* Only support thermal sensors attached to physical port 0 */
  3193. if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
  3194. status = IXGBE_NOT_IMPLEMENTED;
  3195. goto out;
  3196. }
  3197. status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
  3198. if (status)
  3199. goto out;
  3200. num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
  3201. if (num_sensors > IXGBE_MAX_SENSORS)
  3202. num_sensors = IXGBE_MAX_SENSORS;
  3203. for (i = 0; i < num_sensors; i++) {
  3204. u8 sensor_index;
  3205. u8 sensor_location;
  3206. status = hw->eeprom.ops.read(hw, (ets_offset + 1 + i),
  3207. &ets_sensor);
  3208. if (status)
  3209. goto out;
  3210. sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
  3211. IXGBE_ETS_DATA_INDEX_SHIFT);
  3212. sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
  3213. IXGBE_ETS_DATA_LOC_SHIFT);
  3214. if (sensor_location != 0) {
  3215. status = hw->phy.ops.read_i2c_byte(hw,
  3216. ixgbe_emc_temp_data[sensor_index],
  3217. IXGBE_I2C_THERMAL_SENSOR_ADDR,
  3218. &data->sensor[i].temp);
  3219. if (status)
  3220. goto out;
  3221. }
  3222. }
  3223. out:
  3224. return status;
  3225. }
  3226. /**
  3227. * ixgbe_init_thermal_sensor_thresh_generic - Inits thermal sensor thresholds
  3228. * @hw: pointer to hardware structure
  3229. *
  3230. * Inits the thermal sensor thresholds according to the NVM map
  3231. * and save off the threshold and location values into mac.thermal_sensor_data
  3232. **/
  3233. s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
  3234. {
  3235. s32 status = 0;
  3236. u16 ets_offset;
  3237. u16 ets_cfg;
  3238. u16 ets_sensor;
  3239. u8 low_thresh_delta;
  3240. u8 num_sensors;
  3241. u8 therm_limit;
  3242. u8 i;
  3243. struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  3244. memset(data, 0, sizeof(struct ixgbe_thermal_sensor_data));
  3245. /* Only support thermal sensors attached to physical port 0 */
  3246. if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
  3247. status = IXGBE_NOT_IMPLEMENTED;
  3248. goto out;
  3249. }
  3250. status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
  3251. if (status)
  3252. goto out;
  3253. low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >>
  3254. IXGBE_ETS_LTHRES_DELTA_SHIFT);
  3255. num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
  3256. if (num_sensors > IXGBE_MAX_SENSORS)
  3257. num_sensors = IXGBE_MAX_SENSORS;
  3258. for (i = 0; i < num_sensors; i++) {
  3259. u8 sensor_index;
  3260. u8 sensor_location;
  3261. hw->eeprom.ops.read(hw, (ets_offset + 1 + i), &ets_sensor);
  3262. sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
  3263. IXGBE_ETS_DATA_INDEX_SHIFT);
  3264. sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
  3265. IXGBE_ETS_DATA_LOC_SHIFT);
  3266. therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK;
  3267. hw->phy.ops.write_i2c_byte(hw,
  3268. ixgbe_emc_therm_limit[sensor_index],
  3269. IXGBE_I2C_THERMAL_SENSOR_ADDR, therm_limit);
  3270. if (sensor_location == 0)
  3271. continue;
  3272. data->sensor[i].location = sensor_location;
  3273. data->sensor[i].caution_thresh = therm_limit;
  3274. data->sensor[i].max_op_thresh = therm_limit - low_thresh_delta;
  3275. }
  3276. out:
  3277. return status;
  3278. }