mpt2sas_base.c 131 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628
  1. /*
  2. * This is the Fusion MPT base driver providing common API layer interface
  3. * for access to MPT (Message Passing Technology) firmware.
  4. *
  5. * This code is based on drivers/scsi/mpt2sas/mpt2_base.c
  6. * Copyright (C) 2007-2010 LSI Corporation
  7. * (mailto:DL-MPTFusionLinux@lsi.com)
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * NO WARRANTY
  20. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. * solely responsible for determining the appropriateness of using and
  25. * distributing the Program and assumes all risks associated with its
  26. * exercise of rights under this Agreement, including but not limited to
  27. * the risks and costs of program errors, damage to or loss of data,
  28. * programs or equipment, and unavailability or interruption of operations.
  29. * DISCLAIMER OF LIABILITY
  30. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  40. * USA.
  41. */
  42. #include <linux/kernel.h>
  43. #include <linux/module.h>
  44. #include <linux/errno.h>
  45. #include <linux/init.h>
  46. #include <linux/slab.h>
  47. #include <linux/types.h>
  48. #include <linux/pci.h>
  49. #include <linux/kdev_t.h>
  50. #include <linux/blkdev.h>
  51. #include <linux/delay.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/dma-mapping.h>
  54. #include <linux/sort.h>
  55. #include <linux/io.h>
  56. #include <linux/time.h>
  57. #include <linux/kthread.h>
  58. #include <linux/aer.h>
  59. #include "mpt2sas_base.h"
  60. static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS];
  61. #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
  62. #define MAX_HBA_QUEUE_DEPTH 30000
  63. #define MAX_CHAIN_DEPTH 100000
  64. static int max_queue_depth = -1;
  65. module_param(max_queue_depth, int, 0);
  66. MODULE_PARM_DESC(max_queue_depth, " max controller queue depth ");
  67. static int max_sgl_entries = -1;
  68. module_param(max_sgl_entries, int, 0);
  69. MODULE_PARM_DESC(max_sgl_entries, " max sg entries ");
  70. static int msix_disable = -1;
  71. module_param(msix_disable, int, 0);
  72. MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)");
  73. static int missing_delay[2] = {-1, -1};
  74. module_param_array(missing_delay, int, NULL, 0);
  75. MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
  76. static int mpt2sas_fwfault_debug;
  77. MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
  78. "and halt firmware - (default=0)");
  79. static int disable_discovery = -1;
  80. module_param(disable_discovery, int, 0);
  81. MODULE_PARM_DESC(disable_discovery, " disable discovery ");
  82. /**
  83. * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
  84. *
  85. */
  86. static int
  87. _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
  88. {
  89. int ret = param_set_int(val, kp);
  90. struct MPT2SAS_ADAPTER *ioc;
  91. if (ret)
  92. return ret;
  93. printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
  94. list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
  95. ioc->fwfault_debug = mpt2sas_fwfault_debug;
  96. return 0;
  97. }
  98. module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug,
  99. param_get_int, &mpt2sas_fwfault_debug, 0644);
  100. /**
  101. * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc
  102. * @arg: input argument, used to derive ioc
  103. *
  104. * Return 0 if controller is removed from pci subsystem.
  105. * Return -1 for other case.
  106. */
  107. static int mpt2sas_remove_dead_ioc_func(void *arg)
  108. {
  109. struct MPT2SAS_ADAPTER *ioc = (struct MPT2SAS_ADAPTER *)arg;
  110. struct pci_dev *pdev;
  111. if ((ioc == NULL))
  112. return -1;
  113. pdev = ioc->pdev;
  114. if ((pdev == NULL))
  115. return -1;
  116. pci_stop_and_remove_bus_device(pdev);
  117. return 0;
  118. }
  119. /**
  120. * _base_fault_reset_work - workq handling ioc fault conditions
  121. * @work: input argument, used to derive ioc
  122. * Context: sleep.
  123. *
  124. * Return nothing.
  125. */
  126. static void
  127. _base_fault_reset_work(struct work_struct *work)
  128. {
  129. struct MPT2SAS_ADAPTER *ioc =
  130. container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
  131. unsigned long flags;
  132. u32 doorbell;
  133. int rc;
  134. struct task_struct *p;
  135. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  136. if (ioc->shost_recovery)
  137. goto rearm_timer;
  138. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  139. doorbell = mpt2sas_base_get_iocstate(ioc, 0);
  140. if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) {
  141. printk(MPT2SAS_INFO_FMT "%s : SAS host is non-operational !!!!\n",
  142. ioc->name, __func__);
  143. /*
  144. * Call _scsih_flush_pending_cmds callback so that we flush all
  145. * pending commands back to OS. This call is required to aovid
  146. * deadlock at block layer. Dead IOC will fail to do diag reset,
  147. * and this call is safe since dead ioc will never return any
  148. * command back from HW.
  149. */
  150. ioc->schedule_dead_ioc_flush_running_cmds(ioc);
  151. /*
  152. * Set remove_host flag early since kernel thread will
  153. * take some time to execute.
  154. */
  155. ioc->remove_host = 1;
  156. /*Remove the Dead Host */
  157. p = kthread_run(mpt2sas_remove_dead_ioc_func, ioc,
  158. "mpt2sas_dead_ioc_%d", ioc->id);
  159. if (IS_ERR(p)) {
  160. printk(MPT2SAS_ERR_FMT
  161. "%s: Running mpt2sas_dead_ioc thread failed !!!!\n",
  162. ioc->name, __func__);
  163. } else {
  164. printk(MPT2SAS_ERR_FMT
  165. "%s: Running mpt2sas_dead_ioc thread success !!!!\n",
  166. ioc->name, __func__);
  167. }
  168. return; /* don't rearm timer */
  169. }
  170. if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  171. rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  172. FORCE_BIG_HAMMER);
  173. printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
  174. __func__, (rc == 0) ? "success" : "failed");
  175. doorbell = mpt2sas_base_get_iocstate(ioc, 0);
  176. if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
  177. mpt2sas_base_fault_info(ioc, doorbell &
  178. MPI2_DOORBELL_DATA_MASK);
  179. }
  180. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  181. rearm_timer:
  182. if (ioc->fault_reset_work_q)
  183. queue_delayed_work(ioc->fault_reset_work_q,
  184. &ioc->fault_reset_work,
  185. msecs_to_jiffies(FAULT_POLLING_INTERVAL));
  186. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  187. }
  188. /**
  189. * mpt2sas_base_start_watchdog - start the fault_reset_work_q
  190. * @ioc: per adapter object
  191. * Context: sleep.
  192. *
  193. * Return nothing.
  194. */
  195. void
  196. mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
  197. {
  198. unsigned long flags;
  199. if (ioc->fault_reset_work_q)
  200. return;
  201. /* initialize fault polling */
  202. INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
  203. snprintf(ioc->fault_reset_work_q_name,
  204. sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
  205. ioc->fault_reset_work_q =
  206. create_singlethread_workqueue(ioc->fault_reset_work_q_name);
  207. if (!ioc->fault_reset_work_q) {
  208. printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
  209. ioc->name, __func__, __LINE__);
  210. return;
  211. }
  212. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  213. if (ioc->fault_reset_work_q)
  214. queue_delayed_work(ioc->fault_reset_work_q,
  215. &ioc->fault_reset_work,
  216. msecs_to_jiffies(FAULT_POLLING_INTERVAL));
  217. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  218. }
  219. /**
  220. * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
  221. * @ioc: per adapter object
  222. * Context: sleep.
  223. *
  224. * Return nothing.
  225. */
  226. void
  227. mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
  228. {
  229. unsigned long flags;
  230. struct workqueue_struct *wq;
  231. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  232. wq = ioc->fault_reset_work_q;
  233. ioc->fault_reset_work_q = NULL;
  234. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  235. if (wq) {
  236. if (!cancel_delayed_work(&ioc->fault_reset_work))
  237. flush_workqueue(wq);
  238. destroy_workqueue(wq);
  239. }
  240. }
  241. /**
  242. * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
  243. * @ioc: per adapter object
  244. * @fault_code: fault code
  245. *
  246. * Return nothing.
  247. */
  248. void
  249. mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
  250. {
  251. printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
  252. ioc->name, fault_code);
  253. }
  254. /**
  255. * mpt2sas_halt_firmware - halt's mpt controller firmware
  256. * @ioc: per adapter object
  257. *
  258. * For debugging timeout related issues. Writing 0xCOFFEE00
  259. * to the doorbell register will halt controller firmware. With
  260. * the purpose to stop both driver and firmware, the enduser can
  261. * obtain a ring buffer from controller UART.
  262. */
  263. void
  264. mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc)
  265. {
  266. u32 doorbell;
  267. if (!ioc->fwfault_debug)
  268. return;
  269. dump_stack();
  270. doorbell = readl(&ioc->chip->Doorbell);
  271. if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
  272. mpt2sas_base_fault_info(ioc , doorbell);
  273. else {
  274. writel(0xC0FFEE00, &ioc->chip->Doorbell);
  275. printk(MPT2SAS_ERR_FMT "Firmware is halted due to command "
  276. "timeout\n", ioc->name);
  277. }
  278. panic("panic in %s\n", __func__);
  279. }
  280. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  281. /**
  282. * _base_sas_ioc_info - verbose translation of the ioc status
  283. * @ioc: per adapter object
  284. * @mpi_reply: reply mf payload returned from firmware
  285. * @request_hdr: request mf
  286. *
  287. * Return nothing.
  288. */
  289. static void
  290. _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
  291. MPI2RequestHeader_t *request_hdr)
  292. {
  293. u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
  294. MPI2_IOCSTATUS_MASK;
  295. char *desc = NULL;
  296. u16 frame_sz;
  297. char *func_str = NULL;
  298. /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
  299. if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
  300. request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
  301. request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
  302. return;
  303. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  304. return;
  305. switch (ioc_status) {
  306. /****************************************************************************
  307. * Common IOCStatus values for all replies
  308. ****************************************************************************/
  309. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  310. desc = "invalid function";
  311. break;
  312. case MPI2_IOCSTATUS_BUSY:
  313. desc = "busy";
  314. break;
  315. case MPI2_IOCSTATUS_INVALID_SGL:
  316. desc = "invalid sgl";
  317. break;
  318. case MPI2_IOCSTATUS_INTERNAL_ERROR:
  319. desc = "internal error";
  320. break;
  321. case MPI2_IOCSTATUS_INVALID_VPID:
  322. desc = "invalid vpid";
  323. break;
  324. case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
  325. desc = "insufficient resources";
  326. break;
  327. case MPI2_IOCSTATUS_INVALID_FIELD:
  328. desc = "invalid field";
  329. break;
  330. case MPI2_IOCSTATUS_INVALID_STATE:
  331. desc = "invalid state";
  332. break;
  333. case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
  334. desc = "op state not supported";
  335. break;
  336. /****************************************************************************
  337. * Config IOCStatus values
  338. ****************************************************************************/
  339. case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
  340. desc = "config invalid action";
  341. break;
  342. case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
  343. desc = "config invalid type";
  344. break;
  345. case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
  346. desc = "config invalid page";
  347. break;
  348. case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
  349. desc = "config invalid data";
  350. break;
  351. case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
  352. desc = "config no defaults";
  353. break;
  354. case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
  355. desc = "config cant commit";
  356. break;
  357. /****************************************************************************
  358. * SCSI IO Reply
  359. ****************************************************************************/
  360. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  361. case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
  362. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  363. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  364. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  365. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  366. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  367. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  368. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  369. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  370. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  371. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  372. break;
  373. /****************************************************************************
  374. * For use by SCSI Initiator and SCSI Target end-to-end data protection
  375. ****************************************************************************/
  376. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  377. desc = "eedp guard error";
  378. break;
  379. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  380. desc = "eedp ref tag error";
  381. break;
  382. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  383. desc = "eedp app tag error";
  384. break;
  385. /****************************************************************************
  386. * SCSI Target values
  387. ****************************************************************************/
  388. case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
  389. desc = "target invalid io index";
  390. break;
  391. case MPI2_IOCSTATUS_TARGET_ABORTED:
  392. desc = "target aborted";
  393. break;
  394. case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
  395. desc = "target no conn retryable";
  396. break;
  397. case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
  398. desc = "target no connection";
  399. break;
  400. case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
  401. desc = "target xfer count mismatch";
  402. break;
  403. case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
  404. desc = "target data offset error";
  405. break;
  406. case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
  407. desc = "target too much write data";
  408. break;
  409. case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
  410. desc = "target iu too short";
  411. break;
  412. case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
  413. desc = "target ack nak timeout";
  414. break;
  415. case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
  416. desc = "target nak received";
  417. break;
  418. /****************************************************************************
  419. * Serial Attached SCSI values
  420. ****************************************************************************/
  421. case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
  422. desc = "smp request failed";
  423. break;
  424. case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
  425. desc = "smp data overrun";
  426. break;
  427. /****************************************************************************
  428. * Diagnostic Buffer Post / Diagnostic Release values
  429. ****************************************************************************/
  430. case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
  431. desc = "diagnostic released";
  432. break;
  433. default:
  434. break;
  435. }
  436. if (!desc)
  437. return;
  438. switch (request_hdr->Function) {
  439. case MPI2_FUNCTION_CONFIG:
  440. frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
  441. func_str = "config_page";
  442. break;
  443. case MPI2_FUNCTION_SCSI_TASK_MGMT:
  444. frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
  445. func_str = "task_mgmt";
  446. break;
  447. case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
  448. frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
  449. func_str = "sas_iounit_ctl";
  450. break;
  451. case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
  452. frame_sz = sizeof(Mpi2SepRequest_t);
  453. func_str = "enclosure";
  454. break;
  455. case MPI2_FUNCTION_IOC_INIT:
  456. frame_sz = sizeof(Mpi2IOCInitRequest_t);
  457. func_str = "ioc_init";
  458. break;
  459. case MPI2_FUNCTION_PORT_ENABLE:
  460. frame_sz = sizeof(Mpi2PortEnableRequest_t);
  461. func_str = "port_enable";
  462. break;
  463. case MPI2_FUNCTION_SMP_PASSTHROUGH:
  464. frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
  465. func_str = "smp_passthru";
  466. break;
  467. default:
  468. frame_sz = 32;
  469. func_str = "unknown";
  470. break;
  471. }
  472. printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
  473. " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
  474. _debug_dump_mf(request_hdr, frame_sz/4);
  475. }
  476. /**
  477. * _base_display_event_data - verbose translation of firmware asyn events
  478. * @ioc: per adapter object
  479. * @mpi_reply: reply mf payload returned from firmware
  480. *
  481. * Return nothing.
  482. */
  483. static void
  484. _base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
  485. Mpi2EventNotificationReply_t *mpi_reply)
  486. {
  487. char *desc = NULL;
  488. u16 event;
  489. if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
  490. return;
  491. event = le16_to_cpu(mpi_reply->Event);
  492. switch (event) {
  493. case MPI2_EVENT_LOG_DATA:
  494. desc = "Log Data";
  495. break;
  496. case MPI2_EVENT_STATE_CHANGE:
  497. desc = "Status Change";
  498. break;
  499. case MPI2_EVENT_HARD_RESET_RECEIVED:
  500. desc = "Hard Reset Received";
  501. break;
  502. case MPI2_EVENT_EVENT_CHANGE:
  503. desc = "Event Change";
  504. break;
  505. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  506. desc = "Device Status Change";
  507. break;
  508. case MPI2_EVENT_IR_OPERATION_STATUS:
  509. if (!ioc->hide_ir_msg)
  510. desc = "IR Operation Status";
  511. break;
  512. case MPI2_EVENT_SAS_DISCOVERY:
  513. {
  514. Mpi2EventDataSasDiscovery_t *event_data =
  515. (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData;
  516. printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name,
  517. (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
  518. "start" : "stop");
  519. if (event_data->DiscoveryStatus)
  520. printk("discovery_status(0x%08x)",
  521. le32_to_cpu(event_data->DiscoveryStatus));
  522. printk("\n");
  523. return;
  524. }
  525. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  526. desc = "SAS Broadcast Primitive";
  527. break;
  528. case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
  529. desc = "SAS Init Device Status Change";
  530. break;
  531. case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
  532. desc = "SAS Init Table Overflow";
  533. break;
  534. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  535. desc = "SAS Topology Change List";
  536. break;
  537. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  538. desc = "SAS Enclosure Device Status Change";
  539. break;
  540. case MPI2_EVENT_IR_VOLUME:
  541. if (!ioc->hide_ir_msg)
  542. desc = "IR Volume";
  543. break;
  544. case MPI2_EVENT_IR_PHYSICAL_DISK:
  545. if (!ioc->hide_ir_msg)
  546. desc = "IR Physical Disk";
  547. break;
  548. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  549. if (!ioc->hide_ir_msg)
  550. desc = "IR Configuration Change List";
  551. break;
  552. case MPI2_EVENT_LOG_ENTRY_ADDED:
  553. if (!ioc->hide_ir_msg)
  554. desc = "Log Entry Added";
  555. break;
  556. }
  557. if (!desc)
  558. return;
  559. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
  560. }
  561. #endif
  562. /**
  563. * _base_sas_log_info - verbose translation of firmware log info
  564. * @ioc: per adapter object
  565. * @log_info: log info
  566. *
  567. * Return nothing.
  568. */
  569. static void
  570. _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
  571. {
  572. union loginfo_type {
  573. u32 loginfo;
  574. struct {
  575. u32 subcode:16;
  576. u32 code:8;
  577. u32 originator:4;
  578. u32 bus_type:4;
  579. } dw;
  580. };
  581. union loginfo_type sas_loginfo;
  582. char *originator_str = NULL;
  583. sas_loginfo.loginfo = log_info;
  584. if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
  585. return;
  586. /* each nexus loss loginfo */
  587. if (log_info == 0x31170000)
  588. return;
  589. /* eat the loginfos associated with task aborts */
  590. if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info ==
  591. 0x31140000 || log_info == 0x31130000))
  592. return;
  593. switch (sas_loginfo.dw.originator) {
  594. case 0:
  595. originator_str = "IOP";
  596. break;
  597. case 1:
  598. originator_str = "PL";
  599. break;
  600. case 2:
  601. if (!ioc->hide_ir_msg)
  602. originator_str = "IR";
  603. else
  604. originator_str = "WarpDrive";
  605. break;
  606. }
  607. printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
  608. "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
  609. originator_str, sas_loginfo.dw.code,
  610. sas_loginfo.dw.subcode);
  611. }
  612. /**
  613. * _base_display_reply_info -
  614. * @ioc: per adapter object
  615. * @smid: system request message index
  616. * @msix_index: MSIX table index supplied by the OS
  617. * @reply: reply message frame(lower 32bit addr)
  618. *
  619. * Return nothing.
  620. */
  621. static void
  622. _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  623. u32 reply)
  624. {
  625. MPI2DefaultReply_t *mpi_reply;
  626. u16 ioc_status;
  627. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  628. if (unlikely(!mpi_reply)) {
  629. printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
  630. ioc->name, __FILE__, __LINE__, __func__);
  631. return;
  632. }
  633. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  634. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  635. if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
  636. (ioc->logging_level & MPT_DEBUG_REPLY)) {
  637. _base_sas_ioc_info(ioc , mpi_reply,
  638. mpt2sas_base_get_msg_frame(ioc, smid));
  639. }
  640. #endif
  641. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  642. _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
  643. }
  644. /**
  645. * mpt2sas_base_done - base internal command completion routine
  646. * @ioc: per adapter object
  647. * @smid: system request message index
  648. * @msix_index: MSIX table index supplied by the OS
  649. * @reply: reply message frame(lower 32bit addr)
  650. *
  651. * Return 1 meaning mf should be freed from _base_interrupt
  652. * 0 means the mf is freed from this function.
  653. */
  654. u8
  655. mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  656. u32 reply)
  657. {
  658. MPI2DefaultReply_t *mpi_reply;
  659. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  660. if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
  661. return 1;
  662. if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
  663. return 1;
  664. ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
  665. if (mpi_reply) {
  666. ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
  667. memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  668. }
  669. ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
  670. complete(&ioc->base_cmds.done);
  671. return 1;
  672. }
  673. /**
  674. * _base_async_event - main callback handler for firmware asyn events
  675. * @ioc: per adapter object
  676. * @msix_index: MSIX table index supplied by the OS
  677. * @reply: reply message frame(lower 32bit addr)
  678. *
  679. * Return 1 meaning mf should be freed from _base_interrupt
  680. * 0 means the mf is freed from this function.
  681. */
  682. static u8
  683. _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
  684. {
  685. Mpi2EventNotificationReply_t *mpi_reply;
  686. Mpi2EventAckRequest_t *ack_request;
  687. u16 smid;
  688. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  689. if (!mpi_reply)
  690. return 1;
  691. if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
  692. return 1;
  693. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  694. _base_display_event_data(ioc, mpi_reply);
  695. #endif
  696. if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
  697. goto out;
  698. smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
  699. if (!smid) {
  700. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  701. ioc->name, __func__);
  702. goto out;
  703. }
  704. ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
  705. memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
  706. ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
  707. ack_request->Event = mpi_reply->Event;
  708. ack_request->EventContext = mpi_reply->EventContext;
  709. ack_request->VF_ID = 0; /* TODO */
  710. ack_request->VP_ID = 0;
  711. mpt2sas_base_put_smid_default(ioc, smid);
  712. out:
  713. /* scsih callback handler */
  714. mpt2sas_scsih_event_callback(ioc, msix_index, reply);
  715. /* ctl callback handler */
  716. mpt2sas_ctl_event_callback(ioc, msix_index, reply);
  717. return 1;
  718. }
  719. /**
  720. * _base_get_cb_idx - obtain the callback index
  721. * @ioc: per adapter object
  722. * @smid: system request message index
  723. *
  724. * Return callback index.
  725. */
  726. static u8
  727. _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  728. {
  729. int i;
  730. u8 cb_idx;
  731. if (smid < ioc->hi_priority_smid) {
  732. i = smid - 1;
  733. cb_idx = ioc->scsi_lookup[i].cb_idx;
  734. } else if (smid < ioc->internal_smid) {
  735. i = smid - ioc->hi_priority_smid;
  736. cb_idx = ioc->hpr_lookup[i].cb_idx;
  737. } else if (smid <= ioc->hba_queue_depth) {
  738. i = smid - ioc->internal_smid;
  739. cb_idx = ioc->internal_lookup[i].cb_idx;
  740. } else
  741. cb_idx = 0xFF;
  742. return cb_idx;
  743. }
  744. /**
  745. * _base_mask_interrupts - disable interrupts
  746. * @ioc: per adapter object
  747. *
  748. * Disabling ResetIRQ, Reply and Doorbell Interrupts
  749. *
  750. * Return nothing.
  751. */
  752. static void
  753. _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
  754. {
  755. u32 him_register;
  756. ioc->mask_interrupts = 1;
  757. him_register = readl(&ioc->chip->HostInterruptMask);
  758. him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
  759. writel(him_register, &ioc->chip->HostInterruptMask);
  760. readl(&ioc->chip->HostInterruptMask);
  761. }
  762. /**
  763. * _base_unmask_interrupts - enable interrupts
  764. * @ioc: per adapter object
  765. *
  766. * Enabling only Reply Interrupts
  767. *
  768. * Return nothing.
  769. */
  770. static void
  771. _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
  772. {
  773. u32 him_register;
  774. him_register = readl(&ioc->chip->HostInterruptMask);
  775. him_register &= ~MPI2_HIM_RIM;
  776. writel(him_register, &ioc->chip->HostInterruptMask);
  777. ioc->mask_interrupts = 0;
  778. }
  779. union reply_descriptor {
  780. u64 word;
  781. struct {
  782. u32 low;
  783. u32 high;
  784. } u;
  785. };
  786. /**
  787. * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
  788. * @irq: irq number (not used)
  789. * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
  790. * @r: pt_regs pointer (not used)
  791. *
  792. * Return IRQ_HANDLE if processed, else IRQ_NONE.
  793. */
  794. static irqreturn_t
  795. _base_interrupt(int irq, void *bus_id)
  796. {
  797. struct adapter_reply_queue *reply_q = bus_id;
  798. union reply_descriptor rd;
  799. u32 completed_cmds;
  800. u8 request_desript_type;
  801. u16 smid;
  802. u8 cb_idx;
  803. u32 reply;
  804. u8 msix_index = reply_q->msix_index;
  805. struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
  806. Mpi2ReplyDescriptorsUnion_t *rpf;
  807. u8 rc;
  808. if (ioc->mask_interrupts)
  809. return IRQ_NONE;
  810. if (!atomic_add_unless(&reply_q->busy, 1, 1))
  811. return IRQ_NONE;
  812. rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
  813. request_desript_type = rpf->Default.ReplyFlags
  814. & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  815. if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
  816. atomic_dec(&reply_q->busy);
  817. return IRQ_NONE;
  818. }
  819. completed_cmds = 0;
  820. cb_idx = 0xFF;
  821. do {
  822. rd.word = le64_to_cpu(rpf->Words);
  823. if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
  824. goto out;
  825. reply = 0;
  826. smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
  827. if (request_desript_type ==
  828. MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
  829. reply = le32_to_cpu
  830. (rpf->AddressReply.ReplyFrameAddress);
  831. if (reply > ioc->reply_dma_max_address ||
  832. reply < ioc->reply_dma_min_address)
  833. reply = 0;
  834. } else if (request_desript_type ==
  835. MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
  836. goto next;
  837. else if (request_desript_type ==
  838. MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
  839. goto next;
  840. if (smid) {
  841. cb_idx = _base_get_cb_idx(ioc, smid);
  842. if ((likely(cb_idx < MPT_MAX_CALLBACKS))
  843. && (likely(mpt_callbacks[cb_idx] != NULL))) {
  844. rc = mpt_callbacks[cb_idx](ioc, smid,
  845. msix_index, reply);
  846. if (reply)
  847. _base_display_reply_info(ioc, smid,
  848. msix_index, reply);
  849. if (rc)
  850. mpt2sas_base_free_smid(ioc, smid);
  851. }
  852. }
  853. if (!smid)
  854. _base_async_event(ioc, msix_index, reply);
  855. /* reply free queue handling */
  856. if (reply) {
  857. ioc->reply_free_host_index =
  858. (ioc->reply_free_host_index ==
  859. (ioc->reply_free_queue_depth - 1)) ?
  860. 0 : ioc->reply_free_host_index + 1;
  861. ioc->reply_free[ioc->reply_free_host_index] =
  862. cpu_to_le32(reply);
  863. wmb();
  864. writel(ioc->reply_free_host_index,
  865. &ioc->chip->ReplyFreeHostIndex);
  866. }
  867. next:
  868. rpf->Words = cpu_to_le64(ULLONG_MAX);
  869. reply_q->reply_post_host_index =
  870. (reply_q->reply_post_host_index ==
  871. (ioc->reply_post_queue_depth - 1)) ? 0 :
  872. reply_q->reply_post_host_index + 1;
  873. request_desript_type =
  874. reply_q->reply_post_free[reply_q->reply_post_host_index].
  875. Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  876. completed_cmds++;
  877. if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
  878. goto out;
  879. if (!reply_q->reply_post_host_index)
  880. rpf = reply_q->reply_post_free;
  881. else
  882. rpf++;
  883. } while (1);
  884. out:
  885. if (!completed_cmds) {
  886. atomic_dec(&reply_q->busy);
  887. return IRQ_NONE;
  888. }
  889. wmb();
  890. if (ioc->is_warpdrive) {
  891. writel(reply_q->reply_post_host_index,
  892. ioc->reply_post_host_index[msix_index]);
  893. atomic_dec(&reply_q->busy);
  894. return IRQ_HANDLED;
  895. }
  896. writel(reply_q->reply_post_host_index | (msix_index <<
  897. MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
  898. atomic_dec(&reply_q->busy);
  899. return IRQ_HANDLED;
  900. }
  901. /**
  902. * _base_is_controller_msix_enabled - is controller support muli-reply queues
  903. * @ioc: per adapter object
  904. *
  905. */
  906. static inline int
  907. _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
  908. {
  909. return (ioc->facts.IOCCapabilities &
  910. MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
  911. }
  912. /**
  913. * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
  914. * @ioc: per adapter object
  915. * Context: ISR conext
  916. *
  917. * Called when a Task Management request has completed. We want
  918. * to flush the other reply queues so all the outstanding IO has been
  919. * completed back to OS before we process the TM completetion.
  920. *
  921. * Return nothing.
  922. */
  923. void
  924. mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
  925. {
  926. struct adapter_reply_queue *reply_q;
  927. /* If MSIX capability is turned off
  928. * then multi-queues are not enabled
  929. */
  930. if (!_base_is_controller_msix_enabled(ioc))
  931. return;
  932. list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
  933. if (ioc->shost_recovery)
  934. return;
  935. /* TMs are on msix_index == 0 */
  936. if (reply_q->msix_index == 0)
  937. continue;
  938. _base_interrupt(reply_q->vector, (void *)reply_q);
  939. }
  940. }
  941. /**
  942. * mpt2sas_base_release_callback_handler - clear interrupt callback handler
  943. * @cb_idx: callback index
  944. *
  945. * Return nothing.
  946. */
  947. void
  948. mpt2sas_base_release_callback_handler(u8 cb_idx)
  949. {
  950. mpt_callbacks[cb_idx] = NULL;
  951. }
  952. /**
  953. * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
  954. * @cb_func: callback function
  955. *
  956. * Returns cb_func.
  957. */
  958. u8
  959. mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
  960. {
  961. u8 cb_idx;
  962. for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
  963. if (mpt_callbacks[cb_idx] == NULL)
  964. break;
  965. mpt_callbacks[cb_idx] = cb_func;
  966. return cb_idx;
  967. }
  968. /**
  969. * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
  970. *
  971. * Return nothing.
  972. */
  973. void
  974. mpt2sas_base_initialize_callback_handler(void)
  975. {
  976. u8 cb_idx;
  977. for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
  978. mpt2sas_base_release_callback_handler(cb_idx);
  979. }
  980. /**
  981. * mpt2sas_base_build_zero_len_sge - build zero length sg entry
  982. * @ioc: per adapter object
  983. * @paddr: virtual address for SGE
  984. *
  985. * Create a zero length scatter gather entry to insure the IOCs hardware has
  986. * something to use if the target device goes brain dead and tries
  987. * to send data even when none is asked for.
  988. *
  989. * Return nothing.
  990. */
  991. void
  992. mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
  993. {
  994. u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
  995. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
  996. MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
  997. MPI2_SGE_FLAGS_SHIFT);
  998. ioc->base_add_sg_single(paddr, flags_length, -1);
  999. }
  1000. /**
  1001. * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
  1002. * @paddr: virtual address for SGE
  1003. * @flags_length: SGE flags and data transfer length
  1004. * @dma_addr: Physical address
  1005. *
  1006. * Return nothing.
  1007. */
  1008. static void
  1009. _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
  1010. {
  1011. Mpi2SGESimple32_t *sgel = paddr;
  1012. flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
  1013. MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
  1014. sgel->FlagsLength = cpu_to_le32(flags_length);
  1015. sgel->Address = cpu_to_le32(dma_addr);
  1016. }
  1017. /**
  1018. * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
  1019. * @paddr: virtual address for SGE
  1020. * @flags_length: SGE flags and data transfer length
  1021. * @dma_addr: Physical address
  1022. *
  1023. * Return nothing.
  1024. */
  1025. static void
  1026. _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
  1027. {
  1028. Mpi2SGESimple64_t *sgel = paddr;
  1029. flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
  1030. MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
  1031. sgel->FlagsLength = cpu_to_le32(flags_length);
  1032. sgel->Address = cpu_to_le64(dma_addr);
  1033. }
  1034. #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
  1035. /**
  1036. * _base_config_dma_addressing - set dma addressing
  1037. * @ioc: per adapter object
  1038. * @pdev: PCI device struct
  1039. *
  1040. * Returns 0 for success, non-zero for failure.
  1041. */
  1042. static int
  1043. _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
  1044. {
  1045. struct sysinfo s;
  1046. char *desc = NULL;
  1047. if (sizeof(dma_addr_t) > 4) {
  1048. const uint64_t required_mask =
  1049. dma_get_required_mask(&pdev->dev);
  1050. if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
  1051. DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
  1052. DMA_BIT_MASK(64))) {
  1053. ioc->base_add_sg_single = &_base_add_sg_single_64;
  1054. ioc->sge_size = sizeof(Mpi2SGESimple64_t);
  1055. desc = "64";
  1056. goto out;
  1057. }
  1058. }
  1059. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
  1060. && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
  1061. ioc->base_add_sg_single = &_base_add_sg_single_32;
  1062. ioc->sge_size = sizeof(Mpi2SGESimple32_t);
  1063. desc = "32";
  1064. } else
  1065. return -ENODEV;
  1066. out:
  1067. si_meminfo(&s);
  1068. printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
  1069. "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
  1070. return 0;
  1071. }
  1072. /**
  1073. * _base_check_enable_msix - checks MSIX capabable.
  1074. * @ioc: per adapter object
  1075. *
  1076. * Check to see if card is capable of MSIX, and set number
  1077. * of available msix vectors
  1078. */
  1079. static int
  1080. _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
  1081. {
  1082. int base;
  1083. u16 message_control;
  1084. base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
  1085. if (!base) {
  1086. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
  1087. "supported\n", ioc->name));
  1088. return -EINVAL;
  1089. }
  1090. /* get msix vector count */
  1091. /* NUMA_IO not supported for older controllers */
  1092. if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
  1093. ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
  1094. ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
  1095. ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
  1096. ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
  1097. ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
  1098. ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
  1099. ioc->msix_vector_count = 1;
  1100. else {
  1101. pci_read_config_word(ioc->pdev, base + 2, &message_control);
  1102. ioc->msix_vector_count = (message_control & 0x3FF) + 1;
  1103. }
  1104. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
  1105. "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
  1106. return 0;
  1107. }
  1108. /**
  1109. * _base_free_irq - free irq
  1110. * @ioc: per adapter object
  1111. *
  1112. * Freeing respective reply_queue from the list.
  1113. */
  1114. static void
  1115. _base_free_irq(struct MPT2SAS_ADAPTER *ioc)
  1116. {
  1117. struct adapter_reply_queue *reply_q, *next;
  1118. if (list_empty(&ioc->reply_queue_list))
  1119. return;
  1120. list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
  1121. list_del(&reply_q->list);
  1122. synchronize_irq(reply_q->vector);
  1123. free_irq(reply_q->vector, reply_q);
  1124. kfree(reply_q);
  1125. }
  1126. }
  1127. /**
  1128. * _base_request_irq - request irq
  1129. * @ioc: per adapter object
  1130. * @index: msix index into vector table
  1131. * @vector: irq vector
  1132. *
  1133. * Inserting respective reply_queue into the list.
  1134. */
  1135. static int
  1136. _base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
  1137. {
  1138. struct adapter_reply_queue *reply_q;
  1139. int r;
  1140. reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
  1141. if (!reply_q) {
  1142. printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
  1143. ioc->name, (int)sizeof(struct adapter_reply_queue));
  1144. return -ENOMEM;
  1145. }
  1146. reply_q->ioc = ioc;
  1147. reply_q->msix_index = index;
  1148. reply_q->vector = vector;
  1149. atomic_set(&reply_q->busy, 0);
  1150. if (ioc->msix_enable)
  1151. snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
  1152. MPT2SAS_DRIVER_NAME, ioc->id, index);
  1153. else
  1154. snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
  1155. MPT2SAS_DRIVER_NAME, ioc->id);
  1156. r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
  1157. reply_q);
  1158. if (r) {
  1159. printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
  1160. reply_q->name, vector);
  1161. kfree(reply_q);
  1162. return -EBUSY;
  1163. }
  1164. INIT_LIST_HEAD(&reply_q->list);
  1165. list_add_tail(&reply_q->list, &ioc->reply_queue_list);
  1166. return 0;
  1167. }
  1168. /**
  1169. * _base_assign_reply_queues - assigning msix index for each cpu
  1170. * @ioc: per adapter object
  1171. *
  1172. * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
  1173. *
  1174. * It would nice if we could call irq_set_affinity, however it is not
  1175. * an exported symbol
  1176. */
  1177. static void
  1178. _base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
  1179. {
  1180. struct adapter_reply_queue *reply_q;
  1181. int cpu_id;
  1182. int cpu_grouping, loop, grouping, grouping_mod;
  1183. if (!_base_is_controller_msix_enabled(ioc))
  1184. return;
  1185. memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
  1186. /* when there are more cpus than available msix vectors,
  1187. * then group cpus togeather on same irq
  1188. */
  1189. if (ioc->cpu_count > ioc->msix_vector_count) {
  1190. grouping = ioc->cpu_count / ioc->msix_vector_count;
  1191. grouping_mod = ioc->cpu_count % ioc->msix_vector_count;
  1192. if (grouping < 2 || (grouping == 2 && !grouping_mod))
  1193. cpu_grouping = 2;
  1194. else if (grouping < 4 || (grouping == 4 && !grouping_mod))
  1195. cpu_grouping = 4;
  1196. else if (grouping < 8 || (grouping == 8 && !grouping_mod))
  1197. cpu_grouping = 8;
  1198. else
  1199. cpu_grouping = 16;
  1200. } else
  1201. cpu_grouping = 0;
  1202. loop = 0;
  1203. reply_q = list_entry(ioc->reply_queue_list.next,
  1204. struct adapter_reply_queue, list);
  1205. for_each_online_cpu(cpu_id) {
  1206. if (!cpu_grouping) {
  1207. ioc->cpu_msix_table[cpu_id] = reply_q->msix_index;
  1208. reply_q = list_entry(reply_q->list.next,
  1209. struct adapter_reply_queue, list);
  1210. } else {
  1211. if (loop < cpu_grouping) {
  1212. ioc->cpu_msix_table[cpu_id] =
  1213. reply_q->msix_index;
  1214. loop++;
  1215. } else {
  1216. reply_q = list_entry(reply_q->list.next,
  1217. struct adapter_reply_queue, list);
  1218. ioc->cpu_msix_table[cpu_id] =
  1219. reply_q->msix_index;
  1220. loop = 1;
  1221. }
  1222. }
  1223. }
  1224. }
  1225. /**
  1226. * _base_disable_msix - disables msix
  1227. * @ioc: per adapter object
  1228. *
  1229. */
  1230. static void
  1231. _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
  1232. {
  1233. if (ioc->msix_enable) {
  1234. pci_disable_msix(ioc->pdev);
  1235. ioc->msix_enable = 0;
  1236. }
  1237. }
  1238. /**
  1239. * _base_enable_msix - enables msix, failback to io_apic
  1240. * @ioc: per adapter object
  1241. *
  1242. */
  1243. static int
  1244. _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
  1245. {
  1246. struct msix_entry *entries, *a;
  1247. int r;
  1248. int i;
  1249. u8 try_msix = 0;
  1250. INIT_LIST_HEAD(&ioc->reply_queue_list);
  1251. if (msix_disable == -1 || msix_disable == 0)
  1252. try_msix = 1;
  1253. if (!try_msix)
  1254. goto try_ioapic;
  1255. if (_base_check_enable_msix(ioc) != 0)
  1256. goto try_ioapic;
  1257. ioc->reply_queue_count = min_t(int, ioc->cpu_count,
  1258. ioc->msix_vector_count);
  1259. entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
  1260. GFP_KERNEL);
  1261. if (!entries) {
  1262. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
  1263. "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
  1264. __LINE__, __func__));
  1265. goto try_ioapic;
  1266. }
  1267. for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
  1268. a->entry = i;
  1269. r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
  1270. if (r) {
  1271. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
  1272. "failed (r=%d) !!!\n", ioc->name, r));
  1273. kfree(entries);
  1274. goto try_ioapic;
  1275. }
  1276. ioc->msix_enable = 1;
  1277. for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
  1278. r = _base_request_irq(ioc, i, a->vector);
  1279. if (r) {
  1280. _base_free_irq(ioc);
  1281. _base_disable_msix(ioc);
  1282. kfree(entries);
  1283. goto try_ioapic;
  1284. }
  1285. }
  1286. kfree(entries);
  1287. return 0;
  1288. /* failback to io_apic interrupt routing */
  1289. try_ioapic:
  1290. r = _base_request_irq(ioc, 0, ioc->pdev->irq);
  1291. return r;
  1292. }
  1293. /**
  1294. * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
  1295. * @ioc: per adapter object
  1296. *
  1297. * Returns 0 for success, non-zero for failure.
  1298. */
  1299. int
  1300. mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
  1301. {
  1302. struct pci_dev *pdev = ioc->pdev;
  1303. u32 memap_sz;
  1304. u32 pio_sz;
  1305. int i, r = 0;
  1306. u64 pio_chip = 0;
  1307. u64 chip_phys = 0;
  1308. struct adapter_reply_queue *reply_q;
  1309. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
  1310. ioc->name, __func__));
  1311. ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1312. if (pci_enable_device_mem(pdev)) {
  1313. printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
  1314. "failed\n", ioc->name);
  1315. return -ENODEV;
  1316. }
  1317. if (pci_request_selected_regions(pdev, ioc->bars,
  1318. MPT2SAS_DRIVER_NAME)) {
  1319. printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
  1320. "failed\n", ioc->name);
  1321. r = -ENODEV;
  1322. goto out_fail;
  1323. }
  1324. /* AER (Advanced Error Reporting) hooks */
  1325. pci_enable_pcie_error_reporting(pdev);
  1326. pci_set_master(pdev);
  1327. if (_base_config_dma_addressing(ioc, pdev) != 0) {
  1328. printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
  1329. ioc->name, pci_name(pdev));
  1330. r = -ENODEV;
  1331. goto out_fail;
  1332. }
  1333. for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
  1334. if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
  1335. if (pio_sz)
  1336. continue;
  1337. pio_chip = (u64)pci_resource_start(pdev, i);
  1338. pio_sz = pci_resource_len(pdev, i);
  1339. } else {
  1340. if (memap_sz)
  1341. continue;
  1342. /* verify memory resource is valid before using */
  1343. if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
  1344. ioc->chip_phys = pci_resource_start(pdev, i);
  1345. chip_phys = (u64)ioc->chip_phys;
  1346. memap_sz = pci_resource_len(pdev, i);
  1347. ioc->chip = ioremap(ioc->chip_phys, memap_sz);
  1348. if (ioc->chip == NULL) {
  1349. printk(MPT2SAS_ERR_FMT "unable to map "
  1350. "adapter memory!\n", ioc->name);
  1351. r = -EINVAL;
  1352. goto out_fail;
  1353. }
  1354. }
  1355. }
  1356. }
  1357. _base_mask_interrupts(ioc);
  1358. r = _base_enable_msix(ioc);
  1359. if (r)
  1360. goto out_fail;
  1361. list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
  1362. printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
  1363. reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
  1364. "IO-APIC enabled"), reply_q->vector);
  1365. printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
  1366. ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
  1367. printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
  1368. ioc->name, (unsigned long long)pio_chip, pio_sz);
  1369. /* Save PCI configuration state for recovery from PCI AER/EEH errors */
  1370. pci_save_state(pdev);
  1371. return 0;
  1372. out_fail:
  1373. if (ioc->chip_phys)
  1374. iounmap(ioc->chip);
  1375. ioc->chip_phys = 0;
  1376. pci_release_selected_regions(ioc->pdev, ioc->bars);
  1377. pci_disable_pcie_error_reporting(pdev);
  1378. pci_disable_device(pdev);
  1379. return r;
  1380. }
  1381. /**
  1382. * mpt2sas_base_get_msg_frame - obtain request mf pointer
  1383. * @ioc: per adapter object
  1384. * @smid: system request message index(smid zero is invalid)
  1385. *
  1386. * Returns virt pointer to message frame.
  1387. */
  1388. void *
  1389. mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1390. {
  1391. return (void *)(ioc->request + (smid * ioc->request_sz));
  1392. }
  1393. /**
  1394. * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
  1395. * @ioc: per adapter object
  1396. * @smid: system request message index
  1397. *
  1398. * Returns virt pointer to sense buffer.
  1399. */
  1400. void *
  1401. mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1402. {
  1403. return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
  1404. }
  1405. /**
  1406. * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
  1407. * @ioc: per adapter object
  1408. * @smid: system request message index
  1409. *
  1410. * Returns phys pointer to the low 32bit address of the sense buffer.
  1411. */
  1412. __le32
  1413. mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1414. {
  1415. return cpu_to_le32(ioc->sense_dma +
  1416. ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
  1417. }
  1418. /**
  1419. * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
  1420. * @ioc: per adapter object
  1421. * @phys_addr: lower 32 physical addr of the reply
  1422. *
  1423. * Converts 32bit lower physical addr into a virt address.
  1424. */
  1425. void *
  1426. mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
  1427. {
  1428. if (!phys_addr)
  1429. return NULL;
  1430. return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
  1431. }
  1432. /**
  1433. * mpt2sas_base_get_smid - obtain a free smid from internal queue
  1434. * @ioc: per adapter object
  1435. * @cb_idx: callback index
  1436. *
  1437. * Returns smid (zero is invalid)
  1438. */
  1439. u16
  1440. mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
  1441. {
  1442. unsigned long flags;
  1443. struct request_tracker *request;
  1444. u16 smid;
  1445. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1446. if (list_empty(&ioc->internal_free_list)) {
  1447. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1448. printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
  1449. ioc->name, __func__);
  1450. return 0;
  1451. }
  1452. request = list_entry(ioc->internal_free_list.next,
  1453. struct request_tracker, tracker_list);
  1454. request->cb_idx = cb_idx;
  1455. smid = request->smid;
  1456. list_del(&request->tracker_list);
  1457. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1458. return smid;
  1459. }
  1460. /**
  1461. * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
  1462. * @ioc: per adapter object
  1463. * @cb_idx: callback index
  1464. * @scmd: pointer to scsi command object
  1465. *
  1466. * Returns smid (zero is invalid)
  1467. */
  1468. u16
  1469. mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
  1470. struct scsi_cmnd *scmd)
  1471. {
  1472. unsigned long flags;
  1473. struct scsiio_tracker *request;
  1474. u16 smid;
  1475. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1476. if (list_empty(&ioc->free_list)) {
  1477. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1478. printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
  1479. ioc->name, __func__);
  1480. return 0;
  1481. }
  1482. request = list_entry(ioc->free_list.next,
  1483. struct scsiio_tracker, tracker_list);
  1484. request->scmd = scmd;
  1485. request->cb_idx = cb_idx;
  1486. smid = request->smid;
  1487. list_del(&request->tracker_list);
  1488. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1489. return smid;
  1490. }
  1491. /**
  1492. * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
  1493. * @ioc: per adapter object
  1494. * @cb_idx: callback index
  1495. *
  1496. * Returns smid (zero is invalid)
  1497. */
  1498. u16
  1499. mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
  1500. {
  1501. unsigned long flags;
  1502. struct request_tracker *request;
  1503. u16 smid;
  1504. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1505. if (list_empty(&ioc->hpr_free_list)) {
  1506. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1507. return 0;
  1508. }
  1509. request = list_entry(ioc->hpr_free_list.next,
  1510. struct request_tracker, tracker_list);
  1511. request->cb_idx = cb_idx;
  1512. smid = request->smid;
  1513. list_del(&request->tracker_list);
  1514. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1515. return smid;
  1516. }
  1517. /**
  1518. * mpt2sas_base_free_smid - put smid back on free_list
  1519. * @ioc: per adapter object
  1520. * @smid: system request message index
  1521. *
  1522. * Return nothing.
  1523. */
  1524. void
  1525. mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1526. {
  1527. unsigned long flags;
  1528. int i;
  1529. struct chain_tracker *chain_req, *next;
  1530. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1531. if (smid < ioc->hi_priority_smid) {
  1532. /* scsiio queue */
  1533. i = smid - 1;
  1534. if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
  1535. list_for_each_entry_safe(chain_req, next,
  1536. &ioc->scsi_lookup[i].chain_list, tracker_list) {
  1537. list_del_init(&chain_req->tracker_list);
  1538. list_add_tail(&chain_req->tracker_list,
  1539. &ioc->free_chain_list);
  1540. }
  1541. }
  1542. ioc->scsi_lookup[i].cb_idx = 0xFF;
  1543. ioc->scsi_lookup[i].scmd = NULL;
  1544. ioc->scsi_lookup[i].direct_io = 0;
  1545. list_add_tail(&ioc->scsi_lookup[i].tracker_list,
  1546. &ioc->free_list);
  1547. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1548. /*
  1549. * See _wait_for_commands_to_complete() call with regards
  1550. * to this code.
  1551. */
  1552. if (ioc->shost_recovery && ioc->pending_io_count) {
  1553. if (ioc->pending_io_count == 1)
  1554. wake_up(&ioc->reset_wq);
  1555. ioc->pending_io_count--;
  1556. }
  1557. return;
  1558. } else if (smid < ioc->internal_smid) {
  1559. /* hi-priority */
  1560. i = smid - ioc->hi_priority_smid;
  1561. ioc->hpr_lookup[i].cb_idx = 0xFF;
  1562. list_add_tail(&ioc->hpr_lookup[i].tracker_list,
  1563. &ioc->hpr_free_list);
  1564. } else if (smid <= ioc->hba_queue_depth) {
  1565. /* internal queue */
  1566. i = smid - ioc->internal_smid;
  1567. ioc->internal_lookup[i].cb_idx = 0xFF;
  1568. list_add_tail(&ioc->internal_lookup[i].tracker_list,
  1569. &ioc->internal_free_list);
  1570. }
  1571. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1572. }
  1573. /**
  1574. * _base_writeq - 64 bit write to MMIO
  1575. * @ioc: per adapter object
  1576. * @b: data payload
  1577. * @addr: address in MMIO space
  1578. * @writeq_lock: spin lock
  1579. *
  1580. * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
  1581. * care of 32 bit environment where its not quarenteed to send the entire word
  1582. * in one transfer.
  1583. */
  1584. #ifndef writeq
  1585. static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
  1586. spinlock_t *writeq_lock)
  1587. {
  1588. unsigned long flags;
  1589. __u64 data_out = cpu_to_le64(b);
  1590. spin_lock_irqsave(writeq_lock, flags);
  1591. writel((u32)(data_out), addr);
  1592. writel((u32)(data_out >> 32), (addr + 4));
  1593. spin_unlock_irqrestore(writeq_lock, flags);
  1594. }
  1595. #else
  1596. static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
  1597. spinlock_t *writeq_lock)
  1598. {
  1599. writeq(cpu_to_le64(b), addr);
  1600. }
  1601. #endif
  1602. static inline u8
  1603. _base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
  1604. {
  1605. return ioc->cpu_msix_table[smp_processor_id()];
  1606. }
  1607. /**
  1608. * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
  1609. * @ioc: per adapter object
  1610. * @smid: system request message index
  1611. * @handle: device handle
  1612. *
  1613. * Return nothing.
  1614. */
  1615. void
  1616. mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
  1617. {
  1618. Mpi2RequestDescriptorUnion_t descriptor;
  1619. u64 *request = (u64 *)&descriptor;
  1620. descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
  1621. descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc);
  1622. descriptor.SCSIIO.SMID = cpu_to_le16(smid);
  1623. descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
  1624. descriptor.SCSIIO.LMID = 0;
  1625. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1626. &ioc->scsi_lookup_lock);
  1627. }
  1628. /**
  1629. * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
  1630. * @ioc: per adapter object
  1631. * @smid: system request message index
  1632. *
  1633. * Return nothing.
  1634. */
  1635. void
  1636. mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1637. {
  1638. Mpi2RequestDescriptorUnion_t descriptor;
  1639. u64 *request = (u64 *)&descriptor;
  1640. descriptor.HighPriority.RequestFlags =
  1641. MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
  1642. descriptor.HighPriority.MSIxIndex = 0;
  1643. descriptor.HighPriority.SMID = cpu_to_le16(smid);
  1644. descriptor.HighPriority.LMID = 0;
  1645. descriptor.HighPriority.Reserved1 = 0;
  1646. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1647. &ioc->scsi_lookup_lock);
  1648. }
  1649. /**
  1650. * mpt2sas_base_put_smid_default - Default, primarily used for config pages
  1651. * @ioc: per adapter object
  1652. * @smid: system request message index
  1653. *
  1654. * Return nothing.
  1655. */
  1656. void
  1657. mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  1658. {
  1659. Mpi2RequestDescriptorUnion_t descriptor;
  1660. u64 *request = (u64 *)&descriptor;
  1661. descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
  1662. descriptor.Default.MSIxIndex = _base_get_msix_index(ioc);
  1663. descriptor.Default.SMID = cpu_to_le16(smid);
  1664. descriptor.Default.LMID = 0;
  1665. descriptor.Default.DescriptorTypeDependent = 0;
  1666. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1667. &ioc->scsi_lookup_lock);
  1668. }
  1669. /**
  1670. * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
  1671. * @ioc: per adapter object
  1672. * @smid: system request message index
  1673. * @io_index: value used to track the IO
  1674. *
  1675. * Return nothing.
  1676. */
  1677. void
  1678. mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  1679. u16 io_index)
  1680. {
  1681. Mpi2RequestDescriptorUnion_t descriptor;
  1682. u64 *request = (u64 *)&descriptor;
  1683. descriptor.SCSITarget.RequestFlags =
  1684. MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
  1685. descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc);
  1686. descriptor.SCSITarget.SMID = cpu_to_le16(smid);
  1687. descriptor.SCSITarget.LMID = 0;
  1688. descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
  1689. _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
  1690. &ioc->scsi_lookup_lock);
  1691. }
  1692. /**
  1693. * _base_display_dell_branding - Disply branding string
  1694. * @ioc: per adapter object
  1695. *
  1696. * Return nothing.
  1697. */
  1698. static void
  1699. _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
  1700. {
  1701. char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
  1702. if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
  1703. return;
  1704. memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
  1705. switch (ioc->pdev->subsystem_device) {
  1706. case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
  1707. strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
  1708. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1709. break;
  1710. case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
  1711. strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
  1712. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1713. break;
  1714. case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
  1715. strncpy(dell_branding,
  1716. MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
  1717. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1718. break;
  1719. case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
  1720. strncpy(dell_branding,
  1721. MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
  1722. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1723. break;
  1724. case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
  1725. strncpy(dell_branding,
  1726. MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
  1727. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1728. break;
  1729. case MPT2SAS_DELL_PERC_H200_SSDID:
  1730. strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
  1731. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1732. break;
  1733. case MPT2SAS_DELL_6GBPS_SAS_SSDID:
  1734. strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
  1735. MPT2SAS_DELL_BRANDING_SIZE - 1);
  1736. break;
  1737. default:
  1738. sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
  1739. break;
  1740. }
  1741. printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
  1742. " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
  1743. ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
  1744. ioc->pdev->subsystem_device);
  1745. }
  1746. /**
  1747. * _base_display_intel_branding - Display branding string
  1748. * @ioc: per adapter object
  1749. *
  1750. * Return nothing.
  1751. */
  1752. static void
  1753. _base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
  1754. {
  1755. if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
  1756. return;
  1757. switch (ioc->pdev->device) {
  1758. case MPI2_MFGPAGE_DEVID_SAS2008:
  1759. switch (ioc->pdev->subsystem_device) {
  1760. case MPT2SAS_INTEL_RMS2LL080_SSDID:
  1761. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1762. MPT2SAS_INTEL_RMS2LL080_BRANDING);
  1763. break;
  1764. case MPT2SAS_INTEL_RMS2LL040_SSDID:
  1765. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1766. MPT2SAS_INTEL_RMS2LL040_BRANDING);
  1767. break;
  1768. case MPT2SAS_INTEL_RAMSDALE_SSDID:
  1769. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1770. MPT2SAS_INTEL_RAMSDALE_BRANDING);
  1771. break;
  1772. default:
  1773. break;
  1774. }
  1775. case MPI2_MFGPAGE_DEVID_SAS2308_2:
  1776. switch (ioc->pdev->subsystem_device) {
  1777. case MPT2SAS_INTEL_RS25GB008_SSDID:
  1778. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1779. MPT2SAS_INTEL_RS25GB008_BRANDING);
  1780. break;
  1781. case MPT2SAS_INTEL_RMS25JB080_SSDID:
  1782. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1783. MPT2SAS_INTEL_RMS25JB080_BRANDING);
  1784. break;
  1785. case MPT2SAS_INTEL_RMS25JB040_SSDID:
  1786. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1787. MPT2SAS_INTEL_RMS25JB040_BRANDING);
  1788. break;
  1789. case MPT2SAS_INTEL_RMS25KB080_SSDID:
  1790. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1791. MPT2SAS_INTEL_RMS25KB080_BRANDING);
  1792. break;
  1793. case MPT2SAS_INTEL_RMS25KB040_SSDID:
  1794. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1795. MPT2SAS_INTEL_RMS25KB040_BRANDING);
  1796. break;
  1797. default:
  1798. break;
  1799. }
  1800. default:
  1801. break;
  1802. }
  1803. }
  1804. /**
  1805. * _base_display_hp_branding - Display branding string
  1806. * @ioc: per adapter object
  1807. *
  1808. * Return nothing.
  1809. */
  1810. static void
  1811. _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
  1812. {
  1813. if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
  1814. return;
  1815. switch (ioc->pdev->device) {
  1816. case MPI2_MFGPAGE_DEVID_SAS2004:
  1817. switch (ioc->pdev->subsystem_device) {
  1818. case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
  1819. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1820. MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
  1821. break;
  1822. default:
  1823. break;
  1824. }
  1825. case MPI2_MFGPAGE_DEVID_SAS2308_2:
  1826. switch (ioc->pdev->subsystem_device) {
  1827. case MPT2SAS_HP_2_4_INTERNAL_SSDID:
  1828. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1829. MPT2SAS_HP_2_4_INTERNAL_BRANDING);
  1830. break;
  1831. case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
  1832. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1833. MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
  1834. break;
  1835. case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
  1836. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1837. MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
  1838. break;
  1839. case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
  1840. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  1841. MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
  1842. break;
  1843. default:
  1844. break;
  1845. }
  1846. default:
  1847. break;
  1848. }
  1849. }
  1850. /**
  1851. * _base_display_ioc_capabilities - Disply IOC's capabilities.
  1852. * @ioc: per adapter object
  1853. *
  1854. * Return nothing.
  1855. */
  1856. static void
  1857. _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
  1858. {
  1859. int i = 0;
  1860. char desc[16];
  1861. u32 iounit_pg1_flags;
  1862. u32 bios_version;
  1863. bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
  1864. strncpy(desc, ioc->manu_pg0.ChipName, 16);
  1865. printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
  1866. "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
  1867. ioc->name, desc,
  1868. (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
  1869. (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
  1870. (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
  1871. ioc->facts.FWVersion.Word & 0x000000FF,
  1872. ioc->pdev->revision,
  1873. (bios_version & 0xFF000000) >> 24,
  1874. (bios_version & 0x00FF0000) >> 16,
  1875. (bios_version & 0x0000FF00) >> 8,
  1876. bios_version & 0x000000FF);
  1877. _base_display_dell_branding(ioc);
  1878. _base_display_intel_branding(ioc);
  1879. _base_display_hp_branding(ioc);
  1880. printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
  1881. if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
  1882. printk("Initiator");
  1883. i++;
  1884. }
  1885. if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
  1886. printk("%sTarget", i ? "," : "");
  1887. i++;
  1888. }
  1889. i = 0;
  1890. printk("), ");
  1891. printk("Capabilities=(");
  1892. if (!ioc->hide_ir_msg) {
  1893. if (ioc->facts.IOCCapabilities &
  1894. MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
  1895. printk("Raid");
  1896. i++;
  1897. }
  1898. }
  1899. if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
  1900. printk("%sTLR", i ? "," : "");
  1901. i++;
  1902. }
  1903. if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
  1904. printk("%sMulticast", i ? "," : "");
  1905. i++;
  1906. }
  1907. if (ioc->facts.IOCCapabilities &
  1908. MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
  1909. printk("%sBIDI Target", i ? "," : "");
  1910. i++;
  1911. }
  1912. if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
  1913. printk("%sEEDP", i ? "," : "");
  1914. i++;
  1915. }
  1916. if (ioc->facts.IOCCapabilities &
  1917. MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
  1918. printk("%sSnapshot Buffer", i ? "," : "");
  1919. i++;
  1920. }
  1921. if (ioc->facts.IOCCapabilities &
  1922. MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
  1923. printk("%sDiag Trace Buffer", i ? "," : "");
  1924. i++;
  1925. }
  1926. if (ioc->facts.IOCCapabilities &
  1927. MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
  1928. printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
  1929. i++;
  1930. }
  1931. if (ioc->facts.IOCCapabilities &
  1932. MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
  1933. printk("%sTask Set Full", i ? "," : "");
  1934. i++;
  1935. }
  1936. iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
  1937. if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
  1938. printk("%sNCQ", i ? "," : "");
  1939. i++;
  1940. }
  1941. printk(")\n");
  1942. }
  1943. /**
  1944. * _base_update_missing_delay - change the missing delay timers
  1945. * @ioc: per adapter object
  1946. * @device_missing_delay: amount of time till device is reported missing
  1947. * @io_missing_delay: interval IO is returned when there is a missing device
  1948. *
  1949. * Return nothing.
  1950. *
  1951. * Passed on the command line, this function will modify the device missing
  1952. * delay, as well as the io missing delay. This should be called at driver
  1953. * load time.
  1954. */
  1955. static void
  1956. _base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
  1957. u16 device_missing_delay, u8 io_missing_delay)
  1958. {
  1959. u16 dmd, dmd_new, dmd_orignal;
  1960. u8 io_missing_delay_original;
  1961. u16 sz;
  1962. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  1963. Mpi2ConfigReply_t mpi_reply;
  1964. u8 num_phys = 0;
  1965. u16 ioc_status;
  1966. mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
  1967. if (!num_phys)
  1968. return;
  1969. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
  1970. sizeof(Mpi2SasIOUnit1PhyData_t));
  1971. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  1972. if (!sas_iounit_pg1) {
  1973. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1974. ioc->name, __FILE__, __LINE__, __func__);
  1975. goto out;
  1976. }
  1977. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  1978. sas_iounit_pg1, sz))) {
  1979. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1980. ioc->name, __FILE__, __LINE__, __func__);
  1981. goto out;
  1982. }
  1983. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1984. MPI2_IOCSTATUS_MASK;
  1985. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1986. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1987. ioc->name, __FILE__, __LINE__, __func__);
  1988. goto out;
  1989. }
  1990. /* device missing delay */
  1991. dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
  1992. if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
  1993. dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
  1994. else
  1995. dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  1996. dmd_orignal = dmd;
  1997. if (device_missing_delay > 0x7F) {
  1998. dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
  1999. device_missing_delay;
  2000. dmd = dmd / 16;
  2001. dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
  2002. } else
  2003. dmd = device_missing_delay;
  2004. sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
  2005. /* io missing delay */
  2006. io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
  2007. sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
  2008. if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
  2009. sz)) {
  2010. if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
  2011. dmd_new = (dmd &
  2012. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
  2013. else
  2014. dmd_new =
  2015. dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  2016. printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
  2017. "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
  2018. printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
  2019. "new(%d)\n", ioc->name, io_missing_delay_original,
  2020. io_missing_delay);
  2021. ioc->device_missing_delay = dmd_new;
  2022. ioc->io_missing_delay = io_missing_delay;
  2023. }
  2024. out:
  2025. kfree(sas_iounit_pg1);
  2026. }
  2027. /**
  2028. * _base_static_config_pages - static start of day config pages
  2029. * @ioc: per adapter object
  2030. *
  2031. * Return nothing.
  2032. */
  2033. static void
  2034. _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
  2035. {
  2036. Mpi2ConfigReply_t mpi_reply;
  2037. u32 iounit_pg1_flags;
  2038. mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
  2039. if (ioc->ir_firmware)
  2040. mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
  2041. &ioc->manu_pg10);
  2042. mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
  2043. mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
  2044. mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
  2045. mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
  2046. mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
  2047. _base_display_ioc_capabilities(ioc);
  2048. /*
  2049. * Enable task_set_full handling in iounit_pg1 when the
  2050. * facts capabilities indicate that its supported.
  2051. */
  2052. iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
  2053. if ((ioc->facts.IOCCapabilities &
  2054. MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
  2055. iounit_pg1_flags &=
  2056. ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
  2057. else
  2058. iounit_pg1_flags |=
  2059. MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
  2060. ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
  2061. mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
  2062. }
  2063. /**
  2064. * _base_release_memory_pools - release memory
  2065. * @ioc: per adapter object
  2066. *
  2067. * Free memory allocated from _base_allocate_memory_pools.
  2068. *
  2069. * Return nothing.
  2070. */
  2071. static void
  2072. _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
  2073. {
  2074. int i;
  2075. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  2076. __func__));
  2077. if (ioc->request) {
  2078. pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
  2079. ioc->request, ioc->request_dma);
  2080. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
  2081. ": free\n", ioc->name, ioc->request));
  2082. ioc->request = NULL;
  2083. }
  2084. if (ioc->sense) {
  2085. pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
  2086. if (ioc->sense_dma_pool)
  2087. pci_pool_destroy(ioc->sense_dma_pool);
  2088. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
  2089. ": free\n", ioc->name, ioc->sense));
  2090. ioc->sense = NULL;
  2091. }
  2092. if (ioc->reply) {
  2093. pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
  2094. if (ioc->reply_dma_pool)
  2095. pci_pool_destroy(ioc->reply_dma_pool);
  2096. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
  2097. ": free\n", ioc->name, ioc->reply));
  2098. ioc->reply = NULL;
  2099. }
  2100. if (ioc->reply_free) {
  2101. pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
  2102. ioc->reply_free_dma);
  2103. if (ioc->reply_free_dma_pool)
  2104. pci_pool_destroy(ioc->reply_free_dma_pool);
  2105. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
  2106. "(0x%p): free\n", ioc->name, ioc->reply_free));
  2107. ioc->reply_free = NULL;
  2108. }
  2109. if (ioc->reply_post_free) {
  2110. pci_pool_free(ioc->reply_post_free_dma_pool,
  2111. ioc->reply_post_free, ioc->reply_post_free_dma);
  2112. if (ioc->reply_post_free_dma_pool)
  2113. pci_pool_destroy(ioc->reply_post_free_dma_pool);
  2114. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
  2115. "reply_post_free_pool(0x%p): free\n", ioc->name,
  2116. ioc->reply_post_free));
  2117. ioc->reply_post_free = NULL;
  2118. }
  2119. if (ioc->config_page) {
  2120. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
  2121. "config_page(0x%p): free\n", ioc->name,
  2122. ioc->config_page));
  2123. pci_free_consistent(ioc->pdev, ioc->config_page_sz,
  2124. ioc->config_page, ioc->config_page_dma);
  2125. }
  2126. if (ioc->scsi_lookup) {
  2127. free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
  2128. ioc->scsi_lookup = NULL;
  2129. }
  2130. kfree(ioc->hpr_lookup);
  2131. kfree(ioc->internal_lookup);
  2132. if (ioc->chain_lookup) {
  2133. for (i = 0; i < ioc->chain_depth; i++) {
  2134. if (ioc->chain_lookup[i].chain_buffer)
  2135. pci_pool_free(ioc->chain_dma_pool,
  2136. ioc->chain_lookup[i].chain_buffer,
  2137. ioc->chain_lookup[i].chain_buffer_dma);
  2138. }
  2139. if (ioc->chain_dma_pool)
  2140. pci_pool_destroy(ioc->chain_dma_pool);
  2141. free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
  2142. ioc->chain_lookup = NULL;
  2143. }
  2144. }
  2145. /**
  2146. * _base_allocate_memory_pools - allocate start of day memory pools
  2147. * @ioc: per adapter object
  2148. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2149. *
  2150. * Returns 0 success, anything else error
  2151. */
  2152. static int
  2153. _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  2154. {
  2155. struct mpt2sas_facts *facts;
  2156. u16 max_sge_elements;
  2157. u16 chains_needed_per_io;
  2158. u32 sz, total_sz, reply_post_free_sz;
  2159. u32 retry_sz;
  2160. u16 max_request_credit;
  2161. int i;
  2162. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  2163. __func__));
  2164. retry_sz = 0;
  2165. facts = &ioc->facts;
  2166. /* command line tunables for max sgl entries */
  2167. if (max_sgl_entries != -1) {
  2168. ioc->shost->sg_tablesize = (max_sgl_entries <
  2169. MPT2SAS_SG_DEPTH) ? max_sgl_entries :
  2170. MPT2SAS_SG_DEPTH;
  2171. } else {
  2172. ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
  2173. }
  2174. /* command line tunables for max controller queue depth */
  2175. if (max_queue_depth != -1)
  2176. max_request_credit = (max_queue_depth < facts->RequestCredit)
  2177. ? max_queue_depth : facts->RequestCredit;
  2178. else
  2179. max_request_credit = min_t(u16, facts->RequestCredit,
  2180. MAX_HBA_QUEUE_DEPTH);
  2181. ioc->hba_queue_depth = max_request_credit;
  2182. ioc->hi_priority_depth = facts->HighPriorityCredit;
  2183. ioc->internal_depth = ioc->hi_priority_depth + 5;
  2184. /* request frame size */
  2185. ioc->request_sz = facts->IOCRequestFrameSize * 4;
  2186. /* reply frame size */
  2187. ioc->reply_sz = facts->ReplyFrameSize * 4;
  2188. retry_allocation:
  2189. total_sz = 0;
  2190. /* calculate number of sg elements left over in the 1st frame */
  2191. max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
  2192. sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
  2193. ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
  2194. /* now do the same for a chain buffer */
  2195. max_sge_elements = ioc->request_sz - ioc->sge_size;
  2196. ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
  2197. ioc->chain_offset_value_for_main_message =
  2198. ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
  2199. (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
  2200. /*
  2201. * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
  2202. */
  2203. chains_needed_per_io = ((ioc->shost->sg_tablesize -
  2204. ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
  2205. + 1;
  2206. if (chains_needed_per_io > facts->MaxChainDepth) {
  2207. chains_needed_per_io = facts->MaxChainDepth;
  2208. ioc->shost->sg_tablesize = min_t(u16,
  2209. ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
  2210. * chains_needed_per_io), ioc->shost->sg_tablesize);
  2211. }
  2212. ioc->chains_needed_per_io = chains_needed_per_io;
  2213. /* reply free queue sizing - taking into account for 64 FW events */
  2214. ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64;
  2215. /* align the reply post queue on the next 16 count boundary */
  2216. if (!ioc->reply_free_queue_depth % 16)
  2217. ioc->reply_post_queue_depth = ioc->reply_free_queue_depth + 16;
  2218. else
  2219. ioc->reply_post_queue_depth = ioc->reply_free_queue_depth +
  2220. 32 - (ioc->reply_free_queue_depth % 16);
  2221. if (ioc->reply_post_queue_depth >
  2222. facts->MaxReplyDescriptorPostQueueDepth) {
  2223. ioc->reply_post_queue_depth = min_t(u16,
  2224. (facts->MaxReplyDescriptorPostQueueDepth -
  2225. (facts->MaxReplyDescriptorPostQueueDepth % 16)),
  2226. (ioc->hba_queue_depth - (ioc->hba_queue_depth % 16)));
  2227. ioc->reply_free_queue_depth = ioc->reply_post_queue_depth - 16;
  2228. ioc->hba_queue_depth = ioc->reply_free_queue_depth - 64;
  2229. }
  2230. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
  2231. "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
  2232. "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
  2233. ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
  2234. ioc->chains_needed_per_io));
  2235. ioc->scsiio_depth = ioc->hba_queue_depth -
  2236. ioc->hi_priority_depth - ioc->internal_depth;
  2237. /* set the scsi host can_queue depth
  2238. * with some internal commands that could be outstanding
  2239. */
  2240. ioc->shost->can_queue = ioc->scsiio_depth - (2);
  2241. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
  2242. "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
  2243. /* contiguous pool for request and chains, 16 byte align, one extra "
  2244. * "frame for smid=0
  2245. */
  2246. ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
  2247. sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
  2248. /* hi-priority queue */
  2249. sz += (ioc->hi_priority_depth * ioc->request_sz);
  2250. /* internal queue */
  2251. sz += (ioc->internal_depth * ioc->request_sz);
  2252. ioc->request_dma_sz = sz;
  2253. ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
  2254. if (!ioc->request) {
  2255. printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
  2256. "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
  2257. "total(%d kB)\n", ioc->name, ioc->hba_queue_depth,
  2258. ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
  2259. if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
  2260. goto out;
  2261. retry_sz += 64;
  2262. ioc->hba_queue_depth = max_request_credit - retry_sz;
  2263. goto retry_allocation;
  2264. }
  2265. if (retry_sz)
  2266. printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
  2267. "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
  2268. "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
  2269. ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
  2270. /* hi-priority queue */
  2271. ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
  2272. ioc->request_sz);
  2273. ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
  2274. ioc->request_sz);
  2275. /* internal queue */
  2276. ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
  2277. ioc->request_sz);
  2278. ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
  2279. ioc->request_sz);
  2280. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
  2281. "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
  2282. ioc->request, ioc->hba_queue_depth, ioc->request_sz,
  2283. (ioc->hba_queue_depth * ioc->request_sz)/1024));
  2284. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
  2285. ioc->name, (unsigned long long) ioc->request_dma));
  2286. total_sz += sz;
  2287. sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
  2288. ioc->scsi_lookup_pages = get_order(sz);
  2289. ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
  2290. GFP_KERNEL, ioc->scsi_lookup_pages);
  2291. if (!ioc->scsi_lookup) {
  2292. printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
  2293. "sz(%d)\n", ioc->name, (int)sz);
  2294. goto out;
  2295. }
  2296. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
  2297. "depth(%d)\n", ioc->name, ioc->request,
  2298. ioc->scsiio_depth));
  2299. ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH);
  2300. sz = ioc->chain_depth * sizeof(struct chain_tracker);
  2301. ioc->chain_pages = get_order(sz);
  2302. ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
  2303. GFP_KERNEL, ioc->chain_pages);
  2304. if (!ioc->chain_lookup) {
  2305. printk(MPT2SAS_ERR_FMT "chain_lookup: get_free_pages failed, "
  2306. "sz(%d)\n", ioc->name, (int)sz);
  2307. goto out;
  2308. }
  2309. ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
  2310. ioc->request_sz, 16, 0);
  2311. if (!ioc->chain_dma_pool) {
  2312. printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
  2313. "failed\n", ioc->name);
  2314. goto out;
  2315. }
  2316. for (i = 0; i < ioc->chain_depth; i++) {
  2317. ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
  2318. ioc->chain_dma_pool , GFP_KERNEL,
  2319. &ioc->chain_lookup[i].chain_buffer_dma);
  2320. if (!ioc->chain_lookup[i].chain_buffer) {
  2321. ioc->chain_depth = i;
  2322. goto chain_done;
  2323. }
  2324. total_sz += ioc->request_sz;
  2325. }
  2326. chain_done:
  2327. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
  2328. "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
  2329. ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
  2330. ioc->request_sz))/1024));
  2331. /* initialize hi-priority queue smid's */
  2332. ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
  2333. sizeof(struct request_tracker), GFP_KERNEL);
  2334. if (!ioc->hpr_lookup) {
  2335. printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
  2336. ioc->name);
  2337. goto out;
  2338. }
  2339. ioc->hi_priority_smid = ioc->scsiio_depth + 1;
  2340. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
  2341. "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
  2342. ioc->hi_priority_depth, ioc->hi_priority_smid));
  2343. /* initialize internal queue smid's */
  2344. ioc->internal_lookup = kcalloc(ioc->internal_depth,
  2345. sizeof(struct request_tracker), GFP_KERNEL);
  2346. if (!ioc->internal_lookup) {
  2347. printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
  2348. ioc->name);
  2349. goto out;
  2350. }
  2351. ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
  2352. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
  2353. "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
  2354. ioc->internal_depth, ioc->internal_smid));
  2355. /* sense buffers, 4 byte align */
  2356. sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
  2357. ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
  2358. 0);
  2359. if (!ioc->sense_dma_pool) {
  2360. printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
  2361. ioc->name);
  2362. goto out;
  2363. }
  2364. ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
  2365. &ioc->sense_dma);
  2366. if (!ioc->sense) {
  2367. printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
  2368. ioc->name);
  2369. goto out;
  2370. }
  2371. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
  2372. "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
  2373. "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
  2374. SCSI_SENSE_BUFFERSIZE, sz/1024));
  2375. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
  2376. ioc->name, (unsigned long long)ioc->sense_dma));
  2377. total_sz += sz;
  2378. /* reply pool, 4 byte align */
  2379. sz = ioc->reply_free_queue_depth * ioc->reply_sz;
  2380. ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
  2381. 0);
  2382. if (!ioc->reply_dma_pool) {
  2383. printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
  2384. ioc->name);
  2385. goto out;
  2386. }
  2387. ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
  2388. &ioc->reply_dma);
  2389. if (!ioc->reply) {
  2390. printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
  2391. ioc->name);
  2392. goto out;
  2393. }
  2394. ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
  2395. ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
  2396. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
  2397. "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
  2398. ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
  2399. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
  2400. ioc->name, (unsigned long long)ioc->reply_dma));
  2401. total_sz += sz;
  2402. /* reply free queue, 16 byte align */
  2403. sz = ioc->reply_free_queue_depth * 4;
  2404. ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
  2405. ioc->pdev, sz, 16, 0);
  2406. if (!ioc->reply_free_dma_pool) {
  2407. printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
  2408. "failed\n", ioc->name);
  2409. goto out;
  2410. }
  2411. ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
  2412. &ioc->reply_free_dma);
  2413. if (!ioc->reply_free) {
  2414. printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
  2415. "failed\n", ioc->name);
  2416. goto out;
  2417. }
  2418. memset(ioc->reply_free, 0, sz);
  2419. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
  2420. "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
  2421. ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
  2422. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
  2423. "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
  2424. total_sz += sz;
  2425. /* reply post queue, 16 byte align */
  2426. reply_post_free_sz = ioc->reply_post_queue_depth *
  2427. sizeof(Mpi2DefaultReplyDescriptor_t);
  2428. if (_base_is_controller_msix_enabled(ioc))
  2429. sz = reply_post_free_sz * ioc->reply_queue_count;
  2430. else
  2431. sz = reply_post_free_sz;
  2432. ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
  2433. ioc->pdev, sz, 16, 0);
  2434. if (!ioc->reply_post_free_dma_pool) {
  2435. printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
  2436. "failed\n", ioc->name);
  2437. goto out;
  2438. }
  2439. ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
  2440. GFP_KERNEL, &ioc->reply_post_free_dma);
  2441. if (!ioc->reply_post_free) {
  2442. printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
  2443. "failed\n", ioc->name);
  2444. goto out;
  2445. }
  2446. memset(ioc->reply_post_free, 0, sz);
  2447. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
  2448. "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
  2449. ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
  2450. sz/1024));
  2451. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
  2452. "(0x%llx)\n", ioc->name, (unsigned long long)
  2453. ioc->reply_post_free_dma));
  2454. total_sz += sz;
  2455. ioc->config_page_sz = 512;
  2456. ioc->config_page = pci_alloc_consistent(ioc->pdev,
  2457. ioc->config_page_sz, &ioc->config_page_dma);
  2458. if (!ioc->config_page) {
  2459. printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
  2460. "failed\n", ioc->name);
  2461. goto out;
  2462. }
  2463. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
  2464. "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
  2465. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
  2466. "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
  2467. total_sz += ioc->config_page_sz;
  2468. printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
  2469. ioc->name, total_sz/1024);
  2470. printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
  2471. "Max Controller Queue Depth(%d)\n",
  2472. ioc->name, ioc->shost->can_queue, facts->RequestCredit);
  2473. printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
  2474. ioc->name, ioc->shost->sg_tablesize);
  2475. return 0;
  2476. out:
  2477. return -ENOMEM;
  2478. }
  2479. /**
  2480. * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
  2481. * @ioc: Pointer to MPT_ADAPTER structure
  2482. * @cooked: Request raw or cooked IOC state
  2483. *
  2484. * Returns all IOC Doorbell register bits if cooked==0, else just the
  2485. * Doorbell bits in MPI_IOC_STATE_MASK.
  2486. */
  2487. u32
  2488. mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
  2489. {
  2490. u32 s, sc;
  2491. s = readl(&ioc->chip->Doorbell);
  2492. sc = s & MPI2_IOC_STATE_MASK;
  2493. return cooked ? sc : s;
  2494. }
  2495. /**
  2496. * _base_wait_on_iocstate - waiting on a particular ioc state
  2497. * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
  2498. * @timeout: timeout in second
  2499. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2500. *
  2501. * Returns 0 for success, non-zero for failure.
  2502. */
  2503. static int
  2504. _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
  2505. int sleep_flag)
  2506. {
  2507. u32 count, cntdn;
  2508. u32 current_state;
  2509. count = 0;
  2510. cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
  2511. do {
  2512. current_state = mpt2sas_base_get_iocstate(ioc, 1);
  2513. if (current_state == ioc_state)
  2514. return 0;
  2515. if (count && current_state == MPI2_IOC_STATE_FAULT)
  2516. break;
  2517. if (sleep_flag == CAN_SLEEP)
  2518. msleep(1);
  2519. else
  2520. udelay(500);
  2521. count++;
  2522. } while (--cntdn);
  2523. return current_state;
  2524. }
  2525. /**
  2526. * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
  2527. * a write to the doorbell)
  2528. * @ioc: per adapter object
  2529. * @timeout: timeout in second
  2530. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2531. *
  2532. * Returns 0 for success, non-zero for failure.
  2533. *
  2534. * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
  2535. */
  2536. static int
  2537. _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
  2538. int sleep_flag)
  2539. {
  2540. u32 cntdn, count;
  2541. u32 int_status;
  2542. count = 0;
  2543. cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
  2544. do {
  2545. int_status = readl(&ioc->chip->HostInterruptStatus);
  2546. if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
  2547. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  2548. "successful count(%d), timeout(%d)\n", ioc->name,
  2549. __func__, count, timeout));
  2550. return 0;
  2551. }
  2552. if (sleep_flag == CAN_SLEEP)
  2553. msleep(1);
  2554. else
  2555. udelay(500);
  2556. count++;
  2557. } while (--cntdn);
  2558. printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
  2559. "int_status(%x)!\n", ioc->name, __func__, count, int_status);
  2560. return -EFAULT;
  2561. }
  2562. /**
  2563. * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
  2564. * @ioc: per adapter object
  2565. * @timeout: timeout in second
  2566. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2567. *
  2568. * Returns 0 for success, non-zero for failure.
  2569. *
  2570. * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
  2571. * doorbell.
  2572. */
  2573. static int
  2574. _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
  2575. int sleep_flag)
  2576. {
  2577. u32 cntdn, count;
  2578. u32 int_status;
  2579. u32 doorbell;
  2580. count = 0;
  2581. cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
  2582. do {
  2583. int_status = readl(&ioc->chip->HostInterruptStatus);
  2584. if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
  2585. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  2586. "successful count(%d), timeout(%d)\n", ioc->name,
  2587. __func__, count, timeout));
  2588. return 0;
  2589. } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
  2590. doorbell = readl(&ioc->chip->Doorbell);
  2591. if ((doorbell & MPI2_IOC_STATE_MASK) ==
  2592. MPI2_IOC_STATE_FAULT) {
  2593. mpt2sas_base_fault_info(ioc , doorbell);
  2594. return -EFAULT;
  2595. }
  2596. } else if (int_status == 0xFFFFFFFF)
  2597. goto out;
  2598. if (sleep_flag == CAN_SLEEP)
  2599. msleep(1);
  2600. else
  2601. udelay(500);
  2602. count++;
  2603. } while (--cntdn);
  2604. out:
  2605. printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
  2606. "int_status(%x)!\n", ioc->name, __func__, count, int_status);
  2607. return -EFAULT;
  2608. }
  2609. /**
  2610. * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
  2611. * @ioc: per adapter object
  2612. * @timeout: timeout in second
  2613. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2614. *
  2615. * Returns 0 for success, non-zero for failure.
  2616. *
  2617. */
  2618. static int
  2619. _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
  2620. int sleep_flag)
  2621. {
  2622. u32 cntdn, count;
  2623. u32 doorbell_reg;
  2624. count = 0;
  2625. cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
  2626. do {
  2627. doorbell_reg = readl(&ioc->chip->Doorbell);
  2628. if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
  2629. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  2630. "successful count(%d), timeout(%d)\n", ioc->name,
  2631. __func__, count, timeout));
  2632. return 0;
  2633. }
  2634. if (sleep_flag == CAN_SLEEP)
  2635. msleep(1);
  2636. else
  2637. udelay(500);
  2638. count++;
  2639. } while (--cntdn);
  2640. printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
  2641. "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
  2642. return -EFAULT;
  2643. }
  2644. /**
  2645. * _base_send_ioc_reset - send doorbell reset
  2646. * @ioc: per adapter object
  2647. * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
  2648. * @timeout: timeout in second
  2649. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2650. *
  2651. * Returns 0 for success, non-zero for failure.
  2652. */
  2653. static int
  2654. _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
  2655. int sleep_flag)
  2656. {
  2657. u32 ioc_state;
  2658. int r = 0;
  2659. if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
  2660. printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
  2661. ioc->name, __func__);
  2662. return -EFAULT;
  2663. }
  2664. if (!(ioc->facts.IOCCapabilities &
  2665. MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
  2666. return -EFAULT;
  2667. printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
  2668. writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
  2669. &ioc->chip->Doorbell);
  2670. if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
  2671. r = -EFAULT;
  2672. goto out;
  2673. }
  2674. ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
  2675. timeout, sleep_flag);
  2676. if (ioc_state) {
  2677. printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
  2678. " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
  2679. r = -EFAULT;
  2680. goto out;
  2681. }
  2682. out:
  2683. printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
  2684. ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
  2685. return r;
  2686. }
  2687. /**
  2688. * _base_handshake_req_reply_wait - send request thru doorbell interface
  2689. * @ioc: per adapter object
  2690. * @request_bytes: request length
  2691. * @request: pointer having request payload
  2692. * @reply_bytes: reply length
  2693. * @reply: pointer to reply payload
  2694. * @timeout: timeout in second
  2695. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2696. *
  2697. * Returns 0 for success, non-zero for failure.
  2698. */
  2699. static int
  2700. _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
  2701. u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
  2702. {
  2703. MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
  2704. int i;
  2705. u8 failed;
  2706. u16 dummy;
  2707. __le32 *mfp;
  2708. /* make sure doorbell is not in use */
  2709. if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
  2710. printk(MPT2SAS_ERR_FMT "doorbell is in use "
  2711. " (line=%d)\n", ioc->name, __LINE__);
  2712. return -EFAULT;
  2713. }
  2714. /* clear pending doorbell interrupts from previous state changes */
  2715. if (readl(&ioc->chip->HostInterruptStatus) &
  2716. MPI2_HIS_IOC2SYS_DB_STATUS)
  2717. writel(0, &ioc->chip->HostInterruptStatus);
  2718. /* send message to ioc */
  2719. writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
  2720. ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
  2721. &ioc->chip->Doorbell);
  2722. if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
  2723. printk(MPT2SAS_ERR_FMT "doorbell handshake "
  2724. "int failed (line=%d)\n", ioc->name, __LINE__);
  2725. return -EFAULT;
  2726. }
  2727. writel(0, &ioc->chip->HostInterruptStatus);
  2728. if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
  2729. printk(MPT2SAS_ERR_FMT "doorbell handshake "
  2730. "ack failed (line=%d)\n", ioc->name, __LINE__);
  2731. return -EFAULT;
  2732. }
  2733. /* send message 32-bits at a time */
  2734. for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
  2735. writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
  2736. if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
  2737. failed = 1;
  2738. }
  2739. if (failed) {
  2740. printk(MPT2SAS_ERR_FMT "doorbell handshake "
  2741. "sending request failed (line=%d)\n", ioc->name, __LINE__);
  2742. return -EFAULT;
  2743. }
  2744. /* now wait for the reply */
  2745. if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
  2746. printk(MPT2SAS_ERR_FMT "doorbell handshake "
  2747. "int failed (line=%d)\n", ioc->name, __LINE__);
  2748. return -EFAULT;
  2749. }
  2750. /* read the first two 16-bits, it gives the total length of the reply */
  2751. reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
  2752. & MPI2_DOORBELL_DATA_MASK);
  2753. writel(0, &ioc->chip->HostInterruptStatus);
  2754. if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
  2755. printk(MPT2SAS_ERR_FMT "doorbell handshake "
  2756. "int failed (line=%d)\n", ioc->name, __LINE__);
  2757. return -EFAULT;
  2758. }
  2759. reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
  2760. & MPI2_DOORBELL_DATA_MASK);
  2761. writel(0, &ioc->chip->HostInterruptStatus);
  2762. for (i = 2; i < default_reply->MsgLength * 2; i++) {
  2763. if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
  2764. printk(MPT2SAS_ERR_FMT "doorbell "
  2765. "handshake int failed (line=%d)\n", ioc->name,
  2766. __LINE__);
  2767. return -EFAULT;
  2768. }
  2769. if (i >= reply_bytes/2) /* overflow case */
  2770. dummy = readl(&ioc->chip->Doorbell);
  2771. else
  2772. reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
  2773. & MPI2_DOORBELL_DATA_MASK);
  2774. writel(0, &ioc->chip->HostInterruptStatus);
  2775. }
  2776. _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
  2777. if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
  2778. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
  2779. " (line=%d)\n", ioc->name, __LINE__));
  2780. }
  2781. writel(0, &ioc->chip->HostInterruptStatus);
  2782. if (ioc->logging_level & MPT_DEBUG_INIT) {
  2783. mfp = (__le32 *)reply;
  2784. printk(KERN_INFO "\toffset:data\n");
  2785. for (i = 0; i < reply_bytes/4; i++)
  2786. printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
  2787. le32_to_cpu(mfp[i]));
  2788. }
  2789. return 0;
  2790. }
  2791. /**
  2792. * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
  2793. * @ioc: per adapter object
  2794. * @mpi_reply: the reply payload from FW
  2795. * @mpi_request: the request payload sent to FW
  2796. *
  2797. * The SAS IO Unit Control Request message allows the host to perform low-level
  2798. * operations, such as resets on the PHYs of the IO Unit, also allows the host
  2799. * to obtain the IOC assigned device handles for a device if it has other
  2800. * identifying information about the device, in addition allows the host to
  2801. * remove IOC resources associated with the device.
  2802. *
  2803. * Returns 0 for success, non-zero for failure.
  2804. */
  2805. int
  2806. mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
  2807. Mpi2SasIoUnitControlReply_t *mpi_reply,
  2808. Mpi2SasIoUnitControlRequest_t *mpi_request)
  2809. {
  2810. u16 smid;
  2811. u32 ioc_state;
  2812. unsigned long timeleft;
  2813. u8 issue_reset;
  2814. int rc;
  2815. void *request;
  2816. u16 wait_state_count;
  2817. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  2818. __func__));
  2819. mutex_lock(&ioc->base_cmds.mutex);
  2820. if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
  2821. printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
  2822. ioc->name, __func__);
  2823. rc = -EAGAIN;
  2824. goto out;
  2825. }
  2826. wait_state_count = 0;
  2827. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  2828. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  2829. if (wait_state_count++ == 10) {
  2830. printk(MPT2SAS_ERR_FMT
  2831. "%s: failed due to ioc not operational\n",
  2832. ioc->name, __func__);
  2833. rc = -EFAULT;
  2834. goto out;
  2835. }
  2836. ssleep(1);
  2837. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  2838. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  2839. "operational state(count=%d)\n", ioc->name,
  2840. __func__, wait_state_count);
  2841. }
  2842. smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
  2843. if (!smid) {
  2844. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2845. ioc->name, __func__);
  2846. rc = -EAGAIN;
  2847. goto out;
  2848. }
  2849. rc = 0;
  2850. ioc->base_cmds.status = MPT2_CMD_PENDING;
  2851. request = mpt2sas_base_get_msg_frame(ioc, smid);
  2852. ioc->base_cmds.smid = smid;
  2853. memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
  2854. if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
  2855. mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
  2856. ioc->ioc_link_reset_in_progress = 1;
  2857. init_completion(&ioc->base_cmds.done);
  2858. mpt2sas_base_put_smid_default(ioc, smid);
  2859. timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
  2860. msecs_to_jiffies(10000));
  2861. if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
  2862. mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
  2863. ioc->ioc_link_reset_in_progress)
  2864. ioc->ioc_link_reset_in_progress = 0;
  2865. if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
  2866. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  2867. ioc->name, __func__);
  2868. _debug_dump_mf(mpi_request,
  2869. sizeof(Mpi2SasIoUnitControlRequest_t)/4);
  2870. if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
  2871. issue_reset = 1;
  2872. goto issue_host_reset;
  2873. }
  2874. if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
  2875. memcpy(mpi_reply, ioc->base_cmds.reply,
  2876. sizeof(Mpi2SasIoUnitControlReply_t));
  2877. else
  2878. memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
  2879. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  2880. goto out;
  2881. issue_host_reset:
  2882. if (issue_reset)
  2883. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  2884. FORCE_BIG_HAMMER);
  2885. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  2886. rc = -EFAULT;
  2887. out:
  2888. mutex_unlock(&ioc->base_cmds.mutex);
  2889. return rc;
  2890. }
  2891. /**
  2892. * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
  2893. * @ioc: per adapter object
  2894. * @mpi_reply: the reply payload from FW
  2895. * @mpi_request: the request payload sent to FW
  2896. *
  2897. * The SCSI Enclosure Processor request message causes the IOC to
  2898. * communicate with SES devices to control LED status signals.
  2899. *
  2900. * Returns 0 for success, non-zero for failure.
  2901. */
  2902. int
  2903. mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
  2904. Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
  2905. {
  2906. u16 smid;
  2907. u32 ioc_state;
  2908. unsigned long timeleft;
  2909. u8 issue_reset;
  2910. int rc;
  2911. void *request;
  2912. u16 wait_state_count;
  2913. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  2914. __func__));
  2915. mutex_lock(&ioc->base_cmds.mutex);
  2916. if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
  2917. printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
  2918. ioc->name, __func__);
  2919. rc = -EAGAIN;
  2920. goto out;
  2921. }
  2922. wait_state_count = 0;
  2923. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  2924. while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  2925. if (wait_state_count++ == 10) {
  2926. printk(MPT2SAS_ERR_FMT
  2927. "%s: failed due to ioc not operational\n",
  2928. ioc->name, __func__);
  2929. rc = -EFAULT;
  2930. goto out;
  2931. }
  2932. ssleep(1);
  2933. ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
  2934. printk(MPT2SAS_INFO_FMT "%s: waiting for "
  2935. "operational state(count=%d)\n", ioc->name,
  2936. __func__, wait_state_count);
  2937. }
  2938. smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
  2939. if (!smid) {
  2940. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2941. ioc->name, __func__);
  2942. rc = -EAGAIN;
  2943. goto out;
  2944. }
  2945. rc = 0;
  2946. ioc->base_cmds.status = MPT2_CMD_PENDING;
  2947. request = mpt2sas_base_get_msg_frame(ioc, smid);
  2948. ioc->base_cmds.smid = smid;
  2949. memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
  2950. init_completion(&ioc->base_cmds.done);
  2951. mpt2sas_base_put_smid_default(ioc, smid);
  2952. timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
  2953. msecs_to_jiffies(10000));
  2954. if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
  2955. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  2956. ioc->name, __func__);
  2957. _debug_dump_mf(mpi_request,
  2958. sizeof(Mpi2SepRequest_t)/4);
  2959. if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
  2960. issue_reset = 1;
  2961. goto issue_host_reset;
  2962. }
  2963. if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
  2964. memcpy(mpi_reply, ioc->base_cmds.reply,
  2965. sizeof(Mpi2SepReply_t));
  2966. else
  2967. memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
  2968. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  2969. goto out;
  2970. issue_host_reset:
  2971. if (issue_reset)
  2972. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  2973. FORCE_BIG_HAMMER);
  2974. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  2975. rc = -EFAULT;
  2976. out:
  2977. mutex_unlock(&ioc->base_cmds.mutex);
  2978. return rc;
  2979. }
  2980. /**
  2981. * _base_get_port_facts - obtain port facts reply and save in ioc
  2982. * @ioc: per adapter object
  2983. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  2984. *
  2985. * Returns 0 for success, non-zero for failure.
  2986. */
  2987. static int
  2988. _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
  2989. {
  2990. Mpi2PortFactsRequest_t mpi_request;
  2991. Mpi2PortFactsReply_t mpi_reply;
  2992. struct mpt2sas_port_facts *pfacts;
  2993. int mpi_reply_sz, mpi_request_sz, r;
  2994. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  2995. __func__));
  2996. mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
  2997. mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
  2998. memset(&mpi_request, 0, mpi_request_sz);
  2999. mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
  3000. mpi_request.PortNumber = port;
  3001. r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
  3002. (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
  3003. if (r != 0) {
  3004. printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
  3005. ioc->name, __func__, r);
  3006. return r;
  3007. }
  3008. pfacts = &ioc->pfacts[port];
  3009. memset(pfacts, 0, sizeof(struct mpt2sas_port_facts));
  3010. pfacts->PortNumber = mpi_reply.PortNumber;
  3011. pfacts->VP_ID = mpi_reply.VP_ID;
  3012. pfacts->VF_ID = mpi_reply.VF_ID;
  3013. pfacts->MaxPostedCmdBuffers =
  3014. le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
  3015. return 0;
  3016. }
  3017. /**
  3018. * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
  3019. * @ioc: per adapter object
  3020. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  3021. *
  3022. * Returns 0 for success, non-zero for failure.
  3023. */
  3024. static int
  3025. _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  3026. {
  3027. Mpi2IOCFactsRequest_t mpi_request;
  3028. Mpi2IOCFactsReply_t mpi_reply;
  3029. struct mpt2sas_facts *facts;
  3030. int mpi_reply_sz, mpi_request_sz, r;
  3031. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3032. __func__));
  3033. mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
  3034. mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
  3035. memset(&mpi_request, 0, mpi_request_sz);
  3036. mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
  3037. r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
  3038. (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
  3039. if (r != 0) {
  3040. printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
  3041. ioc->name, __func__, r);
  3042. return r;
  3043. }
  3044. facts = &ioc->facts;
  3045. memset(facts, 0, sizeof(struct mpt2sas_facts));
  3046. facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
  3047. facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
  3048. facts->VP_ID = mpi_reply.VP_ID;
  3049. facts->VF_ID = mpi_reply.VF_ID;
  3050. facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
  3051. facts->MaxChainDepth = mpi_reply.MaxChainDepth;
  3052. facts->WhoInit = mpi_reply.WhoInit;
  3053. facts->NumberOfPorts = mpi_reply.NumberOfPorts;
  3054. facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
  3055. facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
  3056. facts->MaxReplyDescriptorPostQueueDepth =
  3057. le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
  3058. facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
  3059. facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
  3060. if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
  3061. ioc->ir_firmware = 1;
  3062. facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
  3063. facts->IOCRequestFrameSize =
  3064. le16_to_cpu(mpi_reply.IOCRequestFrameSize);
  3065. facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
  3066. facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
  3067. ioc->shost->max_id = -1;
  3068. facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
  3069. facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
  3070. facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
  3071. facts->HighPriorityCredit =
  3072. le16_to_cpu(mpi_reply.HighPriorityCredit);
  3073. facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
  3074. facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
  3075. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
  3076. "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
  3077. facts->MaxChainDepth));
  3078. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
  3079. "reply frame size(%d)\n", ioc->name,
  3080. facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
  3081. return 0;
  3082. }
  3083. /**
  3084. * _base_send_ioc_init - send ioc_init to firmware
  3085. * @ioc: per adapter object
  3086. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  3087. *
  3088. * Returns 0 for success, non-zero for failure.
  3089. */
  3090. static int
  3091. _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  3092. {
  3093. Mpi2IOCInitRequest_t mpi_request;
  3094. Mpi2IOCInitReply_t mpi_reply;
  3095. int r;
  3096. struct timeval current_time;
  3097. u16 ioc_status;
  3098. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3099. __func__));
  3100. memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
  3101. mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
  3102. mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
  3103. mpi_request.VF_ID = 0; /* TODO */
  3104. mpi_request.VP_ID = 0;
  3105. mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
  3106. mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
  3107. if (_base_is_controller_msix_enabled(ioc))
  3108. mpi_request.HostMSIxVectors = ioc->reply_queue_count;
  3109. mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
  3110. mpi_request.ReplyDescriptorPostQueueDepth =
  3111. cpu_to_le16(ioc->reply_post_queue_depth);
  3112. mpi_request.ReplyFreeQueueDepth =
  3113. cpu_to_le16(ioc->reply_free_queue_depth);
  3114. mpi_request.SenseBufferAddressHigh =
  3115. cpu_to_le32((u64)ioc->sense_dma >> 32);
  3116. mpi_request.SystemReplyAddressHigh =
  3117. cpu_to_le32((u64)ioc->reply_dma >> 32);
  3118. mpi_request.SystemRequestFrameBaseAddress =
  3119. cpu_to_le64((u64)ioc->request_dma);
  3120. mpi_request.ReplyFreeQueueAddress =
  3121. cpu_to_le64((u64)ioc->reply_free_dma);
  3122. mpi_request.ReplyDescriptorPostQueueAddress =
  3123. cpu_to_le64((u64)ioc->reply_post_free_dma);
  3124. /* This time stamp specifies number of milliseconds
  3125. * since epoch ~ midnight January 1, 1970.
  3126. */
  3127. do_gettimeofday(&current_time);
  3128. mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
  3129. (current_time.tv_usec / 1000));
  3130. if (ioc->logging_level & MPT_DEBUG_INIT) {
  3131. __le32 *mfp;
  3132. int i;
  3133. mfp = (__le32 *)&mpi_request;
  3134. printk(KERN_INFO "\toffset:data\n");
  3135. for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
  3136. printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
  3137. le32_to_cpu(mfp[i]));
  3138. }
  3139. r = _base_handshake_req_reply_wait(ioc,
  3140. sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
  3141. sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
  3142. sleep_flag);
  3143. if (r != 0) {
  3144. printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
  3145. ioc->name, __func__, r);
  3146. return r;
  3147. }
  3148. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  3149. if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
  3150. mpi_reply.IOCLogInfo) {
  3151. printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
  3152. r = -EIO;
  3153. }
  3154. return 0;
  3155. }
  3156. /**
  3157. * mpt2sas_port_enable_done - command completion routine for port enable
  3158. * @ioc: per adapter object
  3159. * @smid: system request message index
  3160. * @msix_index: MSIX table index supplied by the OS
  3161. * @reply: reply message frame(lower 32bit addr)
  3162. *
  3163. * Return 1 meaning mf should be freed from _base_interrupt
  3164. * 0 means the mf is freed from this function.
  3165. */
  3166. u8
  3167. mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  3168. u32 reply)
  3169. {
  3170. MPI2DefaultReply_t *mpi_reply;
  3171. u16 ioc_status;
  3172. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  3173. if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
  3174. return 1;
  3175. if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
  3176. return 1;
  3177. ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
  3178. if (mpi_reply) {
  3179. ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
  3180. memcpy(ioc->port_enable_cmds.reply, mpi_reply,
  3181. mpi_reply->MsgLength*4);
  3182. }
  3183. ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
  3184. ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
  3185. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  3186. ioc->port_enable_failed = 1;
  3187. if (ioc->is_driver_loading) {
  3188. if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
  3189. mpt2sas_port_enable_complete(ioc);
  3190. return 1;
  3191. } else {
  3192. ioc->start_scan_failed = ioc_status;
  3193. ioc->start_scan = 0;
  3194. return 1;
  3195. }
  3196. }
  3197. complete(&ioc->port_enable_cmds.done);
  3198. return 1;
  3199. }
  3200. /**
  3201. * _base_send_port_enable - send port_enable(discovery stuff) to firmware
  3202. * @ioc: per adapter object
  3203. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  3204. *
  3205. * Returns 0 for success, non-zero for failure.
  3206. */
  3207. static int
  3208. _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  3209. {
  3210. Mpi2PortEnableRequest_t *mpi_request;
  3211. Mpi2PortEnableReply_t *mpi_reply;
  3212. unsigned long timeleft;
  3213. int r = 0;
  3214. u16 smid;
  3215. u16 ioc_status;
  3216. printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
  3217. if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
  3218. printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
  3219. ioc->name, __func__);
  3220. return -EAGAIN;
  3221. }
  3222. smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
  3223. if (!smid) {
  3224. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  3225. ioc->name, __func__);
  3226. return -EAGAIN;
  3227. }
  3228. ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
  3229. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  3230. ioc->port_enable_cmds.smid = smid;
  3231. memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
  3232. mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
  3233. init_completion(&ioc->port_enable_cmds.done);
  3234. mpt2sas_base_put_smid_default(ioc, smid);
  3235. timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
  3236. 300*HZ);
  3237. if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
  3238. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  3239. ioc->name, __func__);
  3240. _debug_dump_mf(mpi_request,
  3241. sizeof(Mpi2PortEnableRequest_t)/4);
  3242. if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
  3243. r = -EFAULT;
  3244. else
  3245. r = -ETIME;
  3246. goto out;
  3247. }
  3248. mpi_reply = ioc->port_enable_cmds.reply;
  3249. ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
  3250. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3251. printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
  3252. ioc->name, __func__, ioc_status);
  3253. r = -EFAULT;
  3254. goto out;
  3255. }
  3256. out:
  3257. ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
  3258. printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
  3259. "SUCCESS" : "FAILED"));
  3260. return r;
  3261. }
  3262. /**
  3263. * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
  3264. * @ioc: per adapter object
  3265. *
  3266. * Returns 0 for success, non-zero for failure.
  3267. */
  3268. int
  3269. mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
  3270. {
  3271. Mpi2PortEnableRequest_t *mpi_request;
  3272. u16 smid;
  3273. printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
  3274. if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
  3275. printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
  3276. ioc->name, __func__);
  3277. return -EAGAIN;
  3278. }
  3279. smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
  3280. if (!smid) {
  3281. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  3282. ioc->name, __func__);
  3283. return -EAGAIN;
  3284. }
  3285. ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
  3286. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  3287. ioc->port_enable_cmds.smid = smid;
  3288. memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
  3289. mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
  3290. mpt2sas_base_put_smid_default(ioc, smid);
  3291. return 0;
  3292. }
  3293. /**
  3294. * _base_determine_wait_on_discovery - desposition
  3295. * @ioc: per adapter object
  3296. *
  3297. * Decide whether to wait on discovery to complete. Used to either
  3298. * locate boot device, or report volumes ahead of physical devices.
  3299. *
  3300. * Returns 1 for wait, 0 for don't wait
  3301. */
  3302. static int
  3303. _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
  3304. {
  3305. /* We wait for discovery to complete if IR firmware is loaded.
  3306. * The sas topology events arrive before PD events, so we need time to
  3307. * turn on the bit in ioc->pd_handles to indicate PD
  3308. * Also, it maybe required to report Volumes ahead of physical
  3309. * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
  3310. */
  3311. if (ioc->ir_firmware)
  3312. return 1;
  3313. /* if no Bios, then we don't need to wait */
  3314. if (!ioc->bios_pg3.BiosVersion)
  3315. return 0;
  3316. /* Bios is present, then we drop down here.
  3317. *
  3318. * If there any entries in the Bios Page 2, then we wait
  3319. * for discovery to complete.
  3320. */
  3321. /* Current Boot Device */
  3322. if ((ioc->bios_pg2.CurrentBootDeviceForm &
  3323. MPI2_BIOSPAGE2_FORM_MASK) ==
  3324. MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
  3325. /* Request Boot Device */
  3326. (ioc->bios_pg2.ReqBootDeviceForm &
  3327. MPI2_BIOSPAGE2_FORM_MASK) ==
  3328. MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
  3329. /* Alternate Request Boot Device */
  3330. (ioc->bios_pg2.ReqAltBootDeviceForm &
  3331. MPI2_BIOSPAGE2_FORM_MASK) ==
  3332. MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
  3333. return 0;
  3334. return 1;
  3335. }
  3336. /**
  3337. * _base_unmask_events - turn on notification for this event
  3338. * @ioc: per adapter object
  3339. * @event: firmware event
  3340. *
  3341. * The mask is stored in ioc->event_masks.
  3342. */
  3343. static void
  3344. _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
  3345. {
  3346. u32 desired_event;
  3347. if (event >= 128)
  3348. return;
  3349. desired_event = (1 << (event % 32));
  3350. if (event < 32)
  3351. ioc->event_masks[0] &= ~desired_event;
  3352. else if (event < 64)
  3353. ioc->event_masks[1] &= ~desired_event;
  3354. else if (event < 96)
  3355. ioc->event_masks[2] &= ~desired_event;
  3356. else if (event < 128)
  3357. ioc->event_masks[3] &= ~desired_event;
  3358. }
  3359. /**
  3360. * _base_event_notification - send event notification
  3361. * @ioc: per adapter object
  3362. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  3363. *
  3364. * Returns 0 for success, non-zero for failure.
  3365. */
  3366. static int
  3367. _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  3368. {
  3369. Mpi2EventNotificationRequest_t *mpi_request;
  3370. unsigned long timeleft;
  3371. u16 smid;
  3372. int r = 0;
  3373. int i;
  3374. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3375. __func__));
  3376. if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
  3377. printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
  3378. ioc->name, __func__);
  3379. return -EAGAIN;
  3380. }
  3381. smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
  3382. if (!smid) {
  3383. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  3384. ioc->name, __func__);
  3385. return -EAGAIN;
  3386. }
  3387. ioc->base_cmds.status = MPT2_CMD_PENDING;
  3388. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  3389. ioc->base_cmds.smid = smid;
  3390. memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
  3391. mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
  3392. mpi_request->VF_ID = 0; /* TODO */
  3393. mpi_request->VP_ID = 0;
  3394. for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
  3395. mpi_request->EventMasks[i] =
  3396. cpu_to_le32(ioc->event_masks[i]);
  3397. init_completion(&ioc->base_cmds.done);
  3398. mpt2sas_base_put_smid_default(ioc, smid);
  3399. timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
  3400. if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
  3401. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  3402. ioc->name, __func__);
  3403. _debug_dump_mf(mpi_request,
  3404. sizeof(Mpi2EventNotificationRequest_t)/4);
  3405. if (ioc->base_cmds.status & MPT2_CMD_RESET)
  3406. r = -EFAULT;
  3407. else
  3408. r = -ETIME;
  3409. } else
  3410. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
  3411. ioc->name, __func__));
  3412. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  3413. return r;
  3414. }
  3415. /**
  3416. * mpt2sas_base_validate_event_type - validating event types
  3417. * @ioc: per adapter object
  3418. * @event: firmware event
  3419. *
  3420. * This will turn on firmware event notification when application
  3421. * ask for that event. We don't mask events that are already enabled.
  3422. */
  3423. void
  3424. mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
  3425. {
  3426. int i, j;
  3427. u32 event_mask, desired_event;
  3428. u8 send_update_to_fw;
  3429. for (i = 0, send_update_to_fw = 0; i <
  3430. MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
  3431. event_mask = ~event_type[i];
  3432. desired_event = 1;
  3433. for (j = 0; j < 32; j++) {
  3434. if (!(event_mask & desired_event) &&
  3435. (ioc->event_masks[i] & desired_event)) {
  3436. ioc->event_masks[i] &= ~desired_event;
  3437. send_update_to_fw = 1;
  3438. }
  3439. desired_event = (desired_event << 1);
  3440. }
  3441. }
  3442. if (!send_update_to_fw)
  3443. return;
  3444. mutex_lock(&ioc->base_cmds.mutex);
  3445. _base_event_notification(ioc, CAN_SLEEP);
  3446. mutex_unlock(&ioc->base_cmds.mutex);
  3447. }
  3448. /**
  3449. * _base_diag_reset - the "big hammer" start of day reset
  3450. * @ioc: per adapter object
  3451. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  3452. *
  3453. * Returns 0 for success, non-zero for failure.
  3454. */
  3455. static int
  3456. _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  3457. {
  3458. u32 host_diagnostic;
  3459. u32 ioc_state;
  3460. u32 count;
  3461. u32 hcb_size;
  3462. printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
  3463. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
  3464. ioc->name));
  3465. count = 0;
  3466. do {
  3467. /* Write magic sequence to WriteSequence register
  3468. * Loop until in diagnostic mode
  3469. */
  3470. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
  3471. "sequence\n", ioc->name));
  3472. writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
  3473. writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
  3474. writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
  3475. writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
  3476. writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
  3477. writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
  3478. writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
  3479. /* wait 100 msec */
  3480. if (sleep_flag == CAN_SLEEP)
  3481. msleep(100);
  3482. else
  3483. mdelay(100);
  3484. if (count++ > 20)
  3485. goto out;
  3486. host_diagnostic = readl(&ioc->chip->HostDiagnostic);
  3487. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
  3488. "sequence: count(%d), host_diagnostic(0x%08x)\n",
  3489. ioc->name, count, host_diagnostic));
  3490. } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
  3491. hcb_size = readl(&ioc->chip->HCBSize);
  3492. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
  3493. ioc->name));
  3494. writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
  3495. &ioc->chip->HostDiagnostic);
  3496. /* don't access any registers for 50 milliseconds */
  3497. msleep(50);
  3498. /* 300 second max wait */
  3499. for (count = 0; count < 3000000 ; count++) {
  3500. host_diagnostic = readl(&ioc->chip->HostDiagnostic);
  3501. if (host_diagnostic == 0xFFFFFFFF)
  3502. goto out;
  3503. if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
  3504. break;
  3505. /* wait 100 msec */
  3506. if (sleep_flag == CAN_SLEEP)
  3507. msleep(1);
  3508. else
  3509. mdelay(1);
  3510. }
  3511. if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
  3512. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
  3513. "assuming the HCB Address points to good F/W\n",
  3514. ioc->name));
  3515. host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
  3516. host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
  3517. writel(host_diagnostic, &ioc->chip->HostDiagnostic);
  3518. drsprintk(ioc, printk(MPT2SAS_INFO_FMT
  3519. "re-enable the HCDW\n", ioc->name));
  3520. writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
  3521. &ioc->chip->HCBSize);
  3522. }
  3523. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
  3524. ioc->name));
  3525. writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
  3526. &ioc->chip->HostDiagnostic);
  3527. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
  3528. "diagnostic register\n", ioc->name));
  3529. writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
  3530. drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
  3531. "READY state\n", ioc->name));
  3532. ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
  3533. sleep_flag);
  3534. if (ioc_state) {
  3535. printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
  3536. " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
  3537. goto out;
  3538. }
  3539. printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
  3540. return 0;
  3541. out:
  3542. printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
  3543. return -EFAULT;
  3544. }
  3545. /**
  3546. * _base_make_ioc_ready - put controller in READY state
  3547. * @ioc: per adapter object
  3548. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  3549. * @type: FORCE_BIG_HAMMER or SOFT_RESET
  3550. *
  3551. * Returns 0 for success, non-zero for failure.
  3552. */
  3553. static int
  3554. _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
  3555. enum reset_type type)
  3556. {
  3557. u32 ioc_state;
  3558. int rc;
  3559. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3560. __func__));
  3561. if (ioc->pci_error_recovery)
  3562. return 0;
  3563. ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
  3564. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
  3565. ioc->name, __func__, ioc_state));
  3566. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
  3567. return 0;
  3568. if (ioc_state & MPI2_DOORBELL_USED) {
  3569. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
  3570. "active!\n", ioc->name));
  3571. goto issue_diag_reset;
  3572. }
  3573. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  3574. mpt2sas_base_fault_info(ioc, ioc_state &
  3575. MPI2_DOORBELL_DATA_MASK);
  3576. goto issue_diag_reset;
  3577. }
  3578. if (type == FORCE_BIG_HAMMER)
  3579. goto issue_diag_reset;
  3580. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
  3581. if (!(_base_send_ioc_reset(ioc,
  3582. MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
  3583. ioc->ioc_reset_count++;
  3584. return 0;
  3585. }
  3586. issue_diag_reset:
  3587. rc = _base_diag_reset(ioc, CAN_SLEEP);
  3588. ioc->ioc_reset_count++;
  3589. return rc;
  3590. }
  3591. /**
  3592. * _base_make_ioc_operational - put controller in OPERATIONAL state
  3593. * @ioc: per adapter object
  3594. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  3595. *
  3596. * Returns 0 for success, non-zero for failure.
  3597. */
  3598. static int
  3599. _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  3600. {
  3601. int r, i;
  3602. unsigned long flags;
  3603. u32 reply_address;
  3604. u16 smid;
  3605. struct _tr_list *delayed_tr, *delayed_tr_next;
  3606. u8 hide_flag;
  3607. struct adapter_reply_queue *reply_q;
  3608. long reply_post_free;
  3609. u32 reply_post_free_sz;
  3610. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3611. __func__));
  3612. /* clean the delayed target reset list */
  3613. list_for_each_entry_safe(delayed_tr, delayed_tr_next,
  3614. &ioc->delayed_tr_list, list) {
  3615. list_del(&delayed_tr->list);
  3616. kfree(delayed_tr);
  3617. }
  3618. list_for_each_entry_safe(delayed_tr, delayed_tr_next,
  3619. &ioc->delayed_tr_volume_list, list) {
  3620. list_del(&delayed_tr->list);
  3621. kfree(delayed_tr);
  3622. }
  3623. /* initialize the scsi lookup free list */
  3624. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  3625. INIT_LIST_HEAD(&ioc->free_list);
  3626. smid = 1;
  3627. for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
  3628. INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
  3629. ioc->scsi_lookup[i].cb_idx = 0xFF;
  3630. ioc->scsi_lookup[i].smid = smid;
  3631. ioc->scsi_lookup[i].scmd = NULL;
  3632. ioc->scsi_lookup[i].direct_io = 0;
  3633. list_add_tail(&ioc->scsi_lookup[i].tracker_list,
  3634. &ioc->free_list);
  3635. }
  3636. /* hi-priority queue */
  3637. INIT_LIST_HEAD(&ioc->hpr_free_list);
  3638. smid = ioc->hi_priority_smid;
  3639. for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
  3640. ioc->hpr_lookup[i].cb_idx = 0xFF;
  3641. ioc->hpr_lookup[i].smid = smid;
  3642. list_add_tail(&ioc->hpr_lookup[i].tracker_list,
  3643. &ioc->hpr_free_list);
  3644. }
  3645. /* internal queue */
  3646. INIT_LIST_HEAD(&ioc->internal_free_list);
  3647. smid = ioc->internal_smid;
  3648. for (i = 0; i < ioc->internal_depth; i++, smid++) {
  3649. ioc->internal_lookup[i].cb_idx = 0xFF;
  3650. ioc->internal_lookup[i].smid = smid;
  3651. list_add_tail(&ioc->internal_lookup[i].tracker_list,
  3652. &ioc->internal_free_list);
  3653. }
  3654. /* chain pool */
  3655. INIT_LIST_HEAD(&ioc->free_chain_list);
  3656. for (i = 0; i < ioc->chain_depth; i++)
  3657. list_add_tail(&ioc->chain_lookup[i].tracker_list,
  3658. &ioc->free_chain_list);
  3659. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  3660. /* initialize Reply Free Queue */
  3661. for (i = 0, reply_address = (u32)ioc->reply_dma ;
  3662. i < ioc->reply_free_queue_depth ; i++, reply_address +=
  3663. ioc->reply_sz)
  3664. ioc->reply_free[i] = cpu_to_le32(reply_address);
  3665. /* initialize reply queues */
  3666. if (ioc->is_driver_loading)
  3667. _base_assign_reply_queues(ioc);
  3668. /* initialize Reply Post Free Queue */
  3669. reply_post_free = (long)ioc->reply_post_free;
  3670. reply_post_free_sz = ioc->reply_post_queue_depth *
  3671. sizeof(Mpi2DefaultReplyDescriptor_t);
  3672. list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
  3673. reply_q->reply_post_host_index = 0;
  3674. reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
  3675. reply_post_free;
  3676. for (i = 0; i < ioc->reply_post_queue_depth; i++)
  3677. reply_q->reply_post_free[i].Words =
  3678. cpu_to_le64(ULLONG_MAX);
  3679. if (!_base_is_controller_msix_enabled(ioc))
  3680. goto skip_init_reply_post_free_queue;
  3681. reply_post_free += reply_post_free_sz;
  3682. }
  3683. skip_init_reply_post_free_queue:
  3684. r = _base_send_ioc_init(ioc, sleep_flag);
  3685. if (r)
  3686. return r;
  3687. /* initialize reply free host index */
  3688. ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
  3689. writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
  3690. /* initialize reply post host index */
  3691. list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
  3692. writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
  3693. &ioc->chip->ReplyPostHostIndex);
  3694. if (!_base_is_controller_msix_enabled(ioc))
  3695. goto skip_init_reply_post_host_index;
  3696. }
  3697. skip_init_reply_post_host_index:
  3698. _base_unmask_interrupts(ioc);
  3699. r = _base_event_notification(ioc, sleep_flag);
  3700. if (r)
  3701. return r;
  3702. if (sleep_flag == CAN_SLEEP)
  3703. _base_static_config_pages(ioc);
  3704. if (ioc->is_driver_loading) {
  3705. if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier
  3706. == 0x80) {
  3707. hide_flag = (u8) (
  3708. le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) &
  3709. MFG_PAGE10_HIDE_SSDS_MASK);
  3710. if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
  3711. ioc->mfg_pg10_hide_flag = hide_flag;
  3712. }
  3713. ioc->wait_for_discovery_to_complete =
  3714. _base_determine_wait_on_discovery(ioc);
  3715. return r; /* scan_start and scan_finished support */
  3716. }
  3717. r = _base_send_port_enable(ioc, sleep_flag);
  3718. if (r)
  3719. return r;
  3720. return r;
  3721. }
  3722. /**
  3723. * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
  3724. * @ioc: per adapter object
  3725. *
  3726. * Return nothing.
  3727. */
  3728. void
  3729. mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
  3730. {
  3731. struct pci_dev *pdev = ioc->pdev;
  3732. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3733. __func__));
  3734. _base_mask_interrupts(ioc);
  3735. ioc->shost_recovery = 1;
  3736. _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
  3737. ioc->shost_recovery = 0;
  3738. _base_free_irq(ioc);
  3739. _base_disable_msix(ioc);
  3740. if (ioc->chip_phys)
  3741. iounmap(ioc->chip);
  3742. ioc->chip_phys = 0;
  3743. pci_release_selected_regions(ioc->pdev, ioc->bars);
  3744. pci_disable_pcie_error_reporting(pdev);
  3745. pci_disable_device(pdev);
  3746. return;
  3747. }
  3748. /**
  3749. * mpt2sas_base_attach - attach controller instance
  3750. * @ioc: per adapter object
  3751. *
  3752. * Returns 0 for success, non-zero for failure.
  3753. */
  3754. int
  3755. mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
  3756. {
  3757. int r, i;
  3758. int cpu_id, last_cpu_id = 0;
  3759. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3760. __func__));
  3761. /* setup cpu_msix_table */
  3762. ioc->cpu_count = num_online_cpus();
  3763. for_each_online_cpu(cpu_id)
  3764. last_cpu_id = cpu_id;
  3765. ioc->cpu_msix_table_sz = last_cpu_id + 1;
  3766. ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
  3767. ioc->reply_queue_count = 1;
  3768. if (!ioc->cpu_msix_table) {
  3769. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
  3770. "cpu_msix_table failed!!!\n", ioc->name));
  3771. r = -ENOMEM;
  3772. goto out_free_resources;
  3773. }
  3774. if (ioc->is_warpdrive) {
  3775. ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
  3776. sizeof(resource_size_t *), GFP_KERNEL);
  3777. if (!ioc->reply_post_host_index) {
  3778. dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
  3779. "for cpu_msix_table failed!!!\n", ioc->name));
  3780. r = -ENOMEM;
  3781. goto out_free_resources;
  3782. }
  3783. }
  3784. r = mpt2sas_base_map_resources(ioc);
  3785. if (r)
  3786. goto out_free_resources;
  3787. if (ioc->is_warpdrive) {
  3788. ioc->reply_post_host_index[0] =
  3789. (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
  3790. for (i = 1; i < ioc->cpu_msix_table_sz; i++)
  3791. ioc->reply_post_host_index[i] = (resource_size_t *)
  3792. ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
  3793. * 4)));
  3794. }
  3795. pci_set_drvdata(ioc->pdev, ioc->shost);
  3796. r = _base_get_ioc_facts(ioc, CAN_SLEEP);
  3797. if (r)
  3798. goto out_free_resources;
  3799. r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
  3800. if (r)
  3801. goto out_free_resources;
  3802. ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
  3803. sizeof(struct mpt2sas_port_facts), GFP_KERNEL);
  3804. if (!ioc->pfacts) {
  3805. r = -ENOMEM;
  3806. goto out_free_resources;
  3807. }
  3808. for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
  3809. r = _base_get_port_facts(ioc, i, CAN_SLEEP);
  3810. if (r)
  3811. goto out_free_resources;
  3812. }
  3813. r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
  3814. if (r)
  3815. goto out_free_resources;
  3816. init_waitqueue_head(&ioc->reset_wq);
  3817. /* allocate memory pd handle bitmask list */
  3818. ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
  3819. if (ioc->facts.MaxDevHandle % 8)
  3820. ioc->pd_handles_sz++;
  3821. ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
  3822. GFP_KERNEL);
  3823. if (!ioc->pd_handles) {
  3824. r = -ENOMEM;
  3825. goto out_free_resources;
  3826. }
  3827. ioc->blocking_handles = kzalloc(ioc->pd_handles_sz,
  3828. GFP_KERNEL);
  3829. if (!ioc->blocking_handles) {
  3830. r = -ENOMEM;
  3831. goto out_free_resources;
  3832. }
  3833. ioc->fwfault_debug = mpt2sas_fwfault_debug;
  3834. /* base internal command bits */
  3835. mutex_init(&ioc->base_cmds.mutex);
  3836. ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
  3837. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  3838. /* port_enable command bits */
  3839. ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
  3840. ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
  3841. /* transport internal command bits */
  3842. ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
  3843. ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
  3844. mutex_init(&ioc->transport_cmds.mutex);
  3845. /* scsih internal command bits */
  3846. ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
  3847. ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
  3848. mutex_init(&ioc->scsih_cmds.mutex);
  3849. /* task management internal command bits */
  3850. ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
  3851. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  3852. mutex_init(&ioc->tm_cmds.mutex);
  3853. /* config page internal command bits */
  3854. ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
  3855. ioc->config_cmds.status = MPT2_CMD_NOT_USED;
  3856. mutex_init(&ioc->config_cmds.mutex);
  3857. /* ctl module internal command bits */
  3858. ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
  3859. ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
  3860. ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
  3861. mutex_init(&ioc->ctl_cmds.mutex);
  3862. if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
  3863. !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
  3864. !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
  3865. !ioc->ctl_cmds.sense) {
  3866. r = -ENOMEM;
  3867. goto out_free_resources;
  3868. }
  3869. if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
  3870. !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
  3871. !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
  3872. r = -ENOMEM;
  3873. goto out_free_resources;
  3874. }
  3875. for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
  3876. ioc->event_masks[i] = -1;
  3877. /* here we enable the events we care about */
  3878. _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
  3879. _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
  3880. _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
  3881. _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
  3882. _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
  3883. _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
  3884. _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
  3885. _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
  3886. _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
  3887. _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
  3888. r = _base_make_ioc_operational(ioc, CAN_SLEEP);
  3889. if (r)
  3890. goto out_free_resources;
  3891. if (missing_delay[0] != -1 && missing_delay[1] != -1)
  3892. _base_update_missing_delay(ioc, missing_delay[0],
  3893. missing_delay[1]);
  3894. return 0;
  3895. out_free_resources:
  3896. ioc->remove_host = 1;
  3897. mpt2sas_base_free_resources(ioc);
  3898. _base_release_memory_pools(ioc);
  3899. pci_set_drvdata(ioc->pdev, NULL);
  3900. kfree(ioc->cpu_msix_table);
  3901. if (ioc->is_warpdrive)
  3902. kfree(ioc->reply_post_host_index);
  3903. kfree(ioc->pd_handles);
  3904. kfree(ioc->blocking_handles);
  3905. kfree(ioc->tm_cmds.reply);
  3906. kfree(ioc->transport_cmds.reply);
  3907. kfree(ioc->scsih_cmds.reply);
  3908. kfree(ioc->config_cmds.reply);
  3909. kfree(ioc->base_cmds.reply);
  3910. kfree(ioc->port_enable_cmds.reply);
  3911. kfree(ioc->ctl_cmds.reply);
  3912. kfree(ioc->ctl_cmds.sense);
  3913. kfree(ioc->pfacts);
  3914. ioc->ctl_cmds.reply = NULL;
  3915. ioc->base_cmds.reply = NULL;
  3916. ioc->tm_cmds.reply = NULL;
  3917. ioc->scsih_cmds.reply = NULL;
  3918. ioc->transport_cmds.reply = NULL;
  3919. ioc->config_cmds.reply = NULL;
  3920. ioc->pfacts = NULL;
  3921. return r;
  3922. }
  3923. /**
  3924. * mpt2sas_base_detach - remove controller instance
  3925. * @ioc: per adapter object
  3926. *
  3927. * Return nothing.
  3928. */
  3929. void
  3930. mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
  3931. {
  3932. dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
  3933. __func__));
  3934. mpt2sas_base_stop_watchdog(ioc);
  3935. mpt2sas_base_free_resources(ioc);
  3936. _base_release_memory_pools(ioc);
  3937. pci_set_drvdata(ioc->pdev, NULL);
  3938. kfree(ioc->cpu_msix_table);
  3939. if (ioc->is_warpdrive)
  3940. kfree(ioc->reply_post_host_index);
  3941. kfree(ioc->pd_handles);
  3942. kfree(ioc->blocking_handles);
  3943. kfree(ioc->pfacts);
  3944. kfree(ioc->ctl_cmds.reply);
  3945. kfree(ioc->ctl_cmds.sense);
  3946. kfree(ioc->base_cmds.reply);
  3947. kfree(ioc->port_enable_cmds.reply);
  3948. kfree(ioc->tm_cmds.reply);
  3949. kfree(ioc->transport_cmds.reply);
  3950. kfree(ioc->scsih_cmds.reply);
  3951. kfree(ioc->config_cmds.reply);
  3952. }
  3953. /**
  3954. * _base_reset_handler - reset callback handler (for base)
  3955. * @ioc: per adapter object
  3956. * @reset_phase: phase
  3957. *
  3958. * The handler for doing any required cleanup or initialization.
  3959. *
  3960. * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
  3961. * MPT2_IOC_DONE_RESET
  3962. *
  3963. * Return nothing.
  3964. */
  3965. static void
  3966. _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
  3967. {
  3968. mpt2sas_scsih_reset_handler(ioc, reset_phase);
  3969. mpt2sas_ctl_reset_handler(ioc, reset_phase);
  3970. switch (reset_phase) {
  3971. case MPT2_IOC_PRE_RESET:
  3972. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  3973. "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
  3974. break;
  3975. case MPT2_IOC_AFTER_RESET:
  3976. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  3977. "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
  3978. if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
  3979. ioc->transport_cmds.status |= MPT2_CMD_RESET;
  3980. mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
  3981. complete(&ioc->transport_cmds.done);
  3982. }
  3983. if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
  3984. ioc->base_cmds.status |= MPT2_CMD_RESET;
  3985. mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
  3986. complete(&ioc->base_cmds.done);
  3987. }
  3988. if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
  3989. ioc->port_enable_failed = 1;
  3990. ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
  3991. mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
  3992. if (ioc->is_driver_loading) {
  3993. ioc->start_scan_failed =
  3994. MPI2_IOCSTATUS_INTERNAL_ERROR;
  3995. ioc->start_scan = 0;
  3996. ioc->port_enable_cmds.status =
  3997. MPT2_CMD_NOT_USED;
  3998. } else
  3999. complete(&ioc->port_enable_cmds.done);
  4000. }
  4001. if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
  4002. ioc->config_cmds.status |= MPT2_CMD_RESET;
  4003. mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
  4004. ioc->config_cmds.smid = USHRT_MAX;
  4005. complete(&ioc->config_cmds.done);
  4006. }
  4007. break;
  4008. case MPT2_IOC_DONE_RESET:
  4009. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  4010. "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
  4011. break;
  4012. }
  4013. }
  4014. /**
  4015. * _wait_for_commands_to_complete - reset controller
  4016. * @ioc: Pointer to MPT_ADAPTER structure
  4017. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  4018. *
  4019. * This function waiting(3s) for all pending commands to complete
  4020. * prior to putting controller in reset.
  4021. */
  4022. static void
  4023. _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
  4024. {
  4025. u32 ioc_state;
  4026. unsigned long flags;
  4027. u16 i;
  4028. ioc->pending_io_count = 0;
  4029. if (sleep_flag != CAN_SLEEP)
  4030. return;
  4031. ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
  4032. if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
  4033. return;
  4034. /* pending command count */
  4035. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  4036. for (i = 0; i < ioc->scsiio_depth; i++)
  4037. if (ioc->scsi_lookup[i].cb_idx != 0xFF)
  4038. ioc->pending_io_count++;
  4039. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  4040. if (!ioc->pending_io_count)
  4041. return;
  4042. /* wait for pending commands to complete */
  4043. wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
  4044. }
  4045. /**
  4046. * mpt2sas_base_hard_reset_handler - reset controller
  4047. * @ioc: Pointer to MPT_ADAPTER structure
  4048. * @sleep_flag: CAN_SLEEP or NO_SLEEP
  4049. * @type: FORCE_BIG_HAMMER or SOFT_RESET
  4050. *
  4051. * Returns 0 for success, non-zero for failure.
  4052. */
  4053. int
  4054. mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
  4055. enum reset_type type)
  4056. {
  4057. int r;
  4058. unsigned long flags;
  4059. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
  4060. __func__));
  4061. if (ioc->pci_error_recovery) {
  4062. printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
  4063. ioc->name, __func__);
  4064. r = 0;
  4065. goto out_unlocked;
  4066. }
  4067. if (mpt2sas_fwfault_debug)
  4068. mpt2sas_halt_firmware(ioc);
  4069. /* TODO - What we really should be doing is pulling
  4070. * out all the code associated with NO_SLEEP; its never used.
  4071. * That is legacy code from mpt fusion driver, ported over.
  4072. * I will leave this BUG_ON here for now till its been resolved.
  4073. */
  4074. BUG_ON(sleep_flag == NO_SLEEP);
  4075. /* wait for an active reset in progress to complete */
  4076. if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
  4077. do {
  4078. ssleep(1);
  4079. } while (ioc->shost_recovery == 1);
  4080. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
  4081. __func__));
  4082. return ioc->ioc_reset_in_progress_status;
  4083. }
  4084. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  4085. ioc->shost_recovery = 1;
  4086. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  4087. _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
  4088. _wait_for_commands_to_complete(ioc, sleep_flag);
  4089. _base_mask_interrupts(ioc);
  4090. r = _base_make_ioc_ready(ioc, sleep_flag, type);
  4091. if (r)
  4092. goto out;
  4093. _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
  4094. /* If this hard reset is called while port enable is active, then
  4095. * there is no reason to call make_ioc_operational
  4096. */
  4097. if (ioc->is_driver_loading && ioc->port_enable_failed) {
  4098. ioc->remove_host = 1;
  4099. r = -EFAULT;
  4100. goto out;
  4101. }
  4102. r = _base_make_ioc_operational(ioc, sleep_flag);
  4103. if (!r)
  4104. _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
  4105. out:
  4106. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
  4107. ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
  4108. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  4109. ioc->ioc_reset_in_progress_status = r;
  4110. ioc->shost_recovery = 0;
  4111. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
  4112. mutex_unlock(&ioc->reset_in_progress_mutex);
  4113. out_unlocked:
  4114. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
  4115. __func__));
  4116. return r;
  4117. }