ixgbe_common.c 119 KB

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