be_main.c 127 KB

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