ixgbe_common.c 117 KB

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