be_main.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912
  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. } else {
  1489. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
  1490. pwrb, sge_len);
  1491. sg_len = sg_dma_len(sg);
  1492. addr = (u64) sg_dma_address(sg);
  1493. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
  1494. (addr & 0xFFFFFFFF));
  1495. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
  1496. (addr >> 32));
  1497. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
  1498. sg_len);
  1499. }
  1500. }
  1501. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  1502. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  1503. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  1504. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1505. io_task->bhs_pa.u.a32.address_hi);
  1506. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1507. io_task->bhs_pa.u.a32.address_lo);
  1508. if (num_sg == 1) {
  1509. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1510. 1);
  1511. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1512. 0);
  1513. } else if (num_sg == 2) {
  1514. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1515. 0);
  1516. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1517. 1);
  1518. } else {
  1519. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1520. 0);
  1521. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1522. 0);
  1523. }
  1524. sg = l_sg;
  1525. psgl++;
  1526. psgl++;
  1527. offset = 0;
  1528. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  1529. sg_len = sg_dma_len(sg);
  1530. addr = (u64) sg_dma_address(sg);
  1531. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1532. (addr & 0xFFFFFFFF));
  1533. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1534. (addr >> 32));
  1535. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  1536. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  1537. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  1538. offset += sg_len;
  1539. }
  1540. psgl--;
  1541. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  1542. }
  1543. static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
  1544. {
  1545. struct iscsi_sge *psgl;
  1546. unsigned long long addr;
  1547. struct beiscsi_io_task *io_task = task->dd_data;
  1548. struct beiscsi_conn *beiscsi_conn = io_task->conn;
  1549. struct beiscsi_hba *phba = beiscsi_conn->phba;
  1550. io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
  1551. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  1552. io_task->bhs_pa.u.a32.address_lo);
  1553. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  1554. io_task->bhs_pa.u.a32.address_hi);
  1555. if (task->data) {
  1556. if (task->data_count) {
  1557. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  1558. addr = (u64) pci_map_single(phba->pcidev,
  1559. task->data,
  1560. task->data_count, 1);
  1561. } else {
  1562. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  1563. addr = 0;
  1564. }
  1565. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  1566. (addr & 0xFFFFFFFF));
  1567. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  1568. (addr >> 32));
  1569. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  1570. task->data_count);
  1571. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
  1572. } else {
  1573. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  1574. addr = 0;
  1575. }
  1576. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  1577. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
  1578. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1579. io_task->bhs_pa.u.a32.address_hi);
  1580. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1581. io_task->bhs_pa.u.a32.address_lo);
  1582. if (task->data) {
  1583. psgl++;
  1584. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
  1585. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
  1586. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
  1587. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
  1588. AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
  1589. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  1590. psgl++;
  1591. if (task->data) {
  1592. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1593. (addr & 0xFFFFFFFF));
  1594. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1595. (addr >> 32));
  1596. }
  1597. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
  1598. }
  1599. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  1600. }
  1601. static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
  1602. {
  1603. unsigned int num_cq_pages, num_async_pdu_buf_pages;
  1604. unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
  1605. unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
  1606. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  1607. sizeof(struct sol_cqe));
  1608. num_async_pdu_buf_pages =
  1609. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1610. phba->params.defpdu_hdr_sz);
  1611. num_async_pdu_buf_sgl_pages =
  1612. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1613. sizeof(struct phys_addr));
  1614. num_async_pdu_data_pages =
  1615. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1616. phba->params.defpdu_data_sz);
  1617. num_async_pdu_data_sgl_pages =
  1618. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1619. sizeof(struct phys_addr));
  1620. phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
  1621. phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
  1622. BE_ISCSI_PDU_HEADER_SIZE;
  1623. phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
  1624. sizeof(struct hwi_context_memory);
  1625. phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
  1626. * (phba->params.wrbs_per_cxn)
  1627. * phba->params.cxns_per_ctrl;
  1628. wrb_sz_per_cxn = sizeof(struct wrb_handle) *
  1629. (phba->params.wrbs_per_cxn);
  1630. phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
  1631. phba->params.cxns_per_ctrl);
  1632. phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
  1633. phba->params.icds_per_ctrl;
  1634. phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
  1635. phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
  1636. phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
  1637. num_async_pdu_buf_pages * PAGE_SIZE;
  1638. phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
  1639. num_async_pdu_data_pages * PAGE_SIZE;
  1640. phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
  1641. num_async_pdu_buf_sgl_pages * PAGE_SIZE;
  1642. phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
  1643. num_async_pdu_data_sgl_pages * PAGE_SIZE;
  1644. phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
  1645. phba->params.asyncpdus_per_ctrl *
  1646. sizeof(struct async_pdu_handle);
  1647. phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
  1648. phba->params.asyncpdus_per_ctrl *
  1649. sizeof(struct async_pdu_handle);
  1650. phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
  1651. sizeof(struct hwi_async_pdu_context) +
  1652. (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
  1653. }
  1654. static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
  1655. {
  1656. struct be_mem_descriptor *mem_descr;
  1657. dma_addr_t bus_add;
  1658. struct mem_array *mem_arr, *mem_arr_orig;
  1659. unsigned int i, j, alloc_size, curr_alloc_size;
  1660. phba->phwi_ctrlr = kmalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
  1661. if (!phba->phwi_ctrlr)
  1662. return -ENOMEM;
  1663. phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
  1664. GFP_KERNEL);
  1665. if (!phba->init_mem) {
  1666. kfree(phba->phwi_ctrlr);
  1667. return -ENOMEM;
  1668. }
  1669. mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
  1670. GFP_KERNEL);
  1671. if (!mem_arr_orig) {
  1672. kfree(phba->init_mem);
  1673. kfree(phba->phwi_ctrlr);
  1674. return -ENOMEM;
  1675. }
  1676. mem_descr = phba->init_mem;
  1677. for (i = 0; i < SE_MEM_MAX; i++) {
  1678. j = 0;
  1679. mem_arr = mem_arr_orig;
  1680. alloc_size = phba->mem_req[i];
  1681. memset(mem_arr, 0, sizeof(struct mem_array) *
  1682. BEISCSI_MAX_FRAGS_INIT);
  1683. curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
  1684. do {
  1685. mem_arr->virtual_address = pci_alloc_consistent(
  1686. phba->pcidev,
  1687. curr_alloc_size,
  1688. &bus_add);
  1689. if (!mem_arr->virtual_address) {
  1690. if (curr_alloc_size <= BE_MIN_MEM_SIZE)
  1691. goto free_mem;
  1692. if (curr_alloc_size -
  1693. rounddown_pow_of_two(curr_alloc_size))
  1694. curr_alloc_size = rounddown_pow_of_two
  1695. (curr_alloc_size);
  1696. else
  1697. curr_alloc_size = curr_alloc_size / 2;
  1698. } else {
  1699. mem_arr->bus_address.u.
  1700. a64.address = (__u64) bus_add;
  1701. mem_arr->size = curr_alloc_size;
  1702. alloc_size -= curr_alloc_size;
  1703. curr_alloc_size = min(be_max_phys_size *
  1704. 1024, alloc_size);
  1705. j++;
  1706. mem_arr++;
  1707. }
  1708. } while (alloc_size);
  1709. mem_descr->num_elements = j;
  1710. mem_descr->size_in_bytes = phba->mem_req[i];
  1711. mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
  1712. GFP_KERNEL);
  1713. if (!mem_descr->mem_array)
  1714. goto free_mem;
  1715. memcpy(mem_descr->mem_array, mem_arr_orig,
  1716. sizeof(struct mem_array) * j);
  1717. mem_descr++;
  1718. }
  1719. kfree(mem_arr_orig);
  1720. return 0;
  1721. free_mem:
  1722. mem_descr->num_elements = j;
  1723. while ((i) || (j)) {
  1724. for (j = mem_descr->num_elements; j > 0; j--) {
  1725. pci_free_consistent(phba->pcidev,
  1726. mem_descr->mem_array[j - 1].size,
  1727. mem_descr->mem_array[j - 1].
  1728. virtual_address,
  1729. mem_descr->mem_array[j - 1].
  1730. bus_address.u.a64.address);
  1731. }
  1732. if (i) {
  1733. i--;
  1734. kfree(mem_descr->mem_array);
  1735. mem_descr--;
  1736. }
  1737. }
  1738. kfree(mem_arr_orig);
  1739. kfree(phba->init_mem);
  1740. kfree(phba->phwi_ctrlr);
  1741. return -ENOMEM;
  1742. }
  1743. static int beiscsi_get_memory(struct beiscsi_hba *phba)
  1744. {
  1745. beiscsi_find_mem_req(phba);
  1746. return beiscsi_alloc_mem(phba);
  1747. }
  1748. static void iscsi_init_global_templates(struct beiscsi_hba *phba)
  1749. {
  1750. struct pdu_data_out *pdata_out;
  1751. struct pdu_nop_out *pnop_out;
  1752. struct be_mem_descriptor *mem_descr;
  1753. mem_descr = phba->init_mem;
  1754. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  1755. pdata_out =
  1756. (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
  1757. memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  1758. AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
  1759. IIOC_SCSI_DATA);
  1760. pnop_out =
  1761. (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
  1762. virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
  1763. memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  1764. AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
  1765. AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
  1766. AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
  1767. }
  1768. static void beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
  1769. {
  1770. struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
  1771. struct wrb_handle *pwrb_handle;
  1772. struct hwi_controller *phwi_ctrlr;
  1773. struct hwi_wrb_context *pwrb_context;
  1774. struct iscsi_wrb *pwrb;
  1775. unsigned int num_cxn_wrbh;
  1776. unsigned int num_cxn_wrb, j, idx, index;
  1777. mem_descr_wrbh = phba->init_mem;
  1778. mem_descr_wrbh += HWI_MEM_WRBH;
  1779. mem_descr_wrb = phba->init_mem;
  1780. mem_descr_wrb += HWI_MEM_WRB;
  1781. idx = 0;
  1782. pwrb_handle = mem_descr_wrbh->mem_array[idx].virtual_address;
  1783. num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
  1784. ((sizeof(struct wrb_handle)) *
  1785. phba->params.wrbs_per_cxn));
  1786. phwi_ctrlr = phba->phwi_ctrlr;
  1787. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  1788. pwrb_context = &phwi_ctrlr->wrb_context[index];
  1789. pwrb_context->pwrb_handle_base =
  1790. kzalloc(sizeof(struct wrb_handle *) *
  1791. phba->params.wrbs_per_cxn, GFP_KERNEL);
  1792. pwrb_context->pwrb_handle_basestd =
  1793. kzalloc(sizeof(struct wrb_handle *) *
  1794. phba->params.wrbs_per_cxn, GFP_KERNEL);
  1795. if (num_cxn_wrbh) {
  1796. pwrb_context->alloc_index = 0;
  1797. pwrb_context->wrb_handles_available = 0;
  1798. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  1799. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  1800. pwrb_context->pwrb_handle_basestd[j] =
  1801. pwrb_handle;
  1802. pwrb_context->wrb_handles_available++;
  1803. pwrb_handle->wrb_index = j;
  1804. pwrb_handle++;
  1805. }
  1806. pwrb_context->free_index = 0;
  1807. num_cxn_wrbh--;
  1808. } else {
  1809. idx++;
  1810. pwrb_handle =
  1811. mem_descr_wrbh->mem_array[idx].virtual_address;
  1812. num_cxn_wrbh =
  1813. ((mem_descr_wrbh->mem_array[idx].size) /
  1814. ((sizeof(struct wrb_handle)) *
  1815. phba->params.wrbs_per_cxn));
  1816. pwrb_context->alloc_index = 0;
  1817. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  1818. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  1819. pwrb_context->pwrb_handle_basestd[j] =
  1820. pwrb_handle;
  1821. pwrb_context->wrb_handles_available++;
  1822. pwrb_handle->wrb_index = j;
  1823. pwrb_handle++;
  1824. }
  1825. pwrb_context->free_index = 0;
  1826. num_cxn_wrbh--;
  1827. }
  1828. }
  1829. idx = 0;
  1830. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  1831. num_cxn_wrb =
  1832. ((mem_descr_wrb->mem_array[idx].size) / (sizeof(struct iscsi_wrb)) *
  1833. phba->params.wrbs_per_cxn);
  1834. for (index = 0; index < phba->params.cxns_per_ctrl; index += 2) {
  1835. pwrb_context = &phwi_ctrlr->wrb_context[index];
  1836. if (num_cxn_wrb) {
  1837. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  1838. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  1839. pwrb_handle->pwrb = pwrb;
  1840. pwrb++;
  1841. }
  1842. num_cxn_wrb--;
  1843. } else {
  1844. idx++;
  1845. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  1846. num_cxn_wrb = ((mem_descr_wrb->mem_array[idx].size) /
  1847. (sizeof(struct iscsi_wrb)) *
  1848. phba->params.wrbs_per_cxn);
  1849. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  1850. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  1851. pwrb_handle->pwrb = pwrb;
  1852. pwrb++;
  1853. }
  1854. num_cxn_wrb--;
  1855. }
  1856. }
  1857. }
  1858. static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
  1859. {
  1860. struct hwi_controller *phwi_ctrlr;
  1861. struct hba_parameters *p = &phba->params;
  1862. struct hwi_async_pdu_context *pasync_ctx;
  1863. struct async_pdu_handle *pasync_header_h, *pasync_data_h;
  1864. unsigned int index;
  1865. struct be_mem_descriptor *mem_descr;
  1866. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  1867. mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
  1868. phwi_ctrlr = phba->phwi_ctrlr;
  1869. phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
  1870. mem_descr->mem_array[0].virtual_address;
  1871. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
  1872. memset(pasync_ctx, 0, sizeof(*pasync_ctx));
  1873. pasync_ctx->async_header.num_entries = p->asyncpdus_per_ctrl;
  1874. pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz;
  1875. pasync_ctx->async_data.buffer_size = p->defpdu_data_sz;
  1876. pasync_ctx->async_data.num_entries = p->asyncpdus_per_ctrl;
  1877. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  1878. mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
  1879. if (mem_descr->mem_array[0].virtual_address) {
  1880. SE_DEBUG(DBG_LVL_8,
  1881. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_BUF"
  1882. "va=%p \n", mem_descr->mem_array[0].virtual_address);
  1883. } else
  1884. shost_printk(KERN_WARNING, phba->shost,
  1885. "No Virtual address \n");
  1886. pasync_ctx->async_header.va_base =
  1887. mem_descr->mem_array[0].virtual_address;
  1888. pasync_ctx->async_header.pa_base.u.a64.address =
  1889. mem_descr->mem_array[0].bus_address.u.a64.address;
  1890. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  1891. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  1892. if (mem_descr->mem_array[0].virtual_address) {
  1893. SE_DEBUG(DBG_LVL_8,
  1894. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_RING"
  1895. "va=%p \n", mem_descr->mem_array[0].virtual_address);
  1896. } else
  1897. shost_printk(KERN_WARNING, phba->shost,
  1898. "No Virtual address \n");
  1899. pasync_ctx->async_header.ring_base =
  1900. mem_descr->mem_array[0].virtual_address;
  1901. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  1902. mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
  1903. if (mem_descr->mem_array[0].virtual_address) {
  1904. SE_DEBUG(DBG_LVL_8,
  1905. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_HANDLE"
  1906. "va=%p \n", mem_descr->mem_array[0].virtual_address);
  1907. } else
  1908. shost_printk(KERN_WARNING, phba->shost,
  1909. "No Virtual address \n");
  1910. pasync_ctx->async_header.handle_base =
  1911. mem_descr->mem_array[0].virtual_address;
  1912. pasync_ctx->async_header.writables = 0;
  1913. INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
  1914. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  1915. mem_descr += HWI_MEM_ASYNC_DATA_BUF;
  1916. if (mem_descr->mem_array[0].virtual_address) {
  1917. SE_DEBUG(DBG_LVL_8,
  1918. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_BUF"
  1919. "va=%p \n", mem_descr->mem_array[0].virtual_address);
  1920. } else
  1921. shost_printk(KERN_WARNING, phba->shost,
  1922. "No Virtual address \n");
  1923. pasync_ctx->async_data.va_base =
  1924. mem_descr->mem_array[0].virtual_address;
  1925. pasync_ctx->async_data.pa_base.u.a64.address =
  1926. mem_descr->mem_array[0].bus_address.u.a64.address;
  1927. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  1928. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  1929. if (mem_descr->mem_array[0].virtual_address) {
  1930. SE_DEBUG(DBG_LVL_8,
  1931. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_RING"
  1932. "va=%p \n", mem_descr->mem_array[0].virtual_address);
  1933. } else
  1934. shost_printk(KERN_WARNING, phba->shost,
  1935. "No Virtual address \n");
  1936. pasync_ctx->async_data.ring_base =
  1937. mem_descr->mem_array[0].virtual_address;
  1938. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  1939. mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
  1940. if (!mem_descr->mem_array[0].virtual_address)
  1941. shost_printk(KERN_WARNING, phba->shost,
  1942. "No Virtual address \n");
  1943. pasync_ctx->async_data.handle_base =
  1944. mem_descr->mem_array[0].virtual_address;
  1945. pasync_ctx->async_data.writables = 0;
  1946. INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
  1947. pasync_header_h =
  1948. (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
  1949. pasync_data_h =
  1950. (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
  1951. for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
  1952. pasync_header_h->cri = -1;
  1953. pasync_header_h->index = (char)index;
  1954. INIT_LIST_HEAD(&pasync_header_h->link);
  1955. pasync_header_h->pbuffer =
  1956. (void *)((unsigned long)
  1957. (pasync_ctx->async_header.va_base) +
  1958. (p->defpdu_hdr_sz * index));
  1959. pasync_header_h->pa.u.a64.address =
  1960. pasync_ctx->async_header.pa_base.u.a64.address +
  1961. (p->defpdu_hdr_sz * index);
  1962. list_add_tail(&pasync_header_h->link,
  1963. &pasync_ctx->async_header.free_list);
  1964. pasync_header_h++;
  1965. pasync_ctx->async_header.free_entries++;
  1966. pasync_ctx->async_header.writables++;
  1967. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
  1968. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  1969. header_busy_list);
  1970. pasync_data_h->cri = -1;
  1971. pasync_data_h->index = (char)index;
  1972. INIT_LIST_HEAD(&pasync_data_h->link);
  1973. pasync_data_h->pbuffer =
  1974. (void *)((unsigned long)
  1975. (pasync_ctx->async_data.va_base) +
  1976. (p->defpdu_data_sz * index));
  1977. pasync_data_h->pa.u.a64.address =
  1978. pasync_ctx->async_data.pa_base.u.a64.address +
  1979. (p->defpdu_data_sz * index);
  1980. list_add_tail(&pasync_data_h->link,
  1981. &pasync_ctx->async_data.free_list);
  1982. pasync_data_h++;
  1983. pasync_ctx->async_data.free_entries++;
  1984. pasync_ctx->async_data.writables++;
  1985. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
  1986. }
  1987. pasync_ctx->async_header.host_write_ptr = 0;
  1988. pasync_ctx->async_header.ep_read_ptr = -1;
  1989. pasync_ctx->async_data.host_write_ptr = 0;
  1990. pasync_ctx->async_data.ep_read_ptr = -1;
  1991. }
  1992. static int
  1993. be_sgl_create_contiguous(void *virtual_address,
  1994. u64 physical_address, u32 length,
  1995. struct be_dma_mem *sgl)
  1996. {
  1997. WARN_ON(!virtual_address);
  1998. WARN_ON(!physical_address);
  1999. WARN_ON(!length > 0);
  2000. WARN_ON(!sgl);
  2001. sgl->va = virtual_address;
  2002. sgl->dma = physical_address;
  2003. sgl->size = length;
  2004. return 0;
  2005. }
  2006. static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
  2007. {
  2008. memset(sgl, 0, sizeof(*sgl));
  2009. }
  2010. static void
  2011. hwi_build_be_sgl_arr(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(pmem->virtual_address,
  2017. pmem->bus_address.u.a64.address,
  2018. pmem->size, sgl);
  2019. }
  2020. static void
  2021. hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
  2022. struct mem_array *pmem, struct be_dma_mem *sgl)
  2023. {
  2024. if (sgl->va)
  2025. be_sgl_destroy_contiguous(sgl);
  2026. be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
  2027. pmem->bus_address.u.a64.address,
  2028. pmem->size, sgl);
  2029. }
  2030. static int be_fill_queue(struct be_queue_info *q,
  2031. u16 len, u16 entry_size, void *vaddress)
  2032. {
  2033. struct be_dma_mem *mem = &q->dma_mem;
  2034. memset(q, 0, sizeof(*q));
  2035. q->len = len;
  2036. q->entry_size = entry_size;
  2037. mem->size = len * entry_size;
  2038. mem->va = vaddress;
  2039. if (!mem->va)
  2040. return -ENOMEM;
  2041. memset(mem->va, 0, mem->size);
  2042. return 0;
  2043. }
  2044. static int beiscsi_create_eqs(struct beiscsi_hba *phba,
  2045. struct hwi_context_memory *phwi_context)
  2046. {
  2047. unsigned int i, num_eq_pages;
  2048. int ret, eq_for_mcc;
  2049. struct be_queue_info *eq;
  2050. struct be_dma_mem *mem;
  2051. void *eq_vaddress;
  2052. dma_addr_t paddr;
  2053. num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
  2054. sizeof(struct be_eq_entry));
  2055. if (phba->msix_enabled)
  2056. eq_for_mcc = 1;
  2057. else
  2058. eq_for_mcc = 0;
  2059. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2060. eq = &phwi_context->be_eq[i].q;
  2061. mem = &eq->dma_mem;
  2062. phwi_context->be_eq[i].phba = phba;
  2063. eq_vaddress = pci_alloc_consistent(phba->pcidev,
  2064. num_eq_pages * PAGE_SIZE,
  2065. &paddr);
  2066. if (!eq_vaddress)
  2067. goto create_eq_error;
  2068. mem->va = eq_vaddress;
  2069. ret = be_fill_queue(eq, phba->params.num_eq_entries,
  2070. sizeof(struct be_eq_entry), eq_vaddress);
  2071. if (ret) {
  2072. shost_printk(KERN_ERR, phba->shost,
  2073. "be_fill_queue Failed for EQ \n");
  2074. goto create_eq_error;
  2075. }
  2076. mem->dma = paddr;
  2077. ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
  2078. phwi_context->cur_eqd);
  2079. if (ret) {
  2080. shost_printk(KERN_ERR, phba->shost,
  2081. "beiscsi_cmd_eq_create"
  2082. "Failedfor EQ \n");
  2083. goto create_eq_error;
  2084. }
  2085. SE_DEBUG(DBG_LVL_8, "eqid = %d\n", phwi_context->be_eq[i].q.id);
  2086. }
  2087. return 0;
  2088. create_eq_error:
  2089. for (i = 0; i < (phba->num_cpus + 1); i++) {
  2090. eq = &phwi_context->be_eq[i].q;
  2091. mem = &eq->dma_mem;
  2092. if (mem->va)
  2093. pci_free_consistent(phba->pcidev, num_eq_pages
  2094. * PAGE_SIZE,
  2095. mem->va, mem->dma);
  2096. }
  2097. return ret;
  2098. }
  2099. static int beiscsi_create_cqs(struct beiscsi_hba *phba,
  2100. struct hwi_context_memory *phwi_context)
  2101. {
  2102. unsigned int i, num_cq_pages;
  2103. int ret;
  2104. struct be_queue_info *cq, *eq;
  2105. struct be_dma_mem *mem;
  2106. struct be_eq_obj *pbe_eq;
  2107. void *cq_vaddress;
  2108. dma_addr_t paddr;
  2109. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2110. sizeof(struct sol_cqe));
  2111. for (i = 0; i < phba->num_cpus; i++) {
  2112. cq = &phwi_context->be_cq[i];
  2113. eq = &phwi_context->be_eq[i].q;
  2114. pbe_eq = &phwi_context->be_eq[i];
  2115. pbe_eq->cq = cq;
  2116. pbe_eq->phba = phba;
  2117. mem = &cq->dma_mem;
  2118. cq_vaddress = pci_alloc_consistent(phba->pcidev,
  2119. num_cq_pages * PAGE_SIZE,
  2120. &paddr);
  2121. if (!cq_vaddress)
  2122. goto create_cq_error;
  2123. ret = be_fill_queue(cq, phba->params.num_cq_entries,
  2124. sizeof(struct sol_cqe), cq_vaddress);
  2125. if (ret) {
  2126. shost_printk(KERN_ERR, phba->shost,
  2127. "be_fill_queue Failed for ISCSI CQ \n");
  2128. goto create_cq_error;
  2129. }
  2130. mem->dma = paddr;
  2131. ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
  2132. false, 0);
  2133. if (ret) {
  2134. shost_printk(KERN_ERR, phba->shost,
  2135. "beiscsi_cmd_eq_create"
  2136. "Failed for ISCSI CQ \n");
  2137. goto create_cq_error;
  2138. }
  2139. SE_DEBUG(DBG_LVL_8, "iscsi cq_id is %d for eq_id %d\n",
  2140. cq->id, eq->id);
  2141. SE_DEBUG(DBG_LVL_8, "ISCSI CQ CREATED\n");
  2142. }
  2143. return 0;
  2144. create_cq_error:
  2145. for (i = 0; i < phba->num_cpus; i++) {
  2146. cq = &phwi_context->be_cq[i];
  2147. mem = &cq->dma_mem;
  2148. if (mem->va)
  2149. pci_free_consistent(phba->pcidev, num_cq_pages
  2150. * PAGE_SIZE,
  2151. mem->va, mem->dma);
  2152. }
  2153. return ret;
  2154. }
  2155. static int
  2156. beiscsi_create_def_hdr(struct beiscsi_hba *phba,
  2157. struct hwi_context_memory *phwi_context,
  2158. struct hwi_controller *phwi_ctrlr,
  2159. unsigned int def_pdu_ring_sz)
  2160. {
  2161. unsigned int idx;
  2162. int ret;
  2163. struct be_queue_info *dq, *cq;
  2164. struct be_dma_mem *mem;
  2165. struct be_mem_descriptor *mem_descr;
  2166. void *dq_vaddress;
  2167. idx = 0;
  2168. dq = &phwi_context->be_def_hdrq;
  2169. cq = &phwi_context->be_cq[0];
  2170. mem = &dq->dma_mem;
  2171. mem_descr = phba->init_mem;
  2172. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2173. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2174. ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
  2175. sizeof(struct phys_addr),
  2176. sizeof(struct phys_addr), dq_vaddress);
  2177. if (ret) {
  2178. shost_printk(KERN_ERR, phba->shost,
  2179. "be_fill_queue Failed for DEF PDU HDR\n");
  2180. return ret;
  2181. }
  2182. mem->dma = mem_descr->mem_array[idx].bus_address.u.a64.address;
  2183. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
  2184. def_pdu_ring_sz,
  2185. phba->params.defpdu_hdr_sz);
  2186. if (ret) {
  2187. shost_printk(KERN_ERR, phba->shost,
  2188. "be_cmd_create_default_pdu_queue Failed DEFHDR\n");
  2189. return ret;
  2190. }
  2191. phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
  2192. SE_DEBUG(DBG_LVL_8, "iscsi def pdu id is %d\n",
  2193. phwi_context->be_def_hdrq.id);
  2194. hwi_post_async_buffers(phba, 1);
  2195. return 0;
  2196. }
  2197. static int
  2198. beiscsi_create_def_data(struct beiscsi_hba *phba,
  2199. struct hwi_context_memory *phwi_context,
  2200. struct hwi_controller *phwi_ctrlr,
  2201. unsigned int def_pdu_ring_sz)
  2202. {
  2203. unsigned int idx;
  2204. int ret;
  2205. struct be_queue_info *dataq, *cq;
  2206. struct be_dma_mem *mem;
  2207. struct be_mem_descriptor *mem_descr;
  2208. void *dq_vaddress;
  2209. idx = 0;
  2210. dataq = &phwi_context->be_def_dataq;
  2211. cq = &phwi_context->be_cq[0];
  2212. mem = &dataq->dma_mem;
  2213. mem_descr = phba->init_mem;
  2214. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2215. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2216. ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
  2217. sizeof(struct phys_addr),
  2218. sizeof(struct phys_addr), dq_vaddress);
  2219. if (ret) {
  2220. shost_printk(KERN_ERR, phba->shost,
  2221. "be_fill_queue Failed for DEF PDU DATA\n");
  2222. return ret;
  2223. }
  2224. mem->dma = mem_descr->mem_array[idx].bus_address.u.a64.address;
  2225. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
  2226. def_pdu_ring_sz,
  2227. phba->params.defpdu_data_sz);
  2228. if (ret) {
  2229. shost_printk(KERN_ERR, phba->shost,
  2230. "be_cmd_create_default_pdu_queue Failed"
  2231. " for DEF PDU DATA\n");
  2232. return ret;
  2233. }
  2234. phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
  2235. SE_DEBUG(DBG_LVL_8, "iscsi def data id is %d\n",
  2236. phwi_context->be_def_dataq.id);
  2237. hwi_post_async_buffers(phba, 0);
  2238. SE_DEBUG(DBG_LVL_8, "DEFAULT PDU DATA RING CREATED \n");
  2239. return 0;
  2240. }
  2241. static int
  2242. beiscsi_post_pages(struct beiscsi_hba *phba)
  2243. {
  2244. struct be_mem_descriptor *mem_descr;
  2245. struct mem_array *pm_arr;
  2246. unsigned int page_offset, i;
  2247. struct be_dma_mem sgl;
  2248. int status;
  2249. mem_descr = phba->init_mem;
  2250. mem_descr += HWI_MEM_SGE;
  2251. pm_arr = mem_descr->mem_array;
  2252. page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
  2253. phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
  2254. for (i = 0; i < mem_descr->num_elements; i++) {
  2255. hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
  2256. status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
  2257. page_offset,
  2258. (pm_arr->size / PAGE_SIZE));
  2259. page_offset += pm_arr->size / PAGE_SIZE;
  2260. if (status != 0) {
  2261. shost_printk(KERN_ERR, phba->shost,
  2262. "post sgl failed.\n");
  2263. return status;
  2264. }
  2265. pm_arr++;
  2266. }
  2267. SE_DEBUG(DBG_LVL_8, "POSTED PAGES \n");
  2268. return 0;
  2269. }
  2270. static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
  2271. {
  2272. struct be_dma_mem *mem = &q->dma_mem;
  2273. if (mem->va)
  2274. pci_free_consistent(phba->pcidev, mem->size,
  2275. mem->va, mem->dma);
  2276. }
  2277. static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
  2278. u16 len, u16 entry_size)
  2279. {
  2280. struct be_dma_mem *mem = &q->dma_mem;
  2281. memset(q, 0, sizeof(*q));
  2282. q->len = len;
  2283. q->entry_size = entry_size;
  2284. mem->size = len * entry_size;
  2285. mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
  2286. if (!mem->va)
  2287. return -1;
  2288. memset(mem->va, 0, mem->size);
  2289. return 0;
  2290. }
  2291. static int
  2292. beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
  2293. struct hwi_context_memory *phwi_context,
  2294. struct hwi_controller *phwi_ctrlr)
  2295. {
  2296. unsigned int wrb_mem_index, offset, size, num_wrb_rings;
  2297. u64 pa_addr_lo;
  2298. unsigned int idx, num, i;
  2299. struct mem_array *pwrb_arr;
  2300. void *wrb_vaddr;
  2301. struct be_dma_mem sgl;
  2302. struct be_mem_descriptor *mem_descr;
  2303. int status;
  2304. idx = 0;
  2305. mem_descr = phba->init_mem;
  2306. mem_descr += HWI_MEM_WRB;
  2307. pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
  2308. GFP_KERNEL);
  2309. if (!pwrb_arr) {
  2310. shost_printk(KERN_ERR, phba->shost,
  2311. "Memory alloc failed in create wrb ring.\n");
  2312. return -ENOMEM;
  2313. }
  2314. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2315. pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
  2316. num_wrb_rings = mem_descr->mem_array[idx].size /
  2317. (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
  2318. for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
  2319. if (num_wrb_rings) {
  2320. pwrb_arr[num].virtual_address = wrb_vaddr;
  2321. pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
  2322. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2323. sizeof(struct iscsi_wrb);
  2324. wrb_vaddr += pwrb_arr[num].size;
  2325. pa_addr_lo += pwrb_arr[num].size;
  2326. num_wrb_rings--;
  2327. } else {
  2328. idx++;
  2329. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2330. pa_addr_lo = mem_descr->mem_array[idx].\
  2331. bus_address.u.a64.address;
  2332. num_wrb_rings = mem_descr->mem_array[idx].size /
  2333. (phba->params.wrbs_per_cxn *
  2334. sizeof(struct iscsi_wrb));
  2335. pwrb_arr[num].virtual_address = wrb_vaddr;
  2336. pwrb_arr[num].bus_address.u.a64.address\
  2337. = pa_addr_lo;
  2338. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2339. sizeof(struct iscsi_wrb);
  2340. wrb_vaddr += pwrb_arr[num].size;
  2341. pa_addr_lo += pwrb_arr[num].size;
  2342. num_wrb_rings--;
  2343. }
  2344. }
  2345. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2346. wrb_mem_index = 0;
  2347. offset = 0;
  2348. size = 0;
  2349. hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
  2350. status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
  2351. &phwi_context->be_wrbq[i]);
  2352. if (status != 0) {
  2353. shost_printk(KERN_ERR, phba->shost,
  2354. "wrbq create failed.");
  2355. return status;
  2356. }
  2357. phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
  2358. id;
  2359. }
  2360. kfree(pwrb_arr);
  2361. return 0;
  2362. }
  2363. static void free_wrb_handles(struct beiscsi_hba *phba)
  2364. {
  2365. unsigned int index;
  2366. struct hwi_controller *phwi_ctrlr;
  2367. struct hwi_wrb_context *pwrb_context;
  2368. phwi_ctrlr = phba->phwi_ctrlr;
  2369. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2370. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2371. kfree(pwrb_context->pwrb_handle_base);
  2372. kfree(pwrb_context->pwrb_handle_basestd);
  2373. }
  2374. }
  2375. static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
  2376. {
  2377. struct be_queue_info *q;
  2378. struct be_ctrl_info *ctrl = &phba->ctrl;
  2379. q = &phba->ctrl.mcc_obj.q;
  2380. if (q->created)
  2381. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
  2382. be_queue_free(phba, q);
  2383. q = &phba->ctrl.mcc_obj.cq;
  2384. if (q->created)
  2385. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  2386. be_queue_free(phba, q);
  2387. }
  2388. static void hwi_cleanup(struct beiscsi_hba *phba)
  2389. {
  2390. struct be_queue_info *q;
  2391. struct be_ctrl_info *ctrl = &phba->ctrl;
  2392. struct hwi_controller *phwi_ctrlr;
  2393. struct hwi_context_memory *phwi_context;
  2394. int i, eq_num;
  2395. phwi_ctrlr = phba->phwi_ctrlr;
  2396. phwi_context = phwi_ctrlr->phwi_ctxt;
  2397. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2398. q = &phwi_context->be_wrbq[i];
  2399. if (q->created)
  2400. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
  2401. }
  2402. free_wrb_handles(phba);
  2403. q = &phwi_context->be_def_hdrq;
  2404. if (q->created)
  2405. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  2406. q = &phwi_context->be_def_dataq;
  2407. if (q->created)
  2408. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  2409. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  2410. for (i = 0; i < (phba->num_cpus); i++) {
  2411. q = &phwi_context->be_cq[i];
  2412. if (q->created)
  2413. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  2414. }
  2415. if (phba->msix_enabled)
  2416. eq_num = 1;
  2417. else
  2418. eq_num = 0;
  2419. for (i = 0; i < (phba->num_cpus + eq_num); i++) {
  2420. q = &phwi_context->be_eq[i].q;
  2421. if (q->created)
  2422. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
  2423. }
  2424. be_mcc_queues_destroy(phba);
  2425. }
  2426. static int be_mcc_queues_create(struct beiscsi_hba *phba,
  2427. struct hwi_context_memory *phwi_context)
  2428. {
  2429. struct be_queue_info *q, *cq;
  2430. struct be_ctrl_info *ctrl = &phba->ctrl;
  2431. /* Alloc MCC compl queue */
  2432. cq = &phba->ctrl.mcc_obj.cq;
  2433. if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
  2434. sizeof(struct be_mcc_compl)))
  2435. goto err;
  2436. /* Ask BE to create MCC compl queue; */
  2437. if (phba->msix_enabled) {
  2438. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
  2439. [phba->num_cpus].q, false, true, 0))
  2440. goto mcc_cq_free;
  2441. } else {
  2442. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
  2443. false, true, 0))
  2444. goto mcc_cq_free;
  2445. }
  2446. /* Alloc MCC queue */
  2447. q = &phba->ctrl.mcc_obj.q;
  2448. if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
  2449. goto mcc_cq_destroy;
  2450. /* Ask BE to create MCC queue */
  2451. if (beiscsi_cmd_mccq_create(phba, q, cq))
  2452. goto mcc_q_free;
  2453. return 0;
  2454. mcc_q_free:
  2455. be_queue_free(phba, q);
  2456. mcc_cq_destroy:
  2457. beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
  2458. mcc_cq_free:
  2459. be_queue_free(phba, cq);
  2460. err:
  2461. return -1;
  2462. }
  2463. static int find_num_cpus(void)
  2464. {
  2465. int num_cpus = 0;
  2466. num_cpus = num_online_cpus();
  2467. if (num_cpus >= MAX_CPUS)
  2468. num_cpus = MAX_CPUS - 1;
  2469. SE_DEBUG(DBG_LVL_8, "num_cpus = %d \n", num_cpus);
  2470. return num_cpus;
  2471. }
  2472. static int hwi_init_port(struct beiscsi_hba *phba)
  2473. {
  2474. struct hwi_controller *phwi_ctrlr;
  2475. struct hwi_context_memory *phwi_context;
  2476. unsigned int def_pdu_ring_sz;
  2477. struct be_ctrl_info *ctrl = &phba->ctrl;
  2478. int status;
  2479. def_pdu_ring_sz =
  2480. phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
  2481. phwi_ctrlr = phba->phwi_ctrlr;
  2482. phwi_context = phwi_ctrlr->phwi_ctxt;
  2483. phwi_context->max_eqd = 0;
  2484. phwi_context->min_eqd = 0;
  2485. phwi_context->cur_eqd = 64;
  2486. be_cmd_fw_initialize(&phba->ctrl);
  2487. status = beiscsi_create_eqs(phba, phwi_context);
  2488. if (status != 0) {
  2489. shost_printk(KERN_ERR, phba->shost, "EQ not created \n");
  2490. goto error;
  2491. }
  2492. status = be_mcc_queues_create(phba, phwi_context);
  2493. if (status != 0)
  2494. goto error;
  2495. status = mgmt_check_supported_fw(ctrl, phba);
  2496. if (status != 0) {
  2497. shost_printk(KERN_ERR, phba->shost,
  2498. "Unsupported fw version \n");
  2499. goto error;
  2500. }
  2501. status = beiscsi_create_cqs(phba, phwi_context);
  2502. if (status != 0) {
  2503. shost_printk(KERN_ERR, phba->shost, "CQ not created\n");
  2504. goto error;
  2505. }
  2506. status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
  2507. def_pdu_ring_sz);
  2508. if (status != 0) {
  2509. shost_printk(KERN_ERR, phba->shost,
  2510. "Default Header not created\n");
  2511. goto error;
  2512. }
  2513. status = beiscsi_create_def_data(phba, phwi_context,
  2514. phwi_ctrlr, def_pdu_ring_sz);
  2515. if (status != 0) {
  2516. shost_printk(KERN_ERR, phba->shost,
  2517. "Default Data not created\n");
  2518. goto error;
  2519. }
  2520. status = beiscsi_post_pages(phba);
  2521. if (status != 0) {
  2522. shost_printk(KERN_ERR, phba->shost, "Post SGL Pages Failed\n");
  2523. goto error;
  2524. }
  2525. status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
  2526. if (status != 0) {
  2527. shost_printk(KERN_ERR, phba->shost,
  2528. "WRB Rings not created\n");
  2529. goto error;
  2530. }
  2531. SE_DEBUG(DBG_LVL_8, "hwi_init_port success\n");
  2532. return 0;
  2533. error:
  2534. shost_printk(KERN_ERR, phba->shost, "hwi_init_port failed");
  2535. hwi_cleanup(phba);
  2536. return -ENOMEM;
  2537. }
  2538. static int hwi_init_controller(struct beiscsi_hba *phba)
  2539. {
  2540. struct hwi_controller *phwi_ctrlr;
  2541. phwi_ctrlr = phba->phwi_ctrlr;
  2542. if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
  2543. phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
  2544. init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
  2545. SE_DEBUG(DBG_LVL_8, " phwi_ctrlr->phwi_ctxt=%p \n",
  2546. phwi_ctrlr->phwi_ctxt);
  2547. } else {
  2548. shost_printk(KERN_ERR, phba->shost,
  2549. "HWI_MEM_ADDN_CONTEXT is more than one element."
  2550. "Failing to load\n");
  2551. return -ENOMEM;
  2552. }
  2553. iscsi_init_global_templates(phba);
  2554. beiscsi_init_wrb_handle(phba);
  2555. hwi_init_async_pdu_ctx(phba);
  2556. if (hwi_init_port(phba) != 0) {
  2557. shost_printk(KERN_ERR, phba->shost,
  2558. "hwi_init_controller failed\n");
  2559. return -ENOMEM;
  2560. }
  2561. return 0;
  2562. }
  2563. static void beiscsi_free_mem(struct beiscsi_hba *phba)
  2564. {
  2565. struct be_mem_descriptor *mem_descr;
  2566. int i, j;
  2567. mem_descr = phba->init_mem;
  2568. i = 0;
  2569. j = 0;
  2570. for (i = 0; i < SE_MEM_MAX; i++) {
  2571. for (j = mem_descr->num_elements; j > 0; j--) {
  2572. pci_free_consistent(phba->pcidev,
  2573. mem_descr->mem_array[j - 1].size,
  2574. mem_descr->mem_array[j - 1].virtual_address,
  2575. mem_descr->mem_array[j - 1].bus_address.
  2576. u.a64.address);
  2577. }
  2578. kfree(mem_descr->mem_array);
  2579. mem_descr++;
  2580. }
  2581. kfree(phba->init_mem);
  2582. kfree(phba->phwi_ctrlr);
  2583. }
  2584. static int beiscsi_init_controller(struct beiscsi_hba *phba)
  2585. {
  2586. int ret = -ENOMEM;
  2587. ret = beiscsi_get_memory(phba);
  2588. if (ret < 0) {
  2589. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe -"
  2590. "Failed in beiscsi_alloc_memory \n");
  2591. return ret;
  2592. }
  2593. ret = hwi_init_controller(phba);
  2594. if (ret)
  2595. goto free_init;
  2596. SE_DEBUG(DBG_LVL_8, "Return success from beiscsi_init_controller");
  2597. return 0;
  2598. free_init:
  2599. beiscsi_free_mem(phba);
  2600. return -ENOMEM;
  2601. }
  2602. static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
  2603. {
  2604. struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
  2605. struct sgl_handle *psgl_handle;
  2606. struct iscsi_sge *pfrag;
  2607. unsigned int arr_index, i, idx;
  2608. phba->io_sgl_hndl_avbl = 0;
  2609. phba->eh_sgl_hndl_avbl = 0;
  2610. mem_descr_sglh = phba->init_mem;
  2611. mem_descr_sglh += HWI_MEM_SGLH;
  2612. if (1 == mem_descr_sglh->num_elements) {
  2613. phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  2614. phba->params.ios_per_ctrl,
  2615. GFP_KERNEL);
  2616. if (!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. phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  2622. (phba->params.icds_per_ctrl -
  2623. phba->params.ios_per_ctrl),
  2624. GFP_KERNEL);
  2625. if (!phba->eh_sgl_hndl_base) {
  2626. kfree(phba->io_sgl_hndl_base);
  2627. shost_printk(KERN_ERR, phba->shost,
  2628. "Mem Alloc Failed. Failing to load\n");
  2629. return -ENOMEM;
  2630. }
  2631. } else {
  2632. shost_printk(KERN_ERR, phba->shost,
  2633. "HWI_MEM_SGLH is more than one element."
  2634. "Failing to load\n");
  2635. return -ENOMEM;
  2636. }
  2637. arr_index = 0;
  2638. idx = 0;
  2639. while (idx < mem_descr_sglh->num_elements) {
  2640. psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
  2641. for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
  2642. sizeof(struct sgl_handle)); i++) {
  2643. if (arr_index < phba->params.ios_per_ctrl) {
  2644. phba->io_sgl_hndl_base[arr_index] = psgl_handle;
  2645. phba->io_sgl_hndl_avbl++;
  2646. arr_index++;
  2647. } else {
  2648. phba->eh_sgl_hndl_base[arr_index -
  2649. phba->params.ios_per_ctrl] =
  2650. psgl_handle;
  2651. arr_index++;
  2652. phba->eh_sgl_hndl_avbl++;
  2653. }
  2654. psgl_handle++;
  2655. }
  2656. idx++;
  2657. }
  2658. SE_DEBUG(DBG_LVL_8,
  2659. "phba->io_sgl_hndl_avbl=%d"
  2660. "phba->eh_sgl_hndl_avbl=%d \n",
  2661. phba->io_sgl_hndl_avbl,
  2662. phba->eh_sgl_hndl_avbl);
  2663. mem_descr_sg = phba->init_mem;
  2664. mem_descr_sg += HWI_MEM_SGE;
  2665. SE_DEBUG(DBG_LVL_8, "\n mem_descr_sg->num_elements=%d \n",
  2666. mem_descr_sg->num_elements);
  2667. arr_index = 0;
  2668. idx = 0;
  2669. while (idx < mem_descr_sg->num_elements) {
  2670. pfrag = mem_descr_sg->mem_array[idx].virtual_address;
  2671. for (i = 0;
  2672. i < (mem_descr_sg->mem_array[idx].size) /
  2673. (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
  2674. i++) {
  2675. if (arr_index < phba->params.ios_per_ctrl)
  2676. psgl_handle = phba->io_sgl_hndl_base[arr_index];
  2677. else
  2678. psgl_handle = phba->eh_sgl_hndl_base[arr_index -
  2679. phba->params.ios_per_ctrl];
  2680. psgl_handle->pfrag = pfrag;
  2681. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
  2682. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
  2683. pfrag += phba->params.num_sge_per_io;
  2684. psgl_handle->sgl_index =
  2685. phba->fw_config.iscsi_icd_start + arr_index++;
  2686. }
  2687. idx++;
  2688. }
  2689. phba->io_sgl_free_index = 0;
  2690. phba->io_sgl_alloc_index = 0;
  2691. phba->eh_sgl_free_index = 0;
  2692. phba->eh_sgl_alloc_index = 0;
  2693. return 0;
  2694. }
  2695. static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
  2696. {
  2697. int i, new_cid;
  2698. phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
  2699. GFP_KERNEL);
  2700. if (!phba->cid_array) {
  2701. shost_printk(KERN_ERR, phba->shost,
  2702. "Failed to allocate memory in "
  2703. "hba_setup_cid_tbls\n");
  2704. return -ENOMEM;
  2705. }
  2706. phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
  2707. phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
  2708. if (!phba->ep_array) {
  2709. shost_printk(KERN_ERR, phba->shost,
  2710. "Failed to allocate memory in "
  2711. "hba_setup_cid_tbls \n");
  2712. kfree(phba->cid_array);
  2713. return -ENOMEM;
  2714. }
  2715. new_cid = phba->fw_config.iscsi_cid_start;
  2716. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2717. phba->cid_array[i] = new_cid;
  2718. new_cid += 2;
  2719. }
  2720. phba->avlbl_cids = phba->params.cxns_per_ctrl;
  2721. return 0;
  2722. }
  2723. static unsigned char hwi_enable_intr(struct beiscsi_hba *phba)
  2724. {
  2725. struct be_ctrl_info *ctrl = &phba->ctrl;
  2726. struct hwi_controller *phwi_ctrlr;
  2727. struct hwi_context_memory *phwi_context;
  2728. struct be_queue_info *eq;
  2729. u8 __iomem *addr;
  2730. u32 reg, i;
  2731. u32 enabled;
  2732. phwi_ctrlr = phba->phwi_ctrlr;
  2733. phwi_context = phwi_ctrlr->phwi_ctxt;
  2734. addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
  2735. PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
  2736. reg = ioread32(addr);
  2737. SE_DEBUG(DBG_LVL_8, "reg =x%08x \n", reg);
  2738. enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  2739. if (!enabled) {
  2740. reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  2741. SE_DEBUG(DBG_LVL_8, "reg =x%08x addr=%p \n", reg, addr);
  2742. iowrite32(reg, addr);
  2743. for (i = 0; i <= phba->num_cpus; i++) {
  2744. eq = &phwi_context->be_eq[i].q;
  2745. SE_DEBUG(DBG_LVL_8, "eq->id=%d \n", eq->id);
  2746. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  2747. }
  2748. } else
  2749. shost_printk(KERN_WARNING, phba->shost,
  2750. "In hwi_enable_intr, Not Enabled \n");
  2751. return true;
  2752. }
  2753. static void hwi_disable_intr(struct beiscsi_hba *phba)
  2754. {
  2755. struct be_ctrl_info *ctrl = &phba->ctrl;
  2756. u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
  2757. u32 reg = ioread32(addr);
  2758. u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  2759. if (enabled) {
  2760. reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  2761. iowrite32(reg, addr);
  2762. } else
  2763. shost_printk(KERN_WARNING, phba->shost,
  2764. "In hwi_disable_intr, Already Disabled \n");
  2765. }
  2766. static int beiscsi_init_port(struct beiscsi_hba *phba)
  2767. {
  2768. int ret;
  2769. ret = beiscsi_init_controller(phba);
  2770. if (ret < 0) {
  2771. shost_printk(KERN_ERR, phba->shost,
  2772. "beiscsi_dev_probe - Failed in"
  2773. "beiscsi_init_controller \n");
  2774. return ret;
  2775. }
  2776. ret = beiscsi_init_sgl_handle(phba);
  2777. if (ret < 0) {
  2778. shost_printk(KERN_ERR, phba->shost,
  2779. "beiscsi_dev_probe - Failed in"
  2780. "beiscsi_init_sgl_handle \n");
  2781. goto do_cleanup_ctrlr;
  2782. }
  2783. if (hba_setup_cid_tbls(phba)) {
  2784. shost_printk(KERN_ERR, phba->shost,
  2785. "Failed in hba_setup_cid_tbls\n");
  2786. kfree(phba->io_sgl_hndl_base);
  2787. kfree(phba->eh_sgl_hndl_base);
  2788. goto do_cleanup_ctrlr;
  2789. }
  2790. return ret;
  2791. do_cleanup_ctrlr:
  2792. hwi_cleanup(phba);
  2793. return ret;
  2794. }
  2795. static void hwi_purge_eq(struct beiscsi_hba *phba)
  2796. {
  2797. struct hwi_controller *phwi_ctrlr;
  2798. struct hwi_context_memory *phwi_context;
  2799. struct be_queue_info *eq;
  2800. struct be_eq_entry *eqe = NULL;
  2801. int i, eq_msix;
  2802. unsigned int num_processed;
  2803. phwi_ctrlr = phba->phwi_ctrlr;
  2804. phwi_context = phwi_ctrlr->phwi_ctxt;
  2805. if (phba->msix_enabled)
  2806. eq_msix = 1;
  2807. else
  2808. eq_msix = 0;
  2809. for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
  2810. eq = &phwi_context->be_eq[i].q;
  2811. eqe = queue_tail_node(eq);
  2812. num_processed = 0;
  2813. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  2814. & EQE_VALID_MASK) {
  2815. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  2816. queue_tail_inc(eq);
  2817. eqe = queue_tail_node(eq);
  2818. num_processed++;
  2819. }
  2820. if (num_processed)
  2821. hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
  2822. }
  2823. }
  2824. static void beiscsi_clean_port(struct beiscsi_hba *phba)
  2825. {
  2826. unsigned char mgmt_status;
  2827. mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
  2828. if (mgmt_status)
  2829. shost_printk(KERN_WARNING, phba->shost,
  2830. "mgmt_epfw_cleanup FAILED \n");
  2831. hwi_purge_eq(phba);
  2832. hwi_cleanup(phba);
  2833. kfree(phba->io_sgl_hndl_base);
  2834. kfree(phba->eh_sgl_hndl_base);
  2835. kfree(phba->cid_array);
  2836. kfree(phba->ep_array);
  2837. }
  2838. void
  2839. beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
  2840. struct beiscsi_offload_params *params)
  2841. {
  2842. struct wrb_handle *pwrb_handle;
  2843. struct iscsi_target_context_update_wrb *pwrb = NULL;
  2844. struct be_mem_descriptor *mem_descr;
  2845. struct beiscsi_hba *phba = beiscsi_conn->phba;
  2846. u32 doorbell = 0;
  2847. /*
  2848. * We can always use 0 here because it is reserved by libiscsi for
  2849. * login/startup related tasks.
  2850. */
  2851. pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
  2852. phba->fw_config.iscsi_cid_start));
  2853. pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb;
  2854. memset(pwrb, 0, sizeof(*pwrb));
  2855. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  2856. max_burst_length, pwrb, params->dw[offsetof
  2857. (struct amap_beiscsi_offload_params,
  2858. max_burst_length) / 32]);
  2859. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  2860. max_send_data_segment_length, pwrb,
  2861. params->dw[offsetof(struct amap_beiscsi_offload_params,
  2862. max_send_data_segment_length) / 32]);
  2863. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  2864. first_burst_length,
  2865. pwrb,
  2866. params->dw[offsetof(struct amap_beiscsi_offload_params,
  2867. first_burst_length) / 32]);
  2868. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
  2869. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  2870. erl) / 32] & OFFLD_PARAMS_ERL));
  2871. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
  2872. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  2873. dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
  2874. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
  2875. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  2876. hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
  2877. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
  2878. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  2879. ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
  2880. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
  2881. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  2882. imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
  2883. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
  2884. pwrb,
  2885. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  2886. exp_statsn) / 32] + 1));
  2887. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
  2888. 0x7);
  2889. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
  2890. pwrb, pwrb_handle->wrb_index);
  2891. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
  2892. pwrb, pwrb_handle->nxt_wrb_index);
  2893. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  2894. session_state, pwrb, 0);
  2895. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
  2896. pwrb, 1);
  2897. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
  2898. pwrb, 0);
  2899. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
  2900. 0);
  2901. mem_descr = phba->init_mem;
  2902. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  2903. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  2904. pad_buffer_addr_hi, pwrb,
  2905. mem_descr->mem_array[0].bus_address.u.a32.address_hi);
  2906. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  2907. pad_buffer_addr_lo, pwrb,
  2908. mem_descr->mem_array[0].bus_address.u.a32.address_lo);
  2909. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
  2910. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  2911. doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
  2912. << DB_DEF_PDU_WRB_INDEX_SHIFT;
  2913. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  2914. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  2915. }
  2916. static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
  2917. int *index, int *age)
  2918. {
  2919. *index = (int)itt;
  2920. if (age)
  2921. *age = conn->session->age;
  2922. }
  2923. /**
  2924. * beiscsi_alloc_pdu - allocates pdu and related resources
  2925. * @task: libiscsi task
  2926. * @opcode: opcode of pdu for task
  2927. *
  2928. * This is called with the session lock held. It will allocate
  2929. * the wrb and sgl if needed for the command. And it will prep
  2930. * the pdu's itt. beiscsi_parse_pdu will later translate
  2931. * the pdu itt to the libiscsi task itt.
  2932. */
  2933. static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  2934. {
  2935. struct beiscsi_io_task *io_task = task->dd_data;
  2936. struct iscsi_conn *conn = task->conn;
  2937. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  2938. struct beiscsi_hba *phba = beiscsi_conn->phba;
  2939. struct hwi_wrb_context *pwrb_context;
  2940. struct hwi_controller *phwi_ctrlr;
  2941. itt_t itt;
  2942. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  2943. dma_addr_t paddr;
  2944. io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
  2945. GFP_KERNEL, &paddr);
  2946. if (!io_task->cmd_bhs)
  2947. return -ENOMEM;
  2948. io_task->bhs_pa.u.a64.address = paddr;
  2949. io_task->libiscsi_itt = (itt_t)task->itt;
  2950. io_task->pwrb_handle = alloc_wrb_handle(phba,
  2951. beiscsi_conn->beiscsi_conn_cid -
  2952. phba->fw_config.iscsi_cid_start
  2953. );
  2954. io_task->conn = beiscsi_conn;
  2955. task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
  2956. task->hdr_max = sizeof(struct be_cmd_bhs);
  2957. if (task->sc) {
  2958. spin_lock(&phba->io_sgl_lock);
  2959. io_task->psgl_handle = alloc_io_sgl_handle(phba);
  2960. spin_unlock(&phba->io_sgl_lock);
  2961. if (!io_task->psgl_handle)
  2962. goto free_hndls;
  2963. } else {
  2964. io_task->scsi_cmnd = NULL;
  2965. if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
  2966. if (!beiscsi_conn->login_in_progress) {
  2967. spin_lock(&phba->mgmt_sgl_lock);
  2968. io_task->psgl_handle = (struct sgl_handle *)
  2969. alloc_mgmt_sgl_handle(phba);
  2970. spin_unlock(&phba->mgmt_sgl_lock);
  2971. if (!io_task->psgl_handle)
  2972. goto free_hndls;
  2973. beiscsi_conn->login_in_progress = 1;
  2974. beiscsi_conn->plogin_sgl_handle =
  2975. io_task->psgl_handle;
  2976. } else {
  2977. io_task->psgl_handle =
  2978. beiscsi_conn->plogin_sgl_handle;
  2979. }
  2980. } else {
  2981. spin_lock(&phba->mgmt_sgl_lock);
  2982. io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
  2983. spin_unlock(&phba->mgmt_sgl_lock);
  2984. if (!io_task->psgl_handle)
  2985. goto free_hndls;
  2986. }
  2987. }
  2988. itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
  2989. wrb_index << 16) | (unsigned int)
  2990. (io_task->psgl_handle->sgl_index));
  2991. io_task->pwrb_handle->pio_handle = task;
  2992. io_task->cmd_bhs->iscsi_hdr.itt = itt;
  2993. return 0;
  2994. free_hndls:
  2995. phwi_ctrlr = phba->phwi_ctrlr;
  2996. pwrb_context = &phwi_ctrlr->wrb_context[
  2997. beiscsi_conn->beiscsi_conn_cid -
  2998. phba->fw_config.iscsi_cid_start];
  2999. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  3000. io_task->pwrb_handle = NULL;
  3001. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3002. io_task->bhs_pa.u.a64.address);
  3003. SE_DEBUG(DBG_LVL_1, "Alloc of SGL_ICD Failed \n");
  3004. return -ENOMEM;
  3005. }
  3006. static void beiscsi_cleanup_task(struct iscsi_task *task)
  3007. {
  3008. struct beiscsi_io_task *io_task = task->dd_data;
  3009. struct iscsi_conn *conn = task->conn;
  3010. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3011. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3012. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3013. struct hwi_wrb_context *pwrb_context;
  3014. struct hwi_controller *phwi_ctrlr;
  3015. phwi_ctrlr = phba->phwi_ctrlr;
  3016. pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
  3017. - phba->fw_config.iscsi_cid_start];
  3018. if (io_task->pwrb_handle) {
  3019. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  3020. io_task->pwrb_handle = NULL;
  3021. }
  3022. if (io_task->cmd_bhs) {
  3023. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3024. io_task->bhs_pa.u.a64.address);
  3025. }
  3026. if (task->sc) {
  3027. if (io_task->psgl_handle) {
  3028. spin_lock(&phba->io_sgl_lock);
  3029. free_io_sgl_handle(phba, io_task->psgl_handle);
  3030. spin_unlock(&phba->io_sgl_lock);
  3031. io_task->psgl_handle = NULL;
  3032. }
  3033. } else {
  3034. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN)
  3035. return;
  3036. if (io_task->psgl_handle) {
  3037. spin_lock(&phba->mgmt_sgl_lock);
  3038. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  3039. spin_unlock(&phba->mgmt_sgl_lock);
  3040. io_task->psgl_handle = NULL;
  3041. }
  3042. }
  3043. }
  3044. static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
  3045. unsigned int num_sg, unsigned int xferlen,
  3046. unsigned int writedir)
  3047. {
  3048. struct beiscsi_io_task *io_task = task->dd_data;
  3049. struct iscsi_conn *conn = task->conn;
  3050. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3051. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3052. struct iscsi_wrb *pwrb = NULL;
  3053. unsigned int doorbell = 0;
  3054. pwrb = io_task->pwrb_handle->pwrb;
  3055. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  3056. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  3057. if (writedir) {
  3058. memset(&io_task->cmd_bhs->iscsi_data_pdu, 0, 48);
  3059. AMAP_SET_BITS(struct amap_pdu_data_out, itt,
  3060. &io_task->cmd_bhs->iscsi_data_pdu,
  3061. (unsigned int)io_task->cmd_bhs->iscsi_hdr.itt);
  3062. AMAP_SET_BITS(struct amap_pdu_data_out, opcode,
  3063. &io_task->cmd_bhs->iscsi_data_pdu,
  3064. ISCSI_OPCODE_SCSI_DATA_OUT);
  3065. AMAP_SET_BITS(struct amap_pdu_data_out, final_bit,
  3066. &io_task->cmd_bhs->iscsi_data_pdu, 1);
  3067. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3068. INI_WR_CMD);
  3069. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  3070. } else {
  3071. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3072. INI_RD_CMD);
  3073. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  3074. }
  3075. memcpy(&io_task->cmd_bhs->iscsi_data_pdu.
  3076. dw[offsetof(struct amap_pdu_data_out, lun) / 32],
  3077. io_task->cmd_bhs->iscsi_hdr.lun, sizeof(struct scsi_lun));
  3078. AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
  3079. cpu_to_be16((unsigned short)io_task->cmd_bhs->iscsi_hdr.
  3080. lun[0]));
  3081. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
  3082. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3083. io_task->pwrb_handle->wrb_index);
  3084. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3085. be32_to_cpu(task->cmdsn));
  3086. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3087. io_task->psgl_handle->sgl_index);
  3088. hwi_write_sgl(pwrb, sg, num_sg, io_task);
  3089. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3090. io_task->pwrb_handle->nxt_wrb_index);
  3091. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3092. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3093. doorbell |= (io_task->pwrb_handle->wrb_index &
  3094. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3095. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3096. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3097. return 0;
  3098. }
  3099. static int beiscsi_mtask(struct iscsi_task *task)
  3100. {
  3101. struct beiscsi_io_task *aborted_io_task, *io_task = task->dd_data;
  3102. struct iscsi_conn *conn = task->conn;
  3103. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3104. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3105. struct iscsi_session *session;
  3106. struct iscsi_wrb *pwrb = NULL;
  3107. struct hwi_controller *phwi_ctrlr;
  3108. struct hwi_wrb_context *pwrb_context;
  3109. struct wrb_handle *pwrb_handle;
  3110. unsigned int doorbell = 0;
  3111. unsigned int i, cid;
  3112. struct iscsi_task *aborted_task;
  3113. unsigned int tag;
  3114. cid = beiscsi_conn->beiscsi_conn_cid;
  3115. pwrb = io_task->pwrb_handle->pwrb;
  3116. memset(pwrb, 0, sizeof(*pwrb));
  3117. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3118. be32_to_cpu(task->cmdsn));
  3119. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3120. io_task->pwrb_handle->wrb_index);
  3121. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3122. io_task->psgl_handle->sgl_index);
  3123. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  3124. case ISCSI_OP_LOGIN:
  3125. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3126. TGT_DM_CMD);
  3127. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3128. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
  3129. hwi_write_buffer(pwrb, task);
  3130. break;
  3131. case ISCSI_OP_NOOP_OUT:
  3132. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3133. INI_RD_CMD);
  3134. if (task->hdr->ttt == ISCSI_RESERVED_TAG)
  3135. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3136. else
  3137. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
  3138. hwi_write_buffer(pwrb, task);
  3139. break;
  3140. case ISCSI_OP_TEXT:
  3141. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3142. TGT_DM_CMD);
  3143. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3144. hwi_write_buffer(pwrb, task);
  3145. break;
  3146. case ISCSI_OP_SCSI_TMFUNC:
  3147. session = conn->session;
  3148. i = ((struct iscsi_tm *)task->hdr)->rtt;
  3149. phwi_ctrlr = phba->phwi_ctrlr;
  3150. pwrb_context = &phwi_ctrlr->wrb_context[cid -
  3151. phba->fw_config.iscsi_cid_start];
  3152. pwrb_handle = pwrb_context->pwrb_handle_basestd[be32_to_cpu(i)
  3153. >> 16];
  3154. aborted_task = pwrb_handle->pio_handle;
  3155. if (!aborted_task)
  3156. return 0;
  3157. aborted_io_task = aborted_task->dd_data;
  3158. if (!aborted_io_task->scsi_cmnd)
  3159. return 0;
  3160. tag = mgmt_invalidate_icds(phba,
  3161. aborted_io_task->psgl_handle->sgl_index,
  3162. cid);
  3163. if (!tag) {
  3164. shost_printk(KERN_WARNING, phba->shost,
  3165. "mgmt_invalidate_icds could not be"
  3166. " submitted\n");
  3167. } else {
  3168. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  3169. phba->ctrl.mcc_numtag[tag]);
  3170. free_mcc_tag(&phba->ctrl, tag);
  3171. }
  3172. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3173. INI_TMF_CMD);
  3174. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3175. hwi_write_buffer(pwrb, task);
  3176. break;
  3177. case ISCSI_OP_LOGOUT:
  3178. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3179. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3180. HWH_TYPE_LOGOUT);
  3181. hwi_write_buffer(pwrb, task);
  3182. break;
  3183. default:
  3184. SE_DEBUG(DBG_LVL_1, "opcode =%d Not supported \n",
  3185. task->hdr->opcode & ISCSI_OPCODE_MASK);
  3186. return -EINVAL;
  3187. }
  3188. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
  3189. task->data_count);
  3190. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3191. io_task->pwrb_handle->nxt_wrb_index);
  3192. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3193. doorbell |= cid & DB_WRB_POST_CID_MASK;
  3194. doorbell |= (io_task->pwrb_handle->wrb_index &
  3195. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3196. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3197. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3198. return 0;
  3199. }
  3200. static int beiscsi_task_xmit(struct iscsi_task *task)
  3201. {
  3202. struct iscsi_conn *conn = task->conn;
  3203. struct beiscsi_io_task *io_task = task->dd_data;
  3204. struct scsi_cmnd *sc = task->sc;
  3205. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3206. struct scatterlist *sg;
  3207. int num_sg;
  3208. unsigned int writedir = 0, xferlen = 0;
  3209. SE_DEBUG(DBG_LVL_4, "\n cid=%d In beiscsi_task_xmit task=%p conn=%p \t"
  3210. "beiscsi_conn=%p \n", beiscsi_conn->beiscsi_conn_cid,
  3211. task, conn, beiscsi_conn);
  3212. if (!sc)
  3213. return beiscsi_mtask(task);
  3214. io_task->scsi_cmnd = sc;
  3215. num_sg = scsi_dma_map(sc);
  3216. if (num_sg < 0) {
  3217. SE_DEBUG(DBG_LVL_1, " scsi_dma_map Failed\n")
  3218. return num_sg;
  3219. }
  3220. SE_DEBUG(DBG_LVL_4, "xferlen=0x%08x scmd=%p num_sg=%d sernum=%lu\n",
  3221. (scsi_bufflen(sc)), sc, num_sg, sc->serial_number);
  3222. xferlen = scsi_bufflen(sc);
  3223. sg = scsi_sglist(sc);
  3224. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  3225. writedir = 1;
  3226. SE_DEBUG(DBG_LVL_4, "task->imm_count=0x%08x \n",
  3227. task->imm_count);
  3228. } else
  3229. writedir = 0;
  3230. return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
  3231. }
  3232. static void beiscsi_remove(struct pci_dev *pcidev)
  3233. {
  3234. struct beiscsi_hba *phba = NULL;
  3235. struct hwi_controller *phwi_ctrlr;
  3236. struct hwi_context_memory *phwi_context;
  3237. struct be_eq_obj *pbe_eq;
  3238. unsigned int i, msix_vec;
  3239. phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
  3240. if (!phba) {
  3241. dev_err(&pcidev->dev, "beiscsi_remove called with no phba \n");
  3242. return;
  3243. }
  3244. phwi_ctrlr = phba->phwi_ctrlr;
  3245. phwi_context = phwi_ctrlr->phwi_ctxt;
  3246. hwi_disable_intr(phba);
  3247. if (phba->msix_enabled) {
  3248. for (i = 0; i <= phba->num_cpus; i++) {
  3249. msix_vec = phba->msix_entries[i].vector;
  3250. free_irq(msix_vec, &phwi_context->be_eq[i]);
  3251. }
  3252. } else
  3253. if (phba->pcidev->irq)
  3254. free_irq(phba->pcidev->irq, phba);
  3255. pci_disable_msix(phba->pcidev);
  3256. destroy_workqueue(phba->wq);
  3257. if (blk_iopoll_enabled)
  3258. for (i = 0; i < phba->num_cpus; i++) {
  3259. pbe_eq = &phwi_context->be_eq[i];
  3260. blk_iopoll_disable(&pbe_eq->iopoll);
  3261. }
  3262. beiscsi_clean_port(phba);
  3263. beiscsi_free_mem(phba);
  3264. beiscsi_unmap_pci_function(phba);
  3265. pci_free_consistent(phba->pcidev,
  3266. phba->ctrl.mbox_mem_alloced.size,
  3267. phba->ctrl.mbox_mem_alloced.va,
  3268. phba->ctrl.mbox_mem_alloced.dma);
  3269. iscsi_host_remove(phba->shost);
  3270. pci_dev_put(phba->pcidev);
  3271. iscsi_host_free(phba->shost);
  3272. }
  3273. static void beiscsi_msix_enable(struct beiscsi_hba *phba)
  3274. {
  3275. int i, status;
  3276. for (i = 0; i <= phba->num_cpus; i++)
  3277. phba->msix_entries[i].entry = i;
  3278. status = pci_enable_msix(phba->pcidev, phba->msix_entries,
  3279. (phba->num_cpus + 1));
  3280. if (!status)
  3281. phba->msix_enabled = true;
  3282. return;
  3283. }
  3284. static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
  3285. const struct pci_device_id *id)
  3286. {
  3287. struct beiscsi_hba *phba = NULL;
  3288. struct hwi_controller *phwi_ctrlr;
  3289. struct hwi_context_memory *phwi_context;
  3290. struct be_eq_obj *pbe_eq;
  3291. int ret, msix_vec, num_cpus, i;
  3292. ret = beiscsi_enable_pci(pcidev);
  3293. if (ret < 0) {
  3294. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3295. "Failed to enable pci device \n");
  3296. return ret;
  3297. }
  3298. phba = beiscsi_hba_alloc(pcidev);
  3299. if (!phba) {
  3300. dev_err(&pcidev->dev, "beiscsi_dev_probe-"
  3301. " Failed in beiscsi_hba_alloc \n");
  3302. goto disable_pci;
  3303. }
  3304. SE_DEBUG(DBG_LVL_8, " phba = %p \n", phba);
  3305. if (enable_msix)
  3306. num_cpus = find_num_cpus();
  3307. else
  3308. num_cpus = 1;
  3309. phba->num_cpus = num_cpus;
  3310. SE_DEBUG(DBG_LVL_8, "num_cpus = %d \n", phba->num_cpus);
  3311. if (enable_msix)
  3312. beiscsi_msix_enable(phba);
  3313. ret = be_ctrl_init(phba, pcidev);
  3314. if (ret) {
  3315. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3316. "Failed in be_ctrl_init\n");
  3317. goto hba_free;
  3318. }
  3319. spin_lock_init(&phba->io_sgl_lock);
  3320. spin_lock_init(&phba->mgmt_sgl_lock);
  3321. spin_lock_init(&phba->isr_lock);
  3322. ret = mgmt_get_fw_config(&phba->ctrl, phba);
  3323. if (ret != 0) {
  3324. shost_printk(KERN_ERR, phba->shost,
  3325. "Error getting fw config\n");
  3326. goto free_port;
  3327. }
  3328. phba->shost->max_id = phba->fw_config.iscsi_cid_count;
  3329. beiscsi_get_params(phba);
  3330. phba->shost->can_queue = phba->params.ios_per_ctrl;
  3331. ret = beiscsi_init_port(phba);
  3332. if (ret < 0) {
  3333. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3334. "Failed in beiscsi_init_port\n");
  3335. goto free_port;
  3336. }
  3337. for (i = 0; i < MAX_MCC_CMD ; i++) {
  3338. init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
  3339. phba->ctrl.mcc_tag[i] = i + 1;
  3340. phba->ctrl.mcc_numtag[i + 1] = 0;
  3341. phba->ctrl.mcc_tag_available++;
  3342. }
  3343. phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
  3344. snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_q_irq%u",
  3345. phba->shost->host_no);
  3346. phba->wq = create_workqueue(phba->wq_name);
  3347. if (!phba->wq) {
  3348. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3349. "Failed to allocate work queue\n");
  3350. goto free_twq;
  3351. }
  3352. INIT_WORK(&phba->work_cqs, beiscsi_process_all_cqs);
  3353. phwi_ctrlr = phba->phwi_ctrlr;
  3354. phwi_context = phwi_ctrlr->phwi_ctxt;
  3355. if (blk_iopoll_enabled) {
  3356. for (i = 0; i < phba->num_cpus; i++) {
  3357. pbe_eq = &phwi_context->be_eq[i];
  3358. blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
  3359. be_iopoll);
  3360. blk_iopoll_enable(&pbe_eq->iopoll);
  3361. }
  3362. }
  3363. ret = beiscsi_init_irqs(phba);
  3364. if (ret < 0) {
  3365. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3366. "Failed to beiscsi_init_irqs\n");
  3367. goto free_blkenbld;
  3368. }
  3369. ret = hwi_enable_intr(phba);
  3370. if (ret < 0) {
  3371. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3372. "Failed to hwi_enable_intr\n");
  3373. goto free_ctrlr;
  3374. }
  3375. SE_DEBUG(DBG_LVL_8, "\n\n\n SUCCESS - DRIVER LOADED \n\n\n");
  3376. return 0;
  3377. free_ctrlr:
  3378. if (phba->msix_enabled) {
  3379. for (i = 0; i <= phba->num_cpus; i++) {
  3380. msix_vec = phba->msix_entries[i].vector;
  3381. free_irq(msix_vec, &phwi_context->be_eq[i]);
  3382. }
  3383. } else
  3384. if (phba->pcidev->irq)
  3385. free_irq(phba->pcidev->irq, phba);
  3386. pci_disable_msix(phba->pcidev);
  3387. free_blkenbld:
  3388. destroy_workqueue(phba->wq);
  3389. if (blk_iopoll_enabled)
  3390. for (i = 0; i < phba->num_cpus; i++) {
  3391. pbe_eq = &phwi_context->be_eq[i];
  3392. blk_iopoll_disable(&pbe_eq->iopoll);
  3393. }
  3394. free_twq:
  3395. beiscsi_clean_port(phba);
  3396. beiscsi_free_mem(phba);
  3397. free_port:
  3398. pci_free_consistent(phba->pcidev,
  3399. phba->ctrl.mbox_mem_alloced.size,
  3400. phba->ctrl.mbox_mem_alloced.va,
  3401. phba->ctrl.mbox_mem_alloced.dma);
  3402. beiscsi_unmap_pci_function(phba);
  3403. hba_free:
  3404. iscsi_host_remove(phba->shost);
  3405. pci_dev_put(phba->pcidev);
  3406. iscsi_host_free(phba->shost);
  3407. disable_pci:
  3408. pci_disable_device(pcidev);
  3409. return ret;
  3410. }
  3411. struct iscsi_transport beiscsi_iscsi_transport = {
  3412. .owner = THIS_MODULE,
  3413. .name = DRV_NAME,
  3414. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
  3415. CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
  3416. .param_mask = ISCSI_MAX_RECV_DLENGTH |
  3417. ISCSI_MAX_XMIT_DLENGTH |
  3418. ISCSI_HDRDGST_EN |
  3419. ISCSI_DATADGST_EN |
  3420. ISCSI_INITIAL_R2T_EN |
  3421. ISCSI_MAX_R2T |
  3422. ISCSI_IMM_DATA_EN |
  3423. ISCSI_FIRST_BURST |
  3424. ISCSI_MAX_BURST |
  3425. ISCSI_PDU_INORDER_EN |
  3426. ISCSI_DATASEQ_INORDER_EN |
  3427. ISCSI_ERL |
  3428. ISCSI_CONN_PORT |
  3429. ISCSI_CONN_ADDRESS |
  3430. ISCSI_EXP_STATSN |
  3431. ISCSI_PERSISTENT_PORT |
  3432. ISCSI_PERSISTENT_ADDRESS |
  3433. ISCSI_TARGET_NAME | ISCSI_TPGT |
  3434. ISCSI_USERNAME | ISCSI_PASSWORD |
  3435. ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
  3436. ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
  3437. ISCSI_LU_RESET_TMO |
  3438. ISCSI_PING_TMO | ISCSI_RECV_TMO |
  3439. ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
  3440. .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
  3441. ISCSI_HOST_INITIATOR_NAME,
  3442. .create_session = beiscsi_session_create,
  3443. .destroy_session = beiscsi_session_destroy,
  3444. .create_conn = beiscsi_conn_create,
  3445. .bind_conn = beiscsi_conn_bind,
  3446. .destroy_conn = iscsi_conn_teardown,
  3447. .set_param = beiscsi_set_param,
  3448. .get_conn_param = beiscsi_conn_get_param,
  3449. .get_session_param = iscsi_session_get_param,
  3450. .get_host_param = beiscsi_get_host_param,
  3451. .start_conn = beiscsi_conn_start,
  3452. .stop_conn = beiscsi_conn_stop,
  3453. .send_pdu = iscsi_conn_send_pdu,
  3454. .xmit_task = beiscsi_task_xmit,
  3455. .cleanup_task = beiscsi_cleanup_task,
  3456. .alloc_pdu = beiscsi_alloc_pdu,
  3457. .parse_pdu_itt = beiscsi_parse_pdu,
  3458. .get_stats = beiscsi_conn_get_stats,
  3459. .ep_connect = beiscsi_ep_connect,
  3460. .ep_poll = beiscsi_ep_poll,
  3461. .ep_disconnect = beiscsi_ep_disconnect,
  3462. .session_recovery_timedout = iscsi_session_recovery_timedout,
  3463. };
  3464. static struct pci_driver beiscsi_pci_driver = {
  3465. .name = DRV_NAME,
  3466. .probe = beiscsi_dev_probe,
  3467. .remove = beiscsi_remove,
  3468. .id_table = beiscsi_pci_id_table
  3469. };
  3470. static int __init beiscsi_module_init(void)
  3471. {
  3472. int ret;
  3473. beiscsi_scsi_transport =
  3474. iscsi_register_transport(&beiscsi_iscsi_transport);
  3475. if (!beiscsi_scsi_transport) {
  3476. SE_DEBUG(DBG_LVL_1,
  3477. "beiscsi_module_init - Unable to register beiscsi"
  3478. "transport.\n");
  3479. return -ENOMEM;
  3480. }
  3481. SE_DEBUG(DBG_LVL_8, "In beiscsi_module_init, tt=%p \n",
  3482. &beiscsi_iscsi_transport);
  3483. ret = pci_register_driver(&beiscsi_pci_driver);
  3484. if (ret) {
  3485. SE_DEBUG(DBG_LVL_1,
  3486. "beiscsi_module_init - Unable to register"
  3487. "beiscsi pci driver.\n");
  3488. goto unregister_iscsi_transport;
  3489. }
  3490. return 0;
  3491. unregister_iscsi_transport:
  3492. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  3493. return ret;
  3494. }
  3495. static void __exit beiscsi_module_exit(void)
  3496. {
  3497. pci_unregister_driver(&beiscsi_pci_driver);
  3498. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  3499. }
  3500. module_init(beiscsi_module_init);
  3501. module_exit(beiscsi_module_exit);