ixgbe_common.c 103 KB

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