ql4_os.c 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2012 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <linux/blkdev.h>
  10. #include <linux/iscsi_boot_sysfs.h>
  11. #include <linux/inet.h>
  12. #include <scsi/scsi_tcq.h>
  13. #include <scsi/scsicam.h>
  14. #include "ql4_def.h"
  15. #include "ql4_version.h"
  16. #include "ql4_glbl.h"
  17. #include "ql4_dbg.h"
  18. #include "ql4_inline.h"
  19. #include "ql4_83xx.h"
  20. /*
  21. * Driver version
  22. */
  23. static char qla4xxx_version_str[40];
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * Module parameter information and variables
  30. */
  31. static int ql4xdisablesysfsboot = 1;
  32. module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
  33. MODULE_PARM_DESC(ql4xdisablesysfsboot,
  34. " Set to disable exporting boot targets to sysfs.\n"
  35. "\t\t 0 - Export boot targets\n"
  36. "\t\t 1 - Do not export boot targets (Default)");
  37. int ql4xdontresethba;
  38. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  39. MODULE_PARM_DESC(ql4xdontresethba,
  40. " Don't reset the HBA for driver recovery.\n"
  41. "\t\t 0 - It will reset HBA (Default)\n"
  42. "\t\t 1 - It will NOT reset HBA");
  43. int ql4xextended_error_logging;
  44. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  45. MODULE_PARM_DESC(ql4xextended_error_logging,
  46. " Option to enable extended error logging.\n"
  47. "\t\t 0 - no logging (Default)\n"
  48. "\t\t 2 - debug logging");
  49. int ql4xenablemsix = 1;
  50. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  51. MODULE_PARM_DESC(ql4xenablemsix,
  52. " Set to enable MSI or MSI-X interrupt mechanism.\n"
  53. "\t\t 0 = enable INTx interrupt mechanism.\n"
  54. "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
  55. "\t\t 2 = enable MSI interrupt mechanism.");
  56. #define QL4_DEF_QDEPTH 32
  57. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  58. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  59. MODULE_PARM_DESC(ql4xmaxqdepth,
  60. " Maximum queue depth to report for target devices.\n"
  61. "\t\t Default: 32.");
  62. static int ql4xqfulltracking = 1;
  63. module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
  64. MODULE_PARM_DESC(ql4xqfulltracking,
  65. " Enable or disable dynamic tracking and adjustment of\n"
  66. "\t\t scsi device queue depth.\n"
  67. "\t\t 0 - Disable.\n"
  68. "\t\t 1 - Enable. (Default)");
  69. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  70. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  71. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  72. " Target Session Recovery Timeout.\n"
  73. "\t\t Default: 120 sec.");
  74. int ql4xmdcapmask = 0x1F;
  75. module_param(ql4xmdcapmask, int, S_IRUGO);
  76. MODULE_PARM_DESC(ql4xmdcapmask,
  77. " Set the Minidump driver capture mask level.\n"
  78. "\t\t Default is 0x1F.\n"
  79. "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
  80. int ql4xenablemd = 1;
  81. module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
  82. MODULE_PARM_DESC(ql4xenablemd,
  83. " Set to enable minidump.\n"
  84. "\t\t 0 - disable minidump\n"
  85. "\t\t 1 - enable minidump (Default)");
  86. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  87. /*
  88. * SCSI host template entry points
  89. */
  90. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  91. /*
  92. * iSCSI template entry points
  93. */
  94. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  95. enum iscsi_param param, char *buf);
  96. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  97. enum iscsi_param param, char *buf);
  98. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  99. enum iscsi_host_param param, char *buf);
  100. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
  101. uint32_t len);
  102. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  103. enum iscsi_param_type param_type,
  104. int param, char *buf);
  105. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  106. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  107. struct sockaddr *dst_addr,
  108. int non_blocking);
  109. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  110. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  111. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  112. enum iscsi_param param, char *buf);
  113. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  114. static struct iscsi_cls_conn *
  115. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  116. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  117. struct iscsi_cls_conn *cls_conn,
  118. uint64_t transport_fd, int is_leading);
  119. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  120. static struct iscsi_cls_session *
  121. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  122. uint16_t qdepth, uint32_t initial_cmdsn);
  123. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  124. static void qla4xxx_task_work(struct work_struct *wdata);
  125. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  126. static int qla4xxx_task_xmit(struct iscsi_task *);
  127. static void qla4xxx_task_cleanup(struct iscsi_task *);
  128. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  129. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  130. struct iscsi_stats *stats);
  131. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  132. uint32_t iface_type, uint32_t payload_size,
  133. uint32_t pid, struct sockaddr *dst_addr);
  134. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  135. uint32_t *num_entries, char *buf);
  136. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
  137. /*
  138. * SCSI host template entry points
  139. */
  140. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  141. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  142. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  143. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  144. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  145. static int qla4xxx_slave_alloc(struct scsi_device *device);
  146. static int qla4xxx_slave_configure(struct scsi_device *device);
  147. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  148. static umode_t qla4_attr_is_visible(int param_type, int param);
  149. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  150. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  151. int reason);
  152. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  153. QLA82XX_LEGACY_INTR_CONFIG;
  154. static struct scsi_host_template qla4xxx_driver_template = {
  155. .module = THIS_MODULE,
  156. .name = DRIVER_NAME,
  157. .proc_name = DRIVER_NAME,
  158. .queuecommand = qla4xxx_queuecommand,
  159. .eh_abort_handler = qla4xxx_eh_abort,
  160. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  161. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  162. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  163. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  164. .slave_configure = qla4xxx_slave_configure,
  165. .slave_alloc = qla4xxx_slave_alloc,
  166. .slave_destroy = qla4xxx_slave_destroy,
  167. .change_queue_depth = qla4xxx_change_queue_depth,
  168. .this_id = -1,
  169. .cmd_per_lun = 3,
  170. .use_clustering = ENABLE_CLUSTERING,
  171. .sg_tablesize = SG_ALL,
  172. .max_sectors = 0xFFFF,
  173. .shost_attrs = qla4xxx_host_attrs,
  174. .host_reset = qla4xxx_host_reset,
  175. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  176. };
  177. static struct iscsi_transport qla4xxx_iscsi_transport = {
  178. .owner = THIS_MODULE,
  179. .name = DRIVER_NAME,
  180. .caps = CAP_TEXT_NEGO |
  181. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  182. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  183. CAP_MULTI_R2T,
  184. .attr_is_visible = qla4_attr_is_visible,
  185. .create_session = qla4xxx_session_create,
  186. .destroy_session = qla4xxx_session_destroy,
  187. .start_conn = qla4xxx_conn_start,
  188. .create_conn = qla4xxx_conn_create,
  189. .bind_conn = qla4xxx_conn_bind,
  190. .stop_conn = iscsi_conn_stop,
  191. .destroy_conn = qla4xxx_conn_destroy,
  192. .set_param = iscsi_set_param,
  193. .get_conn_param = qla4xxx_conn_get_param,
  194. .get_session_param = qla4xxx_session_get_param,
  195. .get_ep_param = qla4xxx_get_ep_param,
  196. .ep_connect = qla4xxx_ep_connect,
  197. .ep_poll = qla4xxx_ep_poll,
  198. .ep_disconnect = qla4xxx_ep_disconnect,
  199. .get_stats = qla4xxx_conn_get_stats,
  200. .send_pdu = iscsi_conn_send_pdu,
  201. .xmit_task = qla4xxx_task_xmit,
  202. .cleanup_task = qla4xxx_task_cleanup,
  203. .alloc_pdu = qla4xxx_alloc_pdu,
  204. .get_host_param = qla4xxx_host_get_param,
  205. .set_iface_param = qla4xxx_iface_set_param,
  206. .get_iface_param = qla4xxx_get_iface_param,
  207. .bsg_request = qla4xxx_bsg_request,
  208. .send_ping = qla4xxx_send_ping,
  209. .get_chap = qla4xxx_get_chap_list,
  210. .delete_chap = qla4xxx_delete_chap,
  211. };
  212. static struct scsi_transport_template *qla4xxx_scsi_transport;
  213. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  214. uint32_t iface_type, uint32_t payload_size,
  215. uint32_t pid, struct sockaddr *dst_addr)
  216. {
  217. struct scsi_qla_host *ha = to_qla_host(shost);
  218. struct sockaddr_in *addr;
  219. struct sockaddr_in6 *addr6;
  220. uint32_t options = 0;
  221. uint8_t ipaddr[IPv6_ADDR_LEN];
  222. int rval;
  223. memset(ipaddr, 0, IPv6_ADDR_LEN);
  224. /* IPv4 to IPv4 */
  225. if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
  226. (dst_addr->sa_family == AF_INET)) {
  227. addr = (struct sockaddr_in *)dst_addr;
  228. memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
  229. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
  230. "dest: %pI4\n", __func__,
  231. &ha->ip_config.ip_address, ipaddr));
  232. rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
  233. ipaddr);
  234. if (rval)
  235. rval = -EINVAL;
  236. } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
  237. (dst_addr->sa_family == AF_INET6)) {
  238. /* IPv6 to IPv6 */
  239. addr6 = (struct sockaddr_in6 *)dst_addr;
  240. memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
  241. options |= PING_IPV6_PROTOCOL_ENABLE;
  242. /* Ping using LinkLocal address */
  243. if ((iface_num == 0) || (iface_num == 1)) {
  244. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
  245. "src: %pI6 dest: %pI6\n", __func__,
  246. &ha->ip_config.ipv6_link_local_addr,
  247. ipaddr));
  248. options |= PING_IPV6_LINKLOCAL_ADDR;
  249. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  250. pid, ipaddr);
  251. } else {
  252. ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
  253. "not supported\n", __func__, iface_num);
  254. rval = -ENOSYS;
  255. goto exit_send_ping;
  256. }
  257. /*
  258. * If ping using LinkLocal address fails, try ping using
  259. * IPv6 address
  260. */
  261. if (rval != QLA_SUCCESS) {
  262. options &= ~PING_IPV6_LINKLOCAL_ADDR;
  263. if (iface_num == 0) {
  264. options |= PING_IPV6_ADDR0;
  265. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  266. "Ping src: %pI6 "
  267. "dest: %pI6\n", __func__,
  268. &ha->ip_config.ipv6_addr0,
  269. ipaddr));
  270. } else if (iface_num == 1) {
  271. options |= PING_IPV6_ADDR1;
  272. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  273. "Ping src: %pI6 "
  274. "dest: %pI6\n", __func__,
  275. &ha->ip_config.ipv6_addr1,
  276. ipaddr));
  277. }
  278. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  279. pid, ipaddr);
  280. if (rval)
  281. rval = -EINVAL;
  282. }
  283. } else
  284. rval = -ENOSYS;
  285. exit_send_ping:
  286. return rval;
  287. }
  288. static umode_t qla4_attr_is_visible(int param_type, int param)
  289. {
  290. switch (param_type) {
  291. case ISCSI_HOST_PARAM:
  292. switch (param) {
  293. case ISCSI_HOST_PARAM_HWADDRESS:
  294. case ISCSI_HOST_PARAM_IPADDRESS:
  295. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  296. case ISCSI_HOST_PARAM_PORT_STATE:
  297. case ISCSI_HOST_PARAM_PORT_SPEED:
  298. return S_IRUGO;
  299. default:
  300. return 0;
  301. }
  302. case ISCSI_PARAM:
  303. switch (param) {
  304. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  305. case ISCSI_PARAM_PERSISTENT_PORT:
  306. case ISCSI_PARAM_CONN_ADDRESS:
  307. case ISCSI_PARAM_CONN_PORT:
  308. case ISCSI_PARAM_TARGET_NAME:
  309. case ISCSI_PARAM_TPGT:
  310. case ISCSI_PARAM_TARGET_ALIAS:
  311. case ISCSI_PARAM_MAX_BURST:
  312. case ISCSI_PARAM_MAX_R2T:
  313. case ISCSI_PARAM_FIRST_BURST:
  314. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  315. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  316. case ISCSI_PARAM_IFACE_NAME:
  317. case ISCSI_PARAM_CHAP_OUT_IDX:
  318. case ISCSI_PARAM_CHAP_IN_IDX:
  319. case ISCSI_PARAM_USERNAME:
  320. case ISCSI_PARAM_PASSWORD:
  321. case ISCSI_PARAM_USERNAME_IN:
  322. case ISCSI_PARAM_PASSWORD_IN:
  323. return S_IRUGO;
  324. default:
  325. return 0;
  326. }
  327. case ISCSI_NET_PARAM:
  328. switch (param) {
  329. case ISCSI_NET_PARAM_IPV4_ADDR:
  330. case ISCSI_NET_PARAM_IPV4_SUBNET:
  331. case ISCSI_NET_PARAM_IPV4_GW:
  332. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  333. case ISCSI_NET_PARAM_IFACE_ENABLE:
  334. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  335. case ISCSI_NET_PARAM_IPV6_ADDR:
  336. case ISCSI_NET_PARAM_IPV6_ROUTER:
  337. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  338. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  339. case ISCSI_NET_PARAM_VLAN_ID:
  340. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  341. case ISCSI_NET_PARAM_VLAN_ENABLED:
  342. case ISCSI_NET_PARAM_MTU:
  343. case ISCSI_NET_PARAM_PORT:
  344. return S_IRUGO;
  345. default:
  346. return 0;
  347. }
  348. }
  349. return 0;
  350. }
  351. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  352. uint32_t *num_entries, char *buf)
  353. {
  354. struct scsi_qla_host *ha = to_qla_host(shost);
  355. struct ql4_chap_table *chap_table;
  356. struct iscsi_chap_rec *chap_rec;
  357. int max_chap_entries = 0;
  358. int valid_chap_entries = 0;
  359. int ret = 0, i;
  360. if (is_qla8022(ha))
  361. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  362. sizeof(struct ql4_chap_table);
  363. else
  364. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  365. ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
  366. __func__, *num_entries, chap_tbl_idx);
  367. if (!buf) {
  368. ret = -ENOMEM;
  369. goto exit_get_chap_list;
  370. }
  371. chap_rec = (struct iscsi_chap_rec *) buf;
  372. mutex_lock(&ha->chap_sem);
  373. for (i = chap_tbl_idx; i < max_chap_entries; i++) {
  374. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  375. if (chap_table->cookie !=
  376. __constant_cpu_to_le16(CHAP_VALID_COOKIE))
  377. continue;
  378. chap_rec->chap_tbl_idx = i;
  379. strncpy(chap_rec->username, chap_table->name,
  380. ISCSI_CHAP_AUTH_NAME_MAX_LEN);
  381. strncpy(chap_rec->password, chap_table->secret,
  382. QL4_CHAP_MAX_SECRET_LEN);
  383. chap_rec->password_length = chap_table->secret_len;
  384. if (chap_table->flags & BIT_7) /* local */
  385. chap_rec->chap_type = CHAP_TYPE_OUT;
  386. if (chap_table->flags & BIT_6) /* peer */
  387. chap_rec->chap_type = CHAP_TYPE_IN;
  388. chap_rec++;
  389. valid_chap_entries++;
  390. if (valid_chap_entries == *num_entries)
  391. break;
  392. else
  393. continue;
  394. }
  395. mutex_unlock(&ha->chap_sem);
  396. exit_get_chap_list:
  397. ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
  398. __func__, valid_chap_entries);
  399. *num_entries = valid_chap_entries;
  400. return ret;
  401. }
  402. static int __qla4xxx_is_chap_active(struct device *dev, void *data)
  403. {
  404. int ret = 0;
  405. uint16_t *chap_tbl_idx = (uint16_t *) data;
  406. struct iscsi_cls_session *cls_session;
  407. struct iscsi_session *sess;
  408. struct ddb_entry *ddb_entry;
  409. if (!iscsi_is_session_dev(dev))
  410. goto exit_is_chap_active;
  411. cls_session = iscsi_dev_to_session(dev);
  412. sess = cls_session->dd_data;
  413. ddb_entry = sess->dd_data;
  414. if (iscsi_session_chkready(cls_session))
  415. goto exit_is_chap_active;
  416. if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
  417. ret = 1;
  418. exit_is_chap_active:
  419. return ret;
  420. }
  421. static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
  422. uint16_t chap_tbl_idx)
  423. {
  424. int ret = 0;
  425. ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
  426. __qla4xxx_is_chap_active);
  427. return ret;
  428. }
  429. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
  430. {
  431. struct scsi_qla_host *ha = to_qla_host(shost);
  432. struct ql4_chap_table *chap_table;
  433. dma_addr_t chap_dma;
  434. int max_chap_entries = 0;
  435. uint32_t offset = 0;
  436. uint32_t chap_size;
  437. int ret = 0;
  438. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  439. if (chap_table == NULL)
  440. return -ENOMEM;
  441. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  442. if (is_qla8022(ha))
  443. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  444. sizeof(struct ql4_chap_table);
  445. else
  446. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  447. if (chap_tbl_idx > max_chap_entries) {
  448. ret = -EINVAL;
  449. goto exit_delete_chap;
  450. }
  451. /* Check if chap index is in use.
  452. * If chap is in use don't delet chap entry */
  453. ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
  454. if (ret) {
  455. ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
  456. "delete from flash\n", chap_tbl_idx);
  457. ret = -EBUSY;
  458. goto exit_delete_chap;
  459. }
  460. chap_size = sizeof(struct ql4_chap_table);
  461. if (is_qla40XX(ha))
  462. offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
  463. else {
  464. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  465. /* flt_chap_size is CHAP table size for both ports
  466. * so divide it by 2 to calculate the offset for second port
  467. */
  468. if (ha->port_num == 1)
  469. offset += (ha->hw.flt_chap_size / 2);
  470. offset += (chap_tbl_idx * chap_size);
  471. }
  472. ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  473. if (ret != QLA_SUCCESS) {
  474. ret = -EINVAL;
  475. goto exit_delete_chap;
  476. }
  477. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  478. __le16_to_cpu(chap_table->cookie)));
  479. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  480. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  481. goto exit_delete_chap;
  482. }
  483. chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
  484. offset = FLASH_CHAP_OFFSET |
  485. (chap_tbl_idx * sizeof(struct ql4_chap_table));
  486. ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
  487. FLASH_OPT_RMW_COMMIT);
  488. if (ret == QLA_SUCCESS && ha->chap_list) {
  489. mutex_lock(&ha->chap_sem);
  490. /* Update ha chap_list cache */
  491. memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
  492. chap_table, sizeof(struct ql4_chap_table));
  493. mutex_unlock(&ha->chap_sem);
  494. }
  495. if (ret != QLA_SUCCESS)
  496. ret = -EINVAL;
  497. exit_delete_chap:
  498. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  499. return ret;
  500. }
  501. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  502. enum iscsi_param_type param_type,
  503. int param, char *buf)
  504. {
  505. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  506. struct scsi_qla_host *ha = to_qla_host(shost);
  507. int len = -ENOSYS;
  508. if (param_type != ISCSI_NET_PARAM)
  509. return -ENOSYS;
  510. switch (param) {
  511. case ISCSI_NET_PARAM_IPV4_ADDR:
  512. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  513. break;
  514. case ISCSI_NET_PARAM_IPV4_SUBNET:
  515. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  516. break;
  517. case ISCSI_NET_PARAM_IPV4_GW:
  518. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  519. break;
  520. case ISCSI_NET_PARAM_IFACE_ENABLE:
  521. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  522. len = sprintf(buf, "%s\n",
  523. (ha->ip_config.ipv4_options &
  524. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  525. "enabled" : "disabled");
  526. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  527. len = sprintf(buf, "%s\n",
  528. (ha->ip_config.ipv6_options &
  529. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  530. "enabled" : "disabled");
  531. break;
  532. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  533. len = sprintf(buf, "%s\n",
  534. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  535. "dhcp" : "static");
  536. break;
  537. case ISCSI_NET_PARAM_IPV6_ADDR:
  538. if (iface->iface_num == 0)
  539. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  540. if (iface->iface_num == 1)
  541. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  542. break;
  543. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  544. len = sprintf(buf, "%pI6\n",
  545. &ha->ip_config.ipv6_link_local_addr);
  546. break;
  547. case ISCSI_NET_PARAM_IPV6_ROUTER:
  548. len = sprintf(buf, "%pI6\n",
  549. &ha->ip_config.ipv6_default_router_addr);
  550. break;
  551. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  552. len = sprintf(buf, "%s\n",
  553. (ha->ip_config.ipv6_addl_options &
  554. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  555. "nd" : "static");
  556. break;
  557. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  558. len = sprintf(buf, "%s\n",
  559. (ha->ip_config.ipv6_addl_options &
  560. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  561. "auto" : "static");
  562. break;
  563. case ISCSI_NET_PARAM_VLAN_ID:
  564. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  565. len = sprintf(buf, "%d\n",
  566. (ha->ip_config.ipv4_vlan_tag &
  567. ISCSI_MAX_VLAN_ID));
  568. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  569. len = sprintf(buf, "%d\n",
  570. (ha->ip_config.ipv6_vlan_tag &
  571. ISCSI_MAX_VLAN_ID));
  572. break;
  573. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  574. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  575. len = sprintf(buf, "%d\n",
  576. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  577. ISCSI_MAX_VLAN_PRIORITY));
  578. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  579. len = sprintf(buf, "%d\n",
  580. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  581. ISCSI_MAX_VLAN_PRIORITY));
  582. break;
  583. case ISCSI_NET_PARAM_VLAN_ENABLED:
  584. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  585. len = sprintf(buf, "%s\n",
  586. (ha->ip_config.ipv4_options &
  587. IPOPT_VLAN_TAGGING_ENABLE) ?
  588. "enabled" : "disabled");
  589. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  590. len = sprintf(buf, "%s\n",
  591. (ha->ip_config.ipv6_options &
  592. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  593. "enabled" : "disabled");
  594. break;
  595. case ISCSI_NET_PARAM_MTU:
  596. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  597. break;
  598. case ISCSI_NET_PARAM_PORT:
  599. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  600. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
  601. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  602. len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
  603. break;
  604. default:
  605. len = -ENOSYS;
  606. }
  607. return len;
  608. }
  609. static struct iscsi_endpoint *
  610. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  611. int non_blocking)
  612. {
  613. int ret;
  614. struct iscsi_endpoint *ep;
  615. struct qla_endpoint *qla_ep;
  616. struct scsi_qla_host *ha;
  617. struct sockaddr_in *addr;
  618. struct sockaddr_in6 *addr6;
  619. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  620. if (!shost) {
  621. ret = -ENXIO;
  622. printk(KERN_ERR "%s: shost is NULL\n",
  623. __func__);
  624. return ERR_PTR(ret);
  625. }
  626. ha = iscsi_host_priv(shost);
  627. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  628. if (!ep) {
  629. ret = -ENOMEM;
  630. return ERR_PTR(ret);
  631. }
  632. qla_ep = ep->dd_data;
  633. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  634. if (dst_addr->sa_family == AF_INET) {
  635. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  636. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  637. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  638. (char *)&addr->sin_addr));
  639. } else if (dst_addr->sa_family == AF_INET6) {
  640. memcpy(&qla_ep->dst_addr, dst_addr,
  641. sizeof(struct sockaddr_in6));
  642. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  643. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  644. (char *)&addr6->sin6_addr));
  645. }
  646. qla_ep->host = shost;
  647. return ep;
  648. }
  649. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  650. {
  651. struct qla_endpoint *qla_ep;
  652. struct scsi_qla_host *ha;
  653. int ret = 0;
  654. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  655. qla_ep = ep->dd_data;
  656. ha = to_qla_host(qla_ep->host);
  657. if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
  658. ret = 1;
  659. return ret;
  660. }
  661. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  662. {
  663. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  664. iscsi_destroy_endpoint(ep);
  665. }
  666. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  667. enum iscsi_param param,
  668. char *buf)
  669. {
  670. struct qla_endpoint *qla_ep = ep->dd_data;
  671. struct sockaddr *dst_addr;
  672. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  673. switch (param) {
  674. case ISCSI_PARAM_CONN_PORT:
  675. case ISCSI_PARAM_CONN_ADDRESS:
  676. if (!qla_ep)
  677. return -ENOTCONN;
  678. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  679. if (!dst_addr)
  680. return -ENOTCONN;
  681. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  682. &qla_ep->dst_addr, param, buf);
  683. default:
  684. return -ENOSYS;
  685. }
  686. }
  687. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  688. struct iscsi_stats *stats)
  689. {
  690. struct iscsi_session *sess;
  691. struct iscsi_cls_session *cls_sess;
  692. struct ddb_entry *ddb_entry;
  693. struct scsi_qla_host *ha;
  694. struct ql_iscsi_stats *ql_iscsi_stats;
  695. int stats_size;
  696. int ret;
  697. dma_addr_t iscsi_stats_dma;
  698. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  699. cls_sess = iscsi_conn_to_session(cls_conn);
  700. sess = cls_sess->dd_data;
  701. ddb_entry = sess->dd_data;
  702. ha = ddb_entry->ha;
  703. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  704. /* Allocate memory */
  705. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  706. &iscsi_stats_dma, GFP_KERNEL);
  707. if (!ql_iscsi_stats) {
  708. ql4_printk(KERN_ERR, ha,
  709. "Unable to allocate memory for iscsi stats\n");
  710. goto exit_get_stats;
  711. }
  712. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  713. iscsi_stats_dma);
  714. if (ret != QLA_SUCCESS) {
  715. ql4_printk(KERN_ERR, ha,
  716. "Unable to retrieve iscsi stats\n");
  717. goto free_stats;
  718. }
  719. /* octets */
  720. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  721. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  722. /* xmit pdus */
  723. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  724. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  725. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  726. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  727. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  728. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  729. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  730. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  731. /* recv pdus */
  732. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  733. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  734. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  735. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  736. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  737. stats->logoutrsp_pdus =
  738. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  739. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  740. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  741. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  742. free_stats:
  743. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  744. iscsi_stats_dma);
  745. exit_get_stats:
  746. return;
  747. }
  748. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  749. {
  750. struct iscsi_cls_session *session;
  751. struct iscsi_session *sess;
  752. unsigned long flags;
  753. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  754. session = starget_to_session(scsi_target(sc->device));
  755. sess = session->dd_data;
  756. spin_lock_irqsave(&session->lock, flags);
  757. if (session->state == ISCSI_SESSION_FAILED)
  758. ret = BLK_EH_RESET_TIMER;
  759. spin_unlock_irqrestore(&session->lock, flags);
  760. return ret;
  761. }
  762. static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
  763. {
  764. struct scsi_qla_host *ha = to_qla_host(shost);
  765. struct iscsi_cls_host *ihost = shost->shost_data;
  766. uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
  767. qla4xxx_get_firmware_state(ha);
  768. switch (ha->addl_fw_state & 0x0F00) {
  769. case FW_ADDSTATE_LINK_SPEED_10MBPS:
  770. speed = ISCSI_PORT_SPEED_10MBPS;
  771. break;
  772. case FW_ADDSTATE_LINK_SPEED_100MBPS:
  773. speed = ISCSI_PORT_SPEED_100MBPS;
  774. break;
  775. case FW_ADDSTATE_LINK_SPEED_1GBPS:
  776. speed = ISCSI_PORT_SPEED_1GBPS;
  777. break;
  778. case FW_ADDSTATE_LINK_SPEED_10GBPS:
  779. speed = ISCSI_PORT_SPEED_10GBPS;
  780. break;
  781. }
  782. ihost->port_speed = speed;
  783. }
  784. static void qla4xxx_set_port_state(struct Scsi_Host *shost)
  785. {
  786. struct scsi_qla_host *ha = to_qla_host(shost);
  787. struct iscsi_cls_host *ihost = shost->shost_data;
  788. uint32_t state = ISCSI_PORT_STATE_DOWN;
  789. if (test_bit(AF_LINK_UP, &ha->flags))
  790. state = ISCSI_PORT_STATE_UP;
  791. ihost->port_state = state;
  792. }
  793. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  794. enum iscsi_host_param param, char *buf)
  795. {
  796. struct scsi_qla_host *ha = to_qla_host(shost);
  797. int len;
  798. switch (param) {
  799. case ISCSI_HOST_PARAM_HWADDRESS:
  800. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  801. break;
  802. case ISCSI_HOST_PARAM_IPADDRESS:
  803. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  804. break;
  805. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  806. len = sprintf(buf, "%s\n", ha->name_string);
  807. break;
  808. case ISCSI_HOST_PARAM_PORT_STATE:
  809. qla4xxx_set_port_state(shost);
  810. len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  811. break;
  812. case ISCSI_HOST_PARAM_PORT_SPEED:
  813. qla4xxx_set_port_speed(shost);
  814. len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  815. break;
  816. default:
  817. return -ENOSYS;
  818. }
  819. return len;
  820. }
  821. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  822. {
  823. if (ha->iface_ipv4)
  824. return;
  825. /* IPv4 */
  826. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  827. &qla4xxx_iscsi_transport,
  828. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  829. if (!ha->iface_ipv4)
  830. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  831. "iface0.\n");
  832. }
  833. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  834. {
  835. if (!ha->iface_ipv6_0)
  836. /* IPv6 iface-0 */
  837. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  838. &qla4xxx_iscsi_transport,
  839. ISCSI_IFACE_TYPE_IPV6, 0,
  840. 0);
  841. if (!ha->iface_ipv6_0)
  842. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  843. "iface0.\n");
  844. if (!ha->iface_ipv6_1)
  845. /* IPv6 iface-1 */
  846. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  847. &qla4xxx_iscsi_transport,
  848. ISCSI_IFACE_TYPE_IPV6, 1,
  849. 0);
  850. if (!ha->iface_ipv6_1)
  851. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  852. "iface1.\n");
  853. }
  854. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  855. {
  856. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  857. qla4xxx_create_ipv4_iface(ha);
  858. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  859. qla4xxx_create_ipv6_iface(ha);
  860. }
  861. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  862. {
  863. if (ha->iface_ipv4) {
  864. iscsi_destroy_iface(ha->iface_ipv4);
  865. ha->iface_ipv4 = NULL;
  866. }
  867. }
  868. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  869. {
  870. if (ha->iface_ipv6_0) {
  871. iscsi_destroy_iface(ha->iface_ipv6_0);
  872. ha->iface_ipv6_0 = NULL;
  873. }
  874. if (ha->iface_ipv6_1) {
  875. iscsi_destroy_iface(ha->iface_ipv6_1);
  876. ha->iface_ipv6_1 = NULL;
  877. }
  878. }
  879. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  880. {
  881. qla4xxx_destroy_ipv4_iface(ha);
  882. qla4xxx_destroy_ipv6_iface(ha);
  883. }
  884. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  885. struct iscsi_iface_param_info *iface_param,
  886. struct addr_ctrl_blk *init_fw_cb)
  887. {
  888. /*
  889. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  890. * iface_num 1 is valid only for IPv6 Addr.
  891. */
  892. switch (iface_param->param) {
  893. case ISCSI_NET_PARAM_IPV6_ADDR:
  894. if (iface_param->iface_num & 0x1)
  895. /* IPv6 Addr 1 */
  896. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  897. sizeof(init_fw_cb->ipv6_addr1));
  898. else
  899. /* IPv6 Addr 0 */
  900. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  901. sizeof(init_fw_cb->ipv6_addr0));
  902. break;
  903. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  904. if (iface_param->iface_num & 0x1)
  905. break;
  906. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  907. sizeof(init_fw_cb->ipv6_if_id));
  908. break;
  909. case ISCSI_NET_PARAM_IPV6_ROUTER:
  910. if (iface_param->iface_num & 0x1)
  911. break;
  912. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  913. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  914. break;
  915. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  916. /* Autocfg applies to even interface */
  917. if (iface_param->iface_num & 0x1)
  918. break;
  919. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  920. init_fw_cb->ipv6_addtl_opts &=
  921. cpu_to_le16(
  922. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  923. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  924. init_fw_cb->ipv6_addtl_opts |=
  925. cpu_to_le16(
  926. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  927. else
  928. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  929. "IPv6 addr\n");
  930. break;
  931. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  932. /* Autocfg applies to even interface */
  933. if (iface_param->iface_num & 0x1)
  934. break;
  935. if (iface_param->value[0] ==
  936. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  937. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  938. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  939. else if (iface_param->value[0] ==
  940. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  941. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  942. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  943. else
  944. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  945. "IPv6 linklocal addr\n");
  946. break;
  947. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  948. /* Autocfg applies to even interface */
  949. if (iface_param->iface_num & 0x1)
  950. break;
  951. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  952. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  953. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  954. break;
  955. case ISCSI_NET_PARAM_IFACE_ENABLE:
  956. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  957. init_fw_cb->ipv6_opts |=
  958. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  959. qla4xxx_create_ipv6_iface(ha);
  960. } else {
  961. init_fw_cb->ipv6_opts &=
  962. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  963. 0xFFFF);
  964. qla4xxx_destroy_ipv6_iface(ha);
  965. }
  966. break;
  967. case ISCSI_NET_PARAM_VLAN_TAG:
  968. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  969. break;
  970. init_fw_cb->ipv6_vlan_tag =
  971. cpu_to_be16(*(uint16_t *)iface_param->value);
  972. break;
  973. case ISCSI_NET_PARAM_VLAN_ENABLED:
  974. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  975. init_fw_cb->ipv6_opts |=
  976. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  977. else
  978. init_fw_cb->ipv6_opts &=
  979. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  980. break;
  981. case ISCSI_NET_PARAM_MTU:
  982. init_fw_cb->eth_mtu_size =
  983. cpu_to_le16(*(uint16_t *)iface_param->value);
  984. break;
  985. case ISCSI_NET_PARAM_PORT:
  986. /* Autocfg applies to even interface */
  987. if (iface_param->iface_num & 0x1)
  988. break;
  989. init_fw_cb->ipv6_port =
  990. cpu_to_le16(*(uint16_t *)iface_param->value);
  991. break;
  992. default:
  993. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  994. iface_param->param);
  995. break;
  996. }
  997. }
  998. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  999. struct iscsi_iface_param_info *iface_param,
  1000. struct addr_ctrl_blk *init_fw_cb)
  1001. {
  1002. switch (iface_param->param) {
  1003. case ISCSI_NET_PARAM_IPV4_ADDR:
  1004. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  1005. sizeof(init_fw_cb->ipv4_addr));
  1006. break;
  1007. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1008. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  1009. sizeof(init_fw_cb->ipv4_subnet));
  1010. break;
  1011. case ISCSI_NET_PARAM_IPV4_GW:
  1012. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  1013. sizeof(init_fw_cb->ipv4_gw_addr));
  1014. break;
  1015. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1016. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  1017. init_fw_cb->ipv4_tcp_opts |=
  1018. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  1019. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  1020. init_fw_cb->ipv4_tcp_opts &=
  1021. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  1022. else
  1023. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  1024. break;
  1025. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1026. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1027. init_fw_cb->ipv4_ip_opts |=
  1028. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  1029. qla4xxx_create_ipv4_iface(ha);
  1030. } else {
  1031. init_fw_cb->ipv4_ip_opts &=
  1032. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  1033. 0xFFFF);
  1034. qla4xxx_destroy_ipv4_iface(ha);
  1035. }
  1036. break;
  1037. case ISCSI_NET_PARAM_VLAN_TAG:
  1038. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  1039. break;
  1040. init_fw_cb->ipv4_vlan_tag =
  1041. cpu_to_be16(*(uint16_t *)iface_param->value);
  1042. break;
  1043. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1044. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1045. init_fw_cb->ipv4_ip_opts |=
  1046. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  1047. else
  1048. init_fw_cb->ipv4_ip_opts &=
  1049. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  1050. break;
  1051. case ISCSI_NET_PARAM_MTU:
  1052. init_fw_cb->eth_mtu_size =
  1053. cpu_to_le16(*(uint16_t *)iface_param->value);
  1054. break;
  1055. case ISCSI_NET_PARAM_PORT:
  1056. init_fw_cb->ipv4_port =
  1057. cpu_to_le16(*(uint16_t *)iface_param->value);
  1058. break;
  1059. default:
  1060. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  1061. iface_param->param);
  1062. break;
  1063. }
  1064. }
  1065. static void
  1066. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  1067. {
  1068. struct addr_ctrl_blk_def *acb;
  1069. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  1070. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  1071. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  1072. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  1073. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  1074. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  1075. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  1076. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  1077. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  1078. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  1079. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  1080. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  1081. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  1082. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  1083. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  1084. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  1085. }
  1086. static int
  1087. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  1088. {
  1089. struct scsi_qla_host *ha = to_qla_host(shost);
  1090. int rval = 0;
  1091. struct iscsi_iface_param_info *iface_param = NULL;
  1092. struct addr_ctrl_blk *init_fw_cb = NULL;
  1093. dma_addr_t init_fw_cb_dma;
  1094. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1095. uint32_t mbox_sts[MBOX_REG_COUNT];
  1096. uint32_t rem = len;
  1097. struct nlattr *attr;
  1098. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  1099. sizeof(struct addr_ctrl_blk),
  1100. &init_fw_cb_dma, GFP_KERNEL);
  1101. if (!init_fw_cb) {
  1102. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  1103. __func__);
  1104. return -ENOMEM;
  1105. }
  1106. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1107. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1108. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1109. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  1110. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  1111. rval = -EIO;
  1112. goto exit_init_fw_cb;
  1113. }
  1114. nla_for_each_attr(attr, data, len, rem) {
  1115. iface_param = nla_data(attr);
  1116. if (iface_param->param_type != ISCSI_NET_PARAM)
  1117. continue;
  1118. switch (iface_param->iface_type) {
  1119. case ISCSI_IFACE_TYPE_IPV4:
  1120. switch (iface_param->iface_num) {
  1121. case 0:
  1122. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  1123. break;
  1124. default:
  1125. /* Cannot have more than one IPv4 interface */
  1126. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  1127. "number = %d\n",
  1128. iface_param->iface_num);
  1129. break;
  1130. }
  1131. break;
  1132. case ISCSI_IFACE_TYPE_IPV6:
  1133. switch (iface_param->iface_num) {
  1134. case 0:
  1135. case 1:
  1136. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  1137. break;
  1138. default:
  1139. /* Cannot have more than two IPv6 interface */
  1140. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  1141. "number = %d\n",
  1142. iface_param->iface_num);
  1143. break;
  1144. }
  1145. break;
  1146. default:
  1147. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  1148. break;
  1149. }
  1150. }
  1151. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  1152. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  1153. sizeof(struct addr_ctrl_blk),
  1154. FLASH_OPT_RMW_COMMIT);
  1155. if (rval != QLA_SUCCESS) {
  1156. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  1157. __func__);
  1158. rval = -EIO;
  1159. goto exit_init_fw_cb;
  1160. }
  1161. rval = qla4xxx_disable_acb(ha);
  1162. if (rval != QLA_SUCCESS) {
  1163. ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
  1164. __func__);
  1165. rval = -EIO;
  1166. goto exit_init_fw_cb;
  1167. }
  1168. wait_for_completion_timeout(&ha->disable_acb_comp,
  1169. DISABLE_ACB_TOV * HZ);
  1170. qla4xxx_initcb_to_acb(init_fw_cb);
  1171. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  1172. if (rval != QLA_SUCCESS) {
  1173. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  1174. __func__);
  1175. rval = -EIO;
  1176. goto exit_init_fw_cb;
  1177. }
  1178. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1179. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  1180. init_fw_cb_dma);
  1181. exit_init_fw_cb:
  1182. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  1183. init_fw_cb, init_fw_cb_dma);
  1184. return rval;
  1185. }
  1186. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  1187. enum iscsi_param param, char *buf)
  1188. {
  1189. struct iscsi_session *sess = cls_sess->dd_data;
  1190. struct ddb_entry *ddb_entry = sess->dd_data;
  1191. struct scsi_qla_host *ha = ddb_entry->ha;
  1192. int rval, len;
  1193. uint16_t idx;
  1194. switch (param) {
  1195. case ISCSI_PARAM_CHAP_IN_IDX:
  1196. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  1197. sess->password_in, BIDI_CHAP,
  1198. &idx);
  1199. if (rval)
  1200. len = sprintf(buf, "\n");
  1201. else
  1202. len = sprintf(buf, "%hu\n", idx);
  1203. break;
  1204. case ISCSI_PARAM_CHAP_OUT_IDX:
  1205. rval = qla4xxx_get_chap_index(ha, sess->username,
  1206. sess->password, LOCAL_CHAP,
  1207. &idx);
  1208. if (rval)
  1209. len = sprintf(buf, "\n");
  1210. else
  1211. len = sprintf(buf, "%hu\n", idx);
  1212. break;
  1213. default:
  1214. return iscsi_session_get_param(cls_sess, param, buf);
  1215. }
  1216. return len;
  1217. }
  1218. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  1219. enum iscsi_param param, char *buf)
  1220. {
  1221. struct iscsi_conn *conn;
  1222. struct qla_conn *qla_conn;
  1223. struct sockaddr *dst_addr;
  1224. int len = 0;
  1225. conn = cls_conn->dd_data;
  1226. qla_conn = conn->dd_data;
  1227. dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
  1228. switch (param) {
  1229. case ISCSI_PARAM_CONN_PORT:
  1230. case ISCSI_PARAM_CONN_ADDRESS:
  1231. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  1232. dst_addr, param, buf);
  1233. default:
  1234. return iscsi_conn_get_param(cls_conn, param, buf);
  1235. }
  1236. return len;
  1237. }
  1238. int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
  1239. {
  1240. uint32_t mbx_sts = 0;
  1241. uint16_t tmp_ddb_index;
  1242. int ret;
  1243. get_ddb_index:
  1244. tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  1245. if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
  1246. DEBUG2(ql4_printk(KERN_INFO, ha,
  1247. "Free DDB index not available\n"));
  1248. ret = QLA_ERROR;
  1249. goto exit_get_ddb_index;
  1250. }
  1251. if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
  1252. goto get_ddb_index;
  1253. DEBUG2(ql4_printk(KERN_INFO, ha,
  1254. "Found a free DDB index at %d\n", tmp_ddb_index));
  1255. ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
  1256. if (ret == QLA_ERROR) {
  1257. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  1258. ql4_printk(KERN_INFO, ha,
  1259. "DDB index = %d not available trying next\n",
  1260. tmp_ddb_index);
  1261. goto get_ddb_index;
  1262. }
  1263. DEBUG2(ql4_printk(KERN_INFO, ha,
  1264. "Free FW DDB not available\n"));
  1265. }
  1266. *ddb_index = tmp_ddb_index;
  1267. exit_get_ddb_index:
  1268. return ret;
  1269. }
  1270. static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
  1271. struct ddb_entry *ddb_entry,
  1272. char *existing_ipaddr,
  1273. char *user_ipaddr)
  1274. {
  1275. uint8_t dst_ipaddr[IPv6_ADDR_LEN];
  1276. char formatted_ipaddr[DDB_IPADDR_LEN];
  1277. int status = QLA_SUCCESS, ret = 0;
  1278. if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
  1279. ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1280. '\0', NULL);
  1281. if (ret == 0) {
  1282. status = QLA_ERROR;
  1283. goto out_match;
  1284. }
  1285. ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
  1286. } else {
  1287. ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1288. '\0', NULL);
  1289. if (ret == 0) {
  1290. status = QLA_ERROR;
  1291. goto out_match;
  1292. }
  1293. ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
  1294. }
  1295. if (strcmp(existing_ipaddr, formatted_ipaddr))
  1296. status = QLA_ERROR;
  1297. out_match:
  1298. return status;
  1299. }
  1300. static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
  1301. struct iscsi_cls_conn *cls_conn)
  1302. {
  1303. int idx = 0, max_ddbs, rval;
  1304. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1305. struct iscsi_session *sess, *existing_sess;
  1306. struct iscsi_conn *conn, *existing_conn;
  1307. struct ddb_entry *ddb_entry;
  1308. sess = cls_sess->dd_data;
  1309. conn = cls_conn->dd_data;
  1310. if (sess->targetname == NULL ||
  1311. conn->persistent_address == NULL ||
  1312. conn->persistent_port == 0)
  1313. return QLA_ERROR;
  1314. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  1315. MAX_DEV_DB_ENTRIES;
  1316. for (idx = 0; idx < max_ddbs; idx++) {
  1317. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  1318. if (ddb_entry == NULL)
  1319. continue;
  1320. if (ddb_entry->ddb_type != FLASH_DDB)
  1321. continue;
  1322. existing_sess = ddb_entry->sess->dd_data;
  1323. existing_conn = ddb_entry->conn->dd_data;
  1324. if (existing_sess->targetname == NULL ||
  1325. existing_conn->persistent_address == NULL ||
  1326. existing_conn->persistent_port == 0)
  1327. continue;
  1328. DEBUG2(ql4_printk(KERN_INFO, ha,
  1329. "IQN = %s User IQN = %s\n",
  1330. existing_sess->targetname,
  1331. sess->targetname));
  1332. DEBUG2(ql4_printk(KERN_INFO, ha,
  1333. "IP = %s User IP = %s\n",
  1334. existing_conn->persistent_address,
  1335. conn->persistent_address));
  1336. DEBUG2(ql4_printk(KERN_INFO, ha,
  1337. "Port = %d User Port = %d\n",
  1338. existing_conn->persistent_port,
  1339. conn->persistent_port));
  1340. if (strcmp(existing_sess->targetname, sess->targetname))
  1341. continue;
  1342. rval = qla4xxx_match_ipaddress(ha, ddb_entry,
  1343. existing_conn->persistent_address,
  1344. conn->persistent_address);
  1345. if (rval == QLA_ERROR)
  1346. continue;
  1347. if (existing_conn->persistent_port != conn->persistent_port)
  1348. continue;
  1349. break;
  1350. }
  1351. if (idx == max_ddbs)
  1352. return QLA_ERROR;
  1353. DEBUG2(ql4_printk(KERN_INFO, ha,
  1354. "Match found in fwdb sessions\n"));
  1355. return QLA_SUCCESS;
  1356. }
  1357. static struct iscsi_cls_session *
  1358. qla4xxx_session_create(struct iscsi_endpoint *ep,
  1359. uint16_t cmds_max, uint16_t qdepth,
  1360. uint32_t initial_cmdsn)
  1361. {
  1362. struct iscsi_cls_session *cls_sess;
  1363. struct scsi_qla_host *ha;
  1364. struct qla_endpoint *qla_ep;
  1365. struct ddb_entry *ddb_entry;
  1366. uint16_t ddb_index;
  1367. struct iscsi_session *sess;
  1368. struct sockaddr *dst_addr;
  1369. int ret;
  1370. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1371. if (!ep) {
  1372. printk(KERN_ERR "qla4xxx: missing ep.\n");
  1373. return NULL;
  1374. }
  1375. qla_ep = ep->dd_data;
  1376. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  1377. ha = to_qla_host(qla_ep->host);
  1378. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  1379. if (ret == QLA_ERROR)
  1380. return NULL;
  1381. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  1382. cmds_max, sizeof(struct ddb_entry),
  1383. sizeof(struct ql4_task_data),
  1384. initial_cmdsn, ddb_index);
  1385. if (!cls_sess)
  1386. return NULL;
  1387. sess = cls_sess->dd_data;
  1388. ddb_entry = sess->dd_data;
  1389. ddb_entry->fw_ddb_index = ddb_index;
  1390. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  1391. ddb_entry->ha = ha;
  1392. ddb_entry->sess = cls_sess;
  1393. ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
  1394. ddb_entry->ddb_change = qla4xxx_ddb_change;
  1395. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  1396. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  1397. ha->tot_ddbs++;
  1398. return cls_sess;
  1399. }
  1400. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  1401. {
  1402. struct iscsi_session *sess;
  1403. struct ddb_entry *ddb_entry;
  1404. struct scsi_qla_host *ha;
  1405. unsigned long flags, wtime;
  1406. struct dev_db_entry *fw_ddb_entry = NULL;
  1407. dma_addr_t fw_ddb_entry_dma;
  1408. uint32_t ddb_state;
  1409. int ret;
  1410. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1411. sess = cls_sess->dd_data;
  1412. ddb_entry = sess->dd_data;
  1413. ha = ddb_entry->ha;
  1414. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1415. &fw_ddb_entry_dma, GFP_KERNEL);
  1416. if (!fw_ddb_entry) {
  1417. ql4_printk(KERN_ERR, ha,
  1418. "%s: Unable to allocate dma buffer\n", __func__);
  1419. goto destroy_session;
  1420. }
  1421. wtime = jiffies + (HZ * LOGOUT_TOV);
  1422. do {
  1423. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  1424. fw_ddb_entry, fw_ddb_entry_dma,
  1425. NULL, NULL, &ddb_state, NULL,
  1426. NULL, NULL);
  1427. if (ret == QLA_ERROR)
  1428. goto destroy_session;
  1429. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  1430. (ddb_state == DDB_DS_SESSION_FAILED))
  1431. goto destroy_session;
  1432. schedule_timeout_uninterruptible(HZ);
  1433. } while ((time_after(wtime, jiffies)));
  1434. destroy_session:
  1435. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  1436. spin_lock_irqsave(&ha->hardware_lock, flags);
  1437. qla4xxx_free_ddb(ha, ddb_entry);
  1438. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1439. iscsi_session_teardown(cls_sess);
  1440. if (fw_ddb_entry)
  1441. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1442. fw_ddb_entry, fw_ddb_entry_dma);
  1443. }
  1444. static struct iscsi_cls_conn *
  1445. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  1446. {
  1447. struct iscsi_cls_conn *cls_conn;
  1448. struct iscsi_session *sess;
  1449. struct ddb_entry *ddb_entry;
  1450. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1451. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  1452. conn_idx);
  1453. if (!cls_conn)
  1454. return NULL;
  1455. sess = cls_sess->dd_data;
  1456. ddb_entry = sess->dd_data;
  1457. ddb_entry->conn = cls_conn;
  1458. return cls_conn;
  1459. }
  1460. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  1461. struct iscsi_cls_conn *cls_conn,
  1462. uint64_t transport_fd, int is_leading)
  1463. {
  1464. struct iscsi_conn *conn;
  1465. struct qla_conn *qla_conn;
  1466. struct iscsi_endpoint *ep;
  1467. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1468. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  1469. return -EINVAL;
  1470. ep = iscsi_lookup_endpoint(transport_fd);
  1471. conn = cls_conn->dd_data;
  1472. qla_conn = conn->dd_data;
  1473. qla_conn->qla_ep = ep->dd_data;
  1474. return 0;
  1475. }
  1476. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  1477. {
  1478. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1479. struct iscsi_session *sess;
  1480. struct ddb_entry *ddb_entry;
  1481. struct scsi_qla_host *ha;
  1482. struct dev_db_entry *fw_ddb_entry = NULL;
  1483. dma_addr_t fw_ddb_entry_dma;
  1484. uint32_t mbx_sts = 0;
  1485. int ret = 0;
  1486. int status = QLA_SUCCESS;
  1487. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1488. sess = cls_sess->dd_data;
  1489. ddb_entry = sess->dd_data;
  1490. ha = ddb_entry->ha;
  1491. /* Check if we have matching FW DDB, if yes then do not
  1492. * login to this target. This could cause target to logout previous
  1493. * connection
  1494. */
  1495. ret = qla4xxx_match_fwdb_session(ha, cls_conn);
  1496. if (ret == QLA_SUCCESS) {
  1497. ql4_printk(KERN_INFO, ha,
  1498. "Session already exist in FW.\n");
  1499. ret = -EEXIST;
  1500. goto exit_conn_start;
  1501. }
  1502. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1503. &fw_ddb_entry_dma, GFP_KERNEL);
  1504. if (!fw_ddb_entry) {
  1505. ql4_printk(KERN_ERR, ha,
  1506. "%s: Unable to allocate dma buffer\n", __func__);
  1507. ret = -ENOMEM;
  1508. goto exit_conn_start;
  1509. }
  1510. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  1511. if (ret) {
  1512. /* If iscsid is stopped and started then no need to do
  1513. * set param again since ddb state will be already
  1514. * active and FW does not allow set ddb to an
  1515. * active session.
  1516. */
  1517. if (mbx_sts)
  1518. if (ddb_entry->fw_ddb_device_state ==
  1519. DDB_DS_SESSION_ACTIVE) {
  1520. ddb_entry->unblock_sess(ddb_entry->sess);
  1521. goto exit_set_param;
  1522. }
  1523. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  1524. __func__, ddb_entry->fw_ddb_index);
  1525. goto exit_conn_start;
  1526. }
  1527. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  1528. if (status == QLA_ERROR) {
  1529. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  1530. sess->targetname);
  1531. ret = -EINVAL;
  1532. goto exit_conn_start;
  1533. }
  1534. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  1535. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  1536. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  1537. ddb_entry->fw_ddb_device_state));
  1538. exit_set_param:
  1539. ret = 0;
  1540. exit_conn_start:
  1541. if (fw_ddb_entry)
  1542. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1543. fw_ddb_entry, fw_ddb_entry_dma);
  1544. return ret;
  1545. }
  1546. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1547. {
  1548. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1549. struct iscsi_session *sess;
  1550. struct scsi_qla_host *ha;
  1551. struct ddb_entry *ddb_entry;
  1552. int options;
  1553. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1554. sess = cls_sess->dd_data;
  1555. ddb_entry = sess->dd_data;
  1556. ha = ddb_entry->ha;
  1557. options = LOGOUT_OPTION_CLOSE_SESSION;
  1558. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  1559. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  1560. }
  1561. static void qla4xxx_task_work(struct work_struct *wdata)
  1562. {
  1563. struct ql4_task_data *task_data;
  1564. struct scsi_qla_host *ha;
  1565. struct passthru_status *sts;
  1566. struct iscsi_task *task;
  1567. struct iscsi_hdr *hdr;
  1568. uint8_t *data;
  1569. uint32_t data_len;
  1570. struct iscsi_conn *conn;
  1571. int hdr_len;
  1572. itt_t itt;
  1573. task_data = container_of(wdata, struct ql4_task_data, task_work);
  1574. ha = task_data->ha;
  1575. task = task_data->task;
  1576. sts = &task_data->sts;
  1577. hdr_len = sizeof(struct iscsi_hdr);
  1578. DEBUG3(printk(KERN_INFO "Status returned\n"));
  1579. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  1580. DEBUG3(printk(KERN_INFO "Response buffer"));
  1581. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  1582. conn = task->conn;
  1583. switch (sts->completionStatus) {
  1584. case PASSTHRU_STATUS_COMPLETE:
  1585. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  1586. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  1587. itt = sts->handle;
  1588. hdr->itt = itt;
  1589. data = task_data->resp_buffer + hdr_len;
  1590. data_len = task_data->resp_len - hdr_len;
  1591. iscsi_complete_pdu(conn, hdr, data, data_len);
  1592. break;
  1593. default:
  1594. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  1595. sts->completionStatus);
  1596. break;
  1597. }
  1598. return;
  1599. }
  1600. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  1601. {
  1602. struct ql4_task_data *task_data;
  1603. struct iscsi_session *sess;
  1604. struct ddb_entry *ddb_entry;
  1605. struct scsi_qla_host *ha;
  1606. int hdr_len;
  1607. sess = task->conn->session;
  1608. ddb_entry = sess->dd_data;
  1609. ha = ddb_entry->ha;
  1610. task_data = task->dd_data;
  1611. memset(task_data, 0, sizeof(struct ql4_task_data));
  1612. if (task->sc) {
  1613. ql4_printk(KERN_INFO, ha,
  1614. "%s: SCSI Commands not implemented\n", __func__);
  1615. return -EINVAL;
  1616. }
  1617. hdr_len = sizeof(struct iscsi_hdr);
  1618. task_data->ha = ha;
  1619. task_data->task = task;
  1620. if (task->data_count) {
  1621. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  1622. task->data_count,
  1623. PCI_DMA_TODEVICE);
  1624. }
  1625. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1626. __func__, task->conn->max_recv_dlength, hdr_len));
  1627. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  1628. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1629. task_data->resp_len,
  1630. &task_data->resp_dma,
  1631. GFP_ATOMIC);
  1632. if (!task_data->resp_buffer)
  1633. goto exit_alloc_pdu;
  1634. task_data->req_len = task->data_count + hdr_len;
  1635. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1636. task_data->req_len,
  1637. &task_data->req_dma,
  1638. GFP_ATOMIC);
  1639. if (!task_data->req_buffer)
  1640. goto exit_alloc_pdu;
  1641. task->hdr = task_data->req_buffer;
  1642. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  1643. return 0;
  1644. exit_alloc_pdu:
  1645. if (task_data->resp_buffer)
  1646. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1647. task_data->resp_buffer, task_data->resp_dma);
  1648. if (task_data->req_buffer)
  1649. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1650. task_data->req_buffer, task_data->req_dma);
  1651. return -ENOMEM;
  1652. }
  1653. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  1654. {
  1655. struct ql4_task_data *task_data;
  1656. struct iscsi_session *sess;
  1657. struct ddb_entry *ddb_entry;
  1658. struct scsi_qla_host *ha;
  1659. int hdr_len;
  1660. hdr_len = sizeof(struct iscsi_hdr);
  1661. sess = task->conn->session;
  1662. ddb_entry = sess->dd_data;
  1663. ha = ddb_entry->ha;
  1664. task_data = task->dd_data;
  1665. if (task->data_count) {
  1666. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  1667. task->data_count, PCI_DMA_TODEVICE);
  1668. }
  1669. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1670. __func__, task->conn->max_recv_dlength, hdr_len));
  1671. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1672. task_data->resp_buffer, task_data->resp_dma);
  1673. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1674. task_data->req_buffer, task_data->req_dma);
  1675. return;
  1676. }
  1677. static int qla4xxx_task_xmit(struct iscsi_task *task)
  1678. {
  1679. struct scsi_cmnd *sc = task->sc;
  1680. struct iscsi_session *sess = task->conn->session;
  1681. struct ddb_entry *ddb_entry = sess->dd_data;
  1682. struct scsi_qla_host *ha = ddb_entry->ha;
  1683. if (!sc)
  1684. return qla4xxx_send_passthru0(task);
  1685. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  1686. __func__);
  1687. return -ENOSYS;
  1688. }
  1689. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  1690. struct dev_db_entry *fw_ddb_entry,
  1691. struct iscsi_cls_session *cls_sess,
  1692. struct iscsi_cls_conn *cls_conn)
  1693. {
  1694. int buflen = 0;
  1695. struct iscsi_session *sess;
  1696. struct ddb_entry *ddb_entry;
  1697. struct iscsi_conn *conn;
  1698. char ip_addr[DDB_IPADDR_LEN];
  1699. uint16_t options = 0;
  1700. sess = cls_sess->dd_data;
  1701. ddb_entry = sess->dd_data;
  1702. conn = cls_conn->dd_data;
  1703. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1704. conn->max_recv_dlength = BYTE_UNITS *
  1705. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1706. conn->max_xmit_dlength = BYTE_UNITS *
  1707. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1708. sess->initial_r2t_en =
  1709. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1710. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1711. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1712. sess->first_burst = BYTE_UNITS *
  1713. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1714. sess->max_burst = BYTE_UNITS *
  1715. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1716. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1717. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1718. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  1719. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1720. options = le16_to_cpu(fw_ddb_entry->options);
  1721. if (options & DDB_OPT_IPV6_DEVICE)
  1722. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  1723. else
  1724. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  1725. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  1726. (char *)fw_ddb_entry->iscsi_name, buflen);
  1727. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  1728. (char *)ha->name_string, buflen);
  1729. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  1730. (char *)ip_addr, buflen);
  1731. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  1732. (char *)fw_ddb_entry->iscsi_alias, buflen);
  1733. }
  1734. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  1735. struct ddb_entry *ddb_entry)
  1736. {
  1737. struct iscsi_cls_session *cls_sess;
  1738. struct iscsi_cls_conn *cls_conn;
  1739. uint32_t ddb_state;
  1740. dma_addr_t fw_ddb_entry_dma;
  1741. struct dev_db_entry *fw_ddb_entry;
  1742. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1743. &fw_ddb_entry_dma, GFP_KERNEL);
  1744. if (!fw_ddb_entry) {
  1745. ql4_printk(KERN_ERR, ha,
  1746. "%s: Unable to allocate dma buffer\n", __func__);
  1747. goto exit_session_conn_fwddb_param;
  1748. }
  1749. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1750. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1751. NULL, NULL, NULL) == QLA_ERROR) {
  1752. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1753. "get_ddb_entry for fw_ddb_index %d\n",
  1754. ha->host_no, __func__,
  1755. ddb_entry->fw_ddb_index));
  1756. goto exit_session_conn_fwddb_param;
  1757. }
  1758. cls_sess = ddb_entry->sess;
  1759. cls_conn = ddb_entry->conn;
  1760. /* Update params */
  1761. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  1762. exit_session_conn_fwddb_param:
  1763. if (fw_ddb_entry)
  1764. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1765. fw_ddb_entry, fw_ddb_entry_dma);
  1766. }
  1767. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  1768. struct ddb_entry *ddb_entry)
  1769. {
  1770. struct iscsi_cls_session *cls_sess;
  1771. struct iscsi_cls_conn *cls_conn;
  1772. struct iscsi_session *sess;
  1773. struct iscsi_conn *conn;
  1774. uint32_t ddb_state;
  1775. dma_addr_t fw_ddb_entry_dma;
  1776. struct dev_db_entry *fw_ddb_entry;
  1777. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1778. &fw_ddb_entry_dma, GFP_KERNEL);
  1779. if (!fw_ddb_entry) {
  1780. ql4_printk(KERN_ERR, ha,
  1781. "%s: Unable to allocate dma buffer\n", __func__);
  1782. goto exit_session_conn_param;
  1783. }
  1784. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1785. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1786. NULL, NULL, NULL) == QLA_ERROR) {
  1787. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1788. "get_ddb_entry for fw_ddb_index %d\n",
  1789. ha->host_no, __func__,
  1790. ddb_entry->fw_ddb_index));
  1791. goto exit_session_conn_param;
  1792. }
  1793. cls_sess = ddb_entry->sess;
  1794. sess = cls_sess->dd_data;
  1795. cls_conn = ddb_entry->conn;
  1796. conn = cls_conn->dd_data;
  1797. /* Update timers after login */
  1798. ddb_entry->default_relogin_timeout =
  1799. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  1800. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  1801. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  1802. ddb_entry->default_time2wait =
  1803. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1804. /* Update params */
  1805. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1806. conn->max_recv_dlength = BYTE_UNITS *
  1807. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1808. conn->max_xmit_dlength = BYTE_UNITS *
  1809. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1810. sess->initial_r2t_en =
  1811. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1812. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1813. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1814. sess->first_burst = BYTE_UNITS *
  1815. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1816. sess->max_burst = BYTE_UNITS *
  1817. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1818. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1819. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1820. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1821. memcpy(sess->initiatorname, ha->name_string,
  1822. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  1823. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  1824. (char *)fw_ddb_entry->iscsi_alias, 0);
  1825. exit_session_conn_param:
  1826. if (fw_ddb_entry)
  1827. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1828. fw_ddb_entry, fw_ddb_entry_dma);
  1829. }
  1830. /*
  1831. * Timer routines
  1832. */
  1833. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  1834. unsigned long interval)
  1835. {
  1836. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  1837. __func__, ha->host->host_no));
  1838. init_timer(&ha->timer);
  1839. ha->timer.expires = jiffies + interval * HZ;
  1840. ha->timer.data = (unsigned long)ha;
  1841. ha->timer.function = (void (*)(unsigned long))func;
  1842. add_timer(&ha->timer);
  1843. ha->timer_active = 1;
  1844. }
  1845. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  1846. {
  1847. del_timer_sync(&ha->timer);
  1848. ha->timer_active = 0;
  1849. }
  1850. /***
  1851. * qla4xxx_mark_device_missing - blocks the session
  1852. * @cls_session: Pointer to the session to be blocked
  1853. * @ddb_entry: Pointer to device database entry
  1854. *
  1855. * This routine marks a device missing and close connection.
  1856. **/
  1857. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  1858. {
  1859. iscsi_block_session(cls_session);
  1860. }
  1861. /**
  1862. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  1863. * @ha: Pointer to host adapter structure.
  1864. *
  1865. * This routine marks a device missing and resets the relogin retry count.
  1866. **/
  1867. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  1868. {
  1869. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  1870. }
  1871. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  1872. struct ddb_entry *ddb_entry,
  1873. struct scsi_cmnd *cmd)
  1874. {
  1875. struct srb *srb;
  1876. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  1877. if (!srb)
  1878. return srb;
  1879. kref_init(&srb->srb_ref);
  1880. srb->ha = ha;
  1881. srb->ddb = ddb_entry;
  1882. srb->cmd = cmd;
  1883. srb->flags = 0;
  1884. CMD_SP(cmd) = (void *)srb;
  1885. return srb;
  1886. }
  1887. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  1888. {
  1889. struct scsi_cmnd *cmd = srb->cmd;
  1890. if (srb->flags & SRB_DMA_VALID) {
  1891. scsi_dma_unmap(cmd);
  1892. srb->flags &= ~SRB_DMA_VALID;
  1893. }
  1894. CMD_SP(cmd) = NULL;
  1895. }
  1896. void qla4xxx_srb_compl(struct kref *ref)
  1897. {
  1898. struct srb *srb = container_of(ref, struct srb, srb_ref);
  1899. struct scsi_cmnd *cmd = srb->cmd;
  1900. struct scsi_qla_host *ha = srb->ha;
  1901. qla4xxx_srb_free_dma(ha, srb);
  1902. mempool_free(srb, ha->srb_mempool);
  1903. cmd->scsi_done(cmd);
  1904. }
  1905. /**
  1906. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  1907. * @host: scsi host
  1908. * @cmd: Pointer to Linux's SCSI command structure
  1909. *
  1910. * Remarks:
  1911. * This routine is invoked by Linux to send a SCSI command to the driver.
  1912. * The mid-level driver tries to ensure that queuecommand never gets
  1913. * invoked concurrently with itself or the interrupt handler (although
  1914. * the interrupt handler may call this routine as part of request-
  1915. * completion handling). Unfortunely, it sometimes calls the scheduler
  1916. * in interrupt context which is a big NO! NO!.
  1917. **/
  1918. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  1919. {
  1920. struct scsi_qla_host *ha = to_qla_host(host);
  1921. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1922. struct iscsi_cls_session *sess = ddb_entry->sess;
  1923. struct srb *srb;
  1924. int rval;
  1925. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1926. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  1927. cmd->result = DID_NO_CONNECT << 16;
  1928. else
  1929. cmd->result = DID_REQUEUE << 16;
  1930. goto qc_fail_command;
  1931. }
  1932. if (!sess) {
  1933. cmd->result = DID_IMM_RETRY << 16;
  1934. goto qc_fail_command;
  1935. }
  1936. rval = iscsi_session_chkready(sess);
  1937. if (rval) {
  1938. cmd->result = rval;
  1939. goto qc_fail_command;
  1940. }
  1941. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1942. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1943. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1944. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1945. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1946. !test_bit(AF_ONLINE, &ha->flags) ||
  1947. !test_bit(AF_LINK_UP, &ha->flags) ||
  1948. test_bit(AF_LOOPBACK, &ha->flags) ||
  1949. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  1950. goto qc_host_busy;
  1951. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  1952. if (!srb)
  1953. goto qc_host_busy;
  1954. rval = qla4xxx_send_command_to_isp(ha, srb);
  1955. if (rval != QLA_SUCCESS)
  1956. goto qc_host_busy_free_sp;
  1957. return 0;
  1958. qc_host_busy_free_sp:
  1959. qla4xxx_srb_free_dma(ha, srb);
  1960. mempool_free(srb, ha->srb_mempool);
  1961. qc_host_busy:
  1962. return SCSI_MLQUEUE_HOST_BUSY;
  1963. qc_fail_command:
  1964. cmd->scsi_done(cmd);
  1965. return 0;
  1966. }
  1967. /**
  1968. * qla4xxx_mem_free - frees memory allocated to adapter
  1969. * @ha: Pointer to host adapter structure.
  1970. *
  1971. * Frees memory previously allocated by qla4xxx_mem_alloc
  1972. **/
  1973. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  1974. {
  1975. if (ha->queues)
  1976. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  1977. ha->queues_dma);
  1978. if (ha->fw_dump)
  1979. vfree(ha->fw_dump);
  1980. ha->queues_len = 0;
  1981. ha->queues = NULL;
  1982. ha->queues_dma = 0;
  1983. ha->request_ring = NULL;
  1984. ha->request_dma = 0;
  1985. ha->response_ring = NULL;
  1986. ha->response_dma = 0;
  1987. ha->shadow_regs = NULL;
  1988. ha->shadow_regs_dma = 0;
  1989. ha->fw_dump = NULL;
  1990. ha->fw_dump_size = 0;
  1991. /* Free srb pool. */
  1992. if (ha->srb_mempool)
  1993. mempool_destroy(ha->srb_mempool);
  1994. ha->srb_mempool = NULL;
  1995. if (ha->chap_dma_pool)
  1996. dma_pool_destroy(ha->chap_dma_pool);
  1997. if (ha->chap_list)
  1998. vfree(ha->chap_list);
  1999. ha->chap_list = NULL;
  2000. if (ha->fw_ddb_dma_pool)
  2001. dma_pool_destroy(ha->fw_ddb_dma_pool);
  2002. /* release io space registers */
  2003. if (is_qla8022(ha)) {
  2004. if (ha->nx_pcibase)
  2005. iounmap(
  2006. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  2007. } else if (is_qla8032(ha)) {
  2008. if (ha->nx_pcibase)
  2009. iounmap(
  2010. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  2011. } else if (ha->reg) {
  2012. iounmap(ha->reg);
  2013. }
  2014. if (ha->reset_tmplt.buff)
  2015. vfree(ha->reset_tmplt.buff);
  2016. pci_release_regions(ha->pdev);
  2017. }
  2018. /**
  2019. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  2020. * @ha: Pointer to host adapter structure
  2021. *
  2022. * Allocates DMA memory for request and response queues. Also allocates memory
  2023. * for srbs.
  2024. **/
  2025. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  2026. {
  2027. unsigned long align;
  2028. /* Allocate contiguous block of DMA memory for queues. */
  2029. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2030. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  2031. sizeof(struct shadow_regs) +
  2032. MEM_ALIGN_VALUE +
  2033. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  2034. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  2035. &ha->queues_dma, GFP_KERNEL);
  2036. if (ha->queues == NULL) {
  2037. ql4_printk(KERN_WARNING, ha,
  2038. "Memory Allocation failed - queues.\n");
  2039. goto mem_alloc_error_exit;
  2040. }
  2041. memset(ha->queues, 0, ha->queues_len);
  2042. /*
  2043. * As per RISC alignment requirements -- the bus-address must be a
  2044. * multiple of the request-ring size (in bytes).
  2045. */
  2046. align = 0;
  2047. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  2048. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  2049. (MEM_ALIGN_VALUE - 1));
  2050. /* Update request and response queue pointers. */
  2051. ha->request_dma = ha->queues_dma + align;
  2052. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  2053. ha->response_dma = ha->queues_dma + align +
  2054. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  2055. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  2056. (REQUEST_QUEUE_DEPTH *
  2057. QUEUE_SIZE));
  2058. ha->shadow_regs_dma = ha->queues_dma + align +
  2059. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2060. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  2061. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  2062. (REQUEST_QUEUE_DEPTH *
  2063. QUEUE_SIZE) +
  2064. (RESPONSE_QUEUE_DEPTH *
  2065. QUEUE_SIZE));
  2066. /* Allocate memory for srb pool. */
  2067. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  2068. mempool_free_slab, srb_cachep);
  2069. if (ha->srb_mempool == NULL) {
  2070. ql4_printk(KERN_WARNING, ha,
  2071. "Memory Allocation failed - SRB Pool.\n");
  2072. goto mem_alloc_error_exit;
  2073. }
  2074. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  2075. CHAP_DMA_BLOCK_SIZE, 8, 0);
  2076. if (ha->chap_dma_pool == NULL) {
  2077. ql4_printk(KERN_WARNING, ha,
  2078. "%s: chap_dma_pool allocation failed..\n", __func__);
  2079. goto mem_alloc_error_exit;
  2080. }
  2081. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  2082. DDB_DMA_BLOCK_SIZE, 8, 0);
  2083. if (ha->fw_ddb_dma_pool == NULL) {
  2084. ql4_printk(KERN_WARNING, ha,
  2085. "%s: fw_ddb_dma_pool allocation failed..\n",
  2086. __func__);
  2087. goto mem_alloc_error_exit;
  2088. }
  2089. return QLA_SUCCESS;
  2090. mem_alloc_error_exit:
  2091. qla4xxx_mem_free(ha);
  2092. return QLA_ERROR;
  2093. }
  2094. /**
  2095. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  2096. * @ha: adapter block pointer.
  2097. *
  2098. * Note: The caller should not hold the idc lock.
  2099. **/
  2100. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  2101. {
  2102. uint32_t temp, temp_state, temp_val;
  2103. int status = QLA_SUCCESS;
  2104. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  2105. temp_state = qla82xx_get_temp_state(temp);
  2106. temp_val = qla82xx_get_temp_val(temp);
  2107. if (temp_state == QLA82XX_TEMP_PANIC) {
  2108. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  2109. " exceeds maximum allowed. Hardware has been shut"
  2110. " down.\n", temp_val);
  2111. status = QLA_ERROR;
  2112. } else if (temp_state == QLA82XX_TEMP_WARN) {
  2113. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  2114. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  2115. " degrees C exceeds operating range."
  2116. " Immediate action needed.\n", temp_val);
  2117. } else {
  2118. if (ha->temperature == QLA82XX_TEMP_WARN)
  2119. ql4_printk(KERN_INFO, ha, "Device temperature is"
  2120. " now %d degrees C in normal range.\n",
  2121. temp_val);
  2122. }
  2123. ha->temperature = temp_state;
  2124. return status;
  2125. }
  2126. /**
  2127. * qla4_8xxx_check_fw_alive - Check firmware health
  2128. * @ha: Pointer to host adapter structure.
  2129. *
  2130. * Context: Interrupt
  2131. **/
  2132. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  2133. {
  2134. uint32_t fw_heartbeat_counter;
  2135. int status = QLA_SUCCESS;
  2136. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  2137. QLA8XXX_PEG_ALIVE_COUNTER);
  2138. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  2139. if (fw_heartbeat_counter == 0xffffffff) {
  2140. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  2141. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  2142. ha->host_no, __func__));
  2143. return status;
  2144. }
  2145. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  2146. ha->seconds_since_last_heartbeat++;
  2147. /* FW not alive after 2 seconds */
  2148. if (ha->seconds_since_last_heartbeat == 2) {
  2149. ha->seconds_since_last_heartbeat = 0;
  2150. qla4_8xxx_dump_peg_reg(ha);
  2151. status = QLA_ERROR;
  2152. }
  2153. } else
  2154. ha->seconds_since_last_heartbeat = 0;
  2155. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  2156. return status;
  2157. }
  2158. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  2159. {
  2160. uint32_t halt_status;
  2161. int halt_status_unrecoverable = 0;
  2162. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  2163. if (is_qla8022(ha)) {
  2164. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2165. __func__);
  2166. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2167. CRB_NIU_XG_PAUSE_CTL_P0 |
  2168. CRB_NIU_XG_PAUSE_CTL_P1);
  2169. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  2170. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  2171. __func__);
  2172. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  2173. halt_status_unrecoverable = 1;
  2174. } else if (is_qla8032(ha)) {
  2175. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  2176. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  2177. __func__);
  2178. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  2179. halt_status_unrecoverable = 1;
  2180. }
  2181. /*
  2182. * Since we cannot change dev_state in interrupt context,
  2183. * set appropriate DPC flag then wakeup DPC
  2184. */
  2185. if (halt_status_unrecoverable) {
  2186. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2187. } else {
  2188. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  2189. __func__);
  2190. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2191. }
  2192. qla4xxx_mailbox_premature_completion(ha);
  2193. qla4xxx_wake_dpc(ha);
  2194. }
  2195. /**
  2196. * qla4_8xxx_watchdog - Poll dev state
  2197. * @ha: Pointer to host adapter structure.
  2198. *
  2199. * Context: Interrupt
  2200. **/
  2201. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  2202. {
  2203. uint32_t dev_state;
  2204. /* don't poll if reset is going on */
  2205. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2206. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2207. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  2208. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  2209. if (qla4_8xxx_check_temp(ha)) {
  2210. if (is_qla8022(ha)) {
  2211. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  2212. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2213. CRB_NIU_XG_PAUSE_CTL_P0 |
  2214. CRB_NIU_XG_PAUSE_CTL_P1);
  2215. }
  2216. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2217. qla4xxx_wake_dpc(ha);
  2218. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  2219. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2220. if (is_qla8032(ha) ||
  2221. (is_qla8022(ha) && !ql4xdontresethba)) {
  2222. ql4_printk(KERN_INFO, ha, "%s: HW State: "
  2223. "NEED RESET!\n", __func__);
  2224. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2225. qla4xxx_wake_dpc(ha);
  2226. }
  2227. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  2228. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2229. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  2230. __func__);
  2231. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  2232. qla4xxx_wake_dpc(ha);
  2233. } else {
  2234. /* Check firmware health */
  2235. if (qla4_8xxx_check_fw_alive(ha))
  2236. qla4_8xxx_process_fw_error(ha);
  2237. }
  2238. }
  2239. }
  2240. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2241. {
  2242. struct iscsi_session *sess;
  2243. struct ddb_entry *ddb_entry;
  2244. struct scsi_qla_host *ha;
  2245. sess = cls_sess->dd_data;
  2246. ddb_entry = sess->dd_data;
  2247. ha = ddb_entry->ha;
  2248. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2249. return;
  2250. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2251. !iscsi_is_session_online(cls_sess)) {
  2252. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  2253. INVALID_ENTRY) {
  2254. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  2255. 0) {
  2256. atomic_set(&ddb_entry->retry_relogin_timer,
  2257. INVALID_ENTRY);
  2258. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2259. set_bit(DF_RELOGIN, &ddb_entry->flags);
  2260. DEBUG2(ql4_printk(KERN_INFO, ha,
  2261. "%s: index [%d] login device\n",
  2262. __func__, ddb_entry->fw_ddb_index));
  2263. } else
  2264. atomic_dec(&ddb_entry->retry_relogin_timer);
  2265. }
  2266. }
  2267. /* Wait for relogin to timeout */
  2268. if (atomic_read(&ddb_entry->relogin_timer) &&
  2269. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  2270. /*
  2271. * If the relogin times out and the device is
  2272. * still NOT ONLINE then try and relogin again.
  2273. */
  2274. if (!iscsi_is_session_online(cls_sess)) {
  2275. /* Reset retry relogin timer */
  2276. atomic_inc(&ddb_entry->relogin_retry_count);
  2277. DEBUG2(ql4_printk(KERN_INFO, ha,
  2278. "%s: index[%d] relogin timed out-retrying"
  2279. " relogin (%d), retry (%d)\n", __func__,
  2280. ddb_entry->fw_ddb_index,
  2281. atomic_read(&ddb_entry->relogin_retry_count),
  2282. ddb_entry->default_time2wait + 4));
  2283. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2284. atomic_set(&ddb_entry->retry_relogin_timer,
  2285. ddb_entry->default_time2wait + 4);
  2286. }
  2287. }
  2288. }
  2289. /**
  2290. * qla4xxx_timer - checks every second for work to do.
  2291. * @ha: Pointer to host adapter structure.
  2292. **/
  2293. static void qla4xxx_timer(struct scsi_qla_host *ha)
  2294. {
  2295. int start_dpc = 0;
  2296. uint16_t w;
  2297. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  2298. /* If we are in the middle of AER/EEH processing
  2299. * skip any processing and reschedule the timer
  2300. */
  2301. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2302. mod_timer(&ha->timer, jiffies + HZ);
  2303. return;
  2304. }
  2305. /* Hardware read to trigger an EEH error during mailbox waits. */
  2306. if (!pci_channel_offline(ha->pdev))
  2307. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2308. if (is_qla80XX(ha))
  2309. qla4_8xxx_watchdog(ha);
  2310. if (is_qla40XX(ha)) {
  2311. /* Check for heartbeat interval. */
  2312. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  2313. ha->heartbeat_interval != 0) {
  2314. ha->seconds_since_last_heartbeat++;
  2315. if (ha->seconds_since_last_heartbeat >
  2316. ha->heartbeat_interval + 2)
  2317. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2318. }
  2319. }
  2320. /* Process any deferred work. */
  2321. if (!list_empty(&ha->work_list))
  2322. start_dpc++;
  2323. /* Wakeup the dpc routine for this adapter, if needed. */
  2324. if (start_dpc ||
  2325. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2326. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  2327. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  2328. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2329. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2330. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  2331. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  2332. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2333. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2334. test_bit(DPC_AEN, &ha->dpc_flags)) {
  2335. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  2336. " - dpc flags = 0x%lx\n",
  2337. ha->host_no, __func__, ha->dpc_flags));
  2338. qla4xxx_wake_dpc(ha);
  2339. }
  2340. /* Reschedule timer thread to call us back in one second */
  2341. mod_timer(&ha->timer, jiffies + HZ);
  2342. DEBUG2(ha->seconds_since_last_intr++);
  2343. }
  2344. /**
  2345. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  2346. * @ha: Pointer to host adapter structure.
  2347. *
  2348. * This routine stalls the driver until all outstanding commands are returned.
  2349. * Caller must release the Hardware Lock prior to calling this routine.
  2350. **/
  2351. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  2352. {
  2353. uint32_t index = 0;
  2354. unsigned long flags;
  2355. struct scsi_cmnd *cmd;
  2356. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  2357. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  2358. "complete\n", WAIT_CMD_TOV));
  2359. while (!time_after_eq(jiffies, wtime)) {
  2360. spin_lock_irqsave(&ha->hardware_lock, flags);
  2361. /* Find a command that hasn't completed. */
  2362. for (index = 0; index < ha->host->can_queue; index++) {
  2363. cmd = scsi_host_find_tag(ha->host, index);
  2364. /*
  2365. * We cannot just check if the index is valid,
  2366. * becase if we are run from the scsi eh, then
  2367. * the scsi/block layer is going to prevent
  2368. * the tag from being released.
  2369. */
  2370. if (cmd != NULL && CMD_SP(cmd))
  2371. break;
  2372. }
  2373. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2374. /* If No Commands are pending, wait is complete */
  2375. if (index == ha->host->can_queue)
  2376. return QLA_SUCCESS;
  2377. msleep(1000);
  2378. }
  2379. /* If we timed out on waiting for commands to come back
  2380. * return ERROR. */
  2381. return QLA_ERROR;
  2382. }
  2383. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  2384. {
  2385. uint32_t ctrl_status;
  2386. unsigned long flags = 0;
  2387. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  2388. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  2389. return QLA_ERROR;
  2390. spin_lock_irqsave(&ha->hardware_lock, flags);
  2391. /*
  2392. * If the SCSI Reset Interrupt bit is set, clear it.
  2393. * Otherwise, the Soft Reset won't work.
  2394. */
  2395. ctrl_status = readw(&ha->reg->ctrl_status);
  2396. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  2397. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2398. /* Issue Soft Reset */
  2399. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  2400. readl(&ha->reg->ctrl_status);
  2401. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2402. return QLA_SUCCESS;
  2403. }
  2404. /**
  2405. * qla4xxx_soft_reset - performs soft reset.
  2406. * @ha: Pointer to host adapter structure.
  2407. **/
  2408. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  2409. {
  2410. uint32_t max_wait_time;
  2411. unsigned long flags = 0;
  2412. int status;
  2413. uint32_t ctrl_status;
  2414. status = qla4xxx_hw_reset(ha);
  2415. if (status != QLA_SUCCESS)
  2416. return status;
  2417. status = QLA_ERROR;
  2418. /* Wait until the Network Reset Intr bit is cleared */
  2419. max_wait_time = RESET_INTR_TOV;
  2420. do {
  2421. spin_lock_irqsave(&ha->hardware_lock, flags);
  2422. ctrl_status = readw(&ha->reg->ctrl_status);
  2423. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2424. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  2425. break;
  2426. msleep(1000);
  2427. } while ((--max_wait_time));
  2428. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  2429. DEBUG2(printk(KERN_WARNING
  2430. "scsi%ld: Network Reset Intr not cleared by "
  2431. "Network function, clearing it now!\n",
  2432. ha->host_no));
  2433. spin_lock_irqsave(&ha->hardware_lock, flags);
  2434. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  2435. readl(&ha->reg->ctrl_status);
  2436. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2437. }
  2438. /* Wait until the firmware tells us the Soft Reset is done */
  2439. max_wait_time = SOFT_RESET_TOV;
  2440. do {
  2441. spin_lock_irqsave(&ha->hardware_lock, flags);
  2442. ctrl_status = readw(&ha->reg->ctrl_status);
  2443. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2444. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  2445. status = QLA_SUCCESS;
  2446. break;
  2447. }
  2448. msleep(1000);
  2449. } while ((--max_wait_time));
  2450. /*
  2451. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  2452. * after the soft reset has taken place.
  2453. */
  2454. spin_lock_irqsave(&ha->hardware_lock, flags);
  2455. ctrl_status = readw(&ha->reg->ctrl_status);
  2456. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  2457. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2458. readl(&ha->reg->ctrl_status);
  2459. }
  2460. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2461. /* If soft reset fails then most probably the bios on other
  2462. * function is also enabled.
  2463. * Since the initialization is sequential the other fn
  2464. * wont be able to acknowledge the soft reset.
  2465. * Issue a force soft reset to workaround this scenario.
  2466. */
  2467. if (max_wait_time == 0) {
  2468. /* Issue Force Soft Reset */
  2469. spin_lock_irqsave(&ha->hardware_lock, flags);
  2470. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  2471. readl(&ha->reg->ctrl_status);
  2472. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2473. /* Wait until the firmware tells us the Soft Reset is done */
  2474. max_wait_time = SOFT_RESET_TOV;
  2475. do {
  2476. spin_lock_irqsave(&ha->hardware_lock, flags);
  2477. ctrl_status = readw(&ha->reg->ctrl_status);
  2478. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2479. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  2480. status = QLA_SUCCESS;
  2481. break;
  2482. }
  2483. msleep(1000);
  2484. } while ((--max_wait_time));
  2485. }
  2486. return status;
  2487. }
  2488. /**
  2489. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  2490. * @ha: Pointer to host adapter structure.
  2491. * @res: returned scsi status
  2492. *
  2493. * This routine is called just prior to a HARD RESET to return all
  2494. * outstanding commands back to the Operating System.
  2495. * Caller should make sure that the following locks are released
  2496. * before this calling routine: Hardware lock, and io_request_lock.
  2497. **/
  2498. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  2499. {
  2500. struct srb *srb;
  2501. int i;
  2502. unsigned long flags;
  2503. spin_lock_irqsave(&ha->hardware_lock, flags);
  2504. for (i = 0; i < ha->host->can_queue; i++) {
  2505. srb = qla4xxx_del_from_active_array(ha, i);
  2506. if (srb != NULL) {
  2507. srb->cmd->result = res;
  2508. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2509. }
  2510. }
  2511. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2512. }
  2513. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  2514. {
  2515. clear_bit(AF_ONLINE, &ha->flags);
  2516. /* Disable the board */
  2517. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  2518. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2519. qla4xxx_mark_all_devices_missing(ha);
  2520. clear_bit(AF_INIT_DONE, &ha->flags);
  2521. }
  2522. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  2523. {
  2524. struct iscsi_session *sess;
  2525. struct ddb_entry *ddb_entry;
  2526. sess = cls_session->dd_data;
  2527. ddb_entry = sess->dd_data;
  2528. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  2529. if (ddb_entry->ddb_type == FLASH_DDB)
  2530. iscsi_block_session(ddb_entry->sess);
  2531. else
  2532. iscsi_session_failure(cls_session->dd_data,
  2533. ISCSI_ERR_CONN_FAILED);
  2534. }
  2535. /**
  2536. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  2537. * @ha: Pointer to host adapter structure.
  2538. **/
  2539. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  2540. {
  2541. int status = QLA_ERROR;
  2542. uint8_t reset_chip = 0;
  2543. uint32_t dev_state;
  2544. unsigned long wait;
  2545. /* Stall incoming I/O until we are done */
  2546. scsi_block_requests(ha->host);
  2547. clear_bit(AF_ONLINE, &ha->flags);
  2548. clear_bit(AF_LINK_UP, &ha->flags);
  2549. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  2550. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2551. if (is_qla8032(ha) &&
  2552. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2553. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2554. __func__);
  2555. /* disable pause frame for ISP83xx */
  2556. qla4_83xx_disable_pause(ha);
  2557. }
  2558. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  2559. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2560. reset_chip = 1;
  2561. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  2562. * do not reset adapter, jump to initialize_adapter */
  2563. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2564. status = QLA_SUCCESS;
  2565. goto recover_ha_init_adapter;
  2566. }
  2567. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  2568. * from eh_host_reset or ioctl module */
  2569. if (is_qla80XX(ha) && !reset_chip &&
  2570. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2571. DEBUG2(ql4_printk(KERN_INFO, ha,
  2572. "scsi%ld: %s - Performing stop_firmware...\n",
  2573. ha->host_no, __func__));
  2574. status = ha->isp_ops->reset_firmware(ha);
  2575. if (status == QLA_SUCCESS) {
  2576. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2577. qla4xxx_cmd_wait(ha);
  2578. ha->isp_ops->disable_intrs(ha);
  2579. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2580. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2581. } else {
  2582. /* If the stop_firmware fails then
  2583. * reset the entire chip */
  2584. reset_chip = 1;
  2585. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2586. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2587. }
  2588. }
  2589. /* Issue full chip reset if recovering from a catastrophic error,
  2590. * or if stop_firmware fails for ISP-8xxx.
  2591. * This is the default case for ISP-4xxx */
  2592. if (is_qla40XX(ha) || reset_chip) {
  2593. if (is_qla40XX(ha))
  2594. goto chip_reset;
  2595. /* Check if 8XXX firmware is alive or not
  2596. * We may have arrived here from NEED_RESET
  2597. * detection only */
  2598. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  2599. goto chip_reset;
  2600. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  2601. while (time_before(jiffies, wait)) {
  2602. if (qla4_8xxx_check_fw_alive(ha)) {
  2603. qla4xxx_mailbox_premature_completion(ha);
  2604. break;
  2605. }
  2606. set_current_state(TASK_UNINTERRUPTIBLE);
  2607. schedule_timeout(HZ);
  2608. }
  2609. chip_reset:
  2610. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2611. qla4xxx_cmd_wait(ha);
  2612. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2613. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2614. DEBUG2(ql4_printk(KERN_INFO, ha,
  2615. "scsi%ld: %s - Performing chip reset..\n",
  2616. ha->host_no, __func__));
  2617. status = ha->isp_ops->reset_chip(ha);
  2618. }
  2619. /* Flush any pending ddb changed AENs */
  2620. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2621. recover_ha_init_adapter:
  2622. /* Upon successful firmware/chip reset, re-initialize the adapter */
  2623. if (status == QLA_SUCCESS) {
  2624. /* For ISP-4xxx, force function 1 to always initialize
  2625. * before function 3 to prevent both funcions from
  2626. * stepping on top of the other */
  2627. if (is_qla40XX(ha) && (ha->mac_index == 3))
  2628. ssleep(6);
  2629. /* NOTE: AF_ONLINE flag set upon successful completion of
  2630. * qla4xxx_initialize_adapter */
  2631. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  2632. }
  2633. /* Retry failed adapter initialization, if necessary
  2634. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  2635. * case to prevent ping-pong resets between functions */
  2636. if (!test_bit(AF_ONLINE, &ha->flags) &&
  2637. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2638. /* Adapter initialization failed, see if we can retry
  2639. * resetting the ha.
  2640. * Since we don't want to block the DPC for too long
  2641. * with multiple resets in the same thread,
  2642. * utilize DPC to retry */
  2643. if (is_qla80XX(ha)) {
  2644. ha->isp_ops->idc_lock(ha);
  2645. dev_state = qla4_8xxx_rd_direct(ha,
  2646. QLA8XXX_CRB_DEV_STATE);
  2647. ha->isp_ops->idc_unlock(ha);
  2648. if (dev_state == QLA8XXX_DEV_FAILED) {
  2649. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  2650. "recover adapter. H/W is in Failed "
  2651. "state\n", __func__);
  2652. qla4xxx_dead_adapter_cleanup(ha);
  2653. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2654. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2655. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  2656. &ha->dpc_flags);
  2657. status = QLA_ERROR;
  2658. goto exit_recover;
  2659. }
  2660. }
  2661. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  2662. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  2663. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  2664. "(%d) more times\n", ha->host_no,
  2665. ha->retry_reset_ha_cnt));
  2666. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2667. status = QLA_ERROR;
  2668. } else {
  2669. if (ha->retry_reset_ha_cnt > 0) {
  2670. /* Schedule another Reset HA--DPC will retry */
  2671. ha->retry_reset_ha_cnt--;
  2672. DEBUG2(printk("scsi%ld: recover adapter - "
  2673. "retry remaining %d\n",
  2674. ha->host_no,
  2675. ha->retry_reset_ha_cnt));
  2676. status = QLA_ERROR;
  2677. }
  2678. if (ha->retry_reset_ha_cnt == 0) {
  2679. /* Recover adapter retries have been exhausted.
  2680. * Adapter DEAD */
  2681. DEBUG2(printk("scsi%ld: recover adapter "
  2682. "failed - board disabled\n",
  2683. ha->host_no));
  2684. qla4xxx_dead_adapter_cleanup(ha);
  2685. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2686. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2687. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  2688. &ha->dpc_flags);
  2689. status = QLA_ERROR;
  2690. }
  2691. }
  2692. } else {
  2693. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2694. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2695. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2696. }
  2697. exit_recover:
  2698. ha->adapter_error_count++;
  2699. if (test_bit(AF_ONLINE, &ha->flags))
  2700. ha->isp_ops->enable_intrs(ha);
  2701. scsi_unblock_requests(ha->host);
  2702. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2703. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  2704. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  2705. return status;
  2706. }
  2707. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  2708. {
  2709. struct iscsi_session *sess;
  2710. struct ddb_entry *ddb_entry;
  2711. struct scsi_qla_host *ha;
  2712. sess = cls_session->dd_data;
  2713. ddb_entry = sess->dd_data;
  2714. ha = ddb_entry->ha;
  2715. if (!iscsi_is_session_online(cls_session)) {
  2716. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  2717. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2718. " unblock session\n", ha->host_no, __func__,
  2719. ddb_entry->fw_ddb_index);
  2720. iscsi_unblock_session(ddb_entry->sess);
  2721. } else {
  2722. /* Trigger relogin */
  2723. if (ddb_entry->ddb_type == FLASH_DDB) {
  2724. if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
  2725. qla4xxx_arm_relogin_timer(ddb_entry);
  2726. } else
  2727. iscsi_session_failure(cls_session->dd_data,
  2728. ISCSI_ERR_CONN_FAILED);
  2729. }
  2730. }
  2731. }
  2732. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  2733. {
  2734. struct iscsi_session *sess;
  2735. struct ddb_entry *ddb_entry;
  2736. struct scsi_qla_host *ha;
  2737. sess = cls_session->dd_data;
  2738. ddb_entry = sess->dd_data;
  2739. ha = ddb_entry->ha;
  2740. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2741. " unblock session\n", ha->host_no, __func__,
  2742. ddb_entry->fw_ddb_index);
  2743. iscsi_unblock_session(ddb_entry->sess);
  2744. /* Start scan target */
  2745. if (test_bit(AF_ONLINE, &ha->flags)) {
  2746. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2747. " start scan\n", ha->host_no, __func__,
  2748. ddb_entry->fw_ddb_index);
  2749. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  2750. }
  2751. return QLA_SUCCESS;
  2752. }
  2753. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  2754. {
  2755. struct iscsi_session *sess;
  2756. struct ddb_entry *ddb_entry;
  2757. struct scsi_qla_host *ha;
  2758. int status = QLA_SUCCESS;
  2759. sess = cls_session->dd_data;
  2760. ddb_entry = sess->dd_data;
  2761. ha = ddb_entry->ha;
  2762. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2763. " unblock user space session\n", ha->host_no, __func__,
  2764. ddb_entry->fw_ddb_index);
  2765. if (!iscsi_is_session_online(cls_session)) {
  2766. iscsi_conn_start(ddb_entry->conn);
  2767. iscsi_conn_login_event(ddb_entry->conn,
  2768. ISCSI_CONN_STATE_LOGGED_IN);
  2769. } else {
  2770. ql4_printk(KERN_INFO, ha,
  2771. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  2772. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  2773. cls_session->sid);
  2774. status = QLA_ERROR;
  2775. }
  2776. return status;
  2777. }
  2778. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  2779. {
  2780. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  2781. }
  2782. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2783. {
  2784. uint16_t relogin_timer;
  2785. struct iscsi_session *sess;
  2786. struct ddb_entry *ddb_entry;
  2787. struct scsi_qla_host *ha;
  2788. sess = cls_sess->dd_data;
  2789. ddb_entry = sess->dd_data;
  2790. ha = ddb_entry->ha;
  2791. relogin_timer = max(ddb_entry->default_relogin_timeout,
  2792. (uint16_t)RELOGIN_TOV);
  2793. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  2794. DEBUG2(ql4_printk(KERN_INFO, ha,
  2795. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  2796. ddb_entry->fw_ddb_index, relogin_timer));
  2797. qla4xxx_login_flash_ddb(cls_sess);
  2798. }
  2799. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  2800. {
  2801. struct iscsi_session *sess;
  2802. struct ddb_entry *ddb_entry;
  2803. struct scsi_qla_host *ha;
  2804. sess = cls_sess->dd_data;
  2805. ddb_entry = sess->dd_data;
  2806. ha = ddb_entry->ha;
  2807. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2808. return;
  2809. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2810. !iscsi_is_session_online(cls_sess)) {
  2811. DEBUG2(ql4_printk(KERN_INFO, ha,
  2812. "relogin issued\n"));
  2813. qla4xxx_relogin_flash_ddb(cls_sess);
  2814. }
  2815. }
  2816. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  2817. {
  2818. if (ha->dpc_thread)
  2819. queue_work(ha->dpc_thread, &ha->dpc_work);
  2820. }
  2821. static struct qla4_work_evt *
  2822. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  2823. enum qla4_work_type type)
  2824. {
  2825. struct qla4_work_evt *e;
  2826. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  2827. e = kzalloc(size, GFP_ATOMIC);
  2828. if (!e)
  2829. return NULL;
  2830. INIT_LIST_HEAD(&e->list);
  2831. e->type = type;
  2832. return e;
  2833. }
  2834. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  2835. struct qla4_work_evt *e)
  2836. {
  2837. unsigned long flags;
  2838. spin_lock_irqsave(&ha->work_lock, flags);
  2839. list_add_tail(&e->list, &ha->work_list);
  2840. spin_unlock_irqrestore(&ha->work_lock, flags);
  2841. qla4xxx_wake_dpc(ha);
  2842. }
  2843. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  2844. enum iscsi_host_event_code aen_code,
  2845. uint32_t data_size, uint8_t *data)
  2846. {
  2847. struct qla4_work_evt *e;
  2848. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  2849. if (!e)
  2850. return QLA_ERROR;
  2851. e->u.aen.code = aen_code;
  2852. e->u.aen.data_size = data_size;
  2853. memcpy(e->u.aen.data, data, data_size);
  2854. qla4xxx_post_work(ha, e);
  2855. return QLA_SUCCESS;
  2856. }
  2857. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  2858. uint32_t status, uint32_t pid,
  2859. uint32_t data_size, uint8_t *data)
  2860. {
  2861. struct qla4_work_evt *e;
  2862. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  2863. if (!e)
  2864. return QLA_ERROR;
  2865. e->u.ping.status = status;
  2866. e->u.ping.pid = pid;
  2867. e->u.ping.data_size = data_size;
  2868. memcpy(e->u.ping.data, data, data_size);
  2869. qla4xxx_post_work(ha, e);
  2870. return QLA_SUCCESS;
  2871. }
  2872. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  2873. {
  2874. struct qla4_work_evt *e, *tmp;
  2875. unsigned long flags;
  2876. LIST_HEAD(work);
  2877. spin_lock_irqsave(&ha->work_lock, flags);
  2878. list_splice_init(&ha->work_list, &work);
  2879. spin_unlock_irqrestore(&ha->work_lock, flags);
  2880. list_for_each_entry_safe(e, tmp, &work, list) {
  2881. list_del_init(&e->list);
  2882. switch (e->type) {
  2883. case QLA4_EVENT_AEN:
  2884. iscsi_post_host_event(ha->host_no,
  2885. &qla4xxx_iscsi_transport,
  2886. e->u.aen.code,
  2887. e->u.aen.data_size,
  2888. e->u.aen.data);
  2889. break;
  2890. case QLA4_EVENT_PING_STATUS:
  2891. iscsi_ping_comp_event(ha->host_no,
  2892. &qla4xxx_iscsi_transport,
  2893. e->u.ping.status,
  2894. e->u.ping.pid,
  2895. e->u.ping.data_size,
  2896. e->u.ping.data);
  2897. break;
  2898. default:
  2899. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  2900. "supported", e->type);
  2901. }
  2902. kfree(e);
  2903. }
  2904. }
  2905. /**
  2906. * qla4xxx_do_dpc - dpc routine
  2907. * @data: in our case pointer to adapter structure
  2908. *
  2909. * This routine is a task that is schedule by the interrupt handler
  2910. * to perform the background processing for interrupts. We put it
  2911. * on a task queue that is consumed whenever the scheduler runs; that's
  2912. * so you can do anything (i.e. put the process to sleep etc). In fact,
  2913. * the mid-level tries to sleep when it reaches the driver threshold
  2914. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  2915. **/
  2916. static void qla4xxx_do_dpc(struct work_struct *work)
  2917. {
  2918. struct scsi_qla_host *ha =
  2919. container_of(work, struct scsi_qla_host, dpc_work);
  2920. int status = QLA_ERROR;
  2921. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  2922. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  2923. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  2924. /* Initialization not yet finished. Don't do anything yet. */
  2925. if (!test_bit(AF_INIT_DONE, &ha->flags))
  2926. return;
  2927. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2928. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  2929. ha->host_no, __func__, ha->flags));
  2930. return;
  2931. }
  2932. /* post events to application */
  2933. qla4xxx_do_work(ha);
  2934. if (is_qla80XX(ha)) {
  2935. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  2936. if (is_qla8032(ha)) {
  2937. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2938. __func__);
  2939. /* disable pause frame for ISP83xx */
  2940. qla4_83xx_disable_pause(ha);
  2941. }
  2942. ha->isp_ops->idc_lock(ha);
  2943. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  2944. QLA8XXX_DEV_FAILED);
  2945. ha->isp_ops->idc_unlock(ha);
  2946. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  2947. qla4_8xxx_device_state_handler(ha);
  2948. }
  2949. if (test_and_clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags))
  2950. qla4_83xx_post_idc_ack(ha);
  2951. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2952. qla4_8xxx_need_qsnt_handler(ha);
  2953. }
  2954. }
  2955. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  2956. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2957. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2958. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  2959. if ((is_qla8022(ha) && ql4xdontresethba) ||
  2960. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  2961. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  2962. ha->host_no, __func__));
  2963. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2964. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2965. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2966. goto dpc_post_reset_ha;
  2967. }
  2968. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2969. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2970. qla4xxx_recover_adapter(ha);
  2971. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2972. uint8_t wait_time = RESET_INTR_TOV;
  2973. while ((readw(&ha->reg->ctrl_status) &
  2974. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  2975. if (--wait_time == 0)
  2976. break;
  2977. msleep(1000);
  2978. }
  2979. if (wait_time == 0)
  2980. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  2981. "bit not cleared-- resetting\n",
  2982. ha->host_no, __func__));
  2983. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2984. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  2985. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2986. status = qla4xxx_recover_adapter(ha);
  2987. }
  2988. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2989. if (status == QLA_SUCCESS)
  2990. ha->isp_ops->enable_intrs(ha);
  2991. }
  2992. }
  2993. dpc_post_reset_ha:
  2994. /* ---- process AEN? --- */
  2995. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  2996. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  2997. /* ---- Get DHCP IP Address? --- */
  2998. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  2999. qla4xxx_get_dhcp_ip_address(ha);
  3000. /* ---- relogin device? --- */
  3001. if (adapter_up(ha) &&
  3002. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  3003. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  3004. }
  3005. /* ---- link change? --- */
  3006. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  3007. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  3008. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  3009. /* ---- link down? --- */
  3010. qla4xxx_mark_all_devices_missing(ha);
  3011. } else {
  3012. /* ---- link up? --- *
  3013. * F/W will auto login to all devices ONLY ONCE after
  3014. * link up during driver initialization and runtime
  3015. * fatal error recovery. Therefore, the driver must
  3016. * manually relogin to devices when recovering from
  3017. * connection failures, logouts, expired KATO, etc. */
  3018. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  3019. qla4xxx_build_ddb_list(ha, ha->is_reset);
  3020. iscsi_host_for_each_session(ha->host,
  3021. qla4xxx_login_flash_ddb);
  3022. } else
  3023. qla4xxx_relogin_all_devices(ha);
  3024. }
  3025. }
  3026. }
  3027. /**
  3028. * qla4xxx_free_adapter - release the adapter
  3029. * @ha: pointer to adapter structure
  3030. **/
  3031. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  3032. {
  3033. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3034. /* Turn-off interrupts on the card. */
  3035. ha->isp_ops->disable_intrs(ha);
  3036. if (is_qla40XX(ha)) {
  3037. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  3038. &ha->reg->ctrl_status);
  3039. readl(&ha->reg->ctrl_status);
  3040. } else if (is_qla8022(ha)) {
  3041. writel(0, &ha->qla4_82xx_reg->host_int);
  3042. readl(&ha->qla4_82xx_reg->host_int);
  3043. } else if (is_qla8032(ha)) {
  3044. writel(0, &ha->qla4_83xx_reg->risc_intr);
  3045. readl(&ha->qla4_83xx_reg->risc_intr);
  3046. }
  3047. /* Remove timer thread, if present */
  3048. if (ha->timer_active)
  3049. qla4xxx_stop_timer(ha);
  3050. /* Kill the kernel thread for this host */
  3051. if (ha->dpc_thread)
  3052. destroy_workqueue(ha->dpc_thread);
  3053. /* Kill the kernel thread for this host */
  3054. if (ha->task_wq)
  3055. destroy_workqueue(ha->task_wq);
  3056. /* Put firmware in known state */
  3057. ha->isp_ops->reset_firmware(ha);
  3058. if (is_qla80XX(ha)) {
  3059. ha->isp_ops->idc_lock(ha);
  3060. qla4_8xxx_clear_drv_active(ha);
  3061. ha->isp_ops->idc_unlock(ha);
  3062. }
  3063. /* Detach interrupts */
  3064. qla4xxx_free_irqs(ha);
  3065. /* free extra memory */
  3066. qla4xxx_mem_free(ha);
  3067. }
  3068. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  3069. {
  3070. int status = 0;
  3071. unsigned long mem_base, mem_len, db_base, db_len;
  3072. struct pci_dev *pdev = ha->pdev;
  3073. status = pci_request_regions(pdev, DRIVER_NAME);
  3074. if (status) {
  3075. printk(KERN_WARNING
  3076. "scsi(%ld) Failed to reserve PIO regions (%s) "
  3077. "status=%d\n", ha->host_no, pci_name(pdev), status);
  3078. goto iospace_error_exit;
  3079. }
  3080. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  3081. __func__, pdev->revision));
  3082. ha->revision_id = pdev->revision;
  3083. /* remap phys address */
  3084. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  3085. mem_len = pci_resource_len(pdev, 0);
  3086. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  3087. __func__, mem_base, mem_len));
  3088. /* mapping of pcibase pointer */
  3089. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  3090. if (!ha->nx_pcibase) {
  3091. printk(KERN_ERR
  3092. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  3093. pci_release_regions(ha->pdev);
  3094. goto iospace_error_exit;
  3095. }
  3096. /* Mapping of IO base pointer, door bell read and write pointer */
  3097. /* mapping of IO base pointer */
  3098. if (is_qla8022(ha)) {
  3099. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  3100. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  3101. (ha->pdev->devfn << 11));
  3102. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  3103. QLA82XX_CAM_RAM_DB2);
  3104. } else if (is_qla8032(ha)) {
  3105. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  3106. ((uint8_t *)ha->nx_pcibase);
  3107. }
  3108. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  3109. db_len = pci_resource_len(pdev, 4);
  3110. return 0;
  3111. iospace_error_exit:
  3112. return -ENOMEM;
  3113. }
  3114. /***
  3115. * qla4xxx_iospace_config - maps registers
  3116. * @ha: pointer to adapter structure
  3117. *
  3118. * This routines maps HBA's registers from the pci address space
  3119. * into the kernel virtual address space for memory mapped i/o.
  3120. **/
  3121. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  3122. {
  3123. unsigned long pio, pio_len, pio_flags;
  3124. unsigned long mmio, mmio_len, mmio_flags;
  3125. pio = pci_resource_start(ha->pdev, 0);
  3126. pio_len = pci_resource_len(ha->pdev, 0);
  3127. pio_flags = pci_resource_flags(ha->pdev, 0);
  3128. if (pio_flags & IORESOURCE_IO) {
  3129. if (pio_len < MIN_IOBASE_LEN) {
  3130. ql4_printk(KERN_WARNING, ha,
  3131. "Invalid PCI I/O region size\n");
  3132. pio = 0;
  3133. }
  3134. } else {
  3135. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  3136. pio = 0;
  3137. }
  3138. /* Use MMIO operations for all accesses. */
  3139. mmio = pci_resource_start(ha->pdev, 1);
  3140. mmio_len = pci_resource_len(ha->pdev, 1);
  3141. mmio_flags = pci_resource_flags(ha->pdev, 1);
  3142. if (!(mmio_flags & IORESOURCE_MEM)) {
  3143. ql4_printk(KERN_ERR, ha,
  3144. "region #0 not an MMIO resource, aborting\n");
  3145. goto iospace_error_exit;
  3146. }
  3147. if (mmio_len < MIN_IOBASE_LEN) {
  3148. ql4_printk(KERN_ERR, ha,
  3149. "Invalid PCI mem region size, aborting\n");
  3150. goto iospace_error_exit;
  3151. }
  3152. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  3153. ql4_printk(KERN_WARNING, ha,
  3154. "Failed to reserve PIO/MMIO regions\n");
  3155. goto iospace_error_exit;
  3156. }
  3157. ha->pio_address = pio;
  3158. ha->pio_length = pio_len;
  3159. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  3160. if (!ha->reg) {
  3161. ql4_printk(KERN_ERR, ha,
  3162. "cannot remap MMIO, aborting\n");
  3163. goto iospace_error_exit;
  3164. }
  3165. return 0;
  3166. iospace_error_exit:
  3167. return -ENOMEM;
  3168. }
  3169. static struct isp_operations qla4xxx_isp_ops = {
  3170. .iospace_config = qla4xxx_iospace_config,
  3171. .pci_config = qla4xxx_pci_config,
  3172. .disable_intrs = qla4xxx_disable_intrs,
  3173. .enable_intrs = qla4xxx_enable_intrs,
  3174. .start_firmware = qla4xxx_start_firmware,
  3175. .intr_handler = qla4xxx_intr_handler,
  3176. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  3177. .reset_chip = qla4xxx_soft_reset,
  3178. .reset_firmware = qla4xxx_hw_reset,
  3179. .queue_iocb = qla4xxx_queue_iocb,
  3180. .complete_iocb = qla4xxx_complete_iocb,
  3181. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3182. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3183. .get_sys_info = qla4xxx_get_sys_info,
  3184. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  3185. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  3186. };
  3187. static struct isp_operations qla4_82xx_isp_ops = {
  3188. .iospace_config = qla4_8xxx_iospace_config,
  3189. .pci_config = qla4_8xxx_pci_config,
  3190. .disable_intrs = qla4_82xx_disable_intrs,
  3191. .enable_intrs = qla4_82xx_enable_intrs,
  3192. .start_firmware = qla4_8xxx_load_risc,
  3193. .restart_firmware = qla4_82xx_try_start_fw,
  3194. .intr_handler = qla4_82xx_intr_handler,
  3195. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  3196. .need_reset = qla4_8xxx_need_reset,
  3197. .reset_chip = qla4_82xx_isp_reset,
  3198. .reset_firmware = qla4_8xxx_stop_firmware,
  3199. .queue_iocb = qla4_82xx_queue_iocb,
  3200. .complete_iocb = qla4_82xx_complete_iocb,
  3201. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  3202. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  3203. .get_sys_info = qla4_8xxx_get_sys_info,
  3204. .rd_reg_direct = qla4_82xx_rd_32,
  3205. .wr_reg_direct = qla4_82xx_wr_32,
  3206. .rd_reg_indirect = qla4_82xx_md_rd_32,
  3207. .wr_reg_indirect = qla4_82xx_md_wr_32,
  3208. .idc_lock = qla4_82xx_idc_lock,
  3209. .idc_unlock = qla4_82xx_idc_unlock,
  3210. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  3211. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  3212. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  3213. };
  3214. static struct isp_operations qla4_83xx_isp_ops = {
  3215. .iospace_config = qla4_8xxx_iospace_config,
  3216. .pci_config = qla4_8xxx_pci_config,
  3217. .disable_intrs = qla4_83xx_disable_intrs,
  3218. .enable_intrs = qla4_83xx_enable_intrs,
  3219. .start_firmware = qla4_8xxx_load_risc,
  3220. .restart_firmware = qla4_83xx_start_firmware,
  3221. .intr_handler = qla4_83xx_intr_handler,
  3222. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  3223. .need_reset = qla4_8xxx_need_reset,
  3224. .reset_chip = qla4_83xx_isp_reset,
  3225. .reset_firmware = qla4_8xxx_stop_firmware,
  3226. .queue_iocb = qla4_83xx_queue_iocb,
  3227. .complete_iocb = qla4_83xx_complete_iocb,
  3228. .rd_shdw_req_q_out = qla4_83xx_rd_shdw_req_q_out,
  3229. .rd_shdw_rsp_q_in = qla4_83xx_rd_shdw_rsp_q_in,
  3230. .get_sys_info = qla4_8xxx_get_sys_info,
  3231. .rd_reg_direct = qla4_83xx_rd_reg,
  3232. .wr_reg_direct = qla4_83xx_wr_reg,
  3233. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  3234. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  3235. .idc_lock = qla4_83xx_drv_lock,
  3236. .idc_unlock = qla4_83xx_drv_unlock,
  3237. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  3238. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  3239. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  3240. };
  3241. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3242. {
  3243. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  3244. }
  3245. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3246. {
  3247. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  3248. }
  3249. uint16_t qla4_83xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3250. {
  3251. return (uint16_t)le32_to_cpu(readl(&ha->qla4_83xx_reg->req_q_out));
  3252. }
  3253. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3254. {
  3255. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  3256. }
  3257. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3258. {
  3259. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  3260. }
  3261. uint16_t qla4_83xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3262. {
  3263. return (uint16_t)le32_to_cpu(readl(&ha->qla4_83xx_reg->rsp_q_in));
  3264. }
  3265. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  3266. {
  3267. struct scsi_qla_host *ha = data;
  3268. char *str = buf;
  3269. int rc;
  3270. switch (type) {
  3271. case ISCSI_BOOT_ETH_FLAGS:
  3272. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3273. break;
  3274. case ISCSI_BOOT_ETH_INDEX:
  3275. rc = sprintf(str, "0\n");
  3276. break;
  3277. case ISCSI_BOOT_ETH_MAC:
  3278. rc = sysfs_format_mac(str, ha->my_mac,
  3279. MAC_ADDR_LEN);
  3280. break;
  3281. default:
  3282. rc = -ENOSYS;
  3283. break;
  3284. }
  3285. return rc;
  3286. }
  3287. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  3288. {
  3289. int rc;
  3290. switch (type) {
  3291. case ISCSI_BOOT_ETH_FLAGS:
  3292. case ISCSI_BOOT_ETH_MAC:
  3293. case ISCSI_BOOT_ETH_INDEX:
  3294. rc = S_IRUGO;
  3295. break;
  3296. default:
  3297. rc = 0;
  3298. break;
  3299. }
  3300. return rc;
  3301. }
  3302. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  3303. {
  3304. struct scsi_qla_host *ha = data;
  3305. char *str = buf;
  3306. int rc;
  3307. switch (type) {
  3308. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3309. rc = sprintf(str, "%s\n", ha->name_string);
  3310. break;
  3311. default:
  3312. rc = -ENOSYS;
  3313. break;
  3314. }
  3315. return rc;
  3316. }
  3317. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  3318. {
  3319. int rc;
  3320. switch (type) {
  3321. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3322. rc = S_IRUGO;
  3323. break;
  3324. default:
  3325. rc = 0;
  3326. break;
  3327. }
  3328. return rc;
  3329. }
  3330. static ssize_t
  3331. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  3332. char *buf)
  3333. {
  3334. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3335. char *str = buf;
  3336. int rc;
  3337. switch (type) {
  3338. case ISCSI_BOOT_TGT_NAME:
  3339. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  3340. break;
  3341. case ISCSI_BOOT_TGT_IP_ADDR:
  3342. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  3343. rc = sprintf(buf, "%pI4\n",
  3344. &boot_conn->dest_ipaddr.ip_address);
  3345. else
  3346. rc = sprintf(str, "%pI6\n",
  3347. &boot_conn->dest_ipaddr.ip_address);
  3348. break;
  3349. case ISCSI_BOOT_TGT_PORT:
  3350. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  3351. break;
  3352. case ISCSI_BOOT_TGT_CHAP_NAME:
  3353. rc = sprintf(str, "%.*s\n",
  3354. boot_conn->chap.target_chap_name_length,
  3355. (char *)&boot_conn->chap.target_chap_name);
  3356. break;
  3357. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3358. rc = sprintf(str, "%.*s\n",
  3359. boot_conn->chap.target_secret_length,
  3360. (char *)&boot_conn->chap.target_secret);
  3361. break;
  3362. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3363. rc = sprintf(str, "%.*s\n",
  3364. boot_conn->chap.intr_chap_name_length,
  3365. (char *)&boot_conn->chap.intr_chap_name);
  3366. break;
  3367. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3368. rc = sprintf(str, "%.*s\n",
  3369. boot_conn->chap.intr_secret_length,
  3370. (char *)&boot_conn->chap.intr_secret);
  3371. break;
  3372. case ISCSI_BOOT_TGT_FLAGS:
  3373. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3374. break;
  3375. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3376. rc = sprintf(str, "0\n");
  3377. break;
  3378. default:
  3379. rc = -ENOSYS;
  3380. break;
  3381. }
  3382. return rc;
  3383. }
  3384. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  3385. {
  3386. struct scsi_qla_host *ha = data;
  3387. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  3388. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3389. }
  3390. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  3391. {
  3392. struct scsi_qla_host *ha = data;
  3393. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  3394. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3395. }
  3396. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  3397. {
  3398. int rc;
  3399. switch (type) {
  3400. case ISCSI_BOOT_TGT_NAME:
  3401. case ISCSI_BOOT_TGT_IP_ADDR:
  3402. case ISCSI_BOOT_TGT_PORT:
  3403. case ISCSI_BOOT_TGT_CHAP_NAME:
  3404. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3405. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3406. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3407. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3408. case ISCSI_BOOT_TGT_FLAGS:
  3409. rc = S_IRUGO;
  3410. break;
  3411. default:
  3412. rc = 0;
  3413. break;
  3414. }
  3415. return rc;
  3416. }
  3417. static void qla4xxx_boot_release(void *data)
  3418. {
  3419. struct scsi_qla_host *ha = data;
  3420. scsi_host_put(ha->host);
  3421. }
  3422. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  3423. {
  3424. dma_addr_t buf_dma;
  3425. uint32_t addr, pri_addr, sec_addr;
  3426. uint32_t offset;
  3427. uint16_t func_num;
  3428. uint8_t val;
  3429. uint8_t *buf = NULL;
  3430. size_t size = 13 * sizeof(uint8_t);
  3431. int ret = QLA_SUCCESS;
  3432. func_num = PCI_FUNC(ha->pdev->devfn);
  3433. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  3434. __func__, ha->pdev->device, func_num);
  3435. if (is_qla40XX(ha)) {
  3436. if (func_num == 1) {
  3437. addr = NVRAM_PORT0_BOOT_MODE;
  3438. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  3439. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  3440. } else if (func_num == 3) {
  3441. addr = NVRAM_PORT1_BOOT_MODE;
  3442. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  3443. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  3444. } else {
  3445. ret = QLA_ERROR;
  3446. goto exit_boot_info;
  3447. }
  3448. /* Check Boot Mode */
  3449. val = rd_nvram_byte(ha, addr);
  3450. if (!(val & 0x07)) {
  3451. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  3452. "options : 0x%x\n", __func__, val));
  3453. ret = QLA_ERROR;
  3454. goto exit_boot_info;
  3455. }
  3456. /* get primary valid target index */
  3457. val = rd_nvram_byte(ha, pri_addr);
  3458. if (val & BIT_7)
  3459. ddb_index[0] = (val & 0x7f);
  3460. /* get secondary valid target index */
  3461. val = rd_nvram_byte(ha, sec_addr);
  3462. if (val & BIT_7)
  3463. ddb_index[1] = (val & 0x7f);
  3464. } else if (is_qla8022(ha)) {
  3465. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  3466. &buf_dma, GFP_KERNEL);
  3467. if (!buf) {
  3468. DEBUG2(ql4_printk(KERN_ERR, ha,
  3469. "%s: Unable to allocate dma buffer\n",
  3470. __func__));
  3471. ret = QLA_ERROR;
  3472. goto exit_boot_info;
  3473. }
  3474. if (ha->port_num == 0)
  3475. offset = BOOT_PARAM_OFFSET_PORT0;
  3476. else if (ha->port_num == 1)
  3477. offset = BOOT_PARAM_OFFSET_PORT1;
  3478. else {
  3479. ret = QLA_ERROR;
  3480. goto exit_boot_info_free;
  3481. }
  3482. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  3483. offset;
  3484. if (qla4xxx_get_flash(ha, buf_dma, addr,
  3485. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  3486. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  3487. " failed\n", ha->host_no, __func__));
  3488. ret = QLA_ERROR;
  3489. goto exit_boot_info_free;
  3490. }
  3491. /* Check Boot Mode */
  3492. if (!(buf[1] & 0x07)) {
  3493. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  3494. " : 0x%x\n", buf[1]));
  3495. ret = QLA_ERROR;
  3496. goto exit_boot_info_free;
  3497. }
  3498. /* get primary valid target index */
  3499. if (buf[2] & BIT_7)
  3500. ddb_index[0] = buf[2] & 0x7f;
  3501. /* get secondary valid target index */
  3502. if (buf[11] & BIT_7)
  3503. ddb_index[1] = buf[11] & 0x7f;
  3504. } else {
  3505. ret = QLA_ERROR;
  3506. goto exit_boot_info;
  3507. }
  3508. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  3509. " target ID %d\n", __func__, ddb_index[0],
  3510. ddb_index[1]));
  3511. exit_boot_info_free:
  3512. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  3513. exit_boot_info:
  3514. ha->pri_ddb_idx = ddb_index[0];
  3515. ha->sec_ddb_idx = ddb_index[1];
  3516. return ret;
  3517. }
  3518. /**
  3519. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  3520. * @ha: pointer to adapter structure
  3521. * @username: CHAP username to be returned
  3522. * @password: CHAP password to be returned
  3523. *
  3524. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  3525. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  3526. * So from the CHAP cache find the first BIDI CHAP entry and set it
  3527. * to the boot record in sysfs.
  3528. **/
  3529. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  3530. char *password)
  3531. {
  3532. int i, ret = -EINVAL;
  3533. int max_chap_entries = 0;
  3534. struct ql4_chap_table *chap_table;
  3535. if (is_qla8022(ha))
  3536. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  3537. sizeof(struct ql4_chap_table);
  3538. else
  3539. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  3540. if (!ha->chap_list) {
  3541. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  3542. return ret;
  3543. }
  3544. mutex_lock(&ha->chap_sem);
  3545. for (i = 0; i < max_chap_entries; i++) {
  3546. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  3547. if (chap_table->cookie !=
  3548. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  3549. continue;
  3550. }
  3551. if (chap_table->flags & BIT_7) /* local */
  3552. continue;
  3553. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  3554. continue;
  3555. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  3556. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  3557. ret = 0;
  3558. break;
  3559. }
  3560. mutex_unlock(&ha->chap_sem);
  3561. return ret;
  3562. }
  3563. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  3564. struct ql4_boot_session_info *boot_sess,
  3565. uint16_t ddb_index)
  3566. {
  3567. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3568. struct dev_db_entry *fw_ddb_entry;
  3569. dma_addr_t fw_ddb_entry_dma;
  3570. uint16_t idx;
  3571. uint16_t options;
  3572. int ret = QLA_SUCCESS;
  3573. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3574. &fw_ddb_entry_dma, GFP_KERNEL);
  3575. if (!fw_ddb_entry) {
  3576. DEBUG2(ql4_printk(KERN_ERR, ha,
  3577. "%s: Unable to allocate dma buffer.\n",
  3578. __func__));
  3579. ret = QLA_ERROR;
  3580. return ret;
  3581. }
  3582. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  3583. fw_ddb_entry_dma, ddb_index)) {
  3584. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  3585. "index [%d]\n", __func__, ddb_index));
  3586. ret = QLA_ERROR;
  3587. goto exit_boot_target;
  3588. }
  3589. /* Update target name and IP from DDB */
  3590. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  3591. min(sizeof(boot_sess->target_name),
  3592. sizeof(fw_ddb_entry->iscsi_name)));
  3593. options = le16_to_cpu(fw_ddb_entry->options);
  3594. if (options & DDB_OPT_IPV6_DEVICE) {
  3595. memcpy(&boot_conn->dest_ipaddr.ip_address,
  3596. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  3597. } else {
  3598. boot_conn->dest_ipaddr.ip_type = 0x1;
  3599. memcpy(&boot_conn->dest_ipaddr.ip_address,
  3600. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  3601. }
  3602. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  3603. /* update chap information */
  3604. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3605. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  3606. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  3607. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  3608. target_chap_name,
  3609. (char *)&boot_conn->chap.target_secret,
  3610. idx);
  3611. if (ret) {
  3612. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  3613. ret = QLA_ERROR;
  3614. goto exit_boot_target;
  3615. }
  3616. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  3617. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  3618. }
  3619. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  3620. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  3621. ret = qla4xxx_get_bidi_chap(ha,
  3622. (char *)&boot_conn->chap.intr_chap_name,
  3623. (char *)&boot_conn->chap.intr_secret);
  3624. if (ret) {
  3625. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  3626. ret = QLA_ERROR;
  3627. goto exit_boot_target;
  3628. }
  3629. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  3630. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  3631. }
  3632. exit_boot_target:
  3633. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3634. fw_ddb_entry, fw_ddb_entry_dma);
  3635. return ret;
  3636. }
  3637. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  3638. {
  3639. uint16_t ddb_index[2];
  3640. int ret = QLA_ERROR;
  3641. int rval;
  3642. memset(ddb_index, 0, sizeof(ddb_index));
  3643. ddb_index[0] = 0xffff;
  3644. ddb_index[1] = 0xffff;
  3645. ret = get_fw_boot_info(ha, ddb_index);
  3646. if (ret != QLA_SUCCESS) {
  3647. DEBUG2(ql4_printk(KERN_INFO, ha,
  3648. "%s: No boot target configured.\n", __func__));
  3649. return ret;
  3650. }
  3651. if (ql4xdisablesysfsboot)
  3652. return QLA_SUCCESS;
  3653. if (ddb_index[0] == 0xffff)
  3654. goto sec_target;
  3655. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  3656. ddb_index[0]);
  3657. if (rval != QLA_SUCCESS) {
  3658. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  3659. "configured\n", __func__));
  3660. } else
  3661. ret = QLA_SUCCESS;
  3662. sec_target:
  3663. if (ddb_index[1] == 0xffff)
  3664. goto exit_get_boot_info;
  3665. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  3666. ddb_index[1]);
  3667. if (rval != QLA_SUCCESS) {
  3668. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  3669. " configured\n", __func__));
  3670. } else
  3671. ret = QLA_SUCCESS;
  3672. exit_get_boot_info:
  3673. return ret;
  3674. }
  3675. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  3676. {
  3677. struct iscsi_boot_kobj *boot_kobj;
  3678. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  3679. return QLA_ERROR;
  3680. if (ql4xdisablesysfsboot) {
  3681. ql4_printk(KERN_INFO, ha,
  3682. "%s: syfsboot disabled - driver will trigger login "
  3683. "and publish session for discovery .\n", __func__);
  3684. return QLA_SUCCESS;
  3685. }
  3686. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  3687. if (!ha->boot_kset)
  3688. goto kset_free;
  3689. if (!scsi_host_get(ha->host))
  3690. goto kset_free;
  3691. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  3692. qla4xxx_show_boot_tgt_pri_info,
  3693. qla4xxx_tgt_get_attr_visibility,
  3694. qla4xxx_boot_release);
  3695. if (!boot_kobj)
  3696. goto put_host;
  3697. if (!scsi_host_get(ha->host))
  3698. goto kset_free;
  3699. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  3700. qla4xxx_show_boot_tgt_sec_info,
  3701. qla4xxx_tgt_get_attr_visibility,
  3702. qla4xxx_boot_release);
  3703. if (!boot_kobj)
  3704. goto put_host;
  3705. if (!scsi_host_get(ha->host))
  3706. goto kset_free;
  3707. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  3708. qla4xxx_show_boot_ini_info,
  3709. qla4xxx_ini_get_attr_visibility,
  3710. qla4xxx_boot_release);
  3711. if (!boot_kobj)
  3712. goto put_host;
  3713. if (!scsi_host_get(ha->host))
  3714. goto kset_free;
  3715. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  3716. qla4xxx_show_boot_eth_info,
  3717. qla4xxx_eth_get_attr_visibility,
  3718. qla4xxx_boot_release);
  3719. if (!boot_kobj)
  3720. goto put_host;
  3721. return QLA_SUCCESS;
  3722. put_host:
  3723. scsi_host_put(ha->host);
  3724. kset_free:
  3725. iscsi_boot_destroy_kset(ha->boot_kset);
  3726. return -ENOMEM;
  3727. }
  3728. /**
  3729. * qla4xxx_create chap_list - Create CHAP list from FLASH
  3730. * @ha: pointer to adapter structure
  3731. *
  3732. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  3733. * is received, it will be checked in this list. If entry exist then the CHAP
  3734. * entry index is set in the DDB. If CHAP entry does not exist in this list
  3735. * then a new entry is added in FLASH in CHAP table and the index obtained is
  3736. * used in the DDB.
  3737. **/
  3738. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  3739. {
  3740. int rval = 0;
  3741. uint8_t *chap_flash_data = NULL;
  3742. uint32_t offset;
  3743. dma_addr_t chap_dma;
  3744. uint32_t chap_size = 0;
  3745. if (is_qla40XX(ha))
  3746. chap_size = MAX_CHAP_ENTRIES_40XX *
  3747. sizeof(struct ql4_chap_table);
  3748. else /* Single region contains CHAP info for both
  3749. * ports which is divided into half for each port.
  3750. */
  3751. chap_size = ha->hw.flt_chap_size / 2;
  3752. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  3753. &chap_dma, GFP_KERNEL);
  3754. if (!chap_flash_data) {
  3755. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  3756. return;
  3757. }
  3758. if (is_qla40XX(ha))
  3759. offset = FLASH_CHAP_OFFSET;
  3760. else {
  3761. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  3762. if (ha->port_num == 1)
  3763. offset += chap_size;
  3764. }
  3765. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  3766. if (rval != QLA_SUCCESS)
  3767. goto exit_chap_list;
  3768. if (ha->chap_list == NULL)
  3769. ha->chap_list = vmalloc(chap_size);
  3770. if (ha->chap_list == NULL) {
  3771. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  3772. goto exit_chap_list;
  3773. }
  3774. memcpy(ha->chap_list, chap_flash_data, chap_size);
  3775. exit_chap_list:
  3776. dma_free_coherent(&ha->pdev->dev, chap_size,
  3777. chap_flash_data, chap_dma);
  3778. }
  3779. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  3780. struct ql4_tuple_ddb *tddb)
  3781. {
  3782. struct scsi_qla_host *ha;
  3783. struct iscsi_cls_session *cls_sess;
  3784. struct iscsi_cls_conn *cls_conn;
  3785. struct iscsi_session *sess;
  3786. struct iscsi_conn *conn;
  3787. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  3788. ha = ddb_entry->ha;
  3789. cls_sess = ddb_entry->sess;
  3790. sess = cls_sess->dd_data;
  3791. cls_conn = ddb_entry->conn;
  3792. conn = cls_conn->dd_data;
  3793. tddb->tpgt = sess->tpgt;
  3794. tddb->port = conn->persistent_port;
  3795. strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  3796. strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  3797. }
  3798. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  3799. struct ql4_tuple_ddb *tddb,
  3800. uint8_t *flash_isid)
  3801. {
  3802. uint16_t options = 0;
  3803. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  3804. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  3805. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  3806. options = le16_to_cpu(fw_ddb_entry->options);
  3807. if (options & DDB_OPT_IPV6_DEVICE)
  3808. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  3809. else
  3810. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  3811. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  3812. if (flash_isid == NULL)
  3813. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  3814. sizeof(tddb->isid));
  3815. else
  3816. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  3817. }
  3818. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  3819. struct ql4_tuple_ddb *old_tddb,
  3820. struct ql4_tuple_ddb *new_tddb,
  3821. uint8_t is_isid_compare)
  3822. {
  3823. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  3824. return QLA_ERROR;
  3825. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  3826. return QLA_ERROR;
  3827. if (old_tddb->port != new_tddb->port)
  3828. return QLA_ERROR;
  3829. /* For multi sessions, driver generates the ISID, so do not compare
  3830. * ISID in reset path since it would be a comparison between the
  3831. * driver generated ISID and firmware generated ISID. This could
  3832. * lead to adding duplicated DDBs in the list as driver generated
  3833. * ISID would not match firmware generated ISID.
  3834. */
  3835. if (is_isid_compare) {
  3836. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  3837. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  3838. __func__, old_tddb->isid[5], old_tddb->isid[4],
  3839. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  3840. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  3841. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  3842. new_tddb->isid[0]));
  3843. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  3844. sizeof(old_tddb->isid)))
  3845. return QLA_ERROR;
  3846. }
  3847. DEBUG2(ql4_printk(KERN_INFO, ha,
  3848. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  3849. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  3850. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  3851. new_tddb->ip_addr, new_tddb->iscsi_name));
  3852. return QLA_SUCCESS;
  3853. }
  3854. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  3855. struct dev_db_entry *fw_ddb_entry)
  3856. {
  3857. struct ddb_entry *ddb_entry;
  3858. struct ql4_tuple_ddb *fw_tddb = NULL;
  3859. struct ql4_tuple_ddb *tmp_tddb = NULL;
  3860. int idx;
  3861. int ret = QLA_ERROR;
  3862. fw_tddb = vzalloc(sizeof(*fw_tddb));
  3863. if (!fw_tddb) {
  3864. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3865. "Memory Allocation failed.\n"));
  3866. ret = QLA_SUCCESS;
  3867. goto exit_check;
  3868. }
  3869. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  3870. if (!tmp_tddb) {
  3871. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3872. "Memory Allocation failed.\n"));
  3873. ret = QLA_SUCCESS;
  3874. goto exit_check;
  3875. }
  3876. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  3877. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  3878. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  3879. if (ddb_entry == NULL)
  3880. continue;
  3881. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  3882. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  3883. ret = QLA_SUCCESS; /* found */
  3884. goto exit_check;
  3885. }
  3886. }
  3887. exit_check:
  3888. if (fw_tddb)
  3889. vfree(fw_tddb);
  3890. if (tmp_tddb)
  3891. vfree(tmp_tddb);
  3892. return ret;
  3893. }
  3894. /**
  3895. * qla4xxx_check_existing_isid - check if target with same isid exist
  3896. * in target list
  3897. * @list_nt: list of target
  3898. * @isid: isid to check
  3899. *
  3900. * This routine return QLA_SUCCESS if target with same isid exist
  3901. **/
  3902. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  3903. {
  3904. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  3905. struct dev_db_entry *fw_ddb_entry;
  3906. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  3907. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  3908. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  3909. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  3910. return QLA_SUCCESS;
  3911. }
  3912. }
  3913. return QLA_ERROR;
  3914. }
  3915. /**
  3916. * qla4xxx_update_isid - compare ddbs and updated isid
  3917. * @ha: Pointer to host adapter structure.
  3918. * @list_nt: list of nt target
  3919. * @fw_ddb_entry: firmware ddb entry
  3920. *
  3921. * This routine update isid if ddbs have same iqn, same isid and
  3922. * different IP addr.
  3923. * Return QLA_SUCCESS if isid is updated.
  3924. **/
  3925. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  3926. struct list_head *list_nt,
  3927. struct dev_db_entry *fw_ddb_entry)
  3928. {
  3929. uint8_t base_value, i;
  3930. base_value = fw_ddb_entry->isid[1] & 0x1f;
  3931. for (i = 0; i < 8; i++) {
  3932. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  3933. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  3934. break;
  3935. }
  3936. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  3937. return QLA_ERROR;
  3938. return QLA_SUCCESS;
  3939. }
  3940. /**
  3941. * qla4xxx_should_update_isid - check if isid need to update
  3942. * @ha: Pointer to host adapter structure.
  3943. * @old_tddb: ddb tuple
  3944. * @new_tddb: ddb tuple
  3945. *
  3946. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  3947. * same isid
  3948. **/
  3949. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  3950. struct ql4_tuple_ddb *old_tddb,
  3951. struct ql4_tuple_ddb *new_tddb)
  3952. {
  3953. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  3954. /* Same ip */
  3955. if (old_tddb->port == new_tddb->port)
  3956. return QLA_ERROR;
  3957. }
  3958. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  3959. /* different iqn */
  3960. return QLA_ERROR;
  3961. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  3962. sizeof(old_tddb->isid)))
  3963. /* different isid */
  3964. return QLA_ERROR;
  3965. return QLA_SUCCESS;
  3966. }
  3967. /**
  3968. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  3969. * @ha: Pointer to host adapter structure.
  3970. * @list_nt: list of nt target.
  3971. * @fw_ddb_entry: firmware ddb entry.
  3972. *
  3973. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  3974. * duplicate ddb in list_nt.
  3975. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  3976. * Note: This function also update isid of DDB if required.
  3977. **/
  3978. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  3979. struct list_head *list_nt,
  3980. struct dev_db_entry *fw_ddb_entry)
  3981. {
  3982. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  3983. struct ql4_tuple_ddb *fw_tddb = NULL;
  3984. struct ql4_tuple_ddb *tmp_tddb = NULL;
  3985. int rval, ret = QLA_ERROR;
  3986. fw_tddb = vzalloc(sizeof(*fw_tddb));
  3987. if (!fw_tddb) {
  3988. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3989. "Memory Allocation failed.\n"));
  3990. ret = QLA_SUCCESS;
  3991. goto exit_check;
  3992. }
  3993. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  3994. if (!tmp_tddb) {
  3995. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3996. "Memory Allocation failed.\n"));
  3997. ret = QLA_SUCCESS;
  3998. goto exit_check;
  3999. }
  4000. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4001. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4002. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  4003. nt_ddb_idx->flash_isid);
  4004. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  4005. /* found duplicate ddb */
  4006. if (ret == QLA_SUCCESS)
  4007. goto exit_check;
  4008. }
  4009. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4010. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  4011. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  4012. if (ret == QLA_SUCCESS) {
  4013. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  4014. if (rval == QLA_SUCCESS)
  4015. ret = QLA_ERROR;
  4016. else
  4017. ret = QLA_SUCCESS;
  4018. goto exit_check;
  4019. }
  4020. }
  4021. exit_check:
  4022. if (fw_tddb)
  4023. vfree(fw_tddb);
  4024. if (tmp_tddb)
  4025. vfree(tmp_tddb);
  4026. return ret;
  4027. }
  4028. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  4029. {
  4030. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4031. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4032. list_del_init(&ddb_idx->list);
  4033. vfree(ddb_idx);
  4034. }
  4035. }
  4036. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  4037. struct dev_db_entry *fw_ddb_entry)
  4038. {
  4039. struct iscsi_endpoint *ep;
  4040. struct sockaddr_in *addr;
  4041. struct sockaddr_in6 *addr6;
  4042. struct sockaddr *t_addr;
  4043. struct sockaddr_storage *dst_addr;
  4044. char *ip;
  4045. /* TODO: need to destroy on unload iscsi_endpoint*/
  4046. dst_addr = vmalloc(sizeof(*dst_addr));
  4047. if (!dst_addr)
  4048. return NULL;
  4049. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  4050. t_addr = (struct sockaddr *)dst_addr;
  4051. t_addr->sa_family = AF_INET6;
  4052. addr6 = (struct sockaddr_in6 *)dst_addr;
  4053. ip = (char *)&addr6->sin6_addr;
  4054. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  4055. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4056. } else {
  4057. t_addr = (struct sockaddr *)dst_addr;
  4058. t_addr->sa_family = AF_INET;
  4059. addr = (struct sockaddr_in *)dst_addr;
  4060. ip = (char *)&addr->sin_addr;
  4061. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  4062. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4063. }
  4064. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  4065. vfree(dst_addr);
  4066. return ep;
  4067. }
  4068. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  4069. {
  4070. if (ql4xdisablesysfsboot)
  4071. return QLA_SUCCESS;
  4072. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  4073. return QLA_ERROR;
  4074. return QLA_SUCCESS;
  4075. }
  4076. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  4077. struct ddb_entry *ddb_entry,
  4078. uint16_t idx)
  4079. {
  4080. uint16_t def_timeout;
  4081. ddb_entry->ddb_type = FLASH_DDB;
  4082. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  4083. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  4084. ddb_entry->ha = ha;
  4085. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  4086. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  4087. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  4088. atomic_set(&ddb_entry->relogin_timer, 0);
  4089. atomic_set(&ddb_entry->relogin_retry_count, 0);
  4090. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  4091. ddb_entry->default_relogin_timeout =
  4092. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  4093. def_timeout : LOGIN_TOV;
  4094. ddb_entry->default_time2wait =
  4095. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  4096. if (ql4xdisablesysfsboot &&
  4097. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  4098. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  4099. }
  4100. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  4101. {
  4102. uint32_t idx = 0;
  4103. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  4104. uint32_t sts[MBOX_REG_COUNT];
  4105. uint32_t ip_state;
  4106. unsigned long wtime;
  4107. int ret;
  4108. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  4109. do {
  4110. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  4111. if (ip_idx[idx] == -1)
  4112. continue;
  4113. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  4114. if (ret == QLA_ERROR) {
  4115. ip_idx[idx] = -1;
  4116. continue;
  4117. }
  4118. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  4119. DEBUG2(ql4_printk(KERN_INFO, ha,
  4120. "Waiting for IP state for idx = %d, state = 0x%x\n",
  4121. ip_idx[idx], ip_state));
  4122. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  4123. ip_state == IP_ADDRSTATE_INVALID ||
  4124. ip_state == IP_ADDRSTATE_PREFERRED ||
  4125. ip_state == IP_ADDRSTATE_DEPRICATED ||
  4126. ip_state == IP_ADDRSTATE_DISABLING)
  4127. ip_idx[idx] = -1;
  4128. }
  4129. /* Break if all IP states checked */
  4130. if ((ip_idx[0] == -1) &&
  4131. (ip_idx[1] == -1) &&
  4132. (ip_idx[2] == -1) &&
  4133. (ip_idx[3] == -1))
  4134. break;
  4135. schedule_timeout_uninterruptible(HZ);
  4136. } while (time_after(wtime, jiffies));
  4137. }
  4138. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  4139. struct list_head *list_st)
  4140. {
  4141. struct qla_ddb_index *st_ddb_idx;
  4142. int max_ddbs;
  4143. int fw_idx_size;
  4144. struct dev_db_entry *fw_ddb_entry;
  4145. dma_addr_t fw_ddb_dma;
  4146. int ret;
  4147. uint32_t idx = 0, next_idx = 0;
  4148. uint32_t state = 0, conn_err = 0;
  4149. uint16_t conn_id = 0;
  4150. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4151. &fw_ddb_dma);
  4152. if (fw_ddb_entry == NULL) {
  4153. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4154. goto exit_st_list;
  4155. }
  4156. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4157. MAX_DEV_DB_ENTRIES;
  4158. fw_idx_size = sizeof(struct qla_ddb_index);
  4159. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4160. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4161. NULL, &next_idx, &state,
  4162. &conn_err, NULL, &conn_id);
  4163. if (ret == QLA_ERROR)
  4164. break;
  4165. /* Ignore DDB if invalid state (unassigned) */
  4166. if (state == DDB_DS_UNASSIGNED)
  4167. goto continue_next_st;
  4168. /* Check if ST, add to the list_st */
  4169. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  4170. goto continue_next_st;
  4171. st_ddb_idx = vzalloc(fw_idx_size);
  4172. if (!st_ddb_idx)
  4173. break;
  4174. st_ddb_idx->fw_ddb_idx = idx;
  4175. list_add_tail(&st_ddb_idx->list, list_st);
  4176. continue_next_st:
  4177. if (next_idx == 0)
  4178. break;
  4179. }
  4180. exit_st_list:
  4181. if (fw_ddb_entry)
  4182. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4183. }
  4184. /**
  4185. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  4186. * @ha: pointer to adapter structure
  4187. * @list_ddb: List from which failed ddb to be removed
  4188. *
  4189. * Iterate over the list of DDBs and find and remove DDBs that are either in
  4190. * no connection active state or failed state
  4191. **/
  4192. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  4193. struct list_head *list_ddb)
  4194. {
  4195. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4196. uint32_t next_idx = 0;
  4197. uint32_t state = 0, conn_err = 0;
  4198. int ret;
  4199. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4200. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  4201. NULL, 0, NULL, &next_idx, &state,
  4202. &conn_err, NULL, NULL);
  4203. if (ret == QLA_ERROR)
  4204. continue;
  4205. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4206. state == DDB_DS_SESSION_FAILED) {
  4207. list_del_init(&ddb_idx->list);
  4208. vfree(ddb_idx);
  4209. }
  4210. }
  4211. }
  4212. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  4213. struct dev_db_entry *fw_ddb_entry,
  4214. int is_reset, uint16_t idx)
  4215. {
  4216. struct iscsi_cls_session *cls_sess;
  4217. struct iscsi_session *sess;
  4218. struct iscsi_cls_conn *cls_conn;
  4219. struct iscsi_endpoint *ep;
  4220. uint16_t cmds_max = 32;
  4221. uint16_t conn_id = 0;
  4222. uint32_t initial_cmdsn = 0;
  4223. int ret = QLA_SUCCESS;
  4224. struct ddb_entry *ddb_entry = NULL;
  4225. /* Create session object, with INVALID_ENTRY,
  4226. * the targer_id would get set when we issue the login
  4227. */
  4228. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  4229. cmds_max, sizeof(struct ddb_entry),
  4230. sizeof(struct ql4_task_data),
  4231. initial_cmdsn, INVALID_ENTRY);
  4232. if (!cls_sess) {
  4233. ret = QLA_ERROR;
  4234. goto exit_setup;
  4235. }
  4236. /*
  4237. * so calling module_put function to decrement the
  4238. * reference count.
  4239. **/
  4240. module_put(qla4xxx_iscsi_transport.owner);
  4241. sess = cls_sess->dd_data;
  4242. ddb_entry = sess->dd_data;
  4243. ddb_entry->sess = cls_sess;
  4244. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  4245. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  4246. sizeof(struct dev_db_entry));
  4247. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  4248. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  4249. if (!cls_conn) {
  4250. ret = QLA_ERROR;
  4251. goto exit_setup;
  4252. }
  4253. ddb_entry->conn = cls_conn;
  4254. /* Setup ep, for displaying attributes in sysfs */
  4255. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  4256. if (ep) {
  4257. ep->conn = cls_conn;
  4258. cls_conn->ep = ep;
  4259. } else {
  4260. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  4261. ret = QLA_ERROR;
  4262. goto exit_setup;
  4263. }
  4264. /* Update sess/conn params */
  4265. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  4266. if (is_reset == RESET_ADAPTER) {
  4267. iscsi_block_session(cls_sess);
  4268. /* Use the relogin path to discover new devices
  4269. * by short-circuting the logic of setting
  4270. * timer to relogin - instead set the flags
  4271. * to initiate login right away.
  4272. */
  4273. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4274. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4275. }
  4276. exit_setup:
  4277. return ret;
  4278. }
  4279. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  4280. struct list_head *list_nt, int is_reset)
  4281. {
  4282. struct dev_db_entry *fw_ddb_entry;
  4283. dma_addr_t fw_ddb_dma;
  4284. int max_ddbs;
  4285. int fw_idx_size;
  4286. int ret;
  4287. uint32_t idx = 0, next_idx = 0;
  4288. uint32_t state = 0, conn_err = 0;
  4289. uint16_t conn_id = 0;
  4290. struct qla_ddb_index *nt_ddb_idx;
  4291. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4292. &fw_ddb_dma);
  4293. if (fw_ddb_entry == NULL) {
  4294. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4295. goto exit_nt_list;
  4296. }
  4297. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4298. MAX_DEV_DB_ENTRIES;
  4299. fw_idx_size = sizeof(struct qla_ddb_index);
  4300. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4301. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4302. NULL, &next_idx, &state,
  4303. &conn_err, NULL, &conn_id);
  4304. if (ret == QLA_ERROR)
  4305. break;
  4306. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  4307. goto continue_next_nt;
  4308. /* Check if NT, then add to list it */
  4309. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  4310. goto continue_next_nt;
  4311. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4312. state == DDB_DS_SESSION_FAILED))
  4313. goto continue_next_nt;
  4314. DEBUG2(ql4_printk(KERN_INFO, ha,
  4315. "Adding DDB to session = 0x%x\n", idx));
  4316. if (is_reset == INIT_ADAPTER) {
  4317. nt_ddb_idx = vmalloc(fw_idx_size);
  4318. if (!nt_ddb_idx)
  4319. break;
  4320. nt_ddb_idx->fw_ddb_idx = idx;
  4321. /* Copy original isid as it may get updated in function
  4322. * qla4xxx_update_isid(). We need original isid in
  4323. * function qla4xxx_compare_tuple_ddb to find duplicate
  4324. * target */
  4325. memcpy(&nt_ddb_idx->flash_isid[0],
  4326. &fw_ddb_entry->isid[0],
  4327. sizeof(nt_ddb_idx->flash_isid));
  4328. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  4329. fw_ddb_entry);
  4330. if (ret == QLA_SUCCESS) {
  4331. /* free nt_ddb_idx and do not add to list_nt */
  4332. vfree(nt_ddb_idx);
  4333. goto continue_next_nt;
  4334. }
  4335. /* Copy updated isid */
  4336. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  4337. sizeof(struct dev_db_entry));
  4338. list_add_tail(&nt_ddb_idx->list, list_nt);
  4339. } else if (is_reset == RESET_ADAPTER) {
  4340. if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
  4341. QLA_SUCCESS)
  4342. goto continue_next_nt;
  4343. }
  4344. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  4345. if (ret == QLA_ERROR)
  4346. goto exit_nt_list;
  4347. continue_next_nt:
  4348. if (next_idx == 0)
  4349. break;
  4350. }
  4351. exit_nt_list:
  4352. if (fw_ddb_entry)
  4353. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4354. }
  4355. /**
  4356. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  4357. * @ha: pointer to adapter structure
  4358. * @is_reset: Is this init path or reset path
  4359. *
  4360. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  4361. * using connection open, then create the list of normal targets (nt)
  4362. * from firmware DDBs. Based on the list of nt setup session and connection
  4363. * objects.
  4364. **/
  4365. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  4366. {
  4367. uint16_t tmo = 0;
  4368. struct list_head list_st, list_nt;
  4369. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  4370. unsigned long wtime;
  4371. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  4372. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  4373. ha->is_reset = is_reset;
  4374. return;
  4375. }
  4376. INIT_LIST_HEAD(&list_st);
  4377. INIT_LIST_HEAD(&list_nt);
  4378. qla4xxx_build_st_list(ha, &list_st);
  4379. /* Before issuing conn open mbox, ensure all IPs states are configured
  4380. * Note, conn open fails if IPs are not configured
  4381. */
  4382. qla4xxx_wait_for_ip_configuration(ha);
  4383. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  4384. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  4385. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  4386. }
  4387. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  4388. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  4389. (ha->def_timeout < LOGIN_TOV * 10) ?
  4390. ha->def_timeout : LOGIN_TOV);
  4391. DEBUG2(ql4_printk(KERN_INFO, ha,
  4392. "Default time to wait for build ddb %d\n", tmo));
  4393. wtime = jiffies + (HZ * tmo);
  4394. do {
  4395. if (list_empty(&list_st))
  4396. break;
  4397. qla4xxx_remove_failed_ddb(ha, &list_st);
  4398. schedule_timeout_uninterruptible(HZ / 10);
  4399. } while (time_after(wtime, jiffies));
  4400. /* Free up the sendtargets list */
  4401. qla4xxx_free_ddb_list(&list_st);
  4402. qla4xxx_build_nt_list(ha, &list_nt, is_reset);
  4403. qla4xxx_free_ddb_list(&list_nt);
  4404. qla4xxx_free_ddb_index(ha);
  4405. }
  4406. /**
  4407. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  4408. * response.
  4409. * @ha: pointer to adapter structure
  4410. *
  4411. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  4412. * set in DDB and we will wait for login response of boot targets during
  4413. * probe.
  4414. **/
  4415. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  4416. {
  4417. struct ddb_entry *ddb_entry;
  4418. struct dev_db_entry *fw_ddb_entry = NULL;
  4419. dma_addr_t fw_ddb_entry_dma;
  4420. unsigned long wtime;
  4421. uint32_t ddb_state;
  4422. int max_ddbs, idx, ret;
  4423. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4424. MAX_DEV_DB_ENTRIES;
  4425. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4426. &fw_ddb_entry_dma, GFP_KERNEL);
  4427. if (!fw_ddb_entry) {
  4428. ql4_printk(KERN_ERR, ha,
  4429. "%s: Unable to allocate dma buffer\n", __func__);
  4430. goto exit_login_resp;
  4431. }
  4432. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  4433. for (idx = 0; idx < max_ddbs; idx++) {
  4434. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4435. if (ddb_entry == NULL)
  4436. continue;
  4437. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  4438. DEBUG2(ql4_printk(KERN_INFO, ha,
  4439. "%s: DDB index [%d]\n", __func__,
  4440. ddb_entry->fw_ddb_index));
  4441. do {
  4442. ret = qla4xxx_get_fwddb_entry(ha,
  4443. ddb_entry->fw_ddb_index,
  4444. fw_ddb_entry, fw_ddb_entry_dma,
  4445. NULL, NULL, &ddb_state, NULL,
  4446. NULL, NULL);
  4447. if (ret == QLA_ERROR)
  4448. goto exit_login_resp;
  4449. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  4450. (ddb_state == DDB_DS_SESSION_FAILED))
  4451. break;
  4452. schedule_timeout_uninterruptible(HZ);
  4453. } while ((time_after(wtime, jiffies)));
  4454. if (!time_after(wtime, jiffies)) {
  4455. DEBUG2(ql4_printk(KERN_INFO, ha,
  4456. "%s: Login response wait timer expired\n",
  4457. __func__));
  4458. goto exit_login_resp;
  4459. }
  4460. }
  4461. }
  4462. exit_login_resp:
  4463. if (fw_ddb_entry)
  4464. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4465. fw_ddb_entry, fw_ddb_entry_dma);
  4466. }
  4467. /**
  4468. * qla4xxx_probe_adapter - callback function to probe HBA
  4469. * @pdev: pointer to pci_dev structure
  4470. * @pci_device_id: pointer to pci_device entry
  4471. *
  4472. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  4473. * It returns zero if successful. It also initializes all data necessary for
  4474. * the driver.
  4475. **/
  4476. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  4477. const struct pci_device_id *ent)
  4478. {
  4479. int ret = -ENODEV, status;
  4480. struct Scsi_Host *host;
  4481. struct scsi_qla_host *ha;
  4482. uint8_t init_retry_count = 0;
  4483. char buf[34];
  4484. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  4485. uint32_t dev_state;
  4486. if (pci_enable_device(pdev))
  4487. return -1;
  4488. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  4489. if (host == NULL) {
  4490. printk(KERN_WARNING
  4491. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  4492. goto probe_disable_device;
  4493. }
  4494. /* Clear our data area */
  4495. ha = to_qla_host(host);
  4496. memset(ha, 0, sizeof(*ha));
  4497. /* Save the information from PCI BIOS. */
  4498. ha->pdev = pdev;
  4499. ha->host = host;
  4500. ha->host_no = host->host_no;
  4501. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  4502. pci_enable_pcie_error_reporting(pdev);
  4503. /* Setup Runtime configurable options */
  4504. if (is_qla8022(ha)) {
  4505. ha->isp_ops = &qla4_82xx_isp_ops;
  4506. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  4507. ha->qdr_sn_window = -1;
  4508. ha->ddr_mn_window = -1;
  4509. ha->curr_window = 255;
  4510. nx_legacy_intr = &legacy_intr[ha->func_num];
  4511. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  4512. ha->nx_legacy_intr.tgt_status_reg =
  4513. nx_legacy_intr->tgt_status_reg;
  4514. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  4515. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  4516. } else if (is_qla8032(ha)) {
  4517. ha->isp_ops = &qla4_83xx_isp_ops;
  4518. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  4519. } else {
  4520. ha->isp_ops = &qla4xxx_isp_ops;
  4521. }
  4522. if (is_qla80XX(ha)) {
  4523. rwlock_init(&ha->hw_lock);
  4524. ha->pf_bit = ha->func_num << 16;
  4525. /* Set EEH reset type to fundamental if required by hba */
  4526. pdev->needs_freset = 1;
  4527. }
  4528. /* Configure PCI I/O space. */
  4529. ret = ha->isp_ops->iospace_config(ha);
  4530. if (ret)
  4531. goto probe_failed_ioconfig;
  4532. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  4533. pdev->device, pdev->irq, ha->reg);
  4534. qla4xxx_config_dma_addressing(ha);
  4535. /* Initialize lists and spinlocks. */
  4536. INIT_LIST_HEAD(&ha->free_srb_q);
  4537. mutex_init(&ha->mbox_sem);
  4538. mutex_init(&ha->chap_sem);
  4539. init_completion(&ha->mbx_intr_comp);
  4540. init_completion(&ha->disable_acb_comp);
  4541. spin_lock_init(&ha->hardware_lock);
  4542. spin_lock_init(&ha->work_lock);
  4543. /* Initialize work list */
  4544. INIT_LIST_HEAD(&ha->work_list);
  4545. /* Allocate dma buffers */
  4546. if (qla4xxx_mem_alloc(ha)) {
  4547. ql4_printk(KERN_WARNING, ha,
  4548. "[ERROR] Failed to allocate memory for adapter\n");
  4549. ret = -ENOMEM;
  4550. goto probe_failed;
  4551. }
  4552. host->cmd_per_lun = 3;
  4553. host->max_channel = 0;
  4554. host->max_lun = MAX_LUNS - 1;
  4555. host->max_id = MAX_TARGETS;
  4556. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  4557. host->can_queue = MAX_SRBS ;
  4558. host->transportt = qla4xxx_scsi_transport;
  4559. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  4560. if (ret) {
  4561. ql4_printk(KERN_WARNING, ha,
  4562. "%s: scsi_init_shared_tag_map failed\n", __func__);
  4563. goto probe_failed;
  4564. }
  4565. pci_set_drvdata(pdev, ha);
  4566. ret = scsi_add_host(host, &pdev->dev);
  4567. if (ret)
  4568. goto probe_failed;
  4569. if (is_qla80XX(ha))
  4570. qla4_8xxx_get_flash_info(ha);
  4571. if (is_qla8032(ha)) {
  4572. qla4_83xx_read_reset_template(ha);
  4573. /*
  4574. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  4575. * If DONRESET_BIT0 is set, drivers should not set dev_state
  4576. * to NEED_RESET. But if NEED_RESET is set, drivers should
  4577. * should honor the reset.
  4578. */
  4579. if (ql4xdontresethba == 1)
  4580. qla4_83xx_set_idc_dontreset(ha);
  4581. }
  4582. /*
  4583. * Initialize the Host adapter request/response queues and
  4584. * firmware
  4585. * NOTE: interrupts enabled upon successful completion
  4586. */
  4587. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  4588. /* Dont retry adapter initialization if IRQ allocation failed */
  4589. if (!test_bit(AF_IRQ_ATTACHED, &ha->flags))
  4590. goto skip_retry_init;
  4591. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  4592. init_retry_count++ < MAX_INIT_RETRIES) {
  4593. if (is_qla80XX(ha)) {
  4594. ha->isp_ops->idc_lock(ha);
  4595. dev_state = qla4_8xxx_rd_direct(ha,
  4596. QLA8XXX_CRB_DEV_STATE);
  4597. ha->isp_ops->idc_unlock(ha);
  4598. if (dev_state == QLA8XXX_DEV_FAILED) {
  4599. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  4600. "initialize adapter. H/W is in failed state\n",
  4601. __func__);
  4602. break;
  4603. }
  4604. }
  4605. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  4606. "(%d)\n", __func__, init_retry_count));
  4607. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  4608. continue;
  4609. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  4610. }
  4611. skip_retry_init:
  4612. if (!test_bit(AF_ONLINE, &ha->flags)) {
  4613. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  4614. if ((is_qla8022(ha) && ql4xdontresethba) ||
  4615. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  4616. /* Put the device in failed state. */
  4617. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  4618. ha->isp_ops->idc_lock(ha);
  4619. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  4620. QLA8XXX_DEV_FAILED);
  4621. ha->isp_ops->idc_unlock(ha);
  4622. }
  4623. ret = -ENODEV;
  4624. goto remove_host;
  4625. }
  4626. /* Startup the kernel thread for this host adapter. */
  4627. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  4628. "qla4xxx_dpc\n", __func__));
  4629. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  4630. ha->dpc_thread = create_singlethread_workqueue(buf);
  4631. if (!ha->dpc_thread) {
  4632. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  4633. ret = -ENODEV;
  4634. goto remove_host;
  4635. }
  4636. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  4637. sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
  4638. ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
  4639. if (!ha->task_wq) {
  4640. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  4641. ret = -ENODEV;
  4642. goto remove_host;
  4643. }
  4644. /*
  4645. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  4646. * (which is called indirectly by qla4xxx_initialize_adapter),
  4647. * so that irqs will be registered after crbinit but before
  4648. * mbx_intr_enable.
  4649. */
  4650. if (is_qla40XX(ha)) {
  4651. ret = qla4xxx_request_irqs(ha);
  4652. if (ret) {
  4653. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  4654. "interrupt %d already in use.\n", pdev->irq);
  4655. goto remove_host;
  4656. }
  4657. }
  4658. pci_save_state(ha->pdev);
  4659. ha->isp_ops->enable_intrs(ha);
  4660. /* Start timer thread. */
  4661. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  4662. set_bit(AF_INIT_DONE, &ha->flags);
  4663. qla4_8xxx_alloc_sysfs_attr(ha);
  4664. printk(KERN_INFO
  4665. " QLogic iSCSI HBA Driver version: %s\n"
  4666. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  4667. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  4668. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  4669. ha->patch_number, ha->build_number);
  4670. /* Set the driver version */
  4671. if (is_qla80XX(ha))
  4672. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  4673. if (qla4xxx_setup_boot_info(ha))
  4674. ql4_printk(KERN_ERR, ha,
  4675. "%s: No iSCSI boot target configured\n", __func__);
  4676. /* Perform the build ddb list and login to each */
  4677. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  4678. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  4679. qla4xxx_wait_login_resp_boot_tgt(ha);
  4680. qla4xxx_create_chap_list(ha);
  4681. qla4xxx_create_ifaces(ha);
  4682. return 0;
  4683. remove_host:
  4684. scsi_remove_host(ha->host);
  4685. probe_failed:
  4686. qla4xxx_free_adapter(ha);
  4687. probe_failed_ioconfig:
  4688. pci_disable_pcie_error_reporting(pdev);
  4689. scsi_host_put(ha->host);
  4690. probe_disable_device:
  4691. pci_disable_device(pdev);
  4692. return ret;
  4693. }
  4694. /**
  4695. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  4696. * @ha: pointer to adapter structure
  4697. *
  4698. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  4699. * so that the other port will not re-initialize while in the process of
  4700. * removing the ha due to driver unload or hba hotplug.
  4701. **/
  4702. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  4703. {
  4704. struct scsi_qla_host *other_ha = NULL;
  4705. struct pci_dev *other_pdev = NULL;
  4706. int fn = ISP4XXX_PCI_FN_2;
  4707. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  4708. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  4709. fn = ISP4XXX_PCI_FN_1;
  4710. other_pdev =
  4711. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  4712. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  4713. fn));
  4714. /* Get other_ha if other_pdev is valid and state is enable*/
  4715. if (other_pdev) {
  4716. if (atomic_read(&other_pdev->enable_cnt)) {
  4717. other_ha = pci_get_drvdata(other_pdev);
  4718. if (other_ha) {
  4719. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  4720. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  4721. "Prevent %s reinit\n", __func__,
  4722. dev_name(&other_ha->pdev->dev)));
  4723. }
  4724. }
  4725. pci_dev_put(other_pdev);
  4726. }
  4727. }
  4728. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  4729. {
  4730. struct ddb_entry *ddb_entry;
  4731. int options;
  4732. int idx;
  4733. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  4734. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4735. if ((ddb_entry != NULL) &&
  4736. (ddb_entry->ddb_type == FLASH_DDB)) {
  4737. options = LOGOUT_OPTION_CLOSE_SESSION;
  4738. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
  4739. == QLA_ERROR)
  4740. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
  4741. __func__);
  4742. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  4743. /*
  4744. * we have decremented the reference count of the driver
  4745. * when we setup the session to have the driver unload
  4746. * to be seamless without actually destroying the
  4747. * session
  4748. **/
  4749. try_module_get(qla4xxx_iscsi_transport.owner);
  4750. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  4751. qla4xxx_free_ddb(ha, ddb_entry);
  4752. iscsi_session_teardown(ddb_entry->sess);
  4753. }
  4754. }
  4755. }
  4756. /**
  4757. * qla4xxx_remove_adapter - callback function to remove adapter.
  4758. * @pci_dev: PCI device pointer
  4759. **/
  4760. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  4761. {
  4762. struct scsi_qla_host *ha;
  4763. /*
  4764. * If the PCI device is disabled then it means probe_adapter had
  4765. * failed and resources already cleaned up on probe_adapter exit.
  4766. */
  4767. if (!pci_is_enabled(pdev))
  4768. return;
  4769. ha = pci_get_drvdata(pdev);
  4770. if (is_qla40XX(ha))
  4771. qla4xxx_prevent_other_port_reinit(ha);
  4772. /* destroy iface from sysfs */
  4773. qla4xxx_destroy_ifaces(ha);
  4774. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  4775. iscsi_boot_destroy_kset(ha->boot_kset);
  4776. qla4xxx_destroy_fw_ddb_session(ha);
  4777. qla4_8xxx_free_sysfs_attr(ha);
  4778. scsi_remove_host(ha->host);
  4779. qla4xxx_free_adapter(ha);
  4780. scsi_host_put(ha->host);
  4781. pci_disable_pcie_error_reporting(pdev);
  4782. pci_disable_device(pdev);
  4783. pci_set_drvdata(pdev, NULL);
  4784. }
  4785. /**
  4786. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  4787. * @ha: HA context
  4788. *
  4789. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  4790. * supported addressing method.
  4791. */
  4792. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  4793. {
  4794. int retval;
  4795. /* Update our PCI device dma_mask for full 64 bit mask */
  4796. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  4797. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  4798. dev_dbg(&ha->pdev->dev,
  4799. "Failed to set 64 bit PCI consistent mask; "
  4800. "using 32 bit.\n");
  4801. retval = pci_set_consistent_dma_mask(ha->pdev,
  4802. DMA_BIT_MASK(32));
  4803. }
  4804. } else
  4805. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  4806. }
  4807. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  4808. {
  4809. struct iscsi_cls_session *cls_sess;
  4810. struct iscsi_session *sess;
  4811. struct ddb_entry *ddb;
  4812. int queue_depth = QL4_DEF_QDEPTH;
  4813. cls_sess = starget_to_session(sdev->sdev_target);
  4814. sess = cls_sess->dd_data;
  4815. ddb = sess->dd_data;
  4816. sdev->hostdata = ddb;
  4817. sdev->tagged_supported = 1;
  4818. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  4819. queue_depth = ql4xmaxqdepth;
  4820. scsi_activate_tcq(sdev, queue_depth);
  4821. return 0;
  4822. }
  4823. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  4824. {
  4825. sdev->tagged_supported = 1;
  4826. return 0;
  4827. }
  4828. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  4829. {
  4830. scsi_deactivate_tcq(sdev, 1);
  4831. }
  4832. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  4833. int reason)
  4834. {
  4835. if (!ql4xqfulltracking)
  4836. return -EOPNOTSUPP;
  4837. return iscsi_change_queue_depth(sdev, qdepth, reason);
  4838. }
  4839. /**
  4840. * qla4xxx_del_from_active_array - returns an active srb
  4841. * @ha: Pointer to host adapter structure.
  4842. * @index: index into the active_array
  4843. *
  4844. * This routine removes and returns the srb at the specified index
  4845. **/
  4846. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  4847. uint32_t index)
  4848. {
  4849. struct srb *srb = NULL;
  4850. struct scsi_cmnd *cmd = NULL;
  4851. cmd = scsi_host_find_tag(ha->host, index);
  4852. if (!cmd)
  4853. return srb;
  4854. srb = (struct srb *)CMD_SP(cmd);
  4855. if (!srb)
  4856. return srb;
  4857. /* update counters */
  4858. if (srb->flags & SRB_DMA_VALID) {
  4859. ha->req_q_count += srb->iocb_cnt;
  4860. ha->iocb_cnt -= srb->iocb_cnt;
  4861. if (srb->cmd)
  4862. srb->cmd->host_scribble =
  4863. (unsigned char *)(unsigned long) MAX_SRBS;
  4864. }
  4865. return srb;
  4866. }
  4867. /**
  4868. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  4869. * @ha: Pointer to host adapter structure.
  4870. * @cmd: Scsi Command to wait on.
  4871. *
  4872. * This routine waits for the command to be returned by the Firmware
  4873. * for some max time.
  4874. **/
  4875. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  4876. struct scsi_cmnd *cmd)
  4877. {
  4878. int done = 0;
  4879. struct srb *rp;
  4880. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  4881. int ret = SUCCESS;
  4882. /* Dont wait on command if PCI error is being handled
  4883. * by PCI AER driver
  4884. */
  4885. if (unlikely(pci_channel_offline(ha->pdev)) ||
  4886. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  4887. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  4888. ha->host_no, __func__);
  4889. return ret;
  4890. }
  4891. do {
  4892. /* Checking to see if its returned to OS */
  4893. rp = (struct srb *) CMD_SP(cmd);
  4894. if (rp == NULL) {
  4895. done++;
  4896. break;
  4897. }
  4898. msleep(2000);
  4899. } while (max_wait_time--);
  4900. return done;
  4901. }
  4902. /**
  4903. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  4904. * @ha: Pointer to host adapter structure
  4905. **/
  4906. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  4907. {
  4908. unsigned long wait_online;
  4909. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  4910. while (time_before(jiffies, wait_online)) {
  4911. if (adapter_up(ha))
  4912. return QLA_SUCCESS;
  4913. msleep(2000);
  4914. }
  4915. return QLA_ERROR;
  4916. }
  4917. /**
  4918. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  4919. * @ha: pointer to HBA
  4920. * @t: target id
  4921. * @l: lun id
  4922. *
  4923. * This function waits for all outstanding commands to a lun to complete. It
  4924. * returns 0 if all pending commands are returned and 1 otherwise.
  4925. **/
  4926. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  4927. struct scsi_target *stgt,
  4928. struct scsi_device *sdev)
  4929. {
  4930. int cnt;
  4931. int status = 0;
  4932. struct scsi_cmnd *cmd;
  4933. /*
  4934. * Waiting for all commands for the designated target or dev
  4935. * in the active array
  4936. */
  4937. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  4938. cmd = scsi_host_find_tag(ha->host, cnt);
  4939. if (cmd && stgt == scsi_target(cmd->device) &&
  4940. (!sdev || sdev == cmd->device)) {
  4941. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  4942. status++;
  4943. break;
  4944. }
  4945. }
  4946. }
  4947. return status;
  4948. }
  4949. /**
  4950. * qla4xxx_eh_abort - callback for abort task.
  4951. * @cmd: Pointer to Linux's SCSI command structure
  4952. *
  4953. * This routine is called by the Linux OS to abort the specified
  4954. * command.
  4955. **/
  4956. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  4957. {
  4958. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  4959. unsigned int id = cmd->device->id;
  4960. unsigned int lun = cmd->device->lun;
  4961. unsigned long flags;
  4962. struct srb *srb = NULL;
  4963. int ret = SUCCESS;
  4964. int wait = 0;
  4965. ql4_printk(KERN_INFO, ha,
  4966. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  4967. ha->host_no, id, lun, cmd);
  4968. spin_lock_irqsave(&ha->hardware_lock, flags);
  4969. srb = (struct srb *) CMD_SP(cmd);
  4970. if (!srb) {
  4971. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4972. return SUCCESS;
  4973. }
  4974. kref_get(&srb->srb_ref);
  4975. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4976. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  4977. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  4978. ha->host_no, id, lun));
  4979. ret = FAILED;
  4980. } else {
  4981. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  4982. ha->host_no, id, lun));
  4983. wait = 1;
  4984. }
  4985. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  4986. /* Wait for command to complete */
  4987. if (wait) {
  4988. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  4989. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  4990. ha->host_no, id, lun));
  4991. ret = FAILED;
  4992. }
  4993. }
  4994. ql4_printk(KERN_INFO, ha,
  4995. "scsi%ld:%d:%d: Abort command - %s\n",
  4996. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  4997. return ret;
  4998. }
  4999. /**
  5000. * qla4xxx_eh_device_reset - callback for target reset.
  5001. * @cmd: Pointer to Linux's SCSI command structure
  5002. *
  5003. * This routine is called by the Linux OS to reset all luns on the
  5004. * specified target.
  5005. **/
  5006. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  5007. {
  5008. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  5009. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  5010. int ret = FAILED, stat;
  5011. if (!ddb_entry)
  5012. return ret;
  5013. ret = iscsi_block_scsi_eh(cmd);
  5014. if (ret)
  5015. return ret;
  5016. ret = FAILED;
  5017. ql4_printk(KERN_INFO, ha,
  5018. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  5019. cmd->device->channel, cmd->device->id, cmd->device->lun);
  5020. DEBUG2(printk(KERN_INFO
  5021. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  5022. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  5023. cmd, jiffies, cmd->request->timeout / HZ,
  5024. ha->dpc_flags, cmd->result, cmd->allowed));
  5025. /* FIXME: wait for hba to go online */
  5026. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  5027. if (stat != QLA_SUCCESS) {
  5028. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  5029. goto eh_dev_reset_done;
  5030. }
  5031. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  5032. cmd->device)) {
  5033. ql4_printk(KERN_INFO, ha,
  5034. "DEVICE RESET FAILED - waiting for "
  5035. "commands.\n");
  5036. goto eh_dev_reset_done;
  5037. }
  5038. /* Send marker. */
  5039. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  5040. MM_LUN_RESET) != QLA_SUCCESS)
  5041. goto eh_dev_reset_done;
  5042. ql4_printk(KERN_INFO, ha,
  5043. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  5044. ha->host_no, cmd->device->channel, cmd->device->id,
  5045. cmd->device->lun);
  5046. ret = SUCCESS;
  5047. eh_dev_reset_done:
  5048. return ret;
  5049. }
  5050. /**
  5051. * qla4xxx_eh_target_reset - callback for target reset.
  5052. * @cmd: Pointer to Linux's SCSI command structure
  5053. *
  5054. * This routine is called by the Linux OS to reset the target.
  5055. **/
  5056. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  5057. {
  5058. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  5059. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  5060. int stat, ret;
  5061. if (!ddb_entry)
  5062. return FAILED;
  5063. ret = iscsi_block_scsi_eh(cmd);
  5064. if (ret)
  5065. return ret;
  5066. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5067. "WARM TARGET RESET ISSUED.\n");
  5068. DEBUG2(printk(KERN_INFO
  5069. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  5070. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  5071. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  5072. ha->dpc_flags, cmd->result, cmd->allowed));
  5073. stat = qla4xxx_reset_target(ha, ddb_entry);
  5074. if (stat != QLA_SUCCESS) {
  5075. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5076. "WARM TARGET RESET FAILED.\n");
  5077. return FAILED;
  5078. }
  5079. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  5080. NULL)) {
  5081. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5082. "WARM TARGET DEVICE RESET FAILED - "
  5083. "waiting for commands.\n");
  5084. return FAILED;
  5085. }
  5086. /* Send marker. */
  5087. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  5088. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  5089. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5090. "WARM TARGET DEVICE RESET FAILED - "
  5091. "marker iocb failed.\n");
  5092. return FAILED;
  5093. }
  5094. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5095. "WARM TARGET RESET SUCCEEDED.\n");
  5096. return SUCCESS;
  5097. }
  5098. /**
  5099. * qla4xxx_is_eh_active - check if error handler is running
  5100. * @shost: Pointer to SCSI Host struct
  5101. *
  5102. * This routine finds that if reset host is called in EH
  5103. * scenario or from some application like sg_reset
  5104. **/
  5105. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  5106. {
  5107. if (shost->shost_state == SHOST_RECOVERY)
  5108. return 1;
  5109. return 0;
  5110. }
  5111. /**
  5112. * qla4xxx_eh_host_reset - kernel callback
  5113. * @cmd: Pointer to Linux's SCSI command structure
  5114. *
  5115. * This routine is invoked by the Linux kernel to perform fatal error
  5116. * recovery on the specified adapter.
  5117. **/
  5118. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  5119. {
  5120. int return_status = FAILED;
  5121. struct scsi_qla_host *ha;
  5122. ha = to_qla_host(cmd->device->host);
  5123. if (is_qla8032(ha) && ql4xdontresethba)
  5124. qla4_83xx_set_idc_dontreset(ha);
  5125. /*
  5126. * For ISP8324, if IDC_CTRL DONTRESET_BIT0 is set by other
  5127. * protocol drivers, we should not set device_state to
  5128. * NEED_RESET
  5129. */
  5130. if (ql4xdontresethba ||
  5131. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  5132. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  5133. ha->host_no, __func__));
  5134. /* Clear outstanding srb in queues */
  5135. if (qla4xxx_is_eh_active(cmd->device->host))
  5136. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  5137. return FAILED;
  5138. }
  5139. ql4_printk(KERN_INFO, ha,
  5140. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  5141. cmd->device->channel, cmd->device->id, cmd->device->lun);
  5142. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  5143. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  5144. "DEAD.\n", ha->host_no, cmd->device->channel,
  5145. __func__));
  5146. return FAILED;
  5147. }
  5148. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  5149. if (is_qla80XX(ha))
  5150. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  5151. else
  5152. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  5153. }
  5154. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  5155. return_status = SUCCESS;
  5156. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  5157. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  5158. return return_status;
  5159. }
  5160. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  5161. {
  5162. uint32_t mbox_cmd[MBOX_REG_COUNT];
  5163. uint32_t mbox_sts[MBOX_REG_COUNT];
  5164. struct addr_ctrl_blk_def *acb = NULL;
  5165. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  5166. int rval = QLA_SUCCESS;
  5167. dma_addr_t acb_dma;
  5168. acb = dma_alloc_coherent(&ha->pdev->dev,
  5169. sizeof(struct addr_ctrl_blk_def),
  5170. &acb_dma, GFP_KERNEL);
  5171. if (!acb) {
  5172. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  5173. __func__);
  5174. rval = -ENOMEM;
  5175. goto exit_port_reset;
  5176. }
  5177. memset(acb, 0, acb_len);
  5178. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  5179. if (rval != QLA_SUCCESS) {
  5180. rval = -EIO;
  5181. goto exit_free_acb;
  5182. }
  5183. rval = qla4xxx_disable_acb(ha);
  5184. if (rval != QLA_SUCCESS) {
  5185. rval = -EIO;
  5186. goto exit_free_acb;
  5187. }
  5188. wait_for_completion_timeout(&ha->disable_acb_comp,
  5189. DISABLE_ACB_TOV * HZ);
  5190. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  5191. if (rval != QLA_SUCCESS) {
  5192. rval = -EIO;
  5193. goto exit_free_acb;
  5194. }
  5195. exit_free_acb:
  5196. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  5197. acb, acb_dma);
  5198. exit_port_reset:
  5199. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  5200. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  5201. return rval;
  5202. }
  5203. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  5204. {
  5205. struct scsi_qla_host *ha = to_qla_host(shost);
  5206. int rval = QLA_SUCCESS;
  5207. if (ql4xdontresethba) {
  5208. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  5209. __func__));
  5210. rval = -EPERM;
  5211. goto exit_host_reset;
  5212. }
  5213. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  5214. goto recover_adapter;
  5215. switch (reset_type) {
  5216. case SCSI_ADAPTER_RESET:
  5217. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  5218. break;
  5219. case SCSI_FIRMWARE_RESET:
  5220. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  5221. if (is_qla80XX(ha))
  5222. /* set firmware context reset */
  5223. set_bit(DPC_RESET_HA_FW_CONTEXT,
  5224. &ha->dpc_flags);
  5225. else {
  5226. rval = qla4xxx_context_reset(ha);
  5227. goto exit_host_reset;
  5228. }
  5229. }
  5230. break;
  5231. }
  5232. recover_adapter:
  5233. rval = qla4xxx_recover_adapter(ha);
  5234. if (rval != QLA_SUCCESS) {
  5235. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  5236. __func__));
  5237. rval = -EIO;
  5238. }
  5239. exit_host_reset:
  5240. return rval;
  5241. }
  5242. /* PCI AER driver recovers from all correctable errors w/o
  5243. * driver intervention. For uncorrectable errors PCI AER
  5244. * driver calls the following device driver's callbacks
  5245. *
  5246. * - Fatal Errors - link_reset
  5247. * - Non-Fatal Errors - driver's pci_error_detected() which
  5248. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  5249. *
  5250. * PCI AER driver calls
  5251. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  5252. * returns RECOVERED or NEED_RESET if fw_hung
  5253. * NEED_RESET - driver's slot_reset()
  5254. * DISCONNECT - device is dead & cannot recover
  5255. * RECOVERED - driver's pci_resume()
  5256. */
  5257. static pci_ers_result_t
  5258. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  5259. {
  5260. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5261. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  5262. ha->host_no, __func__, state);
  5263. if (!is_aer_supported(ha))
  5264. return PCI_ERS_RESULT_NONE;
  5265. switch (state) {
  5266. case pci_channel_io_normal:
  5267. clear_bit(AF_EEH_BUSY, &ha->flags);
  5268. return PCI_ERS_RESULT_CAN_RECOVER;
  5269. case pci_channel_io_frozen:
  5270. set_bit(AF_EEH_BUSY, &ha->flags);
  5271. qla4xxx_mailbox_premature_completion(ha);
  5272. qla4xxx_free_irqs(ha);
  5273. pci_disable_device(pdev);
  5274. /* Return back all IOs */
  5275. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  5276. return PCI_ERS_RESULT_NEED_RESET;
  5277. case pci_channel_io_perm_failure:
  5278. set_bit(AF_EEH_BUSY, &ha->flags);
  5279. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  5280. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  5281. return PCI_ERS_RESULT_DISCONNECT;
  5282. }
  5283. return PCI_ERS_RESULT_NEED_RESET;
  5284. }
  5285. /**
  5286. * qla4xxx_pci_mmio_enabled() gets called if
  5287. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  5288. * and read/write to the device still works.
  5289. **/
  5290. static pci_ers_result_t
  5291. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  5292. {
  5293. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5294. if (!is_aer_supported(ha))
  5295. return PCI_ERS_RESULT_NONE;
  5296. return PCI_ERS_RESULT_RECOVERED;
  5297. }
  5298. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  5299. {
  5300. uint32_t rval = QLA_ERROR;
  5301. int fn;
  5302. struct pci_dev *other_pdev = NULL;
  5303. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  5304. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  5305. if (test_bit(AF_ONLINE, &ha->flags)) {
  5306. clear_bit(AF_ONLINE, &ha->flags);
  5307. clear_bit(AF_LINK_UP, &ha->flags);
  5308. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  5309. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  5310. }
  5311. fn = PCI_FUNC(ha->pdev->devfn);
  5312. while (fn > 0) {
  5313. fn--;
  5314. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  5315. "func %x\n", ha->host_no, __func__, fn);
  5316. /* Get the pci device given the domain, bus,
  5317. * slot/function number */
  5318. other_pdev =
  5319. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  5320. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  5321. fn));
  5322. if (!other_pdev)
  5323. continue;
  5324. if (atomic_read(&other_pdev->enable_cnt)) {
  5325. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  5326. "func in enabled state%x\n", ha->host_no,
  5327. __func__, fn);
  5328. pci_dev_put(other_pdev);
  5329. break;
  5330. }
  5331. pci_dev_put(other_pdev);
  5332. }
  5333. /* The first function on the card, the reset owner will
  5334. * start & initialize the firmware. The other functions
  5335. * on the card will reset the firmware context
  5336. */
  5337. if (!fn) {
  5338. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  5339. "0x%x is the owner\n", ha->host_no, __func__,
  5340. ha->pdev->devfn);
  5341. ha->isp_ops->idc_lock(ha);
  5342. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5343. QLA8XXX_DEV_COLD);
  5344. ha->isp_ops->idc_unlock(ha);
  5345. rval = qla4_8xxx_update_idc_reg(ha);
  5346. if (rval == QLA_ERROR) {
  5347. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  5348. ha->host_no, __func__);
  5349. ha->isp_ops->idc_lock(ha);
  5350. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5351. QLA8XXX_DEV_FAILED);
  5352. ha->isp_ops->idc_unlock(ha);
  5353. goto exit_error_recovery;
  5354. }
  5355. clear_bit(AF_FW_RECOVERY, &ha->flags);
  5356. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  5357. if (rval != QLA_SUCCESS) {
  5358. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  5359. "FAILED\n", ha->host_no, __func__);
  5360. ha->isp_ops->idc_lock(ha);
  5361. qla4_8xxx_clear_drv_active(ha);
  5362. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5363. QLA8XXX_DEV_FAILED);
  5364. ha->isp_ops->idc_unlock(ha);
  5365. } else {
  5366. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  5367. "READY\n", ha->host_no, __func__);
  5368. ha->isp_ops->idc_lock(ha);
  5369. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5370. QLA8XXX_DEV_READY);
  5371. /* Clear driver state register */
  5372. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  5373. qla4_8xxx_set_drv_active(ha);
  5374. ha->isp_ops->idc_unlock(ha);
  5375. ha->isp_ops->enable_intrs(ha);
  5376. }
  5377. } else {
  5378. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  5379. "the reset owner\n", ha->host_no, __func__,
  5380. ha->pdev->devfn);
  5381. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  5382. QLA8XXX_DEV_READY)) {
  5383. clear_bit(AF_FW_RECOVERY, &ha->flags);
  5384. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  5385. if (rval == QLA_SUCCESS)
  5386. ha->isp_ops->enable_intrs(ha);
  5387. ha->isp_ops->idc_lock(ha);
  5388. qla4_8xxx_set_drv_active(ha);
  5389. ha->isp_ops->idc_unlock(ha);
  5390. }
  5391. }
  5392. exit_error_recovery:
  5393. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  5394. return rval;
  5395. }
  5396. static pci_ers_result_t
  5397. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  5398. {
  5399. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  5400. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5401. int rc;
  5402. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  5403. ha->host_no, __func__);
  5404. if (!is_aer_supported(ha))
  5405. return PCI_ERS_RESULT_NONE;
  5406. /* Restore the saved state of PCIe device -
  5407. * BAR registers, PCI Config space, PCIX, MSI,
  5408. * IOV states
  5409. */
  5410. pci_restore_state(pdev);
  5411. /* pci_restore_state() clears the saved_state flag of the device
  5412. * save restored state which resets saved_state flag
  5413. */
  5414. pci_save_state(pdev);
  5415. /* Initialize device or resume if in suspended state */
  5416. rc = pci_enable_device(pdev);
  5417. if (rc) {
  5418. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  5419. "device after reset\n", ha->host_no, __func__);
  5420. goto exit_slot_reset;
  5421. }
  5422. ha->isp_ops->disable_intrs(ha);
  5423. if (is_qla80XX(ha)) {
  5424. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  5425. ret = PCI_ERS_RESULT_RECOVERED;
  5426. goto exit_slot_reset;
  5427. } else
  5428. goto exit_slot_reset;
  5429. }
  5430. exit_slot_reset:
  5431. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  5432. "device after reset\n", ha->host_no, __func__, ret);
  5433. return ret;
  5434. }
  5435. static void
  5436. qla4xxx_pci_resume(struct pci_dev *pdev)
  5437. {
  5438. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5439. int ret;
  5440. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  5441. ha->host_no, __func__);
  5442. ret = qla4xxx_wait_for_hba_online(ha);
  5443. if (ret != QLA_SUCCESS) {
  5444. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  5445. "resume I/O from slot/link_reset\n", ha->host_no,
  5446. __func__);
  5447. }
  5448. pci_cleanup_aer_uncorrect_error_status(pdev);
  5449. clear_bit(AF_EEH_BUSY, &ha->flags);
  5450. }
  5451. static const struct pci_error_handlers qla4xxx_err_handler = {
  5452. .error_detected = qla4xxx_pci_error_detected,
  5453. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  5454. .slot_reset = qla4xxx_pci_slot_reset,
  5455. .resume = qla4xxx_pci_resume,
  5456. };
  5457. static struct pci_device_id qla4xxx_pci_tbl[] = {
  5458. {
  5459. .vendor = PCI_VENDOR_ID_QLOGIC,
  5460. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  5461. .subvendor = PCI_ANY_ID,
  5462. .subdevice = PCI_ANY_ID,
  5463. },
  5464. {
  5465. .vendor = PCI_VENDOR_ID_QLOGIC,
  5466. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  5467. .subvendor = PCI_ANY_ID,
  5468. .subdevice = PCI_ANY_ID,
  5469. },
  5470. {
  5471. .vendor = PCI_VENDOR_ID_QLOGIC,
  5472. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  5473. .subvendor = PCI_ANY_ID,
  5474. .subdevice = PCI_ANY_ID,
  5475. },
  5476. {
  5477. .vendor = PCI_VENDOR_ID_QLOGIC,
  5478. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  5479. .subvendor = PCI_ANY_ID,
  5480. .subdevice = PCI_ANY_ID,
  5481. },
  5482. {
  5483. .vendor = PCI_VENDOR_ID_QLOGIC,
  5484. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  5485. .subvendor = PCI_ANY_ID,
  5486. .subdevice = PCI_ANY_ID,
  5487. },
  5488. {0, 0},
  5489. };
  5490. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  5491. static struct pci_driver qla4xxx_pci_driver = {
  5492. .name = DRIVER_NAME,
  5493. .id_table = qla4xxx_pci_tbl,
  5494. .probe = qla4xxx_probe_adapter,
  5495. .remove = qla4xxx_remove_adapter,
  5496. .err_handler = &qla4xxx_err_handler,
  5497. };
  5498. static int __init qla4xxx_module_init(void)
  5499. {
  5500. int ret;
  5501. /* Allocate cache for SRBs. */
  5502. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  5503. SLAB_HWCACHE_ALIGN, NULL);
  5504. if (srb_cachep == NULL) {
  5505. printk(KERN_ERR
  5506. "%s: Unable to allocate SRB cache..."
  5507. "Failing load!\n", DRIVER_NAME);
  5508. ret = -ENOMEM;
  5509. goto no_srp_cache;
  5510. }
  5511. /* Derive version string. */
  5512. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  5513. if (ql4xextended_error_logging)
  5514. strcat(qla4xxx_version_str, "-debug");
  5515. qla4xxx_scsi_transport =
  5516. iscsi_register_transport(&qla4xxx_iscsi_transport);
  5517. if (!qla4xxx_scsi_transport){
  5518. ret = -ENODEV;
  5519. goto release_srb_cache;
  5520. }
  5521. ret = pci_register_driver(&qla4xxx_pci_driver);
  5522. if (ret)
  5523. goto unregister_transport;
  5524. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  5525. return 0;
  5526. unregister_transport:
  5527. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  5528. release_srb_cache:
  5529. kmem_cache_destroy(srb_cachep);
  5530. no_srp_cache:
  5531. return ret;
  5532. }
  5533. static void __exit qla4xxx_module_exit(void)
  5534. {
  5535. pci_unregister_driver(&qla4xxx_pci_driver);
  5536. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  5537. kmem_cache_destroy(srb_cachep);
  5538. }
  5539. module_init(qla4xxx_module_init);
  5540. module_exit(qla4xxx_module_exit);
  5541. MODULE_AUTHOR("QLogic Corporation");
  5542. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  5543. MODULE_LICENSE("GPL");
  5544. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);