ql4_os.c 158 KB

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