ixgbe_common.c 102 KB

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