be_main.c 116 KB

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