qib_iba7322.c 264 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506
  1. /*
  2. * Copyright (c) 2012 - 2017 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2008 - 2012 QLogic Corporation. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. /*
  34. * This file contains all of the code that is specific to the
  35. * InfiniPath 7322 chip
  36. */
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/io.h>
  41. #include <linux/jiffies.h>
  42. #include <linux/module.h>
  43. #include <rdma/ib_verbs.h>
  44. #include <rdma/ib_smi.h>
  45. #ifdef CONFIG_INFINIBAND_QIB_DCA
  46. #include <linux/dca.h>
  47. #endif
  48. #include "qib.h"
  49. #include "qib_7322_regs.h"
  50. #include "qib_qsfp.h"
  51. #include "qib_mad.h"
  52. #include "qib_verbs.h"
  53. #undef pr_fmt
  54. #define pr_fmt(fmt) QIB_DRV_NAME " " fmt
  55. static void qib_setup_7322_setextled(struct qib_pportdata *, u32);
  56. static void qib_7322_handle_hwerrors(struct qib_devdata *, char *, size_t);
  57. static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op);
  58. static irqreturn_t qib_7322intr(int irq, void *data);
  59. static irqreturn_t qib_7322bufavail(int irq, void *data);
  60. static irqreturn_t sdma_intr(int irq, void *data);
  61. static irqreturn_t sdma_idle_intr(int irq, void *data);
  62. static irqreturn_t sdma_progress_intr(int irq, void *data);
  63. static irqreturn_t sdma_cleanup_intr(int irq, void *data);
  64. static void qib_7322_txchk_change(struct qib_devdata *, u32, u32, u32,
  65. struct qib_ctxtdata *rcd);
  66. static u8 qib_7322_phys_portstate(u64);
  67. static u32 qib_7322_iblink_state(u64);
  68. static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  69. u16 linitcmd);
  70. static void force_h1(struct qib_pportdata *);
  71. static void adj_tx_serdes(struct qib_pportdata *);
  72. static u32 qib_7322_setpbc_control(struct qib_pportdata *, u32, u8, u8);
  73. static void qib_7322_mini_pcs_reset(struct qib_pportdata *);
  74. static u32 ahb_mod(struct qib_devdata *, int, int, int, u32, u32);
  75. static void ibsd_wr_allchans(struct qib_pportdata *, int, unsigned, unsigned);
  76. static void serdes_7322_los_enable(struct qib_pportdata *, int);
  77. static int serdes_7322_init_old(struct qib_pportdata *);
  78. static int serdes_7322_init_new(struct qib_pportdata *);
  79. static void dump_sdma_7322_state(struct qib_pportdata *);
  80. #define BMASK(msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb))
  81. /* LE2 serdes values for different cases */
  82. #define LE2_DEFAULT 5
  83. #define LE2_5m 4
  84. #define LE2_QME 0
  85. /* Below is special-purpose, so only really works for the IB SerDes blocks. */
  86. #define IBSD(hw_pidx) (hw_pidx + 2)
  87. /* these are variables for documentation and experimentation purposes */
  88. static const unsigned rcv_int_timeout = 375;
  89. static const unsigned rcv_int_count = 16;
  90. static const unsigned sdma_idle_cnt = 64;
  91. /* Time to stop altering Rx Equalization parameters, after link up. */
  92. #define RXEQ_DISABLE_MSECS 2500
  93. /*
  94. * Number of VLs we are configured to use (to allow for more
  95. * credits per vl, etc.)
  96. */
  97. ushort qib_num_cfg_vls = 2;
  98. module_param_named(num_vls, qib_num_cfg_vls, ushort, S_IRUGO);
  99. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  100. static ushort qib_chase = 1;
  101. module_param_named(chase, qib_chase, ushort, S_IRUGO);
  102. MODULE_PARM_DESC(chase, "Enable state chase handling");
  103. static ushort qib_long_atten = 10; /* 10 dB ~= 5m length */
  104. module_param_named(long_attenuation, qib_long_atten, ushort, S_IRUGO);
  105. MODULE_PARM_DESC(long_attenuation,
  106. "attenuation cutoff (dB) for long copper cable setup");
  107. static ushort qib_singleport;
  108. module_param_named(singleport, qib_singleport, ushort, S_IRUGO);
  109. MODULE_PARM_DESC(singleport, "Use only IB port 1; more per-port buffer space");
  110. static ushort qib_krcvq01_no_msi;
  111. module_param_named(krcvq01_no_msi, qib_krcvq01_no_msi, ushort, S_IRUGO);
  112. MODULE_PARM_DESC(krcvq01_no_msi, "No MSI for kctx < 2");
  113. /*
  114. * Receive header queue sizes
  115. */
  116. static unsigned qib_rcvhdrcnt;
  117. module_param_named(rcvhdrcnt, qib_rcvhdrcnt, uint, S_IRUGO);
  118. MODULE_PARM_DESC(rcvhdrcnt, "receive header count");
  119. static unsigned qib_rcvhdrsize;
  120. module_param_named(rcvhdrsize, qib_rcvhdrsize, uint, S_IRUGO);
  121. MODULE_PARM_DESC(rcvhdrsize, "receive header size in 32-bit words");
  122. static unsigned qib_rcvhdrentsize;
  123. module_param_named(rcvhdrentsize, qib_rcvhdrentsize, uint, S_IRUGO);
  124. MODULE_PARM_DESC(rcvhdrentsize, "receive header entry size in 32-bit words");
  125. #define MAX_ATTEN_LEN 64 /* plenty for any real system */
  126. /* for read back, default index is ~5m copper cable */
  127. static char txselect_list[MAX_ATTEN_LEN] = "10";
  128. static struct kparam_string kp_txselect = {
  129. .string = txselect_list,
  130. .maxlen = MAX_ATTEN_LEN
  131. };
  132. static int setup_txselect(const char *, const struct kernel_param *);
  133. module_param_call(txselect, setup_txselect, param_get_string,
  134. &kp_txselect, S_IWUSR | S_IRUGO);
  135. MODULE_PARM_DESC(txselect,
  136. "Tx serdes indices (for no QSFP or invalid QSFP data)");
  137. #define BOARD_QME7342 5
  138. #define BOARD_QMH7342 6
  139. #define BOARD_QMH7360 9
  140. #define IS_QMH(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
  141. BOARD_QMH7342)
  142. #define IS_QME(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
  143. BOARD_QME7342)
  144. #define KREG_IDX(regname) (QIB_7322_##regname##_OFFS / sizeof(u64))
  145. #define KREG_IBPORT_IDX(regname) ((QIB_7322_##regname##_0_OFFS / sizeof(u64)))
  146. #define MASK_ACROSS(lsb, msb) \
  147. (((1ULL << ((msb) + 1 - (lsb))) - 1) << (lsb))
  148. #define SYM_RMASK(regname, fldname) ((u64) \
  149. QIB_7322_##regname##_##fldname##_RMASK)
  150. #define SYM_MASK(regname, fldname) ((u64) \
  151. QIB_7322_##regname##_##fldname##_RMASK << \
  152. QIB_7322_##regname##_##fldname##_LSB)
  153. #define SYM_FIELD(value, regname, fldname) ((u64) \
  154. (((value) >> SYM_LSB(regname, fldname)) & \
  155. SYM_RMASK(regname, fldname)))
  156. /* useful for things like LaFifoEmpty_0...7, TxCreditOK_0...7, etc. */
  157. #define SYM_FIELD_ACROSS(value, regname, fldname, nbits) \
  158. (((value) >> SYM_LSB(regname, fldname)) & MASK_ACROSS(0, nbits))
  159. #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
  160. #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
  161. #define ERR_MASK_N(fldname) SYM_MASK(ErrMask_0, fldname##Mask)
  162. #define INT_MASK(fldname) SYM_MASK(IntMask, fldname##IntMask)
  163. #define INT_MASK_P(fldname, port) SYM_MASK(IntMask, fldname##IntMask##_##port)
  164. /* Below because most, but not all, fields of IntMask have that full suffix */
  165. #define INT_MASK_PM(fldname, port) SYM_MASK(IntMask, fldname##Mask##_##port)
  166. #define SYM_LSB(regname, fldname) (QIB_7322_##regname##_##fldname##_LSB)
  167. /*
  168. * the size bits give us 2^N, in KB units. 0 marks as invalid,
  169. * and 7 is reserved. We currently use only 2KB and 4KB
  170. */
  171. #define IBA7322_TID_SZ_SHIFT QIB_7322_RcvTIDArray0_RT_BufSize_LSB
  172. #define IBA7322_TID_SZ_2K (1UL<<IBA7322_TID_SZ_SHIFT) /* 2KB */
  173. #define IBA7322_TID_SZ_4K (2UL<<IBA7322_TID_SZ_SHIFT) /* 4KB */
  174. #define IBA7322_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
  175. #define SendIBSLIDAssignMask \
  176. QIB_7322_SendIBSLIDAssign_0_SendIBSLIDAssign_15_0_RMASK
  177. #define SendIBSLMCMask \
  178. QIB_7322_SendIBSLIDMask_0_SendIBSLIDMask_15_0_RMASK
  179. #define ExtLED_IB1_YEL SYM_MASK(EXTCtrl, LEDPort0YellowOn)
  180. #define ExtLED_IB1_GRN SYM_MASK(EXTCtrl, LEDPort0GreenOn)
  181. #define ExtLED_IB2_YEL SYM_MASK(EXTCtrl, LEDPort1YellowOn)
  182. #define ExtLED_IB2_GRN SYM_MASK(EXTCtrl, LEDPort1GreenOn)
  183. #define ExtLED_IB1_MASK (ExtLED_IB1_YEL | ExtLED_IB1_GRN)
  184. #define ExtLED_IB2_MASK (ExtLED_IB2_YEL | ExtLED_IB2_GRN)
  185. #define _QIB_GPIO_SDA_NUM 1
  186. #define _QIB_GPIO_SCL_NUM 0
  187. #define QIB_EEPROM_WEN_NUM 14
  188. #define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7322 cards. */
  189. /* HW counter clock is at 4nsec */
  190. #define QIB_7322_PSXMITWAIT_CHECK_RATE 4000
  191. /* full speed IB port 1 only */
  192. #define PORT_SPD_CAP (QIB_IB_SDR | QIB_IB_DDR | QIB_IB_QDR)
  193. #define PORT_SPD_CAP_SHIFT 3
  194. /* full speed featuremask, both ports */
  195. #define DUAL_PORT_CAP (PORT_SPD_CAP | (PORT_SPD_CAP << PORT_SPD_CAP_SHIFT))
  196. /*
  197. * This file contains almost all the chip-specific register information and
  198. * access functions for the FAKED QLogic InfiniPath 7322 PCI-Express chip.
  199. */
  200. /* Use defines to tie machine-generated names to lower-case names */
  201. #define kr_contextcnt KREG_IDX(ContextCnt)
  202. #define kr_control KREG_IDX(Control)
  203. #define kr_counterregbase KREG_IDX(CntrRegBase)
  204. #define kr_errclear KREG_IDX(ErrClear)
  205. #define kr_errmask KREG_IDX(ErrMask)
  206. #define kr_errstatus KREG_IDX(ErrStatus)
  207. #define kr_extctrl KREG_IDX(EXTCtrl)
  208. #define kr_extstatus KREG_IDX(EXTStatus)
  209. #define kr_gpio_clear KREG_IDX(GPIOClear)
  210. #define kr_gpio_mask KREG_IDX(GPIOMask)
  211. #define kr_gpio_out KREG_IDX(GPIOOut)
  212. #define kr_gpio_status KREG_IDX(GPIOStatus)
  213. #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
  214. #define kr_debugportval KREG_IDX(DebugPortValueReg)
  215. #define kr_fmask KREG_IDX(feature_mask)
  216. #define kr_act_fmask KREG_IDX(active_feature_mask)
  217. #define kr_hwerrclear KREG_IDX(HwErrClear)
  218. #define kr_hwerrmask KREG_IDX(HwErrMask)
  219. #define kr_hwerrstatus KREG_IDX(HwErrStatus)
  220. #define kr_intclear KREG_IDX(IntClear)
  221. #define kr_intmask KREG_IDX(IntMask)
  222. #define kr_intredirect KREG_IDX(IntRedirect0)
  223. #define kr_intstatus KREG_IDX(IntStatus)
  224. #define kr_pagealign KREG_IDX(PageAlign)
  225. #define kr_rcvavailtimeout KREG_IDX(RcvAvailTimeOut0)
  226. #define kr_rcvctrl KREG_IDX(RcvCtrl) /* Common, but chip also has per-port */
  227. #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
  228. #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
  229. #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
  230. #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
  231. #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
  232. #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
  233. #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
  234. #define kr_revision KREG_IDX(Revision)
  235. #define kr_scratch KREG_IDX(Scratch)
  236. #define kr_sendbuffererror KREG_IDX(SendBufErr0) /* and base for 1 and 2 */
  237. #define kr_sendcheckmask KREG_IDX(SendCheckMask0) /* and 1, 2 */
  238. #define kr_sendctrl KREG_IDX(SendCtrl)
  239. #define kr_sendgrhcheckmask KREG_IDX(SendGRHCheckMask0) /* and 1, 2 */
  240. #define kr_sendibpktmask KREG_IDX(SendIBPacketMask0) /* and 1, 2 */
  241. #define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
  242. #define kr_sendpiobufbase KREG_IDX(SendBufBase)
  243. #define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
  244. #define kr_sendpiosize KREG_IDX(SendBufSize)
  245. #define kr_sendregbase KREG_IDX(SendRegBase)
  246. #define kr_sendbufavail0 KREG_IDX(SendBufAvail0)
  247. #define kr_userregbase KREG_IDX(UserRegBase)
  248. #define kr_intgranted KREG_IDX(Int_Granted)
  249. #define kr_vecclr_wo_int KREG_IDX(vec_clr_without_int)
  250. #define kr_intblocked KREG_IDX(IntBlocked)
  251. #define kr_r_access KREG_IDX(SPC_JTAG_ACCESS_REG)
  252. /*
  253. * per-port kernel registers. Access only with qib_read_kreg_port()
  254. * or qib_write_kreg_port()
  255. */
  256. #define krp_errclear KREG_IBPORT_IDX(ErrClear)
  257. #define krp_errmask KREG_IBPORT_IDX(ErrMask)
  258. #define krp_errstatus KREG_IBPORT_IDX(ErrStatus)
  259. #define krp_highprio_0 KREG_IBPORT_IDX(HighPriority0)
  260. #define krp_highprio_limit KREG_IBPORT_IDX(HighPriorityLimit)
  261. #define krp_hrtbt_guid KREG_IBPORT_IDX(HRTBT_GUID)
  262. #define krp_ib_pcsconfig KREG_IBPORT_IDX(IBPCSConfig)
  263. #define krp_ibcctrl_a KREG_IBPORT_IDX(IBCCtrlA)
  264. #define krp_ibcctrl_b KREG_IBPORT_IDX(IBCCtrlB)
  265. #define krp_ibcctrl_c KREG_IBPORT_IDX(IBCCtrlC)
  266. #define krp_ibcstatus_a KREG_IBPORT_IDX(IBCStatusA)
  267. #define krp_ibcstatus_b KREG_IBPORT_IDX(IBCStatusB)
  268. #define krp_txestatus KREG_IBPORT_IDX(TXEStatus)
  269. #define krp_lowprio_0 KREG_IBPORT_IDX(LowPriority0)
  270. #define krp_ncmodectrl KREG_IBPORT_IDX(IBNCModeCtrl)
  271. #define krp_partitionkey KREG_IBPORT_IDX(RcvPartitionKey)
  272. #define krp_psinterval KREG_IBPORT_IDX(PSInterval)
  273. #define krp_psstart KREG_IBPORT_IDX(PSStart)
  274. #define krp_psstat KREG_IBPORT_IDX(PSStat)
  275. #define krp_rcvbthqp KREG_IBPORT_IDX(RcvBTHQP)
  276. #define krp_rcvctrl KREG_IBPORT_IDX(RcvCtrl)
  277. #define krp_rcvpktledcnt KREG_IBPORT_IDX(RcvPktLEDCnt)
  278. #define krp_rcvqpmaptable KREG_IBPORT_IDX(RcvQPMapTableA)
  279. #define krp_rxcreditvl0 KREG_IBPORT_IDX(RxCreditVL0)
  280. #define krp_rxcreditvl15 (KREG_IBPORT_IDX(RxCreditVL0)+15)
  281. #define krp_sendcheckcontrol KREG_IBPORT_IDX(SendCheckControl)
  282. #define krp_sendctrl KREG_IBPORT_IDX(SendCtrl)
  283. #define krp_senddmabase KREG_IBPORT_IDX(SendDmaBase)
  284. #define krp_senddmabufmask0 KREG_IBPORT_IDX(SendDmaBufMask0)
  285. #define krp_senddmabufmask1 (KREG_IBPORT_IDX(SendDmaBufMask0) + 1)
  286. #define krp_senddmabufmask2 (KREG_IBPORT_IDX(SendDmaBufMask0) + 2)
  287. #define krp_senddmabuf_use0 KREG_IBPORT_IDX(SendDmaBufUsed0)
  288. #define krp_senddmabuf_use1 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 1)
  289. #define krp_senddmabuf_use2 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 2)
  290. #define krp_senddmadesccnt KREG_IBPORT_IDX(SendDmaDescCnt)
  291. #define krp_senddmahead KREG_IBPORT_IDX(SendDmaHead)
  292. #define krp_senddmaheadaddr KREG_IBPORT_IDX(SendDmaHeadAddr)
  293. #define krp_senddmaidlecnt KREG_IBPORT_IDX(SendDmaIdleCnt)
  294. #define krp_senddmalengen KREG_IBPORT_IDX(SendDmaLenGen)
  295. #define krp_senddmaprioritythld KREG_IBPORT_IDX(SendDmaPriorityThld)
  296. #define krp_senddmareloadcnt KREG_IBPORT_IDX(SendDmaReloadCnt)
  297. #define krp_senddmastatus KREG_IBPORT_IDX(SendDmaStatus)
  298. #define krp_senddmatail KREG_IBPORT_IDX(SendDmaTail)
  299. #define krp_sendhdrsymptom KREG_IBPORT_IDX(SendHdrErrSymptom)
  300. #define krp_sendslid KREG_IBPORT_IDX(SendIBSLIDAssign)
  301. #define krp_sendslidmask KREG_IBPORT_IDX(SendIBSLIDMask)
  302. #define krp_ibsdtestiftx KREG_IBPORT_IDX(IB_SDTEST_IF_TX)
  303. #define krp_adapt_dis_timer KREG_IBPORT_IDX(ADAPT_DISABLE_TIMER_THRESHOLD)
  304. #define krp_tx_deemph_override KREG_IBPORT_IDX(IBSD_TX_DEEMPHASIS_OVERRIDE)
  305. #define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
  306. /*
  307. * Per-context kernel registers. Access only with qib_read_kreg_ctxt()
  308. * or qib_write_kreg_ctxt()
  309. */
  310. #define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
  311. #define krc_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
  312. /*
  313. * TID Flow table, per context. Reduces
  314. * number of hdrq updates to one per flow (or on errors).
  315. * context 0 and 1 share same memory, but have distinct
  316. * addresses. Since for now, we never use expected sends
  317. * on kernel contexts, we don't worry about that (we initialize
  318. * those entries for ctxt 0/1 on driver load twice, for example).
  319. */
  320. #define NUM_TIDFLOWS_CTXT 0x20 /* 0x20 per context; have to hardcode */
  321. #define ur_rcvflowtable (KREG_IDX(RcvTIDFlowTable0) - KREG_IDX(RcvHdrTail0))
  322. /* these are the error bits in the tid flows, and are W1C */
  323. #define TIDFLOW_ERRBITS ( \
  324. (SYM_MASK(RcvTIDFlowTable0, GenMismatch) << \
  325. SYM_LSB(RcvTIDFlowTable0, GenMismatch)) | \
  326. (SYM_MASK(RcvTIDFlowTable0, SeqMismatch) << \
  327. SYM_LSB(RcvTIDFlowTable0, SeqMismatch)))
  328. /* Most (not all) Counters are per-IBport.
  329. * Requires LBIntCnt is at offset 0 in the group
  330. */
  331. #define CREG_IDX(regname) \
  332. ((QIB_7322_##regname##_0_OFFS - QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
  333. #define crp_badformat CREG_IDX(RxVersionErrCnt)
  334. #define crp_err_rlen CREG_IDX(RxLenErrCnt)
  335. #define crp_erricrc CREG_IDX(RxICRCErrCnt)
  336. #define crp_errlink CREG_IDX(RxLinkMalformCnt)
  337. #define crp_errlpcrc CREG_IDX(RxLPCRCErrCnt)
  338. #define crp_errpkey CREG_IDX(RxPKeyMismatchCnt)
  339. #define crp_errvcrc CREG_IDX(RxVCRCErrCnt)
  340. #define crp_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
  341. #define crp_iblinkdown CREG_IDX(IBLinkDownedCnt)
  342. #define crp_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
  343. #define crp_ibstatuschange CREG_IDX(IBStatusChangeCnt)
  344. #define crp_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
  345. #define crp_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
  346. #define crp_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
  347. #define crp_pktrcv CREG_IDX(RxDataPktCnt)
  348. #define crp_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
  349. #define crp_pktsend CREG_IDX(TxDataPktCnt)
  350. #define crp_pktsendflow CREG_IDX(TxFlowPktCnt)
  351. #define crp_psrcvdatacount CREG_IDX(PSRcvDataCount)
  352. #define crp_psrcvpktscount CREG_IDX(PSRcvPktsCount)
  353. #define crp_psxmitdatacount CREG_IDX(PSXmitDataCount)
  354. #define crp_psxmitpktscount CREG_IDX(PSXmitPktsCount)
  355. #define crp_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
  356. #define crp_rcvebp CREG_IDX(RxEBPCnt)
  357. #define crp_rcvflowctrlviol CREG_IDX(RxFlowCtrlViolCnt)
  358. #define crp_rcvovfl CREG_IDX(RxBufOvflCnt)
  359. #define crp_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
  360. #define crp_rxdroppkt CREG_IDX(RxDroppedPktCnt)
  361. #define crp_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
  362. #define crp_rxqpinvalidctxt CREG_IDX(RxQPInvalidContextCnt)
  363. #define crp_rxvlerr CREG_IDX(RxVlErrCnt)
  364. #define crp_sendstall CREG_IDX(TxFlowStallCnt)
  365. #define crp_txdroppedpkt CREG_IDX(TxDroppedPktCnt)
  366. #define crp_txhdrerr CREG_IDX(TxHeadersErrCnt)
  367. #define crp_txlenerr CREG_IDX(TxLenErrCnt)
  368. #define crp_txminmaxlenerr CREG_IDX(TxMaxMinLenErrCnt)
  369. #define crp_txsdmadesc CREG_IDX(TxSDmaDescCnt)
  370. #define crp_txunderrun CREG_IDX(TxUnderrunCnt)
  371. #define crp_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
  372. #define crp_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
  373. #define crp_wordrcv CREG_IDX(RxDwordCnt)
  374. #define crp_wordsend CREG_IDX(TxDwordCnt)
  375. #define crp_tx_creditstalls CREG_IDX(TxCreditUpToDateTimeOut)
  376. /* these are the (few) counters that are not port-specific */
  377. #define CREG_DEVIDX(regname) ((QIB_7322_##regname##_OFFS - \
  378. QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
  379. #define cr_base_egrovfl CREG_DEVIDX(RxP0HdrEgrOvflCnt)
  380. #define cr_lbint CREG_DEVIDX(LBIntCnt)
  381. #define cr_lbstall CREG_DEVIDX(LBFlowStallCnt)
  382. #define cr_pcieretrydiag CREG_DEVIDX(PcieRetryBufDiagQwordCnt)
  383. #define cr_rxtidflowdrop CREG_DEVIDX(RxTidFlowDropCnt)
  384. #define cr_tidfull CREG_DEVIDX(RxTIDFullErrCnt)
  385. #define cr_tidinvalid CREG_DEVIDX(RxTIDValidErrCnt)
  386. /* no chip register for # of IB ports supported, so define */
  387. #define NUM_IB_PORTS 2
  388. /* 1 VL15 buffer per hardware IB port, no register for this, so define */
  389. #define NUM_VL15_BUFS NUM_IB_PORTS
  390. /*
  391. * context 0 and 1 are special, and there is no chip register that
  392. * defines this value, so we have to define it here.
  393. * These are all allocated to either 0 or 1 for single port
  394. * hardware configuration, otherwise each gets half
  395. */
  396. #define KCTXT0_EGRCNT 2048
  397. /* values for vl and port fields in PBC, 7322-specific */
  398. #define PBC_PORT_SEL_LSB 26
  399. #define PBC_PORT_SEL_RMASK 1
  400. #define PBC_VL_NUM_LSB 27
  401. #define PBC_VL_NUM_RMASK 7
  402. #define PBC_7322_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
  403. #define PBC_7322_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
  404. static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
  405. [IB_RATE_2_5_GBPS] = 16,
  406. [IB_RATE_5_GBPS] = 8,
  407. [IB_RATE_10_GBPS] = 4,
  408. [IB_RATE_20_GBPS] = 2,
  409. [IB_RATE_30_GBPS] = 2,
  410. [IB_RATE_40_GBPS] = 1
  411. };
  412. static const char * const qib_sdma_state_names[] = {
  413. [qib_sdma_state_s00_hw_down] = "s00_HwDown",
  414. [qib_sdma_state_s10_hw_start_up_wait] = "s10_HwStartUpWait",
  415. [qib_sdma_state_s20_idle] = "s20_Idle",
  416. [qib_sdma_state_s30_sw_clean_up_wait] = "s30_SwCleanUpWait",
  417. [qib_sdma_state_s40_hw_clean_up_wait] = "s40_HwCleanUpWait",
  418. [qib_sdma_state_s50_hw_halt_wait] = "s50_HwHaltWait",
  419. [qib_sdma_state_s99_running] = "s99_Running",
  420. };
  421. #define IBA7322_LINKSPEED_SHIFT SYM_LSB(IBCStatusA_0, LinkSpeedActive)
  422. #define IBA7322_LINKWIDTH_SHIFT SYM_LSB(IBCStatusA_0, LinkWidthActive)
  423. /* link training states, from IBC */
  424. #define IB_7322_LT_STATE_DISABLED 0x00
  425. #define IB_7322_LT_STATE_LINKUP 0x01
  426. #define IB_7322_LT_STATE_POLLACTIVE 0x02
  427. #define IB_7322_LT_STATE_POLLQUIET 0x03
  428. #define IB_7322_LT_STATE_SLEEPDELAY 0x04
  429. #define IB_7322_LT_STATE_SLEEPQUIET 0x05
  430. #define IB_7322_LT_STATE_CFGDEBOUNCE 0x08
  431. #define IB_7322_LT_STATE_CFGRCVFCFG 0x09
  432. #define IB_7322_LT_STATE_CFGWAITRMT 0x0a
  433. #define IB_7322_LT_STATE_CFGIDLE 0x0b
  434. #define IB_7322_LT_STATE_RECOVERRETRAIN 0x0c
  435. #define IB_7322_LT_STATE_TXREVLANES 0x0d
  436. #define IB_7322_LT_STATE_RECOVERWAITRMT 0x0e
  437. #define IB_7322_LT_STATE_RECOVERIDLE 0x0f
  438. #define IB_7322_LT_STATE_CFGENH 0x10
  439. #define IB_7322_LT_STATE_CFGTEST 0x11
  440. #define IB_7322_LT_STATE_CFGWAITRMTTEST 0x12
  441. #define IB_7322_LT_STATE_CFGWAITENH 0x13
  442. /* link state machine states from IBC */
  443. #define IB_7322_L_STATE_DOWN 0x0
  444. #define IB_7322_L_STATE_INIT 0x1
  445. #define IB_7322_L_STATE_ARM 0x2
  446. #define IB_7322_L_STATE_ACTIVE 0x3
  447. #define IB_7322_L_STATE_ACT_DEFER 0x4
  448. static const u8 qib_7322_physportstate[0x20] = {
  449. [IB_7322_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
  450. [IB_7322_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
  451. [IB_7322_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
  452. [IB_7322_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
  453. [IB_7322_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
  454. [IB_7322_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
  455. [IB_7322_LT_STATE_CFGDEBOUNCE] = IB_PHYSPORTSTATE_CFG_TRAIN,
  456. [IB_7322_LT_STATE_CFGRCVFCFG] =
  457. IB_PHYSPORTSTATE_CFG_TRAIN,
  458. [IB_7322_LT_STATE_CFGWAITRMT] =
  459. IB_PHYSPORTSTATE_CFG_TRAIN,
  460. [IB_7322_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_IDLE,
  461. [IB_7322_LT_STATE_RECOVERRETRAIN] =
  462. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  463. [IB_7322_LT_STATE_RECOVERWAITRMT] =
  464. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  465. [IB_7322_LT_STATE_RECOVERIDLE] =
  466. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  467. [IB_7322_LT_STATE_CFGENH] = IB_PHYSPORTSTATE_CFG_ENH,
  468. [IB_7322_LT_STATE_CFGTEST] = IB_PHYSPORTSTATE_CFG_TRAIN,
  469. [IB_7322_LT_STATE_CFGWAITRMTTEST] =
  470. IB_PHYSPORTSTATE_CFG_TRAIN,
  471. [IB_7322_LT_STATE_CFGWAITENH] =
  472. IB_PHYSPORTSTATE_CFG_WAIT_ENH,
  473. [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
  474. [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
  475. [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
  476. [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
  477. };
  478. #ifdef CONFIG_INFINIBAND_QIB_DCA
  479. struct qib_irq_notify {
  480. int rcv;
  481. void *arg;
  482. struct irq_affinity_notify notify;
  483. };
  484. #endif
  485. struct qib_chip_specific {
  486. u64 __iomem *cregbase;
  487. u64 *cntrs;
  488. spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
  489. spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
  490. u64 main_int_mask; /* clear bits which have dedicated handlers */
  491. u64 int_enable_mask; /* for per port interrupts in single port mode */
  492. u64 errormask;
  493. u64 hwerrmask;
  494. u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
  495. u64 gpio_mask; /* shadow the gpio mask register */
  496. u64 extctrl; /* shadow the gpio output enable, etc... */
  497. u32 ncntrs;
  498. u32 nportcntrs;
  499. u32 cntrnamelen;
  500. u32 portcntrnamelen;
  501. u32 numctxts;
  502. u32 rcvegrcnt;
  503. u32 updthresh; /* current AvailUpdThld */
  504. u32 updthresh_dflt; /* default AvailUpdThld */
  505. u32 r1;
  506. u32 num_msix_entries;
  507. u32 sdmabufcnt;
  508. u32 lastbuf_for_pio;
  509. u32 stay_in_freeze;
  510. u32 recovery_ports_initted;
  511. #ifdef CONFIG_INFINIBAND_QIB_DCA
  512. u32 dca_ctrl;
  513. int rhdr_cpu[18];
  514. int sdma_cpu[2];
  515. u64 dca_rcvhdr_ctrl[5]; /* B, C, D, E, F */
  516. #endif
  517. struct qib_msix_entry *msix_entries;
  518. unsigned long *sendchkenable;
  519. unsigned long *sendgrhchk;
  520. unsigned long *sendibchk;
  521. u32 rcvavail_timeout[18];
  522. char emsgbuf[128]; /* for device error interrupt msg buffer */
  523. };
  524. /* Table of entries in "human readable" form Tx Emphasis. */
  525. struct txdds_ent {
  526. u8 amp;
  527. u8 pre;
  528. u8 main;
  529. u8 post;
  530. };
  531. struct vendor_txdds_ent {
  532. u8 oui[QSFP_VOUI_LEN];
  533. u8 *partnum;
  534. struct txdds_ent sdr;
  535. struct txdds_ent ddr;
  536. struct txdds_ent qdr;
  537. };
  538. static void write_tx_serdes_param(struct qib_pportdata *, struct txdds_ent *);
  539. #define TXDDS_TABLE_SZ 16 /* number of entries per speed in onchip table */
  540. #define TXDDS_EXTRA_SZ 18 /* number of extra tx settings entries */
  541. #define TXDDS_MFG_SZ 2 /* number of mfg tx settings entries */
  542. #define SERDES_CHANS 4 /* yes, it's obvious, but one less magic number */
  543. #define H1_FORCE_VAL 8
  544. #define H1_FORCE_QME 1 /* may be overridden via setup_txselect() */
  545. #define H1_FORCE_QMH 7 /* may be overridden via setup_txselect() */
  546. /* The static and dynamic registers are paired, and the pairs indexed by spd */
  547. #define krp_static_adapt_dis(spd) (KREG_IBPORT_IDX(ADAPT_DISABLE_STATIC_SDR) \
  548. + ((spd) * 2))
  549. #define QDR_DFE_DISABLE_DELAY 4000 /* msec after LINKUP */
  550. #define QDR_STATIC_ADAPT_DOWN 0xf0f0f0f0ULL /* link down, H1-H4 QDR adapts */
  551. #define QDR_STATIC_ADAPT_DOWN_R1 0ULL /* r1 link down, H1-H4 QDR adapts */
  552. #define QDR_STATIC_ADAPT_INIT 0xffffffffffULL /* up, disable H0,H1-8, LE */
  553. #define QDR_STATIC_ADAPT_INIT_R1 0xf0ffffffffULL /* r1 up, disable H0,H1-8 */
  554. struct qib_chippport_specific {
  555. u64 __iomem *kpregbase;
  556. u64 __iomem *cpregbase;
  557. u64 *portcntrs;
  558. struct qib_pportdata *ppd;
  559. wait_queue_head_t autoneg_wait;
  560. struct delayed_work autoneg_work;
  561. struct delayed_work ipg_work;
  562. struct timer_list chase_timer;
  563. /*
  564. * these 5 fields are used to establish deltas for IB symbol
  565. * errors and linkrecovery errors. They can be reported on
  566. * some chips during link negotiation prior to INIT, and with
  567. * DDR when faking DDR negotiations with non-IBTA switches.
  568. * The chip counters are adjusted at driver unload if there is
  569. * a non-zero delta.
  570. */
  571. u64 ibdeltainprog;
  572. u64 ibsymdelta;
  573. u64 ibsymsnap;
  574. u64 iblnkerrdelta;
  575. u64 iblnkerrsnap;
  576. u64 iblnkdownsnap;
  577. u64 iblnkdowndelta;
  578. u64 ibmalfdelta;
  579. u64 ibmalfsnap;
  580. u64 ibcctrl_a; /* krp_ibcctrl_a shadow */
  581. u64 ibcctrl_b; /* krp_ibcctrl_b shadow */
  582. unsigned long qdr_dfe_time;
  583. unsigned long chase_end;
  584. u32 autoneg_tries;
  585. u32 recovery_init;
  586. u32 qdr_dfe_on;
  587. u32 qdr_reforce;
  588. /*
  589. * Per-bay per-channel rcv QMH H1 values and Tx values for QDR.
  590. * entry zero is unused, to simplify indexing
  591. */
  592. u8 h1_val;
  593. u8 no_eep; /* txselect table index to use if no qsfp info */
  594. u8 ipg_tries;
  595. u8 ibmalfusesnap;
  596. struct qib_qsfp_data qsfp_data;
  597. char epmsgbuf[192]; /* for port error interrupt msg buffer */
  598. char sdmamsgbuf[192]; /* for per-port sdma error messages */
  599. };
  600. static struct {
  601. const char *name;
  602. irq_handler_t handler;
  603. int lsb;
  604. int port; /* 0 if not port-specific, else port # */
  605. int dca;
  606. } irq_table[] = {
  607. { "", qib_7322intr, -1, 0, 0 },
  608. { " (buf avail)", qib_7322bufavail,
  609. SYM_LSB(IntStatus, SendBufAvail), 0, 0},
  610. { " (sdma 0)", sdma_intr,
  611. SYM_LSB(IntStatus, SDmaInt_0), 1, 1 },
  612. { " (sdma 1)", sdma_intr,
  613. SYM_LSB(IntStatus, SDmaInt_1), 2, 1 },
  614. { " (sdmaI 0)", sdma_idle_intr,
  615. SYM_LSB(IntStatus, SDmaIdleInt_0), 1, 1},
  616. { " (sdmaI 1)", sdma_idle_intr,
  617. SYM_LSB(IntStatus, SDmaIdleInt_1), 2, 1},
  618. { " (sdmaP 0)", sdma_progress_intr,
  619. SYM_LSB(IntStatus, SDmaProgressInt_0), 1, 1 },
  620. { " (sdmaP 1)", sdma_progress_intr,
  621. SYM_LSB(IntStatus, SDmaProgressInt_1), 2, 1 },
  622. { " (sdmaC 0)", sdma_cleanup_intr,
  623. SYM_LSB(IntStatus, SDmaCleanupDone_0), 1, 0 },
  624. { " (sdmaC 1)", sdma_cleanup_intr,
  625. SYM_LSB(IntStatus, SDmaCleanupDone_1), 2 , 0},
  626. };
  627. #ifdef CONFIG_INFINIBAND_QIB_DCA
  628. static const struct dca_reg_map {
  629. int shadow_inx;
  630. int lsb;
  631. u64 mask;
  632. u16 regno;
  633. } dca_rcvhdr_reg_map[] = {
  634. { 0, SYM_LSB(DCACtrlB, RcvHdrq0DCAOPH),
  635. ~SYM_MASK(DCACtrlB, RcvHdrq0DCAOPH) , KREG_IDX(DCACtrlB) },
  636. { 0, SYM_LSB(DCACtrlB, RcvHdrq1DCAOPH),
  637. ~SYM_MASK(DCACtrlB, RcvHdrq1DCAOPH) , KREG_IDX(DCACtrlB) },
  638. { 0, SYM_LSB(DCACtrlB, RcvHdrq2DCAOPH),
  639. ~SYM_MASK(DCACtrlB, RcvHdrq2DCAOPH) , KREG_IDX(DCACtrlB) },
  640. { 0, SYM_LSB(DCACtrlB, RcvHdrq3DCAOPH),
  641. ~SYM_MASK(DCACtrlB, RcvHdrq3DCAOPH) , KREG_IDX(DCACtrlB) },
  642. { 1, SYM_LSB(DCACtrlC, RcvHdrq4DCAOPH),
  643. ~SYM_MASK(DCACtrlC, RcvHdrq4DCAOPH) , KREG_IDX(DCACtrlC) },
  644. { 1, SYM_LSB(DCACtrlC, RcvHdrq5DCAOPH),
  645. ~SYM_MASK(DCACtrlC, RcvHdrq5DCAOPH) , KREG_IDX(DCACtrlC) },
  646. { 1, SYM_LSB(DCACtrlC, RcvHdrq6DCAOPH),
  647. ~SYM_MASK(DCACtrlC, RcvHdrq6DCAOPH) , KREG_IDX(DCACtrlC) },
  648. { 1, SYM_LSB(DCACtrlC, RcvHdrq7DCAOPH),
  649. ~SYM_MASK(DCACtrlC, RcvHdrq7DCAOPH) , KREG_IDX(DCACtrlC) },
  650. { 2, SYM_LSB(DCACtrlD, RcvHdrq8DCAOPH),
  651. ~SYM_MASK(DCACtrlD, RcvHdrq8DCAOPH) , KREG_IDX(DCACtrlD) },
  652. { 2, SYM_LSB(DCACtrlD, RcvHdrq9DCAOPH),
  653. ~SYM_MASK(DCACtrlD, RcvHdrq9DCAOPH) , KREG_IDX(DCACtrlD) },
  654. { 2, SYM_LSB(DCACtrlD, RcvHdrq10DCAOPH),
  655. ~SYM_MASK(DCACtrlD, RcvHdrq10DCAOPH) , KREG_IDX(DCACtrlD) },
  656. { 2, SYM_LSB(DCACtrlD, RcvHdrq11DCAOPH),
  657. ~SYM_MASK(DCACtrlD, RcvHdrq11DCAOPH) , KREG_IDX(DCACtrlD) },
  658. { 3, SYM_LSB(DCACtrlE, RcvHdrq12DCAOPH),
  659. ~SYM_MASK(DCACtrlE, RcvHdrq12DCAOPH) , KREG_IDX(DCACtrlE) },
  660. { 3, SYM_LSB(DCACtrlE, RcvHdrq13DCAOPH),
  661. ~SYM_MASK(DCACtrlE, RcvHdrq13DCAOPH) , KREG_IDX(DCACtrlE) },
  662. { 3, SYM_LSB(DCACtrlE, RcvHdrq14DCAOPH),
  663. ~SYM_MASK(DCACtrlE, RcvHdrq14DCAOPH) , KREG_IDX(DCACtrlE) },
  664. { 3, SYM_LSB(DCACtrlE, RcvHdrq15DCAOPH),
  665. ~SYM_MASK(DCACtrlE, RcvHdrq15DCAOPH) , KREG_IDX(DCACtrlE) },
  666. { 4, SYM_LSB(DCACtrlF, RcvHdrq16DCAOPH),
  667. ~SYM_MASK(DCACtrlF, RcvHdrq16DCAOPH) , KREG_IDX(DCACtrlF) },
  668. { 4, SYM_LSB(DCACtrlF, RcvHdrq17DCAOPH),
  669. ~SYM_MASK(DCACtrlF, RcvHdrq17DCAOPH) , KREG_IDX(DCACtrlF) },
  670. };
  671. #endif
  672. /* ibcctrl bits */
  673. #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
  674. /* cycle through TS1/TS2 till OK */
  675. #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
  676. /* wait for TS1, then go on */
  677. #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
  678. #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
  679. #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
  680. #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
  681. #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
  682. #define BLOB_7322_IBCHG 0x101
  683. static inline void qib_write_kreg(const struct qib_devdata *dd,
  684. const u32 regno, u64 value);
  685. static inline u32 qib_read_kreg32(const struct qib_devdata *, const u32);
  686. static void write_7322_initregs(struct qib_devdata *);
  687. static void write_7322_init_portregs(struct qib_pportdata *);
  688. static void setup_7322_link_recovery(struct qib_pportdata *, u32);
  689. static void check_7322_rxe_status(struct qib_pportdata *);
  690. static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *, u64, u32 *);
  691. #ifdef CONFIG_INFINIBAND_QIB_DCA
  692. static void qib_setup_dca(struct qib_devdata *dd);
  693. static void setup_dca_notifier(struct qib_devdata *dd, int msixnum);
  694. static void reset_dca_notifier(struct qib_devdata *dd, int msixnum);
  695. #endif
  696. /**
  697. * qib_read_ureg32 - read 32-bit virtualized per-context register
  698. * @dd: device
  699. * @regno: register number
  700. * @ctxt: context number
  701. *
  702. * Return the contents of a register that is virtualized to be per context.
  703. * Returns -1 on errors (not distinguishable from valid contents at
  704. * runtime; we may add a separate error variable at some point).
  705. */
  706. static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
  707. enum qib_ureg regno, int ctxt)
  708. {
  709. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  710. return 0;
  711. return readl(regno + (u64 __iomem *)(
  712. (dd->ureg_align * ctxt) + (dd->userbase ?
  713. (char __iomem *)dd->userbase :
  714. (char __iomem *)dd->kregbase + dd->uregbase)));
  715. }
  716. /**
  717. * qib_read_ureg - read virtualized per-context register
  718. * @dd: device
  719. * @regno: register number
  720. * @ctxt: context number
  721. *
  722. * Return the contents of a register that is virtualized to be per context.
  723. * Returns -1 on errors (not distinguishable from valid contents at
  724. * runtime; we may add a separate error variable at some point).
  725. */
  726. static inline u64 qib_read_ureg(const struct qib_devdata *dd,
  727. enum qib_ureg regno, int ctxt)
  728. {
  729. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  730. return 0;
  731. return readq(regno + (u64 __iomem *)(
  732. (dd->ureg_align * ctxt) + (dd->userbase ?
  733. (char __iomem *)dd->userbase :
  734. (char __iomem *)dd->kregbase + dd->uregbase)));
  735. }
  736. /**
  737. * qib_write_ureg - write virtualized per-context register
  738. * @dd: device
  739. * @regno: register number
  740. * @value: value
  741. * @ctxt: context
  742. *
  743. * Write the contents of a register that is virtualized to be per context.
  744. */
  745. static inline void qib_write_ureg(const struct qib_devdata *dd,
  746. enum qib_ureg regno, u64 value, int ctxt)
  747. {
  748. u64 __iomem *ubase;
  749. if (dd->userbase)
  750. ubase = (u64 __iomem *)
  751. ((char __iomem *) dd->userbase +
  752. dd->ureg_align * ctxt);
  753. else
  754. ubase = (u64 __iomem *)
  755. (dd->uregbase +
  756. (char __iomem *) dd->kregbase +
  757. dd->ureg_align * ctxt);
  758. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  759. writeq(value, &ubase[regno]);
  760. }
  761. static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
  762. const u32 regno)
  763. {
  764. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  765. return -1;
  766. return readl((u32 __iomem *) &dd->kregbase[regno]);
  767. }
  768. static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
  769. const u32 regno)
  770. {
  771. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  772. return -1;
  773. return readq(&dd->kregbase[regno]);
  774. }
  775. static inline void qib_write_kreg(const struct qib_devdata *dd,
  776. const u32 regno, u64 value)
  777. {
  778. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  779. writeq(value, &dd->kregbase[regno]);
  780. }
  781. /*
  782. * not many sanity checks for the port-specific kernel register routines,
  783. * since they are only used when it's known to be safe.
  784. */
  785. static inline u64 qib_read_kreg_port(const struct qib_pportdata *ppd,
  786. const u16 regno)
  787. {
  788. if (!ppd->cpspec->kpregbase || !(ppd->dd->flags & QIB_PRESENT))
  789. return 0ULL;
  790. return readq(&ppd->cpspec->kpregbase[regno]);
  791. }
  792. static inline void qib_write_kreg_port(const struct qib_pportdata *ppd,
  793. const u16 regno, u64 value)
  794. {
  795. if (ppd->cpspec && ppd->dd && ppd->cpspec->kpregbase &&
  796. (ppd->dd->flags & QIB_PRESENT))
  797. writeq(value, &ppd->cpspec->kpregbase[regno]);
  798. }
  799. /**
  800. * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
  801. * @dd: the qlogic_ib device
  802. * @regno: the register number to write
  803. * @ctxt: the context containing the register
  804. * @value: the value to write
  805. */
  806. static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
  807. const u16 regno, unsigned ctxt,
  808. u64 value)
  809. {
  810. qib_write_kreg(dd, regno + ctxt, value);
  811. }
  812. static inline u64 read_7322_creg(const struct qib_devdata *dd, u16 regno)
  813. {
  814. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  815. return 0;
  816. return readq(&dd->cspec->cregbase[regno]);
  817. }
  818. static inline u32 read_7322_creg32(const struct qib_devdata *dd, u16 regno)
  819. {
  820. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  821. return 0;
  822. return readl(&dd->cspec->cregbase[regno]);
  823. }
  824. static inline void write_7322_creg_port(const struct qib_pportdata *ppd,
  825. u16 regno, u64 value)
  826. {
  827. if (ppd->cpspec && ppd->cpspec->cpregbase &&
  828. (ppd->dd->flags & QIB_PRESENT))
  829. writeq(value, &ppd->cpspec->cpregbase[regno]);
  830. }
  831. static inline u64 read_7322_creg_port(const struct qib_pportdata *ppd,
  832. u16 regno)
  833. {
  834. if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
  835. !(ppd->dd->flags & QIB_PRESENT))
  836. return 0;
  837. return readq(&ppd->cpspec->cpregbase[regno]);
  838. }
  839. static inline u32 read_7322_creg32_port(const struct qib_pportdata *ppd,
  840. u16 regno)
  841. {
  842. if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
  843. !(ppd->dd->flags & QIB_PRESENT))
  844. return 0;
  845. return readl(&ppd->cpspec->cpregbase[regno]);
  846. }
  847. /* bits in Control register */
  848. #define QLOGIC_IB_C_RESET SYM_MASK(Control, SyncReset)
  849. #define QLOGIC_IB_C_SDMAFETCHPRIOEN SYM_MASK(Control, SDmaDescFetchPriorityEn)
  850. /* bits in general interrupt regs */
  851. #define QIB_I_RCVURG_LSB SYM_LSB(IntMask, RcvUrg0IntMask)
  852. #define QIB_I_RCVURG_RMASK MASK_ACROSS(0, 17)
  853. #define QIB_I_RCVURG_MASK (QIB_I_RCVURG_RMASK << QIB_I_RCVURG_LSB)
  854. #define QIB_I_RCVAVAIL_LSB SYM_LSB(IntMask, RcvAvail0IntMask)
  855. #define QIB_I_RCVAVAIL_RMASK MASK_ACROSS(0, 17)
  856. #define QIB_I_RCVAVAIL_MASK (QIB_I_RCVAVAIL_RMASK << QIB_I_RCVAVAIL_LSB)
  857. #define QIB_I_C_ERROR INT_MASK(Err)
  858. #define QIB_I_SPIOSENT (INT_MASK_P(SendDone, 0) | INT_MASK_P(SendDone, 1))
  859. #define QIB_I_SPIOBUFAVAIL INT_MASK(SendBufAvail)
  860. #define QIB_I_GPIO INT_MASK(AssertGPIO)
  861. #define QIB_I_P_SDMAINT(pidx) \
  862. (INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
  863. INT_MASK_P(SDmaProgress, pidx) | \
  864. INT_MASK_PM(SDmaCleanupDone, pidx))
  865. /* Interrupt bits that are "per port" */
  866. #define QIB_I_P_BITSEXTANT(pidx) \
  867. (INT_MASK_P(Err, pidx) | INT_MASK_P(SendDone, pidx) | \
  868. INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
  869. INT_MASK_P(SDmaProgress, pidx) | \
  870. INT_MASK_PM(SDmaCleanupDone, pidx))
  871. /* Interrupt bits that are common to a device */
  872. /* currently unused: QIB_I_SPIOSENT */
  873. #define QIB_I_C_BITSEXTANT \
  874. (QIB_I_RCVURG_MASK | QIB_I_RCVAVAIL_MASK | \
  875. QIB_I_SPIOSENT | \
  876. QIB_I_C_ERROR | QIB_I_SPIOBUFAVAIL | QIB_I_GPIO)
  877. #define QIB_I_BITSEXTANT (QIB_I_C_BITSEXTANT | \
  878. QIB_I_P_BITSEXTANT(0) | QIB_I_P_BITSEXTANT(1))
  879. /*
  880. * Error bits that are "per port".
  881. */
  882. #define QIB_E_P_IBSTATUSCHANGED ERR_MASK_N(IBStatusChanged)
  883. #define QIB_E_P_SHDR ERR_MASK_N(SHeadersErr)
  884. #define QIB_E_P_VL15_BUF_MISUSE ERR_MASK_N(VL15BufMisuseErr)
  885. #define QIB_E_P_SND_BUF_MISUSE ERR_MASK_N(SendBufMisuseErr)
  886. #define QIB_E_P_SUNSUPVL ERR_MASK_N(SendUnsupportedVLErr)
  887. #define QIB_E_P_SUNEXP_PKTNUM ERR_MASK_N(SendUnexpectedPktNumErr)
  888. #define QIB_E_P_SDROP_DATA ERR_MASK_N(SendDroppedDataPktErr)
  889. #define QIB_E_P_SDROP_SMP ERR_MASK_N(SendDroppedSmpPktErr)
  890. #define QIB_E_P_SPKTLEN ERR_MASK_N(SendPktLenErr)
  891. #define QIB_E_P_SUNDERRUN ERR_MASK_N(SendUnderRunErr)
  892. #define QIB_E_P_SMAXPKTLEN ERR_MASK_N(SendMaxPktLenErr)
  893. #define QIB_E_P_SMINPKTLEN ERR_MASK_N(SendMinPktLenErr)
  894. #define QIB_E_P_RIBLOSTLINK ERR_MASK_N(RcvIBLostLinkErr)
  895. #define QIB_E_P_RHDR ERR_MASK_N(RcvHdrErr)
  896. #define QIB_E_P_RHDRLEN ERR_MASK_N(RcvHdrLenErr)
  897. #define QIB_E_P_RBADTID ERR_MASK_N(RcvBadTidErr)
  898. #define QIB_E_P_RBADVERSION ERR_MASK_N(RcvBadVersionErr)
  899. #define QIB_E_P_RIBFLOW ERR_MASK_N(RcvIBFlowErr)
  900. #define QIB_E_P_REBP ERR_MASK_N(RcvEBPErr)
  901. #define QIB_E_P_RUNSUPVL ERR_MASK_N(RcvUnsupportedVLErr)
  902. #define QIB_E_P_RUNEXPCHAR ERR_MASK_N(RcvUnexpectedCharErr)
  903. #define QIB_E_P_RSHORTPKTLEN ERR_MASK_N(RcvShortPktLenErr)
  904. #define QIB_E_P_RLONGPKTLEN ERR_MASK_N(RcvLongPktLenErr)
  905. #define QIB_E_P_RMAXPKTLEN ERR_MASK_N(RcvMaxPktLenErr)
  906. #define QIB_E_P_RMINPKTLEN ERR_MASK_N(RcvMinPktLenErr)
  907. #define QIB_E_P_RICRC ERR_MASK_N(RcvICRCErr)
  908. #define QIB_E_P_RVCRC ERR_MASK_N(RcvVCRCErr)
  909. #define QIB_E_P_RFORMATERR ERR_MASK_N(RcvFormatErr)
  910. #define QIB_E_P_SDMA1STDESC ERR_MASK_N(SDma1stDescErr)
  911. #define QIB_E_P_SDMABASE ERR_MASK_N(SDmaBaseErr)
  912. #define QIB_E_P_SDMADESCADDRMISALIGN ERR_MASK_N(SDmaDescAddrMisalignErr)
  913. #define QIB_E_P_SDMADWEN ERR_MASK_N(SDmaDwEnErr)
  914. #define QIB_E_P_SDMAGENMISMATCH ERR_MASK_N(SDmaGenMismatchErr)
  915. #define QIB_E_P_SDMAHALT ERR_MASK_N(SDmaHaltErr)
  916. #define QIB_E_P_SDMAMISSINGDW ERR_MASK_N(SDmaMissingDwErr)
  917. #define QIB_E_P_SDMAOUTOFBOUND ERR_MASK_N(SDmaOutOfBoundErr)
  918. #define QIB_E_P_SDMARPYTAG ERR_MASK_N(SDmaRpyTagErr)
  919. #define QIB_E_P_SDMATAILOUTOFBOUND ERR_MASK_N(SDmaTailOutOfBoundErr)
  920. #define QIB_E_P_SDMAUNEXPDATA ERR_MASK_N(SDmaUnexpDataErr)
  921. /* Error bits that are common to a device */
  922. #define QIB_E_RESET ERR_MASK(ResetNegated)
  923. #define QIB_E_HARDWARE ERR_MASK(HardwareErr)
  924. #define QIB_E_INVALIDADDR ERR_MASK(InvalidAddrErr)
  925. /*
  926. * Per chip (rather than per-port) errors. Most either do
  927. * nothing but trigger a print (because they self-recover, or
  928. * always occur in tandem with other errors that handle the
  929. * issue), or because they indicate errors with no recovery,
  930. * but we want to know that they happened.
  931. */
  932. #define QIB_E_SBUF_VL15_MISUSE ERR_MASK(SBufVL15MisUseErr)
  933. #define QIB_E_BADEEP ERR_MASK(InvalidEEPCmd)
  934. #define QIB_E_VLMISMATCH ERR_MASK(SendVLMismatchErr)
  935. #define QIB_E_ARMLAUNCH ERR_MASK(SendArmLaunchErr)
  936. #define QIB_E_SPCLTRIG ERR_MASK(SendSpecialTriggerErr)
  937. #define QIB_E_RRCVHDRFULL ERR_MASK(RcvHdrFullErr)
  938. #define QIB_E_RRCVEGRFULL ERR_MASK(RcvEgrFullErr)
  939. #define QIB_E_RCVCTXTSHARE ERR_MASK(RcvContextShareErr)
  940. /* SDMA chip errors (not per port)
  941. * QIB_E_SDMA_BUF_DUP needs no special handling, because we will also get
  942. * the SDMAHALT error immediately, so we just print the dup error via the
  943. * E_AUTO mechanism. This is true of most of the per-port fatal errors
  944. * as well, but since this is port-independent, by definition, it's
  945. * handled a bit differently. SDMA_VL15 and SDMA_WRONG_PORT are per
  946. * packet send errors, and so are handled in the same manner as other
  947. * per-packet errors.
  948. */
  949. #define QIB_E_SDMA_VL15 ERR_MASK(SDmaVL15Err)
  950. #define QIB_E_SDMA_WRONG_PORT ERR_MASK(SDmaWrongPortErr)
  951. #define QIB_E_SDMA_BUF_DUP ERR_MASK(SDmaBufMaskDuplicateErr)
  952. /*
  953. * Below functionally equivalent to legacy QLOGIC_IB_E_PKTERRS
  954. * it is used to print "common" packet errors.
  955. */
  956. #define QIB_E_P_PKTERRS (QIB_E_P_SPKTLEN |\
  957. QIB_E_P_SDROP_DATA | QIB_E_P_RVCRC |\
  958. QIB_E_P_RICRC | QIB_E_P_RSHORTPKTLEN |\
  959. QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
  960. QIB_E_P_REBP)
  961. /* Error Bits that Packet-related (Receive, per-port) */
  962. #define QIB_E_P_RPKTERRS (\
  963. QIB_E_P_RHDRLEN | QIB_E_P_RBADTID | \
  964. QIB_E_P_RBADVERSION | QIB_E_P_RHDR | \
  965. QIB_E_P_RLONGPKTLEN | QIB_E_P_RSHORTPKTLEN |\
  966. QIB_E_P_RMAXPKTLEN | QIB_E_P_RMINPKTLEN | \
  967. QIB_E_P_RFORMATERR | QIB_E_P_RUNSUPVL | \
  968. QIB_E_P_RUNEXPCHAR | QIB_E_P_RIBFLOW | QIB_E_P_REBP)
  969. /*
  970. * Error bits that are Send-related (per port)
  971. * (ARMLAUNCH excluded from E_SPKTERRS because it gets special handling).
  972. * All of these potentially need to have a buffer disarmed
  973. */
  974. #define QIB_E_P_SPKTERRS (\
  975. QIB_E_P_SUNEXP_PKTNUM |\
  976. QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
  977. QIB_E_P_SMAXPKTLEN |\
  978. QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
  979. QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN | \
  980. QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNSUPVL)
  981. #define QIB_E_SPKTERRS ( \
  982. QIB_E_SBUF_VL15_MISUSE | QIB_E_VLMISMATCH | \
  983. ERR_MASK_N(SendUnsupportedVLErr) | \
  984. QIB_E_SPCLTRIG | QIB_E_SDMA_VL15 | QIB_E_SDMA_WRONG_PORT)
  985. #define QIB_E_P_SDMAERRS ( \
  986. QIB_E_P_SDMAHALT | \
  987. QIB_E_P_SDMADESCADDRMISALIGN | \
  988. QIB_E_P_SDMAUNEXPDATA | \
  989. QIB_E_P_SDMAMISSINGDW | \
  990. QIB_E_P_SDMADWEN | \
  991. QIB_E_P_SDMARPYTAG | \
  992. QIB_E_P_SDMA1STDESC | \
  993. QIB_E_P_SDMABASE | \
  994. QIB_E_P_SDMATAILOUTOFBOUND | \
  995. QIB_E_P_SDMAOUTOFBOUND | \
  996. QIB_E_P_SDMAGENMISMATCH)
  997. /*
  998. * This sets some bits more than once, but makes it more obvious which
  999. * bits are not handled under other categories, and the repeat definition
  1000. * is not a problem.
  1001. */
  1002. #define QIB_E_P_BITSEXTANT ( \
  1003. QIB_E_P_SPKTERRS | QIB_E_P_PKTERRS | QIB_E_P_RPKTERRS | \
  1004. QIB_E_P_RIBLOSTLINK | QIB_E_P_IBSTATUSCHANGED | \
  1005. QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNDERRUN | \
  1006. QIB_E_P_SHDR | QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SDMAERRS \
  1007. )
  1008. /*
  1009. * These are errors that can occur when the link
  1010. * changes state while a packet is being sent or received. This doesn't
  1011. * cover things like EBP or VCRC that can be the result of a sending
  1012. * having the link change state, so we receive a "known bad" packet.
  1013. * All of these are "per port", so renamed:
  1014. */
  1015. #define QIB_E_P_LINK_PKTERRS (\
  1016. QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
  1017. QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN |\
  1018. QIB_E_P_RSHORTPKTLEN | QIB_E_P_RMINPKTLEN |\
  1019. QIB_E_P_RUNEXPCHAR)
  1020. /*
  1021. * This sets some bits more than once, but makes it more obvious which
  1022. * bits are not handled under other categories (such as QIB_E_SPKTERRS),
  1023. * and the repeat definition is not a problem.
  1024. */
  1025. #define QIB_E_C_BITSEXTANT (\
  1026. QIB_E_HARDWARE | QIB_E_INVALIDADDR | QIB_E_BADEEP |\
  1027. QIB_E_ARMLAUNCH | QIB_E_VLMISMATCH | QIB_E_RRCVHDRFULL |\
  1028. QIB_E_RRCVEGRFULL | QIB_E_RESET | QIB_E_SBUF_VL15_MISUSE)
  1029. /* Likewise Neuter E_SPKT_ERRS_IGNORE */
  1030. #define E_SPKT_ERRS_IGNORE 0
  1031. #define QIB_EXTS_MEMBIST_DISABLED \
  1032. SYM_MASK(EXTStatus, MemBISTDisabled)
  1033. #define QIB_EXTS_MEMBIST_ENDTEST \
  1034. SYM_MASK(EXTStatus, MemBISTEndTest)
  1035. #define QIB_E_SPIOARMLAUNCH \
  1036. ERR_MASK(SendArmLaunchErr)
  1037. #define IBA7322_IBCC_LINKINITCMD_MASK SYM_RMASK(IBCCtrlA_0, LinkInitCmd)
  1038. #define IBA7322_IBCC_LINKCMD_SHIFT SYM_LSB(IBCCtrlA_0, LinkCmd)
  1039. /*
  1040. * IBTA_1_2 is set when multiple speeds are enabled (normal),
  1041. * and also if forced QDR (only QDR enabled). It's enabled for the
  1042. * forced QDR case so that scrambling will be enabled by the TS3
  1043. * exchange, when supported by both sides of the link.
  1044. */
  1045. #define IBA7322_IBC_IBTA_1_2_MASK SYM_MASK(IBCCtrlB_0, IB_ENHANCED_MODE)
  1046. #define IBA7322_IBC_MAX_SPEED_MASK SYM_MASK(IBCCtrlB_0, SD_SPEED)
  1047. #define IBA7322_IBC_SPEED_QDR SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR)
  1048. #define IBA7322_IBC_SPEED_DDR SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR)
  1049. #define IBA7322_IBC_SPEED_SDR SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR)
  1050. #define IBA7322_IBC_SPEED_MASK (SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR) | \
  1051. SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR) | SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR))
  1052. #define IBA7322_IBC_SPEED_LSB SYM_LSB(IBCCtrlB_0, SD_SPEED_SDR)
  1053. #define IBA7322_LEDBLINK_OFF_SHIFT SYM_LSB(RcvPktLEDCnt_0, OFFperiod)
  1054. #define IBA7322_LEDBLINK_ON_SHIFT SYM_LSB(RcvPktLEDCnt_0, ONperiod)
  1055. #define IBA7322_IBC_WIDTH_AUTONEG SYM_MASK(IBCCtrlB_0, IB_NUM_CHANNELS)
  1056. #define IBA7322_IBC_WIDTH_4X_ONLY (1<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
  1057. #define IBA7322_IBC_WIDTH_1X_ONLY (0<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
  1058. #define IBA7322_IBC_RXPOL_MASK SYM_MASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
  1059. #define IBA7322_IBC_RXPOL_LSB SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
  1060. #define IBA7322_IBC_HRTBT_MASK (SYM_MASK(IBCCtrlB_0, HRTBT_AUTO) | \
  1061. SYM_MASK(IBCCtrlB_0, HRTBT_ENB))
  1062. #define IBA7322_IBC_HRTBT_RMASK (IBA7322_IBC_HRTBT_MASK >> \
  1063. SYM_LSB(IBCCtrlB_0, HRTBT_ENB))
  1064. #define IBA7322_IBC_HRTBT_LSB SYM_LSB(IBCCtrlB_0, HRTBT_ENB)
  1065. #define IBA7322_REDIRECT_VEC_PER_REG 12
  1066. #define IBA7322_SENDCHK_PKEY SYM_MASK(SendCheckControl_0, PKey_En)
  1067. #define IBA7322_SENDCHK_BTHQP SYM_MASK(SendCheckControl_0, BTHQP_En)
  1068. #define IBA7322_SENDCHK_SLID SYM_MASK(SendCheckControl_0, SLID_En)
  1069. #define IBA7322_SENDCHK_RAW_IPV6 SYM_MASK(SendCheckControl_0, RawIPV6_En)
  1070. #define IBA7322_SENDCHK_MINSZ SYM_MASK(SendCheckControl_0, PacketTooSmall_En)
  1071. #define AUTONEG_TRIES 3 /* sequential retries to negotiate DDR */
  1072. #define HWE_AUTO(fldname) { .mask = SYM_MASK(HwErrMask, fldname##Mask), \
  1073. .msg = #fldname , .sz = sizeof(#fldname) }
  1074. #define HWE_AUTO_P(fldname, port) { .mask = SYM_MASK(HwErrMask, \
  1075. fldname##Mask##_##port), .msg = #fldname , .sz = sizeof(#fldname) }
  1076. static const struct qib_hwerror_msgs qib_7322_hwerror_msgs[] = {
  1077. HWE_AUTO_P(IBSerdesPClkNotDetect, 1),
  1078. HWE_AUTO_P(IBSerdesPClkNotDetect, 0),
  1079. HWE_AUTO(PCIESerdesPClkNotDetect),
  1080. HWE_AUTO(PowerOnBISTFailed),
  1081. HWE_AUTO(TempsenseTholdReached),
  1082. HWE_AUTO(MemoryErr),
  1083. HWE_AUTO(PCIeBusParityErr),
  1084. HWE_AUTO(PcieCplTimeout),
  1085. HWE_AUTO(PciePoisonedTLP),
  1086. HWE_AUTO_P(SDmaMemReadErr, 1),
  1087. HWE_AUTO_P(SDmaMemReadErr, 0),
  1088. HWE_AUTO_P(IBCBusFromSPCParityErr, 1),
  1089. HWE_AUTO_P(IBCBusToSPCParityErr, 1),
  1090. HWE_AUTO_P(IBCBusFromSPCParityErr, 0),
  1091. HWE_AUTO(statusValidNoEop),
  1092. HWE_AUTO(LATriggered),
  1093. { .mask = 0, .sz = 0 }
  1094. };
  1095. #define E_AUTO(fldname) { .mask = SYM_MASK(ErrMask, fldname##Mask), \
  1096. .msg = #fldname, .sz = sizeof(#fldname) }
  1097. #define E_P_AUTO(fldname) { .mask = SYM_MASK(ErrMask_0, fldname##Mask), \
  1098. .msg = #fldname, .sz = sizeof(#fldname) }
  1099. static const struct qib_hwerror_msgs qib_7322error_msgs[] = {
  1100. E_AUTO(RcvEgrFullErr),
  1101. E_AUTO(RcvHdrFullErr),
  1102. E_AUTO(ResetNegated),
  1103. E_AUTO(HardwareErr),
  1104. E_AUTO(InvalidAddrErr),
  1105. E_AUTO(SDmaVL15Err),
  1106. E_AUTO(SBufVL15MisUseErr),
  1107. E_AUTO(InvalidEEPCmd),
  1108. E_AUTO(RcvContextShareErr),
  1109. E_AUTO(SendVLMismatchErr),
  1110. E_AUTO(SendArmLaunchErr),
  1111. E_AUTO(SendSpecialTriggerErr),
  1112. E_AUTO(SDmaWrongPortErr),
  1113. E_AUTO(SDmaBufMaskDuplicateErr),
  1114. { .mask = 0, .sz = 0 }
  1115. };
  1116. static const struct qib_hwerror_msgs qib_7322p_error_msgs[] = {
  1117. E_P_AUTO(IBStatusChanged),
  1118. E_P_AUTO(SHeadersErr),
  1119. E_P_AUTO(VL15BufMisuseErr),
  1120. /*
  1121. * SDmaHaltErr is not really an error, make it clearer;
  1122. */
  1123. {.mask = SYM_MASK(ErrMask_0, SDmaHaltErrMask), .msg = "SDmaHalted",
  1124. .sz = 11},
  1125. E_P_AUTO(SDmaDescAddrMisalignErr),
  1126. E_P_AUTO(SDmaUnexpDataErr),
  1127. E_P_AUTO(SDmaMissingDwErr),
  1128. E_P_AUTO(SDmaDwEnErr),
  1129. E_P_AUTO(SDmaRpyTagErr),
  1130. E_P_AUTO(SDma1stDescErr),
  1131. E_P_AUTO(SDmaBaseErr),
  1132. E_P_AUTO(SDmaTailOutOfBoundErr),
  1133. E_P_AUTO(SDmaOutOfBoundErr),
  1134. E_P_AUTO(SDmaGenMismatchErr),
  1135. E_P_AUTO(SendBufMisuseErr),
  1136. E_P_AUTO(SendUnsupportedVLErr),
  1137. E_P_AUTO(SendUnexpectedPktNumErr),
  1138. E_P_AUTO(SendDroppedDataPktErr),
  1139. E_P_AUTO(SendDroppedSmpPktErr),
  1140. E_P_AUTO(SendPktLenErr),
  1141. E_P_AUTO(SendUnderRunErr),
  1142. E_P_AUTO(SendMaxPktLenErr),
  1143. E_P_AUTO(SendMinPktLenErr),
  1144. E_P_AUTO(RcvIBLostLinkErr),
  1145. E_P_AUTO(RcvHdrErr),
  1146. E_P_AUTO(RcvHdrLenErr),
  1147. E_P_AUTO(RcvBadTidErr),
  1148. E_P_AUTO(RcvBadVersionErr),
  1149. E_P_AUTO(RcvIBFlowErr),
  1150. E_P_AUTO(RcvEBPErr),
  1151. E_P_AUTO(RcvUnsupportedVLErr),
  1152. E_P_AUTO(RcvUnexpectedCharErr),
  1153. E_P_AUTO(RcvShortPktLenErr),
  1154. E_P_AUTO(RcvLongPktLenErr),
  1155. E_P_AUTO(RcvMaxPktLenErr),
  1156. E_P_AUTO(RcvMinPktLenErr),
  1157. E_P_AUTO(RcvICRCErr),
  1158. E_P_AUTO(RcvVCRCErr),
  1159. E_P_AUTO(RcvFormatErr),
  1160. { .mask = 0, .sz = 0 }
  1161. };
  1162. /*
  1163. * Below generates "auto-message" for interrupts not specific to any port or
  1164. * context
  1165. */
  1166. #define INTR_AUTO(fldname) { .mask = SYM_MASK(IntMask, fldname##Mask), \
  1167. .msg = #fldname, .sz = sizeof(#fldname) }
  1168. /* Below generates "auto-message" for interrupts specific to a port */
  1169. #define INTR_AUTO_P(fldname) { .mask = MASK_ACROSS(\
  1170. SYM_LSB(IntMask, fldname##Mask##_0), \
  1171. SYM_LSB(IntMask, fldname##Mask##_1)), \
  1172. .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
  1173. /* For some reason, the SerDesTrimDone bits are reversed */
  1174. #define INTR_AUTO_PI(fldname) { .mask = MASK_ACROSS(\
  1175. SYM_LSB(IntMask, fldname##Mask##_1), \
  1176. SYM_LSB(IntMask, fldname##Mask##_0)), \
  1177. .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
  1178. /*
  1179. * Below generates "auto-message" for interrupts specific to a context,
  1180. * with ctxt-number appended
  1181. */
  1182. #define INTR_AUTO_C(fldname) { .mask = MASK_ACROSS(\
  1183. SYM_LSB(IntMask, fldname##0IntMask), \
  1184. SYM_LSB(IntMask, fldname##17IntMask)), \
  1185. .msg = #fldname "_C", .sz = sizeof(#fldname "_C") }
  1186. #define TXSYMPTOM_AUTO_P(fldname) \
  1187. { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), \
  1188. .msg = #fldname, .sz = sizeof(#fldname) }
  1189. static const struct qib_hwerror_msgs hdrchk_msgs[] = {
  1190. TXSYMPTOM_AUTO_P(NonKeyPacket),
  1191. TXSYMPTOM_AUTO_P(GRHFail),
  1192. TXSYMPTOM_AUTO_P(PkeyFail),
  1193. TXSYMPTOM_AUTO_P(QPFail),
  1194. TXSYMPTOM_AUTO_P(SLIDFail),
  1195. TXSYMPTOM_AUTO_P(RawIPV6),
  1196. TXSYMPTOM_AUTO_P(PacketTooSmall),
  1197. { .mask = 0, .sz = 0 }
  1198. };
  1199. #define IBA7322_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
  1200. /*
  1201. * Called when we might have an error that is specific to a particular
  1202. * PIO buffer, and may need to cancel that buffer, so it can be re-used,
  1203. * because we don't need to force the update of pioavail
  1204. */
  1205. static void qib_disarm_7322_senderrbufs(struct qib_pportdata *ppd)
  1206. {
  1207. struct qib_devdata *dd = ppd->dd;
  1208. u32 i;
  1209. int any;
  1210. u32 piobcnt = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  1211. u32 regcnt = (piobcnt + BITS_PER_LONG - 1) / BITS_PER_LONG;
  1212. unsigned long sbuf[4];
  1213. /*
  1214. * It's possible that sendbuffererror could have bits set; might
  1215. * have already done this as a result of hardware error handling.
  1216. */
  1217. any = 0;
  1218. for (i = 0; i < regcnt; ++i) {
  1219. sbuf[i] = qib_read_kreg64(dd, kr_sendbuffererror + i);
  1220. if (sbuf[i]) {
  1221. any = 1;
  1222. qib_write_kreg(dd, kr_sendbuffererror + i, sbuf[i]);
  1223. }
  1224. }
  1225. if (any)
  1226. qib_disarm_piobufs_set(dd, sbuf, piobcnt);
  1227. }
  1228. /* No txe_recover yet, if ever */
  1229. /* No decode__errors yet */
  1230. static void err_decode(char *msg, size_t len, u64 errs,
  1231. const struct qib_hwerror_msgs *msp)
  1232. {
  1233. u64 these, lmask;
  1234. int took, multi, n = 0;
  1235. while (errs && msp && msp->mask) {
  1236. multi = (msp->mask & (msp->mask - 1));
  1237. while (errs & msp->mask) {
  1238. these = (errs & msp->mask);
  1239. lmask = (these & (these - 1)) ^ these;
  1240. if (len) {
  1241. if (n++) {
  1242. /* separate the strings */
  1243. *msg++ = ',';
  1244. len--;
  1245. }
  1246. BUG_ON(!msp->sz);
  1247. /* msp->sz counts the nul */
  1248. took = min_t(size_t, msp->sz - (size_t)1, len);
  1249. memcpy(msg, msp->msg, took);
  1250. len -= took;
  1251. msg += took;
  1252. if (len)
  1253. *msg = '\0';
  1254. }
  1255. errs &= ~lmask;
  1256. if (len && multi) {
  1257. /* More than one bit this mask */
  1258. int idx = -1;
  1259. while (lmask & msp->mask) {
  1260. ++idx;
  1261. lmask >>= 1;
  1262. }
  1263. took = scnprintf(msg, len, "_%d", idx);
  1264. len -= took;
  1265. msg += took;
  1266. }
  1267. }
  1268. ++msp;
  1269. }
  1270. /* If some bits are left, show in hex. */
  1271. if (len && errs)
  1272. snprintf(msg, len, "%sMORE:%llX", n ? "," : "",
  1273. (unsigned long long) errs);
  1274. }
  1275. /* only called if r1 set */
  1276. static void flush_fifo(struct qib_pportdata *ppd)
  1277. {
  1278. struct qib_devdata *dd = ppd->dd;
  1279. u32 __iomem *piobuf;
  1280. u32 bufn;
  1281. u32 *hdr;
  1282. u64 pbc;
  1283. const unsigned hdrwords = 7;
  1284. static struct ib_header ibhdr = {
  1285. .lrh[0] = cpu_to_be16(0xF000 | QIB_LRH_BTH),
  1286. .lrh[1] = IB_LID_PERMISSIVE,
  1287. .lrh[2] = cpu_to_be16(hdrwords + SIZE_OF_CRC),
  1288. .lrh[3] = IB_LID_PERMISSIVE,
  1289. .u.oth.bth[0] = cpu_to_be32(
  1290. (IB_OPCODE_UD_SEND_ONLY << 24) | QIB_DEFAULT_P_KEY),
  1291. .u.oth.bth[1] = cpu_to_be32(0),
  1292. .u.oth.bth[2] = cpu_to_be32(0),
  1293. .u.oth.u.ud.deth[0] = cpu_to_be32(0),
  1294. .u.oth.u.ud.deth[1] = cpu_to_be32(0),
  1295. };
  1296. /*
  1297. * Send a dummy VL15 packet to flush the launch FIFO.
  1298. * This will not actually be sent since the TxeBypassIbc bit is set.
  1299. */
  1300. pbc = PBC_7322_VL15_SEND |
  1301. (((u64)ppd->hw_pidx) << (PBC_PORT_SEL_LSB + 32)) |
  1302. (hdrwords + SIZE_OF_CRC);
  1303. piobuf = qib_7322_getsendbuf(ppd, pbc, &bufn);
  1304. if (!piobuf)
  1305. return;
  1306. writeq(pbc, piobuf);
  1307. hdr = (u32 *) &ibhdr;
  1308. if (dd->flags & QIB_PIO_FLUSH_WC) {
  1309. qib_flush_wc();
  1310. qib_pio_copy(piobuf + 2, hdr, hdrwords - 1);
  1311. qib_flush_wc();
  1312. __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords + 1);
  1313. qib_flush_wc();
  1314. } else
  1315. qib_pio_copy(piobuf + 2, hdr, hdrwords);
  1316. qib_sendbuf_done(dd, bufn);
  1317. }
  1318. /*
  1319. * This is called with interrupts disabled and sdma_lock held.
  1320. */
  1321. static void qib_7322_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
  1322. {
  1323. struct qib_devdata *dd = ppd->dd;
  1324. u64 set_sendctrl = 0;
  1325. u64 clr_sendctrl = 0;
  1326. if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
  1327. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
  1328. else
  1329. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
  1330. if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
  1331. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
  1332. else
  1333. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
  1334. if (op & QIB_SDMA_SENDCTRL_OP_HALT)
  1335. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
  1336. else
  1337. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
  1338. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN)
  1339. set_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
  1340. SYM_MASK(SendCtrl_0, TxeAbortIbc) |
  1341. SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
  1342. else
  1343. clr_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
  1344. SYM_MASK(SendCtrl_0, TxeAbortIbc) |
  1345. SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
  1346. spin_lock(&dd->sendctrl_lock);
  1347. /* If we are draining everything, block sends first */
  1348. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
  1349. ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
  1350. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1351. qib_write_kreg(dd, kr_scratch, 0);
  1352. }
  1353. ppd->p_sendctrl |= set_sendctrl;
  1354. ppd->p_sendctrl &= ~clr_sendctrl;
  1355. if (op & QIB_SDMA_SENDCTRL_OP_CLEANUP)
  1356. qib_write_kreg_port(ppd, krp_sendctrl,
  1357. ppd->p_sendctrl |
  1358. SYM_MASK(SendCtrl_0, SDmaCleanup));
  1359. else
  1360. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1361. qib_write_kreg(dd, kr_scratch, 0);
  1362. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
  1363. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
  1364. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1365. qib_write_kreg(dd, kr_scratch, 0);
  1366. }
  1367. spin_unlock(&dd->sendctrl_lock);
  1368. if ((op & QIB_SDMA_SENDCTRL_OP_DRAIN) && ppd->dd->cspec->r1)
  1369. flush_fifo(ppd);
  1370. }
  1371. static void qib_7322_sdma_hw_clean_up(struct qib_pportdata *ppd)
  1372. {
  1373. __qib_sdma_process_event(ppd, qib_sdma_event_e50_hw_cleaned);
  1374. }
  1375. static void qib_sdma_7322_setlengen(struct qib_pportdata *ppd)
  1376. {
  1377. /*
  1378. * Set SendDmaLenGen and clear and set
  1379. * the MSB of the generation count to enable generation checking
  1380. * and load the internal generation counter.
  1381. */
  1382. qib_write_kreg_port(ppd, krp_senddmalengen, ppd->sdma_descq_cnt);
  1383. qib_write_kreg_port(ppd, krp_senddmalengen,
  1384. ppd->sdma_descq_cnt |
  1385. (1ULL << QIB_7322_SendDmaLenGen_0_Generation_MSB));
  1386. }
  1387. /*
  1388. * Must be called with sdma_lock held, or before init finished.
  1389. */
  1390. static void qib_sdma_update_7322_tail(struct qib_pportdata *ppd, u16 tail)
  1391. {
  1392. /* Commit writes to memory and advance the tail on the chip */
  1393. wmb();
  1394. ppd->sdma_descq_tail = tail;
  1395. qib_write_kreg_port(ppd, krp_senddmatail, tail);
  1396. }
  1397. /*
  1398. * This is called with interrupts disabled and sdma_lock held.
  1399. */
  1400. static void qib_7322_sdma_hw_start_up(struct qib_pportdata *ppd)
  1401. {
  1402. /*
  1403. * Drain all FIFOs.
  1404. * The hardware doesn't require this but we do it so that verbs
  1405. * and user applications don't wait for link active to send stale
  1406. * data.
  1407. */
  1408. sendctrl_7322_mod(ppd, QIB_SENDCTRL_FLUSH);
  1409. qib_sdma_7322_setlengen(ppd);
  1410. qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
  1411. ppd->sdma_head_dma[0] = 0;
  1412. qib_7322_sdma_sendctrl(ppd,
  1413. ppd->sdma_state.current_op | QIB_SDMA_SENDCTRL_OP_CLEANUP);
  1414. }
  1415. #define DISABLES_SDMA ( \
  1416. QIB_E_P_SDMAHALT | \
  1417. QIB_E_P_SDMADESCADDRMISALIGN | \
  1418. QIB_E_P_SDMAMISSINGDW | \
  1419. QIB_E_P_SDMADWEN | \
  1420. QIB_E_P_SDMARPYTAG | \
  1421. QIB_E_P_SDMA1STDESC | \
  1422. QIB_E_P_SDMABASE | \
  1423. QIB_E_P_SDMATAILOUTOFBOUND | \
  1424. QIB_E_P_SDMAOUTOFBOUND | \
  1425. QIB_E_P_SDMAGENMISMATCH)
  1426. static void sdma_7322_p_errors(struct qib_pportdata *ppd, u64 errs)
  1427. {
  1428. unsigned long flags;
  1429. struct qib_devdata *dd = ppd->dd;
  1430. errs &= QIB_E_P_SDMAERRS;
  1431. err_decode(ppd->cpspec->sdmamsgbuf, sizeof(ppd->cpspec->sdmamsgbuf),
  1432. errs, qib_7322p_error_msgs);
  1433. if (errs & QIB_E_P_SDMAUNEXPDATA)
  1434. qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", dd->unit,
  1435. ppd->port);
  1436. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1437. if (errs != QIB_E_P_SDMAHALT) {
  1438. /* SDMA errors have QIB_E_P_SDMAHALT and another bit set */
  1439. qib_dev_porterr(dd, ppd->port,
  1440. "SDMA %s 0x%016llx %s\n",
  1441. qib_sdma_state_names[ppd->sdma_state.current_state],
  1442. errs, ppd->cpspec->sdmamsgbuf);
  1443. dump_sdma_7322_state(ppd);
  1444. }
  1445. switch (ppd->sdma_state.current_state) {
  1446. case qib_sdma_state_s00_hw_down:
  1447. break;
  1448. case qib_sdma_state_s10_hw_start_up_wait:
  1449. if (errs & QIB_E_P_SDMAHALT)
  1450. __qib_sdma_process_event(ppd,
  1451. qib_sdma_event_e20_hw_started);
  1452. break;
  1453. case qib_sdma_state_s20_idle:
  1454. break;
  1455. case qib_sdma_state_s30_sw_clean_up_wait:
  1456. break;
  1457. case qib_sdma_state_s40_hw_clean_up_wait:
  1458. if (errs & QIB_E_P_SDMAHALT)
  1459. __qib_sdma_process_event(ppd,
  1460. qib_sdma_event_e50_hw_cleaned);
  1461. break;
  1462. case qib_sdma_state_s50_hw_halt_wait:
  1463. if (errs & QIB_E_P_SDMAHALT)
  1464. __qib_sdma_process_event(ppd,
  1465. qib_sdma_event_e60_hw_halted);
  1466. break;
  1467. case qib_sdma_state_s99_running:
  1468. __qib_sdma_process_event(ppd, qib_sdma_event_e7322_err_halted);
  1469. __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
  1470. break;
  1471. }
  1472. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1473. }
  1474. /*
  1475. * handle per-device errors (not per-port errors)
  1476. */
  1477. static noinline void handle_7322_errors(struct qib_devdata *dd)
  1478. {
  1479. char *msg;
  1480. u64 iserr = 0;
  1481. u64 errs;
  1482. u64 mask;
  1483. qib_stats.sps_errints++;
  1484. errs = qib_read_kreg64(dd, kr_errstatus);
  1485. if (!errs) {
  1486. qib_devinfo(dd->pcidev,
  1487. "device error interrupt, but no error bits set!\n");
  1488. goto done;
  1489. }
  1490. /* don't report errors that are masked */
  1491. errs &= dd->cspec->errormask;
  1492. msg = dd->cspec->emsgbuf;
  1493. /* do these first, they are most important */
  1494. if (errs & QIB_E_HARDWARE) {
  1495. *msg = '\0';
  1496. qib_7322_handle_hwerrors(dd, msg, sizeof(dd->cspec->emsgbuf));
  1497. }
  1498. if (errs & QIB_E_SPKTERRS) {
  1499. qib_disarm_7322_senderrbufs(dd->pport);
  1500. qib_stats.sps_txerrs++;
  1501. } else if (errs & QIB_E_INVALIDADDR)
  1502. qib_stats.sps_txerrs++;
  1503. else if (errs & QIB_E_ARMLAUNCH) {
  1504. qib_stats.sps_txerrs++;
  1505. qib_disarm_7322_senderrbufs(dd->pport);
  1506. }
  1507. qib_write_kreg(dd, kr_errclear, errs);
  1508. /*
  1509. * The ones we mask off are handled specially below
  1510. * or above. Also mask SDMADISABLED by default as it
  1511. * is too chatty.
  1512. */
  1513. mask = QIB_E_HARDWARE;
  1514. *msg = '\0';
  1515. err_decode(msg, sizeof(dd->cspec->emsgbuf), errs & ~mask,
  1516. qib_7322error_msgs);
  1517. /*
  1518. * Getting reset is a tragedy for all ports. Mark the device
  1519. * _and_ the ports as "offline" in way meaningful to each.
  1520. */
  1521. if (errs & QIB_E_RESET) {
  1522. int pidx;
  1523. qib_dev_err(dd,
  1524. "Got reset, requires re-init (unload and reload driver)\n");
  1525. dd->flags &= ~QIB_INITTED; /* needs re-init */
  1526. /* mark as having had error */
  1527. *dd->devstatusp |= QIB_STATUS_HWERROR;
  1528. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1529. if (dd->pport[pidx].link_speed_supported)
  1530. *dd->pport[pidx].statusp &= ~QIB_STATUS_IB_CONF;
  1531. }
  1532. if (*msg && iserr)
  1533. qib_dev_err(dd, "%s error\n", msg);
  1534. /*
  1535. * If there were hdrq or egrfull errors, wake up any processes
  1536. * waiting in poll. We used to try to check which contexts had
  1537. * the overflow, but given the cost of that and the chip reads
  1538. * to support it, it's better to just wake everybody up if we
  1539. * get an overflow; waiters can poll again if it's not them.
  1540. */
  1541. if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
  1542. qib_handle_urcv(dd, ~0U);
  1543. if (errs & ERR_MASK(RcvEgrFullErr))
  1544. qib_stats.sps_buffull++;
  1545. else
  1546. qib_stats.sps_hdrfull++;
  1547. }
  1548. done:
  1549. return;
  1550. }
  1551. static void qib_error_tasklet(unsigned long data)
  1552. {
  1553. struct qib_devdata *dd = (struct qib_devdata *)data;
  1554. handle_7322_errors(dd);
  1555. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1556. }
  1557. static void reenable_chase(struct timer_list *t)
  1558. {
  1559. struct qib_chippport_specific *cp = from_timer(cp, t, chase_timer);
  1560. struct qib_pportdata *ppd = cp->ppd;
  1561. ppd->cpspec->chase_timer.expires = 0;
  1562. qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
  1563. QLOGIC_IB_IBCC_LINKINITCMD_POLL);
  1564. }
  1565. static void disable_chase(struct qib_pportdata *ppd, unsigned long tnow,
  1566. u8 ibclt)
  1567. {
  1568. ppd->cpspec->chase_end = 0;
  1569. if (!qib_chase)
  1570. return;
  1571. qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
  1572. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1573. ppd->cpspec->chase_timer.expires = jiffies + QIB_CHASE_DIS_TIME;
  1574. add_timer(&ppd->cpspec->chase_timer);
  1575. }
  1576. static void handle_serdes_issues(struct qib_pportdata *ppd, u64 ibcst)
  1577. {
  1578. u8 ibclt;
  1579. unsigned long tnow;
  1580. ibclt = (u8)SYM_FIELD(ibcst, IBCStatusA_0, LinkTrainingState);
  1581. /*
  1582. * Detect and handle the state chase issue, where we can
  1583. * get stuck if we are unlucky on timing on both sides of
  1584. * the link. If we are, we disable, set a timer, and
  1585. * then re-enable.
  1586. */
  1587. switch (ibclt) {
  1588. case IB_7322_LT_STATE_CFGRCVFCFG:
  1589. case IB_7322_LT_STATE_CFGWAITRMT:
  1590. case IB_7322_LT_STATE_TXREVLANES:
  1591. case IB_7322_LT_STATE_CFGENH:
  1592. tnow = jiffies;
  1593. if (ppd->cpspec->chase_end &&
  1594. time_after(tnow, ppd->cpspec->chase_end))
  1595. disable_chase(ppd, tnow, ibclt);
  1596. else if (!ppd->cpspec->chase_end)
  1597. ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
  1598. break;
  1599. default:
  1600. ppd->cpspec->chase_end = 0;
  1601. break;
  1602. }
  1603. if (((ibclt >= IB_7322_LT_STATE_CFGTEST &&
  1604. ibclt <= IB_7322_LT_STATE_CFGWAITENH) ||
  1605. ibclt == IB_7322_LT_STATE_LINKUP) &&
  1606. (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR))) {
  1607. force_h1(ppd);
  1608. ppd->cpspec->qdr_reforce = 1;
  1609. if (!ppd->dd->cspec->r1)
  1610. serdes_7322_los_enable(ppd, 0);
  1611. } else if (ppd->cpspec->qdr_reforce &&
  1612. (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) &&
  1613. (ibclt == IB_7322_LT_STATE_CFGENH ||
  1614. ibclt == IB_7322_LT_STATE_CFGIDLE ||
  1615. ibclt == IB_7322_LT_STATE_LINKUP))
  1616. force_h1(ppd);
  1617. if ((IS_QMH(ppd->dd) || IS_QME(ppd->dd)) &&
  1618. ppd->link_speed_enabled == QIB_IB_QDR &&
  1619. (ibclt == IB_7322_LT_STATE_CFGTEST ||
  1620. ibclt == IB_7322_LT_STATE_CFGENH ||
  1621. (ibclt >= IB_7322_LT_STATE_POLLACTIVE &&
  1622. ibclt <= IB_7322_LT_STATE_SLEEPQUIET)))
  1623. adj_tx_serdes(ppd);
  1624. if (ibclt != IB_7322_LT_STATE_LINKUP) {
  1625. u8 ltstate = qib_7322_phys_portstate(ibcst);
  1626. u8 pibclt = (u8)SYM_FIELD(ppd->lastibcstat, IBCStatusA_0,
  1627. LinkTrainingState);
  1628. if (!ppd->dd->cspec->r1 &&
  1629. pibclt == IB_7322_LT_STATE_LINKUP &&
  1630. ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
  1631. ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
  1632. ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
  1633. ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
  1634. /* If the link went down (but no into recovery,
  1635. * turn LOS back on */
  1636. serdes_7322_los_enable(ppd, 1);
  1637. if (!ppd->cpspec->qdr_dfe_on &&
  1638. ibclt <= IB_7322_LT_STATE_SLEEPQUIET) {
  1639. ppd->cpspec->qdr_dfe_on = 1;
  1640. ppd->cpspec->qdr_dfe_time = 0;
  1641. /* On link down, reenable QDR adaptation */
  1642. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  1643. ppd->dd->cspec->r1 ?
  1644. QDR_STATIC_ADAPT_DOWN_R1 :
  1645. QDR_STATIC_ADAPT_DOWN);
  1646. pr_info(
  1647. "IB%u:%u re-enabled QDR adaptation ibclt %x\n",
  1648. ppd->dd->unit, ppd->port, ibclt);
  1649. }
  1650. }
  1651. }
  1652. static int qib_7322_set_ib_cfg(struct qib_pportdata *, int, u32);
  1653. /*
  1654. * This is per-pport error handling.
  1655. * will likely get it's own MSIx interrupt (one for each port,
  1656. * although just a single handler).
  1657. */
  1658. static noinline void handle_7322_p_errors(struct qib_pportdata *ppd)
  1659. {
  1660. char *msg;
  1661. u64 ignore_this_time = 0, iserr = 0, errs, fmask;
  1662. struct qib_devdata *dd = ppd->dd;
  1663. /* do this as soon as possible */
  1664. fmask = qib_read_kreg64(dd, kr_act_fmask);
  1665. if (!fmask)
  1666. check_7322_rxe_status(ppd);
  1667. errs = qib_read_kreg_port(ppd, krp_errstatus);
  1668. if (!errs)
  1669. qib_devinfo(dd->pcidev,
  1670. "Port%d error interrupt, but no error bits set!\n",
  1671. ppd->port);
  1672. if (!fmask)
  1673. errs &= ~QIB_E_P_IBSTATUSCHANGED;
  1674. if (!errs)
  1675. goto done;
  1676. msg = ppd->cpspec->epmsgbuf;
  1677. *msg = '\0';
  1678. if (errs & ~QIB_E_P_BITSEXTANT) {
  1679. err_decode(msg, sizeof(ppd->cpspec->epmsgbuf),
  1680. errs & ~QIB_E_P_BITSEXTANT, qib_7322p_error_msgs);
  1681. if (!*msg)
  1682. snprintf(msg, sizeof(ppd->cpspec->epmsgbuf),
  1683. "no others");
  1684. qib_dev_porterr(dd, ppd->port,
  1685. "error interrupt with unknown errors 0x%016Lx set (and %s)\n",
  1686. (errs & ~QIB_E_P_BITSEXTANT), msg);
  1687. *msg = '\0';
  1688. }
  1689. if (errs & QIB_E_P_SHDR) {
  1690. u64 symptom;
  1691. /* determine cause, then write to clear */
  1692. symptom = qib_read_kreg_port(ppd, krp_sendhdrsymptom);
  1693. qib_write_kreg_port(ppd, krp_sendhdrsymptom, 0);
  1694. err_decode(msg, sizeof(ppd->cpspec->epmsgbuf), symptom,
  1695. hdrchk_msgs);
  1696. *msg = '\0';
  1697. /* senderrbuf cleared in SPKTERRS below */
  1698. }
  1699. if (errs & QIB_E_P_SPKTERRS) {
  1700. if ((errs & QIB_E_P_LINK_PKTERRS) &&
  1701. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1702. /*
  1703. * This can happen when trying to bring the link
  1704. * up, but the IB link changes state at the "wrong"
  1705. * time. The IB logic then complains that the packet
  1706. * isn't valid. We don't want to confuse people, so
  1707. * we just don't print them, except at debug
  1708. */
  1709. err_decode(msg, sizeof(ppd->cpspec->epmsgbuf),
  1710. (errs & QIB_E_P_LINK_PKTERRS),
  1711. qib_7322p_error_msgs);
  1712. *msg = '\0';
  1713. ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
  1714. }
  1715. qib_disarm_7322_senderrbufs(ppd);
  1716. } else if ((errs & QIB_E_P_LINK_PKTERRS) &&
  1717. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1718. /*
  1719. * This can happen when SMA is trying to bring the link
  1720. * up, but the IB link changes state at the "wrong" time.
  1721. * The IB logic then complains that the packet isn't
  1722. * valid. We don't want to confuse people, so we just
  1723. * don't print them, except at debug
  1724. */
  1725. err_decode(msg, sizeof(ppd->cpspec->epmsgbuf), errs,
  1726. qib_7322p_error_msgs);
  1727. ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
  1728. *msg = '\0';
  1729. }
  1730. qib_write_kreg_port(ppd, krp_errclear, errs);
  1731. errs &= ~ignore_this_time;
  1732. if (!errs)
  1733. goto done;
  1734. if (errs & QIB_E_P_RPKTERRS)
  1735. qib_stats.sps_rcverrs++;
  1736. if (errs & QIB_E_P_SPKTERRS)
  1737. qib_stats.sps_txerrs++;
  1738. iserr = errs & ~(QIB_E_P_RPKTERRS | QIB_E_P_PKTERRS);
  1739. if (errs & QIB_E_P_SDMAERRS)
  1740. sdma_7322_p_errors(ppd, errs);
  1741. if (errs & QIB_E_P_IBSTATUSCHANGED) {
  1742. u64 ibcs;
  1743. u8 ltstate;
  1744. ibcs = qib_read_kreg_port(ppd, krp_ibcstatus_a);
  1745. ltstate = qib_7322_phys_portstate(ibcs);
  1746. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  1747. handle_serdes_issues(ppd, ibcs);
  1748. if (!(ppd->cpspec->ibcctrl_a &
  1749. SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn))) {
  1750. /*
  1751. * We got our interrupt, so init code should be
  1752. * happy and not try alternatives. Now squelch
  1753. * other "chatter" from link-negotiation (pre Init)
  1754. */
  1755. ppd->cpspec->ibcctrl_a |=
  1756. SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  1757. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  1758. ppd->cpspec->ibcctrl_a);
  1759. }
  1760. /* Update our picture of width and speed from chip */
  1761. ppd->link_width_active =
  1762. (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) ?
  1763. IB_WIDTH_4X : IB_WIDTH_1X;
  1764. ppd->link_speed_active = (ibcs & SYM_MASK(IBCStatusA_0,
  1765. LinkSpeedQDR)) ? QIB_IB_QDR : (ibcs &
  1766. SYM_MASK(IBCStatusA_0, LinkSpeedActive)) ?
  1767. QIB_IB_DDR : QIB_IB_SDR;
  1768. if ((ppd->lflags & QIBL_IB_LINK_DISABLED) && ltstate !=
  1769. IB_PHYSPORTSTATE_DISABLED)
  1770. qib_set_ib_7322_lstate(ppd, 0,
  1771. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1772. else
  1773. /*
  1774. * Since going into a recovery state causes the link
  1775. * state to go down and since recovery is transitory,
  1776. * it is better if we "miss" ever seeing the link
  1777. * training state go into recovery (i.e., ignore this
  1778. * transition for link state special handling purposes)
  1779. * without updating lastibcstat.
  1780. */
  1781. if (ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
  1782. ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
  1783. ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
  1784. ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
  1785. qib_handle_e_ibstatuschanged(ppd, ibcs);
  1786. }
  1787. if (*msg && iserr)
  1788. qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
  1789. if (ppd->state_wanted & ppd->lflags)
  1790. wake_up_interruptible(&ppd->state_wait);
  1791. done:
  1792. return;
  1793. }
  1794. /* enable/disable chip from delivering interrupts */
  1795. static void qib_7322_set_intr_state(struct qib_devdata *dd, u32 enable)
  1796. {
  1797. if (enable) {
  1798. if (dd->flags & QIB_BADINTR)
  1799. return;
  1800. qib_write_kreg(dd, kr_intmask, dd->cspec->int_enable_mask);
  1801. /* cause any pending enabled interrupts to be re-delivered */
  1802. qib_write_kreg(dd, kr_intclear, 0ULL);
  1803. if (dd->cspec->num_msix_entries) {
  1804. /* and same for MSIx */
  1805. u64 val = qib_read_kreg64(dd, kr_intgranted);
  1806. if (val)
  1807. qib_write_kreg(dd, kr_intgranted, val);
  1808. }
  1809. } else
  1810. qib_write_kreg(dd, kr_intmask, 0ULL);
  1811. }
  1812. /*
  1813. * Try to cleanup as much as possible for anything that might have gone
  1814. * wrong while in freeze mode, such as pio buffers being written by user
  1815. * processes (causing armlaunch), send errors due to going into freeze mode,
  1816. * etc., and try to avoid causing extra interrupts while doing so.
  1817. * Forcibly update the in-memory pioavail register copies after cleanup
  1818. * because the chip won't do it while in freeze mode (the register values
  1819. * themselves are kept correct).
  1820. * Make sure that we don't lose any important interrupts by using the chip
  1821. * feature that says that writing 0 to a bit in *clear that is set in
  1822. * *status will cause an interrupt to be generated again (if allowed by
  1823. * the *mask value).
  1824. * This is in chip-specific code because of all of the register accesses,
  1825. * even though the details are similar on most chips.
  1826. */
  1827. static void qib_7322_clear_freeze(struct qib_devdata *dd)
  1828. {
  1829. int pidx;
  1830. /* disable error interrupts, to avoid confusion */
  1831. qib_write_kreg(dd, kr_errmask, 0ULL);
  1832. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1833. if (dd->pport[pidx].link_speed_supported)
  1834. qib_write_kreg_port(dd->pport + pidx, krp_errmask,
  1835. 0ULL);
  1836. /* also disable interrupts; errormask is sometimes overwritten */
  1837. qib_7322_set_intr_state(dd, 0);
  1838. /* clear the freeze, and be sure chip saw it */
  1839. qib_write_kreg(dd, kr_control, dd->control);
  1840. qib_read_kreg32(dd, kr_scratch);
  1841. /*
  1842. * Force new interrupt if any hwerr, error or interrupt bits are
  1843. * still set, and clear "safe" send packet errors related to freeze
  1844. * and cancelling sends. Re-enable error interrupts before possible
  1845. * force of re-interrupt on pending interrupts.
  1846. */
  1847. qib_write_kreg(dd, kr_hwerrclear, 0ULL);
  1848. qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
  1849. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1850. /* We need to purge per-port errs and reset mask, too */
  1851. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  1852. if (!dd->pport[pidx].link_speed_supported)
  1853. continue;
  1854. qib_write_kreg_port(dd->pport + pidx, krp_errclear, ~0Ull);
  1855. qib_write_kreg_port(dd->pport + pidx, krp_errmask, ~0Ull);
  1856. }
  1857. qib_7322_set_intr_state(dd, 1);
  1858. }
  1859. /* no error handling to speak of */
  1860. /**
  1861. * qib_7322_handle_hwerrors - display hardware errors.
  1862. * @dd: the qlogic_ib device
  1863. * @msg: the output buffer
  1864. * @msgl: the size of the output buffer
  1865. *
  1866. * Use same msg buffer as regular errors to avoid excessive stack
  1867. * use. Most hardware errors are catastrophic, but for right now,
  1868. * we'll print them and continue. We reuse the same message buffer as
  1869. * qib_handle_errors() to avoid excessive stack usage.
  1870. */
  1871. static void qib_7322_handle_hwerrors(struct qib_devdata *dd, char *msg,
  1872. size_t msgl)
  1873. {
  1874. u64 hwerrs;
  1875. u32 ctrl;
  1876. int isfatal = 0;
  1877. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  1878. if (!hwerrs)
  1879. goto bail;
  1880. if (hwerrs == ~0ULL) {
  1881. qib_dev_err(dd,
  1882. "Read of hardware error status failed (all bits set); ignoring\n");
  1883. goto bail;
  1884. }
  1885. qib_stats.sps_hwerrs++;
  1886. /* Always clear the error status register, except BIST fail */
  1887. qib_write_kreg(dd, kr_hwerrclear, hwerrs &
  1888. ~HWE_MASK(PowerOnBISTFailed));
  1889. hwerrs &= dd->cspec->hwerrmask;
  1890. /* no EEPROM logging, yet */
  1891. if (hwerrs)
  1892. qib_devinfo(dd->pcidev,
  1893. "Hardware error: hwerr=0x%llx (cleared)\n",
  1894. (unsigned long long) hwerrs);
  1895. ctrl = qib_read_kreg32(dd, kr_control);
  1896. if ((ctrl & SYM_MASK(Control, FreezeMode)) && !dd->diag_client) {
  1897. /*
  1898. * No recovery yet...
  1899. */
  1900. if ((hwerrs & ~HWE_MASK(LATriggered)) ||
  1901. dd->cspec->stay_in_freeze) {
  1902. /*
  1903. * If any set that we aren't ignoring only make the
  1904. * complaint once, in case it's stuck or recurring,
  1905. * and we get here multiple times
  1906. * Force link down, so switch knows, and
  1907. * LEDs are turned off.
  1908. */
  1909. if (dd->flags & QIB_INITTED)
  1910. isfatal = 1;
  1911. } else
  1912. qib_7322_clear_freeze(dd);
  1913. }
  1914. if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
  1915. isfatal = 1;
  1916. strlcpy(msg,
  1917. "[Memory BIST test failed, InfiniPath hardware unusable]",
  1918. msgl);
  1919. /* ignore from now on, so disable until driver reloaded */
  1920. dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
  1921. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1922. }
  1923. err_decode(msg, msgl, hwerrs, qib_7322_hwerror_msgs);
  1924. /* Ignore esoteric PLL failures et al. */
  1925. qib_dev_err(dd, "%s hardware error\n", msg);
  1926. if (hwerrs &
  1927. (SYM_MASK(HwErrMask, SDmaMemReadErrMask_0) |
  1928. SYM_MASK(HwErrMask, SDmaMemReadErrMask_1))) {
  1929. int pidx = 0;
  1930. int err;
  1931. unsigned long flags;
  1932. struct qib_pportdata *ppd = dd->pport;
  1933. for (; pidx < dd->num_pports; ++pidx, ppd++) {
  1934. err = 0;
  1935. if (pidx == 0 && (hwerrs &
  1936. SYM_MASK(HwErrMask, SDmaMemReadErrMask_0)))
  1937. err++;
  1938. if (pidx == 1 && (hwerrs &
  1939. SYM_MASK(HwErrMask, SDmaMemReadErrMask_1)))
  1940. err++;
  1941. if (err) {
  1942. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1943. dump_sdma_7322_state(ppd);
  1944. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1945. }
  1946. }
  1947. }
  1948. if (isfatal && !dd->diag_client) {
  1949. qib_dev_err(dd,
  1950. "Fatal Hardware Error, no longer usable, SN %.16s\n",
  1951. dd->serial);
  1952. /*
  1953. * for /sys status file and user programs to print; if no
  1954. * trailing brace is copied, we'll know it was truncated.
  1955. */
  1956. if (dd->freezemsg)
  1957. snprintf(dd->freezemsg, dd->freezelen,
  1958. "{%s}", msg);
  1959. qib_disable_after_error(dd);
  1960. }
  1961. bail:;
  1962. }
  1963. /**
  1964. * qib_7322_init_hwerrors - enable hardware errors
  1965. * @dd: the qlogic_ib device
  1966. *
  1967. * now that we have finished initializing everything that might reasonably
  1968. * cause a hardware error, and cleared those errors bits as they occur,
  1969. * we can enable hardware errors in the mask (potentially enabling
  1970. * freeze mode), and enable hardware errors as errors (along with
  1971. * everything else) in errormask
  1972. */
  1973. static void qib_7322_init_hwerrors(struct qib_devdata *dd)
  1974. {
  1975. int pidx;
  1976. u64 extsval;
  1977. extsval = qib_read_kreg64(dd, kr_extstatus);
  1978. if (!(extsval & (QIB_EXTS_MEMBIST_DISABLED |
  1979. QIB_EXTS_MEMBIST_ENDTEST)))
  1980. qib_dev_err(dd, "MemBIST did not complete!\n");
  1981. /* never clear BIST failure, so reported on each driver load */
  1982. qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
  1983. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1984. /* clear all */
  1985. qib_write_kreg(dd, kr_errclear, ~0ULL);
  1986. /* enable errors that are masked, at least this first time. */
  1987. qib_write_kreg(dd, kr_errmask, ~0ULL);
  1988. dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
  1989. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1990. if (dd->pport[pidx].link_speed_supported)
  1991. qib_write_kreg_port(dd->pport + pidx, krp_errmask,
  1992. ~0ULL);
  1993. }
  1994. /*
  1995. * Disable and enable the armlaunch error. Used for PIO bandwidth testing
  1996. * on chips that are count-based, rather than trigger-based. There is no
  1997. * reference counting, but that's also fine, given the intended use.
  1998. * Only chip-specific because it's all register accesses
  1999. */
  2000. static void qib_set_7322_armlaunch(struct qib_devdata *dd, u32 enable)
  2001. {
  2002. if (enable) {
  2003. qib_write_kreg(dd, kr_errclear, QIB_E_SPIOARMLAUNCH);
  2004. dd->cspec->errormask |= QIB_E_SPIOARMLAUNCH;
  2005. } else
  2006. dd->cspec->errormask &= ~QIB_E_SPIOARMLAUNCH;
  2007. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  2008. }
  2009. /*
  2010. * Formerly took parameter <which> in pre-shifted,
  2011. * pre-merged form with LinkCmd and LinkInitCmd
  2012. * together, and assuming the zero was NOP.
  2013. */
  2014. static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  2015. u16 linitcmd)
  2016. {
  2017. u64 mod_wd;
  2018. struct qib_devdata *dd = ppd->dd;
  2019. unsigned long flags;
  2020. if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
  2021. /*
  2022. * If we are told to disable, note that so link-recovery
  2023. * code does not attempt to bring us back up.
  2024. * Also reset everything that we can, so we start
  2025. * completely clean when re-enabled (before we
  2026. * actually issue the disable to the IBC)
  2027. */
  2028. qib_7322_mini_pcs_reset(ppd);
  2029. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2030. ppd->lflags |= QIBL_IB_LINK_DISABLED;
  2031. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2032. } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
  2033. /*
  2034. * Any other linkinitcmd will lead to LINKDOWN and then
  2035. * to INIT (if all is well), so clear flag to let
  2036. * link-recovery code attempt to bring us back up.
  2037. */
  2038. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2039. ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
  2040. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2041. /*
  2042. * Clear status change interrupt reduction so the
  2043. * new state is seen.
  2044. */
  2045. ppd->cpspec->ibcctrl_a &=
  2046. ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  2047. }
  2048. mod_wd = (linkcmd << IBA7322_IBCC_LINKCMD_SHIFT) |
  2049. (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  2050. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a |
  2051. mod_wd);
  2052. /* write to chip to prevent back-to-back writes of ibc reg */
  2053. qib_write_kreg(dd, kr_scratch, 0);
  2054. }
  2055. /*
  2056. * The total RCV buffer memory is 64KB, used for both ports, and is
  2057. * in units of 64 bytes (same as IB flow control credit unit).
  2058. * The consumedVL unit in the same registers are in 32 byte units!
  2059. * So, a VL15 packet needs 4.50 IB credits, and 9 rx buffer chunks,
  2060. * and we can therefore allocate just 9 IB credits for 2 VL15 packets
  2061. * in krp_rxcreditvl15, rather than 10.
  2062. */
  2063. #define RCV_BUF_UNITSZ 64
  2064. #define NUM_RCV_BUF_UNITS(dd) ((64 * 1024) / (RCV_BUF_UNITSZ * dd->num_pports))
  2065. static void set_vls(struct qib_pportdata *ppd)
  2066. {
  2067. int i, numvls, totcred, cred_vl, vl0extra;
  2068. struct qib_devdata *dd = ppd->dd;
  2069. u64 val;
  2070. numvls = qib_num_vls(ppd->vls_operational);
  2071. /*
  2072. * Set up per-VL credits. Below is kluge based on these assumptions:
  2073. * 1) port is disabled at the time early_init is called.
  2074. * 2) give VL15 17 credits, for two max-plausible packets.
  2075. * 3) Give VL0-N the rest, with any rounding excess used for VL0
  2076. */
  2077. /* 2 VL15 packets @ 288 bytes each (including IB headers) */
  2078. totcred = NUM_RCV_BUF_UNITS(dd);
  2079. cred_vl = (2 * 288 + RCV_BUF_UNITSZ - 1) / RCV_BUF_UNITSZ;
  2080. totcred -= cred_vl;
  2081. qib_write_kreg_port(ppd, krp_rxcreditvl15, (u64) cred_vl);
  2082. cred_vl = totcred / numvls;
  2083. vl0extra = totcred - cred_vl * numvls;
  2084. qib_write_kreg_port(ppd, krp_rxcreditvl0, cred_vl + vl0extra);
  2085. for (i = 1; i < numvls; i++)
  2086. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, cred_vl);
  2087. for (; i < 8; i++) /* no buffer space for other VLs */
  2088. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
  2089. /* Notify IBC that credits need to be recalculated */
  2090. val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
  2091. val |= SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
  2092. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  2093. qib_write_kreg(dd, kr_scratch, 0ULL);
  2094. val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
  2095. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  2096. for (i = 0; i < numvls; i++)
  2097. val = qib_read_kreg_port(ppd, krp_rxcreditvl0 + i);
  2098. val = qib_read_kreg_port(ppd, krp_rxcreditvl15);
  2099. /* Change the number of operational VLs */
  2100. ppd->cpspec->ibcctrl_a = (ppd->cpspec->ibcctrl_a &
  2101. ~SYM_MASK(IBCCtrlA_0, NumVLane)) |
  2102. ((u64)(numvls - 1) << SYM_LSB(IBCCtrlA_0, NumVLane));
  2103. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  2104. qib_write_kreg(dd, kr_scratch, 0ULL);
  2105. }
  2106. /*
  2107. * The code that deals with actual SerDes is in serdes_7322_init().
  2108. * Compared to the code for iba7220, it is minimal.
  2109. */
  2110. static int serdes_7322_init(struct qib_pportdata *ppd);
  2111. /**
  2112. * qib_7322_bringup_serdes - bring up the serdes
  2113. * @ppd: physical port on the qlogic_ib device
  2114. */
  2115. static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
  2116. {
  2117. struct qib_devdata *dd = ppd->dd;
  2118. u64 val, guid, ibc;
  2119. unsigned long flags;
  2120. int ret = 0;
  2121. /*
  2122. * SerDes model not in Pd, but still need to
  2123. * set up much of IBCCtrl and IBCDDRCtrl; move elsewhere
  2124. * eventually.
  2125. */
  2126. /* Put IBC in reset, sends disabled (should be in reset already) */
  2127. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2128. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  2129. qib_write_kreg(dd, kr_scratch, 0ULL);
  2130. /* ensure previous Tx parameters are not still forced */
  2131. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  2132. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  2133. reset_tx_deemphasis_override));
  2134. if (qib_compat_ddr_negotiate) {
  2135. ppd->cpspec->ibdeltainprog = 1;
  2136. ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
  2137. crp_ibsymbolerr);
  2138. ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
  2139. crp_iblinkerrrecov);
  2140. }
  2141. /* flowcontrolwatermark is in units of KBytes */
  2142. ibc = 0x5ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlWaterMark);
  2143. /*
  2144. * Flow control is sent this often, even if no changes in
  2145. * buffer space occur. Units are 128ns for this chip.
  2146. * Set to 3usec.
  2147. */
  2148. ibc |= 24ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlPeriod);
  2149. /* max error tolerance */
  2150. ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
  2151. /* IB credit flow control. */
  2152. ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, OverrunThreshold);
  2153. /*
  2154. * set initial max size pkt IBC will send, including ICRC; it's the
  2155. * PIO buffer size in dwords, less 1; also see qib_set_mtu()
  2156. */
  2157. ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) <<
  2158. SYM_LSB(IBCCtrlA_0, MaxPktLen);
  2159. ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */
  2160. /*
  2161. * Reset the PCS interface to the serdes (and also ibc, which is still
  2162. * in reset from above). Writes new value of ibcctrl_a as last step.
  2163. */
  2164. qib_7322_mini_pcs_reset(ppd);
  2165. if (!ppd->cpspec->ibcctrl_b) {
  2166. unsigned lse = ppd->link_speed_enabled;
  2167. /*
  2168. * Not on re-init after reset, establish shadow
  2169. * and force initial config.
  2170. */
  2171. ppd->cpspec->ibcctrl_b = qib_read_kreg_port(ppd,
  2172. krp_ibcctrl_b);
  2173. ppd->cpspec->ibcctrl_b &= ~(IBA7322_IBC_SPEED_QDR |
  2174. IBA7322_IBC_SPEED_DDR |
  2175. IBA7322_IBC_SPEED_SDR |
  2176. IBA7322_IBC_WIDTH_AUTONEG |
  2177. SYM_MASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED));
  2178. if (lse & (lse - 1)) /* Muliple speeds enabled */
  2179. ppd->cpspec->ibcctrl_b |=
  2180. (lse << IBA7322_IBC_SPEED_LSB) |
  2181. IBA7322_IBC_IBTA_1_2_MASK |
  2182. IBA7322_IBC_MAX_SPEED_MASK;
  2183. else
  2184. ppd->cpspec->ibcctrl_b |= (lse == QIB_IB_QDR) ?
  2185. IBA7322_IBC_SPEED_QDR |
  2186. IBA7322_IBC_IBTA_1_2_MASK :
  2187. (lse == QIB_IB_DDR) ?
  2188. IBA7322_IBC_SPEED_DDR :
  2189. IBA7322_IBC_SPEED_SDR;
  2190. if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
  2191. (IB_WIDTH_1X | IB_WIDTH_4X))
  2192. ppd->cpspec->ibcctrl_b |= IBA7322_IBC_WIDTH_AUTONEG;
  2193. else
  2194. ppd->cpspec->ibcctrl_b |=
  2195. ppd->link_width_enabled == IB_WIDTH_4X ?
  2196. IBA7322_IBC_WIDTH_4X_ONLY :
  2197. IBA7322_IBC_WIDTH_1X_ONLY;
  2198. /* always enable these on driver reload, not sticky */
  2199. ppd->cpspec->ibcctrl_b |= (IBA7322_IBC_RXPOL_MASK |
  2200. IBA7322_IBC_HRTBT_MASK);
  2201. }
  2202. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  2203. /* setup so we have more time at CFGTEST to change H1 */
  2204. val = qib_read_kreg_port(ppd, krp_ibcctrl_c);
  2205. val &= ~SYM_MASK(IBCCtrlC_0, IB_FRONT_PORCH);
  2206. val |= 0xfULL << SYM_LSB(IBCCtrlC_0, IB_FRONT_PORCH);
  2207. qib_write_kreg_port(ppd, krp_ibcctrl_c, val);
  2208. serdes_7322_init(ppd);
  2209. guid = be64_to_cpu(ppd->guid);
  2210. if (!guid) {
  2211. if (dd->base_guid)
  2212. guid = be64_to_cpu(dd->base_guid) + ppd->port - 1;
  2213. ppd->guid = cpu_to_be64(guid);
  2214. }
  2215. qib_write_kreg_port(ppd, krp_hrtbt_guid, guid);
  2216. /* write to chip to prevent back-to-back writes of ibc reg */
  2217. qib_write_kreg(dd, kr_scratch, 0);
  2218. /* Enable port */
  2219. ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2220. set_vls(ppd);
  2221. /* initially come up DISABLED, without sending anything. */
  2222. val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
  2223. QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  2224. qib_write_kreg_port(ppd, krp_ibcctrl_a, val);
  2225. qib_write_kreg(dd, kr_scratch, 0ULL);
  2226. /* clear the linkinit cmds */
  2227. ppd->cpspec->ibcctrl_a = val & ~SYM_MASK(IBCCtrlA_0, LinkInitCmd);
  2228. /* be paranoid against later code motion, etc. */
  2229. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  2230. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
  2231. qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
  2232. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  2233. /* Also enable IBSTATUSCHG interrupt. */
  2234. val = qib_read_kreg_port(ppd, krp_errmask);
  2235. qib_write_kreg_port(ppd, krp_errmask,
  2236. val | ERR_MASK_N(IBStatusChanged));
  2237. /* Always zero until we start messing with SerDes for real */
  2238. return ret;
  2239. }
  2240. /**
  2241. * qib_7322_quiet_serdes - set serdes to txidle
  2242. * @dd: the qlogic_ib device
  2243. * Called when driver is being unloaded
  2244. */
  2245. static void qib_7322_mini_quiet_serdes(struct qib_pportdata *ppd)
  2246. {
  2247. u64 val;
  2248. unsigned long flags;
  2249. qib_set_ib_7322_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  2250. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2251. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  2252. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2253. wake_up(&ppd->cpspec->autoneg_wait);
  2254. cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
  2255. if (ppd->dd->cspec->r1)
  2256. cancel_delayed_work_sync(&ppd->cpspec->ipg_work);
  2257. ppd->cpspec->chase_end = 0;
  2258. if (ppd->cpspec->chase_timer.function) /* if initted */
  2259. del_timer_sync(&ppd->cpspec->chase_timer);
  2260. /*
  2261. * Despite the name, actually disables IBC as well. Do it when
  2262. * we are as sure as possible that no more packets can be
  2263. * received, following the down and the PCS reset.
  2264. * The actual disabling happens in qib_7322_mini_pci_reset(),
  2265. * along with the PCS being reset.
  2266. */
  2267. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2268. qib_7322_mini_pcs_reset(ppd);
  2269. /*
  2270. * Update the adjusted counters so the adjustment persists
  2271. * across driver reload.
  2272. */
  2273. if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
  2274. ppd->cpspec->ibdeltainprog || ppd->cpspec->iblnkdowndelta) {
  2275. struct qib_devdata *dd = ppd->dd;
  2276. u64 diagc;
  2277. /* enable counter writes */
  2278. diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
  2279. qib_write_kreg(dd, kr_hwdiagctrl,
  2280. diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
  2281. if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
  2282. val = read_7322_creg32_port(ppd, crp_ibsymbolerr);
  2283. if (ppd->cpspec->ibdeltainprog)
  2284. val -= val - ppd->cpspec->ibsymsnap;
  2285. val -= ppd->cpspec->ibsymdelta;
  2286. write_7322_creg_port(ppd, crp_ibsymbolerr, val);
  2287. }
  2288. if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
  2289. val = read_7322_creg32_port(ppd, crp_iblinkerrrecov);
  2290. if (ppd->cpspec->ibdeltainprog)
  2291. val -= val - ppd->cpspec->iblnkerrsnap;
  2292. val -= ppd->cpspec->iblnkerrdelta;
  2293. write_7322_creg_port(ppd, crp_iblinkerrrecov, val);
  2294. }
  2295. if (ppd->cpspec->iblnkdowndelta) {
  2296. val = read_7322_creg32_port(ppd, crp_iblinkdown);
  2297. val += ppd->cpspec->iblnkdowndelta;
  2298. write_7322_creg_port(ppd, crp_iblinkdown, val);
  2299. }
  2300. /*
  2301. * No need to save ibmalfdelta since IB perfcounters
  2302. * are cleared on driver reload.
  2303. */
  2304. /* and disable counter writes */
  2305. qib_write_kreg(dd, kr_hwdiagctrl, diagc);
  2306. }
  2307. }
  2308. /**
  2309. * qib_setup_7322_setextled - set the state of the two external LEDs
  2310. * @ppd: physical port on the qlogic_ib device
  2311. * @on: whether the link is up or not
  2312. *
  2313. * The exact combo of LEDs if on is true is determined by looking
  2314. * at the ibcstatus.
  2315. *
  2316. * These LEDs indicate the physical and logical state of IB link.
  2317. * For this chip (at least with recommended board pinouts), LED1
  2318. * is Yellow (logical state) and LED2 is Green (physical state),
  2319. *
  2320. * Note: We try to match the Mellanox HCA LED behavior as best
  2321. * we can. Green indicates physical link state is OK (something is
  2322. * plugged in, and we can train).
  2323. * Amber indicates the link is logically up (ACTIVE).
  2324. * Mellanox further blinks the amber LED to indicate data packet
  2325. * activity, but we have no hardware support for that, so it would
  2326. * require waking up every 10-20 msecs and checking the counters
  2327. * on the chip, and then turning the LED off if appropriate. That's
  2328. * visible overhead, so not something we will do.
  2329. */
  2330. static void qib_setup_7322_setextled(struct qib_pportdata *ppd, u32 on)
  2331. {
  2332. struct qib_devdata *dd = ppd->dd;
  2333. u64 extctl, ledblink = 0, val;
  2334. unsigned long flags;
  2335. int yel, grn;
  2336. /*
  2337. * The diags use the LED to indicate diag info, so we leave
  2338. * the external LED alone when the diags are running.
  2339. */
  2340. if (dd->diag_client)
  2341. return;
  2342. /* Allow override of LED display for, e.g. Locating system in rack */
  2343. if (ppd->led_override) {
  2344. grn = (ppd->led_override & QIB_LED_PHYS);
  2345. yel = (ppd->led_override & QIB_LED_LOG);
  2346. } else if (on) {
  2347. val = qib_read_kreg_port(ppd, krp_ibcstatus_a);
  2348. grn = qib_7322_phys_portstate(val) ==
  2349. IB_PHYSPORTSTATE_LINKUP;
  2350. yel = qib_7322_iblink_state(val) == IB_PORT_ACTIVE;
  2351. } else {
  2352. grn = 0;
  2353. yel = 0;
  2354. }
  2355. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2356. extctl = dd->cspec->extctrl & (ppd->port == 1 ?
  2357. ~ExtLED_IB1_MASK : ~ExtLED_IB2_MASK);
  2358. if (grn) {
  2359. extctl |= ppd->port == 1 ? ExtLED_IB1_GRN : ExtLED_IB2_GRN;
  2360. /*
  2361. * Counts are in chip clock (4ns) periods.
  2362. * This is 1/16 sec (66.6ms) on,
  2363. * 3/16 sec (187.5 ms) off, with packets rcvd.
  2364. */
  2365. ledblink = ((66600 * 1000UL / 4) << IBA7322_LEDBLINK_ON_SHIFT) |
  2366. ((187500 * 1000UL / 4) << IBA7322_LEDBLINK_OFF_SHIFT);
  2367. }
  2368. if (yel)
  2369. extctl |= ppd->port == 1 ? ExtLED_IB1_YEL : ExtLED_IB2_YEL;
  2370. dd->cspec->extctrl = extctl;
  2371. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  2372. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2373. if (ledblink) /* blink the LED on packet receive */
  2374. qib_write_kreg_port(ppd, krp_rcvpktledcnt, ledblink);
  2375. }
  2376. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2377. static int qib_7322_notify_dca(struct qib_devdata *dd, unsigned long event)
  2378. {
  2379. switch (event) {
  2380. case DCA_PROVIDER_ADD:
  2381. if (dd->flags & QIB_DCA_ENABLED)
  2382. break;
  2383. if (!dca_add_requester(&dd->pcidev->dev)) {
  2384. qib_devinfo(dd->pcidev, "DCA enabled\n");
  2385. dd->flags |= QIB_DCA_ENABLED;
  2386. qib_setup_dca(dd);
  2387. }
  2388. break;
  2389. case DCA_PROVIDER_REMOVE:
  2390. if (dd->flags & QIB_DCA_ENABLED) {
  2391. dca_remove_requester(&dd->pcidev->dev);
  2392. dd->flags &= ~QIB_DCA_ENABLED;
  2393. dd->cspec->dca_ctrl = 0;
  2394. qib_write_kreg(dd, KREG_IDX(DCACtrlA),
  2395. dd->cspec->dca_ctrl);
  2396. }
  2397. break;
  2398. }
  2399. return 0;
  2400. }
  2401. static void qib_update_rhdrq_dca(struct qib_ctxtdata *rcd, int cpu)
  2402. {
  2403. struct qib_devdata *dd = rcd->dd;
  2404. struct qib_chip_specific *cspec = dd->cspec;
  2405. if (!(dd->flags & QIB_DCA_ENABLED))
  2406. return;
  2407. if (cspec->rhdr_cpu[rcd->ctxt] != cpu) {
  2408. const struct dca_reg_map *rmp;
  2409. cspec->rhdr_cpu[rcd->ctxt] = cpu;
  2410. rmp = &dca_rcvhdr_reg_map[rcd->ctxt];
  2411. cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] &= rmp->mask;
  2412. cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] |=
  2413. (u64) dca3_get_tag(&dd->pcidev->dev, cpu) << rmp->lsb;
  2414. qib_devinfo(dd->pcidev,
  2415. "Ctxt %d cpu %d dca %llx\n", rcd->ctxt, cpu,
  2416. (long long) cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
  2417. qib_write_kreg(dd, rmp->regno,
  2418. cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
  2419. cspec->dca_ctrl |= SYM_MASK(DCACtrlA, RcvHdrqDCAEnable);
  2420. qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
  2421. }
  2422. }
  2423. static void qib_update_sdma_dca(struct qib_pportdata *ppd, int cpu)
  2424. {
  2425. struct qib_devdata *dd = ppd->dd;
  2426. struct qib_chip_specific *cspec = dd->cspec;
  2427. unsigned pidx = ppd->port - 1;
  2428. if (!(dd->flags & QIB_DCA_ENABLED))
  2429. return;
  2430. if (cspec->sdma_cpu[pidx] != cpu) {
  2431. cspec->sdma_cpu[pidx] = cpu;
  2432. cspec->dca_rcvhdr_ctrl[4] &= ~(ppd->hw_pidx ?
  2433. SYM_MASK(DCACtrlF, SendDma1DCAOPH) :
  2434. SYM_MASK(DCACtrlF, SendDma0DCAOPH));
  2435. cspec->dca_rcvhdr_ctrl[4] |=
  2436. (u64) dca3_get_tag(&dd->pcidev->dev, cpu) <<
  2437. (ppd->hw_pidx ?
  2438. SYM_LSB(DCACtrlF, SendDma1DCAOPH) :
  2439. SYM_LSB(DCACtrlF, SendDma0DCAOPH));
  2440. qib_devinfo(dd->pcidev,
  2441. "sdma %d cpu %d dca %llx\n", ppd->hw_pidx, cpu,
  2442. (long long) cspec->dca_rcvhdr_ctrl[4]);
  2443. qib_write_kreg(dd, KREG_IDX(DCACtrlF),
  2444. cspec->dca_rcvhdr_ctrl[4]);
  2445. cspec->dca_ctrl |= ppd->hw_pidx ?
  2446. SYM_MASK(DCACtrlA, SendDMAHead1DCAEnable) :
  2447. SYM_MASK(DCACtrlA, SendDMAHead0DCAEnable);
  2448. qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
  2449. }
  2450. }
  2451. static void qib_setup_dca(struct qib_devdata *dd)
  2452. {
  2453. struct qib_chip_specific *cspec = dd->cspec;
  2454. int i;
  2455. for (i = 0; i < ARRAY_SIZE(cspec->rhdr_cpu); i++)
  2456. cspec->rhdr_cpu[i] = -1;
  2457. for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
  2458. cspec->sdma_cpu[i] = -1;
  2459. cspec->dca_rcvhdr_ctrl[0] =
  2460. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq0DCAXfrCnt)) |
  2461. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq1DCAXfrCnt)) |
  2462. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq2DCAXfrCnt)) |
  2463. (1ULL << SYM_LSB(DCACtrlB, RcvHdrq3DCAXfrCnt));
  2464. cspec->dca_rcvhdr_ctrl[1] =
  2465. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq4DCAXfrCnt)) |
  2466. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq5DCAXfrCnt)) |
  2467. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq6DCAXfrCnt)) |
  2468. (1ULL << SYM_LSB(DCACtrlC, RcvHdrq7DCAXfrCnt));
  2469. cspec->dca_rcvhdr_ctrl[2] =
  2470. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq8DCAXfrCnt)) |
  2471. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq9DCAXfrCnt)) |
  2472. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq10DCAXfrCnt)) |
  2473. (1ULL << SYM_LSB(DCACtrlD, RcvHdrq11DCAXfrCnt));
  2474. cspec->dca_rcvhdr_ctrl[3] =
  2475. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq12DCAXfrCnt)) |
  2476. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq13DCAXfrCnt)) |
  2477. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq14DCAXfrCnt)) |
  2478. (1ULL << SYM_LSB(DCACtrlE, RcvHdrq15DCAXfrCnt));
  2479. cspec->dca_rcvhdr_ctrl[4] =
  2480. (1ULL << SYM_LSB(DCACtrlF, RcvHdrq16DCAXfrCnt)) |
  2481. (1ULL << SYM_LSB(DCACtrlF, RcvHdrq17DCAXfrCnt));
  2482. for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
  2483. qib_write_kreg(dd, KREG_IDX(DCACtrlB) + i,
  2484. cspec->dca_rcvhdr_ctrl[i]);
  2485. for (i = 0; i < cspec->num_msix_entries; i++)
  2486. setup_dca_notifier(dd, i);
  2487. }
  2488. static void qib_irq_notifier_notify(struct irq_affinity_notify *notify,
  2489. const cpumask_t *mask)
  2490. {
  2491. struct qib_irq_notify *n =
  2492. container_of(notify, struct qib_irq_notify, notify);
  2493. int cpu = cpumask_first(mask);
  2494. if (n->rcv) {
  2495. struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
  2496. qib_update_rhdrq_dca(rcd, cpu);
  2497. } else {
  2498. struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
  2499. qib_update_sdma_dca(ppd, cpu);
  2500. }
  2501. }
  2502. static void qib_irq_notifier_release(struct kref *ref)
  2503. {
  2504. struct qib_irq_notify *n =
  2505. container_of(ref, struct qib_irq_notify, notify.kref);
  2506. struct qib_devdata *dd;
  2507. if (n->rcv) {
  2508. struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
  2509. dd = rcd->dd;
  2510. } else {
  2511. struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
  2512. dd = ppd->dd;
  2513. }
  2514. qib_devinfo(dd->pcidev,
  2515. "release on HCA notify 0x%p n 0x%p\n", ref, n);
  2516. kfree(n);
  2517. }
  2518. #endif
  2519. static void qib_7322_free_irq(struct qib_devdata *dd)
  2520. {
  2521. u64 intgranted;
  2522. int i;
  2523. dd->cspec->main_int_mask = ~0ULL;
  2524. for (i = 0; i < dd->cspec->num_msix_entries; i++) {
  2525. /* only free IRQs that were allocated */
  2526. if (dd->cspec->msix_entries[i].arg) {
  2527. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2528. reset_dca_notifier(dd, i);
  2529. #endif
  2530. irq_set_affinity_hint(pci_irq_vector(dd->pcidev, i),
  2531. NULL);
  2532. free_cpumask_var(dd->cspec->msix_entries[i].mask);
  2533. pci_free_irq(dd->pcidev, i,
  2534. dd->cspec->msix_entries[i].arg);
  2535. }
  2536. }
  2537. /* If num_msix_entries was 0, disable the INTx IRQ */
  2538. if (!dd->cspec->num_msix_entries)
  2539. pci_free_irq(dd->pcidev, 0, dd);
  2540. else
  2541. dd->cspec->num_msix_entries = 0;
  2542. pci_free_irq_vectors(dd->pcidev);
  2543. /* make sure no MSIx interrupts are left pending */
  2544. intgranted = qib_read_kreg64(dd, kr_intgranted);
  2545. if (intgranted)
  2546. qib_write_kreg(dd, kr_intgranted, intgranted);
  2547. }
  2548. static void qib_setup_7322_cleanup(struct qib_devdata *dd)
  2549. {
  2550. int i;
  2551. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2552. if (dd->flags & QIB_DCA_ENABLED) {
  2553. dca_remove_requester(&dd->pcidev->dev);
  2554. dd->flags &= ~QIB_DCA_ENABLED;
  2555. dd->cspec->dca_ctrl = 0;
  2556. qib_write_kreg(dd, KREG_IDX(DCACtrlA), dd->cspec->dca_ctrl);
  2557. }
  2558. #endif
  2559. qib_7322_free_irq(dd);
  2560. kfree(dd->cspec->cntrs);
  2561. kfree(dd->cspec->sendchkenable);
  2562. kfree(dd->cspec->sendgrhchk);
  2563. kfree(dd->cspec->sendibchk);
  2564. kfree(dd->cspec->msix_entries);
  2565. for (i = 0; i < dd->num_pports; i++) {
  2566. unsigned long flags;
  2567. u32 mask = QSFP_GPIO_MOD_PRS_N |
  2568. (QSFP_GPIO_MOD_PRS_N << QSFP_GPIO_PORT2_SHIFT);
  2569. kfree(dd->pport[i].cpspec->portcntrs);
  2570. if (dd->flags & QIB_HAS_QSFP) {
  2571. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2572. dd->cspec->gpio_mask &= ~mask;
  2573. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  2574. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2575. }
  2576. }
  2577. }
  2578. /* handle SDMA interrupts */
  2579. static void sdma_7322_intr(struct qib_devdata *dd, u64 istat)
  2580. {
  2581. struct qib_pportdata *ppd0 = &dd->pport[0];
  2582. struct qib_pportdata *ppd1 = &dd->pport[1];
  2583. u64 intr0 = istat & (INT_MASK_P(SDma, 0) |
  2584. INT_MASK_P(SDmaIdle, 0) | INT_MASK_P(SDmaProgress, 0));
  2585. u64 intr1 = istat & (INT_MASK_P(SDma, 1) |
  2586. INT_MASK_P(SDmaIdle, 1) | INT_MASK_P(SDmaProgress, 1));
  2587. if (intr0)
  2588. qib_sdma_intr(ppd0);
  2589. if (intr1)
  2590. qib_sdma_intr(ppd1);
  2591. if (istat & INT_MASK_PM(SDmaCleanupDone, 0))
  2592. qib_sdma_process_event(ppd0, qib_sdma_event_e20_hw_started);
  2593. if (istat & INT_MASK_PM(SDmaCleanupDone, 1))
  2594. qib_sdma_process_event(ppd1, qib_sdma_event_e20_hw_started);
  2595. }
  2596. /*
  2597. * Set or clear the Send buffer available interrupt enable bit.
  2598. */
  2599. static void qib_wantpiobuf_7322_intr(struct qib_devdata *dd, u32 needint)
  2600. {
  2601. unsigned long flags;
  2602. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  2603. if (needint)
  2604. dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
  2605. else
  2606. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
  2607. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  2608. qib_write_kreg(dd, kr_scratch, 0ULL);
  2609. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  2610. }
  2611. /*
  2612. * Somehow got an interrupt with reserved bits set in interrupt status.
  2613. * Print a message so we know it happened, then clear them.
  2614. * keep mainline interrupt handler cache-friendly
  2615. */
  2616. static noinline void unknown_7322_ibits(struct qib_devdata *dd, u64 istat)
  2617. {
  2618. u64 kills;
  2619. char msg[128];
  2620. kills = istat & ~QIB_I_BITSEXTANT;
  2621. qib_dev_err(dd,
  2622. "Clearing reserved interrupt(s) 0x%016llx: %s\n",
  2623. (unsigned long long) kills, msg);
  2624. qib_write_kreg(dd, kr_intmask, (dd->cspec->int_enable_mask & ~kills));
  2625. }
  2626. /* keep mainline interrupt handler cache-friendly */
  2627. static noinline void unknown_7322_gpio_intr(struct qib_devdata *dd)
  2628. {
  2629. u32 gpiostatus;
  2630. int handled = 0;
  2631. int pidx;
  2632. /*
  2633. * Boards for this chip currently don't use GPIO interrupts,
  2634. * so clear by writing GPIOstatus to GPIOclear, and complain
  2635. * to developer. To avoid endless repeats, clear
  2636. * the bits in the mask, since there is some kind of
  2637. * programming error or chip problem.
  2638. */
  2639. gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
  2640. /*
  2641. * In theory, writing GPIOstatus to GPIOclear could
  2642. * have a bad side-effect on some diagnostic that wanted
  2643. * to poll for a status-change, but the various shadows
  2644. * make that problematic at best. Diags will just suppress
  2645. * all GPIO interrupts during such tests.
  2646. */
  2647. qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
  2648. /*
  2649. * Check for QSFP MOD_PRS changes
  2650. * only works for single port if IB1 != pidx1
  2651. */
  2652. for (pidx = 0; pidx < dd->num_pports && (dd->flags & QIB_HAS_QSFP);
  2653. ++pidx) {
  2654. struct qib_pportdata *ppd;
  2655. struct qib_qsfp_data *qd;
  2656. u32 mask;
  2657. if (!dd->pport[pidx].link_speed_supported)
  2658. continue;
  2659. mask = QSFP_GPIO_MOD_PRS_N;
  2660. ppd = dd->pport + pidx;
  2661. mask <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
  2662. if (gpiostatus & dd->cspec->gpio_mask & mask) {
  2663. u64 pins;
  2664. qd = &ppd->cpspec->qsfp_data;
  2665. gpiostatus &= ~mask;
  2666. pins = qib_read_kreg64(dd, kr_extstatus);
  2667. pins >>= SYM_LSB(EXTStatus, GPIOIn);
  2668. if (!(pins & mask)) {
  2669. ++handled;
  2670. qd->t_insert = jiffies;
  2671. queue_work(ib_wq, &qd->work);
  2672. }
  2673. }
  2674. }
  2675. if (gpiostatus && !handled) {
  2676. const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
  2677. u32 gpio_irq = mask & gpiostatus;
  2678. /*
  2679. * Clear any troublemakers, and update chip from shadow
  2680. */
  2681. dd->cspec->gpio_mask &= ~gpio_irq;
  2682. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  2683. }
  2684. }
  2685. /*
  2686. * Handle errors and unusual events first, separate function
  2687. * to improve cache hits for fast path interrupt handling.
  2688. */
  2689. static noinline void unlikely_7322_intr(struct qib_devdata *dd, u64 istat)
  2690. {
  2691. if (istat & ~QIB_I_BITSEXTANT)
  2692. unknown_7322_ibits(dd, istat);
  2693. if (istat & QIB_I_GPIO)
  2694. unknown_7322_gpio_intr(dd);
  2695. if (istat & QIB_I_C_ERROR) {
  2696. qib_write_kreg(dd, kr_errmask, 0ULL);
  2697. tasklet_schedule(&dd->error_tasklet);
  2698. }
  2699. if (istat & INT_MASK_P(Err, 0) && dd->rcd[0])
  2700. handle_7322_p_errors(dd->rcd[0]->ppd);
  2701. if (istat & INT_MASK_P(Err, 1) && dd->rcd[1])
  2702. handle_7322_p_errors(dd->rcd[1]->ppd);
  2703. }
  2704. /*
  2705. * Dynamically adjust the rcv int timeout for a context based on incoming
  2706. * packet rate.
  2707. */
  2708. static void adjust_rcv_timeout(struct qib_ctxtdata *rcd, int npkts)
  2709. {
  2710. struct qib_devdata *dd = rcd->dd;
  2711. u32 timeout = dd->cspec->rcvavail_timeout[rcd->ctxt];
  2712. /*
  2713. * Dynamically adjust idle timeout on chip
  2714. * based on number of packets processed.
  2715. */
  2716. if (npkts < rcv_int_count && timeout > 2)
  2717. timeout >>= 1;
  2718. else if (npkts >= rcv_int_count && timeout < rcv_int_timeout)
  2719. timeout = min(timeout << 1, rcv_int_timeout);
  2720. else
  2721. return;
  2722. dd->cspec->rcvavail_timeout[rcd->ctxt] = timeout;
  2723. qib_write_kreg(dd, kr_rcvavailtimeout + rcd->ctxt, timeout);
  2724. }
  2725. /*
  2726. * This is the main interrupt handler.
  2727. * It will normally only be used for low frequency interrupts but may
  2728. * have to handle all interrupts if INTx is enabled or fewer than normal
  2729. * MSIx interrupts were allocated.
  2730. * This routine should ignore the interrupt bits for any of the
  2731. * dedicated MSIx handlers.
  2732. */
  2733. static irqreturn_t qib_7322intr(int irq, void *data)
  2734. {
  2735. struct qib_devdata *dd = data;
  2736. irqreturn_t ret;
  2737. u64 istat;
  2738. u64 ctxtrbits;
  2739. u64 rmask;
  2740. unsigned i;
  2741. u32 npkts;
  2742. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
  2743. /*
  2744. * This return value is not great, but we do not want the
  2745. * interrupt core code to remove our interrupt handler
  2746. * because we don't appear to be handling an interrupt
  2747. * during a chip reset.
  2748. */
  2749. ret = IRQ_HANDLED;
  2750. goto bail;
  2751. }
  2752. istat = qib_read_kreg64(dd, kr_intstatus);
  2753. if (unlikely(istat == ~0ULL)) {
  2754. qib_bad_intrstatus(dd);
  2755. qib_dev_err(dd, "Interrupt status all f's, skipping\n");
  2756. /* don't know if it was our interrupt or not */
  2757. ret = IRQ_NONE;
  2758. goto bail;
  2759. }
  2760. istat &= dd->cspec->main_int_mask;
  2761. if (unlikely(!istat)) {
  2762. /* already handled, or shared and not us */
  2763. ret = IRQ_NONE;
  2764. goto bail;
  2765. }
  2766. this_cpu_inc(*dd->int_counter);
  2767. /* handle "errors" of various kinds first, device ahead of port */
  2768. if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
  2769. QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
  2770. INT_MASK_P(Err, 1))))
  2771. unlikely_7322_intr(dd, istat);
  2772. /*
  2773. * Clear the interrupt bits we found set, relatively early, so we
  2774. * "know" know the chip will have seen this by the time we process
  2775. * the queue, and will re-interrupt if necessary. The processor
  2776. * itself won't take the interrupt again until we return.
  2777. */
  2778. qib_write_kreg(dd, kr_intclear, istat);
  2779. /*
  2780. * Handle kernel receive queues before checking for pio buffers
  2781. * available since receives can overflow; piobuf waiters can afford
  2782. * a few extra cycles, since they were waiting anyway.
  2783. */
  2784. ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
  2785. if (ctxtrbits) {
  2786. rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
  2787. (1ULL << QIB_I_RCVURG_LSB);
  2788. for (i = 0; i < dd->first_user_ctxt; i++) {
  2789. if (ctxtrbits & rmask) {
  2790. ctxtrbits &= ~rmask;
  2791. if (dd->rcd[i])
  2792. qib_kreceive(dd->rcd[i], NULL, &npkts);
  2793. }
  2794. rmask <<= 1;
  2795. }
  2796. if (ctxtrbits) {
  2797. ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
  2798. (ctxtrbits >> QIB_I_RCVURG_LSB);
  2799. qib_handle_urcv(dd, ctxtrbits);
  2800. }
  2801. }
  2802. if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
  2803. sdma_7322_intr(dd, istat);
  2804. if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
  2805. qib_ib_piobufavail(dd);
  2806. ret = IRQ_HANDLED;
  2807. bail:
  2808. return ret;
  2809. }
  2810. /*
  2811. * Dedicated receive packet available interrupt handler.
  2812. */
  2813. static irqreturn_t qib_7322pintr(int irq, void *data)
  2814. {
  2815. struct qib_ctxtdata *rcd = data;
  2816. struct qib_devdata *dd = rcd->dd;
  2817. u32 npkts;
  2818. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2819. /*
  2820. * This return value is not great, but we do not want the
  2821. * interrupt core code to remove our interrupt handler
  2822. * because we don't appear to be handling an interrupt
  2823. * during a chip reset.
  2824. */
  2825. return IRQ_HANDLED;
  2826. this_cpu_inc(*dd->int_counter);
  2827. /* Clear the interrupt bit we expect to be set. */
  2828. qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
  2829. (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
  2830. qib_kreceive(rcd, NULL, &npkts);
  2831. return IRQ_HANDLED;
  2832. }
  2833. /*
  2834. * Dedicated Send buffer available interrupt handler.
  2835. */
  2836. static irqreturn_t qib_7322bufavail(int irq, void *data)
  2837. {
  2838. struct qib_devdata *dd = data;
  2839. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2840. /*
  2841. * This return value is not great, but we do not want the
  2842. * interrupt core code to remove our interrupt handler
  2843. * because we don't appear to be handling an interrupt
  2844. * during a chip reset.
  2845. */
  2846. return IRQ_HANDLED;
  2847. this_cpu_inc(*dd->int_counter);
  2848. /* Clear the interrupt bit we expect to be set. */
  2849. qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
  2850. /* qib_ib_piobufavail() will clear the want PIO interrupt if needed */
  2851. if (dd->flags & QIB_INITTED)
  2852. qib_ib_piobufavail(dd);
  2853. else
  2854. qib_wantpiobuf_7322_intr(dd, 0);
  2855. return IRQ_HANDLED;
  2856. }
  2857. /*
  2858. * Dedicated Send DMA interrupt handler.
  2859. */
  2860. static irqreturn_t sdma_intr(int irq, void *data)
  2861. {
  2862. struct qib_pportdata *ppd = data;
  2863. struct qib_devdata *dd = ppd->dd;
  2864. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2865. /*
  2866. * This return value is not great, but we do not want the
  2867. * interrupt core code to remove our interrupt handler
  2868. * because we don't appear to be handling an interrupt
  2869. * during a chip reset.
  2870. */
  2871. return IRQ_HANDLED;
  2872. this_cpu_inc(*dd->int_counter);
  2873. /* Clear the interrupt bit we expect to be set. */
  2874. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2875. INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
  2876. qib_sdma_intr(ppd);
  2877. return IRQ_HANDLED;
  2878. }
  2879. /*
  2880. * Dedicated Send DMA idle interrupt handler.
  2881. */
  2882. static irqreturn_t sdma_idle_intr(int irq, void *data)
  2883. {
  2884. struct qib_pportdata *ppd = data;
  2885. struct qib_devdata *dd = ppd->dd;
  2886. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2887. /*
  2888. * This return value is not great, but we do not want the
  2889. * interrupt core code to remove our interrupt handler
  2890. * because we don't appear to be handling an interrupt
  2891. * during a chip reset.
  2892. */
  2893. return IRQ_HANDLED;
  2894. this_cpu_inc(*dd->int_counter);
  2895. /* Clear the interrupt bit we expect to be set. */
  2896. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2897. INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
  2898. qib_sdma_intr(ppd);
  2899. return IRQ_HANDLED;
  2900. }
  2901. /*
  2902. * Dedicated Send DMA progress interrupt handler.
  2903. */
  2904. static irqreturn_t sdma_progress_intr(int irq, void *data)
  2905. {
  2906. struct qib_pportdata *ppd = data;
  2907. struct qib_devdata *dd = ppd->dd;
  2908. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2909. /*
  2910. * This return value is not great, but we do not want the
  2911. * interrupt core code to remove our interrupt handler
  2912. * because we don't appear to be handling an interrupt
  2913. * during a chip reset.
  2914. */
  2915. return IRQ_HANDLED;
  2916. this_cpu_inc(*dd->int_counter);
  2917. /* Clear the interrupt bit we expect to be set. */
  2918. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2919. INT_MASK_P(SDmaProgress, 1) :
  2920. INT_MASK_P(SDmaProgress, 0));
  2921. qib_sdma_intr(ppd);
  2922. return IRQ_HANDLED;
  2923. }
  2924. /*
  2925. * Dedicated Send DMA cleanup interrupt handler.
  2926. */
  2927. static irqreturn_t sdma_cleanup_intr(int irq, void *data)
  2928. {
  2929. struct qib_pportdata *ppd = data;
  2930. struct qib_devdata *dd = ppd->dd;
  2931. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2932. /*
  2933. * This return value is not great, but we do not want the
  2934. * interrupt core code to remove our interrupt handler
  2935. * because we don't appear to be handling an interrupt
  2936. * during a chip reset.
  2937. */
  2938. return IRQ_HANDLED;
  2939. this_cpu_inc(*dd->int_counter);
  2940. /* Clear the interrupt bit we expect to be set. */
  2941. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2942. INT_MASK_PM(SDmaCleanupDone, 1) :
  2943. INT_MASK_PM(SDmaCleanupDone, 0));
  2944. qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
  2945. return IRQ_HANDLED;
  2946. }
  2947. #ifdef CONFIG_INFINIBAND_QIB_DCA
  2948. static void reset_dca_notifier(struct qib_devdata *dd, int msixnum)
  2949. {
  2950. if (!dd->cspec->msix_entries[msixnum].dca)
  2951. return;
  2952. qib_devinfo(dd->pcidev, "Disabling notifier on HCA %d irq %d\n",
  2953. dd->unit, pci_irq_vector(dd->pcidev, msixnum));
  2954. irq_set_affinity_notifier(pci_irq_vector(dd->pcidev, msixnum), NULL);
  2955. dd->cspec->msix_entries[msixnum].notifier = NULL;
  2956. }
  2957. static void setup_dca_notifier(struct qib_devdata *dd, int msixnum)
  2958. {
  2959. struct qib_msix_entry *m = &dd->cspec->msix_entries[msixnum];
  2960. struct qib_irq_notify *n;
  2961. if (!m->dca)
  2962. return;
  2963. n = kzalloc(sizeof(*n), GFP_KERNEL);
  2964. if (n) {
  2965. int ret;
  2966. m->notifier = n;
  2967. n->notify.irq = pci_irq_vector(dd->pcidev, msixnum);
  2968. n->notify.notify = qib_irq_notifier_notify;
  2969. n->notify.release = qib_irq_notifier_release;
  2970. n->arg = m->arg;
  2971. n->rcv = m->rcv;
  2972. qib_devinfo(dd->pcidev,
  2973. "set notifier irq %d rcv %d notify %p\n",
  2974. n->notify.irq, n->rcv, &n->notify);
  2975. ret = irq_set_affinity_notifier(
  2976. n->notify.irq,
  2977. &n->notify);
  2978. if (ret) {
  2979. m->notifier = NULL;
  2980. kfree(n);
  2981. }
  2982. }
  2983. }
  2984. #endif
  2985. /*
  2986. * Set up our chip-specific interrupt handler.
  2987. * The interrupt type has already been setup, so
  2988. * we just need to do the registration and error checking.
  2989. * If we are using MSIx interrupts, we may fall back to
  2990. * INTx later, if the interrupt handler doesn't get called
  2991. * within 1/2 second (see verify_interrupt()).
  2992. */
  2993. static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
  2994. {
  2995. int ret, i, msixnum;
  2996. u64 redirect[6];
  2997. u64 mask;
  2998. const struct cpumask *local_mask;
  2999. int firstcpu, secondcpu = 0, currrcvcpu = 0;
  3000. if (!dd->num_pports)
  3001. return;
  3002. if (clearpend) {
  3003. /*
  3004. * if not switching interrupt types, be sure interrupts are
  3005. * disabled, and then clear anything pending at this point,
  3006. * because we are starting clean.
  3007. */
  3008. qib_7322_set_intr_state(dd, 0);
  3009. /* clear the reset error, init error/hwerror mask */
  3010. qib_7322_init_hwerrors(dd);
  3011. /* clear any interrupt bits that might be set */
  3012. qib_write_kreg(dd, kr_intclear, ~0ULL);
  3013. /* make sure no pending MSIx intr, and clear diag reg */
  3014. qib_write_kreg(dd, kr_intgranted, ~0ULL);
  3015. qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
  3016. }
  3017. if (!dd->cspec->num_msix_entries) {
  3018. /* Try to get INTx interrupt */
  3019. try_intx:
  3020. ret = pci_request_irq(dd->pcidev, 0, qib_7322intr, NULL, dd,
  3021. QIB_DRV_NAME);
  3022. if (ret) {
  3023. qib_dev_err(
  3024. dd,
  3025. "Couldn't setup INTx interrupt (irq=%d): %d\n",
  3026. pci_irq_vector(dd->pcidev, 0), ret);
  3027. return;
  3028. }
  3029. dd->cspec->main_int_mask = ~0ULL;
  3030. return;
  3031. }
  3032. /* Try to get MSIx interrupts */
  3033. memset(redirect, 0, sizeof(redirect));
  3034. mask = ~0ULL;
  3035. msixnum = 0;
  3036. local_mask = cpumask_of_pcibus(dd->pcidev->bus);
  3037. firstcpu = cpumask_first(local_mask);
  3038. if (firstcpu >= nr_cpu_ids ||
  3039. cpumask_weight(local_mask) == num_online_cpus()) {
  3040. local_mask = topology_core_cpumask(0);
  3041. firstcpu = cpumask_first(local_mask);
  3042. }
  3043. if (firstcpu < nr_cpu_ids) {
  3044. secondcpu = cpumask_next(firstcpu, local_mask);
  3045. if (secondcpu >= nr_cpu_ids)
  3046. secondcpu = firstcpu;
  3047. currrcvcpu = secondcpu;
  3048. }
  3049. for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
  3050. irq_handler_t handler;
  3051. void *arg;
  3052. int lsb, reg, sh;
  3053. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3054. int dca = 0;
  3055. #endif
  3056. if (i < ARRAY_SIZE(irq_table)) {
  3057. if (irq_table[i].port) {
  3058. /* skip if for a non-configured port */
  3059. if (irq_table[i].port > dd->num_pports)
  3060. continue;
  3061. arg = dd->pport + irq_table[i].port - 1;
  3062. } else
  3063. arg = dd;
  3064. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3065. dca = irq_table[i].dca;
  3066. #endif
  3067. lsb = irq_table[i].lsb;
  3068. handler = irq_table[i].handler;
  3069. ret = pci_request_irq(dd->pcidev, msixnum, handler,
  3070. NULL, arg, QIB_DRV_NAME "%d%s",
  3071. dd->unit,
  3072. irq_table[i].name);
  3073. } else {
  3074. unsigned ctxt;
  3075. ctxt = i - ARRAY_SIZE(irq_table);
  3076. /* per krcvq context receive interrupt */
  3077. arg = dd->rcd[ctxt];
  3078. if (!arg)
  3079. continue;
  3080. if (qib_krcvq01_no_msi && ctxt < 2)
  3081. continue;
  3082. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3083. dca = 1;
  3084. #endif
  3085. lsb = QIB_I_RCVAVAIL_LSB + ctxt;
  3086. handler = qib_7322pintr;
  3087. ret = pci_request_irq(dd->pcidev, msixnum, handler,
  3088. NULL, arg,
  3089. QIB_DRV_NAME "%d (kctx)",
  3090. dd->unit);
  3091. }
  3092. if (ret) {
  3093. /*
  3094. * Shouldn't happen since the enable said we could
  3095. * have as many as we are trying to setup here.
  3096. */
  3097. qib_dev_err(dd,
  3098. "Couldn't setup MSIx interrupt (vec=%d, irq=%d): %d\n",
  3099. msixnum,
  3100. pci_irq_vector(dd->pcidev, msixnum),
  3101. ret);
  3102. qib_7322_free_irq(dd);
  3103. pci_alloc_irq_vectors(dd->pcidev, 1, 1,
  3104. PCI_IRQ_LEGACY);
  3105. goto try_intx;
  3106. }
  3107. dd->cspec->msix_entries[msixnum].arg = arg;
  3108. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3109. dd->cspec->msix_entries[msixnum].dca = dca;
  3110. dd->cspec->msix_entries[msixnum].rcv =
  3111. handler == qib_7322pintr;
  3112. #endif
  3113. if (lsb >= 0) {
  3114. reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
  3115. sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
  3116. SYM_LSB(IntRedirect0, vec1);
  3117. mask &= ~(1ULL << lsb);
  3118. redirect[reg] |= ((u64) msixnum) << sh;
  3119. }
  3120. qib_read_kreg64(dd, 2 * msixnum + 1 +
  3121. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3122. if (firstcpu < nr_cpu_ids &&
  3123. zalloc_cpumask_var(
  3124. &dd->cspec->msix_entries[msixnum].mask,
  3125. GFP_KERNEL)) {
  3126. if (handler == qib_7322pintr) {
  3127. cpumask_set_cpu(currrcvcpu,
  3128. dd->cspec->msix_entries[msixnum].mask);
  3129. currrcvcpu = cpumask_next(currrcvcpu,
  3130. local_mask);
  3131. if (currrcvcpu >= nr_cpu_ids)
  3132. currrcvcpu = secondcpu;
  3133. } else {
  3134. cpumask_set_cpu(firstcpu,
  3135. dd->cspec->msix_entries[msixnum].mask);
  3136. }
  3137. irq_set_affinity_hint(
  3138. pci_irq_vector(dd->pcidev, msixnum),
  3139. dd->cspec->msix_entries[msixnum].mask);
  3140. }
  3141. msixnum++;
  3142. }
  3143. /* Initialize the vector mapping */
  3144. for (i = 0; i < ARRAY_SIZE(redirect); i++)
  3145. qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
  3146. dd->cspec->main_int_mask = mask;
  3147. tasklet_init(&dd->error_tasklet, qib_error_tasklet,
  3148. (unsigned long)dd);
  3149. }
  3150. /**
  3151. * qib_7322_boardname - fill in the board name and note features
  3152. * @dd: the qlogic_ib device
  3153. *
  3154. * info will be based on the board revision register
  3155. */
  3156. static unsigned qib_7322_boardname(struct qib_devdata *dd)
  3157. {
  3158. /* Will need enumeration of board-types here */
  3159. u32 boardid;
  3160. unsigned int features = DUAL_PORT_CAP;
  3161. boardid = SYM_FIELD(dd->revision, Revision, BoardID);
  3162. switch (boardid) {
  3163. case 0:
  3164. dd->boardname = "InfiniPath_QLE7342_Emulation";
  3165. break;
  3166. case 1:
  3167. dd->boardname = "InfiniPath_QLE7340";
  3168. dd->flags |= QIB_HAS_QSFP;
  3169. features = PORT_SPD_CAP;
  3170. break;
  3171. case 2:
  3172. dd->boardname = "InfiniPath_QLE7342";
  3173. dd->flags |= QIB_HAS_QSFP;
  3174. break;
  3175. case 3:
  3176. dd->boardname = "InfiniPath_QMI7342";
  3177. break;
  3178. case 4:
  3179. dd->boardname = "InfiniPath_Unsupported7342";
  3180. qib_dev_err(dd, "Unsupported version of QMH7342\n");
  3181. features = 0;
  3182. break;
  3183. case BOARD_QMH7342:
  3184. dd->boardname = "InfiniPath_QMH7342";
  3185. features = 0x24;
  3186. break;
  3187. case BOARD_QME7342:
  3188. dd->boardname = "InfiniPath_QME7342";
  3189. break;
  3190. case 8:
  3191. dd->boardname = "InfiniPath_QME7362";
  3192. dd->flags |= QIB_HAS_QSFP;
  3193. break;
  3194. case BOARD_QMH7360:
  3195. dd->boardname = "Intel IB QDR 1P FLR-QSFP Adptr";
  3196. dd->flags |= QIB_HAS_QSFP;
  3197. break;
  3198. case 15:
  3199. dd->boardname = "InfiniPath_QLE7342_TEST";
  3200. dd->flags |= QIB_HAS_QSFP;
  3201. break;
  3202. default:
  3203. dd->boardname = "InfiniPath_QLE73xy_UNKNOWN";
  3204. qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
  3205. break;
  3206. }
  3207. dd->board_atten = 1; /* index into txdds_Xdr */
  3208. snprintf(dd->boardversion, sizeof(dd->boardversion),
  3209. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
  3210. QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
  3211. (unsigned int)SYM_FIELD(dd->revision, Revision_R, Arch),
  3212. dd->majrev, dd->minrev,
  3213. (unsigned int)SYM_FIELD(dd->revision, Revision_R, SW));
  3214. if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
  3215. qib_devinfo(dd->pcidev,
  3216. "IB%u: Forced to single port mode by module parameter\n",
  3217. dd->unit);
  3218. features &= PORT_SPD_CAP;
  3219. }
  3220. return features;
  3221. }
  3222. /*
  3223. * This routine sleeps, so it can only be called from user context, not
  3224. * from interrupt context.
  3225. */
  3226. static int qib_do_7322_reset(struct qib_devdata *dd)
  3227. {
  3228. u64 val;
  3229. u64 *msix_vecsave = NULL;
  3230. int i, msix_entries, ret = 1;
  3231. u16 cmdval;
  3232. u8 int_line, clinesz;
  3233. unsigned long flags;
  3234. /* Use dev_err so it shows up in logs, etc. */
  3235. qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
  3236. qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
  3237. msix_entries = dd->cspec->num_msix_entries;
  3238. /* no interrupts till re-initted */
  3239. qib_7322_set_intr_state(dd, 0);
  3240. qib_7322_free_irq(dd);
  3241. if (msix_entries) {
  3242. /* can be up to 512 bytes, too big for stack */
  3243. msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
  3244. sizeof(u64), GFP_KERNEL);
  3245. }
  3246. /*
  3247. * Core PCI (as of 2.6.18) doesn't save or rewrite the full vector
  3248. * info that is set up by the BIOS, so we have to save and restore
  3249. * it ourselves. There is some risk something could change it,
  3250. * after we save it, but since we have disabled the MSIx, it
  3251. * shouldn't be touched...
  3252. */
  3253. for (i = 0; i < msix_entries; i++) {
  3254. u64 vecaddr, vecdata;
  3255. vecaddr = qib_read_kreg64(dd, 2 * i +
  3256. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3257. vecdata = qib_read_kreg64(dd, 1 + 2 * i +
  3258. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  3259. if (msix_vecsave) {
  3260. msix_vecsave[2 * i] = vecaddr;
  3261. /* save it without the masked bit set */
  3262. msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
  3263. }
  3264. }
  3265. dd->pport->cpspec->ibdeltainprog = 0;
  3266. dd->pport->cpspec->ibsymdelta = 0;
  3267. dd->pport->cpspec->iblnkerrdelta = 0;
  3268. dd->pport->cpspec->ibmalfdelta = 0;
  3269. /* so we check interrupts work again */
  3270. dd->z_int_counter = qib_int_counter(dd);
  3271. /*
  3272. * Keep chip from being accessed until we are ready. Use
  3273. * writeq() directly, to allow the write even though QIB_PRESENT
  3274. * isn't set.
  3275. */
  3276. dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
  3277. dd->flags |= QIB_DOING_RESET;
  3278. val = dd->control | QLOGIC_IB_C_RESET;
  3279. writeq(val, &dd->kregbase[kr_control]);
  3280. for (i = 1; i <= 5; i++) {
  3281. /*
  3282. * Allow MBIST, etc. to complete; longer on each retry.
  3283. * We sometimes get machine checks from bus timeout if no
  3284. * response, so for now, make it *really* long.
  3285. */
  3286. msleep(1000 + (1 + i) * 3000);
  3287. qib_pcie_reenable(dd, cmdval, int_line, clinesz);
  3288. /*
  3289. * Use readq directly, so we don't need to mark it as PRESENT
  3290. * until we get a successful indication that all is well.
  3291. */
  3292. val = readq(&dd->kregbase[kr_revision]);
  3293. if (val == dd->revision)
  3294. break;
  3295. if (i == 5) {
  3296. qib_dev_err(dd,
  3297. "Failed to initialize after reset, unusable\n");
  3298. ret = 0;
  3299. goto bail;
  3300. }
  3301. }
  3302. dd->flags |= QIB_PRESENT; /* it's back */
  3303. if (msix_entries) {
  3304. /* restore the MSIx vector address and data if saved above */
  3305. for (i = 0; i < msix_entries; i++) {
  3306. if (!msix_vecsave || !msix_vecsave[2 * i])
  3307. continue;
  3308. qib_write_kreg(dd, 2 * i +
  3309. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  3310. msix_vecsave[2 * i]);
  3311. qib_write_kreg(dd, 1 + 2 * i +
  3312. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  3313. msix_vecsave[1 + 2 * i]);
  3314. }
  3315. }
  3316. /* initialize the remaining registers. */
  3317. for (i = 0; i < dd->num_pports; ++i)
  3318. write_7322_init_portregs(&dd->pport[i]);
  3319. write_7322_initregs(dd);
  3320. if (qib_pcie_params(dd, dd->lbus_width, &msix_entries))
  3321. qib_dev_err(dd,
  3322. "Reset failed to setup PCIe or interrupts; continuing anyway\n");
  3323. dd->cspec->num_msix_entries = msix_entries;
  3324. qib_setup_7322_interrupt(dd, 1);
  3325. for (i = 0; i < dd->num_pports; ++i) {
  3326. struct qib_pportdata *ppd = &dd->pport[i];
  3327. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3328. ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
  3329. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3330. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3331. }
  3332. bail:
  3333. dd->flags &= ~QIB_DOING_RESET; /* OK or not, no longer resetting */
  3334. kfree(msix_vecsave);
  3335. return ret;
  3336. }
  3337. /**
  3338. * qib_7322_put_tid - write a TID to the chip
  3339. * @dd: the qlogic_ib device
  3340. * @tidptr: pointer to the expected TID (in chip) to update
  3341. * @tidtype: 0 for eager, 1 for expected
  3342. * @pa: physical address of in memory buffer; tidinvalid if freeing
  3343. */
  3344. static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
  3345. u32 type, unsigned long pa)
  3346. {
  3347. if (!(dd->flags & QIB_PRESENT))
  3348. return;
  3349. if (pa != dd->tidinvalid) {
  3350. u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
  3351. /* paranoia checks */
  3352. if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
  3353. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  3354. pa);
  3355. return;
  3356. }
  3357. if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
  3358. qib_dev_err(dd,
  3359. "Physical page address 0x%lx larger than supported\n",
  3360. pa);
  3361. return;
  3362. }
  3363. if (type == RCVHQ_RCV_TYPE_EAGER)
  3364. chippa |= dd->tidtemplate;
  3365. else /* for now, always full 4KB page */
  3366. chippa |= IBA7322_TID_SZ_4K;
  3367. pa = chippa;
  3368. }
  3369. writeq(pa, tidptr);
  3370. mmiowb();
  3371. }
  3372. /**
  3373. * qib_7322_clear_tids - clear all TID entries for a ctxt, expected and eager
  3374. * @dd: the qlogic_ib device
  3375. * @ctxt: the ctxt
  3376. *
  3377. * clear all TID entries for a ctxt, expected and eager.
  3378. * Used from qib_close().
  3379. */
  3380. static void qib_7322_clear_tids(struct qib_devdata *dd,
  3381. struct qib_ctxtdata *rcd)
  3382. {
  3383. u64 __iomem *tidbase;
  3384. unsigned long tidinv;
  3385. u32 ctxt;
  3386. int i;
  3387. if (!dd->kregbase || !rcd)
  3388. return;
  3389. ctxt = rcd->ctxt;
  3390. tidinv = dd->tidinvalid;
  3391. tidbase = (u64 __iomem *)
  3392. ((char __iomem *) dd->kregbase +
  3393. dd->rcvtidbase +
  3394. ctxt * dd->rcvtidcnt * sizeof(*tidbase));
  3395. for (i = 0; i < dd->rcvtidcnt; i++)
  3396. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  3397. tidinv);
  3398. tidbase = (u64 __iomem *)
  3399. ((char __iomem *) dd->kregbase +
  3400. dd->rcvegrbase +
  3401. rcd->rcvegr_tid_base * sizeof(*tidbase));
  3402. for (i = 0; i < rcd->rcvegrcnt; i++)
  3403. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  3404. tidinv);
  3405. }
  3406. /**
  3407. * qib_7322_tidtemplate - setup constants for TID updates
  3408. * @dd: the qlogic_ib device
  3409. *
  3410. * We setup stuff that we use a lot, to avoid calculating each time
  3411. */
  3412. static void qib_7322_tidtemplate(struct qib_devdata *dd)
  3413. {
  3414. /*
  3415. * For now, we always allocate 4KB buffers (at init) so we can
  3416. * receive max size packets. We may want a module parameter to
  3417. * specify 2KB or 4KB and/or make it per port instead of per device
  3418. * for those who want to reduce memory footprint. Note that the
  3419. * rcvhdrentsize size must be large enough to hold the largest
  3420. * IB header (currently 96 bytes) that we expect to handle (plus of
  3421. * course the 2 dwords of RHF).
  3422. */
  3423. if (dd->rcvegrbufsize == 2048)
  3424. dd->tidtemplate = IBA7322_TID_SZ_2K;
  3425. else if (dd->rcvegrbufsize == 4096)
  3426. dd->tidtemplate = IBA7322_TID_SZ_4K;
  3427. dd->tidinvalid = 0;
  3428. }
  3429. /**
  3430. * qib_init_7322_get_base_info - set chip-specific flags for user code
  3431. * @rcd: the qlogic_ib ctxt
  3432. * @kbase: qib_base_info pointer
  3433. *
  3434. * We set the PCIE flag because the lower bandwidth on PCIe vs
  3435. * HyperTransport can affect some user packet algorithims.
  3436. */
  3437. static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
  3438. struct qib_base_info *kinfo)
  3439. {
  3440. kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
  3441. QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
  3442. QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
  3443. if (rcd->dd->cspec->r1)
  3444. kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
  3445. if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
  3446. kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
  3447. return 0;
  3448. }
  3449. static struct qib_message_header *
  3450. qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
  3451. {
  3452. u32 offset = qib_hdrget_offset(rhf_addr);
  3453. return (struct qib_message_header *)
  3454. (rhf_addr - dd->rhf_offset + offset);
  3455. }
  3456. /*
  3457. * Configure number of contexts.
  3458. */
  3459. static void qib_7322_config_ctxts(struct qib_devdata *dd)
  3460. {
  3461. unsigned long flags;
  3462. u32 nchipctxts;
  3463. nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
  3464. dd->cspec->numctxts = nchipctxts;
  3465. if (qib_n_krcv_queues > 1 && dd->num_pports) {
  3466. dd->first_user_ctxt = NUM_IB_PORTS +
  3467. (qib_n_krcv_queues - 1) * dd->num_pports;
  3468. if (dd->first_user_ctxt > nchipctxts)
  3469. dd->first_user_ctxt = nchipctxts;
  3470. dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
  3471. } else {
  3472. dd->first_user_ctxt = NUM_IB_PORTS;
  3473. dd->n_krcv_queues = 1;
  3474. }
  3475. if (!qib_cfgctxts) {
  3476. int nctxts = dd->first_user_ctxt + num_online_cpus();
  3477. if (nctxts <= 6)
  3478. dd->ctxtcnt = 6;
  3479. else if (nctxts <= 10)
  3480. dd->ctxtcnt = 10;
  3481. else if (nctxts <= nchipctxts)
  3482. dd->ctxtcnt = nchipctxts;
  3483. } else if (qib_cfgctxts < dd->num_pports)
  3484. dd->ctxtcnt = dd->num_pports;
  3485. else if (qib_cfgctxts <= nchipctxts)
  3486. dd->ctxtcnt = qib_cfgctxts;
  3487. if (!dd->ctxtcnt) /* none of the above, set to max */
  3488. dd->ctxtcnt = nchipctxts;
  3489. /*
  3490. * Chip can be configured for 6, 10, or 18 ctxts, and choice
  3491. * affects number of eager TIDs per ctxt (1K, 2K, 4K).
  3492. * Lock to be paranoid about later motion, etc.
  3493. */
  3494. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  3495. if (dd->ctxtcnt > 10)
  3496. dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3497. else if (dd->ctxtcnt > 6)
  3498. dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3499. /* else configure for default 6 receive ctxts */
  3500. /* The XRC opcode is 5. */
  3501. dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
  3502. /*
  3503. * RcvCtrl *must* be written here so that the
  3504. * chip understands how to change rcvegrcnt below.
  3505. */
  3506. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  3507. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  3508. /* kr_rcvegrcnt changes based on the number of contexts enabled */
  3509. dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
  3510. if (qib_rcvhdrcnt)
  3511. dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, qib_rcvhdrcnt);
  3512. else
  3513. dd->rcvhdrcnt = 2 * max(dd->cspec->rcvegrcnt,
  3514. dd->num_pports > 1 ? 1024U : 2048U);
  3515. }
  3516. static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
  3517. {
  3518. int lsb, ret = 0;
  3519. u64 maskr; /* right-justified mask */
  3520. switch (which) {
  3521. case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
  3522. ret = ppd->link_width_enabled;
  3523. goto done;
  3524. case QIB_IB_CFG_LWID: /* Get currently active Link-width */
  3525. ret = ppd->link_width_active;
  3526. goto done;
  3527. case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
  3528. ret = ppd->link_speed_enabled;
  3529. goto done;
  3530. case QIB_IB_CFG_SPD: /* Get current Link spd */
  3531. ret = ppd->link_speed_active;
  3532. goto done;
  3533. case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
  3534. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3535. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3536. break;
  3537. case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
  3538. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3539. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3540. break;
  3541. case QIB_IB_CFG_LINKLATENCY:
  3542. ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  3543. SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
  3544. goto done;
  3545. case QIB_IB_CFG_OP_VLS:
  3546. ret = ppd->vls_operational;
  3547. goto done;
  3548. case QIB_IB_CFG_VL_HIGH_CAP:
  3549. ret = 16;
  3550. goto done;
  3551. case QIB_IB_CFG_VL_LOW_CAP:
  3552. ret = 16;
  3553. goto done;
  3554. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3555. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3556. OverrunThreshold);
  3557. goto done;
  3558. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  3559. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3560. PhyerrThreshold);
  3561. goto done;
  3562. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3563. /* will only take effect when the link state changes */
  3564. ret = (ppd->cpspec->ibcctrl_a &
  3565. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
  3566. IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
  3567. goto done;
  3568. case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  3569. lsb = IBA7322_IBC_HRTBT_LSB;
  3570. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3571. break;
  3572. case QIB_IB_CFG_PMA_TICKS:
  3573. /*
  3574. * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
  3575. * Since the clock is always 250MHz, the value is 3, 1 or 0.
  3576. */
  3577. if (ppd->link_speed_active == QIB_IB_QDR)
  3578. ret = 3;
  3579. else if (ppd->link_speed_active == QIB_IB_DDR)
  3580. ret = 1;
  3581. else
  3582. ret = 0;
  3583. goto done;
  3584. default:
  3585. ret = -EINVAL;
  3586. goto done;
  3587. }
  3588. ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
  3589. done:
  3590. return ret;
  3591. }
  3592. /*
  3593. * Below again cribbed liberally from older version. Do not lean
  3594. * heavily on it.
  3595. */
  3596. #define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
  3597. #define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
  3598. | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
  3599. static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
  3600. {
  3601. struct qib_devdata *dd = ppd->dd;
  3602. u64 maskr; /* right-justified mask */
  3603. int lsb, ret = 0;
  3604. u16 lcmd, licmd;
  3605. unsigned long flags;
  3606. switch (which) {
  3607. case QIB_IB_CFG_LIDLMC:
  3608. /*
  3609. * Set LID and LMC. Combined to avoid possible hazard
  3610. * caller puts LMC in 16MSbits, DLID in 16LSbits of val
  3611. */
  3612. lsb = IBA7322_IBC_DLIDLMC_SHIFT;
  3613. maskr = IBA7322_IBC_DLIDLMC_MASK;
  3614. /*
  3615. * For header-checking, the SLID in the packet will
  3616. * be masked with SendIBSLMCMask, and compared
  3617. * with SendIBSLIDAssignMask. Make sure we do not
  3618. * set any bits not covered by the mask, or we get
  3619. * false-positives.
  3620. */
  3621. qib_write_kreg_port(ppd, krp_sendslid,
  3622. val & (val >> 16) & SendIBSLIDAssignMask);
  3623. qib_write_kreg_port(ppd, krp_sendslidmask,
  3624. (val >> 16) & SendIBSLMCMask);
  3625. break;
  3626. case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
  3627. ppd->link_width_enabled = val;
  3628. /* convert IB value to chip register value */
  3629. if (val == IB_WIDTH_1X)
  3630. val = 0;
  3631. else if (val == IB_WIDTH_4X)
  3632. val = 1;
  3633. else
  3634. val = 3;
  3635. maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
  3636. lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
  3637. break;
  3638. case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
  3639. /*
  3640. * As with width, only write the actual register if the
  3641. * link is currently down, otherwise takes effect on next
  3642. * link change. Since setting is being explicitly requested
  3643. * (via MAD or sysfs), clear autoneg failure status if speed
  3644. * autoneg is enabled.
  3645. */
  3646. ppd->link_speed_enabled = val;
  3647. val <<= IBA7322_IBC_SPEED_LSB;
  3648. maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
  3649. IBA7322_IBC_MAX_SPEED_MASK;
  3650. if (val & (val - 1)) {
  3651. /* Muliple speeds enabled */
  3652. val |= IBA7322_IBC_IBTA_1_2_MASK |
  3653. IBA7322_IBC_MAX_SPEED_MASK;
  3654. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3655. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3656. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3657. } else if (val & IBA7322_IBC_SPEED_QDR)
  3658. val |= IBA7322_IBC_IBTA_1_2_MASK;
  3659. /* IBTA 1.2 mode + min/max + speed bits are contiguous */
  3660. lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
  3661. break;
  3662. case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
  3663. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3664. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3665. break;
  3666. case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
  3667. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3668. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3669. break;
  3670. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3671. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3672. OverrunThreshold);
  3673. if (maskr != val) {
  3674. ppd->cpspec->ibcctrl_a &=
  3675. ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
  3676. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3677. SYM_LSB(IBCCtrlA_0, OverrunThreshold);
  3678. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3679. ppd->cpspec->ibcctrl_a);
  3680. qib_write_kreg(dd, kr_scratch, 0ULL);
  3681. }
  3682. goto bail;
  3683. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  3684. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3685. PhyerrThreshold);
  3686. if (maskr != val) {
  3687. ppd->cpspec->ibcctrl_a &=
  3688. ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
  3689. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3690. SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
  3691. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3692. ppd->cpspec->ibcctrl_a);
  3693. qib_write_kreg(dd, kr_scratch, 0ULL);
  3694. }
  3695. goto bail;
  3696. case QIB_IB_CFG_PKEYS: /* update pkeys */
  3697. maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
  3698. ((u64) ppd->pkeys[2] << 32) |
  3699. ((u64) ppd->pkeys[3] << 48);
  3700. qib_write_kreg_port(ppd, krp_partitionkey, maskr);
  3701. goto bail;
  3702. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3703. /* will only take effect when the link state changes */
  3704. if (val == IB_LINKINITCMD_POLL)
  3705. ppd->cpspec->ibcctrl_a &=
  3706. ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3707. else /* SLEEP */
  3708. ppd->cpspec->ibcctrl_a |=
  3709. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3710. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  3711. qib_write_kreg(dd, kr_scratch, 0ULL);
  3712. goto bail;
  3713. case QIB_IB_CFG_MTU: /* update the MTU in IBC */
  3714. /*
  3715. * Update our housekeeping variables, and set IBC max
  3716. * size, same as init code; max IBC is max we allow in
  3717. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  3718. * Set even if it's unchanged, print debug message only
  3719. * on changes.
  3720. */
  3721. val = (ppd->ibmaxlen >> 2) + 1;
  3722. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
  3723. ppd->cpspec->ibcctrl_a |= (u64)val <<
  3724. SYM_LSB(IBCCtrlA_0, MaxPktLen);
  3725. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3726. ppd->cpspec->ibcctrl_a);
  3727. qib_write_kreg(dd, kr_scratch, 0ULL);
  3728. goto bail;
  3729. case QIB_IB_CFG_LSTATE: /* set the IB link state */
  3730. switch (val & 0xffff0000) {
  3731. case IB_LINKCMD_DOWN:
  3732. lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
  3733. ppd->cpspec->ibmalfusesnap = 1;
  3734. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  3735. crp_errlink);
  3736. if (!ppd->cpspec->ibdeltainprog &&
  3737. qib_compat_ddr_negotiate) {
  3738. ppd->cpspec->ibdeltainprog = 1;
  3739. ppd->cpspec->ibsymsnap =
  3740. read_7322_creg32_port(ppd,
  3741. crp_ibsymbolerr);
  3742. ppd->cpspec->iblnkerrsnap =
  3743. read_7322_creg32_port(ppd,
  3744. crp_iblinkerrrecov);
  3745. }
  3746. break;
  3747. case IB_LINKCMD_ARMED:
  3748. lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
  3749. if (ppd->cpspec->ibmalfusesnap) {
  3750. ppd->cpspec->ibmalfusesnap = 0;
  3751. ppd->cpspec->ibmalfdelta +=
  3752. read_7322_creg32_port(ppd,
  3753. crp_errlink) -
  3754. ppd->cpspec->ibmalfsnap;
  3755. }
  3756. break;
  3757. case IB_LINKCMD_ACTIVE:
  3758. lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
  3759. break;
  3760. default:
  3761. ret = -EINVAL;
  3762. qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
  3763. goto bail;
  3764. }
  3765. switch (val & 0xffff) {
  3766. case IB_LINKINITCMD_NOP:
  3767. licmd = 0;
  3768. break;
  3769. case IB_LINKINITCMD_POLL:
  3770. licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
  3771. break;
  3772. case IB_LINKINITCMD_SLEEP:
  3773. licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
  3774. break;
  3775. case IB_LINKINITCMD_DISABLE:
  3776. licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
  3777. ppd->cpspec->chase_end = 0;
  3778. /*
  3779. * stop state chase counter and timer, if running.
  3780. * wait forpending timer, but don't clear .data (ppd)!
  3781. */
  3782. if (ppd->cpspec->chase_timer.expires) {
  3783. del_timer_sync(&ppd->cpspec->chase_timer);
  3784. ppd->cpspec->chase_timer.expires = 0;
  3785. }
  3786. break;
  3787. default:
  3788. ret = -EINVAL;
  3789. qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
  3790. val & 0xffff);
  3791. goto bail;
  3792. }
  3793. qib_set_ib_7322_lstate(ppd, lcmd, licmd);
  3794. goto bail;
  3795. case QIB_IB_CFG_OP_VLS:
  3796. if (ppd->vls_operational != val) {
  3797. ppd->vls_operational = val;
  3798. set_vls(ppd);
  3799. }
  3800. goto bail;
  3801. case QIB_IB_CFG_VL_HIGH_LIMIT:
  3802. qib_write_kreg_port(ppd, krp_highprio_limit, val);
  3803. goto bail;
  3804. case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
  3805. if (val > 3) {
  3806. ret = -EINVAL;
  3807. goto bail;
  3808. }
  3809. lsb = IBA7322_IBC_HRTBT_LSB;
  3810. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3811. break;
  3812. case QIB_IB_CFG_PORT:
  3813. /* val is the port number of the switch we are connected to. */
  3814. if (ppd->dd->cspec->r1) {
  3815. cancel_delayed_work(&ppd->cpspec->ipg_work);
  3816. ppd->cpspec->ipg_tries = 0;
  3817. }
  3818. goto bail;
  3819. default:
  3820. ret = -EINVAL;
  3821. goto bail;
  3822. }
  3823. ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
  3824. ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
  3825. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  3826. qib_write_kreg(dd, kr_scratch, 0);
  3827. bail:
  3828. return ret;
  3829. }
  3830. static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
  3831. {
  3832. int ret = 0;
  3833. u64 val, ctrlb;
  3834. /* only IBC loopback, may add serdes and xgxs loopbacks later */
  3835. if (!strncmp(what, "ibc", 3)) {
  3836. ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
  3837. Loopback);
  3838. val = 0; /* disable heart beat, so link will come up */
  3839. qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
  3840. ppd->dd->unit, ppd->port);
  3841. } else if (!strncmp(what, "off", 3)) {
  3842. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
  3843. Loopback);
  3844. /* enable heart beat again */
  3845. val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
  3846. qib_devinfo(ppd->dd->pcidev,
  3847. "Disabling IB%u:%u IBC loopback (normal)\n",
  3848. ppd->dd->unit, ppd->port);
  3849. } else
  3850. ret = -EINVAL;
  3851. if (!ret) {
  3852. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3853. ppd->cpspec->ibcctrl_a);
  3854. ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
  3855. << IBA7322_IBC_HRTBT_LSB);
  3856. ppd->cpspec->ibcctrl_b = ctrlb | val;
  3857. qib_write_kreg_port(ppd, krp_ibcctrl_b,
  3858. ppd->cpspec->ibcctrl_b);
  3859. qib_write_kreg(ppd->dd, kr_scratch, 0);
  3860. }
  3861. return ret;
  3862. }
  3863. static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3864. struct ib_vl_weight_elem *vl)
  3865. {
  3866. unsigned i;
  3867. for (i = 0; i < 16; i++, regno++, vl++) {
  3868. u32 val = qib_read_kreg_port(ppd, regno);
  3869. vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
  3870. SYM_RMASK(LowPriority0_0, VirtualLane);
  3871. vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
  3872. SYM_RMASK(LowPriority0_0, Weight);
  3873. }
  3874. }
  3875. static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3876. struct ib_vl_weight_elem *vl)
  3877. {
  3878. unsigned i;
  3879. for (i = 0; i < 16; i++, regno++, vl++) {
  3880. u64 val;
  3881. val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
  3882. SYM_LSB(LowPriority0_0, VirtualLane)) |
  3883. ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
  3884. SYM_LSB(LowPriority0_0, Weight));
  3885. qib_write_kreg_port(ppd, regno, val);
  3886. }
  3887. if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
  3888. struct qib_devdata *dd = ppd->dd;
  3889. unsigned long flags;
  3890. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3891. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
  3892. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  3893. qib_write_kreg(dd, kr_scratch, 0);
  3894. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3895. }
  3896. }
  3897. static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3898. {
  3899. switch (which) {
  3900. case QIB_IB_TBL_VL_HIGH_ARB:
  3901. get_vl_weights(ppd, krp_highprio_0, t);
  3902. break;
  3903. case QIB_IB_TBL_VL_LOW_ARB:
  3904. get_vl_weights(ppd, krp_lowprio_0, t);
  3905. break;
  3906. default:
  3907. return -EINVAL;
  3908. }
  3909. return 0;
  3910. }
  3911. static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3912. {
  3913. switch (which) {
  3914. case QIB_IB_TBL_VL_HIGH_ARB:
  3915. set_vl_weights(ppd, krp_highprio_0, t);
  3916. break;
  3917. case QIB_IB_TBL_VL_LOW_ARB:
  3918. set_vl_weights(ppd, krp_lowprio_0, t);
  3919. break;
  3920. default:
  3921. return -EINVAL;
  3922. }
  3923. return 0;
  3924. }
  3925. static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
  3926. u32 updegr, u32 egrhd, u32 npkts)
  3927. {
  3928. /*
  3929. * Need to write timeout register before updating rcvhdrhead to ensure
  3930. * that the timer is enabled on reception of a packet.
  3931. */
  3932. if (hd >> IBA7322_HDRHEAD_PKTINT_SHIFT)
  3933. adjust_rcv_timeout(rcd, npkts);
  3934. if (updegr)
  3935. qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
  3936. mmiowb();
  3937. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3938. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3939. mmiowb();
  3940. }
  3941. static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
  3942. {
  3943. u32 head, tail;
  3944. head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
  3945. if (rcd->rcvhdrtail_kvaddr)
  3946. tail = qib_get_rcvhdrtail(rcd);
  3947. else
  3948. tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
  3949. return head == tail;
  3950. }
  3951. #define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
  3952. QIB_RCVCTRL_CTXT_DIS | \
  3953. QIB_RCVCTRL_TIDFLOW_ENB | \
  3954. QIB_RCVCTRL_TIDFLOW_DIS | \
  3955. QIB_RCVCTRL_TAILUPD_ENB | \
  3956. QIB_RCVCTRL_TAILUPD_DIS | \
  3957. QIB_RCVCTRL_INTRAVAIL_ENB | \
  3958. QIB_RCVCTRL_INTRAVAIL_DIS | \
  3959. QIB_RCVCTRL_BP_ENB | \
  3960. QIB_RCVCTRL_BP_DIS)
  3961. #define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
  3962. QIB_RCVCTRL_CTXT_DIS | \
  3963. QIB_RCVCTRL_PKEY_DIS | \
  3964. QIB_RCVCTRL_PKEY_ENB)
  3965. /*
  3966. * Modify the RCVCTRL register in chip-specific way. This
  3967. * is a function because bit positions and (future) register
  3968. * location is chip-specifc, but the needed operations are
  3969. * generic. <op> is a bit-mask because we often want to
  3970. * do multiple modifications.
  3971. */
  3972. static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
  3973. int ctxt)
  3974. {
  3975. struct qib_devdata *dd = ppd->dd;
  3976. struct qib_ctxtdata *rcd;
  3977. u64 mask, val;
  3978. unsigned long flags;
  3979. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  3980. if (op & QIB_RCVCTRL_TIDFLOW_ENB)
  3981. dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
  3982. if (op & QIB_RCVCTRL_TIDFLOW_DIS)
  3983. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
  3984. if (op & QIB_RCVCTRL_TAILUPD_ENB)
  3985. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  3986. if (op & QIB_RCVCTRL_TAILUPD_DIS)
  3987. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
  3988. if (op & QIB_RCVCTRL_PKEY_ENB)
  3989. ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  3990. if (op & QIB_RCVCTRL_PKEY_DIS)
  3991. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  3992. if (ctxt < 0) {
  3993. mask = (1ULL << dd->ctxtcnt) - 1;
  3994. rcd = NULL;
  3995. } else {
  3996. mask = (1ULL << ctxt);
  3997. rcd = dd->rcd[ctxt];
  3998. }
  3999. if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
  4000. ppd->p_rcvctrl |=
  4001. (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  4002. if (!(dd->flags & QIB_NODMA_RTAIL)) {
  4003. op |= QIB_RCVCTRL_TAILUPD_ENB; /* need reg write */
  4004. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  4005. }
  4006. /* Write these registers before the context is enabled. */
  4007. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
  4008. rcd->rcvhdrqtailaddr_phys);
  4009. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
  4010. rcd->rcvhdrq_phys);
  4011. rcd->seq_cnt = 1;
  4012. }
  4013. if (op & QIB_RCVCTRL_CTXT_DIS)
  4014. ppd->p_rcvctrl &=
  4015. ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  4016. if (op & QIB_RCVCTRL_BP_ENB)
  4017. dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
  4018. if (op & QIB_RCVCTRL_BP_DIS)
  4019. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
  4020. if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
  4021. dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
  4022. if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
  4023. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
  4024. /*
  4025. * Decide which registers to write depending on the ops enabled.
  4026. * Special case is "flush" (no bits set at all)
  4027. * which needs to write both.
  4028. */
  4029. if (op == 0 || (op & RCVCTRL_COMMON_MODS))
  4030. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  4031. if (op == 0 || (op & RCVCTRL_PORT_MODS))
  4032. qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
  4033. if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
  4034. /*
  4035. * Init the context registers also; if we were
  4036. * disabled, tail and head should both be zero
  4037. * already from the enable, but since we don't
  4038. * know, we have to do it explicitly.
  4039. */
  4040. val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
  4041. qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
  4042. /* be sure enabling write seen; hd/tl should be 0 */
  4043. (void) qib_read_kreg32(dd, kr_scratch);
  4044. val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
  4045. dd->rcd[ctxt]->head = val;
  4046. /* If kctxt, interrupt on next receive. */
  4047. if (ctxt < dd->first_user_ctxt)
  4048. val |= dd->rhdrhead_intr_off;
  4049. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  4050. } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
  4051. dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
  4052. /* arm rcv interrupt */
  4053. val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
  4054. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  4055. }
  4056. if (op & QIB_RCVCTRL_CTXT_DIS) {
  4057. unsigned f;
  4058. /* Now that the context is disabled, clear these registers. */
  4059. if (ctxt >= 0) {
  4060. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
  4061. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
  4062. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  4063. qib_write_ureg(dd, ur_rcvflowtable + f,
  4064. TIDFLOW_ERRBITS, ctxt);
  4065. } else {
  4066. unsigned i;
  4067. for (i = 0; i < dd->cfgctxts; i++) {
  4068. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
  4069. i, 0);
  4070. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
  4071. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  4072. qib_write_ureg(dd, ur_rcvflowtable + f,
  4073. TIDFLOW_ERRBITS, i);
  4074. }
  4075. }
  4076. }
  4077. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  4078. }
  4079. /*
  4080. * Modify the SENDCTRL register in chip-specific way. This
  4081. * is a function where there are multiple such registers with
  4082. * slightly different layouts.
  4083. * The chip doesn't allow back-to-back sendctrl writes, so write
  4084. * the scratch register after writing sendctrl.
  4085. *
  4086. * Which register is written depends on the operation.
  4087. * Most operate on the common register, while
  4088. * SEND_ENB and SEND_DIS operate on the per-port ones.
  4089. * SEND_ENB is included in common because it can change SPCL_TRIG
  4090. */
  4091. #define SENDCTRL_COMMON_MODS (\
  4092. QIB_SENDCTRL_CLEAR | \
  4093. QIB_SENDCTRL_AVAIL_DIS | \
  4094. QIB_SENDCTRL_AVAIL_ENB | \
  4095. QIB_SENDCTRL_AVAIL_BLIP | \
  4096. QIB_SENDCTRL_DISARM | \
  4097. QIB_SENDCTRL_DISARM_ALL | \
  4098. QIB_SENDCTRL_SEND_ENB)
  4099. #define SENDCTRL_PORT_MODS (\
  4100. QIB_SENDCTRL_CLEAR | \
  4101. QIB_SENDCTRL_SEND_ENB | \
  4102. QIB_SENDCTRL_SEND_DIS | \
  4103. QIB_SENDCTRL_FLUSH)
  4104. static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
  4105. {
  4106. struct qib_devdata *dd = ppd->dd;
  4107. u64 tmp_dd_sendctrl;
  4108. unsigned long flags;
  4109. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  4110. /* First the dd ones that are "sticky", saved in shadow */
  4111. if (op & QIB_SENDCTRL_CLEAR)
  4112. dd->sendctrl = 0;
  4113. if (op & QIB_SENDCTRL_AVAIL_DIS)
  4114. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4115. else if (op & QIB_SENDCTRL_AVAIL_ENB) {
  4116. dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
  4117. if (dd->flags & QIB_USE_SPCL_TRIG)
  4118. dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
  4119. }
  4120. /* Then the ppd ones that are "sticky", saved in shadow */
  4121. if (op & QIB_SENDCTRL_SEND_DIS)
  4122. ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
  4123. else if (op & QIB_SENDCTRL_SEND_ENB)
  4124. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
  4125. if (op & QIB_SENDCTRL_DISARM_ALL) {
  4126. u32 i, last;
  4127. tmp_dd_sendctrl = dd->sendctrl;
  4128. last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  4129. /*
  4130. * Disarm any buffers that are not yet launched,
  4131. * disabling updates until done.
  4132. */
  4133. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4134. for (i = 0; i < last; i++) {
  4135. qib_write_kreg(dd, kr_sendctrl,
  4136. tmp_dd_sendctrl |
  4137. SYM_MASK(SendCtrl, Disarm) | i);
  4138. qib_write_kreg(dd, kr_scratch, 0);
  4139. }
  4140. }
  4141. if (op & QIB_SENDCTRL_FLUSH) {
  4142. u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
  4143. /*
  4144. * Now drain all the fifos. The Abort bit should never be
  4145. * needed, so for now, at least, we don't use it.
  4146. */
  4147. tmp_ppd_sendctrl |=
  4148. SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
  4149. SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
  4150. SYM_MASK(SendCtrl_0, TxeBypassIbc);
  4151. qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
  4152. qib_write_kreg(dd, kr_scratch, 0);
  4153. }
  4154. tmp_dd_sendctrl = dd->sendctrl;
  4155. if (op & QIB_SENDCTRL_DISARM)
  4156. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
  4157. ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
  4158. SYM_LSB(SendCtrl, DisarmSendBuf));
  4159. if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
  4160. (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
  4161. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  4162. if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
  4163. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
  4164. qib_write_kreg(dd, kr_scratch, 0);
  4165. }
  4166. if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
  4167. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  4168. qib_write_kreg(dd, kr_scratch, 0);
  4169. }
  4170. if (op & QIB_SENDCTRL_AVAIL_BLIP) {
  4171. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  4172. qib_write_kreg(dd, kr_scratch, 0);
  4173. }
  4174. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  4175. if (op & QIB_SENDCTRL_FLUSH) {
  4176. u32 v;
  4177. /*
  4178. * ensure writes have hit chip, then do a few
  4179. * more reads, to allow DMA of pioavail registers
  4180. * to occur, so in-memory copy is in sync with
  4181. * the chip. Not always safe to sleep.
  4182. */
  4183. v = qib_read_kreg32(dd, kr_scratch);
  4184. qib_write_kreg(dd, kr_scratch, v);
  4185. v = qib_read_kreg32(dd, kr_scratch);
  4186. qib_write_kreg(dd, kr_scratch, v);
  4187. qib_read_kreg32(dd, kr_scratch);
  4188. }
  4189. }
  4190. #define _PORT_VIRT_FLAG 0x8000U /* "virtual", need adjustments */
  4191. #define _PORT_64BIT_FLAG 0x10000U /* not "virtual", but 64bit */
  4192. #define _PORT_CNTR_IDXMASK 0x7fffU /* mask off flags above */
  4193. /**
  4194. * qib_portcntr_7322 - read a per-port chip counter
  4195. * @ppd: the qlogic_ib pport
  4196. * @creg: the counter to read (not a chip offset)
  4197. */
  4198. static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
  4199. {
  4200. struct qib_devdata *dd = ppd->dd;
  4201. u64 ret = 0ULL;
  4202. u16 creg;
  4203. /* 0xffff for unimplemented or synthesized counters */
  4204. static const u32 xlator[] = {
  4205. [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
  4206. [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
  4207. [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
  4208. [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
  4209. [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
  4210. [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
  4211. [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
  4212. [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
  4213. [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
  4214. [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
  4215. [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
  4216. [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
  4217. [QIBPORTCNTR_RXDROPPKT] = 0xffff, /* not needed for 7322 */
  4218. [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
  4219. [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
  4220. [QIBPORTCNTR_ERRICRC] = crp_erricrc,
  4221. [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
  4222. [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
  4223. [QIBPORTCNTR_BADFORMAT] = crp_badformat,
  4224. [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
  4225. [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
  4226. [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
  4227. [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
  4228. [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
  4229. [QIBPORTCNTR_ERRLINK] = crp_errlink,
  4230. [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
  4231. [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
  4232. [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
  4233. [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
  4234. [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
  4235. /*
  4236. * the next 3 aren't really counters, but were implemented
  4237. * as counters in older chips, so still get accessed as
  4238. * though they were counters from this code.
  4239. */
  4240. [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
  4241. [QIBPORTCNTR_PSSTART] = krp_psstart,
  4242. [QIBPORTCNTR_PSSTAT] = krp_psstat,
  4243. /* pseudo-counter, summed for all ports */
  4244. [QIBPORTCNTR_KHDROVFL] = 0xffff,
  4245. };
  4246. if (reg >= ARRAY_SIZE(xlator)) {
  4247. qib_devinfo(ppd->dd->pcidev,
  4248. "Unimplemented portcounter %u\n", reg);
  4249. goto done;
  4250. }
  4251. creg = xlator[reg] & _PORT_CNTR_IDXMASK;
  4252. /* handle non-counters and special cases first */
  4253. if (reg == QIBPORTCNTR_KHDROVFL) {
  4254. int i;
  4255. /* sum over all kernel contexts (skip if mini_init) */
  4256. for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
  4257. struct qib_ctxtdata *rcd = dd->rcd[i];
  4258. if (!rcd || rcd->ppd != ppd)
  4259. continue;
  4260. ret += read_7322_creg32(dd, cr_base_egrovfl + i);
  4261. }
  4262. goto done;
  4263. } else if (reg == QIBPORTCNTR_RXDROPPKT) {
  4264. /*
  4265. * Used as part of the synthesis of port_rcv_errors
  4266. * in the verbs code for IBTA counters. Not needed for 7322,
  4267. * because all the errors are already counted by other cntrs.
  4268. */
  4269. goto done;
  4270. } else if (reg == QIBPORTCNTR_PSINTERVAL ||
  4271. reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
  4272. /* were counters in older chips, now per-port kernel regs */
  4273. ret = qib_read_kreg_port(ppd, creg);
  4274. goto done;
  4275. }
  4276. /*
  4277. * Only fast increment counters are 64 bits; use 32 bit reads to
  4278. * avoid two independent reads when on Opteron.
  4279. */
  4280. if (xlator[reg] & _PORT_64BIT_FLAG)
  4281. ret = read_7322_creg_port(ppd, creg);
  4282. else
  4283. ret = read_7322_creg32_port(ppd, creg);
  4284. if (creg == crp_ibsymbolerr) {
  4285. if (ppd->cpspec->ibdeltainprog)
  4286. ret -= ret - ppd->cpspec->ibsymsnap;
  4287. ret -= ppd->cpspec->ibsymdelta;
  4288. } else if (creg == crp_iblinkerrrecov) {
  4289. if (ppd->cpspec->ibdeltainprog)
  4290. ret -= ret - ppd->cpspec->iblnkerrsnap;
  4291. ret -= ppd->cpspec->iblnkerrdelta;
  4292. } else if (creg == crp_errlink)
  4293. ret -= ppd->cpspec->ibmalfdelta;
  4294. else if (creg == crp_iblinkdown)
  4295. ret += ppd->cpspec->iblnkdowndelta;
  4296. done:
  4297. return ret;
  4298. }
  4299. /*
  4300. * Device counter names (not port-specific), one line per stat,
  4301. * single string. Used by utilities like ipathstats to print the stats
  4302. * in a way which works for different versions of drivers, without changing
  4303. * the utility. Names need to be 12 chars or less (w/o newline), for proper
  4304. * display by utility.
  4305. * Non-error counters are first.
  4306. * Start of "error" conters is indicated by a leading "E " on the first
  4307. * "error" counter, and doesn't count in label length.
  4308. * The EgrOvfl list needs to be last so we truncate them at the configured
  4309. * context count for the device.
  4310. * cntr7322indices contains the corresponding register indices.
  4311. */
  4312. static const char cntr7322names[] =
  4313. "Interrupts\n"
  4314. "HostBusStall\n"
  4315. "E RxTIDFull\n"
  4316. "RxTIDInvalid\n"
  4317. "RxTIDFloDrop\n" /* 7322 only */
  4318. "Ctxt0EgrOvfl\n"
  4319. "Ctxt1EgrOvfl\n"
  4320. "Ctxt2EgrOvfl\n"
  4321. "Ctxt3EgrOvfl\n"
  4322. "Ctxt4EgrOvfl\n"
  4323. "Ctxt5EgrOvfl\n"
  4324. "Ctxt6EgrOvfl\n"
  4325. "Ctxt7EgrOvfl\n"
  4326. "Ctxt8EgrOvfl\n"
  4327. "Ctxt9EgrOvfl\n"
  4328. "Ctx10EgrOvfl\n"
  4329. "Ctx11EgrOvfl\n"
  4330. "Ctx12EgrOvfl\n"
  4331. "Ctx13EgrOvfl\n"
  4332. "Ctx14EgrOvfl\n"
  4333. "Ctx15EgrOvfl\n"
  4334. "Ctx16EgrOvfl\n"
  4335. "Ctx17EgrOvfl\n"
  4336. ;
  4337. static const u32 cntr7322indices[] = {
  4338. cr_lbint | _PORT_64BIT_FLAG,
  4339. cr_lbstall | _PORT_64BIT_FLAG,
  4340. cr_tidfull,
  4341. cr_tidinvalid,
  4342. cr_rxtidflowdrop,
  4343. cr_base_egrovfl + 0,
  4344. cr_base_egrovfl + 1,
  4345. cr_base_egrovfl + 2,
  4346. cr_base_egrovfl + 3,
  4347. cr_base_egrovfl + 4,
  4348. cr_base_egrovfl + 5,
  4349. cr_base_egrovfl + 6,
  4350. cr_base_egrovfl + 7,
  4351. cr_base_egrovfl + 8,
  4352. cr_base_egrovfl + 9,
  4353. cr_base_egrovfl + 10,
  4354. cr_base_egrovfl + 11,
  4355. cr_base_egrovfl + 12,
  4356. cr_base_egrovfl + 13,
  4357. cr_base_egrovfl + 14,
  4358. cr_base_egrovfl + 15,
  4359. cr_base_egrovfl + 16,
  4360. cr_base_egrovfl + 17,
  4361. };
  4362. /*
  4363. * same as cntr7322names and cntr7322indices, but for port-specific counters.
  4364. * portcntr7322indices is somewhat complicated by some registers needing
  4365. * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
  4366. */
  4367. static const char portcntr7322names[] =
  4368. "TxPkt\n"
  4369. "TxFlowPkt\n"
  4370. "TxWords\n"
  4371. "RxPkt\n"
  4372. "RxFlowPkt\n"
  4373. "RxWords\n"
  4374. "TxFlowStall\n"
  4375. "TxDmaDesc\n" /* 7220 and 7322-only */
  4376. "E RxDlidFltr\n" /* 7220 and 7322-only */
  4377. "IBStatusChng\n"
  4378. "IBLinkDown\n"
  4379. "IBLnkRecov\n"
  4380. "IBRxLinkErr\n"
  4381. "IBSymbolErr\n"
  4382. "RxLLIErr\n"
  4383. "RxBadFormat\n"
  4384. "RxBadLen\n"
  4385. "RxBufOvrfl\n"
  4386. "RxEBP\n"
  4387. "RxFlowCtlErr\n"
  4388. "RxICRCerr\n"
  4389. "RxLPCRCerr\n"
  4390. "RxVCRCerr\n"
  4391. "RxInvalLen\n"
  4392. "RxInvalPKey\n"
  4393. "RxPktDropped\n"
  4394. "TxBadLength\n"
  4395. "TxDropped\n"
  4396. "TxInvalLen\n"
  4397. "TxUnderrun\n"
  4398. "TxUnsupVL\n"
  4399. "RxLclPhyErr\n" /* 7220 and 7322-only from here down */
  4400. "RxVL15Drop\n"
  4401. "RxVlErr\n"
  4402. "XcessBufOvfl\n"
  4403. "RxQPBadCtxt\n" /* 7322-only from here down */
  4404. "TXBadHeader\n"
  4405. ;
  4406. static const u32 portcntr7322indices[] = {
  4407. QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
  4408. crp_pktsendflow,
  4409. QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
  4410. QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
  4411. crp_pktrcvflowctrl,
  4412. QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
  4413. QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
  4414. crp_txsdmadesc | _PORT_64BIT_FLAG,
  4415. crp_rxdlidfltr,
  4416. crp_ibstatuschange,
  4417. QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
  4418. QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
  4419. QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
  4420. QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
  4421. QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
  4422. QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
  4423. QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
  4424. QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
  4425. QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
  4426. crp_rcvflowctrlviol,
  4427. QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
  4428. QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
  4429. QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
  4430. QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
  4431. QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
  4432. QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
  4433. crp_txminmaxlenerr,
  4434. crp_txdroppedpkt,
  4435. crp_txlenerr,
  4436. crp_txunderrun,
  4437. crp_txunsupvl,
  4438. QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
  4439. QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
  4440. QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
  4441. QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
  4442. crp_rxqpinvalidctxt,
  4443. crp_txhdrerr,
  4444. };
  4445. /* do all the setup to make the counter reads efficient later */
  4446. static void init_7322_cntrnames(struct qib_devdata *dd)
  4447. {
  4448. int i, j = 0;
  4449. char *s;
  4450. for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
  4451. i++) {
  4452. /* we always have at least one counter before the egrovfl */
  4453. if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
  4454. j = 1;
  4455. s = strchr(s + 1, '\n');
  4456. if (s && j)
  4457. j++;
  4458. }
  4459. dd->cspec->ncntrs = i;
  4460. if (!s)
  4461. /* full list; size is without terminating null */
  4462. dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
  4463. else
  4464. dd->cspec->cntrnamelen = 1 + s - cntr7322names;
  4465. dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
  4466. * sizeof(u64), GFP_KERNEL);
  4467. for (i = 0, s = (char *)portcntr7322names; s; i++)
  4468. s = strchr(s + 1, '\n');
  4469. dd->cspec->nportcntrs = i - 1;
  4470. dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
  4471. for (i = 0; i < dd->num_pports; ++i) {
  4472. dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
  4473. * sizeof(u64), GFP_KERNEL);
  4474. }
  4475. }
  4476. static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
  4477. u64 **cntrp)
  4478. {
  4479. u32 ret;
  4480. if (namep) {
  4481. ret = dd->cspec->cntrnamelen;
  4482. if (pos >= ret)
  4483. ret = 0; /* final read after getting everything */
  4484. else
  4485. *namep = (char *) cntr7322names;
  4486. } else {
  4487. u64 *cntr = dd->cspec->cntrs;
  4488. int i;
  4489. ret = dd->cspec->ncntrs * sizeof(u64);
  4490. if (!cntr || pos >= ret) {
  4491. /* everything read, or couldn't get memory */
  4492. ret = 0;
  4493. goto done;
  4494. }
  4495. *cntrp = cntr;
  4496. for (i = 0; i < dd->cspec->ncntrs; i++)
  4497. if (cntr7322indices[i] & _PORT_64BIT_FLAG)
  4498. *cntr++ = read_7322_creg(dd,
  4499. cntr7322indices[i] &
  4500. _PORT_CNTR_IDXMASK);
  4501. else
  4502. *cntr++ = read_7322_creg32(dd,
  4503. cntr7322indices[i]);
  4504. }
  4505. done:
  4506. return ret;
  4507. }
  4508. static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
  4509. char **namep, u64 **cntrp)
  4510. {
  4511. u32 ret;
  4512. if (namep) {
  4513. ret = dd->cspec->portcntrnamelen;
  4514. if (pos >= ret)
  4515. ret = 0; /* final read after getting everything */
  4516. else
  4517. *namep = (char *)portcntr7322names;
  4518. } else {
  4519. struct qib_pportdata *ppd = &dd->pport[port];
  4520. u64 *cntr = ppd->cpspec->portcntrs;
  4521. int i;
  4522. ret = dd->cspec->nportcntrs * sizeof(u64);
  4523. if (!cntr || pos >= ret) {
  4524. /* everything read, or couldn't get memory */
  4525. ret = 0;
  4526. goto done;
  4527. }
  4528. *cntrp = cntr;
  4529. for (i = 0; i < dd->cspec->nportcntrs; i++) {
  4530. if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
  4531. *cntr++ = qib_portcntr_7322(ppd,
  4532. portcntr7322indices[i] &
  4533. _PORT_CNTR_IDXMASK);
  4534. else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
  4535. *cntr++ = read_7322_creg_port(ppd,
  4536. portcntr7322indices[i] &
  4537. _PORT_CNTR_IDXMASK);
  4538. else
  4539. *cntr++ = read_7322_creg32_port(ppd,
  4540. portcntr7322indices[i]);
  4541. }
  4542. }
  4543. done:
  4544. return ret;
  4545. }
  4546. /**
  4547. * qib_get_7322_faststats - get word counters from chip before they overflow
  4548. * @opaque - contains a pointer to the qlogic_ib device qib_devdata
  4549. *
  4550. * VESTIGIAL IBA7322 has no "small fast counters", so the only
  4551. * real purpose of this function is to maintain the notion of
  4552. * "active time", which in turn is only logged into the eeprom,
  4553. * which we don;t have, yet, for 7322-based boards.
  4554. *
  4555. * called from add_timer
  4556. */
  4557. static void qib_get_7322_faststats(struct timer_list *t)
  4558. {
  4559. struct qib_devdata *dd = from_timer(dd, t, stats_timer);
  4560. struct qib_pportdata *ppd;
  4561. unsigned long flags;
  4562. u64 traffic_wds;
  4563. int pidx;
  4564. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  4565. ppd = dd->pport + pidx;
  4566. /*
  4567. * If port isn't enabled or not operational ports, or
  4568. * diags is running (can cause memory diags to fail)
  4569. * skip this port this time.
  4570. */
  4571. if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
  4572. || dd->diag_client)
  4573. continue;
  4574. /*
  4575. * Maintain an activity timer, based on traffic
  4576. * exceeding a threshold, so we need to check the word-counts
  4577. * even if they are 64-bit.
  4578. */
  4579. traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
  4580. qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
  4581. spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
  4582. traffic_wds -= ppd->dd->traffic_wds;
  4583. ppd->dd->traffic_wds += traffic_wds;
  4584. spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
  4585. if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
  4586. QIB_IB_QDR) &&
  4587. (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  4588. QIBL_LINKACTIVE)) &&
  4589. ppd->cpspec->qdr_dfe_time &&
  4590. time_is_before_jiffies(ppd->cpspec->qdr_dfe_time)) {
  4591. ppd->cpspec->qdr_dfe_on = 0;
  4592. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  4593. ppd->dd->cspec->r1 ?
  4594. QDR_STATIC_ADAPT_INIT_R1 :
  4595. QDR_STATIC_ADAPT_INIT);
  4596. force_h1(ppd);
  4597. }
  4598. }
  4599. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  4600. }
  4601. /*
  4602. * If we were using MSIx, try to fallback to INTx.
  4603. */
  4604. static int qib_7322_intr_fallback(struct qib_devdata *dd)
  4605. {
  4606. if (!dd->cspec->num_msix_entries)
  4607. return 0; /* already using INTx */
  4608. qib_devinfo(dd->pcidev,
  4609. "MSIx interrupt not detected, trying INTx interrupts\n");
  4610. qib_7322_free_irq(dd);
  4611. if (pci_alloc_irq_vectors(dd->pcidev, 1, 1, PCI_IRQ_LEGACY) < 0)
  4612. qib_dev_err(dd, "Failed to enable INTx\n");
  4613. qib_setup_7322_interrupt(dd, 0);
  4614. return 1;
  4615. }
  4616. /*
  4617. * Reset the XGXS (between serdes and IBC). Slightly less intrusive
  4618. * than resetting the IBC or external link state, and useful in some
  4619. * cases to cause some retraining. To do this right, we reset IBC
  4620. * as well, then return to previous state (which may be still in reset)
  4621. * NOTE: some callers of this "know" this writes the current value
  4622. * of cpspec->ibcctrl_a as part of it's operation, so if that changes,
  4623. * check all callers.
  4624. */
  4625. static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
  4626. {
  4627. u64 val;
  4628. struct qib_devdata *dd = ppd->dd;
  4629. const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
  4630. SYM_MASK(IBPCSConfig_0, xcv_treset) |
  4631. SYM_MASK(IBPCSConfig_0, tx_rx_reset);
  4632. val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
  4633. qib_write_kreg(dd, kr_hwerrmask,
  4634. dd->cspec->hwerrmask & ~HWE_MASK(statusValidNoEop));
  4635. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  4636. ppd->cpspec->ibcctrl_a &
  4637. ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
  4638. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
  4639. qib_read_kreg32(dd, kr_scratch);
  4640. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
  4641. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  4642. qib_write_kreg(dd, kr_scratch, 0ULL);
  4643. qib_write_kreg(dd, kr_hwerrclear,
  4644. SYM_MASK(HwErrClear, statusValidNoEopClear));
  4645. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  4646. }
  4647. /*
  4648. * This code for non-IBTA-compliant IB speed negotiation is only known to
  4649. * work for the SDR to DDR transition, and only between an HCA and a switch
  4650. * with recent firmware. It is based on observed heuristics, rather than
  4651. * actual knowledge of the non-compliant speed negotiation.
  4652. * It has a number of hard-coded fields, since the hope is to rewrite this
  4653. * when a spec is available on how the negoation is intended to work.
  4654. */
  4655. static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
  4656. u32 dcnt, u32 *data)
  4657. {
  4658. int i;
  4659. u64 pbc;
  4660. u32 __iomem *piobuf;
  4661. u32 pnum, control, len;
  4662. struct qib_devdata *dd = ppd->dd;
  4663. i = 0;
  4664. len = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
  4665. control = qib_7322_setpbc_control(ppd, len, 0, 15);
  4666. pbc = ((u64) control << 32) | len;
  4667. while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
  4668. if (i++ > 15)
  4669. return;
  4670. udelay(2);
  4671. }
  4672. /* disable header check on this packet, since it can't be valid */
  4673. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
  4674. writeq(pbc, piobuf);
  4675. qib_flush_wc();
  4676. qib_pio_copy(piobuf + 2, hdr, 7);
  4677. qib_pio_copy(piobuf + 9, data, dcnt);
  4678. if (dd->flags & QIB_USE_SPCL_TRIG) {
  4679. u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
  4680. qib_flush_wc();
  4681. __raw_writel(0xaebecede, piobuf + spcl_off);
  4682. }
  4683. qib_flush_wc();
  4684. qib_sendbuf_done(dd, pnum);
  4685. /* and re-enable hdr check */
  4686. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
  4687. }
  4688. /*
  4689. * _start packet gets sent twice at start, _done gets sent twice at end
  4690. */
  4691. static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
  4692. {
  4693. struct qib_devdata *dd = ppd->dd;
  4694. static u32 swapped;
  4695. u32 dw, i, hcnt, dcnt, *data;
  4696. static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
  4697. static u32 madpayload_start[0x40] = {
  4698. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4699. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4700. 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
  4701. };
  4702. static u32 madpayload_done[0x40] = {
  4703. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4704. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4705. 0x40000001, 0x1388, 0x15e, /* rest 0's */
  4706. };
  4707. dcnt = ARRAY_SIZE(madpayload_start);
  4708. hcnt = ARRAY_SIZE(hdr);
  4709. if (!swapped) {
  4710. /* for maintainability, do it at runtime */
  4711. for (i = 0; i < hcnt; i++) {
  4712. dw = (__force u32) cpu_to_be32(hdr[i]);
  4713. hdr[i] = dw;
  4714. }
  4715. for (i = 0; i < dcnt; i++) {
  4716. dw = (__force u32) cpu_to_be32(madpayload_start[i]);
  4717. madpayload_start[i] = dw;
  4718. dw = (__force u32) cpu_to_be32(madpayload_done[i]);
  4719. madpayload_done[i] = dw;
  4720. }
  4721. swapped = 1;
  4722. }
  4723. data = which ? madpayload_done : madpayload_start;
  4724. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4725. qib_read_kreg64(dd, kr_scratch);
  4726. udelay(2);
  4727. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4728. qib_read_kreg64(dd, kr_scratch);
  4729. udelay(2);
  4730. }
  4731. /*
  4732. * Do the absolute minimum to cause an IB speed change, and make it
  4733. * ready, but don't actually trigger the change. The caller will
  4734. * do that when ready (if link is in Polling training state, it will
  4735. * happen immediately, otherwise when link next goes down)
  4736. *
  4737. * This routine should only be used as part of the DDR autonegotation
  4738. * code for devices that are not compliant with IB 1.2 (or code that
  4739. * fixes things up for same).
  4740. *
  4741. * When link has gone down, and autoneg enabled, or autoneg has
  4742. * failed and we give up until next time we set both speeds, and
  4743. * then we want IBTA enabled as well as "use max enabled speed.
  4744. */
  4745. static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
  4746. {
  4747. u64 newctrlb;
  4748. newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
  4749. IBA7322_IBC_IBTA_1_2_MASK |
  4750. IBA7322_IBC_MAX_SPEED_MASK);
  4751. if (speed & (speed - 1)) /* multiple speeds */
  4752. newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
  4753. IBA7322_IBC_IBTA_1_2_MASK |
  4754. IBA7322_IBC_MAX_SPEED_MASK;
  4755. else
  4756. newctrlb |= speed == QIB_IB_QDR ?
  4757. IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
  4758. ((speed == QIB_IB_DDR ?
  4759. IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
  4760. if (newctrlb == ppd->cpspec->ibcctrl_b)
  4761. return;
  4762. ppd->cpspec->ibcctrl_b = newctrlb;
  4763. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  4764. qib_write_kreg(ppd->dd, kr_scratch, 0);
  4765. }
  4766. /*
  4767. * This routine is only used when we are not talking to another
  4768. * IB 1.2-compliant device that we think can do DDR.
  4769. * (This includes all existing switch chips as of Oct 2007.)
  4770. * 1.2-compliant devices go directly to DDR prior to reaching INIT
  4771. */
  4772. static void try_7322_autoneg(struct qib_pportdata *ppd)
  4773. {
  4774. unsigned long flags;
  4775. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4776. ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
  4777. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4778. qib_autoneg_7322_send(ppd, 0);
  4779. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  4780. qib_7322_mini_pcs_reset(ppd);
  4781. /* 2 msec is minimum length of a poll cycle */
  4782. queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
  4783. msecs_to_jiffies(2));
  4784. }
  4785. /*
  4786. * Handle the empirically determined mechanism for auto-negotiation
  4787. * of DDR speed with switches.
  4788. */
  4789. static void autoneg_7322_work(struct work_struct *work)
  4790. {
  4791. struct qib_pportdata *ppd;
  4792. u32 i;
  4793. unsigned long flags;
  4794. ppd = container_of(work, struct qib_chippport_specific,
  4795. autoneg_work.work)->ppd;
  4796. /*
  4797. * Busy wait for this first part, it should be at most a
  4798. * few hundred usec, since we scheduled ourselves for 2msec.
  4799. */
  4800. for (i = 0; i < 25; i++) {
  4801. if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
  4802. == IB_7322_LT_STATE_POLLQUIET) {
  4803. qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
  4804. break;
  4805. }
  4806. udelay(100);
  4807. }
  4808. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  4809. goto done; /* we got there early or told to stop */
  4810. /* we expect this to timeout */
  4811. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4812. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4813. msecs_to_jiffies(90)))
  4814. goto done;
  4815. qib_7322_mini_pcs_reset(ppd);
  4816. /* we expect this to timeout */
  4817. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4818. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4819. msecs_to_jiffies(1700)))
  4820. goto done;
  4821. qib_7322_mini_pcs_reset(ppd);
  4822. set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
  4823. /*
  4824. * Wait up to 250 msec for link to train and get to INIT at DDR;
  4825. * this should terminate early.
  4826. */
  4827. wait_event_timeout(ppd->cpspec->autoneg_wait,
  4828. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4829. msecs_to_jiffies(250));
  4830. done:
  4831. if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
  4832. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4833. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  4834. if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
  4835. ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
  4836. ppd->cpspec->autoneg_tries = 0;
  4837. }
  4838. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4839. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  4840. }
  4841. }
  4842. /*
  4843. * This routine is used to request IPG set in the QLogic switch.
  4844. * Only called if r1.
  4845. */
  4846. static void try_7322_ipg(struct qib_pportdata *ppd)
  4847. {
  4848. struct qib_ibport *ibp = &ppd->ibport_data;
  4849. struct ib_mad_send_buf *send_buf;
  4850. struct ib_mad_agent *agent;
  4851. struct ib_smp *smp;
  4852. unsigned delay;
  4853. int ret;
  4854. agent = ibp->rvp.send_agent;
  4855. if (!agent)
  4856. goto retry;
  4857. send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
  4858. IB_MGMT_MAD_DATA, GFP_ATOMIC,
  4859. IB_MGMT_BASE_VERSION);
  4860. if (IS_ERR(send_buf))
  4861. goto retry;
  4862. if (!ibp->smi_ah) {
  4863. struct ib_ah *ah;
  4864. ah = qib_create_qp0_ah(ibp, be16_to_cpu(IB_LID_PERMISSIVE));
  4865. if (IS_ERR(ah))
  4866. ret = PTR_ERR(ah);
  4867. else {
  4868. send_buf->ah = ah;
  4869. ibp->smi_ah = ibah_to_rvtah(ah);
  4870. ret = 0;
  4871. }
  4872. } else {
  4873. send_buf->ah = &ibp->smi_ah->ibah;
  4874. ret = 0;
  4875. }
  4876. smp = send_buf->mad;
  4877. smp->base_version = IB_MGMT_BASE_VERSION;
  4878. smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
  4879. smp->class_version = 1;
  4880. smp->method = IB_MGMT_METHOD_SEND;
  4881. smp->hop_cnt = 1;
  4882. smp->attr_id = QIB_VENDOR_IPG;
  4883. smp->attr_mod = 0;
  4884. if (!ret)
  4885. ret = ib_post_send_mad(send_buf, NULL);
  4886. if (ret)
  4887. ib_free_send_mad(send_buf);
  4888. retry:
  4889. delay = 2 << ppd->cpspec->ipg_tries;
  4890. queue_delayed_work(ib_wq, &ppd->cpspec->ipg_work,
  4891. msecs_to_jiffies(delay));
  4892. }
  4893. /*
  4894. * Timeout handler for setting IPG.
  4895. * Only called if r1.
  4896. */
  4897. static void ipg_7322_work(struct work_struct *work)
  4898. {
  4899. struct qib_pportdata *ppd;
  4900. ppd = container_of(work, struct qib_chippport_specific,
  4901. ipg_work.work)->ppd;
  4902. if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
  4903. && ++ppd->cpspec->ipg_tries <= 10)
  4904. try_7322_ipg(ppd);
  4905. }
  4906. static u32 qib_7322_iblink_state(u64 ibcs)
  4907. {
  4908. u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
  4909. switch (state) {
  4910. case IB_7322_L_STATE_INIT:
  4911. state = IB_PORT_INIT;
  4912. break;
  4913. case IB_7322_L_STATE_ARM:
  4914. state = IB_PORT_ARMED;
  4915. break;
  4916. case IB_7322_L_STATE_ACTIVE:
  4917. /* fall through */
  4918. case IB_7322_L_STATE_ACT_DEFER:
  4919. state = IB_PORT_ACTIVE;
  4920. break;
  4921. default: /* fall through */
  4922. case IB_7322_L_STATE_DOWN:
  4923. state = IB_PORT_DOWN;
  4924. break;
  4925. }
  4926. return state;
  4927. }
  4928. /* returns the IBTA port state, rather than the IBC link training state */
  4929. static u8 qib_7322_phys_portstate(u64 ibcs)
  4930. {
  4931. u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
  4932. return qib_7322_physportstate[state];
  4933. }
  4934. static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
  4935. {
  4936. int ret = 0, symadj = 0;
  4937. unsigned long flags;
  4938. int mult;
  4939. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4940. ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
  4941. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4942. /* Update our picture of width and speed from chip */
  4943. if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
  4944. ppd->link_speed_active = QIB_IB_QDR;
  4945. mult = 4;
  4946. } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
  4947. ppd->link_speed_active = QIB_IB_DDR;
  4948. mult = 2;
  4949. } else {
  4950. ppd->link_speed_active = QIB_IB_SDR;
  4951. mult = 1;
  4952. }
  4953. if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
  4954. ppd->link_width_active = IB_WIDTH_4X;
  4955. mult *= 4;
  4956. } else
  4957. ppd->link_width_active = IB_WIDTH_1X;
  4958. ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
  4959. if (!ibup) {
  4960. u64 clr;
  4961. /* Link went down. */
  4962. /* do IPG MAD again after linkdown, even if last time failed */
  4963. ppd->cpspec->ipg_tries = 0;
  4964. clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  4965. (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
  4966. SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
  4967. if (clr)
  4968. qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
  4969. if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  4970. QIBL_IB_AUTONEG_INPROG)))
  4971. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  4972. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  4973. struct qib_qsfp_data *qd =
  4974. &ppd->cpspec->qsfp_data;
  4975. /* unlock the Tx settings, speed may change */
  4976. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  4977. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  4978. reset_tx_deemphasis_override));
  4979. qib_cancel_sends(ppd);
  4980. /* on link down, ensure sane pcs state */
  4981. qib_7322_mini_pcs_reset(ppd);
  4982. /* schedule the qsfp refresh which should turn the link
  4983. off */
  4984. if (ppd->dd->flags & QIB_HAS_QSFP) {
  4985. qd->t_insert = jiffies;
  4986. queue_work(ib_wq, &qd->work);
  4987. }
  4988. spin_lock_irqsave(&ppd->sdma_lock, flags);
  4989. if (__qib_sdma_running(ppd))
  4990. __qib_sdma_process_event(ppd,
  4991. qib_sdma_event_e70_go_idle);
  4992. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  4993. }
  4994. clr = read_7322_creg32_port(ppd, crp_iblinkdown);
  4995. if (clr == ppd->cpspec->iblnkdownsnap)
  4996. ppd->cpspec->iblnkdowndelta++;
  4997. } else {
  4998. if (qib_compat_ddr_negotiate &&
  4999. !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  5000. QIBL_IB_AUTONEG_INPROG)) &&
  5001. ppd->link_speed_active == QIB_IB_SDR &&
  5002. (ppd->link_speed_enabled & QIB_IB_DDR)
  5003. && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
  5004. /* we are SDR, and auto-negotiation enabled */
  5005. ++ppd->cpspec->autoneg_tries;
  5006. if (!ppd->cpspec->ibdeltainprog) {
  5007. ppd->cpspec->ibdeltainprog = 1;
  5008. ppd->cpspec->ibsymdelta +=
  5009. read_7322_creg32_port(ppd,
  5010. crp_ibsymbolerr) -
  5011. ppd->cpspec->ibsymsnap;
  5012. ppd->cpspec->iblnkerrdelta +=
  5013. read_7322_creg32_port(ppd,
  5014. crp_iblinkerrrecov) -
  5015. ppd->cpspec->iblnkerrsnap;
  5016. }
  5017. try_7322_autoneg(ppd);
  5018. ret = 1; /* no other IB status change processing */
  5019. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  5020. ppd->link_speed_active == QIB_IB_SDR) {
  5021. qib_autoneg_7322_send(ppd, 1);
  5022. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  5023. qib_7322_mini_pcs_reset(ppd);
  5024. udelay(2);
  5025. ret = 1; /* no other IB status change processing */
  5026. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  5027. (ppd->link_speed_active & QIB_IB_DDR)) {
  5028. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5029. ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
  5030. QIBL_IB_AUTONEG_FAILED);
  5031. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5032. ppd->cpspec->autoneg_tries = 0;
  5033. /* re-enable SDR, for next link down */
  5034. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  5035. wake_up(&ppd->cpspec->autoneg_wait);
  5036. symadj = 1;
  5037. } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
  5038. /*
  5039. * Clear autoneg failure flag, and do setup
  5040. * so we'll try next time link goes down and
  5041. * back to INIT (possibly connected to a
  5042. * different device).
  5043. */
  5044. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5045. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  5046. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5047. ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
  5048. symadj = 1;
  5049. }
  5050. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5051. symadj = 1;
  5052. if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
  5053. try_7322_ipg(ppd);
  5054. if (!ppd->cpspec->recovery_init)
  5055. setup_7322_link_recovery(ppd, 0);
  5056. ppd->cpspec->qdr_dfe_time = jiffies +
  5057. msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
  5058. }
  5059. ppd->cpspec->ibmalfusesnap = 0;
  5060. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  5061. crp_errlink);
  5062. }
  5063. if (symadj) {
  5064. ppd->cpspec->iblnkdownsnap =
  5065. read_7322_creg32_port(ppd, crp_iblinkdown);
  5066. if (ppd->cpspec->ibdeltainprog) {
  5067. ppd->cpspec->ibdeltainprog = 0;
  5068. ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
  5069. crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
  5070. ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
  5071. crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
  5072. }
  5073. } else if (!ibup && qib_compat_ddr_negotiate &&
  5074. !ppd->cpspec->ibdeltainprog &&
  5075. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  5076. ppd->cpspec->ibdeltainprog = 1;
  5077. ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
  5078. crp_ibsymbolerr);
  5079. ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
  5080. crp_iblinkerrrecov);
  5081. }
  5082. if (!ret)
  5083. qib_setup_7322_setextled(ppd, ibup);
  5084. return ret;
  5085. }
  5086. /*
  5087. * Does read/modify/write to appropriate registers to
  5088. * set output and direction bits selected by mask.
  5089. * these are in their canonical postions (e.g. lsb of
  5090. * dir will end up in D48 of extctrl on existing chips).
  5091. * returns contents of GP Inputs.
  5092. */
  5093. static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
  5094. {
  5095. u64 read_val, new_out;
  5096. unsigned long flags;
  5097. if (mask) {
  5098. /* some bits being written, lock access to GPIO */
  5099. dir &= mask;
  5100. out &= mask;
  5101. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  5102. dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
  5103. dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
  5104. new_out = (dd->cspec->gpio_out & ~mask) | out;
  5105. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  5106. qib_write_kreg(dd, kr_gpio_out, new_out);
  5107. dd->cspec->gpio_out = new_out;
  5108. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  5109. }
  5110. /*
  5111. * It is unlikely that a read at this time would get valid
  5112. * data on a pin whose direction line was set in the same
  5113. * call to this function. We include the read here because
  5114. * that allows us to potentially combine a change on one pin with
  5115. * a read on another, and because the old code did something like
  5116. * this.
  5117. */
  5118. read_val = qib_read_kreg64(dd, kr_extstatus);
  5119. return SYM_FIELD(read_val, EXTStatus, GPIOIn);
  5120. }
  5121. /* Enable writes to config EEPROM, if possible. Returns previous state */
  5122. static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
  5123. {
  5124. int prev_wen;
  5125. u32 mask;
  5126. mask = 1 << QIB_EEPROM_WEN_NUM;
  5127. prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
  5128. gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
  5129. return prev_wen & 1;
  5130. }
  5131. /*
  5132. * Read fundamental info we need to use the chip. These are
  5133. * the registers that describe chip capabilities, and are
  5134. * saved in shadow registers.
  5135. */
  5136. static void get_7322_chip_params(struct qib_devdata *dd)
  5137. {
  5138. u64 val;
  5139. u32 piobufs;
  5140. int mtu;
  5141. dd->palign = qib_read_kreg32(dd, kr_pagealign);
  5142. dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
  5143. dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
  5144. dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
  5145. dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
  5146. dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
  5147. dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
  5148. val = qib_read_kreg64(dd, kr_sendpiobufcnt);
  5149. dd->piobcnt2k = val & ~0U;
  5150. dd->piobcnt4k = val >> 32;
  5151. val = qib_read_kreg64(dd, kr_sendpiosize);
  5152. dd->piosize2k = val & ~0U;
  5153. dd->piosize4k = val >> 32;
  5154. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  5155. if (mtu == -1)
  5156. mtu = QIB_DEFAULT_MTU;
  5157. dd->pport[0].ibmtu = (u32)mtu;
  5158. dd->pport[1].ibmtu = (u32)mtu;
  5159. /* these may be adjusted in init_chip_wc_pat() */
  5160. dd->pio2kbase = (u32 __iomem *)
  5161. ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
  5162. dd->pio4kbase = (u32 __iomem *)
  5163. ((char __iomem *) dd->kregbase +
  5164. (dd->piobufbase >> 32));
  5165. /*
  5166. * 4K buffers take 2 pages; we use roundup just to be
  5167. * paranoid; we calculate it once here, rather than on
  5168. * ever buf allocate
  5169. */
  5170. dd->align4k = ALIGN(dd->piosize4k, dd->palign);
  5171. piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
  5172. dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
  5173. (sizeof(u64) * BITS_PER_BYTE / 2);
  5174. }
  5175. /*
  5176. * The chip base addresses in cspec and cpspec have to be set
  5177. * after possible init_chip_wc_pat(), rather than in
  5178. * get_7322_chip_params(), so split out as separate function
  5179. */
  5180. static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
  5181. {
  5182. u32 cregbase;
  5183. cregbase = qib_read_kreg32(dd, kr_counterregbase);
  5184. dd->cspec->cregbase = (u64 __iomem *)(cregbase +
  5185. (char __iomem *)dd->kregbase);
  5186. dd->egrtidbase = (u64 __iomem *)
  5187. ((char __iomem *) dd->kregbase + dd->rcvegrbase);
  5188. /* port registers are defined as relative to base of chip */
  5189. dd->pport[0].cpspec->kpregbase =
  5190. (u64 __iomem *)((char __iomem *)dd->kregbase);
  5191. dd->pport[1].cpspec->kpregbase =
  5192. (u64 __iomem *)(dd->palign +
  5193. (char __iomem *)dd->kregbase);
  5194. dd->pport[0].cpspec->cpregbase =
  5195. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
  5196. kr_counterregbase) + (char __iomem *)dd->kregbase);
  5197. dd->pport[1].cpspec->cpregbase =
  5198. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
  5199. kr_counterregbase) + (char __iomem *)dd->kregbase);
  5200. }
  5201. /*
  5202. * This is a fairly special-purpose observer, so we only support
  5203. * the port-specific parts of SendCtrl
  5204. */
  5205. #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
  5206. SYM_MASK(SendCtrl_0, SDmaEnable) | \
  5207. SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
  5208. SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
  5209. SYM_MASK(SendCtrl_0, SDmaHalt) | \
  5210. SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
  5211. SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
  5212. static int sendctrl_hook(struct qib_devdata *dd,
  5213. const struct diag_observer *op, u32 offs,
  5214. u64 *data, u64 mask, int only_32)
  5215. {
  5216. unsigned long flags;
  5217. unsigned idx;
  5218. unsigned pidx;
  5219. struct qib_pportdata *ppd = NULL;
  5220. u64 local_data, all_bits;
  5221. /*
  5222. * The fixed correspondence between Physical ports and pports is
  5223. * severed. We need to hunt for the ppd that corresponds
  5224. * to the offset we got. And we have to do that without admitting
  5225. * we know the stride, apparently.
  5226. */
  5227. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  5228. u64 __iomem *psptr;
  5229. u32 psoffs;
  5230. ppd = dd->pport + pidx;
  5231. if (!ppd->cpspec->kpregbase)
  5232. continue;
  5233. psptr = ppd->cpspec->kpregbase + krp_sendctrl;
  5234. psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
  5235. if (psoffs == offs)
  5236. break;
  5237. }
  5238. /* If pport is not being managed by driver, just avoid shadows. */
  5239. if (pidx >= dd->num_pports)
  5240. ppd = NULL;
  5241. /* In any case, "idx" is flat index in kreg space */
  5242. idx = offs / sizeof(u64);
  5243. all_bits = ~0ULL;
  5244. if (only_32)
  5245. all_bits >>= 32;
  5246. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  5247. if (!ppd || (mask & all_bits) != all_bits) {
  5248. /*
  5249. * At least some mask bits are zero, so we need
  5250. * to read. The judgement call is whether from
  5251. * reg or shadow. First-cut: read reg, and complain
  5252. * if any bits which should be shadowed are different
  5253. * from their shadowed value.
  5254. */
  5255. if (only_32)
  5256. local_data = (u64)qib_read_kreg32(dd, idx);
  5257. else
  5258. local_data = qib_read_kreg64(dd, idx);
  5259. *data = (local_data & ~mask) | (*data & mask);
  5260. }
  5261. if (mask) {
  5262. /*
  5263. * At least some mask bits are one, so we need
  5264. * to write, but only shadow some bits.
  5265. */
  5266. u64 sval, tval; /* Shadowed, transient */
  5267. /*
  5268. * New shadow val is bits we don't want to touch,
  5269. * ORed with bits we do, that are intended for shadow.
  5270. */
  5271. if (ppd) {
  5272. sval = ppd->p_sendctrl & ~mask;
  5273. sval |= *data & SENDCTRL_SHADOWED & mask;
  5274. ppd->p_sendctrl = sval;
  5275. } else
  5276. sval = *data & SENDCTRL_SHADOWED & mask;
  5277. tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
  5278. qib_write_kreg(dd, idx, tval);
  5279. qib_write_kreg(dd, kr_scratch, 0Ull);
  5280. }
  5281. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  5282. return only_32 ? 4 : 8;
  5283. }
  5284. static const struct diag_observer sendctrl_0_observer = {
  5285. sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
  5286. KREG_IDX(SendCtrl_0) * sizeof(u64)
  5287. };
  5288. static const struct diag_observer sendctrl_1_observer = {
  5289. sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
  5290. KREG_IDX(SendCtrl_1) * sizeof(u64)
  5291. };
  5292. static ushort sdma_fetch_prio = 8;
  5293. module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
  5294. MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
  5295. /* Besides logging QSFP events, we set appropriate TxDDS values */
  5296. static void init_txdds_table(struct qib_pportdata *ppd, int override);
  5297. static void qsfp_7322_event(struct work_struct *work)
  5298. {
  5299. struct qib_qsfp_data *qd;
  5300. struct qib_pportdata *ppd;
  5301. unsigned long pwrup;
  5302. unsigned long flags;
  5303. int ret;
  5304. u32 le2;
  5305. qd = container_of(work, struct qib_qsfp_data, work);
  5306. ppd = qd->ppd;
  5307. pwrup = qd->t_insert +
  5308. msecs_to_jiffies(QSFP_PWR_LAG_MSEC - QSFP_MODPRS_LAG_MSEC);
  5309. /* Delay for 20 msecs to allow ModPrs resistor to setup */
  5310. mdelay(QSFP_MODPRS_LAG_MSEC);
  5311. if (!qib_qsfp_mod_present(ppd)) {
  5312. ppd->cpspec->qsfp_data.modpresent = 0;
  5313. /* Set the physical link to disabled */
  5314. qib_set_ib_7322_lstate(ppd, 0,
  5315. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  5316. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5317. ppd->lflags &= ~QIBL_LINKV;
  5318. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5319. } else {
  5320. /*
  5321. * Some QSFP's not only do not respond until the full power-up
  5322. * time, but may behave badly if we try. So hold off responding
  5323. * to insertion.
  5324. */
  5325. while (1) {
  5326. if (time_is_before_jiffies(pwrup))
  5327. break;
  5328. msleep(20);
  5329. }
  5330. ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
  5331. /*
  5332. * Need to change LE2 back to defaults if we couldn't
  5333. * read the cable type (to handle cable swaps), so do this
  5334. * even on failure to read cable information. We don't
  5335. * get here for QME, so IS_QME check not needed here.
  5336. */
  5337. if (!ret && !ppd->dd->cspec->r1) {
  5338. if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
  5339. le2 = LE2_QME;
  5340. else if (qd->cache.atten[1] >= qib_long_atten &&
  5341. QSFP_IS_CU(qd->cache.tech))
  5342. le2 = LE2_5m;
  5343. else
  5344. le2 = LE2_DEFAULT;
  5345. } else
  5346. le2 = LE2_DEFAULT;
  5347. ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
  5348. /*
  5349. * We always change parameteters, since we can choose
  5350. * values for cables without eeproms, and the cable may have
  5351. * changed from a cable with full or partial eeprom content
  5352. * to one with partial or no content.
  5353. */
  5354. init_txdds_table(ppd, 0);
  5355. /* The physical link is being re-enabled only when the
  5356. * previous state was DISABLED and the VALID bit is not
  5357. * set. This should only happen when the cable has been
  5358. * physically pulled. */
  5359. if (!ppd->cpspec->qsfp_data.modpresent &&
  5360. (ppd->lflags & (QIBL_LINKV | QIBL_IB_LINK_DISABLED))) {
  5361. ppd->cpspec->qsfp_data.modpresent = 1;
  5362. qib_set_ib_7322_lstate(ppd, 0,
  5363. QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
  5364. spin_lock_irqsave(&ppd->lflags_lock, flags);
  5365. ppd->lflags |= QIBL_LINKV;
  5366. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  5367. }
  5368. }
  5369. }
  5370. /*
  5371. * There is little we can do but complain to the user if QSFP
  5372. * initialization fails.
  5373. */
  5374. static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
  5375. {
  5376. unsigned long flags;
  5377. struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
  5378. struct qib_devdata *dd = ppd->dd;
  5379. u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
  5380. mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
  5381. qd->ppd = ppd;
  5382. qib_qsfp_init(qd, qsfp_7322_event);
  5383. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  5384. dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
  5385. dd->cspec->gpio_mask |= mod_prs_bit;
  5386. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  5387. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  5388. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  5389. }
  5390. /*
  5391. * called at device initialization time, and also if the txselect
  5392. * module parameter is changed. This is used for cables that don't
  5393. * have valid QSFP EEPROMs (not present, or attenuation is zero).
  5394. * We initialize to the default, then if there is a specific
  5395. * unit,port match, we use that (and set it immediately, for the
  5396. * current speed, if the link is at INIT or better).
  5397. * String format is "default# unit#,port#=# ... u,p=#", separators must
  5398. * be a SPACE character. A newline terminates. The u,p=# tuples may
  5399. * optionally have "u,p=#,#", where the final # is the H1 value
  5400. * The last specific match is used (actually, all are used, but last
  5401. * one is the one that winds up set); if none at all, fall back on default.
  5402. */
  5403. static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
  5404. {
  5405. char *nxt, *str;
  5406. u32 pidx, unit, port, deflt, h1;
  5407. unsigned long val;
  5408. int any = 0, seth1;
  5409. int txdds_size;
  5410. str = txselect_list;
  5411. /* default number is validated in setup_txselect() */
  5412. deflt = simple_strtoul(str, &nxt, 0);
  5413. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5414. dd->pport[pidx].cpspec->no_eep = deflt;
  5415. txdds_size = TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ;
  5416. if (IS_QME(dd) || IS_QMH(dd))
  5417. txdds_size += TXDDS_MFG_SZ;
  5418. while (*nxt && nxt[1]) {
  5419. str = ++nxt;
  5420. unit = simple_strtoul(str, &nxt, 0);
  5421. if (nxt == str || !*nxt || *nxt != ',') {
  5422. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5423. ;
  5424. continue;
  5425. }
  5426. str = ++nxt;
  5427. port = simple_strtoul(str, &nxt, 0);
  5428. if (nxt == str || *nxt != '=') {
  5429. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5430. ;
  5431. continue;
  5432. }
  5433. str = ++nxt;
  5434. val = simple_strtoul(str, &nxt, 0);
  5435. if (nxt == str) {
  5436. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5437. ;
  5438. continue;
  5439. }
  5440. if (val >= txdds_size)
  5441. continue;
  5442. seth1 = 0;
  5443. h1 = 0; /* gcc thinks it might be used uninitted */
  5444. if (*nxt == ',' && nxt[1]) {
  5445. str = ++nxt;
  5446. h1 = (u32)simple_strtoul(str, &nxt, 0);
  5447. if (nxt == str)
  5448. while (*nxt && *nxt++ != ' ') /* skip */
  5449. ;
  5450. else
  5451. seth1 = 1;
  5452. }
  5453. for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
  5454. ++pidx) {
  5455. struct qib_pportdata *ppd = &dd->pport[pidx];
  5456. if (ppd->port != port || !ppd->link_speed_supported)
  5457. continue;
  5458. ppd->cpspec->no_eep = val;
  5459. if (seth1)
  5460. ppd->cpspec->h1_val = h1;
  5461. /* now change the IBC and serdes, overriding generic */
  5462. init_txdds_table(ppd, 1);
  5463. /* Re-enable the physical state machine on mezz boards
  5464. * now that the correct settings have been set.
  5465. * QSFP boards are handles by the QSFP event handler */
  5466. if (IS_QMH(dd) || IS_QME(dd))
  5467. qib_set_ib_7322_lstate(ppd, 0,
  5468. QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
  5469. any++;
  5470. }
  5471. if (*nxt == '\n')
  5472. break; /* done */
  5473. }
  5474. if (change && !any) {
  5475. /* no specific setting, use the default.
  5476. * Change the IBC and serdes, but since it's
  5477. * general, don't override specific settings.
  5478. */
  5479. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5480. if (dd->pport[pidx].link_speed_supported)
  5481. init_txdds_table(&dd->pport[pidx], 0);
  5482. }
  5483. }
  5484. /* handle the txselect parameter changing */
  5485. static int setup_txselect(const char *str, const struct kernel_param *kp)
  5486. {
  5487. struct qib_devdata *dd;
  5488. unsigned long val;
  5489. char *n;
  5490. if (strlen(str) >= ARRAY_SIZE(txselect_list)) {
  5491. pr_info("txselect_values string too long\n");
  5492. return -ENOSPC;
  5493. }
  5494. val = simple_strtoul(str, &n, 0);
  5495. if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  5496. TXDDS_MFG_SZ)) {
  5497. pr_info("txselect_values must start with a number < %d\n",
  5498. TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
  5499. return -EINVAL;
  5500. }
  5501. strncpy(txselect_list, str, ARRAY_SIZE(txselect_list) - 1);
  5502. list_for_each_entry(dd, &qib_dev_list, list)
  5503. if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
  5504. set_no_qsfp_atten(dd, 1);
  5505. return 0;
  5506. }
  5507. /*
  5508. * Write the final few registers that depend on some of the
  5509. * init setup. Done late in init, just before bringing up
  5510. * the serdes.
  5511. */
  5512. static int qib_late_7322_initreg(struct qib_devdata *dd)
  5513. {
  5514. int ret = 0, n;
  5515. u64 val;
  5516. qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
  5517. qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
  5518. qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
  5519. qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
  5520. val = qib_read_kreg64(dd, kr_sendpioavailaddr);
  5521. if (val != dd->pioavailregs_phys) {
  5522. qib_dev_err(dd,
  5523. "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
  5524. (unsigned long) dd->pioavailregs_phys,
  5525. (unsigned long long) val);
  5526. ret = -EINVAL;
  5527. }
  5528. n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  5529. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
  5530. /* driver sends get pkey, lid, etc. checking also, to catch bugs */
  5531. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
  5532. qib_register_observer(dd, &sendctrl_0_observer);
  5533. qib_register_observer(dd, &sendctrl_1_observer);
  5534. dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5535. qib_write_kreg(dd, kr_control, dd->control);
  5536. /*
  5537. * Set SendDmaFetchPriority and init Tx params, including
  5538. * QSFP handler on boards that have QSFP.
  5539. * First set our default attenuation entry for cables that
  5540. * don't have valid attenuation.
  5541. */
  5542. set_no_qsfp_atten(dd, 0);
  5543. for (n = 0; n < dd->num_pports; ++n) {
  5544. struct qib_pportdata *ppd = dd->pport + n;
  5545. qib_write_kreg_port(ppd, krp_senddmaprioritythld,
  5546. sdma_fetch_prio & 0xf);
  5547. /* Initialize qsfp if present on board. */
  5548. if (dd->flags & QIB_HAS_QSFP)
  5549. qib_init_7322_qsfp(ppd);
  5550. }
  5551. dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5552. qib_write_kreg(dd, kr_control, dd->control);
  5553. return ret;
  5554. }
  5555. /* per IB port errors. */
  5556. #define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
  5557. MASK_ACROSS(8, 15))
  5558. #define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
  5559. #define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
  5560. MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
  5561. MASK_ACROSS(0, 11))
  5562. /*
  5563. * Write the initialization per-port registers that need to be done at
  5564. * driver load and after reset completes (i.e., that aren't done as part
  5565. * of other init procedures called from qib_init.c).
  5566. * Some of these should be redundant on reset, but play safe.
  5567. */
  5568. static void write_7322_init_portregs(struct qib_pportdata *ppd)
  5569. {
  5570. u64 val;
  5571. int i;
  5572. if (!ppd->link_speed_supported) {
  5573. /* no buffer credits for this port */
  5574. for (i = 1; i < 8; i++)
  5575. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
  5576. qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
  5577. qib_write_kreg(ppd->dd, kr_scratch, 0);
  5578. return;
  5579. }
  5580. /*
  5581. * Set the number of supported virtual lanes in IBC,
  5582. * for flow control packet handling on unsupported VLs
  5583. */
  5584. val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
  5585. val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
  5586. val |= (u64)(ppd->vls_supported - 1) <<
  5587. SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
  5588. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  5589. qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
  5590. /* enable tx header checking */
  5591. qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
  5592. IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
  5593. IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
  5594. qib_write_kreg_port(ppd, krp_ncmodectrl,
  5595. SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
  5596. /*
  5597. * Unconditionally clear the bufmask bits. If SDMA is
  5598. * enabled, we'll set them appropriately later.
  5599. */
  5600. qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
  5601. qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
  5602. qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
  5603. if (ppd->dd->cspec->r1)
  5604. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
  5605. }
  5606. /*
  5607. * Write the initialization per-device registers that need to be done at
  5608. * driver load and after reset completes (i.e., that aren't done as part
  5609. * of other init procedures called from qib_init.c). Also write per-port
  5610. * registers that are affected by overall device config, such as QP mapping
  5611. * Some of these should be redundant on reset, but play safe.
  5612. */
  5613. static void write_7322_initregs(struct qib_devdata *dd)
  5614. {
  5615. struct qib_pportdata *ppd;
  5616. int i, pidx;
  5617. u64 val;
  5618. /* Set Multicast QPs received by port 2 to map to context one. */
  5619. qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
  5620. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  5621. unsigned n, regno;
  5622. unsigned long flags;
  5623. if (dd->n_krcv_queues < 2 ||
  5624. !dd->pport[pidx].link_speed_supported)
  5625. continue;
  5626. ppd = &dd->pport[pidx];
  5627. /* be paranoid against later code motion, etc. */
  5628. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  5629. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
  5630. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  5631. /* Initialize QP to context mapping */
  5632. regno = krp_rcvqpmaptable;
  5633. val = 0;
  5634. if (dd->num_pports > 1)
  5635. n = dd->first_user_ctxt / dd->num_pports;
  5636. else
  5637. n = dd->first_user_ctxt - 1;
  5638. for (i = 0; i < 32; ) {
  5639. unsigned ctxt;
  5640. if (dd->num_pports > 1)
  5641. ctxt = (i % n) * dd->num_pports + pidx;
  5642. else if (i % n)
  5643. ctxt = (i % n) + 1;
  5644. else
  5645. ctxt = ppd->hw_pidx;
  5646. val |= ctxt << (5 * (i % 6));
  5647. i++;
  5648. if (i % 6 == 0) {
  5649. qib_write_kreg_port(ppd, regno, val);
  5650. val = 0;
  5651. regno++;
  5652. }
  5653. }
  5654. qib_write_kreg_port(ppd, regno, val);
  5655. }
  5656. /*
  5657. * Setup up interrupt mitigation for kernel contexts, but
  5658. * not user contexts (user contexts use interrupts when
  5659. * stalled waiting for any packet, so want those interrupts
  5660. * right away).
  5661. */
  5662. for (i = 0; i < dd->first_user_ctxt; i++) {
  5663. dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
  5664. qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
  5665. }
  5666. /*
  5667. * Initialize as (disabled) rcvflow tables. Application code
  5668. * will setup each flow as it uses the flow.
  5669. * Doesn't clear any of the error bits that might be set.
  5670. */
  5671. val = TIDFLOW_ERRBITS; /* these are W1C */
  5672. for (i = 0; i < dd->cfgctxts; i++) {
  5673. int flow;
  5674. for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
  5675. qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
  5676. }
  5677. /*
  5678. * dual cards init to dual port recovery, single port cards to
  5679. * the one port. Dual port cards may later adjust to 1 port,
  5680. * and then back to dual port if both ports are connected
  5681. * */
  5682. if (dd->num_pports)
  5683. setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
  5684. }
  5685. static int qib_init_7322_variables(struct qib_devdata *dd)
  5686. {
  5687. struct qib_pportdata *ppd;
  5688. unsigned features, pidx, sbufcnt;
  5689. int ret, mtu;
  5690. u32 sbufs, updthresh;
  5691. resource_size_t vl15off;
  5692. /* pport structs are contiguous, allocated after devdata */
  5693. ppd = (struct qib_pportdata *)(dd + 1);
  5694. dd->pport = ppd;
  5695. ppd[0].dd = dd;
  5696. ppd[1].dd = dd;
  5697. dd->cspec = (struct qib_chip_specific *)(ppd + 2);
  5698. ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
  5699. ppd[1].cpspec = &ppd[0].cpspec[1];
  5700. ppd[0].cpspec->ppd = &ppd[0]; /* for autoneg_7322_work() */
  5701. ppd[1].cpspec->ppd = &ppd[1]; /* for autoneg_7322_work() */
  5702. spin_lock_init(&dd->cspec->rcvmod_lock);
  5703. spin_lock_init(&dd->cspec->gpio_lock);
  5704. /* we haven't yet set QIB_PRESENT, so use read directly */
  5705. dd->revision = readq(&dd->kregbase[kr_revision]);
  5706. if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
  5707. qib_dev_err(dd,
  5708. "Revision register read failure, giving up initialization\n");
  5709. ret = -ENODEV;
  5710. goto bail;
  5711. }
  5712. dd->flags |= QIB_PRESENT; /* now register routines work */
  5713. dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
  5714. dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
  5715. dd->cspec->r1 = dd->minrev == 1;
  5716. get_7322_chip_params(dd);
  5717. features = qib_7322_boardname(dd);
  5718. /* now that piobcnt2k and 4k set, we can allocate these */
  5719. sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
  5720. NUM_VL15_BUFS + BITS_PER_LONG - 1;
  5721. sbufcnt /= BITS_PER_LONG;
  5722. dd->cspec->sendchkenable = kmalloc(sbufcnt *
  5723. sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
  5724. dd->cspec->sendgrhchk = kmalloc(sbufcnt *
  5725. sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
  5726. dd->cspec->sendibchk = kmalloc(sbufcnt *
  5727. sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
  5728. if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
  5729. !dd->cspec->sendibchk) {
  5730. ret = -ENOMEM;
  5731. goto bail;
  5732. }
  5733. ppd = dd->pport;
  5734. /*
  5735. * GPIO bits for TWSI data and clock,
  5736. * used for serial EEPROM.
  5737. */
  5738. dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
  5739. dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
  5740. dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
  5741. dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
  5742. QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
  5743. QIB_HAS_THRESH_UPDATE |
  5744. (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
  5745. dd->flags |= qib_special_trigger ?
  5746. QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
  5747. /*
  5748. * Setup initial values. These may change when PAT is enabled, but
  5749. * we need these to do initial chip register accesses.
  5750. */
  5751. qib_7322_set_baseaddrs(dd);
  5752. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  5753. if (mtu == -1)
  5754. mtu = QIB_DEFAULT_MTU;
  5755. dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
  5756. /* all hwerrors become interrupts, unless special purposed */
  5757. dd->cspec->hwerrmask = ~0ULL;
  5758. /* link_recovery setup causes these errors, so ignore them,
  5759. * other than clearing them when they occur */
  5760. dd->cspec->hwerrmask &=
  5761. ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
  5762. SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
  5763. HWE_MASK(LATriggered));
  5764. for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
  5765. struct qib_chippport_specific *cp = ppd->cpspec;
  5766. ppd->link_speed_supported = features & PORT_SPD_CAP;
  5767. features >>= PORT_SPD_CAP_SHIFT;
  5768. if (!ppd->link_speed_supported) {
  5769. /* single port mode (7340, or configured) */
  5770. dd->skip_kctxt_mask |= 1 << pidx;
  5771. if (pidx == 0) {
  5772. /* Make sure port is disabled. */
  5773. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5774. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5775. ppd[0] = ppd[1];
  5776. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5777. IBSerdesPClkNotDetectMask_0)
  5778. | SYM_MASK(HwErrMask,
  5779. SDmaMemReadErrMask_0));
  5780. dd->cspec->int_enable_mask &= ~(
  5781. SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
  5782. SYM_MASK(IntMask, SDmaIdleIntMask_0) |
  5783. SYM_MASK(IntMask, SDmaProgressIntMask_0) |
  5784. SYM_MASK(IntMask, SDmaIntMask_0) |
  5785. SYM_MASK(IntMask, ErrIntMask_0) |
  5786. SYM_MASK(IntMask, SendDoneIntMask_0));
  5787. } else {
  5788. /* Make sure port is disabled. */
  5789. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5790. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5791. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5792. IBSerdesPClkNotDetectMask_1)
  5793. | SYM_MASK(HwErrMask,
  5794. SDmaMemReadErrMask_1));
  5795. dd->cspec->int_enable_mask &= ~(
  5796. SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
  5797. SYM_MASK(IntMask, SDmaIdleIntMask_1) |
  5798. SYM_MASK(IntMask, SDmaProgressIntMask_1) |
  5799. SYM_MASK(IntMask, SDmaIntMask_1) |
  5800. SYM_MASK(IntMask, ErrIntMask_1) |
  5801. SYM_MASK(IntMask, SendDoneIntMask_1));
  5802. }
  5803. continue;
  5804. }
  5805. dd->num_pports++;
  5806. ret = qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
  5807. if (ret) {
  5808. dd->num_pports--;
  5809. goto bail;
  5810. }
  5811. ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  5812. ppd->link_width_enabled = IB_WIDTH_4X;
  5813. ppd->link_speed_enabled = ppd->link_speed_supported;
  5814. /*
  5815. * Set the initial values to reasonable default, will be set
  5816. * for real when link is up.
  5817. */
  5818. ppd->link_width_active = IB_WIDTH_4X;
  5819. ppd->link_speed_active = QIB_IB_SDR;
  5820. ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
  5821. switch (qib_num_cfg_vls) {
  5822. case 1:
  5823. ppd->vls_supported = IB_VL_VL0;
  5824. break;
  5825. case 2:
  5826. ppd->vls_supported = IB_VL_VL0_1;
  5827. break;
  5828. default:
  5829. qib_devinfo(dd->pcidev,
  5830. "Invalid num_vls %u, using 4 VLs\n",
  5831. qib_num_cfg_vls);
  5832. qib_num_cfg_vls = 4;
  5833. /* fall through */
  5834. case 4:
  5835. ppd->vls_supported = IB_VL_VL0_3;
  5836. break;
  5837. case 8:
  5838. if (mtu <= 2048)
  5839. ppd->vls_supported = IB_VL_VL0_7;
  5840. else {
  5841. qib_devinfo(dd->pcidev,
  5842. "Invalid num_vls %u for MTU %d , using 4 VLs\n",
  5843. qib_num_cfg_vls, mtu);
  5844. ppd->vls_supported = IB_VL_VL0_3;
  5845. qib_num_cfg_vls = 4;
  5846. }
  5847. break;
  5848. }
  5849. ppd->vls_operational = ppd->vls_supported;
  5850. init_waitqueue_head(&cp->autoneg_wait);
  5851. INIT_DELAYED_WORK(&cp->autoneg_work,
  5852. autoneg_7322_work);
  5853. if (ppd->dd->cspec->r1)
  5854. INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
  5855. /*
  5856. * For Mez and similar cards, no qsfp info, so do
  5857. * the "cable info" setup here. Can be overridden
  5858. * in adapter-specific routines.
  5859. */
  5860. if (!(dd->flags & QIB_HAS_QSFP)) {
  5861. if (!IS_QMH(dd) && !IS_QME(dd))
  5862. qib_devinfo(dd->pcidev,
  5863. "IB%u:%u: Unknown mezzanine card type\n",
  5864. dd->unit, ppd->port);
  5865. cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
  5866. /*
  5867. * Choose center value as default tx serdes setting
  5868. * until changed through module parameter.
  5869. */
  5870. ppd->cpspec->no_eep = IS_QMH(dd) ?
  5871. TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
  5872. } else
  5873. cp->h1_val = H1_FORCE_VAL;
  5874. /* Avoid writes to chip for mini_init */
  5875. if (!qib_mini_init)
  5876. write_7322_init_portregs(ppd);
  5877. timer_setup(&cp->chase_timer, reenable_chase, 0);
  5878. ppd++;
  5879. }
  5880. dd->rcvhdrentsize = qib_rcvhdrentsize ?
  5881. qib_rcvhdrentsize : QIB_RCVHDR_ENTSIZE;
  5882. dd->rcvhdrsize = qib_rcvhdrsize ?
  5883. qib_rcvhdrsize : QIB_DFLT_RCVHDRSIZE;
  5884. dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
  5885. /* we always allocate at least 2048 bytes for eager buffers */
  5886. dd->rcvegrbufsize = max(mtu, 2048);
  5887. BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
  5888. dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
  5889. qib_7322_tidtemplate(dd);
  5890. /*
  5891. * We can request a receive interrupt for 1 or
  5892. * more packets from current offset.
  5893. */
  5894. dd->rhdrhead_intr_off =
  5895. (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
  5896. /* setup the stats timer; the add_timer is done at end of init */
  5897. timer_setup(&dd->stats_timer, qib_get_7322_faststats, 0);
  5898. dd->ureg_align = 0x10000; /* 64KB alignment */
  5899. dd->piosize2kmax_dwords = dd->piosize2k >> 2;
  5900. qib_7322_config_ctxts(dd);
  5901. qib_set_ctxtcnt(dd);
  5902. /*
  5903. * We do not set WC on the VL15 buffers to avoid
  5904. * a rare problem with unaligned writes from
  5905. * interrupt-flushed store buffers, so we need
  5906. * to map those separately here. We can't solve
  5907. * this for the rarely used mtrr case.
  5908. */
  5909. ret = init_chip_wc_pat(dd, 0);
  5910. if (ret)
  5911. goto bail;
  5912. /* vl15 buffers start just after the 4k buffers */
  5913. vl15off = dd->physaddr + (dd->piobufbase >> 32) +
  5914. dd->piobcnt4k * dd->align4k;
  5915. dd->piovl15base = ioremap_nocache(vl15off,
  5916. NUM_VL15_BUFS * dd->align4k);
  5917. if (!dd->piovl15base) {
  5918. ret = -ENOMEM;
  5919. goto bail;
  5920. }
  5921. qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
  5922. ret = 0;
  5923. if (qib_mini_init)
  5924. goto bail;
  5925. if (!dd->num_pports) {
  5926. qib_dev_err(dd, "No ports enabled, giving up initialization\n");
  5927. goto bail; /* no error, so can still figure out why err */
  5928. }
  5929. write_7322_initregs(dd);
  5930. ret = qib_create_ctxts(dd);
  5931. init_7322_cntrnames(dd);
  5932. updthresh = 8U; /* update threshold */
  5933. /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
  5934. * reserve the update threshold amount for other kernel use, such
  5935. * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
  5936. * unless we aren't enabling SDMA, in which case we want to use
  5937. * all the 4k bufs for the kernel.
  5938. * if this was less than the update threshold, we could wait
  5939. * a long time for an update. Coded this way because we
  5940. * sometimes change the update threshold for various reasons,
  5941. * and we want this to remain robust.
  5942. */
  5943. if (dd->flags & QIB_HAS_SEND_DMA) {
  5944. dd->cspec->sdmabufcnt = dd->piobcnt4k;
  5945. sbufs = updthresh > 3 ? updthresh : 3;
  5946. } else {
  5947. dd->cspec->sdmabufcnt = 0;
  5948. sbufs = dd->piobcnt4k;
  5949. }
  5950. dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
  5951. dd->cspec->sdmabufcnt;
  5952. dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
  5953. dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
  5954. dd->last_pio = dd->cspec->lastbuf_for_pio;
  5955. dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
  5956. dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
  5957. /*
  5958. * If we have 16 user contexts, we will have 7 sbufs
  5959. * per context, so reduce the update threshold to match. We
  5960. * want to update before we actually run out, at low pbufs/ctxt
  5961. * so give ourselves some margin.
  5962. */
  5963. if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
  5964. updthresh = dd->pbufsctxt - 2;
  5965. dd->cspec->updthresh_dflt = updthresh;
  5966. dd->cspec->updthresh = updthresh;
  5967. /* before full enable, no interrupts, no locking needed */
  5968. dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
  5969. << SYM_LSB(SendCtrl, AvailUpdThld)) |
  5970. SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
  5971. dd->psxmitwait_supported = 1;
  5972. dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
  5973. bail:
  5974. if (!dd->ctxtcnt)
  5975. dd->ctxtcnt = 1; /* for other initialization code */
  5976. return ret;
  5977. }
  5978. static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
  5979. u32 *pbufnum)
  5980. {
  5981. u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
  5982. struct qib_devdata *dd = ppd->dd;
  5983. /* last is same for 2k and 4k, because we use 4k if all 2k busy */
  5984. if (pbc & PBC_7322_VL15_SEND) {
  5985. first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
  5986. last = first;
  5987. } else {
  5988. if ((plen + 1) > dd->piosize2kmax_dwords)
  5989. first = dd->piobcnt2k;
  5990. else
  5991. first = 0;
  5992. last = dd->cspec->lastbuf_for_pio;
  5993. }
  5994. return qib_getsendbuf_range(dd, pbufnum, first, last);
  5995. }
  5996. static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
  5997. u32 start)
  5998. {
  5999. qib_write_kreg_port(ppd, krp_psinterval, intv);
  6000. qib_write_kreg_port(ppd, krp_psstart, start);
  6001. }
  6002. /*
  6003. * Must be called with sdma_lock held, or before init finished.
  6004. */
  6005. static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
  6006. {
  6007. qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
  6008. }
  6009. /*
  6010. * sdma_lock should be acquired before calling this routine
  6011. */
  6012. static void dump_sdma_7322_state(struct qib_pportdata *ppd)
  6013. {
  6014. u64 reg, reg1, reg2;
  6015. reg = qib_read_kreg_port(ppd, krp_senddmastatus);
  6016. qib_dev_porterr(ppd->dd, ppd->port,
  6017. "SDMA senddmastatus: 0x%016llx\n", reg);
  6018. reg = qib_read_kreg_port(ppd, krp_sendctrl);
  6019. qib_dev_porterr(ppd->dd, ppd->port,
  6020. "SDMA sendctrl: 0x%016llx\n", reg);
  6021. reg = qib_read_kreg_port(ppd, krp_senddmabase);
  6022. qib_dev_porterr(ppd->dd, ppd->port,
  6023. "SDMA senddmabase: 0x%016llx\n", reg);
  6024. reg = qib_read_kreg_port(ppd, krp_senddmabufmask0);
  6025. reg1 = qib_read_kreg_port(ppd, krp_senddmabufmask1);
  6026. reg2 = qib_read_kreg_port(ppd, krp_senddmabufmask2);
  6027. qib_dev_porterr(ppd->dd, ppd->port,
  6028. "SDMA senddmabufmask 0:%llx 1:%llx 2:%llx\n",
  6029. reg, reg1, reg2);
  6030. /* get bufuse bits, clear them, and print them again if non-zero */
  6031. reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
  6032. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg);
  6033. reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
  6034. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg1);
  6035. reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
  6036. qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg2);
  6037. /* 0 and 1 should always be zero, so print as short form */
  6038. qib_dev_porterr(ppd->dd, ppd->port,
  6039. "SDMA current senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
  6040. reg, reg1, reg2);
  6041. reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
  6042. reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
  6043. reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
  6044. /* 0 and 1 should always be zero, so print as short form */
  6045. qib_dev_porterr(ppd->dd, ppd->port,
  6046. "SDMA cleared senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
  6047. reg, reg1, reg2);
  6048. reg = qib_read_kreg_port(ppd, krp_senddmatail);
  6049. qib_dev_porterr(ppd->dd, ppd->port,
  6050. "SDMA senddmatail: 0x%016llx\n", reg);
  6051. reg = qib_read_kreg_port(ppd, krp_senddmahead);
  6052. qib_dev_porterr(ppd->dd, ppd->port,
  6053. "SDMA senddmahead: 0x%016llx\n", reg);
  6054. reg = qib_read_kreg_port(ppd, krp_senddmaheadaddr);
  6055. qib_dev_porterr(ppd->dd, ppd->port,
  6056. "SDMA senddmaheadaddr: 0x%016llx\n", reg);
  6057. reg = qib_read_kreg_port(ppd, krp_senddmalengen);
  6058. qib_dev_porterr(ppd->dd, ppd->port,
  6059. "SDMA senddmalengen: 0x%016llx\n", reg);
  6060. reg = qib_read_kreg_port(ppd, krp_senddmadesccnt);
  6061. qib_dev_porterr(ppd->dd, ppd->port,
  6062. "SDMA senddmadesccnt: 0x%016llx\n", reg);
  6063. reg = qib_read_kreg_port(ppd, krp_senddmaidlecnt);
  6064. qib_dev_porterr(ppd->dd, ppd->port,
  6065. "SDMA senddmaidlecnt: 0x%016llx\n", reg);
  6066. reg = qib_read_kreg_port(ppd, krp_senddmaprioritythld);
  6067. qib_dev_porterr(ppd->dd, ppd->port,
  6068. "SDMA senddmapriorityhld: 0x%016llx\n", reg);
  6069. reg = qib_read_kreg_port(ppd, krp_senddmareloadcnt);
  6070. qib_dev_porterr(ppd->dd, ppd->port,
  6071. "SDMA senddmareloadcnt: 0x%016llx\n", reg);
  6072. dump_sdma_state(ppd);
  6073. }
  6074. static struct sdma_set_state_action sdma_7322_action_table[] = {
  6075. [qib_sdma_state_s00_hw_down] = {
  6076. .go_s99_running_tofalse = 1,
  6077. .op_enable = 0,
  6078. .op_intenable = 0,
  6079. .op_halt = 0,
  6080. .op_drain = 0,
  6081. },
  6082. [qib_sdma_state_s10_hw_start_up_wait] = {
  6083. .op_enable = 0,
  6084. .op_intenable = 1,
  6085. .op_halt = 1,
  6086. .op_drain = 0,
  6087. },
  6088. [qib_sdma_state_s20_idle] = {
  6089. .op_enable = 1,
  6090. .op_intenable = 1,
  6091. .op_halt = 1,
  6092. .op_drain = 0,
  6093. },
  6094. [qib_sdma_state_s30_sw_clean_up_wait] = {
  6095. .op_enable = 0,
  6096. .op_intenable = 1,
  6097. .op_halt = 1,
  6098. .op_drain = 0,
  6099. },
  6100. [qib_sdma_state_s40_hw_clean_up_wait] = {
  6101. .op_enable = 1,
  6102. .op_intenable = 1,
  6103. .op_halt = 1,
  6104. .op_drain = 0,
  6105. },
  6106. [qib_sdma_state_s50_hw_halt_wait] = {
  6107. .op_enable = 1,
  6108. .op_intenable = 1,
  6109. .op_halt = 1,
  6110. .op_drain = 1,
  6111. },
  6112. [qib_sdma_state_s99_running] = {
  6113. .op_enable = 1,
  6114. .op_intenable = 1,
  6115. .op_halt = 0,
  6116. .op_drain = 0,
  6117. .go_s99_running_totrue = 1,
  6118. },
  6119. };
  6120. static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
  6121. {
  6122. ppd->sdma_state.set_state_action = sdma_7322_action_table;
  6123. }
  6124. static int init_sdma_7322_regs(struct qib_pportdata *ppd)
  6125. {
  6126. struct qib_devdata *dd = ppd->dd;
  6127. unsigned lastbuf, erstbuf;
  6128. u64 senddmabufmask[3] = { 0 };
  6129. int n, ret = 0;
  6130. qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
  6131. qib_sdma_7322_setlengen(ppd);
  6132. qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
  6133. qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
  6134. qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
  6135. qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
  6136. if (dd->num_pports)
  6137. n = dd->cspec->sdmabufcnt / dd->num_pports; /* no remainder */
  6138. else
  6139. n = dd->cspec->sdmabufcnt; /* failsafe for init */
  6140. erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
  6141. ((dd->num_pports == 1 || ppd->port == 2) ? n :
  6142. dd->cspec->sdmabufcnt);
  6143. lastbuf = erstbuf + n;
  6144. ppd->sdma_state.first_sendbuf = erstbuf;
  6145. ppd->sdma_state.last_sendbuf = lastbuf;
  6146. for (; erstbuf < lastbuf; ++erstbuf) {
  6147. unsigned word = erstbuf / BITS_PER_LONG;
  6148. unsigned bit = erstbuf & (BITS_PER_LONG - 1);
  6149. BUG_ON(word >= 3);
  6150. senddmabufmask[word] |= 1ULL << bit;
  6151. }
  6152. qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
  6153. qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
  6154. qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
  6155. return ret;
  6156. }
  6157. /* sdma_lock must be held */
  6158. static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
  6159. {
  6160. struct qib_devdata *dd = ppd->dd;
  6161. int sane;
  6162. int use_dmahead;
  6163. u16 swhead;
  6164. u16 swtail;
  6165. u16 cnt;
  6166. u16 hwhead;
  6167. use_dmahead = __qib_sdma_running(ppd) &&
  6168. (dd->flags & QIB_HAS_SDMA_TIMEOUT);
  6169. retry:
  6170. hwhead = use_dmahead ?
  6171. (u16) le64_to_cpu(*ppd->sdma_head_dma) :
  6172. (u16) qib_read_kreg_port(ppd, krp_senddmahead);
  6173. swhead = ppd->sdma_descq_head;
  6174. swtail = ppd->sdma_descq_tail;
  6175. cnt = ppd->sdma_descq_cnt;
  6176. if (swhead < swtail)
  6177. /* not wrapped */
  6178. sane = (hwhead >= swhead) & (hwhead <= swtail);
  6179. else if (swhead > swtail)
  6180. /* wrapped around */
  6181. sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
  6182. (hwhead <= swtail);
  6183. else
  6184. /* empty */
  6185. sane = (hwhead == swhead);
  6186. if (unlikely(!sane)) {
  6187. if (use_dmahead) {
  6188. /* try one more time, directly from the register */
  6189. use_dmahead = 0;
  6190. goto retry;
  6191. }
  6192. /* proceed as if no progress */
  6193. hwhead = swhead;
  6194. }
  6195. return hwhead;
  6196. }
  6197. static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
  6198. {
  6199. u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
  6200. return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
  6201. (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
  6202. !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
  6203. !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
  6204. }
  6205. /*
  6206. * Compute the amount of delay before sending the next packet if the
  6207. * port's send rate differs from the static rate set for the QP.
  6208. * The delay affects the next packet and the amount of the delay is
  6209. * based on the length of the this packet.
  6210. */
  6211. static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
  6212. u8 srate, u8 vl)
  6213. {
  6214. u8 snd_mult = ppd->delay_mult;
  6215. u8 rcv_mult = ib_rate_to_delay[srate];
  6216. u32 ret;
  6217. ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
  6218. /* Indicate VL15, else set the VL in the control word */
  6219. if (vl == 15)
  6220. ret |= PBC_7322_VL15_SEND_CTRL;
  6221. else
  6222. ret |= vl << PBC_VL_NUM_LSB;
  6223. ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
  6224. return ret;
  6225. }
  6226. /*
  6227. * Enable the per-port VL15 send buffers for use.
  6228. * They follow the rest of the buffers, without a config parameter.
  6229. * This was in initregs, but that is done before the shadow
  6230. * is set up, and this has to be done after the shadow is
  6231. * set up.
  6232. */
  6233. static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
  6234. {
  6235. unsigned vl15bufs;
  6236. vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
  6237. qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
  6238. TXCHK_CHG_TYPE_KERN, NULL);
  6239. }
  6240. static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
  6241. {
  6242. if (rcd->ctxt < NUM_IB_PORTS) {
  6243. if (rcd->dd->num_pports > 1) {
  6244. rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
  6245. rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
  6246. } else {
  6247. rcd->rcvegrcnt = KCTXT0_EGRCNT;
  6248. rcd->rcvegr_tid_base = 0;
  6249. }
  6250. } else {
  6251. rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
  6252. rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
  6253. (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
  6254. }
  6255. }
  6256. #define QTXSLEEPS 5000
  6257. static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
  6258. u32 len, u32 which, struct qib_ctxtdata *rcd)
  6259. {
  6260. int i;
  6261. const int last = start + len - 1;
  6262. const int lastr = last / BITS_PER_LONG;
  6263. u32 sleeps = 0;
  6264. int wait = rcd != NULL;
  6265. unsigned long flags;
  6266. while (wait) {
  6267. unsigned long shadow = 0;
  6268. int cstart, previ = -1;
  6269. /*
  6270. * when flipping from kernel to user, we can't change
  6271. * the checking type if the buffer is allocated to the
  6272. * driver. It's OK the other direction, because it's
  6273. * from close, and we have just disarm'ed all the
  6274. * buffers. All the kernel to kernel changes are also
  6275. * OK.
  6276. */
  6277. for (cstart = start; cstart <= last; cstart++) {
  6278. i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  6279. / BITS_PER_LONG;
  6280. if (i != previ) {
  6281. shadow = (unsigned long)
  6282. le64_to_cpu(dd->pioavailregs_dma[i]);
  6283. previ = i;
  6284. }
  6285. if (test_bit(((2 * cstart) +
  6286. QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  6287. % BITS_PER_LONG, &shadow))
  6288. break;
  6289. }
  6290. if (cstart > last)
  6291. break;
  6292. if (sleeps == QTXSLEEPS)
  6293. break;
  6294. /* make sure we see an updated copy next time around */
  6295. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6296. sleeps++;
  6297. msleep(20);
  6298. }
  6299. switch (which) {
  6300. case TXCHK_CHG_TYPE_DIS1:
  6301. /*
  6302. * disable checking on a range; used by diags; just
  6303. * one buffer, but still written generically
  6304. */
  6305. for (i = start; i <= last; i++)
  6306. clear_bit(i, dd->cspec->sendchkenable);
  6307. break;
  6308. case TXCHK_CHG_TYPE_ENAB1:
  6309. /*
  6310. * (re)enable checking on a range; used by diags; just
  6311. * one buffer, but still written generically; read
  6312. * scratch to be sure buffer actually triggered, not
  6313. * just flushed from processor.
  6314. */
  6315. qib_read_kreg32(dd, kr_scratch);
  6316. for (i = start; i <= last; i++)
  6317. set_bit(i, dd->cspec->sendchkenable);
  6318. break;
  6319. case TXCHK_CHG_TYPE_KERN:
  6320. /* usable by kernel */
  6321. for (i = start; i <= last; i++) {
  6322. set_bit(i, dd->cspec->sendibchk);
  6323. clear_bit(i, dd->cspec->sendgrhchk);
  6324. }
  6325. spin_lock_irqsave(&dd->uctxt_lock, flags);
  6326. /* see if we need to raise avail update threshold */
  6327. for (i = dd->first_user_ctxt;
  6328. dd->cspec->updthresh != dd->cspec->updthresh_dflt
  6329. && i < dd->cfgctxts; i++)
  6330. if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
  6331. ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
  6332. < dd->cspec->updthresh_dflt)
  6333. break;
  6334. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  6335. if (i == dd->cfgctxts) {
  6336. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  6337. dd->cspec->updthresh = dd->cspec->updthresh_dflt;
  6338. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  6339. dd->sendctrl |= (dd->cspec->updthresh &
  6340. SYM_RMASK(SendCtrl, AvailUpdThld)) <<
  6341. SYM_LSB(SendCtrl, AvailUpdThld);
  6342. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6343. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6344. }
  6345. break;
  6346. case TXCHK_CHG_TYPE_USER:
  6347. /* for user process */
  6348. for (i = start; i <= last; i++) {
  6349. clear_bit(i, dd->cspec->sendibchk);
  6350. set_bit(i, dd->cspec->sendgrhchk);
  6351. }
  6352. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  6353. if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
  6354. / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
  6355. dd->cspec->updthresh = (rcd->piocnt /
  6356. rcd->subctxt_cnt) - 1;
  6357. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  6358. dd->sendctrl |= (dd->cspec->updthresh &
  6359. SYM_RMASK(SendCtrl, AvailUpdThld))
  6360. << SYM_LSB(SendCtrl, AvailUpdThld);
  6361. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6362. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  6363. } else
  6364. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  6365. break;
  6366. default:
  6367. break;
  6368. }
  6369. for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
  6370. qib_write_kreg(dd, kr_sendcheckmask + i,
  6371. dd->cspec->sendchkenable[i]);
  6372. for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
  6373. qib_write_kreg(dd, kr_sendgrhcheckmask + i,
  6374. dd->cspec->sendgrhchk[i]);
  6375. qib_write_kreg(dd, kr_sendibpktmask + i,
  6376. dd->cspec->sendibchk[i]);
  6377. }
  6378. /*
  6379. * Be sure whatever we did was seen by the chip and acted upon,
  6380. * before we return. Mostly important for which >= 2.
  6381. */
  6382. qib_read_kreg32(dd, kr_scratch);
  6383. }
  6384. /* useful for trigger analyzers, etc. */
  6385. static void writescratch(struct qib_devdata *dd, u32 val)
  6386. {
  6387. qib_write_kreg(dd, kr_scratch, val);
  6388. }
  6389. /* Dummy for now, use chip regs soon */
  6390. static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
  6391. {
  6392. return -ENXIO;
  6393. }
  6394. /**
  6395. * qib_init_iba7322_funcs - set up the chip-specific function pointers
  6396. * @dev: the pci_dev for qlogic_ib device
  6397. * @ent: pci_device_id struct for this dev
  6398. *
  6399. * Also allocates, inits, and returns the devdata struct for this
  6400. * device instance
  6401. *
  6402. * This is global, and is called directly at init to set up the
  6403. * chip-specific function pointers for later use.
  6404. */
  6405. struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
  6406. const struct pci_device_id *ent)
  6407. {
  6408. struct qib_devdata *dd;
  6409. int ret, i;
  6410. u32 tabsize, actual_cnt = 0;
  6411. dd = qib_alloc_devdata(pdev,
  6412. NUM_IB_PORTS * sizeof(struct qib_pportdata) +
  6413. sizeof(struct qib_chip_specific) +
  6414. NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
  6415. if (IS_ERR(dd))
  6416. goto bail;
  6417. dd->f_bringup_serdes = qib_7322_bringup_serdes;
  6418. dd->f_cleanup = qib_setup_7322_cleanup;
  6419. dd->f_clear_tids = qib_7322_clear_tids;
  6420. dd->f_free_irq = qib_7322_free_irq;
  6421. dd->f_get_base_info = qib_7322_get_base_info;
  6422. dd->f_get_msgheader = qib_7322_get_msgheader;
  6423. dd->f_getsendbuf = qib_7322_getsendbuf;
  6424. dd->f_gpio_mod = gpio_7322_mod;
  6425. dd->f_eeprom_wen = qib_7322_eeprom_wen;
  6426. dd->f_hdrqempty = qib_7322_hdrqempty;
  6427. dd->f_ib_updown = qib_7322_ib_updown;
  6428. dd->f_init_ctxt = qib_7322_init_ctxt;
  6429. dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
  6430. dd->f_intr_fallback = qib_7322_intr_fallback;
  6431. dd->f_late_initreg = qib_late_7322_initreg;
  6432. dd->f_setpbc_control = qib_7322_setpbc_control;
  6433. dd->f_portcntr = qib_portcntr_7322;
  6434. dd->f_put_tid = qib_7322_put_tid;
  6435. dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
  6436. dd->f_rcvctrl = rcvctrl_7322_mod;
  6437. dd->f_read_cntrs = qib_read_7322cntrs;
  6438. dd->f_read_portcntrs = qib_read_7322portcntrs;
  6439. dd->f_reset = qib_do_7322_reset;
  6440. dd->f_init_sdma_regs = init_sdma_7322_regs;
  6441. dd->f_sdma_busy = qib_sdma_7322_busy;
  6442. dd->f_sdma_gethead = qib_sdma_7322_gethead;
  6443. dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
  6444. dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
  6445. dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
  6446. dd->f_sendctrl = sendctrl_7322_mod;
  6447. dd->f_set_armlaunch = qib_set_7322_armlaunch;
  6448. dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
  6449. dd->f_iblink_state = qib_7322_iblink_state;
  6450. dd->f_ibphys_portstate = qib_7322_phys_portstate;
  6451. dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
  6452. dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
  6453. dd->f_set_ib_loopback = qib_7322_set_loopback;
  6454. dd->f_get_ib_table = qib_7322_get_ib_table;
  6455. dd->f_set_ib_table = qib_7322_set_ib_table;
  6456. dd->f_set_intr_state = qib_7322_set_intr_state;
  6457. dd->f_setextled = qib_setup_7322_setextled;
  6458. dd->f_txchk_change = qib_7322_txchk_change;
  6459. dd->f_update_usrhead = qib_update_7322_usrhead;
  6460. dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
  6461. dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
  6462. dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
  6463. dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
  6464. dd->f_sdma_init_early = qib_7322_sdma_init_early;
  6465. dd->f_writescratch = writescratch;
  6466. dd->f_tempsense_rd = qib_7322_tempsense_rd;
  6467. #ifdef CONFIG_INFINIBAND_QIB_DCA
  6468. dd->f_notify_dca = qib_7322_notify_dca;
  6469. #endif
  6470. /*
  6471. * Do remaining PCIe setup and save PCIe values in dd.
  6472. * Any error printing is already done by the init code.
  6473. * On return, we have the chip mapped, but chip registers
  6474. * are not set up until start of qib_init_7322_variables.
  6475. */
  6476. ret = qib_pcie_ddinit(dd, pdev, ent);
  6477. if (ret < 0)
  6478. goto bail_free;
  6479. /* initialize chip-specific variables */
  6480. ret = qib_init_7322_variables(dd);
  6481. if (ret)
  6482. goto bail_cleanup;
  6483. if (qib_mini_init || !dd->num_pports)
  6484. goto bail;
  6485. /*
  6486. * Determine number of vectors we want; depends on port count
  6487. * and number of configured kernel receive queues actually used.
  6488. * Should also depend on whether sdma is enabled or not, but
  6489. * that's such a rare testing case it's not worth worrying about.
  6490. */
  6491. tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
  6492. for (i = 0; i < tabsize; i++)
  6493. if ((i < ARRAY_SIZE(irq_table) &&
  6494. irq_table[i].port <= dd->num_pports) ||
  6495. (i >= ARRAY_SIZE(irq_table) &&
  6496. dd->rcd[i - ARRAY_SIZE(irq_table)]))
  6497. actual_cnt++;
  6498. /* reduce by ctxt's < 2 */
  6499. if (qib_krcvq01_no_msi)
  6500. actual_cnt -= dd->num_pports;
  6501. tabsize = actual_cnt;
  6502. dd->cspec->msix_entries = kzalloc(tabsize *
  6503. sizeof(struct qib_msix_entry), GFP_KERNEL);
  6504. if (!dd->cspec->msix_entries)
  6505. tabsize = 0;
  6506. if (qib_pcie_params(dd, 8, &tabsize))
  6507. qib_dev_err(dd,
  6508. "Failed to setup PCIe or interrupts; continuing anyway\n");
  6509. /* may be less than we wanted, if not enough available */
  6510. dd->cspec->num_msix_entries = tabsize;
  6511. /* setup interrupt handler */
  6512. qib_setup_7322_interrupt(dd, 1);
  6513. /* clear diagctrl register, in case diags were running and crashed */
  6514. qib_write_kreg(dd, kr_hwdiagctrl, 0);
  6515. #ifdef CONFIG_INFINIBAND_QIB_DCA
  6516. if (!dca_add_requester(&pdev->dev)) {
  6517. qib_devinfo(dd->pcidev, "DCA enabled\n");
  6518. dd->flags |= QIB_DCA_ENABLED;
  6519. qib_setup_dca(dd);
  6520. }
  6521. #endif
  6522. goto bail;
  6523. bail_cleanup:
  6524. qib_pcie_ddcleanup(dd);
  6525. bail_free:
  6526. qib_free_devdata(dd);
  6527. dd = ERR_PTR(ret);
  6528. bail:
  6529. return dd;
  6530. }
  6531. /*
  6532. * Set the table entry at the specified index from the table specifed.
  6533. * There are 3 * TXDDS_TABLE_SZ entries in all per port, with the first
  6534. * TXDDS_TABLE_SZ for SDR, the next for DDR, and the last for QDR.
  6535. * 'idx' below addresses the correct entry, while its 4 LSBs select the
  6536. * corresponding entry (one of TXDDS_TABLE_SZ) from the selected table.
  6537. */
  6538. #define DDS_ENT_AMP_LSB 14
  6539. #define DDS_ENT_MAIN_LSB 9
  6540. #define DDS_ENT_POST_LSB 5
  6541. #define DDS_ENT_PRE_XTRA_LSB 3
  6542. #define DDS_ENT_PRE_LSB 0
  6543. /*
  6544. * Set one entry in the TxDDS table for spec'd port
  6545. * ridx picks one of the entries, while tp points
  6546. * to the appropriate table entry.
  6547. */
  6548. static void set_txdds(struct qib_pportdata *ppd, int ridx,
  6549. const struct txdds_ent *tp)
  6550. {
  6551. struct qib_devdata *dd = ppd->dd;
  6552. u32 pack_ent;
  6553. int regidx;
  6554. /* Get correct offset in chip-space, and in source table */
  6555. regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
  6556. /*
  6557. * We do not use qib_write_kreg_port() because it was intended
  6558. * only for registers in the lower "port specific" pages.
  6559. * So do index calculation by hand.
  6560. */
  6561. if (ppd->hw_pidx)
  6562. regidx += (dd->palign / sizeof(u64));
  6563. pack_ent = tp->amp << DDS_ENT_AMP_LSB;
  6564. pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
  6565. pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
  6566. pack_ent |= tp->post << DDS_ENT_POST_LSB;
  6567. qib_write_kreg(dd, regidx, pack_ent);
  6568. /* Prevent back-to-back writes by hitting scratch */
  6569. qib_write_kreg(ppd->dd, kr_scratch, 0);
  6570. }
  6571. static const struct vendor_txdds_ent vendor_txdds[] = {
  6572. { /* Amphenol 1m 30awg NoEq */
  6573. { 0x41, 0x50, 0x48 }, "584470002 ",
  6574. { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
  6575. },
  6576. { /* Amphenol 3m 28awg NoEq */
  6577. { 0x41, 0x50, 0x48 }, "584470004 ",
  6578. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
  6579. },
  6580. { /* Finisar 3m OM2 Optical */
  6581. { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
  6582. { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
  6583. },
  6584. { /* Finisar 30m OM2 Optical */
  6585. { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
  6586. { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
  6587. },
  6588. { /* Finisar Default OM2 Optical */
  6589. { 0x00, 0x90, 0x65 }, NULL,
  6590. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
  6591. },
  6592. { /* Gore 1m 30awg NoEq */
  6593. { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
  6594. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
  6595. },
  6596. { /* Gore 2m 30awg NoEq */
  6597. { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
  6598. { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
  6599. },
  6600. { /* Gore 1m 28awg NoEq */
  6601. { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
  6602. { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
  6603. },
  6604. { /* Gore 3m 28awg NoEq */
  6605. { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
  6606. { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
  6607. },
  6608. { /* Gore 5m 24awg Eq */
  6609. { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
  6610. { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
  6611. },
  6612. { /* Gore 7m 24awg Eq */
  6613. { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
  6614. { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
  6615. },
  6616. { /* Gore 5m 26awg Eq */
  6617. { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
  6618. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
  6619. },
  6620. { /* Gore 7m 26awg Eq */
  6621. { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
  6622. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
  6623. },
  6624. { /* Intersil 12m 24awg Active */
  6625. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
  6626. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
  6627. },
  6628. { /* Intersil 10m 28awg Active */
  6629. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
  6630. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
  6631. },
  6632. { /* Intersil 7m 30awg Active */
  6633. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
  6634. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
  6635. },
  6636. { /* Intersil 5m 32awg Active */
  6637. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
  6638. { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
  6639. },
  6640. { /* Intersil Default Active */
  6641. { 0x00, 0x30, 0xB4 }, NULL,
  6642. { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
  6643. },
  6644. { /* Luxtera 20m Active Optical */
  6645. { 0x00, 0x25, 0x63 }, NULL,
  6646. { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
  6647. },
  6648. { /* Molex 1M Cu loopback */
  6649. { 0x00, 0x09, 0x3A }, "74763-0025 ",
  6650. { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
  6651. },
  6652. { /* Molex 2m 28awg NoEq */
  6653. { 0x00, 0x09, 0x3A }, "74757-2201 ",
  6654. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
  6655. },
  6656. };
  6657. static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
  6658. /* amp, pre, main, post */
  6659. { 2, 2, 15, 6 }, /* Loopback */
  6660. { 0, 0, 0, 1 }, /* 2 dB */
  6661. { 0, 0, 0, 2 }, /* 3 dB */
  6662. { 0, 0, 0, 3 }, /* 4 dB */
  6663. { 0, 0, 0, 4 }, /* 5 dB */
  6664. { 0, 0, 0, 5 }, /* 6 dB */
  6665. { 0, 0, 0, 6 }, /* 7 dB */
  6666. { 0, 0, 0, 7 }, /* 8 dB */
  6667. { 0, 0, 0, 8 }, /* 9 dB */
  6668. { 0, 0, 0, 9 }, /* 10 dB */
  6669. { 0, 0, 0, 10 }, /* 11 dB */
  6670. { 0, 0, 0, 11 }, /* 12 dB */
  6671. { 0, 0, 0, 12 }, /* 13 dB */
  6672. { 0, 0, 0, 13 }, /* 14 dB */
  6673. { 0, 0, 0, 14 }, /* 15 dB */
  6674. { 0, 0, 0, 15 }, /* 16 dB */
  6675. };
  6676. static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
  6677. /* amp, pre, main, post */
  6678. { 2, 2, 15, 6 }, /* Loopback */
  6679. { 0, 0, 0, 8 }, /* 2 dB */
  6680. { 0, 0, 0, 8 }, /* 3 dB */
  6681. { 0, 0, 0, 9 }, /* 4 dB */
  6682. { 0, 0, 0, 9 }, /* 5 dB */
  6683. { 0, 0, 0, 10 }, /* 6 dB */
  6684. { 0, 0, 0, 10 }, /* 7 dB */
  6685. { 0, 0, 0, 11 }, /* 8 dB */
  6686. { 0, 0, 0, 11 }, /* 9 dB */
  6687. { 0, 0, 0, 12 }, /* 10 dB */
  6688. { 0, 0, 0, 12 }, /* 11 dB */
  6689. { 0, 0, 0, 13 }, /* 12 dB */
  6690. { 0, 0, 0, 13 }, /* 13 dB */
  6691. { 0, 0, 0, 14 }, /* 14 dB */
  6692. { 0, 0, 0, 14 }, /* 15 dB */
  6693. { 0, 0, 0, 15 }, /* 16 dB */
  6694. };
  6695. static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
  6696. /* amp, pre, main, post */
  6697. { 2, 2, 15, 6 }, /* Loopback */
  6698. { 0, 1, 0, 7 }, /* 2 dB (also QMH7342) */
  6699. { 0, 1, 0, 9 }, /* 3 dB (also QMH7342) */
  6700. { 0, 1, 0, 11 }, /* 4 dB */
  6701. { 0, 1, 0, 13 }, /* 5 dB */
  6702. { 0, 1, 0, 15 }, /* 6 dB */
  6703. { 0, 1, 3, 15 }, /* 7 dB */
  6704. { 0, 1, 7, 15 }, /* 8 dB */
  6705. { 0, 1, 7, 15 }, /* 9 dB */
  6706. { 0, 1, 8, 15 }, /* 10 dB */
  6707. { 0, 1, 9, 15 }, /* 11 dB */
  6708. { 0, 1, 10, 15 }, /* 12 dB */
  6709. { 0, 2, 6, 15 }, /* 13 dB */
  6710. { 0, 2, 7, 15 }, /* 14 dB */
  6711. { 0, 2, 8, 15 }, /* 15 dB */
  6712. { 0, 2, 9, 15 }, /* 16 dB */
  6713. };
  6714. /*
  6715. * extra entries for use with txselect, for indices >= TXDDS_TABLE_SZ.
  6716. * These are mostly used for mez cards going through connectors
  6717. * and backplane traces, but can be used to add other "unusual"
  6718. * table values as well.
  6719. */
  6720. static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
  6721. /* amp, pre, main, post */
  6722. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6723. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6724. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6725. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6726. { 0, 0, 0, 3 }, /* QMH7342 backplane settings */
  6727. { 0, 0, 0, 4 }, /* QMH7342 backplane settings */
  6728. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6729. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6730. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6731. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6732. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6733. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6734. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6735. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6736. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6737. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6738. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6739. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6740. };
  6741. static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
  6742. /* amp, pre, main, post */
  6743. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6744. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6745. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6746. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6747. { 0, 0, 0, 9 }, /* QMH7342 backplane settings */
  6748. { 0, 0, 0, 10 }, /* QMH7342 backplane settings */
  6749. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6750. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6751. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6752. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6753. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6754. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6755. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6756. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6757. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6758. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6759. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6760. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6761. };
  6762. static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
  6763. /* amp, pre, main, post */
  6764. { 0, 1, 0, 4 }, /* QMH7342 backplane settings */
  6765. { 0, 1, 0, 5 }, /* QMH7342 backplane settings */
  6766. { 0, 1, 0, 6 }, /* QMH7342 backplane settings */
  6767. { 0, 1, 0, 8 }, /* QMH7342 backplane settings */
  6768. { 0, 1, 0, 10 }, /* QMH7342 backplane settings */
  6769. { 0, 1, 0, 12 }, /* QMH7342 backplane settings */
  6770. { 0, 1, 4, 15 }, /* QME7342 backplane settings 1.0 */
  6771. { 0, 1, 3, 15 }, /* QME7342 backplane settings 1.0 */
  6772. { 0, 1, 0, 12 }, /* QME7342 backplane settings 1.0 */
  6773. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.0 */
  6774. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.0 */
  6775. { 0, 1, 0, 14 }, /* QME7342 backplane settings 1.0 */
  6776. { 0, 1, 2, 15 }, /* QME7342 backplane settings 1.0 */
  6777. { 0, 1, 0, 11 }, /* QME7342 backplane settings 1.1 */
  6778. { 0, 1, 0, 7 }, /* QME7342 backplane settings 1.1 */
  6779. { 0, 1, 0, 9 }, /* QME7342 backplane settings 1.1 */
  6780. { 0, 1, 0, 6 }, /* QME7342 backplane settings 1.1 */
  6781. { 0, 1, 0, 8 }, /* QME7342 backplane settings 1.1 */
  6782. };
  6783. static const struct txdds_ent txdds_extra_mfg[TXDDS_MFG_SZ] = {
  6784. /* amp, pre, main, post */
  6785. { 0, 0, 0, 0 }, /* QME7342 mfg settings */
  6786. { 0, 0, 0, 6 }, /* QME7342 P2 mfg settings */
  6787. };
  6788. static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
  6789. unsigned atten)
  6790. {
  6791. /*
  6792. * The attenuation table starts at 2dB for entry 1,
  6793. * with entry 0 being the loopback entry.
  6794. */
  6795. if (atten <= 2)
  6796. atten = 1;
  6797. else if (atten > TXDDS_TABLE_SZ)
  6798. atten = TXDDS_TABLE_SZ - 1;
  6799. else
  6800. atten--;
  6801. return txdds + atten;
  6802. }
  6803. /*
  6804. * if override is set, the module parameter txselect has a value
  6805. * for this specific port, so use it, rather than our normal mechanism.
  6806. */
  6807. static void find_best_ent(struct qib_pportdata *ppd,
  6808. const struct txdds_ent **sdr_dds,
  6809. const struct txdds_ent **ddr_dds,
  6810. const struct txdds_ent **qdr_dds, int override)
  6811. {
  6812. struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
  6813. int idx;
  6814. /* Search table of known cables */
  6815. for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
  6816. const struct vendor_txdds_ent *v = vendor_txdds + idx;
  6817. if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
  6818. (!v->partnum ||
  6819. !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
  6820. *sdr_dds = &v->sdr;
  6821. *ddr_dds = &v->ddr;
  6822. *qdr_dds = &v->qdr;
  6823. return;
  6824. }
  6825. }
  6826. /* Active cables don't have attenuation so we only set SERDES
  6827. * settings to account for the attenuation of the board traces. */
  6828. if (!override && QSFP_IS_ACTIVE(qd->tech)) {
  6829. *sdr_dds = txdds_sdr + ppd->dd->board_atten;
  6830. *ddr_dds = txdds_ddr + ppd->dd->board_atten;
  6831. *qdr_dds = txdds_qdr + ppd->dd->board_atten;
  6832. return;
  6833. }
  6834. if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
  6835. qd->atten[1])) {
  6836. *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
  6837. *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
  6838. *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
  6839. return;
  6840. } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
  6841. /*
  6842. * If we have no (or incomplete) data from the cable
  6843. * EEPROM, or no QSFP, or override is set, use the
  6844. * module parameter value to index into the attentuation
  6845. * table.
  6846. */
  6847. idx = ppd->cpspec->no_eep;
  6848. *sdr_dds = &txdds_sdr[idx];
  6849. *ddr_dds = &txdds_ddr[idx];
  6850. *qdr_dds = &txdds_qdr[idx];
  6851. } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
  6852. /* similar to above, but index into the "extra" table. */
  6853. idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
  6854. *sdr_dds = &txdds_extra_sdr[idx];
  6855. *ddr_dds = &txdds_extra_ddr[idx];
  6856. *qdr_dds = &txdds_extra_qdr[idx];
  6857. } else if ((IS_QME(ppd->dd) || IS_QMH(ppd->dd)) &&
  6858. ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  6859. TXDDS_MFG_SZ)) {
  6860. idx = ppd->cpspec->no_eep - (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
  6861. pr_info("IB%u:%u use idx %u into txdds_mfg\n",
  6862. ppd->dd->unit, ppd->port, idx);
  6863. *sdr_dds = &txdds_extra_mfg[idx];
  6864. *ddr_dds = &txdds_extra_mfg[idx];
  6865. *qdr_dds = &txdds_extra_mfg[idx];
  6866. } else {
  6867. /* this shouldn't happen, it's range checked */
  6868. *sdr_dds = txdds_sdr + qib_long_atten;
  6869. *ddr_dds = txdds_ddr + qib_long_atten;
  6870. *qdr_dds = txdds_qdr + qib_long_atten;
  6871. }
  6872. }
  6873. static void init_txdds_table(struct qib_pportdata *ppd, int override)
  6874. {
  6875. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  6876. struct txdds_ent *dds;
  6877. int idx;
  6878. int single_ent = 0;
  6879. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
  6880. /* for mez cards or override, use the selected value for all entries */
  6881. if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
  6882. single_ent = 1;
  6883. /* Fill in the first entry with the best entry found. */
  6884. set_txdds(ppd, 0, sdr_dds);
  6885. set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
  6886. set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
  6887. if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  6888. QIBL_LINKACTIVE)) {
  6889. dds = (struct txdds_ent *)(ppd->link_speed_active ==
  6890. QIB_IB_QDR ? qdr_dds :
  6891. (ppd->link_speed_active ==
  6892. QIB_IB_DDR ? ddr_dds : sdr_dds));
  6893. write_tx_serdes_param(ppd, dds);
  6894. }
  6895. /* Fill in the remaining entries with the default table values. */
  6896. for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
  6897. set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
  6898. set_txdds(ppd, idx + TXDDS_TABLE_SZ,
  6899. single_ent ? ddr_dds : txdds_ddr + idx);
  6900. set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
  6901. single_ent ? qdr_dds : txdds_qdr + idx);
  6902. }
  6903. }
  6904. #define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
  6905. #define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
  6906. #define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
  6907. #define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
  6908. #define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
  6909. #define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
  6910. #define AHB_TRANS_TRIES 10
  6911. /*
  6912. * The chan argument is 0=chan0, 1=chan1, 2=pll, 3=chan2, 4=chan4,
  6913. * 5=subsystem which is why most calls have "chan + chan >> 1"
  6914. * for the channel argument.
  6915. */
  6916. static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
  6917. u32 data, u32 mask)
  6918. {
  6919. u32 rd_data, wr_data, sz_mask;
  6920. u64 trans, acc, prev_acc;
  6921. u32 ret = 0xBAD0BAD;
  6922. int tries;
  6923. prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
  6924. /* From this point on, make sure we return access */
  6925. acc = (quad << 1) | 1;
  6926. qib_write_kreg(dd, KR_AHB_ACC, acc);
  6927. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  6928. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6929. if (trans & AHB_TRANS_RDY)
  6930. break;
  6931. }
  6932. if (tries >= AHB_TRANS_TRIES) {
  6933. qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
  6934. goto bail;
  6935. }
  6936. /* If mask is not all 1s, we need to read, but different SerDes
  6937. * entities have different sizes
  6938. */
  6939. sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
  6940. wr_data = data & mask & sz_mask;
  6941. if ((~mask & sz_mask) != 0) {
  6942. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  6943. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  6944. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  6945. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6946. if (trans & AHB_TRANS_RDY)
  6947. break;
  6948. }
  6949. if (tries >= AHB_TRANS_TRIES) {
  6950. qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
  6951. AHB_TRANS_TRIES);
  6952. goto bail;
  6953. }
  6954. /* Re-read in case host split reads and read data first */
  6955. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6956. rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
  6957. wr_data |= (rd_data & ~mask & sz_mask);
  6958. }
  6959. /* If mask is not zero, we need to write. */
  6960. if (mask & sz_mask) {
  6961. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  6962. trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
  6963. trans |= AHB_WR;
  6964. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  6965. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  6966. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6967. if (trans & AHB_TRANS_RDY)
  6968. break;
  6969. }
  6970. if (tries >= AHB_TRANS_TRIES) {
  6971. qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
  6972. AHB_TRANS_TRIES);
  6973. goto bail;
  6974. }
  6975. }
  6976. ret = wr_data;
  6977. bail:
  6978. qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
  6979. return ret;
  6980. }
  6981. static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
  6982. unsigned mask)
  6983. {
  6984. struct qib_devdata *dd = ppd->dd;
  6985. int chan;
  6986. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  6987. ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
  6988. data, mask);
  6989. ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
  6990. 0, 0);
  6991. }
  6992. }
  6993. static void serdes_7322_los_enable(struct qib_pportdata *ppd, int enable)
  6994. {
  6995. u64 data = qib_read_kreg_port(ppd, krp_serdesctrl);
  6996. u8 state = SYM_FIELD(data, IBSerdesCtrl_0, RXLOSEN);
  6997. if (enable && !state) {
  6998. pr_info("IB%u:%u Turning LOS on\n",
  6999. ppd->dd->unit, ppd->port);
  7000. data |= SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  7001. } else if (!enable && state) {
  7002. pr_info("IB%u:%u Turning LOS off\n",
  7003. ppd->dd->unit, ppd->port);
  7004. data &= ~SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  7005. }
  7006. qib_write_kreg_port(ppd, krp_serdesctrl, data);
  7007. }
  7008. static int serdes_7322_init(struct qib_pportdata *ppd)
  7009. {
  7010. int ret = 0;
  7011. if (ppd->dd->cspec->r1)
  7012. ret = serdes_7322_init_old(ppd);
  7013. else
  7014. ret = serdes_7322_init_new(ppd);
  7015. return ret;
  7016. }
  7017. static int serdes_7322_init_old(struct qib_pportdata *ppd)
  7018. {
  7019. u32 le_val;
  7020. /*
  7021. * Initialize the Tx DDS tables. Also done every QSFP event,
  7022. * for adapters with QSFP
  7023. */
  7024. init_txdds_table(ppd, 0);
  7025. /* ensure no tx overrides from earlier driver loads */
  7026. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  7027. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7028. reset_tx_deemphasis_override));
  7029. /* Patch some SerDes defaults to "Better for IB" */
  7030. /* Timing Loop Bandwidth: cdr_timing[11:9] = 0 */
  7031. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  7032. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  7033. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  7034. /* Enable LE2: rxle2en_r2a addr 13 bit [6] = 1 */
  7035. ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
  7036. /* May be overridden in qsfp_7322_event */
  7037. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  7038. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  7039. /* enable LE1 adaptation for all but QME, which is disabled */
  7040. le_val = IS_QME(ppd->dd) ? 0 : 1;
  7041. ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
  7042. /* Clear cmode-override, may be set from older driver */
  7043. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  7044. /* Timing Recovery: rxtapsel addr 5 bits [9:8] = 0 */
  7045. ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
  7046. /* setup LoS params; these are subsystem, so chan == 5 */
  7047. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  7048. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  7049. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  7050. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  7051. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  7052. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  7053. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  7054. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  7055. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  7056. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  7057. /* LoS filter select enabled */
  7058. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  7059. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  7060. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  7061. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  7062. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  7063. serdes_7322_los_enable(ppd, 1);
  7064. /* rxbistena; set 0 to avoid effects of it switch later */
  7065. ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
  7066. /* Configure 4 DFE taps, and only they adapt */
  7067. ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
  7068. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  7069. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  7070. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  7071. /*
  7072. * Set receive adaptation mode. SDR and DDR adaptation are
  7073. * always on, and QDR is initially enabled; later disabled.
  7074. */
  7075. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  7076. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  7077. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  7078. ppd->dd->cspec->r1 ?
  7079. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  7080. ppd->cpspec->qdr_dfe_on = 1;
  7081. /* FLoop LOS gate: PPM filter enabled */
  7082. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  7083. /* rx offset center enabled */
  7084. ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
  7085. if (!ppd->dd->cspec->r1) {
  7086. ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
  7087. ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
  7088. }
  7089. /* Set the frequency loop bandwidth to 15 */
  7090. ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
  7091. return 0;
  7092. }
  7093. static int serdes_7322_init_new(struct qib_pportdata *ppd)
  7094. {
  7095. unsigned long tend;
  7096. u32 le_val, rxcaldone;
  7097. int chan, chan_done = (1 << SERDES_CHANS) - 1;
  7098. /* Clear cmode-override, may be set from older driver */
  7099. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  7100. /* ensure no tx overrides from earlier driver loads */
  7101. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  7102. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7103. reset_tx_deemphasis_override));
  7104. /* START OF LSI SUGGESTED SERDES BRINGUP */
  7105. /* Reset - Calibration Setup */
  7106. /* Stop DFE adaptaion */
  7107. ibsd_wr_allchans(ppd, 1, 0, BMASK(9, 1));
  7108. /* Disable LE1 */
  7109. ibsd_wr_allchans(ppd, 13, 0, BMASK(5, 5));
  7110. /* Disable autoadapt for LE1 */
  7111. ibsd_wr_allchans(ppd, 1, 0, BMASK(15, 15));
  7112. /* Disable LE2 */
  7113. ibsd_wr_allchans(ppd, 13, 0, BMASK(6, 6));
  7114. /* Disable VGA */
  7115. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  7116. /* Disable AFE Offset Cancel */
  7117. ibsd_wr_allchans(ppd, 12, 0, BMASK(12, 12));
  7118. /* Disable Timing Loop */
  7119. ibsd_wr_allchans(ppd, 2, 0, BMASK(3, 3));
  7120. /* Disable Frequency Loop */
  7121. ibsd_wr_allchans(ppd, 2, 0, BMASK(4, 4));
  7122. /* Disable Baseline Wander Correction */
  7123. ibsd_wr_allchans(ppd, 13, 0, BMASK(13, 13));
  7124. /* Disable RX Calibration */
  7125. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  7126. /* Disable RX Offset Calibration */
  7127. ibsd_wr_allchans(ppd, 12, 0, BMASK(4, 4));
  7128. /* Select BB CDR */
  7129. ibsd_wr_allchans(ppd, 2, (1 << 15), BMASK(15, 15));
  7130. /* CDR Step Size */
  7131. ibsd_wr_allchans(ppd, 5, 0, BMASK(9, 8));
  7132. /* Enable phase Calibration */
  7133. ibsd_wr_allchans(ppd, 12, (1 << 5), BMASK(5, 5));
  7134. /* DFE Bandwidth [2:14-12] */
  7135. ibsd_wr_allchans(ppd, 2, (4 << 12), BMASK(14, 12));
  7136. /* DFE Config (4 taps only) */
  7137. ibsd_wr_allchans(ppd, 16, 0, BMASK(1, 0));
  7138. /* Gain Loop Bandwidth */
  7139. if (!ppd->dd->cspec->r1) {
  7140. ibsd_wr_allchans(ppd, 12, 1 << 12, BMASK(12, 12));
  7141. ibsd_wr_allchans(ppd, 12, 2 << 8, BMASK(11, 8));
  7142. } else {
  7143. ibsd_wr_allchans(ppd, 19, (3 << 11), BMASK(13, 11));
  7144. }
  7145. /* Baseline Wander Correction Gain [13:4-0] (leave as default) */
  7146. /* Baseline Wander Correction Gain [3:7-5] (leave as default) */
  7147. /* Data Rate Select [5:7-6] (leave as default) */
  7148. /* RX Parallel Word Width [3:10-8] (leave as default) */
  7149. /* RX REST */
  7150. /* Single- or Multi-channel reset */
  7151. /* RX Analog reset */
  7152. /* RX Digital reset */
  7153. ibsd_wr_allchans(ppd, 0, 0, BMASK(15, 13));
  7154. msleep(20);
  7155. /* RX Analog reset */
  7156. ibsd_wr_allchans(ppd, 0, (1 << 14), BMASK(14, 14));
  7157. msleep(20);
  7158. /* RX Digital reset */
  7159. ibsd_wr_allchans(ppd, 0, (1 << 13), BMASK(13, 13));
  7160. msleep(20);
  7161. /* setup LoS params; these are subsystem, so chan == 5 */
  7162. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  7163. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  7164. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  7165. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  7166. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  7167. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  7168. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  7169. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  7170. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  7171. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  7172. /* LoS filter select enabled */
  7173. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  7174. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  7175. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  7176. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  7177. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  7178. /* Turn on LOS on initial SERDES init */
  7179. serdes_7322_los_enable(ppd, 1);
  7180. /* FLoop LOS gate: PPM filter enabled */
  7181. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  7182. /* RX LATCH CALIBRATION */
  7183. /* Enable Eyefinder Phase Calibration latch */
  7184. ibsd_wr_allchans(ppd, 15, 1, BMASK(0, 0));
  7185. /* Enable RX Offset Calibration latch */
  7186. ibsd_wr_allchans(ppd, 12, (1 << 4), BMASK(4, 4));
  7187. msleep(20);
  7188. /* Start Calibration */
  7189. ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10));
  7190. tend = jiffies + msecs_to_jiffies(500);
  7191. while (chan_done && !time_is_before_jiffies(tend)) {
  7192. msleep(20);
  7193. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7194. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  7195. (chan + (chan >> 1)),
  7196. 25, 0, 0);
  7197. if ((~rxcaldone & (u32)BMASK(9, 9)) == 0 &&
  7198. (~chan_done & (1 << chan)) == 0)
  7199. chan_done &= ~(1 << chan);
  7200. }
  7201. }
  7202. if (chan_done) {
  7203. pr_info("Serdes %d calibration not done after .5 sec: 0x%x\n",
  7204. IBSD(ppd->hw_pidx), chan_done);
  7205. } else {
  7206. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  7207. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  7208. (chan + (chan >> 1)),
  7209. 25, 0, 0);
  7210. if ((~rxcaldone & (u32)BMASK(10, 10)) == 0)
  7211. pr_info("Serdes %d chan %d calibration failed\n",
  7212. IBSD(ppd->hw_pidx), chan);
  7213. }
  7214. }
  7215. /* Turn off Calibration */
  7216. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  7217. msleep(20);
  7218. /* BRING RX UP */
  7219. /* Set LE2 value (May be overridden in qsfp_7322_event) */
  7220. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  7221. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  7222. /* Set LE2 Loop bandwidth */
  7223. ibsd_wr_allchans(ppd, 3, (7 << 5), BMASK(7, 5));
  7224. /* Enable LE2 */
  7225. ibsd_wr_allchans(ppd, 13, (1 << 6), BMASK(6, 6));
  7226. msleep(20);
  7227. /* Enable H0 only */
  7228. ibsd_wr_allchans(ppd, 1, 1, BMASK(9, 1));
  7229. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  7230. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  7231. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  7232. /* Enable VGA */
  7233. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  7234. msleep(20);
  7235. /* Set Frequency Loop Bandwidth */
  7236. ibsd_wr_allchans(ppd, 2, (15 << 5), BMASK(8, 5));
  7237. /* Enable Frequency Loop */
  7238. ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
  7239. /* Set Timing Loop Bandwidth */
  7240. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  7241. /* Enable Timing Loop */
  7242. ibsd_wr_allchans(ppd, 2, (1 << 3), BMASK(3, 3));
  7243. msleep(50);
  7244. /* Enable DFE
  7245. * Set receive adaptation mode. SDR and DDR adaptation are
  7246. * always on, and QDR is initially enabled; later disabled.
  7247. */
  7248. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  7249. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  7250. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  7251. ppd->dd->cspec->r1 ?
  7252. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  7253. ppd->cpspec->qdr_dfe_on = 1;
  7254. /* Disable LE1 */
  7255. ibsd_wr_allchans(ppd, 13, (0 << 5), (1 << 5));
  7256. /* Disable auto adapt for LE1 */
  7257. ibsd_wr_allchans(ppd, 1, (0 << 15), BMASK(15, 15));
  7258. msleep(20);
  7259. /* Enable AFE Offset Cancel */
  7260. ibsd_wr_allchans(ppd, 12, (1 << 12), BMASK(12, 12));
  7261. /* Enable Baseline Wander Correction */
  7262. ibsd_wr_allchans(ppd, 12, (1 << 13), BMASK(13, 13));
  7263. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  7264. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  7265. /* VGA output common mode */
  7266. ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
  7267. /*
  7268. * Initialize the Tx DDS tables. Also done every QSFP event,
  7269. * for adapters with QSFP
  7270. */
  7271. init_txdds_table(ppd, 0);
  7272. return 0;
  7273. }
  7274. /* start adjust QMH serdes parameters */
  7275. static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
  7276. {
  7277. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7278. 9, code << 9, 0x3f << 9);
  7279. }
  7280. static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
  7281. int enable, u32 tapenable)
  7282. {
  7283. if (enable)
  7284. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7285. 1, 3 << 10, 0x1f << 10);
  7286. else
  7287. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7288. 1, 0, 0x1f << 10);
  7289. }
  7290. /* Set clock to 1, 0, 1, 0 */
  7291. static void clock_man(struct qib_pportdata *ppd, int chan)
  7292. {
  7293. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7294. 4, 0x4000, 0x4000);
  7295. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7296. 4, 0, 0x4000);
  7297. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7298. 4, 0x4000, 0x4000);
  7299. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  7300. 4, 0, 0x4000);
  7301. }
  7302. /*
  7303. * write the current Tx serdes pre,post,main,amp settings into the serdes.
  7304. * The caller must pass the settings appropriate for the current speed,
  7305. * or not care if they are correct for the current speed.
  7306. */
  7307. static void write_tx_serdes_param(struct qib_pportdata *ppd,
  7308. struct txdds_ent *txdds)
  7309. {
  7310. u64 deemph;
  7311. deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
  7312. /* field names for amp, main, post, pre, respectively */
  7313. deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
  7314. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
  7315. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
  7316. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
  7317. deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7318. tx_override_deemphasis_select);
  7319. deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7320. txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7321. txampcntl_d2a);
  7322. deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7323. txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7324. txc0_ena);
  7325. deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7326. txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7327. txcp1_ena);
  7328. deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7329. txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  7330. txcn1_ena);
  7331. qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
  7332. }
  7333. /*
  7334. * Set the parameters for mez cards on link bounce, so they are
  7335. * always exactly what was requested. Similar logic to init_txdds
  7336. * but does just the serdes.
  7337. */
  7338. static void adj_tx_serdes(struct qib_pportdata *ppd)
  7339. {
  7340. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  7341. struct txdds_ent *dds;
  7342. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
  7343. dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
  7344. qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
  7345. ddr_dds : sdr_dds));
  7346. write_tx_serdes_param(ppd, dds);
  7347. }
  7348. /* set QDR forced value for H1, if needed */
  7349. static void force_h1(struct qib_pportdata *ppd)
  7350. {
  7351. int chan;
  7352. ppd->cpspec->qdr_reforce = 0;
  7353. if (!ppd->dd->cspec->r1)
  7354. return;
  7355. for (chan = 0; chan < SERDES_CHANS; chan++) {
  7356. set_man_mode_h1(ppd, chan, 1, 0);
  7357. set_man_code(ppd, chan, ppd->cpspec->h1_val);
  7358. clock_man(ppd, chan);
  7359. set_man_mode_h1(ppd, chan, 0, 0);
  7360. }
  7361. }
  7362. #define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
  7363. #define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
  7364. #define R_OPCODE_LSB 3
  7365. #define R_OP_NOP 0
  7366. #define R_OP_SHIFT 2
  7367. #define R_OP_UPDATE 3
  7368. #define R_TDI_LSB 2
  7369. #define R_TDO_LSB 1
  7370. #define R_RDY 1
  7371. static int qib_r_grab(struct qib_devdata *dd)
  7372. {
  7373. u64 val = SJA_EN;
  7374. qib_write_kreg(dd, kr_r_access, val);
  7375. qib_read_kreg32(dd, kr_scratch);
  7376. return 0;
  7377. }
  7378. /* qib_r_wait_for_rdy() not only waits for the ready bit, it
  7379. * returns the current state of R_TDO
  7380. */
  7381. static int qib_r_wait_for_rdy(struct qib_devdata *dd)
  7382. {
  7383. u64 val;
  7384. int timeout;
  7385. for (timeout = 0; timeout < 100 ; ++timeout) {
  7386. val = qib_read_kreg32(dd, kr_r_access);
  7387. if (val & R_RDY)
  7388. return (val >> R_TDO_LSB) & 1;
  7389. }
  7390. return -1;
  7391. }
  7392. static int qib_r_shift(struct qib_devdata *dd, int bisten,
  7393. int len, u8 *inp, u8 *outp)
  7394. {
  7395. u64 valbase, val;
  7396. int ret, pos;
  7397. valbase = SJA_EN | (bisten << BISTEN_LSB) |
  7398. (R_OP_SHIFT << R_OPCODE_LSB);
  7399. ret = qib_r_wait_for_rdy(dd);
  7400. if (ret < 0)
  7401. goto bail;
  7402. for (pos = 0; pos < len; ++pos) {
  7403. val = valbase;
  7404. if (outp) {
  7405. outp[pos >> 3] &= ~(1 << (pos & 7));
  7406. outp[pos >> 3] |= (ret << (pos & 7));
  7407. }
  7408. if (inp) {
  7409. int tdi = inp[pos >> 3] >> (pos & 7);
  7410. val |= ((tdi & 1) << R_TDI_LSB);
  7411. }
  7412. qib_write_kreg(dd, kr_r_access, val);
  7413. qib_read_kreg32(dd, kr_scratch);
  7414. ret = qib_r_wait_for_rdy(dd);
  7415. if (ret < 0)
  7416. break;
  7417. }
  7418. /* Restore to NOP between operations. */
  7419. val = SJA_EN | (bisten << BISTEN_LSB);
  7420. qib_write_kreg(dd, kr_r_access, val);
  7421. qib_read_kreg32(dd, kr_scratch);
  7422. ret = qib_r_wait_for_rdy(dd);
  7423. if (ret >= 0)
  7424. ret = pos;
  7425. bail:
  7426. return ret;
  7427. }
  7428. static int qib_r_update(struct qib_devdata *dd, int bisten)
  7429. {
  7430. u64 val;
  7431. int ret;
  7432. val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
  7433. ret = qib_r_wait_for_rdy(dd);
  7434. if (ret >= 0) {
  7435. qib_write_kreg(dd, kr_r_access, val);
  7436. qib_read_kreg32(dd, kr_scratch);
  7437. }
  7438. return ret;
  7439. }
  7440. #define BISTEN_PORT_SEL 15
  7441. #define LEN_PORT_SEL 625
  7442. #define BISTEN_AT 17
  7443. #define LEN_AT 156
  7444. #define BISTEN_ETM 16
  7445. #define LEN_ETM 632
  7446. #define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
  7447. /* these are common for all IB port use cases. */
  7448. static u8 reset_at[BIT2BYTE(LEN_AT)] = {
  7449. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7450. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7451. };
  7452. static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
  7453. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7454. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7455. 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
  7456. 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
  7457. 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
  7458. 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
  7459. 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7460. 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  7461. };
  7462. static u8 at[BIT2BYTE(LEN_AT)] = {
  7463. 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
  7464. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7465. };
  7466. /* used for IB1 or IB2, only one in use */
  7467. static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
  7468. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7469. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7470. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7471. 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
  7472. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7473. 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
  7474. 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
  7475. 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
  7476. };
  7477. /* used when both IB1 and IB2 are in use */
  7478. static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
  7479. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7480. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
  7481. 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7482. 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
  7483. 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  7484. 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
  7485. 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
  7486. 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
  7487. };
  7488. /* used when only IB1 is in use */
  7489. static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
  7490. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7491. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7492. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7493. 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7494. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7495. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7496. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7497. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7498. };
  7499. /* used when only IB2 is in use */
  7500. static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
  7501. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
  7502. 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
  7503. 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7504. 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7505. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
  7506. 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7507. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7508. 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  7509. };
  7510. /* used when both IB1 and IB2 are in use */
  7511. static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
  7512. 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7513. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7514. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7515. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7516. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7517. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
  7518. 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7519. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7520. };
  7521. /*
  7522. * Do setup to properly handle IB link recovery; if port is zero, we
  7523. * are initializing to cover both ports; otherwise we are initializing
  7524. * to cover a single port card, or the port has reached INIT and we may
  7525. * need to switch coverage types.
  7526. */
  7527. static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
  7528. {
  7529. u8 *portsel, *etm;
  7530. struct qib_devdata *dd = ppd->dd;
  7531. if (!ppd->dd->cspec->r1)
  7532. return;
  7533. if (!both) {
  7534. dd->cspec->recovery_ports_initted++;
  7535. ppd->cpspec->recovery_init = 1;
  7536. }
  7537. if (!both && dd->cspec->recovery_ports_initted == 1) {
  7538. portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
  7539. etm = atetm_1port;
  7540. } else {
  7541. portsel = portsel_2port;
  7542. etm = atetm_2port;
  7543. }
  7544. if (qib_r_grab(dd) < 0 ||
  7545. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
  7546. qib_r_update(dd, BISTEN_ETM) < 0 ||
  7547. qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
  7548. qib_r_update(dd, BISTEN_AT) < 0 ||
  7549. qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
  7550. portsel, NULL) < 0 ||
  7551. qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
  7552. qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
  7553. qib_r_update(dd, BISTEN_AT) < 0 ||
  7554. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
  7555. qib_r_update(dd, BISTEN_ETM) < 0)
  7556. qib_dev_err(dd, "Failed IB link recovery setup\n");
  7557. }
  7558. static void check_7322_rxe_status(struct qib_pportdata *ppd)
  7559. {
  7560. struct qib_devdata *dd = ppd->dd;
  7561. u64 fmask;
  7562. if (dd->cspec->recovery_ports_initted != 1)
  7563. return; /* rest doesn't apply to dualport */
  7564. qib_write_kreg(dd, kr_control, dd->control |
  7565. SYM_MASK(Control, FreezeMode));
  7566. (void)qib_read_kreg64(dd, kr_scratch);
  7567. udelay(3); /* ibcreset asserted 400ns, be sure that's over */
  7568. fmask = qib_read_kreg64(dd, kr_act_fmask);
  7569. if (!fmask) {
  7570. /*
  7571. * require a powercycle before we'll work again, and make
  7572. * sure we get no more interrupts, and don't turn off
  7573. * freeze.
  7574. */
  7575. ppd->dd->cspec->stay_in_freeze = 1;
  7576. qib_7322_set_intr_state(ppd->dd, 0);
  7577. qib_write_kreg(dd, kr_fmask, 0ULL);
  7578. qib_dev_err(dd, "HCA unusable until powercycled\n");
  7579. return; /* eventually reset */
  7580. }
  7581. qib_write_kreg(ppd->dd, kr_hwerrclear,
  7582. SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
  7583. /* don't do the full clear_freeze(), not needed for this */
  7584. qib_write_kreg(dd, kr_control, dd->control);
  7585. qib_read_kreg32(dd, kr_scratch);
  7586. /* take IBC out of reset */
  7587. if (ppd->link_speed_supported) {
  7588. ppd->cpspec->ibcctrl_a &=
  7589. ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  7590. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  7591. ppd->cpspec->ibcctrl_a);
  7592. qib_read_kreg32(dd, kr_scratch);
  7593. if (ppd->lflags & QIBL_IB_LINK_DISABLED)
  7594. qib_set_ib_7322_lstate(ppd, 0,
  7595. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  7596. }
  7597. }