be_main.c 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484
  1. /**
  2. * Copyright (C) 2005 - 2011 Emulex
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@emulex.com
  14. *
  15. * Emulex
  16. * 3333 Susan Street
  17. * Costa Mesa, CA 92626
  18. */
  19. #include <linux/reboot.h>
  20. #include <linux/delay.h>
  21. #include <linux/slab.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/pci.h>
  25. #include <linux/string.h>
  26. #include <linux/kernel.h>
  27. #include <linux/semaphore.h>
  28. #include <linux/iscsi_boot_sysfs.h>
  29. #include <linux/module.h>
  30. #include <scsi/libiscsi.h>
  31. #include <scsi/scsi_transport_iscsi.h>
  32. #include <scsi/scsi_transport.h>
  33. #include <scsi/scsi_cmnd.h>
  34. #include <scsi/scsi_device.h>
  35. #include <scsi/scsi_host.h>
  36. #include <scsi/scsi.h>
  37. #include "be_main.h"
  38. #include "be_iscsi.h"
  39. #include "be_mgmt.h"
  40. static unsigned int be_iopoll_budget = 10;
  41. static unsigned int be_max_phys_size = 64;
  42. static unsigned int enable_msix = 1;
  43. static unsigned int gcrashmode = 0;
  44. static unsigned int num_hba = 0;
  45. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  46. MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
  47. MODULE_AUTHOR("ServerEngines Corporation");
  48. MODULE_LICENSE("GPL");
  49. module_param(be_iopoll_budget, int, 0);
  50. module_param(enable_msix, int, 0);
  51. module_param(be_max_phys_size, uint, S_IRUGO);
  52. MODULE_PARM_DESC(be_max_phys_size, "Maximum Size (In Kilobytes) of physically"
  53. "contiguous memory that can be allocated."
  54. "Range is 16 - 128");
  55. static int beiscsi_slave_configure(struct scsi_device *sdev)
  56. {
  57. blk_queue_max_segment_size(sdev->request_queue, 65536);
  58. return 0;
  59. }
  60. static int beiscsi_eh_abort(struct scsi_cmnd *sc)
  61. {
  62. struct iscsi_cls_session *cls_session;
  63. struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
  64. struct beiscsi_io_task *aborted_io_task;
  65. struct iscsi_conn *conn;
  66. struct beiscsi_conn *beiscsi_conn;
  67. struct beiscsi_hba *phba;
  68. struct iscsi_session *session;
  69. struct invalidate_command_table *inv_tbl;
  70. struct be_dma_mem nonemb_cmd;
  71. unsigned int cid, tag, num_invalidate;
  72. cls_session = starget_to_session(scsi_target(sc->device));
  73. session = cls_session->dd_data;
  74. spin_lock_bh(&session->lock);
  75. if (!aborted_task || !aborted_task->sc) {
  76. /* we raced */
  77. spin_unlock_bh(&session->lock);
  78. return SUCCESS;
  79. }
  80. aborted_io_task = aborted_task->dd_data;
  81. if (!aborted_io_task->scsi_cmnd) {
  82. /* raced or invalid command */
  83. spin_unlock_bh(&session->lock);
  84. return SUCCESS;
  85. }
  86. spin_unlock_bh(&session->lock);
  87. conn = aborted_task->conn;
  88. beiscsi_conn = conn->dd_data;
  89. phba = beiscsi_conn->phba;
  90. /* invalidate iocb */
  91. cid = beiscsi_conn->beiscsi_conn_cid;
  92. inv_tbl = phba->inv_tbl;
  93. memset(inv_tbl, 0x0, sizeof(*inv_tbl));
  94. inv_tbl->cid = cid;
  95. inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
  96. num_invalidate = 1;
  97. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  98. sizeof(struct invalidate_commands_params_in),
  99. &nonemb_cmd.dma);
  100. if (nonemb_cmd.va == NULL) {
  101. SE_DEBUG(DBG_LVL_1,
  102. "Failed to allocate memory for"
  103. "mgmt_invalidate_icds\n");
  104. return FAILED;
  105. }
  106. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  107. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  108. cid, &nonemb_cmd);
  109. if (!tag) {
  110. shost_printk(KERN_WARNING, phba->shost,
  111. "mgmt_invalidate_icds could not be"
  112. " submitted\n");
  113. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  114. nonemb_cmd.va, nonemb_cmd.dma);
  115. return FAILED;
  116. } else {
  117. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  118. phba->ctrl.mcc_numtag[tag]);
  119. free_mcc_tag(&phba->ctrl, tag);
  120. }
  121. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  122. nonemb_cmd.va, nonemb_cmd.dma);
  123. return iscsi_eh_abort(sc);
  124. }
  125. static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
  126. {
  127. struct iscsi_task *abrt_task;
  128. struct beiscsi_io_task *abrt_io_task;
  129. struct iscsi_conn *conn;
  130. struct beiscsi_conn *beiscsi_conn;
  131. struct beiscsi_hba *phba;
  132. struct iscsi_session *session;
  133. struct iscsi_cls_session *cls_session;
  134. struct invalidate_command_table *inv_tbl;
  135. struct be_dma_mem nonemb_cmd;
  136. unsigned int cid, tag, i, num_invalidate;
  137. int rc = FAILED;
  138. /* invalidate iocbs */
  139. cls_session = starget_to_session(scsi_target(sc->device));
  140. session = cls_session->dd_data;
  141. spin_lock_bh(&session->lock);
  142. if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
  143. goto unlock;
  144. conn = session->leadconn;
  145. beiscsi_conn = conn->dd_data;
  146. phba = beiscsi_conn->phba;
  147. cid = beiscsi_conn->beiscsi_conn_cid;
  148. inv_tbl = phba->inv_tbl;
  149. memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
  150. num_invalidate = 0;
  151. for (i = 0; i < conn->session->cmds_max; i++) {
  152. abrt_task = conn->session->cmds[i];
  153. abrt_io_task = abrt_task->dd_data;
  154. if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
  155. continue;
  156. if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
  157. continue;
  158. inv_tbl->cid = cid;
  159. inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
  160. num_invalidate++;
  161. inv_tbl++;
  162. }
  163. spin_unlock_bh(&session->lock);
  164. inv_tbl = phba->inv_tbl;
  165. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  166. sizeof(struct invalidate_commands_params_in),
  167. &nonemb_cmd.dma);
  168. if (nonemb_cmd.va == NULL) {
  169. SE_DEBUG(DBG_LVL_1,
  170. "Failed to allocate memory for"
  171. "mgmt_invalidate_icds\n");
  172. return FAILED;
  173. }
  174. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  175. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  176. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  177. cid, &nonemb_cmd);
  178. if (!tag) {
  179. shost_printk(KERN_WARNING, phba->shost,
  180. "mgmt_invalidate_icds could not be"
  181. " submitted\n");
  182. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  183. nonemb_cmd.va, nonemb_cmd.dma);
  184. return FAILED;
  185. } else {
  186. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  187. phba->ctrl.mcc_numtag[tag]);
  188. free_mcc_tag(&phba->ctrl, tag);
  189. }
  190. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  191. nonemb_cmd.va, nonemb_cmd.dma);
  192. return iscsi_eh_device_reset(sc);
  193. unlock:
  194. spin_unlock_bh(&session->lock);
  195. return rc;
  196. }
  197. static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
  198. {
  199. struct beiscsi_hba *phba = data;
  200. struct mgmt_session_info *boot_sess = &phba->boot_sess;
  201. struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
  202. char *str = buf;
  203. int rc;
  204. switch (type) {
  205. case ISCSI_BOOT_TGT_NAME:
  206. rc = sprintf(buf, "%.*s\n",
  207. (int)strlen(boot_sess->target_name),
  208. (char *)&boot_sess->target_name);
  209. break;
  210. case ISCSI_BOOT_TGT_IP_ADDR:
  211. if (boot_conn->dest_ipaddr.ip_type == 0x1)
  212. rc = sprintf(buf, "%pI4\n",
  213. (char *)&boot_conn->dest_ipaddr.ip_address);
  214. else
  215. rc = sprintf(str, "%pI6\n",
  216. (char *)&boot_conn->dest_ipaddr.ip_address);
  217. break;
  218. case ISCSI_BOOT_TGT_PORT:
  219. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  220. break;
  221. case ISCSI_BOOT_TGT_CHAP_NAME:
  222. rc = sprintf(str, "%.*s\n",
  223. boot_conn->negotiated_login_options.auth_data.chap.
  224. target_chap_name_length,
  225. (char *)&boot_conn->negotiated_login_options.
  226. auth_data.chap.target_chap_name);
  227. break;
  228. case ISCSI_BOOT_TGT_CHAP_SECRET:
  229. rc = sprintf(str, "%.*s\n",
  230. boot_conn->negotiated_login_options.auth_data.chap.
  231. target_secret_length,
  232. (char *)&boot_conn->negotiated_login_options.
  233. auth_data.chap.target_secret);
  234. break;
  235. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  236. rc = sprintf(str, "%.*s\n",
  237. boot_conn->negotiated_login_options.auth_data.chap.
  238. intr_chap_name_length,
  239. (char *)&boot_conn->negotiated_login_options.
  240. auth_data.chap.intr_chap_name);
  241. break;
  242. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  243. rc = sprintf(str, "%.*s\n",
  244. boot_conn->negotiated_login_options.auth_data.chap.
  245. intr_secret_length,
  246. (char *)&boot_conn->negotiated_login_options.
  247. auth_data.chap.intr_secret);
  248. break;
  249. case ISCSI_BOOT_TGT_FLAGS:
  250. rc = sprintf(str, "2\n");
  251. break;
  252. case ISCSI_BOOT_TGT_NIC_ASSOC:
  253. rc = sprintf(str, "0\n");
  254. break;
  255. default:
  256. rc = -ENOSYS;
  257. break;
  258. }
  259. return rc;
  260. }
  261. static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
  262. {
  263. struct beiscsi_hba *phba = data;
  264. char *str = buf;
  265. int rc;
  266. switch (type) {
  267. case ISCSI_BOOT_INI_INITIATOR_NAME:
  268. rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
  269. break;
  270. default:
  271. rc = -ENOSYS;
  272. break;
  273. }
  274. return rc;
  275. }
  276. static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
  277. {
  278. struct beiscsi_hba *phba = data;
  279. char *str = buf;
  280. int rc;
  281. switch (type) {
  282. case ISCSI_BOOT_ETH_FLAGS:
  283. rc = sprintf(str, "2\n");
  284. break;
  285. case ISCSI_BOOT_ETH_INDEX:
  286. rc = sprintf(str, "0\n");
  287. break;
  288. case ISCSI_BOOT_ETH_MAC:
  289. rc = beiscsi_get_macaddr(buf, phba);
  290. if (rc < 0) {
  291. SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n");
  292. return rc;
  293. }
  294. break;
  295. default:
  296. rc = -ENOSYS;
  297. break;
  298. }
  299. return rc;
  300. }
  301. static mode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
  302. {
  303. int rc;
  304. switch (type) {
  305. case ISCSI_BOOT_TGT_NAME:
  306. case ISCSI_BOOT_TGT_IP_ADDR:
  307. case ISCSI_BOOT_TGT_PORT:
  308. case ISCSI_BOOT_TGT_CHAP_NAME:
  309. case ISCSI_BOOT_TGT_CHAP_SECRET:
  310. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  311. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  312. case ISCSI_BOOT_TGT_NIC_ASSOC:
  313. case ISCSI_BOOT_TGT_FLAGS:
  314. rc = S_IRUGO;
  315. break;
  316. default:
  317. rc = 0;
  318. break;
  319. }
  320. return rc;
  321. }
  322. static mode_t beiscsi_ini_get_attr_visibility(void *data, int type)
  323. {
  324. int rc;
  325. switch (type) {
  326. case ISCSI_BOOT_INI_INITIATOR_NAME:
  327. rc = S_IRUGO;
  328. break;
  329. default:
  330. rc = 0;
  331. break;
  332. }
  333. return rc;
  334. }
  335. static mode_t beiscsi_eth_get_attr_visibility(void *data, int type)
  336. {
  337. int rc;
  338. switch (type) {
  339. case ISCSI_BOOT_ETH_FLAGS:
  340. case ISCSI_BOOT_ETH_MAC:
  341. case ISCSI_BOOT_ETH_INDEX:
  342. rc = S_IRUGO;
  343. break;
  344. default:
  345. rc = 0;
  346. break;
  347. }
  348. return rc;
  349. }
  350. /*------------------- PCI Driver operations and data ----------------- */
  351. static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
  352. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
  353. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
  354. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
  355. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
  356. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
  357. { 0 }
  358. };
  359. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  360. static struct scsi_host_template beiscsi_sht = {
  361. .module = THIS_MODULE,
  362. .name = "ServerEngines 10Gbe open-iscsi Initiator Driver",
  363. .proc_name = DRV_NAME,
  364. .queuecommand = iscsi_queuecommand,
  365. .change_queue_depth = iscsi_change_queue_depth,
  366. .slave_configure = beiscsi_slave_configure,
  367. .target_alloc = iscsi_target_alloc,
  368. .eh_abort_handler = beiscsi_eh_abort,
  369. .eh_device_reset_handler = beiscsi_eh_device_reset,
  370. .eh_target_reset_handler = iscsi_eh_session_reset,
  371. .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
  372. .can_queue = BE2_IO_DEPTH,
  373. .this_id = -1,
  374. .max_sectors = BEISCSI_MAX_SECTORS,
  375. .cmd_per_lun = BEISCSI_CMD_PER_LUN,
  376. .use_clustering = ENABLE_CLUSTERING,
  377. };
  378. static struct scsi_transport_template *beiscsi_scsi_transport;
  379. static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
  380. {
  381. struct beiscsi_hba *phba;
  382. struct Scsi_Host *shost;
  383. shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
  384. if (!shost) {
  385. dev_err(&pcidev->dev, "beiscsi_hba_alloc -"
  386. "iscsi_host_alloc failed\n");
  387. return NULL;
  388. }
  389. shost->dma_boundary = pcidev->dma_mask;
  390. shost->max_id = BE2_MAX_SESSIONS;
  391. shost->max_channel = 0;
  392. shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
  393. shost->max_lun = BEISCSI_NUM_MAX_LUN;
  394. shost->transportt = beiscsi_scsi_transport;
  395. phba = iscsi_host_priv(shost);
  396. memset(phba, 0, sizeof(*phba));
  397. phba->shost = shost;
  398. phba->pcidev = pci_dev_get(pcidev);
  399. pci_set_drvdata(pcidev, phba);
  400. if (iscsi_host_add(shost, &phba->pcidev->dev))
  401. goto free_devices;
  402. return phba;
  403. free_devices:
  404. pci_dev_put(phba->pcidev);
  405. iscsi_host_free(phba->shost);
  406. return NULL;
  407. }
  408. static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
  409. {
  410. if (phba->csr_va) {
  411. iounmap(phba->csr_va);
  412. phba->csr_va = NULL;
  413. }
  414. if (phba->db_va) {
  415. iounmap(phba->db_va);
  416. phba->db_va = NULL;
  417. }
  418. if (phba->pci_va) {
  419. iounmap(phba->pci_va);
  420. phba->pci_va = NULL;
  421. }
  422. }
  423. static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
  424. struct pci_dev *pcidev)
  425. {
  426. u8 __iomem *addr;
  427. int pcicfg_reg;
  428. addr = ioremap_nocache(pci_resource_start(pcidev, 2),
  429. pci_resource_len(pcidev, 2));
  430. if (addr == NULL)
  431. return -ENOMEM;
  432. phba->ctrl.csr = addr;
  433. phba->csr_va = addr;
  434. phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
  435. addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
  436. if (addr == NULL)
  437. goto pci_map_err;
  438. phba->ctrl.db = addr;
  439. phba->db_va = addr;
  440. phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
  441. if (phba->generation == BE_GEN2)
  442. pcicfg_reg = 1;
  443. else
  444. pcicfg_reg = 0;
  445. addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
  446. pci_resource_len(pcidev, pcicfg_reg));
  447. if (addr == NULL)
  448. goto pci_map_err;
  449. phba->ctrl.pcicfg = addr;
  450. phba->pci_va = addr;
  451. phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
  452. return 0;
  453. pci_map_err:
  454. beiscsi_unmap_pci_function(phba);
  455. return -ENOMEM;
  456. }
  457. static int beiscsi_enable_pci(struct pci_dev *pcidev)
  458. {
  459. int ret;
  460. ret = pci_enable_device(pcidev);
  461. if (ret) {
  462. dev_err(&pcidev->dev, "beiscsi_enable_pci - enable device "
  463. "failed. Returning -ENODEV\n");
  464. return ret;
  465. }
  466. pci_set_master(pcidev);
  467. if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
  468. ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
  469. if (ret) {
  470. dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
  471. pci_disable_device(pcidev);
  472. return ret;
  473. }
  474. }
  475. return 0;
  476. }
  477. static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
  478. {
  479. struct be_ctrl_info *ctrl = &phba->ctrl;
  480. struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
  481. struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
  482. int status = 0;
  483. ctrl->pdev = pdev;
  484. status = beiscsi_map_pci_bars(phba, pdev);
  485. if (status)
  486. return status;
  487. mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
  488. mbox_mem_alloc->va = pci_alloc_consistent(pdev,
  489. mbox_mem_alloc->size,
  490. &mbox_mem_alloc->dma);
  491. if (!mbox_mem_alloc->va) {
  492. beiscsi_unmap_pci_function(phba);
  493. status = -ENOMEM;
  494. return status;
  495. }
  496. mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
  497. mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
  498. mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
  499. memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
  500. spin_lock_init(&ctrl->mbox_lock);
  501. spin_lock_init(&phba->ctrl.mcc_lock);
  502. spin_lock_init(&phba->ctrl.mcc_cq_lock);
  503. return status;
  504. }
  505. static void beiscsi_get_params(struct beiscsi_hba *phba)
  506. {
  507. phba->params.ios_per_ctrl = (phba->fw_config.iscsi_icd_count
  508. - (phba->fw_config.iscsi_cid_count
  509. + BE2_TMFS
  510. + BE2_NOPOUT_REQ));
  511. phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
  512. phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count * 2;
  513. phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;
  514. phba->params.num_sge_per_io = BE2_SGE;
  515. phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
  516. phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
  517. phba->params.eq_timer = 64;
  518. phba->params.num_eq_entries =
  519. (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
  520. + BE2_TMFS) / 512) + 1) * 512;
  521. phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024)
  522. ? 1024 : phba->params.num_eq_entries;
  523. SE_DEBUG(DBG_LVL_8, "phba->params.num_eq_entries=%d\n",
  524. phba->params.num_eq_entries);
  525. phba->params.num_cq_entries =
  526. (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
  527. + BE2_TMFS) / 512) + 1) * 512;
  528. phba->params.wrbs_per_cxn = 256;
  529. }
  530. static void hwi_ring_eq_db(struct beiscsi_hba *phba,
  531. unsigned int id, unsigned int clr_interrupt,
  532. unsigned int num_processed,
  533. unsigned char rearm, unsigned char event)
  534. {
  535. u32 val = 0;
  536. val |= id & DB_EQ_RING_ID_MASK;
  537. if (rearm)
  538. val |= 1 << DB_EQ_REARM_SHIFT;
  539. if (clr_interrupt)
  540. val |= 1 << DB_EQ_CLR_SHIFT;
  541. if (event)
  542. val |= 1 << DB_EQ_EVNT_SHIFT;
  543. val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
  544. iowrite32(val, phba->db_va + DB_EQ_OFFSET);
  545. }
  546. /**
  547. * be_isr_mcc - The isr routine of the driver.
  548. * @irq: Not used
  549. * @dev_id: Pointer to host adapter structure
  550. */
  551. static irqreturn_t be_isr_mcc(int irq, void *dev_id)
  552. {
  553. struct beiscsi_hba *phba;
  554. struct be_eq_entry *eqe = NULL;
  555. struct be_queue_info *eq;
  556. struct be_queue_info *mcc;
  557. unsigned int num_eq_processed;
  558. struct be_eq_obj *pbe_eq;
  559. unsigned long flags;
  560. pbe_eq = dev_id;
  561. eq = &pbe_eq->q;
  562. phba = pbe_eq->phba;
  563. mcc = &phba->ctrl.mcc_obj.cq;
  564. eqe = queue_tail_node(eq);
  565. if (!eqe)
  566. SE_DEBUG(DBG_LVL_1, "eqe is NULL\n");
  567. num_eq_processed = 0;
  568. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  569. & EQE_VALID_MASK) {
  570. if (((eqe->dw[offsetof(struct amap_eq_entry,
  571. resource_id) / 32] &
  572. EQE_RESID_MASK) >> 16) == mcc->id) {
  573. spin_lock_irqsave(&phba->isr_lock, flags);
  574. phba->todo_mcc_cq = 1;
  575. spin_unlock_irqrestore(&phba->isr_lock, flags);
  576. }
  577. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  578. queue_tail_inc(eq);
  579. eqe = queue_tail_node(eq);
  580. num_eq_processed++;
  581. }
  582. if (phba->todo_mcc_cq)
  583. queue_work(phba->wq, &phba->work_cqs);
  584. if (num_eq_processed)
  585. hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
  586. return IRQ_HANDLED;
  587. }
  588. /**
  589. * be_isr_msix - The isr routine of the driver.
  590. * @irq: Not used
  591. * @dev_id: Pointer to host adapter structure
  592. */
  593. static irqreturn_t be_isr_msix(int irq, void *dev_id)
  594. {
  595. struct beiscsi_hba *phba;
  596. struct be_eq_entry *eqe = NULL;
  597. struct be_queue_info *eq;
  598. struct be_queue_info *cq;
  599. unsigned int num_eq_processed;
  600. struct be_eq_obj *pbe_eq;
  601. unsigned long flags;
  602. pbe_eq = dev_id;
  603. eq = &pbe_eq->q;
  604. cq = pbe_eq->cq;
  605. eqe = queue_tail_node(eq);
  606. if (!eqe)
  607. SE_DEBUG(DBG_LVL_1, "eqe is NULL\n");
  608. phba = pbe_eq->phba;
  609. num_eq_processed = 0;
  610. if (blk_iopoll_enabled) {
  611. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  612. & EQE_VALID_MASK) {
  613. if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
  614. blk_iopoll_sched(&pbe_eq->iopoll);
  615. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  616. queue_tail_inc(eq);
  617. eqe = queue_tail_node(eq);
  618. num_eq_processed++;
  619. }
  620. if (num_eq_processed)
  621. hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
  622. return IRQ_HANDLED;
  623. } else {
  624. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  625. & EQE_VALID_MASK) {
  626. spin_lock_irqsave(&phba->isr_lock, flags);
  627. phba->todo_cq = 1;
  628. spin_unlock_irqrestore(&phba->isr_lock, flags);
  629. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  630. queue_tail_inc(eq);
  631. eqe = queue_tail_node(eq);
  632. num_eq_processed++;
  633. }
  634. if (phba->todo_cq)
  635. queue_work(phba->wq, &phba->work_cqs);
  636. if (num_eq_processed)
  637. hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
  638. return IRQ_HANDLED;
  639. }
  640. }
  641. /**
  642. * be_isr - The isr routine of the driver.
  643. * @irq: Not used
  644. * @dev_id: Pointer to host adapter structure
  645. */
  646. static irqreturn_t be_isr(int irq, void *dev_id)
  647. {
  648. struct beiscsi_hba *phba;
  649. struct hwi_controller *phwi_ctrlr;
  650. struct hwi_context_memory *phwi_context;
  651. struct be_eq_entry *eqe = NULL;
  652. struct be_queue_info *eq;
  653. struct be_queue_info *cq;
  654. struct be_queue_info *mcc;
  655. unsigned long flags, index;
  656. unsigned int num_mcceq_processed, num_ioeq_processed;
  657. struct be_ctrl_info *ctrl;
  658. struct be_eq_obj *pbe_eq;
  659. int isr;
  660. phba = dev_id;
  661. ctrl = &phba->ctrl;
  662. isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
  663. (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
  664. if (!isr)
  665. return IRQ_NONE;
  666. phwi_ctrlr = phba->phwi_ctrlr;
  667. phwi_context = phwi_ctrlr->phwi_ctxt;
  668. pbe_eq = &phwi_context->be_eq[0];
  669. eq = &phwi_context->be_eq[0].q;
  670. mcc = &phba->ctrl.mcc_obj.cq;
  671. index = 0;
  672. eqe = queue_tail_node(eq);
  673. if (!eqe)
  674. SE_DEBUG(DBG_LVL_1, "eqe is NULL\n");
  675. num_ioeq_processed = 0;
  676. num_mcceq_processed = 0;
  677. if (blk_iopoll_enabled) {
  678. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  679. & EQE_VALID_MASK) {
  680. if (((eqe->dw[offsetof(struct amap_eq_entry,
  681. resource_id) / 32] &
  682. EQE_RESID_MASK) >> 16) == mcc->id) {
  683. spin_lock_irqsave(&phba->isr_lock, flags);
  684. phba->todo_mcc_cq = 1;
  685. spin_unlock_irqrestore(&phba->isr_lock, flags);
  686. num_mcceq_processed++;
  687. } else {
  688. if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
  689. blk_iopoll_sched(&pbe_eq->iopoll);
  690. num_ioeq_processed++;
  691. }
  692. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  693. queue_tail_inc(eq);
  694. eqe = queue_tail_node(eq);
  695. }
  696. if (num_ioeq_processed || num_mcceq_processed) {
  697. if (phba->todo_mcc_cq)
  698. queue_work(phba->wq, &phba->work_cqs);
  699. if ((num_mcceq_processed) && (!num_ioeq_processed))
  700. hwi_ring_eq_db(phba, eq->id, 0,
  701. (num_ioeq_processed +
  702. num_mcceq_processed) , 1, 1);
  703. else
  704. hwi_ring_eq_db(phba, eq->id, 0,
  705. (num_ioeq_processed +
  706. num_mcceq_processed), 0, 1);
  707. return IRQ_HANDLED;
  708. } else
  709. return IRQ_NONE;
  710. } else {
  711. cq = &phwi_context->be_cq[0];
  712. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  713. & EQE_VALID_MASK) {
  714. if (((eqe->dw[offsetof(struct amap_eq_entry,
  715. resource_id) / 32] &
  716. EQE_RESID_MASK) >> 16) != cq->id) {
  717. spin_lock_irqsave(&phba->isr_lock, flags);
  718. phba->todo_mcc_cq = 1;
  719. spin_unlock_irqrestore(&phba->isr_lock, flags);
  720. } else {
  721. spin_lock_irqsave(&phba->isr_lock, flags);
  722. phba->todo_cq = 1;
  723. spin_unlock_irqrestore(&phba->isr_lock, flags);
  724. }
  725. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  726. queue_tail_inc(eq);
  727. eqe = queue_tail_node(eq);
  728. num_ioeq_processed++;
  729. }
  730. if (phba->todo_cq || phba->todo_mcc_cq)
  731. queue_work(phba->wq, &phba->work_cqs);
  732. if (num_ioeq_processed) {
  733. hwi_ring_eq_db(phba, eq->id, 0,
  734. num_ioeq_processed, 1, 1);
  735. return IRQ_HANDLED;
  736. } else
  737. return IRQ_NONE;
  738. }
  739. }
  740. static int beiscsi_init_irqs(struct beiscsi_hba *phba)
  741. {
  742. struct pci_dev *pcidev = phba->pcidev;
  743. struct hwi_controller *phwi_ctrlr;
  744. struct hwi_context_memory *phwi_context;
  745. int ret, msix_vec, i, j;
  746. phwi_ctrlr = phba->phwi_ctrlr;
  747. phwi_context = phwi_ctrlr->phwi_ctxt;
  748. if (phba->msix_enabled) {
  749. for (i = 0; i < phba->num_cpus; i++) {
  750. phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
  751. GFP_KERNEL);
  752. if (!phba->msi_name[i]) {
  753. ret = -ENOMEM;
  754. goto free_msix_irqs;
  755. }
  756. sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
  757. phba->shost->host_no, i);
  758. msix_vec = phba->msix_entries[i].vector;
  759. ret = request_irq(msix_vec, be_isr_msix, 0,
  760. phba->msi_name[i],
  761. &phwi_context->be_eq[i]);
  762. if (ret) {
  763. shost_printk(KERN_ERR, phba->shost,
  764. "beiscsi_init_irqs-Failed to"
  765. "register msix for i = %d\n", i);
  766. kfree(phba->msi_name[i]);
  767. goto free_msix_irqs;
  768. }
  769. }
  770. phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
  771. if (!phba->msi_name[i]) {
  772. ret = -ENOMEM;
  773. goto free_msix_irqs;
  774. }
  775. sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
  776. phba->shost->host_no);
  777. msix_vec = phba->msix_entries[i].vector;
  778. ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
  779. &phwi_context->be_eq[i]);
  780. if (ret) {
  781. shost_printk(KERN_ERR, phba->shost, "beiscsi_init_irqs-"
  782. "Failed to register beiscsi_msix_mcc\n");
  783. kfree(phba->msi_name[i]);
  784. goto free_msix_irqs;
  785. }
  786. } else {
  787. ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
  788. "beiscsi", phba);
  789. if (ret) {
  790. shost_printk(KERN_ERR, phba->shost, "beiscsi_init_irqs-"
  791. "Failed to register irq\\n");
  792. return ret;
  793. }
  794. }
  795. return 0;
  796. free_msix_irqs:
  797. for (j = i - 1; j >= 0; j--) {
  798. kfree(phba->msi_name[j]);
  799. msix_vec = phba->msix_entries[j].vector;
  800. free_irq(msix_vec, &phwi_context->be_eq[j]);
  801. }
  802. return ret;
  803. }
  804. static void hwi_ring_cq_db(struct beiscsi_hba *phba,
  805. unsigned int id, unsigned int num_processed,
  806. unsigned char rearm, unsigned char event)
  807. {
  808. u32 val = 0;
  809. val |= id & DB_CQ_RING_ID_MASK;
  810. if (rearm)
  811. val |= 1 << DB_CQ_REARM_SHIFT;
  812. val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
  813. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  814. }
  815. static unsigned int
  816. beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
  817. struct beiscsi_hba *phba,
  818. unsigned short cid,
  819. struct pdu_base *ppdu,
  820. unsigned long pdu_len,
  821. void *pbuffer, unsigned long buf_len)
  822. {
  823. struct iscsi_conn *conn = beiscsi_conn->conn;
  824. struct iscsi_session *session = conn->session;
  825. struct iscsi_task *task;
  826. struct beiscsi_io_task *io_task;
  827. struct iscsi_hdr *login_hdr;
  828. switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
  829. PDUBASE_OPCODE_MASK) {
  830. case ISCSI_OP_NOOP_IN:
  831. pbuffer = NULL;
  832. buf_len = 0;
  833. break;
  834. case ISCSI_OP_ASYNC_EVENT:
  835. break;
  836. case ISCSI_OP_REJECT:
  837. WARN_ON(!pbuffer);
  838. WARN_ON(!(buf_len == 48));
  839. SE_DEBUG(DBG_LVL_1, "In ISCSI_OP_REJECT\n");
  840. break;
  841. case ISCSI_OP_LOGIN_RSP:
  842. case ISCSI_OP_TEXT_RSP:
  843. task = conn->login_task;
  844. io_task = task->dd_data;
  845. login_hdr = (struct iscsi_hdr *)ppdu;
  846. login_hdr->itt = io_task->libiscsi_itt;
  847. break;
  848. default:
  849. shost_printk(KERN_WARNING, phba->shost,
  850. "Unrecognized opcode 0x%x in async msg\n",
  851. (ppdu->
  852. dw[offsetof(struct amap_pdu_base, opcode) / 32]
  853. & PDUBASE_OPCODE_MASK));
  854. return 1;
  855. }
  856. spin_lock_bh(&session->lock);
  857. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
  858. spin_unlock_bh(&session->lock);
  859. return 0;
  860. }
  861. static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
  862. {
  863. struct sgl_handle *psgl_handle;
  864. if (phba->io_sgl_hndl_avbl) {
  865. SE_DEBUG(DBG_LVL_8,
  866. "In alloc_io_sgl_handle,io_sgl_alloc_index=%d\n",
  867. phba->io_sgl_alloc_index);
  868. psgl_handle = phba->io_sgl_hndl_base[phba->
  869. io_sgl_alloc_index];
  870. phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
  871. phba->io_sgl_hndl_avbl--;
  872. if (phba->io_sgl_alloc_index == (phba->params.
  873. ios_per_ctrl - 1))
  874. phba->io_sgl_alloc_index = 0;
  875. else
  876. phba->io_sgl_alloc_index++;
  877. } else
  878. psgl_handle = NULL;
  879. return psgl_handle;
  880. }
  881. static void
  882. free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
  883. {
  884. SE_DEBUG(DBG_LVL_8, "In free_,io_sgl_free_index=%d\n",
  885. phba->io_sgl_free_index);
  886. if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
  887. /*
  888. * this can happen if clean_task is called on a task that
  889. * failed in xmit_task or alloc_pdu.
  890. */
  891. SE_DEBUG(DBG_LVL_8,
  892. "Double Free in IO SGL io_sgl_free_index=%d,"
  893. "value there=%p\n", phba->io_sgl_free_index,
  894. phba->io_sgl_hndl_base[phba->io_sgl_free_index]);
  895. return;
  896. }
  897. phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
  898. phba->io_sgl_hndl_avbl++;
  899. if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
  900. phba->io_sgl_free_index = 0;
  901. else
  902. phba->io_sgl_free_index++;
  903. }
  904. /**
  905. * alloc_wrb_handle - To allocate a wrb handle
  906. * @phba: The hba pointer
  907. * @cid: The cid to use for allocation
  908. *
  909. * This happens under session_lock until submission to chip
  910. */
  911. struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
  912. {
  913. struct hwi_wrb_context *pwrb_context;
  914. struct hwi_controller *phwi_ctrlr;
  915. struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
  916. phwi_ctrlr = phba->phwi_ctrlr;
  917. pwrb_context = &phwi_ctrlr->wrb_context[cid];
  918. if (pwrb_context->wrb_handles_available >= 2) {
  919. pwrb_handle = pwrb_context->pwrb_handle_base[
  920. pwrb_context->alloc_index];
  921. pwrb_context->wrb_handles_available--;
  922. if (pwrb_context->alloc_index ==
  923. (phba->params.wrbs_per_cxn - 1))
  924. pwrb_context->alloc_index = 0;
  925. else
  926. pwrb_context->alloc_index++;
  927. pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
  928. pwrb_context->alloc_index];
  929. pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
  930. } else
  931. pwrb_handle = NULL;
  932. return pwrb_handle;
  933. }
  934. /**
  935. * free_wrb_handle - To free the wrb handle back to pool
  936. * @phba: The hba pointer
  937. * @pwrb_context: The context to free from
  938. * @pwrb_handle: The wrb_handle to free
  939. *
  940. * This happens under session_lock until submission to chip
  941. */
  942. static void
  943. free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
  944. struct wrb_handle *pwrb_handle)
  945. {
  946. pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
  947. pwrb_context->wrb_handles_available++;
  948. if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
  949. pwrb_context->free_index = 0;
  950. else
  951. pwrb_context->free_index++;
  952. SE_DEBUG(DBG_LVL_8,
  953. "FREE WRB: pwrb_handle=%p free_index=0x%x"
  954. "wrb_handles_available=%d\n",
  955. pwrb_handle, pwrb_context->free_index,
  956. pwrb_context->wrb_handles_available);
  957. }
  958. static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
  959. {
  960. struct sgl_handle *psgl_handle;
  961. if (phba->eh_sgl_hndl_avbl) {
  962. psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
  963. phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
  964. SE_DEBUG(DBG_LVL_8, "mgmt_sgl_alloc_index=%d=0x%x\n",
  965. phba->eh_sgl_alloc_index, phba->eh_sgl_alloc_index);
  966. phba->eh_sgl_hndl_avbl--;
  967. if (phba->eh_sgl_alloc_index ==
  968. (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
  969. 1))
  970. phba->eh_sgl_alloc_index = 0;
  971. else
  972. phba->eh_sgl_alloc_index++;
  973. } else
  974. psgl_handle = NULL;
  975. return psgl_handle;
  976. }
  977. void
  978. free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
  979. {
  980. SE_DEBUG(DBG_LVL_8, "In free_mgmt_sgl_handle,eh_sgl_free_index=%d\n",
  981. phba->eh_sgl_free_index);
  982. if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
  983. /*
  984. * this can happen if clean_task is called on a task that
  985. * failed in xmit_task or alloc_pdu.
  986. */
  987. SE_DEBUG(DBG_LVL_8,
  988. "Double Free in eh SGL ,eh_sgl_free_index=%d\n",
  989. phba->eh_sgl_free_index);
  990. return;
  991. }
  992. phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
  993. phba->eh_sgl_hndl_avbl++;
  994. if (phba->eh_sgl_free_index ==
  995. (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
  996. phba->eh_sgl_free_index = 0;
  997. else
  998. phba->eh_sgl_free_index++;
  999. }
  1000. static void
  1001. be_complete_io(struct beiscsi_conn *beiscsi_conn,
  1002. struct iscsi_task *task, struct sol_cqe *psol)
  1003. {
  1004. struct beiscsi_io_task *io_task = task->dd_data;
  1005. struct be_status_bhs *sts_bhs =
  1006. (struct be_status_bhs *)io_task->cmd_bhs;
  1007. struct iscsi_conn *conn = beiscsi_conn->conn;
  1008. unsigned int sense_len;
  1009. unsigned char *sense;
  1010. u32 resid = 0, exp_cmdsn, max_cmdsn;
  1011. u8 rsp, status, flags;
  1012. exp_cmdsn = (psol->
  1013. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1014. & SOL_EXP_CMD_SN_MASK);
  1015. max_cmdsn = ((psol->
  1016. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1017. & SOL_EXP_CMD_SN_MASK) +
  1018. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1019. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1020. rsp = ((psol->dw[offsetof(struct amap_sol_cqe, i_resp) / 32]
  1021. & SOL_RESP_MASK) >> 16);
  1022. status = ((psol->dw[offsetof(struct amap_sol_cqe, i_sts) / 32]
  1023. & SOL_STS_MASK) >> 8);
  1024. flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1025. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1026. if (!task->sc) {
  1027. if (io_task->scsi_cmnd)
  1028. scsi_dma_unmap(io_task->scsi_cmnd);
  1029. return;
  1030. }
  1031. task->sc->result = (DID_OK << 16) | status;
  1032. if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
  1033. task->sc->result = DID_ERROR << 16;
  1034. goto unmap;
  1035. }
  1036. /* bidi not initially supported */
  1037. if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
  1038. resid = (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) /
  1039. 32] & SOL_RES_CNT_MASK);
  1040. if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
  1041. task->sc->result = DID_ERROR << 16;
  1042. if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
  1043. scsi_set_resid(task->sc, resid);
  1044. if (!status && (scsi_bufflen(task->sc) - resid <
  1045. task->sc->underflow))
  1046. task->sc->result = DID_ERROR << 16;
  1047. }
  1048. }
  1049. if (status == SAM_STAT_CHECK_CONDITION) {
  1050. unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
  1051. sense = sts_bhs->sense_info + sizeof(unsigned short);
  1052. sense_len = cpu_to_be16(*slen);
  1053. memcpy(task->sc->sense_buffer, sense,
  1054. min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
  1055. }
  1056. if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) {
  1057. if (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
  1058. & SOL_RES_CNT_MASK)
  1059. conn->rxdata_octets += (psol->
  1060. dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
  1061. & SOL_RES_CNT_MASK);
  1062. }
  1063. unmap:
  1064. scsi_dma_unmap(io_task->scsi_cmnd);
  1065. iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
  1066. }
  1067. static void
  1068. be_complete_logout(struct beiscsi_conn *beiscsi_conn,
  1069. struct iscsi_task *task, struct sol_cqe *psol)
  1070. {
  1071. struct iscsi_logout_rsp *hdr;
  1072. struct beiscsi_io_task *io_task = task->dd_data;
  1073. struct iscsi_conn *conn = beiscsi_conn->conn;
  1074. hdr = (struct iscsi_logout_rsp *)task->hdr;
  1075. hdr->opcode = ISCSI_OP_LOGOUT_RSP;
  1076. hdr->t2wait = 5;
  1077. hdr->t2retain = 0;
  1078. hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1079. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1080. hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
  1081. 32] & SOL_RESP_MASK);
  1082. hdr->exp_cmdsn = cpu_to_be32(psol->
  1083. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1084. & SOL_EXP_CMD_SN_MASK);
  1085. hdr->max_cmdsn = be32_to_cpu((psol->
  1086. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1087. & SOL_EXP_CMD_SN_MASK) +
  1088. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1089. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1090. hdr->dlength[0] = 0;
  1091. hdr->dlength[1] = 0;
  1092. hdr->dlength[2] = 0;
  1093. hdr->hlength = 0;
  1094. hdr->itt = io_task->libiscsi_itt;
  1095. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1096. }
  1097. static void
  1098. be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
  1099. struct iscsi_task *task, struct sol_cqe *psol)
  1100. {
  1101. struct iscsi_tm_rsp *hdr;
  1102. struct iscsi_conn *conn = beiscsi_conn->conn;
  1103. struct beiscsi_io_task *io_task = task->dd_data;
  1104. hdr = (struct iscsi_tm_rsp *)task->hdr;
  1105. hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
  1106. hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1107. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1108. hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
  1109. 32] & SOL_RESP_MASK);
  1110. hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
  1111. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
  1112. hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
  1113. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
  1114. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1115. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1116. hdr->itt = io_task->libiscsi_itt;
  1117. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1118. }
  1119. static void
  1120. hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
  1121. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1122. {
  1123. struct hwi_wrb_context *pwrb_context;
  1124. struct wrb_handle *pwrb_handle = NULL;
  1125. struct hwi_controller *phwi_ctrlr;
  1126. struct iscsi_task *task;
  1127. struct beiscsi_io_task *io_task;
  1128. struct iscsi_conn *conn = beiscsi_conn->conn;
  1129. struct iscsi_session *session = conn->session;
  1130. phwi_ctrlr = phba->phwi_ctrlr;
  1131. pwrb_context = &phwi_ctrlr->wrb_context[((psol->
  1132. dw[offsetof(struct amap_sol_cqe, cid) / 32] &
  1133. SOL_CID_MASK) >> 6) -
  1134. phba->fw_config.iscsi_cid_start];
  1135. pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
  1136. dw[offsetof(struct amap_sol_cqe, wrb_index) /
  1137. 32] & SOL_WRB_INDEX_MASK) >> 16)];
  1138. task = pwrb_handle->pio_handle;
  1139. io_task = task->dd_data;
  1140. spin_lock(&phba->mgmt_sgl_lock);
  1141. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  1142. spin_unlock(&phba->mgmt_sgl_lock);
  1143. spin_lock_bh(&session->lock);
  1144. free_wrb_handle(phba, pwrb_context, pwrb_handle);
  1145. spin_unlock_bh(&session->lock);
  1146. }
  1147. static void
  1148. be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
  1149. struct iscsi_task *task, struct sol_cqe *psol)
  1150. {
  1151. struct iscsi_nopin *hdr;
  1152. struct iscsi_conn *conn = beiscsi_conn->conn;
  1153. struct beiscsi_io_task *io_task = task->dd_data;
  1154. hdr = (struct iscsi_nopin *)task->hdr;
  1155. hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1156. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1157. hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
  1158. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
  1159. hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
  1160. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
  1161. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1162. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1163. hdr->opcode = ISCSI_OP_NOOP_IN;
  1164. hdr->itt = io_task->libiscsi_itt;
  1165. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1166. }
  1167. static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
  1168. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1169. {
  1170. struct hwi_wrb_context *pwrb_context;
  1171. struct wrb_handle *pwrb_handle;
  1172. struct iscsi_wrb *pwrb = NULL;
  1173. struct hwi_controller *phwi_ctrlr;
  1174. struct iscsi_task *task;
  1175. unsigned int type;
  1176. struct iscsi_conn *conn = beiscsi_conn->conn;
  1177. struct iscsi_session *session = conn->session;
  1178. phwi_ctrlr = phba->phwi_ctrlr;
  1179. pwrb_context = &phwi_ctrlr->wrb_context[((psol->dw[offsetof
  1180. (struct amap_sol_cqe, cid) / 32]
  1181. & SOL_CID_MASK) >> 6) -
  1182. phba->fw_config.iscsi_cid_start];
  1183. pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
  1184. dw[offsetof(struct amap_sol_cqe, wrb_index) /
  1185. 32] & SOL_WRB_INDEX_MASK) >> 16)];
  1186. task = pwrb_handle->pio_handle;
  1187. pwrb = pwrb_handle->pwrb;
  1188. type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
  1189. WRB_TYPE_MASK) >> 28;
  1190. spin_lock_bh(&session->lock);
  1191. switch (type) {
  1192. case HWH_TYPE_IO:
  1193. case HWH_TYPE_IO_RD:
  1194. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
  1195. ISCSI_OP_NOOP_OUT)
  1196. be_complete_nopin_resp(beiscsi_conn, task, psol);
  1197. else
  1198. be_complete_io(beiscsi_conn, task, psol);
  1199. break;
  1200. case HWH_TYPE_LOGOUT:
  1201. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
  1202. be_complete_logout(beiscsi_conn, task, psol);
  1203. else
  1204. be_complete_tmf(beiscsi_conn, task, psol);
  1205. break;
  1206. case HWH_TYPE_LOGIN:
  1207. SE_DEBUG(DBG_LVL_1,
  1208. "\t\t No HWH_TYPE_LOGIN Expected in hwi_complete_cmd"
  1209. "- Solicited path\n");
  1210. break;
  1211. case HWH_TYPE_NOP:
  1212. be_complete_nopin_resp(beiscsi_conn, task, psol);
  1213. break;
  1214. default:
  1215. shost_printk(KERN_WARNING, phba->shost,
  1216. "In hwi_complete_cmd, unknown type = %d"
  1217. "wrb_index 0x%x CID 0x%x\n", type,
  1218. ((psol->dw[offsetof(struct amap_iscsi_wrb,
  1219. type) / 32] & SOL_WRB_INDEX_MASK) >> 16),
  1220. ((psol->dw[offsetof(struct amap_sol_cqe,
  1221. cid) / 32] & SOL_CID_MASK) >> 6));
  1222. break;
  1223. }
  1224. spin_unlock_bh(&session->lock);
  1225. }
  1226. static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
  1227. *pasync_ctx, unsigned int is_header,
  1228. unsigned int host_write_ptr)
  1229. {
  1230. if (is_header)
  1231. return &pasync_ctx->async_entry[host_write_ptr].
  1232. header_busy_list;
  1233. else
  1234. return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
  1235. }
  1236. static struct async_pdu_handle *
  1237. hwi_get_async_handle(struct beiscsi_hba *phba,
  1238. struct beiscsi_conn *beiscsi_conn,
  1239. struct hwi_async_pdu_context *pasync_ctx,
  1240. struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
  1241. {
  1242. struct be_bus_address phys_addr;
  1243. struct list_head *pbusy_list;
  1244. struct async_pdu_handle *pasync_handle = NULL;
  1245. int buffer_len = 0;
  1246. unsigned char buffer_index = -1;
  1247. unsigned char is_header = 0;
  1248. phys_addr.u.a32.address_lo =
  1249. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_lo) / 32] -
  1250. ((pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
  1251. & PDUCQE_DPL_MASK) >> 16);
  1252. phys_addr.u.a32.address_hi =
  1253. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_hi) / 32];
  1254. phys_addr.u.a64.address =
  1255. *((unsigned long long *)(&phys_addr.u.a64.address));
  1256. switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
  1257. & PDUCQE_CODE_MASK) {
  1258. case UNSOL_HDR_NOTIFY:
  1259. is_header = 1;
  1260. pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1,
  1261. (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1262. index) / 32] & PDUCQE_INDEX_MASK));
  1263. buffer_len = (unsigned int)(phys_addr.u.a64.address -
  1264. pasync_ctx->async_header.pa_base.u.a64.address);
  1265. buffer_index = buffer_len /
  1266. pasync_ctx->async_header.buffer_size;
  1267. break;
  1268. case UNSOL_DATA_NOTIFY:
  1269. pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe->
  1270. dw[offsetof(struct amap_i_t_dpdu_cqe,
  1271. index) / 32] & PDUCQE_INDEX_MASK));
  1272. buffer_len = (unsigned long)(phys_addr.u.a64.address -
  1273. pasync_ctx->async_data.pa_base.u.
  1274. a64.address);
  1275. buffer_index = buffer_len / pasync_ctx->async_data.buffer_size;
  1276. break;
  1277. default:
  1278. pbusy_list = NULL;
  1279. shost_printk(KERN_WARNING, phba->shost,
  1280. "Unexpected code=%d\n",
  1281. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1282. code) / 32] & PDUCQE_CODE_MASK);
  1283. return NULL;
  1284. }
  1285. WARN_ON(!(buffer_index <= pasync_ctx->async_data.num_entries));
  1286. WARN_ON(list_empty(pbusy_list));
  1287. list_for_each_entry(pasync_handle, pbusy_list, link) {
  1288. WARN_ON(pasync_handle->consumed);
  1289. if (pasync_handle->index == buffer_index)
  1290. break;
  1291. }
  1292. WARN_ON(!pasync_handle);
  1293. pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid -
  1294. phba->fw_config.iscsi_cid_start;
  1295. pasync_handle->is_header = is_header;
  1296. pasync_handle->buffer_len = ((pdpdu_cqe->
  1297. dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
  1298. & PDUCQE_DPL_MASK) >> 16);
  1299. *pcq_index = (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1300. index) / 32] & PDUCQE_INDEX_MASK);
  1301. return pasync_handle;
  1302. }
  1303. static unsigned int
  1304. hwi_update_async_writables(struct hwi_async_pdu_context *pasync_ctx,
  1305. unsigned int is_header, unsigned int cq_index)
  1306. {
  1307. struct list_head *pbusy_list;
  1308. struct async_pdu_handle *pasync_handle;
  1309. unsigned int num_entries, writables = 0;
  1310. unsigned int *pep_read_ptr, *pwritables;
  1311. if (is_header) {
  1312. pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
  1313. pwritables = &pasync_ctx->async_header.writables;
  1314. num_entries = pasync_ctx->async_header.num_entries;
  1315. } else {
  1316. pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
  1317. pwritables = &pasync_ctx->async_data.writables;
  1318. num_entries = pasync_ctx->async_data.num_entries;
  1319. }
  1320. while ((*pep_read_ptr) != cq_index) {
  1321. (*pep_read_ptr)++;
  1322. *pep_read_ptr = (*pep_read_ptr) % num_entries;
  1323. pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
  1324. *pep_read_ptr);
  1325. if (writables == 0)
  1326. WARN_ON(list_empty(pbusy_list));
  1327. if (!list_empty(pbusy_list)) {
  1328. pasync_handle = list_entry(pbusy_list->next,
  1329. struct async_pdu_handle,
  1330. link);
  1331. WARN_ON(!pasync_handle);
  1332. pasync_handle->consumed = 1;
  1333. }
  1334. writables++;
  1335. }
  1336. if (!writables) {
  1337. SE_DEBUG(DBG_LVL_1,
  1338. "Duplicate notification received - index 0x%x!!\n",
  1339. cq_index);
  1340. WARN_ON(1);
  1341. }
  1342. *pwritables = *pwritables + writables;
  1343. return 0;
  1344. }
  1345. static unsigned int hwi_free_async_msg(struct beiscsi_hba *phba,
  1346. unsigned int cri)
  1347. {
  1348. struct hwi_controller *phwi_ctrlr;
  1349. struct hwi_async_pdu_context *pasync_ctx;
  1350. struct async_pdu_handle *pasync_handle, *tmp_handle;
  1351. struct list_head *plist;
  1352. unsigned int i = 0;
  1353. phwi_ctrlr = phba->phwi_ctrlr;
  1354. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1355. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1356. list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
  1357. list_del(&pasync_handle->link);
  1358. if (i == 0) {
  1359. list_add_tail(&pasync_handle->link,
  1360. &pasync_ctx->async_header.free_list);
  1361. pasync_ctx->async_header.free_entries++;
  1362. i++;
  1363. } else {
  1364. list_add_tail(&pasync_handle->link,
  1365. &pasync_ctx->async_data.free_list);
  1366. pasync_ctx->async_data.free_entries++;
  1367. i++;
  1368. }
  1369. }
  1370. INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
  1371. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
  1372. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1373. return 0;
  1374. }
  1375. static struct phys_addr *
  1376. hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
  1377. unsigned int is_header, unsigned int host_write_ptr)
  1378. {
  1379. struct phys_addr *pasync_sge = NULL;
  1380. if (is_header)
  1381. pasync_sge = pasync_ctx->async_header.ring_base;
  1382. else
  1383. pasync_sge = pasync_ctx->async_data.ring_base;
  1384. return pasync_sge + host_write_ptr;
  1385. }
  1386. static void hwi_post_async_buffers(struct beiscsi_hba *phba,
  1387. unsigned int is_header)
  1388. {
  1389. struct hwi_controller *phwi_ctrlr;
  1390. struct hwi_async_pdu_context *pasync_ctx;
  1391. struct async_pdu_handle *pasync_handle;
  1392. struct list_head *pfree_link, *pbusy_list;
  1393. struct phys_addr *pasync_sge;
  1394. unsigned int ring_id, num_entries;
  1395. unsigned int host_write_num;
  1396. unsigned int writables;
  1397. unsigned int i = 0;
  1398. u32 doorbell = 0;
  1399. phwi_ctrlr = phba->phwi_ctrlr;
  1400. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1401. if (is_header) {
  1402. num_entries = pasync_ctx->async_header.num_entries;
  1403. writables = min(pasync_ctx->async_header.writables,
  1404. pasync_ctx->async_header.free_entries);
  1405. pfree_link = pasync_ctx->async_header.free_list.next;
  1406. host_write_num = pasync_ctx->async_header.host_write_ptr;
  1407. ring_id = phwi_ctrlr->default_pdu_hdr.id;
  1408. } else {
  1409. num_entries = pasync_ctx->async_data.num_entries;
  1410. writables = min(pasync_ctx->async_data.writables,
  1411. pasync_ctx->async_data.free_entries);
  1412. pfree_link = pasync_ctx->async_data.free_list.next;
  1413. host_write_num = pasync_ctx->async_data.host_write_ptr;
  1414. ring_id = phwi_ctrlr->default_pdu_data.id;
  1415. }
  1416. writables = (writables / 8) * 8;
  1417. if (writables) {
  1418. for (i = 0; i < writables; i++) {
  1419. pbusy_list =
  1420. hwi_get_async_busy_list(pasync_ctx, is_header,
  1421. host_write_num);
  1422. pasync_handle =
  1423. list_entry(pfree_link, struct async_pdu_handle,
  1424. link);
  1425. WARN_ON(!pasync_handle);
  1426. pasync_handle->consumed = 0;
  1427. pfree_link = pfree_link->next;
  1428. pasync_sge = hwi_get_ring_address(pasync_ctx,
  1429. is_header, host_write_num);
  1430. pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
  1431. pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
  1432. list_move(&pasync_handle->link, pbusy_list);
  1433. host_write_num++;
  1434. host_write_num = host_write_num % num_entries;
  1435. }
  1436. if (is_header) {
  1437. pasync_ctx->async_header.host_write_ptr =
  1438. host_write_num;
  1439. pasync_ctx->async_header.free_entries -= writables;
  1440. pasync_ctx->async_header.writables -= writables;
  1441. pasync_ctx->async_header.busy_entries += writables;
  1442. } else {
  1443. pasync_ctx->async_data.host_write_ptr = host_write_num;
  1444. pasync_ctx->async_data.free_entries -= writables;
  1445. pasync_ctx->async_data.writables -= writables;
  1446. pasync_ctx->async_data.busy_entries += writables;
  1447. }
  1448. doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
  1449. doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
  1450. doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
  1451. doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
  1452. << DB_DEF_PDU_CQPROC_SHIFT;
  1453. iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
  1454. }
  1455. }
  1456. static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
  1457. struct beiscsi_conn *beiscsi_conn,
  1458. struct i_t_dpdu_cqe *pdpdu_cqe)
  1459. {
  1460. struct hwi_controller *phwi_ctrlr;
  1461. struct hwi_async_pdu_context *pasync_ctx;
  1462. struct async_pdu_handle *pasync_handle = NULL;
  1463. unsigned int cq_index = -1;
  1464. phwi_ctrlr = phba->phwi_ctrlr;
  1465. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1466. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1467. pdpdu_cqe, &cq_index);
  1468. BUG_ON(pasync_handle->is_header != 0);
  1469. if (pasync_handle->consumed == 0)
  1470. hwi_update_async_writables(pasync_ctx, pasync_handle->is_header,
  1471. cq_index);
  1472. hwi_free_async_msg(phba, pasync_handle->cri);
  1473. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1474. }
  1475. static unsigned int
  1476. hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
  1477. struct beiscsi_hba *phba,
  1478. struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
  1479. {
  1480. struct list_head *plist;
  1481. struct async_pdu_handle *pasync_handle;
  1482. void *phdr = NULL;
  1483. unsigned int hdr_len = 0, buf_len = 0;
  1484. unsigned int status, index = 0, offset = 0;
  1485. void *pfirst_buffer = NULL;
  1486. unsigned int num_buf = 0;
  1487. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1488. list_for_each_entry(pasync_handle, plist, link) {
  1489. if (index == 0) {
  1490. phdr = pasync_handle->pbuffer;
  1491. hdr_len = pasync_handle->buffer_len;
  1492. } else {
  1493. buf_len = pasync_handle->buffer_len;
  1494. if (!num_buf) {
  1495. pfirst_buffer = pasync_handle->pbuffer;
  1496. num_buf++;
  1497. }
  1498. memcpy(pfirst_buffer + offset,
  1499. pasync_handle->pbuffer, buf_len);
  1500. offset = buf_len;
  1501. }
  1502. index++;
  1503. }
  1504. status = beiscsi_process_async_pdu(beiscsi_conn, phba,
  1505. (beiscsi_conn->beiscsi_conn_cid -
  1506. phba->fw_config.iscsi_cid_start),
  1507. phdr, hdr_len, pfirst_buffer,
  1508. buf_len);
  1509. if (status == 0)
  1510. hwi_free_async_msg(phba, cri);
  1511. return 0;
  1512. }
  1513. static unsigned int
  1514. hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
  1515. struct beiscsi_hba *phba,
  1516. struct async_pdu_handle *pasync_handle)
  1517. {
  1518. struct hwi_async_pdu_context *pasync_ctx;
  1519. struct hwi_controller *phwi_ctrlr;
  1520. unsigned int bytes_needed = 0, status = 0;
  1521. unsigned short cri = pasync_handle->cri;
  1522. struct pdu_base *ppdu;
  1523. phwi_ctrlr = phba->phwi_ctrlr;
  1524. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1525. list_del(&pasync_handle->link);
  1526. if (pasync_handle->is_header) {
  1527. pasync_ctx->async_header.busy_entries--;
  1528. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1529. hwi_free_async_msg(phba, cri);
  1530. BUG();
  1531. }
  1532. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1533. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
  1534. pasync_ctx->async_entry[cri].wait_queue.hdr_len =
  1535. (unsigned short)pasync_handle->buffer_len;
  1536. list_add_tail(&pasync_handle->link,
  1537. &pasync_ctx->async_entry[cri].wait_queue.list);
  1538. ppdu = pasync_handle->pbuffer;
  1539. bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
  1540. data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
  1541. 0xFFFF0000) | ((be16_to_cpu((ppdu->
  1542. dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
  1543. & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
  1544. if (status == 0) {
  1545. pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
  1546. bytes_needed;
  1547. if (bytes_needed == 0)
  1548. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1549. pasync_ctx, cri);
  1550. }
  1551. } else {
  1552. pasync_ctx->async_data.busy_entries--;
  1553. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1554. list_add_tail(&pasync_handle->link,
  1555. &pasync_ctx->async_entry[cri].wait_queue.
  1556. list);
  1557. pasync_ctx->async_entry[cri].wait_queue.
  1558. bytes_received +=
  1559. (unsigned short)pasync_handle->buffer_len;
  1560. if (pasync_ctx->async_entry[cri].wait_queue.
  1561. bytes_received >=
  1562. pasync_ctx->async_entry[cri].wait_queue.
  1563. bytes_needed)
  1564. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1565. pasync_ctx, cri);
  1566. }
  1567. }
  1568. return status;
  1569. }
  1570. static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
  1571. struct beiscsi_hba *phba,
  1572. struct i_t_dpdu_cqe *pdpdu_cqe)
  1573. {
  1574. struct hwi_controller *phwi_ctrlr;
  1575. struct hwi_async_pdu_context *pasync_ctx;
  1576. struct async_pdu_handle *pasync_handle = NULL;
  1577. unsigned int cq_index = -1;
  1578. phwi_ctrlr = phba->phwi_ctrlr;
  1579. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1580. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1581. pdpdu_cqe, &cq_index);
  1582. if (pasync_handle->consumed == 0)
  1583. hwi_update_async_writables(pasync_ctx, pasync_handle->is_header,
  1584. cq_index);
  1585. hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
  1586. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1587. }
  1588. static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
  1589. {
  1590. struct be_queue_info *mcc_cq;
  1591. struct be_mcc_compl *mcc_compl;
  1592. unsigned int num_processed = 0;
  1593. mcc_cq = &phba->ctrl.mcc_obj.cq;
  1594. mcc_compl = queue_tail_node(mcc_cq);
  1595. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1596. while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
  1597. if (num_processed >= 32) {
  1598. hwi_ring_cq_db(phba, mcc_cq->id,
  1599. num_processed, 0, 0);
  1600. num_processed = 0;
  1601. }
  1602. if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
  1603. /* Interpret flags as an async trailer */
  1604. if (is_link_state_evt(mcc_compl->flags))
  1605. /* Interpret compl as a async link evt */
  1606. beiscsi_async_link_state_process(phba,
  1607. (struct be_async_event_link_state *) mcc_compl);
  1608. else
  1609. SE_DEBUG(DBG_LVL_1,
  1610. " Unsupported Async Event, flags"
  1611. " = 0x%08x\n", mcc_compl->flags);
  1612. } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  1613. be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
  1614. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  1615. }
  1616. mcc_compl->flags = 0;
  1617. queue_tail_inc(mcc_cq);
  1618. mcc_compl = queue_tail_node(mcc_cq);
  1619. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1620. num_processed++;
  1621. }
  1622. if (num_processed > 0)
  1623. hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
  1624. }
  1625. static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
  1626. {
  1627. struct be_queue_info *cq;
  1628. struct sol_cqe *sol;
  1629. struct dmsg_cqe *dmsg;
  1630. unsigned int num_processed = 0;
  1631. unsigned int tot_nump = 0;
  1632. struct beiscsi_conn *beiscsi_conn;
  1633. struct beiscsi_endpoint *beiscsi_ep;
  1634. struct iscsi_endpoint *ep;
  1635. struct beiscsi_hba *phba;
  1636. cq = pbe_eq->cq;
  1637. sol = queue_tail_node(cq);
  1638. phba = pbe_eq->phba;
  1639. while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
  1640. CQE_VALID_MASK) {
  1641. be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
  1642. ep = phba->ep_array[(u32) ((sol->
  1643. dw[offsetof(struct amap_sol_cqe, cid) / 32] &
  1644. SOL_CID_MASK) >> 6) -
  1645. phba->fw_config.iscsi_cid_start];
  1646. beiscsi_ep = ep->dd_data;
  1647. beiscsi_conn = beiscsi_ep->conn;
  1648. if (num_processed >= 32) {
  1649. hwi_ring_cq_db(phba, cq->id,
  1650. num_processed, 0, 0);
  1651. tot_nump += num_processed;
  1652. num_processed = 0;
  1653. }
  1654. switch ((u32) sol->dw[offsetof(struct amap_sol_cqe, code) /
  1655. 32] & CQE_CODE_MASK) {
  1656. case SOL_CMD_COMPLETE:
  1657. hwi_complete_cmd(beiscsi_conn, phba, sol);
  1658. break;
  1659. case DRIVERMSG_NOTIFY:
  1660. SE_DEBUG(DBG_LVL_8, "Received DRIVERMSG_NOTIFY\n");
  1661. dmsg = (struct dmsg_cqe *)sol;
  1662. hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
  1663. break;
  1664. case UNSOL_HDR_NOTIFY:
  1665. SE_DEBUG(DBG_LVL_8, "Received UNSOL_HDR_ NOTIFY\n");
  1666. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1667. (struct i_t_dpdu_cqe *)sol);
  1668. break;
  1669. case UNSOL_DATA_NOTIFY:
  1670. SE_DEBUG(DBG_LVL_8, "Received UNSOL_DATA_NOTIFY\n");
  1671. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1672. (struct i_t_dpdu_cqe *)sol);
  1673. break;
  1674. case CXN_INVALIDATE_INDEX_NOTIFY:
  1675. case CMD_INVALIDATED_NOTIFY:
  1676. case CXN_INVALIDATE_NOTIFY:
  1677. SE_DEBUG(DBG_LVL_1,
  1678. "Ignoring CQ Error notification for cmd/cxn"
  1679. "invalidate\n");
  1680. break;
  1681. case SOL_CMD_KILLED_DATA_DIGEST_ERR:
  1682. case CMD_KILLED_INVALID_STATSN_RCVD:
  1683. case CMD_KILLED_INVALID_R2T_RCVD:
  1684. case CMD_CXN_KILLED_LUN_INVALID:
  1685. case CMD_CXN_KILLED_ICD_INVALID:
  1686. case CMD_CXN_KILLED_ITT_INVALID:
  1687. case CMD_CXN_KILLED_SEQ_OUTOFORDER:
  1688. case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
  1689. SE_DEBUG(DBG_LVL_1,
  1690. "CQ Error notification for cmd.. "
  1691. "code %d cid 0x%x\n",
  1692. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1693. 32] & CQE_CODE_MASK,
  1694. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1695. 32] & SOL_CID_MASK));
  1696. break;
  1697. case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
  1698. SE_DEBUG(DBG_LVL_1,
  1699. "Digest error on def pdu ring, dropping..\n");
  1700. hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
  1701. (struct i_t_dpdu_cqe *) sol);
  1702. break;
  1703. case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
  1704. case CXN_KILLED_BURST_LEN_MISMATCH:
  1705. case CXN_KILLED_AHS_RCVD:
  1706. case CXN_KILLED_HDR_DIGEST_ERR:
  1707. case CXN_KILLED_UNKNOWN_HDR:
  1708. case CXN_KILLED_STALE_ITT_TTT_RCVD:
  1709. case CXN_KILLED_INVALID_ITT_TTT_RCVD:
  1710. case CXN_KILLED_TIMED_OUT:
  1711. case CXN_KILLED_FIN_RCVD:
  1712. case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
  1713. case CXN_KILLED_BAD_WRB_INDEX_ERROR:
  1714. case CXN_KILLED_OVER_RUN_RESIDUAL:
  1715. case CXN_KILLED_UNDER_RUN_RESIDUAL:
  1716. case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
  1717. SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
  1718. "0x%x...\n",
  1719. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1720. 32] & CQE_CODE_MASK,
  1721. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1722. 32] & CQE_CID_MASK));
  1723. iscsi_conn_failure(beiscsi_conn->conn,
  1724. ISCSI_ERR_CONN_FAILED);
  1725. break;
  1726. case CXN_KILLED_RST_SENT:
  1727. case CXN_KILLED_RST_RCVD:
  1728. SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
  1729. "received/sent on CID 0x%x...\n",
  1730. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1731. 32] & CQE_CODE_MASK,
  1732. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1733. 32] & CQE_CID_MASK));
  1734. iscsi_conn_failure(beiscsi_conn->conn,
  1735. ISCSI_ERR_CONN_FAILED);
  1736. break;
  1737. default:
  1738. SE_DEBUG(DBG_LVL_1, "CQ Error Invalid code= %d "
  1739. "received on CID 0x%x...\n",
  1740. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1741. 32] & CQE_CODE_MASK,
  1742. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1743. 32] & CQE_CID_MASK));
  1744. break;
  1745. }
  1746. AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
  1747. queue_tail_inc(cq);
  1748. sol = queue_tail_node(cq);
  1749. num_processed++;
  1750. }
  1751. if (num_processed > 0) {
  1752. tot_nump += num_processed;
  1753. hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
  1754. }
  1755. return tot_nump;
  1756. }
  1757. void beiscsi_process_all_cqs(struct work_struct *work)
  1758. {
  1759. unsigned long flags;
  1760. struct hwi_controller *phwi_ctrlr;
  1761. struct hwi_context_memory *phwi_context;
  1762. struct be_eq_obj *pbe_eq;
  1763. struct beiscsi_hba *phba =
  1764. container_of(work, struct beiscsi_hba, work_cqs);
  1765. phwi_ctrlr = phba->phwi_ctrlr;
  1766. phwi_context = phwi_ctrlr->phwi_ctxt;
  1767. if (phba->msix_enabled)
  1768. pbe_eq = &phwi_context->be_eq[phba->num_cpus];
  1769. else
  1770. pbe_eq = &phwi_context->be_eq[0];
  1771. if (phba->todo_mcc_cq) {
  1772. spin_lock_irqsave(&phba->isr_lock, flags);
  1773. phba->todo_mcc_cq = 0;
  1774. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1775. beiscsi_process_mcc_isr(phba);
  1776. }
  1777. if (phba->todo_cq) {
  1778. spin_lock_irqsave(&phba->isr_lock, flags);
  1779. phba->todo_cq = 0;
  1780. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1781. beiscsi_process_cq(pbe_eq);
  1782. }
  1783. }
  1784. static int be_iopoll(struct blk_iopoll *iop, int budget)
  1785. {
  1786. static unsigned int ret;
  1787. struct beiscsi_hba *phba;
  1788. struct be_eq_obj *pbe_eq;
  1789. pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
  1790. ret = beiscsi_process_cq(pbe_eq);
  1791. if (ret < budget) {
  1792. phba = pbe_eq->phba;
  1793. blk_iopoll_complete(iop);
  1794. SE_DEBUG(DBG_LVL_8, "rearm pbe_eq->q.id =%d\n", pbe_eq->q.id);
  1795. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  1796. }
  1797. return ret;
  1798. }
  1799. static void
  1800. hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  1801. unsigned int num_sg, struct beiscsi_io_task *io_task)
  1802. {
  1803. struct iscsi_sge *psgl;
  1804. unsigned int sg_len, index;
  1805. unsigned int sge_len = 0;
  1806. unsigned long long addr;
  1807. struct scatterlist *l_sg;
  1808. unsigned int offset;
  1809. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  1810. io_task->bhs_pa.u.a32.address_lo);
  1811. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  1812. io_task->bhs_pa.u.a32.address_hi);
  1813. l_sg = sg;
  1814. for (index = 0; (index < num_sg) && (index < 2); index++,
  1815. sg = sg_next(sg)) {
  1816. if (index == 0) {
  1817. sg_len = sg_dma_len(sg);
  1818. addr = (u64) sg_dma_address(sg);
  1819. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  1820. ((u32)(addr & 0xFFFFFFFF)));
  1821. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  1822. ((u32)(addr >> 32)));
  1823. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  1824. sg_len);
  1825. sge_len = sg_len;
  1826. } else {
  1827. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
  1828. pwrb, sge_len);
  1829. sg_len = sg_dma_len(sg);
  1830. addr = (u64) sg_dma_address(sg);
  1831. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
  1832. ((u32)(addr & 0xFFFFFFFF)));
  1833. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
  1834. ((u32)(addr >> 32)));
  1835. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
  1836. sg_len);
  1837. }
  1838. }
  1839. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  1840. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  1841. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  1842. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1843. io_task->bhs_pa.u.a32.address_hi);
  1844. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1845. io_task->bhs_pa.u.a32.address_lo);
  1846. if (num_sg == 1) {
  1847. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1848. 1);
  1849. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1850. 0);
  1851. } else if (num_sg == 2) {
  1852. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1853. 0);
  1854. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1855. 1);
  1856. } else {
  1857. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1858. 0);
  1859. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1860. 0);
  1861. }
  1862. sg = l_sg;
  1863. psgl++;
  1864. psgl++;
  1865. offset = 0;
  1866. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  1867. sg_len = sg_dma_len(sg);
  1868. addr = (u64) sg_dma_address(sg);
  1869. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1870. (addr & 0xFFFFFFFF));
  1871. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1872. (addr >> 32));
  1873. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  1874. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  1875. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  1876. offset += sg_len;
  1877. }
  1878. psgl--;
  1879. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  1880. }
  1881. static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
  1882. {
  1883. struct iscsi_sge *psgl;
  1884. unsigned long long addr;
  1885. struct beiscsi_io_task *io_task = task->dd_data;
  1886. struct beiscsi_conn *beiscsi_conn = io_task->conn;
  1887. struct beiscsi_hba *phba = beiscsi_conn->phba;
  1888. io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
  1889. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  1890. io_task->bhs_pa.u.a32.address_lo);
  1891. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  1892. io_task->bhs_pa.u.a32.address_hi);
  1893. if (task->data) {
  1894. if (task->data_count) {
  1895. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  1896. addr = (u64) pci_map_single(phba->pcidev,
  1897. task->data,
  1898. task->data_count, 1);
  1899. } else {
  1900. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  1901. addr = 0;
  1902. }
  1903. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  1904. ((u32)(addr & 0xFFFFFFFF)));
  1905. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  1906. ((u32)(addr >> 32)));
  1907. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  1908. task->data_count);
  1909. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
  1910. } else {
  1911. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  1912. addr = 0;
  1913. }
  1914. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  1915. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
  1916. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1917. io_task->bhs_pa.u.a32.address_hi);
  1918. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1919. io_task->bhs_pa.u.a32.address_lo);
  1920. if (task->data) {
  1921. psgl++;
  1922. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
  1923. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
  1924. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
  1925. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
  1926. AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
  1927. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  1928. psgl++;
  1929. if (task->data) {
  1930. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1931. ((u32)(addr & 0xFFFFFFFF)));
  1932. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1933. ((u32)(addr >> 32)));
  1934. }
  1935. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
  1936. }
  1937. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  1938. }
  1939. static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
  1940. {
  1941. unsigned int num_cq_pages, num_async_pdu_buf_pages;
  1942. unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
  1943. unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
  1944. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  1945. sizeof(struct sol_cqe));
  1946. num_async_pdu_buf_pages =
  1947. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1948. phba->params.defpdu_hdr_sz);
  1949. num_async_pdu_buf_sgl_pages =
  1950. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1951. sizeof(struct phys_addr));
  1952. num_async_pdu_data_pages =
  1953. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1954. phba->params.defpdu_data_sz);
  1955. num_async_pdu_data_sgl_pages =
  1956. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1957. sizeof(struct phys_addr));
  1958. phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
  1959. phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
  1960. BE_ISCSI_PDU_HEADER_SIZE;
  1961. phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
  1962. sizeof(struct hwi_context_memory);
  1963. phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
  1964. * (phba->params.wrbs_per_cxn)
  1965. * phba->params.cxns_per_ctrl;
  1966. wrb_sz_per_cxn = sizeof(struct wrb_handle) *
  1967. (phba->params.wrbs_per_cxn);
  1968. phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
  1969. phba->params.cxns_per_ctrl);
  1970. phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
  1971. phba->params.icds_per_ctrl;
  1972. phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
  1973. phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
  1974. phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
  1975. num_async_pdu_buf_pages * PAGE_SIZE;
  1976. phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
  1977. num_async_pdu_data_pages * PAGE_SIZE;
  1978. phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
  1979. num_async_pdu_buf_sgl_pages * PAGE_SIZE;
  1980. phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
  1981. num_async_pdu_data_sgl_pages * PAGE_SIZE;
  1982. phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
  1983. phba->params.asyncpdus_per_ctrl *
  1984. sizeof(struct async_pdu_handle);
  1985. phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
  1986. phba->params.asyncpdus_per_ctrl *
  1987. sizeof(struct async_pdu_handle);
  1988. phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
  1989. sizeof(struct hwi_async_pdu_context) +
  1990. (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
  1991. }
  1992. static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
  1993. {
  1994. struct be_mem_descriptor *mem_descr;
  1995. dma_addr_t bus_add;
  1996. struct mem_array *mem_arr, *mem_arr_orig;
  1997. unsigned int i, j, alloc_size, curr_alloc_size;
  1998. phba->phwi_ctrlr = kmalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
  1999. if (!phba->phwi_ctrlr)
  2000. return -ENOMEM;
  2001. phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
  2002. GFP_KERNEL);
  2003. if (!phba->init_mem) {
  2004. kfree(phba->phwi_ctrlr);
  2005. return -ENOMEM;
  2006. }
  2007. mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
  2008. GFP_KERNEL);
  2009. if (!mem_arr_orig) {
  2010. kfree(phba->init_mem);
  2011. kfree(phba->phwi_ctrlr);
  2012. return -ENOMEM;
  2013. }
  2014. mem_descr = phba->init_mem;
  2015. for (i = 0; i < SE_MEM_MAX; i++) {
  2016. j = 0;
  2017. mem_arr = mem_arr_orig;
  2018. alloc_size = phba->mem_req[i];
  2019. memset(mem_arr, 0, sizeof(struct mem_array) *
  2020. BEISCSI_MAX_FRAGS_INIT);
  2021. curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
  2022. do {
  2023. mem_arr->virtual_address = pci_alloc_consistent(
  2024. phba->pcidev,
  2025. curr_alloc_size,
  2026. &bus_add);
  2027. if (!mem_arr->virtual_address) {
  2028. if (curr_alloc_size <= BE_MIN_MEM_SIZE)
  2029. goto free_mem;
  2030. if (curr_alloc_size -
  2031. rounddown_pow_of_two(curr_alloc_size))
  2032. curr_alloc_size = rounddown_pow_of_two
  2033. (curr_alloc_size);
  2034. else
  2035. curr_alloc_size = curr_alloc_size / 2;
  2036. } else {
  2037. mem_arr->bus_address.u.
  2038. a64.address = (__u64) bus_add;
  2039. mem_arr->size = curr_alloc_size;
  2040. alloc_size -= curr_alloc_size;
  2041. curr_alloc_size = min(be_max_phys_size *
  2042. 1024, alloc_size);
  2043. j++;
  2044. mem_arr++;
  2045. }
  2046. } while (alloc_size);
  2047. mem_descr->num_elements = j;
  2048. mem_descr->size_in_bytes = phba->mem_req[i];
  2049. mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
  2050. GFP_KERNEL);
  2051. if (!mem_descr->mem_array)
  2052. goto free_mem;
  2053. memcpy(mem_descr->mem_array, mem_arr_orig,
  2054. sizeof(struct mem_array) * j);
  2055. mem_descr++;
  2056. }
  2057. kfree(mem_arr_orig);
  2058. return 0;
  2059. free_mem:
  2060. mem_descr->num_elements = j;
  2061. while ((i) || (j)) {
  2062. for (j = mem_descr->num_elements; j > 0; j--) {
  2063. pci_free_consistent(phba->pcidev,
  2064. mem_descr->mem_array[j - 1].size,
  2065. mem_descr->mem_array[j - 1].
  2066. virtual_address,
  2067. (unsigned long)mem_descr->
  2068. mem_array[j - 1].
  2069. bus_address.u.a64.address);
  2070. }
  2071. if (i) {
  2072. i--;
  2073. kfree(mem_descr->mem_array);
  2074. mem_descr--;
  2075. }
  2076. }
  2077. kfree(mem_arr_orig);
  2078. kfree(phba->init_mem);
  2079. kfree(phba->phwi_ctrlr);
  2080. return -ENOMEM;
  2081. }
  2082. static int beiscsi_get_memory(struct beiscsi_hba *phba)
  2083. {
  2084. beiscsi_find_mem_req(phba);
  2085. return beiscsi_alloc_mem(phba);
  2086. }
  2087. static void iscsi_init_global_templates(struct beiscsi_hba *phba)
  2088. {
  2089. struct pdu_data_out *pdata_out;
  2090. struct pdu_nop_out *pnop_out;
  2091. struct be_mem_descriptor *mem_descr;
  2092. mem_descr = phba->init_mem;
  2093. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  2094. pdata_out =
  2095. (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
  2096. memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2097. AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
  2098. IIOC_SCSI_DATA);
  2099. pnop_out =
  2100. (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
  2101. virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
  2102. memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2103. AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
  2104. AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
  2105. AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
  2106. }
  2107. static void beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
  2108. {
  2109. struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
  2110. struct wrb_handle *pwrb_handle;
  2111. struct hwi_controller *phwi_ctrlr;
  2112. struct hwi_wrb_context *pwrb_context;
  2113. struct iscsi_wrb *pwrb;
  2114. unsigned int num_cxn_wrbh;
  2115. unsigned int num_cxn_wrb, j, idx, index;
  2116. mem_descr_wrbh = phba->init_mem;
  2117. mem_descr_wrbh += HWI_MEM_WRBH;
  2118. mem_descr_wrb = phba->init_mem;
  2119. mem_descr_wrb += HWI_MEM_WRB;
  2120. idx = 0;
  2121. pwrb_handle = mem_descr_wrbh->mem_array[idx].virtual_address;
  2122. num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
  2123. ((sizeof(struct wrb_handle)) *
  2124. phba->params.wrbs_per_cxn));
  2125. phwi_ctrlr = phba->phwi_ctrlr;
  2126. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2127. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2128. pwrb_context->pwrb_handle_base =
  2129. kzalloc(sizeof(struct wrb_handle *) *
  2130. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2131. pwrb_context->pwrb_handle_basestd =
  2132. kzalloc(sizeof(struct wrb_handle *) *
  2133. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2134. if (num_cxn_wrbh) {
  2135. pwrb_context->alloc_index = 0;
  2136. pwrb_context->wrb_handles_available = 0;
  2137. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2138. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  2139. pwrb_context->pwrb_handle_basestd[j] =
  2140. pwrb_handle;
  2141. pwrb_context->wrb_handles_available++;
  2142. pwrb_handle->wrb_index = j;
  2143. pwrb_handle++;
  2144. }
  2145. pwrb_context->free_index = 0;
  2146. num_cxn_wrbh--;
  2147. } else {
  2148. idx++;
  2149. pwrb_handle =
  2150. mem_descr_wrbh->mem_array[idx].virtual_address;
  2151. num_cxn_wrbh =
  2152. ((mem_descr_wrbh->mem_array[idx].size) /
  2153. ((sizeof(struct wrb_handle)) *
  2154. phba->params.wrbs_per_cxn));
  2155. pwrb_context->alloc_index = 0;
  2156. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2157. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  2158. pwrb_context->pwrb_handle_basestd[j] =
  2159. pwrb_handle;
  2160. pwrb_context->wrb_handles_available++;
  2161. pwrb_handle->wrb_index = j;
  2162. pwrb_handle++;
  2163. }
  2164. pwrb_context->free_index = 0;
  2165. num_cxn_wrbh--;
  2166. }
  2167. }
  2168. idx = 0;
  2169. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  2170. num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
  2171. ((sizeof(struct iscsi_wrb) *
  2172. phba->params.wrbs_per_cxn));
  2173. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2174. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2175. if (num_cxn_wrb) {
  2176. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2177. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  2178. pwrb_handle->pwrb = pwrb;
  2179. pwrb++;
  2180. }
  2181. num_cxn_wrb--;
  2182. } else {
  2183. idx++;
  2184. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  2185. num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
  2186. ((sizeof(struct iscsi_wrb) *
  2187. phba->params.wrbs_per_cxn));
  2188. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2189. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  2190. pwrb_handle->pwrb = pwrb;
  2191. pwrb++;
  2192. }
  2193. num_cxn_wrb--;
  2194. }
  2195. }
  2196. }
  2197. static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
  2198. {
  2199. struct hwi_controller *phwi_ctrlr;
  2200. struct hba_parameters *p = &phba->params;
  2201. struct hwi_async_pdu_context *pasync_ctx;
  2202. struct async_pdu_handle *pasync_header_h, *pasync_data_h;
  2203. unsigned int index;
  2204. struct be_mem_descriptor *mem_descr;
  2205. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2206. mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
  2207. phwi_ctrlr = phba->phwi_ctrlr;
  2208. phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
  2209. mem_descr->mem_array[0].virtual_address;
  2210. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
  2211. memset(pasync_ctx, 0, sizeof(*pasync_ctx));
  2212. pasync_ctx->async_header.num_entries = p->asyncpdus_per_ctrl;
  2213. pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz;
  2214. pasync_ctx->async_data.buffer_size = p->defpdu_data_sz;
  2215. pasync_ctx->async_data.num_entries = p->asyncpdus_per_ctrl;
  2216. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2217. mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
  2218. if (mem_descr->mem_array[0].virtual_address) {
  2219. SE_DEBUG(DBG_LVL_8,
  2220. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_BUF"
  2221. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2222. } else
  2223. shost_printk(KERN_WARNING, phba->shost,
  2224. "No Virtual address\n");
  2225. pasync_ctx->async_header.va_base =
  2226. mem_descr->mem_array[0].virtual_address;
  2227. pasync_ctx->async_header.pa_base.u.a64.address =
  2228. mem_descr->mem_array[0].bus_address.u.a64.address;
  2229. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2230. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2231. if (mem_descr->mem_array[0].virtual_address) {
  2232. SE_DEBUG(DBG_LVL_8,
  2233. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_RING"
  2234. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2235. } else
  2236. shost_printk(KERN_WARNING, phba->shost,
  2237. "No Virtual address\n");
  2238. pasync_ctx->async_header.ring_base =
  2239. mem_descr->mem_array[0].virtual_address;
  2240. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2241. mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
  2242. if (mem_descr->mem_array[0].virtual_address) {
  2243. SE_DEBUG(DBG_LVL_8,
  2244. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_HANDLE"
  2245. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2246. } else
  2247. shost_printk(KERN_WARNING, phba->shost,
  2248. "No Virtual address\n");
  2249. pasync_ctx->async_header.handle_base =
  2250. mem_descr->mem_array[0].virtual_address;
  2251. pasync_ctx->async_header.writables = 0;
  2252. INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
  2253. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2254. mem_descr += HWI_MEM_ASYNC_DATA_BUF;
  2255. if (mem_descr->mem_array[0].virtual_address) {
  2256. SE_DEBUG(DBG_LVL_8,
  2257. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_BUF"
  2258. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2259. } else
  2260. shost_printk(KERN_WARNING, phba->shost,
  2261. "No Virtual address\n");
  2262. pasync_ctx->async_data.va_base =
  2263. mem_descr->mem_array[0].virtual_address;
  2264. pasync_ctx->async_data.pa_base.u.a64.address =
  2265. mem_descr->mem_array[0].bus_address.u.a64.address;
  2266. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2267. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2268. if (mem_descr->mem_array[0].virtual_address) {
  2269. SE_DEBUG(DBG_LVL_8,
  2270. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_RING"
  2271. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2272. } else
  2273. shost_printk(KERN_WARNING, phba->shost,
  2274. "No Virtual address\n");
  2275. pasync_ctx->async_data.ring_base =
  2276. mem_descr->mem_array[0].virtual_address;
  2277. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2278. mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
  2279. if (!mem_descr->mem_array[0].virtual_address)
  2280. shost_printk(KERN_WARNING, phba->shost,
  2281. "No Virtual address\n");
  2282. pasync_ctx->async_data.handle_base =
  2283. mem_descr->mem_array[0].virtual_address;
  2284. pasync_ctx->async_data.writables = 0;
  2285. INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
  2286. pasync_header_h =
  2287. (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
  2288. pasync_data_h =
  2289. (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
  2290. for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
  2291. pasync_header_h->cri = -1;
  2292. pasync_header_h->index = (char)index;
  2293. INIT_LIST_HEAD(&pasync_header_h->link);
  2294. pasync_header_h->pbuffer =
  2295. (void *)((unsigned long)
  2296. (pasync_ctx->async_header.va_base) +
  2297. (p->defpdu_hdr_sz * index));
  2298. pasync_header_h->pa.u.a64.address =
  2299. pasync_ctx->async_header.pa_base.u.a64.address +
  2300. (p->defpdu_hdr_sz * index);
  2301. list_add_tail(&pasync_header_h->link,
  2302. &pasync_ctx->async_header.free_list);
  2303. pasync_header_h++;
  2304. pasync_ctx->async_header.free_entries++;
  2305. pasync_ctx->async_header.writables++;
  2306. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
  2307. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  2308. header_busy_list);
  2309. pasync_data_h->cri = -1;
  2310. pasync_data_h->index = (char)index;
  2311. INIT_LIST_HEAD(&pasync_data_h->link);
  2312. pasync_data_h->pbuffer =
  2313. (void *)((unsigned long)
  2314. (pasync_ctx->async_data.va_base) +
  2315. (p->defpdu_data_sz * index));
  2316. pasync_data_h->pa.u.a64.address =
  2317. pasync_ctx->async_data.pa_base.u.a64.address +
  2318. (p->defpdu_data_sz * index);
  2319. list_add_tail(&pasync_data_h->link,
  2320. &pasync_ctx->async_data.free_list);
  2321. pasync_data_h++;
  2322. pasync_ctx->async_data.free_entries++;
  2323. pasync_ctx->async_data.writables++;
  2324. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
  2325. }
  2326. pasync_ctx->async_header.host_write_ptr = 0;
  2327. pasync_ctx->async_header.ep_read_ptr = -1;
  2328. pasync_ctx->async_data.host_write_ptr = 0;
  2329. pasync_ctx->async_data.ep_read_ptr = -1;
  2330. }
  2331. static int
  2332. be_sgl_create_contiguous(void *virtual_address,
  2333. u64 physical_address, u32 length,
  2334. struct be_dma_mem *sgl)
  2335. {
  2336. WARN_ON(!virtual_address);
  2337. WARN_ON(!physical_address);
  2338. WARN_ON(!length > 0);
  2339. WARN_ON(!sgl);
  2340. sgl->va = virtual_address;
  2341. sgl->dma = (unsigned long)physical_address;
  2342. sgl->size = length;
  2343. return 0;
  2344. }
  2345. static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
  2346. {
  2347. memset(sgl, 0, sizeof(*sgl));
  2348. }
  2349. static void
  2350. hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
  2351. struct mem_array *pmem, struct be_dma_mem *sgl)
  2352. {
  2353. if (sgl->va)
  2354. be_sgl_destroy_contiguous(sgl);
  2355. be_sgl_create_contiguous(pmem->virtual_address,
  2356. pmem->bus_address.u.a64.address,
  2357. pmem->size, sgl);
  2358. }
  2359. static void
  2360. hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
  2361. struct mem_array *pmem, struct be_dma_mem *sgl)
  2362. {
  2363. if (sgl->va)
  2364. be_sgl_destroy_contiguous(sgl);
  2365. be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
  2366. pmem->bus_address.u.a64.address,
  2367. pmem->size, sgl);
  2368. }
  2369. static int be_fill_queue(struct be_queue_info *q,
  2370. u16 len, u16 entry_size, void *vaddress)
  2371. {
  2372. struct be_dma_mem *mem = &q->dma_mem;
  2373. memset(q, 0, sizeof(*q));
  2374. q->len = len;
  2375. q->entry_size = entry_size;
  2376. mem->size = len * entry_size;
  2377. mem->va = vaddress;
  2378. if (!mem->va)
  2379. return -ENOMEM;
  2380. memset(mem->va, 0, mem->size);
  2381. return 0;
  2382. }
  2383. static int beiscsi_create_eqs(struct beiscsi_hba *phba,
  2384. struct hwi_context_memory *phwi_context)
  2385. {
  2386. unsigned int i, num_eq_pages;
  2387. int ret, eq_for_mcc;
  2388. struct be_queue_info *eq;
  2389. struct be_dma_mem *mem;
  2390. void *eq_vaddress;
  2391. dma_addr_t paddr;
  2392. num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
  2393. sizeof(struct be_eq_entry));
  2394. if (phba->msix_enabled)
  2395. eq_for_mcc = 1;
  2396. else
  2397. eq_for_mcc = 0;
  2398. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2399. eq = &phwi_context->be_eq[i].q;
  2400. mem = &eq->dma_mem;
  2401. phwi_context->be_eq[i].phba = phba;
  2402. eq_vaddress = pci_alloc_consistent(phba->pcidev,
  2403. num_eq_pages * PAGE_SIZE,
  2404. &paddr);
  2405. if (!eq_vaddress)
  2406. goto create_eq_error;
  2407. mem->va = eq_vaddress;
  2408. ret = be_fill_queue(eq, phba->params.num_eq_entries,
  2409. sizeof(struct be_eq_entry), eq_vaddress);
  2410. if (ret) {
  2411. shost_printk(KERN_ERR, phba->shost,
  2412. "be_fill_queue Failed for EQ\n");
  2413. goto create_eq_error;
  2414. }
  2415. mem->dma = paddr;
  2416. ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
  2417. phwi_context->cur_eqd);
  2418. if (ret) {
  2419. shost_printk(KERN_ERR, phba->shost,
  2420. "beiscsi_cmd_eq_create"
  2421. "Failedfor EQ\n");
  2422. goto create_eq_error;
  2423. }
  2424. SE_DEBUG(DBG_LVL_8, "eqid = %d\n", phwi_context->be_eq[i].q.id);
  2425. }
  2426. return 0;
  2427. create_eq_error:
  2428. for (i = 0; i < (phba->num_cpus + 1); i++) {
  2429. eq = &phwi_context->be_eq[i].q;
  2430. mem = &eq->dma_mem;
  2431. if (mem->va)
  2432. pci_free_consistent(phba->pcidev, num_eq_pages
  2433. * PAGE_SIZE,
  2434. mem->va, mem->dma);
  2435. }
  2436. return ret;
  2437. }
  2438. static int beiscsi_create_cqs(struct beiscsi_hba *phba,
  2439. struct hwi_context_memory *phwi_context)
  2440. {
  2441. unsigned int i, num_cq_pages;
  2442. int ret;
  2443. struct be_queue_info *cq, *eq;
  2444. struct be_dma_mem *mem;
  2445. struct be_eq_obj *pbe_eq;
  2446. void *cq_vaddress;
  2447. dma_addr_t paddr;
  2448. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2449. sizeof(struct sol_cqe));
  2450. for (i = 0; i < phba->num_cpus; i++) {
  2451. cq = &phwi_context->be_cq[i];
  2452. eq = &phwi_context->be_eq[i].q;
  2453. pbe_eq = &phwi_context->be_eq[i];
  2454. pbe_eq->cq = cq;
  2455. pbe_eq->phba = phba;
  2456. mem = &cq->dma_mem;
  2457. cq_vaddress = pci_alloc_consistent(phba->pcidev,
  2458. num_cq_pages * PAGE_SIZE,
  2459. &paddr);
  2460. if (!cq_vaddress)
  2461. goto create_cq_error;
  2462. ret = be_fill_queue(cq, phba->params.num_cq_entries,
  2463. sizeof(struct sol_cqe), cq_vaddress);
  2464. if (ret) {
  2465. shost_printk(KERN_ERR, phba->shost,
  2466. "be_fill_queue Failed for ISCSI CQ\n");
  2467. goto create_cq_error;
  2468. }
  2469. mem->dma = paddr;
  2470. ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
  2471. false, 0);
  2472. if (ret) {
  2473. shost_printk(KERN_ERR, phba->shost,
  2474. "beiscsi_cmd_eq_create"
  2475. "Failed for ISCSI CQ\n");
  2476. goto create_cq_error;
  2477. }
  2478. SE_DEBUG(DBG_LVL_8, "iscsi cq_id is %d for eq_id %d\n",
  2479. cq->id, eq->id);
  2480. SE_DEBUG(DBG_LVL_8, "ISCSI CQ CREATED\n");
  2481. }
  2482. return 0;
  2483. create_cq_error:
  2484. for (i = 0; i < phba->num_cpus; i++) {
  2485. cq = &phwi_context->be_cq[i];
  2486. mem = &cq->dma_mem;
  2487. if (mem->va)
  2488. pci_free_consistent(phba->pcidev, num_cq_pages
  2489. * PAGE_SIZE,
  2490. mem->va, mem->dma);
  2491. }
  2492. return ret;
  2493. }
  2494. static int
  2495. beiscsi_create_def_hdr(struct beiscsi_hba *phba,
  2496. struct hwi_context_memory *phwi_context,
  2497. struct hwi_controller *phwi_ctrlr,
  2498. unsigned int def_pdu_ring_sz)
  2499. {
  2500. unsigned int idx;
  2501. int ret;
  2502. struct be_queue_info *dq, *cq;
  2503. struct be_dma_mem *mem;
  2504. struct be_mem_descriptor *mem_descr;
  2505. void *dq_vaddress;
  2506. idx = 0;
  2507. dq = &phwi_context->be_def_hdrq;
  2508. cq = &phwi_context->be_cq[0];
  2509. mem = &dq->dma_mem;
  2510. mem_descr = phba->init_mem;
  2511. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2512. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2513. ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
  2514. sizeof(struct phys_addr),
  2515. sizeof(struct phys_addr), dq_vaddress);
  2516. if (ret) {
  2517. shost_printk(KERN_ERR, phba->shost,
  2518. "be_fill_queue Failed for DEF PDU HDR\n");
  2519. return ret;
  2520. }
  2521. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2522. bus_address.u.a64.address;
  2523. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
  2524. def_pdu_ring_sz,
  2525. phba->params.defpdu_hdr_sz);
  2526. if (ret) {
  2527. shost_printk(KERN_ERR, phba->shost,
  2528. "be_cmd_create_default_pdu_queue Failed DEFHDR\n");
  2529. return ret;
  2530. }
  2531. phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
  2532. SE_DEBUG(DBG_LVL_8, "iscsi def pdu id is %d\n",
  2533. phwi_context->be_def_hdrq.id);
  2534. hwi_post_async_buffers(phba, 1);
  2535. return 0;
  2536. }
  2537. static int
  2538. beiscsi_create_def_data(struct beiscsi_hba *phba,
  2539. struct hwi_context_memory *phwi_context,
  2540. struct hwi_controller *phwi_ctrlr,
  2541. unsigned int def_pdu_ring_sz)
  2542. {
  2543. unsigned int idx;
  2544. int ret;
  2545. struct be_queue_info *dataq, *cq;
  2546. struct be_dma_mem *mem;
  2547. struct be_mem_descriptor *mem_descr;
  2548. void *dq_vaddress;
  2549. idx = 0;
  2550. dataq = &phwi_context->be_def_dataq;
  2551. cq = &phwi_context->be_cq[0];
  2552. mem = &dataq->dma_mem;
  2553. mem_descr = phba->init_mem;
  2554. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2555. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2556. ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
  2557. sizeof(struct phys_addr),
  2558. sizeof(struct phys_addr), dq_vaddress);
  2559. if (ret) {
  2560. shost_printk(KERN_ERR, phba->shost,
  2561. "be_fill_queue Failed for DEF PDU DATA\n");
  2562. return ret;
  2563. }
  2564. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2565. bus_address.u.a64.address;
  2566. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
  2567. def_pdu_ring_sz,
  2568. phba->params.defpdu_data_sz);
  2569. if (ret) {
  2570. shost_printk(KERN_ERR, phba->shost,
  2571. "be_cmd_create_default_pdu_queue Failed"
  2572. " for DEF PDU DATA\n");
  2573. return ret;
  2574. }
  2575. phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
  2576. SE_DEBUG(DBG_LVL_8, "iscsi def data id is %d\n",
  2577. phwi_context->be_def_dataq.id);
  2578. hwi_post_async_buffers(phba, 0);
  2579. SE_DEBUG(DBG_LVL_8, "DEFAULT PDU DATA RING CREATED\n");
  2580. return 0;
  2581. }
  2582. static int
  2583. beiscsi_post_pages(struct beiscsi_hba *phba)
  2584. {
  2585. struct be_mem_descriptor *mem_descr;
  2586. struct mem_array *pm_arr;
  2587. unsigned int page_offset, i;
  2588. struct be_dma_mem sgl;
  2589. int status;
  2590. mem_descr = phba->init_mem;
  2591. mem_descr += HWI_MEM_SGE;
  2592. pm_arr = mem_descr->mem_array;
  2593. page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
  2594. phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
  2595. for (i = 0; i < mem_descr->num_elements; i++) {
  2596. hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
  2597. status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
  2598. page_offset,
  2599. (pm_arr->size / PAGE_SIZE));
  2600. page_offset += pm_arr->size / PAGE_SIZE;
  2601. if (status != 0) {
  2602. shost_printk(KERN_ERR, phba->shost,
  2603. "post sgl failed.\n");
  2604. return status;
  2605. }
  2606. pm_arr++;
  2607. }
  2608. SE_DEBUG(DBG_LVL_8, "POSTED PAGES\n");
  2609. return 0;
  2610. }
  2611. static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
  2612. {
  2613. struct be_dma_mem *mem = &q->dma_mem;
  2614. if (mem->va)
  2615. pci_free_consistent(phba->pcidev, mem->size,
  2616. mem->va, mem->dma);
  2617. }
  2618. static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
  2619. u16 len, u16 entry_size)
  2620. {
  2621. struct be_dma_mem *mem = &q->dma_mem;
  2622. memset(q, 0, sizeof(*q));
  2623. q->len = len;
  2624. q->entry_size = entry_size;
  2625. mem->size = len * entry_size;
  2626. mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
  2627. if (!mem->va)
  2628. return -ENOMEM;
  2629. memset(mem->va, 0, mem->size);
  2630. return 0;
  2631. }
  2632. static int
  2633. beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
  2634. struct hwi_context_memory *phwi_context,
  2635. struct hwi_controller *phwi_ctrlr)
  2636. {
  2637. unsigned int wrb_mem_index, offset, size, num_wrb_rings;
  2638. u64 pa_addr_lo;
  2639. unsigned int idx, num, i;
  2640. struct mem_array *pwrb_arr;
  2641. void *wrb_vaddr;
  2642. struct be_dma_mem sgl;
  2643. struct be_mem_descriptor *mem_descr;
  2644. int status;
  2645. idx = 0;
  2646. mem_descr = phba->init_mem;
  2647. mem_descr += HWI_MEM_WRB;
  2648. pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
  2649. GFP_KERNEL);
  2650. if (!pwrb_arr) {
  2651. shost_printk(KERN_ERR, phba->shost,
  2652. "Memory alloc failed in create wrb ring.\n");
  2653. return -ENOMEM;
  2654. }
  2655. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2656. pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
  2657. num_wrb_rings = mem_descr->mem_array[idx].size /
  2658. (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
  2659. for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
  2660. if (num_wrb_rings) {
  2661. pwrb_arr[num].virtual_address = wrb_vaddr;
  2662. pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
  2663. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2664. sizeof(struct iscsi_wrb);
  2665. wrb_vaddr += pwrb_arr[num].size;
  2666. pa_addr_lo += pwrb_arr[num].size;
  2667. num_wrb_rings--;
  2668. } else {
  2669. idx++;
  2670. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2671. pa_addr_lo = mem_descr->mem_array[idx].\
  2672. bus_address.u.a64.address;
  2673. num_wrb_rings = mem_descr->mem_array[idx].size /
  2674. (phba->params.wrbs_per_cxn *
  2675. sizeof(struct iscsi_wrb));
  2676. pwrb_arr[num].virtual_address = wrb_vaddr;
  2677. pwrb_arr[num].bus_address.u.a64.address\
  2678. = pa_addr_lo;
  2679. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2680. sizeof(struct iscsi_wrb);
  2681. wrb_vaddr += pwrb_arr[num].size;
  2682. pa_addr_lo += pwrb_arr[num].size;
  2683. num_wrb_rings--;
  2684. }
  2685. }
  2686. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2687. wrb_mem_index = 0;
  2688. offset = 0;
  2689. size = 0;
  2690. hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
  2691. status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
  2692. &phwi_context->be_wrbq[i]);
  2693. if (status != 0) {
  2694. shost_printk(KERN_ERR, phba->shost,
  2695. "wrbq create failed.");
  2696. kfree(pwrb_arr);
  2697. return status;
  2698. }
  2699. phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
  2700. id;
  2701. }
  2702. kfree(pwrb_arr);
  2703. return 0;
  2704. }
  2705. static void free_wrb_handles(struct beiscsi_hba *phba)
  2706. {
  2707. unsigned int index;
  2708. struct hwi_controller *phwi_ctrlr;
  2709. struct hwi_wrb_context *pwrb_context;
  2710. phwi_ctrlr = phba->phwi_ctrlr;
  2711. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2712. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2713. kfree(pwrb_context->pwrb_handle_base);
  2714. kfree(pwrb_context->pwrb_handle_basestd);
  2715. }
  2716. }
  2717. static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
  2718. {
  2719. struct be_queue_info *q;
  2720. struct be_ctrl_info *ctrl = &phba->ctrl;
  2721. q = &phba->ctrl.mcc_obj.q;
  2722. if (q->created)
  2723. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
  2724. be_queue_free(phba, q);
  2725. q = &phba->ctrl.mcc_obj.cq;
  2726. if (q->created)
  2727. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  2728. be_queue_free(phba, q);
  2729. }
  2730. static void hwi_cleanup(struct beiscsi_hba *phba)
  2731. {
  2732. struct be_queue_info *q;
  2733. struct be_ctrl_info *ctrl = &phba->ctrl;
  2734. struct hwi_controller *phwi_ctrlr;
  2735. struct hwi_context_memory *phwi_context;
  2736. int i, eq_num;
  2737. phwi_ctrlr = phba->phwi_ctrlr;
  2738. phwi_context = phwi_ctrlr->phwi_ctxt;
  2739. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2740. q = &phwi_context->be_wrbq[i];
  2741. if (q->created)
  2742. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
  2743. }
  2744. free_wrb_handles(phba);
  2745. q = &phwi_context->be_def_hdrq;
  2746. if (q->created)
  2747. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  2748. q = &phwi_context->be_def_dataq;
  2749. if (q->created)
  2750. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  2751. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  2752. for (i = 0; i < (phba->num_cpus); i++) {
  2753. q = &phwi_context->be_cq[i];
  2754. if (q->created)
  2755. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  2756. }
  2757. if (phba->msix_enabled)
  2758. eq_num = 1;
  2759. else
  2760. eq_num = 0;
  2761. for (i = 0; i < (phba->num_cpus + eq_num); i++) {
  2762. q = &phwi_context->be_eq[i].q;
  2763. if (q->created)
  2764. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
  2765. }
  2766. be_mcc_queues_destroy(phba);
  2767. }
  2768. static int be_mcc_queues_create(struct beiscsi_hba *phba,
  2769. struct hwi_context_memory *phwi_context)
  2770. {
  2771. struct be_queue_info *q, *cq;
  2772. struct be_ctrl_info *ctrl = &phba->ctrl;
  2773. /* Alloc MCC compl queue */
  2774. cq = &phba->ctrl.mcc_obj.cq;
  2775. if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
  2776. sizeof(struct be_mcc_compl)))
  2777. goto err;
  2778. /* Ask BE to create MCC compl queue; */
  2779. if (phba->msix_enabled) {
  2780. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
  2781. [phba->num_cpus].q, false, true, 0))
  2782. goto mcc_cq_free;
  2783. } else {
  2784. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
  2785. false, true, 0))
  2786. goto mcc_cq_free;
  2787. }
  2788. /* Alloc MCC queue */
  2789. q = &phba->ctrl.mcc_obj.q;
  2790. if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
  2791. goto mcc_cq_destroy;
  2792. /* Ask BE to create MCC queue */
  2793. if (beiscsi_cmd_mccq_create(phba, q, cq))
  2794. goto mcc_q_free;
  2795. return 0;
  2796. mcc_q_free:
  2797. be_queue_free(phba, q);
  2798. mcc_cq_destroy:
  2799. beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
  2800. mcc_cq_free:
  2801. be_queue_free(phba, cq);
  2802. err:
  2803. return -ENOMEM;
  2804. }
  2805. static int find_num_cpus(void)
  2806. {
  2807. int num_cpus = 0;
  2808. num_cpus = num_online_cpus();
  2809. if (num_cpus >= MAX_CPUS)
  2810. num_cpus = MAX_CPUS - 1;
  2811. SE_DEBUG(DBG_LVL_8, "num_cpus = %d\n", num_cpus);
  2812. return num_cpus;
  2813. }
  2814. static int hwi_init_port(struct beiscsi_hba *phba)
  2815. {
  2816. struct hwi_controller *phwi_ctrlr;
  2817. struct hwi_context_memory *phwi_context;
  2818. unsigned int def_pdu_ring_sz;
  2819. struct be_ctrl_info *ctrl = &phba->ctrl;
  2820. int status;
  2821. def_pdu_ring_sz =
  2822. phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
  2823. phwi_ctrlr = phba->phwi_ctrlr;
  2824. phwi_context = phwi_ctrlr->phwi_ctxt;
  2825. phwi_context->max_eqd = 0;
  2826. phwi_context->min_eqd = 0;
  2827. phwi_context->cur_eqd = 64;
  2828. be_cmd_fw_initialize(&phba->ctrl);
  2829. status = beiscsi_create_eqs(phba, phwi_context);
  2830. if (status != 0) {
  2831. shost_printk(KERN_ERR, phba->shost, "EQ not created\n");
  2832. goto error;
  2833. }
  2834. status = be_mcc_queues_create(phba, phwi_context);
  2835. if (status != 0)
  2836. goto error;
  2837. status = mgmt_check_supported_fw(ctrl, phba);
  2838. if (status != 0) {
  2839. shost_printk(KERN_ERR, phba->shost,
  2840. "Unsupported fw version\n");
  2841. goto error;
  2842. }
  2843. status = beiscsi_create_cqs(phba, phwi_context);
  2844. if (status != 0) {
  2845. shost_printk(KERN_ERR, phba->shost, "CQ not created\n");
  2846. goto error;
  2847. }
  2848. status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
  2849. def_pdu_ring_sz);
  2850. if (status != 0) {
  2851. shost_printk(KERN_ERR, phba->shost,
  2852. "Default Header not created\n");
  2853. goto error;
  2854. }
  2855. status = beiscsi_create_def_data(phba, phwi_context,
  2856. phwi_ctrlr, def_pdu_ring_sz);
  2857. if (status != 0) {
  2858. shost_printk(KERN_ERR, phba->shost,
  2859. "Default Data not created\n");
  2860. goto error;
  2861. }
  2862. status = beiscsi_post_pages(phba);
  2863. if (status != 0) {
  2864. shost_printk(KERN_ERR, phba->shost, "Post SGL Pages Failed\n");
  2865. goto error;
  2866. }
  2867. status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
  2868. if (status != 0) {
  2869. shost_printk(KERN_ERR, phba->shost,
  2870. "WRB Rings not created\n");
  2871. goto error;
  2872. }
  2873. SE_DEBUG(DBG_LVL_8, "hwi_init_port success\n");
  2874. return 0;
  2875. error:
  2876. shost_printk(KERN_ERR, phba->shost, "hwi_init_port failed");
  2877. hwi_cleanup(phba);
  2878. return -ENOMEM;
  2879. }
  2880. static int hwi_init_controller(struct beiscsi_hba *phba)
  2881. {
  2882. struct hwi_controller *phwi_ctrlr;
  2883. phwi_ctrlr = phba->phwi_ctrlr;
  2884. if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
  2885. phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
  2886. init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
  2887. SE_DEBUG(DBG_LVL_8, " phwi_ctrlr->phwi_ctxt=%p\n",
  2888. phwi_ctrlr->phwi_ctxt);
  2889. } else {
  2890. shost_printk(KERN_ERR, phba->shost,
  2891. "HWI_MEM_ADDN_CONTEXT is more than one element."
  2892. "Failing to load\n");
  2893. return -ENOMEM;
  2894. }
  2895. iscsi_init_global_templates(phba);
  2896. beiscsi_init_wrb_handle(phba);
  2897. hwi_init_async_pdu_ctx(phba);
  2898. if (hwi_init_port(phba) != 0) {
  2899. shost_printk(KERN_ERR, phba->shost,
  2900. "hwi_init_controller failed\n");
  2901. return -ENOMEM;
  2902. }
  2903. return 0;
  2904. }
  2905. static void beiscsi_free_mem(struct beiscsi_hba *phba)
  2906. {
  2907. struct be_mem_descriptor *mem_descr;
  2908. int i, j;
  2909. mem_descr = phba->init_mem;
  2910. i = 0;
  2911. j = 0;
  2912. for (i = 0; i < SE_MEM_MAX; i++) {
  2913. for (j = mem_descr->num_elements; j > 0; j--) {
  2914. pci_free_consistent(phba->pcidev,
  2915. mem_descr->mem_array[j - 1].size,
  2916. mem_descr->mem_array[j - 1].virtual_address,
  2917. (unsigned long)mem_descr->mem_array[j - 1].
  2918. bus_address.u.a64.address);
  2919. }
  2920. kfree(mem_descr->mem_array);
  2921. mem_descr++;
  2922. }
  2923. kfree(phba->init_mem);
  2924. kfree(phba->phwi_ctrlr);
  2925. }
  2926. static int beiscsi_init_controller(struct beiscsi_hba *phba)
  2927. {
  2928. int ret = -ENOMEM;
  2929. ret = beiscsi_get_memory(phba);
  2930. if (ret < 0) {
  2931. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe -"
  2932. "Failed in beiscsi_alloc_memory\n");
  2933. return ret;
  2934. }
  2935. ret = hwi_init_controller(phba);
  2936. if (ret)
  2937. goto free_init;
  2938. SE_DEBUG(DBG_LVL_8, "Return success from beiscsi_init_controller");
  2939. return 0;
  2940. free_init:
  2941. beiscsi_free_mem(phba);
  2942. return -ENOMEM;
  2943. }
  2944. static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
  2945. {
  2946. struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
  2947. struct sgl_handle *psgl_handle;
  2948. struct iscsi_sge *pfrag;
  2949. unsigned int arr_index, i, idx;
  2950. phba->io_sgl_hndl_avbl = 0;
  2951. phba->eh_sgl_hndl_avbl = 0;
  2952. mem_descr_sglh = phba->init_mem;
  2953. mem_descr_sglh += HWI_MEM_SGLH;
  2954. if (1 == mem_descr_sglh->num_elements) {
  2955. phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  2956. phba->params.ios_per_ctrl,
  2957. GFP_KERNEL);
  2958. if (!phba->io_sgl_hndl_base) {
  2959. shost_printk(KERN_ERR, phba->shost,
  2960. "Mem Alloc Failed. Failing to load\n");
  2961. return -ENOMEM;
  2962. }
  2963. phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  2964. (phba->params.icds_per_ctrl -
  2965. phba->params.ios_per_ctrl),
  2966. GFP_KERNEL);
  2967. if (!phba->eh_sgl_hndl_base) {
  2968. kfree(phba->io_sgl_hndl_base);
  2969. shost_printk(KERN_ERR, phba->shost,
  2970. "Mem Alloc Failed. Failing to load\n");
  2971. return -ENOMEM;
  2972. }
  2973. } else {
  2974. shost_printk(KERN_ERR, phba->shost,
  2975. "HWI_MEM_SGLH is more than one element."
  2976. "Failing to load\n");
  2977. return -ENOMEM;
  2978. }
  2979. arr_index = 0;
  2980. idx = 0;
  2981. while (idx < mem_descr_sglh->num_elements) {
  2982. psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
  2983. for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
  2984. sizeof(struct sgl_handle)); i++) {
  2985. if (arr_index < phba->params.ios_per_ctrl) {
  2986. phba->io_sgl_hndl_base[arr_index] = psgl_handle;
  2987. phba->io_sgl_hndl_avbl++;
  2988. arr_index++;
  2989. } else {
  2990. phba->eh_sgl_hndl_base[arr_index -
  2991. phba->params.ios_per_ctrl] =
  2992. psgl_handle;
  2993. arr_index++;
  2994. phba->eh_sgl_hndl_avbl++;
  2995. }
  2996. psgl_handle++;
  2997. }
  2998. idx++;
  2999. }
  3000. SE_DEBUG(DBG_LVL_8,
  3001. "phba->io_sgl_hndl_avbl=%d"
  3002. "phba->eh_sgl_hndl_avbl=%d\n",
  3003. phba->io_sgl_hndl_avbl,
  3004. phba->eh_sgl_hndl_avbl);
  3005. mem_descr_sg = phba->init_mem;
  3006. mem_descr_sg += HWI_MEM_SGE;
  3007. SE_DEBUG(DBG_LVL_8, "\n mem_descr_sg->num_elements=%d\n",
  3008. mem_descr_sg->num_elements);
  3009. arr_index = 0;
  3010. idx = 0;
  3011. while (idx < mem_descr_sg->num_elements) {
  3012. pfrag = mem_descr_sg->mem_array[idx].virtual_address;
  3013. for (i = 0;
  3014. i < (mem_descr_sg->mem_array[idx].size) /
  3015. (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
  3016. i++) {
  3017. if (arr_index < phba->params.ios_per_ctrl)
  3018. psgl_handle = phba->io_sgl_hndl_base[arr_index];
  3019. else
  3020. psgl_handle = phba->eh_sgl_hndl_base[arr_index -
  3021. phba->params.ios_per_ctrl];
  3022. psgl_handle->pfrag = pfrag;
  3023. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
  3024. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
  3025. pfrag += phba->params.num_sge_per_io;
  3026. psgl_handle->sgl_index =
  3027. phba->fw_config.iscsi_icd_start + arr_index++;
  3028. }
  3029. idx++;
  3030. }
  3031. phba->io_sgl_free_index = 0;
  3032. phba->io_sgl_alloc_index = 0;
  3033. phba->eh_sgl_free_index = 0;
  3034. phba->eh_sgl_alloc_index = 0;
  3035. return 0;
  3036. }
  3037. static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
  3038. {
  3039. int i, new_cid;
  3040. phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
  3041. GFP_KERNEL);
  3042. if (!phba->cid_array) {
  3043. shost_printk(KERN_ERR, phba->shost,
  3044. "Failed to allocate memory in "
  3045. "hba_setup_cid_tbls\n");
  3046. return -ENOMEM;
  3047. }
  3048. phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
  3049. phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
  3050. if (!phba->ep_array) {
  3051. shost_printk(KERN_ERR, phba->shost,
  3052. "Failed to allocate memory in "
  3053. "hba_setup_cid_tbls\n");
  3054. kfree(phba->cid_array);
  3055. return -ENOMEM;
  3056. }
  3057. new_cid = phba->fw_config.iscsi_cid_start;
  3058. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3059. phba->cid_array[i] = new_cid;
  3060. new_cid += 2;
  3061. }
  3062. phba->avlbl_cids = phba->params.cxns_per_ctrl;
  3063. return 0;
  3064. }
  3065. static void hwi_enable_intr(struct beiscsi_hba *phba)
  3066. {
  3067. struct be_ctrl_info *ctrl = &phba->ctrl;
  3068. struct hwi_controller *phwi_ctrlr;
  3069. struct hwi_context_memory *phwi_context;
  3070. struct be_queue_info *eq;
  3071. u8 __iomem *addr;
  3072. u32 reg, i;
  3073. u32 enabled;
  3074. phwi_ctrlr = phba->phwi_ctrlr;
  3075. phwi_context = phwi_ctrlr->phwi_ctxt;
  3076. addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
  3077. PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
  3078. reg = ioread32(addr);
  3079. enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3080. if (!enabled) {
  3081. reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3082. SE_DEBUG(DBG_LVL_8, "reg =x%08x addr=%p\n", reg, addr);
  3083. iowrite32(reg, addr);
  3084. }
  3085. if (!phba->msix_enabled) {
  3086. eq = &phwi_context->be_eq[0].q;
  3087. SE_DEBUG(DBG_LVL_8, "eq->id=%d\n", eq->id);
  3088. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3089. } else {
  3090. for (i = 0; i <= phba->num_cpus; i++) {
  3091. eq = &phwi_context->be_eq[i].q;
  3092. SE_DEBUG(DBG_LVL_8, "eq->id=%d\n", eq->id);
  3093. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3094. }
  3095. }
  3096. }
  3097. static void hwi_disable_intr(struct beiscsi_hba *phba)
  3098. {
  3099. struct be_ctrl_info *ctrl = &phba->ctrl;
  3100. u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
  3101. u32 reg = ioread32(addr);
  3102. u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3103. if (enabled) {
  3104. reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3105. iowrite32(reg, addr);
  3106. } else
  3107. shost_printk(KERN_WARNING, phba->shost,
  3108. "In hwi_disable_intr, Already Disabled\n");
  3109. }
  3110. static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
  3111. {
  3112. struct be_cmd_resp_get_boot_target *boot_resp;
  3113. struct be_cmd_resp_get_session *session_resp;
  3114. struct be_mcc_wrb *wrb;
  3115. struct be_dma_mem nonemb_cmd;
  3116. unsigned int tag, wrb_num;
  3117. unsigned short status, extd_status;
  3118. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  3119. int ret = -ENOMEM;
  3120. tag = beiscsi_get_boot_target(phba);
  3121. if (!tag) {
  3122. SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n");
  3123. return -EAGAIN;
  3124. } else
  3125. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  3126. phba->ctrl.mcc_numtag[tag]);
  3127. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  3128. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  3129. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  3130. if (status || extd_status) {
  3131. SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed"
  3132. " status = %d extd_status = %d\n",
  3133. status, extd_status);
  3134. free_mcc_tag(&phba->ctrl, tag);
  3135. return -EBUSY;
  3136. }
  3137. wrb = queue_get_wrb(mccq, wrb_num);
  3138. free_mcc_tag(&phba->ctrl, tag);
  3139. boot_resp = embedded_payload(wrb);
  3140. if (boot_resp->boot_session_handle < 0) {
  3141. shost_printk(KERN_INFO, phba->shost, "No Boot Session.\n");
  3142. return -ENXIO;
  3143. }
  3144. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  3145. sizeof(*session_resp),
  3146. &nonemb_cmd.dma);
  3147. if (nonemb_cmd.va == NULL) {
  3148. SE_DEBUG(DBG_LVL_1,
  3149. "Failed to allocate memory for"
  3150. "beiscsi_get_session_info\n");
  3151. return -ENOMEM;
  3152. }
  3153. memset(nonemb_cmd.va, 0, sizeof(*session_resp));
  3154. tag = beiscsi_get_session_info(phba,
  3155. boot_resp->boot_session_handle, &nonemb_cmd);
  3156. if (!tag) {
  3157. SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info"
  3158. " Failed\n");
  3159. goto boot_freemem;
  3160. } else
  3161. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  3162. phba->ctrl.mcc_numtag[tag]);
  3163. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  3164. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  3165. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  3166. if (status || extd_status) {
  3167. SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info Failed"
  3168. " status = %d extd_status = %d\n",
  3169. status, extd_status);
  3170. free_mcc_tag(&phba->ctrl, tag);
  3171. goto boot_freemem;
  3172. }
  3173. wrb = queue_get_wrb(mccq, wrb_num);
  3174. free_mcc_tag(&phba->ctrl, tag);
  3175. session_resp = nonemb_cmd.va ;
  3176. memcpy(&phba->boot_sess, &session_resp->session_info,
  3177. sizeof(struct mgmt_session_info));
  3178. ret = 0;
  3179. boot_freemem:
  3180. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  3181. nonemb_cmd.va, nonemb_cmd.dma);
  3182. return ret;
  3183. }
  3184. static void beiscsi_boot_release(void *data)
  3185. {
  3186. struct beiscsi_hba *phba = data;
  3187. scsi_host_put(phba->shost);
  3188. }
  3189. static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
  3190. {
  3191. struct iscsi_boot_kobj *boot_kobj;
  3192. /* get boot info using mgmt cmd */
  3193. if (beiscsi_get_boot_info(phba))
  3194. /* Try to see if we can carry on without this */
  3195. return 0;
  3196. phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
  3197. if (!phba->boot_kset)
  3198. return -ENOMEM;
  3199. /* get a ref because the show function will ref the phba */
  3200. if (!scsi_host_get(phba->shost))
  3201. goto free_kset;
  3202. boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
  3203. beiscsi_show_boot_tgt_info,
  3204. beiscsi_tgt_get_attr_visibility,
  3205. beiscsi_boot_release);
  3206. if (!boot_kobj)
  3207. goto put_shost;
  3208. if (!scsi_host_get(phba->shost))
  3209. goto free_kset;
  3210. boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
  3211. beiscsi_show_boot_ini_info,
  3212. beiscsi_ini_get_attr_visibility,
  3213. beiscsi_boot_release);
  3214. if (!boot_kobj)
  3215. goto put_shost;
  3216. if (!scsi_host_get(phba->shost))
  3217. goto free_kset;
  3218. boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
  3219. beiscsi_show_boot_eth_info,
  3220. beiscsi_eth_get_attr_visibility,
  3221. beiscsi_boot_release);
  3222. if (!boot_kobj)
  3223. goto put_shost;
  3224. return 0;
  3225. put_shost:
  3226. scsi_host_put(phba->shost);
  3227. free_kset:
  3228. iscsi_boot_destroy_kset(phba->boot_kset);
  3229. return -ENOMEM;
  3230. }
  3231. static int beiscsi_init_port(struct beiscsi_hba *phba)
  3232. {
  3233. int ret;
  3234. ret = beiscsi_init_controller(phba);
  3235. if (ret < 0) {
  3236. shost_printk(KERN_ERR, phba->shost,
  3237. "beiscsi_dev_probe - Failed in"
  3238. "beiscsi_init_controller\n");
  3239. return ret;
  3240. }
  3241. ret = beiscsi_init_sgl_handle(phba);
  3242. if (ret < 0) {
  3243. shost_printk(KERN_ERR, phba->shost,
  3244. "beiscsi_dev_probe - Failed in"
  3245. "beiscsi_init_sgl_handle\n");
  3246. goto do_cleanup_ctrlr;
  3247. }
  3248. if (hba_setup_cid_tbls(phba)) {
  3249. shost_printk(KERN_ERR, phba->shost,
  3250. "Failed in hba_setup_cid_tbls\n");
  3251. kfree(phba->io_sgl_hndl_base);
  3252. kfree(phba->eh_sgl_hndl_base);
  3253. goto do_cleanup_ctrlr;
  3254. }
  3255. return ret;
  3256. do_cleanup_ctrlr:
  3257. hwi_cleanup(phba);
  3258. return ret;
  3259. }
  3260. static void hwi_purge_eq(struct beiscsi_hba *phba)
  3261. {
  3262. struct hwi_controller *phwi_ctrlr;
  3263. struct hwi_context_memory *phwi_context;
  3264. struct be_queue_info *eq;
  3265. struct be_eq_entry *eqe = NULL;
  3266. int i, eq_msix;
  3267. unsigned int num_processed;
  3268. phwi_ctrlr = phba->phwi_ctrlr;
  3269. phwi_context = phwi_ctrlr->phwi_ctxt;
  3270. if (phba->msix_enabled)
  3271. eq_msix = 1;
  3272. else
  3273. eq_msix = 0;
  3274. for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
  3275. eq = &phwi_context->be_eq[i].q;
  3276. eqe = queue_tail_node(eq);
  3277. num_processed = 0;
  3278. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  3279. & EQE_VALID_MASK) {
  3280. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  3281. queue_tail_inc(eq);
  3282. eqe = queue_tail_node(eq);
  3283. num_processed++;
  3284. }
  3285. if (num_processed)
  3286. hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
  3287. }
  3288. }
  3289. static void beiscsi_clean_port(struct beiscsi_hba *phba)
  3290. {
  3291. int mgmt_status;
  3292. mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
  3293. if (mgmt_status)
  3294. shost_printk(KERN_WARNING, phba->shost,
  3295. "mgmt_epfw_cleanup FAILED\n");
  3296. hwi_purge_eq(phba);
  3297. hwi_cleanup(phba);
  3298. kfree(phba->io_sgl_hndl_base);
  3299. kfree(phba->eh_sgl_hndl_base);
  3300. kfree(phba->cid_array);
  3301. kfree(phba->ep_array);
  3302. }
  3303. void
  3304. beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
  3305. struct beiscsi_offload_params *params)
  3306. {
  3307. struct wrb_handle *pwrb_handle;
  3308. struct iscsi_target_context_update_wrb *pwrb = NULL;
  3309. struct be_mem_descriptor *mem_descr;
  3310. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3311. u32 doorbell = 0;
  3312. /*
  3313. * We can always use 0 here because it is reserved by libiscsi for
  3314. * login/startup related tasks.
  3315. */
  3316. pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
  3317. phba->fw_config.iscsi_cid_start));
  3318. pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb;
  3319. memset(pwrb, 0, sizeof(*pwrb));
  3320. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3321. max_burst_length, pwrb, params->dw[offsetof
  3322. (struct amap_beiscsi_offload_params,
  3323. max_burst_length) / 32]);
  3324. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3325. max_send_data_segment_length, pwrb,
  3326. params->dw[offsetof(struct amap_beiscsi_offload_params,
  3327. max_send_data_segment_length) / 32]);
  3328. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3329. first_burst_length,
  3330. pwrb,
  3331. params->dw[offsetof(struct amap_beiscsi_offload_params,
  3332. first_burst_length) / 32]);
  3333. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
  3334. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3335. erl) / 32] & OFFLD_PARAMS_ERL));
  3336. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
  3337. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3338. dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
  3339. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
  3340. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3341. hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
  3342. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
  3343. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3344. ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
  3345. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
  3346. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3347. imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
  3348. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
  3349. pwrb,
  3350. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3351. exp_statsn) / 32] + 1));
  3352. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
  3353. 0x7);
  3354. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
  3355. pwrb, pwrb_handle->wrb_index);
  3356. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
  3357. pwrb, pwrb_handle->nxt_wrb_index);
  3358. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3359. session_state, pwrb, 0);
  3360. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
  3361. pwrb, 1);
  3362. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
  3363. pwrb, 0);
  3364. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
  3365. 0);
  3366. mem_descr = phba->init_mem;
  3367. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  3368. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3369. pad_buffer_addr_hi, pwrb,
  3370. mem_descr->mem_array[0].bus_address.u.a32.address_hi);
  3371. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3372. pad_buffer_addr_lo, pwrb,
  3373. mem_descr->mem_array[0].bus_address.u.a32.address_lo);
  3374. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
  3375. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3376. doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
  3377. << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3378. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3379. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3380. }
  3381. static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
  3382. int *index, int *age)
  3383. {
  3384. *index = (int)itt;
  3385. if (age)
  3386. *age = conn->session->age;
  3387. }
  3388. /**
  3389. * beiscsi_alloc_pdu - allocates pdu and related resources
  3390. * @task: libiscsi task
  3391. * @opcode: opcode of pdu for task
  3392. *
  3393. * This is called with the session lock held. It will allocate
  3394. * the wrb and sgl if needed for the command. And it will prep
  3395. * the pdu's itt. beiscsi_parse_pdu will later translate
  3396. * the pdu itt to the libiscsi task itt.
  3397. */
  3398. static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  3399. {
  3400. struct beiscsi_io_task *io_task = task->dd_data;
  3401. struct iscsi_conn *conn = task->conn;
  3402. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3403. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3404. struct hwi_wrb_context *pwrb_context;
  3405. struct hwi_controller *phwi_ctrlr;
  3406. itt_t itt;
  3407. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3408. dma_addr_t paddr;
  3409. io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
  3410. GFP_ATOMIC, &paddr);
  3411. if (!io_task->cmd_bhs)
  3412. return -ENOMEM;
  3413. io_task->bhs_pa.u.a64.address = paddr;
  3414. io_task->libiscsi_itt = (itt_t)task->itt;
  3415. io_task->conn = beiscsi_conn;
  3416. task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
  3417. task->hdr_max = sizeof(struct be_cmd_bhs);
  3418. io_task->psgl_handle = NULL;
  3419. io_task->psgl_handle = NULL;
  3420. if (task->sc) {
  3421. spin_lock(&phba->io_sgl_lock);
  3422. io_task->psgl_handle = alloc_io_sgl_handle(phba);
  3423. spin_unlock(&phba->io_sgl_lock);
  3424. if (!io_task->psgl_handle)
  3425. goto free_hndls;
  3426. io_task->pwrb_handle = alloc_wrb_handle(phba,
  3427. beiscsi_conn->beiscsi_conn_cid -
  3428. phba->fw_config.iscsi_cid_start);
  3429. if (!io_task->pwrb_handle)
  3430. goto free_io_hndls;
  3431. } else {
  3432. io_task->scsi_cmnd = NULL;
  3433. if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
  3434. if (!beiscsi_conn->login_in_progress) {
  3435. spin_lock(&phba->mgmt_sgl_lock);
  3436. io_task->psgl_handle = (struct sgl_handle *)
  3437. alloc_mgmt_sgl_handle(phba);
  3438. spin_unlock(&phba->mgmt_sgl_lock);
  3439. if (!io_task->psgl_handle)
  3440. goto free_hndls;
  3441. beiscsi_conn->login_in_progress = 1;
  3442. beiscsi_conn->plogin_sgl_handle =
  3443. io_task->psgl_handle;
  3444. io_task->pwrb_handle =
  3445. alloc_wrb_handle(phba,
  3446. beiscsi_conn->beiscsi_conn_cid -
  3447. phba->fw_config.iscsi_cid_start);
  3448. if (!io_task->pwrb_handle)
  3449. goto free_io_hndls;
  3450. beiscsi_conn->plogin_wrb_handle =
  3451. io_task->pwrb_handle;
  3452. } else {
  3453. io_task->psgl_handle =
  3454. beiscsi_conn->plogin_sgl_handle;
  3455. io_task->pwrb_handle =
  3456. beiscsi_conn->plogin_wrb_handle;
  3457. }
  3458. } else {
  3459. spin_lock(&phba->mgmt_sgl_lock);
  3460. io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
  3461. spin_unlock(&phba->mgmt_sgl_lock);
  3462. if (!io_task->psgl_handle)
  3463. goto free_hndls;
  3464. io_task->pwrb_handle =
  3465. alloc_wrb_handle(phba,
  3466. beiscsi_conn->beiscsi_conn_cid -
  3467. phba->fw_config.iscsi_cid_start);
  3468. if (!io_task->pwrb_handle)
  3469. goto free_mgmt_hndls;
  3470. }
  3471. }
  3472. itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
  3473. wrb_index << 16) | (unsigned int)
  3474. (io_task->psgl_handle->sgl_index));
  3475. io_task->pwrb_handle->pio_handle = task;
  3476. io_task->cmd_bhs->iscsi_hdr.itt = itt;
  3477. return 0;
  3478. free_io_hndls:
  3479. spin_lock(&phba->io_sgl_lock);
  3480. free_io_sgl_handle(phba, io_task->psgl_handle);
  3481. spin_unlock(&phba->io_sgl_lock);
  3482. goto free_hndls;
  3483. free_mgmt_hndls:
  3484. spin_lock(&phba->mgmt_sgl_lock);
  3485. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  3486. spin_unlock(&phba->mgmt_sgl_lock);
  3487. free_hndls:
  3488. phwi_ctrlr = phba->phwi_ctrlr;
  3489. pwrb_context = &phwi_ctrlr->wrb_context[
  3490. beiscsi_conn->beiscsi_conn_cid -
  3491. phba->fw_config.iscsi_cid_start];
  3492. if (io_task->pwrb_handle)
  3493. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  3494. io_task->pwrb_handle = NULL;
  3495. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3496. io_task->bhs_pa.u.a64.address);
  3497. SE_DEBUG(DBG_LVL_1, "Alloc of SGL_ICD Failed\n");
  3498. return -ENOMEM;
  3499. }
  3500. static void beiscsi_cleanup_task(struct iscsi_task *task)
  3501. {
  3502. struct beiscsi_io_task *io_task = task->dd_data;
  3503. struct iscsi_conn *conn = task->conn;
  3504. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3505. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3506. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3507. struct hwi_wrb_context *pwrb_context;
  3508. struct hwi_controller *phwi_ctrlr;
  3509. phwi_ctrlr = phba->phwi_ctrlr;
  3510. pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
  3511. - phba->fw_config.iscsi_cid_start];
  3512. if (io_task->pwrb_handle) {
  3513. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  3514. io_task->pwrb_handle = NULL;
  3515. }
  3516. if (io_task->cmd_bhs) {
  3517. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3518. io_task->bhs_pa.u.a64.address);
  3519. }
  3520. if (task->sc) {
  3521. if (io_task->psgl_handle) {
  3522. spin_lock(&phba->io_sgl_lock);
  3523. free_io_sgl_handle(phba, io_task->psgl_handle);
  3524. spin_unlock(&phba->io_sgl_lock);
  3525. io_task->psgl_handle = NULL;
  3526. }
  3527. } else {
  3528. if (task->hdr &&
  3529. ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN))
  3530. return;
  3531. if (io_task->psgl_handle) {
  3532. spin_lock(&phba->mgmt_sgl_lock);
  3533. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  3534. spin_unlock(&phba->mgmt_sgl_lock);
  3535. io_task->psgl_handle = NULL;
  3536. }
  3537. }
  3538. }
  3539. static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
  3540. unsigned int num_sg, unsigned int xferlen,
  3541. unsigned int writedir)
  3542. {
  3543. struct beiscsi_io_task *io_task = task->dd_data;
  3544. struct iscsi_conn *conn = task->conn;
  3545. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3546. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3547. struct iscsi_wrb *pwrb = NULL;
  3548. unsigned int doorbell = 0;
  3549. pwrb = io_task->pwrb_handle->pwrb;
  3550. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  3551. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  3552. if (writedir) {
  3553. memset(&io_task->cmd_bhs->iscsi_data_pdu, 0, 48);
  3554. AMAP_SET_BITS(struct amap_pdu_data_out, itt,
  3555. &io_task->cmd_bhs->iscsi_data_pdu,
  3556. (unsigned int)io_task->cmd_bhs->iscsi_hdr.itt);
  3557. AMAP_SET_BITS(struct amap_pdu_data_out, opcode,
  3558. &io_task->cmd_bhs->iscsi_data_pdu,
  3559. ISCSI_OPCODE_SCSI_DATA_OUT);
  3560. AMAP_SET_BITS(struct amap_pdu_data_out, final_bit,
  3561. &io_task->cmd_bhs->iscsi_data_pdu, 1);
  3562. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3563. INI_WR_CMD);
  3564. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  3565. } else {
  3566. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3567. INI_RD_CMD);
  3568. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  3569. }
  3570. memcpy(&io_task->cmd_bhs->iscsi_data_pdu.
  3571. dw[offsetof(struct amap_pdu_data_out, lun) / 32],
  3572. &io_task->cmd_bhs->iscsi_hdr.lun, sizeof(struct scsi_lun));
  3573. AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
  3574. cpu_to_be16(*(unsigned short *)&io_task->cmd_bhs->iscsi_hdr.lun));
  3575. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
  3576. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3577. io_task->pwrb_handle->wrb_index);
  3578. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3579. be32_to_cpu(task->cmdsn));
  3580. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3581. io_task->psgl_handle->sgl_index);
  3582. hwi_write_sgl(pwrb, sg, num_sg, io_task);
  3583. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3584. io_task->pwrb_handle->nxt_wrb_index);
  3585. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3586. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3587. doorbell |= (io_task->pwrb_handle->wrb_index &
  3588. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3589. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3590. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3591. return 0;
  3592. }
  3593. static int beiscsi_mtask(struct iscsi_task *task)
  3594. {
  3595. struct beiscsi_io_task *io_task = task->dd_data;
  3596. struct iscsi_conn *conn = task->conn;
  3597. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3598. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3599. struct iscsi_wrb *pwrb = NULL;
  3600. unsigned int doorbell = 0;
  3601. unsigned int cid;
  3602. cid = beiscsi_conn->beiscsi_conn_cid;
  3603. pwrb = io_task->pwrb_handle->pwrb;
  3604. memset(pwrb, 0, sizeof(*pwrb));
  3605. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3606. be32_to_cpu(task->cmdsn));
  3607. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3608. io_task->pwrb_handle->wrb_index);
  3609. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3610. io_task->psgl_handle->sgl_index);
  3611. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  3612. case ISCSI_OP_LOGIN:
  3613. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3614. TGT_DM_CMD);
  3615. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3616. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
  3617. hwi_write_buffer(pwrb, task);
  3618. break;
  3619. case ISCSI_OP_NOOP_OUT:
  3620. if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
  3621. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3622. TGT_DM_CMD);
  3623. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt,
  3624. pwrb, 0);
  3625. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
  3626. } else {
  3627. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3628. INI_RD_CMD);
  3629. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3630. }
  3631. hwi_write_buffer(pwrb, task);
  3632. break;
  3633. case ISCSI_OP_TEXT:
  3634. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3635. TGT_DM_CMD);
  3636. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3637. hwi_write_buffer(pwrb, task);
  3638. break;
  3639. case ISCSI_OP_SCSI_TMFUNC:
  3640. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3641. INI_TMF_CMD);
  3642. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3643. hwi_write_buffer(pwrb, task);
  3644. break;
  3645. case ISCSI_OP_LOGOUT:
  3646. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3647. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3648. HWH_TYPE_LOGOUT);
  3649. hwi_write_buffer(pwrb, task);
  3650. break;
  3651. default:
  3652. SE_DEBUG(DBG_LVL_1, "opcode =%d Not supported\n",
  3653. task->hdr->opcode & ISCSI_OPCODE_MASK);
  3654. return -EINVAL;
  3655. }
  3656. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
  3657. task->data_count);
  3658. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3659. io_task->pwrb_handle->nxt_wrb_index);
  3660. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3661. doorbell |= cid & DB_WRB_POST_CID_MASK;
  3662. doorbell |= (io_task->pwrb_handle->wrb_index &
  3663. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3664. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3665. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3666. return 0;
  3667. }
  3668. static int beiscsi_task_xmit(struct iscsi_task *task)
  3669. {
  3670. struct beiscsi_io_task *io_task = task->dd_data;
  3671. struct scsi_cmnd *sc = task->sc;
  3672. struct scatterlist *sg;
  3673. int num_sg;
  3674. unsigned int writedir = 0, xferlen = 0;
  3675. if (!sc)
  3676. return beiscsi_mtask(task);
  3677. io_task->scsi_cmnd = sc;
  3678. num_sg = scsi_dma_map(sc);
  3679. if (num_sg < 0) {
  3680. SE_DEBUG(DBG_LVL_1, " scsi_dma_map Failed\n")
  3681. return num_sg;
  3682. }
  3683. xferlen = scsi_bufflen(sc);
  3684. sg = scsi_sglist(sc);
  3685. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  3686. writedir = 1;
  3687. SE_DEBUG(DBG_LVL_4, "task->imm_count=0x%08x\n",
  3688. task->imm_count);
  3689. } else
  3690. writedir = 0;
  3691. return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
  3692. }
  3693. static void beiscsi_quiesce(struct beiscsi_hba *phba)
  3694. {
  3695. struct hwi_controller *phwi_ctrlr;
  3696. struct hwi_context_memory *phwi_context;
  3697. struct be_eq_obj *pbe_eq;
  3698. unsigned int i, msix_vec;
  3699. u8 *real_offset = 0;
  3700. u32 value = 0;
  3701. phwi_ctrlr = phba->phwi_ctrlr;
  3702. phwi_context = phwi_ctrlr->phwi_ctxt;
  3703. hwi_disable_intr(phba);
  3704. if (phba->msix_enabled) {
  3705. for (i = 0; i <= phba->num_cpus; i++) {
  3706. msix_vec = phba->msix_entries[i].vector;
  3707. free_irq(msix_vec, &phwi_context->be_eq[i]);
  3708. kfree(phba->msi_name[i]);
  3709. }
  3710. } else
  3711. if (phba->pcidev->irq)
  3712. free_irq(phba->pcidev->irq, phba);
  3713. pci_disable_msix(phba->pcidev);
  3714. destroy_workqueue(phba->wq);
  3715. if (blk_iopoll_enabled)
  3716. for (i = 0; i < phba->num_cpus; i++) {
  3717. pbe_eq = &phwi_context->be_eq[i];
  3718. blk_iopoll_disable(&pbe_eq->iopoll);
  3719. }
  3720. beiscsi_clean_port(phba);
  3721. beiscsi_free_mem(phba);
  3722. real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  3723. value = readl((void *)real_offset);
  3724. if (value & 0x00010000) {
  3725. value &= 0xfffeffff;
  3726. writel(value, (void *)real_offset);
  3727. }
  3728. beiscsi_unmap_pci_function(phba);
  3729. pci_free_consistent(phba->pcidev,
  3730. phba->ctrl.mbox_mem_alloced.size,
  3731. phba->ctrl.mbox_mem_alloced.va,
  3732. phba->ctrl.mbox_mem_alloced.dma);
  3733. }
  3734. static void beiscsi_remove(struct pci_dev *pcidev)
  3735. {
  3736. struct beiscsi_hba *phba = NULL;
  3737. phba = pci_get_drvdata(pcidev);
  3738. if (!phba) {
  3739. dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
  3740. return;
  3741. }
  3742. beiscsi_quiesce(phba);
  3743. iscsi_boot_destroy_kset(phba->boot_kset);
  3744. iscsi_host_remove(phba->shost);
  3745. pci_dev_put(phba->pcidev);
  3746. iscsi_host_free(phba->shost);
  3747. pci_disable_device(pcidev);
  3748. }
  3749. static void beiscsi_shutdown(struct pci_dev *pcidev)
  3750. {
  3751. struct beiscsi_hba *phba = NULL;
  3752. phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
  3753. if (!phba) {
  3754. dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
  3755. return;
  3756. }
  3757. beiscsi_quiesce(phba);
  3758. pci_disable_device(pcidev);
  3759. }
  3760. static void beiscsi_msix_enable(struct beiscsi_hba *phba)
  3761. {
  3762. int i, status;
  3763. for (i = 0; i <= phba->num_cpus; i++)
  3764. phba->msix_entries[i].entry = i;
  3765. status = pci_enable_msix(phba->pcidev, phba->msix_entries,
  3766. (phba->num_cpus + 1));
  3767. if (!status)
  3768. phba->msix_enabled = true;
  3769. return;
  3770. }
  3771. static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
  3772. const struct pci_device_id *id)
  3773. {
  3774. struct beiscsi_hba *phba = NULL;
  3775. struct hwi_controller *phwi_ctrlr;
  3776. struct hwi_context_memory *phwi_context;
  3777. struct be_eq_obj *pbe_eq;
  3778. int ret, num_cpus, i;
  3779. u8 *real_offset = 0;
  3780. u32 value = 0;
  3781. ret = beiscsi_enable_pci(pcidev);
  3782. if (ret < 0) {
  3783. dev_err(&pcidev->dev, "beiscsi_dev_probe-"
  3784. " Failed to enable pci device\n");
  3785. return ret;
  3786. }
  3787. phba = beiscsi_hba_alloc(pcidev);
  3788. if (!phba) {
  3789. dev_err(&pcidev->dev, "beiscsi_dev_probe-"
  3790. " Failed in beiscsi_hba_alloc\n");
  3791. goto disable_pci;
  3792. }
  3793. switch (pcidev->device) {
  3794. case BE_DEVICE_ID1:
  3795. case OC_DEVICE_ID1:
  3796. case OC_DEVICE_ID2:
  3797. phba->generation = BE_GEN2;
  3798. break;
  3799. case BE_DEVICE_ID2:
  3800. case OC_DEVICE_ID3:
  3801. phba->generation = BE_GEN3;
  3802. break;
  3803. default:
  3804. phba->generation = 0;
  3805. }
  3806. if (enable_msix)
  3807. num_cpus = find_num_cpus();
  3808. else
  3809. num_cpus = 1;
  3810. phba->num_cpus = num_cpus;
  3811. SE_DEBUG(DBG_LVL_8, "num_cpus = %d\n", phba->num_cpus);
  3812. if (enable_msix)
  3813. beiscsi_msix_enable(phba);
  3814. ret = be_ctrl_init(phba, pcidev);
  3815. if (ret) {
  3816. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3817. "Failed in be_ctrl_init\n");
  3818. goto hba_free;
  3819. }
  3820. if (!num_hba) {
  3821. real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  3822. value = readl((void *)real_offset);
  3823. if (value & 0x00010000) {
  3824. gcrashmode++;
  3825. shost_printk(KERN_ERR, phba->shost,
  3826. "Loading Driver in crashdump mode\n");
  3827. ret = beiscsi_cmd_reset_function(phba);
  3828. if (ret) {
  3829. shost_printk(KERN_ERR, phba->shost,
  3830. "Reset Failed. Aborting Crashdump\n");
  3831. goto hba_free;
  3832. }
  3833. ret = be_chk_reset_complete(phba);
  3834. if (ret) {
  3835. shost_printk(KERN_ERR, phba->shost,
  3836. "Failed to get out of reset."
  3837. "Aborting Crashdump\n");
  3838. goto hba_free;
  3839. }
  3840. } else {
  3841. value |= 0x00010000;
  3842. writel(value, (void *)real_offset);
  3843. num_hba++;
  3844. }
  3845. }
  3846. spin_lock_init(&phba->io_sgl_lock);
  3847. spin_lock_init(&phba->mgmt_sgl_lock);
  3848. spin_lock_init(&phba->isr_lock);
  3849. ret = mgmt_get_fw_config(&phba->ctrl, phba);
  3850. if (ret != 0) {
  3851. shost_printk(KERN_ERR, phba->shost,
  3852. "Error getting fw config\n");
  3853. goto free_port;
  3854. }
  3855. phba->shost->max_id = phba->fw_config.iscsi_cid_count;
  3856. beiscsi_get_params(phba);
  3857. phba->shost->can_queue = phba->params.ios_per_ctrl;
  3858. ret = beiscsi_init_port(phba);
  3859. if (ret < 0) {
  3860. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3861. "Failed in beiscsi_init_port\n");
  3862. goto free_port;
  3863. }
  3864. for (i = 0; i < MAX_MCC_CMD ; i++) {
  3865. init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
  3866. phba->ctrl.mcc_tag[i] = i + 1;
  3867. phba->ctrl.mcc_numtag[i + 1] = 0;
  3868. phba->ctrl.mcc_tag_available++;
  3869. }
  3870. phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
  3871. snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_q_irq%u",
  3872. phba->shost->host_no);
  3873. phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
  3874. if (!phba->wq) {
  3875. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3876. "Failed to allocate work queue\n");
  3877. goto free_twq;
  3878. }
  3879. INIT_WORK(&phba->work_cqs, beiscsi_process_all_cqs);
  3880. phwi_ctrlr = phba->phwi_ctrlr;
  3881. phwi_context = phwi_ctrlr->phwi_ctxt;
  3882. if (blk_iopoll_enabled) {
  3883. for (i = 0; i < phba->num_cpus; i++) {
  3884. pbe_eq = &phwi_context->be_eq[i];
  3885. blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
  3886. be_iopoll);
  3887. blk_iopoll_enable(&pbe_eq->iopoll);
  3888. }
  3889. }
  3890. ret = beiscsi_init_irqs(phba);
  3891. if (ret < 0) {
  3892. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3893. "Failed to beiscsi_init_irqs\n");
  3894. goto free_blkenbld;
  3895. }
  3896. hwi_enable_intr(phba);
  3897. if (beiscsi_setup_boot_info(phba))
  3898. /*
  3899. * log error but continue, because we may not be using
  3900. * iscsi boot.
  3901. */
  3902. shost_printk(KERN_ERR, phba->shost, "Could not set up "
  3903. "iSCSI boot info.");
  3904. SE_DEBUG(DBG_LVL_8, "\n\n\n SUCCESS - DRIVER LOADED\n\n\n");
  3905. return 0;
  3906. free_blkenbld:
  3907. destroy_workqueue(phba->wq);
  3908. if (blk_iopoll_enabled)
  3909. for (i = 0; i < phba->num_cpus; i++) {
  3910. pbe_eq = &phwi_context->be_eq[i];
  3911. blk_iopoll_disable(&pbe_eq->iopoll);
  3912. }
  3913. free_twq:
  3914. beiscsi_clean_port(phba);
  3915. beiscsi_free_mem(phba);
  3916. free_port:
  3917. real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  3918. value = readl((void *)real_offset);
  3919. if (value & 0x00010000) {
  3920. value &= 0xfffeffff;
  3921. writel(value, (void *)real_offset);
  3922. }
  3923. pci_free_consistent(phba->pcidev,
  3924. phba->ctrl.mbox_mem_alloced.size,
  3925. phba->ctrl.mbox_mem_alloced.va,
  3926. phba->ctrl.mbox_mem_alloced.dma);
  3927. beiscsi_unmap_pci_function(phba);
  3928. hba_free:
  3929. if (phba->msix_enabled)
  3930. pci_disable_msix(phba->pcidev);
  3931. iscsi_host_remove(phba->shost);
  3932. pci_dev_put(phba->pcidev);
  3933. iscsi_host_free(phba->shost);
  3934. disable_pci:
  3935. pci_disable_device(pcidev);
  3936. return ret;
  3937. }
  3938. struct iscsi_transport beiscsi_iscsi_transport = {
  3939. .owner = THIS_MODULE,
  3940. .name = DRV_NAME,
  3941. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
  3942. CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
  3943. .create_session = beiscsi_session_create,
  3944. .destroy_session = beiscsi_session_destroy,
  3945. .create_conn = beiscsi_conn_create,
  3946. .bind_conn = beiscsi_conn_bind,
  3947. .destroy_conn = iscsi_conn_teardown,
  3948. .attr_is_visible = be2iscsi_attr_is_visible,
  3949. .set_param = beiscsi_set_param,
  3950. .get_conn_param = iscsi_conn_get_param,
  3951. .get_session_param = iscsi_session_get_param,
  3952. .get_host_param = beiscsi_get_host_param,
  3953. .start_conn = beiscsi_conn_start,
  3954. .stop_conn = iscsi_conn_stop,
  3955. .send_pdu = iscsi_conn_send_pdu,
  3956. .xmit_task = beiscsi_task_xmit,
  3957. .cleanup_task = beiscsi_cleanup_task,
  3958. .alloc_pdu = beiscsi_alloc_pdu,
  3959. .parse_pdu_itt = beiscsi_parse_pdu,
  3960. .get_stats = beiscsi_conn_get_stats,
  3961. .get_ep_param = beiscsi_ep_get_param,
  3962. .ep_connect = beiscsi_ep_connect,
  3963. .ep_poll = beiscsi_ep_poll,
  3964. .ep_disconnect = beiscsi_ep_disconnect,
  3965. .session_recovery_timedout = iscsi_session_recovery_timedout,
  3966. };
  3967. static struct pci_driver beiscsi_pci_driver = {
  3968. .name = DRV_NAME,
  3969. .probe = beiscsi_dev_probe,
  3970. .remove = beiscsi_remove,
  3971. .shutdown = beiscsi_shutdown,
  3972. .id_table = beiscsi_pci_id_table
  3973. };
  3974. static int __init beiscsi_module_init(void)
  3975. {
  3976. int ret;
  3977. beiscsi_scsi_transport =
  3978. iscsi_register_transport(&beiscsi_iscsi_transport);
  3979. if (!beiscsi_scsi_transport) {
  3980. SE_DEBUG(DBG_LVL_1,
  3981. "beiscsi_module_init - Unable to register beiscsi"
  3982. "transport.\n");
  3983. return -ENOMEM;
  3984. }
  3985. SE_DEBUG(DBG_LVL_8, "In beiscsi_module_init, tt=%p\n",
  3986. &beiscsi_iscsi_transport);
  3987. ret = pci_register_driver(&beiscsi_pci_driver);
  3988. if (ret) {
  3989. SE_DEBUG(DBG_LVL_1,
  3990. "beiscsi_module_init - Unable to register"
  3991. "beiscsi pci driver.\n");
  3992. goto unregister_iscsi_transport;
  3993. }
  3994. return 0;
  3995. unregister_iscsi_transport:
  3996. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  3997. return ret;
  3998. }
  3999. static void __exit beiscsi_module_exit(void)
  4000. {
  4001. pci_unregister_driver(&beiscsi_pci_driver);
  4002. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  4003. }
  4004. module_init(beiscsi_module_init);
  4005. module_exit(beiscsi_module_exit);