ixgbe_common.c 104 KB

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