be_main.c 116 KB

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