be_main.c 113 KB

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