be_main.c 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999
  1. /**
  2. * Copyright (C) 2005 - 2011 Emulex
  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 (jayamohan.kallickal@emulex.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@emulex.com
  14. *
  15. * Emulex
  16. * 3333 Susan Street
  17. * Costa Mesa, CA 92626
  18. */
  19. #include <linux/reboot.h>
  20. #include <linux/delay.h>
  21. #include <linux/slab.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 <linux/iscsi_boot_sysfs.h>
  29. #include <linux/module.h>
  30. #include <linux/bsg-lib.h>
  31. #include <scsi/libiscsi.h>
  32. #include <scsi/scsi_bsg_iscsi.h>
  33. #include <scsi/scsi_netlink.h>
  34. #include <scsi/scsi_transport_iscsi.h>
  35. #include <scsi/scsi_transport.h>
  36. #include <scsi/scsi_cmnd.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi.h>
  40. #include "be_main.h"
  41. #include "be_iscsi.h"
  42. #include "be_mgmt.h"
  43. #include "be_cmds.h"
  44. static unsigned int be_iopoll_budget = 10;
  45. static unsigned int be_max_phys_size = 64;
  46. static unsigned int enable_msix = 1;
  47. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  48. MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
  49. MODULE_VERSION(BUILD_STR);
  50. MODULE_AUTHOR("Emulex Corporation");
  51. MODULE_LICENSE("GPL");
  52. module_param(be_iopoll_budget, int, 0);
  53. module_param(enable_msix, int, 0);
  54. module_param(be_max_phys_size, uint, S_IRUGO);
  55. MODULE_PARM_DESC(be_max_phys_size,
  56. "Maximum Size (In Kilobytes) of physically contiguous "
  57. "memory that can be allocated. Range is 16 - 128");
  58. #define beiscsi_disp_param(_name)\
  59. ssize_t \
  60. beiscsi_##_name##_disp(struct device *dev,\
  61. struct device_attribute *attrib, char *buf) \
  62. { \
  63. struct Scsi_Host *shost = class_to_shost(dev);\
  64. struct beiscsi_hba *phba = iscsi_host_priv(shost); \
  65. uint32_t param_val = 0; \
  66. param_val = phba->attr_##_name;\
  67. return snprintf(buf, PAGE_SIZE, "%d\n",\
  68. phba->attr_##_name);\
  69. }
  70. #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
  71. int \
  72. beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
  73. {\
  74. if (val >= _minval && val <= _maxval) {\
  75. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
  76. "BA_%d : beiscsi_"#_name" updated "\
  77. "from 0x%x ==> 0x%x\n",\
  78. phba->attr_##_name, val); \
  79. phba->attr_##_name = val;\
  80. return 0;\
  81. } \
  82. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
  83. "BA_%d beiscsi_"#_name" attribute "\
  84. "cannot be updated to 0x%x, "\
  85. "range allowed is ["#_minval" - "#_maxval"]\n", val);\
  86. return -EINVAL;\
  87. }
  88. #define beiscsi_store_param(_name) \
  89. ssize_t \
  90. beiscsi_##_name##_store(struct device *dev,\
  91. struct device_attribute *attr, const char *buf,\
  92. size_t count) \
  93. { \
  94. struct Scsi_Host *shost = class_to_shost(dev);\
  95. struct beiscsi_hba *phba = iscsi_host_priv(shost);\
  96. uint32_t param_val = 0;\
  97. if (!isdigit(buf[0]))\
  98. return -EINVAL;\
  99. if (sscanf(buf, "%i", &param_val) != 1)\
  100. return -EINVAL;\
  101. if (beiscsi_##_name##_change(phba, param_val) == 0) \
  102. return strlen(buf);\
  103. else \
  104. return -EINVAL;\
  105. }
  106. #define beiscsi_init_param(_name, _minval, _maxval, _defval) \
  107. int \
  108. beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
  109. { \
  110. if (val >= _minval && val <= _maxval) {\
  111. phba->attr_##_name = val;\
  112. return 0;\
  113. } \
  114. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
  115. "BA_%d beiscsi_"#_name" attribute " \
  116. "cannot be updated to 0x%x, "\
  117. "range allowed is ["#_minval" - "#_maxval"]\n", val);\
  118. phba->attr_##_name = _defval;\
  119. return -EINVAL;\
  120. }
  121. #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
  122. static uint beiscsi_##_name = _defval;\
  123. module_param(beiscsi_##_name, uint, S_IRUGO);\
  124. MODULE_PARM_DESC(beiscsi_##_name, _descp);\
  125. beiscsi_disp_param(_name)\
  126. beiscsi_change_param(_name, _minval, _maxval, _defval)\
  127. beiscsi_store_param(_name)\
  128. beiscsi_init_param(_name, _minval, _maxval, _defval)\
  129. DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
  130. beiscsi_##_name##_disp, beiscsi_##_name##_store)
  131. /*
  132. * When new log level added update the
  133. * the MAX allowed value for log_enable
  134. */
  135. BEISCSI_RW_ATTR(log_enable, 0x00,
  136. 0xFF, 0x00, "Enable logging Bit Mask\n"
  137. "\t\t\t\tInitialization Events : 0x01\n"
  138. "\t\t\t\tMailbox Events : 0x02\n"
  139. "\t\t\t\tMiscellaneous Events : 0x04\n"
  140. "\t\t\t\tError Handling : 0x08\n"
  141. "\t\t\t\tIO Path Events : 0x10\n"
  142. "\t\t\t\tConfiguration Path : 0x20\n");
  143. DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
  144. struct device_attribute *beiscsi_attrs[] = {
  145. &dev_attr_beiscsi_log_enable,
  146. &dev_attr_beiscsi_drvr_ver,
  147. NULL,
  148. };
  149. static char const *cqe_desc[] = {
  150. "RESERVED_DESC",
  151. "SOL_CMD_COMPLETE",
  152. "SOL_CMD_KILLED_DATA_DIGEST_ERR",
  153. "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
  154. "CXN_KILLED_BURST_LEN_MISMATCH",
  155. "CXN_KILLED_AHS_RCVD",
  156. "CXN_KILLED_HDR_DIGEST_ERR",
  157. "CXN_KILLED_UNKNOWN_HDR",
  158. "CXN_KILLED_STALE_ITT_TTT_RCVD",
  159. "CXN_KILLED_INVALID_ITT_TTT_RCVD",
  160. "CXN_KILLED_RST_RCVD",
  161. "CXN_KILLED_TIMED_OUT",
  162. "CXN_KILLED_RST_SENT",
  163. "CXN_KILLED_FIN_RCVD",
  164. "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
  165. "CXN_KILLED_BAD_WRB_INDEX_ERROR",
  166. "CXN_KILLED_OVER_RUN_RESIDUAL",
  167. "CXN_KILLED_UNDER_RUN_RESIDUAL",
  168. "CMD_KILLED_INVALID_STATSN_RCVD",
  169. "CMD_KILLED_INVALID_R2T_RCVD",
  170. "CMD_CXN_KILLED_LUN_INVALID",
  171. "CMD_CXN_KILLED_ICD_INVALID",
  172. "CMD_CXN_KILLED_ITT_INVALID",
  173. "CMD_CXN_KILLED_SEQ_OUTOFORDER",
  174. "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
  175. "CXN_INVALIDATE_NOTIFY",
  176. "CXN_INVALIDATE_INDEX_NOTIFY",
  177. "CMD_INVALIDATED_NOTIFY",
  178. "UNSOL_HDR_NOTIFY",
  179. "UNSOL_DATA_NOTIFY",
  180. "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
  181. "DRIVERMSG_NOTIFY",
  182. "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
  183. "SOL_CMD_KILLED_DIF_ERR",
  184. "CXN_KILLED_SYN_RCVD",
  185. "CXN_KILLED_IMM_DATA_RCVD"
  186. };
  187. static int beiscsi_slave_configure(struct scsi_device *sdev)
  188. {
  189. blk_queue_max_segment_size(sdev->request_queue, 65536);
  190. return 0;
  191. }
  192. static int beiscsi_eh_abort(struct scsi_cmnd *sc)
  193. {
  194. struct iscsi_cls_session *cls_session;
  195. struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
  196. struct beiscsi_io_task *aborted_io_task;
  197. struct iscsi_conn *conn;
  198. struct beiscsi_conn *beiscsi_conn;
  199. struct beiscsi_hba *phba;
  200. struct iscsi_session *session;
  201. struct invalidate_command_table *inv_tbl;
  202. struct be_dma_mem nonemb_cmd;
  203. unsigned int cid, tag, num_invalidate;
  204. cls_session = starget_to_session(scsi_target(sc->device));
  205. session = cls_session->dd_data;
  206. spin_lock_bh(&session->lock);
  207. if (!aborted_task || !aborted_task->sc) {
  208. /* we raced */
  209. spin_unlock_bh(&session->lock);
  210. return SUCCESS;
  211. }
  212. aborted_io_task = aborted_task->dd_data;
  213. if (!aborted_io_task->scsi_cmnd) {
  214. /* raced or invalid command */
  215. spin_unlock_bh(&session->lock);
  216. return SUCCESS;
  217. }
  218. spin_unlock_bh(&session->lock);
  219. conn = aborted_task->conn;
  220. beiscsi_conn = conn->dd_data;
  221. phba = beiscsi_conn->phba;
  222. /* invalidate iocb */
  223. cid = beiscsi_conn->beiscsi_conn_cid;
  224. inv_tbl = phba->inv_tbl;
  225. memset(inv_tbl, 0x0, sizeof(*inv_tbl));
  226. inv_tbl->cid = cid;
  227. inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
  228. num_invalidate = 1;
  229. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  230. sizeof(struct invalidate_commands_params_in),
  231. &nonemb_cmd.dma);
  232. if (nonemb_cmd.va == NULL) {
  233. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
  234. "BM_%d : Failed to allocate memory for"
  235. "mgmt_invalidate_icds\n");
  236. return FAILED;
  237. }
  238. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  239. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  240. cid, &nonemb_cmd);
  241. if (!tag) {
  242. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
  243. "BM_%d : mgmt_invalidate_icds could not be"
  244. "submitted\n");
  245. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  246. nonemb_cmd.va, nonemb_cmd.dma);
  247. return FAILED;
  248. } else {
  249. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  250. phba->ctrl.mcc_numtag[tag]);
  251. free_mcc_tag(&phba->ctrl, tag);
  252. }
  253. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  254. nonemb_cmd.va, nonemb_cmd.dma);
  255. return iscsi_eh_abort(sc);
  256. }
  257. static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
  258. {
  259. struct iscsi_task *abrt_task;
  260. struct beiscsi_io_task *abrt_io_task;
  261. struct iscsi_conn *conn;
  262. struct beiscsi_conn *beiscsi_conn;
  263. struct beiscsi_hba *phba;
  264. struct iscsi_session *session;
  265. struct iscsi_cls_session *cls_session;
  266. struct invalidate_command_table *inv_tbl;
  267. struct be_dma_mem nonemb_cmd;
  268. unsigned int cid, tag, i, num_invalidate;
  269. /* invalidate iocbs */
  270. cls_session = starget_to_session(scsi_target(sc->device));
  271. session = cls_session->dd_data;
  272. spin_lock_bh(&session->lock);
  273. if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
  274. spin_unlock_bh(&session->lock);
  275. return FAILED;
  276. }
  277. conn = session->leadconn;
  278. beiscsi_conn = conn->dd_data;
  279. phba = beiscsi_conn->phba;
  280. cid = beiscsi_conn->beiscsi_conn_cid;
  281. inv_tbl = phba->inv_tbl;
  282. memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
  283. num_invalidate = 0;
  284. for (i = 0; i < conn->session->cmds_max; i++) {
  285. abrt_task = conn->session->cmds[i];
  286. abrt_io_task = abrt_task->dd_data;
  287. if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
  288. continue;
  289. if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
  290. continue;
  291. inv_tbl->cid = cid;
  292. inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
  293. num_invalidate++;
  294. inv_tbl++;
  295. }
  296. spin_unlock_bh(&session->lock);
  297. inv_tbl = phba->inv_tbl;
  298. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  299. sizeof(struct invalidate_commands_params_in),
  300. &nonemb_cmd.dma);
  301. if (nonemb_cmd.va == NULL) {
  302. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
  303. "BM_%d : Failed to allocate memory for"
  304. "mgmt_invalidate_icds\n");
  305. return FAILED;
  306. }
  307. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  308. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  309. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  310. cid, &nonemb_cmd);
  311. if (!tag) {
  312. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
  313. "BM_%d : mgmt_invalidate_icds could not be"
  314. " submitted\n");
  315. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  316. nonemb_cmd.va, nonemb_cmd.dma);
  317. return FAILED;
  318. } else {
  319. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  320. phba->ctrl.mcc_numtag[tag]);
  321. free_mcc_tag(&phba->ctrl, tag);
  322. }
  323. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  324. nonemb_cmd.va, nonemb_cmd.dma);
  325. return iscsi_eh_device_reset(sc);
  326. }
  327. static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
  328. {
  329. struct beiscsi_hba *phba = data;
  330. struct mgmt_session_info *boot_sess = &phba->boot_sess;
  331. struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
  332. char *str = buf;
  333. int rc;
  334. switch (type) {
  335. case ISCSI_BOOT_TGT_NAME:
  336. rc = sprintf(buf, "%.*s\n",
  337. (int)strlen(boot_sess->target_name),
  338. (char *)&boot_sess->target_name);
  339. break;
  340. case ISCSI_BOOT_TGT_IP_ADDR:
  341. if (boot_conn->dest_ipaddr.ip_type == 0x1)
  342. rc = sprintf(buf, "%pI4\n",
  343. (char *)&boot_conn->dest_ipaddr.addr);
  344. else
  345. rc = sprintf(str, "%pI6\n",
  346. (char *)&boot_conn->dest_ipaddr.addr);
  347. break;
  348. case ISCSI_BOOT_TGT_PORT:
  349. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  350. break;
  351. case ISCSI_BOOT_TGT_CHAP_NAME:
  352. rc = sprintf(str, "%.*s\n",
  353. boot_conn->negotiated_login_options.auth_data.chap.
  354. target_chap_name_length,
  355. (char *)&boot_conn->negotiated_login_options.
  356. auth_data.chap.target_chap_name);
  357. break;
  358. case ISCSI_BOOT_TGT_CHAP_SECRET:
  359. rc = sprintf(str, "%.*s\n",
  360. boot_conn->negotiated_login_options.auth_data.chap.
  361. target_secret_length,
  362. (char *)&boot_conn->negotiated_login_options.
  363. auth_data.chap.target_secret);
  364. break;
  365. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  366. rc = sprintf(str, "%.*s\n",
  367. boot_conn->negotiated_login_options.auth_data.chap.
  368. intr_chap_name_length,
  369. (char *)&boot_conn->negotiated_login_options.
  370. auth_data.chap.intr_chap_name);
  371. break;
  372. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  373. rc = sprintf(str, "%.*s\n",
  374. boot_conn->negotiated_login_options.auth_data.chap.
  375. intr_secret_length,
  376. (char *)&boot_conn->negotiated_login_options.
  377. auth_data.chap.intr_secret);
  378. break;
  379. case ISCSI_BOOT_TGT_FLAGS:
  380. rc = sprintf(str, "2\n");
  381. break;
  382. case ISCSI_BOOT_TGT_NIC_ASSOC:
  383. rc = sprintf(str, "0\n");
  384. break;
  385. default:
  386. rc = -ENOSYS;
  387. break;
  388. }
  389. return rc;
  390. }
  391. static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
  392. {
  393. struct beiscsi_hba *phba = data;
  394. char *str = buf;
  395. int rc;
  396. switch (type) {
  397. case ISCSI_BOOT_INI_INITIATOR_NAME:
  398. rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
  399. break;
  400. default:
  401. rc = -ENOSYS;
  402. break;
  403. }
  404. return rc;
  405. }
  406. static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
  407. {
  408. struct beiscsi_hba *phba = data;
  409. char *str = buf;
  410. int rc;
  411. switch (type) {
  412. case ISCSI_BOOT_ETH_FLAGS:
  413. rc = sprintf(str, "2\n");
  414. break;
  415. case ISCSI_BOOT_ETH_INDEX:
  416. rc = sprintf(str, "0\n");
  417. break;
  418. case ISCSI_BOOT_ETH_MAC:
  419. rc = beiscsi_get_macaddr(str, phba);
  420. break;
  421. default:
  422. rc = -ENOSYS;
  423. break;
  424. }
  425. return rc;
  426. }
  427. static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
  428. {
  429. umode_t rc;
  430. switch (type) {
  431. case ISCSI_BOOT_TGT_NAME:
  432. case ISCSI_BOOT_TGT_IP_ADDR:
  433. case ISCSI_BOOT_TGT_PORT:
  434. case ISCSI_BOOT_TGT_CHAP_NAME:
  435. case ISCSI_BOOT_TGT_CHAP_SECRET:
  436. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  437. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  438. case ISCSI_BOOT_TGT_NIC_ASSOC:
  439. case ISCSI_BOOT_TGT_FLAGS:
  440. rc = S_IRUGO;
  441. break;
  442. default:
  443. rc = 0;
  444. break;
  445. }
  446. return rc;
  447. }
  448. static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
  449. {
  450. umode_t rc;
  451. switch (type) {
  452. case ISCSI_BOOT_INI_INITIATOR_NAME:
  453. rc = S_IRUGO;
  454. break;
  455. default:
  456. rc = 0;
  457. break;
  458. }
  459. return rc;
  460. }
  461. static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
  462. {
  463. umode_t rc;
  464. switch (type) {
  465. case ISCSI_BOOT_ETH_FLAGS:
  466. case ISCSI_BOOT_ETH_MAC:
  467. case ISCSI_BOOT_ETH_INDEX:
  468. rc = S_IRUGO;
  469. break;
  470. default:
  471. rc = 0;
  472. break;
  473. }
  474. return rc;
  475. }
  476. /*------------------- PCI Driver operations and data ----------------- */
  477. static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
  478. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
  479. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
  480. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
  481. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
  482. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
  483. { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
  484. { 0 }
  485. };
  486. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  487. static struct scsi_host_template beiscsi_sht = {
  488. .module = THIS_MODULE,
  489. .name = "Emulex 10Gbe open-iscsi Initiator Driver",
  490. .proc_name = DRV_NAME,
  491. .queuecommand = iscsi_queuecommand,
  492. .change_queue_depth = iscsi_change_queue_depth,
  493. .slave_configure = beiscsi_slave_configure,
  494. .target_alloc = iscsi_target_alloc,
  495. .eh_abort_handler = beiscsi_eh_abort,
  496. .eh_device_reset_handler = beiscsi_eh_device_reset,
  497. .eh_target_reset_handler = iscsi_eh_session_reset,
  498. .shost_attrs = beiscsi_attrs,
  499. .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
  500. .can_queue = BE2_IO_DEPTH,
  501. .this_id = -1,
  502. .max_sectors = BEISCSI_MAX_SECTORS,
  503. .cmd_per_lun = BEISCSI_CMD_PER_LUN,
  504. .use_clustering = ENABLE_CLUSTERING,
  505. .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
  506. };
  507. static struct scsi_transport_template *beiscsi_scsi_transport;
  508. static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
  509. {
  510. struct beiscsi_hba *phba;
  511. struct Scsi_Host *shost;
  512. shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
  513. if (!shost) {
  514. dev_err(&pcidev->dev,
  515. "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
  516. return NULL;
  517. }
  518. shost->dma_boundary = pcidev->dma_mask;
  519. shost->max_id = BE2_MAX_SESSIONS;
  520. shost->max_channel = 0;
  521. shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
  522. shost->max_lun = BEISCSI_NUM_MAX_LUN;
  523. shost->transportt = beiscsi_scsi_transport;
  524. phba = iscsi_host_priv(shost);
  525. memset(phba, 0, sizeof(*phba));
  526. phba->shost = shost;
  527. phba->pcidev = pci_dev_get(pcidev);
  528. pci_set_drvdata(pcidev, phba);
  529. phba->interface_handle = 0xFFFFFFFF;
  530. if (iscsi_host_add(shost, &phba->pcidev->dev))
  531. goto free_devices;
  532. return phba;
  533. free_devices:
  534. pci_dev_put(phba->pcidev);
  535. iscsi_host_free(phba->shost);
  536. return NULL;
  537. }
  538. static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
  539. {
  540. if (phba->csr_va) {
  541. iounmap(phba->csr_va);
  542. phba->csr_va = NULL;
  543. }
  544. if (phba->db_va) {
  545. iounmap(phba->db_va);
  546. phba->db_va = NULL;
  547. }
  548. if (phba->pci_va) {
  549. iounmap(phba->pci_va);
  550. phba->pci_va = NULL;
  551. }
  552. }
  553. static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
  554. struct pci_dev *pcidev)
  555. {
  556. u8 __iomem *addr;
  557. int pcicfg_reg;
  558. addr = ioremap_nocache(pci_resource_start(pcidev, 2),
  559. pci_resource_len(pcidev, 2));
  560. if (addr == NULL)
  561. return -ENOMEM;
  562. phba->ctrl.csr = addr;
  563. phba->csr_va = addr;
  564. phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
  565. addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
  566. if (addr == NULL)
  567. goto pci_map_err;
  568. phba->ctrl.db = addr;
  569. phba->db_va = addr;
  570. phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
  571. if (phba->generation == BE_GEN2)
  572. pcicfg_reg = 1;
  573. else
  574. pcicfg_reg = 0;
  575. addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
  576. pci_resource_len(pcidev, pcicfg_reg));
  577. if (addr == NULL)
  578. goto pci_map_err;
  579. phba->ctrl.pcicfg = addr;
  580. phba->pci_va = addr;
  581. phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
  582. return 0;
  583. pci_map_err:
  584. beiscsi_unmap_pci_function(phba);
  585. return -ENOMEM;
  586. }
  587. static int beiscsi_enable_pci(struct pci_dev *pcidev)
  588. {
  589. int ret;
  590. ret = pci_enable_device(pcidev);
  591. if (ret) {
  592. dev_err(&pcidev->dev,
  593. "beiscsi_enable_pci - enable device failed\n");
  594. return ret;
  595. }
  596. pci_set_master(pcidev);
  597. if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
  598. ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
  599. if (ret) {
  600. dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
  601. pci_disable_device(pcidev);
  602. return ret;
  603. }
  604. }
  605. return 0;
  606. }
  607. static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
  608. {
  609. struct be_ctrl_info *ctrl = &phba->ctrl;
  610. struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
  611. struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
  612. int status = 0;
  613. ctrl->pdev = pdev;
  614. status = beiscsi_map_pci_bars(phba, pdev);
  615. if (status)
  616. return status;
  617. mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
  618. mbox_mem_alloc->va = pci_alloc_consistent(pdev,
  619. mbox_mem_alloc->size,
  620. &mbox_mem_alloc->dma);
  621. if (!mbox_mem_alloc->va) {
  622. beiscsi_unmap_pci_function(phba);
  623. return -ENOMEM;
  624. }
  625. mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
  626. mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
  627. mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
  628. memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
  629. spin_lock_init(&ctrl->mbox_lock);
  630. spin_lock_init(&phba->ctrl.mcc_lock);
  631. spin_lock_init(&phba->ctrl.mcc_cq_lock);
  632. return status;
  633. }
  634. static void beiscsi_get_params(struct beiscsi_hba *phba)
  635. {
  636. phba->params.ios_per_ctrl = (phba->fw_config.iscsi_icd_count
  637. - (phba->fw_config.iscsi_cid_count
  638. + BE2_TMFS
  639. + BE2_NOPOUT_REQ));
  640. phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
  641. phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count * 2;
  642. phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;
  643. phba->params.num_sge_per_io = BE2_SGE;
  644. phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
  645. phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
  646. phba->params.eq_timer = 64;
  647. phba->params.num_eq_entries =
  648. (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
  649. + BE2_TMFS) / 512) + 1) * 512;
  650. phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024)
  651. ? 1024 : phba->params.num_eq_entries;
  652. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  653. "BM_%d : phba->params.num_eq_entries=%d\n",
  654. phba->params.num_eq_entries);
  655. phba->params.num_cq_entries =
  656. (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
  657. + BE2_TMFS) / 512) + 1) * 512;
  658. phba->params.wrbs_per_cxn = 256;
  659. }
  660. static void hwi_ring_eq_db(struct beiscsi_hba *phba,
  661. unsigned int id, unsigned int clr_interrupt,
  662. unsigned int num_processed,
  663. unsigned char rearm, unsigned char event)
  664. {
  665. u32 val = 0;
  666. val |= id & DB_EQ_RING_ID_MASK;
  667. if (rearm)
  668. val |= 1 << DB_EQ_REARM_SHIFT;
  669. if (clr_interrupt)
  670. val |= 1 << DB_EQ_CLR_SHIFT;
  671. if (event)
  672. val |= 1 << DB_EQ_EVNT_SHIFT;
  673. val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
  674. iowrite32(val, phba->db_va + DB_EQ_OFFSET);
  675. }
  676. /**
  677. * be_isr_mcc - The isr routine of the driver.
  678. * @irq: Not used
  679. * @dev_id: Pointer to host adapter structure
  680. */
  681. static irqreturn_t be_isr_mcc(int irq, void *dev_id)
  682. {
  683. struct beiscsi_hba *phba;
  684. struct be_eq_entry *eqe = NULL;
  685. struct be_queue_info *eq;
  686. struct be_queue_info *mcc;
  687. unsigned int num_eq_processed;
  688. struct be_eq_obj *pbe_eq;
  689. unsigned long flags;
  690. pbe_eq = dev_id;
  691. eq = &pbe_eq->q;
  692. phba = pbe_eq->phba;
  693. mcc = &phba->ctrl.mcc_obj.cq;
  694. eqe = queue_tail_node(eq);
  695. num_eq_processed = 0;
  696. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  697. & EQE_VALID_MASK) {
  698. if (((eqe->dw[offsetof(struct amap_eq_entry,
  699. resource_id) / 32] &
  700. EQE_RESID_MASK) >> 16) == mcc->id) {
  701. spin_lock_irqsave(&phba->isr_lock, flags);
  702. pbe_eq->todo_mcc_cq = true;
  703. spin_unlock_irqrestore(&phba->isr_lock, flags);
  704. }
  705. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  706. queue_tail_inc(eq);
  707. eqe = queue_tail_node(eq);
  708. num_eq_processed++;
  709. }
  710. if (pbe_eq->todo_mcc_cq)
  711. queue_work(phba->wq, &pbe_eq->work_cqs);
  712. if (num_eq_processed)
  713. hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
  714. return IRQ_HANDLED;
  715. }
  716. /**
  717. * be_isr_msix - The isr routine of the driver.
  718. * @irq: Not used
  719. * @dev_id: Pointer to host adapter structure
  720. */
  721. static irqreturn_t be_isr_msix(int irq, void *dev_id)
  722. {
  723. struct beiscsi_hba *phba;
  724. struct be_eq_entry *eqe = NULL;
  725. struct be_queue_info *eq;
  726. struct be_queue_info *cq;
  727. unsigned int num_eq_processed;
  728. struct be_eq_obj *pbe_eq;
  729. unsigned long flags;
  730. pbe_eq = dev_id;
  731. eq = &pbe_eq->q;
  732. cq = pbe_eq->cq;
  733. eqe = queue_tail_node(eq);
  734. phba = pbe_eq->phba;
  735. num_eq_processed = 0;
  736. if (blk_iopoll_enabled) {
  737. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  738. & EQE_VALID_MASK) {
  739. if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
  740. blk_iopoll_sched(&pbe_eq->iopoll);
  741. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  742. queue_tail_inc(eq);
  743. eqe = queue_tail_node(eq);
  744. num_eq_processed++;
  745. }
  746. } else {
  747. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  748. & EQE_VALID_MASK) {
  749. spin_lock_irqsave(&phba->isr_lock, flags);
  750. pbe_eq->todo_cq = true;
  751. spin_unlock_irqrestore(&phba->isr_lock, flags);
  752. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  753. queue_tail_inc(eq);
  754. eqe = queue_tail_node(eq);
  755. num_eq_processed++;
  756. }
  757. if (pbe_eq->todo_cq)
  758. queue_work(phba->wq, &pbe_eq->work_cqs);
  759. }
  760. if (num_eq_processed)
  761. hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
  762. return IRQ_HANDLED;
  763. }
  764. /**
  765. * be_isr - The isr routine of the driver.
  766. * @irq: Not used
  767. * @dev_id: Pointer to host adapter structure
  768. */
  769. static irqreturn_t be_isr(int irq, void *dev_id)
  770. {
  771. struct beiscsi_hba *phba;
  772. struct hwi_controller *phwi_ctrlr;
  773. struct hwi_context_memory *phwi_context;
  774. struct be_eq_entry *eqe = NULL;
  775. struct be_queue_info *eq;
  776. struct be_queue_info *cq;
  777. struct be_queue_info *mcc;
  778. unsigned long flags, index;
  779. unsigned int num_mcceq_processed, num_ioeq_processed;
  780. struct be_ctrl_info *ctrl;
  781. struct be_eq_obj *pbe_eq;
  782. int isr;
  783. phba = dev_id;
  784. ctrl = &phba->ctrl;
  785. isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
  786. (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
  787. if (!isr)
  788. return IRQ_NONE;
  789. phwi_ctrlr = phba->phwi_ctrlr;
  790. phwi_context = phwi_ctrlr->phwi_ctxt;
  791. pbe_eq = &phwi_context->be_eq[0];
  792. eq = &phwi_context->be_eq[0].q;
  793. mcc = &phba->ctrl.mcc_obj.cq;
  794. index = 0;
  795. eqe = queue_tail_node(eq);
  796. num_ioeq_processed = 0;
  797. num_mcceq_processed = 0;
  798. if (blk_iopoll_enabled) {
  799. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  800. & EQE_VALID_MASK) {
  801. if (((eqe->dw[offsetof(struct amap_eq_entry,
  802. resource_id) / 32] &
  803. EQE_RESID_MASK) >> 16) == mcc->id) {
  804. spin_lock_irqsave(&phba->isr_lock, flags);
  805. pbe_eq->todo_mcc_cq = true;
  806. spin_unlock_irqrestore(&phba->isr_lock, flags);
  807. num_mcceq_processed++;
  808. } else {
  809. if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
  810. blk_iopoll_sched(&pbe_eq->iopoll);
  811. num_ioeq_processed++;
  812. }
  813. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  814. queue_tail_inc(eq);
  815. eqe = queue_tail_node(eq);
  816. }
  817. if (num_ioeq_processed || num_mcceq_processed) {
  818. if (pbe_eq->todo_mcc_cq)
  819. queue_work(phba->wq, &pbe_eq->work_cqs);
  820. if ((num_mcceq_processed) && (!num_ioeq_processed))
  821. hwi_ring_eq_db(phba, eq->id, 0,
  822. (num_ioeq_processed +
  823. num_mcceq_processed) , 1, 1);
  824. else
  825. hwi_ring_eq_db(phba, eq->id, 0,
  826. (num_ioeq_processed +
  827. num_mcceq_processed), 0, 1);
  828. return IRQ_HANDLED;
  829. } else
  830. return IRQ_NONE;
  831. } else {
  832. cq = &phwi_context->be_cq[0];
  833. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  834. & EQE_VALID_MASK) {
  835. if (((eqe->dw[offsetof(struct amap_eq_entry,
  836. resource_id) / 32] &
  837. EQE_RESID_MASK) >> 16) != cq->id) {
  838. spin_lock_irqsave(&phba->isr_lock, flags);
  839. pbe_eq->todo_mcc_cq = true;
  840. spin_unlock_irqrestore(&phba->isr_lock, flags);
  841. } else {
  842. spin_lock_irqsave(&phba->isr_lock, flags);
  843. pbe_eq->todo_cq = true;
  844. spin_unlock_irqrestore(&phba->isr_lock, flags);
  845. }
  846. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  847. queue_tail_inc(eq);
  848. eqe = queue_tail_node(eq);
  849. num_ioeq_processed++;
  850. }
  851. if (pbe_eq->todo_cq || pbe_eq->todo_mcc_cq)
  852. queue_work(phba->wq, &pbe_eq->work_cqs);
  853. if (num_ioeq_processed) {
  854. hwi_ring_eq_db(phba, eq->id, 0,
  855. num_ioeq_processed, 1, 1);
  856. return IRQ_HANDLED;
  857. } else
  858. return IRQ_NONE;
  859. }
  860. }
  861. static int beiscsi_init_irqs(struct beiscsi_hba *phba)
  862. {
  863. struct pci_dev *pcidev = phba->pcidev;
  864. struct hwi_controller *phwi_ctrlr;
  865. struct hwi_context_memory *phwi_context;
  866. int ret, msix_vec, i, j;
  867. phwi_ctrlr = phba->phwi_ctrlr;
  868. phwi_context = phwi_ctrlr->phwi_ctxt;
  869. if (phba->msix_enabled) {
  870. for (i = 0; i < phba->num_cpus; i++) {
  871. phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
  872. GFP_KERNEL);
  873. if (!phba->msi_name[i]) {
  874. ret = -ENOMEM;
  875. goto free_msix_irqs;
  876. }
  877. sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
  878. phba->shost->host_no, i);
  879. msix_vec = phba->msix_entries[i].vector;
  880. ret = request_irq(msix_vec, be_isr_msix, 0,
  881. phba->msi_name[i],
  882. &phwi_context->be_eq[i]);
  883. if (ret) {
  884. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  885. "BM_%d : beiscsi_init_irqs-Failed to"
  886. "register msix for i = %d\n",
  887. i);
  888. kfree(phba->msi_name[i]);
  889. goto free_msix_irqs;
  890. }
  891. }
  892. phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
  893. if (!phba->msi_name[i]) {
  894. ret = -ENOMEM;
  895. goto free_msix_irqs;
  896. }
  897. sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
  898. phba->shost->host_no);
  899. msix_vec = phba->msix_entries[i].vector;
  900. ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
  901. &phwi_context->be_eq[i]);
  902. if (ret) {
  903. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
  904. "BM_%d : beiscsi_init_irqs-"
  905. "Failed to register beiscsi_msix_mcc\n");
  906. kfree(phba->msi_name[i]);
  907. goto free_msix_irqs;
  908. }
  909. } else {
  910. ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
  911. "beiscsi", phba);
  912. if (ret) {
  913. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  914. "BM_%d : beiscsi_init_irqs-"
  915. "Failed to register irq\\n");
  916. return ret;
  917. }
  918. }
  919. return 0;
  920. free_msix_irqs:
  921. for (j = i - 1; j >= 0; j--) {
  922. kfree(phba->msi_name[j]);
  923. msix_vec = phba->msix_entries[j].vector;
  924. free_irq(msix_vec, &phwi_context->be_eq[j]);
  925. }
  926. return ret;
  927. }
  928. static void hwi_ring_cq_db(struct beiscsi_hba *phba,
  929. unsigned int id, unsigned int num_processed,
  930. unsigned char rearm, unsigned char event)
  931. {
  932. u32 val = 0;
  933. val |= id & DB_CQ_RING_ID_MASK;
  934. if (rearm)
  935. val |= 1 << DB_CQ_REARM_SHIFT;
  936. val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
  937. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  938. }
  939. static unsigned int
  940. beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
  941. struct beiscsi_hba *phba,
  942. unsigned short cid,
  943. struct pdu_base *ppdu,
  944. unsigned long pdu_len,
  945. void *pbuffer, unsigned long buf_len)
  946. {
  947. struct iscsi_conn *conn = beiscsi_conn->conn;
  948. struct iscsi_session *session = conn->session;
  949. struct iscsi_task *task;
  950. struct beiscsi_io_task *io_task;
  951. struct iscsi_hdr *login_hdr;
  952. switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
  953. PDUBASE_OPCODE_MASK) {
  954. case ISCSI_OP_NOOP_IN:
  955. pbuffer = NULL;
  956. buf_len = 0;
  957. break;
  958. case ISCSI_OP_ASYNC_EVENT:
  959. break;
  960. case ISCSI_OP_REJECT:
  961. WARN_ON(!pbuffer);
  962. WARN_ON(!(buf_len == 48));
  963. beiscsi_log(phba, KERN_ERR,
  964. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  965. "BM_%d : In ISCSI_OP_REJECT\n");
  966. break;
  967. case ISCSI_OP_LOGIN_RSP:
  968. case ISCSI_OP_TEXT_RSP:
  969. task = conn->login_task;
  970. io_task = task->dd_data;
  971. login_hdr = (struct iscsi_hdr *)ppdu;
  972. login_hdr->itt = io_task->libiscsi_itt;
  973. break;
  974. default:
  975. beiscsi_log(phba, KERN_WARNING,
  976. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  977. "BM_%d : Unrecognized opcode 0x%x in async msg\n",
  978. (ppdu->
  979. dw[offsetof(struct amap_pdu_base, opcode) / 32]
  980. & PDUBASE_OPCODE_MASK));
  981. return 1;
  982. }
  983. spin_lock_bh(&session->lock);
  984. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
  985. spin_unlock_bh(&session->lock);
  986. return 0;
  987. }
  988. static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
  989. {
  990. struct sgl_handle *psgl_handle;
  991. if (phba->io_sgl_hndl_avbl) {
  992. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  993. "BM_%d : In alloc_io_sgl_handle,"
  994. " io_sgl_alloc_index=%d\n",
  995. phba->io_sgl_alloc_index);
  996. psgl_handle = phba->io_sgl_hndl_base[phba->
  997. io_sgl_alloc_index];
  998. phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
  999. phba->io_sgl_hndl_avbl--;
  1000. if (phba->io_sgl_alloc_index == (phba->params.
  1001. ios_per_ctrl - 1))
  1002. phba->io_sgl_alloc_index = 0;
  1003. else
  1004. phba->io_sgl_alloc_index++;
  1005. } else
  1006. psgl_handle = NULL;
  1007. return psgl_handle;
  1008. }
  1009. static void
  1010. free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
  1011. {
  1012. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  1013. "BM_%d : In free_,io_sgl_free_index=%d\n",
  1014. phba->io_sgl_free_index);
  1015. if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
  1016. /*
  1017. * this can happen if clean_task is called on a task that
  1018. * failed in xmit_task or alloc_pdu.
  1019. */
  1020. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  1021. "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
  1022. "value there=%p\n", phba->io_sgl_free_index,
  1023. phba->io_sgl_hndl_base
  1024. [phba->io_sgl_free_index]);
  1025. return;
  1026. }
  1027. phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
  1028. phba->io_sgl_hndl_avbl++;
  1029. if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
  1030. phba->io_sgl_free_index = 0;
  1031. else
  1032. phba->io_sgl_free_index++;
  1033. }
  1034. /**
  1035. * alloc_wrb_handle - To allocate a wrb handle
  1036. * @phba: The hba pointer
  1037. * @cid: The cid to use for allocation
  1038. *
  1039. * This happens under session_lock until submission to chip
  1040. */
  1041. struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
  1042. {
  1043. struct hwi_wrb_context *pwrb_context;
  1044. struct hwi_controller *phwi_ctrlr;
  1045. struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
  1046. phwi_ctrlr = phba->phwi_ctrlr;
  1047. pwrb_context = &phwi_ctrlr->wrb_context[cid];
  1048. if (pwrb_context->wrb_handles_available >= 2) {
  1049. pwrb_handle = pwrb_context->pwrb_handle_base[
  1050. pwrb_context->alloc_index];
  1051. pwrb_context->wrb_handles_available--;
  1052. if (pwrb_context->alloc_index ==
  1053. (phba->params.wrbs_per_cxn - 1))
  1054. pwrb_context->alloc_index = 0;
  1055. else
  1056. pwrb_context->alloc_index++;
  1057. pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
  1058. pwrb_context->alloc_index];
  1059. pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
  1060. } else
  1061. pwrb_handle = NULL;
  1062. return pwrb_handle;
  1063. }
  1064. /**
  1065. * free_wrb_handle - To free the wrb handle back to pool
  1066. * @phba: The hba pointer
  1067. * @pwrb_context: The context to free from
  1068. * @pwrb_handle: The wrb_handle to free
  1069. *
  1070. * This happens under session_lock until submission to chip
  1071. */
  1072. static void
  1073. free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
  1074. struct wrb_handle *pwrb_handle)
  1075. {
  1076. pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
  1077. pwrb_context->wrb_handles_available++;
  1078. if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
  1079. pwrb_context->free_index = 0;
  1080. else
  1081. pwrb_context->free_index++;
  1082. beiscsi_log(phba, KERN_INFO,
  1083. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1084. "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
  1085. "wrb_handles_available=%d\n",
  1086. pwrb_handle, pwrb_context->free_index,
  1087. pwrb_context->wrb_handles_available);
  1088. }
  1089. static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
  1090. {
  1091. struct sgl_handle *psgl_handle;
  1092. if (phba->eh_sgl_hndl_avbl) {
  1093. psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
  1094. phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
  1095. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1096. "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
  1097. phba->eh_sgl_alloc_index,
  1098. phba->eh_sgl_alloc_index);
  1099. phba->eh_sgl_hndl_avbl--;
  1100. if (phba->eh_sgl_alloc_index ==
  1101. (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
  1102. 1))
  1103. phba->eh_sgl_alloc_index = 0;
  1104. else
  1105. phba->eh_sgl_alloc_index++;
  1106. } else
  1107. psgl_handle = NULL;
  1108. return psgl_handle;
  1109. }
  1110. void
  1111. free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
  1112. {
  1113. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1114. "BM_%d : In free_mgmt_sgl_handle,"
  1115. "eh_sgl_free_index=%d\n",
  1116. phba->eh_sgl_free_index);
  1117. if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
  1118. /*
  1119. * this can happen if clean_task is called on a task that
  1120. * failed in xmit_task or alloc_pdu.
  1121. */
  1122. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  1123. "BM_%d : Double Free in eh SGL ,"
  1124. "eh_sgl_free_index=%d\n",
  1125. phba->eh_sgl_free_index);
  1126. return;
  1127. }
  1128. phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
  1129. phba->eh_sgl_hndl_avbl++;
  1130. if (phba->eh_sgl_free_index ==
  1131. (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
  1132. phba->eh_sgl_free_index = 0;
  1133. else
  1134. phba->eh_sgl_free_index++;
  1135. }
  1136. static void
  1137. be_complete_io(struct beiscsi_conn *beiscsi_conn,
  1138. struct iscsi_task *task, struct sol_cqe *psol)
  1139. {
  1140. struct beiscsi_io_task *io_task = task->dd_data;
  1141. struct be_status_bhs *sts_bhs =
  1142. (struct be_status_bhs *)io_task->cmd_bhs;
  1143. struct iscsi_conn *conn = beiscsi_conn->conn;
  1144. unsigned char *sense;
  1145. u32 resid = 0, exp_cmdsn, max_cmdsn;
  1146. u8 rsp, status, flags;
  1147. exp_cmdsn = (psol->
  1148. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1149. & SOL_EXP_CMD_SN_MASK);
  1150. max_cmdsn = ((psol->
  1151. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1152. & SOL_EXP_CMD_SN_MASK) +
  1153. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1154. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1155. rsp = ((psol->dw[offsetof(struct amap_sol_cqe, i_resp) / 32]
  1156. & SOL_RESP_MASK) >> 16);
  1157. status = ((psol->dw[offsetof(struct amap_sol_cqe, i_sts) / 32]
  1158. & SOL_STS_MASK) >> 8);
  1159. flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1160. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1161. if (!task->sc) {
  1162. if (io_task->scsi_cmnd)
  1163. scsi_dma_unmap(io_task->scsi_cmnd);
  1164. return;
  1165. }
  1166. task->sc->result = (DID_OK << 16) | status;
  1167. if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
  1168. task->sc->result = DID_ERROR << 16;
  1169. goto unmap;
  1170. }
  1171. /* bidi not initially supported */
  1172. if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
  1173. resid = (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) /
  1174. 32] & SOL_RES_CNT_MASK);
  1175. if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
  1176. task->sc->result = DID_ERROR << 16;
  1177. if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
  1178. scsi_set_resid(task->sc, resid);
  1179. if (!status && (scsi_bufflen(task->sc) - resid <
  1180. task->sc->underflow))
  1181. task->sc->result = DID_ERROR << 16;
  1182. }
  1183. }
  1184. if (status == SAM_STAT_CHECK_CONDITION) {
  1185. u16 sense_len;
  1186. unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
  1187. sense = sts_bhs->sense_info + sizeof(unsigned short);
  1188. sense_len = be16_to_cpu(*slen);
  1189. memcpy(task->sc->sense_buffer, sense,
  1190. min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
  1191. }
  1192. if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) {
  1193. if (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
  1194. & SOL_RES_CNT_MASK)
  1195. conn->rxdata_octets += (psol->
  1196. dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
  1197. & SOL_RES_CNT_MASK);
  1198. }
  1199. unmap:
  1200. scsi_dma_unmap(io_task->scsi_cmnd);
  1201. iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
  1202. }
  1203. static void
  1204. be_complete_logout(struct beiscsi_conn *beiscsi_conn,
  1205. struct iscsi_task *task, struct sol_cqe *psol)
  1206. {
  1207. struct iscsi_logout_rsp *hdr;
  1208. struct beiscsi_io_task *io_task = task->dd_data;
  1209. struct iscsi_conn *conn = beiscsi_conn->conn;
  1210. hdr = (struct iscsi_logout_rsp *)task->hdr;
  1211. hdr->opcode = ISCSI_OP_LOGOUT_RSP;
  1212. hdr->t2wait = 5;
  1213. hdr->t2retain = 0;
  1214. hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1215. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1216. hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
  1217. 32] & SOL_RESP_MASK);
  1218. hdr->exp_cmdsn = cpu_to_be32(psol->
  1219. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1220. & SOL_EXP_CMD_SN_MASK);
  1221. hdr->max_cmdsn = be32_to_cpu((psol->
  1222. dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
  1223. & SOL_EXP_CMD_SN_MASK) +
  1224. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1225. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1226. hdr->dlength[0] = 0;
  1227. hdr->dlength[1] = 0;
  1228. hdr->dlength[2] = 0;
  1229. hdr->hlength = 0;
  1230. hdr->itt = io_task->libiscsi_itt;
  1231. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1232. }
  1233. static void
  1234. be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
  1235. struct iscsi_task *task, struct sol_cqe *psol)
  1236. {
  1237. struct iscsi_tm_rsp *hdr;
  1238. struct iscsi_conn *conn = beiscsi_conn->conn;
  1239. struct beiscsi_io_task *io_task = task->dd_data;
  1240. hdr = (struct iscsi_tm_rsp *)task->hdr;
  1241. hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
  1242. hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1243. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1244. hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
  1245. 32] & SOL_RESP_MASK);
  1246. hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
  1247. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
  1248. hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
  1249. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
  1250. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1251. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1252. hdr->itt = io_task->libiscsi_itt;
  1253. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1254. }
  1255. static void
  1256. hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
  1257. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1258. {
  1259. struct hwi_wrb_context *pwrb_context;
  1260. struct wrb_handle *pwrb_handle = NULL;
  1261. struct hwi_controller *phwi_ctrlr;
  1262. struct iscsi_task *task;
  1263. struct beiscsi_io_task *io_task;
  1264. struct iscsi_conn *conn = beiscsi_conn->conn;
  1265. struct iscsi_session *session = conn->session;
  1266. phwi_ctrlr = phba->phwi_ctrlr;
  1267. pwrb_context = &phwi_ctrlr->wrb_context[((psol->
  1268. dw[offsetof(struct amap_sol_cqe, cid) / 32] &
  1269. SOL_CID_MASK) >> 6) -
  1270. phba->fw_config.iscsi_cid_start];
  1271. pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
  1272. dw[offsetof(struct amap_sol_cqe, wrb_index) /
  1273. 32] & SOL_WRB_INDEX_MASK) >> 16)];
  1274. task = pwrb_handle->pio_handle;
  1275. io_task = task->dd_data;
  1276. spin_lock_bh(&phba->mgmt_sgl_lock);
  1277. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  1278. spin_unlock_bh(&phba->mgmt_sgl_lock);
  1279. spin_lock_bh(&session->lock);
  1280. free_wrb_handle(phba, pwrb_context, pwrb_handle);
  1281. spin_unlock_bh(&session->lock);
  1282. }
  1283. static void
  1284. be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
  1285. struct iscsi_task *task, struct sol_cqe *psol)
  1286. {
  1287. struct iscsi_nopin *hdr;
  1288. struct iscsi_conn *conn = beiscsi_conn->conn;
  1289. struct beiscsi_io_task *io_task = task->dd_data;
  1290. hdr = (struct iscsi_nopin *)task->hdr;
  1291. hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
  1292. & SOL_FLAGS_MASK) >> 24) | 0x80;
  1293. hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
  1294. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
  1295. hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
  1296. i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
  1297. ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
  1298. / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
  1299. hdr->opcode = ISCSI_OP_NOOP_IN;
  1300. hdr->itt = io_task->libiscsi_itt;
  1301. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1302. }
  1303. static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
  1304. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1305. {
  1306. struct hwi_wrb_context *pwrb_context;
  1307. struct wrb_handle *pwrb_handle;
  1308. struct iscsi_wrb *pwrb = NULL;
  1309. struct hwi_controller *phwi_ctrlr;
  1310. struct iscsi_task *task;
  1311. unsigned int type;
  1312. struct iscsi_conn *conn = beiscsi_conn->conn;
  1313. struct iscsi_session *session = conn->session;
  1314. phwi_ctrlr = phba->phwi_ctrlr;
  1315. pwrb_context = &phwi_ctrlr->wrb_context[((psol->dw[offsetof
  1316. (struct amap_sol_cqe, cid) / 32]
  1317. & SOL_CID_MASK) >> 6) -
  1318. phba->fw_config.iscsi_cid_start];
  1319. pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
  1320. dw[offsetof(struct amap_sol_cqe, wrb_index) /
  1321. 32] & SOL_WRB_INDEX_MASK) >> 16)];
  1322. task = pwrb_handle->pio_handle;
  1323. pwrb = pwrb_handle->pwrb;
  1324. type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
  1325. WRB_TYPE_MASK) >> 28;
  1326. spin_lock_bh(&session->lock);
  1327. switch (type) {
  1328. case HWH_TYPE_IO:
  1329. case HWH_TYPE_IO_RD:
  1330. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
  1331. ISCSI_OP_NOOP_OUT)
  1332. be_complete_nopin_resp(beiscsi_conn, task, psol);
  1333. else
  1334. be_complete_io(beiscsi_conn, task, psol);
  1335. break;
  1336. case HWH_TYPE_LOGOUT:
  1337. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
  1338. be_complete_logout(beiscsi_conn, task, psol);
  1339. else
  1340. be_complete_tmf(beiscsi_conn, task, psol);
  1341. break;
  1342. case HWH_TYPE_LOGIN:
  1343. beiscsi_log(phba, KERN_ERR,
  1344. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1345. "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
  1346. " hwi_complete_cmd- Solicited path\n");
  1347. break;
  1348. case HWH_TYPE_NOP:
  1349. be_complete_nopin_resp(beiscsi_conn, task, psol);
  1350. break;
  1351. default:
  1352. beiscsi_log(phba, KERN_WARNING,
  1353. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1354. "BM_%d : In hwi_complete_cmd, unknown type = %d"
  1355. "wrb_index 0x%x CID 0x%x\n", type,
  1356. ((psol->dw[offsetof(struct amap_iscsi_wrb,
  1357. type) / 32] & SOL_WRB_INDEX_MASK) >> 16),
  1358. ((psol->dw[offsetof(struct amap_sol_cqe,
  1359. cid) / 32] & SOL_CID_MASK) >> 6));
  1360. break;
  1361. }
  1362. spin_unlock_bh(&session->lock);
  1363. }
  1364. static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
  1365. *pasync_ctx, unsigned int is_header,
  1366. unsigned int host_write_ptr)
  1367. {
  1368. if (is_header)
  1369. return &pasync_ctx->async_entry[host_write_ptr].
  1370. header_busy_list;
  1371. else
  1372. return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
  1373. }
  1374. static struct async_pdu_handle *
  1375. hwi_get_async_handle(struct beiscsi_hba *phba,
  1376. struct beiscsi_conn *beiscsi_conn,
  1377. struct hwi_async_pdu_context *pasync_ctx,
  1378. struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
  1379. {
  1380. struct be_bus_address phys_addr;
  1381. struct list_head *pbusy_list;
  1382. struct async_pdu_handle *pasync_handle = NULL;
  1383. unsigned char is_header = 0;
  1384. phys_addr.u.a32.address_lo =
  1385. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_lo) / 32] -
  1386. ((pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
  1387. & PDUCQE_DPL_MASK) >> 16);
  1388. phys_addr.u.a32.address_hi =
  1389. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_hi) / 32];
  1390. phys_addr.u.a64.address =
  1391. *((unsigned long long *)(&phys_addr.u.a64.address));
  1392. switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
  1393. & PDUCQE_CODE_MASK) {
  1394. case UNSOL_HDR_NOTIFY:
  1395. is_header = 1;
  1396. pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1,
  1397. (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1398. index) / 32] & PDUCQE_INDEX_MASK));
  1399. break;
  1400. case UNSOL_DATA_NOTIFY:
  1401. pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe->
  1402. dw[offsetof(struct amap_i_t_dpdu_cqe,
  1403. index) / 32] & PDUCQE_INDEX_MASK));
  1404. break;
  1405. default:
  1406. pbusy_list = NULL;
  1407. beiscsi_log(phba, KERN_WARNING,
  1408. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1409. "BM_%d : Unexpected code=%d\n",
  1410. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1411. code) / 32] & PDUCQE_CODE_MASK);
  1412. return NULL;
  1413. }
  1414. WARN_ON(list_empty(pbusy_list));
  1415. list_for_each_entry(pasync_handle, pbusy_list, link) {
  1416. if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
  1417. break;
  1418. }
  1419. WARN_ON(!pasync_handle);
  1420. pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid -
  1421. phba->fw_config.iscsi_cid_start;
  1422. pasync_handle->is_header = is_header;
  1423. pasync_handle->buffer_len = ((pdpdu_cqe->
  1424. dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
  1425. & PDUCQE_DPL_MASK) >> 16);
  1426. *pcq_index = (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1427. index) / 32] & PDUCQE_INDEX_MASK);
  1428. return pasync_handle;
  1429. }
  1430. static unsigned int
  1431. hwi_update_async_writables(struct beiscsi_hba *phba,
  1432. struct hwi_async_pdu_context *pasync_ctx,
  1433. unsigned int is_header, unsigned int cq_index)
  1434. {
  1435. struct list_head *pbusy_list;
  1436. struct async_pdu_handle *pasync_handle;
  1437. unsigned int num_entries, writables = 0;
  1438. unsigned int *pep_read_ptr, *pwritables;
  1439. num_entries = pasync_ctx->num_entries;
  1440. if (is_header) {
  1441. pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
  1442. pwritables = &pasync_ctx->async_header.writables;
  1443. } else {
  1444. pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
  1445. pwritables = &pasync_ctx->async_data.writables;
  1446. }
  1447. while ((*pep_read_ptr) != cq_index) {
  1448. (*pep_read_ptr)++;
  1449. *pep_read_ptr = (*pep_read_ptr) % num_entries;
  1450. pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
  1451. *pep_read_ptr);
  1452. if (writables == 0)
  1453. WARN_ON(list_empty(pbusy_list));
  1454. if (!list_empty(pbusy_list)) {
  1455. pasync_handle = list_entry(pbusy_list->next,
  1456. struct async_pdu_handle,
  1457. link);
  1458. WARN_ON(!pasync_handle);
  1459. pasync_handle->consumed = 1;
  1460. }
  1461. writables++;
  1462. }
  1463. if (!writables) {
  1464. beiscsi_log(phba, KERN_ERR,
  1465. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1466. "BM_%d : Duplicate notification received - index 0x%x!!\n",
  1467. cq_index);
  1468. WARN_ON(1);
  1469. }
  1470. *pwritables = *pwritables + writables;
  1471. return 0;
  1472. }
  1473. static void hwi_free_async_msg(struct beiscsi_hba *phba,
  1474. unsigned int cri)
  1475. {
  1476. struct hwi_controller *phwi_ctrlr;
  1477. struct hwi_async_pdu_context *pasync_ctx;
  1478. struct async_pdu_handle *pasync_handle, *tmp_handle;
  1479. struct list_head *plist;
  1480. phwi_ctrlr = phba->phwi_ctrlr;
  1481. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1482. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1483. list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
  1484. list_del(&pasync_handle->link);
  1485. if (pasync_handle->is_header) {
  1486. list_add_tail(&pasync_handle->link,
  1487. &pasync_ctx->async_header.free_list);
  1488. pasync_ctx->async_header.free_entries++;
  1489. } else {
  1490. list_add_tail(&pasync_handle->link,
  1491. &pasync_ctx->async_data.free_list);
  1492. pasync_ctx->async_data.free_entries++;
  1493. }
  1494. }
  1495. INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
  1496. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
  1497. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1498. }
  1499. static struct phys_addr *
  1500. hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
  1501. unsigned int is_header, unsigned int host_write_ptr)
  1502. {
  1503. struct phys_addr *pasync_sge = NULL;
  1504. if (is_header)
  1505. pasync_sge = pasync_ctx->async_header.ring_base;
  1506. else
  1507. pasync_sge = pasync_ctx->async_data.ring_base;
  1508. return pasync_sge + host_write_ptr;
  1509. }
  1510. static void hwi_post_async_buffers(struct beiscsi_hba *phba,
  1511. unsigned int is_header)
  1512. {
  1513. struct hwi_controller *phwi_ctrlr;
  1514. struct hwi_async_pdu_context *pasync_ctx;
  1515. struct async_pdu_handle *pasync_handle;
  1516. struct list_head *pfree_link, *pbusy_list;
  1517. struct phys_addr *pasync_sge;
  1518. unsigned int ring_id, num_entries;
  1519. unsigned int host_write_num;
  1520. unsigned int writables;
  1521. unsigned int i = 0;
  1522. u32 doorbell = 0;
  1523. phwi_ctrlr = phba->phwi_ctrlr;
  1524. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1525. num_entries = pasync_ctx->num_entries;
  1526. if (is_header) {
  1527. writables = min(pasync_ctx->async_header.writables,
  1528. pasync_ctx->async_header.free_entries);
  1529. pfree_link = pasync_ctx->async_header.free_list.next;
  1530. host_write_num = pasync_ctx->async_header.host_write_ptr;
  1531. ring_id = phwi_ctrlr->default_pdu_hdr.id;
  1532. } else {
  1533. writables = min(pasync_ctx->async_data.writables,
  1534. pasync_ctx->async_data.free_entries);
  1535. pfree_link = pasync_ctx->async_data.free_list.next;
  1536. host_write_num = pasync_ctx->async_data.host_write_ptr;
  1537. ring_id = phwi_ctrlr->default_pdu_data.id;
  1538. }
  1539. writables = (writables / 8) * 8;
  1540. if (writables) {
  1541. for (i = 0; i < writables; i++) {
  1542. pbusy_list =
  1543. hwi_get_async_busy_list(pasync_ctx, is_header,
  1544. host_write_num);
  1545. pasync_handle =
  1546. list_entry(pfree_link, struct async_pdu_handle,
  1547. link);
  1548. WARN_ON(!pasync_handle);
  1549. pasync_handle->consumed = 0;
  1550. pfree_link = pfree_link->next;
  1551. pasync_sge = hwi_get_ring_address(pasync_ctx,
  1552. is_header, host_write_num);
  1553. pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
  1554. pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
  1555. list_move(&pasync_handle->link, pbusy_list);
  1556. host_write_num++;
  1557. host_write_num = host_write_num % num_entries;
  1558. }
  1559. if (is_header) {
  1560. pasync_ctx->async_header.host_write_ptr =
  1561. host_write_num;
  1562. pasync_ctx->async_header.free_entries -= writables;
  1563. pasync_ctx->async_header.writables -= writables;
  1564. pasync_ctx->async_header.busy_entries += writables;
  1565. } else {
  1566. pasync_ctx->async_data.host_write_ptr = host_write_num;
  1567. pasync_ctx->async_data.free_entries -= writables;
  1568. pasync_ctx->async_data.writables -= writables;
  1569. pasync_ctx->async_data.busy_entries += writables;
  1570. }
  1571. doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
  1572. doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
  1573. doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
  1574. doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
  1575. << DB_DEF_PDU_CQPROC_SHIFT;
  1576. iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
  1577. }
  1578. }
  1579. static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
  1580. struct beiscsi_conn *beiscsi_conn,
  1581. struct i_t_dpdu_cqe *pdpdu_cqe)
  1582. {
  1583. struct hwi_controller *phwi_ctrlr;
  1584. struct hwi_async_pdu_context *pasync_ctx;
  1585. struct async_pdu_handle *pasync_handle = NULL;
  1586. unsigned int cq_index = -1;
  1587. phwi_ctrlr = phba->phwi_ctrlr;
  1588. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1589. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1590. pdpdu_cqe, &cq_index);
  1591. BUG_ON(pasync_handle->is_header != 0);
  1592. if (pasync_handle->consumed == 0)
  1593. hwi_update_async_writables(phba, pasync_ctx,
  1594. pasync_handle->is_header, cq_index);
  1595. hwi_free_async_msg(phba, pasync_handle->cri);
  1596. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1597. }
  1598. static unsigned int
  1599. hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
  1600. struct beiscsi_hba *phba,
  1601. struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
  1602. {
  1603. struct list_head *plist;
  1604. struct async_pdu_handle *pasync_handle;
  1605. void *phdr = NULL;
  1606. unsigned int hdr_len = 0, buf_len = 0;
  1607. unsigned int status, index = 0, offset = 0;
  1608. void *pfirst_buffer = NULL;
  1609. unsigned int num_buf = 0;
  1610. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1611. list_for_each_entry(pasync_handle, plist, link) {
  1612. if (index == 0) {
  1613. phdr = pasync_handle->pbuffer;
  1614. hdr_len = pasync_handle->buffer_len;
  1615. } else {
  1616. buf_len = pasync_handle->buffer_len;
  1617. if (!num_buf) {
  1618. pfirst_buffer = pasync_handle->pbuffer;
  1619. num_buf++;
  1620. }
  1621. memcpy(pfirst_buffer + offset,
  1622. pasync_handle->pbuffer, buf_len);
  1623. offset += buf_len;
  1624. }
  1625. index++;
  1626. }
  1627. status = beiscsi_process_async_pdu(beiscsi_conn, phba,
  1628. (beiscsi_conn->beiscsi_conn_cid -
  1629. phba->fw_config.iscsi_cid_start),
  1630. phdr, hdr_len, pfirst_buffer,
  1631. offset);
  1632. hwi_free_async_msg(phba, cri);
  1633. return 0;
  1634. }
  1635. static unsigned int
  1636. hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
  1637. struct beiscsi_hba *phba,
  1638. struct async_pdu_handle *pasync_handle)
  1639. {
  1640. struct hwi_async_pdu_context *pasync_ctx;
  1641. struct hwi_controller *phwi_ctrlr;
  1642. unsigned int bytes_needed = 0, status = 0;
  1643. unsigned short cri = pasync_handle->cri;
  1644. struct pdu_base *ppdu;
  1645. phwi_ctrlr = phba->phwi_ctrlr;
  1646. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1647. list_del(&pasync_handle->link);
  1648. if (pasync_handle->is_header) {
  1649. pasync_ctx->async_header.busy_entries--;
  1650. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1651. hwi_free_async_msg(phba, cri);
  1652. BUG();
  1653. }
  1654. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1655. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
  1656. pasync_ctx->async_entry[cri].wait_queue.hdr_len =
  1657. (unsigned short)pasync_handle->buffer_len;
  1658. list_add_tail(&pasync_handle->link,
  1659. &pasync_ctx->async_entry[cri].wait_queue.list);
  1660. ppdu = pasync_handle->pbuffer;
  1661. bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
  1662. data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
  1663. 0xFFFF0000) | ((be16_to_cpu((ppdu->
  1664. dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
  1665. & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
  1666. if (status == 0) {
  1667. pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
  1668. bytes_needed;
  1669. if (bytes_needed == 0)
  1670. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1671. pasync_ctx, cri);
  1672. }
  1673. } else {
  1674. pasync_ctx->async_data.busy_entries--;
  1675. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1676. list_add_tail(&pasync_handle->link,
  1677. &pasync_ctx->async_entry[cri].wait_queue.
  1678. list);
  1679. pasync_ctx->async_entry[cri].wait_queue.
  1680. bytes_received +=
  1681. (unsigned short)pasync_handle->buffer_len;
  1682. if (pasync_ctx->async_entry[cri].wait_queue.
  1683. bytes_received >=
  1684. pasync_ctx->async_entry[cri].wait_queue.
  1685. bytes_needed)
  1686. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1687. pasync_ctx, cri);
  1688. }
  1689. }
  1690. return status;
  1691. }
  1692. static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
  1693. struct beiscsi_hba *phba,
  1694. struct i_t_dpdu_cqe *pdpdu_cqe)
  1695. {
  1696. struct hwi_controller *phwi_ctrlr;
  1697. struct hwi_async_pdu_context *pasync_ctx;
  1698. struct async_pdu_handle *pasync_handle = NULL;
  1699. unsigned int cq_index = -1;
  1700. phwi_ctrlr = phba->phwi_ctrlr;
  1701. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1702. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1703. pdpdu_cqe, &cq_index);
  1704. if (pasync_handle->consumed == 0)
  1705. hwi_update_async_writables(phba, pasync_ctx,
  1706. pasync_handle->is_header, cq_index);
  1707. hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
  1708. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1709. }
  1710. static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
  1711. {
  1712. struct be_queue_info *mcc_cq;
  1713. struct be_mcc_compl *mcc_compl;
  1714. unsigned int num_processed = 0;
  1715. mcc_cq = &phba->ctrl.mcc_obj.cq;
  1716. mcc_compl = queue_tail_node(mcc_cq);
  1717. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1718. while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
  1719. if (num_processed >= 32) {
  1720. hwi_ring_cq_db(phba, mcc_cq->id,
  1721. num_processed, 0, 0);
  1722. num_processed = 0;
  1723. }
  1724. if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
  1725. /* Interpret flags as an async trailer */
  1726. if (is_link_state_evt(mcc_compl->flags))
  1727. /* Interpret compl as a async link evt */
  1728. beiscsi_async_link_state_process(phba,
  1729. (struct be_async_event_link_state *) mcc_compl);
  1730. else
  1731. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
  1732. "BM_%d : Unsupported Async Event, flags"
  1733. " = 0x%08x\n",
  1734. mcc_compl->flags);
  1735. } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  1736. be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
  1737. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  1738. }
  1739. mcc_compl->flags = 0;
  1740. queue_tail_inc(mcc_cq);
  1741. mcc_compl = queue_tail_node(mcc_cq);
  1742. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1743. num_processed++;
  1744. }
  1745. if (num_processed > 0)
  1746. hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
  1747. }
  1748. /**
  1749. * beiscsi_process_cq()- Process the Completion Queue
  1750. * @pbe_eq: Event Q on which the Completion has come
  1751. *
  1752. * return
  1753. * Number of Completion Entries processed.
  1754. **/
  1755. static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
  1756. {
  1757. struct be_queue_info *cq;
  1758. struct sol_cqe *sol;
  1759. struct dmsg_cqe *dmsg;
  1760. unsigned int num_processed = 0;
  1761. unsigned int tot_nump = 0;
  1762. unsigned short code = 0, cid = 0;
  1763. struct beiscsi_conn *beiscsi_conn;
  1764. struct beiscsi_endpoint *beiscsi_ep;
  1765. struct iscsi_endpoint *ep;
  1766. struct beiscsi_hba *phba;
  1767. cq = pbe_eq->cq;
  1768. sol = queue_tail_node(cq);
  1769. phba = pbe_eq->phba;
  1770. while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
  1771. CQE_VALID_MASK) {
  1772. be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
  1773. cid = ((sol->dw[offsetof(struct amap_sol_cqe, cid)/32] &
  1774. CQE_CID_MASK) >> 6);
  1775. code = (sol->dw[offsetof(struct amap_sol_cqe, code)/32] &
  1776. CQE_CODE_MASK);
  1777. ep = phba->ep_array[cid - phba->fw_config.iscsi_cid_start];
  1778. beiscsi_ep = ep->dd_data;
  1779. beiscsi_conn = beiscsi_ep->conn;
  1780. if (num_processed >= 32) {
  1781. hwi_ring_cq_db(phba, cq->id,
  1782. num_processed, 0, 0);
  1783. tot_nump += num_processed;
  1784. num_processed = 0;
  1785. }
  1786. switch (code) {
  1787. case SOL_CMD_COMPLETE:
  1788. hwi_complete_cmd(beiscsi_conn, phba, sol);
  1789. break;
  1790. case DRIVERMSG_NOTIFY:
  1791. beiscsi_log(phba, KERN_INFO,
  1792. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1793. "BM_%d : Received %s[%d] on CID : %d\n",
  1794. cqe_desc[code], code, cid);
  1795. dmsg = (struct dmsg_cqe *)sol;
  1796. hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
  1797. break;
  1798. case UNSOL_HDR_NOTIFY:
  1799. beiscsi_log(phba, KERN_INFO,
  1800. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1801. "BM_%d : Received %s[%d] on CID : %d\n",
  1802. cqe_desc[code], code, cid);
  1803. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1804. (struct i_t_dpdu_cqe *)sol);
  1805. break;
  1806. case UNSOL_DATA_NOTIFY:
  1807. beiscsi_log(phba, KERN_INFO,
  1808. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1809. "BM_%d : Received %s[%d] on CID : %d\n",
  1810. cqe_desc[code], code, cid);
  1811. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1812. (struct i_t_dpdu_cqe *)sol);
  1813. break;
  1814. case CXN_INVALIDATE_INDEX_NOTIFY:
  1815. case CMD_INVALIDATED_NOTIFY:
  1816. case CXN_INVALIDATE_NOTIFY:
  1817. beiscsi_log(phba, KERN_ERR,
  1818. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1819. "BM_%d : Ignoring %s[%d] on CID : %d\n",
  1820. cqe_desc[code], code, cid);
  1821. break;
  1822. case SOL_CMD_KILLED_DATA_DIGEST_ERR:
  1823. case CMD_KILLED_INVALID_STATSN_RCVD:
  1824. case CMD_KILLED_INVALID_R2T_RCVD:
  1825. case CMD_CXN_KILLED_LUN_INVALID:
  1826. case CMD_CXN_KILLED_ICD_INVALID:
  1827. case CMD_CXN_KILLED_ITT_INVALID:
  1828. case CMD_CXN_KILLED_SEQ_OUTOFORDER:
  1829. case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
  1830. beiscsi_log(phba, KERN_ERR,
  1831. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1832. "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
  1833. cqe_desc[code], code, cid);
  1834. break;
  1835. case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
  1836. beiscsi_log(phba, KERN_ERR,
  1837. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1838. "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
  1839. cqe_desc[code], code, cid);
  1840. hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
  1841. (struct i_t_dpdu_cqe *) sol);
  1842. break;
  1843. case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
  1844. case CXN_KILLED_BURST_LEN_MISMATCH:
  1845. case CXN_KILLED_AHS_RCVD:
  1846. case CXN_KILLED_HDR_DIGEST_ERR:
  1847. case CXN_KILLED_UNKNOWN_HDR:
  1848. case CXN_KILLED_STALE_ITT_TTT_RCVD:
  1849. case CXN_KILLED_INVALID_ITT_TTT_RCVD:
  1850. case CXN_KILLED_TIMED_OUT:
  1851. case CXN_KILLED_FIN_RCVD:
  1852. case CXN_KILLED_RST_SENT:
  1853. case CXN_KILLED_RST_RCVD:
  1854. case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
  1855. case CXN_KILLED_BAD_WRB_INDEX_ERROR:
  1856. case CXN_KILLED_OVER_RUN_RESIDUAL:
  1857. case CXN_KILLED_UNDER_RUN_RESIDUAL:
  1858. case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
  1859. beiscsi_log(phba, KERN_ERR,
  1860. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1861. "BM_%d : Event %s[%d] received on CID : %d\n",
  1862. cqe_desc[code], code, cid);
  1863. if (beiscsi_conn)
  1864. iscsi_conn_failure(beiscsi_conn->conn,
  1865. ISCSI_ERR_CONN_FAILED);
  1866. break;
  1867. default:
  1868. beiscsi_log(phba, KERN_ERR,
  1869. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1870. "BM_%d : Invalid CQE Event Received Code : %d"
  1871. "CID 0x%x...\n",
  1872. code, cid);
  1873. break;
  1874. }
  1875. AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
  1876. queue_tail_inc(cq);
  1877. sol = queue_tail_node(cq);
  1878. num_processed++;
  1879. }
  1880. if (num_processed > 0) {
  1881. tot_nump += num_processed;
  1882. hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
  1883. }
  1884. return tot_nump;
  1885. }
  1886. void beiscsi_process_all_cqs(struct work_struct *work)
  1887. {
  1888. unsigned long flags;
  1889. struct hwi_controller *phwi_ctrlr;
  1890. struct hwi_context_memory *phwi_context;
  1891. struct beiscsi_hba *phba;
  1892. struct be_eq_obj *pbe_eq =
  1893. container_of(work, struct be_eq_obj, work_cqs);
  1894. phba = pbe_eq->phba;
  1895. phwi_ctrlr = phba->phwi_ctrlr;
  1896. phwi_context = phwi_ctrlr->phwi_ctxt;
  1897. if (pbe_eq->todo_mcc_cq) {
  1898. spin_lock_irqsave(&phba->isr_lock, flags);
  1899. pbe_eq->todo_mcc_cq = false;
  1900. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1901. beiscsi_process_mcc_isr(phba);
  1902. }
  1903. if (pbe_eq->todo_cq) {
  1904. spin_lock_irqsave(&phba->isr_lock, flags);
  1905. pbe_eq->todo_cq = false;
  1906. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1907. beiscsi_process_cq(pbe_eq);
  1908. }
  1909. /* rearm EQ for further interrupts */
  1910. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  1911. }
  1912. static int be_iopoll(struct blk_iopoll *iop, int budget)
  1913. {
  1914. static unsigned int ret;
  1915. struct beiscsi_hba *phba;
  1916. struct be_eq_obj *pbe_eq;
  1917. pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
  1918. ret = beiscsi_process_cq(pbe_eq);
  1919. if (ret < budget) {
  1920. phba = pbe_eq->phba;
  1921. blk_iopoll_complete(iop);
  1922. beiscsi_log(phba, KERN_INFO,
  1923. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1924. "BM_%d : rearm pbe_eq->q.id =%d\n",
  1925. pbe_eq->q.id);
  1926. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  1927. }
  1928. return ret;
  1929. }
  1930. static void
  1931. hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  1932. unsigned int num_sg, struct beiscsi_io_task *io_task)
  1933. {
  1934. struct iscsi_sge *psgl;
  1935. unsigned int sg_len, index;
  1936. unsigned int sge_len = 0;
  1937. unsigned long long addr;
  1938. struct scatterlist *l_sg;
  1939. unsigned int offset;
  1940. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
  1941. io_task->bhs_pa.u.a32.address_lo);
  1942. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
  1943. io_task->bhs_pa.u.a32.address_hi);
  1944. l_sg = sg;
  1945. for (index = 0; (index < num_sg) && (index < 2); index++,
  1946. sg = sg_next(sg)) {
  1947. if (index == 0) {
  1948. sg_len = sg_dma_len(sg);
  1949. addr = (u64) sg_dma_address(sg);
  1950. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1951. sge0_addr_lo, pwrb,
  1952. lower_32_bits(addr));
  1953. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1954. sge0_addr_hi, pwrb,
  1955. upper_32_bits(addr));
  1956. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1957. sge0_len, pwrb,
  1958. sg_len);
  1959. sge_len = sg_len;
  1960. } else {
  1961. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
  1962. pwrb, sge_len);
  1963. sg_len = sg_dma_len(sg);
  1964. addr = (u64) sg_dma_address(sg);
  1965. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1966. sge1_addr_lo, pwrb,
  1967. lower_32_bits(addr));
  1968. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1969. sge1_addr_hi, pwrb,
  1970. upper_32_bits(addr));
  1971. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1972. sge1_len, pwrb,
  1973. sg_len);
  1974. }
  1975. }
  1976. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  1977. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  1978. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  1979. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  1980. io_task->bhs_pa.u.a32.address_hi);
  1981. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  1982. io_task->bhs_pa.u.a32.address_lo);
  1983. if (num_sg == 1) {
  1984. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  1985. 1);
  1986. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  1987. 0);
  1988. } else if (num_sg == 2) {
  1989. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  1990. 0);
  1991. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  1992. 1);
  1993. } else {
  1994. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  1995. 0);
  1996. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  1997. 0);
  1998. }
  1999. sg = l_sg;
  2000. psgl++;
  2001. psgl++;
  2002. offset = 0;
  2003. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  2004. sg_len = sg_dma_len(sg);
  2005. addr = (u64) sg_dma_address(sg);
  2006. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2007. lower_32_bits(addr));
  2008. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2009. upper_32_bits(addr));
  2010. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  2011. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  2012. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2013. offset += sg_len;
  2014. }
  2015. psgl--;
  2016. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2017. }
  2018. static void
  2019. hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  2020. unsigned int num_sg, struct beiscsi_io_task *io_task)
  2021. {
  2022. struct iscsi_sge *psgl;
  2023. unsigned int sg_len, index;
  2024. unsigned int sge_len = 0;
  2025. unsigned long long addr;
  2026. struct scatterlist *l_sg;
  2027. unsigned int offset;
  2028. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  2029. io_task->bhs_pa.u.a32.address_lo);
  2030. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  2031. io_task->bhs_pa.u.a32.address_hi);
  2032. l_sg = sg;
  2033. for (index = 0; (index < num_sg) && (index < 2); index++,
  2034. sg = sg_next(sg)) {
  2035. if (index == 0) {
  2036. sg_len = sg_dma_len(sg);
  2037. addr = (u64) sg_dma_address(sg);
  2038. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  2039. ((u32)(addr & 0xFFFFFFFF)));
  2040. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  2041. ((u32)(addr >> 32)));
  2042. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  2043. sg_len);
  2044. sge_len = sg_len;
  2045. } else {
  2046. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
  2047. pwrb, sge_len);
  2048. sg_len = sg_dma_len(sg);
  2049. addr = (u64) sg_dma_address(sg);
  2050. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
  2051. ((u32)(addr & 0xFFFFFFFF)));
  2052. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
  2053. ((u32)(addr >> 32)));
  2054. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
  2055. sg_len);
  2056. }
  2057. }
  2058. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2059. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  2060. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  2061. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2062. io_task->bhs_pa.u.a32.address_hi);
  2063. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2064. io_task->bhs_pa.u.a32.address_lo);
  2065. if (num_sg == 1) {
  2066. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2067. 1);
  2068. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2069. 0);
  2070. } else if (num_sg == 2) {
  2071. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2072. 0);
  2073. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2074. 1);
  2075. } else {
  2076. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2077. 0);
  2078. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2079. 0);
  2080. }
  2081. sg = l_sg;
  2082. psgl++;
  2083. psgl++;
  2084. offset = 0;
  2085. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  2086. sg_len = sg_dma_len(sg);
  2087. addr = (u64) sg_dma_address(sg);
  2088. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2089. (addr & 0xFFFFFFFF));
  2090. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2091. (addr >> 32));
  2092. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  2093. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  2094. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2095. offset += sg_len;
  2096. }
  2097. psgl--;
  2098. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2099. }
  2100. /**
  2101. * hwi_write_buffer()- Populate the WRB with task info
  2102. * @pwrb: ptr to the WRB entry
  2103. * @task: iscsi task which is to be executed
  2104. **/
  2105. static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
  2106. {
  2107. struct iscsi_sge *psgl;
  2108. struct beiscsi_io_task *io_task = task->dd_data;
  2109. struct beiscsi_conn *beiscsi_conn = io_task->conn;
  2110. struct beiscsi_hba *phba = beiscsi_conn->phba;
  2111. uint8_t dsp_value = 0;
  2112. io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
  2113. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  2114. io_task->bhs_pa.u.a32.address_lo);
  2115. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  2116. io_task->bhs_pa.u.a32.address_hi);
  2117. if (task->data) {
  2118. /* Check for the data_count */
  2119. dsp_value = (task->data_count) ? 1 : 0;
  2120. if (chip_skh_r(phba->pcidev))
  2121. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
  2122. pwrb, dsp_value);
  2123. else
  2124. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
  2125. pwrb, dsp_value);
  2126. /* Map addr only if there is data_count */
  2127. if (dsp_value) {
  2128. io_task->mtask_addr = pci_map_single(phba->pcidev,
  2129. task->data,
  2130. task->data_count,
  2131. PCI_DMA_TODEVICE);
  2132. io_task->mtask_data_count = task->data_count;
  2133. } else
  2134. io_task->mtask_addr = 0;
  2135. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  2136. lower_32_bits(io_task->mtask_addr));
  2137. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  2138. upper_32_bits(io_task->mtask_addr));
  2139. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  2140. task->data_count);
  2141. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
  2142. } else {
  2143. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  2144. io_task->mtask_addr = 0;
  2145. }
  2146. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2147. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
  2148. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2149. io_task->bhs_pa.u.a32.address_hi);
  2150. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2151. io_task->bhs_pa.u.a32.address_lo);
  2152. if (task->data) {
  2153. psgl++;
  2154. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
  2155. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
  2156. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
  2157. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
  2158. AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
  2159. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2160. psgl++;
  2161. if (task->data) {
  2162. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2163. lower_32_bits(io_task->mtask_addr));
  2164. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2165. upper_32_bits(io_task->mtask_addr));
  2166. }
  2167. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
  2168. }
  2169. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2170. }
  2171. static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
  2172. {
  2173. unsigned int num_cq_pages, num_async_pdu_buf_pages;
  2174. unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
  2175. unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
  2176. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2177. sizeof(struct sol_cqe));
  2178. num_async_pdu_buf_pages =
  2179. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2180. phba->params.defpdu_hdr_sz);
  2181. num_async_pdu_buf_sgl_pages =
  2182. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2183. sizeof(struct phys_addr));
  2184. num_async_pdu_data_pages =
  2185. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2186. phba->params.defpdu_data_sz);
  2187. num_async_pdu_data_sgl_pages =
  2188. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2189. sizeof(struct phys_addr));
  2190. phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
  2191. phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
  2192. BE_ISCSI_PDU_HEADER_SIZE;
  2193. phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
  2194. sizeof(struct hwi_context_memory);
  2195. phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
  2196. * (phba->params.wrbs_per_cxn)
  2197. * phba->params.cxns_per_ctrl;
  2198. wrb_sz_per_cxn = sizeof(struct wrb_handle) *
  2199. (phba->params.wrbs_per_cxn);
  2200. phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
  2201. phba->params.cxns_per_ctrl);
  2202. phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
  2203. phba->params.icds_per_ctrl;
  2204. phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
  2205. phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
  2206. phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
  2207. num_async_pdu_buf_pages * PAGE_SIZE;
  2208. phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
  2209. num_async_pdu_data_pages * PAGE_SIZE;
  2210. phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
  2211. num_async_pdu_buf_sgl_pages * PAGE_SIZE;
  2212. phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
  2213. num_async_pdu_data_sgl_pages * PAGE_SIZE;
  2214. phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
  2215. phba->params.asyncpdus_per_ctrl *
  2216. sizeof(struct async_pdu_handle);
  2217. phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
  2218. phba->params.asyncpdus_per_ctrl *
  2219. sizeof(struct async_pdu_handle);
  2220. phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
  2221. sizeof(struct hwi_async_pdu_context) +
  2222. (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
  2223. }
  2224. static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
  2225. {
  2226. struct be_mem_descriptor *mem_descr;
  2227. dma_addr_t bus_add;
  2228. struct mem_array *mem_arr, *mem_arr_orig;
  2229. unsigned int i, j, alloc_size, curr_alloc_size;
  2230. phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
  2231. if (!phba->phwi_ctrlr)
  2232. return -ENOMEM;
  2233. phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
  2234. GFP_KERNEL);
  2235. if (!phba->init_mem) {
  2236. kfree(phba->phwi_ctrlr);
  2237. return -ENOMEM;
  2238. }
  2239. mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
  2240. GFP_KERNEL);
  2241. if (!mem_arr_orig) {
  2242. kfree(phba->init_mem);
  2243. kfree(phba->phwi_ctrlr);
  2244. return -ENOMEM;
  2245. }
  2246. mem_descr = phba->init_mem;
  2247. for (i = 0; i < SE_MEM_MAX; i++) {
  2248. j = 0;
  2249. mem_arr = mem_arr_orig;
  2250. alloc_size = phba->mem_req[i];
  2251. memset(mem_arr, 0, sizeof(struct mem_array) *
  2252. BEISCSI_MAX_FRAGS_INIT);
  2253. curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
  2254. do {
  2255. mem_arr->virtual_address = pci_alloc_consistent(
  2256. phba->pcidev,
  2257. curr_alloc_size,
  2258. &bus_add);
  2259. if (!mem_arr->virtual_address) {
  2260. if (curr_alloc_size <= BE_MIN_MEM_SIZE)
  2261. goto free_mem;
  2262. if (curr_alloc_size -
  2263. rounddown_pow_of_two(curr_alloc_size))
  2264. curr_alloc_size = rounddown_pow_of_two
  2265. (curr_alloc_size);
  2266. else
  2267. curr_alloc_size = curr_alloc_size / 2;
  2268. } else {
  2269. mem_arr->bus_address.u.
  2270. a64.address = (__u64) bus_add;
  2271. mem_arr->size = curr_alloc_size;
  2272. alloc_size -= curr_alloc_size;
  2273. curr_alloc_size = min(be_max_phys_size *
  2274. 1024, alloc_size);
  2275. j++;
  2276. mem_arr++;
  2277. }
  2278. } while (alloc_size);
  2279. mem_descr->num_elements = j;
  2280. mem_descr->size_in_bytes = phba->mem_req[i];
  2281. mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
  2282. GFP_KERNEL);
  2283. if (!mem_descr->mem_array)
  2284. goto free_mem;
  2285. memcpy(mem_descr->mem_array, mem_arr_orig,
  2286. sizeof(struct mem_array) * j);
  2287. mem_descr++;
  2288. }
  2289. kfree(mem_arr_orig);
  2290. return 0;
  2291. free_mem:
  2292. mem_descr->num_elements = j;
  2293. while ((i) || (j)) {
  2294. for (j = mem_descr->num_elements; j > 0; j--) {
  2295. pci_free_consistent(phba->pcidev,
  2296. mem_descr->mem_array[j - 1].size,
  2297. mem_descr->mem_array[j - 1].
  2298. virtual_address,
  2299. (unsigned long)mem_descr->
  2300. mem_array[j - 1].
  2301. bus_address.u.a64.address);
  2302. }
  2303. if (i) {
  2304. i--;
  2305. kfree(mem_descr->mem_array);
  2306. mem_descr--;
  2307. }
  2308. }
  2309. kfree(mem_arr_orig);
  2310. kfree(phba->init_mem);
  2311. kfree(phba->phwi_ctrlr);
  2312. return -ENOMEM;
  2313. }
  2314. static int beiscsi_get_memory(struct beiscsi_hba *phba)
  2315. {
  2316. beiscsi_find_mem_req(phba);
  2317. return beiscsi_alloc_mem(phba);
  2318. }
  2319. static void iscsi_init_global_templates(struct beiscsi_hba *phba)
  2320. {
  2321. struct pdu_data_out *pdata_out;
  2322. struct pdu_nop_out *pnop_out;
  2323. struct be_mem_descriptor *mem_descr;
  2324. mem_descr = phba->init_mem;
  2325. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  2326. pdata_out =
  2327. (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
  2328. memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2329. AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
  2330. IIOC_SCSI_DATA);
  2331. pnop_out =
  2332. (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
  2333. virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
  2334. memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2335. AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
  2336. AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
  2337. AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
  2338. }
  2339. static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
  2340. {
  2341. struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
  2342. struct wrb_handle *pwrb_handle = NULL;
  2343. struct hwi_controller *phwi_ctrlr;
  2344. struct hwi_wrb_context *pwrb_context;
  2345. struct iscsi_wrb *pwrb = NULL;
  2346. unsigned int num_cxn_wrbh = 0;
  2347. unsigned int num_cxn_wrb = 0, j, idx = 0, index;
  2348. mem_descr_wrbh = phba->init_mem;
  2349. mem_descr_wrbh += HWI_MEM_WRBH;
  2350. mem_descr_wrb = phba->init_mem;
  2351. mem_descr_wrb += HWI_MEM_WRB;
  2352. phwi_ctrlr = phba->phwi_ctrlr;
  2353. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2354. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2355. pwrb_context->pwrb_handle_base =
  2356. kzalloc(sizeof(struct wrb_handle *) *
  2357. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2358. if (!pwrb_context->pwrb_handle_base) {
  2359. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2360. "BM_%d : Mem Alloc Failed. Failing to load\n");
  2361. goto init_wrb_hndl_failed;
  2362. }
  2363. pwrb_context->pwrb_handle_basestd =
  2364. kzalloc(sizeof(struct wrb_handle *) *
  2365. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2366. if (!pwrb_context->pwrb_handle_basestd) {
  2367. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2368. "BM_%d : Mem Alloc Failed. Failing to load\n");
  2369. goto init_wrb_hndl_failed;
  2370. }
  2371. if (!num_cxn_wrbh) {
  2372. pwrb_handle =
  2373. mem_descr_wrbh->mem_array[idx].virtual_address;
  2374. num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
  2375. ((sizeof(struct wrb_handle)) *
  2376. phba->params.wrbs_per_cxn));
  2377. idx++;
  2378. }
  2379. pwrb_context->alloc_index = 0;
  2380. pwrb_context->wrb_handles_available = 0;
  2381. pwrb_context->free_index = 0;
  2382. if (num_cxn_wrbh) {
  2383. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2384. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  2385. pwrb_context->pwrb_handle_basestd[j] =
  2386. pwrb_handle;
  2387. pwrb_context->wrb_handles_available++;
  2388. pwrb_handle->wrb_index = j;
  2389. pwrb_handle++;
  2390. }
  2391. num_cxn_wrbh--;
  2392. }
  2393. }
  2394. idx = 0;
  2395. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2396. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2397. if (!num_cxn_wrb) {
  2398. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  2399. num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
  2400. ((sizeof(struct iscsi_wrb) *
  2401. phba->params.wrbs_per_cxn));
  2402. idx++;
  2403. }
  2404. if (num_cxn_wrb) {
  2405. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2406. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  2407. pwrb_handle->pwrb = pwrb;
  2408. pwrb++;
  2409. }
  2410. num_cxn_wrb--;
  2411. }
  2412. }
  2413. return 0;
  2414. init_wrb_hndl_failed:
  2415. for (j = index; j > 0; j--) {
  2416. pwrb_context = &phwi_ctrlr->wrb_context[j];
  2417. kfree(pwrb_context->pwrb_handle_base);
  2418. kfree(pwrb_context->pwrb_handle_basestd);
  2419. }
  2420. return -ENOMEM;
  2421. }
  2422. static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
  2423. {
  2424. struct hwi_controller *phwi_ctrlr;
  2425. struct hba_parameters *p = &phba->params;
  2426. struct hwi_async_pdu_context *pasync_ctx;
  2427. struct async_pdu_handle *pasync_header_h, *pasync_data_h;
  2428. unsigned int index, idx, num_per_mem, num_async_data;
  2429. struct be_mem_descriptor *mem_descr;
  2430. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2431. mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
  2432. phwi_ctrlr = phba->phwi_ctrlr;
  2433. phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
  2434. mem_descr->mem_array[0].virtual_address;
  2435. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
  2436. memset(pasync_ctx, 0, sizeof(*pasync_ctx));
  2437. pasync_ctx->num_entries = p->asyncpdus_per_ctrl;
  2438. pasync_ctx->buffer_size = p->defpdu_hdr_sz;
  2439. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2440. mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
  2441. if (mem_descr->mem_array[0].virtual_address) {
  2442. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2443. "BM_%d : hwi_init_async_pdu_ctx"
  2444. " HWI_MEM_ASYNC_HEADER_BUF va=%p\n",
  2445. mem_descr->mem_array[0].virtual_address);
  2446. } else
  2447. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2448. "BM_%d : No Virtual address\n");
  2449. pasync_ctx->async_header.va_base =
  2450. mem_descr->mem_array[0].virtual_address;
  2451. pasync_ctx->async_header.pa_base.u.a64.address =
  2452. mem_descr->mem_array[0].bus_address.u.a64.address;
  2453. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2454. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2455. if (mem_descr->mem_array[0].virtual_address) {
  2456. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2457. "BM_%d : hwi_init_async_pdu_ctx"
  2458. " HWI_MEM_ASYNC_HEADER_RING va=%p\n",
  2459. mem_descr->mem_array[0].virtual_address);
  2460. } else
  2461. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2462. "BM_%d : No Virtual address\n");
  2463. pasync_ctx->async_header.ring_base =
  2464. mem_descr->mem_array[0].virtual_address;
  2465. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2466. mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
  2467. if (mem_descr->mem_array[0].virtual_address) {
  2468. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2469. "BM_%d : hwi_init_async_pdu_ctx"
  2470. " HWI_MEM_ASYNC_HEADER_HANDLE va=%p\n",
  2471. mem_descr->mem_array[0].virtual_address);
  2472. } else
  2473. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2474. "BM_%d : No Virtual address\n");
  2475. pasync_ctx->async_header.handle_base =
  2476. mem_descr->mem_array[0].virtual_address;
  2477. pasync_ctx->async_header.writables = 0;
  2478. INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
  2479. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2480. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2481. if (mem_descr->mem_array[0].virtual_address) {
  2482. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2483. "BM_%d : hwi_init_async_pdu_ctx"
  2484. " HWI_MEM_ASYNC_DATA_RING va=%p\n",
  2485. mem_descr->mem_array[0].virtual_address);
  2486. } else
  2487. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2488. "BM_%d : No Virtual address\n");
  2489. pasync_ctx->async_data.ring_base =
  2490. mem_descr->mem_array[0].virtual_address;
  2491. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2492. mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
  2493. if (!mem_descr->mem_array[0].virtual_address)
  2494. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2495. "BM_%d : No Virtual address\n");
  2496. pasync_ctx->async_data.handle_base =
  2497. mem_descr->mem_array[0].virtual_address;
  2498. pasync_ctx->async_data.writables = 0;
  2499. INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
  2500. pasync_header_h =
  2501. (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
  2502. pasync_data_h =
  2503. (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
  2504. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2505. mem_descr += HWI_MEM_ASYNC_DATA_BUF;
  2506. if (mem_descr->mem_array[0].virtual_address) {
  2507. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2508. "BM_%d : hwi_init_async_pdu_ctx"
  2509. " HWI_MEM_ASYNC_DATA_BUF va=%p\n",
  2510. mem_descr->mem_array[0].virtual_address);
  2511. } else
  2512. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2513. "BM_%d : No Virtual address\n");
  2514. idx = 0;
  2515. pasync_ctx->async_data.va_base =
  2516. mem_descr->mem_array[idx].virtual_address;
  2517. pasync_ctx->async_data.pa_base.u.a64.address =
  2518. mem_descr->mem_array[idx].bus_address.u.a64.address;
  2519. num_async_data = ((mem_descr->mem_array[idx].size) /
  2520. phba->params.defpdu_data_sz);
  2521. num_per_mem = 0;
  2522. for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
  2523. pasync_header_h->cri = -1;
  2524. pasync_header_h->index = (char)index;
  2525. INIT_LIST_HEAD(&pasync_header_h->link);
  2526. pasync_header_h->pbuffer =
  2527. (void *)((unsigned long)
  2528. (pasync_ctx->async_header.va_base) +
  2529. (p->defpdu_hdr_sz * index));
  2530. pasync_header_h->pa.u.a64.address =
  2531. pasync_ctx->async_header.pa_base.u.a64.address +
  2532. (p->defpdu_hdr_sz * index);
  2533. list_add_tail(&pasync_header_h->link,
  2534. &pasync_ctx->async_header.free_list);
  2535. pasync_header_h++;
  2536. pasync_ctx->async_header.free_entries++;
  2537. pasync_ctx->async_header.writables++;
  2538. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
  2539. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  2540. header_busy_list);
  2541. pasync_data_h->cri = -1;
  2542. pasync_data_h->index = (char)index;
  2543. INIT_LIST_HEAD(&pasync_data_h->link);
  2544. if (!num_async_data) {
  2545. num_per_mem = 0;
  2546. idx++;
  2547. pasync_ctx->async_data.va_base =
  2548. mem_descr->mem_array[idx].virtual_address;
  2549. pasync_ctx->async_data.pa_base.u.a64.address =
  2550. mem_descr->mem_array[idx].
  2551. bus_address.u.a64.address;
  2552. num_async_data = ((mem_descr->mem_array[idx].size) /
  2553. phba->params.defpdu_data_sz);
  2554. }
  2555. pasync_data_h->pbuffer =
  2556. (void *)((unsigned long)
  2557. (pasync_ctx->async_data.va_base) +
  2558. (p->defpdu_data_sz * num_per_mem));
  2559. pasync_data_h->pa.u.a64.address =
  2560. pasync_ctx->async_data.pa_base.u.a64.address +
  2561. (p->defpdu_data_sz * num_per_mem);
  2562. num_per_mem++;
  2563. num_async_data--;
  2564. list_add_tail(&pasync_data_h->link,
  2565. &pasync_ctx->async_data.free_list);
  2566. pasync_data_h++;
  2567. pasync_ctx->async_data.free_entries++;
  2568. pasync_ctx->async_data.writables++;
  2569. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
  2570. }
  2571. pasync_ctx->async_header.host_write_ptr = 0;
  2572. pasync_ctx->async_header.ep_read_ptr = -1;
  2573. pasync_ctx->async_data.host_write_ptr = 0;
  2574. pasync_ctx->async_data.ep_read_ptr = -1;
  2575. }
  2576. static int
  2577. be_sgl_create_contiguous(void *virtual_address,
  2578. u64 physical_address, u32 length,
  2579. struct be_dma_mem *sgl)
  2580. {
  2581. WARN_ON(!virtual_address);
  2582. WARN_ON(!physical_address);
  2583. WARN_ON(!length > 0);
  2584. WARN_ON(!sgl);
  2585. sgl->va = virtual_address;
  2586. sgl->dma = (unsigned long)physical_address;
  2587. sgl->size = length;
  2588. return 0;
  2589. }
  2590. static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
  2591. {
  2592. memset(sgl, 0, sizeof(*sgl));
  2593. }
  2594. static void
  2595. hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
  2596. struct mem_array *pmem, struct be_dma_mem *sgl)
  2597. {
  2598. if (sgl->va)
  2599. be_sgl_destroy_contiguous(sgl);
  2600. be_sgl_create_contiguous(pmem->virtual_address,
  2601. pmem->bus_address.u.a64.address,
  2602. pmem->size, sgl);
  2603. }
  2604. static void
  2605. hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
  2606. struct mem_array *pmem, struct be_dma_mem *sgl)
  2607. {
  2608. if (sgl->va)
  2609. be_sgl_destroy_contiguous(sgl);
  2610. be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
  2611. pmem->bus_address.u.a64.address,
  2612. pmem->size, sgl);
  2613. }
  2614. static int be_fill_queue(struct be_queue_info *q,
  2615. u16 len, u16 entry_size, void *vaddress)
  2616. {
  2617. struct be_dma_mem *mem = &q->dma_mem;
  2618. memset(q, 0, sizeof(*q));
  2619. q->len = len;
  2620. q->entry_size = entry_size;
  2621. mem->size = len * entry_size;
  2622. mem->va = vaddress;
  2623. if (!mem->va)
  2624. return -ENOMEM;
  2625. memset(mem->va, 0, mem->size);
  2626. return 0;
  2627. }
  2628. static int beiscsi_create_eqs(struct beiscsi_hba *phba,
  2629. struct hwi_context_memory *phwi_context)
  2630. {
  2631. unsigned int i, num_eq_pages;
  2632. int ret = 0, eq_for_mcc;
  2633. struct be_queue_info *eq;
  2634. struct be_dma_mem *mem;
  2635. void *eq_vaddress;
  2636. dma_addr_t paddr;
  2637. num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
  2638. sizeof(struct be_eq_entry));
  2639. if (phba->msix_enabled)
  2640. eq_for_mcc = 1;
  2641. else
  2642. eq_for_mcc = 0;
  2643. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2644. eq = &phwi_context->be_eq[i].q;
  2645. mem = &eq->dma_mem;
  2646. phwi_context->be_eq[i].phba = phba;
  2647. eq_vaddress = pci_alloc_consistent(phba->pcidev,
  2648. num_eq_pages * PAGE_SIZE,
  2649. &paddr);
  2650. if (!eq_vaddress)
  2651. goto create_eq_error;
  2652. mem->va = eq_vaddress;
  2653. ret = be_fill_queue(eq, phba->params.num_eq_entries,
  2654. sizeof(struct be_eq_entry), eq_vaddress);
  2655. if (ret) {
  2656. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2657. "BM_%d : be_fill_queue Failed for EQ\n");
  2658. goto create_eq_error;
  2659. }
  2660. mem->dma = paddr;
  2661. ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
  2662. phwi_context->cur_eqd);
  2663. if (ret) {
  2664. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2665. "BM_%d : beiscsi_cmd_eq_create"
  2666. "Failed for EQ\n");
  2667. goto create_eq_error;
  2668. }
  2669. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2670. "BM_%d : eqid = %d\n",
  2671. phwi_context->be_eq[i].q.id);
  2672. }
  2673. return 0;
  2674. create_eq_error:
  2675. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2676. eq = &phwi_context->be_eq[i].q;
  2677. mem = &eq->dma_mem;
  2678. if (mem->va)
  2679. pci_free_consistent(phba->pcidev, num_eq_pages
  2680. * PAGE_SIZE,
  2681. mem->va, mem->dma);
  2682. }
  2683. return ret;
  2684. }
  2685. static int beiscsi_create_cqs(struct beiscsi_hba *phba,
  2686. struct hwi_context_memory *phwi_context)
  2687. {
  2688. unsigned int i, num_cq_pages;
  2689. int ret = 0;
  2690. struct be_queue_info *cq, *eq;
  2691. struct be_dma_mem *mem;
  2692. struct be_eq_obj *pbe_eq;
  2693. void *cq_vaddress;
  2694. dma_addr_t paddr;
  2695. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2696. sizeof(struct sol_cqe));
  2697. for (i = 0; i < phba->num_cpus; i++) {
  2698. cq = &phwi_context->be_cq[i];
  2699. eq = &phwi_context->be_eq[i].q;
  2700. pbe_eq = &phwi_context->be_eq[i];
  2701. pbe_eq->cq = cq;
  2702. pbe_eq->phba = phba;
  2703. mem = &cq->dma_mem;
  2704. cq_vaddress = pci_alloc_consistent(phba->pcidev,
  2705. num_cq_pages * PAGE_SIZE,
  2706. &paddr);
  2707. if (!cq_vaddress)
  2708. goto create_cq_error;
  2709. ret = be_fill_queue(cq, phba->params.num_cq_entries,
  2710. sizeof(struct sol_cqe), cq_vaddress);
  2711. if (ret) {
  2712. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2713. "BM_%d : be_fill_queue Failed "
  2714. "for ISCSI CQ\n");
  2715. goto create_cq_error;
  2716. }
  2717. mem->dma = paddr;
  2718. ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
  2719. false, 0);
  2720. if (ret) {
  2721. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2722. "BM_%d : beiscsi_cmd_eq_create"
  2723. "Failed for ISCSI CQ\n");
  2724. goto create_cq_error;
  2725. }
  2726. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2727. "BM_%d : iscsi cq_id is %d for eq_id %d\n"
  2728. "iSCSI CQ CREATED\n", cq->id, eq->id);
  2729. }
  2730. return 0;
  2731. create_cq_error:
  2732. for (i = 0; i < phba->num_cpus; i++) {
  2733. cq = &phwi_context->be_cq[i];
  2734. mem = &cq->dma_mem;
  2735. if (mem->va)
  2736. pci_free_consistent(phba->pcidev, num_cq_pages
  2737. * PAGE_SIZE,
  2738. mem->va, mem->dma);
  2739. }
  2740. return ret;
  2741. }
  2742. static int
  2743. beiscsi_create_def_hdr(struct beiscsi_hba *phba,
  2744. struct hwi_context_memory *phwi_context,
  2745. struct hwi_controller *phwi_ctrlr,
  2746. unsigned int def_pdu_ring_sz)
  2747. {
  2748. unsigned int idx;
  2749. int ret;
  2750. struct be_queue_info *dq, *cq;
  2751. struct be_dma_mem *mem;
  2752. struct be_mem_descriptor *mem_descr;
  2753. void *dq_vaddress;
  2754. idx = 0;
  2755. dq = &phwi_context->be_def_hdrq;
  2756. cq = &phwi_context->be_cq[0];
  2757. mem = &dq->dma_mem;
  2758. mem_descr = phba->init_mem;
  2759. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2760. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2761. ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
  2762. sizeof(struct phys_addr),
  2763. sizeof(struct phys_addr), dq_vaddress);
  2764. if (ret) {
  2765. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2766. "BM_%d : be_fill_queue Failed for DEF PDU HDR\n");
  2767. return ret;
  2768. }
  2769. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2770. bus_address.u.a64.address;
  2771. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
  2772. def_pdu_ring_sz,
  2773. phba->params.defpdu_hdr_sz);
  2774. if (ret) {
  2775. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2776. "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR\n");
  2777. return ret;
  2778. }
  2779. phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
  2780. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2781. "BM_%d : iscsi def pdu id is %d\n",
  2782. phwi_context->be_def_hdrq.id);
  2783. hwi_post_async_buffers(phba, 1);
  2784. return 0;
  2785. }
  2786. static int
  2787. beiscsi_create_def_data(struct beiscsi_hba *phba,
  2788. struct hwi_context_memory *phwi_context,
  2789. struct hwi_controller *phwi_ctrlr,
  2790. unsigned int def_pdu_ring_sz)
  2791. {
  2792. unsigned int idx;
  2793. int ret;
  2794. struct be_queue_info *dataq, *cq;
  2795. struct be_dma_mem *mem;
  2796. struct be_mem_descriptor *mem_descr;
  2797. void *dq_vaddress;
  2798. idx = 0;
  2799. dataq = &phwi_context->be_def_dataq;
  2800. cq = &phwi_context->be_cq[0];
  2801. mem = &dataq->dma_mem;
  2802. mem_descr = phba->init_mem;
  2803. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2804. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2805. ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
  2806. sizeof(struct phys_addr),
  2807. sizeof(struct phys_addr), dq_vaddress);
  2808. if (ret) {
  2809. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2810. "BM_%d : be_fill_queue Failed for DEF PDU DATA\n");
  2811. return ret;
  2812. }
  2813. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2814. bus_address.u.a64.address;
  2815. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
  2816. def_pdu_ring_sz,
  2817. phba->params.defpdu_data_sz);
  2818. if (ret) {
  2819. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2820. "BM_%d be_cmd_create_default_pdu_queue"
  2821. " Failed for DEF PDU DATA\n");
  2822. return ret;
  2823. }
  2824. phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
  2825. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2826. "BM_%d : iscsi def data id is %d\n",
  2827. phwi_context->be_def_dataq.id);
  2828. hwi_post_async_buffers(phba, 0);
  2829. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2830. "BM_%d : DEFAULT PDU DATA RING CREATED\n");
  2831. return 0;
  2832. }
  2833. static int
  2834. beiscsi_post_pages(struct beiscsi_hba *phba)
  2835. {
  2836. struct be_mem_descriptor *mem_descr;
  2837. struct mem_array *pm_arr;
  2838. unsigned int page_offset, i;
  2839. struct be_dma_mem sgl;
  2840. int status;
  2841. mem_descr = phba->init_mem;
  2842. mem_descr += HWI_MEM_SGE;
  2843. pm_arr = mem_descr->mem_array;
  2844. page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
  2845. phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
  2846. for (i = 0; i < mem_descr->num_elements; i++) {
  2847. hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
  2848. status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
  2849. page_offset,
  2850. (pm_arr->size / PAGE_SIZE));
  2851. page_offset += pm_arr->size / PAGE_SIZE;
  2852. if (status != 0) {
  2853. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2854. "BM_%d : post sgl failed.\n");
  2855. return status;
  2856. }
  2857. pm_arr++;
  2858. }
  2859. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2860. "BM_%d : POSTED PAGES\n");
  2861. return 0;
  2862. }
  2863. static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
  2864. {
  2865. struct be_dma_mem *mem = &q->dma_mem;
  2866. if (mem->va) {
  2867. pci_free_consistent(phba->pcidev, mem->size,
  2868. mem->va, mem->dma);
  2869. mem->va = NULL;
  2870. }
  2871. }
  2872. static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
  2873. u16 len, u16 entry_size)
  2874. {
  2875. struct be_dma_mem *mem = &q->dma_mem;
  2876. memset(q, 0, sizeof(*q));
  2877. q->len = len;
  2878. q->entry_size = entry_size;
  2879. mem->size = len * entry_size;
  2880. mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
  2881. if (!mem->va)
  2882. return -ENOMEM;
  2883. memset(mem->va, 0, mem->size);
  2884. return 0;
  2885. }
  2886. static int
  2887. beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
  2888. struct hwi_context_memory *phwi_context,
  2889. struct hwi_controller *phwi_ctrlr)
  2890. {
  2891. unsigned int wrb_mem_index, offset, size, num_wrb_rings;
  2892. u64 pa_addr_lo;
  2893. unsigned int idx, num, i;
  2894. struct mem_array *pwrb_arr;
  2895. void *wrb_vaddr;
  2896. struct be_dma_mem sgl;
  2897. struct be_mem_descriptor *mem_descr;
  2898. int status;
  2899. idx = 0;
  2900. mem_descr = phba->init_mem;
  2901. mem_descr += HWI_MEM_WRB;
  2902. pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
  2903. GFP_KERNEL);
  2904. if (!pwrb_arr) {
  2905. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2906. "BM_%d : Memory alloc failed in create wrb ring.\n");
  2907. return -ENOMEM;
  2908. }
  2909. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2910. pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
  2911. num_wrb_rings = mem_descr->mem_array[idx].size /
  2912. (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
  2913. for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
  2914. if (num_wrb_rings) {
  2915. pwrb_arr[num].virtual_address = wrb_vaddr;
  2916. pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
  2917. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2918. sizeof(struct iscsi_wrb);
  2919. wrb_vaddr += pwrb_arr[num].size;
  2920. pa_addr_lo += pwrb_arr[num].size;
  2921. num_wrb_rings--;
  2922. } else {
  2923. idx++;
  2924. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2925. pa_addr_lo = mem_descr->mem_array[idx].\
  2926. bus_address.u.a64.address;
  2927. num_wrb_rings = mem_descr->mem_array[idx].size /
  2928. (phba->params.wrbs_per_cxn *
  2929. sizeof(struct iscsi_wrb));
  2930. pwrb_arr[num].virtual_address = wrb_vaddr;
  2931. pwrb_arr[num].bus_address.u.a64.address\
  2932. = pa_addr_lo;
  2933. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2934. sizeof(struct iscsi_wrb);
  2935. wrb_vaddr += pwrb_arr[num].size;
  2936. pa_addr_lo += pwrb_arr[num].size;
  2937. num_wrb_rings--;
  2938. }
  2939. }
  2940. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2941. wrb_mem_index = 0;
  2942. offset = 0;
  2943. size = 0;
  2944. hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
  2945. status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
  2946. &phwi_context->be_wrbq[i]);
  2947. if (status != 0) {
  2948. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2949. "BM_%d : wrbq create failed.");
  2950. kfree(pwrb_arr);
  2951. return status;
  2952. }
  2953. phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
  2954. id;
  2955. }
  2956. kfree(pwrb_arr);
  2957. return 0;
  2958. }
  2959. static void free_wrb_handles(struct beiscsi_hba *phba)
  2960. {
  2961. unsigned int index;
  2962. struct hwi_controller *phwi_ctrlr;
  2963. struct hwi_wrb_context *pwrb_context;
  2964. phwi_ctrlr = phba->phwi_ctrlr;
  2965. for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
  2966. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2967. kfree(pwrb_context->pwrb_handle_base);
  2968. kfree(pwrb_context->pwrb_handle_basestd);
  2969. }
  2970. }
  2971. static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
  2972. {
  2973. struct be_queue_info *q;
  2974. struct be_ctrl_info *ctrl = &phba->ctrl;
  2975. q = &phba->ctrl.mcc_obj.q;
  2976. if (q->created)
  2977. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
  2978. be_queue_free(phba, q);
  2979. q = &phba->ctrl.mcc_obj.cq;
  2980. if (q->created)
  2981. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  2982. be_queue_free(phba, q);
  2983. }
  2984. static void hwi_cleanup(struct beiscsi_hba *phba)
  2985. {
  2986. struct be_queue_info *q;
  2987. struct be_ctrl_info *ctrl = &phba->ctrl;
  2988. struct hwi_controller *phwi_ctrlr;
  2989. struct hwi_context_memory *phwi_context;
  2990. int i, eq_num;
  2991. phwi_ctrlr = phba->phwi_ctrlr;
  2992. phwi_context = phwi_ctrlr->phwi_ctxt;
  2993. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  2994. q = &phwi_context->be_wrbq[i];
  2995. if (q->created)
  2996. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
  2997. }
  2998. free_wrb_handles(phba);
  2999. q = &phwi_context->be_def_hdrq;
  3000. if (q->created)
  3001. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  3002. q = &phwi_context->be_def_dataq;
  3003. if (q->created)
  3004. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  3005. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  3006. for (i = 0; i < (phba->num_cpus); i++) {
  3007. q = &phwi_context->be_cq[i];
  3008. if (q->created)
  3009. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  3010. }
  3011. if (phba->msix_enabled)
  3012. eq_num = 1;
  3013. else
  3014. eq_num = 0;
  3015. for (i = 0; i < (phba->num_cpus + eq_num); i++) {
  3016. q = &phwi_context->be_eq[i].q;
  3017. if (q->created)
  3018. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
  3019. }
  3020. be_mcc_queues_destroy(phba);
  3021. }
  3022. static int be_mcc_queues_create(struct beiscsi_hba *phba,
  3023. struct hwi_context_memory *phwi_context)
  3024. {
  3025. struct be_queue_info *q, *cq;
  3026. struct be_ctrl_info *ctrl = &phba->ctrl;
  3027. /* Alloc MCC compl queue */
  3028. cq = &phba->ctrl.mcc_obj.cq;
  3029. if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
  3030. sizeof(struct be_mcc_compl)))
  3031. goto err;
  3032. /* Ask BE to create MCC compl queue; */
  3033. if (phba->msix_enabled) {
  3034. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
  3035. [phba->num_cpus].q, false, true, 0))
  3036. goto mcc_cq_free;
  3037. } else {
  3038. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
  3039. false, true, 0))
  3040. goto mcc_cq_free;
  3041. }
  3042. /* Alloc MCC queue */
  3043. q = &phba->ctrl.mcc_obj.q;
  3044. if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
  3045. goto mcc_cq_destroy;
  3046. /* Ask BE to create MCC queue */
  3047. if (beiscsi_cmd_mccq_create(phba, q, cq))
  3048. goto mcc_q_free;
  3049. return 0;
  3050. mcc_q_free:
  3051. be_queue_free(phba, q);
  3052. mcc_cq_destroy:
  3053. beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
  3054. mcc_cq_free:
  3055. be_queue_free(phba, cq);
  3056. err:
  3057. return -ENOMEM;
  3058. }
  3059. /**
  3060. * find_num_cpus()- Get the CPU online count
  3061. * @phba: ptr to priv structure
  3062. *
  3063. * CPU count is used for creating EQ.
  3064. **/
  3065. static void find_num_cpus(struct beiscsi_hba *phba)
  3066. {
  3067. int num_cpus = 0;
  3068. num_cpus = num_online_cpus();
  3069. switch (phba->generation) {
  3070. case BE_GEN2:
  3071. case BE_GEN3:
  3072. phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
  3073. BEISCSI_MAX_NUM_CPUS : num_cpus;
  3074. break;
  3075. case BE_GEN4:
  3076. phba->num_cpus = (num_cpus > OC_SKH_MAX_NUM_CPUS) ?
  3077. OC_SKH_MAX_NUM_CPUS : num_cpus;
  3078. break;
  3079. default:
  3080. phba->num_cpus = 1;
  3081. }
  3082. }
  3083. static int hwi_init_port(struct beiscsi_hba *phba)
  3084. {
  3085. struct hwi_controller *phwi_ctrlr;
  3086. struct hwi_context_memory *phwi_context;
  3087. unsigned int def_pdu_ring_sz;
  3088. struct be_ctrl_info *ctrl = &phba->ctrl;
  3089. int status;
  3090. def_pdu_ring_sz =
  3091. phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
  3092. phwi_ctrlr = phba->phwi_ctrlr;
  3093. phwi_context = phwi_ctrlr->phwi_ctxt;
  3094. phwi_context->max_eqd = 0;
  3095. phwi_context->min_eqd = 0;
  3096. phwi_context->cur_eqd = 64;
  3097. be_cmd_fw_initialize(&phba->ctrl);
  3098. status = beiscsi_create_eqs(phba, phwi_context);
  3099. if (status != 0) {
  3100. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3101. "BM_%d : EQ not created\n");
  3102. goto error;
  3103. }
  3104. status = be_mcc_queues_create(phba, phwi_context);
  3105. if (status != 0)
  3106. goto error;
  3107. status = mgmt_check_supported_fw(ctrl, phba);
  3108. if (status != 0) {
  3109. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3110. "BM_%d : Unsupported fw version\n");
  3111. goto error;
  3112. }
  3113. status = beiscsi_create_cqs(phba, phwi_context);
  3114. if (status != 0) {
  3115. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3116. "BM_%d : CQ not created\n");
  3117. goto error;
  3118. }
  3119. status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
  3120. def_pdu_ring_sz);
  3121. if (status != 0) {
  3122. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3123. "BM_%d : Default Header not created\n");
  3124. goto error;
  3125. }
  3126. status = beiscsi_create_def_data(phba, phwi_context,
  3127. phwi_ctrlr, def_pdu_ring_sz);
  3128. if (status != 0) {
  3129. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3130. "BM_%d : Default Data not created\n");
  3131. goto error;
  3132. }
  3133. status = beiscsi_post_pages(phba);
  3134. if (status != 0) {
  3135. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3136. "BM_%d : Post SGL Pages Failed\n");
  3137. goto error;
  3138. }
  3139. status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
  3140. if (status != 0) {
  3141. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3142. "BM_%d : WRB Rings not created\n");
  3143. goto error;
  3144. }
  3145. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3146. "BM_%d : hwi_init_port success\n");
  3147. return 0;
  3148. error:
  3149. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3150. "BM_%d : hwi_init_port failed");
  3151. hwi_cleanup(phba);
  3152. return status;
  3153. }
  3154. static int hwi_init_controller(struct beiscsi_hba *phba)
  3155. {
  3156. struct hwi_controller *phwi_ctrlr;
  3157. phwi_ctrlr = phba->phwi_ctrlr;
  3158. if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
  3159. phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
  3160. init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
  3161. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3162. "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
  3163. phwi_ctrlr->phwi_ctxt);
  3164. } else {
  3165. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3166. "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
  3167. "than one element.Failing to load\n");
  3168. return -ENOMEM;
  3169. }
  3170. iscsi_init_global_templates(phba);
  3171. if (beiscsi_init_wrb_handle(phba))
  3172. return -ENOMEM;
  3173. hwi_init_async_pdu_ctx(phba);
  3174. if (hwi_init_port(phba) != 0) {
  3175. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3176. "BM_%d : hwi_init_controller failed\n");
  3177. return -ENOMEM;
  3178. }
  3179. return 0;
  3180. }
  3181. static void beiscsi_free_mem(struct beiscsi_hba *phba)
  3182. {
  3183. struct be_mem_descriptor *mem_descr;
  3184. int i, j;
  3185. mem_descr = phba->init_mem;
  3186. i = 0;
  3187. j = 0;
  3188. for (i = 0; i < SE_MEM_MAX; i++) {
  3189. for (j = mem_descr->num_elements; j > 0; j--) {
  3190. pci_free_consistent(phba->pcidev,
  3191. mem_descr->mem_array[j - 1].size,
  3192. mem_descr->mem_array[j - 1].virtual_address,
  3193. (unsigned long)mem_descr->mem_array[j - 1].
  3194. bus_address.u.a64.address);
  3195. }
  3196. kfree(mem_descr->mem_array);
  3197. mem_descr++;
  3198. }
  3199. kfree(phba->init_mem);
  3200. kfree(phba->phwi_ctrlr);
  3201. }
  3202. static int beiscsi_init_controller(struct beiscsi_hba *phba)
  3203. {
  3204. int ret = -ENOMEM;
  3205. ret = beiscsi_get_memory(phba);
  3206. if (ret < 0) {
  3207. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3208. "BM_%d : beiscsi_dev_probe -"
  3209. "Failed in beiscsi_alloc_memory\n");
  3210. return ret;
  3211. }
  3212. ret = hwi_init_controller(phba);
  3213. if (ret)
  3214. goto free_init;
  3215. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3216. "BM_%d : Return success from beiscsi_init_controller");
  3217. return 0;
  3218. free_init:
  3219. beiscsi_free_mem(phba);
  3220. return ret;
  3221. }
  3222. static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
  3223. {
  3224. struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
  3225. struct sgl_handle *psgl_handle;
  3226. struct iscsi_sge *pfrag;
  3227. unsigned int arr_index, i, idx;
  3228. phba->io_sgl_hndl_avbl = 0;
  3229. phba->eh_sgl_hndl_avbl = 0;
  3230. mem_descr_sglh = phba->init_mem;
  3231. mem_descr_sglh += HWI_MEM_SGLH;
  3232. if (1 == mem_descr_sglh->num_elements) {
  3233. phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  3234. phba->params.ios_per_ctrl,
  3235. GFP_KERNEL);
  3236. if (!phba->io_sgl_hndl_base) {
  3237. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3238. "BM_%d : Mem Alloc Failed. Failing to load\n");
  3239. return -ENOMEM;
  3240. }
  3241. phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  3242. (phba->params.icds_per_ctrl -
  3243. phba->params.ios_per_ctrl),
  3244. GFP_KERNEL);
  3245. if (!phba->eh_sgl_hndl_base) {
  3246. kfree(phba->io_sgl_hndl_base);
  3247. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3248. "BM_%d : Mem Alloc Failed. Failing to load\n");
  3249. return -ENOMEM;
  3250. }
  3251. } else {
  3252. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3253. "BM_%d : HWI_MEM_SGLH is more than one element."
  3254. "Failing to load\n");
  3255. return -ENOMEM;
  3256. }
  3257. arr_index = 0;
  3258. idx = 0;
  3259. while (idx < mem_descr_sglh->num_elements) {
  3260. psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
  3261. for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
  3262. sizeof(struct sgl_handle)); i++) {
  3263. if (arr_index < phba->params.ios_per_ctrl) {
  3264. phba->io_sgl_hndl_base[arr_index] = psgl_handle;
  3265. phba->io_sgl_hndl_avbl++;
  3266. arr_index++;
  3267. } else {
  3268. phba->eh_sgl_hndl_base[arr_index -
  3269. phba->params.ios_per_ctrl] =
  3270. psgl_handle;
  3271. arr_index++;
  3272. phba->eh_sgl_hndl_avbl++;
  3273. }
  3274. psgl_handle++;
  3275. }
  3276. idx++;
  3277. }
  3278. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3279. "BM_%d : phba->io_sgl_hndl_avbl=%d"
  3280. "phba->eh_sgl_hndl_avbl=%d\n",
  3281. phba->io_sgl_hndl_avbl,
  3282. phba->eh_sgl_hndl_avbl);
  3283. mem_descr_sg = phba->init_mem;
  3284. mem_descr_sg += HWI_MEM_SGE;
  3285. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3286. "\n BM_%d : mem_descr_sg->num_elements=%d\n",
  3287. mem_descr_sg->num_elements);
  3288. arr_index = 0;
  3289. idx = 0;
  3290. while (idx < mem_descr_sg->num_elements) {
  3291. pfrag = mem_descr_sg->mem_array[idx].virtual_address;
  3292. for (i = 0;
  3293. i < (mem_descr_sg->mem_array[idx].size) /
  3294. (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
  3295. i++) {
  3296. if (arr_index < phba->params.ios_per_ctrl)
  3297. psgl_handle = phba->io_sgl_hndl_base[arr_index];
  3298. else
  3299. psgl_handle = phba->eh_sgl_hndl_base[arr_index -
  3300. phba->params.ios_per_ctrl];
  3301. psgl_handle->pfrag = pfrag;
  3302. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
  3303. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
  3304. pfrag += phba->params.num_sge_per_io;
  3305. psgl_handle->sgl_index =
  3306. phba->fw_config.iscsi_icd_start + arr_index++;
  3307. }
  3308. idx++;
  3309. }
  3310. phba->io_sgl_free_index = 0;
  3311. phba->io_sgl_alloc_index = 0;
  3312. phba->eh_sgl_free_index = 0;
  3313. phba->eh_sgl_alloc_index = 0;
  3314. return 0;
  3315. }
  3316. static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
  3317. {
  3318. int i, new_cid;
  3319. phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
  3320. GFP_KERNEL);
  3321. if (!phba->cid_array) {
  3322. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3323. "BM_%d : Failed to allocate memory in "
  3324. "hba_setup_cid_tbls\n");
  3325. return -ENOMEM;
  3326. }
  3327. phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
  3328. phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
  3329. if (!phba->ep_array) {
  3330. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3331. "BM_%d : Failed to allocate memory in "
  3332. "hba_setup_cid_tbls\n");
  3333. kfree(phba->cid_array);
  3334. return -ENOMEM;
  3335. }
  3336. new_cid = phba->fw_config.iscsi_cid_start;
  3337. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3338. phba->cid_array[i] = new_cid;
  3339. new_cid += 2;
  3340. }
  3341. phba->avlbl_cids = phba->params.cxns_per_ctrl;
  3342. return 0;
  3343. }
  3344. static void hwi_enable_intr(struct beiscsi_hba *phba)
  3345. {
  3346. struct be_ctrl_info *ctrl = &phba->ctrl;
  3347. struct hwi_controller *phwi_ctrlr;
  3348. struct hwi_context_memory *phwi_context;
  3349. struct be_queue_info *eq;
  3350. u8 __iomem *addr;
  3351. u32 reg, i;
  3352. u32 enabled;
  3353. phwi_ctrlr = phba->phwi_ctrlr;
  3354. phwi_context = phwi_ctrlr->phwi_ctxt;
  3355. addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
  3356. PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
  3357. reg = ioread32(addr);
  3358. enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3359. if (!enabled) {
  3360. reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3361. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3362. "BM_%d : reg =x%08x addr=%p\n", reg, addr);
  3363. iowrite32(reg, addr);
  3364. }
  3365. if (!phba->msix_enabled) {
  3366. eq = &phwi_context->be_eq[0].q;
  3367. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3368. "BM_%d : eq->id=%d\n", eq->id);
  3369. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3370. } else {
  3371. for (i = 0; i <= phba->num_cpus; i++) {
  3372. eq = &phwi_context->be_eq[i].q;
  3373. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3374. "BM_%d : eq->id=%d\n", eq->id);
  3375. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3376. }
  3377. }
  3378. }
  3379. static void hwi_disable_intr(struct beiscsi_hba *phba)
  3380. {
  3381. struct be_ctrl_info *ctrl = &phba->ctrl;
  3382. u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
  3383. u32 reg = ioread32(addr);
  3384. u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3385. if (enabled) {
  3386. reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3387. iowrite32(reg, addr);
  3388. } else
  3389. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  3390. "BM_%d : In hwi_disable_intr, Already Disabled\n");
  3391. }
  3392. /**
  3393. * beiscsi_get_boot_info()- Get the boot session info
  3394. * @phba: The device priv structure instance
  3395. *
  3396. * Get the boot target info and store in driver priv structure
  3397. *
  3398. * return values
  3399. * Success: 0
  3400. * Failure: Non-Zero Value
  3401. **/
  3402. static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
  3403. {
  3404. struct be_cmd_get_session_resp *session_resp;
  3405. struct be_mcc_wrb *wrb;
  3406. struct be_dma_mem nonemb_cmd;
  3407. unsigned int tag, wrb_num;
  3408. unsigned short status, extd_status;
  3409. unsigned int s_handle;
  3410. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  3411. int ret = -ENOMEM;
  3412. /* Get the session handle of the boot target */
  3413. ret = be_mgmt_get_boot_shandle(phba, &s_handle);
  3414. if (ret) {
  3415. beiscsi_log(phba, KERN_ERR,
  3416. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3417. "BM_%d : No boot session\n");
  3418. return ret;
  3419. }
  3420. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  3421. sizeof(*session_resp),
  3422. &nonemb_cmd.dma);
  3423. if (nonemb_cmd.va == NULL) {
  3424. beiscsi_log(phba, KERN_ERR,
  3425. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3426. "BM_%d : Failed to allocate memory for"
  3427. "beiscsi_get_session_info\n");
  3428. return -ENOMEM;
  3429. }
  3430. memset(nonemb_cmd.va, 0, sizeof(*session_resp));
  3431. tag = mgmt_get_session_info(phba, s_handle,
  3432. &nonemb_cmd);
  3433. if (!tag) {
  3434. beiscsi_log(phba, KERN_ERR,
  3435. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3436. "BM_%d : beiscsi_get_session_info"
  3437. " Failed\n");
  3438. goto boot_freemem;
  3439. } else
  3440. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  3441. phba->ctrl.mcc_numtag[tag]);
  3442. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  3443. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  3444. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  3445. if (status || extd_status) {
  3446. beiscsi_log(phba, KERN_ERR,
  3447. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3448. "BM_%d : beiscsi_get_session_info Failed"
  3449. " status = %d extd_status = %d\n",
  3450. status, extd_status);
  3451. free_mcc_tag(&phba->ctrl, tag);
  3452. goto boot_freemem;
  3453. }
  3454. wrb = queue_get_wrb(mccq, wrb_num);
  3455. free_mcc_tag(&phba->ctrl, tag);
  3456. session_resp = nonemb_cmd.va ;
  3457. memcpy(&phba->boot_sess, &session_resp->session_info,
  3458. sizeof(struct mgmt_session_info));
  3459. ret = 0;
  3460. boot_freemem:
  3461. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  3462. nonemb_cmd.va, nonemb_cmd.dma);
  3463. return ret;
  3464. }
  3465. static void beiscsi_boot_release(void *data)
  3466. {
  3467. struct beiscsi_hba *phba = data;
  3468. scsi_host_put(phba->shost);
  3469. }
  3470. static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
  3471. {
  3472. struct iscsi_boot_kobj *boot_kobj;
  3473. /* get boot info using mgmt cmd */
  3474. if (beiscsi_get_boot_info(phba))
  3475. /* Try to see if we can carry on without this */
  3476. return 0;
  3477. phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
  3478. if (!phba->boot_kset)
  3479. return -ENOMEM;
  3480. /* get a ref because the show function will ref the phba */
  3481. if (!scsi_host_get(phba->shost))
  3482. goto free_kset;
  3483. boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
  3484. beiscsi_show_boot_tgt_info,
  3485. beiscsi_tgt_get_attr_visibility,
  3486. beiscsi_boot_release);
  3487. if (!boot_kobj)
  3488. goto put_shost;
  3489. if (!scsi_host_get(phba->shost))
  3490. goto free_kset;
  3491. boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
  3492. beiscsi_show_boot_ini_info,
  3493. beiscsi_ini_get_attr_visibility,
  3494. beiscsi_boot_release);
  3495. if (!boot_kobj)
  3496. goto put_shost;
  3497. if (!scsi_host_get(phba->shost))
  3498. goto free_kset;
  3499. boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
  3500. beiscsi_show_boot_eth_info,
  3501. beiscsi_eth_get_attr_visibility,
  3502. beiscsi_boot_release);
  3503. if (!boot_kobj)
  3504. goto put_shost;
  3505. return 0;
  3506. put_shost:
  3507. scsi_host_put(phba->shost);
  3508. free_kset:
  3509. iscsi_boot_destroy_kset(phba->boot_kset);
  3510. return -ENOMEM;
  3511. }
  3512. static int beiscsi_init_port(struct beiscsi_hba *phba)
  3513. {
  3514. int ret;
  3515. ret = beiscsi_init_controller(phba);
  3516. if (ret < 0) {
  3517. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3518. "BM_%d : beiscsi_dev_probe - Failed in"
  3519. "beiscsi_init_controller\n");
  3520. return ret;
  3521. }
  3522. ret = beiscsi_init_sgl_handle(phba);
  3523. if (ret < 0) {
  3524. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3525. "BM_%d : beiscsi_dev_probe - Failed in"
  3526. "beiscsi_init_sgl_handle\n");
  3527. goto do_cleanup_ctrlr;
  3528. }
  3529. if (hba_setup_cid_tbls(phba)) {
  3530. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3531. "BM_%d : Failed in hba_setup_cid_tbls\n");
  3532. kfree(phba->io_sgl_hndl_base);
  3533. kfree(phba->eh_sgl_hndl_base);
  3534. goto do_cleanup_ctrlr;
  3535. }
  3536. return ret;
  3537. do_cleanup_ctrlr:
  3538. hwi_cleanup(phba);
  3539. return ret;
  3540. }
  3541. static void hwi_purge_eq(struct beiscsi_hba *phba)
  3542. {
  3543. struct hwi_controller *phwi_ctrlr;
  3544. struct hwi_context_memory *phwi_context;
  3545. struct be_queue_info *eq;
  3546. struct be_eq_entry *eqe = NULL;
  3547. int i, eq_msix;
  3548. unsigned int num_processed;
  3549. phwi_ctrlr = phba->phwi_ctrlr;
  3550. phwi_context = phwi_ctrlr->phwi_ctxt;
  3551. if (phba->msix_enabled)
  3552. eq_msix = 1;
  3553. else
  3554. eq_msix = 0;
  3555. for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
  3556. eq = &phwi_context->be_eq[i].q;
  3557. eqe = queue_tail_node(eq);
  3558. num_processed = 0;
  3559. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  3560. & EQE_VALID_MASK) {
  3561. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  3562. queue_tail_inc(eq);
  3563. eqe = queue_tail_node(eq);
  3564. num_processed++;
  3565. }
  3566. if (num_processed)
  3567. hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
  3568. }
  3569. }
  3570. static void beiscsi_clean_port(struct beiscsi_hba *phba)
  3571. {
  3572. int mgmt_status;
  3573. mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
  3574. if (mgmt_status)
  3575. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  3576. "BM_%d : mgmt_epfw_cleanup FAILED\n");
  3577. hwi_purge_eq(phba);
  3578. hwi_cleanup(phba);
  3579. kfree(phba->io_sgl_hndl_base);
  3580. kfree(phba->eh_sgl_hndl_base);
  3581. kfree(phba->cid_array);
  3582. kfree(phba->ep_array);
  3583. }
  3584. /**
  3585. * beiscsi_cleanup_task()- Free driver resources of the task
  3586. * @task: ptr to the iscsi task
  3587. *
  3588. **/
  3589. static void beiscsi_cleanup_task(struct iscsi_task *task)
  3590. {
  3591. struct beiscsi_io_task *io_task = task->dd_data;
  3592. struct iscsi_conn *conn = task->conn;
  3593. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3594. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3595. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3596. struct hwi_wrb_context *pwrb_context;
  3597. struct hwi_controller *phwi_ctrlr;
  3598. phwi_ctrlr = phba->phwi_ctrlr;
  3599. pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
  3600. - phba->fw_config.iscsi_cid_start];
  3601. if (io_task->cmd_bhs) {
  3602. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3603. io_task->bhs_pa.u.a64.address);
  3604. io_task->cmd_bhs = NULL;
  3605. }
  3606. if (task->sc) {
  3607. if (io_task->pwrb_handle) {
  3608. free_wrb_handle(phba, pwrb_context,
  3609. io_task->pwrb_handle);
  3610. io_task->pwrb_handle = NULL;
  3611. }
  3612. if (io_task->psgl_handle) {
  3613. spin_lock(&phba->io_sgl_lock);
  3614. free_io_sgl_handle(phba, io_task->psgl_handle);
  3615. spin_unlock(&phba->io_sgl_lock);
  3616. io_task->psgl_handle = NULL;
  3617. }
  3618. } else {
  3619. if (!beiscsi_conn->login_in_progress) {
  3620. if (io_task->pwrb_handle) {
  3621. free_wrb_handle(phba, pwrb_context,
  3622. io_task->pwrb_handle);
  3623. io_task->pwrb_handle = NULL;
  3624. }
  3625. if (io_task->psgl_handle) {
  3626. spin_lock(&phba->mgmt_sgl_lock);
  3627. free_mgmt_sgl_handle(phba,
  3628. io_task->psgl_handle);
  3629. spin_unlock(&phba->mgmt_sgl_lock);
  3630. io_task->psgl_handle = NULL;
  3631. }
  3632. if (io_task->mtask_addr) {
  3633. pci_unmap_single(phba->pcidev,
  3634. io_task->mtask_addr,
  3635. io_task->mtask_data_count,
  3636. PCI_DMA_TODEVICE);
  3637. io_task->mtask_addr = 0;
  3638. }
  3639. }
  3640. }
  3641. }
  3642. void
  3643. beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
  3644. struct beiscsi_offload_params *params)
  3645. {
  3646. struct wrb_handle *pwrb_handle;
  3647. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3648. struct iscsi_task *task = beiscsi_conn->task;
  3649. struct iscsi_session *session = task->conn->session;
  3650. u32 doorbell = 0;
  3651. /*
  3652. * We can always use 0 here because it is reserved by libiscsi for
  3653. * login/startup related tasks.
  3654. */
  3655. beiscsi_conn->login_in_progress = 0;
  3656. spin_lock_bh(&session->lock);
  3657. beiscsi_cleanup_task(task);
  3658. spin_unlock_bh(&session->lock);
  3659. pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
  3660. phba->fw_config.iscsi_cid_start));
  3661. /* Check for the adapter family */
  3662. if (chip_skh_r(phba->pcidev))
  3663. beiscsi_offload_cxn_v2(params, pwrb_handle);
  3664. else
  3665. beiscsi_offload_cxn_v0(params, pwrb_handle,
  3666. phba->init_mem);
  3667. be_dws_le_to_cpu(pwrb_handle->pwrb,
  3668. sizeof(struct iscsi_target_context_update_wrb));
  3669. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3670. doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
  3671. << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3672. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3673. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3674. }
  3675. static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
  3676. int *index, int *age)
  3677. {
  3678. *index = (int)itt;
  3679. if (age)
  3680. *age = conn->session->age;
  3681. }
  3682. /**
  3683. * beiscsi_alloc_pdu - allocates pdu and related resources
  3684. * @task: libiscsi task
  3685. * @opcode: opcode of pdu for task
  3686. *
  3687. * This is called with the session lock held. It will allocate
  3688. * the wrb and sgl if needed for the command. And it will prep
  3689. * the pdu's itt. beiscsi_parse_pdu will later translate
  3690. * the pdu itt to the libiscsi task itt.
  3691. */
  3692. static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  3693. {
  3694. struct beiscsi_io_task *io_task = task->dd_data;
  3695. struct iscsi_conn *conn = task->conn;
  3696. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3697. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3698. struct hwi_wrb_context *pwrb_context;
  3699. struct hwi_controller *phwi_ctrlr;
  3700. itt_t itt;
  3701. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3702. dma_addr_t paddr;
  3703. io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
  3704. GFP_ATOMIC, &paddr);
  3705. if (!io_task->cmd_bhs)
  3706. return -ENOMEM;
  3707. io_task->bhs_pa.u.a64.address = paddr;
  3708. io_task->libiscsi_itt = (itt_t)task->itt;
  3709. io_task->conn = beiscsi_conn;
  3710. task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
  3711. task->hdr_max = sizeof(struct be_cmd_bhs);
  3712. io_task->psgl_handle = NULL;
  3713. io_task->pwrb_handle = NULL;
  3714. if (task->sc) {
  3715. spin_lock(&phba->io_sgl_lock);
  3716. io_task->psgl_handle = alloc_io_sgl_handle(phba);
  3717. spin_unlock(&phba->io_sgl_lock);
  3718. if (!io_task->psgl_handle) {
  3719. beiscsi_log(phba, KERN_ERR,
  3720. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  3721. "BM_%d : Alloc of IO_SGL_ICD Failed"
  3722. "for the CID : %d\n",
  3723. beiscsi_conn->beiscsi_conn_cid);
  3724. goto free_hndls;
  3725. }
  3726. io_task->pwrb_handle = alloc_wrb_handle(phba,
  3727. beiscsi_conn->beiscsi_conn_cid -
  3728. phba->fw_config.iscsi_cid_start);
  3729. if (!io_task->pwrb_handle) {
  3730. beiscsi_log(phba, KERN_ERR,
  3731. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  3732. "BM_%d : Alloc of WRB_HANDLE Failed"
  3733. "for the CID : %d\n",
  3734. beiscsi_conn->beiscsi_conn_cid);
  3735. goto free_io_hndls;
  3736. }
  3737. } else {
  3738. io_task->scsi_cmnd = NULL;
  3739. if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
  3740. if (!beiscsi_conn->login_in_progress) {
  3741. spin_lock(&phba->mgmt_sgl_lock);
  3742. io_task->psgl_handle = (struct sgl_handle *)
  3743. alloc_mgmt_sgl_handle(phba);
  3744. spin_unlock(&phba->mgmt_sgl_lock);
  3745. if (!io_task->psgl_handle) {
  3746. beiscsi_log(phba, KERN_ERR,
  3747. BEISCSI_LOG_IO |
  3748. BEISCSI_LOG_CONFIG,
  3749. "BM_%d : Alloc of MGMT_SGL_ICD Failed"
  3750. "for the CID : %d\n",
  3751. beiscsi_conn->
  3752. beiscsi_conn_cid);
  3753. goto free_hndls;
  3754. }
  3755. beiscsi_conn->login_in_progress = 1;
  3756. beiscsi_conn->plogin_sgl_handle =
  3757. io_task->psgl_handle;
  3758. io_task->pwrb_handle =
  3759. alloc_wrb_handle(phba,
  3760. beiscsi_conn->beiscsi_conn_cid -
  3761. phba->fw_config.iscsi_cid_start);
  3762. if (!io_task->pwrb_handle) {
  3763. beiscsi_log(phba, KERN_ERR,
  3764. BEISCSI_LOG_IO |
  3765. BEISCSI_LOG_CONFIG,
  3766. "BM_%d : Alloc of WRB_HANDLE Failed"
  3767. "for the CID : %d\n",
  3768. beiscsi_conn->
  3769. beiscsi_conn_cid);
  3770. goto free_mgmt_hndls;
  3771. }
  3772. beiscsi_conn->plogin_wrb_handle =
  3773. io_task->pwrb_handle;
  3774. } else {
  3775. io_task->psgl_handle =
  3776. beiscsi_conn->plogin_sgl_handle;
  3777. io_task->pwrb_handle =
  3778. beiscsi_conn->plogin_wrb_handle;
  3779. }
  3780. beiscsi_conn->task = task;
  3781. } else {
  3782. spin_lock(&phba->mgmt_sgl_lock);
  3783. io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
  3784. spin_unlock(&phba->mgmt_sgl_lock);
  3785. if (!io_task->psgl_handle) {
  3786. beiscsi_log(phba, KERN_ERR,
  3787. BEISCSI_LOG_IO |
  3788. BEISCSI_LOG_CONFIG,
  3789. "BM_%d : Alloc of MGMT_SGL_ICD Failed"
  3790. "for the CID : %d\n",
  3791. beiscsi_conn->
  3792. beiscsi_conn_cid);
  3793. goto free_hndls;
  3794. }
  3795. io_task->pwrb_handle =
  3796. alloc_wrb_handle(phba,
  3797. beiscsi_conn->beiscsi_conn_cid -
  3798. phba->fw_config.iscsi_cid_start);
  3799. if (!io_task->pwrb_handle) {
  3800. beiscsi_log(phba, KERN_ERR,
  3801. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  3802. "BM_%d : Alloc of WRB_HANDLE Failed"
  3803. "for the CID : %d\n",
  3804. beiscsi_conn->beiscsi_conn_cid);
  3805. goto free_mgmt_hndls;
  3806. }
  3807. }
  3808. }
  3809. itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
  3810. wrb_index << 16) | (unsigned int)
  3811. (io_task->psgl_handle->sgl_index));
  3812. io_task->pwrb_handle->pio_handle = task;
  3813. io_task->cmd_bhs->iscsi_hdr.itt = itt;
  3814. return 0;
  3815. free_io_hndls:
  3816. spin_lock(&phba->io_sgl_lock);
  3817. free_io_sgl_handle(phba, io_task->psgl_handle);
  3818. spin_unlock(&phba->io_sgl_lock);
  3819. goto free_hndls;
  3820. free_mgmt_hndls:
  3821. spin_lock(&phba->mgmt_sgl_lock);
  3822. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  3823. spin_unlock(&phba->mgmt_sgl_lock);
  3824. free_hndls:
  3825. phwi_ctrlr = phba->phwi_ctrlr;
  3826. pwrb_context = &phwi_ctrlr->wrb_context[
  3827. beiscsi_conn->beiscsi_conn_cid -
  3828. phba->fw_config.iscsi_cid_start];
  3829. if (io_task->pwrb_handle)
  3830. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  3831. io_task->pwrb_handle = NULL;
  3832. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3833. io_task->bhs_pa.u.a64.address);
  3834. io_task->cmd_bhs = NULL;
  3835. return -ENOMEM;
  3836. }
  3837. int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
  3838. unsigned int num_sg, unsigned int xferlen,
  3839. unsigned int writedir)
  3840. {
  3841. struct beiscsi_io_task *io_task = task->dd_data;
  3842. struct iscsi_conn *conn = task->conn;
  3843. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3844. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3845. struct iscsi_wrb *pwrb = NULL;
  3846. unsigned int doorbell = 0;
  3847. pwrb = io_task->pwrb_handle->pwrb;
  3848. memset(pwrb, 0, sizeof(*pwrb));
  3849. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  3850. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  3851. if (writedir) {
  3852. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
  3853. INI_WR_CMD);
  3854. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
  3855. } else {
  3856. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
  3857. INI_RD_CMD);
  3858. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
  3859. }
  3860. io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
  3861. type, pwrb);
  3862. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
  3863. cpu_to_be16(*(unsigned short *)
  3864. &io_task->cmd_bhs->iscsi_hdr.lun));
  3865. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
  3866. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
  3867. io_task->pwrb_handle->wrb_index);
  3868. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
  3869. be32_to_cpu(task->cmdsn));
  3870. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
  3871. io_task->psgl_handle->sgl_index);
  3872. hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
  3873. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
  3874. io_task->pwrb_handle->nxt_wrb_index);
  3875. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3876. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3877. doorbell |= (io_task->pwrb_handle->wrb_index &
  3878. DB_DEF_PDU_WRB_INDEX_MASK) <<
  3879. DB_DEF_PDU_WRB_INDEX_SHIFT;
  3880. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3881. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3882. return 0;
  3883. }
  3884. static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
  3885. unsigned int num_sg, unsigned int xferlen,
  3886. unsigned int writedir)
  3887. {
  3888. struct beiscsi_io_task *io_task = task->dd_data;
  3889. struct iscsi_conn *conn = task->conn;
  3890. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3891. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3892. struct iscsi_wrb *pwrb = NULL;
  3893. unsigned int doorbell = 0;
  3894. pwrb = io_task->pwrb_handle->pwrb;
  3895. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  3896. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  3897. if (writedir) {
  3898. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3899. INI_WR_CMD);
  3900. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  3901. } else {
  3902. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  3903. INI_RD_CMD);
  3904. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  3905. }
  3906. io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
  3907. type, pwrb);
  3908. AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
  3909. cpu_to_be16(*(unsigned short *)
  3910. &io_task->cmd_bhs->iscsi_hdr.lun));
  3911. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
  3912. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3913. io_task->pwrb_handle->wrb_index);
  3914. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3915. be32_to_cpu(task->cmdsn));
  3916. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3917. io_task->psgl_handle->sgl_index);
  3918. hwi_write_sgl(pwrb, sg, num_sg, io_task);
  3919. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3920. io_task->pwrb_handle->nxt_wrb_index);
  3921. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3922. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3923. doorbell |= (io_task->pwrb_handle->wrb_index &
  3924. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3925. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3926. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3927. return 0;
  3928. }
  3929. static int beiscsi_mtask(struct iscsi_task *task)
  3930. {
  3931. struct beiscsi_io_task *io_task = task->dd_data;
  3932. struct iscsi_conn *conn = task->conn;
  3933. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3934. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3935. struct iscsi_wrb *pwrb = NULL;
  3936. unsigned int doorbell = 0;
  3937. unsigned int cid;
  3938. unsigned int pwrb_typeoffset = 0;
  3939. cid = beiscsi_conn->beiscsi_conn_cid;
  3940. pwrb = io_task->pwrb_handle->pwrb;
  3941. memset(pwrb, 0, sizeof(*pwrb));
  3942. if (chip_skh_r(phba->pcidev)) {
  3943. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
  3944. be32_to_cpu(task->cmdsn));
  3945. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
  3946. io_task->pwrb_handle->wrb_index);
  3947. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
  3948. io_task->psgl_handle->sgl_index);
  3949. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
  3950. task->data_count);
  3951. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
  3952. io_task->pwrb_handle->nxt_wrb_index);
  3953. pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
  3954. } else {
  3955. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  3956. be32_to_cpu(task->cmdsn));
  3957. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  3958. io_task->pwrb_handle->wrb_index);
  3959. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  3960. io_task->psgl_handle->sgl_index);
  3961. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
  3962. task->data_count);
  3963. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  3964. io_task->pwrb_handle->nxt_wrb_index);
  3965. pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
  3966. }
  3967. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  3968. case ISCSI_OP_LOGIN:
  3969. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
  3970. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  3971. hwi_write_buffer(pwrb, task);
  3972. break;
  3973. case ISCSI_OP_NOOP_OUT:
  3974. if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
  3975. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  3976. if (chip_skh_r(phba->pcidev))
  3977. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  3978. dmsg, pwrb, 1);
  3979. else
  3980. AMAP_SET_BITS(struct amap_iscsi_wrb,
  3981. dmsg, pwrb, 1);
  3982. } else {
  3983. ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
  3984. if (chip_skh_r(phba->pcidev))
  3985. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  3986. dmsg, pwrb, 0);
  3987. else
  3988. AMAP_SET_BITS(struct amap_iscsi_wrb,
  3989. dmsg, pwrb, 0);
  3990. }
  3991. hwi_write_buffer(pwrb, task);
  3992. break;
  3993. case ISCSI_OP_TEXT:
  3994. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  3995. hwi_write_buffer(pwrb, task);
  3996. break;
  3997. case ISCSI_OP_SCSI_TMFUNC:
  3998. ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
  3999. hwi_write_buffer(pwrb, task);
  4000. break;
  4001. case ISCSI_OP_LOGOUT:
  4002. ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
  4003. hwi_write_buffer(pwrb, task);
  4004. break;
  4005. default:
  4006. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4007. "BM_%d : opcode =%d Not supported\n",
  4008. task->hdr->opcode & ISCSI_OPCODE_MASK);
  4009. return -EINVAL;
  4010. }
  4011. /* Set the task type */
  4012. io_task->wrb_type = (chip_skh_r(phba->pcidev)) ?
  4013. AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb) :
  4014. AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb);
  4015. doorbell |= cid & DB_WRB_POST_CID_MASK;
  4016. doorbell |= (io_task->pwrb_handle->wrb_index &
  4017. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  4018. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  4019. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  4020. return 0;
  4021. }
  4022. static int beiscsi_task_xmit(struct iscsi_task *task)
  4023. {
  4024. struct beiscsi_io_task *io_task = task->dd_data;
  4025. struct scsi_cmnd *sc = task->sc;
  4026. struct beiscsi_hba *phba = NULL;
  4027. struct scatterlist *sg;
  4028. int num_sg;
  4029. unsigned int writedir = 0, xferlen = 0;
  4030. phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba;
  4031. if (!sc)
  4032. return beiscsi_mtask(task);
  4033. io_task->scsi_cmnd = sc;
  4034. num_sg = scsi_dma_map(sc);
  4035. if (num_sg < 0) {
  4036. struct iscsi_conn *conn = task->conn;
  4037. struct beiscsi_hba *phba = NULL;
  4038. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  4039. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_IO,
  4040. "BM_%d : scsi_dma_map Failed\n");
  4041. return num_sg;
  4042. }
  4043. xferlen = scsi_bufflen(sc);
  4044. sg = scsi_sglist(sc);
  4045. if (sc->sc_data_direction == DMA_TO_DEVICE)
  4046. writedir = 1;
  4047. else
  4048. writedir = 0;
  4049. return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
  4050. }
  4051. /**
  4052. * beiscsi_bsg_request - handle bsg request from ISCSI transport
  4053. * @job: job to handle
  4054. */
  4055. static int beiscsi_bsg_request(struct bsg_job *job)
  4056. {
  4057. struct Scsi_Host *shost;
  4058. struct beiscsi_hba *phba;
  4059. struct iscsi_bsg_request *bsg_req = job->request;
  4060. int rc = -EINVAL;
  4061. unsigned int tag;
  4062. struct be_dma_mem nonemb_cmd;
  4063. struct be_cmd_resp_hdr *resp;
  4064. struct iscsi_bsg_reply *bsg_reply = job->reply;
  4065. unsigned short status, extd_status;
  4066. shost = iscsi_job_to_shost(job);
  4067. phba = iscsi_host_priv(shost);
  4068. switch (bsg_req->msgcode) {
  4069. case ISCSI_BSG_HST_VENDOR:
  4070. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  4071. job->request_payload.payload_len,
  4072. &nonemb_cmd.dma);
  4073. if (nonemb_cmd.va == NULL) {
  4074. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4075. "BM_%d : Failed to allocate memory for "
  4076. "beiscsi_bsg_request\n");
  4077. return -ENOMEM;
  4078. }
  4079. tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
  4080. &nonemb_cmd);
  4081. if (!tag) {
  4082. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4083. "BM_%d : MBX Tag Allocation Failed\n");
  4084. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  4085. nonemb_cmd.va, nonemb_cmd.dma);
  4086. return -EAGAIN;
  4087. } else
  4088. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  4089. phba->ctrl.mcc_numtag[tag]);
  4090. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  4091. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  4092. free_mcc_tag(&phba->ctrl, tag);
  4093. resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
  4094. sg_copy_from_buffer(job->reply_payload.sg_list,
  4095. job->reply_payload.sg_cnt,
  4096. nonemb_cmd.va, (resp->response_length
  4097. + sizeof(*resp)));
  4098. bsg_reply->reply_payload_rcv_len = resp->response_length;
  4099. bsg_reply->result = status;
  4100. bsg_job_done(job, bsg_reply->result,
  4101. bsg_reply->reply_payload_rcv_len);
  4102. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  4103. nonemb_cmd.va, nonemb_cmd.dma);
  4104. if (status || extd_status) {
  4105. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4106. "BM_%d : MBX Cmd Failed"
  4107. " status = %d extd_status = %d\n",
  4108. status, extd_status);
  4109. return -EIO;
  4110. } else {
  4111. rc = 0;
  4112. }
  4113. break;
  4114. default:
  4115. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4116. "BM_%d : Unsupported bsg command: 0x%x\n",
  4117. bsg_req->msgcode);
  4118. break;
  4119. }
  4120. return rc;
  4121. }
  4122. void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
  4123. {
  4124. /* Set the logging parameter */
  4125. beiscsi_log_enable_init(phba, beiscsi_log_enable);
  4126. }
  4127. /*
  4128. * beiscsi_quiesce()- Cleanup Driver resources
  4129. * @phba: Instance Priv structure
  4130. *
  4131. * Free the OS and HW resources held by the driver
  4132. **/
  4133. static void beiscsi_quiesce(struct beiscsi_hba *phba)
  4134. {
  4135. struct hwi_controller *phwi_ctrlr;
  4136. struct hwi_context_memory *phwi_context;
  4137. struct be_eq_obj *pbe_eq;
  4138. unsigned int i, msix_vec;
  4139. phwi_ctrlr = phba->phwi_ctrlr;
  4140. phwi_context = phwi_ctrlr->phwi_ctxt;
  4141. hwi_disable_intr(phba);
  4142. if (phba->msix_enabled) {
  4143. for (i = 0; i <= phba->num_cpus; i++) {
  4144. msix_vec = phba->msix_entries[i].vector;
  4145. free_irq(msix_vec, &phwi_context->be_eq[i]);
  4146. kfree(phba->msi_name[i]);
  4147. }
  4148. } else
  4149. if (phba->pcidev->irq)
  4150. free_irq(phba->pcidev->irq, phba);
  4151. pci_disable_msix(phba->pcidev);
  4152. destroy_workqueue(phba->wq);
  4153. if (blk_iopoll_enabled)
  4154. for (i = 0; i < phba->num_cpus; i++) {
  4155. pbe_eq = &phwi_context->be_eq[i];
  4156. blk_iopoll_disable(&pbe_eq->iopoll);
  4157. }
  4158. beiscsi_clean_port(phba);
  4159. beiscsi_free_mem(phba);
  4160. beiscsi_unmap_pci_function(phba);
  4161. pci_free_consistent(phba->pcidev,
  4162. phba->ctrl.mbox_mem_alloced.size,
  4163. phba->ctrl.mbox_mem_alloced.va,
  4164. phba->ctrl.mbox_mem_alloced.dma);
  4165. }
  4166. static void beiscsi_remove(struct pci_dev *pcidev)
  4167. {
  4168. struct beiscsi_hba *phba = NULL;
  4169. phba = pci_get_drvdata(pcidev);
  4170. if (!phba) {
  4171. dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
  4172. return;
  4173. }
  4174. beiscsi_destroy_def_ifaces(phba);
  4175. beiscsi_quiesce(phba);
  4176. iscsi_boot_destroy_kset(phba->boot_kset);
  4177. iscsi_host_remove(phba->shost);
  4178. pci_dev_put(phba->pcidev);
  4179. iscsi_host_free(phba->shost);
  4180. pci_disable_device(pcidev);
  4181. }
  4182. static void beiscsi_shutdown(struct pci_dev *pcidev)
  4183. {
  4184. struct beiscsi_hba *phba = NULL;
  4185. phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
  4186. if (!phba) {
  4187. dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
  4188. return;
  4189. }
  4190. beiscsi_quiesce(phba);
  4191. pci_disable_device(pcidev);
  4192. }
  4193. static void beiscsi_msix_enable(struct beiscsi_hba *phba)
  4194. {
  4195. int i, status;
  4196. for (i = 0; i <= phba->num_cpus; i++)
  4197. phba->msix_entries[i].entry = i;
  4198. status = pci_enable_msix(phba->pcidev, phba->msix_entries,
  4199. (phba->num_cpus + 1));
  4200. if (!status)
  4201. phba->msix_enabled = true;
  4202. return;
  4203. }
  4204. static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
  4205. const struct pci_device_id *id)
  4206. {
  4207. struct beiscsi_hba *phba = NULL;
  4208. struct hwi_controller *phwi_ctrlr;
  4209. struct hwi_context_memory *phwi_context;
  4210. struct be_eq_obj *pbe_eq;
  4211. int ret, i;
  4212. ret = beiscsi_enable_pci(pcidev);
  4213. if (ret < 0) {
  4214. dev_err(&pcidev->dev,
  4215. "beiscsi_dev_probe - Failed to enable pci device\n");
  4216. return ret;
  4217. }
  4218. phba = beiscsi_hba_alloc(pcidev);
  4219. if (!phba) {
  4220. dev_err(&pcidev->dev,
  4221. "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
  4222. goto disable_pci;
  4223. }
  4224. /* Initialize Driver configuration Paramters */
  4225. beiscsi_hba_attrs_init(phba);
  4226. switch (pcidev->device) {
  4227. case BE_DEVICE_ID1:
  4228. case OC_DEVICE_ID1:
  4229. case OC_DEVICE_ID2:
  4230. phba->generation = BE_GEN2;
  4231. phba->iotask_fn = beiscsi_iotask;
  4232. break;
  4233. case BE_DEVICE_ID2:
  4234. case OC_DEVICE_ID3:
  4235. phba->generation = BE_GEN3;
  4236. phba->iotask_fn = beiscsi_iotask;
  4237. break;
  4238. case OC_SKH_ID1:
  4239. phba->generation = BE_GEN4;
  4240. phba->iotask_fn = beiscsi_iotask_v2;
  4241. default:
  4242. phba->generation = 0;
  4243. }
  4244. if (enable_msix)
  4245. find_num_cpus(phba);
  4246. else
  4247. phba->num_cpus = 1;
  4248. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  4249. "BM_%d : num_cpus = %d\n",
  4250. phba->num_cpus);
  4251. if (enable_msix) {
  4252. beiscsi_msix_enable(phba);
  4253. if (!phba->msix_enabled)
  4254. phba->num_cpus = 1;
  4255. }
  4256. ret = be_ctrl_init(phba, pcidev);
  4257. if (ret) {
  4258. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4259. "BM_%d : beiscsi_dev_probe-"
  4260. "Failed in be_ctrl_init\n");
  4261. goto hba_free;
  4262. }
  4263. ret = beiscsi_cmd_reset_function(phba);
  4264. if (ret) {
  4265. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4266. "BM_%d : Reset Failed. Aborting Crashdump\n");
  4267. goto hba_free;
  4268. }
  4269. ret = be_chk_reset_complete(phba);
  4270. if (ret) {
  4271. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4272. "BM_%d : Failed to get out of reset."
  4273. "Aborting Crashdump\n");
  4274. goto hba_free;
  4275. }
  4276. spin_lock_init(&phba->io_sgl_lock);
  4277. spin_lock_init(&phba->mgmt_sgl_lock);
  4278. spin_lock_init(&phba->isr_lock);
  4279. ret = mgmt_get_fw_config(&phba->ctrl, phba);
  4280. if (ret != 0) {
  4281. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4282. "BM_%d : Error getting fw config\n");
  4283. goto free_port;
  4284. }
  4285. phba->shost->max_id = phba->fw_config.iscsi_cid_count;
  4286. beiscsi_get_params(phba);
  4287. phba->shost->can_queue = phba->params.ios_per_ctrl;
  4288. ret = beiscsi_init_port(phba);
  4289. if (ret < 0) {
  4290. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4291. "BM_%d : beiscsi_dev_probe-"
  4292. "Failed in beiscsi_init_port\n");
  4293. goto free_port;
  4294. }
  4295. for (i = 0; i < MAX_MCC_CMD ; i++) {
  4296. init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
  4297. phba->ctrl.mcc_tag[i] = i + 1;
  4298. phba->ctrl.mcc_numtag[i + 1] = 0;
  4299. phba->ctrl.mcc_tag_available++;
  4300. }
  4301. phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
  4302. snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
  4303. phba->shost->host_no);
  4304. phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
  4305. if (!phba->wq) {
  4306. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4307. "BM_%d : beiscsi_dev_probe-"
  4308. "Failed to allocate work queue\n");
  4309. goto free_twq;
  4310. }
  4311. phwi_ctrlr = phba->phwi_ctrlr;
  4312. phwi_context = phwi_ctrlr->phwi_ctxt;
  4313. if (blk_iopoll_enabled) {
  4314. for (i = 0; i < phba->num_cpus; i++) {
  4315. pbe_eq = &phwi_context->be_eq[i];
  4316. blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
  4317. be_iopoll);
  4318. blk_iopoll_enable(&pbe_eq->iopoll);
  4319. }
  4320. i = (phba->msix_enabled) ? i : 0;
  4321. /* Work item for MCC handling */
  4322. pbe_eq = &phwi_context->be_eq[i];
  4323. INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
  4324. } else {
  4325. if (phba->msix_enabled) {
  4326. for (i = 0; i <= phba->num_cpus; i++) {
  4327. pbe_eq = &phwi_context->be_eq[i];
  4328. INIT_WORK(&pbe_eq->work_cqs,
  4329. beiscsi_process_all_cqs);
  4330. }
  4331. } else {
  4332. pbe_eq = &phwi_context->be_eq[0];
  4333. INIT_WORK(&pbe_eq->work_cqs,
  4334. beiscsi_process_all_cqs);
  4335. }
  4336. }
  4337. ret = beiscsi_init_irqs(phba);
  4338. if (ret < 0) {
  4339. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4340. "BM_%d : beiscsi_dev_probe-"
  4341. "Failed to beiscsi_init_irqs\n");
  4342. goto free_blkenbld;
  4343. }
  4344. hwi_enable_intr(phba);
  4345. if (beiscsi_setup_boot_info(phba))
  4346. /*
  4347. * log error but continue, because we may not be using
  4348. * iscsi boot.
  4349. */
  4350. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4351. "BM_%d : Could not set up "
  4352. "iSCSI boot info.\n");
  4353. beiscsi_create_def_ifaces(phba);
  4354. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  4355. "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
  4356. return 0;
  4357. free_blkenbld:
  4358. destroy_workqueue(phba->wq);
  4359. if (blk_iopoll_enabled)
  4360. for (i = 0; i < phba->num_cpus; i++) {
  4361. pbe_eq = &phwi_context->be_eq[i];
  4362. blk_iopoll_disable(&pbe_eq->iopoll);
  4363. }
  4364. free_twq:
  4365. beiscsi_clean_port(phba);
  4366. beiscsi_free_mem(phba);
  4367. free_port:
  4368. pci_free_consistent(phba->pcidev,
  4369. phba->ctrl.mbox_mem_alloced.size,
  4370. phba->ctrl.mbox_mem_alloced.va,
  4371. phba->ctrl.mbox_mem_alloced.dma);
  4372. beiscsi_unmap_pci_function(phba);
  4373. hba_free:
  4374. if (phba->msix_enabled)
  4375. pci_disable_msix(phba->pcidev);
  4376. iscsi_host_remove(phba->shost);
  4377. pci_dev_put(phba->pcidev);
  4378. iscsi_host_free(phba->shost);
  4379. disable_pci:
  4380. pci_disable_device(pcidev);
  4381. return ret;
  4382. }
  4383. struct iscsi_transport beiscsi_iscsi_transport = {
  4384. .owner = THIS_MODULE,
  4385. .name = DRV_NAME,
  4386. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
  4387. CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
  4388. .create_session = beiscsi_session_create,
  4389. .destroy_session = beiscsi_session_destroy,
  4390. .create_conn = beiscsi_conn_create,
  4391. .bind_conn = beiscsi_conn_bind,
  4392. .destroy_conn = iscsi_conn_teardown,
  4393. .attr_is_visible = be2iscsi_attr_is_visible,
  4394. .set_iface_param = be2iscsi_iface_set_param,
  4395. .get_iface_param = be2iscsi_iface_get_param,
  4396. .set_param = beiscsi_set_param,
  4397. .get_conn_param = iscsi_conn_get_param,
  4398. .get_session_param = iscsi_session_get_param,
  4399. .get_host_param = beiscsi_get_host_param,
  4400. .start_conn = beiscsi_conn_start,
  4401. .stop_conn = iscsi_conn_stop,
  4402. .send_pdu = iscsi_conn_send_pdu,
  4403. .xmit_task = beiscsi_task_xmit,
  4404. .cleanup_task = beiscsi_cleanup_task,
  4405. .alloc_pdu = beiscsi_alloc_pdu,
  4406. .parse_pdu_itt = beiscsi_parse_pdu,
  4407. .get_stats = beiscsi_conn_get_stats,
  4408. .get_ep_param = beiscsi_ep_get_param,
  4409. .ep_connect = beiscsi_ep_connect,
  4410. .ep_poll = beiscsi_ep_poll,
  4411. .ep_disconnect = beiscsi_ep_disconnect,
  4412. .session_recovery_timedout = iscsi_session_recovery_timedout,
  4413. .bsg_request = beiscsi_bsg_request,
  4414. };
  4415. static struct pci_driver beiscsi_pci_driver = {
  4416. .name = DRV_NAME,
  4417. .probe = beiscsi_dev_probe,
  4418. .remove = beiscsi_remove,
  4419. .shutdown = beiscsi_shutdown,
  4420. .id_table = beiscsi_pci_id_table
  4421. };
  4422. static int __init beiscsi_module_init(void)
  4423. {
  4424. int ret;
  4425. beiscsi_scsi_transport =
  4426. iscsi_register_transport(&beiscsi_iscsi_transport);
  4427. if (!beiscsi_scsi_transport) {
  4428. printk(KERN_ERR
  4429. "beiscsi_module_init - Unable to register beiscsi transport.\n");
  4430. return -ENOMEM;
  4431. }
  4432. printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
  4433. &beiscsi_iscsi_transport);
  4434. ret = pci_register_driver(&beiscsi_pci_driver);
  4435. if (ret) {
  4436. printk(KERN_ERR
  4437. "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
  4438. goto unregister_iscsi_transport;
  4439. }
  4440. return 0;
  4441. unregister_iscsi_transport:
  4442. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  4443. return ret;
  4444. }
  4445. static void __exit beiscsi_module_exit(void)
  4446. {
  4447. pci_unregister_driver(&beiscsi_pci_driver);
  4448. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  4449. }
  4450. module_init(beiscsi_module_init);
  4451. module_exit(beiscsi_module_exit);