be_main.c 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551
  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 <linux/bsg-lib.h>
  31. #include <scsi/libiscsi.h>
  32. #include <scsi/scsi_bsg_iscsi.h>
  33. #include <scsi/scsi_netlink.h>
  34. #include <scsi/scsi_transport_iscsi.h>
  35. #include <scsi/scsi_transport.h>
  36. #include <scsi/scsi_cmnd.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi.h>
  40. #include "be_main.h"
  41. #include "be_iscsi.h"
  42. #include "be_mgmt.h"
  43. static unsigned int be_iopoll_budget = 10;
  44. static unsigned int be_max_phys_size = 64;
  45. static unsigned int enable_msix = 1;
  46. static unsigned int gcrashmode = 0;
  47. static unsigned int num_hba = 0;
  48. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  49. MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
  50. MODULE_VERSION(BUILD_STR);
  51. MODULE_AUTHOR("Emulex Corporation");
  52. MODULE_LICENSE("GPL");
  53. module_param(be_iopoll_budget, int, 0);
  54. module_param(enable_msix, int, 0);
  55. module_param(be_max_phys_size, uint, S_IRUGO);
  56. MODULE_PARM_DESC(be_max_phys_size, "Maximum Size (In Kilobytes) of physically"
  57. "contiguous memory that can be allocated."
  58. "Range is 16 - 128");
  59. static int beiscsi_slave_configure(struct scsi_device *sdev)
  60. {
  61. blk_queue_max_segment_size(sdev->request_queue, 65536);
  62. return 0;
  63. }
  64. static int beiscsi_eh_abort(struct scsi_cmnd *sc)
  65. {
  66. struct iscsi_cls_session *cls_session;
  67. struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
  68. struct beiscsi_io_task *aborted_io_task;
  69. struct iscsi_conn *conn;
  70. struct beiscsi_conn *beiscsi_conn;
  71. struct beiscsi_hba *phba;
  72. struct iscsi_session *session;
  73. struct invalidate_command_table *inv_tbl;
  74. struct be_dma_mem nonemb_cmd;
  75. unsigned int cid, tag, num_invalidate;
  76. cls_session = starget_to_session(scsi_target(sc->device));
  77. session = cls_session->dd_data;
  78. spin_lock_bh(&session->lock);
  79. if (!aborted_task || !aborted_task->sc) {
  80. /* we raced */
  81. spin_unlock_bh(&session->lock);
  82. return SUCCESS;
  83. }
  84. aborted_io_task = aborted_task->dd_data;
  85. if (!aborted_io_task->scsi_cmnd) {
  86. /* raced or invalid command */
  87. spin_unlock_bh(&session->lock);
  88. return SUCCESS;
  89. }
  90. spin_unlock_bh(&session->lock);
  91. conn = aborted_task->conn;
  92. beiscsi_conn = conn->dd_data;
  93. phba = beiscsi_conn->phba;
  94. /* invalidate iocb */
  95. cid = beiscsi_conn->beiscsi_conn_cid;
  96. inv_tbl = phba->inv_tbl;
  97. memset(inv_tbl, 0x0, sizeof(*inv_tbl));
  98. inv_tbl->cid = cid;
  99. inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
  100. num_invalidate = 1;
  101. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  102. sizeof(struct invalidate_commands_params_in),
  103. &nonemb_cmd.dma);
  104. if (nonemb_cmd.va == NULL) {
  105. SE_DEBUG(DBG_LVL_1,
  106. "Failed to allocate memory for"
  107. "mgmt_invalidate_icds\n");
  108. return FAILED;
  109. }
  110. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  111. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  112. cid, &nonemb_cmd);
  113. if (!tag) {
  114. shost_printk(KERN_WARNING, phba->shost,
  115. "mgmt_invalidate_icds could not be"
  116. " submitted\n");
  117. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  118. nonemb_cmd.va, nonemb_cmd.dma);
  119. return FAILED;
  120. } else {
  121. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  122. phba->ctrl.mcc_numtag[tag]);
  123. free_mcc_tag(&phba->ctrl, tag);
  124. }
  125. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  126. nonemb_cmd.va, nonemb_cmd.dma);
  127. return iscsi_eh_abort(sc);
  128. }
  129. static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
  130. {
  131. struct iscsi_task *abrt_task;
  132. struct beiscsi_io_task *abrt_io_task;
  133. struct iscsi_conn *conn;
  134. struct beiscsi_conn *beiscsi_conn;
  135. struct beiscsi_hba *phba;
  136. struct iscsi_session *session;
  137. struct iscsi_cls_session *cls_session;
  138. struct invalidate_command_table *inv_tbl;
  139. struct be_dma_mem nonemb_cmd;
  140. unsigned int cid, tag, i, num_invalidate;
  141. /* invalidate iocbs */
  142. cls_session = starget_to_session(scsi_target(sc->device));
  143. session = cls_session->dd_data;
  144. spin_lock_bh(&session->lock);
  145. if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
  146. spin_unlock_bh(&session->lock);
  147. return FAILED;
  148. }
  149. conn = session->leadconn;
  150. beiscsi_conn = conn->dd_data;
  151. phba = beiscsi_conn->phba;
  152. cid = beiscsi_conn->beiscsi_conn_cid;
  153. inv_tbl = phba->inv_tbl;
  154. memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
  155. num_invalidate = 0;
  156. for (i = 0; i < conn->session->cmds_max; i++) {
  157. abrt_task = conn->session->cmds[i];
  158. abrt_io_task = abrt_task->dd_data;
  159. if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
  160. continue;
  161. if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
  162. continue;
  163. inv_tbl->cid = cid;
  164. inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
  165. num_invalidate++;
  166. inv_tbl++;
  167. }
  168. spin_unlock_bh(&session->lock);
  169. inv_tbl = phba->inv_tbl;
  170. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  171. sizeof(struct invalidate_commands_params_in),
  172. &nonemb_cmd.dma);
  173. if (nonemb_cmd.va == NULL) {
  174. SE_DEBUG(DBG_LVL_1,
  175. "Failed to allocate memory for"
  176. "mgmt_invalidate_icds\n");
  177. return FAILED;
  178. }
  179. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  180. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  181. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  182. cid, &nonemb_cmd);
  183. if (!tag) {
  184. shost_printk(KERN_WARNING, phba->shost,
  185. "mgmt_invalidate_icds could not be"
  186. " submitted\n");
  187. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  188. nonemb_cmd.va, nonemb_cmd.dma);
  189. return FAILED;
  190. } else {
  191. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  192. phba->ctrl.mcc_numtag[tag]);
  193. free_mcc_tag(&phba->ctrl, tag);
  194. }
  195. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  196. nonemb_cmd.va, nonemb_cmd.dma);
  197. return iscsi_eh_device_reset(sc);
  198. }
  199. static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
  200. {
  201. struct beiscsi_hba *phba = data;
  202. struct mgmt_session_info *boot_sess = &phba->boot_sess;
  203. struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
  204. char *str = buf;
  205. int rc;
  206. switch (type) {
  207. case ISCSI_BOOT_TGT_NAME:
  208. rc = sprintf(buf, "%.*s\n",
  209. (int)strlen(boot_sess->target_name),
  210. (char *)&boot_sess->target_name);
  211. break;
  212. case ISCSI_BOOT_TGT_IP_ADDR:
  213. if (boot_conn->dest_ipaddr.ip_type == 0x1)
  214. rc = sprintf(buf, "%pI4\n",
  215. (char *)&boot_conn->dest_ipaddr.addr);
  216. else
  217. rc = sprintf(str, "%pI6\n",
  218. (char *)&boot_conn->dest_ipaddr.addr);
  219. break;
  220. case ISCSI_BOOT_TGT_PORT:
  221. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  222. break;
  223. case ISCSI_BOOT_TGT_CHAP_NAME:
  224. rc = sprintf(str, "%.*s\n",
  225. boot_conn->negotiated_login_options.auth_data.chap.
  226. target_chap_name_length,
  227. (char *)&boot_conn->negotiated_login_options.
  228. auth_data.chap.target_chap_name);
  229. break;
  230. case ISCSI_BOOT_TGT_CHAP_SECRET:
  231. rc = sprintf(str, "%.*s\n",
  232. boot_conn->negotiated_login_options.auth_data.chap.
  233. target_secret_length,
  234. (char *)&boot_conn->negotiated_login_options.
  235. auth_data.chap.target_secret);
  236. break;
  237. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  238. rc = sprintf(str, "%.*s\n",
  239. boot_conn->negotiated_login_options.auth_data.chap.
  240. intr_chap_name_length,
  241. (char *)&boot_conn->negotiated_login_options.
  242. auth_data.chap.intr_chap_name);
  243. break;
  244. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  245. rc = sprintf(str, "%.*s\n",
  246. boot_conn->negotiated_login_options.auth_data.chap.
  247. intr_secret_length,
  248. (char *)&boot_conn->negotiated_login_options.
  249. auth_data.chap.intr_secret);
  250. break;
  251. case ISCSI_BOOT_TGT_FLAGS:
  252. rc = sprintf(str, "2\n");
  253. break;
  254. case ISCSI_BOOT_TGT_NIC_ASSOC:
  255. rc = sprintf(str, "0\n");
  256. break;
  257. default:
  258. rc = -ENOSYS;
  259. break;
  260. }
  261. return rc;
  262. }
  263. static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
  264. {
  265. struct beiscsi_hba *phba = data;
  266. char *str = buf;
  267. int rc;
  268. switch (type) {
  269. case ISCSI_BOOT_INI_INITIATOR_NAME:
  270. rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
  271. break;
  272. default:
  273. rc = -ENOSYS;
  274. break;
  275. }
  276. return rc;
  277. }
  278. static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
  279. {
  280. struct beiscsi_hba *phba = data;
  281. char *str = buf;
  282. int rc;
  283. switch (type) {
  284. case ISCSI_BOOT_ETH_FLAGS:
  285. rc = sprintf(str, "2\n");
  286. break;
  287. case ISCSI_BOOT_ETH_INDEX:
  288. rc = sprintf(str, "0\n");
  289. break;
  290. case ISCSI_BOOT_ETH_MAC:
  291. rc = beiscsi_get_macaddr(str, phba);
  292. break;
  293. default:
  294. rc = -ENOSYS;
  295. break;
  296. }
  297. return rc;
  298. }
  299. static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
  300. {
  301. umode_t rc;
  302. switch (type) {
  303. case ISCSI_BOOT_TGT_NAME:
  304. case ISCSI_BOOT_TGT_IP_ADDR:
  305. case ISCSI_BOOT_TGT_PORT:
  306. case ISCSI_BOOT_TGT_CHAP_NAME:
  307. case ISCSI_BOOT_TGT_CHAP_SECRET:
  308. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  309. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  310. case ISCSI_BOOT_TGT_NIC_ASSOC:
  311. case ISCSI_BOOT_TGT_FLAGS:
  312. rc = S_IRUGO;
  313. break;
  314. default:
  315. rc = 0;
  316. break;
  317. }
  318. return rc;
  319. }
  320. static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
  321. {
  322. umode_t rc;
  323. switch (type) {
  324. case ISCSI_BOOT_INI_INITIATOR_NAME:
  325. rc = S_IRUGO;
  326. break;
  327. default:
  328. rc = 0;
  329. break;
  330. }
  331. return rc;
  332. }
  333. static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
  334. {
  335. umode_t rc;
  336. switch (type) {
  337. case ISCSI_BOOT_ETH_FLAGS:
  338. case ISCSI_BOOT_ETH_MAC:
  339. case ISCSI_BOOT_ETH_INDEX:
  340. rc = S_IRUGO;
  341. break;
  342. default:
  343. rc = 0;
  344. break;
  345. }
  346. return rc;
  347. }
  348. /*------------------- PCI Driver operations and data ----------------- */
  349. static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
  350. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
  351. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
  352. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
  353. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
  354. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
  355. { 0 }
  356. };
  357. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  358. static struct scsi_host_template beiscsi_sht = {
  359. .module = THIS_MODULE,
  360. .name = "Emulex 10Gbe open-iscsi Initiator Driver",
  361. .proc_name = DRV_NAME,
  362. .queuecommand = iscsi_queuecommand,
  363. .change_queue_depth = iscsi_change_queue_depth,
  364. .slave_configure = beiscsi_slave_configure,
  365. .target_alloc = iscsi_target_alloc,
  366. .eh_abort_handler = beiscsi_eh_abort,
  367. .eh_device_reset_handler = beiscsi_eh_device_reset,
  368. .eh_target_reset_handler = iscsi_eh_session_reset,
  369. .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
  370. .can_queue = BE2_IO_DEPTH,
  371. .this_id = -1,
  372. .max_sectors = BEISCSI_MAX_SECTORS,
  373. .cmd_per_lun = BEISCSI_CMD_PER_LUN,
  374. .use_clustering = ENABLE_CLUSTERING,
  375. .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
  376. };
  377. static struct scsi_transport_template *beiscsi_scsi_transport;
  378. static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
  379. {
  380. struct beiscsi_hba *phba;
  381. struct Scsi_Host *shost;
  382. shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
  383. if (!shost) {
  384. dev_err(&pcidev->dev, "beiscsi_hba_alloc -"
  385. "iscsi_host_alloc failed\n");
  386. return NULL;
  387. }
  388. shost->dma_boundary = pcidev->dma_mask;
  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. phba->interface_handle = 0xFFFFFFFF;
  400. if (iscsi_host_add(shost, &phba->pcidev->dev))
  401. goto free_devices;
  402. return phba;
  403. free_devices:
  404. pci_dev_put(phba->pcidev);
  405. iscsi_host_free(phba->shost);
  406. return NULL;
  407. }
  408. static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
  409. {
  410. if (phba->csr_va) {
  411. iounmap(phba->csr_va);
  412. phba->csr_va = NULL;
  413. }
  414. if (phba->db_va) {
  415. iounmap(phba->db_va);
  416. phba->db_va = NULL;
  417. }
  418. if (phba->pci_va) {
  419. iounmap(phba->pci_va);
  420. phba->pci_va = NULL;
  421. }
  422. }
  423. static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
  424. struct pci_dev *pcidev)
  425. {
  426. u8 __iomem *addr;
  427. int pcicfg_reg;
  428. addr = ioremap_nocache(pci_resource_start(pcidev, 2),
  429. pci_resource_len(pcidev, 2));
  430. if (addr == NULL)
  431. return -ENOMEM;
  432. phba->ctrl.csr = addr;
  433. phba->csr_va = addr;
  434. phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
  435. addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
  436. if (addr == NULL)
  437. goto pci_map_err;
  438. phba->ctrl.db = addr;
  439. phba->db_va = addr;
  440. phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
  441. if (phba->generation == BE_GEN2)
  442. pcicfg_reg = 1;
  443. else
  444. pcicfg_reg = 0;
  445. addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
  446. pci_resource_len(pcidev, pcicfg_reg));
  447. if (addr == NULL)
  448. goto pci_map_err;
  449. phba->ctrl.pcicfg = addr;
  450. phba->pci_va = addr;
  451. phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
  452. return 0;
  453. pci_map_err:
  454. beiscsi_unmap_pci_function(phba);
  455. return -ENOMEM;
  456. }
  457. static int beiscsi_enable_pci(struct pci_dev *pcidev)
  458. {
  459. int ret;
  460. ret = pci_enable_device(pcidev);
  461. if (ret) {
  462. dev_err(&pcidev->dev, "beiscsi_enable_pci - enable device "
  463. "failed. Returning -ENODEV\n");
  464. return ret;
  465. }
  466. pci_set_master(pcidev);
  467. if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
  468. ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
  469. if (ret) {
  470. dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
  471. pci_disable_device(pcidev);
  472. return ret;
  473. }
  474. }
  475. return 0;
  476. }
  477. static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
  478. {
  479. struct be_ctrl_info *ctrl = &phba->ctrl;
  480. struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
  481. struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
  482. int status = 0;
  483. ctrl->pdev = pdev;
  484. status = beiscsi_map_pci_bars(phba, pdev);
  485. if (status)
  486. return status;
  487. mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
  488. mbox_mem_alloc->va = pci_alloc_consistent(pdev,
  489. mbox_mem_alloc->size,
  490. &mbox_mem_alloc->dma);
  491. if (!mbox_mem_alloc->va) {
  492. beiscsi_unmap_pci_function(phba);
  493. return -ENOMEM;
  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_bh(&phba->mgmt_sgl_lock);
  1140. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  1141. spin_unlock_bh(&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. unsigned char is_header = 0;
  1245. phys_addr.u.a32.address_lo =
  1246. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_lo) / 32] -
  1247. ((pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
  1248. & PDUCQE_DPL_MASK) >> 16);
  1249. phys_addr.u.a32.address_hi =
  1250. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_hi) / 32];
  1251. phys_addr.u.a64.address =
  1252. *((unsigned long long *)(&phys_addr.u.a64.address));
  1253. switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
  1254. & PDUCQE_CODE_MASK) {
  1255. case UNSOL_HDR_NOTIFY:
  1256. is_header = 1;
  1257. pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1,
  1258. (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1259. index) / 32] & PDUCQE_INDEX_MASK));
  1260. break;
  1261. case UNSOL_DATA_NOTIFY:
  1262. pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe->
  1263. dw[offsetof(struct amap_i_t_dpdu_cqe,
  1264. index) / 32] & PDUCQE_INDEX_MASK));
  1265. break;
  1266. default:
  1267. pbusy_list = NULL;
  1268. shost_printk(KERN_WARNING, phba->shost,
  1269. "Unexpected code=%d\n",
  1270. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1271. code) / 32] & PDUCQE_CODE_MASK);
  1272. return NULL;
  1273. }
  1274. WARN_ON(list_empty(pbusy_list));
  1275. list_for_each_entry(pasync_handle, pbusy_list, link) {
  1276. if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
  1277. break;
  1278. }
  1279. WARN_ON(!pasync_handle);
  1280. pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid -
  1281. phba->fw_config.iscsi_cid_start;
  1282. pasync_handle->is_header = is_header;
  1283. pasync_handle->buffer_len = ((pdpdu_cqe->
  1284. dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
  1285. & PDUCQE_DPL_MASK) >> 16);
  1286. *pcq_index = (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1287. index) / 32] & PDUCQE_INDEX_MASK);
  1288. return pasync_handle;
  1289. }
  1290. static unsigned int
  1291. hwi_update_async_writables(struct hwi_async_pdu_context *pasync_ctx,
  1292. unsigned int is_header, unsigned int cq_index)
  1293. {
  1294. struct list_head *pbusy_list;
  1295. struct async_pdu_handle *pasync_handle;
  1296. unsigned int num_entries, writables = 0;
  1297. unsigned int *pep_read_ptr, *pwritables;
  1298. num_entries = pasync_ctx->num_entries;
  1299. if (is_header) {
  1300. pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
  1301. pwritables = &pasync_ctx->async_header.writables;
  1302. } else {
  1303. pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
  1304. pwritables = &pasync_ctx->async_data.writables;
  1305. }
  1306. while ((*pep_read_ptr) != cq_index) {
  1307. (*pep_read_ptr)++;
  1308. *pep_read_ptr = (*pep_read_ptr) % num_entries;
  1309. pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
  1310. *pep_read_ptr);
  1311. if (writables == 0)
  1312. WARN_ON(list_empty(pbusy_list));
  1313. if (!list_empty(pbusy_list)) {
  1314. pasync_handle = list_entry(pbusy_list->next,
  1315. struct async_pdu_handle,
  1316. link);
  1317. WARN_ON(!pasync_handle);
  1318. pasync_handle->consumed = 1;
  1319. }
  1320. writables++;
  1321. }
  1322. if (!writables) {
  1323. SE_DEBUG(DBG_LVL_1,
  1324. "Duplicate notification received - index 0x%x!!\n",
  1325. cq_index);
  1326. WARN_ON(1);
  1327. }
  1328. *pwritables = *pwritables + writables;
  1329. return 0;
  1330. }
  1331. static void hwi_free_async_msg(struct beiscsi_hba *phba,
  1332. unsigned int cri)
  1333. {
  1334. struct hwi_controller *phwi_ctrlr;
  1335. struct hwi_async_pdu_context *pasync_ctx;
  1336. struct async_pdu_handle *pasync_handle, *tmp_handle;
  1337. struct list_head *plist;
  1338. phwi_ctrlr = phba->phwi_ctrlr;
  1339. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1340. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1341. list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
  1342. list_del(&pasync_handle->link);
  1343. if (pasync_handle->is_header) {
  1344. list_add_tail(&pasync_handle->link,
  1345. &pasync_ctx->async_header.free_list);
  1346. pasync_ctx->async_header.free_entries++;
  1347. } else {
  1348. list_add_tail(&pasync_handle->link,
  1349. &pasync_ctx->async_data.free_list);
  1350. pasync_ctx->async_data.free_entries++;
  1351. }
  1352. }
  1353. INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
  1354. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
  1355. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1356. }
  1357. static struct phys_addr *
  1358. hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
  1359. unsigned int is_header, unsigned int host_write_ptr)
  1360. {
  1361. struct phys_addr *pasync_sge = NULL;
  1362. if (is_header)
  1363. pasync_sge = pasync_ctx->async_header.ring_base;
  1364. else
  1365. pasync_sge = pasync_ctx->async_data.ring_base;
  1366. return pasync_sge + host_write_ptr;
  1367. }
  1368. static void hwi_post_async_buffers(struct beiscsi_hba *phba,
  1369. unsigned int is_header)
  1370. {
  1371. struct hwi_controller *phwi_ctrlr;
  1372. struct hwi_async_pdu_context *pasync_ctx;
  1373. struct async_pdu_handle *pasync_handle;
  1374. struct list_head *pfree_link, *pbusy_list;
  1375. struct phys_addr *pasync_sge;
  1376. unsigned int ring_id, num_entries;
  1377. unsigned int host_write_num;
  1378. unsigned int writables;
  1379. unsigned int i = 0;
  1380. u32 doorbell = 0;
  1381. phwi_ctrlr = phba->phwi_ctrlr;
  1382. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1383. num_entries = pasync_ctx->num_entries;
  1384. if (is_header) {
  1385. writables = min(pasync_ctx->async_header.writables,
  1386. pasync_ctx->async_header.free_entries);
  1387. pfree_link = pasync_ctx->async_header.free_list.next;
  1388. host_write_num = pasync_ctx->async_header.host_write_ptr;
  1389. ring_id = phwi_ctrlr->default_pdu_hdr.id;
  1390. } else {
  1391. writables = min(pasync_ctx->async_data.writables,
  1392. pasync_ctx->async_data.free_entries);
  1393. pfree_link = pasync_ctx->async_data.free_list.next;
  1394. host_write_num = pasync_ctx->async_data.host_write_ptr;
  1395. ring_id = phwi_ctrlr->default_pdu_data.id;
  1396. }
  1397. writables = (writables / 8) * 8;
  1398. if (writables) {
  1399. for (i = 0; i < writables; i++) {
  1400. pbusy_list =
  1401. hwi_get_async_busy_list(pasync_ctx, is_header,
  1402. host_write_num);
  1403. pasync_handle =
  1404. list_entry(pfree_link, struct async_pdu_handle,
  1405. link);
  1406. WARN_ON(!pasync_handle);
  1407. pasync_handle->consumed = 0;
  1408. pfree_link = pfree_link->next;
  1409. pasync_sge = hwi_get_ring_address(pasync_ctx,
  1410. is_header, host_write_num);
  1411. pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
  1412. pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
  1413. list_move(&pasync_handle->link, pbusy_list);
  1414. host_write_num++;
  1415. host_write_num = host_write_num % num_entries;
  1416. }
  1417. if (is_header) {
  1418. pasync_ctx->async_header.host_write_ptr =
  1419. host_write_num;
  1420. pasync_ctx->async_header.free_entries -= writables;
  1421. pasync_ctx->async_header.writables -= writables;
  1422. pasync_ctx->async_header.busy_entries += writables;
  1423. } else {
  1424. pasync_ctx->async_data.host_write_ptr = host_write_num;
  1425. pasync_ctx->async_data.free_entries -= writables;
  1426. pasync_ctx->async_data.writables -= writables;
  1427. pasync_ctx->async_data.busy_entries += writables;
  1428. }
  1429. doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
  1430. doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
  1431. doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
  1432. doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
  1433. << DB_DEF_PDU_CQPROC_SHIFT;
  1434. iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
  1435. }
  1436. }
  1437. static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
  1438. struct beiscsi_conn *beiscsi_conn,
  1439. struct i_t_dpdu_cqe *pdpdu_cqe)
  1440. {
  1441. struct hwi_controller *phwi_ctrlr;
  1442. struct hwi_async_pdu_context *pasync_ctx;
  1443. struct async_pdu_handle *pasync_handle = NULL;
  1444. unsigned int cq_index = -1;
  1445. phwi_ctrlr = phba->phwi_ctrlr;
  1446. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1447. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1448. pdpdu_cqe, &cq_index);
  1449. BUG_ON(pasync_handle->is_header != 0);
  1450. if (pasync_handle->consumed == 0)
  1451. hwi_update_async_writables(pasync_ctx, pasync_handle->is_header,
  1452. cq_index);
  1453. hwi_free_async_msg(phba, pasync_handle->cri);
  1454. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1455. }
  1456. static unsigned int
  1457. hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
  1458. struct beiscsi_hba *phba,
  1459. struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
  1460. {
  1461. struct list_head *plist;
  1462. struct async_pdu_handle *pasync_handle;
  1463. void *phdr = NULL;
  1464. unsigned int hdr_len = 0, buf_len = 0;
  1465. unsigned int status, index = 0, offset = 0;
  1466. void *pfirst_buffer = NULL;
  1467. unsigned int num_buf = 0;
  1468. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1469. list_for_each_entry(pasync_handle, plist, link) {
  1470. if (index == 0) {
  1471. phdr = pasync_handle->pbuffer;
  1472. hdr_len = pasync_handle->buffer_len;
  1473. } else {
  1474. buf_len = pasync_handle->buffer_len;
  1475. if (!num_buf) {
  1476. pfirst_buffer = pasync_handle->pbuffer;
  1477. num_buf++;
  1478. }
  1479. memcpy(pfirst_buffer + offset,
  1480. pasync_handle->pbuffer, buf_len);
  1481. offset += buf_len;
  1482. }
  1483. index++;
  1484. }
  1485. status = beiscsi_process_async_pdu(beiscsi_conn, phba,
  1486. (beiscsi_conn->beiscsi_conn_cid -
  1487. phba->fw_config.iscsi_cid_start),
  1488. phdr, hdr_len, pfirst_buffer,
  1489. offset);
  1490. hwi_free_async_msg(phba, cri);
  1491. return 0;
  1492. }
  1493. static unsigned int
  1494. hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
  1495. struct beiscsi_hba *phba,
  1496. struct async_pdu_handle *pasync_handle)
  1497. {
  1498. struct hwi_async_pdu_context *pasync_ctx;
  1499. struct hwi_controller *phwi_ctrlr;
  1500. unsigned int bytes_needed = 0, status = 0;
  1501. unsigned short cri = pasync_handle->cri;
  1502. struct pdu_base *ppdu;
  1503. phwi_ctrlr = phba->phwi_ctrlr;
  1504. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1505. list_del(&pasync_handle->link);
  1506. if (pasync_handle->is_header) {
  1507. pasync_ctx->async_header.busy_entries--;
  1508. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1509. hwi_free_async_msg(phba, cri);
  1510. BUG();
  1511. }
  1512. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1513. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
  1514. pasync_ctx->async_entry[cri].wait_queue.hdr_len =
  1515. (unsigned short)pasync_handle->buffer_len;
  1516. list_add_tail(&pasync_handle->link,
  1517. &pasync_ctx->async_entry[cri].wait_queue.list);
  1518. ppdu = pasync_handle->pbuffer;
  1519. bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
  1520. data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
  1521. 0xFFFF0000) | ((be16_to_cpu((ppdu->
  1522. dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
  1523. & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
  1524. if (status == 0) {
  1525. pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
  1526. bytes_needed;
  1527. if (bytes_needed == 0)
  1528. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1529. pasync_ctx, cri);
  1530. }
  1531. } else {
  1532. pasync_ctx->async_data.busy_entries--;
  1533. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1534. list_add_tail(&pasync_handle->link,
  1535. &pasync_ctx->async_entry[cri].wait_queue.
  1536. list);
  1537. pasync_ctx->async_entry[cri].wait_queue.
  1538. bytes_received +=
  1539. (unsigned short)pasync_handle->buffer_len;
  1540. if (pasync_ctx->async_entry[cri].wait_queue.
  1541. bytes_received >=
  1542. pasync_ctx->async_entry[cri].wait_queue.
  1543. bytes_needed)
  1544. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1545. pasync_ctx, cri);
  1546. }
  1547. }
  1548. return status;
  1549. }
  1550. static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
  1551. struct beiscsi_hba *phba,
  1552. struct i_t_dpdu_cqe *pdpdu_cqe)
  1553. {
  1554. struct hwi_controller *phwi_ctrlr;
  1555. struct hwi_async_pdu_context *pasync_ctx;
  1556. struct async_pdu_handle *pasync_handle = NULL;
  1557. unsigned int cq_index = -1;
  1558. phwi_ctrlr = phba->phwi_ctrlr;
  1559. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1560. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1561. pdpdu_cqe, &cq_index);
  1562. if (pasync_handle->consumed == 0)
  1563. hwi_update_async_writables(pasync_ctx, pasync_handle->is_header,
  1564. cq_index);
  1565. hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
  1566. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1567. }
  1568. static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
  1569. {
  1570. struct be_queue_info *mcc_cq;
  1571. struct be_mcc_compl *mcc_compl;
  1572. unsigned int num_processed = 0;
  1573. mcc_cq = &phba->ctrl.mcc_obj.cq;
  1574. mcc_compl = queue_tail_node(mcc_cq);
  1575. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1576. while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
  1577. if (num_processed >= 32) {
  1578. hwi_ring_cq_db(phba, mcc_cq->id,
  1579. num_processed, 0, 0);
  1580. num_processed = 0;
  1581. }
  1582. if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
  1583. /* Interpret flags as an async trailer */
  1584. if (is_link_state_evt(mcc_compl->flags))
  1585. /* Interpret compl as a async link evt */
  1586. beiscsi_async_link_state_process(phba,
  1587. (struct be_async_event_link_state *) mcc_compl);
  1588. else
  1589. SE_DEBUG(DBG_LVL_1,
  1590. " Unsupported Async Event, flags"
  1591. " = 0x%08x\n", mcc_compl->flags);
  1592. } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  1593. be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
  1594. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  1595. }
  1596. mcc_compl->flags = 0;
  1597. queue_tail_inc(mcc_cq);
  1598. mcc_compl = queue_tail_node(mcc_cq);
  1599. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1600. num_processed++;
  1601. }
  1602. if (num_processed > 0)
  1603. hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
  1604. }
  1605. static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
  1606. {
  1607. struct be_queue_info *cq;
  1608. struct sol_cqe *sol;
  1609. struct dmsg_cqe *dmsg;
  1610. unsigned int num_processed = 0;
  1611. unsigned int tot_nump = 0;
  1612. struct beiscsi_conn *beiscsi_conn;
  1613. struct beiscsi_endpoint *beiscsi_ep;
  1614. struct iscsi_endpoint *ep;
  1615. struct beiscsi_hba *phba;
  1616. cq = pbe_eq->cq;
  1617. sol = queue_tail_node(cq);
  1618. phba = pbe_eq->phba;
  1619. while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
  1620. CQE_VALID_MASK) {
  1621. be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
  1622. ep = phba->ep_array[(u32) ((sol->
  1623. dw[offsetof(struct amap_sol_cqe, cid) / 32] &
  1624. SOL_CID_MASK) >> 6) -
  1625. phba->fw_config.iscsi_cid_start];
  1626. beiscsi_ep = ep->dd_data;
  1627. beiscsi_conn = beiscsi_ep->conn;
  1628. if (num_processed >= 32) {
  1629. hwi_ring_cq_db(phba, cq->id,
  1630. num_processed, 0, 0);
  1631. tot_nump += num_processed;
  1632. num_processed = 0;
  1633. }
  1634. switch ((u32) sol->dw[offsetof(struct amap_sol_cqe, code) /
  1635. 32] & CQE_CODE_MASK) {
  1636. case SOL_CMD_COMPLETE:
  1637. hwi_complete_cmd(beiscsi_conn, phba, sol);
  1638. break;
  1639. case DRIVERMSG_NOTIFY:
  1640. SE_DEBUG(DBG_LVL_8, "Received DRIVERMSG_NOTIFY\n");
  1641. dmsg = (struct dmsg_cqe *)sol;
  1642. hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
  1643. break;
  1644. case UNSOL_HDR_NOTIFY:
  1645. SE_DEBUG(DBG_LVL_8, "Received UNSOL_HDR_ NOTIFY\n");
  1646. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1647. (struct i_t_dpdu_cqe *)sol);
  1648. break;
  1649. case UNSOL_DATA_NOTIFY:
  1650. SE_DEBUG(DBG_LVL_8, "Received UNSOL_DATA_NOTIFY\n");
  1651. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1652. (struct i_t_dpdu_cqe *)sol);
  1653. break;
  1654. case CXN_INVALIDATE_INDEX_NOTIFY:
  1655. case CMD_INVALIDATED_NOTIFY:
  1656. case CXN_INVALIDATE_NOTIFY:
  1657. SE_DEBUG(DBG_LVL_1,
  1658. "Ignoring CQ Error notification for cmd/cxn"
  1659. "invalidate\n");
  1660. break;
  1661. case SOL_CMD_KILLED_DATA_DIGEST_ERR:
  1662. case CMD_KILLED_INVALID_STATSN_RCVD:
  1663. case CMD_KILLED_INVALID_R2T_RCVD:
  1664. case CMD_CXN_KILLED_LUN_INVALID:
  1665. case CMD_CXN_KILLED_ICD_INVALID:
  1666. case CMD_CXN_KILLED_ITT_INVALID:
  1667. case CMD_CXN_KILLED_SEQ_OUTOFORDER:
  1668. case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
  1669. SE_DEBUG(DBG_LVL_1,
  1670. "CQ Error notification for cmd.. "
  1671. "code %d cid 0x%x\n",
  1672. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1673. 32] & CQE_CODE_MASK,
  1674. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1675. 32] & SOL_CID_MASK));
  1676. break;
  1677. case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
  1678. SE_DEBUG(DBG_LVL_1,
  1679. "Digest error on def pdu ring, dropping..\n");
  1680. hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
  1681. (struct i_t_dpdu_cqe *) sol);
  1682. break;
  1683. case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
  1684. case CXN_KILLED_BURST_LEN_MISMATCH:
  1685. case CXN_KILLED_AHS_RCVD:
  1686. case CXN_KILLED_HDR_DIGEST_ERR:
  1687. case CXN_KILLED_UNKNOWN_HDR:
  1688. case CXN_KILLED_STALE_ITT_TTT_RCVD:
  1689. case CXN_KILLED_INVALID_ITT_TTT_RCVD:
  1690. case CXN_KILLED_TIMED_OUT:
  1691. case CXN_KILLED_FIN_RCVD:
  1692. case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
  1693. case CXN_KILLED_BAD_WRB_INDEX_ERROR:
  1694. case CXN_KILLED_OVER_RUN_RESIDUAL:
  1695. case CXN_KILLED_UNDER_RUN_RESIDUAL:
  1696. case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
  1697. SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
  1698. "0x%x...\n",
  1699. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1700. 32] & CQE_CODE_MASK,
  1701. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1702. 32] & CQE_CID_MASK));
  1703. iscsi_conn_failure(beiscsi_conn->conn,
  1704. ISCSI_ERR_CONN_FAILED);
  1705. break;
  1706. case CXN_KILLED_RST_SENT:
  1707. case CXN_KILLED_RST_RCVD:
  1708. SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
  1709. "received/sent on CID 0x%x...\n",
  1710. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1711. 32] & CQE_CODE_MASK,
  1712. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1713. 32] & CQE_CID_MASK));
  1714. iscsi_conn_failure(beiscsi_conn->conn,
  1715. ISCSI_ERR_CONN_FAILED);
  1716. break;
  1717. default:
  1718. SE_DEBUG(DBG_LVL_1, "CQ Error Invalid code= %d "
  1719. "received on CID 0x%x...\n",
  1720. sol->dw[offsetof(struct amap_sol_cqe, code) /
  1721. 32] & CQE_CODE_MASK,
  1722. (sol->dw[offsetof(struct amap_sol_cqe, cid) /
  1723. 32] & CQE_CID_MASK));
  1724. break;
  1725. }
  1726. AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
  1727. queue_tail_inc(cq);
  1728. sol = queue_tail_node(cq);
  1729. num_processed++;
  1730. }
  1731. if (num_processed > 0) {
  1732. tot_nump += num_processed;
  1733. hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
  1734. }
  1735. return tot_nump;
  1736. }
  1737. void beiscsi_process_all_cqs(struct work_struct *work)
  1738. {
  1739. unsigned long flags;
  1740. struct hwi_controller *phwi_ctrlr;
  1741. struct hwi_context_memory *phwi_context;
  1742. struct be_eq_obj *pbe_eq;
  1743. struct beiscsi_hba *phba =
  1744. container_of(work, struct beiscsi_hba, work_cqs);
  1745. phwi_ctrlr = phba->phwi_ctrlr;
  1746. phwi_context = phwi_ctrlr->phwi_ctxt;
  1747. if (phba->msix_enabled)
  1748. pbe_eq = &phwi_context->be_eq[phba->num_cpus];
  1749. else
  1750. pbe_eq = &phwi_context->be_eq[0];
  1751. if (phba->todo_mcc_cq) {
  1752. spin_lock_irqsave(&phba->isr_lock, flags);
  1753. phba->todo_mcc_cq = 0;
  1754. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1755. beiscsi_process_mcc_isr(phba);
  1756. }
  1757. if (phba->todo_cq) {
  1758. spin_lock_irqsave(&phba->isr_lock, flags);
  1759. phba->todo_cq = 0;
  1760. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1761. beiscsi_process_cq(pbe_eq);
  1762. }
  1763. }
  1764. static int be_iopoll(struct blk_iopoll *iop, int budget)
  1765. {
  1766. static unsigned int ret;
  1767. struct beiscsi_hba *phba;
  1768. struct be_eq_obj *pbe_eq;
  1769. pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
  1770. ret = beiscsi_process_cq(pbe_eq);
  1771. if (ret < budget) {
  1772. phba = pbe_eq->phba;
  1773. blk_iopoll_complete(iop);
  1774. SE_DEBUG(DBG_LVL_8, "rearm pbe_eq->q.id =%d\n", pbe_eq->q.id);
  1775. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  1776. }
  1777. return ret;
  1778. }
  1779. static void
  1780. hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  1781. unsigned int num_sg, struct beiscsi_io_task *io_task)
  1782. {
  1783. struct iscsi_sge *psgl;
  1784. unsigned int sg_len, index;
  1785. unsigned int sge_len = 0;
  1786. unsigned long long addr;
  1787. struct scatterlist *l_sg;
  1788. unsigned int offset;
  1789. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  1790. io_task->bhs_pa.u.a32.address_lo);
  1791. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  1792. io_task->bhs_pa.u.a32.address_hi);
  1793. l_sg = sg;
  1794. for (index = 0; (index < num_sg) && (index < 2); index++,
  1795. sg = sg_next(sg)) {
  1796. if (index == 0) {
  1797. sg_len = sg_dma_len(sg);
  1798. addr = (u64) sg_dma_address(sg);
  1799. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  1800. ((u32)(addr & 0xFFFFFFFF)));
  1801. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  1802. ((u32)(addr >> 32)));
  1803. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  1804. sg_len);
  1805. sge_len = sg_len;
  1806. } else {
  1807. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
  1808. pwrb, sge_len);
  1809. sg_len = sg_dma_len(sg);
  1810. addr = (u64) sg_dma_address(sg);
  1811. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
  1812. ((u32)(addr & 0xFFFFFFFF)));
  1813. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
  1814. ((u32)(addr >> 32)));
  1815. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
  1816. sg_len);
  1817. }
  1818. }
  1819. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  1820. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  1821. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  1822. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1823. io_task->bhs_pa.u.a32.address_hi);
  1824. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1825. io_task->bhs_pa.u.a32.address_lo);
  1826. if (num_sg == 1) {
  1827. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1828. 1);
  1829. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1830. 0);
  1831. } else if (num_sg == 2) {
  1832. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1833. 0);
  1834. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1835. 1);
  1836. } else {
  1837. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  1838. 0);
  1839. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  1840. 0);
  1841. }
  1842. sg = l_sg;
  1843. psgl++;
  1844. psgl++;
  1845. offset = 0;
  1846. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  1847. sg_len = sg_dma_len(sg);
  1848. addr = (u64) sg_dma_address(sg);
  1849. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1850. (addr & 0xFFFFFFFF));
  1851. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1852. (addr >> 32));
  1853. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  1854. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  1855. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  1856. offset += sg_len;
  1857. }
  1858. psgl--;
  1859. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  1860. }
  1861. static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
  1862. {
  1863. struct iscsi_sge *psgl;
  1864. unsigned long long addr;
  1865. struct beiscsi_io_task *io_task = task->dd_data;
  1866. struct beiscsi_conn *beiscsi_conn = io_task->conn;
  1867. struct beiscsi_hba *phba = beiscsi_conn->phba;
  1868. io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
  1869. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  1870. io_task->bhs_pa.u.a32.address_lo);
  1871. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  1872. io_task->bhs_pa.u.a32.address_hi);
  1873. if (task->data) {
  1874. if (task->data_count) {
  1875. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  1876. addr = (u64) pci_map_single(phba->pcidev,
  1877. task->data,
  1878. task->data_count, 1);
  1879. } else {
  1880. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  1881. addr = 0;
  1882. }
  1883. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  1884. ((u32)(addr & 0xFFFFFFFF)));
  1885. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  1886. ((u32)(addr >> 32)));
  1887. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  1888. task->data_count);
  1889. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
  1890. } else {
  1891. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  1892. addr = 0;
  1893. }
  1894. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  1895. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
  1896. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1897. io_task->bhs_pa.u.a32.address_hi);
  1898. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1899. io_task->bhs_pa.u.a32.address_lo);
  1900. if (task->data) {
  1901. psgl++;
  1902. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
  1903. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
  1904. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
  1905. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
  1906. AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
  1907. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  1908. psgl++;
  1909. if (task->data) {
  1910. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1911. ((u32)(addr & 0xFFFFFFFF)));
  1912. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1913. ((u32)(addr >> 32)));
  1914. }
  1915. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
  1916. }
  1917. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  1918. }
  1919. static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
  1920. {
  1921. unsigned int num_cq_pages, num_async_pdu_buf_pages;
  1922. unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
  1923. unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
  1924. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  1925. sizeof(struct sol_cqe));
  1926. num_async_pdu_buf_pages =
  1927. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1928. phba->params.defpdu_hdr_sz);
  1929. num_async_pdu_buf_sgl_pages =
  1930. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1931. sizeof(struct phys_addr));
  1932. num_async_pdu_data_pages =
  1933. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1934. phba->params.defpdu_data_sz);
  1935. num_async_pdu_data_sgl_pages =
  1936. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  1937. sizeof(struct phys_addr));
  1938. phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
  1939. phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
  1940. BE_ISCSI_PDU_HEADER_SIZE;
  1941. phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
  1942. sizeof(struct hwi_context_memory);
  1943. phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
  1944. * (phba->params.wrbs_per_cxn)
  1945. * phba->params.cxns_per_ctrl;
  1946. wrb_sz_per_cxn = sizeof(struct wrb_handle) *
  1947. (phba->params.wrbs_per_cxn);
  1948. phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
  1949. phba->params.cxns_per_ctrl);
  1950. phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
  1951. phba->params.icds_per_ctrl;
  1952. phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
  1953. phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
  1954. phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
  1955. num_async_pdu_buf_pages * PAGE_SIZE;
  1956. phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
  1957. num_async_pdu_data_pages * PAGE_SIZE;
  1958. phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
  1959. num_async_pdu_buf_sgl_pages * PAGE_SIZE;
  1960. phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
  1961. num_async_pdu_data_sgl_pages * PAGE_SIZE;
  1962. phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
  1963. phba->params.asyncpdus_per_ctrl *
  1964. sizeof(struct async_pdu_handle);
  1965. phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
  1966. phba->params.asyncpdus_per_ctrl *
  1967. sizeof(struct async_pdu_handle);
  1968. phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
  1969. sizeof(struct hwi_async_pdu_context) +
  1970. (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
  1971. }
  1972. static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
  1973. {
  1974. struct be_mem_descriptor *mem_descr;
  1975. dma_addr_t bus_add;
  1976. struct mem_array *mem_arr, *mem_arr_orig;
  1977. unsigned int i, j, alloc_size, curr_alloc_size;
  1978. phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
  1979. if (!phba->phwi_ctrlr)
  1980. return -ENOMEM;
  1981. phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
  1982. GFP_KERNEL);
  1983. if (!phba->init_mem) {
  1984. kfree(phba->phwi_ctrlr);
  1985. return -ENOMEM;
  1986. }
  1987. mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
  1988. GFP_KERNEL);
  1989. if (!mem_arr_orig) {
  1990. kfree(phba->init_mem);
  1991. kfree(phba->phwi_ctrlr);
  1992. return -ENOMEM;
  1993. }
  1994. mem_descr = phba->init_mem;
  1995. for (i = 0; i < SE_MEM_MAX; i++) {
  1996. j = 0;
  1997. mem_arr = mem_arr_orig;
  1998. alloc_size = phba->mem_req[i];
  1999. memset(mem_arr, 0, sizeof(struct mem_array) *
  2000. BEISCSI_MAX_FRAGS_INIT);
  2001. curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
  2002. do {
  2003. mem_arr->virtual_address = pci_alloc_consistent(
  2004. phba->pcidev,
  2005. curr_alloc_size,
  2006. &bus_add);
  2007. if (!mem_arr->virtual_address) {
  2008. if (curr_alloc_size <= BE_MIN_MEM_SIZE)
  2009. goto free_mem;
  2010. if (curr_alloc_size -
  2011. rounddown_pow_of_two(curr_alloc_size))
  2012. curr_alloc_size = rounddown_pow_of_two
  2013. (curr_alloc_size);
  2014. else
  2015. curr_alloc_size = curr_alloc_size / 2;
  2016. } else {
  2017. mem_arr->bus_address.u.
  2018. a64.address = (__u64) bus_add;
  2019. mem_arr->size = curr_alloc_size;
  2020. alloc_size -= curr_alloc_size;
  2021. curr_alloc_size = min(be_max_phys_size *
  2022. 1024, alloc_size);
  2023. j++;
  2024. mem_arr++;
  2025. }
  2026. } while (alloc_size);
  2027. mem_descr->num_elements = j;
  2028. mem_descr->size_in_bytes = phba->mem_req[i];
  2029. mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
  2030. GFP_KERNEL);
  2031. if (!mem_descr->mem_array)
  2032. goto free_mem;
  2033. memcpy(mem_descr->mem_array, mem_arr_orig,
  2034. sizeof(struct mem_array) * j);
  2035. mem_descr++;
  2036. }
  2037. kfree(mem_arr_orig);
  2038. return 0;
  2039. free_mem:
  2040. mem_descr->num_elements = j;
  2041. while ((i) || (j)) {
  2042. for (j = mem_descr->num_elements; j > 0; j--) {
  2043. pci_free_consistent(phba->pcidev,
  2044. mem_descr->mem_array[j - 1].size,
  2045. mem_descr->mem_array[j - 1].
  2046. virtual_address,
  2047. (unsigned long)mem_descr->
  2048. mem_array[j - 1].
  2049. bus_address.u.a64.address);
  2050. }
  2051. if (i) {
  2052. i--;
  2053. kfree(mem_descr->mem_array);
  2054. mem_descr--;
  2055. }
  2056. }
  2057. kfree(mem_arr_orig);
  2058. kfree(phba->init_mem);
  2059. kfree(phba->phwi_ctrlr);
  2060. return -ENOMEM;
  2061. }
  2062. static int beiscsi_get_memory(struct beiscsi_hba *phba)
  2063. {
  2064. beiscsi_find_mem_req(phba);
  2065. return beiscsi_alloc_mem(phba);
  2066. }
  2067. static void iscsi_init_global_templates(struct beiscsi_hba *phba)
  2068. {
  2069. struct pdu_data_out *pdata_out;
  2070. struct pdu_nop_out *pnop_out;
  2071. struct be_mem_descriptor *mem_descr;
  2072. mem_descr = phba->init_mem;
  2073. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  2074. pdata_out =
  2075. (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
  2076. memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2077. AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
  2078. IIOC_SCSI_DATA);
  2079. pnop_out =
  2080. (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
  2081. virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
  2082. memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2083. AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
  2084. AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
  2085. AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
  2086. }
  2087. static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
  2088. {
  2089. struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
  2090. struct wrb_handle *pwrb_handle = NULL;
  2091. struct hwi_controller *phwi_ctrlr;
  2092. struct hwi_wrb_context *pwrb_context;
  2093. struct iscsi_wrb *pwrb = NULL;
  2094. unsigned int num_cxn_wrbh = 0;
  2095. unsigned int num_cxn_wrb = 0, j, idx = 0, index;
  2096. mem_descr_wrbh = phba->init_mem;
  2097. mem_descr_wrbh += HWI_MEM_WRBH;
  2098. mem_descr_wrb = phba->init_mem;
  2099. mem_descr_wrb += HWI_MEM_WRB;
  2100. phwi_ctrlr = phba->phwi_ctrlr;
  2101. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2102. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2103. pwrb_context->pwrb_handle_base =
  2104. kzalloc(sizeof(struct wrb_handle *) *
  2105. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2106. if (!pwrb_context->pwrb_handle_base) {
  2107. shost_printk(KERN_ERR, phba->shost,
  2108. "Mem Alloc Failed. Failing to load\n");
  2109. goto init_wrb_hndl_failed;
  2110. }
  2111. pwrb_context->pwrb_handle_basestd =
  2112. kzalloc(sizeof(struct wrb_handle *) *
  2113. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2114. if (!pwrb_context->pwrb_handle_basestd) {
  2115. shost_printk(KERN_ERR, phba->shost,
  2116. "Mem Alloc Failed. Failing to load\n");
  2117. goto init_wrb_hndl_failed;
  2118. }
  2119. if (!num_cxn_wrbh) {
  2120. pwrb_handle =
  2121. mem_descr_wrbh->mem_array[idx].virtual_address;
  2122. num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
  2123. ((sizeof(struct wrb_handle)) *
  2124. phba->params.wrbs_per_cxn));
  2125. idx++;
  2126. }
  2127. pwrb_context->alloc_index = 0;
  2128. pwrb_context->wrb_handles_available = 0;
  2129. pwrb_context->free_index = 0;
  2130. if (num_cxn_wrbh) {
  2131. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2132. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  2133. pwrb_context->pwrb_handle_basestd[j] =
  2134. pwrb_handle;
  2135. pwrb_context->wrb_handles_available++;
  2136. pwrb_handle->wrb_index = j;
  2137. pwrb_handle++;
  2138. }
  2139. num_cxn_wrbh--;
  2140. }
  2141. }
  2142. idx = 0;
  2143. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2144. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2145. if (!num_cxn_wrb) {
  2146. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  2147. num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
  2148. ((sizeof(struct iscsi_wrb) *
  2149. phba->params.wrbs_per_cxn));
  2150. idx++;
  2151. }
  2152. if (num_cxn_wrb) {
  2153. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2154. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  2155. pwrb_handle->pwrb = pwrb;
  2156. pwrb++;
  2157. }
  2158. num_cxn_wrb--;
  2159. }
  2160. }
  2161. return 0;
  2162. init_wrb_hndl_failed:
  2163. for (j = index; j > 0; j--) {
  2164. pwrb_context = &phwi_ctrlr->wrb_context[j];
  2165. kfree(pwrb_context->pwrb_handle_base);
  2166. kfree(pwrb_context->pwrb_handle_basestd);
  2167. }
  2168. return -ENOMEM;
  2169. }
  2170. static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
  2171. {
  2172. struct hwi_controller *phwi_ctrlr;
  2173. struct hba_parameters *p = &phba->params;
  2174. struct hwi_async_pdu_context *pasync_ctx;
  2175. struct async_pdu_handle *pasync_header_h, *pasync_data_h;
  2176. unsigned int index, idx, num_per_mem, num_async_data;
  2177. struct be_mem_descriptor *mem_descr;
  2178. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2179. mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
  2180. phwi_ctrlr = phba->phwi_ctrlr;
  2181. phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
  2182. mem_descr->mem_array[0].virtual_address;
  2183. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
  2184. memset(pasync_ctx, 0, sizeof(*pasync_ctx));
  2185. pasync_ctx->num_entries = p->asyncpdus_per_ctrl;
  2186. pasync_ctx->buffer_size = p->defpdu_hdr_sz;
  2187. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2188. mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
  2189. if (mem_descr->mem_array[0].virtual_address) {
  2190. SE_DEBUG(DBG_LVL_8,
  2191. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_BUF"
  2192. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2193. } else
  2194. shost_printk(KERN_WARNING, phba->shost,
  2195. "No Virtual address\n");
  2196. pasync_ctx->async_header.va_base =
  2197. mem_descr->mem_array[0].virtual_address;
  2198. pasync_ctx->async_header.pa_base.u.a64.address =
  2199. mem_descr->mem_array[0].bus_address.u.a64.address;
  2200. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2201. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2202. if (mem_descr->mem_array[0].virtual_address) {
  2203. SE_DEBUG(DBG_LVL_8,
  2204. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_RING"
  2205. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2206. } else
  2207. shost_printk(KERN_WARNING, phba->shost,
  2208. "No Virtual address\n");
  2209. pasync_ctx->async_header.ring_base =
  2210. mem_descr->mem_array[0].virtual_address;
  2211. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2212. mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
  2213. if (mem_descr->mem_array[0].virtual_address) {
  2214. SE_DEBUG(DBG_LVL_8,
  2215. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_HANDLE"
  2216. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2217. } else
  2218. shost_printk(KERN_WARNING, phba->shost,
  2219. "No Virtual address\n");
  2220. pasync_ctx->async_header.handle_base =
  2221. mem_descr->mem_array[0].virtual_address;
  2222. pasync_ctx->async_header.writables = 0;
  2223. INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
  2224. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2225. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2226. if (mem_descr->mem_array[0].virtual_address) {
  2227. SE_DEBUG(DBG_LVL_8,
  2228. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_RING"
  2229. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2230. } else
  2231. shost_printk(KERN_WARNING, phba->shost,
  2232. "No Virtual address\n");
  2233. pasync_ctx->async_data.ring_base =
  2234. mem_descr->mem_array[0].virtual_address;
  2235. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2236. mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
  2237. if (!mem_descr->mem_array[0].virtual_address)
  2238. shost_printk(KERN_WARNING, phba->shost,
  2239. "No Virtual address\n");
  2240. pasync_ctx->async_data.handle_base =
  2241. mem_descr->mem_array[0].virtual_address;
  2242. pasync_ctx->async_data.writables = 0;
  2243. INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
  2244. pasync_header_h =
  2245. (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
  2246. pasync_data_h =
  2247. (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
  2248. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2249. mem_descr += HWI_MEM_ASYNC_DATA_BUF;
  2250. if (mem_descr->mem_array[0].virtual_address) {
  2251. SE_DEBUG(DBG_LVL_8,
  2252. "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_BUF"
  2253. "va=%p\n", mem_descr->mem_array[0].virtual_address);
  2254. } else
  2255. shost_printk(KERN_WARNING, phba->shost,
  2256. "No Virtual address\n");
  2257. idx = 0;
  2258. pasync_ctx->async_data.va_base =
  2259. mem_descr->mem_array[idx].virtual_address;
  2260. pasync_ctx->async_data.pa_base.u.a64.address =
  2261. mem_descr->mem_array[idx].bus_address.u.a64.address;
  2262. num_async_data = ((mem_descr->mem_array[idx].size) /
  2263. phba->params.defpdu_data_sz);
  2264. num_per_mem = 0;
  2265. for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
  2266. pasync_header_h->cri = -1;
  2267. pasync_header_h->index = (char)index;
  2268. INIT_LIST_HEAD(&pasync_header_h->link);
  2269. pasync_header_h->pbuffer =
  2270. (void *)((unsigned long)
  2271. (pasync_ctx->async_header.va_base) +
  2272. (p->defpdu_hdr_sz * index));
  2273. pasync_header_h->pa.u.a64.address =
  2274. pasync_ctx->async_header.pa_base.u.a64.address +
  2275. (p->defpdu_hdr_sz * index);
  2276. list_add_tail(&pasync_header_h->link,
  2277. &pasync_ctx->async_header.free_list);
  2278. pasync_header_h++;
  2279. pasync_ctx->async_header.free_entries++;
  2280. pasync_ctx->async_header.writables++;
  2281. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
  2282. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  2283. header_busy_list);
  2284. pasync_data_h->cri = -1;
  2285. pasync_data_h->index = (char)index;
  2286. INIT_LIST_HEAD(&pasync_data_h->link);
  2287. if (!num_async_data) {
  2288. num_per_mem = 0;
  2289. idx++;
  2290. pasync_ctx->async_data.va_base =
  2291. mem_descr->mem_array[idx].virtual_address;
  2292. pasync_ctx->async_data.pa_base.u.a64.address =
  2293. mem_descr->mem_array[idx].
  2294. bus_address.u.a64.address;
  2295. num_async_data = ((mem_descr->mem_array[idx].size) /
  2296. phba->params.defpdu_data_sz);
  2297. }
  2298. pasync_data_h->pbuffer =
  2299. (void *)((unsigned long)
  2300. (pasync_ctx->async_data.va_base) +
  2301. (p->defpdu_data_sz * num_per_mem));
  2302. pasync_data_h->pa.u.a64.address =
  2303. pasync_ctx->async_data.pa_base.u.a64.address +
  2304. (p->defpdu_data_sz * num_per_mem);
  2305. num_per_mem++;
  2306. num_async_data--;
  2307. list_add_tail(&pasync_data_h->link,
  2308. &pasync_ctx->async_data.free_list);
  2309. pasync_data_h++;
  2310. pasync_ctx->async_data.free_entries++;
  2311. pasync_ctx->async_data.writables++;
  2312. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
  2313. }
  2314. pasync_ctx->async_header.host_write_ptr = 0;
  2315. pasync_ctx->async_header.ep_read_ptr = -1;
  2316. pasync_ctx->async_data.host_write_ptr = 0;
  2317. pasync_ctx->async_data.ep_read_ptr = -1;
  2318. }
  2319. static int
  2320. be_sgl_create_contiguous(void *virtual_address,
  2321. u64 physical_address, u32 length,
  2322. struct be_dma_mem *sgl)
  2323. {
  2324. WARN_ON(!virtual_address);
  2325. WARN_ON(!physical_address);
  2326. WARN_ON(!length > 0);
  2327. WARN_ON(!sgl);
  2328. sgl->va = virtual_address;
  2329. sgl->dma = (unsigned long)physical_address;
  2330. sgl->size = length;
  2331. return 0;
  2332. }
  2333. static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
  2334. {
  2335. memset(sgl, 0, sizeof(*sgl));
  2336. }
  2337. static void
  2338. hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
  2339. struct mem_array *pmem, struct be_dma_mem *sgl)
  2340. {
  2341. if (sgl->va)
  2342. be_sgl_destroy_contiguous(sgl);
  2343. be_sgl_create_contiguous(pmem->virtual_address,
  2344. pmem->bus_address.u.a64.address,
  2345. pmem->size, sgl);
  2346. }
  2347. static void
  2348. hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
  2349. struct mem_array *pmem, struct be_dma_mem *sgl)
  2350. {
  2351. if (sgl->va)
  2352. be_sgl_destroy_contiguous(sgl);
  2353. be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
  2354. pmem->bus_address.u.a64.address,
  2355. pmem->size, sgl);
  2356. }
  2357. static int be_fill_queue(struct be_queue_info *q,
  2358. u16 len, u16 entry_size, void *vaddress)
  2359. {
  2360. struct be_dma_mem *mem = &q->dma_mem;
  2361. memset(q, 0, sizeof(*q));
  2362. q->len = len;
  2363. q->entry_size = entry_size;
  2364. mem->size = len * entry_size;
  2365. mem->va = vaddress;
  2366. if (!mem->va)
  2367. return -ENOMEM;
  2368. memset(mem->va, 0, mem->size);
  2369. return 0;
  2370. }
  2371. static int beiscsi_create_eqs(struct beiscsi_hba *phba,
  2372. struct hwi_context_memory *phwi_context)
  2373. {
  2374. unsigned int i, num_eq_pages;
  2375. int ret, eq_for_mcc;
  2376. struct be_queue_info *eq;
  2377. struct be_dma_mem *mem;
  2378. void *eq_vaddress;
  2379. dma_addr_t paddr;
  2380. num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
  2381. sizeof(struct be_eq_entry));
  2382. if (phba->msix_enabled)
  2383. eq_for_mcc = 1;
  2384. else
  2385. eq_for_mcc = 0;
  2386. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2387. eq = &phwi_context->be_eq[i].q;
  2388. mem = &eq->dma_mem;
  2389. phwi_context->be_eq[i].phba = phba;
  2390. eq_vaddress = pci_alloc_consistent(phba->pcidev,
  2391. num_eq_pages * PAGE_SIZE,
  2392. &paddr);
  2393. if (!eq_vaddress)
  2394. goto create_eq_error;
  2395. mem->va = eq_vaddress;
  2396. ret = be_fill_queue(eq, phba->params.num_eq_entries,
  2397. sizeof(struct be_eq_entry), eq_vaddress);
  2398. if (ret) {
  2399. shost_printk(KERN_ERR, phba->shost,
  2400. "be_fill_queue Failed for EQ\n");
  2401. goto create_eq_error;
  2402. }
  2403. mem->dma = paddr;
  2404. ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
  2405. phwi_context->cur_eqd);
  2406. if (ret) {
  2407. shost_printk(KERN_ERR, phba->shost,
  2408. "beiscsi_cmd_eq_create"
  2409. "Failedfor EQ\n");
  2410. goto create_eq_error;
  2411. }
  2412. SE_DEBUG(DBG_LVL_8, "eqid = %d\n", phwi_context->be_eq[i].q.id);
  2413. }
  2414. return 0;
  2415. create_eq_error:
  2416. for (i = 0; i < (phba->num_cpus + 1); i++) {
  2417. eq = &phwi_context->be_eq[i].q;
  2418. mem = &eq->dma_mem;
  2419. if (mem->va)
  2420. pci_free_consistent(phba->pcidev, num_eq_pages
  2421. * PAGE_SIZE,
  2422. mem->va, mem->dma);
  2423. }
  2424. return ret;
  2425. }
  2426. static int beiscsi_create_cqs(struct beiscsi_hba *phba,
  2427. struct hwi_context_memory *phwi_context)
  2428. {
  2429. unsigned int i, num_cq_pages;
  2430. int ret;
  2431. struct be_queue_info *cq, *eq;
  2432. struct be_dma_mem *mem;
  2433. struct be_eq_obj *pbe_eq;
  2434. void *cq_vaddress;
  2435. dma_addr_t paddr;
  2436. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2437. sizeof(struct sol_cqe));
  2438. for (i = 0; i < phba->num_cpus; i++) {
  2439. cq = &phwi_context->be_cq[i];
  2440. eq = &phwi_context->be_eq[i].q;
  2441. pbe_eq = &phwi_context->be_eq[i];
  2442. pbe_eq->cq = cq;
  2443. pbe_eq->phba = phba;
  2444. mem = &cq->dma_mem;
  2445. cq_vaddress = pci_alloc_consistent(phba->pcidev,
  2446. num_cq_pages * PAGE_SIZE,
  2447. &paddr);
  2448. if (!cq_vaddress)
  2449. goto create_cq_error;
  2450. ret = be_fill_queue(cq, phba->params.num_cq_entries,
  2451. sizeof(struct sol_cqe), cq_vaddress);
  2452. if (ret) {
  2453. shost_printk(KERN_ERR, phba->shost,
  2454. "be_fill_queue Failed for ISCSI CQ\n");
  2455. goto create_cq_error;
  2456. }
  2457. mem->dma = paddr;
  2458. ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
  2459. false, 0);
  2460. if (ret) {
  2461. shost_printk(KERN_ERR, phba->shost,
  2462. "beiscsi_cmd_eq_create"
  2463. "Failed for ISCSI CQ\n");
  2464. goto create_cq_error;
  2465. }
  2466. SE_DEBUG(DBG_LVL_8, "iscsi cq_id is %d for eq_id %d\n",
  2467. cq->id, eq->id);
  2468. SE_DEBUG(DBG_LVL_8, "ISCSI CQ CREATED\n");
  2469. }
  2470. return 0;
  2471. create_cq_error:
  2472. for (i = 0; i < phba->num_cpus; i++) {
  2473. cq = &phwi_context->be_cq[i];
  2474. mem = &cq->dma_mem;
  2475. if (mem->va)
  2476. pci_free_consistent(phba->pcidev, num_cq_pages
  2477. * PAGE_SIZE,
  2478. mem->va, mem->dma);
  2479. }
  2480. return ret;
  2481. }
  2482. static int
  2483. beiscsi_create_def_hdr(struct beiscsi_hba *phba,
  2484. struct hwi_context_memory *phwi_context,
  2485. struct hwi_controller *phwi_ctrlr,
  2486. unsigned int def_pdu_ring_sz)
  2487. {
  2488. unsigned int idx;
  2489. int ret;
  2490. struct be_queue_info *dq, *cq;
  2491. struct be_dma_mem *mem;
  2492. struct be_mem_descriptor *mem_descr;
  2493. void *dq_vaddress;
  2494. idx = 0;
  2495. dq = &phwi_context->be_def_hdrq;
  2496. cq = &phwi_context->be_cq[0];
  2497. mem = &dq->dma_mem;
  2498. mem_descr = phba->init_mem;
  2499. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2500. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2501. ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
  2502. sizeof(struct phys_addr),
  2503. sizeof(struct phys_addr), dq_vaddress);
  2504. if (ret) {
  2505. shost_printk(KERN_ERR, phba->shost,
  2506. "be_fill_queue Failed for DEF PDU HDR\n");
  2507. return ret;
  2508. }
  2509. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2510. bus_address.u.a64.address;
  2511. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
  2512. def_pdu_ring_sz,
  2513. phba->params.defpdu_hdr_sz);
  2514. if (ret) {
  2515. shost_printk(KERN_ERR, phba->shost,
  2516. "be_cmd_create_default_pdu_queue Failed DEFHDR\n");
  2517. return ret;
  2518. }
  2519. phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
  2520. SE_DEBUG(DBG_LVL_8, "iscsi def pdu id is %d\n",
  2521. phwi_context->be_def_hdrq.id);
  2522. hwi_post_async_buffers(phba, 1);
  2523. return 0;
  2524. }
  2525. static int
  2526. beiscsi_create_def_data(struct beiscsi_hba *phba,
  2527. struct hwi_context_memory *phwi_context,
  2528. struct hwi_controller *phwi_ctrlr,
  2529. unsigned int def_pdu_ring_sz)
  2530. {
  2531. unsigned int idx;
  2532. int ret;
  2533. struct be_queue_info *dataq, *cq;
  2534. struct be_dma_mem *mem;
  2535. struct be_mem_descriptor *mem_descr;
  2536. void *dq_vaddress;
  2537. idx = 0;
  2538. dataq = &phwi_context->be_def_dataq;
  2539. cq = &phwi_context->be_cq[0];
  2540. mem = &dataq->dma_mem;
  2541. mem_descr = phba->init_mem;
  2542. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2543. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2544. ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
  2545. sizeof(struct phys_addr),
  2546. sizeof(struct phys_addr), dq_vaddress);
  2547. if (ret) {
  2548. shost_printk(KERN_ERR, phba->shost,
  2549. "be_fill_queue Failed for DEF PDU DATA\n");
  2550. return ret;
  2551. }
  2552. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2553. bus_address.u.a64.address;
  2554. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
  2555. def_pdu_ring_sz,
  2556. phba->params.defpdu_data_sz);
  2557. if (ret) {
  2558. shost_printk(KERN_ERR, phba->shost,
  2559. "be_cmd_create_default_pdu_queue Failed"
  2560. " for DEF PDU DATA\n");
  2561. return ret;
  2562. }
  2563. phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
  2564. SE_DEBUG(DBG_LVL_8, "iscsi def data id is %d\n",
  2565. phwi_context->be_def_dataq.id);
  2566. hwi_post_async_buffers(phba, 0);
  2567. SE_DEBUG(DBG_LVL_8, "DEFAULT PDU DATA RING CREATED\n");
  2568. return 0;
  2569. }
  2570. static int
  2571. beiscsi_post_pages(struct beiscsi_hba *phba)
  2572. {
  2573. struct be_mem_descriptor *mem_descr;
  2574. struct mem_array *pm_arr;
  2575. unsigned int page_offset, i;
  2576. struct be_dma_mem sgl;
  2577. int status;
  2578. mem_descr = phba->init_mem;
  2579. mem_descr += HWI_MEM_SGE;
  2580. pm_arr = mem_descr->mem_array;
  2581. page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
  2582. phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
  2583. for (i = 0; i < mem_descr->num_elements; i++) {
  2584. hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
  2585. status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
  2586. page_offset,
  2587. (pm_arr->size / PAGE_SIZE));
  2588. page_offset += pm_arr->size / PAGE_SIZE;
  2589. if (status != 0) {
  2590. shost_printk(KERN_ERR, phba->shost,
  2591. "post sgl failed.\n");
  2592. return status;
  2593. }
  2594. pm_arr++;
  2595. }
  2596. SE_DEBUG(DBG_LVL_8, "POSTED PAGES\n");
  2597. return 0;
  2598. }
  2599. static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
  2600. {
  2601. struct be_dma_mem *mem = &q->dma_mem;
  2602. if (mem->va) {
  2603. pci_free_consistent(phba->pcidev, mem->size,
  2604. mem->va, mem->dma);
  2605. mem->va = NULL;
  2606. }
  2607. }
  2608. static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
  2609. u16 len, u16 entry_size)
  2610. {
  2611. struct be_dma_mem *mem = &q->dma_mem;
  2612. memset(q, 0, sizeof(*q));
  2613. q->len = len;
  2614. q->entry_size = entry_size;
  2615. mem->size = len * entry_size;
  2616. mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
  2617. if (!mem->va)
  2618. return -ENOMEM;
  2619. memset(mem->va, 0, mem->size);
  2620. return 0;
  2621. }
  2622. static int
  2623. beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
  2624. struct hwi_context_memory *phwi_context,
  2625. struct hwi_controller *phwi_ctrlr)
  2626. {
  2627. unsigned int wrb_mem_index, offset, size, num_wrb_rings;
  2628. u64 pa_addr_lo;
  2629. unsigned int idx, num, i;
  2630. struct mem_array *pwrb_arr;
  2631. void *wrb_vaddr;
  2632. struct be_dma_mem sgl;
  2633. struct be_mem_descriptor *mem_descr;
  2634. int status;
  2635. idx = 0;
  2636. mem_descr = phba->init_mem;
  2637. mem_descr += HWI_MEM_WRB;
  2638. pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
  2639. GFP_KERNEL);
  2640. if (!pwrb_arr) {
  2641. shost_printk(KERN_ERR, phba->shost,
  2642. "Memory alloc failed in create wrb ring.\n");
  2643. return -ENOMEM;
  2644. }
  2645. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2646. pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
  2647. num_wrb_rings = mem_descr->mem_array[idx].size /
  2648. (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
  2649. for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
  2650. if (num_wrb_rings) {
  2651. pwrb_arr[num].virtual_address = wrb_vaddr;
  2652. pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
  2653. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2654. sizeof(struct iscsi_wrb);
  2655. wrb_vaddr += pwrb_arr[num].size;
  2656. pa_addr_lo += pwrb_arr[num].size;
  2657. num_wrb_rings--;
  2658. } else {
  2659. idx++;
  2660. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2661. pa_addr_lo = mem_descr->mem_array[idx].\
  2662. bus_address.u.a64.address;
  2663. num_wrb_rings = mem_descr->mem_array[idx].size /
  2664. (phba->params.wrbs_per_cxn *
  2665. sizeof(struct iscsi_wrb));
  2666. pwrb_arr[num].virtual_address = wrb_vaddr;
  2667. pwrb_arr[num].bus_address.u.a64.address\
  2668. = pa_addr_lo;
  2669. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2670. sizeof(struct iscsi_wrb);
  2671. wrb_vaddr += pwrb_arr[num].size;
  2672. pa_addr_lo += pwrb_arr[num].size;
  2673. num_wrb_rings--;
  2674. }
  2675. }
  2676. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2677. wrb_mem_index = 0;
  2678. offset = 0;
  2679. size = 0;
  2680. hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
  2681. status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
  2682. &phwi_context->be_wrbq[i]);
  2683. if (status != 0) {
  2684. shost_printk(KERN_ERR, phba->shost,
  2685. "wrbq create failed.");
  2686. kfree(pwrb_arr);
  2687. return status;
  2688. }
  2689. phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
  2690. id;
  2691. }
  2692. kfree(pwrb_arr);
  2693. return 0;
  2694. }
  2695. static void free_wrb_handles(struct beiscsi_hba *phba)
  2696. {
  2697. unsigned int index;
  2698. struct hwi_controller *phwi_ctrlr;
  2699. struct hwi_wrb_context *pwrb_context;
  2700. phwi_ctrlr = phba->phwi_ctrlr;
  2701. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2702. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2703. kfree(pwrb_context->pwrb_handle_base);
  2704. kfree(pwrb_context->pwrb_handle_basestd);
  2705. }
  2706. }
  2707. static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
  2708. {
  2709. struct be_queue_info *q;
  2710. struct be_ctrl_info *ctrl = &phba->ctrl;
  2711. q = &phba->ctrl.mcc_obj.q;
  2712. if (q->created)
  2713. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
  2714. be_queue_free(phba, q);
  2715. q = &phba->ctrl.mcc_obj.cq;
  2716. if (q->created)
  2717. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  2718. be_queue_free(phba, q);
  2719. }
  2720. static void hwi_cleanup(struct beiscsi_hba *phba)
  2721. {
  2722. struct be_queue_info *q;
  2723. struct be_ctrl_info *ctrl = &phba->ctrl;
  2724. struct hwi_controller *phwi_ctrlr;
  2725. struct hwi_context_memory *phwi_context;
  2726. int i, eq_num;
  2727. phwi_ctrlr = phba->phwi_ctrlr;
  2728. phwi_context = phwi_ctrlr->phwi_ctxt;
  2729. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2730. q = &phwi_context->be_wrbq[i];
  2731. if (q->created)
  2732. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
  2733. }
  2734. free_wrb_handles(phba);
  2735. q = &phwi_context->be_def_hdrq;
  2736. if (q->created)
  2737. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  2738. q = &phwi_context->be_def_dataq;
  2739. if (q->created)
  2740. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  2741. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  2742. for (i = 0; i < (phba->num_cpus); i++) {
  2743. q = &phwi_context->be_cq[i];
  2744. if (q->created)
  2745. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  2746. }
  2747. if (phba->msix_enabled)
  2748. eq_num = 1;
  2749. else
  2750. eq_num = 0;
  2751. for (i = 0; i < (phba->num_cpus + eq_num); i++) {
  2752. q = &phwi_context->be_eq[i].q;
  2753. if (q->created)
  2754. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
  2755. }
  2756. be_mcc_queues_destroy(phba);
  2757. }
  2758. static int be_mcc_queues_create(struct beiscsi_hba *phba,
  2759. struct hwi_context_memory *phwi_context)
  2760. {
  2761. struct be_queue_info *q, *cq;
  2762. struct be_ctrl_info *ctrl = &phba->ctrl;
  2763. /* Alloc MCC compl queue */
  2764. cq = &phba->ctrl.mcc_obj.cq;
  2765. if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
  2766. sizeof(struct be_mcc_compl)))
  2767. goto err;
  2768. /* Ask BE to create MCC compl queue; */
  2769. if (phba->msix_enabled) {
  2770. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
  2771. [phba->num_cpus].q, false, true, 0))
  2772. goto mcc_cq_free;
  2773. } else {
  2774. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
  2775. false, true, 0))
  2776. goto mcc_cq_free;
  2777. }
  2778. /* Alloc MCC queue */
  2779. q = &phba->ctrl.mcc_obj.q;
  2780. if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
  2781. goto mcc_cq_destroy;
  2782. /* Ask BE to create MCC queue */
  2783. if (beiscsi_cmd_mccq_create(phba, q, cq))
  2784. goto mcc_q_free;
  2785. return 0;
  2786. mcc_q_free:
  2787. be_queue_free(phba, q);
  2788. mcc_cq_destroy:
  2789. beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
  2790. mcc_cq_free:
  2791. be_queue_free(phba, cq);
  2792. err:
  2793. return -ENOMEM;
  2794. }
  2795. static int find_num_cpus(void)
  2796. {
  2797. int num_cpus = 0;
  2798. num_cpus = num_online_cpus();
  2799. if (num_cpus >= MAX_CPUS)
  2800. num_cpus = MAX_CPUS - 1;
  2801. SE_DEBUG(DBG_LVL_8, "num_cpus = %d\n", num_cpus);
  2802. return num_cpus;
  2803. }
  2804. static int hwi_init_port(struct beiscsi_hba *phba)
  2805. {
  2806. struct hwi_controller *phwi_ctrlr;
  2807. struct hwi_context_memory *phwi_context;
  2808. unsigned int def_pdu_ring_sz;
  2809. struct be_ctrl_info *ctrl = &phba->ctrl;
  2810. int status;
  2811. def_pdu_ring_sz =
  2812. phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
  2813. phwi_ctrlr = phba->phwi_ctrlr;
  2814. phwi_context = phwi_ctrlr->phwi_ctxt;
  2815. phwi_context->max_eqd = 0;
  2816. phwi_context->min_eqd = 0;
  2817. phwi_context->cur_eqd = 64;
  2818. be_cmd_fw_initialize(&phba->ctrl);
  2819. status = beiscsi_create_eqs(phba, phwi_context);
  2820. if (status != 0) {
  2821. shost_printk(KERN_ERR, phba->shost, "EQ not created\n");
  2822. goto error;
  2823. }
  2824. status = be_mcc_queues_create(phba, phwi_context);
  2825. if (status != 0)
  2826. goto error;
  2827. status = mgmt_check_supported_fw(ctrl, phba);
  2828. if (status != 0) {
  2829. shost_printk(KERN_ERR, phba->shost,
  2830. "Unsupported fw version\n");
  2831. goto error;
  2832. }
  2833. status = beiscsi_create_cqs(phba, phwi_context);
  2834. if (status != 0) {
  2835. shost_printk(KERN_ERR, phba->shost, "CQ not created\n");
  2836. goto error;
  2837. }
  2838. status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
  2839. def_pdu_ring_sz);
  2840. if (status != 0) {
  2841. shost_printk(KERN_ERR, phba->shost,
  2842. "Default Header not created\n");
  2843. goto error;
  2844. }
  2845. status = beiscsi_create_def_data(phba, phwi_context,
  2846. phwi_ctrlr, def_pdu_ring_sz);
  2847. if (status != 0) {
  2848. shost_printk(KERN_ERR, phba->shost,
  2849. "Default Data not created\n");
  2850. goto error;
  2851. }
  2852. status = beiscsi_post_pages(phba);
  2853. if (status != 0) {
  2854. shost_printk(KERN_ERR, phba->shost, "Post SGL Pages Failed\n");
  2855. goto error;
  2856. }
  2857. status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
  2858. if (status != 0) {
  2859. shost_printk(KERN_ERR, phba->shost,
  2860. "WRB Rings not created\n");
  2861. goto error;
  2862. }
  2863. SE_DEBUG(DBG_LVL_8, "hwi_init_port success\n");
  2864. return 0;
  2865. error:
  2866. shost_printk(KERN_ERR, phba->shost, "hwi_init_port failed");
  2867. hwi_cleanup(phba);
  2868. return status;
  2869. }
  2870. static int hwi_init_controller(struct beiscsi_hba *phba)
  2871. {
  2872. struct hwi_controller *phwi_ctrlr;
  2873. phwi_ctrlr = phba->phwi_ctrlr;
  2874. if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
  2875. phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
  2876. init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
  2877. SE_DEBUG(DBG_LVL_8, " phwi_ctrlr->phwi_ctxt=%p\n",
  2878. phwi_ctrlr->phwi_ctxt);
  2879. } else {
  2880. shost_printk(KERN_ERR, phba->shost,
  2881. "HWI_MEM_ADDN_CONTEXT is more than one element."
  2882. "Failing to load\n");
  2883. return -ENOMEM;
  2884. }
  2885. iscsi_init_global_templates(phba);
  2886. if (beiscsi_init_wrb_handle(phba))
  2887. return -ENOMEM;
  2888. hwi_init_async_pdu_ctx(phba);
  2889. if (hwi_init_port(phba) != 0) {
  2890. shost_printk(KERN_ERR, phba->shost,
  2891. "hwi_init_controller failed\n");
  2892. return -ENOMEM;
  2893. }
  2894. return 0;
  2895. }
  2896. static void beiscsi_free_mem(struct beiscsi_hba *phba)
  2897. {
  2898. struct be_mem_descriptor *mem_descr;
  2899. int i, j;
  2900. mem_descr = phba->init_mem;
  2901. i = 0;
  2902. j = 0;
  2903. for (i = 0; i < SE_MEM_MAX; i++) {
  2904. for (j = mem_descr->num_elements; j > 0; j--) {
  2905. pci_free_consistent(phba->pcidev,
  2906. mem_descr->mem_array[j - 1].size,
  2907. mem_descr->mem_array[j - 1].virtual_address,
  2908. (unsigned long)mem_descr->mem_array[j - 1].
  2909. bus_address.u.a64.address);
  2910. }
  2911. kfree(mem_descr->mem_array);
  2912. mem_descr++;
  2913. }
  2914. kfree(phba->init_mem);
  2915. kfree(phba->phwi_ctrlr);
  2916. }
  2917. static int beiscsi_init_controller(struct beiscsi_hba *phba)
  2918. {
  2919. int ret = -ENOMEM;
  2920. ret = beiscsi_get_memory(phba);
  2921. if (ret < 0) {
  2922. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe -"
  2923. "Failed in beiscsi_alloc_memory\n");
  2924. return ret;
  2925. }
  2926. ret = hwi_init_controller(phba);
  2927. if (ret)
  2928. goto free_init;
  2929. SE_DEBUG(DBG_LVL_8, "Return success from beiscsi_init_controller");
  2930. return 0;
  2931. free_init:
  2932. beiscsi_free_mem(phba);
  2933. return ret;
  2934. }
  2935. static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
  2936. {
  2937. struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
  2938. struct sgl_handle *psgl_handle;
  2939. struct iscsi_sge *pfrag;
  2940. unsigned int arr_index, i, idx;
  2941. phba->io_sgl_hndl_avbl = 0;
  2942. phba->eh_sgl_hndl_avbl = 0;
  2943. mem_descr_sglh = phba->init_mem;
  2944. mem_descr_sglh += HWI_MEM_SGLH;
  2945. if (1 == mem_descr_sglh->num_elements) {
  2946. phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  2947. phba->params.ios_per_ctrl,
  2948. GFP_KERNEL);
  2949. if (!phba->io_sgl_hndl_base) {
  2950. shost_printk(KERN_ERR, phba->shost,
  2951. "Mem Alloc Failed. Failing to load\n");
  2952. return -ENOMEM;
  2953. }
  2954. phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  2955. (phba->params.icds_per_ctrl -
  2956. phba->params.ios_per_ctrl),
  2957. GFP_KERNEL);
  2958. if (!phba->eh_sgl_hndl_base) {
  2959. kfree(phba->io_sgl_hndl_base);
  2960. shost_printk(KERN_ERR, phba->shost,
  2961. "Mem Alloc Failed. Failing to load\n");
  2962. return -ENOMEM;
  2963. }
  2964. } else {
  2965. shost_printk(KERN_ERR, phba->shost,
  2966. "HWI_MEM_SGLH is more than one element."
  2967. "Failing to load\n");
  2968. return -ENOMEM;
  2969. }
  2970. arr_index = 0;
  2971. idx = 0;
  2972. while (idx < mem_descr_sglh->num_elements) {
  2973. psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
  2974. for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
  2975. sizeof(struct sgl_handle)); i++) {
  2976. if (arr_index < phba->params.ios_per_ctrl) {
  2977. phba->io_sgl_hndl_base[arr_index] = psgl_handle;
  2978. phba->io_sgl_hndl_avbl++;
  2979. arr_index++;
  2980. } else {
  2981. phba->eh_sgl_hndl_base[arr_index -
  2982. phba->params.ios_per_ctrl] =
  2983. psgl_handle;
  2984. arr_index++;
  2985. phba->eh_sgl_hndl_avbl++;
  2986. }
  2987. psgl_handle++;
  2988. }
  2989. idx++;
  2990. }
  2991. SE_DEBUG(DBG_LVL_8,
  2992. "phba->io_sgl_hndl_avbl=%d"
  2993. "phba->eh_sgl_hndl_avbl=%d\n",
  2994. phba->io_sgl_hndl_avbl,
  2995. phba->eh_sgl_hndl_avbl);
  2996. mem_descr_sg = phba->init_mem;
  2997. mem_descr_sg += HWI_MEM_SGE;
  2998. SE_DEBUG(DBG_LVL_8, "\n mem_descr_sg->num_elements=%d\n",
  2999. mem_descr_sg->num_elements);
  3000. arr_index = 0;
  3001. idx = 0;
  3002. while (idx < mem_descr_sg->num_elements) {
  3003. pfrag = mem_descr_sg->mem_array[idx].virtual_address;
  3004. for (i = 0;
  3005. i < (mem_descr_sg->mem_array[idx].size) /
  3006. (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
  3007. i++) {
  3008. if (arr_index < phba->params.ios_per_ctrl)
  3009. psgl_handle = phba->io_sgl_hndl_base[arr_index];
  3010. else
  3011. psgl_handle = phba->eh_sgl_hndl_base[arr_index -
  3012. phba->params.ios_per_ctrl];
  3013. psgl_handle->pfrag = pfrag;
  3014. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
  3015. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
  3016. pfrag += phba->params.num_sge_per_io;
  3017. psgl_handle->sgl_index =
  3018. phba->fw_config.iscsi_icd_start + arr_index++;
  3019. }
  3020. idx++;
  3021. }
  3022. phba->io_sgl_free_index = 0;
  3023. phba->io_sgl_alloc_index = 0;
  3024. phba->eh_sgl_free_index = 0;
  3025. phba->eh_sgl_alloc_index = 0;
  3026. return 0;
  3027. }
  3028. static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
  3029. {
  3030. int i, new_cid;
  3031. phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
  3032. GFP_KERNEL);
  3033. if (!phba->cid_array) {
  3034. shost_printk(KERN_ERR, phba->shost,
  3035. "Failed to allocate memory in "
  3036. "hba_setup_cid_tbls\n");
  3037. return -ENOMEM;
  3038. }
  3039. phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
  3040. phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
  3041. if (!phba->ep_array) {
  3042. shost_printk(KERN_ERR, phba->shost,
  3043. "Failed to allocate memory in "
  3044. "hba_setup_cid_tbls\n");
  3045. kfree(phba->cid_array);
  3046. return -ENOMEM;
  3047. }
  3048. new_cid = phba->fw_config.iscsi_cid_start;
  3049. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3050. phba->cid_array[i] = new_cid;
  3051. new_cid += 2;
  3052. }
  3053. phba->avlbl_cids = phba->params.cxns_per_ctrl;
  3054. return 0;
  3055. }
  3056. static void hwi_enable_intr(struct beiscsi_hba *phba)
  3057. {
  3058. struct be_ctrl_info *ctrl = &phba->ctrl;
  3059. struct hwi_controller *phwi_ctrlr;
  3060. struct hwi_context_memory *phwi_context;
  3061. struct be_queue_info *eq;
  3062. u8 __iomem *addr;
  3063. u32 reg, i;
  3064. u32 enabled;
  3065. phwi_ctrlr = phba->phwi_ctrlr;
  3066. phwi_context = phwi_ctrlr->phwi_ctxt;
  3067. addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
  3068. PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
  3069. reg = ioread32(addr);
  3070. enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3071. if (!enabled) {
  3072. reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3073. SE_DEBUG(DBG_LVL_8, "reg =x%08x addr=%p\n", reg, addr);
  3074. iowrite32(reg, addr);
  3075. }
  3076. if (!phba->msix_enabled) {
  3077. eq = &phwi_context->be_eq[0].q;
  3078. SE_DEBUG(DBG_LVL_8, "eq->id=%d\n", eq->id);
  3079. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3080. } else {
  3081. for (i = 0; i <= phba->num_cpus; i++) {
  3082. eq = &phwi_context->be_eq[i].q;
  3083. SE_DEBUG(DBG_LVL_8, "eq->id=%d\n", eq->id);
  3084. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3085. }
  3086. }
  3087. }
  3088. static void hwi_disable_intr(struct beiscsi_hba *phba)
  3089. {
  3090. struct be_ctrl_info *ctrl = &phba->ctrl;
  3091. u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
  3092. u32 reg = ioread32(addr);
  3093. u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3094. if (enabled) {
  3095. reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3096. iowrite32(reg, addr);
  3097. } else
  3098. shost_printk(KERN_WARNING, phba->shost,
  3099. "In hwi_disable_intr, Already Disabled\n");
  3100. }
  3101. /**
  3102. * beiscsi_get_boot_info()- Get the boot session info
  3103. * @phba: The device priv structure instance
  3104. *
  3105. * Get the boot target info and store in driver priv structure
  3106. *
  3107. * return values
  3108. * Success: 0
  3109. * Failure: Non-Zero Value
  3110. **/
  3111. static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
  3112. {
  3113. struct be_cmd_get_session_resp *session_resp;
  3114. struct be_mcc_wrb *wrb;
  3115. struct be_dma_mem nonemb_cmd;
  3116. unsigned int tag, wrb_num;
  3117. unsigned short status, extd_status;
  3118. unsigned int s_handle;
  3119. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  3120. int ret = -ENOMEM;
  3121. /* Get the session handle of the boot target */
  3122. ret = be_mgmt_get_boot_shandle(phba, &s_handle);
  3123. if (ret) {
  3124. SE_DEBUG(DBG_LVL_1, "No boot session\n");
  3125. return ret;
  3126. }
  3127. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  3128. sizeof(*session_resp),
  3129. &nonemb_cmd.dma);
  3130. if (nonemb_cmd.va == NULL) {
  3131. SE_DEBUG(DBG_LVL_1,
  3132. "Failed to allocate memory for"
  3133. "beiscsi_get_session_info\n");
  3134. return -ENOMEM;
  3135. }
  3136. memset(nonemb_cmd.va, 0, sizeof(*session_resp));
  3137. tag = mgmt_get_session_info(phba, s_handle,
  3138. &nonemb_cmd);
  3139. if (!tag) {
  3140. SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info"
  3141. " Failed\n");
  3142. goto boot_freemem;
  3143. } else
  3144. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  3145. phba->ctrl.mcc_numtag[tag]);
  3146. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  3147. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  3148. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  3149. if (status || extd_status) {
  3150. SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info Failed"
  3151. " status = %d extd_status = %d\n",
  3152. status, extd_status);
  3153. free_mcc_tag(&phba->ctrl, tag);
  3154. goto boot_freemem;
  3155. }
  3156. wrb = queue_get_wrb(mccq, wrb_num);
  3157. free_mcc_tag(&phba->ctrl, tag);
  3158. session_resp = nonemb_cmd.va ;
  3159. memcpy(&phba->boot_sess, &session_resp->session_info,
  3160. sizeof(struct mgmt_session_info));
  3161. ret = 0;
  3162. boot_freemem:
  3163. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  3164. nonemb_cmd.va, nonemb_cmd.dma);
  3165. return ret;
  3166. }
  3167. static void beiscsi_boot_release(void *data)
  3168. {
  3169. struct beiscsi_hba *phba = data;
  3170. scsi_host_put(phba->shost);
  3171. }
  3172. static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
  3173. {
  3174. struct iscsi_boot_kobj *boot_kobj;
  3175. /* get boot info using mgmt cmd */
  3176. if (beiscsi_get_boot_info(phba))
  3177. /* Try to see if we can carry on without this */
  3178. return 0;
  3179. phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
  3180. if (!phba->boot_kset)
  3181. return -ENOMEM;
  3182. /* get a ref because the show function will ref the phba */
  3183. if (!scsi_host_get(phba->shost))
  3184. goto free_kset;
  3185. boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
  3186. beiscsi_show_boot_tgt_info,
  3187. beiscsi_tgt_get_attr_visibility,
  3188. beiscsi_boot_release);
  3189. if (!boot_kobj)
  3190. goto put_shost;
  3191. if (!scsi_host_get(phba->shost))
  3192. goto free_kset;
  3193. boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
  3194. beiscsi_show_boot_ini_info,
  3195. beiscsi_ini_get_attr_visibility,
  3196. beiscsi_boot_release);
  3197. if (!boot_kobj)
  3198. goto put_shost;
  3199. if (!scsi_host_get(phba->shost))
  3200. goto free_kset;
  3201. boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
  3202. beiscsi_show_boot_eth_info,
  3203. beiscsi_eth_get_attr_visibility,
  3204. beiscsi_boot_release);
  3205. if (!boot_kobj)
  3206. goto put_shost;
  3207. return 0;
  3208. put_shost:
  3209. scsi_host_put(phba->shost);
  3210. free_kset:
  3211. iscsi_boot_destroy_kset(phba->boot_kset);
  3212. return -ENOMEM;
  3213. }
  3214. static int beiscsi_init_port(struct beiscsi_hba *phba)
  3215. {
  3216. int ret;
  3217. ret = beiscsi_init_controller(phba);
  3218. if (ret < 0) {
  3219. shost_printk(KERN_ERR, phba->shost,
  3220. "beiscsi_dev_probe - Failed in"
  3221. "beiscsi_init_controller\n");
  3222. return ret;
  3223. }
  3224. ret = beiscsi_init_sgl_handle(phba);
  3225. if (ret < 0) {
  3226. shost_printk(KERN_ERR, phba->shost,
  3227. "beiscsi_dev_probe - Failed in"
  3228. "beiscsi_init_sgl_handle\n");
  3229. goto do_cleanup_ctrlr;
  3230. }
  3231. if (hba_setup_cid_tbls(phba)) {
  3232. shost_printk(KERN_ERR, phba->shost,
  3233. "Failed in hba_setup_cid_tbls\n");
  3234. kfree(phba->io_sgl_hndl_base);
  3235. kfree(phba->eh_sgl_hndl_base);
  3236. goto do_cleanup_ctrlr;
  3237. }
  3238. return ret;
  3239. do_cleanup_ctrlr:
  3240. hwi_cleanup(phba);
  3241. return ret;
  3242. }
  3243. static void hwi_purge_eq(struct beiscsi_hba *phba)
  3244. {
  3245. struct hwi_controller *phwi_ctrlr;
  3246. struct hwi_context_memory *phwi_context;
  3247. struct be_queue_info *eq;
  3248. struct be_eq_entry *eqe = NULL;
  3249. int i, eq_msix;
  3250. unsigned int num_processed;
  3251. phwi_ctrlr = phba->phwi_ctrlr;
  3252. phwi_context = phwi_ctrlr->phwi_ctxt;
  3253. if (phba->msix_enabled)
  3254. eq_msix = 1;
  3255. else
  3256. eq_msix = 0;
  3257. for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
  3258. eq = &phwi_context->be_eq[i].q;
  3259. eqe = queue_tail_node(eq);
  3260. num_processed = 0;
  3261. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  3262. & EQE_VALID_MASK) {
  3263. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  3264. queue_tail_inc(eq);
  3265. eqe = queue_tail_node(eq);
  3266. num_processed++;
  3267. }
  3268. if (num_processed)
  3269. hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
  3270. }
  3271. }
  3272. static void beiscsi_clean_port(struct beiscsi_hba *phba)
  3273. {
  3274. int mgmt_status;
  3275. mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
  3276. if (mgmt_status)
  3277. shost_printk(KERN_WARNING, phba->shost,
  3278. "mgmt_epfw_cleanup FAILED\n");
  3279. hwi_purge_eq(phba);
  3280. hwi_cleanup(phba);
  3281. kfree(phba->io_sgl_hndl_base);
  3282. kfree(phba->eh_sgl_hndl_base);
  3283. kfree(phba->cid_array);
  3284. kfree(phba->ep_array);
  3285. }
  3286. static void beiscsi_cleanup_task(struct iscsi_task *task)
  3287. {
  3288. struct beiscsi_io_task *io_task = task->dd_data;
  3289. struct iscsi_conn *conn = task->conn;
  3290. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3291. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3292. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3293. struct hwi_wrb_context *pwrb_context;
  3294. struct hwi_controller *phwi_ctrlr;
  3295. phwi_ctrlr = phba->phwi_ctrlr;
  3296. pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
  3297. - phba->fw_config.iscsi_cid_start];
  3298. if (io_task->cmd_bhs) {
  3299. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3300. io_task->bhs_pa.u.a64.address);
  3301. io_task->cmd_bhs = NULL;
  3302. }
  3303. if (task->sc) {
  3304. if (io_task->pwrb_handle) {
  3305. free_wrb_handle(phba, pwrb_context,
  3306. io_task->pwrb_handle);
  3307. io_task->pwrb_handle = NULL;
  3308. }
  3309. if (io_task->psgl_handle) {
  3310. spin_lock(&phba->io_sgl_lock);
  3311. free_io_sgl_handle(phba, io_task->psgl_handle);
  3312. spin_unlock(&phba->io_sgl_lock);
  3313. io_task->psgl_handle = NULL;
  3314. }
  3315. } else {
  3316. if (!beiscsi_conn->login_in_progress) {
  3317. if (io_task->pwrb_handle) {
  3318. free_wrb_handle(phba, pwrb_context,
  3319. io_task->pwrb_handle);
  3320. io_task->pwrb_handle = NULL;
  3321. }
  3322. if (io_task->psgl_handle) {
  3323. spin_lock(&phba->mgmt_sgl_lock);
  3324. free_mgmt_sgl_handle(phba,
  3325. io_task->psgl_handle);
  3326. spin_unlock(&phba->mgmt_sgl_lock);
  3327. io_task->psgl_handle = NULL;
  3328. }
  3329. }
  3330. }
  3331. }
  3332. void
  3333. beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
  3334. struct beiscsi_offload_params *params)
  3335. {
  3336. struct wrb_handle *pwrb_handle;
  3337. struct iscsi_target_context_update_wrb *pwrb = NULL;
  3338. struct be_mem_descriptor *mem_descr;
  3339. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3340. struct iscsi_task *task = beiscsi_conn->task;
  3341. struct iscsi_session *session = task->conn->session;
  3342. u32 doorbell = 0;
  3343. /*
  3344. * We can always use 0 here because it is reserved by libiscsi for
  3345. * login/startup related tasks.
  3346. */
  3347. beiscsi_conn->login_in_progress = 0;
  3348. spin_lock_bh(&session->lock);
  3349. beiscsi_cleanup_task(task);
  3350. spin_unlock_bh(&session->lock);
  3351. pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
  3352. phba->fw_config.iscsi_cid_start));
  3353. pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb;
  3354. memset(pwrb, 0, sizeof(*pwrb));
  3355. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3356. max_burst_length, pwrb, params->dw[offsetof
  3357. (struct amap_beiscsi_offload_params,
  3358. max_burst_length) / 32]);
  3359. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3360. max_send_data_segment_length, pwrb,
  3361. params->dw[offsetof(struct amap_beiscsi_offload_params,
  3362. max_send_data_segment_length) / 32]);
  3363. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3364. first_burst_length,
  3365. pwrb,
  3366. params->dw[offsetof(struct amap_beiscsi_offload_params,
  3367. first_burst_length) / 32]);
  3368. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
  3369. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3370. erl) / 32] & OFFLD_PARAMS_ERL));
  3371. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
  3372. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3373. dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
  3374. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
  3375. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3376. hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
  3377. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
  3378. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3379. ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
  3380. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
  3381. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3382. imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
  3383. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
  3384. pwrb,
  3385. (params->dw[offsetof(struct amap_beiscsi_offload_params,
  3386. exp_statsn) / 32] + 1));
  3387. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
  3388. 0x7);
  3389. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
  3390. pwrb, pwrb_handle->wrb_index);
  3391. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
  3392. pwrb, pwrb_handle->nxt_wrb_index);
  3393. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3394. session_state, pwrb, 0);
  3395. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
  3396. pwrb, 1);
  3397. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
  3398. pwrb, 0);
  3399. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
  3400. 0);
  3401. mem_descr = phba->init_mem;
  3402. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  3403. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3404. pad_buffer_addr_hi, pwrb,
  3405. mem_descr->mem_array[0].bus_address.u.a32.address_hi);
  3406. AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
  3407. pad_buffer_addr_lo, pwrb,
  3408. mem_descr->mem_array[0].bus_address.u.a32.address_lo);
  3409. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
  3410. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3411. doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
  3412. << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3413. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3414. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3415. }
  3416. static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
  3417. int *index, int *age)
  3418. {
  3419. *index = (int)itt;
  3420. if (age)
  3421. *age = conn->session->age;
  3422. }
  3423. /**
  3424. * beiscsi_alloc_pdu - allocates pdu and related resources
  3425. * @task: libiscsi task
  3426. * @opcode: opcode of pdu for task
  3427. *
  3428. * This is called with the session lock held. It will allocate
  3429. * the wrb and sgl if needed for the command. And it will prep
  3430. * the pdu's itt. beiscsi_parse_pdu will later translate
  3431. * the pdu itt to the libiscsi task itt.
  3432. */
  3433. static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  3434. {
  3435. struct beiscsi_io_task *io_task = task->dd_data;
  3436. struct iscsi_conn *conn = task->conn;
  3437. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3438. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3439. struct hwi_wrb_context *pwrb_context;
  3440. struct hwi_controller *phwi_ctrlr;
  3441. itt_t itt;
  3442. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3443. dma_addr_t paddr;
  3444. io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
  3445. GFP_ATOMIC, &paddr);
  3446. if (!io_task->cmd_bhs)
  3447. return -ENOMEM;
  3448. io_task->bhs_pa.u.a64.address = paddr;
  3449. io_task->libiscsi_itt = (itt_t)task->itt;
  3450. io_task->conn = beiscsi_conn;
  3451. task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
  3452. task->hdr_max = sizeof(struct be_cmd_bhs);
  3453. io_task->psgl_handle = NULL;
  3454. io_task->pwrb_handle = NULL;
  3455. if (task->sc) {
  3456. spin_lock(&phba->io_sgl_lock);
  3457. io_task->psgl_handle = alloc_io_sgl_handle(phba);
  3458. spin_unlock(&phba->io_sgl_lock);
  3459. if (!io_task->psgl_handle)
  3460. goto free_hndls;
  3461. io_task->pwrb_handle = alloc_wrb_handle(phba,
  3462. beiscsi_conn->beiscsi_conn_cid -
  3463. phba->fw_config.iscsi_cid_start);
  3464. if (!io_task->pwrb_handle)
  3465. goto free_io_hndls;
  3466. } else {
  3467. io_task->scsi_cmnd = NULL;
  3468. if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
  3469. if (!beiscsi_conn->login_in_progress) {
  3470. spin_lock(&phba->mgmt_sgl_lock);
  3471. io_task->psgl_handle = (struct sgl_handle *)
  3472. alloc_mgmt_sgl_handle(phba);
  3473. spin_unlock(&phba->mgmt_sgl_lock);
  3474. if (!io_task->psgl_handle)
  3475. goto free_hndls;
  3476. beiscsi_conn->login_in_progress = 1;
  3477. beiscsi_conn->plogin_sgl_handle =
  3478. io_task->psgl_handle;
  3479. io_task->pwrb_handle =
  3480. alloc_wrb_handle(phba,
  3481. beiscsi_conn->beiscsi_conn_cid -
  3482. phba->fw_config.iscsi_cid_start);
  3483. if (!io_task->pwrb_handle)
  3484. goto free_io_hndls;
  3485. beiscsi_conn->plogin_wrb_handle =
  3486. io_task->pwrb_handle;
  3487. } else {
  3488. io_task->psgl_handle =
  3489. beiscsi_conn->plogin_sgl_handle;
  3490. io_task->pwrb_handle =
  3491. beiscsi_conn->plogin_wrb_handle;
  3492. }
  3493. beiscsi_conn->task = task;
  3494. } else {
  3495. spin_lock(&phba->mgmt_sgl_lock);
  3496. io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
  3497. spin_unlock(&phba->mgmt_sgl_lock);
  3498. if (!io_task->psgl_handle)
  3499. goto free_hndls;
  3500. io_task->pwrb_handle =
  3501. alloc_wrb_handle(phba,
  3502. beiscsi_conn->beiscsi_conn_cid -
  3503. phba->fw_config.iscsi_cid_start);
  3504. if (!io_task->pwrb_handle)
  3505. goto free_mgmt_hndls;
  3506. }
  3507. }
  3508. itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
  3509. wrb_index << 16) | (unsigned int)
  3510. (io_task->psgl_handle->sgl_index));
  3511. io_task->pwrb_handle->pio_handle = task;
  3512. io_task->cmd_bhs->iscsi_hdr.itt = itt;
  3513. return 0;
  3514. free_io_hndls:
  3515. spin_lock(&phba->io_sgl_lock);
  3516. free_io_sgl_handle(phba, io_task->psgl_handle);
  3517. spin_unlock(&phba->io_sgl_lock);
  3518. goto free_hndls;
  3519. free_mgmt_hndls:
  3520. spin_lock(&phba->mgmt_sgl_lock);
  3521. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  3522. spin_unlock(&phba->mgmt_sgl_lock);
  3523. free_hndls:
  3524. phwi_ctrlr = phba->phwi_ctrlr;
  3525. pwrb_context = &phwi_ctrlr->wrb_context[
  3526. beiscsi_conn->beiscsi_conn_cid -
  3527. phba->fw_config.iscsi_cid_start];
  3528. if (io_task->pwrb_handle)
  3529. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  3530. io_task->pwrb_handle = NULL;
  3531. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3532. io_task->bhs_pa.u.a64.address);
  3533. io_task->cmd_bhs = NULL;
  3534. SE_DEBUG(DBG_LVL_1, "Alloc of SGL_ICD Failed\n");
  3535. return -ENOMEM;
  3536. }
  3537. static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
  3538. unsigned int num_sg, unsigned int xferlen,
  3539. unsigned int writedir)
  3540. {
  3541. struct beiscsi_io_task *io_task = task->dd_data;
  3542. struct iscsi_conn *conn = task->conn;
  3543. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3544. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3545. struct iscsi_wrb *pwrb = NULL;
  3546. unsigned int doorbell = 0;
  3547. pwrb = io_task->pwrb_handle->pwrb;
  3548. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  3549. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  3550. if (writedir) {
  3551. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3552. INI_WR_CMD);
  3553. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  3554. } else {
  3555. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3556. INI_RD_CMD);
  3557. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  3558. }
  3559. AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
  3560. cpu_to_be16(*(unsigned short *)
  3561. &io_task->cmd_bhs->iscsi_hdr.lun));
  3562. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
  3563. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3564. io_task->pwrb_handle->wrb_index);
  3565. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3566. be32_to_cpu(task->cmdsn));
  3567. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3568. io_task->psgl_handle->sgl_index);
  3569. hwi_write_sgl(pwrb, sg, num_sg, io_task);
  3570. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3571. io_task->pwrb_handle->nxt_wrb_index);
  3572. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3573. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3574. doorbell |= (io_task->pwrb_handle->wrb_index &
  3575. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3576. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3577. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3578. return 0;
  3579. }
  3580. static int beiscsi_mtask(struct iscsi_task *task)
  3581. {
  3582. struct beiscsi_io_task *io_task = task->dd_data;
  3583. struct iscsi_conn *conn = task->conn;
  3584. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3585. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3586. struct iscsi_wrb *pwrb = NULL;
  3587. unsigned int doorbell = 0;
  3588. unsigned int cid;
  3589. cid = beiscsi_conn->beiscsi_conn_cid;
  3590. pwrb = io_task->pwrb_handle->pwrb;
  3591. memset(pwrb, 0, sizeof(*pwrb));
  3592. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3593. be32_to_cpu(task->cmdsn));
  3594. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3595. io_task->pwrb_handle->wrb_index);
  3596. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3597. io_task->psgl_handle->sgl_index);
  3598. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  3599. case ISCSI_OP_LOGIN:
  3600. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3601. TGT_DM_CMD);
  3602. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3603. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
  3604. hwi_write_buffer(pwrb, task);
  3605. break;
  3606. case ISCSI_OP_NOOP_OUT:
  3607. if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
  3608. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3609. TGT_DM_CMD);
  3610. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt,
  3611. pwrb, 0);
  3612. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
  3613. } else {
  3614. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3615. INI_RD_CMD);
  3616. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3617. }
  3618. hwi_write_buffer(pwrb, task);
  3619. break;
  3620. case ISCSI_OP_TEXT:
  3621. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3622. TGT_DM_CMD);
  3623. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3624. hwi_write_buffer(pwrb, task);
  3625. break;
  3626. case ISCSI_OP_SCSI_TMFUNC:
  3627. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3628. INI_TMF_CMD);
  3629. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3630. hwi_write_buffer(pwrb, task);
  3631. break;
  3632. case ISCSI_OP_LOGOUT:
  3633. AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
  3634. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3635. HWH_TYPE_LOGOUT);
  3636. hwi_write_buffer(pwrb, task);
  3637. break;
  3638. default:
  3639. SE_DEBUG(DBG_LVL_1, "opcode =%d Not supported\n",
  3640. task->hdr->opcode & ISCSI_OPCODE_MASK);
  3641. return -EINVAL;
  3642. }
  3643. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
  3644. task->data_count);
  3645. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3646. io_task->pwrb_handle->nxt_wrb_index);
  3647. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3648. doorbell |= cid & DB_WRB_POST_CID_MASK;
  3649. doorbell |= (io_task->pwrb_handle->wrb_index &
  3650. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3651. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3652. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3653. return 0;
  3654. }
  3655. static int beiscsi_task_xmit(struct iscsi_task *task)
  3656. {
  3657. struct beiscsi_io_task *io_task = task->dd_data;
  3658. struct scsi_cmnd *sc = task->sc;
  3659. struct scatterlist *sg;
  3660. int num_sg;
  3661. unsigned int writedir = 0, xferlen = 0;
  3662. if (!sc)
  3663. return beiscsi_mtask(task);
  3664. io_task->scsi_cmnd = sc;
  3665. num_sg = scsi_dma_map(sc);
  3666. if (num_sg < 0) {
  3667. SE_DEBUG(DBG_LVL_1, " scsi_dma_map Failed\n")
  3668. return num_sg;
  3669. }
  3670. xferlen = scsi_bufflen(sc);
  3671. sg = scsi_sglist(sc);
  3672. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  3673. writedir = 1;
  3674. SE_DEBUG(DBG_LVL_4, "task->imm_count=0x%08x\n",
  3675. task->imm_count);
  3676. } else
  3677. writedir = 0;
  3678. return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
  3679. }
  3680. /**
  3681. * beiscsi_bsg_request - handle bsg request from ISCSI transport
  3682. * @job: job to handle
  3683. */
  3684. static int beiscsi_bsg_request(struct bsg_job *job)
  3685. {
  3686. struct Scsi_Host *shost;
  3687. struct beiscsi_hba *phba;
  3688. struct iscsi_bsg_request *bsg_req = job->request;
  3689. int rc = -EINVAL;
  3690. unsigned int tag;
  3691. struct be_dma_mem nonemb_cmd;
  3692. struct be_cmd_resp_hdr *resp;
  3693. struct iscsi_bsg_reply *bsg_reply = job->reply;
  3694. unsigned short status, extd_status;
  3695. shost = iscsi_job_to_shost(job);
  3696. phba = iscsi_host_priv(shost);
  3697. switch (bsg_req->msgcode) {
  3698. case ISCSI_BSG_HST_VENDOR:
  3699. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  3700. job->request_payload.payload_len,
  3701. &nonemb_cmd.dma);
  3702. if (nonemb_cmd.va == NULL) {
  3703. SE_DEBUG(DBG_LVL_1, "Failed to allocate memory for "
  3704. "beiscsi_bsg_request\n");
  3705. return -EIO;
  3706. }
  3707. tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
  3708. &nonemb_cmd);
  3709. if (!tag) {
  3710. SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n");
  3711. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  3712. nonemb_cmd.va, nonemb_cmd.dma);
  3713. return -EAGAIN;
  3714. } else
  3715. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  3716. phba->ctrl.mcc_numtag[tag]);
  3717. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  3718. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  3719. free_mcc_tag(&phba->ctrl, tag);
  3720. resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
  3721. sg_copy_from_buffer(job->reply_payload.sg_list,
  3722. job->reply_payload.sg_cnt,
  3723. nonemb_cmd.va, (resp->response_length
  3724. + sizeof(*resp)));
  3725. bsg_reply->reply_payload_rcv_len = resp->response_length;
  3726. bsg_reply->result = status;
  3727. bsg_job_done(job, bsg_reply->result,
  3728. bsg_reply->reply_payload_rcv_len);
  3729. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  3730. nonemb_cmd.va, nonemb_cmd.dma);
  3731. if (status || extd_status) {
  3732. SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed"
  3733. " status = %d extd_status = %d\n",
  3734. status, extd_status);
  3735. return -EIO;
  3736. }
  3737. break;
  3738. default:
  3739. SE_DEBUG(DBG_LVL_1, "Unsupported bsg command: 0x%x\n",
  3740. bsg_req->msgcode);
  3741. break;
  3742. }
  3743. return rc;
  3744. }
  3745. static void beiscsi_quiesce(struct beiscsi_hba *phba)
  3746. {
  3747. struct hwi_controller *phwi_ctrlr;
  3748. struct hwi_context_memory *phwi_context;
  3749. struct be_eq_obj *pbe_eq;
  3750. unsigned int i, msix_vec;
  3751. u8 *real_offset = 0;
  3752. u32 value = 0;
  3753. phwi_ctrlr = phba->phwi_ctrlr;
  3754. phwi_context = phwi_ctrlr->phwi_ctxt;
  3755. hwi_disable_intr(phba);
  3756. if (phba->msix_enabled) {
  3757. for (i = 0; i <= phba->num_cpus; i++) {
  3758. msix_vec = phba->msix_entries[i].vector;
  3759. free_irq(msix_vec, &phwi_context->be_eq[i]);
  3760. kfree(phba->msi_name[i]);
  3761. }
  3762. } else
  3763. if (phba->pcidev->irq)
  3764. free_irq(phba->pcidev->irq, phba);
  3765. pci_disable_msix(phba->pcidev);
  3766. destroy_workqueue(phba->wq);
  3767. if (blk_iopoll_enabled)
  3768. for (i = 0; i < phba->num_cpus; i++) {
  3769. pbe_eq = &phwi_context->be_eq[i];
  3770. blk_iopoll_disable(&pbe_eq->iopoll);
  3771. }
  3772. beiscsi_clean_port(phba);
  3773. beiscsi_free_mem(phba);
  3774. real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  3775. value = readl((void *)real_offset);
  3776. if (value & 0x00010000) {
  3777. value &= 0xfffeffff;
  3778. writel(value, (void *)real_offset);
  3779. }
  3780. beiscsi_unmap_pci_function(phba);
  3781. pci_free_consistent(phba->pcidev,
  3782. phba->ctrl.mbox_mem_alloced.size,
  3783. phba->ctrl.mbox_mem_alloced.va,
  3784. phba->ctrl.mbox_mem_alloced.dma);
  3785. }
  3786. static void beiscsi_remove(struct pci_dev *pcidev)
  3787. {
  3788. struct beiscsi_hba *phba = NULL;
  3789. phba = pci_get_drvdata(pcidev);
  3790. if (!phba) {
  3791. dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
  3792. return;
  3793. }
  3794. beiscsi_destroy_def_ifaces(phba);
  3795. beiscsi_quiesce(phba);
  3796. iscsi_boot_destroy_kset(phba->boot_kset);
  3797. iscsi_host_remove(phba->shost);
  3798. pci_dev_put(phba->pcidev);
  3799. iscsi_host_free(phba->shost);
  3800. pci_disable_device(pcidev);
  3801. }
  3802. static void beiscsi_shutdown(struct pci_dev *pcidev)
  3803. {
  3804. struct beiscsi_hba *phba = NULL;
  3805. phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
  3806. if (!phba) {
  3807. dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
  3808. return;
  3809. }
  3810. beiscsi_quiesce(phba);
  3811. pci_disable_device(pcidev);
  3812. }
  3813. static void beiscsi_msix_enable(struct beiscsi_hba *phba)
  3814. {
  3815. int i, status;
  3816. for (i = 0; i <= phba->num_cpus; i++)
  3817. phba->msix_entries[i].entry = i;
  3818. status = pci_enable_msix(phba->pcidev, phba->msix_entries,
  3819. (phba->num_cpus + 1));
  3820. if (!status)
  3821. phba->msix_enabled = true;
  3822. return;
  3823. }
  3824. static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
  3825. const struct pci_device_id *id)
  3826. {
  3827. struct beiscsi_hba *phba = NULL;
  3828. struct hwi_controller *phwi_ctrlr;
  3829. struct hwi_context_memory *phwi_context;
  3830. struct be_eq_obj *pbe_eq;
  3831. int ret, num_cpus, i;
  3832. u8 *real_offset = 0;
  3833. u32 value = 0;
  3834. ret = beiscsi_enable_pci(pcidev);
  3835. if (ret < 0) {
  3836. dev_err(&pcidev->dev, "beiscsi_dev_probe-"
  3837. " Failed to enable pci device\n");
  3838. return ret;
  3839. }
  3840. phba = beiscsi_hba_alloc(pcidev);
  3841. if (!phba) {
  3842. dev_err(&pcidev->dev, "beiscsi_dev_probe-"
  3843. " Failed in beiscsi_hba_alloc\n");
  3844. goto disable_pci;
  3845. }
  3846. switch (pcidev->device) {
  3847. case BE_DEVICE_ID1:
  3848. case OC_DEVICE_ID1:
  3849. case OC_DEVICE_ID2:
  3850. phba->generation = BE_GEN2;
  3851. break;
  3852. case BE_DEVICE_ID2:
  3853. case OC_DEVICE_ID3:
  3854. phba->generation = BE_GEN3;
  3855. break;
  3856. default:
  3857. phba->generation = 0;
  3858. }
  3859. if (enable_msix)
  3860. num_cpus = find_num_cpus();
  3861. else
  3862. num_cpus = 1;
  3863. phba->num_cpus = num_cpus;
  3864. SE_DEBUG(DBG_LVL_8, "num_cpus = %d\n", phba->num_cpus);
  3865. if (enable_msix) {
  3866. beiscsi_msix_enable(phba);
  3867. if (!phba->msix_enabled)
  3868. phba->num_cpus = 1;
  3869. }
  3870. ret = be_ctrl_init(phba, pcidev);
  3871. if (ret) {
  3872. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3873. "Failed in be_ctrl_init\n");
  3874. goto hba_free;
  3875. }
  3876. if (!num_hba) {
  3877. real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  3878. value = readl((void *)real_offset);
  3879. if (value & 0x00010000) {
  3880. gcrashmode++;
  3881. shost_printk(KERN_ERR, phba->shost,
  3882. "Loading Driver in crashdump mode\n");
  3883. ret = beiscsi_cmd_reset_function(phba);
  3884. if (ret) {
  3885. shost_printk(KERN_ERR, phba->shost,
  3886. "Reset Failed. Aborting Crashdump\n");
  3887. goto hba_free;
  3888. }
  3889. ret = be_chk_reset_complete(phba);
  3890. if (ret) {
  3891. shost_printk(KERN_ERR, phba->shost,
  3892. "Failed to get out of reset."
  3893. "Aborting Crashdump\n");
  3894. goto hba_free;
  3895. }
  3896. } else {
  3897. value |= 0x00010000;
  3898. writel(value, (void *)real_offset);
  3899. num_hba++;
  3900. }
  3901. }
  3902. spin_lock_init(&phba->io_sgl_lock);
  3903. spin_lock_init(&phba->mgmt_sgl_lock);
  3904. spin_lock_init(&phba->isr_lock);
  3905. ret = mgmt_get_fw_config(&phba->ctrl, phba);
  3906. if (ret != 0) {
  3907. shost_printk(KERN_ERR, phba->shost,
  3908. "Error getting fw config\n");
  3909. goto free_port;
  3910. }
  3911. phba->shost->max_id = phba->fw_config.iscsi_cid_count;
  3912. beiscsi_get_params(phba);
  3913. phba->shost->can_queue = phba->params.ios_per_ctrl;
  3914. ret = beiscsi_init_port(phba);
  3915. if (ret < 0) {
  3916. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3917. "Failed in beiscsi_init_port\n");
  3918. goto free_port;
  3919. }
  3920. for (i = 0; i < MAX_MCC_CMD ; i++) {
  3921. init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
  3922. phba->ctrl.mcc_tag[i] = i + 1;
  3923. phba->ctrl.mcc_numtag[i + 1] = 0;
  3924. phba->ctrl.mcc_tag_available++;
  3925. }
  3926. phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
  3927. snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_q_irq%u",
  3928. phba->shost->host_no);
  3929. phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
  3930. if (!phba->wq) {
  3931. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3932. "Failed to allocate work queue\n");
  3933. goto free_twq;
  3934. }
  3935. INIT_WORK(&phba->work_cqs, beiscsi_process_all_cqs);
  3936. phwi_ctrlr = phba->phwi_ctrlr;
  3937. phwi_context = phwi_ctrlr->phwi_ctxt;
  3938. if (blk_iopoll_enabled) {
  3939. for (i = 0; i < phba->num_cpus; i++) {
  3940. pbe_eq = &phwi_context->be_eq[i];
  3941. blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
  3942. be_iopoll);
  3943. blk_iopoll_enable(&pbe_eq->iopoll);
  3944. }
  3945. }
  3946. ret = beiscsi_init_irqs(phba);
  3947. if (ret < 0) {
  3948. shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
  3949. "Failed to beiscsi_init_irqs\n");
  3950. goto free_blkenbld;
  3951. }
  3952. hwi_enable_intr(phba);
  3953. if (beiscsi_setup_boot_info(phba))
  3954. /*
  3955. * log error but continue, because we may not be using
  3956. * iscsi boot.
  3957. */
  3958. shost_printk(KERN_ERR, phba->shost, "Could not set up "
  3959. "iSCSI boot info.\n");
  3960. beiscsi_create_def_ifaces(phba);
  3961. SE_DEBUG(DBG_LVL_8, "\n\n\n SUCCESS - DRIVER LOADED\n\n\n");
  3962. return 0;
  3963. free_blkenbld:
  3964. destroy_workqueue(phba->wq);
  3965. if (blk_iopoll_enabled)
  3966. for (i = 0; i < phba->num_cpus; i++) {
  3967. pbe_eq = &phwi_context->be_eq[i];
  3968. blk_iopoll_disable(&pbe_eq->iopoll);
  3969. }
  3970. free_twq:
  3971. beiscsi_clean_port(phba);
  3972. beiscsi_free_mem(phba);
  3973. free_port:
  3974. real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  3975. value = readl((void *)real_offset);
  3976. if (value & 0x00010000) {
  3977. value &= 0xfffeffff;
  3978. writel(value, (void *)real_offset);
  3979. }
  3980. pci_free_consistent(phba->pcidev,
  3981. phba->ctrl.mbox_mem_alloced.size,
  3982. phba->ctrl.mbox_mem_alloced.va,
  3983. phba->ctrl.mbox_mem_alloced.dma);
  3984. beiscsi_unmap_pci_function(phba);
  3985. hba_free:
  3986. if (phba->msix_enabled)
  3987. pci_disable_msix(phba->pcidev);
  3988. iscsi_host_remove(phba->shost);
  3989. pci_dev_put(phba->pcidev);
  3990. iscsi_host_free(phba->shost);
  3991. disable_pci:
  3992. pci_disable_device(pcidev);
  3993. return ret;
  3994. }
  3995. struct iscsi_transport beiscsi_iscsi_transport = {
  3996. .owner = THIS_MODULE,
  3997. .name = DRV_NAME,
  3998. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
  3999. CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
  4000. .create_session = beiscsi_session_create,
  4001. .destroy_session = beiscsi_session_destroy,
  4002. .create_conn = beiscsi_conn_create,
  4003. .bind_conn = beiscsi_conn_bind,
  4004. .destroy_conn = iscsi_conn_teardown,
  4005. .attr_is_visible = be2iscsi_attr_is_visible,
  4006. .set_iface_param = be2iscsi_iface_set_param,
  4007. .get_iface_param = be2iscsi_iface_get_param,
  4008. .set_param = beiscsi_set_param,
  4009. .get_conn_param = iscsi_conn_get_param,
  4010. .get_session_param = iscsi_session_get_param,
  4011. .get_host_param = beiscsi_get_host_param,
  4012. .start_conn = beiscsi_conn_start,
  4013. .stop_conn = iscsi_conn_stop,
  4014. .send_pdu = iscsi_conn_send_pdu,
  4015. .xmit_task = beiscsi_task_xmit,
  4016. .cleanup_task = beiscsi_cleanup_task,
  4017. .alloc_pdu = beiscsi_alloc_pdu,
  4018. .parse_pdu_itt = beiscsi_parse_pdu,
  4019. .get_stats = beiscsi_conn_get_stats,
  4020. .get_ep_param = beiscsi_ep_get_param,
  4021. .ep_connect = beiscsi_ep_connect,
  4022. .ep_poll = beiscsi_ep_poll,
  4023. .ep_disconnect = beiscsi_ep_disconnect,
  4024. .session_recovery_timedout = iscsi_session_recovery_timedout,
  4025. .bsg_request = beiscsi_bsg_request,
  4026. };
  4027. static struct pci_driver beiscsi_pci_driver = {
  4028. .name = DRV_NAME,
  4029. .probe = beiscsi_dev_probe,
  4030. .remove = beiscsi_remove,
  4031. .shutdown = beiscsi_shutdown,
  4032. .id_table = beiscsi_pci_id_table
  4033. };
  4034. static int __init beiscsi_module_init(void)
  4035. {
  4036. int ret;
  4037. beiscsi_scsi_transport =
  4038. iscsi_register_transport(&beiscsi_iscsi_transport);
  4039. if (!beiscsi_scsi_transport) {
  4040. SE_DEBUG(DBG_LVL_1,
  4041. "beiscsi_module_init - Unable to register beiscsi"
  4042. "transport.\n");
  4043. return -ENOMEM;
  4044. }
  4045. SE_DEBUG(DBG_LVL_8, "In beiscsi_module_init, tt=%p\n",
  4046. &beiscsi_iscsi_transport);
  4047. ret = pci_register_driver(&beiscsi_pci_driver);
  4048. if (ret) {
  4049. SE_DEBUG(DBG_LVL_1,
  4050. "beiscsi_module_init - Unable to register"
  4051. "beiscsi pci driver.\n");
  4052. goto unregister_iscsi_transport;
  4053. }
  4054. return 0;
  4055. unregister_iscsi_transport:
  4056. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  4057. return ret;
  4058. }
  4059. static void __exit beiscsi_module_exit(void)
  4060. {
  4061. pci_unregister_driver(&beiscsi_pci_driver);
  4062. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  4063. }
  4064. module_init(beiscsi_module_init);
  4065. module_exit(beiscsi_module_exit);