be_main.c 127 KB

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