ql4_os.c 171 KB

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