lpfc_init.c 235 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include "lpfc_hw4.h"
  35. #include "lpfc_hw.h"
  36. #include "lpfc_sli.h"
  37. #include "lpfc_sli4.h"
  38. #include "lpfc_nl.h"
  39. #include "lpfc_disc.h"
  40. #include "lpfc_scsi.h"
  41. #include "lpfc.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_crtn.h"
  44. #include "lpfc_vport.h"
  45. #include "lpfc_version.h"
  46. char *_dump_buf_data;
  47. unsigned long _dump_buf_data_order;
  48. char *_dump_buf_dif;
  49. unsigned long _dump_buf_dif_order;
  50. spinlock_t _dump_buf_lock;
  51. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  52. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  53. static int lpfc_sli4_queue_create(struct lpfc_hba *);
  54. static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
  55. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  56. static int lpfc_setup_endian_order(struct lpfc_hba *);
  57. static int lpfc_sli4_read_config(struct lpfc_hba *);
  58. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  59. static void lpfc_free_sgl_list(struct lpfc_hba *);
  60. static int lpfc_init_sgl_list(struct lpfc_hba *);
  61. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  62. static void lpfc_free_active_sgl(struct lpfc_hba *);
  63. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  64. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  65. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  66. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  67. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  68. static struct scsi_transport_template *lpfc_transport_template = NULL;
  69. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  70. static DEFINE_IDR(lpfc_hba_index);
  71. /**
  72. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  73. * @phba: pointer to lpfc hba data structure.
  74. *
  75. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  76. * mailbox command. It retrieves the revision information from the HBA and
  77. * collects the Vital Product Data (VPD) about the HBA for preparing the
  78. * configuration of the HBA.
  79. *
  80. * Return codes:
  81. * 0 - success.
  82. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  83. * Any other value - indicates an error.
  84. **/
  85. int
  86. lpfc_config_port_prep(struct lpfc_hba *phba)
  87. {
  88. lpfc_vpd_t *vp = &phba->vpd;
  89. int i = 0, rc;
  90. LPFC_MBOXQ_t *pmb;
  91. MAILBOX_t *mb;
  92. char *lpfc_vpd_data = NULL;
  93. uint16_t offset = 0;
  94. static char licensed[56] =
  95. "key unlock for use with gnu public licensed code only\0";
  96. static int init_key = 1;
  97. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  98. if (!pmb) {
  99. phba->link_state = LPFC_HBA_ERROR;
  100. return -ENOMEM;
  101. }
  102. mb = &pmb->u.mb;
  103. phba->link_state = LPFC_INIT_MBX_CMDS;
  104. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  105. if (init_key) {
  106. uint32_t *ptext = (uint32_t *) licensed;
  107. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  108. *ptext = cpu_to_be32(*ptext);
  109. init_key = 0;
  110. }
  111. lpfc_read_nv(phba, pmb);
  112. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  113. sizeof (mb->un.varRDnvp.rsvd3));
  114. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  115. sizeof (licensed));
  116. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  117. if (rc != MBX_SUCCESS) {
  118. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  119. "0324 Config Port initialization "
  120. "error, mbxCmd x%x READ_NVPARM, "
  121. "mbxStatus x%x\n",
  122. mb->mbxCommand, mb->mbxStatus);
  123. mempool_free(pmb, phba->mbox_mem_pool);
  124. return -ERESTART;
  125. }
  126. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  127. sizeof(phba->wwnn));
  128. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  129. sizeof(phba->wwpn));
  130. }
  131. phba->sli3_options = 0x0;
  132. /* Setup and issue mailbox READ REV command */
  133. lpfc_read_rev(phba, pmb);
  134. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  135. if (rc != MBX_SUCCESS) {
  136. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  137. "0439 Adapter failed to init, mbxCmd x%x "
  138. "READ_REV, mbxStatus x%x\n",
  139. mb->mbxCommand, mb->mbxStatus);
  140. mempool_free( pmb, phba->mbox_mem_pool);
  141. return -ERESTART;
  142. }
  143. /*
  144. * The value of rr must be 1 since the driver set the cv field to 1.
  145. * This setting requires the FW to set all revision fields.
  146. */
  147. if (mb->un.varRdRev.rr == 0) {
  148. vp->rev.rBit = 0;
  149. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  150. "0440 Adapter failed to init, READ_REV has "
  151. "missing revision information.\n");
  152. mempool_free(pmb, phba->mbox_mem_pool);
  153. return -ERESTART;
  154. }
  155. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  156. mempool_free(pmb, phba->mbox_mem_pool);
  157. return -EINVAL;
  158. }
  159. /* Save information as VPD data */
  160. vp->rev.rBit = 1;
  161. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  162. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  163. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  164. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  165. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  166. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  167. vp->rev.smRev = mb->un.varRdRev.smRev;
  168. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  169. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  170. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  171. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  172. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  173. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  174. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  175. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  176. /* If the sli feature level is less then 9, we must
  177. * tear down all RPIs and VPIs on link down if NPIV
  178. * is enabled.
  179. */
  180. if (vp->rev.feaLevelHigh < 9)
  181. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  182. if (lpfc_is_LC_HBA(phba->pcidev->device))
  183. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  184. sizeof (phba->RandomData));
  185. /* Get adapter VPD information */
  186. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  187. if (!lpfc_vpd_data)
  188. goto out_free_mbox;
  189. do {
  190. lpfc_dump_mem(phba, pmb, offset);
  191. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  192. if (rc != MBX_SUCCESS) {
  193. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  194. "0441 VPD not present on adapter, "
  195. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  196. mb->mbxCommand, mb->mbxStatus);
  197. mb->un.varDmp.word_cnt = 0;
  198. }
  199. /* dump mem may return a zero when finished or we got a
  200. * mailbox error, either way we are done.
  201. */
  202. if (mb->un.varDmp.word_cnt == 0)
  203. break;
  204. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  205. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  206. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  207. lpfc_vpd_data + offset,
  208. mb->un.varDmp.word_cnt);
  209. offset += mb->un.varDmp.word_cnt;
  210. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  211. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  212. kfree(lpfc_vpd_data);
  213. out_free_mbox:
  214. mempool_free(pmb, phba->mbox_mem_pool);
  215. return 0;
  216. }
  217. /**
  218. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  219. * @phba: pointer to lpfc hba data structure.
  220. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  221. *
  222. * This is the completion handler for driver's configuring asynchronous event
  223. * mailbox command to the device. If the mailbox command returns successfully,
  224. * it will set internal async event support flag to 1; otherwise, it will
  225. * set internal async event support flag to 0.
  226. **/
  227. static void
  228. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  229. {
  230. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  231. phba->temp_sensor_support = 1;
  232. else
  233. phba->temp_sensor_support = 0;
  234. mempool_free(pmboxq, phba->mbox_mem_pool);
  235. return;
  236. }
  237. /**
  238. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  239. * @phba: pointer to lpfc hba data structure.
  240. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  241. *
  242. * This is the completion handler for dump mailbox command for getting
  243. * wake up parameters. When this command complete, the response contain
  244. * Option rom version of the HBA. This function translate the version number
  245. * into a human readable string and store it in OptionROMVersion.
  246. **/
  247. static void
  248. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  249. {
  250. struct prog_id *prg;
  251. uint32_t prog_id_word;
  252. char dist = ' ';
  253. /* character array used for decoding dist type. */
  254. char dist_char[] = "nabx";
  255. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  256. mempool_free(pmboxq, phba->mbox_mem_pool);
  257. return;
  258. }
  259. prg = (struct prog_id *) &prog_id_word;
  260. /* word 7 contain option rom version */
  261. prog_id_word = pmboxq->u.mb.un.varWords[7];
  262. /* Decode the Option rom version word to a readable string */
  263. if (prg->dist < 4)
  264. dist = dist_char[prg->dist];
  265. if ((prg->dist == 3) && (prg->num == 0))
  266. sprintf(phba->OptionROMVersion, "%d.%d%d",
  267. prg->ver, prg->rev, prg->lev);
  268. else
  269. sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
  270. prg->ver, prg->rev, prg->lev,
  271. dist, prg->num);
  272. mempool_free(pmboxq, phba->mbox_mem_pool);
  273. return;
  274. }
  275. /**
  276. * lpfc_config_port_post - Perform lpfc initialization after config port
  277. * @phba: pointer to lpfc hba data structure.
  278. *
  279. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  280. * command call. It performs all internal resource and state setups on the
  281. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  282. * ELS ring timers, etc.
  283. *
  284. * Return codes
  285. * 0 - success.
  286. * Any other value - error.
  287. **/
  288. int
  289. lpfc_config_port_post(struct lpfc_hba *phba)
  290. {
  291. struct lpfc_vport *vport = phba->pport;
  292. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  293. LPFC_MBOXQ_t *pmb;
  294. MAILBOX_t *mb;
  295. struct lpfc_dmabuf *mp;
  296. struct lpfc_sli *psli = &phba->sli;
  297. uint32_t status, timeout;
  298. int i, j;
  299. int rc;
  300. spin_lock_irq(&phba->hbalock);
  301. /*
  302. * If the Config port completed correctly the HBA is not
  303. * over heated any more.
  304. */
  305. if (phba->over_temp_state == HBA_OVER_TEMP)
  306. phba->over_temp_state = HBA_NORMAL_TEMP;
  307. spin_unlock_irq(&phba->hbalock);
  308. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  309. if (!pmb) {
  310. phba->link_state = LPFC_HBA_ERROR;
  311. return -ENOMEM;
  312. }
  313. mb = &pmb->u.mb;
  314. /* Get login parameters for NID. */
  315. lpfc_read_sparam(phba, pmb, 0);
  316. pmb->vport = vport;
  317. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  318. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  319. "0448 Adapter failed init, mbxCmd x%x "
  320. "READ_SPARM mbxStatus x%x\n",
  321. mb->mbxCommand, mb->mbxStatus);
  322. phba->link_state = LPFC_HBA_ERROR;
  323. mp = (struct lpfc_dmabuf *) pmb->context1;
  324. mempool_free( pmb, phba->mbox_mem_pool);
  325. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  326. kfree(mp);
  327. return -EIO;
  328. }
  329. mp = (struct lpfc_dmabuf *) pmb->context1;
  330. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  331. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  332. kfree(mp);
  333. pmb->context1 = NULL;
  334. if (phba->cfg_soft_wwnn)
  335. u64_to_wwn(phba->cfg_soft_wwnn,
  336. vport->fc_sparam.nodeName.u.wwn);
  337. if (phba->cfg_soft_wwpn)
  338. u64_to_wwn(phba->cfg_soft_wwpn,
  339. vport->fc_sparam.portName.u.wwn);
  340. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  341. sizeof (struct lpfc_name));
  342. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  343. sizeof (struct lpfc_name));
  344. /* Update the fc_host data structures with new wwn. */
  345. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  346. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  347. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  348. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  349. /* This should be consolidated into parse_vpd ? - mr */
  350. if (phba->SerialNumber[0] == 0) {
  351. uint8_t *outptr;
  352. outptr = &vport->fc_nodename.u.s.IEEE[0];
  353. for (i = 0; i < 12; i++) {
  354. status = *outptr++;
  355. j = ((status & 0xf0) >> 4);
  356. if (j <= 9)
  357. phba->SerialNumber[i] =
  358. (char)((uint8_t) 0x30 + (uint8_t) j);
  359. else
  360. phba->SerialNumber[i] =
  361. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  362. i++;
  363. j = (status & 0xf);
  364. if (j <= 9)
  365. phba->SerialNumber[i] =
  366. (char)((uint8_t) 0x30 + (uint8_t) j);
  367. else
  368. phba->SerialNumber[i] =
  369. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  370. }
  371. }
  372. lpfc_read_config(phba, pmb);
  373. pmb->vport = vport;
  374. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  375. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  376. "0453 Adapter failed to init, mbxCmd x%x "
  377. "READ_CONFIG, mbxStatus x%x\n",
  378. mb->mbxCommand, mb->mbxStatus);
  379. phba->link_state = LPFC_HBA_ERROR;
  380. mempool_free( pmb, phba->mbox_mem_pool);
  381. return -EIO;
  382. }
  383. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  384. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  385. phba->cfg_hba_queue_depth =
  386. (mb->un.varRdConfig.max_xri + 1) -
  387. lpfc_sli4_get_els_iocb_cnt(phba);
  388. phba->lmt = mb->un.varRdConfig.lmt;
  389. /* Get the default values for Model Name and Description */
  390. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  391. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  392. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  393. && !(phba->lmt & LMT_1Gb))
  394. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  395. && !(phba->lmt & LMT_2Gb))
  396. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  397. && !(phba->lmt & LMT_4Gb))
  398. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  399. && !(phba->lmt & LMT_8Gb))
  400. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  401. && !(phba->lmt & LMT_10Gb))) {
  402. /* Reset link speed to auto */
  403. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  404. "1302 Invalid speed for this board: "
  405. "Reset link speed to auto: x%x\n",
  406. phba->cfg_link_speed);
  407. phba->cfg_link_speed = LINK_SPEED_AUTO;
  408. }
  409. phba->link_state = LPFC_LINK_DOWN;
  410. /* Only process IOCBs on ELS ring till hba_state is READY */
  411. if (psli->ring[psli->extra_ring].cmdringaddr)
  412. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  413. if (psli->ring[psli->fcp_ring].cmdringaddr)
  414. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  415. if (psli->ring[psli->next_ring].cmdringaddr)
  416. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  417. /* Post receive buffers for desired rings */
  418. if (phba->sli_rev != 3)
  419. lpfc_post_rcv_buf(phba);
  420. /*
  421. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  422. */
  423. if (phba->intr_type == MSIX) {
  424. rc = lpfc_config_msi(phba, pmb);
  425. if (rc) {
  426. mempool_free(pmb, phba->mbox_mem_pool);
  427. return -EIO;
  428. }
  429. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  430. if (rc != MBX_SUCCESS) {
  431. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  432. "0352 Config MSI mailbox command "
  433. "failed, mbxCmd x%x, mbxStatus x%x\n",
  434. pmb->u.mb.mbxCommand,
  435. pmb->u.mb.mbxStatus);
  436. mempool_free(pmb, phba->mbox_mem_pool);
  437. return -EIO;
  438. }
  439. }
  440. spin_lock_irq(&phba->hbalock);
  441. /* Initialize ERATT handling flag */
  442. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  443. /* Enable appropriate host interrupts */
  444. status = readl(phba->HCregaddr);
  445. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  446. if (psli->num_rings > 0)
  447. status |= HC_R0INT_ENA;
  448. if (psli->num_rings > 1)
  449. status |= HC_R1INT_ENA;
  450. if (psli->num_rings > 2)
  451. status |= HC_R2INT_ENA;
  452. if (psli->num_rings > 3)
  453. status |= HC_R3INT_ENA;
  454. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  455. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  456. status &= ~(HC_R0INT_ENA);
  457. writel(status, phba->HCregaddr);
  458. readl(phba->HCregaddr); /* flush */
  459. spin_unlock_irq(&phba->hbalock);
  460. /* Set up ring-0 (ELS) timer */
  461. timeout = phba->fc_ratov * 2;
  462. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  463. /* Set up heart beat (HB) timer */
  464. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  465. phba->hb_outstanding = 0;
  466. phba->last_completion_time = jiffies;
  467. /* Set up error attention (ERATT) polling timer */
  468. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  469. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  470. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  471. lpfc_set_loopback_flag(phba);
  472. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  473. if (rc != MBX_SUCCESS) {
  474. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  475. "0454 Adapter failed to init, mbxCmd x%x "
  476. "INIT_LINK, mbxStatus x%x\n",
  477. mb->mbxCommand, mb->mbxStatus);
  478. /* Clear all interrupt enable conditions */
  479. writel(0, phba->HCregaddr);
  480. readl(phba->HCregaddr); /* flush */
  481. /* Clear all pending interrupts */
  482. writel(0xffffffff, phba->HAregaddr);
  483. readl(phba->HAregaddr); /* flush */
  484. phba->link_state = LPFC_HBA_ERROR;
  485. if (rc != MBX_BUSY)
  486. mempool_free(pmb, phba->mbox_mem_pool);
  487. return -EIO;
  488. }
  489. /* MBOX buffer will be freed in mbox compl */
  490. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  491. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  492. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  493. pmb->vport = phba->pport;
  494. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  495. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  496. lpfc_printf_log(phba,
  497. KERN_ERR,
  498. LOG_INIT,
  499. "0456 Adapter failed to issue "
  500. "ASYNCEVT_ENABLE mbox status x%x \n.",
  501. rc);
  502. mempool_free(pmb, phba->mbox_mem_pool);
  503. }
  504. /* Get Option rom version */
  505. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  506. lpfc_dump_wakeup_param(phba, pmb);
  507. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  508. pmb->vport = phba->pport;
  509. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  510. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  511. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  512. "to get Option ROM version status x%x\n.", rc);
  513. mempool_free(pmb, phba->mbox_mem_pool);
  514. }
  515. return 0;
  516. }
  517. /**
  518. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  519. * @phba: pointer to lpfc HBA data structure.
  520. *
  521. * This routine will do LPFC uninitialization before the HBA is reset when
  522. * bringing down the SLI Layer.
  523. *
  524. * Return codes
  525. * 0 - success.
  526. * Any other value - error.
  527. **/
  528. int
  529. lpfc_hba_down_prep(struct lpfc_hba *phba)
  530. {
  531. struct lpfc_vport **vports;
  532. int i;
  533. if (phba->sli_rev <= LPFC_SLI_REV3) {
  534. /* Disable interrupts */
  535. writel(0, phba->HCregaddr);
  536. readl(phba->HCregaddr); /* flush */
  537. }
  538. if (phba->pport->load_flag & FC_UNLOADING)
  539. lpfc_cleanup_discovery_resources(phba->pport);
  540. else {
  541. vports = lpfc_create_vport_work_array(phba);
  542. if (vports != NULL)
  543. for (i = 0; i <= phba->max_vports &&
  544. vports[i] != NULL; i++)
  545. lpfc_cleanup_discovery_resources(vports[i]);
  546. lpfc_destroy_vport_work_array(phba, vports);
  547. }
  548. return 0;
  549. }
  550. /**
  551. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  552. * @phba: pointer to lpfc HBA data structure.
  553. *
  554. * This routine will do uninitialization after the HBA is reset when bring
  555. * down the SLI Layer.
  556. *
  557. * Return codes
  558. * 0 - sucess.
  559. * Any other value - error.
  560. **/
  561. static int
  562. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  563. {
  564. struct lpfc_sli *psli = &phba->sli;
  565. struct lpfc_sli_ring *pring;
  566. struct lpfc_dmabuf *mp, *next_mp;
  567. LIST_HEAD(completions);
  568. int i;
  569. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  570. lpfc_sli_hbqbuf_free_all(phba);
  571. else {
  572. /* Cleanup preposted buffers on the ELS ring */
  573. pring = &psli->ring[LPFC_ELS_RING];
  574. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  575. list_del(&mp->list);
  576. pring->postbufq_cnt--;
  577. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  578. kfree(mp);
  579. }
  580. }
  581. spin_lock_irq(&phba->hbalock);
  582. for (i = 0; i < psli->num_rings; i++) {
  583. pring = &psli->ring[i];
  584. /* At this point in time the HBA is either reset or DOA. Either
  585. * way, nothing should be on txcmplq as it will NEVER complete.
  586. */
  587. list_splice_init(&pring->txcmplq, &completions);
  588. pring->txcmplq_cnt = 0;
  589. spin_unlock_irq(&phba->hbalock);
  590. /* Cancel all the IOCBs from the completions list */
  591. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  592. IOERR_SLI_ABORTED);
  593. lpfc_sli_abort_iocb_ring(phba, pring);
  594. spin_lock_irq(&phba->hbalock);
  595. }
  596. spin_unlock_irq(&phba->hbalock);
  597. return 0;
  598. }
  599. /**
  600. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  601. * @phba: pointer to lpfc HBA data structure.
  602. *
  603. * This routine will do uninitialization after the HBA is reset when bring
  604. * down the SLI Layer.
  605. *
  606. * Return codes
  607. * 0 - sucess.
  608. * Any other value - error.
  609. **/
  610. static int
  611. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  612. {
  613. struct lpfc_scsi_buf *psb, *psb_next;
  614. LIST_HEAD(aborts);
  615. int ret;
  616. unsigned long iflag = 0;
  617. ret = lpfc_hba_down_post_s3(phba);
  618. if (ret)
  619. return ret;
  620. /* At this point in time the HBA is either reset or DOA. Either
  621. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  622. * on the lpfc_sgl_list so that it can either be freed if the
  623. * driver is unloading or reposted if the driver is restarting
  624. * the port.
  625. */
  626. spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
  627. /* scsl_buf_list */
  628. /* abts_sgl_list_lock required because worker thread uses this
  629. * list.
  630. */
  631. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  632. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  633. &phba->sli4_hba.lpfc_sgl_list);
  634. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  635. /* abts_scsi_buf_list_lock required because worker thread uses this
  636. * list.
  637. */
  638. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  639. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  640. &aborts);
  641. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  642. spin_unlock_irq(&phba->hbalock);
  643. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  644. psb->pCmd = NULL;
  645. psb->status = IOSTAT_SUCCESS;
  646. }
  647. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  648. list_splice(&aborts, &phba->lpfc_scsi_buf_list);
  649. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  650. return 0;
  651. }
  652. /**
  653. * lpfc_hba_down_post - Wrapper func for hba down post routine
  654. * @phba: pointer to lpfc HBA data structure.
  655. *
  656. * This routine wraps the actual SLI3 or SLI4 routine for performing
  657. * uninitialization after the HBA is reset when bring down the SLI Layer.
  658. *
  659. * Return codes
  660. * 0 - sucess.
  661. * Any other value - error.
  662. **/
  663. int
  664. lpfc_hba_down_post(struct lpfc_hba *phba)
  665. {
  666. return (*phba->lpfc_hba_down_post)(phba);
  667. }
  668. /**
  669. * lpfc_hb_timeout - The HBA-timer timeout handler
  670. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  671. *
  672. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  673. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  674. * work-port-events bitmap and the worker thread is notified. This timeout
  675. * event will be used by the worker thread to invoke the actual timeout
  676. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  677. * be performed in the timeout handler and the HBA timeout event bit shall
  678. * be cleared by the worker thread after it has taken the event bitmap out.
  679. **/
  680. static void
  681. lpfc_hb_timeout(unsigned long ptr)
  682. {
  683. struct lpfc_hba *phba;
  684. uint32_t tmo_posted;
  685. unsigned long iflag;
  686. phba = (struct lpfc_hba *)ptr;
  687. /* Check for heart beat timeout conditions */
  688. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  689. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  690. if (!tmo_posted)
  691. phba->pport->work_port_events |= WORKER_HB_TMO;
  692. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  693. /* Tell the worker thread there is work to do */
  694. if (!tmo_posted)
  695. lpfc_worker_wake_up(phba);
  696. return;
  697. }
  698. /**
  699. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  700. * @phba: pointer to lpfc hba data structure.
  701. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  702. *
  703. * This is the callback function to the lpfc heart-beat mailbox command.
  704. * If configured, the lpfc driver issues the heart-beat mailbox command to
  705. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  706. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  707. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  708. * heart-beat outstanding state. Once the mailbox command comes back and
  709. * no error conditions detected, the heart-beat mailbox command timer is
  710. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  711. * state is cleared for the next heart-beat. If the timer expired with the
  712. * heart-beat outstanding state set, the driver will put the HBA offline.
  713. **/
  714. static void
  715. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  716. {
  717. unsigned long drvr_flag;
  718. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  719. phba->hb_outstanding = 0;
  720. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  721. /* Check and reset heart-beat timer is necessary */
  722. mempool_free(pmboxq, phba->mbox_mem_pool);
  723. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  724. !(phba->link_state == LPFC_HBA_ERROR) &&
  725. !(phba->pport->load_flag & FC_UNLOADING))
  726. mod_timer(&phba->hb_tmofunc,
  727. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  728. return;
  729. }
  730. /**
  731. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  732. * @phba: pointer to lpfc hba data structure.
  733. *
  734. * This is the actual HBA-timer timeout handler to be invoked by the worker
  735. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  736. * handler performs any periodic operations needed for the device. If such
  737. * periodic event has already been attended to either in the interrupt handler
  738. * or by processing slow-ring or fast-ring events within the HBA-timer
  739. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  740. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  741. * is configured and there is no heart-beat mailbox command outstanding, a
  742. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  743. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  744. * to offline.
  745. **/
  746. void
  747. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  748. {
  749. LPFC_MBOXQ_t *pmboxq;
  750. struct lpfc_dmabuf *buf_ptr;
  751. int retval;
  752. struct lpfc_sli *psli = &phba->sli;
  753. LIST_HEAD(completions);
  754. if ((phba->link_state == LPFC_HBA_ERROR) ||
  755. (phba->pport->load_flag & FC_UNLOADING) ||
  756. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  757. return;
  758. spin_lock_irq(&phba->pport->work_port_lock);
  759. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  760. jiffies)) {
  761. spin_unlock_irq(&phba->pport->work_port_lock);
  762. if (!phba->hb_outstanding)
  763. mod_timer(&phba->hb_tmofunc,
  764. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  765. else
  766. mod_timer(&phba->hb_tmofunc,
  767. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  768. return;
  769. }
  770. spin_unlock_irq(&phba->pport->work_port_lock);
  771. if (phba->elsbuf_cnt &&
  772. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  773. spin_lock_irq(&phba->hbalock);
  774. list_splice_init(&phba->elsbuf, &completions);
  775. phba->elsbuf_cnt = 0;
  776. phba->elsbuf_prev_cnt = 0;
  777. spin_unlock_irq(&phba->hbalock);
  778. while (!list_empty(&completions)) {
  779. list_remove_head(&completions, buf_ptr,
  780. struct lpfc_dmabuf, list);
  781. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  782. kfree(buf_ptr);
  783. }
  784. }
  785. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  786. /* If there is no heart beat outstanding, issue a heartbeat command */
  787. if (phba->cfg_enable_hba_heartbeat) {
  788. if (!phba->hb_outstanding) {
  789. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  790. if (!pmboxq) {
  791. mod_timer(&phba->hb_tmofunc,
  792. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  793. return;
  794. }
  795. lpfc_heart_beat(phba, pmboxq);
  796. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  797. pmboxq->vport = phba->pport;
  798. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  799. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  800. mempool_free(pmboxq, phba->mbox_mem_pool);
  801. mod_timer(&phba->hb_tmofunc,
  802. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  803. return;
  804. }
  805. mod_timer(&phba->hb_tmofunc,
  806. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  807. phba->hb_outstanding = 1;
  808. return;
  809. } else {
  810. /*
  811. * If heart beat timeout called with hb_outstanding set
  812. * we need to take the HBA offline.
  813. */
  814. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  815. "0459 Adapter heartbeat failure, "
  816. "taking this port offline.\n");
  817. spin_lock_irq(&phba->hbalock);
  818. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  819. spin_unlock_irq(&phba->hbalock);
  820. lpfc_offline_prep(phba);
  821. lpfc_offline(phba);
  822. lpfc_unblock_mgmt_io(phba);
  823. phba->link_state = LPFC_HBA_ERROR;
  824. lpfc_hba_down_post(phba);
  825. }
  826. }
  827. }
  828. /**
  829. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  830. * @phba: pointer to lpfc hba data structure.
  831. *
  832. * This routine is called to bring the HBA offline when HBA hardware error
  833. * other than Port Error 6 has been detected.
  834. **/
  835. static void
  836. lpfc_offline_eratt(struct lpfc_hba *phba)
  837. {
  838. struct lpfc_sli *psli = &phba->sli;
  839. spin_lock_irq(&phba->hbalock);
  840. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  841. spin_unlock_irq(&phba->hbalock);
  842. lpfc_offline_prep(phba);
  843. lpfc_offline(phba);
  844. lpfc_reset_barrier(phba);
  845. spin_lock_irq(&phba->hbalock);
  846. lpfc_sli_brdreset(phba);
  847. spin_unlock_irq(&phba->hbalock);
  848. lpfc_hba_down_post(phba);
  849. lpfc_sli_brdready(phba, HS_MBRDY);
  850. lpfc_unblock_mgmt_io(phba);
  851. phba->link_state = LPFC_HBA_ERROR;
  852. return;
  853. }
  854. /**
  855. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  856. * @phba: pointer to lpfc hba data structure.
  857. *
  858. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  859. * other than Port Error 6 has been detected.
  860. **/
  861. static void
  862. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  863. {
  864. lpfc_offline_prep(phba);
  865. lpfc_offline(phba);
  866. lpfc_sli4_brdreset(phba);
  867. lpfc_hba_down_post(phba);
  868. lpfc_sli4_post_status_check(phba);
  869. lpfc_unblock_mgmt_io(phba);
  870. phba->link_state = LPFC_HBA_ERROR;
  871. }
  872. /**
  873. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  874. * @phba: pointer to lpfc hba data structure.
  875. *
  876. * This routine is invoked to handle the deferred HBA hardware error
  877. * conditions. This type of error is indicated by HBA by setting ER1
  878. * and another ER bit in the host status register. The driver will
  879. * wait until the ER1 bit clears before handling the error condition.
  880. **/
  881. static void
  882. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  883. {
  884. uint32_t old_host_status = phba->work_hs;
  885. struct lpfc_sli_ring *pring;
  886. struct lpfc_sli *psli = &phba->sli;
  887. /* If the pci channel is offline, ignore possible errors,
  888. * since we cannot communicate with the pci card anyway.
  889. */
  890. if (pci_channel_offline(phba->pcidev)) {
  891. spin_lock_irq(&phba->hbalock);
  892. phba->hba_flag &= ~DEFER_ERATT;
  893. spin_unlock_irq(&phba->hbalock);
  894. return;
  895. }
  896. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  897. "0479 Deferred Adapter Hardware Error "
  898. "Data: x%x x%x x%x\n",
  899. phba->work_hs,
  900. phba->work_status[0], phba->work_status[1]);
  901. spin_lock_irq(&phba->hbalock);
  902. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  903. spin_unlock_irq(&phba->hbalock);
  904. /*
  905. * Firmware stops when it triggred erratt. That could cause the I/Os
  906. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  907. * SCSI layer retry it after re-establishing link.
  908. */
  909. pring = &psli->ring[psli->fcp_ring];
  910. lpfc_sli_abort_iocb_ring(phba, pring);
  911. /*
  912. * There was a firmware error. Take the hba offline and then
  913. * attempt to restart it.
  914. */
  915. lpfc_offline_prep(phba);
  916. lpfc_offline(phba);
  917. /* Wait for the ER1 bit to clear.*/
  918. while (phba->work_hs & HS_FFER1) {
  919. msleep(100);
  920. phba->work_hs = readl(phba->HSregaddr);
  921. /* If driver is unloading let the worker thread continue */
  922. if (phba->pport->load_flag & FC_UNLOADING) {
  923. phba->work_hs = 0;
  924. break;
  925. }
  926. }
  927. /*
  928. * This is to ptrotect against a race condition in which
  929. * first write to the host attention register clear the
  930. * host status register.
  931. */
  932. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  933. phba->work_hs = old_host_status & ~HS_FFER1;
  934. spin_lock_irq(&phba->hbalock);
  935. phba->hba_flag &= ~DEFER_ERATT;
  936. spin_unlock_irq(&phba->hbalock);
  937. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  938. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  939. }
  940. static void
  941. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  942. {
  943. struct lpfc_board_event_header board_event;
  944. struct Scsi_Host *shost;
  945. board_event.event_type = FC_REG_BOARD_EVENT;
  946. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  947. shost = lpfc_shost_from_vport(phba->pport);
  948. fc_host_post_vendor_event(shost, fc_get_event_number(),
  949. sizeof(board_event),
  950. (char *) &board_event,
  951. LPFC_NL_VENDOR_ID);
  952. }
  953. /**
  954. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  955. * @phba: pointer to lpfc hba data structure.
  956. *
  957. * This routine is invoked to handle the following HBA hardware error
  958. * conditions:
  959. * 1 - HBA error attention interrupt
  960. * 2 - DMA ring index out of range
  961. * 3 - Mailbox command came back as unknown
  962. **/
  963. static void
  964. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  965. {
  966. struct lpfc_vport *vport = phba->pport;
  967. struct lpfc_sli *psli = &phba->sli;
  968. struct lpfc_sli_ring *pring;
  969. uint32_t event_data;
  970. unsigned long temperature;
  971. struct temp_event temp_event_data;
  972. struct Scsi_Host *shost;
  973. /* If the pci channel is offline, ignore possible errors,
  974. * since we cannot communicate with the pci card anyway.
  975. */
  976. if (pci_channel_offline(phba->pcidev)) {
  977. spin_lock_irq(&phba->hbalock);
  978. phba->hba_flag &= ~DEFER_ERATT;
  979. spin_unlock_irq(&phba->hbalock);
  980. return;
  981. }
  982. /* If resets are disabled then leave the HBA alone and return */
  983. if (!phba->cfg_enable_hba_reset)
  984. return;
  985. /* Send an internal error event to mgmt application */
  986. lpfc_board_errevt_to_mgmt(phba);
  987. if (phba->hba_flag & DEFER_ERATT)
  988. lpfc_handle_deferred_eratt(phba);
  989. if (phba->work_hs & HS_FFER6) {
  990. /* Re-establishing Link */
  991. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  992. "1301 Re-establishing Link "
  993. "Data: x%x x%x x%x\n",
  994. phba->work_hs,
  995. phba->work_status[0], phba->work_status[1]);
  996. spin_lock_irq(&phba->hbalock);
  997. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  998. spin_unlock_irq(&phba->hbalock);
  999. /*
  1000. * Firmware stops when it triggled erratt with HS_FFER6.
  1001. * That could cause the I/Os dropped by the firmware.
  1002. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1003. * retry it after re-establishing link.
  1004. */
  1005. pring = &psli->ring[psli->fcp_ring];
  1006. lpfc_sli_abort_iocb_ring(phba, pring);
  1007. /*
  1008. * There was a firmware error. Take the hba offline and then
  1009. * attempt to restart it.
  1010. */
  1011. lpfc_offline_prep(phba);
  1012. lpfc_offline(phba);
  1013. lpfc_sli_brdrestart(phba);
  1014. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1015. lpfc_unblock_mgmt_io(phba);
  1016. return;
  1017. }
  1018. lpfc_unblock_mgmt_io(phba);
  1019. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1020. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1021. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1022. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1023. temp_event_data.data = (uint32_t)temperature;
  1024. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1025. "0406 Adapter maximum temperature exceeded "
  1026. "(%ld), taking this port offline "
  1027. "Data: x%x x%x x%x\n",
  1028. temperature, phba->work_hs,
  1029. phba->work_status[0], phba->work_status[1]);
  1030. shost = lpfc_shost_from_vport(phba->pport);
  1031. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1032. sizeof(temp_event_data),
  1033. (char *) &temp_event_data,
  1034. SCSI_NL_VID_TYPE_PCI
  1035. | PCI_VENDOR_ID_EMULEX);
  1036. spin_lock_irq(&phba->hbalock);
  1037. phba->over_temp_state = HBA_OVER_TEMP;
  1038. spin_unlock_irq(&phba->hbalock);
  1039. lpfc_offline_eratt(phba);
  1040. } else {
  1041. /* The if clause above forces this code path when the status
  1042. * failure is a value other than FFER6. Do not call the offline
  1043. * twice. This is the adapter hardware error path.
  1044. */
  1045. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1046. "0457 Adapter Hardware Error "
  1047. "Data: x%x x%x x%x\n",
  1048. phba->work_hs,
  1049. phba->work_status[0], phba->work_status[1]);
  1050. event_data = FC_REG_DUMP_EVENT;
  1051. shost = lpfc_shost_from_vport(vport);
  1052. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1053. sizeof(event_data), (char *) &event_data,
  1054. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1055. lpfc_offline_eratt(phba);
  1056. }
  1057. return;
  1058. }
  1059. /**
  1060. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1061. * @phba: pointer to lpfc hba data structure.
  1062. *
  1063. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1064. * conditions.
  1065. **/
  1066. static void
  1067. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1068. {
  1069. struct lpfc_vport *vport = phba->pport;
  1070. uint32_t event_data;
  1071. struct Scsi_Host *shost;
  1072. /* If the pci channel is offline, ignore possible errors, since
  1073. * we cannot communicate with the pci card anyway.
  1074. */
  1075. if (pci_channel_offline(phba->pcidev))
  1076. return;
  1077. /* If resets are disabled then leave the HBA alone and return */
  1078. if (!phba->cfg_enable_hba_reset)
  1079. return;
  1080. /* Send an internal error event to mgmt application */
  1081. lpfc_board_errevt_to_mgmt(phba);
  1082. /* For now, the actual action for SLI4 device handling is not
  1083. * specified yet, just treated it as adaptor hardware failure
  1084. */
  1085. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1086. "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
  1087. phba->work_status[0], phba->work_status[1]);
  1088. event_data = FC_REG_DUMP_EVENT;
  1089. shost = lpfc_shost_from_vport(vport);
  1090. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1091. sizeof(event_data), (char *) &event_data,
  1092. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1093. lpfc_sli4_offline_eratt(phba);
  1094. }
  1095. /**
  1096. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1097. * @phba: pointer to lpfc HBA data structure.
  1098. *
  1099. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1100. * routine from the API jump table function pointer from the lpfc_hba struct.
  1101. *
  1102. * Return codes
  1103. * 0 - sucess.
  1104. * Any other value - error.
  1105. **/
  1106. void
  1107. lpfc_handle_eratt(struct lpfc_hba *phba)
  1108. {
  1109. (*phba->lpfc_handle_eratt)(phba);
  1110. }
  1111. /**
  1112. * lpfc_handle_latt - The HBA link event handler
  1113. * @phba: pointer to lpfc hba data structure.
  1114. *
  1115. * This routine is invoked from the worker thread to handle a HBA host
  1116. * attention link event.
  1117. **/
  1118. void
  1119. lpfc_handle_latt(struct lpfc_hba *phba)
  1120. {
  1121. struct lpfc_vport *vport = phba->pport;
  1122. struct lpfc_sli *psli = &phba->sli;
  1123. LPFC_MBOXQ_t *pmb;
  1124. volatile uint32_t control;
  1125. struct lpfc_dmabuf *mp;
  1126. int rc = 0;
  1127. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1128. if (!pmb) {
  1129. rc = 1;
  1130. goto lpfc_handle_latt_err_exit;
  1131. }
  1132. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1133. if (!mp) {
  1134. rc = 2;
  1135. goto lpfc_handle_latt_free_pmb;
  1136. }
  1137. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1138. if (!mp->virt) {
  1139. rc = 3;
  1140. goto lpfc_handle_latt_free_mp;
  1141. }
  1142. /* Cleanup any outstanding ELS commands */
  1143. lpfc_els_flush_all_cmd(phba);
  1144. psli->slistat.link_event++;
  1145. lpfc_read_la(phba, pmb, mp);
  1146. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  1147. pmb->vport = vport;
  1148. /* Block ELS IOCBs until we have processed this mbox command */
  1149. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1150. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1151. if (rc == MBX_NOT_FINISHED) {
  1152. rc = 4;
  1153. goto lpfc_handle_latt_free_mbuf;
  1154. }
  1155. /* Clear Link Attention in HA REG */
  1156. spin_lock_irq(&phba->hbalock);
  1157. writel(HA_LATT, phba->HAregaddr);
  1158. readl(phba->HAregaddr); /* flush */
  1159. spin_unlock_irq(&phba->hbalock);
  1160. return;
  1161. lpfc_handle_latt_free_mbuf:
  1162. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1163. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1164. lpfc_handle_latt_free_mp:
  1165. kfree(mp);
  1166. lpfc_handle_latt_free_pmb:
  1167. mempool_free(pmb, phba->mbox_mem_pool);
  1168. lpfc_handle_latt_err_exit:
  1169. /* Enable Link attention interrupts */
  1170. spin_lock_irq(&phba->hbalock);
  1171. psli->sli_flag |= LPFC_PROCESS_LA;
  1172. control = readl(phba->HCregaddr);
  1173. control |= HC_LAINT_ENA;
  1174. writel(control, phba->HCregaddr);
  1175. readl(phba->HCregaddr); /* flush */
  1176. /* Clear Link Attention in HA REG */
  1177. writel(HA_LATT, phba->HAregaddr);
  1178. readl(phba->HAregaddr); /* flush */
  1179. spin_unlock_irq(&phba->hbalock);
  1180. lpfc_linkdown(phba);
  1181. phba->link_state = LPFC_HBA_ERROR;
  1182. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1183. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  1184. return;
  1185. }
  1186. /**
  1187. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  1188. * @phba: pointer to lpfc hba data structure.
  1189. * @vpd: pointer to the vital product data.
  1190. * @len: length of the vital product data in bytes.
  1191. *
  1192. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  1193. * an array of characters. In this routine, the ModelName, ProgramType, and
  1194. * ModelDesc, etc. fields of the phba data structure will be populated.
  1195. *
  1196. * Return codes
  1197. * 0 - pointer to the VPD passed in is NULL
  1198. * 1 - success
  1199. **/
  1200. int
  1201. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  1202. {
  1203. uint8_t lenlo, lenhi;
  1204. int Length;
  1205. int i, j;
  1206. int finished = 0;
  1207. int index = 0;
  1208. if (!vpd)
  1209. return 0;
  1210. /* Vital Product */
  1211. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1212. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  1213. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  1214. (uint32_t) vpd[3]);
  1215. while (!finished && (index < (len - 4))) {
  1216. switch (vpd[index]) {
  1217. case 0x82:
  1218. case 0x91:
  1219. index += 1;
  1220. lenlo = vpd[index];
  1221. index += 1;
  1222. lenhi = vpd[index];
  1223. index += 1;
  1224. i = ((((unsigned short)lenhi) << 8) + lenlo);
  1225. index += i;
  1226. break;
  1227. case 0x90:
  1228. index += 1;
  1229. lenlo = vpd[index];
  1230. index += 1;
  1231. lenhi = vpd[index];
  1232. index += 1;
  1233. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  1234. if (Length > len - index)
  1235. Length = len - index;
  1236. while (Length > 0) {
  1237. /* Look for Serial Number */
  1238. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  1239. index += 2;
  1240. i = vpd[index];
  1241. index += 1;
  1242. j = 0;
  1243. Length -= (3+i);
  1244. while(i--) {
  1245. phba->SerialNumber[j++] = vpd[index++];
  1246. if (j == 31)
  1247. break;
  1248. }
  1249. phba->SerialNumber[j] = 0;
  1250. continue;
  1251. }
  1252. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  1253. phba->vpd_flag |= VPD_MODEL_DESC;
  1254. index += 2;
  1255. i = vpd[index];
  1256. index += 1;
  1257. j = 0;
  1258. Length -= (3+i);
  1259. while(i--) {
  1260. phba->ModelDesc[j++] = vpd[index++];
  1261. if (j == 255)
  1262. break;
  1263. }
  1264. phba->ModelDesc[j] = 0;
  1265. continue;
  1266. }
  1267. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  1268. phba->vpd_flag |= VPD_MODEL_NAME;
  1269. index += 2;
  1270. i = vpd[index];
  1271. index += 1;
  1272. j = 0;
  1273. Length -= (3+i);
  1274. while(i--) {
  1275. phba->ModelName[j++] = vpd[index++];
  1276. if (j == 79)
  1277. break;
  1278. }
  1279. phba->ModelName[j] = 0;
  1280. continue;
  1281. }
  1282. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  1283. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  1284. index += 2;
  1285. i = vpd[index];
  1286. index += 1;
  1287. j = 0;
  1288. Length -= (3+i);
  1289. while(i--) {
  1290. phba->ProgramType[j++] = vpd[index++];
  1291. if (j == 255)
  1292. break;
  1293. }
  1294. phba->ProgramType[j] = 0;
  1295. continue;
  1296. }
  1297. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1298. phba->vpd_flag |= VPD_PORT;
  1299. index += 2;
  1300. i = vpd[index];
  1301. index += 1;
  1302. j = 0;
  1303. Length -= (3+i);
  1304. while(i--) {
  1305. phba->Port[j++] = vpd[index++];
  1306. if (j == 19)
  1307. break;
  1308. }
  1309. phba->Port[j] = 0;
  1310. continue;
  1311. }
  1312. else {
  1313. index += 2;
  1314. i = vpd[index];
  1315. index += 1;
  1316. index += i;
  1317. Length -= (3 + i);
  1318. }
  1319. }
  1320. finished = 0;
  1321. break;
  1322. case 0x78:
  1323. finished = 1;
  1324. break;
  1325. default:
  1326. index ++;
  1327. break;
  1328. }
  1329. }
  1330. return(1);
  1331. }
  1332. /**
  1333. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  1334. * @phba: pointer to lpfc hba data structure.
  1335. * @mdp: pointer to the data structure to hold the derived model name.
  1336. * @descp: pointer to the data structure to hold the derived description.
  1337. *
  1338. * This routine retrieves HBA's description based on its registered PCI device
  1339. * ID. The @descp passed into this function points to an array of 256 chars. It
  1340. * shall be returned with the model name, maximum speed, and the host bus type.
  1341. * The @mdp passed into this function points to an array of 80 chars. When the
  1342. * function returns, the @mdp will be filled with the model name.
  1343. **/
  1344. static void
  1345. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1346. {
  1347. lpfc_vpd_t *vp;
  1348. uint16_t dev_id = phba->pcidev->device;
  1349. int max_speed;
  1350. int GE = 0;
  1351. int oneConnect = 0; /* default is not a oneConnect */
  1352. struct {
  1353. char * name;
  1354. int max_speed;
  1355. char * bus;
  1356. } m = {"<Unknown>", 0, ""};
  1357. if (mdp && mdp[0] != '\0'
  1358. && descp && descp[0] != '\0')
  1359. return;
  1360. if (phba->lmt & LMT_10Gb)
  1361. max_speed = 10;
  1362. else if (phba->lmt & LMT_8Gb)
  1363. max_speed = 8;
  1364. else if (phba->lmt & LMT_4Gb)
  1365. max_speed = 4;
  1366. else if (phba->lmt & LMT_2Gb)
  1367. max_speed = 2;
  1368. else
  1369. max_speed = 1;
  1370. vp = &phba->vpd;
  1371. switch (dev_id) {
  1372. case PCI_DEVICE_ID_FIREFLY:
  1373. m = (typeof(m)){"LP6000", max_speed, "PCI"};
  1374. break;
  1375. case PCI_DEVICE_ID_SUPERFLY:
  1376. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1377. m = (typeof(m)){"LP7000", max_speed, "PCI"};
  1378. else
  1379. m = (typeof(m)){"LP7000E", max_speed, "PCI"};
  1380. break;
  1381. case PCI_DEVICE_ID_DRAGONFLY:
  1382. m = (typeof(m)){"LP8000", max_speed, "PCI"};
  1383. break;
  1384. case PCI_DEVICE_ID_CENTAUR:
  1385. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1386. m = (typeof(m)){"LP9002", max_speed, "PCI"};
  1387. else
  1388. m = (typeof(m)){"LP9000", max_speed, "PCI"};
  1389. break;
  1390. case PCI_DEVICE_ID_RFLY:
  1391. m = (typeof(m)){"LP952", max_speed, "PCI"};
  1392. break;
  1393. case PCI_DEVICE_ID_PEGASUS:
  1394. m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
  1395. break;
  1396. case PCI_DEVICE_ID_THOR:
  1397. m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
  1398. break;
  1399. case PCI_DEVICE_ID_VIPER:
  1400. m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
  1401. break;
  1402. case PCI_DEVICE_ID_PFLY:
  1403. m = (typeof(m)){"LP982", max_speed, "PCI-X"};
  1404. break;
  1405. case PCI_DEVICE_ID_TFLY:
  1406. m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
  1407. break;
  1408. case PCI_DEVICE_ID_HELIOS:
  1409. m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
  1410. break;
  1411. case PCI_DEVICE_ID_HELIOS_SCSP:
  1412. m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
  1413. break;
  1414. case PCI_DEVICE_ID_HELIOS_DCSP:
  1415. m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
  1416. break;
  1417. case PCI_DEVICE_ID_NEPTUNE:
  1418. m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
  1419. break;
  1420. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1421. m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
  1422. break;
  1423. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1424. m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
  1425. break;
  1426. case PCI_DEVICE_ID_BMID:
  1427. m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
  1428. break;
  1429. case PCI_DEVICE_ID_BSMB:
  1430. m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
  1431. break;
  1432. case PCI_DEVICE_ID_ZEPHYR:
  1433. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1434. break;
  1435. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1436. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1437. break;
  1438. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1439. m = (typeof(m)){"LP2105", max_speed, "PCIe"};
  1440. GE = 1;
  1441. break;
  1442. case PCI_DEVICE_ID_ZMID:
  1443. m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
  1444. break;
  1445. case PCI_DEVICE_ID_ZSMB:
  1446. m = (typeof(m)){"LPe111", max_speed, "PCIe"};
  1447. break;
  1448. case PCI_DEVICE_ID_LP101:
  1449. m = (typeof(m)){"LP101", max_speed, "PCI-X"};
  1450. break;
  1451. case PCI_DEVICE_ID_LP10000S:
  1452. m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
  1453. break;
  1454. case PCI_DEVICE_ID_LP11000S:
  1455. m = (typeof(m)){"LP11000-S", max_speed,
  1456. "PCI-X2"};
  1457. break;
  1458. case PCI_DEVICE_ID_LPE11000S:
  1459. m = (typeof(m)){"LPe11000-S", max_speed,
  1460. "PCIe"};
  1461. break;
  1462. case PCI_DEVICE_ID_SAT:
  1463. m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
  1464. break;
  1465. case PCI_DEVICE_ID_SAT_MID:
  1466. m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
  1467. break;
  1468. case PCI_DEVICE_ID_SAT_SMB:
  1469. m = (typeof(m)){"LPe121", max_speed, "PCIe"};
  1470. break;
  1471. case PCI_DEVICE_ID_SAT_DCSP:
  1472. m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
  1473. break;
  1474. case PCI_DEVICE_ID_SAT_SCSP:
  1475. m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
  1476. break;
  1477. case PCI_DEVICE_ID_SAT_S:
  1478. m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
  1479. break;
  1480. case PCI_DEVICE_ID_HORNET:
  1481. m = (typeof(m)){"LP21000", max_speed, "PCIe"};
  1482. GE = 1;
  1483. break;
  1484. case PCI_DEVICE_ID_PROTEUS_VF:
  1485. m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
  1486. break;
  1487. case PCI_DEVICE_ID_PROTEUS_PF:
  1488. m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
  1489. break;
  1490. case PCI_DEVICE_ID_PROTEUS_S:
  1491. m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
  1492. break;
  1493. case PCI_DEVICE_ID_TIGERSHARK:
  1494. oneConnect = 1;
  1495. m = (typeof(m)) {"OCe10100-F", max_speed, "PCIe"};
  1496. break;
  1497. default:
  1498. m = (typeof(m)){ NULL };
  1499. break;
  1500. }
  1501. if (mdp && mdp[0] == '\0')
  1502. snprintf(mdp, 79,"%s", m.name);
  1503. /* oneConnect hba requires special processing, they are all initiators
  1504. * and we put the port number on the end
  1505. */
  1506. if (descp && descp[0] == '\0') {
  1507. if (oneConnect)
  1508. snprintf(descp, 255,
  1509. "Emulex OneConnect %s, FCoE Initiator, Port %s",
  1510. m.name,
  1511. phba->Port);
  1512. else
  1513. snprintf(descp, 255,
  1514. "Emulex %s %d%s %s %s",
  1515. m.name, m.max_speed,
  1516. (GE) ? "GE" : "Gb",
  1517. m.bus,
  1518. (GE) ? "FCoE Adapter" :
  1519. "Fibre Channel Adapter");
  1520. }
  1521. }
  1522. /**
  1523. * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  1524. * @phba: pointer to lpfc hba data structure.
  1525. * @pring: pointer to a IOCB ring.
  1526. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  1527. *
  1528. * This routine posts a given number of IOCBs with the associated DMA buffer
  1529. * descriptors specified by the cnt argument to the given IOCB ring.
  1530. *
  1531. * Return codes
  1532. * The number of IOCBs NOT able to be posted to the IOCB ring.
  1533. **/
  1534. int
  1535. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  1536. {
  1537. IOCB_t *icmd;
  1538. struct lpfc_iocbq *iocb;
  1539. struct lpfc_dmabuf *mp1, *mp2;
  1540. cnt += pring->missbufcnt;
  1541. /* While there are buffers to post */
  1542. while (cnt > 0) {
  1543. /* Allocate buffer for command iocb */
  1544. iocb = lpfc_sli_get_iocbq(phba);
  1545. if (iocb == NULL) {
  1546. pring->missbufcnt = cnt;
  1547. return cnt;
  1548. }
  1549. icmd = &iocb->iocb;
  1550. /* 2 buffers can be posted per command */
  1551. /* Allocate buffer to post */
  1552. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1553. if (mp1)
  1554. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1555. if (!mp1 || !mp1->virt) {
  1556. kfree(mp1);
  1557. lpfc_sli_release_iocbq(phba, iocb);
  1558. pring->missbufcnt = cnt;
  1559. return cnt;
  1560. }
  1561. INIT_LIST_HEAD(&mp1->list);
  1562. /* Allocate buffer to post */
  1563. if (cnt > 1) {
  1564. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1565. if (mp2)
  1566. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1567. &mp2->phys);
  1568. if (!mp2 || !mp2->virt) {
  1569. kfree(mp2);
  1570. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1571. kfree(mp1);
  1572. lpfc_sli_release_iocbq(phba, iocb);
  1573. pring->missbufcnt = cnt;
  1574. return cnt;
  1575. }
  1576. INIT_LIST_HEAD(&mp2->list);
  1577. } else {
  1578. mp2 = NULL;
  1579. }
  1580. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1581. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1582. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1583. icmd->ulpBdeCount = 1;
  1584. cnt--;
  1585. if (mp2) {
  1586. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1587. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1588. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1589. cnt--;
  1590. icmd->ulpBdeCount = 2;
  1591. }
  1592. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1593. icmd->ulpLe = 1;
  1594. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  1595. IOCB_ERROR) {
  1596. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1597. kfree(mp1);
  1598. cnt++;
  1599. if (mp2) {
  1600. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1601. kfree(mp2);
  1602. cnt++;
  1603. }
  1604. lpfc_sli_release_iocbq(phba, iocb);
  1605. pring->missbufcnt = cnt;
  1606. return cnt;
  1607. }
  1608. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1609. if (mp2)
  1610. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1611. }
  1612. pring->missbufcnt = 0;
  1613. return 0;
  1614. }
  1615. /**
  1616. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  1617. * @phba: pointer to lpfc hba data structure.
  1618. *
  1619. * This routine posts initial receive IOCB buffers to the ELS ring. The
  1620. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  1621. * set to 64 IOCBs.
  1622. *
  1623. * Return codes
  1624. * 0 - success (currently always success)
  1625. **/
  1626. static int
  1627. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1628. {
  1629. struct lpfc_sli *psli = &phba->sli;
  1630. /* Ring 0, ELS / CT buffers */
  1631. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  1632. /* Ring 2 - FCP no buffers needed */
  1633. return 0;
  1634. }
  1635. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1636. /**
  1637. * lpfc_sha_init - Set up initial array of hash table entries
  1638. * @HashResultPointer: pointer to an array as hash table.
  1639. *
  1640. * This routine sets up the initial values to the array of hash table entries
  1641. * for the LC HBAs.
  1642. **/
  1643. static void
  1644. lpfc_sha_init(uint32_t * HashResultPointer)
  1645. {
  1646. HashResultPointer[0] = 0x67452301;
  1647. HashResultPointer[1] = 0xEFCDAB89;
  1648. HashResultPointer[2] = 0x98BADCFE;
  1649. HashResultPointer[3] = 0x10325476;
  1650. HashResultPointer[4] = 0xC3D2E1F0;
  1651. }
  1652. /**
  1653. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  1654. * @HashResultPointer: pointer to an initial/result hash table.
  1655. * @HashWorkingPointer: pointer to an working hash table.
  1656. *
  1657. * This routine iterates an initial hash table pointed by @HashResultPointer
  1658. * with the values from the working hash table pointeed by @HashWorkingPointer.
  1659. * The results are putting back to the initial hash table, returned through
  1660. * the @HashResultPointer as the result hash table.
  1661. **/
  1662. static void
  1663. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1664. {
  1665. int t;
  1666. uint32_t TEMP;
  1667. uint32_t A, B, C, D, E;
  1668. t = 16;
  1669. do {
  1670. HashWorkingPointer[t] =
  1671. S(1,
  1672. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1673. 8] ^
  1674. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1675. } while (++t <= 79);
  1676. t = 0;
  1677. A = HashResultPointer[0];
  1678. B = HashResultPointer[1];
  1679. C = HashResultPointer[2];
  1680. D = HashResultPointer[3];
  1681. E = HashResultPointer[4];
  1682. do {
  1683. if (t < 20) {
  1684. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1685. } else if (t < 40) {
  1686. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1687. } else if (t < 60) {
  1688. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1689. } else {
  1690. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1691. }
  1692. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1693. E = D;
  1694. D = C;
  1695. C = S(30, B);
  1696. B = A;
  1697. A = TEMP;
  1698. } while (++t <= 79);
  1699. HashResultPointer[0] += A;
  1700. HashResultPointer[1] += B;
  1701. HashResultPointer[2] += C;
  1702. HashResultPointer[3] += D;
  1703. HashResultPointer[4] += E;
  1704. }
  1705. /**
  1706. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  1707. * @RandomChallenge: pointer to the entry of host challenge random number array.
  1708. * @HashWorking: pointer to the entry of the working hash array.
  1709. *
  1710. * This routine calculates the working hash array referred by @HashWorking
  1711. * from the challenge random numbers associated with the host, referred by
  1712. * @RandomChallenge. The result is put into the entry of the working hash
  1713. * array and returned by reference through @HashWorking.
  1714. **/
  1715. static void
  1716. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1717. {
  1718. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1719. }
  1720. /**
  1721. * lpfc_hba_init - Perform special handling for LC HBA initialization
  1722. * @phba: pointer to lpfc hba data structure.
  1723. * @hbainit: pointer to an array of unsigned 32-bit integers.
  1724. *
  1725. * This routine performs the special handling for LC HBA initialization.
  1726. **/
  1727. void
  1728. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1729. {
  1730. int t;
  1731. uint32_t *HashWorking;
  1732. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1733. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1734. if (!HashWorking)
  1735. return;
  1736. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1737. HashWorking[1] = HashWorking[79] = *pwwnn;
  1738. for (t = 0; t < 7; t++)
  1739. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1740. lpfc_sha_init(hbainit);
  1741. lpfc_sha_iterate(hbainit, HashWorking);
  1742. kfree(HashWorking);
  1743. }
  1744. /**
  1745. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  1746. * @vport: pointer to a virtual N_Port data structure.
  1747. *
  1748. * This routine performs the necessary cleanups before deleting the @vport.
  1749. * It invokes the discovery state machine to perform necessary state
  1750. * transitions and to release the ndlps associated with the @vport. Note,
  1751. * the physical port is treated as @vport 0.
  1752. **/
  1753. void
  1754. lpfc_cleanup(struct lpfc_vport *vport)
  1755. {
  1756. struct lpfc_hba *phba = vport->phba;
  1757. struct lpfc_nodelist *ndlp, *next_ndlp;
  1758. int i = 0;
  1759. if (phba->link_state > LPFC_LINK_DOWN)
  1760. lpfc_port_link_failure(vport);
  1761. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1762. if (!NLP_CHK_NODE_ACT(ndlp)) {
  1763. ndlp = lpfc_enable_node(vport, ndlp,
  1764. NLP_STE_UNUSED_NODE);
  1765. if (!ndlp)
  1766. continue;
  1767. spin_lock_irq(&phba->ndlp_lock);
  1768. NLP_SET_FREE_REQ(ndlp);
  1769. spin_unlock_irq(&phba->ndlp_lock);
  1770. /* Trigger the release of the ndlp memory */
  1771. lpfc_nlp_put(ndlp);
  1772. continue;
  1773. }
  1774. spin_lock_irq(&phba->ndlp_lock);
  1775. if (NLP_CHK_FREE_REQ(ndlp)) {
  1776. /* The ndlp should not be in memory free mode already */
  1777. spin_unlock_irq(&phba->ndlp_lock);
  1778. continue;
  1779. } else
  1780. /* Indicate request for freeing ndlp memory */
  1781. NLP_SET_FREE_REQ(ndlp);
  1782. spin_unlock_irq(&phba->ndlp_lock);
  1783. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  1784. ndlp->nlp_DID == Fabric_DID) {
  1785. /* Just free up ndlp with Fabric_DID for vports */
  1786. lpfc_nlp_put(ndlp);
  1787. continue;
  1788. }
  1789. if (ndlp->nlp_type & NLP_FABRIC)
  1790. lpfc_disc_state_machine(vport, ndlp, NULL,
  1791. NLP_EVT_DEVICE_RECOVERY);
  1792. lpfc_disc_state_machine(vport, ndlp, NULL,
  1793. NLP_EVT_DEVICE_RM);
  1794. }
  1795. /* At this point, ALL ndlp's should be gone
  1796. * because of the previous NLP_EVT_DEVICE_RM.
  1797. * Lets wait for this to happen, if needed.
  1798. */
  1799. while (!list_empty(&vport->fc_nodes)) {
  1800. if (i++ > 3000) {
  1801. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1802. "0233 Nodelist not empty\n");
  1803. list_for_each_entry_safe(ndlp, next_ndlp,
  1804. &vport->fc_nodes, nlp_listp) {
  1805. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  1806. LOG_NODE,
  1807. "0282 did:x%x ndlp:x%p "
  1808. "usgmap:x%x refcnt:%d\n",
  1809. ndlp->nlp_DID, (void *)ndlp,
  1810. ndlp->nlp_usg_map,
  1811. atomic_read(
  1812. &ndlp->kref.refcount));
  1813. }
  1814. break;
  1815. }
  1816. /* Wait for any activity on ndlps to settle */
  1817. msleep(10);
  1818. }
  1819. }
  1820. /**
  1821. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  1822. * @vport: pointer to a virtual N_Port data structure.
  1823. *
  1824. * This routine stops all the timers associated with a @vport. This function
  1825. * is invoked before disabling or deleting a @vport. Note that the physical
  1826. * port is treated as @vport 0.
  1827. **/
  1828. void
  1829. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1830. {
  1831. del_timer_sync(&vport->els_tmofunc);
  1832. del_timer_sync(&vport->fc_fdmitmo);
  1833. lpfc_can_disctmo(vport);
  1834. return;
  1835. }
  1836. /**
  1837. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  1838. * @phba: pointer to lpfc hba data structure.
  1839. *
  1840. * This routine stops all the timers associated with a HBA. This function is
  1841. * invoked before either putting a HBA offline or unloading the driver.
  1842. **/
  1843. void
  1844. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  1845. {
  1846. lpfc_stop_vport_timers(phba->pport);
  1847. del_timer_sync(&phba->sli.mbox_tmo);
  1848. del_timer_sync(&phba->fabric_block_timer);
  1849. del_timer_sync(&phba->eratt_poll);
  1850. del_timer_sync(&phba->hb_tmofunc);
  1851. phba->hb_outstanding = 0;
  1852. switch (phba->pci_dev_grp) {
  1853. case LPFC_PCI_DEV_LP:
  1854. /* Stop any LightPulse device specific driver timers */
  1855. del_timer_sync(&phba->fcp_poll_timer);
  1856. break;
  1857. case LPFC_PCI_DEV_OC:
  1858. /* Stop any OneConnect device sepcific driver timers */
  1859. break;
  1860. default:
  1861. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1862. "0297 Invalid device group (x%x)\n",
  1863. phba->pci_dev_grp);
  1864. break;
  1865. }
  1866. return;
  1867. }
  1868. /**
  1869. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  1870. * @phba: pointer to lpfc hba data structure.
  1871. *
  1872. * This routine marks a HBA's management interface as blocked. Once the HBA's
  1873. * management interface is marked as blocked, all the user space access to
  1874. * the HBA, whether they are from sysfs interface or libdfc interface will
  1875. * all be blocked. The HBA is set to block the management interface when the
  1876. * driver prepares the HBA interface for online or offline.
  1877. **/
  1878. static void
  1879. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1880. {
  1881. unsigned long iflag;
  1882. spin_lock_irqsave(&phba->hbalock, iflag);
  1883. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1884. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1885. }
  1886. /**
  1887. * lpfc_online - Initialize and bring a HBA online
  1888. * @phba: pointer to lpfc hba data structure.
  1889. *
  1890. * This routine initializes the HBA and brings a HBA online. During this
  1891. * process, the management interface is blocked to prevent user space access
  1892. * to the HBA interfering with the driver initialization.
  1893. *
  1894. * Return codes
  1895. * 0 - successful
  1896. * 1 - failed
  1897. **/
  1898. int
  1899. lpfc_online(struct lpfc_hba *phba)
  1900. {
  1901. struct lpfc_vport *vport;
  1902. struct lpfc_vport **vports;
  1903. int i;
  1904. if (!phba)
  1905. return 0;
  1906. vport = phba->pport;
  1907. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1908. return 0;
  1909. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1910. "0458 Bring Adapter online\n");
  1911. lpfc_block_mgmt_io(phba);
  1912. if (!lpfc_sli_queue_setup(phba)) {
  1913. lpfc_unblock_mgmt_io(phba);
  1914. return 1;
  1915. }
  1916. if (phba->sli_rev == LPFC_SLI_REV4) {
  1917. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  1918. lpfc_unblock_mgmt_io(phba);
  1919. return 1;
  1920. }
  1921. } else {
  1922. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  1923. lpfc_unblock_mgmt_io(phba);
  1924. return 1;
  1925. }
  1926. }
  1927. vports = lpfc_create_vport_work_array(phba);
  1928. if (vports != NULL)
  1929. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1930. struct Scsi_Host *shost;
  1931. shost = lpfc_shost_from_vport(vports[i]);
  1932. spin_lock_irq(shost->host_lock);
  1933. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1934. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1935. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1936. spin_unlock_irq(shost->host_lock);
  1937. }
  1938. lpfc_destroy_vport_work_array(phba, vports);
  1939. lpfc_unblock_mgmt_io(phba);
  1940. return 0;
  1941. }
  1942. /**
  1943. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  1944. * @phba: pointer to lpfc hba data structure.
  1945. *
  1946. * This routine marks a HBA's management interface as not blocked. Once the
  1947. * HBA's management interface is marked as not blocked, all the user space
  1948. * access to the HBA, whether they are from sysfs interface or libdfc
  1949. * interface will be allowed. The HBA is set to block the management interface
  1950. * when the driver prepares the HBA interface for online or offline and then
  1951. * set to unblock the management interface afterwards.
  1952. **/
  1953. void
  1954. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  1955. {
  1956. unsigned long iflag;
  1957. spin_lock_irqsave(&phba->hbalock, iflag);
  1958. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  1959. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1960. }
  1961. /**
  1962. * lpfc_offline_prep - Prepare a HBA to be brought offline
  1963. * @phba: pointer to lpfc hba data structure.
  1964. *
  1965. * This routine is invoked to prepare a HBA to be brought offline. It performs
  1966. * unregistration login to all the nodes on all vports and flushes the mailbox
  1967. * queue to make it ready to be brought offline.
  1968. **/
  1969. void
  1970. lpfc_offline_prep(struct lpfc_hba * phba)
  1971. {
  1972. struct lpfc_vport *vport = phba->pport;
  1973. struct lpfc_nodelist *ndlp, *next_ndlp;
  1974. struct lpfc_vport **vports;
  1975. int i;
  1976. if (vport->fc_flag & FC_OFFLINE_MODE)
  1977. return;
  1978. lpfc_block_mgmt_io(phba);
  1979. lpfc_linkdown(phba);
  1980. /* Issue an unreg_login to all nodes on all vports */
  1981. vports = lpfc_create_vport_work_array(phba);
  1982. if (vports != NULL) {
  1983. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1984. struct Scsi_Host *shost;
  1985. if (vports[i]->load_flag & FC_UNLOADING)
  1986. continue;
  1987. vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
  1988. shost = lpfc_shost_from_vport(vports[i]);
  1989. list_for_each_entry_safe(ndlp, next_ndlp,
  1990. &vports[i]->fc_nodes,
  1991. nlp_listp) {
  1992. if (!NLP_CHK_NODE_ACT(ndlp))
  1993. continue;
  1994. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  1995. continue;
  1996. if (ndlp->nlp_type & NLP_FABRIC) {
  1997. lpfc_disc_state_machine(vports[i], ndlp,
  1998. NULL, NLP_EVT_DEVICE_RECOVERY);
  1999. lpfc_disc_state_machine(vports[i], ndlp,
  2000. NULL, NLP_EVT_DEVICE_RM);
  2001. }
  2002. spin_lock_irq(shost->host_lock);
  2003. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2004. spin_unlock_irq(shost->host_lock);
  2005. lpfc_unreg_rpi(vports[i], ndlp);
  2006. }
  2007. }
  2008. }
  2009. lpfc_destroy_vport_work_array(phba, vports);
  2010. lpfc_sli_mbox_sys_shutdown(phba);
  2011. }
  2012. /**
  2013. * lpfc_offline - Bring a HBA offline
  2014. * @phba: pointer to lpfc hba data structure.
  2015. *
  2016. * This routine actually brings a HBA offline. It stops all the timers
  2017. * associated with the HBA, brings down the SLI layer, and eventually
  2018. * marks the HBA as in offline state for the upper layer protocol.
  2019. **/
  2020. void
  2021. lpfc_offline(struct lpfc_hba *phba)
  2022. {
  2023. struct Scsi_Host *shost;
  2024. struct lpfc_vport **vports;
  2025. int i;
  2026. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  2027. return;
  2028. /* stop port and all timers associated with this hba */
  2029. lpfc_stop_port(phba);
  2030. vports = lpfc_create_vport_work_array(phba);
  2031. if (vports != NULL)
  2032. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  2033. lpfc_stop_vport_timers(vports[i]);
  2034. lpfc_destroy_vport_work_array(phba, vports);
  2035. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2036. "0460 Bring Adapter offline\n");
  2037. /* Bring down the SLI Layer and cleanup. The HBA is offline
  2038. now. */
  2039. lpfc_sli_hba_down(phba);
  2040. spin_lock_irq(&phba->hbalock);
  2041. phba->work_ha = 0;
  2042. spin_unlock_irq(&phba->hbalock);
  2043. vports = lpfc_create_vport_work_array(phba);
  2044. if (vports != NULL)
  2045. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2046. shost = lpfc_shost_from_vport(vports[i]);
  2047. spin_lock_irq(shost->host_lock);
  2048. vports[i]->work_port_events = 0;
  2049. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  2050. spin_unlock_irq(shost->host_lock);
  2051. }
  2052. lpfc_destroy_vport_work_array(phba, vports);
  2053. }
  2054. /**
  2055. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2056. * @phba: pointer to lpfc hba data structure.
  2057. *
  2058. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2059. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2060. * the internal resources before the device is removed from the system.
  2061. *
  2062. * Return codes
  2063. * 0 - successful (for now, it always returns 0)
  2064. **/
  2065. static int
  2066. lpfc_scsi_free(struct lpfc_hba *phba)
  2067. {
  2068. struct lpfc_scsi_buf *sb, *sb_next;
  2069. struct lpfc_iocbq *io, *io_next;
  2070. spin_lock_irq(&phba->hbalock);
  2071. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2072. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  2073. list_del(&sb->list);
  2074. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2075. sb->dma_handle);
  2076. kfree(sb);
  2077. phba->total_scsi_bufs--;
  2078. }
  2079. /* Release all the lpfc_iocbq entries maintained by this host. */
  2080. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2081. list_del(&io->list);
  2082. kfree(io);
  2083. phba->total_iocbq_bufs--;
  2084. }
  2085. spin_unlock_irq(&phba->hbalock);
  2086. return 0;
  2087. }
  2088. /**
  2089. * lpfc_create_port - Create an FC port
  2090. * @phba: pointer to lpfc hba data structure.
  2091. * @instance: a unique integer ID to this FC port.
  2092. * @dev: pointer to the device data structure.
  2093. *
  2094. * This routine creates a FC port for the upper layer protocol. The FC port
  2095. * can be created on top of either a physical port or a virtual port provided
  2096. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2097. * and associates the FC port created before adding the shost into the SCSI
  2098. * layer.
  2099. *
  2100. * Return codes
  2101. * @vport - pointer to the virtual N_Port data structure.
  2102. * NULL - port create failed.
  2103. **/
  2104. struct lpfc_vport *
  2105. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2106. {
  2107. struct lpfc_vport *vport;
  2108. struct Scsi_Host *shost;
  2109. int error = 0;
  2110. if (dev != &phba->pcidev->dev)
  2111. shost = scsi_host_alloc(&lpfc_vport_template,
  2112. sizeof(struct lpfc_vport));
  2113. else
  2114. shost = scsi_host_alloc(&lpfc_template,
  2115. sizeof(struct lpfc_vport));
  2116. if (!shost)
  2117. goto out;
  2118. vport = (struct lpfc_vport *) shost->hostdata;
  2119. vport->phba = phba;
  2120. vport->load_flag |= FC_LOADING;
  2121. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2122. vport->fc_rscn_flush = 0;
  2123. lpfc_get_vport_cfgparam(vport);
  2124. shost->unique_id = instance;
  2125. shost->max_id = LPFC_MAX_TARGET;
  2126. shost->max_lun = vport->cfg_max_luns;
  2127. shost->this_id = -1;
  2128. shost->max_cmd_len = 16;
  2129. if (phba->sli_rev == LPFC_SLI_REV4) {
  2130. shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE;
  2131. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2132. }
  2133. /*
  2134. * Set initial can_queue value since 0 is no longer supported and
  2135. * scsi_add_host will fail. This will be adjusted later based on the
  2136. * max xri value determined in hba setup.
  2137. */
  2138. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2139. if (dev != &phba->pcidev->dev) {
  2140. shost->transportt = lpfc_vport_transport_template;
  2141. vport->port_type = LPFC_NPIV_PORT;
  2142. } else {
  2143. shost->transportt = lpfc_transport_template;
  2144. vport->port_type = LPFC_PHYSICAL_PORT;
  2145. }
  2146. /* Initialize all internally managed lists. */
  2147. INIT_LIST_HEAD(&vport->fc_nodes);
  2148. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  2149. spin_lock_init(&vport->work_port_lock);
  2150. init_timer(&vport->fc_disctmo);
  2151. vport->fc_disctmo.function = lpfc_disc_timeout;
  2152. vport->fc_disctmo.data = (unsigned long)vport;
  2153. init_timer(&vport->fc_fdmitmo);
  2154. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  2155. vport->fc_fdmitmo.data = (unsigned long)vport;
  2156. init_timer(&vport->els_tmofunc);
  2157. vport->els_tmofunc.function = lpfc_els_timeout;
  2158. vport->els_tmofunc.data = (unsigned long)vport;
  2159. error = scsi_add_host(shost, dev);
  2160. if (error)
  2161. goto out_put_shost;
  2162. spin_lock_irq(&phba->hbalock);
  2163. list_add_tail(&vport->listentry, &phba->port_list);
  2164. spin_unlock_irq(&phba->hbalock);
  2165. return vport;
  2166. out_put_shost:
  2167. scsi_host_put(shost);
  2168. out:
  2169. return NULL;
  2170. }
  2171. /**
  2172. * destroy_port - destroy an FC port
  2173. * @vport: pointer to an lpfc virtual N_Port data structure.
  2174. *
  2175. * This routine destroys a FC port from the upper layer protocol. All the
  2176. * resources associated with the port are released.
  2177. **/
  2178. void
  2179. destroy_port(struct lpfc_vport *vport)
  2180. {
  2181. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2182. struct lpfc_hba *phba = vport->phba;
  2183. lpfc_debugfs_terminate(vport);
  2184. fc_remove_host(shost);
  2185. scsi_remove_host(shost);
  2186. spin_lock_irq(&phba->hbalock);
  2187. list_del_init(&vport->listentry);
  2188. spin_unlock_irq(&phba->hbalock);
  2189. lpfc_cleanup(vport);
  2190. return;
  2191. }
  2192. /**
  2193. * lpfc_get_instance - Get a unique integer ID
  2194. *
  2195. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  2196. * uses the kernel idr facility to perform the task.
  2197. *
  2198. * Return codes:
  2199. * instance - a unique integer ID allocated as the new instance.
  2200. * -1 - lpfc get instance failed.
  2201. **/
  2202. int
  2203. lpfc_get_instance(void)
  2204. {
  2205. int instance = 0;
  2206. /* Assign an unused number */
  2207. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  2208. return -1;
  2209. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  2210. return -1;
  2211. return instance;
  2212. }
  2213. /**
  2214. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  2215. * @shost: pointer to SCSI host data structure.
  2216. * @time: elapsed time of the scan in jiffies.
  2217. *
  2218. * This routine is called by the SCSI layer with a SCSI host to determine
  2219. * whether the scan host is finished.
  2220. *
  2221. * Note: there is no scan_start function as adapter initialization will have
  2222. * asynchronously kicked off the link initialization.
  2223. *
  2224. * Return codes
  2225. * 0 - SCSI host scan is not over yet.
  2226. * 1 - SCSI host scan is over.
  2227. **/
  2228. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2229. {
  2230. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2231. struct lpfc_hba *phba = vport->phba;
  2232. int stat = 0;
  2233. spin_lock_irq(shost->host_lock);
  2234. if (vport->load_flag & FC_UNLOADING) {
  2235. stat = 1;
  2236. goto finished;
  2237. }
  2238. if (time >= 30 * HZ) {
  2239. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2240. "0461 Scanning longer than 30 "
  2241. "seconds. Continuing initialization\n");
  2242. stat = 1;
  2243. goto finished;
  2244. }
  2245. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  2246. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2247. "0465 Link down longer than 15 "
  2248. "seconds. Continuing initialization\n");
  2249. stat = 1;
  2250. goto finished;
  2251. }
  2252. if (vport->port_state != LPFC_VPORT_READY)
  2253. goto finished;
  2254. if (vport->num_disc_nodes || vport->fc_prli_sent)
  2255. goto finished;
  2256. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  2257. goto finished;
  2258. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  2259. goto finished;
  2260. stat = 1;
  2261. finished:
  2262. spin_unlock_irq(shost->host_lock);
  2263. return stat;
  2264. }
  2265. /**
  2266. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  2267. * @shost: pointer to SCSI host data structure.
  2268. *
  2269. * This routine initializes a given SCSI host attributes on a FC port. The
  2270. * SCSI host can be either on top of a physical port or a virtual port.
  2271. **/
  2272. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  2273. {
  2274. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2275. struct lpfc_hba *phba = vport->phba;
  2276. /*
  2277. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  2278. */
  2279. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  2280. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  2281. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  2282. memset(fc_host_supported_fc4s(shost), 0,
  2283. sizeof(fc_host_supported_fc4s(shost)));
  2284. fc_host_supported_fc4s(shost)[2] = 1;
  2285. fc_host_supported_fc4s(shost)[7] = 1;
  2286. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  2287. sizeof fc_host_symbolic_name(shost));
  2288. fc_host_supported_speeds(shost) = 0;
  2289. if (phba->lmt & LMT_10Gb)
  2290. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  2291. if (phba->lmt & LMT_8Gb)
  2292. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  2293. if (phba->lmt & LMT_4Gb)
  2294. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  2295. if (phba->lmt & LMT_2Gb)
  2296. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  2297. if (phba->lmt & LMT_1Gb)
  2298. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  2299. fc_host_maxframe_size(shost) =
  2300. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  2301. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  2302. /* This value is also unchanging */
  2303. memset(fc_host_active_fc4s(shost), 0,
  2304. sizeof(fc_host_active_fc4s(shost)));
  2305. fc_host_active_fc4s(shost)[2] = 1;
  2306. fc_host_active_fc4s(shost)[7] = 1;
  2307. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  2308. spin_lock_irq(shost->host_lock);
  2309. vport->load_flag &= ~FC_LOADING;
  2310. spin_unlock_irq(shost->host_lock);
  2311. }
  2312. /**
  2313. * lpfc_stop_port_s3 - Stop SLI3 device port
  2314. * @phba: pointer to lpfc hba data structure.
  2315. *
  2316. * This routine is invoked to stop an SLI3 device port, it stops the device
  2317. * from generating interrupts and stops the device driver's timers for the
  2318. * device.
  2319. **/
  2320. static void
  2321. lpfc_stop_port_s3(struct lpfc_hba *phba)
  2322. {
  2323. /* Clear all interrupt enable conditions */
  2324. writel(0, phba->HCregaddr);
  2325. readl(phba->HCregaddr); /* flush */
  2326. /* Clear all pending interrupts */
  2327. writel(0xffffffff, phba->HAregaddr);
  2328. readl(phba->HAregaddr); /* flush */
  2329. /* Reset some HBA SLI setup states */
  2330. lpfc_stop_hba_timers(phba);
  2331. phba->pport->work_port_events = 0;
  2332. }
  2333. /**
  2334. * lpfc_stop_port_s4 - Stop SLI4 device port
  2335. * @phba: pointer to lpfc hba data structure.
  2336. *
  2337. * This routine is invoked to stop an SLI4 device port, it stops the device
  2338. * from generating interrupts and stops the device driver's timers for the
  2339. * device.
  2340. **/
  2341. static void
  2342. lpfc_stop_port_s4(struct lpfc_hba *phba)
  2343. {
  2344. /* Reset some HBA SLI4 setup states */
  2345. lpfc_stop_hba_timers(phba);
  2346. phba->pport->work_port_events = 0;
  2347. phba->sli4_hba.intr_enable = 0;
  2348. /* Hard clear it for now, shall have more graceful way to wait later */
  2349. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2350. }
  2351. /**
  2352. * lpfc_stop_port - Wrapper function for stopping hba port
  2353. * @phba: Pointer to HBA context object.
  2354. *
  2355. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  2356. * the API jump table function pointer from the lpfc_hba struct.
  2357. **/
  2358. void
  2359. lpfc_stop_port(struct lpfc_hba *phba)
  2360. {
  2361. phba->lpfc_stop_port(phba);
  2362. }
  2363. /**
  2364. * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
  2365. * @phba: pointer to lpfc hba data structure.
  2366. *
  2367. * This routine is invoked to remove the driver default fcf record from
  2368. * the port. This routine currently acts on FCF Index 0.
  2369. *
  2370. **/
  2371. void
  2372. lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
  2373. {
  2374. int rc = 0;
  2375. LPFC_MBOXQ_t *mboxq;
  2376. struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record;
  2377. uint32_t mbox_tmo, req_len;
  2378. uint32_t shdr_status, shdr_add_status;
  2379. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2380. if (!mboxq) {
  2381. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2382. "2020 Failed to allocate mbox for ADD_FCF cmd\n");
  2383. return;
  2384. }
  2385. req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) -
  2386. sizeof(struct lpfc_sli4_cfg_mhdr);
  2387. rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  2388. LPFC_MBOX_OPCODE_FCOE_DELETE_FCF,
  2389. req_len, LPFC_SLI4_MBX_EMBED);
  2390. /*
  2391. * In phase 1, there is a single FCF index, 0. In phase2, the driver
  2392. * supports multiple FCF indices.
  2393. */
  2394. del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry;
  2395. bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1);
  2396. bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record,
  2397. phba->fcf.fcf_indx);
  2398. if (!phba->sli4_hba.intr_enable)
  2399. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  2400. else {
  2401. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  2402. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  2403. }
  2404. /* The IOCTL status is embedded in the mailbox subheader. */
  2405. shdr_status = bf_get(lpfc_mbox_hdr_status,
  2406. &del_fcf_record->header.cfg_shdr.response);
  2407. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  2408. &del_fcf_record->header.cfg_shdr.response);
  2409. if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
  2410. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2411. "2516 DEL FCF of default FCF Index failed "
  2412. "mbx status x%x, status x%x add_status x%x\n",
  2413. rc, shdr_status, shdr_add_status);
  2414. }
  2415. if (rc != MBX_TIMEOUT)
  2416. mempool_free(mboxq, phba->mbox_mem_pool);
  2417. }
  2418. /**
  2419. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  2420. * @phba: pointer to lpfc hba data structure.
  2421. * @acqe_link: pointer to the async link completion queue entry.
  2422. *
  2423. * This routine is to parse the SLI4 link-attention link fault code and
  2424. * translate it into the base driver's read link attention mailbox command
  2425. * status.
  2426. *
  2427. * Return: Link-attention status in terms of base driver's coding.
  2428. **/
  2429. static uint16_t
  2430. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  2431. struct lpfc_acqe_link *acqe_link)
  2432. {
  2433. uint16_t latt_fault;
  2434. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  2435. case LPFC_ASYNC_LINK_FAULT_NONE:
  2436. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  2437. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  2438. latt_fault = 0;
  2439. break;
  2440. default:
  2441. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2442. "0398 Invalid link fault code: x%x\n",
  2443. bf_get(lpfc_acqe_link_fault, acqe_link));
  2444. latt_fault = MBXERR_ERROR;
  2445. break;
  2446. }
  2447. return latt_fault;
  2448. }
  2449. /**
  2450. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  2451. * @phba: pointer to lpfc hba data structure.
  2452. * @acqe_link: pointer to the async link completion queue entry.
  2453. *
  2454. * This routine is to parse the SLI4 link attention type and translate it
  2455. * into the base driver's link attention type coding.
  2456. *
  2457. * Return: Link attention type in terms of base driver's coding.
  2458. **/
  2459. static uint8_t
  2460. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  2461. struct lpfc_acqe_link *acqe_link)
  2462. {
  2463. uint8_t att_type;
  2464. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  2465. case LPFC_ASYNC_LINK_STATUS_DOWN:
  2466. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  2467. att_type = AT_LINK_DOWN;
  2468. break;
  2469. case LPFC_ASYNC_LINK_STATUS_UP:
  2470. /* Ignore physical link up events - wait for logical link up */
  2471. att_type = AT_RESERVED;
  2472. break;
  2473. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  2474. att_type = AT_LINK_UP;
  2475. break;
  2476. default:
  2477. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2478. "0399 Invalid link attention type: x%x\n",
  2479. bf_get(lpfc_acqe_link_status, acqe_link));
  2480. att_type = AT_RESERVED;
  2481. break;
  2482. }
  2483. return att_type;
  2484. }
  2485. /**
  2486. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  2487. * @phba: pointer to lpfc hba data structure.
  2488. * @acqe_link: pointer to the async link completion queue entry.
  2489. *
  2490. * This routine is to parse the SLI4 link-attention link speed and translate
  2491. * it into the base driver's link-attention link speed coding.
  2492. *
  2493. * Return: Link-attention link speed in terms of base driver's coding.
  2494. **/
  2495. static uint8_t
  2496. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  2497. struct lpfc_acqe_link *acqe_link)
  2498. {
  2499. uint8_t link_speed;
  2500. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  2501. case LPFC_ASYNC_LINK_SPEED_ZERO:
  2502. link_speed = LA_UNKNW_LINK;
  2503. break;
  2504. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  2505. link_speed = LA_UNKNW_LINK;
  2506. break;
  2507. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  2508. link_speed = LA_UNKNW_LINK;
  2509. break;
  2510. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  2511. link_speed = LA_1GHZ_LINK;
  2512. break;
  2513. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2514. link_speed = LA_10GHZ_LINK;
  2515. break;
  2516. default:
  2517. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2518. "0483 Invalid link-attention link speed: x%x\n",
  2519. bf_get(lpfc_acqe_link_speed, acqe_link));
  2520. link_speed = LA_UNKNW_LINK;
  2521. break;
  2522. }
  2523. return link_speed;
  2524. }
  2525. /**
  2526. * lpfc_sli4_async_link_evt - Process the asynchronous link event
  2527. * @phba: pointer to lpfc hba data structure.
  2528. * @acqe_link: pointer to the async link completion queue entry.
  2529. *
  2530. * This routine is to handle the SLI4 asynchronous link event.
  2531. **/
  2532. static void
  2533. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  2534. struct lpfc_acqe_link *acqe_link)
  2535. {
  2536. struct lpfc_dmabuf *mp;
  2537. LPFC_MBOXQ_t *pmb;
  2538. MAILBOX_t *mb;
  2539. READ_LA_VAR *la;
  2540. uint8_t att_type;
  2541. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  2542. if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP)
  2543. return;
  2544. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2545. if (!pmb) {
  2546. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2547. "0395 The mboxq allocation failed\n");
  2548. return;
  2549. }
  2550. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2551. if (!mp) {
  2552. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2553. "0396 The lpfc_dmabuf allocation failed\n");
  2554. goto out_free_pmb;
  2555. }
  2556. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  2557. if (!mp->virt) {
  2558. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2559. "0397 The mbuf allocation failed\n");
  2560. goto out_free_dmabuf;
  2561. }
  2562. /* Cleanup any outstanding ELS commands */
  2563. lpfc_els_flush_all_cmd(phba);
  2564. /* Block ELS IOCBs until we have done process link event */
  2565. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  2566. /* Update link event statistics */
  2567. phba->sli.slistat.link_event++;
  2568. /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
  2569. lpfc_read_la(phba, pmb, mp);
  2570. pmb->vport = phba->pport;
  2571. /* Parse and translate status field */
  2572. mb = &pmb->u.mb;
  2573. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  2574. /* Parse and translate link attention fields */
  2575. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  2576. la->eventTag = acqe_link->event_tag;
  2577. la->attType = att_type;
  2578. la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link);
  2579. /* Fake the the following irrelvant fields */
  2580. la->topology = TOPOLOGY_PT_PT;
  2581. la->granted_AL_PA = 0;
  2582. la->il = 0;
  2583. la->pb = 0;
  2584. la->fa = 0;
  2585. la->mm = 0;
  2586. /* Keep the link status for extra SLI4 state machine reference */
  2587. phba->sli4_hba.link_state.speed =
  2588. bf_get(lpfc_acqe_link_speed, acqe_link);
  2589. phba->sli4_hba.link_state.duplex =
  2590. bf_get(lpfc_acqe_link_duplex, acqe_link);
  2591. phba->sli4_hba.link_state.status =
  2592. bf_get(lpfc_acqe_link_status, acqe_link);
  2593. phba->sli4_hba.link_state.physical =
  2594. bf_get(lpfc_acqe_link_physical, acqe_link);
  2595. phba->sli4_hba.link_state.fault =
  2596. bf_get(lpfc_acqe_link_fault, acqe_link);
  2597. /* Invoke the lpfc_handle_latt mailbox command callback function */
  2598. lpfc_mbx_cmpl_read_la(phba, pmb);
  2599. return;
  2600. out_free_dmabuf:
  2601. kfree(mp);
  2602. out_free_pmb:
  2603. mempool_free(pmb, phba->mbox_mem_pool);
  2604. }
  2605. /**
  2606. * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
  2607. * @phba: pointer to lpfc hba data structure.
  2608. * @acqe_link: pointer to the async fcoe completion queue entry.
  2609. *
  2610. * This routine is to handle the SLI4 asynchronous fcoe event.
  2611. **/
  2612. static void
  2613. lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
  2614. struct lpfc_acqe_fcoe *acqe_fcoe)
  2615. {
  2616. uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe);
  2617. int rc;
  2618. switch (event_type) {
  2619. case LPFC_FCOE_EVENT_TYPE_NEW_FCF:
  2620. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2621. "2546 New FCF found index 0x%x tag 0x%x \n",
  2622. acqe_fcoe->fcf_index,
  2623. acqe_fcoe->event_tag);
  2624. /*
  2625. * If the current FCF is in discovered state,
  2626. * do nothing.
  2627. */
  2628. spin_lock_irq(&phba->hbalock);
  2629. if (phba->fcf.fcf_flag & FCF_DISCOVERED) {
  2630. spin_unlock_irq(&phba->hbalock);
  2631. break;
  2632. }
  2633. spin_unlock_irq(&phba->hbalock);
  2634. /* Read the FCF table and re-discover SAN. */
  2635. rc = lpfc_sli4_read_fcf_record(phba,
  2636. LPFC_FCOE_FCF_GET_FIRST);
  2637. if (rc)
  2638. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2639. "2547 Read FCF record failed 0x%x\n",
  2640. rc);
  2641. break;
  2642. case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
  2643. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2644. "2548 FCF Table full count 0x%x tag 0x%x \n",
  2645. bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe),
  2646. acqe_fcoe->event_tag);
  2647. break;
  2648. case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
  2649. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2650. "2549 FCF disconnected fron network index 0x%x"
  2651. " tag 0x%x \n", acqe_fcoe->fcf_index,
  2652. acqe_fcoe->event_tag);
  2653. /* If the event is not for currently used fcf do nothing */
  2654. if (phba->fcf.fcf_indx != acqe_fcoe->fcf_index)
  2655. break;
  2656. /*
  2657. * Currently, driver support only one FCF - so treat this as
  2658. * a link down.
  2659. */
  2660. lpfc_linkdown(phba);
  2661. /* Unregister FCF if no devices connected to it */
  2662. lpfc_unregister_unused_fcf(phba);
  2663. break;
  2664. default:
  2665. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2666. "0288 Unknown FCoE event type 0x%x event tag "
  2667. "0x%x\n", event_type, acqe_fcoe->event_tag);
  2668. break;
  2669. }
  2670. }
  2671. /**
  2672. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  2673. * @phba: pointer to lpfc hba data structure.
  2674. * @acqe_link: pointer to the async dcbx completion queue entry.
  2675. *
  2676. * This routine is to handle the SLI4 asynchronous dcbx event.
  2677. **/
  2678. static void
  2679. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  2680. struct lpfc_acqe_dcbx *acqe_dcbx)
  2681. {
  2682. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2683. "0290 The SLI4 DCBX asynchronous event is not "
  2684. "handled yet\n");
  2685. }
  2686. /**
  2687. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  2688. * @phba: pointer to lpfc hba data structure.
  2689. *
  2690. * This routine is invoked by the worker thread to process all the pending
  2691. * SLI4 asynchronous events.
  2692. **/
  2693. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  2694. {
  2695. struct lpfc_cq_event *cq_event;
  2696. /* First, declare the async event has been handled */
  2697. spin_lock_irq(&phba->hbalock);
  2698. phba->hba_flag &= ~ASYNC_EVENT;
  2699. spin_unlock_irq(&phba->hbalock);
  2700. /* Now, handle all the async events */
  2701. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  2702. /* Get the first event from the head of the event queue */
  2703. spin_lock_irq(&phba->hbalock);
  2704. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  2705. cq_event, struct lpfc_cq_event, list);
  2706. spin_unlock_irq(&phba->hbalock);
  2707. /* Process the asynchronous event */
  2708. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  2709. case LPFC_TRAILER_CODE_LINK:
  2710. lpfc_sli4_async_link_evt(phba,
  2711. &cq_event->cqe.acqe_link);
  2712. break;
  2713. case LPFC_TRAILER_CODE_FCOE:
  2714. lpfc_sli4_async_fcoe_evt(phba,
  2715. &cq_event->cqe.acqe_fcoe);
  2716. break;
  2717. case LPFC_TRAILER_CODE_DCBX:
  2718. lpfc_sli4_async_dcbx_evt(phba,
  2719. &cq_event->cqe.acqe_dcbx);
  2720. break;
  2721. default:
  2722. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2723. "1804 Invalid asynchrous event code: "
  2724. "x%x\n", bf_get(lpfc_trailer_code,
  2725. &cq_event->cqe.mcqe_cmpl));
  2726. break;
  2727. }
  2728. /* Free the completion event processed to the free pool */
  2729. lpfc_sli4_cq_event_release(phba, cq_event);
  2730. }
  2731. }
  2732. /**
  2733. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  2734. * @phba: pointer to lpfc hba data structure.
  2735. * @dev_grp: The HBA PCI-Device group number.
  2736. *
  2737. * This routine is invoked to set up the per HBA PCI-Device group function
  2738. * API jump table entries.
  2739. *
  2740. * Return: 0 if success, otherwise -ENODEV
  2741. **/
  2742. int
  2743. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  2744. {
  2745. int rc;
  2746. /* Set up lpfc PCI-device group */
  2747. phba->pci_dev_grp = dev_grp;
  2748. /* The LPFC_PCI_DEV_OC uses SLI4 */
  2749. if (dev_grp == LPFC_PCI_DEV_OC)
  2750. phba->sli_rev = LPFC_SLI_REV4;
  2751. /* Set up device INIT API function jump table */
  2752. rc = lpfc_init_api_table_setup(phba, dev_grp);
  2753. if (rc)
  2754. return -ENODEV;
  2755. /* Set up SCSI API function jump table */
  2756. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  2757. if (rc)
  2758. return -ENODEV;
  2759. /* Set up SLI API function jump table */
  2760. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  2761. if (rc)
  2762. return -ENODEV;
  2763. /* Set up MBOX API function jump table */
  2764. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  2765. if (rc)
  2766. return -ENODEV;
  2767. return 0;
  2768. }
  2769. /**
  2770. * lpfc_log_intr_mode - Log the active interrupt mode
  2771. * @phba: pointer to lpfc hba data structure.
  2772. * @intr_mode: active interrupt mode adopted.
  2773. *
  2774. * This routine it invoked to log the currently used active interrupt mode
  2775. * to the device.
  2776. **/
  2777. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  2778. {
  2779. switch (intr_mode) {
  2780. case 0:
  2781. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2782. "0470 Enable INTx interrupt mode.\n");
  2783. break;
  2784. case 1:
  2785. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2786. "0481 Enabled MSI interrupt mode.\n");
  2787. break;
  2788. case 2:
  2789. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2790. "0480 Enabled MSI-X interrupt mode.\n");
  2791. break;
  2792. default:
  2793. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2794. "0482 Illegal interrupt mode.\n");
  2795. break;
  2796. }
  2797. return;
  2798. }
  2799. /**
  2800. * lpfc_enable_pci_dev - Enable a generic PCI device.
  2801. * @phba: pointer to lpfc hba data structure.
  2802. *
  2803. * This routine is invoked to enable the PCI device that is common to all
  2804. * PCI devices.
  2805. *
  2806. * Return codes
  2807. * 0 - sucessful
  2808. * other values - error
  2809. **/
  2810. static int
  2811. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  2812. {
  2813. struct pci_dev *pdev;
  2814. int bars;
  2815. /* Obtain PCI device reference */
  2816. if (!phba->pcidev)
  2817. goto out_error;
  2818. else
  2819. pdev = phba->pcidev;
  2820. /* Select PCI BARs */
  2821. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2822. /* Enable PCI device */
  2823. if (pci_enable_device_mem(pdev))
  2824. goto out_error;
  2825. /* Request PCI resource for the device */
  2826. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  2827. goto out_disable_device;
  2828. /* Set up device as PCI master and save state for EEH */
  2829. pci_set_master(pdev);
  2830. pci_try_set_mwi(pdev);
  2831. pci_save_state(pdev);
  2832. return 0;
  2833. out_disable_device:
  2834. pci_disable_device(pdev);
  2835. out_error:
  2836. return -ENODEV;
  2837. }
  2838. /**
  2839. * lpfc_disable_pci_dev - Disable a generic PCI device.
  2840. * @phba: pointer to lpfc hba data structure.
  2841. *
  2842. * This routine is invoked to disable the PCI device that is common to all
  2843. * PCI devices.
  2844. **/
  2845. static void
  2846. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  2847. {
  2848. struct pci_dev *pdev;
  2849. int bars;
  2850. /* Obtain PCI device reference */
  2851. if (!phba->pcidev)
  2852. return;
  2853. else
  2854. pdev = phba->pcidev;
  2855. /* Select PCI BARs */
  2856. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2857. /* Release PCI resource and disable PCI device */
  2858. pci_release_selected_regions(pdev, bars);
  2859. pci_disable_device(pdev);
  2860. /* Null out PCI private reference to driver */
  2861. pci_set_drvdata(pdev, NULL);
  2862. return;
  2863. }
  2864. /**
  2865. * lpfc_reset_hba - Reset a hba
  2866. * @phba: pointer to lpfc hba data structure.
  2867. *
  2868. * This routine is invoked to reset a hba device. It brings the HBA
  2869. * offline, performs a board restart, and then brings the board back
  2870. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  2871. * on outstanding mailbox commands.
  2872. **/
  2873. void
  2874. lpfc_reset_hba(struct lpfc_hba *phba)
  2875. {
  2876. /* If resets are disabled then set error state and return. */
  2877. if (!phba->cfg_enable_hba_reset) {
  2878. phba->link_state = LPFC_HBA_ERROR;
  2879. return;
  2880. }
  2881. lpfc_offline_prep(phba);
  2882. lpfc_offline(phba);
  2883. lpfc_sli_brdrestart(phba);
  2884. lpfc_online(phba);
  2885. lpfc_unblock_mgmt_io(phba);
  2886. }
  2887. /**
  2888. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  2889. * @phba: pointer to lpfc hba data structure.
  2890. *
  2891. * This routine is invoked to set up the driver internal resources specific to
  2892. * support the SLI-3 HBA device it attached to.
  2893. *
  2894. * Return codes
  2895. * 0 - sucessful
  2896. * other values - error
  2897. **/
  2898. static int
  2899. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  2900. {
  2901. struct lpfc_sli *psli;
  2902. /*
  2903. * Initialize timers used by driver
  2904. */
  2905. /* Heartbeat timer */
  2906. init_timer(&phba->hb_tmofunc);
  2907. phba->hb_tmofunc.function = lpfc_hb_timeout;
  2908. phba->hb_tmofunc.data = (unsigned long)phba;
  2909. psli = &phba->sli;
  2910. /* MBOX heartbeat timer */
  2911. init_timer(&psli->mbox_tmo);
  2912. psli->mbox_tmo.function = lpfc_mbox_timeout;
  2913. psli->mbox_tmo.data = (unsigned long) phba;
  2914. /* FCP polling mode timer */
  2915. init_timer(&phba->fcp_poll_timer);
  2916. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  2917. phba->fcp_poll_timer.data = (unsigned long) phba;
  2918. /* Fabric block timer */
  2919. init_timer(&phba->fabric_block_timer);
  2920. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  2921. phba->fabric_block_timer.data = (unsigned long) phba;
  2922. /* EA polling mode timer */
  2923. init_timer(&phba->eratt_poll);
  2924. phba->eratt_poll.function = lpfc_poll_eratt;
  2925. phba->eratt_poll.data = (unsigned long) phba;
  2926. /* Host attention work mask setup */
  2927. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  2928. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  2929. /* Get all the module params for configuring this host */
  2930. lpfc_get_cfgparam(phba);
  2931. /*
  2932. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  2933. * used to create the sg_dma_buf_pool must be dynamically calculated.
  2934. * 2 segments are added since the IOCB needs a command and response bde.
  2935. */
  2936. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  2937. sizeof(struct fcp_rsp) +
  2938. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  2939. if (phba->cfg_enable_bg) {
  2940. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  2941. phba->cfg_sg_dma_buf_size +=
  2942. phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
  2943. }
  2944. /* Also reinitialize the host templates with new values. */
  2945. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  2946. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  2947. phba->max_vpi = LPFC_MAX_VPI;
  2948. /* This will be set to correct value after config_port mbox */
  2949. phba->max_vports = 0;
  2950. /*
  2951. * Initialize the SLI Layer to run with lpfc HBAs.
  2952. */
  2953. lpfc_sli_setup(phba);
  2954. lpfc_sli_queue_setup(phba);
  2955. /* Allocate device driver memory */
  2956. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  2957. return -ENOMEM;
  2958. return 0;
  2959. }
  2960. /**
  2961. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  2962. * @phba: pointer to lpfc hba data structure.
  2963. *
  2964. * This routine is invoked to unset the driver internal resources set up
  2965. * specific for supporting the SLI-3 HBA device it attached to.
  2966. **/
  2967. static void
  2968. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  2969. {
  2970. /* Free device driver memory allocated */
  2971. lpfc_mem_free_all(phba);
  2972. return;
  2973. }
  2974. /**
  2975. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  2976. * @phba: pointer to lpfc hba data structure.
  2977. *
  2978. * This routine is invoked to set up the driver internal resources specific to
  2979. * support the SLI-4 HBA device it attached to.
  2980. *
  2981. * Return codes
  2982. * 0 - sucessful
  2983. * other values - error
  2984. **/
  2985. static int
  2986. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  2987. {
  2988. struct lpfc_sli *psli;
  2989. int rc;
  2990. int i, hbq_count;
  2991. /* Before proceed, wait for POST done and device ready */
  2992. rc = lpfc_sli4_post_status_check(phba);
  2993. if (rc)
  2994. return -ENODEV;
  2995. /*
  2996. * Initialize timers used by driver
  2997. */
  2998. /* Heartbeat timer */
  2999. init_timer(&phba->hb_tmofunc);
  3000. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3001. phba->hb_tmofunc.data = (unsigned long)phba;
  3002. psli = &phba->sli;
  3003. /* MBOX heartbeat timer */
  3004. init_timer(&psli->mbox_tmo);
  3005. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3006. psli->mbox_tmo.data = (unsigned long) phba;
  3007. /* Fabric block timer */
  3008. init_timer(&phba->fabric_block_timer);
  3009. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3010. phba->fabric_block_timer.data = (unsigned long) phba;
  3011. /* EA polling mode timer */
  3012. init_timer(&phba->eratt_poll);
  3013. phba->eratt_poll.function = lpfc_poll_eratt;
  3014. phba->eratt_poll.data = (unsigned long) phba;
  3015. /*
  3016. * We need to do a READ_CONFIG mailbox command here before
  3017. * calling lpfc_get_cfgparam. For VFs this will report the
  3018. * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
  3019. * All of the resources allocated
  3020. * for this Port are tied to these values.
  3021. */
  3022. /* Get all the module params for configuring this host */
  3023. lpfc_get_cfgparam(phba);
  3024. phba->max_vpi = LPFC_MAX_VPI;
  3025. /* This will be set to correct value after the read_config mbox */
  3026. phba->max_vports = 0;
  3027. /* Program the default value of vlan_id and fc_map */
  3028. phba->valid_vlan = 0;
  3029. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3030. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3031. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3032. /*
  3033. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3034. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3035. * 2 segments are added since the IOCB needs a command and response bde.
  3036. * To insure that the scsi sgl does not cross a 4k page boundary only
  3037. * sgl sizes of 1k, 2k, 4k, and 8k are supported.
  3038. * Table of sgl sizes and seg_cnt:
  3039. * sgl size, sg_seg_cnt total seg
  3040. * 1k 50 52
  3041. * 2k 114 116
  3042. * 4k 242 244
  3043. * 8k 498 500
  3044. * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
  3045. * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
  3046. * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
  3047. * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
  3048. */
  3049. if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT)
  3050. phba->cfg_sg_seg_cnt = 50;
  3051. else if (phba->cfg_sg_seg_cnt <= 114)
  3052. phba->cfg_sg_seg_cnt = 114;
  3053. else if (phba->cfg_sg_seg_cnt <= 242)
  3054. phba->cfg_sg_seg_cnt = 242;
  3055. else
  3056. phba->cfg_sg_seg_cnt = 498;
  3057. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd)
  3058. + sizeof(struct fcp_rsp);
  3059. phba->cfg_sg_dma_buf_size +=
  3060. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
  3061. /* Initialize buffer queue management fields */
  3062. hbq_count = lpfc_sli_hbq_count();
  3063. for (i = 0; i < hbq_count; ++i)
  3064. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  3065. INIT_LIST_HEAD(&phba->rb_pend_list);
  3066. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  3067. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  3068. /*
  3069. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  3070. */
  3071. /* Initialize the Abort scsi buffer list used by driver */
  3072. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  3073. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  3074. /* This abort list used by worker thread */
  3075. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  3076. /*
  3077. * Initialize dirver internal slow-path work queues
  3078. */
  3079. /* Driver internel slow-path CQ Event pool */
  3080. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  3081. /* Response IOCB work queue list */
  3082. INIT_LIST_HEAD(&phba->sli4_hba.sp_rspiocb_work_queue);
  3083. /* Asynchronous event CQ Event work queue list */
  3084. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  3085. /* Fast-path XRI aborted CQ Event work queue list */
  3086. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  3087. /* Slow-path XRI aborted CQ Event work queue list */
  3088. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  3089. /* Receive queue CQ Event work queue list */
  3090. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  3091. /* Initialize the driver internal SLI layer lists. */
  3092. lpfc_sli_setup(phba);
  3093. lpfc_sli_queue_setup(phba);
  3094. /* Allocate device driver memory */
  3095. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  3096. if (rc)
  3097. return -ENOMEM;
  3098. /* Create the bootstrap mailbox command */
  3099. rc = lpfc_create_bootstrap_mbox(phba);
  3100. if (unlikely(rc))
  3101. goto out_free_mem;
  3102. /* Set up the host's endian order with the device. */
  3103. rc = lpfc_setup_endian_order(phba);
  3104. if (unlikely(rc))
  3105. goto out_free_bsmbx;
  3106. /* Set up the hba's configuration parameters. */
  3107. rc = lpfc_sli4_read_config(phba);
  3108. if (unlikely(rc))
  3109. goto out_free_bsmbx;
  3110. /* Perform a function reset */
  3111. rc = lpfc_pci_function_reset(phba);
  3112. if (unlikely(rc))
  3113. goto out_free_bsmbx;
  3114. /* Create all the SLI4 queues */
  3115. rc = lpfc_sli4_queue_create(phba);
  3116. if (rc)
  3117. goto out_free_bsmbx;
  3118. /* Create driver internal CQE event pool */
  3119. rc = lpfc_sli4_cq_event_pool_create(phba);
  3120. if (rc)
  3121. goto out_destroy_queue;
  3122. /* Initialize and populate the iocb list per host */
  3123. rc = lpfc_init_sgl_list(phba);
  3124. if (rc) {
  3125. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3126. "1400 Failed to initialize sgl list.\n");
  3127. goto out_destroy_cq_event_pool;
  3128. }
  3129. rc = lpfc_init_active_sgl_array(phba);
  3130. if (rc) {
  3131. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3132. "1430 Failed to initialize sgl list.\n");
  3133. goto out_free_sgl_list;
  3134. }
  3135. rc = lpfc_sli4_init_rpi_hdrs(phba);
  3136. if (rc) {
  3137. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3138. "1432 Failed to initialize rpi headers.\n");
  3139. goto out_free_active_sgl;
  3140. }
  3141. phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  3142. phba->cfg_fcp_eq_count), GFP_KERNEL);
  3143. if (!phba->sli4_hba.fcp_eq_hdl) {
  3144. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3145. "2572 Failed allocate memory for fast-path "
  3146. "per-EQ handle array\n");
  3147. goto out_remove_rpi_hdrs;
  3148. }
  3149. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  3150. phba->sli4_hba.cfg_eqn), GFP_KERNEL);
  3151. if (!phba->sli4_hba.msix_entries) {
  3152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3153. "2573 Failed allocate memory for msi-x "
  3154. "interrupt vector entries\n");
  3155. goto out_free_fcp_eq_hdl;
  3156. }
  3157. return rc;
  3158. out_free_fcp_eq_hdl:
  3159. kfree(phba->sli4_hba.fcp_eq_hdl);
  3160. out_remove_rpi_hdrs:
  3161. lpfc_sli4_remove_rpi_hdrs(phba);
  3162. out_free_active_sgl:
  3163. lpfc_free_active_sgl(phba);
  3164. out_free_sgl_list:
  3165. lpfc_free_sgl_list(phba);
  3166. out_destroy_cq_event_pool:
  3167. lpfc_sli4_cq_event_pool_destroy(phba);
  3168. out_destroy_queue:
  3169. lpfc_sli4_queue_destroy(phba);
  3170. out_free_bsmbx:
  3171. lpfc_destroy_bootstrap_mbox(phba);
  3172. out_free_mem:
  3173. lpfc_mem_free(phba);
  3174. return rc;
  3175. }
  3176. /**
  3177. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  3178. * @phba: pointer to lpfc hba data structure.
  3179. *
  3180. * This routine is invoked to unset the driver internal resources set up
  3181. * specific for supporting the SLI-4 HBA device it attached to.
  3182. **/
  3183. static void
  3184. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  3185. {
  3186. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  3187. /* unregister default FCFI from the HBA */
  3188. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  3189. /* Free the default FCR table */
  3190. lpfc_sli_remove_dflt_fcf(phba);
  3191. /* Free memory allocated for msi-x interrupt vector entries */
  3192. kfree(phba->sli4_hba.msix_entries);
  3193. /* Free memory allocated for fast-path work queue handles */
  3194. kfree(phba->sli4_hba.fcp_eq_hdl);
  3195. /* Free the allocated rpi headers. */
  3196. lpfc_sli4_remove_rpi_hdrs(phba);
  3197. /* Free the ELS sgl list */
  3198. lpfc_free_active_sgl(phba);
  3199. lpfc_free_sgl_list(phba);
  3200. /* Free the SCSI sgl management array */
  3201. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  3202. /* Free the SLI4 queues */
  3203. lpfc_sli4_queue_destroy(phba);
  3204. /* Free the completion queue EQ event pool */
  3205. lpfc_sli4_cq_event_release_all(phba);
  3206. lpfc_sli4_cq_event_pool_destroy(phba);
  3207. /* Reset SLI4 HBA FCoE function */
  3208. lpfc_pci_function_reset(phba);
  3209. /* Free the bsmbx region. */
  3210. lpfc_destroy_bootstrap_mbox(phba);
  3211. /* Free the SLI Layer memory with SLI4 HBAs */
  3212. lpfc_mem_free_all(phba);
  3213. /* Free the current connect table */
  3214. list_for_each_entry_safe(conn_entry, next_conn_entry,
  3215. &phba->fcf_conn_rec_list, list)
  3216. kfree(conn_entry);
  3217. return;
  3218. }
  3219. /**
  3220. * lpfc_init_api_table_setup - Set up init api fucntion jump table
  3221. * @phba: The hba struct for which this call is being executed.
  3222. * @dev_grp: The HBA PCI-Device group number.
  3223. *
  3224. * This routine sets up the device INIT interface API function jump table
  3225. * in @phba struct.
  3226. *
  3227. * Returns: 0 - success, -ENODEV - failure.
  3228. **/
  3229. int
  3230. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  3231. {
  3232. switch (dev_grp) {
  3233. case LPFC_PCI_DEV_LP:
  3234. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  3235. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  3236. phba->lpfc_stop_port = lpfc_stop_port_s3;
  3237. break;
  3238. case LPFC_PCI_DEV_OC:
  3239. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  3240. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  3241. phba->lpfc_stop_port = lpfc_stop_port_s4;
  3242. break;
  3243. default:
  3244. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3245. "1431 Invalid HBA PCI-device group: 0x%x\n",
  3246. dev_grp);
  3247. return -ENODEV;
  3248. break;
  3249. }
  3250. return 0;
  3251. }
  3252. /**
  3253. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  3254. * @phba: pointer to lpfc hba data structure.
  3255. *
  3256. * This routine is invoked to set up the driver internal resources before the
  3257. * device specific resource setup to support the HBA device it attached to.
  3258. *
  3259. * Return codes
  3260. * 0 - sucessful
  3261. * other values - error
  3262. **/
  3263. static int
  3264. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  3265. {
  3266. /*
  3267. * Driver resources common to all SLI revisions
  3268. */
  3269. atomic_set(&phba->fast_event_count, 0);
  3270. spin_lock_init(&phba->hbalock);
  3271. /* Initialize ndlp management spinlock */
  3272. spin_lock_init(&phba->ndlp_lock);
  3273. INIT_LIST_HEAD(&phba->port_list);
  3274. INIT_LIST_HEAD(&phba->work_list);
  3275. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  3276. /* Initialize the wait queue head for the kernel thread */
  3277. init_waitqueue_head(&phba->work_waitq);
  3278. /* Initialize the scsi buffer list used by driver for scsi IO */
  3279. spin_lock_init(&phba->scsi_buf_list_lock);
  3280. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  3281. /* Initialize the fabric iocb list */
  3282. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  3283. /* Initialize list to save ELS buffers */
  3284. INIT_LIST_HEAD(&phba->elsbuf);
  3285. /* Initialize FCF connection rec list */
  3286. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  3287. return 0;
  3288. }
  3289. /**
  3290. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  3291. * @phba: pointer to lpfc hba data structure.
  3292. *
  3293. * This routine is invoked to set up the driver internal resources after the
  3294. * device specific resource setup to support the HBA device it attached to.
  3295. *
  3296. * Return codes
  3297. * 0 - sucessful
  3298. * other values - error
  3299. **/
  3300. static int
  3301. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  3302. {
  3303. int error;
  3304. /* Startup the kernel thread for this host adapter. */
  3305. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  3306. "lpfc_worker_%d", phba->brd_no);
  3307. if (IS_ERR(phba->worker_thread)) {
  3308. error = PTR_ERR(phba->worker_thread);
  3309. return error;
  3310. }
  3311. return 0;
  3312. }
  3313. /**
  3314. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  3315. * @phba: pointer to lpfc hba data structure.
  3316. *
  3317. * This routine is invoked to unset the driver internal resources set up after
  3318. * the device specific resource setup for supporting the HBA device it
  3319. * attached to.
  3320. **/
  3321. static void
  3322. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  3323. {
  3324. /* Stop kernel worker thread */
  3325. kthread_stop(phba->worker_thread);
  3326. }
  3327. /**
  3328. * lpfc_free_iocb_list - Free iocb list.
  3329. * @phba: pointer to lpfc hba data structure.
  3330. *
  3331. * This routine is invoked to free the driver's IOCB list and memory.
  3332. **/
  3333. static void
  3334. lpfc_free_iocb_list(struct lpfc_hba *phba)
  3335. {
  3336. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  3337. spin_lock_irq(&phba->hbalock);
  3338. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  3339. &phba->lpfc_iocb_list, list) {
  3340. list_del(&iocbq_entry->list);
  3341. kfree(iocbq_entry);
  3342. phba->total_iocbq_bufs--;
  3343. }
  3344. spin_unlock_irq(&phba->hbalock);
  3345. return;
  3346. }
  3347. /**
  3348. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  3349. * @phba: pointer to lpfc hba data structure.
  3350. *
  3351. * This routine is invoked to allocate and initizlize the driver's IOCB
  3352. * list and set up the IOCB tag array accordingly.
  3353. *
  3354. * Return codes
  3355. * 0 - sucessful
  3356. * other values - error
  3357. **/
  3358. static int
  3359. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  3360. {
  3361. struct lpfc_iocbq *iocbq_entry = NULL;
  3362. uint16_t iotag;
  3363. int i;
  3364. /* Initialize and populate the iocb list per host. */
  3365. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  3366. for (i = 0; i < iocb_count; i++) {
  3367. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  3368. if (iocbq_entry == NULL) {
  3369. printk(KERN_ERR "%s: only allocated %d iocbs of "
  3370. "expected %d count. Unloading driver.\n",
  3371. __func__, i, LPFC_IOCB_LIST_CNT);
  3372. goto out_free_iocbq;
  3373. }
  3374. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  3375. if (iotag == 0) {
  3376. kfree(iocbq_entry);
  3377. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  3378. "Unloading driver.\n", __func__);
  3379. goto out_free_iocbq;
  3380. }
  3381. iocbq_entry->sli4_xritag = NO_XRI;
  3382. spin_lock_irq(&phba->hbalock);
  3383. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  3384. phba->total_iocbq_bufs++;
  3385. spin_unlock_irq(&phba->hbalock);
  3386. }
  3387. return 0;
  3388. out_free_iocbq:
  3389. lpfc_free_iocb_list(phba);
  3390. return -ENOMEM;
  3391. }
  3392. /**
  3393. * lpfc_free_sgl_list - Free sgl list.
  3394. * @phba: pointer to lpfc hba data structure.
  3395. *
  3396. * This routine is invoked to free the driver's sgl list and memory.
  3397. **/
  3398. static void
  3399. lpfc_free_sgl_list(struct lpfc_hba *phba)
  3400. {
  3401. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  3402. LIST_HEAD(sglq_list);
  3403. int rc = 0;
  3404. spin_lock_irq(&phba->hbalock);
  3405. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  3406. spin_unlock_irq(&phba->hbalock);
  3407. list_for_each_entry_safe(sglq_entry, sglq_next,
  3408. &sglq_list, list) {
  3409. list_del(&sglq_entry->list);
  3410. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  3411. kfree(sglq_entry);
  3412. phba->sli4_hba.total_sglq_bufs--;
  3413. }
  3414. rc = lpfc_sli4_remove_all_sgl_pages(phba);
  3415. if (rc) {
  3416. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3417. "2005 Unable to deregister pages from HBA: %x", rc);
  3418. }
  3419. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  3420. }
  3421. /**
  3422. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  3423. * @phba: pointer to lpfc hba data structure.
  3424. *
  3425. * This routine is invoked to allocate the driver's active sgl memory.
  3426. * This array will hold the sglq_entry's for active IOs.
  3427. **/
  3428. static int
  3429. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  3430. {
  3431. int size;
  3432. size = sizeof(struct lpfc_sglq *);
  3433. size *= phba->sli4_hba.max_cfg_param.max_xri;
  3434. phba->sli4_hba.lpfc_sglq_active_list =
  3435. kzalloc(size, GFP_KERNEL);
  3436. if (!phba->sli4_hba.lpfc_sglq_active_list)
  3437. return -ENOMEM;
  3438. return 0;
  3439. }
  3440. /**
  3441. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  3442. * @phba: pointer to lpfc hba data structure.
  3443. *
  3444. * This routine is invoked to walk through the array of active sglq entries
  3445. * and free all of the resources.
  3446. * This is just a place holder for now.
  3447. **/
  3448. static void
  3449. lpfc_free_active_sgl(struct lpfc_hba *phba)
  3450. {
  3451. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  3452. }
  3453. /**
  3454. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  3455. * @phba: pointer to lpfc hba data structure.
  3456. *
  3457. * This routine is invoked to allocate and initizlize the driver's sgl
  3458. * list and set up the sgl xritag tag array accordingly.
  3459. *
  3460. * Return codes
  3461. * 0 - sucessful
  3462. * other values - error
  3463. **/
  3464. static int
  3465. lpfc_init_sgl_list(struct lpfc_hba *phba)
  3466. {
  3467. struct lpfc_sglq *sglq_entry = NULL;
  3468. int i;
  3469. int els_xri_cnt;
  3470. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  3471. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3472. "2400 lpfc_init_sgl_list els %d.\n",
  3473. els_xri_cnt);
  3474. /* Initialize and populate the sglq list per host/VF. */
  3475. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  3476. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  3477. /* Sanity check on XRI management */
  3478. if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
  3479. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3480. "2562 No room left for SCSI XRI allocation: "
  3481. "max_xri=%d, els_xri=%d\n",
  3482. phba->sli4_hba.max_cfg_param.max_xri,
  3483. els_xri_cnt);
  3484. return -ENOMEM;
  3485. }
  3486. /* Allocate memory for the ELS XRI management array */
  3487. phba->sli4_hba.lpfc_els_sgl_array =
  3488. kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
  3489. GFP_KERNEL);
  3490. if (!phba->sli4_hba.lpfc_els_sgl_array) {
  3491. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3492. "2401 Failed to allocate memory for ELS "
  3493. "XRI management array of size %d.\n",
  3494. els_xri_cnt);
  3495. return -ENOMEM;
  3496. }
  3497. /* Keep the SCSI XRI into the XRI management array */
  3498. phba->sli4_hba.scsi_xri_max =
  3499. phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  3500. phba->sli4_hba.scsi_xri_cnt = 0;
  3501. phba->sli4_hba.lpfc_scsi_psb_array =
  3502. kzalloc((sizeof(struct lpfc_scsi_buf *) *
  3503. phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
  3504. if (!phba->sli4_hba.lpfc_scsi_psb_array) {
  3505. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3506. "2563 Failed to allocate memory for SCSI "
  3507. "XRI management array of size %d.\n",
  3508. phba->sli4_hba.scsi_xri_max);
  3509. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  3510. return -ENOMEM;
  3511. }
  3512. for (i = 0; i < els_xri_cnt; i++) {
  3513. sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
  3514. if (sglq_entry == NULL) {
  3515. printk(KERN_ERR "%s: only allocated %d sgls of "
  3516. "expected %d count. Unloading driver.\n",
  3517. __func__, i, els_xri_cnt);
  3518. goto out_free_mem;
  3519. }
  3520. sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
  3521. if (sglq_entry->sli4_xritag == NO_XRI) {
  3522. kfree(sglq_entry);
  3523. printk(KERN_ERR "%s: failed to allocate XRI.\n"
  3524. "Unloading driver.\n", __func__);
  3525. goto out_free_mem;
  3526. }
  3527. sglq_entry->buff_type = GEN_BUFF_TYPE;
  3528. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
  3529. if (sglq_entry->virt == NULL) {
  3530. kfree(sglq_entry);
  3531. printk(KERN_ERR "%s: failed to allocate mbuf.\n"
  3532. "Unloading driver.\n", __func__);
  3533. goto out_free_mem;
  3534. }
  3535. sglq_entry->sgl = sglq_entry->virt;
  3536. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  3537. /* The list order is used by later block SGL registraton */
  3538. spin_lock_irq(&phba->hbalock);
  3539. list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
  3540. phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
  3541. phba->sli4_hba.total_sglq_bufs++;
  3542. spin_unlock_irq(&phba->hbalock);
  3543. }
  3544. return 0;
  3545. out_free_mem:
  3546. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  3547. lpfc_free_sgl_list(phba);
  3548. return -ENOMEM;
  3549. }
  3550. /**
  3551. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  3552. * @phba: pointer to lpfc hba data structure.
  3553. *
  3554. * This routine is invoked to post rpi header templates to the
  3555. * HBA consistent with the SLI-4 interface spec. This routine
  3556. * posts a PAGE_SIZE memory region to the port to hold up to
  3557. * PAGE_SIZE modulo 64 rpi context headers.
  3558. * No locks are held here because this is an initialization routine
  3559. * called only from probe or lpfc_online when interrupts are not
  3560. * enabled and the driver is reinitializing the device.
  3561. *
  3562. * Return codes
  3563. * 0 - sucessful
  3564. * ENOMEM - No availble memory
  3565. * EIO - The mailbox failed to complete successfully.
  3566. **/
  3567. int
  3568. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  3569. {
  3570. int rc = 0;
  3571. int longs;
  3572. uint16_t rpi_count;
  3573. struct lpfc_rpi_hdr *rpi_hdr;
  3574. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  3575. /*
  3576. * Provision an rpi bitmask range for discovery. The total count
  3577. * is the difference between max and base + 1.
  3578. */
  3579. rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
  3580. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  3581. longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  3582. phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
  3583. GFP_KERNEL);
  3584. if (!phba->sli4_hba.rpi_bmask)
  3585. return -ENOMEM;
  3586. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  3587. if (!rpi_hdr) {
  3588. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3589. "0391 Error during rpi post operation\n");
  3590. lpfc_sli4_remove_rpis(phba);
  3591. rc = -ENODEV;
  3592. }
  3593. return rc;
  3594. }
  3595. /**
  3596. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  3597. * @phba: pointer to lpfc hba data structure.
  3598. *
  3599. * This routine is invoked to allocate a single 4KB memory region to
  3600. * support rpis and stores them in the phba. This single region
  3601. * provides support for up to 64 rpis. The region is used globally
  3602. * by the device.
  3603. *
  3604. * Returns:
  3605. * A valid rpi hdr on success.
  3606. * A NULL pointer on any failure.
  3607. **/
  3608. struct lpfc_rpi_hdr *
  3609. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  3610. {
  3611. uint16_t rpi_limit, curr_rpi_range;
  3612. struct lpfc_dmabuf *dmabuf;
  3613. struct lpfc_rpi_hdr *rpi_hdr;
  3614. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  3615. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  3616. spin_lock_irq(&phba->hbalock);
  3617. curr_rpi_range = phba->sli4_hba.next_rpi;
  3618. spin_unlock_irq(&phba->hbalock);
  3619. /*
  3620. * The port has a limited number of rpis. The increment here
  3621. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  3622. * and to allow the full max_rpi range per port.
  3623. */
  3624. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  3625. return NULL;
  3626. /*
  3627. * First allocate the protocol header region for the port. The
  3628. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  3629. */
  3630. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3631. if (!dmabuf)
  3632. return NULL;
  3633. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3634. LPFC_HDR_TEMPLATE_SIZE,
  3635. &dmabuf->phys,
  3636. GFP_KERNEL);
  3637. if (!dmabuf->virt) {
  3638. rpi_hdr = NULL;
  3639. goto err_free_dmabuf;
  3640. }
  3641. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  3642. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  3643. rpi_hdr = NULL;
  3644. goto err_free_coherent;
  3645. }
  3646. /* Save the rpi header data for cleanup later. */
  3647. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  3648. if (!rpi_hdr)
  3649. goto err_free_coherent;
  3650. rpi_hdr->dmabuf = dmabuf;
  3651. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  3652. rpi_hdr->page_count = 1;
  3653. spin_lock_irq(&phba->hbalock);
  3654. rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
  3655. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  3656. /*
  3657. * The next_rpi stores the next module-64 rpi value to post
  3658. * in any subsequent rpi memory region postings.
  3659. */
  3660. phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
  3661. spin_unlock_irq(&phba->hbalock);
  3662. return rpi_hdr;
  3663. err_free_coherent:
  3664. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  3665. dmabuf->virt, dmabuf->phys);
  3666. err_free_dmabuf:
  3667. kfree(dmabuf);
  3668. return NULL;
  3669. }
  3670. /**
  3671. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  3672. * @phba: pointer to lpfc hba data structure.
  3673. *
  3674. * This routine is invoked to remove all memory resources allocated
  3675. * to support rpis. This routine presumes the caller has released all
  3676. * rpis consumed by fabric or port logins and is prepared to have
  3677. * the header pages removed.
  3678. **/
  3679. void
  3680. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  3681. {
  3682. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  3683. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  3684. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  3685. list_del(&rpi_hdr->list);
  3686. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  3687. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  3688. kfree(rpi_hdr->dmabuf);
  3689. kfree(rpi_hdr);
  3690. }
  3691. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  3692. memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
  3693. }
  3694. /**
  3695. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  3696. * @pdev: pointer to pci device data structure.
  3697. *
  3698. * This routine is invoked to allocate the driver hba data structure for an
  3699. * HBA device. If the allocation is successful, the phba reference to the
  3700. * PCI device data structure is set.
  3701. *
  3702. * Return codes
  3703. * pointer to @phba - sucessful
  3704. * NULL - error
  3705. **/
  3706. static struct lpfc_hba *
  3707. lpfc_hba_alloc(struct pci_dev *pdev)
  3708. {
  3709. struct lpfc_hba *phba;
  3710. /* Allocate memory for HBA structure */
  3711. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  3712. if (!phba) {
  3713. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3714. "1417 Failed to allocate hba struct.\n");
  3715. return NULL;
  3716. }
  3717. /* Set reference to PCI device in HBA structure */
  3718. phba->pcidev = pdev;
  3719. /* Assign an unused board number */
  3720. phba->brd_no = lpfc_get_instance();
  3721. if (phba->brd_no < 0) {
  3722. kfree(phba);
  3723. return NULL;
  3724. }
  3725. return phba;
  3726. }
  3727. /**
  3728. * lpfc_hba_free - Free driver hba data structure with a device.
  3729. * @phba: pointer to lpfc hba data structure.
  3730. *
  3731. * This routine is invoked to free the driver hba data structure with an
  3732. * HBA device.
  3733. **/
  3734. static void
  3735. lpfc_hba_free(struct lpfc_hba *phba)
  3736. {
  3737. /* Release the driver assigned board number */
  3738. idr_remove(&lpfc_hba_index, phba->brd_no);
  3739. kfree(phba);
  3740. return;
  3741. }
  3742. /**
  3743. * lpfc_create_shost - Create hba physical port with associated scsi host.
  3744. * @phba: pointer to lpfc hba data structure.
  3745. *
  3746. * This routine is invoked to create HBA physical port and associate a SCSI
  3747. * host with it.
  3748. *
  3749. * Return codes
  3750. * 0 - sucessful
  3751. * other values - error
  3752. **/
  3753. static int
  3754. lpfc_create_shost(struct lpfc_hba *phba)
  3755. {
  3756. struct lpfc_vport *vport;
  3757. struct Scsi_Host *shost;
  3758. /* Initialize HBA FC structure */
  3759. phba->fc_edtov = FF_DEF_EDTOV;
  3760. phba->fc_ratov = FF_DEF_RATOV;
  3761. phba->fc_altov = FF_DEF_ALTOV;
  3762. phba->fc_arbtov = FF_DEF_ARBTOV;
  3763. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  3764. if (!vport)
  3765. return -ENODEV;
  3766. shost = lpfc_shost_from_vport(vport);
  3767. phba->pport = vport;
  3768. lpfc_debugfs_initialize(vport);
  3769. /* Put reference to SCSI host to driver's device private data */
  3770. pci_set_drvdata(phba->pcidev, shost);
  3771. return 0;
  3772. }
  3773. /**
  3774. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  3775. * @phba: pointer to lpfc hba data structure.
  3776. *
  3777. * This routine is invoked to destroy HBA physical port and the associated
  3778. * SCSI host.
  3779. **/
  3780. static void
  3781. lpfc_destroy_shost(struct lpfc_hba *phba)
  3782. {
  3783. struct lpfc_vport *vport = phba->pport;
  3784. /* Destroy physical port that associated with the SCSI host */
  3785. destroy_port(vport);
  3786. return;
  3787. }
  3788. /**
  3789. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  3790. * @phba: pointer to lpfc hba data structure.
  3791. * @shost: the shost to be used to detect Block guard settings.
  3792. *
  3793. * This routine sets up the local Block guard protocol settings for @shost.
  3794. * This routine also allocates memory for debugging bg buffers.
  3795. **/
  3796. static void
  3797. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  3798. {
  3799. int pagecnt = 10;
  3800. if (lpfc_prot_mask && lpfc_prot_guard) {
  3801. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3802. "1478 Registering BlockGuard with the "
  3803. "SCSI layer\n");
  3804. scsi_host_set_prot(shost, lpfc_prot_mask);
  3805. scsi_host_set_guard(shost, lpfc_prot_guard);
  3806. }
  3807. if (!_dump_buf_data) {
  3808. while (pagecnt) {
  3809. spin_lock_init(&_dump_buf_lock);
  3810. _dump_buf_data =
  3811. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  3812. if (_dump_buf_data) {
  3813. printk(KERN_ERR "BLKGRD allocated %d pages for "
  3814. "_dump_buf_data at 0x%p\n",
  3815. (1 << pagecnt), _dump_buf_data);
  3816. _dump_buf_data_order = pagecnt;
  3817. memset(_dump_buf_data, 0,
  3818. ((1 << PAGE_SHIFT) << pagecnt));
  3819. break;
  3820. } else
  3821. --pagecnt;
  3822. }
  3823. if (!_dump_buf_data_order)
  3824. printk(KERN_ERR "BLKGRD ERROR unable to allocate "
  3825. "memory for hexdump\n");
  3826. } else
  3827. printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p"
  3828. "\n", _dump_buf_data);
  3829. if (!_dump_buf_dif) {
  3830. while (pagecnt) {
  3831. _dump_buf_dif =
  3832. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  3833. if (_dump_buf_dif) {
  3834. printk(KERN_ERR "BLKGRD allocated %d pages for "
  3835. "_dump_buf_dif at 0x%p\n",
  3836. (1 << pagecnt), _dump_buf_dif);
  3837. _dump_buf_dif_order = pagecnt;
  3838. memset(_dump_buf_dif, 0,
  3839. ((1 << PAGE_SHIFT) << pagecnt));
  3840. break;
  3841. } else
  3842. --pagecnt;
  3843. }
  3844. if (!_dump_buf_dif_order)
  3845. printk(KERN_ERR "BLKGRD ERROR unable to allocate "
  3846. "memory for hexdump\n");
  3847. } else
  3848. printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n",
  3849. _dump_buf_dif);
  3850. }
  3851. /**
  3852. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  3853. * @phba: pointer to lpfc hba data structure.
  3854. *
  3855. * This routine is invoked to perform all the necessary post initialization
  3856. * setup for the device.
  3857. **/
  3858. static void
  3859. lpfc_post_init_setup(struct lpfc_hba *phba)
  3860. {
  3861. struct Scsi_Host *shost;
  3862. struct lpfc_adapter_event_header adapter_event;
  3863. /* Get the default values for Model Name and Description */
  3864. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  3865. /*
  3866. * hba setup may have changed the hba_queue_depth so we need to
  3867. * adjust the value of can_queue.
  3868. */
  3869. shost = pci_get_drvdata(phba->pcidev);
  3870. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  3871. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  3872. lpfc_setup_bg(phba, shost);
  3873. lpfc_host_attrib_init(shost);
  3874. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  3875. spin_lock_irq(shost->host_lock);
  3876. lpfc_poll_start_timer(phba);
  3877. spin_unlock_irq(shost->host_lock);
  3878. }
  3879. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3880. "0428 Perform SCSI scan\n");
  3881. /* Send board arrival event to upper layer */
  3882. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  3883. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  3884. fc_host_post_vendor_event(shost, fc_get_event_number(),
  3885. sizeof(adapter_event),
  3886. (char *) &adapter_event,
  3887. LPFC_NL_VENDOR_ID);
  3888. return;
  3889. }
  3890. /**
  3891. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  3892. * @phba: pointer to lpfc hba data structure.
  3893. *
  3894. * This routine is invoked to set up the PCI device memory space for device
  3895. * with SLI-3 interface spec.
  3896. *
  3897. * Return codes
  3898. * 0 - sucessful
  3899. * other values - error
  3900. **/
  3901. static int
  3902. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  3903. {
  3904. struct pci_dev *pdev;
  3905. unsigned long bar0map_len, bar2map_len;
  3906. int i, hbq_count;
  3907. void *ptr;
  3908. int error = -ENODEV;
  3909. /* Obtain PCI device reference */
  3910. if (!phba->pcidev)
  3911. return error;
  3912. else
  3913. pdev = phba->pcidev;
  3914. /* Set the device DMA mask size */
  3915. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
  3916. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
  3917. return error;
  3918. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  3919. * required by each mapping.
  3920. */
  3921. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  3922. bar0map_len = pci_resource_len(pdev, 0);
  3923. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  3924. bar2map_len = pci_resource_len(pdev, 2);
  3925. /* Map HBA SLIM to a kernel virtual address. */
  3926. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  3927. if (!phba->slim_memmap_p) {
  3928. dev_printk(KERN_ERR, &pdev->dev,
  3929. "ioremap failed for SLIM memory.\n");
  3930. goto out;
  3931. }
  3932. /* Map HBA Control Registers to a kernel virtual address. */
  3933. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  3934. if (!phba->ctrl_regs_memmap_p) {
  3935. dev_printk(KERN_ERR, &pdev->dev,
  3936. "ioremap failed for HBA control registers.\n");
  3937. goto out_iounmap_slim;
  3938. }
  3939. /* Allocate memory for SLI-2 structures */
  3940. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  3941. SLI2_SLIM_SIZE,
  3942. &phba->slim2p.phys,
  3943. GFP_KERNEL);
  3944. if (!phba->slim2p.virt)
  3945. goto out_iounmap;
  3946. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  3947. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  3948. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  3949. phba->IOCBs = (phba->slim2p.virt +
  3950. offsetof(struct lpfc_sli2_slim, IOCBs));
  3951. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  3952. lpfc_sli_hbq_size(),
  3953. &phba->hbqslimp.phys,
  3954. GFP_KERNEL);
  3955. if (!phba->hbqslimp.virt)
  3956. goto out_free_slim;
  3957. hbq_count = lpfc_sli_hbq_count();
  3958. ptr = phba->hbqslimp.virt;
  3959. for (i = 0; i < hbq_count; ++i) {
  3960. phba->hbqs[i].hbq_virt = ptr;
  3961. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  3962. ptr += (lpfc_hbq_defs[i]->entry_count *
  3963. sizeof(struct lpfc_hbq_entry));
  3964. }
  3965. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  3966. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  3967. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  3968. INIT_LIST_HEAD(&phba->rb_pend_list);
  3969. phba->MBslimaddr = phba->slim_memmap_p;
  3970. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  3971. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  3972. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  3973. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  3974. return 0;
  3975. out_free_slim:
  3976. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  3977. phba->slim2p.virt, phba->slim2p.phys);
  3978. out_iounmap:
  3979. iounmap(phba->ctrl_regs_memmap_p);
  3980. out_iounmap_slim:
  3981. iounmap(phba->slim_memmap_p);
  3982. out:
  3983. return error;
  3984. }
  3985. /**
  3986. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  3987. * @phba: pointer to lpfc hba data structure.
  3988. *
  3989. * This routine is invoked to unset the PCI device memory space for device
  3990. * with SLI-3 interface spec.
  3991. **/
  3992. static void
  3993. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  3994. {
  3995. struct pci_dev *pdev;
  3996. /* Obtain PCI device reference */
  3997. if (!phba->pcidev)
  3998. return;
  3999. else
  4000. pdev = phba->pcidev;
  4001. /* Free coherent DMA memory allocated */
  4002. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  4003. phba->hbqslimp.virt, phba->hbqslimp.phys);
  4004. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4005. phba->slim2p.virt, phba->slim2p.phys);
  4006. /* I/O memory unmap */
  4007. iounmap(phba->ctrl_regs_memmap_p);
  4008. iounmap(phba->slim_memmap_p);
  4009. return;
  4010. }
  4011. /**
  4012. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  4013. * @phba: pointer to lpfc hba data structure.
  4014. *
  4015. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  4016. * done and check status.
  4017. *
  4018. * Return 0 if successful, otherwise -ENODEV.
  4019. **/
  4020. int
  4021. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  4022. {
  4023. struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad;
  4024. uint32_t onlnreg0, onlnreg1;
  4025. int i, port_error = -ENODEV;
  4026. if (!phba->sli4_hba.STAregaddr)
  4027. return -ENODEV;
  4028. /* With uncoverable error, log the error message and return error */
  4029. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  4030. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  4031. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  4032. uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr);
  4033. uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr);
  4034. if (uerrlo_reg.word0 || uerrhi_reg.word0) {
  4035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4036. "1422 HBA Unrecoverable error: "
  4037. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  4038. "online0_reg=0x%x, online1_reg=0x%x\n",
  4039. uerrlo_reg.word0, uerrhi_reg.word0,
  4040. onlnreg0, onlnreg1);
  4041. }
  4042. return -ENODEV;
  4043. }
  4044. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  4045. for (i = 0; i < 3000; i++) {
  4046. sta_reg.word0 = readl(phba->sli4_hba.STAregaddr);
  4047. /* Encounter fatal POST error, break out */
  4048. if (bf_get(lpfc_hst_state_perr, &sta_reg)) {
  4049. port_error = -ENODEV;
  4050. break;
  4051. }
  4052. if (LPFC_POST_STAGE_ARMFW_READY ==
  4053. bf_get(lpfc_hst_state_port_status, &sta_reg)) {
  4054. port_error = 0;
  4055. break;
  4056. }
  4057. msleep(10);
  4058. }
  4059. if (port_error)
  4060. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4061. "1408 Failure HBA POST Status: sta_reg=0x%x, "
  4062. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
  4063. "dl=x%x, pstatus=x%x\n", sta_reg.word0,
  4064. bf_get(lpfc_hst_state_perr, &sta_reg),
  4065. bf_get(lpfc_hst_state_sfi, &sta_reg),
  4066. bf_get(lpfc_hst_state_nip, &sta_reg),
  4067. bf_get(lpfc_hst_state_ipc, &sta_reg),
  4068. bf_get(lpfc_hst_state_xrom, &sta_reg),
  4069. bf_get(lpfc_hst_state_dl, &sta_reg),
  4070. bf_get(lpfc_hst_state_port_status, &sta_reg));
  4071. /* Log device information */
  4072. scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr);
  4073. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4074. "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
  4075. "FeatureL1=0x%x, FeatureL2=0x%x\n",
  4076. bf_get(lpfc_scratchpad_chiptype, &scratchpad),
  4077. bf_get(lpfc_scratchpad_slirev, &scratchpad),
  4078. bf_get(lpfc_scratchpad_featurelevel1, &scratchpad),
  4079. bf_get(lpfc_scratchpad_featurelevel2, &scratchpad));
  4080. return port_error;
  4081. }
  4082. /**
  4083. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  4084. * @phba: pointer to lpfc hba data structure.
  4085. *
  4086. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  4087. * memory map.
  4088. **/
  4089. static void
  4090. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
  4091. {
  4092. phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4093. LPFC_UERR_STATUS_LO;
  4094. phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4095. LPFC_UERR_STATUS_HI;
  4096. phba->sli4_hba.ONLINE0regaddr = phba->sli4_hba.conf_regs_memmap_p +
  4097. LPFC_ONLINE0;
  4098. phba->sli4_hba.ONLINE1regaddr = phba->sli4_hba.conf_regs_memmap_p +
  4099. LPFC_ONLINE1;
  4100. phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4101. LPFC_SCRATCHPAD;
  4102. }
  4103. /**
  4104. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  4105. * @phba: pointer to lpfc hba data structure.
  4106. *
  4107. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  4108. * memory map.
  4109. **/
  4110. static void
  4111. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  4112. {
  4113. phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4114. LPFC_HST_STATE;
  4115. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4116. LPFC_HST_ISR0;
  4117. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4118. LPFC_HST_IMR0;
  4119. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4120. LPFC_HST_ISCR0;
  4121. return;
  4122. }
  4123. /**
  4124. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  4125. * @phba: pointer to lpfc hba data structure.
  4126. * @vf: virtual function number
  4127. *
  4128. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  4129. * based on the given viftual function number, @vf.
  4130. *
  4131. * Return 0 if successful, otherwise -ENODEV.
  4132. **/
  4133. static int
  4134. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  4135. {
  4136. if (vf > LPFC_VIR_FUNC_MAX)
  4137. return -ENODEV;
  4138. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4139. vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
  4140. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4141. vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
  4142. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4143. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  4144. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4145. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  4146. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4147. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  4148. return 0;
  4149. }
  4150. /**
  4151. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  4152. * @phba: pointer to lpfc hba data structure.
  4153. *
  4154. * This routine is invoked to create the bootstrap mailbox
  4155. * region consistent with the SLI-4 interface spec. This
  4156. * routine allocates all memory necessary to communicate
  4157. * mailbox commands to the port and sets up all alignment
  4158. * needs. No locks are expected to be held when calling
  4159. * this routine.
  4160. *
  4161. * Return codes
  4162. * 0 - sucessful
  4163. * ENOMEM - could not allocated memory.
  4164. **/
  4165. static int
  4166. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  4167. {
  4168. uint32_t bmbx_size;
  4169. struct lpfc_dmabuf *dmabuf;
  4170. struct dma_address *dma_address;
  4171. uint32_t pa_addr;
  4172. uint64_t phys_addr;
  4173. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4174. if (!dmabuf)
  4175. return -ENOMEM;
  4176. /*
  4177. * The bootstrap mailbox region is comprised of 2 parts
  4178. * plus an alignment restriction of 16 bytes.
  4179. */
  4180. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  4181. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4182. bmbx_size,
  4183. &dmabuf->phys,
  4184. GFP_KERNEL);
  4185. if (!dmabuf->virt) {
  4186. kfree(dmabuf);
  4187. return -ENOMEM;
  4188. }
  4189. memset(dmabuf->virt, 0, bmbx_size);
  4190. /*
  4191. * Initialize the bootstrap mailbox pointers now so that the register
  4192. * operations are simple later. The mailbox dma address is required
  4193. * to be 16-byte aligned. Also align the virtual memory as each
  4194. * maibox is copied into the bmbx mailbox region before issuing the
  4195. * command to the port.
  4196. */
  4197. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  4198. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  4199. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  4200. LPFC_ALIGN_16_BYTE);
  4201. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  4202. LPFC_ALIGN_16_BYTE);
  4203. /*
  4204. * Set the high and low physical addresses now. The SLI4 alignment
  4205. * requirement is 16 bytes and the mailbox is posted to the port
  4206. * as two 30-bit addresses. The other data is a bit marking whether
  4207. * the 30-bit address is the high or low address.
  4208. * Upcast bmbx aphys to 64bits so shift instruction compiles
  4209. * clean on 32 bit machines.
  4210. */
  4211. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4212. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  4213. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  4214. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  4215. LPFC_BMBX_BIT1_ADDR_HI);
  4216. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  4217. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  4218. LPFC_BMBX_BIT1_ADDR_LO);
  4219. return 0;
  4220. }
  4221. /**
  4222. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  4223. * @phba: pointer to lpfc hba data structure.
  4224. *
  4225. * This routine is invoked to teardown the bootstrap mailbox
  4226. * region and release all host resources. This routine requires
  4227. * the caller to ensure all mailbox commands recovered, no
  4228. * additional mailbox comands are sent, and interrupts are disabled
  4229. * before calling this routine.
  4230. *
  4231. **/
  4232. static void
  4233. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  4234. {
  4235. dma_free_coherent(&phba->pcidev->dev,
  4236. phba->sli4_hba.bmbx.bmbx_size,
  4237. phba->sli4_hba.bmbx.dmabuf->virt,
  4238. phba->sli4_hba.bmbx.dmabuf->phys);
  4239. kfree(phba->sli4_hba.bmbx.dmabuf);
  4240. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  4241. }
  4242. /**
  4243. * lpfc_sli4_read_config - Get the config parameters.
  4244. * @phba: pointer to lpfc hba data structure.
  4245. *
  4246. * This routine is invoked to read the configuration parameters from the HBA.
  4247. * The configuration parameters are used to set the base and maximum values
  4248. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  4249. * allocation for the port.
  4250. *
  4251. * Return codes
  4252. * 0 - sucessful
  4253. * ENOMEM - No availble memory
  4254. * EIO - The mailbox failed to complete successfully.
  4255. **/
  4256. static int
  4257. lpfc_sli4_read_config(struct lpfc_hba *phba)
  4258. {
  4259. LPFC_MBOXQ_t *pmb;
  4260. struct lpfc_mbx_read_config *rd_config;
  4261. uint32_t rc = 0;
  4262. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4263. if (!pmb) {
  4264. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4265. "2011 Unable to allocate memory for issuing "
  4266. "SLI_CONFIG_SPECIAL mailbox command\n");
  4267. return -ENOMEM;
  4268. }
  4269. lpfc_read_config(phba, pmb);
  4270. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4271. if (rc != MBX_SUCCESS) {
  4272. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4273. "2012 Mailbox failed , mbxCmd x%x "
  4274. "READ_CONFIG, mbxStatus x%x\n",
  4275. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  4276. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  4277. rc = -EIO;
  4278. } else {
  4279. rd_config = &pmb->u.mqe.un.rd_config;
  4280. phba->sli4_hba.max_cfg_param.max_xri =
  4281. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  4282. phba->sli4_hba.max_cfg_param.xri_base =
  4283. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  4284. phba->sli4_hba.max_cfg_param.max_vpi =
  4285. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  4286. phba->sli4_hba.max_cfg_param.vpi_base =
  4287. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  4288. phba->sli4_hba.max_cfg_param.max_rpi =
  4289. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  4290. phba->sli4_hba.max_cfg_param.rpi_base =
  4291. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  4292. phba->sli4_hba.max_cfg_param.max_vfi =
  4293. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  4294. phba->sli4_hba.max_cfg_param.vfi_base =
  4295. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  4296. phba->sli4_hba.max_cfg_param.max_fcfi =
  4297. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  4298. phba->sli4_hba.max_cfg_param.fcfi_base =
  4299. bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
  4300. phba->sli4_hba.max_cfg_param.max_eq =
  4301. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  4302. phba->sli4_hba.max_cfg_param.max_rq =
  4303. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  4304. phba->sli4_hba.max_cfg_param.max_wq =
  4305. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  4306. phba->sli4_hba.max_cfg_param.max_cq =
  4307. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  4308. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  4309. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  4310. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  4311. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  4312. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  4313. phba->max_vpi = phba->sli4_hba.max_cfg_param.max_vpi;
  4314. phba->max_vports = phba->max_vpi;
  4315. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4316. "2003 cfg params XRI(B:%d M:%d), "
  4317. "VPI(B:%d M:%d) "
  4318. "VFI(B:%d M:%d) "
  4319. "RPI(B:%d M:%d) "
  4320. "FCFI(B:%d M:%d)\n",
  4321. phba->sli4_hba.max_cfg_param.xri_base,
  4322. phba->sli4_hba.max_cfg_param.max_xri,
  4323. phba->sli4_hba.max_cfg_param.vpi_base,
  4324. phba->sli4_hba.max_cfg_param.max_vpi,
  4325. phba->sli4_hba.max_cfg_param.vfi_base,
  4326. phba->sli4_hba.max_cfg_param.max_vfi,
  4327. phba->sli4_hba.max_cfg_param.rpi_base,
  4328. phba->sli4_hba.max_cfg_param.max_rpi,
  4329. phba->sli4_hba.max_cfg_param.fcfi_base,
  4330. phba->sli4_hba.max_cfg_param.max_fcfi);
  4331. }
  4332. mempool_free(pmb, phba->mbox_mem_pool);
  4333. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  4334. if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri))
  4335. phba->cfg_hba_queue_depth =
  4336. phba->sli4_hba.max_cfg_param.max_xri;
  4337. return rc;
  4338. }
  4339. /**
  4340. * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
  4341. * @phba: pointer to lpfc hba data structure.
  4342. *
  4343. * This routine is invoked to setup the host-side endian order to the
  4344. * HBA consistent with the SLI-4 interface spec.
  4345. *
  4346. * Return codes
  4347. * 0 - sucessful
  4348. * ENOMEM - No availble memory
  4349. * EIO - The mailbox failed to complete successfully.
  4350. **/
  4351. static int
  4352. lpfc_setup_endian_order(struct lpfc_hba *phba)
  4353. {
  4354. LPFC_MBOXQ_t *mboxq;
  4355. uint32_t rc = 0;
  4356. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  4357. HOST_ENDIAN_HIGH_WORD1};
  4358. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4359. if (!mboxq) {
  4360. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4361. "0492 Unable to allocate memory for issuing "
  4362. "SLI_CONFIG_SPECIAL mailbox command\n");
  4363. return -ENOMEM;
  4364. }
  4365. /*
  4366. * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
  4367. * words to contain special data values and no other data.
  4368. */
  4369. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  4370. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  4371. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4372. if (rc != MBX_SUCCESS) {
  4373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4374. "0493 SLI_CONFIG_SPECIAL mailbox failed with "
  4375. "status x%x\n",
  4376. rc);
  4377. rc = -EIO;
  4378. }
  4379. mempool_free(mboxq, phba->mbox_mem_pool);
  4380. return rc;
  4381. }
  4382. /**
  4383. * lpfc_sli4_queue_create - Create all the SLI4 queues
  4384. * @phba: pointer to lpfc hba data structure.
  4385. *
  4386. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  4387. * operation. For each SLI4 queue type, the parameters such as queue entry
  4388. * count (queue depth) shall be taken from the module parameter. For now,
  4389. * we just use some constant number as place holder.
  4390. *
  4391. * Return codes
  4392. * 0 - sucessful
  4393. * ENOMEM - No availble memory
  4394. * EIO - The mailbox failed to complete successfully.
  4395. **/
  4396. static int
  4397. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  4398. {
  4399. struct lpfc_queue *qdesc;
  4400. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  4401. int cfg_fcp_wq_count;
  4402. int cfg_fcp_eq_count;
  4403. /*
  4404. * Sanity check for confiugred queue parameters against the run-time
  4405. * device parameters
  4406. */
  4407. /* Sanity check on FCP fast-path WQ parameters */
  4408. cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
  4409. if (cfg_fcp_wq_count >
  4410. (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
  4411. cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
  4412. LPFC_SP_WQN_DEF;
  4413. if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
  4414. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4415. "2581 Not enough WQs (%d) from "
  4416. "the pci function for supporting "
  4417. "FCP WQs (%d)\n",
  4418. phba->sli4_hba.max_cfg_param.max_wq,
  4419. phba->cfg_fcp_wq_count);
  4420. goto out_error;
  4421. }
  4422. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4423. "2582 Not enough WQs (%d) from the pci "
  4424. "function for supporting the requested "
  4425. "FCP WQs (%d), the actual FCP WQs can "
  4426. "be supported: %d\n",
  4427. phba->sli4_hba.max_cfg_param.max_wq,
  4428. phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
  4429. }
  4430. /* The actual number of FCP work queues adopted */
  4431. phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
  4432. /* Sanity check on FCP fast-path EQ parameters */
  4433. cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
  4434. if (cfg_fcp_eq_count >
  4435. (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
  4436. cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
  4437. LPFC_SP_EQN_DEF;
  4438. if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
  4439. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4440. "2574 Not enough EQs (%d) from the "
  4441. "pci function for supporting FCP "
  4442. "EQs (%d)\n",
  4443. phba->sli4_hba.max_cfg_param.max_eq,
  4444. phba->cfg_fcp_eq_count);
  4445. goto out_error;
  4446. }
  4447. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4448. "2575 Not enough EQs (%d) from the pci "
  4449. "function for supporting the requested "
  4450. "FCP EQs (%d), the actual FCP EQs can "
  4451. "be supported: %d\n",
  4452. phba->sli4_hba.max_cfg_param.max_eq,
  4453. phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
  4454. }
  4455. /* It does not make sense to have more EQs than WQs */
  4456. if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
  4457. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4458. "2593 The number of FCP EQs (%d) is more "
  4459. "than the number of FCP WQs (%d), take "
  4460. "the number of FCP EQs same as than of "
  4461. "WQs (%d)\n", cfg_fcp_eq_count,
  4462. phba->cfg_fcp_wq_count,
  4463. phba->cfg_fcp_wq_count);
  4464. cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
  4465. }
  4466. /* The actual number of FCP event queues adopted */
  4467. phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
  4468. /* The overall number of event queues used */
  4469. phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
  4470. /*
  4471. * Create Event Queues (EQs)
  4472. */
  4473. /* Get EQ depth from module parameter, fake the default for now */
  4474. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  4475. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  4476. /* Create slow path event queue */
  4477. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  4478. phba->sli4_hba.eq_ecount);
  4479. if (!qdesc) {
  4480. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4481. "0496 Failed allocate slow-path EQ\n");
  4482. goto out_error;
  4483. }
  4484. phba->sli4_hba.sp_eq = qdesc;
  4485. /* Create fast-path FCP Event Queue(s) */
  4486. phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
  4487. phba->cfg_fcp_eq_count), GFP_KERNEL);
  4488. if (!phba->sli4_hba.fp_eq) {
  4489. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4490. "2576 Failed allocate memory for fast-path "
  4491. "EQ record array\n");
  4492. goto out_free_sp_eq;
  4493. }
  4494. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  4495. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  4496. phba->sli4_hba.eq_ecount);
  4497. if (!qdesc) {
  4498. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4499. "0497 Failed allocate fast-path EQ\n");
  4500. goto out_free_fp_eq;
  4501. }
  4502. phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
  4503. }
  4504. /*
  4505. * Create Complete Queues (CQs)
  4506. */
  4507. /* Get CQ depth from module parameter, fake the default for now */
  4508. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  4509. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  4510. /* Create slow-path Mailbox Command Complete Queue */
  4511. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4512. phba->sli4_hba.cq_ecount);
  4513. if (!qdesc) {
  4514. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4515. "0500 Failed allocate slow-path mailbox CQ\n");
  4516. goto out_free_fp_eq;
  4517. }
  4518. phba->sli4_hba.mbx_cq = qdesc;
  4519. /* Create slow-path ELS Complete Queue */
  4520. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4521. phba->sli4_hba.cq_ecount);
  4522. if (!qdesc) {
  4523. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4524. "0501 Failed allocate slow-path ELS CQ\n");
  4525. goto out_free_mbx_cq;
  4526. }
  4527. phba->sli4_hba.els_cq = qdesc;
  4528. /* Create slow-path Unsolicited Receive Complete Queue */
  4529. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4530. phba->sli4_hba.cq_ecount);
  4531. if (!qdesc) {
  4532. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4533. "0502 Failed allocate slow-path USOL RX CQ\n");
  4534. goto out_free_els_cq;
  4535. }
  4536. phba->sli4_hba.rxq_cq = qdesc;
  4537. /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
  4538. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  4539. phba->cfg_fcp_eq_count), GFP_KERNEL);
  4540. if (!phba->sli4_hba.fcp_cq) {
  4541. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4542. "2577 Failed allocate memory for fast-path "
  4543. "CQ record array\n");
  4544. goto out_free_rxq_cq;
  4545. }
  4546. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  4547. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4548. phba->sli4_hba.cq_ecount);
  4549. if (!qdesc) {
  4550. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4551. "0499 Failed allocate fast-path FCP "
  4552. "CQ (%d)\n", fcp_cqidx);
  4553. goto out_free_fcp_cq;
  4554. }
  4555. phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
  4556. }
  4557. /* Create Mailbox Command Queue */
  4558. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  4559. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  4560. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  4561. phba->sli4_hba.mq_ecount);
  4562. if (!qdesc) {
  4563. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4564. "0505 Failed allocate slow-path MQ\n");
  4565. goto out_free_fcp_cq;
  4566. }
  4567. phba->sli4_hba.mbx_wq = qdesc;
  4568. /*
  4569. * Create all the Work Queues (WQs)
  4570. */
  4571. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  4572. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  4573. /* Create slow-path ELS Work Queue */
  4574. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  4575. phba->sli4_hba.wq_ecount);
  4576. if (!qdesc) {
  4577. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4578. "0504 Failed allocate slow-path ELS WQ\n");
  4579. goto out_free_mbx_wq;
  4580. }
  4581. phba->sli4_hba.els_wq = qdesc;
  4582. /* Create fast-path FCP Work Queue(s) */
  4583. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  4584. phba->cfg_fcp_wq_count), GFP_KERNEL);
  4585. if (!phba->sli4_hba.fcp_wq) {
  4586. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4587. "2578 Failed allocate memory for fast-path "
  4588. "WQ record array\n");
  4589. goto out_free_els_wq;
  4590. }
  4591. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  4592. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  4593. phba->sli4_hba.wq_ecount);
  4594. if (!qdesc) {
  4595. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4596. "0503 Failed allocate fast-path FCP "
  4597. "WQ (%d)\n", fcp_wqidx);
  4598. goto out_free_fcp_wq;
  4599. }
  4600. phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
  4601. }
  4602. /*
  4603. * Create Receive Queue (RQ)
  4604. */
  4605. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  4606. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  4607. /* Create Receive Queue for header */
  4608. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  4609. phba->sli4_hba.rq_ecount);
  4610. if (!qdesc) {
  4611. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4612. "0506 Failed allocate receive HRQ\n");
  4613. goto out_free_fcp_wq;
  4614. }
  4615. phba->sli4_hba.hdr_rq = qdesc;
  4616. /* Create Receive Queue for data */
  4617. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  4618. phba->sli4_hba.rq_ecount);
  4619. if (!qdesc) {
  4620. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4621. "0507 Failed allocate receive DRQ\n");
  4622. goto out_free_hdr_rq;
  4623. }
  4624. phba->sli4_hba.dat_rq = qdesc;
  4625. return 0;
  4626. out_free_hdr_rq:
  4627. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  4628. phba->sli4_hba.hdr_rq = NULL;
  4629. out_free_fcp_wq:
  4630. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
  4631. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
  4632. phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
  4633. }
  4634. kfree(phba->sli4_hba.fcp_wq);
  4635. out_free_els_wq:
  4636. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  4637. phba->sli4_hba.els_wq = NULL;
  4638. out_free_mbx_wq:
  4639. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  4640. phba->sli4_hba.mbx_wq = NULL;
  4641. out_free_fcp_cq:
  4642. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
  4643. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
  4644. phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
  4645. }
  4646. kfree(phba->sli4_hba.fcp_cq);
  4647. out_free_rxq_cq:
  4648. lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
  4649. phba->sli4_hba.rxq_cq = NULL;
  4650. out_free_els_cq:
  4651. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  4652. phba->sli4_hba.els_cq = NULL;
  4653. out_free_mbx_cq:
  4654. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  4655. phba->sli4_hba.mbx_cq = NULL;
  4656. out_free_fp_eq:
  4657. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
  4658. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
  4659. phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
  4660. }
  4661. kfree(phba->sli4_hba.fp_eq);
  4662. out_free_sp_eq:
  4663. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  4664. phba->sli4_hba.sp_eq = NULL;
  4665. out_error:
  4666. return -ENOMEM;
  4667. }
  4668. /**
  4669. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  4670. * @phba: pointer to lpfc hba data structure.
  4671. *
  4672. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  4673. * operation.
  4674. *
  4675. * Return codes
  4676. * 0 - sucessful
  4677. * ENOMEM - No availble memory
  4678. * EIO - The mailbox failed to complete successfully.
  4679. **/
  4680. static void
  4681. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  4682. {
  4683. int fcp_qidx;
  4684. /* Release mailbox command work queue */
  4685. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  4686. phba->sli4_hba.mbx_wq = NULL;
  4687. /* Release ELS work queue */
  4688. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  4689. phba->sli4_hba.els_wq = NULL;
  4690. /* Release FCP work queue */
  4691. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  4692. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
  4693. kfree(phba->sli4_hba.fcp_wq);
  4694. phba->sli4_hba.fcp_wq = NULL;
  4695. /* Release unsolicited receive queue */
  4696. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  4697. phba->sli4_hba.hdr_rq = NULL;
  4698. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  4699. phba->sli4_hba.dat_rq = NULL;
  4700. /* Release unsolicited receive complete queue */
  4701. lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
  4702. phba->sli4_hba.rxq_cq = NULL;
  4703. /* Release ELS complete queue */
  4704. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  4705. phba->sli4_hba.els_cq = NULL;
  4706. /* Release mailbox command complete queue */
  4707. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  4708. phba->sli4_hba.mbx_cq = NULL;
  4709. /* Release FCP response complete queue */
  4710. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  4711. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
  4712. kfree(phba->sli4_hba.fcp_cq);
  4713. phba->sli4_hba.fcp_cq = NULL;
  4714. /* Release fast-path event queue */
  4715. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  4716. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
  4717. kfree(phba->sli4_hba.fp_eq);
  4718. phba->sli4_hba.fp_eq = NULL;
  4719. /* Release slow-path event queue */
  4720. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  4721. phba->sli4_hba.sp_eq = NULL;
  4722. return;
  4723. }
  4724. /**
  4725. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  4726. * @phba: pointer to lpfc hba data structure.
  4727. *
  4728. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  4729. * operation.
  4730. *
  4731. * Return codes
  4732. * 0 - sucessful
  4733. * ENOMEM - No availble memory
  4734. * EIO - The mailbox failed to complete successfully.
  4735. **/
  4736. int
  4737. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  4738. {
  4739. int rc = -ENOMEM;
  4740. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  4741. int fcp_cq_index = 0;
  4742. /*
  4743. * Set up Event Queues (EQs)
  4744. */
  4745. /* Set up slow-path event queue */
  4746. if (!phba->sli4_hba.sp_eq) {
  4747. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4748. "0520 Slow-path EQ not allocated\n");
  4749. goto out_error;
  4750. }
  4751. rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
  4752. LPFC_SP_DEF_IMAX);
  4753. if (rc) {
  4754. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4755. "0521 Failed setup of slow-path EQ: "
  4756. "rc = 0x%x\n", rc);
  4757. goto out_error;
  4758. }
  4759. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4760. "2583 Slow-path EQ setup: queue-id=%d\n",
  4761. phba->sli4_hba.sp_eq->queue_id);
  4762. /* Set up fast-path event queue */
  4763. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  4764. if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
  4765. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4766. "0522 Fast-path EQ (%d) not "
  4767. "allocated\n", fcp_eqidx);
  4768. goto out_destroy_fp_eq;
  4769. }
  4770. rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
  4771. phba->cfg_fcp_imax);
  4772. if (rc) {
  4773. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4774. "0523 Failed setup of fast-path EQ "
  4775. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  4776. goto out_destroy_fp_eq;
  4777. }
  4778. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4779. "2584 Fast-path EQ setup: "
  4780. "queue[%d]-id=%d\n", fcp_eqidx,
  4781. phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
  4782. }
  4783. /*
  4784. * Set up Complete Queues (CQs)
  4785. */
  4786. /* Set up slow-path MBOX Complete Queue as the first CQ */
  4787. if (!phba->sli4_hba.mbx_cq) {
  4788. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4789. "0528 Mailbox CQ not allocated\n");
  4790. goto out_destroy_fp_eq;
  4791. }
  4792. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
  4793. LPFC_MCQ, LPFC_MBOX);
  4794. if (rc) {
  4795. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4796. "0529 Failed setup of slow-path mailbox CQ: "
  4797. "rc = 0x%x\n", rc);
  4798. goto out_destroy_fp_eq;
  4799. }
  4800. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4801. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  4802. phba->sli4_hba.mbx_cq->queue_id,
  4803. phba->sli4_hba.sp_eq->queue_id);
  4804. /* Set up slow-path ELS Complete Queue */
  4805. if (!phba->sli4_hba.els_cq) {
  4806. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4807. "0530 ELS CQ not allocated\n");
  4808. goto out_destroy_mbx_cq;
  4809. }
  4810. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
  4811. LPFC_WCQ, LPFC_ELS);
  4812. if (rc) {
  4813. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4814. "0531 Failed setup of slow-path ELS CQ: "
  4815. "rc = 0x%x\n", rc);
  4816. goto out_destroy_mbx_cq;
  4817. }
  4818. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4819. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  4820. phba->sli4_hba.els_cq->queue_id,
  4821. phba->sli4_hba.sp_eq->queue_id);
  4822. /* Set up slow-path Unsolicited Receive Complete Queue */
  4823. if (!phba->sli4_hba.rxq_cq) {
  4824. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4825. "0532 USOL RX CQ not allocated\n");
  4826. goto out_destroy_els_cq;
  4827. }
  4828. rc = lpfc_cq_create(phba, phba->sli4_hba.rxq_cq, phba->sli4_hba.sp_eq,
  4829. LPFC_RCQ, LPFC_USOL);
  4830. if (rc) {
  4831. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4832. "0533 Failed setup of slow-path USOL RX CQ: "
  4833. "rc = 0x%x\n", rc);
  4834. goto out_destroy_els_cq;
  4835. }
  4836. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4837. "2587 USL CQ setup: cq-id=%d, parent eq-id=%d\n",
  4838. phba->sli4_hba.rxq_cq->queue_id,
  4839. phba->sli4_hba.sp_eq->queue_id);
  4840. /* Set up fast-path FCP Response Complete Queue */
  4841. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  4842. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  4843. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4844. "0526 Fast-path FCP CQ (%d) not "
  4845. "allocated\n", fcp_cqidx);
  4846. goto out_destroy_fcp_cq;
  4847. }
  4848. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  4849. phba->sli4_hba.fp_eq[fcp_cqidx],
  4850. LPFC_WCQ, LPFC_FCP);
  4851. if (rc) {
  4852. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4853. "0527 Failed setup of fast-path FCP "
  4854. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  4855. goto out_destroy_fcp_cq;
  4856. }
  4857. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4858. "2588 FCP CQ setup: cq[%d]-id=%d, "
  4859. "parent eq[%d]-id=%d\n",
  4860. fcp_cqidx,
  4861. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  4862. fcp_cqidx,
  4863. phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
  4864. }
  4865. /*
  4866. * Set up all the Work Queues (WQs)
  4867. */
  4868. /* Set up Mailbox Command Queue */
  4869. if (!phba->sli4_hba.mbx_wq) {
  4870. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4871. "0538 Slow-path MQ not allocated\n");
  4872. goto out_destroy_fcp_cq;
  4873. }
  4874. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  4875. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  4876. if (rc) {
  4877. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4878. "0539 Failed setup of slow-path MQ: "
  4879. "rc = 0x%x\n", rc);
  4880. goto out_destroy_fcp_cq;
  4881. }
  4882. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4883. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  4884. phba->sli4_hba.mbx_wq->queue_id,
  4885. phba->sli4_hba.mbx_cq->queue_id);
  4886. /* Set up slow-path ELS Work Queue */
  4887. if (!phba->sli4_hba.els_wq) {
  4888. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4889. "0536 Slow-path ELS WQ not allocated\n");
  4890. goto out_destroy_mbx_wq;
  4891. }
  4892. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  4893. phba->sli4_hba.els_cq, LPFC_ELS);
  4894. if (rc) {
  4895. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4896. "0537 Failed setup of slow-path ELS WQ: "
  4897. "rc = 0x%x\n", rc);
  4898. goto out_destroy_mbx_wq;
  4899. }
  4900. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4901. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  4902. phba->sli4_hba.els_wq->queue_id,
  4903. phba->sli4_hba.els_cq->queue_id);
  4904. /* Set up fast-path FCP Work Queue */
  4905. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  4906. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  4907. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4908. "0534 Fast-path FCP WQ (%d) not "
  4909. "allocated\n", fcp_wqidx);
  4910. goto out_destroy_fcp_wq;
  4911. }
  4912. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  4913. phba->sli4_hba.fcp_cq[fcp_cq_index],
  4914. LPFC_FCP);
  4915. if (rc) {
  4916. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4917. "0535 Failed setup of fast-path FCP "
  4918. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  4919. goto out_destroy_fcp_wq;
  4920. }
  4921. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4922. "2591 FCP WQ setup: wq[%d]-id=%d, "
  4923. "parent cq[%d]-id=%d\n",
  4924. fcp_wqidx,
  4925. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  4926. fcp_cq_index,
  4927. phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
  4928. /* Round robin FCP Work Queue's Completion Queue assignment */
  4929. fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
  4930. }
  4931. /*
  4932. * Create Receive Queue (RQ)
  4933. */
  4934. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  4935. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4936. "0540 Receive Queue not allocated\n");
  4937. goto out_destroy_fcp_wq;
  4938. }
  4939. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  4940. phba->sli4_hba.rxq_cq, LPFC_USOL);
  4941. if (rc) {
  4942. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4943. "0541 Failed setup of Receive Queue: "
  4944. "rc = 0x%x\n", rc);
  4945. goto out_destroy_fcp_wq;
  4946. }
  4947. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4948. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  4949. "parent cq-id=%d\n",
  4950. phba->sli4_hba.hdr_rq->queue_id,
  4951. phba->sli4_hba.dat_rq->queue_id,
  4952. phba->sli4_hba.rxq_cq->queue_id);
  4953. return 0;
  4954. out_destroy_fcp_wq:
  4955. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  4956. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  4957. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  4958. out_destroy_mbx_wq:
  4959. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  4960. out_destroy_fcp_cq:
  4961. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  4962. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  4963. lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
  4964. out_destroy_els_cq:
  4965. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  4966. out_destroy_mbx_cq:
  4967. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  4968. out_destroy_fp_eq:
  4969. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  4970. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
  4971. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  4972. out_error:
  4973. return rc;
  4974. }
  4975. /**
  4976. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  4977. * @phba: pointer to lpfc hba data structure.
  4978. *
  4979. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  4980. * operation.
  4981. *
  4982. * Return codes
  4983. * 0 - sucessful
  4984. * ENOMEM - No availble memory
  4985. * EIO - The mailbox failed to complete successfully.
  4986. **/
  4987. void
  4988. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  4989. {
  4990. int fcp_qidx;
  4991. /* Unset mailbox command work queue */
  4992. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  4993. /* Unset ELS work queue */
  4994. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  4995. /* Unset unsolicited receive queue */
  4996. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  4997. /* Unset FCP work queue */
  4998. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  4999. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  5000. /* Unset mailbox command complete queue */
  5001. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5002. /* Unset ELS complete queue */
  5003. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5004. /* Unset unsolicited receive complete queue */
  5005. lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
  5006. /* Unset FCP response complete queue */
  5007. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5008. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  5009. /* Unset fast-path event queue */
  5010. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5011. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
  5012. /* Unset slow-path event queue */
  5013. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5014. }
  5015. /**
  5016. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  5017. * @phba: pointer to lpfc hba data structure.
  5018. *
  5019. * This routine is invoked to allocate and set up a pool of completion queue
  5020. * events. The body of the completion queue event is a completion queue entry
  5021. * CQE. For now, this pool is used for the interrupt service routine to queue
  5022. * the following HBA completion queue events for the worker thread to process:
  5023. * - Mailbox asynchronous events
  5024. * - Receive queue completion unsolicited events
  5025. * Later, this can be used for all the slow-path events.
  5026. *
  5027. * Return codes
  5028. * 0 - sucessful
  5029. * -ENOMEM - No availble memory
  5030. **/
  5031. static int
  5032. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  5033. {
  5034. struct lpfc_cq_event *cq_event;
  5035. int i;
  5036. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  5037. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  5038. if (!cq_event)
  5039. goto out_pool_create_fail;
  5040. list_add_tail(&cq_event->list,
  5041. &phba->sli4_hba.sp_cqe_event_pool);
  5042. }
  5043. return 0;
  5044. out_pool_create_fail:
  5045. lpfc_sli4_cq_event_pool_destroy(phba);
  5046. return -ENOMEM;
  5047. }
  5048. /**
  5049. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  5050. * @phba: pointer to lpfc hba data structure.
  5051. *
  5052. * This routine is invoked to free the pool of completion queue events at
  5053. * driver unload time. Note that, it is the responsibility of the driver
  5054. * cleanup routine to free all the outstanding completion-queue events
  5055. * allocated from this pool back into the pool before invoking this routine
  5056. * to destroy the pool.
  5057. **/
  5058. static void
  5059. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  5060. {
  5061. struct lpfc_cq_event *cq_event, *next_cq_event;
  5062. list_for_each_entry_safe(cq_event, next_cq_event,
  5063. &phba->sli4_hba.sp_cqe_event_pool, list) {
  5064. list_del(&cq_event->list);
  5065. kfree(cq_event);
  5066. }
  5067. }
  5068. /**
  5069. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5070. * @phba: pointer to lpfc hba data structure.
  5071. *
  5072. * This routine is the lock free version of the API invoked to allocate a
  5073. * completion-queue event from the free pool.
  5074. *
  5075. * Return: Pointer to the newly allocated completion-queue event if successful
  5076. * NULL otherwise.
  5077. **/
  5078. struct lpfc_cq_event *
  5079. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5080. {
  5081. struct lpfc_cq_event *cq_event = NULL;
  5082. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  5083. struct lpfc_cq_event, list);
  5084. return cq_event;
  5085. }
  5086. /**
  5087. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5088. * @phba: pointer to lpfc hba data structure.
  5089. *
  5090. * This routine is the lock version of the API invoked to allocate a
  5091. * completion-queue event from the free pool.
  5092. *
  5093. * Return: Pointer to the newly allocated completion-queue event if successful
  5094. * NULL otherwise.
  5095. **/
  5096. struct lpfc_cq_event *
  5097. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5098. {
  5099. struct lpfc_cq_event *cq_event;
  5100. unsigned long iflags;
  5101. spin_lock_irqsave(&phba->hbalock, iflags);
  5102. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  5103. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5104. return cq_event;
  5105. }
  5106. /**
  5107. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5108. * @phba: pointer to lpfc hba data structure.
  5109. * @cq_event: pointer to the completion queue event to be freed.
  5110. *
  5111. * This routine is the lock free version of the API invoked to release a
  5112. * completion-queue event back into the free pool.
  5113. **/
  5114. void
  5115. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5116. struct lpfc_cq_event *cq_event)
  5117. {
  5118. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  5119. }
  5120. /**
  5121. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5122. * @phba: pointer to lpfc hba data structure.
  5123. * @cq_event: pointer to the completion queue event to be freed.
  5124. *
  5125. * This routine is the lock version of the API invoked to release a
  5126. * completion-queue event back into the free pool.
  5127. **/
  5128. void
  5129. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5130. struct lpfc_cq_event *cq_event)
  5131. {
  5132. unsigned long iflags;
  5133. spin_lock_irqsave(&phba->hbalock, iflags);
  5134. __lpfc_sli4_cq_event_release(phba, cq_event);
  5135. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5136. }
  5137. /**
  5138. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  5139. * @phba: pointer to lpfc hba data structure.
  5140. *
  5141. * This routine is to free all the pending completion-queue events to the
  5142. * back into the free pool for device reset.
  5143. **/
  5144. static void
  5145. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  5146. {
  5147. LIST_HEAD(cqelist);
  5148. struct lpfc_cq_event *cqe;
  5149. unsigned long iflags;
  5150. /* Retrieve all the pending WCQEs from pending WCQE lists */
  5151. spin_lock_irqsave(&phba->hbalock, iflags);
  5152. /* Pending FCP XRI abort events */
  5153. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  5154. &cqelist);
  5155. /* Pending ELS XRI abort events */
  5156. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  5157. &cqelist);
  5158. /* Pending asynnc events */
  5159. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  5160. &cqelist);
  5161. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5162. while (!list_empty(&cqelist)) {
  5163. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  5164. lpfc_sli4_cq_event_release(phba, cqe);
  5165. }
  5166. }
  5167. /**
  5168. * lpfc_pci_function_reset - Reset pci function.
  5169. * @phba: pointer to lpfc hba data structure.
  5170. *
  5171. * This routine is invoked to request a PCI function reset. It will destroys
  5172. * all resources assigned to the PCI function which originates this request.
  5173. *
  5174. * Return codes
  5175. * 0 - sucessful
  5176. * ENOMEM - No availble memory
  5177. * EIO - The mailbox failed to complete successfully.
  5178. **/
  5179. int
  5180. lpfc_pci_function_reset(struct lpfc_hba *phba)
  5181. {
  5182. LPFC_MBOXQ_t *mboxq;
  5183. uint32_t rc = 0;
  5184. uint32_t shdr_status, shdr_add_status;
  5185. union lpfc_sli4_cfg_shdr *shdr;
  5186. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5187. if (!mboxq) {
  5188. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5189. "0494 Unable to allocate memory for issuing "
  5190. "SLI_FUNCTION_RESET mailbox command\n");
  5191. return -ENOMEM;
  5192. }
  5193. /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
  5194. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5195. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  5196. LPFC_SLI4_MBX_EMBED);
  5197. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5198. shdr = (union lpfc_sli4_cfg_shdr *)
  5199. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5200. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5201. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5202. if (rc != MBX_TIMEOUT)
  5203. mempool_free(mboxq, phba->mbox_mem_pool);
  5204. if (shdr_status || shdr_add_status || rc) {
  5205. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5206. "0495 SLI_FUNCTION_RESET mailbox failed with "
  5207. "status x%x add_status x%x, mbx status x%x\n",
  5208. shdr_status, shdr_add_status, rc);
  5209. rc = -ENXIO;
  5210. }
  5211. return rc;
  5212. }
  5213. /**
  5214. * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
  5215. * @phba: pointer to lpfc hba data structure.
  5216. * @cnt: number of nop mailbox commands to send.
  5217. *
  5218. * This routine is invoked to send a number @cnt of NOP mailbox command and
  5219. * wait for each command to complete.
  5220. *
  5221. * Return: the number of NOP mailbox command completed.
  5222. **/
  5223. static int
  5224. lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
  5225. {
  5226. LPFC_MBOXQ_t *mboxq;
  5227. int length, cmdsent;
  5228. uint32_t mbox_tmo;
  5229. uint32_t rc = 0;
  5230. uint32_t shdr_status, shdr_add_status;
  5231. union lpfc_sli4_cfg_shdr *shdr;
  5232. if (cnt == 0) {
  5233. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5234. "2518 Requested to send 0 NOP mailbox cmd\n");
  5235. return cnt;
  5236. }
  5237. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5238. if (!mboxq) {
  5239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5240. "2519 Unable to allocate memory for issuing "
  5241. "NOP mailbox command\n");
  5242. return 0;
  5243. }
  5244. /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
  5245. length = (sizeof(struct lpfc_mbx_nop) -
  5246. sizeof(struct lpfc_sli4_cfg_mhdr));
  5247. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5248. LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
  5249. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5250. for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
  5251. if (!phba->sli4_hba.intr_enable)
  5252. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5253. else
  5254. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  5255. if (rc == MBX_TIMEOUT)
  5256. break;
  5257. /* Check return status */
  5258. shdr = (union lpfc_sli4_cfg_shdr *)
  5259. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5260. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5261. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  5262. &shdr->response);
  5263. if (shdr_status || shdr_add_status || rc) {
  5264. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5265. "2520 NOP mailbox command failed "
  5266. "status x%x add_status x%x mbx "
  5267. "status x%x\n", shdr_status,
  5268. shdr_add_status, rc);
  5269. break;
  5270. }
  5271. }
  5272. if (rc != MBX_TIMEOUT)
  5273. mempool_free(mboxq, phba->mbox_mem_pool);
  5274. return cmdsent;
  5275. }
  5276. /**
  5277. * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
  5278. * @phba: pointer to lpfc hba data structure.
  5279. * @fcfi: fcf index.
  5280. *
  5281. * This routine is invoked to unregister a FCFI from device.
  5282. **/
  5283. void
  5284. lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
  5285. {
  5286. LPFC_MBOXQ_t *mbox;
  5287. uint32_t mbox_tmo;
  5288. int rc;
  5289. unsigned long flags;
  5290. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5291. if (!mbox)
  5292. return;
  5293. lpfc_unreg_fcfi(mbox, fcfi);
  5294. if (!phba->sli4_hba.intr_enable)
  5295. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5296. else {
  5297. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5298. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5299. }
  5300. if (rc != MBX_TIMEOUT)
  5301. mempool_free(mbox, phba->mbox_mem_pool);
  5302. if (rc != MBX_SUCCESS)
  5303. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5304. "2517 Unregister FCFI command failed "
  5305. "status %d, mbxStatus x%x\n", rc,
  5306. bf_get(lpfc_mqe_status, &mbox->u.mqe));
  5307. else {
  5308. spin_lock_irqsave(&phba->hbalock, flags);
  5309. /* Mark the FCFI is no longer registered */
  5310. phba->fcf.fcf_flag &=
  5311. ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED);
  5312. spin_unlock_irqrestore(&phba->hbalock, flags);
  5313. }
  5314. }
  5315. /**
  5316. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  5317. * @phba: pointer to lpfc hba data structure.
  5318. *
  5319. * This routine is invoked to set up the PCI device memory space for device
  5320. * with SLI-4 interface spec.
  5321. *
  5322. * Return codes
  5323. * 0 - sucessful
  5324. * other values - error
  5325. **/
  5326. static int
  5327. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  5328. {
  5329. struct pci_dev *pdev;
  5330. unsigned long bar0map_len, bar1map_len, bar2map_len;
  5331. int error = -ENODEV;
  5332. /* Obtain PCI device reference */
  5333. if (!phba->pcidev)
  5334. return error;
  5335. else
  5336. pdev = phba->pcidev;
  5337. /* Set the device DMA mask size */
  5338. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
  5339. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
  5340. return error;
  5341. /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
  5342. * number of bytes required by each mapping. They are actually
  5343. * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device.
  5344. */
  5345. phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0);
  5346. bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0);
  5347. phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1);
  5348. bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1);
  5349. phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2);
  5350. bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2);
  5351. /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
  5352. phba->sli4_hba.conf_regs_memmap_p =
  5353. ioremap(phba->pci_bar0_map, bar0map_len);
  5354. if (!phba->sli4_hba.conf_regs_memmap_p) {
  5355. dev_printk(KERN_ERR, &pdev->dev,
  5356. "ioremap failed for SLI4 PCI config registers.\n");
  5357. goto out;
  5358. }
  5359. /* Map SLI4 HBA Control Register base to a kernel virtual address. */
  5360. phba->sli4_hba.ctrl_regs_memmap_p =
  5361. ioremap(phba->pci_bar1_map, bar1map_len);
  5362. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  5363. dev_printk(KERN_ERR, &pdev->dev,
  5364. "ioremap failed for SLI4 HBA control registers.\n");
  5365. goto out_iounmap_conf;
  5366. }
  5367. /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
  5368. phba->sli4_hba.drbl_regs_memmap_p =
  5369. ioremap(phba->pci_bar2_map, bar2map_len);
  5370. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  5371. dev_printk(KERN_ERR, &pdev->dev,
  5372. "ioremap failed for SLI4 HBA doorbell registers.\n");
  5373. goto out_iounmap_ctrl;
  5374. }
  5375. /* Set up BAR0 PCI config space register memory map */
  5376. lpfc_sli4_bar0_register_memmap(phba);
  5377. /* Set up BAR1 register memory map */
  5378. lpfc_sli4_bar1_register_memmap(phba);
  5379. /* Set up BAR2 register memory map */
  5380. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  5381. if (error)
  5382. goto out_iounmap_all;
  5383. return 0;
  5384. out_iounmap_all:
  5385. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  5386. out_iounmap_ctrl:
  5387. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  5388. out_iounmap_conf:
  5389. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  5390. out:
  5391. return error;
  5392. }
  5393. /**
  5394. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  5395. * @phba: pointer to lpfc hba data structure.
  5396. *
  5397. * This routine is invoked to unset the PCI device memory space for device
  5398. * with SLI-4 interface spec.
  5399. **/
  5400. static void
  5401. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  5402. {
  5403. struct pci_dev *pdev;
  5404. /* Obtain PCI device reference */
  5405. if (!phba->pcidev)
  5406. return;
  5407. else
  5408. pdev = phba->pcidev;
  5409. /* Free coherent DMA memory allocated */
  5410. /* Unmap I/O memory space */
  5411. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  5412. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  5413. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  5414. return;
  5415. }
  5416. /**
  5417. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  5418. * @phba: pointer to lpfc hba data structure.
  5419. *
  5420. * This routine is invoked to enable the MSI-X interrupt vectors to device
  5421. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  5422. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  5423. * invoked, enables either all or nothing, depending on the current
  5424. * availability of PCI vector resources. The device driver is responsible
  5425. * for calling the individual request_irq() to register each MSI-X vector
  5426. * with a interrupt handler, which is done in this function. Note that
  5427. * later when device is unloading, the driver should always call free_irq()
  5428. * on all MSI-X vectors it has done request_irq() on before calling
  5429. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  5430. * will be left with MSI-X enabled and leaks its vectors.
  5431. *
  5432. * Return codes
  5433. * 0 - sucessful
  5434. * other values - error
  5435. **/
  5436. static int
  5437. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  5438. {
  5439. int rc, i;
  5440. LPFC_MBOXQ_t *pmb;
  5441. /* Set up MSI-X multi-message vectors */
  5442. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5443. phba->msix_entries[i].entry = i;
  5444. /* Configure MSI-X capability structure */
  5445. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  5446. ARRAY_SIZE(phba->msix_entries));
  5447. if (rc) {
  5448. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5449. "0420 PCI enable MSI-X failed (%d)\n", rc);
  5450. goto msi_fail_out;
  5451. }
  5452. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5453. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5454. "0477 MSI-X entry[%d]: vector=x%x "
  5455. "message=%d\n", i,
  5456. phba->msix_entries[i].vector,
  5457. phba->msix_entries[i].entry);
  5458. /*
  5459. * Assign MSI-X vectors to interrupt handlers
  5460. */
  5461. /* vector-0 is associated to slow-path handler */
  5462. rc = request_irq(phba->msix_entries[0].vector,
  5463. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  5464. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  5465. if (rc) {
  5466. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5467. "0421 MSI-X slow-path request_irq failed "
  5468. "(%d)\n", rc);
  5469. goto msi_fail_out;
  5470. }
  5471. /* vector-1 is associated to fast-path handler */
  5472. rc = request_irq(phba->msix_entries[1].vector,
  5473. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  5474. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  5475. if (rc) {
  5476. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5477. "0429 MSI-X fast-path request_irq failed "
  5478. "(%d)\n", rc);
  5479. goto irq_fail_out;
  5480. }
  5481. /*
  5482. * Configure HBA MSI-X attention conditions to messages
  5483. */
  5484. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5485. if (!pmb) {
  5486. rc = -ENOMEM;
  5487. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5488. "0474 Unable to allocate memory for issuing "
  5489. "MBOX_CONFIG_MSI command\n");
  5490. goto mem_fail_out;
  5491. }
  5492. rc = lpfc_config_msi(phba, pmb);
  5493. if (rc)
  5494. goto mbx_fail_out;
  5495. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5496. if (rc != MBX_SUCCESS) {
  5497. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  5498. "0351 Config MSI mailbox command failed, "
  5499. "mbxCmd x%x, mbxStatus x%x\n",
  5500. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  5501. goto mbx_fail_out;
  5502. }
  5503. /* Free memory allocated for mailbox command */
  5504. mempool_free(pmb, phba->mbox_mem_pool);
  5505. return rc;
  5506. mbx_fail_out:
  5507. /* Free memory allocated for mailbox command */
  5508. mempool_free(pmb, phba->mbox_mem_pool);
  5509. mem_fail_out:
  5510. /* free the irq already requested */
  5511. free_irq(phba->msix_entries[1].vector, phba);
  5512. irq_fail_out:
  5513. /* free the irq already requested */
  5514. free_irq(phba->msix_entries[0].vector, phba);
  5515. msi_fail_out:
  5516. /* Unconfigure MSI-X capability structure */
  5517. pci_disable_msix(phba->pcidev);
  5518. return rc;
  5519. }
  5520. /**
  5521. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  5522. * @phba: pointer to lpfc hba data structure.
  5523. *
  5524. * This routine is invoked to release the MSI-X vectors and then disable the
  5525. * MSI-X interrupt mode to device with SLI-3 interface spec.
  5526. **/
  5527. static void
  5528. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  5529. {
  5530. int i;
  5531. /* Free up MSI-X multi-message vectors */
  5532. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5533. free_irq(phba->msix_entries[i].vector, phba);
  5534. /* Disable MSI-X */
  5535. pci_disable_msix(phba->pcidev);
  5536. return;
  5537. }
  5538. /**
  5539. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  5540. * @phba: pointer to lpfc hba data structure.
  5541. *
  5542. * This routine is invoked to enable the MSI interrupt mode to device with
  5543. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  5544. * enable the MSI vector. The device driver is responsible for calling the
  5545. * request_irq() to register MSI vector with a interrupt the handler, which
  5546. * is done in this function.
  5547. *
  5548. * Return codes
  5549. * 0 - sucessful
  5550. * other values - error
  5551. */
  5552. static int
  5553. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  5554. {
  5555. int rc;
  5556. rc = pci_enable_msi(phba->pcidev);
  5557. if (!rc)
  5558. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5559. "0462 PCI enable MSI mode success.\n");
  5560. else {
  5561. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5562. "0471 PCI enable MSI mode failed (%d)\n", rc);
  5563. return rc;
  5564. }
  5565. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  5566. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5567. if (rc) {
  5568. pci_disable_msi(phba->pcidev);
  5569. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5570. "0478 MSI request_irq failed (%d)\n", rc);
  5571. }
  5572. return rc;
  5573. }
  5574. /**
  5575. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  5576. * @phba: pointer to lpfc hba data structure.
  5577. *
  5578. * This routine is invoked to disable the MSI interrupt mode to device with
  5579. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  5580. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  5581. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  5582. * its vector.
  5583. */
  5584. static void
  5585. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  5586. {
  5587. free_irq(phba->pcidev->irq, phba);
  5588. pci_disable_msi(phba->pcidev);
  5589. return;
  5590. }
  5591. /**
  5592. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  5593. * @phba: pointer to lpfc hba data structure.
  5594. *
  5595. * This routine is invoked to enable device interrupt and associate driver's
  5596. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  5597. * spec. Depends on the interrupt mode configured to the driver, the driver
  5598. * will try to fallback from the configured interrupt mode to an interrupt
  5599. * mode which is supported by the platform, kernel, and device in the order
  5600. * of:
  5601. * MSI-X -> MSI -> IRQ.
  5602. *
  5603. * Return codes
  5604. * 0 - sucessful
  5605. * other values - error
  5606. **/
  5607. static uint32_t
  5608. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  5609. {
  5610. uint32_t intr_mode = LPFC_INTR_ERROR;
  5611. int retval;
  5612. if (cfg_mode == 2) {
  5613. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  5614. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  5615. if (!retval) {
  5616. /* Now, try to enable MSI-X interrupt mode */
  5617. retval = lpfc_sli_enable_msix(phba);
  5618. if (!retval) {
  5619. /* Indicate initialization to MSI-X mode */
  5620. phba->intr_type = MSIX;
  5621. intr_mode = 2;
  5622. }
  5623. }
  5624. }
  5625. /* Fallback to MSI if MSI-X initialization failed */
  5626. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  5627. retval = lpfc_sli_enable_msi(phba);
  5628. if (!retval) {
  5629. /* Indicate initialization to MSI mode */
  5630. phba->intr_type = MSI;
  5631. intr_mode = 1;
  5632. }
  5633. }
  5634. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  5635. if (phba->intr_type == NONE) {
  5636. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  5637. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5638. if (!retval) {
  5639. /* Indicate initialization to INTx mode */
  5640. phba->intr_type = INTx;
  5641. intr_mode = 0;
  5642. }
  5643. }
  5644. return intr_mode;
  5645. }
  5646. /**
  5647. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  5648. * @phba: pointer to lpfc hba data structure.
  5649. *
  5650. * This routine is invoked to disable device interrupt and disassociate the
  5651. * driver's interrupt handler(s) from interrupt vector(s) to device with
  5652. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  5653. * release the interrupt vector(s) for the message signaled interrupt.
  5654. **/
  5655. static void
  5656. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  5657. {
  5658. /* Disable the currently initialized interrupt mode */
  5659. if (phba->intr_type == MSIX)
  5660. lpfc_sli_disable_msix(phba);
  5661. else if (phba->intr_type == MSI)
  5662. lpfc_sli_disable_msi(phba);
  5663. else if (phba->intr_type == INTx)
  5664. free_irq(phba->pcidev->irq, phba);
  5665. /* Reset interrupt management states */
  5666. phba->intr_type = NONE;
  5667. phba->sli.slistat.sli_intr = 0;
  5668. return;
  5669. }
  5670. /**
  5671. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  5672. * @phba: pointer to lpfc hba data structure.
  5673. *
  5674. * This routine is invoked to enable the MSI-X interrupt vectors to device
  5675. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  5676. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  5677. * enables either all or nothing, depending on the current availability of
  5678. * PCI vector resources. The device driver is responsible for calling the
  5679. * individual request_irq() to register each MSI-X vector with a interrupt
  5680. * handler, which is done in this function. Note that later when device is
  5681. * unloading, the driver should always call free_irq() on all MSI-X vectors
  5682. * it has done request_irq() on before calling pci_disable_msix(). Failure
  5683. * to do so results in a BUG_ON() and a device will be left with MSI-X
  5684. * enabled and leaks its vectors.
  5685. *
  5686. * Return codes
  5687. * 0 - sucessful
  5688. * other values - error
  5689. **/
  5690. static int
  5691. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  5692. {
  5693. int rc, index;
  5694. /* Set up MSI-X multi-message vectors */
  5695. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  5696. phba->sli4_hba.msix_entries[index].entry = index;
  5697. /* Configure MSI-X capability structure */
  5698. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  5699. phba->sli4_hba.cfg_eqn);
  5700. if (rc) {
  5701. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5702. "0484 PCI enable MSI-X failed (%d)\n", rc);
  5703. goto msi_fail_out;
  5704. }
  5705. /* Log MSI-X vector assignment */
  5706. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  5707. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5708. "0489 MSI-X entry[%d]: vector=x%x "
  5709. "message=%d\n", index,
  5710. phba->sli4_hba.msix_entries[index].vector,
  5711. phba->sli4_hba.msix_entries[index].entry);
  5712. /*
  5713. * Assign MSI-X vectors to interrupt handlers
  5714. */
  5715. /* The first vector must associated to slow-path handler for MQ */
  5716. rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
  5717. &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
  5718. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  5719. if (rc) {
  5720. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5721. "0485 MSI-X slow-path request_irq failed "
  5722. "(%d)\n", rc);
  5723. goto msi_fail_out;
  5724. }
  5725. /* The rest of the vector(s) are associated to fast-path handler(s) */
  5726. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) {
  5727. phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
  5728. phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
  5729. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  5730. &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
  5731. LPFC_FP_DRIVER_HANDLER_NAME,
  5732. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5733. if (rc) {
  5734. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5735. "0486 MSI-X fast-path (%d) "
  5736. "request_irq failed (%d)\n", index, rc);
  5737. goto cfg_fail_out;
  5738. }
  5739. }
  5740. return rc;
  5741. cfg_fail_out:
  5742. /* free the irq already requested */
  5743. for (--index; index >= 1; index--)
  5744. free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
  5745. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5746. /* free the irq already requested */
  5747. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  5748. msi_fail_out:
  5749. /* Unconfigure MSI-X capability structure */
  5750. pci_disable_msix(phba->pcidev);
  5751. return rc;
  5752. }
  5753. /**
  5754. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  5755. * @phba: pointer to lpfc hba data structure.
  5756. *
  5757. * This routine is invoked to release the MSI-X vectors and then disable the
  5758. * MSI-X interrupt mode to device with SLI-4 interface spec.
  5759. **/
  5760. static void
  5761. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  5762. {
  5763. int index;
  5764. /* Free up MSI-X multi-message vectors */
  5765. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  5766. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++)
  5767. free_irq(phba->sli4_hba.msix_entries[index].vector,
  5768. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5769. /* Disable MSI-X */
  5770. pci_disable_msix(phba->pcidev);
  5771. return;
  5772. }
  5773. /**
  5774. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  5775. * @phba: pointer to lpfc hba data structure.
  5776. *
  5777. * This routine is invoked to enable the MSI interrupt mode to device with
  5778. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  5779. * to enable the MSI vector. The device driver is responsible for calling
  5780. * the request_irq() to register MSI vector with a interrupt the handler,
  5781. * which is done in this function.
  5782. *
  5783. * Return codes
  5784. * 0 - sucessful
  5785. * other values - error
  5786. **/
  5787. static int
  5788. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  5789. {
  5790. int rc, index;
  5791. rc = pci_enable_msi(phba->pcidev);
  5792. if (!rc)
  5793. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5794. "0487 PCI enable MSI mode success.\n");
  5795. else {
  5796. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5797. "0488 PCI enable MSI mode failed (%d)\n", rc);
  5798. return rc;
  5799. }
  5800. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  5801. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5802. if (rc) {
  5803. pci_disable_msi(phba->pcidev);
  5804. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5805. "0490 MSI request_irq failed (%d)\n", rc);
  5806. }
  5807. for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
  5808. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  5809. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  5810. }
  5811. return rc;
  5812. }
  5813. /**
  5814. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  5815. * @phba: pointer to lpfc hba data structure.
  5816. *
  5817. * This routine is invoked to disable the MSI interrupt mode to device with
  5818. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  5819. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  5820. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  5821. * its vector.
  5822. **/
  5823. static void
  5824. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  5825. {
  5826. free_irq(phba->pcidev->irq, phba);
  5827. pci_disable_msi(phba->pcidev);
  5828. return;
  5829. }
  5830. /**
  5831. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  5832. * @phba: pointer to lpfc hba data structure.
  5833. *
  5834. * This routine is invoked to enable device interrupt and associate driver's
  5835. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  5836. * interface spec. Depends on the interrupt mode configured to the driver,
  5837. * the driver will try to fallback from the configured interrupt mode to an
  5838. * interrupt mode which is supported by the platform, kernel, and device in
  5839. * the order of:
  5840. * MSI-X -> MSI -> IRQ.
  5841. *
  5842. * Return codes
  5843. * 0 - sucessful
  5844. * other values - error
  5845. **/
  5846. static uint32_t
  5847. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  5848. {
  5849. uint32_t intr_mode = LPFC_INTR_ERROR;
  5850. int retval, index;
  5851. if (cfg_mode == 2) {
  5852. /* Preparation before conf_msi mbox cmd */
  5853. retval = 0;
  5854. if (!retval) {
  5855. /* Now, try to enable MSI-X interrupt mode */
  5856. retval = lpfc_sli4_enable_msix(phba);
  5857. if (!retval) {
  5858. /* Indicate initialization to MSI-X mode */
  5859. phba->intr_type = MSIX;
  5860. intr_mode = 2;
  5861. }
  5862. }
  5863. }
  5864. /* Fallback to MSI if MSI-X initialization failed */
  5865. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  5866. retval = lpfc_sli4_enable_msi(phba);
  5867. if (!retval) {
  5868. /* Indicate initialization to MSI mode */
  5869. phba->intr_type = MSI;
  5870. intr_mode = 1;
  5871. }
  5872. }
  5873. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  5874. if (phba->intr_type == NONE) {
  5875. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  5876. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5877. if (!retval) {
  5878. /* Indicate initialization to INTx mode */
  5879. phba->intr_type = INTx;
  5880. intr_mode = 0;
  5881. for (index = 0; index < phba->cfg_fcp_eq_count;
  5882. index++) {
  5883. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  5884. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  5885. }
  5886. }
  5887. }
  5888. return intr_mode;
  5889. }
  5890. /**
  5891. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  5892. * @phba: pointer to lpfc hba data structure.
  5893. *
  5894. * This routine is invoked to disable device interrupt and disassociate
  5895. * the driver's interrupt handler(s) from interrupt vector(s) to device
  5896. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  5897. * will release the interrupt vector(s) for the message signaled interrupt.
  5898. **/
  5899. static void
  5900. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  5901. {
  5902. /* Disable the currently initialized interrupt mode */
  5903. if (phba->intr_type == MSIX)
  5904. lpfc_sli4_disable_msix(phba);
  5905. else if (phba->intr_type == MSI)
  5906. lpfc_sli4_disable_msi(phba);
  5907. else if (phba->intr_type == INTx)
  5908. free_irq(phba->pcidev->irq, phba);
  5909. /* Reset interrupt management states */
  5910. phba->intr_type = NONE;
  5911. phba->sli.slistat.sli_intr = 0;
  5912. return;
  5913. }
  5914. /**
  5915. * lpfc_unset_hba - Unset SLI3 hba device initialization
  5916. * @phba: pointer to lpfc hba data structure.
  5917. *
  5918. * This routine is invoked to unset the HBA device initialization steps to
  5919. * a device with SLI-3 interface spec.
  5920. **/
  5921. static void
  5922. lpfc_unset_hba(struct lpfc_hba *phba)
  5923. {
  5924. struct lpfc_vport *vport = phba->pport;
  5925. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5926. spin_lock_irq(shost->host_lock);
  5927. vport->load_flag |= FC_UNLOADING;
  5928. spin_unlock_irq(shost->host_lock);
  5929. lpfc_stop_hba_timers(phba);
  5930. phba->pport->work_port_events = 0;
  5931. lpfc_sli_hba_down(phba);
  5932. lpfc_sli_brdrestart(phba);
  5933. lpfc_sli_disable_intr(phba);
  5934. return;
  5935. }
  5936. /**
  5937. * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
  5938. * @phba: pointer to lpfc hba data structure.
  5939. *
  5940. * This routine is invoked to unset the HBA device initialization steps to
  5941. * a device with SLI-4 interface spec.
  5942. **/
  5943. static void
  5944. lpfc_sli4_unset_hba(struct lpfc_hba *phba)
  5945. {
  5946. struct lpfc_vport *vport = phba->pport;
  5947. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5948. spin_lock_irq(shost->host_lock);
  5949. vport->load_flag |= FC_UNLOADING;
  5950. spin_unlock_irq(shost->host_lock);
  5951. phba->pport->work_port_events = 0;
  5952. lpfc_sli4_hba_down(phba);
  5953. lpfc_sli4_disable_intr(phba);
  5954. return;
  5955. }
  5956. /**
  5957. * lpfc_sli4_hba_unset - Unset the fcoe hba
  5958. * @phba: Pointer to HBA context object.
  5959. *
  5960. * This function is called in the SLI4 code path to reset the HBA's FCoE
  5961. * function. The caller is not required to hold any lock. This routine
  5962. * issues PCI function reset mailbox command to reset the FCoE function.
  5963. * At the end of the function, it calls lpfc_hba_down_post function to
  5964. * free any pending commands.
  5965. **/
  5966. static void
  5967. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  5968. {
  5969. int wait_cnt = 0;
  5970. LPFC_MBOXQ_t *mboxq;
  5971. lpfc_stop_hba_timers(phba);
  5972. phba->sli4_hba.intr_enable = 0;
  5973. /*
  5974. * Gracefully wait out the potential current outstanding asynchronous
  5975. * mailbox command.
  5976. */
  5977. /* First, block any pending async mailbox command from posted */
  5978. spin_lock_irq(&phba->hbalock);
  5979. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  5980. spin_unlock_irq(&phba->hbalock);
  5981. /* Now, trying to wait it out if we can */
  5982. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5983. msleep(10);
  5984. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  5985. break;
  5986. }
  5987. /* Forcefully release the outstanding mailbox command if timed out */
  5988. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5989. spin_lock_irq(&phba->hbalock);
  5990. mboxq = phba->sli.mbox_active;
  5991. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5992. __lpfc_mbox_cmpl_put(phba, mboxq);
  5993. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5994. phba->sli.mbox_active = NULL;
  5995. spin_unlock_irq(&phba->hbalock);
  5996. }
  5997. /* Tear down the queues in the HBA */
  5998. lpfc_sli4_queue_unset(phba);
  5999. /* Disable PCI subsystem interrupt */
  6000. lpfc_sli4_disable_intr(phba);
  6001. /* Stop kthread signal shall trigger work_done one more time */
  6002. kthread_stop(phba->worker_thread);
  6003. /* Stop the SLI4 device port */
  6004. phba->pport->work_port_events = 0;
  6005. }
  6006. /**
  6007. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  6008. * @pdev: pointer to PCI device
  6009. * @pid: pointer to PCI device identifier
  6010. *
  6011. * This routine is to be called to attach a device with SLI-3 interface spec
  6012. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6013. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  6014. * information of the device and driver to see if the driver state that it can
  6015. * support this kind of device. If the match is successful, the driver core
  6016. * invokes this routine. If this routine determines it can claim the HBA, it
  6017. * does all the initialization that it needs to do to handle the HBA properly.
  6018. *
  6019. * Return code
  6020. * 0 - driver can claim the device
  6021. * negative value - driver can not claim the device
  6022. **/
  6023. static int __devinit
  6024. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  6025. {
  6026. struct lpfc_hba *phba;
  6027. struct lpfc_vport *vport = NULL;
  6028. int error;
  6029. uint32_t cfg_mode, intr_mode;
  6030. /* Allocate memory for HBA structure */
  6031. phba = lpfc_hba_alloc(pdev);
  6032. if (!phba)
  6033. return -ENOMEM;
  6034. /* Perform generic PCI device enabling operation */
  6035. error = lpfc_enable_pci_dev(phba);
  6036. if (error) {
  6037. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6038. "1401 Failed to enable pci device.\n");
  6039. goto out_free_phba;
  6040. }
  6041. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  6042. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  6043. if (error)
  6044. goto out_disable_pci_dev;
  6045. /* Set up SLI-3 specific device PCI memory space */
  6046. error = lpfc_sli_pci_mem_setup(phba);
  6047. if (error) {
  6048. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6049. "1402 Failed to set up pci memory space.\n");
  6050. goto out_disable_pci_dev;
  6051. }
  6052. /* Set up phase-1 common device driver resources */
  6053. error = lpfc_setup_driver_resource_phase1(phba);
  6054. if (error) {
  6055. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6056. "1403 Failed to set up driver resource.\n");
  6057. goto out_unset_pci_mem_s3;
  6058. }
  6059. /* Set up SLI-3 specific device driver resources */
  6060. error = lpfc_sli_driver_resource_setup(phba);
  6061. if (error) {
  6062. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6063. "1404 Failed to set up driver resource.\n");
  6064. goto out_unset_pci_mem_s3;
  6065. }
  6066. /* Initialize and populate the iocb list per host */
  6067. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  6068. if (error) {
  6069. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6070. "1405 Failed to initialize iocb list.\n");
  6071. goto out_unset_driver_resource_s3;
  6072. }
  6073. /* Set up common device driver resources */
  6074. error = lpfc_setup_driver_resource_phase2(phba);
  6075. if (error) {
  6076. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6077. "1406 Failed to set up driver resource.\n");
  6078. goto out_free_iocb_list;
  6079. }
  6080. /* Create SCSI host to the physical port */
  6081. error = lpfc_create_shost(phba);
  6082. if (error) {
  6083. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6084. "1407 Failed to create scsi host.\n");
  6085. goto out_unset_driver_resource;
  6086. }
  6087. /* Configure sysfs attributes */
  6088. vport = phba->pport;
  6089. error = lpfc_alloc_sysfs_attr(vport);
  6090. if (error) {
  6091. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6092. "1476 Failed to allocate sysfs attr\n");
  6093. goto out_destroy_shost;
  6094. }
  6095. /* Now, trying to enable interrupt and bring up the device */
  6096. cfg_mode = phba->cfg_use_msi;
  6097. while (true) {
  6098. /* Put device to a known state before enabling interrupt */
  6099. lpfc_stop_port(phba);
  6100. /* Configure and enable interrupt */
  6101. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  6102. if (intr_mode == LPFC_INTR_ERROR) {
  6103. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6104. "0431 Failed to enable interrupt.\n");
  6105. error = -ENODEV;
  6106. goto out_free_sysfs_attr;
  6107. }
  6108. /* SLI-3 HBA setup */
  6109. if (lpfc_sli_hba_setup(phba)) {
  6110. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6111. "1477 Failed to set up hba\n");
  6112. error = -ENODEV;
  6113. goto out_remove_device;
  6114. }
  6115. /* Wait 50ms for the interrupts of previous mailbox commands */
  6116. msleep(50);
  6117. /* Check active interrupts on message signaled interrupts */
  6118. if (intr_mode == 0 ||
  6119. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  6120. /* Log the current active interrupt mode */
  6121. phba->intr_mode = intr_mode;
  6122. lpfc_log_intr_mode(phba, intr_mode);
  6123. break;
  6124. } else {
  6125. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6126. "0447 Configure interrupt mode (%d) "
  6127. "failed active interrupt test.\n",
  6128. intr_mode);
  6129. /* Disable the current interrupt mode */
  6130. lpfc_sli_disable_intr(phba);
  6131. /* Try next level of interrupt mode */
  6132. cfg_mode = --intr_mode;
  6133. }
  6134. }
  6135. /* Perform post initialization setup */
  6136. lpfc_post_init_setup(phba);
  6137. /* Check if there are static vports to be created. */
  6138. lpfc_create_static_vport(phba);
  6139. return 0;
  6140. out_remove_device:
  6141. lpfc_unset_hba(phba);
  6142. out_free_sysfs_attr:
  6143. lpfc_free_sysfs_attr(vport);
  6144. out_destroy_shost:
  6145. lpfc_destroy_shost(phba);
  6146. out_unset_driver_resource:
  6147. lpfc_unset_driver_resource_phase2(phba);
  6148. out_free_iocb_list:
  6149. lpfc_free_iocb_list(phba);
  6150. out_unset_driver_resource_s3:
  6151. lpfc_sli_driver_resource_unset(phba);
  6152. out_unset_pci_mem_s3:
  6153. lpfc_sli_pci_mem_unset(phba);
  6154. out_disable_pci_dev:
  6155. lpfc_disable_pci_dev(phba);
  6156. out_free_phba:
  6157. lpfc_hba_free(phba);
  6158. return error;
  6159. }
  6160. /**
  6161. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  6162. * @pdev: pointer to PCI device
  6163. *
  6164. * This routine is to be called to disattach a device with SLI-3 interface
  6165. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6166. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  6167. * device to be removed from the PCI subsystem properly.
  6168. **/
  6169. static void __devexit
  6170. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  6171. {
  6172. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6173. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6174. struct lpfc_vport **vports;
  6175. struct lpfc_hba *phba = vport->phba;
  6176. int i;
  6177. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  6178. spin_lock_irq(&phba->hbalock);
  6179. vport->load_flag |= FC_UNLOADING;
  6180. spin_unlock_irq(&phba->hbalock);
  6181. lpfc_free_sysfs_attr(vport);
  6182. /* Release all the vports against this physical port */
  6183. vports = lpfc_create_vport_work_array(phba);
  6184. if (vports != NULL)
  6185. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  6186. fc_vport_terminate(vports[i]->fc_vport);
  6187. lpfc_destroy_vport_work_array(phba, vports);
  6188. /* Remove FC host and then SCSI host with the physical port */
  6189. fc_remove_host(shost);
  6190. scsi_remove_host(shost);
  6191. lpfc_cleanup(vport);
  6192. /*
  6193. * Bring down the SLI Layer. This step disable all interrupts,
  6194. * clears the rings, discards all mailbox commands, and resets
  6195. * the HBA.
  6196. */
  6197. /* HBA interrupt will be diabled after this call */
  6198. lpfc_sli_hba_down(phba);
  6199. /* Stop kthread signal shall trigger work_done one more time */
  6200. kthread_stop(phba->worker_thread);
  6201. /* Final cleanup of txcmplq and reset the HBA */
  6202. lpfc_sli_brdrestart(phba);
  6203. lpfc_stop_hba_timers(phba);
  6204. spin_lock_irq(&phba->hbalock);
  6205. list_del_init(&vport->listentry);
  6206. spin_unlock_irq(&phba->hbalock);
  6207. lpfc_debugfs_terminate(vport);
  6208. /* Disable interrupt */
  6209. lpfc_sli_disable_intr(phba);
  6210. pci_set_drvdata(pdev, NULL);
  6211. scsi_host_put(shost);
  6212. /*
  6213. * Call scsi_free before mem_free since scsi bufs are released to their
  6214. * corresponding pools here.
  6215. */
  6216. lpfc_scsi_free(phba);
  6217. lpfc_mem_free_all(phba);
  6218. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  6219. phba->hbqslimp.virt, phba->hbqslimp.phys);
  6220. /* Free resources associated with SLI2 interface */
  6221. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  6222. phba->slim2p.virt, phba->slim2p.phys);
  6223. /* unmap adapter SLIM and Control Registers */
  6224. iounmap(phba->ctrl_regs_memmap_p);
  6225. iounmap(phba->slim_memmap_p);
  6226. lpfc_hba_free(phba);
  6227. pci_release_selected_regions(pdev, bars);
  6228. pci_disable_device(pdev);
  6229. }
  6230. /**
  6231. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  6232. * @pdev: pointer to PCI device
  6233. * @msg: power management message
  6234. *
  6235. * This routine is to be called from the kernel's PCI subsystem to support
  6236. * system Power Management (PM) to device with SLI-3 interface spec. When
  6237. * PM invokes this method, it quiesces the device by stopping the driver's
  6238. * worker thread for the device, turning off device's interrupt and DMA,
  6239. * and bring the device offline. Note that as the driver implements the
  6240. * minimum PM requirements to a power-aware driver's PM support for the
  6241. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  6242. * to the suspend() method call will be treated as SUSPEND and the driver will
  6243. * fully reinitialize its device during resume() method call, the driver will
  6244. * set device to PCI_D3hot state in PCI config space instead of setting it
  6245. * according to the @msg provided by the PM.
  6246. *
  6247. * Return code
  6248. * 0 - driver suspended the device
  6249. * Error otherwise
  6250. **/
  6251. static int
  6252. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  6253. {
  6254. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6255. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6256. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6257. "0473 PCI device Power Management suspend.\n");
  6258. /* Bring down the device */
  6259. lpfc_offline_prep(phba);
  6260. lpfc_offline(phba);
  6261. kthread_stop(phba->worker_thread);
  6262. /* Disable interrupt from device */
  6263. lpfc_sli_disable_intr(phba);
  6264. /* Save device state to PCI config space */
  6265. pci_save_state(pdev);
  6266. pci_set_power_state(pdev, PCI_D3hot);
  6267. return 0;
  6268. }
  6269. /**
  6270. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  6271. * @pdev: pointer to PCI device
  6272. *
  6273. * This routine is to be called from the kernel's PCI subsystem to support
  6274. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  6275. * invokes this method, it restores the device's PCI config space state and
  6276. * fully reinitializes the device and brings it online. Note that as the
  6277. * driver implements the minimum PM requirements to a power-aware driver's
  6278. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  6279. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  6280. * driver will fully reinitialize its device during resume() method call,
  6281. * the device will be set to PCI_D0 directly in PCI config space before
  6282. * restoring the state.
  6283. *
  6284. * Return code
  6285. * 0 - driver suspended the device
  6286. * Error otherwise
  6287. **/
  6288. static int
  6289. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  6290. {
  6291. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6292. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6293. uint32_t intr_mode;
  6294. int error;
  6295. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6296. "0452 PCI device Power Management resume.\n");
  6297. /* Restore device state from PCI config space */
  6298. pci_set_power_state(pdev, PCI_D0);
  6299. pci_restore_state(pdev);
  6300. if (pdev->is_busmaster)
  6301. pci_set_master(pdev);
  6302. /* Startup the kernel thread for this host adapter. */
  6303. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  6304. "lpfc_worker_%d", phba->brd_no);
  6305. if (IS_ERR(phba->worker_thread)) {
  6306. error = PTR_ERR(phba->worker_thread);
  6307. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6308. "0434 PM resume failed to start worker "
  6309. "thread: error=x%x.\n", error);
  6310. return error;
  6311. }
  6312. /* Configure and enable interrupt */
  6313. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  6314. if (intr_mode == LPFC_INTR_ERROR) {
  6315. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6316. "0430 PM resume Failed to enable interrupt\n");
  6317. return -EIO;
  6318. } else
  6319. phba->intr_mode = intr_mode;
  6320. /* Restart HBA and bring it online */
  6321. lpfc_sli_brdrestart(phba);
  6322. lpfc_online(phba);
  6323. /* Log the current active interrupt mode */
  6324. lpfc_log_intr_mode(phba, phba->intr_mode);
  6325. return 0;
  6326. }
  6327. /**
  6328. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  6329. * @pdev: pointer to PCI device.
  6330. * @state: the current PCI connection state.
  6331. *
  6332. * This routine is called from the PCI subsystem for I/O error handling to
  6333. * device with SLI-3 interface spec. This function is called by the PCI
  6334. * subsystem after a PCI bus error affecting this device has been detected.
  6335. * When this function is invoked, it will need to stop all the I/Os and
  6336. * interrupt(s) to the device. Once that is done, it will return
  6337. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  6338. * as desired.
  6339. *
  6340. * Return codes
  6341. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  6342. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6343. **/
  6344. static pci_ers_result_t
  6345. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  6346. {
  6347. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6348. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6349. struct lpfc_sli *psli = &phba->sli;
  6350. struct lpfc_sli_ring *pring;
  6351. if (state == pci_channel_io_perm_failure) {
  6352. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6353. "0472 PCI channel I/O permanent failure\n");
  6354. /* Block all SCSI devices' I/Os on the host */
  6355. lpfc_scsi_dev_block(phba);
  6356. /* Clean up all driver's outstanding SCSI I/Os */
  6357. lpfc_sli_flush_fcp_rings(phba);
  6358. return PCI_ERS_RESULT_DISCONNECT;
  6359. }
  6360. pci_disable_device(pdev);
  6361. /*
  6362. * There may be I/Os dropped by the firmware.
  6363. * Error iocb (I/O) on txcmplq and let the SCSI layer
  6364. * retry it after re-establishing link.
  6365. */
  6366. pring = &psli->ring[psli->fcp_ring];
  6367. lpfc_sli_abort_iocb_ring(phba, pring);
  6368. /* Disable interrupt */
  6369. lpfc_sli_disable_intr(phba);
  6370. /* Request a slot reset. */
  6371. return PCI_ERS_RESULT_NEED_RESET;
  6372. }
  6373. /**
  6374. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  6375. * @pdev: pointer to PCI device.
  6376. *
  6377. * This routine is called from the PCI subsystem for error handling to
  6378. * device with SLI-3 interface spec. This is called after PCI bus has been
  6379. * reset to restart the PCI card from scratch, as if from a cold-boot.
  6380. * During the PCI subsystem error recovery, after driver returns
  6381. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  6382. * recovery and then call this routine before calling the .resume method
  6383. * to recover the device. This function will initialize the HBA device,
  6384. * enable the interrupt, but it will just put the HBA to offline state
  6385. * without passing any I/O traffic.
  6386. *
  6387. * Return codes
  6388. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  6389. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6390. */
  6391. static pci_ers_result_t
  6392. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  6393. {
  6394. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6395. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6396. struct lpfc_sli *psli = &phba->sli;
  6397. uint32_t intr_mode;
  6398. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  6399. if (pci_enable_device_mem(pdev)) {
  6400. printk(KERN_ERR "lpfc: Cannot re-enable "
  6401. "PCI device after reset.\n");
  6402. return PCI_ERS_RESULT_DISCONNECT;
  6403. }
  6404. pci_restore_state(pdev);
  6405. if (pdev->is_busmaster)
  6406. pci_set_master(pdev);
  6407. spin_lock_irq(&phba->hbalock);
  6408. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6409. spin_unlock_irq(&phba->hbalock);
  6410. /* Configure and enable interrupt */
  6411. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  6412. if (intr_mode == LPFC_INTR_ERROR) {
  6413. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6414. "0427 Cannot re-enable interrupt after "
  6415. "slot reset.\n");
  6416. return PCI_ERS_RESULT_DISCONNECT;
  6417. } else
  6418. phba->intr_mode = intr_mode;
  6419. /* Take device offline; this will perform cleanup */
  6420. lpfc_offline(phba);
  6421. lpfc_sli_brdrestart(phba);
  6422. /* Log the current active interrupt mode */
  6423. lpfc_log_intr_mode(phba, phba->intr_mode);
  6424. return PCI_ERS_RESULT_RECOVERED;
  6425. }
  6426. /**
  6427. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  6428. * @pdev: pointer to PCI device
  6429. *
  6430. * This routine is called from the PCI subsystem for error handling to device
  6431. * with SLI-3 interface spec. It is called when kernel error recovery tells
  6432. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  6433. * error recovery. After this call, traffic can start to flow from this device
  6434. * again.
  6435. */
  6436. static void
  6437. lpfc_io_resume_s3(struct pci_dev *pdev)
  6438. {
  6439. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6440. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6441. lpfc_online(phba);
  6442. }
  6443. /**
  6444. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  6445. * @phba: pointer to lpfc hba data structure.
  6446. *
  6447. * returns the number of ELS/CT IOCBs to reserve
  6448. **/
  6449. int
  6450. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  6451. {
  6452. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  6453. if (phba->sli_rev == LPFC_SLI_REV4) {
  6454. if (max_xri <= 100)
  6455. return 4;
  6456. else if (max_xri <= 256)
  6457. return 8;
  6458. else if (max_xri <= 512)
  6459. return 16;
  6460. else if (max_xri <= 1024)
  6461. return 32;
  6462. else
  6463. return 48;
  6464. } else
  6465. return 0;
  6466. }
  6467. /**
  6468. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  6469. * @pdev: pointer to PCI device
  6470. * @pid: pointer to PCI device identifier
  6471. *
  6472. * This routine is called from the kernel's PCI subsystem to device with
  6473. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  6474. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  6475. * information of the device and driver to see if the driver state that it
  6476. * can support this kind of device. If the match is successful, the driver
  6477. * core invokes this routine. If this routine determines it can claim the HBA,
  6478. * it does all the initialization that it needs to do to handle the HBA
  6479. * properly.
  6480. *
  6481. * Return code
  6482. * 0 - driver can claim the device
  6483. * negative value - driver can not claim the device
  6484. **/
  6485. static int __devinit
  6486. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  6487. {
  6488. struct lpfc_hba *phba;
  6489. struct lpfc_vport *vport = NULL;
  6490. int error;
  6491. uint32_t cfg_mode, intr_mode;
  6492. int mcnt;
  6493. /* Allocate memory for HBA structure */
  6494. phba = lpfc_hba_alloc(pdev);
  6495. if (!phba)
  6496. return -ENOMEM;
  6497. /* Perform generic PCI device enabling operation */
  6498. error = lpfc_enable_pci_dev(phba);
  6499. if (error) {
  6500. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6501. "1409 Failed to enable pci device.\n");
  6502. goto out_free_phba;
  6503. }
  6504. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  6505. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  6506. if (error)
  6507. goto out_disable_pci_dev;
  6508. /* Set up SLI-4 specific device PCI memory space */
  6509. error = lpfc_sli4_pci_mem_setup(phba);
  6510. if (error) {
  6511. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6512. "1410 Failed to set up pci memory space.\n");
  6513. goto out_disable_pci_dev;
  6514. }
  6515. /* Set up phase-1 common device driver resources */
  6516. error = lpfc_setup_driver_resource_phase1(phba);
  6517. if (error) {
  6518. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6519. "1411 Failed to set up driver resource.\n");
  6520. goto out_unset_pci_mem_s4;
  6521. }
  6522. /* Set up SLI-4 Specific device driver resources */
  6523. error = lpfc_sli4_driver_resource_setup(phba);
  6524. if (error) {
  6525. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6526. "1412 Failed to set up driver resource.\n");
  6527. goto out_unset_pci_mem_s4;
  6528. }
  6529. /* Initialize and populate the iocb list per host */
  6530. error = lpfc_init_iocb_list(phba,
  6531. phba->sli4_hba.max_cfg_param.max_xri);
  6532. if (error) {
  6533. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6534. "1413 Failed to initialize iocb list.\n");
  6535. goto out_unset_driver_resource_s4;
  6536. }
  6537. /* Set up common device driver resources */
  6538. error = lpfc_setup_driver_resource_phase2(phba);
  6539. if (error) {
  6540. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6541. "1414 Failed to set up driver resource.\n");
  6542. goto out_free_iocb_list;
  6543. }
  6544. /* Create SCSI host to the physical port */
  6545. error = lpfc_create_shost(phba);
  6546. if (error) {
  6547. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6548. "1415 Failed to create scsi host.\n");
  6549. goto out_unset_driver_resource;
  6550. }
  6551. /* Configure sysfs attributes */
  6552. vport = phba->pport;
  6553. error = lpfc_alloc_sysfs_attr(vport);
  6554. if (error) {
  6555. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6556. "1416 Failed to allocate sysfs attr\n");
  6557. goto out_destroy_shost;
  6558. }
  6559. /* Now, trying to enable interrupt and bring up the device */
  6560. cfg_mode = phba->cfg_use_msi;
  6561. while (true) {
  6562. /* Put device to a known state before enabling interrupt */
  6563. lpfc_stop_port(phba);
  6564. /* Configure and enable interrupt */
  6565. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  6566. if (intr_mode == LPFC_INTR_ERROR) {
  6567. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6568. "0426 Failed to enable interrupt.\n");
  6569. error = -ENODEV;
  6570. goto out_free_sysfs_attr;
  6571. }
  6572. /* Set up SLI-4 HBA */
  6573. if (lpfc_sli4_hba_setup(phba)) {
  6574. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6575. "1421 Failed to set up hba\n");
  6576. error = -ENODEV;
  6577. goto out_disable_intr;
  6578. }
  6579. /* Send NOP mbx cmds for non-INTx mode active interrupt test */
  6580. if (intr_mode != 0)
  6581. mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
  6582. LPFC_ACT_INTR_CNT);
  6583. /* Check active interrupts received only for MSI/MSI-X */
  6584. if (intr_mode == 0 ||
  6585. phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
  6586. /* Log the current active interrupt mode */
  6587. phba->intr_mode = intr_mode;
  6588. lpfc_log_intr_mode(phba, intr_mode);
  6589. break;
  6590. }
  6591. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6592. "0451 Configure interrupt mode (%d) "
  6593. "failed active interrupt test.\n",
  6594. intr_mode);
  6595. /* Unset the preivous SLI-4 HBA setup */
  6596. lpfc_sli4_unset_hba(phba);
  6597. /* Try next level of interrupt mode */
  6598. cfg_mode = --intr_mode;
  6599. }
  6600. /* Perform post initialization setup */
  6601. lpfc_post_init_setup(phba);
  6602. return 0;
  6603. out_disable_intr:
  6604. lpfc_sli4_disable_intr(phba);
  6605. out_free_sysfs_attr:
  6606. lpfc_free_sysfs_attr(vport);
  6607. out_destroy_shost:
  6608. lpfc_destroy_shost(phba);
  6609. out_unset_driver_resource:
  6610. lpfc_unset_driver_resource_phase2(phba);
  6611. out_free_iocb_list:
  6612. lpfc_free_iocb_list(phba);
  6613. out_unset_driver_resource_s4:
  6614. lpfc_sli4_driver_resource_unset(phba);
  6615. out_unset_pci_mem_s4:
  6616. lpfc_sli4_pci_mem_unset(phba);
  6617. out_disable_pci_dev:
  6618. lpfc_disable_pci_dev(phba);
  6619. out_free_phba:
  6620. lpfc_hba_free(phba);
  6621. return error;
  6622. }
  6623. /**
  6624. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  6625. * @pdev: pointer to PCI device
  6626. *
  6627. * This routine is called from the kernel's PCI subsystem to device with
  6628. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  6629. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  6630. * device to be removed from the PCI subsystem properly.
  6631. **/
  6632. static void __devexit
  6633. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  6634. {
  6635. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6636. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6637. struct lpfc_vport **vports;
  6638. struct lpfc_hba *phba = vport->phba;
  6639. int i;
  6640. /* Mark the device unloading flag */
  6641. spin_lock_irq(&phba->hbalock);
  6642. vport->load_flag |= FC_UNLOADING;
  6643. spin_unlock_irq(&phba->hbalock);
  6644. /* Free the HBA sysfs attributes */
  6645. lpfc_free_sysfs_attr(vport);
  6646. /* Release all the vports against this physical port */
  6647. vports = lpfc_create_vport_work_array(phba);
  6648. if (vports != NULL)
  6649. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  6650. fc_vport_terminate(vports[i]->fc_vport);
  6651. lpfc_destroy_vport_work_array(phba, vports);
  6652. /* Remove FC host and then SCSI host with the physical port */
  6653. fc_remove_host(shost);
  6654. scsi_remove_host(shost);
  6655. /* Perform cleanup on the physical port */
  6656. lpfc_cleanup(vport);
  6657. /*
  6658. * Bring down the SLI Layer. This step disables all interrupts,
  6659. * clears the rings, discards all mailbox commands, and resets
  6660. * the HBA FCoE function.
  6661. */
  6662. lpfc_debugfs_terminate(vport);
  6663. lpfc_sli4_hba_unset(phba);
  6664. spin_lock_irq(&phba->hbalock);
  6665. list_del_init(&vport->listentry);
  6666. spin_unlock_irq(&phba->hbalock);
  6667. /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
  6668. * buffers are released to their corresponding pools here.
  6669. */
  6670. lpfc_scsi_free(phba);
  6671. lpfc_sli4_driver_resource_unset(phba);
  6672. /* Unmap adapter Control and Doorbell registers */
  6673. lpfc_sli4_pci_mem_unset(phba);
  6674. /* Release PCI resources and disable device's PCI function */
  6675. scsi_host_put(shost);
  6676. lpfc_disable_pci_dev(phba);
  6677. /* Finally, free the driver's device data structure */
  6678. lpfc_hba_free(phba);
  6679. return;
  6680. }
  6681. /**
  6682. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  6683. * @pdev: pointer to PCI device
  6684. * @msg: power management message
  6685. *
  6686. * This routine is called from the kernel's PCI subsystem to support system
  6687. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  6688. * this method, it quiesces the device by stopping the driver's worker
  6689. * thread for the device, turning off device's interrupt and DMA, and bring
  6690. * the device offline. Note that as the driver implements the minimum PM
  6691. * requirements to a power-aware driver's PM support for suspend/resume -- all
  6692. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  6693. * method call will be treated as SUSPEND and the driver will fully
  6694. * reinitialize its device during resume() method call, the driver will set
  6695. * device to PCI_D3hot state in PCI config space instead of setting it
  6696. * according to the @msg provided by the PM.
  6697. *
  6698. * Return code
  6699. * 0 - driver suspended the device
  6700. * Error otherwise
  6701. **/
  6702. static int
  6703. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  6704. {
  6705. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6706. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6707. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6708. "0298 PCI device Power Management suspend.\n");
  6709. /* Bring down the device */
  6710. lpfc_offline_prep(phba);
  6711. lpfc_offline(phba);
  6712. kthread_stop(phba->worker_thread);
  6713. /* Disable interrupt from device */
  6714. lpfc_sli4_disable_intr(phba);
  6715. /* Save device state to PCI config space */
  6716. pci_save_state(pdev);
  6717. pci_set_power_state(pdev, PCI_D3hot);
  6718. return 0;
  6719. }
  6720. /**
  6721. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  6722. * @pdev: pointer to PCI device
  6723. *
  6724. * This routine is called from the kernel's PCI subsystem to support system
  6725. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  6726. * this method, it restores the device's PCI config space state and fully
  6727. * reinitializes the device and brings it online. Note that as the driver
  6728. * implements the minimum PM requirements to a power-aware driver's PM for
  6729. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  6730. * to the suspend() method call will be treated as SUSPEND and the driver
  6731. * will fully reinitialize its device during resume() method call, the device
  6732. * will be set to PCI_D0 directly in PCI config space before restoring the
  6733. * state.
  6734. *
  6735. * Return code
  6736. * 0 - driver suspended the device
  6737. * Error otherwise
  6738. **/
  6739. static int
  6740. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  6741. {
  6742. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6743. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6744. uint32_t intr_mode;
  6745. int error;
  6746. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6747. "0292 PCI device Power Management resume.\n");
  6748. /* Restore device state from PCI config space */
  6749. pci_set_power_state(pdev, PCI_D0);
  6750. pci_restore_state(pdev);
  6751. if (pdev->is_busmaster)
  6752. pci_set_master(pdev);
  6753. /* Startup the kernel thread for this host adapter. */
  6754. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  6755. "lpfc_worker_%d", phba->brd_no);
  6756. if (IS_ERR(phba->worker_thread)) {
  6757. error = PTR_ERR(phba->worker_thread);
  6758. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6759. "0293 PM resume failed to start worker "
  6760. "thread: error=x%x.\n", error);
  6761. return error;
  6762. }
  6763. /* Configure and enable interrupt */
  6764. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  6765. if (intr_mode == LPFC_INTR_ERROR) {
  6766. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6767. "0294 PM resume Failed to enable interrupt\n");
  6768. return -EIO;
  6769. } else
  6770. phba->intr_mode = intr_mode;
  6771. /* Restart HBA and bring it online */
  6772. lpfc_sli_brdrestart(phba);
  6773. lpfc_online(phba);
  6774. /* Log the current active interrupt mode */
  6775. lpfc_log_intr_mode(phba, phba->intr_mode);
  6776. return 0;
  6777. }
  6778. /**
  6779. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  6780. * @pdev: pointer to PCI device.
  6781. * @state: the current PCI connection state.
  6782. *
  6783. * This routine is called from the PCI subsystem for error handling to device
  6784. * with SLI-4 interface spec. This function is called by the PCI subsystem
  6785. * after a PCI bus error affecting this device has been detected. When this
  6786. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  6787. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  6788. * for the PCI subsystem to perform proper recovery as desired.
  6789. *
  6790. * Return codes
  6791. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  6792. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6793. **/
  6794. static pci_ers_result_t
  6795. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  6796. {
  6797. return PCI_ERS_RESULT_NEED_RESET;
  6798. }
  6799. /**
  6800. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  6801. * @pdev: pointer to PCI device.
  6802. *
  6803. * This routine is called from the PCI subsystem for error handling to device
  6804. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  6805. * restart the PCI card from scratch, as if from a cold-boot. During the
  6806. * PCI subsystem error recovery, after the driver returns
  6807. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  6808. * recovery and then call this routine before calling the .resume method to
  6809. * recover the device. This function will initialize the HBA device, enable
  6810. * the interrupt, but it will just put the HBA to offline state without
  6811. * passing any I/O traffic.
  6812. *
  6813. * Return codes
  6814. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  6815. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6816. */
  6817. static pci_ers_result_t
  6818. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  6819. {
  6820. return PCI_ERS_RESULT_RECOVERED;
  6821. }
  6822. /**
  6823. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  6824. * @pdev: pointer to PCI device
  6825. *
  6826. * This routine is called from the PCI subsystem for error handling to device
  6827. * with SLI-4 interface spec. It is called when kernel error recovery tells
  6828. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  6829. * error recovery. After this call, traffic can start to flow from this device
  6830. * again.
  6831. **/
  6832. static void
  6833. lpfc_io_resume_s4(struct pci_dev *pdev)
  6834. {
  6835. return;
  6836. }
  6837. /**
  6838. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  6839. * @pdev: pointer to PCI device
  6840. * @pid: pointer to PCI device identifier
  6841. *
  6842. * This routine is to be registered to the kernel's PCI subsystem. When an
  6843. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  6844. * at PCI device-specific information of the device and driver to see if the
  6845. * driver state that it can support this kind of device. If the match is
  6846. * successful, the driver core invokes this routine. This routine dispatches
  6847. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  6848. * do all the initialization that it needs to do to handle the HBA device
  6849. * properly.
  6850. *
  6851. * Return code
  6852. * 0 - driver can claim the device
  6853. * negative value - driver can not claim the device
  6854. **/
  6855. static int __devinit
  6856. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  6857. {
  6858. int rc;
  6859. uint16_t dev_id;
  6860. if (pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id))
  6861. return -ENODEV;
  6862. switch (dev_id) {
  6863. case PCI_DEVICE_ID_TIGERSHARK:
  6864. rc = lpfc_pci_probe_one_s4(pdev, pid);
  6865. break;
  6866. default:
  6867. rc = lpfc_pci_probe_one_s3(pdev, pid);
  6868. break;
  6869. }
  6870. return rc;
  6871. }
  6872. /**
  6873. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  6874. * @pdev: pointer to PCI device
  6875. *
  6876. * This routine is to be registered to the kernel's PCI subsystem. When an
  6877. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  6878. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  6879. * remove routine, which will perform all the necessary cleanup for the
  6880. * device to be removed from the PCI subsystem properly.
  6881. **/
  6882. static void __devexit
  6883. lpfc_pci_remove_one(struct pci_dev *pdev)
  6884. {
  6885. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6886. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6887. switch (phba->pci_dev_grp) {
  6888. case LPFC_PCI_DEV_LP:
  6889. lpfc_pci_remove_one_s3(pdev);
  6890. break;
  6891. case LPFC_PCI_DEV_OC:
  6892. lpfc_pci_remove_one_s4(pdev);
  6893. break;
  6894. default:
  6895. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6896. "1424 Invalid PCI device group: 0x%x\n",
  6897. phba->pci_dev_grp);
  6898. break;
  6899. }
  6900. return;
  6901. }
  6902. /**
  6903. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  6904. * @pdev: pointer to PCI device
  6905. * @msg: power management message
  6906. *
  6907. * This routine is to be registered to the kernel's PCI subsystem to support
  6908. * system Power Management (PM). When PM invokes this method, it dispatches
  6909. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  6910. * suspend the device.
  6911. *
  6912. * Return code
  6913. * 0 - driver suspended the device
  6914. * Error otherwise
  6915. **/
  6916. static int
  6917. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  6918. {
  6919. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6920. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6921. int rc = -ENODEV;
  6922. switch (phba->pci_dev_grp) {
  6923. case LPFC_PCI_DEV_LP:
  6924. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  6925. break;
  6926. case LPFC_PCI_DEV_OC:
  6927. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  6928. break;
  6929. default:
  6930. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6931. "1425 Invalid PCI device group: 0x%x\n",
  6932. phba->pci_dev_grp);
  6933. break;
  6934. }
  6935. return rc;
  6936. }
  6937. /**
  6938. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  6939. * @pdev: pointer to PCI device
  6940. *
  6941. * This routine is to be registered to the kernel's PCI subsystem to support
  6942. * system Power Management (PM). When PM invokes this method, it dispatches
  6943. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  6944. * resume the device.
  6945. *
  6946. * Return code
  6947. * 0 - driver suspended the device
  6948. * Error otherwise
  6949. **/
  6950. static int
  6951. lpfc_pci_resume_one(struct pci_dev *pdev)
  6952. {
  6953. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6954. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6955. int rc = -ENODEV;
  6956. switch (phba->pci_dev_grp) {
  6957. case LPFC_PCI_DEV_LP:
  6958. rc = lpfc_pci_resume_one_s3(pdev);
  6959. break;
  6960. case LPFC_PCI_DEV_OC:
  6961. rc = lpfc_pci_resume_one_s4(pdev);
  6962. break;
  6963. default:
  6964. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6965. "1426 Invalid PCI device group: 0x%x\n",
  6966. phba->pci_dev_grp);
  6967. break;
  6968. }
  6969. return rc;
  6970. }
  6971. /**
  6972. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  6973. * @pdev: pointer to PCI device.
  6974. * @state: the current PCI connection state.
  6975. *
  6976. * This routine is registered to the PCI subsystem for error handling. This
  6977. * function is called by the PCI subsystem after a PCI bus error affecting
  6978. * this device has been detected. When this routine is invoked, it dispatches
  6979. * the action to the proper SLI-3 or SLI-4 device error detected handling
  6980. * routine, which will perform the proper error detected operation.
  6981. *
  6982. * Return codes
  6983. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  6984. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6985. **/
  6986. static pci_ers_result_t
  6987. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  6988. {
  6989. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6990. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6991. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  6992. switch (phba->pci_dev_grp) {
  6993. case LPFC_PCI_DEV_LP:
  6994. rc = lpfc_io_error_detected_s3(pdev, state);
  6995. break;
  6996. case LPFC_PCI_DEV_OC:
  6997. rc = lpfc_io_error_detected_s4(pdev, state);
  6998. break;
  6999. default:
  7000. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7001. "1427 Invalid PCI device group: 0x%x\n",
  7002. phba->pci_dev_grp);
  7003. break;
  7004. }
  7005. return rc;
  7006. }
  7007. /**
  7008. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  7009. * @pdev: pointer to PCI device.
  7010. *
  7011. * This routine is registered to the PCI subsystem for error handling. This
  7012. * function is called after PCI bus has been reset to restart the PCI card
  7013. * from scratch, as if from a cold-boot. When this routine is invoked, it
  7014. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  7015. * routine, which will perform the proper device reset.
  7016. *
  7017. * Return codes
  7018. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7019. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7020. **/
  7021. static pci_ers_result_t
  7022. lpfc_io_slot_reset(struct pci_dev *pdev)
  7023. {
  7024. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7025. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7026. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  7027. switch (phba->pci_dev_grp) {
  7028. case LPFC_PCI_DEV_LP:
  7029. rc = lpfc_io_slot_reset_s3(pdev);
  7030. break;
  7031. case LPFC_PCI_DEV_OC:
  7032. rc = lpfc_io_slot_reset_s4(pdev);
  7033. break;
  7034. default:
  7035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7036. "1428 Invalid PCI device group: 0x%x\n",
  7037. phba->pci_dev_grp);
  7038. break;
  7039. }
  7040. return rc;
  7041. }
  7042. /**
  7043. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  7044. * @pdev: pointer to PCI device
  7045. *
  7046. * This routine is registered to the PCI subsystem for error handling. It
  7047. * is called when kernel error recovery tells the lpfc driver that it is
  7048. * OK to resume normal PCI operation after PCI bus error recovery. When
  7049. * this routine is invoked, it dispatches the action to the proper SLI-3
  7050. * or SLI-4 device io_resume routine, which will resume the device operation.
  7051. **/
  7052. static void
  7053. lpfc_io_resume(struct pci_dev *pdev)
  7054. {
  7055. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7056. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7057. switch (phba->pci_dev_grp) {
  7058. case LPFC_PCI_DEV_LP:
  7059. lpfc_io_resume_s3(pdev);
  7060. break;
  7061. case LPFC_PCI_DEV_OC:
  7062. lpfc_io_resume_s4(pdev);
  7063. break;
  7064. default:
  7065. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7066. "1429 Invalid PCI device group: 0x%x\n",
  7067. phba->pci_dev_grp);
  7068. break;
  7069. }
  7070. return;
  7071. }
  7072. static struct pci_device_id lpfc_id_table[] = {
  7073. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  7074. PCI_ANY_ID, PCI_ANY_ID, },
  7075. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  7076. PCI_ANY_ID, PCI_ANY_ID, },
  7077. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  7078. PCI_ANY_ID, PCI_ANY_ID, },
  7079. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  7080. PCI_ANY_ID, PCI_ANY_ID, },
  7081. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  7082. PCI_ANY_ID, PCI_ANY_ID, },
  7083. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  7084. PCI_ANY_ID, PCI_ANY_ID, },
  7085. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  7086. PCI_ANY_ID, PCI_ANY_ID, },
  7087. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  7088. PCI_ANY_ID, PCI_ANY_ID, },
  7089. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  7090. PCI_ANY_ID, PCI_ANY_ID, },
  7091. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  7092. PCI_ANY_ID, PCI_ANY_ID, },
  7093. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  7094. PCI_ANY_ID, PCI_ANY_ID, },
  7095. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  7096. PCI_ANY_ID, PCI_ANY_ID, },
  7097. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  7098. PCI_ANY_ID, PCI_ANY_ID, },
  7099. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  7100. PCI_ANY_ID, PCI_ANY_ID, },
  7101. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  7102. PCI_ANY_ID, PCI_ANY_ID, },
  7103. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  7104. PCI_ANY_ID, PCI_ANY_ID, },
  7105. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  7106. PCI_ANY_ID, PCI_ANY_ID, },
  7107. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  7108. PCI_ANY_ID, PCI_ANY_ID, },
  7109. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  7110. PCI_ANY_ID, PCI_ANY_ID, },
  7111. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  7112. PCI_ANY_ID, PCI_ANY_ID, },
  7113. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  7114. PCI_ANY_ID, PCI_ANY_ID, },
  7115. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  7116. PCI_ANY_ID, PCI_ANY_ID, },
  7117. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  7118. PCI_ANY_ID, PCI_ANY_ID, },
  7119. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  7120. PCI_ANY_ID, PCI_ANY_ID, },
  7121. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  7122. PCI_ANY_ID, PCI_ANY_ID, },
  7123. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  7124. PCI_ANY_ID, PCI_ANY_ID, },
  7125. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  7126. PCI_ANY_ID, PCI_ANY_ID, },
  7127. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  7128. PCI_ANY_ID, PCI_ANY_ID, },
  7129. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  7130. PCI_ANY_ID, PCI_ANY_ID, },
  7131. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  7132. PCI_ANY_ID, PCI_ANY_ID, },
  7133. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  7134. PCI_ANY_ID, PCI_ANY_ID, },
  7135. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  7136. PCI_ANY_ID, PCI_ANY_ID, },
  7137. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  7138. PCI_ANY_ID, PCI_ANY_ID, },
  7139. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  7140. PCI_ANY_ID, PCI_ANY_ID, },
  7141. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  7142. PCI_ANY_ID, PCI_ANY_ID, },
  7143. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  7144. PCI_ANY_ID, PCI_ANY_ID, },
  7145. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  7146. PCI_ANY_ID, PCI_ANY_ID, },
  7147. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  7148. PCI_ANY_ID, PCI_ANY_ID, },
  7149. { 0 }
  7150. };
  7151. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  7152. static struct pci_error_handlers lpfc_err_handler = {
  7153. .error_detected = lpfc_io_error_detected,
  7154. .slot_reset = lpfc_io_slot_reset,
  7155. .resume = lpfc_io_resume,
  7156. };
  7157. static struct pci_driver lpfc_driver = {
  7158. .name = LPFC_DRIVER_NAME,
  7159. .id_table = lpfc_id_table,
  7160. .probe = lpfc_pci_probe_one,
  7161. .remove = __devexit_p(lpfc_pci_remove_one),
  7162. .suspend = lpfc_pci_suspend_one,
  7163. .resume = lpfc_pci_resume_one,
  7164. .err_handler = &lpfc_err_handler,
  7165. };
  7166. /**
  7167. * lpfc_init - lpfc module initialization routine
  7168. *
  7169. * This routine is to be invoked when the lpfc module is loaded into the
  7170. * kernel. The special kernel macro module_init() is used to indicate the
  7171. * role of this routine to the kernel as lpfc module entry point.
  7172. *
  7173. * Return codes
  7174. * 0 - successful
  7175. * -ENOMEM - FC attach transport failed
  7176. * all others - failed
  7177. */
  7178. static int __init
  7179. lpfc_init(void)
  7180. {
  7181. int error = 0;
  7182. printk(LPFC_MODULE_DESC "\n");
  7183. printk(LPFC_COPYRIGHT "\n");
  7184. if (lpfc_enable_npiv) {
  7185. lpfc_transport_functions.vport_create = lpfc_vport_create;
  7186. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  7187. }
  7188. lpfc_transport_template =
  7189. fc_attach_transport(&lpfc_transport_functions);
  7190. if (lpfc_transport_template == NULL)
  7191. return -ENOMEM;
  7192. if (lpfc_enable_npiv) {
  7193. lpfc_vport_transport_template =
  7194. fc_attach_transport(&lpfc_vport_transport_functions);
  7195. if (lpfc_vport_transport_template == NULL) {
  7196. fc_release_transport(lpfc_transport_template);
  7197. return -ENOMEM;
  7198. }
  7199. }
  7200. error = pci_register_driver(&lpfc_driver);
  7201. if (error) {
  7202. fc_release_transport(lpfc_transport_template);
  7203. if (lpfc_enable_npiv)
  7204. fc_release_transport(lpfc_vport_transport_template);
  7205. }
  7206. return error;
  7207. }
  7208. /**
  7209. * lpfc_exit - lpfc module removal routine
  7210. *
  7211. * This routine is invoked when the lpfc module is removed from the kernel.
  7212. * The special kernel macro module_exit() is used to indicate the role of
  7213. * this routine to the kernel as lpfc module exit point.
  7214. */
  7215. static void __exit
  7216. lpfc_exit(void)
  7217. {
  7218. pci_unregister_driver(&lpfc_driver);
  7219. fc_release_transport(lpfc_transport_template);
  7220. if (lpfc_enable_npiv)
  7221. fc_release_transport(lpfc_vport_transport_template);
  7222. if (_dump_buf_data) {
  7223. printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_data "
  7224. "at 0x%p\n",
  7225. (1L << _dump_buf_data_order), _dump_buf_data);
  7226. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  7227. }
  7228. if (_dump_buf_dif) {
  7229. printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_dif "
  7230. "at 0x%p\n",
  7231. (1L << _dump_buf_dif_order), _dump_buf_dif);
  7232. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  7233. }
  7234. }
  7235. module_init(lpfc_init);
  7236. module_exit(lpfc_exit);
  7237. MODULE_LICENSE("GPL");
  7238. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  7239. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  7240. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);