ixgbe_common.c 119 KB

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