qib_iba7322.c 242 KB

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