ixgbe_common.c 116 KB

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