be_main.c 116 KB

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