be_main.c 114 KB

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