be_main.c 113 KB

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