be_main.c 114 KB

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