be_main.c 114 KB

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