be_main.c 145 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167
  1. /**
  2. * Copyright (C) 2005 - 2013 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. DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
  145. DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
  146. DEVICE_ATTR(beiscsi_active_cid_count, S_IRUGO, beiscsi_active_cid_disp, NULL);
  147. struct device_attribute *beiscsi_attrs[] = {
  148. &dev_attr_beiscsi_log_enable,
  149. &dev_attr_beiscsi_drvr_ver,
  150. &dev_attr_beiscsi_adapter_family,
  151. &dev_attr_beiscsi_fw_ver,
  152. &dev_attr_beiscsi_active_cid_count,
  153. NULL,
  154. };
  155. static char const *cqe_desc[] = {
  156. "RESERVED_DESC",
  157. "SOL_CMD_COMPLETE",
  158. "SOL_CMD_KILLED_DATA_DIGEST_ERR",
  159. "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
  160. "CXN_KILLED_BURST_LEN_MISMATCH",
  161. "CXN_KILLED_AHS_RCVD",
  162. "CXN_KILLED_HDR_DIGEST_ERR",
  163. "CXN_KILLED_UNKNOWN_HDR",
  164. "CXN_KILLED_STALE_ITT_TTT_RCVD",
  165. "CXN_KILLED_INVALID_ITT_TTT_RCVD",
  166. "CXN_KILLED_RST_RCVD",
  167. "CXN_KILLED_TIMED_OUT",
  168. "CXN_KILLED_RST_SENT",
  169. "CXN_KILLED_FIN_RCVD",
  170. "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
  171. "CXN_KILLED_BAD_WRB_INDEX_ERROR",
  172. "CXN_KILLED_OVER_RUN_RESIDUAL",
  173. "CXN_KILLED_UNDER_RUN_RESIDUAL",
  174. "CMD_KILLED_INVALID_STATSN_RCVD",
  175. "CMD_KILLED_INVALID_R2T_RCVD",
  176. "CMD_CXN_KILLED_LUN_INVALID",
  177. "CMD_CXN_KILLED_ICD_INVALID",
  178. "CMD_CXN_KILLED_ITT_INVALID",
  179. "CMD_CXN_KILLED_SEQ_OUTOFORDER",
  180. "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
  181. "CXN_INVALIDATE_NOTIFY",
  182. "CXN_INVALIDATE_INDEX_NOTIFY",
  183. "CMD_INVALIDATED_NOTIFY",
  184. "UNSOL_HDR_NOTIFY",
  185. "UNSOL_DATA_NOTIFY",
  186. "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
  187. "DRIVERMSG_NOTIFY",
  188. "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
  189. "SOL_CMD_KILLED_DIF_ERR",
  190. "CXN_KILLED_SYN_RCVD",
  191. "CXN_KILLED_IMM_DATA_RCVD"
  192. };
  193. static int beiscsi_slave_configure(struct scsi_device *sdev)
  194. {
  195. blk_queue_max_segment_size(sdev->request_queue, 65536);
  196. return 0;
  197. }
  198. static int beiscsi_eh_abort(struct scsi_cmnd *sc)
  199. {
  200. struct iscsi_cls_session *cls_session;
  201. struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
  202. struct beiscsi_io_task *aborted_io_task;
  203. struct iscsi_conn *conn;
  204. struct beiscsi_conn *beiscsi_conn;
  205. struct beiscsi_hba *phba;
  206. struct iscsi_session *session;
  207. struct invalidate_command_table *inv_tbl;
  208. struct be_dma_mem nonemb_cmd;
  209. unsigned int cid, tag, num_invalidate;
  210. cls_session = starget_to_session(scsi_target(sc->device));
  211. session = cls_session->dd_data;
  212. spin_lock_bh(&session->lock);
  213. if (!aborted_task || !aborted_task->sc) {
  214. /* we raced */
  215. spin_unlock_bh(&session->lock);
  216. return SUCCESS;
  217. }
  218. aborted_io_task = aborted_task->dd_data;
  219. if (!aborted_io_task->scsi_cmnd) {
  220. /* raced or invalid command */
  221. spin_unlock_bh(&session->lock);
  222. return SUCCESS;
  223. }
  224. spin_unlock_bh(&session->lock);
  225. conn = aborted_task->conn;
  226. beiscsi_conn = conn->dd_data;
  227. phba = beiscsi_conn->phba;
  228. /* invalidate iocb */
  229. cid = beiscsi_conn->beiscsi_conn_cid;
  230. inv_tbl = phba->inv_tbl;
  231. memset(inv_tbl, 0x0, sizeof(*inv_tbl));
  232. inv_tbl->cid = cid;
  233. inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
  234. num_invalidate = 1;
  235. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  236. sizeof(struct invalidate_commands_params_in),
  237. &nonemb_cmd.dma);
  238. if (nonemb_cmd.va == NULL) {
  239. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
  240. "BM_%d : Failed to allocate memory for"
  241. "mgmt_invalidate_icds\n");
  242. return FAILED;
  243. }
  244. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  245. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  246. cid, &nonemb_cmd);
  247. if (!tag) {
  248. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
  249. "BM_%d : mgmt_invalidate_icds could not be"
  250. "submitted\n");
  251. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  252. nonemb_cmd.va, nonemb_cmd.dma);
  253. return FAILED;
  254. }
  255. beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
  256. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  257. nonemb_cmd.va, nonemb_cmd.dma);
  258. return iscsi_eh_abort(sc);
  259. }
  260. static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
  261. {
  262. struct iscsi_task *abrt_task;
  263. struct beiscsi_io_task *abrt_io_task;
  264. struct iscsi_conn *conn;
  265. struct beiscsi_conn *beiscsi_conn;
  266. struct beiscsi_hba *phba;
  267. struct iscsi_session *session;
  268. struct iscsi_cls_session *cls_session;
  269. struct invalidate_command_table *inv_tbl;
  270. struct be_dma_mem nonemb_cmd;
  271. unsigned int cid, tag, i, num_invalidate;
  272. /* invalidate iocbs */
  273. cls_session = starget_to_session(scsi_target(sc->device));
  274. session = cls_session->dd_data;
  275. spin_lock_bh(&session->lock);
  276. if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
  277. spin_unlock_bh(&session->lock);
  278. return FAILED;
  279. }
  280. conn = session->leadconn;
  281. beiscsi_conn = conn->dd_data;
  282. phba = beiscsi_conn->phba;
  283. cid = beiscsi_conn->beiscsi_conn_cid;
  284. inv_tbl = phba->inv_tbl;
  285. memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
  286. num_invalidate = 0;
  287. for (i = 0; i < conn->session->cmds_max; i++) {
  288. abrt_task = conn->session->cmds[i];
  289. abrt_io_task = abrt_task->dd_data;
  290. if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
  291. continue;
  292. if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
  293. continue;
  294. inv_tbl->cid = cid;
  295. inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
  296. num_invalidate++;
  297. inv_tbl++;
  298. }
  299. spin_unlock_bh(&session->lock);
  300. inv_tbl = phba->inv_tbl;
  301. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  302. sizeof(struct invalidate_commands_params_in),
  303. &nonemb_cmd.dma);
  304. if (nonemb_cmd.va == NULL) {
  305. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
  306. "BM_%d : Failed to allocate memory for"
  307. "mgmt_invalidate_icds\n");
  308. return FAILED;
  309. }
  310. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  311. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  312. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  313. cid, &nonemb_cmd);
  314. if (!tag) {
  315. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
  316. "BM_%d : mgmt_invalidate_icds could not be"
  317. " submitted\n");
  318. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  319. nonemb_cmd.va, nonemb_cmd.dma);
  320. return FAILED;
  321. }
  322. beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
  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;
  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. struct pdu_base *ppdu,
  943. unsigned long pdu_len,
  944. void *pbuffer, unsigned long buf_len)
  945. {
  946. struct iscsi_conn *conn = beiscsi_conn->conn;
  947. struct iscsi_session *session = conn->session;
  948. struct iscsi_task *task;
  949. struct beiscsi_io_task *io_task;
  950. struct iscsi_hdr *login_hdr;
  951. switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
  952. PDUBASE_OPCODE_MASK) {
  953. case ISCSI_OP_NOOP_IN:
  954. pbuffer = NULL;
  955. buf_len = 0;
  956. break;
  957. case ISCSI_OP_ASYNC_EVENT:
  958. break;
  959. case ISCSI_OP_REJECT:
  960. WARN_ON(!pbuffer);
  961. WARN_ON(!(buf_len == 48));
  962. beiscsi_log(phba, KERN_ERR,
  963. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  964. "BM_%d : In ISCSI_OP_REJECT\n");
  965. break;
  966. case ISCSI_OP_LOGIN_RSP:
  967. case ISCSI_OP_TEXT_RSP:
  968. task = conn->login_task;
  969. io_task = task->dd_data;
  970. login_hdr = (struct iscsi_hdr *)ppdu;
  971. login_hdr->itt = io_task->libiscsi_itt;
  972. break;
  973. default:
  974. beiscsi_log(phba, KERN_WARNING,
  975. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  976. "BM_%d : Unrecognized opcode 0x%x in async msg\n",
  977. (ppdu->
  978. dw[offsetof(struct amap_pdu_base, opcode) / 32]
  979. & PDUBASE_OPCODE_MASK));
  980. return 1;
  981. }
  982. spin_lock_bh(&session->lock);
  983. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
  984. spin_unlock_bh(&session->lock);
  985. return 0;
  986. }
  987. static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
  988. {
  989. struct sgl_handle *psgl_handle;
  990. if (phba->io_sgl_hndl_avbl) {
  991. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  992. "BM_%d : In alloc_io_sgl_handle,"
  993. " io_sgl_alloc_index=%d\n",
  994. phba->io_sgl_alloc_index);
  995. psgl_handle = phba->io_sgl_hndl_base[phba->
  996. io_sgl_alloc_index];
  997. phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
  998. phba->io_sgl_hndl_avbl--;
  999. if (phba->io_sgl_alloc_index == (phba->params.
  1000. ios_per_ctrl - 1))
  1001. phba->io_sgl_alloc_index = 0;
  1002. else
  1003. phba->io_sgl_alloc_index++;
  1004. } else
  1005. psgl_handle = NULL;
  1006. return psgl_handle;
  1007. }
  1008. static void
  1009. free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
  1010. {
  1011. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  1012. "BM_%d : In free_,io_sgl_free_index=%d\n",
  1013. phba->io_sgl_free_index);
  1014. if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
  1015. /*
  1016. * this can happen if clean_task is called on a task that
  1017. * failed in xmit_task or alloc_pdu.
  1018. */
  1019. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  1020. "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
  1021. "value there=%p\n", phba->io_sgl_free_index,
  1022. phba->io_sgl_hndl_base
  1023. [phba->io_sgl_free_index]);
  1024. return;
  1025. }
  1026. phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
  1027. phba->io_sgl_hndl_avbl++;
  1028. if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
  1029. phba->io_sgl_free_index = 0;
  1030. else
  1031. phba->io_sgl_free_index++;
  1032. }
  1033. /**
  1034. * alloc_wrb_handle - To allocate a wrb handle
  1035. * @phba: The hba pointer
  1036. * @cid: The cid to use for allocation
  1037. *
  1038. * This happens under session_lock until submission to chip
  1039. */
  1040. struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
  1041. {
  1042. struct hwi_wrb_context *pwrb_context;
  1043. struct hwi_controller *phwi_ctrlr;
  1044. struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
  1045. uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
  1046. phwi_ctrlr = phba->phwi_ctrlr;
  1047. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  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,
  1139. struct common_sol_cqe *csol_cqe)
  1140. {
  1141. struct beiscsi_io_task *io_task = task->dd_data;
  1142. struct be_status_bhs *sts_bhs =
  1143. (struct be_status_bhs *)io_task->cmd_bhs;
  1144. struct iscsi_conn *conn = beiscsi_conn->conn;
  1145. unsigned char *sense;
  1146. u32 resid = 0, exp_cmdsn, max_cmdsn;
  1147. u8 rsp, status, flags;
  1148. exp_cmdsn = csol_cqe->exp_cmdsn;
  1149. max_cmdsn = (csol_cqe->exp_cmdsn +
  1150. csol_cqe->cmd_wnd - 1);
  1151. rsp = csol_cqe->i_resp;
  1152. status = csol_cqe->i_sts;
  1153. flags = csol_cqe->i_flags;
  1154. resid = csol_cqe->res_cnt;
  1155. if (!task->sc) {
  1156. if (io_task->scsi_cmnd)
  1157. scsi_dma_unmap(io_task->scsi_cmnd);
  1158. return;
  1159. }
  1160. task->sc->result = (DID_OK << 16) | status;
  1161. if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
  1162. task->sc->result = DID_ERROR << 16;
  1163. goto unmap;
  1164. }
  1165. /* bidi not initially supported */
  1166. if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
  1167. if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
  1168. task->sc->result = DID_ERROR << 16;
  1169. if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
  1170. scsi_set_resid(task->sc, resid);
  1171. if (!status && (scsi_bufflen(task->sc) - resid <
  1172. task->sc->underflow))
  1173. task->sc->result = DID_ERROR << 16;
  1174. }
  1175. }
  1176. if (status == SAM_STAT_CHECK_CONDITION) {
  1177. u16 sense_len;
  1178. unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
  1179. sense = sts_bhs->sense_info + sizeof(unsigned short);
  1180. sense_len = be16_to_cpu(*slen);
  1181. memcpy(task->sc->sense_buffer, sense,
  1182. min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
  1183. }
  1184. if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
  1185. conn->rxdata_octets += resid;
  1186. unmap:
  1187. scsi_dma_unmap(io_task->scsi_cmnd);
  1188. iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
  1189. }
  1190. static void
  1191. be_complete_logout(struct beiscsi_conn *beiscsi_conn,
  1192. struct iscsi_task *task,
  1193. struct common_sol_cqe *csol_cqe)
  1194. {
  1195. struct iscsi_logout_rsp *hdr;
  1196. struct beiscsi_io_task *io_task = task->dd_data;
  1197. struct iscsi_conn *conn = beiscsi_conn->conn;
  1198. hdr = (struct iscsi_logout_rsp *)task->hdr;
  1199. hdr->opcode = ISCSI_OP_LOGOUT_RSP;
  1200. hdr->t2wait = 5;
  1201. hdr->t2retain = 0;
  1202. hdr->flags = csol_cqe->i_flags;
  1203. hdr->response = csol_cqe->i_resp;
  1204. hdr->exp_cmdsn = csol_cqe->exp_cmdsn;
  1205. hdr->max_cmdsn = (csol_cqe->exp_cmdsn + csol_cqe->cmd_wnd - 1);
  1206. hdr->dlength[0] = 0;
  1207. hdr->dlength[1] = 0;
  1208. hdr->dlength[2] = 0;
  1209. hdr->hlength = 0;
  1210. hdr->itt = io_task->libiscsi_itt;
  1211. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1212. }
  1213. static void
  1214. be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
  1215. struct iscsi_task *task,
  1216. struct common_sol_cqe *csol_cqe)
  1217. {
  1218. struct iscsi_tm_rsp *hdr;
  1219. struct iscsi_conn *conn = beiscsi_conn->conn;
  1220. struct beiscsi_io_task *io_task = task->dd_data;
  1221. hdr = (struct iscsi_tm_rsp *)task->hdr;
  1222. hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
  1223. hdr->flags = csol_cqe->i_flags;
  1224. hdr->response = csol_cqe->i_resp;
  1225. hdr->exp_cmdsn = csol_cqe->exp_cmdsn;
  1226. hdr->max_cmdsn = (csol_cqe->exp_cmdsn +
  1227. csol_cqe->cmd_wnd - 1);
  1228. hdr->itt = io_task->libiscsi_itt;
  1229. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1230. }
  1231. static void
  1232. hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
  1233. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1234. {
  1235. struct hwi_wrb_context *pwrb_context;
  1236. struct wrb_handle *pwrb_handle = NULL;
  1237. struct hwi_controller *phwi_ctrlr;
  1238. struct iscsi_task *task;
  1239. struct beiscsi_io_task *io_task;
  1240. uint16_t wrb_index, cid, cri_index;
  1241. phwi_ctrlr = phba->phwi_ctrlr;
  1242. if (is_chip_be2_be3r(phba)) {
  1243. wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
  1244. wrb_idx, psol);
  1245. cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
  1246. cid, psol);
  1247. } else {
  1248. wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
  1249. wrb_idx, psol);
  1250. cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
  1251. cid, psol);
  1252. }
  1253. cri_index = BE_GET_CRI_FROM_CID(cid);
  1254. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  1255. pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
  1256. task = pwrb_handle->pio_handle;
  1257. io_task = task->dd_data;
  1258. memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb));
  1259. iscsi_put_task(task);
  1260. }
  1261. static void
  1262. be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
  1263. struct iscsi_task *task,
  1264. struct common_sol_cqe *csol_cqe)
  1265. {
  1266. struct iscsi_nopin *hdr;
  1267. struct iscsi_conn *conn = beiscsi_conn->conn;
  1268. struct beiscsi_io_task *io_task = task->dd_data;
  1269. hdr = (struct iscsi_nopin *)task->hdr;
  1270. hdr->flags = csol_cqe->i_flags;
  1271. hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
  1272. hdr->max_cmdsn = be32_to_cpu(hdr->exp_cmdsn +
  1273. csol_cqe->cmd_wnd - 1);
  1274. hdr->opcode = ISCSI_OP_NOOP_IN;
  1275. hdr->itt = io_task->libiscsi_itt;
  1276. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1277. }
  1278. static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
  1279. struct sol_cqe *psol,
  1280. struct common_sol_cqe *csol_cqe)
  1281. {
  1282. if (is_chip_be2_be3r(phba)) {
  1283. csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
  1284. i_exp_cmd_sn, psol);
  1285. csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
  1286. i_res_cnt, psol);
  1287. csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
  1288. i_cmd_wnd, psol);
  1289. csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
  1290. wrb_index, psol);
  1291. csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
  1292. cid, psol);
  1293. csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
  1294. hw_sts, psol);
  1295. csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
  1296. i_resp, psol);
  1297. csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
  1298. i_sts, psol);
  1299. csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
  1300. i_flags, psol);
  1301. } else {
  1302. csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1303. i_exp_cmd_sn, psol);
  1304. csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1305. i_res_cnt, psol);
  1306. csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1307. wrb_index, psol);
  1308. csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1309. cid, psol);
  1310. csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1311. hw_sts, psol);
  1312. csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
  1313. i_cmd_wnd, psol);
  1314. if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1315. cmd_cmpl, psol))
  1316. csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1317. i_sts, psol);
  1318. else
  1319. csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1320. i_sts, psol);
  1321. if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1322. u, psol))
  1323. csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
  1324. if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1325. o, psol))
  1326. csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
  1327. }
  1328. }
  1329. static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
  1330. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1331. {
  1332. struct hwi_wrb_context *pwrb_context;
  1333. struct wrb_handle *pwrb_handle;
  1334. struct iscsi_wrb *pwrb = NULL;
  1335. struct hwi_controller *phwi_ctrlr;
  1336. struct iscsi_task *task;
  1337. unsigned int type;
  1338. struct iscsi_conn *conn = beiscsi_conn->conn;
  1339. struct iscsi_session *session = conn->session;
  1340. struct common_sol_cqe csol_cqe = {0};
  1341. uint16_t cri_index = 0;
  1342. phwi_ctrlr = phba->phwi_ctrlr;
  1343. /* Copy the elements to a common structure */
  1344. adapter_get_sol_cqe(phba, psol, &csol_cqe);
  1345. cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
  1346. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  1347. pwrb_handle = pwrb_context->pwrb_handle_basestd[
  1348. csol_cqe.wrb_index];
  1349. task = pwrb_handle->pio_handle;
  1350. pwrb = pwrb_handle->pwrb;
  1351. type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
  1352. spin_lock_bh(&session->lock);
  1353. switch (type) {
  1354. case HWH_TYPE_IO:
  1355. case HWH_TYPE_IO_RD:
  1356. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
  1357. ISCSI_OP_NOOP_OUT)
  1358. be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
  1359. else
  1360. be_complete_io(beiscsi_conn, task, &csol_cqe);
  1361. break;
  1362. case HWH_TYPE_LOGOUT:
  1363. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
  1364. be_complete_logout(beiscsi_conn, task, &csol_cqe);
  1365. else
  1366. be_complete_tmf(beiscsi_conn, task, &csol_cqe);
  1367. break;
  1368. case HWH_TYPE_LOGIN:
  1369. beiscsi_log(phba, KERN_ERR,
  1370. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1371. "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
  1372. " hwi_complete_cmd- Solicited path\n");
  1373. break;
  1374. case HWH_TYPE_NOP:
  1375. be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
  1376. break;
  1377. default:
  1378. beiscsi_log(phba, KERN_WARNING,
  1379. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1380. "BM_%d : In hwi_complete_cmd, unknown type = %d"
  1381. "wrb_index 0x%x CID 0x%x\n", type,
  1382. csol_cqe.wrb_index,
  1383. csol_cqe.cid);
  1384. break;
  1385. }
  1386. spin_unlock_bh(&session->lock);
  1387. }
  1388. static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
  1389. *pasync_ctx, unsigned int is_header,
  1390. unsigned int host_write_ptr)
  1391. {
  1392. if (is_header)
  1393. return &pasync_ctx->async_entry[host_write_ptr].
  1394. header_busy_list;
  1395. else
  1396. return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
  1397. }
  1398. static struct async_pdu_handle *
  1399. hwi_get_async_handle(struct beiscsi_hba *phba,
  1400. struct beiscsi_conn *beiscsi_conn,
  1401. struct hwi_async_pdu_context *pasync_ctx,
  1402. struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
  1403. {
  1404. struct be_bus_address phys_addr;
  1405. struct list_head *pbusy_list;
  1406. struct async_pdu_handle *pasync_handle = NULL;
  1407. unsigned char is_header = 0;
  1408. unsigned int index, dpl;
  1409. if (is_chip_be2_be3r(phba)) {
  1410. dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
  1411. dpl, pdpdu_cqe);
  1412. index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
  1413. index, pdpdu_cqe);
  1414. } else {
  1415. dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
  1416. dpl, pdpdu_cqe);
  1417. index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
  1418. index, pdpdu_cqe);
  1419. }
  1420. phys_addr.u.a32.address_lo =
  1421. (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1422. db_addr_lo) / 32] - dpl);
  1423. phys_addr.u.a32.address_hi =
  1424. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1425. db_addr_hi) / 32];
  1426. phys_addr.u.a64.address =
  1427. *((unsigned long long *)(&phys_addr.u.a64.address));
  1428. switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
  1429. & PDUCQE_CODE_MASK) {
  1430. case UNSOL_HDR_NOTIFY:
  1431. is_header = 1;
  1432. pbusy_list = hwi_get_async_busy_list(pasync_ctx,
  1433. is_header, index);
  1434. break;
  1435. case UNSOL_DATA_NOTIFY:
  1436. pbusy_list = hwi_get_async_busy_list(pasync_ctx,
  1437. is_header, index);
  1438. break;
  1439. default:
  1440. pbusy_list = NULL;
  1441. beiscsi_log(phba, KERN_WARNING,
  1442. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1443. "BM_%d : Unexpected code=%d\n",
  1444. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1445. code) / 32] & PDUCQE_CODE_MASK);
  1446. return NULL;
  1447. }
  1448. WARN_ON(list_empty(pbusy_list));
  1449. list_for_each_entry(pasync_handle, pbusy_list, link) {
  1450. if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
  1451. break;
  1452. }
  1453. WARN_ON(!pasync_handle);
  1454. pasync_handle->cri =
  1455. BE_GET_CRI_FROM_CID(beiscsi_conn->beiscsi_conn_cid);
  1456. pasync_handle->is_header = is_header;
  1457. pasync_handle->buffer_len = dpl;
  1458. *pcq_index = index;
  1459. return pasync_handle;
  1460. }
  1461. static unsigned int
  1462. hwi_update_async_writables(struct beiscsi_hba *phba,
  1463. struct hwi_async_pdu_context *pasync_ctx,
  1464. unsigned int is_header, unsigned int cq_index)
  1465. {
  1466. struct list_head *pbusy_list;
  1467. struct async_pdu_handle *pasync_handle;
  1468. unsigned int num_entries, writables = 0;
  1469. unsigned int *pep_read_ptr, *pwritables;
  1470. num_entries = pasync_ctx->num_entries;
  1471. if (is_header) {
  1472. pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
  1473. pwritables = &pasync_ctx->async_header.writables;
  1474. } else {
  1475. pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
  1476. pwritables = &pasync_ctx->async_data.writables;
  1477. }
  1478. while ((*pep_read_ptr) != cq_index) {
  1479. (*pep_read_ptr)++;
  1480. *pep_read_ptr = (*pep_read_ptr) % num_entries;
  1481. pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
  1482. *pep_read_ptr);
  1483. if (writables == 0)
  1484. WARN_ON(list_empty(pbusy_list));
  1485. if (!list_empty(pbusy_list)) {
  1486. pasync_handle = list_entry(pbusy_list->next,
  1487. struct async_pdu_handle,
  1488. link);
  1489. WARN_ON(!pasync_handle);
  1490. pasync_handle->consumed = 1;
  1491. }
  1492. writables++;
  1493. }
  1494. if (!writables) {
  1495. beiscsi_log(phba, KERN_ERR,
  1496. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1497. "BM_%d : Duplicate notification received - index 0x%x!!\n",
  1498. cq_index);
  1499. WARN_ON(1);
  1500. }
  1501. *pwritables = *pwritables + writables;
  1502. return 0;
  1503. }
  1504. static void hwi_free_async_msg(struct beiscsi_hba *phba,
  1505. unsigned int cri)
  1506. {
  1507. struct hwi_controller *phwi_ctrlr;
  1508. struct hwi_async_pdu_context *pasync_ctx;
  1509. struct async_pdu_handle *pasync_handle, *tmp_handle;
  1510. struct list_head *plist;
  1511. phwi_ctrlr = phba->phwi_ctrlr;
  1512. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1513. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1514. list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
  1515. list_del(&pasync_handle->link);
  1516. if (pasync_handle->is_header) {
  1517. list_add_tail(&pasync_handle->link,
  1518. &pasync_ctx->async_header.free_list);
  1519. pasync_ctx->async_header.free_entries++;
  1520. } else {
  1521. list_add_tail(&pasync_handle->link,
  1522. &pasync_ctx->async_data.free_list);
  1523. pasync_ctx->async_data.free_entries++;
  1524. }
  1525. }
  1526. INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
  1527. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
  1528. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1529. }
  1530. static struct phys_addr *
  1531. hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
  1532. unsigned int is_header, unsigned int host_write_ptr)
  1533. {
  1534. struct phys_addr *pasync_sge = NULL;
  1535. if (is_header)
  1536. pasync_sge = pasync_ctx->async_header.ring_base;
  1537. else
  1538. pasync_sge = pasync_ctx->async_data.ring_base;
  1539. return pasync_sge + host_write_ptr;
  1540. }
  1541. static void hwi_post_async_buffers(struct beiscsi_hba *phba,
  1542. unsigned int is_header)
  1543. {
  1544. struct hwi_controller *phwi_ctrlr;
  1545. struct hwi_async_pdu_context *pasync_ctx;
  1546. struct async_pdu_handle *pasync_handle;
  1547. struct list_head *pfree_link, *pbusy_list;
  1548. struct phys_addr *pasync_sge;
  1549. unsigned int ring_id, num_entries;
  1550. unsigned int host_write_num;
  1551. unsigned int writables;
  1552. unsigned int i = 0;
  1553. u32 doorbell = 0;
  1554. phwi_ctrlr = phba->phwi_ctrlr;
  1555. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1556. num_entries = pasync_ctx->num_entries;
  1557. if (is_header) {
  1558. writables = min(pasync_ctx->async_header.writables,
  1559. pasync_ctx->async_header.free_entries);
  1560. pfree_link = pasync_ctx->async_header.free_list.next;
  1561. host_write_num = pasync_ctx->async_header.host_write_ptr;
  1562. ring_id = phwi_ctrlr->default_pdu_hdr.id;
  1563. } else {
  1564. writables = min(pasync_ctx->async_data.writables,
  1565. pasync_ctx->async_data.free_entries);
  1566. pfree_link = pasync_ctx->async_data.free_list.next;
  1567. host_write_num = pasync_ctx->async_data.host_write_ptr;
  1568. ring_id = phwi_ctrlr->default_pdu_data.id;
  1569. }
  1570. writables = (writables / 8) * 8;
  1571. if (writables) {
  1572. for (i = 0; i < writables; i++) {
  1573. pbusy_list =
  1574. hwi_get_async_busy_list(pasync_ctx, is_header,
  1575. host_write_num);
  1576. pasync_handle =
  1577. list_entry(pfree_link, struct async_pdu_handle,
  1578. link);
  1579. WARN_ON(!pasync_handle);
  1580. pasync_handle->consumed = 0;
  1581. pfree_link = pfree_link->next;
  1582. pasync_sge = hwi_get_ring_address(pasync_ctx,
  1583. is_header, host_write_num);
  1584. pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
  1585. pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
  1586. list_move(&pasync_handle->link, pbusy_list);
  1587. host_write_num++;
  1588. host_write_num = host_write_num % num_entries;
  1589. }
  1590. if (is_header) {
  1591. pasync_ctx->async_header.host_write_ptr =
  1592. host_write_num;
  1593. pasync_ctx->async_header.free_entries -= writables;
  1594. pasync_ctx->async_header.writables -= writables;
  1595. pasync_ctx->async_header.busy_entries += writables;
  1596. } else {
  1597. pasync_ctx->async_data.host_write_ptr = host_write_num;
  1598. pasync_ctx->async_data.free_entries -= writables;
  1599. pasync_ctx->async_data.writables -= writables;
  1600. pasync_ctx->async_data.busy_entries += writables;
  1601. }
  1602. doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
  1603. doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
  1604. doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
  1605. doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
  1606. << DB_DEF_PDU_CQPROC_SHIFT;
  1607. iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
  1608. }
  1609. }
  1610. static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
  1611. struct beiscsi_conn *beiscsi_conn,
  1612. struct i_t_dpdu_cqe *pdpdu_cqe)
  1613. {
  1614. struct hwi_controller *phwi_ctrlr;
  1615. struct hwi_async_pdu_context *pasync_ctx;
  1616. struct async_pdu_handle *pasync_handle = NULL;
  1617. unsigned int cq_index = -1;
  1618. phwi_ctrlr = phba->phwi_ctrlr;
  1619. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1620. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1621. pdpdu_cqe, &cq_index);
  1622. BUG_ON(pasync_handle->is_header != 0);
  1623. if (pasync_handle->consumed == 0)
  1624. hwi_update_async_writables(phba, pasync_ctx,
  1625. pasync_handle->is_header, cq_index);
  1626. hwi_free_async_msg(phba, pasync_handle->cri);
  1627. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1628. }
  1629. static unsigned int
  1630. hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
  1631. struct beiscsi_hba *phba,
  1632. struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
  1633. {
  1634. struct list_head *plist;
  1635. struct async_pdu_handle *pasync_handle;
  1636. void *phdr = NULL;
  1637. unsigned int hdr_len = 0, buf_len = 0;
  1638. unsigned int status, index = 0, offset = 0;
  1639. void *pfirst_buffer = NULL;
  1640. unsigned int num_buf = 0;
  1641. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1642. list_for_each_entry(pasync_handle, plist, link) {
  1643. if (index == 0) {
  1644. phdr = pasync_handle->pbuffer;
  1645. hdr_len = pasync_handle->buffer_len;
  1646. } else {
  1647. buf_len = pasync_handle->buffer_len;
  1648. if (!num_buf) {
  1649. pfirst_buffer = pasync_handle->pbuffer;
  1650. num_buf++;
  1651. }
  1652. memcpy(pfirst_buffer + offset,
  1653. pasync_handle->pbuffer, buf_len);
  1654. offset += buf_len;
  1655. }
  1656. index++;
  1657. }
  1658. status = beiscsi_process_async_pdu(beiscsi_conn, phba,
  1659. phdr, hdr_len, pfirst_buffer,
  1660. offset);
  1661. hwi_free_async_msg(phba, cri);
  1662. return 0;
  1663. }
  1664. static unsigned int
  1665. hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
  1666. struct beiscsi_hba *phba,
  1667. struct async_pdu_handle *pasync_handle)
  1668. {
  1669. struct hwi_async_pdu_context *pasync_ctx;
  1670. struct hwi_controller *phwi_ctrlr;
  1671. unsigned int bytes_needed = 0, status = 0;
  1672. unsigned short cri = pasync_handle->cri;
  1673. struct pdu_base *ppdu;
  1674. phwi_ctrlr = phba->phwi_ctrlr;
  1675. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1676. list_del(&pasync_handle->link);
  1677. if (pasync_handle->is_header) {
  1678. pasync_ctx->async_header.busy_entries--;
  1679. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1680. hwi_free_async_msg(phba, cri);
  1681. BUG();
  1682. }
  1683. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1684. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
  1685. pasync_ctx->async_entry[cri].wait_queue.hdr_len =
  1686. (unsigned short)pasync_handle->buffer_len;
  1687. list_add_tail(&pasync_handle->link,
  1688. &pasync_ctx->async_entry[cri].wait_queue.list);
  1689. ppdu = pasync_handle->pbuffer;
  1690. bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
  1691. data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
  1692. 0xFFFF0000) | ((be16_to_cpu((ppdu->
  1693. dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
  1694. & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
  1695. if (status == 0) {
  1696. pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
  1697. bytes_needed;
  1698. if (bytes_needed == 0)
  1699. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1700. pasync_ctx, cri);
  1701. }
  1702. } else {
  1703. pasync_ctx->async_data.busy_entries--;
  1704. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1705. list_add_tail(&pasync_handle->link,
  1706. &pasync_ctx->async_entry[cri].wait_queue.
  1707. list);
  1708. pasync_ctx->async_entry[cri].wait_queue.
  1709. bytes_received +=
  1710. (unsigned short)pasync_handle->buffer_len;
  1711. if (pasync_ctx->async_entry[cri].wait_queue.
  1712. bytes_received >=
  1713. pasync_ctx->async_entry[cri].wait_queue.
  1714. bytes_needed)
  1715. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1716. pasync_ctx, cri);
  1717. }
  1718. }
  1719. return status;
  1720. }
  1721. static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
  1722. struct beiscsi_hba *phba,
  1723. struct i_t_dpdu_cqe *pdpdu_cqe)
  1724. {
  1725. struct hwi_controller *phwi_ctrlr;
  1726. struct hwi_async_pdu_context *pasync_ctx;
  1727. struct async_pdu_handle *pasync_handle = NULL;
  1728. unsigned int cq_index = -1;
  1729. phwi_ctrlr = phba->phwi_ctrlr;
  1730. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
  1731. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1732. pdpdu_cqe, &cq_index);
  1733. if (pasync_handle->consumed == 0)
  1734. hwi_update_async_writables(phba, pasync_ctx,
  1735. pasync_handle->is_header, cq_index);
  1736. hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
  1737. hwi_post_async_buffers(phba, pasync_handle->is_header);
  1738. }
  1739. static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
  1740. {
  1741. struct be_queue_info *mcc_cq;
  1742. struct be_mcc_compl *mcc_compl;
  1743. unsigned int num_processed = 0;
  1744. mcc_cq = &phba->ctrl.mcc_obj.cq;
  1745. mcc_compl = queue_tail_node(mcc_cq);
  1746. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1747. while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
  1748. if (num_processed >= 32) {
  1749. hwi_ring_cq_db(phba, mcc_cq->id,
  1750. num_processed, 0, 0);
  1751. num_processed = 0;
  1752. }
  1753. if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
  1754. /* Interpret flags as an async trailer */
  1755. if (is_link_state_evt(mcc_compl->flags))
  1756. /* Interpret compl as a async link evt */
  1757. beiscsi_async_link_state_process(phba,
  1758. (struct be_async_event_link_state *) mcc_compl);
  1759. else
  1760. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
  1761. "BM_%d : Unsupported Async Event, flags"
  1762. " = 0x%08x\n",
  1763. mcc_compl->flags);
  1764. } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  1765. be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
  1766. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  1767. }
  1768. mcc_compl->flags = 0;
  1769. queue_tail_inc(mcc_cq);
  1770. mcc_compl = queue_tail_node(mcc_cq);
  1771. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1772. num_processed++;
  1773. }
  1774. if (num_processed > 0)
  1775. hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
  1776. }
  1777. /**
  1778. * beiscsi_process_cq()- Process the Completion Queue
  1779. * @pbe_eq: Event Q on which the Completion has come
  1780. *
  1781. * return
  1782. * Number of Completion Entries processed.
  1783. **/
  1784. static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
  1785. {
  1786. struct be_queue_info *cq;
  1787. struct sol_cqe *sol;
  1788. struct dmsg_cqe *dmsg;
  1789. unsigned int num_processed = 0;
  1790. unsigned int tot_nump = 0;
  1791. unsigned short code = 0, cid = 0;
  1792. uint16_t cri_index = 0;
  1793. struct beiscsi_conn *beiscsi_conn;
  1794. struct beiscsi_endpoint *beiscsi_ep;
  1795. struct iscsi_endpoint *ep;
  1796. struct beiscsi_hba *phba;
  1797. cq = pbe_eq->cq;
  1798. sol = queue_tail_node(cq);
  1799. phba = pbe_eq->phba;
  1800. while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
  1801. CQE_VALID_MASK) {
  1802. be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
  1803. code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
  1804. 32] & CQE_CODE_MASK);
  1805. /* Get the CID */
  1806. if (is_chip_be2_be3r(phba)) {
  1807. cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
  1808. } else {
  1809. if ((code == DRIVERMSG_NOTIFY) ||
  1810. (code == UNSOL_HDR_NOTIFY) ||
  1811. (code == UNSOL_DATA_NOTIFY))
  1812. cid = AMAP_GET_BITS(
  1813. struct amap_i_t_dpdu_cqe_v2,
  1814. cid, sol);
  1815. else
  1816. cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1817. cid, sol);
  1818. }
  1819. cri_index = BE_GET_CRI_FROM_CID(cid);
  1820. ep = phba->ep_array[cri_index];
  1821. beiscsi_ep = ep->dd_data;
  1822. beiscsi_conn = beiscsi_ep->conn;
  1823. if (num_processed >= 32) {
  1824. hwi_ring_cq_db(phba, cq->id,
  1825. num_processed, 0, 0);
  1826. tot_nump += num_processed;
  1827. num_processed = 0;
  1828. }
  1829. switch (code) {
  1830. case SOL_CMD_COMPLETE:
  1831. hwi_complete_cmd(beiscsi_conn, phba, sol);
  1832. break;
  1833. case DRIVERMSG_NOTIFY:
  1834. beiscsi_log(phba, KERN_INFO,
  1835. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1836. "BM_%d : Received %s[%d] on CID : %d\n",
  1837. cqe_desc[code], code, cid);
  1838. dmsg = (struct dmsg_cqe *)sol;
  1839. hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
  1840. break;
  1841. case UNSOL_HDR_NOTIFY:
  1842. beiscsi_log(phba, KERN_INFO,
  1843. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1844. "BM_%d : Received %s[%d] on CID : %d\n",
  1845. cqe_desc[code], code, cid);
  1846. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1847. (struct i_t_dpdu_cqe *)sol);
  1848. break;
  1849. case UNSOL_DATA_NOTIFY:
  1850. beiscsi_log(phba, KERN_INFO,
  1851. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1852. "BM_%d : Received %s[%d] on CID : %d\n",
  1853. cqe_desc[code], code, cid);
  1854. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1855. (struct i_t_dpdu_cqe *)sol);
  1856. break;
  1857. case CXN_INVALIDATE_INDEX_NOTIFY:
  1858. case CMD_INVALIDATED_NOTIFY:
  1859. case CXN_INVALIDATE_NOTIFY:
  1860. beiscsi_log(phba, KERN_ERR,
  1861. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1862. "BM_%d : Ignoring %s[%d] on CID : %d\n",
  1863. cqe_desc[code], code, cid);
  1864. break;
  1865. case SOL_CMD_KILLED_DATA_DIGEST_ERR:
  1866. case CMD_KILLED_INVALID_STATSN_RCVD:
  1867. case CMD_KILLED_INVALID_R2T_RCVD:
  1868. case CMD_CXN_KILLED_LUN_INVALID:
  1869. case CMD_CXN_KILLED_ICD_INVALID:
  1870. case CMD_CXN_KILLED_ITT_INVALID:
  1871. case CMD_CXN_KILLED_SEQ_OUTOFORDER:
  1872. case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
  1873. beiscsi_log(phba, KERN_ERR,
  1874. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1875. "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
  1876. cqe_desc[code], code, cid);
  1877. break;
  1878. case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
  1879. beiscsi_log(phba, KERN_ERR,
  1880. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1881. "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
  1882. cqe_desc[code], code, cid);
  1883. hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
  1884. (struct i_t_dpdu_cqe *) sol);
  1885. break;
  1886. case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
  1887. case CXN_KILLED_BURST_LEN_MISMATCH:
  1888. case CXN_KILLED_AHS_RCVD:
  1889. case CXN_KILLED_HDR_DIGEST_ERR:
  1890. case CXN_KILLED_UNKNOWN_HDR:
  1891. case CXN_KILLED_STALE_ITT_TTT_RCVD:
  1892. case CXN_KILLED_INVALID_ITT_TTT_RCVD:
  1893. case CXN_KILLED_TIMED_OUT:
  1894. case CXN_KILLED_FIN_RCVD:
  1895. case CXN_KILLED_RST_SENT:
  1896. case CXN_KILLED_RST_RCVD:
  1897. case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
  1898. case CXN_KILLED_BAD_WRB_INDEX_ERROR:
  1899. case CXN_KILLED_OVER_RUN_RESIDUAL:
  1900. case CXN_KILLED_UNDER_RUN_RESIDUAL:
  1901. case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
  1902. beiscsi_log(phba, KERN_ERR,
  1903. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1904. "BM_%d : Event %s[%d] received on CID : %d\n",
  1905. cqe_desc[code], code, cid);
  1906. if (beiscsi_conn)
  1907. iscsi_conn_failure(beiscsi_conn->conn,
  1908. ISCSI_ERR_CONN_FAILED);
  1909. break;
  1910. default:
  1911. beiscsi_log(phba, KERN_ERR,
  1912. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1913. "BM_%d : Invalid CQE Event Received Code : %d"
  1914. "CID 0x%x...\n",
  1915. code, cid);
  1916. break;
  1917. }
  1918. AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
  1919. queue_tail_inc(cq);
  1920. sol = queue_tail_node(cq);
  1921. num_processed++;
  1922. }
  1923. if (num_processed > 0) {
  1924. tot_nump += num_processed;
  1925. hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
  1926. }
  1927. return tot_nump;
  1928. }
  1929. void beiscsi_process_all_cqs(struct work_struct *work)
  1930. {
  1931. unsigned long flags;
  1932. struct hwi_controller *phwi_ctrlr;
  1933. struct hwi_context_memory *phwi_context;
  1934. struct beiscsi_hba *phba;
  1935. struct be_eq_obj *pbe_eq =
  1936. container_of(work, struct be_eq_obj, work_cqs);
  1937. phba = pbe_eq->phba;
  1938. phwi_ctrlr = phba->phwi_ctrlr;
  1939. phwi_context = phwi_ctrlr->phwi_ctxt;
  1940. if (pbe_eq->todo_mcc_cq) {
  1941. spin_lock_irqsave(&phba->isr_lock, flags);
  1942. pbe_eq->todo_mcc_cq = false;
  1943. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1944. beiscsi_process_mcc_isr(phba);
  1945. }
  1946. if (pbe_eq->todo_cq) {
  1947. spin_lock_irqsave(&phba->isr_lock, flags);
  1948. pbe_eq->todo_cq = false;
  1949. spin_unlock_irqrestore(&phba->isr_lock, flags);
  1950. beiscsi_process_cq(pbe_eq);
  1951. }
  1952. /* rearm EQ for further interrupts */
  1953. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  1954. }
  1955. static int be_iopoll(struct blk_iopoll *iop, int budget)
  1956. {
  1957. static unsigned int ret;
  1958. struct beiscsi_hba *phba;
  1959. struct be_eq_obj *pbe_eq;
  1960. pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
  1961. ret = beiscsi_process_cq(pbe_eq);
  1962. if (ret < budget) {
  1963. phba = pbe_eq->phba;
  1964. blk_iopoll_complete(iop);
  1965. beiscsi_log(phba, KERN_INFO,
  1966. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1967. "BM_%d : rearm pbe_eq->q.id =%d\n",
  1968. pbe_eq->q.id);
  1969. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  1970. }
  1971. return ret;
  1972. }
  1973. static void
  1974. hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  1975. unsigned int num_sg, struct beiscsi_io_task *io_task)
  1976. {
  1977. struct iscsi_sge *psgl;
  1978. unsigned int sg_len, index;
  1979. unsigned int sge_len = 0;
  1980. unsigned long long addr;
  1981. struct scatterlist *l_sg;
  1982. unsigned int offset;
  1983. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
  1984. io_task->bhs_pa.u.a32.address_lo);
  1985. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
  1986. io_task->bhs_pa.u.a32.address_hi);
  1987. l_sg = sg;
  1988. for (index = 0; (index < num_sg) && (index < 2); index++,
  1989. sg = sg_next(sg)) {
  1990. if (index == 0) {
  1991. sg_len = sg_dma_len(sg);
  1992. addr = (u64) sg_dma_address(sg);
  1993. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1994. sge0_addr_lo, pwrb,
  1995. lower_32_bits(addr));
  1996. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  1997. sge0_addr_hi, pwrb,
  1998. upper_32_bits(addr));
  1999. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2000. sge0_len, pwrb,
  2001. sg_len);
  2002. sge_len = sg_len;
  2003. } else {
  2004. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
  2005. pwrb, sge_len);
  2006. sg_len = sg_dma_len(sg);
  2007. addr = (u64) sg_dma_address(sg);
  2008. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2009. sge1_addr_lo, pwrb,
  2010. lower_32_bits(addr));
  2011. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2012. sge1_addr_hi, pwrb,
  2013. upper_32_bits(addr));
  2014. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2015. sge1_len, pwrb,
  2016. sg_len);
  2017. }
  2018. }
  2019. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2020. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  2021. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  2022. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2023. io_task->bhs_pa.u.a32.address_hi);
  2024. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2025. io_task->bhs_pa.u.a32.address_lo);
  2026. if (num_sg == 1) {
  2027. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  2028. 1);
  2029. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  2030. 0);
  2031. } else if (num_sg == 2) {
  2032. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  2033. 0);
  2034. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  2035. 1);
  2036. } else {
  2037. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  2038. 0);
  2039. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  2040. 0);
  2041. }
  2042. sg = l_sg;
  2043. psgl++;
  2044. psgl++;
  2045. offset = 0;
  2046. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  2047. sg_len = sg_dma_len(sg);
  2048. addr = (u64) sg_dma_address(sg);
  2049. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2050. lower_32_bits(addr));
  2051. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2052. upper_32_bits(addr));
  2053. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  2054. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  2055. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2056. offset += sg_len;
  2057. }
  2058. psgl--;
  2059. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2060. }
  2061. static void
  2062. hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  2063. unsigned int num_sg, struct beiscsi_io_task *io_task)
  2064. {
  2065. struct iscsi_sge *psgl;
  2066. unsigned int sg_len, index;
  2067. unsigned int sge_len = 0;
  2068. unsigned long long addr;
  2069. struct scatterlist *l_sg;
  2070. unsigned int offset;
  2071. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  2072. io_task->bhs_pa.u.a32.address_lo);
  2073. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  2074. io_task->bhs_pa.u.a32.address_hi);
  2075. l_sg = sg;
  2076. for (index = 0; (index < num_sg) && (index < 2); index++,
  2077. sg = sg_next(sg)) {
  2078. if (index == 0) {
  2079. sg_len = sg_dma_len(sg);
  2080. addr = (u64) sg_dma_address(sg);
  2081. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  2082. ((u32)(addr & 0xFFFFFFFF)));
  2083. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  2084. ((u32)(addr >> 32)));
  2085. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  2086. sg_len);
  2087. sge_len = sg_len;
  2088. } else {
  2089. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
  2090. pwrb, sge_len);
  2091. sg_len = sg_dma_len(sg);
  2092. addr = (u64) sg_dma_address(sg);
  2093. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
  2094. ((u32)(addr & 0xFFFFFFFF)));
  2095. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
  2096. ((u32)(addr >> 32)));
  2097. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
  2098. sg_len);
  2099. }
  2100. }
  2101. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2102. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  2103. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  2104. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2105. io_task->bhs_pa.u.a32.address_hi);
  2106. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2107. io_task->bhs_pa.u.a32.address_lo);
  2108. if (num_sg == 1) {
  2109. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2110. 1);
  2111. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2112. 0);
  2113. } else if (num_sg == 2) {
  2114. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2115. 0);
  2116. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2117. 1);
  2118. } else {
  2119. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2120. 0);
  2121. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2122. 0);
  2123. }
  2124. sg = l_sg;
  2125. psgl++;
  2126. psgl++;
  2127. offset = 0;
  2128. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  2129. sg_len = sg_dma_len(sg);
  2130. addr = (u64) sg_dma_address(sg);
  2131. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2132. (addr & 0xFFFFFFFF));
  2133. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2134. (addr >> 32));
  2135. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  2136. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  2137. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2138. offset += sg_len;
  2139. }
  2140. psgl--;
  2141. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2142. }
  2143. /**
  2144. * hwi_write_buffer()- Populate the WRB with task info
  2145. * @pwrb: ptr to the WRB entry
  2146. * @task: iscsi task which is to be executed
  2147. **/
  2148. static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
  2149. {
  2150. struct iscsi_sge *psgl;
  2151. struct beiscsi_io_task *io_task = task->dd_data;
  2152. struct beiscsi_conn *beiscsi_conn = io_task->conn;
  2153. struct beiscsi_hba *phba = beiscsi_conn->phba;
  2154. uint8_t dsp_value = 0;
  2155. io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
  2156. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  2157. io_task->bhs_pa.u.a32.address_lo);
  2158. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  2159. io_task->bhs_pa.u.a32.address_hi);
  2160. if (task->data) {
  2161. /* Check for the data_count */
  2162. dsp_value = (task->data_count) ? 1 : 0;
  2163. if (is_chip_be2_be3r(phba))
  2164. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
  2165. pwrb, dsp_value);
  2166. else
  2167. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
  2168. pwrb, dsp_value);
  2169. /* Map addr only if there is data_count */
  2170. if (dsp_value) {
  2171. io_task->mtask_addr = pci_map_single(phba->pcidev,
  2172. task->data,
  2173. task->data_count,
  2174. PCI_DMA_TODEVICE);
  2175. io_task->mtask_data_count = task->data_count;
  2176. } else
  2177. io_task->mtask_addr = 0;
  2178. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  2179. lower_32_bits(io_task->mtask_addr));
  2180. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  2181. upper_32_bits(io_task->mtask_addr));
  2182. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  2183. task->data_count);
  2184. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
  2185. } else {
  2186. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  2187. io_task->mtask_addr = 0;
  2188. }
  2189. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2190. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
  2191. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2192. io_task->bhs_pa.u.a32.address_hi);
  2193. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2194. io_task->bhs_pa.u.a32.address_lo);
  2195. if (task->data) {
  2196. psgl++;
  2197. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
  2198. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
  2199. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
  2200. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
  2201. AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
  2202. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2203. psgl++;
  2204. if (task->data) {
  2205. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2206. lower_32_bits(io_task->mtask_addr));
  2207. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2208. upper_32_bits(io_task->mtask_addr));
  2209. }
  2210. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
  2211. }
  2212. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2213. }
  2214. static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
  2215. {
  2216. unsigned int num_cq_pages, num_async_pdu_buf_pages;
  2217. unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
  2218. unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
  2219. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2220. sizeof(struct sol_cqe));
  2221. num_async_pdu_buf_pages =
  2222. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2223. phba->params.defpdu_hdr_sz);
  2224. num_async_pdu_buf_sgl_pages =
  2225. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2226. sizeof(struct phys_addr));
  2227. num_async_pdu_data_pages =
  2228. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2229. phba->params.defpdu_data_sz);
  2230. num_async_pdu_data_sgl_pages =
  2231. PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
  2232. sizeof(struct phys_addr));
  2233. phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
  2234. phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
  2235. BE_ISCSI_PDU_HEADER_SIZE;
  2236. phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
  2237. sizeof(struct hwi_context_memory);
  2238. phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
  2239. * (phba->params.wrbs_per_cxn)
  2240. * phba->params.cxns_per_ctrl;
  2241. wrb_sz_per_cxn = sizeof(struct wrb_handle) *
  2242. (phba->params.wrbs_per_cxn);
  2243. phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
  2244. phba->params.cxns_per_ctrl);
  2245. phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
  2246. phba->params.icds_per_ctrl;
  2247. phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
  2248. phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
  2249. phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
  2250. num_async_pdu_buf_pages * PAGE_SIZE;
  2251. phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
  2252. num_async_pdu_data_pages * PAGE_SIZE;
  2253. phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
  2254. num_async_pdu_buf_sgl_pages * PAGE_SIZE;
  2255. phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
  2256. num_async_pdu_data_sgl_pages * PAGE_SIZE;
  2257. phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
  2258. phba->params.asyncpdus_per_ctrl *
  2259. sizeof(struct async_pdu_handle);
  2260. phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
  2261. phba->params.asyncpdus_per_ctrl *
  2262. sizeof(struct async_pdu_handle);
  2263. phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
  2264. sizeof(struct hwi_async_pdu_context) +
  2265. (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
  2266. }
  2267. static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
  2268. {
  2269. dma_addr_t bus_add;
  2270. struct hwi_controller *phwi_ctrlr;
  2271. struct be_mem_descriptor *mem_descr;
  2272. struct mem_array *mem_arr, *mem_arr_orig;
  2273. unsigned int i, j, alloc_size, curr_alloc_size;
  2274. phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
  2275. if (!phba->phwi_ctrlr)
  2276. return -ENOMEM;
  2277. /* Allocate memory for wrb_context */
  2278. phwi_ctrlr = phba->phwi_ctrlr;
  2279. phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
  2280. phba->params.cxns_per_ctrl,
  2281. GFP_KERNEL);
  2282. if (!phwi_ctrlr->wrb_context)
  2283. return -ENOMEM;
  2284. phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
  2285. GFP_KERNEL);
  2286. if (!phba->init_mem) {
  2287. kfree(phwi_ctrlr->wrb_context);
  2288. kfree(phba->phwi_ctrlr);
  2289. return -ENOMEM;
  2290. }
  2291. mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
  2292. GFP_KERNEL);
  2293. if (!mem_arr_orig) {
  2294. kfree(phba->init_mem);
  2295. kfree(phwi_ctrlr->wrb_context);
  2296. kfree(phba->phwi_ctrlr);
  2297. return -ENOMEM;
  2298. }
  2299. mem_descr = phba->init_mem;
  2300. for (i = 0; i < SE_MEM_MAX; i++) {
  2301. j = 0;
  2302. mem_arr = mem_arr_orig;
  2303. alloc_size = phba->mem_req[i];
  2304. memset(mem_arr, 0, sizeof(struct mem_array) *
  2305. BEISCSI_MAX_FRAGS_INIT);
  2306. curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
  2307. do {
  2308. mem_arr->virtual_address = pci_alloc_consistent(
  2309. phba->pcidev,
  2310. curr_alloc_size,
  2311. &bus_add);
  2312. if (!mem_arr->virtual_address) {
  2313. if (curr_alloc_size <= BE_MIN_MEM_SIZE)
  2314. goto free_mem;
  2315. if (curr_alloc_size -
  2316. rounddown_pow_of_two(curr_alloc_size))
  2317. curr_alloc_size = rounddown_pow_of_two
  2318. (curr_alloc_size);
  2319. else
  2320. curr_alloc_size = curr_alloc_size / 2;
  2321. } else {
  2322. mem_arr->bus_address.u.
  2323. a64.address = (__u64) bus_add;
  2324. mem_arr->size = curr_alloc_size;
  2325. alloc_size -= curr_alloc_size;
  2326. curr_alloc_size = min(be_max_phys_size *
  2327. 1024, alloc_size);
  2328. j++;
  2329. mem_arr++;
  2330. }
  2331. } while (alloc_size);
  2332. mem_descr->num_elements = j;
  2333. mem_descr->size_in_bytes = phba->mem_req[i];
  2334. mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
  2335. GFP_KERNEL);
  2336. if (!mem_descr->mem_array)
  2337. goto free_mem;
  2338. memcpy(mem_descr->mem_array, mem_arr_orig,
  2339. sizeof(struct mem_array) * j);
  2340. mem_descr++;
  2341. }
  2342. kfree(mem_arr_orig);
  2343. return 0;
  2344. free_mem:
  2345. mem_descr->num_elements = j;
  2346. while ((i) || (j)) {
  2347. for (j = mem_descr->num_elements; j > 0; j--) {
  2348. pci_free_consistent(phba->pcidev,
  2349. mem_descr->mem_array[j - 1].size,
  2350. mem_descr->mem_array[j - 1].
  2351. virtual_address,
  2352. (unsigned long)mem_descr->
  2353. mem_array[j - 1].
  2354. bus_address.u.a64.address);
  2355. }
  2356. if (i) {
  2357. i--;
  2358. kfree(mem_descr->mem_array);
  2359. mem_descr--;
  2360. }
  2361. }
  2362. kfree(mem_arr_orig);
  2363. kfree(phba->init_mem);
  2364. kfree(phba->phwi_ctrlr->wrb_context);
  2365. kfree(phba->phwi_ctrlr);
  2366. return -ENOMEM;
  2367. }
  2368. static int beiscsi_get_memory(struct beiscsi_hba *phba)
  2369. {
  2370. beiscsi_find_mem_req(phba);
  2371. return beiscsi_alloc_mem(phba);
  2372. }
  2373. static void iscsi_init_global_templates(struct beiscsi_hba *phba)
  2374. {
  2375. struct pdu_data_out *pdata_out;
  2376. struct pdu_nop_out *pnop_out;
  2377. struct be_mem_descriptor *mem_descr;
  2378. mem_descr = phba->init_mem;
  2379. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  2380. pdata_out =
  2381. (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
  2382. memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2383. AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
  2384. IIOC_SCSI_DATA);
  2385. pnop_out =
  2386. (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
  2387. virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
  2388. memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2389. AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
  2390. AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
  2391. AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
  2392. }
  2393. static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
  2394. {
  2395. struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
  2396. struct hwi_context_memory *phwi_ctxt;
  2397. struct wrb_handle *pwrb_handle = NULL;
  2398. struct hwi_controller *phwi_ctrlr;
  2399. struct hwi_wrb_context *pwrb_context;
  2400. struct iscsi_wrb *pwrb = NULL;
  2401. unsigned int num_cxn_wrbh = 0;
  2402. unsigned int num_cxn_wrb = 0, j, idx = 0, index;
  2403. mem_descr_wrbh = phba->init_mem;
  2404. mem_descr_wrbh += HWI_MEM_WRBH;
  2405. mem_descr_wrb = phba->init_mem;
  2406. mem_descr_wrb += HWI_MEM_WRB;
  2407. phwi_ctrlr = phba->phwi_ctrlr;
  2408. /* Allocate memory for WRBQ */
  2409. phwi_ctxt = phwi_ctrlr->phwi_ctxt;
  2410. phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
  2411. phba->fw_config.iscsi_cid_count,
  2412. GFP_KERNEL);
  2413. if (!phwi_ctxt->be_wrbq) {
  2414. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2415. "BM_%d : WRBQ Mem Alloc Failed\n");
  2416. return -ENOMEM;
  2417. }
  2418. for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
  2419. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2420. pwrb_context->pwrb_handle_base =
  2421. kzalloc(sizeof(struct wrb_handle *) *
  2422. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2423. if (!pwrb_context->pwrb_handle_base) {
  2424. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2425. "BM_%d : Mem Alloc Failed. Failing to load\n");
  2426. goto init_wrb_hndl_failed;
  2427. }
  2428. pwrb_context->pwrb_handle_basestd =
  2429. kzalloc(sizeof(struct wrb_handle *) *
  2430. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2431. if (!pwrb_context->pwrb_handle_basestd) {
  2432. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2433. "BM_%d : Mem Alloc Failed. Failing to load\n");
  2434. goto init_wrb_hndl_failed;
  2435. }
  2436. if (!num_cxn_wrbh) {
  2437. pwrb_handle =
  2438. mem_descr_wrbh->mem_array[idx].virtual_address;
  2439. num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
  2440. ((sizeof(struct wrb_handle)) *
  2441. phba->params.wrbs_per_cxn));
  2442. idx++;
  2443. }
  2444. pwrb_context->alloc_index = 0;
  2445. pwrb_context->wrb_handles_available = 0;
  2446. pwrb_context->free_index = 0;
  2447. if (num_cxn_wrbh) {
  2448. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2449. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  2450. pwrb_context->pwrb_handle_basestd[j] =
  2451. pwrb_handle;
  2452. pwrb_context->wrb_handles_available++;
  2453. pwrb_handle->wrb_index = j;
  2454. pwrb_handle++;
  2455. }
  2456. num_cxn_wrbh--;
  2457. }
  2458. }
  2459. idx = 0;
  2460. for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
  2461. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2462. if (!num_cxn_wrb) {
  2463. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  2464. num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
  2465. ((sizeof(struct iscsi_wrb) *
  2466. phba->params.wrbs_per_cxn));
  2467. idx++;
  2468. }
  2469. if (num_cxn_wrb) {
  2470. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2471. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  2472. pwrb_handle->pwrb = pwrb;
  2473. pwrb++;
  2474. }
  2475. num_cxn_wrb--;
  2476. }
  2477. }
  2478. return 0;
  2479. init_wrb_hndl_failed:
  2480. for (j = index; j > 0; j--) {
  2481. pwrb_context = &phwi_ctrlr->wrb_context[j];
  2482. kfree(pwrb_context->pwrb_handle_base);
  2483. kfree(pwrb_context->pwrb_handle_basestd);
  2484. }
  2485. return -ENOMEM;
  2486. }
  2487. static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
  2488. {
  2489. struct hwi_controller *phwi_ctrlr;
  2490. struct hba_parameters *p = &phba->params;
  2491. struct hwi_async_pdu_context *pasync_ctx;
  2492. struct async_pdu_handle *pasync_header_h, *pasync_data_h;
  2493. unsigned int index, idx, num_per_mem, num_async_data;
  2494. struct be_mem_descriptor *mem_descr;
  2495. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2496. mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
  2497. phwi_ctrlr = phba->phwi_ctrlr;
  2498. phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
  2499. mem_descr->mem_array[0].virtual_address;
  2500. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
  2501. memset(pasync_ctx, 0, sizeof(*pasync_ctx));
  2502. pasync_ctx->async_entry = kzalloc(sizeof(struct hwi_async_entry) *
  2503. phba->fw_config.iscsi_cid_count,
  2504. GFP_KERNEL);
  2505. if (!pasync_ctx->async_entry) {
  2506. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2507. "BM_%d : hwi_init_async_pdu_ctx Mem Alloc Failed\n");
  2508. return -ENOMEM;
  2509. }
  2510. pasync_ctx->num_entries = p->asyncpdus_per_ctrl;
  2511. pasync_ctx->buffer_size = p->defpdu_hdr_sz;
  2512. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2513. mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
  2514. if (mem_descr->mem_array[0].virtual_address) {
  2515. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2516. "BM_%d : hwi_init_async_pdu_ctx"
  2517. " HWI_MEM_ASYNC_HEADER_BUF va=%p\n",
  2518. mem_descr->mem_array[0].virtual_address);
  2519. } else
  2520. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2521. "BM_%d : No Virtual address\n");
  2522. pasync_ctx->async_header.va_base =
  2523. mem_descr->mem_array[0].virtual_address;
  2524. pasync_ctx->async_header.pa_base.u.a64.address =
  2525. mem_descr->mem_array[0].bus_address.u.a64.address;
  2526. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2527. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2528. if (mem_descr->mem_array[0].virtual_address) {
  2529. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2530. "BM_%d : hwi_init_async_pdu_ctx"
  2531. " HWI_MEM_ASYNC_HEADER_RING va=%p\n",
  2532. mem_descr->mem_array[0].virtual_address);
  2533. } else
  2534. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2535. "BM_%d : No Virtual address\n");
  2536. pasync_ctx->async_header.ring_base =
  2537. mem_descr->mem_array[0].virtual_address;
  2538. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2539. mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
  2540. if (mem_descr->mem_array[0].virtual_address) {
  2541. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2542. "BM_%d : hwi_init_async_pdu_ctx"
  2543. " HWI_MEM_ASYNC_HEADER_HANDLE va=%p\n",
  2544. mem_descr->mem_array[0].virtual_address);
  2545. } else
  2546. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2547. "BM_%d : No Virtual address\n");
  2548. pasync_ctx->async_header.handle_base =
  2549. mem_descr->mem_array[0].virtual_address;
  2550. pasync_ctx->async_header.writables = 0;
  2551. INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
  2552. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2553. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2554. if (mem_descr->mem_array[0].virtual_address) {
  2555. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2556. "BM_%d : hwi_init_async_pdu_ctx"
  2557. " HWI_MEM_ASYNC_DATA_RING va=%p\n",
  2558. mem_descr->mem_array[0].virtual_address);
  2559. } else
  2560. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2561. "BM_%d : No Virtual address\n");
  2562. pasync_ctx->async_data.ring_base =
  2563. mem_descr->mem_array[0].virtual_address;
  2564. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2565. mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
  2566. if (!mem_descr->mem_array[0].virtual_address)
  2567. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2568. "BM_%d : No Virtual address\n");
  2569. pasync_ctx->async_data.handle_base =
  2570. mem_descr->mem_array[0].virtual_address;
  2571. pasync_ctx->async_data.writables = 0;
  2572. INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
  2573. pasync_header_h =
  2574. (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
  2575. pasync_data_h =
  2576. (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
  2577. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2578. mem_descr += HWI_MEM_ASYNC_DATA_BUF;
  2579. if (mem_descr->mem_array[0].virtual_address) {
  2580. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2581. "BM_%d : hwi_init_async_pdu_ctx"
  2582. " HWI_MEM_ASYNC_DATA_BUF va=%p\n",
  2583. mem_descr->mem_array[0].virtual_address);
  2584. } else
  2585. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  2586. "BM_%d : No Virtual address\n");
  2587. idx = 0;
  2588. pasync_ctx->async_data.va_base =
  2589. mem_descr->mem_array[idx].virtual_address;
  2590. pasync_ctx->async_data.pa_base.u.a64.address =
  2591. mem_descr->mem_array[idx].bus_address.u.a64.address;
  2592. num_async_data = ((mem_descr->mem_array[idx].size) /
  2593. phba->params.defpdu_data_sz);
  2594. num_per_mem = 0;
  2595. for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
  2596. pasync_header_h->cri = -1;
  2597. pasync_header_h->index = (char)index;
  2598. INIT_LIST_HEAD(&pasync_header_h->link);
  2599. pasync_header_h->pbuffer =
  2600. (void *)((unsigned long)
  2601. (pasync_ctx->async_header.va_base) +
  2602. (p->defpdu_hdr_sz * index));
  2603. pasync_header_h->pa.u.a64.address =
  2604. pasync_ctx->async_header.pa_base.u.a64.address +
  2605. (p->defpdu_hdr_sz * index);
  2606. list_add_tail(&pasync_header_h->link,
  2607. &pasync_ctx->async_header.free_list);
  2608. pasync_header_h++;
  2609. pasync_ctx->async_header.free_entries++;
  2610. pasync_ctx->async_header.writables++;
  2611. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
  2612. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  2613. header_busy_list);
  2614. pasync_data_h->cri = -1;
  2615. pasync_data_h->index = (char)index;
  2616. INIT_LIST_HEAD(&pasync_data_h->link);
  2617. if (!num_async_data) {
  2618. num_per_mem = 0;
  2619. idx++;
  2620. pasync_ctx->async_data.va_base =
  2621. mem_descr->mem_array[idx].virtual_address;
  2622. pasync_ctx->async_data.pa_base.u.a64.address =
  2623. mem_descr->mem_array[idx].
  2624. bus_address.u.a64.address;
  2625. num_async_data = ((mem_descr->mem_array[idx].size) /
  2626. phba->params.defpdu_data_sz);
  2627. }
  2628. pasync_data_h->pbuffer =
  2629. (void *)((unsigned long)
  2630. (pasync_ctx->async_data.va_base) +
  2631. (p->defpdu_data_sz * num_per_mem));
  2632. pasync_data_h->pa.u.a64.address =
  2633. pasync_ctx->async_data.pa_base.u.a64.address +
  2634. (p->defpdu_data_sz * num_per_mem);
  2635. num_per_mem++;
  2636. num_async_data--;
  2637. list_add_tail(&pasync_data_h->link,
  2638. &pasync_ctx->async_data.free_list);
  2639. pasync_data_h++;
  2640. pasync_ctx->async_data.free_entries++;
  2641. pasync_ctx->async_data.writables++;
  2642. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
  2643. }
  2644. pasync_ctx->async_header.host_write_ptr = 0;
  2645. pasync_ctx->async_header.ep_read_ptr = -1;
  2646. pasync_ctx->async_data.host_write_ptr = 0;
  2647. pasync_ctx->async_data.ep_read_ptr = -1;
  2648. return 0;
  2649. }
  2650. static int
  2651. be_sgl_create_contiguous(void *virtual_address,
  2652. u64 physical_address, u32 length,
  2653. struct be_dma_mem *sgl)
  2654. {
  2655. WARN_ON(!virtual_address);
  2656. WARN_ON(!physical_address);
  2657. WARN_ON(!length > 0);
  2658. WARN_ON(!sgl);
  2659. sgl->va = virtual_address;
  2660. sgl->dma = (unsigned long)physical_address;
  2661. sgl->size = length;
  2662. return 0;
  2663. }
  2664. static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
  2665. {
  2666. memset(sgl, 0, sizeof(*sgl));
  2667. }
  2668. static void
  2669. hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
  2670. struct mem_array *pmem, struct be_dma_mem *sgl)
  2671. {
  2672. if (sgl->va)
  2673. be_sgl_destroy_contiguous(sgl);
  2674. be_sgl_create_contiguous(pmem->virtual_address,
  2675. pmem->bus_address.u.a64.address,
  2676. pmem->size, sgl);
  2677. }
  2678. static void
  2679. hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
  2680. struct mem_array *pmem, struct be_dma_mem *sgl)
  2681. {
  2682. if (sgl->va)
  2683. be_sgl_destroy_contiguous(sgl);
  2684. be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
  2685. pmem->bus_address.u.a64.address,
  2686. pmem->size, sgl);
  2687. }
  2688. static int be_fill_queue(struct be_queue_info *q,
  2689. u16 len, u16 entry_size, void *vaddress)
  2690. {
  2691. struct be_dma_mem *mem = &q->dma_mem;
  2692. memset(q, 0, sizeof(*q));
  2693. q->len = len;
  2694. q->entry_size = entry_size;
  2695. mem->size = len * entry_size;
  2696. mem->va = vaddress;
  2697. if (!mem->va)
  2698. return -ENOMEM;
  2699. memset(mem->va, 0, mem->size);
  2700. return 0;
  2701. }
  2702. static int beiscsi_create_eqs(struct beiscsi_hba *phba,
  2703. struct hwi_context_memory *phwi_context)
  2704. {
  2705. unsigned int i, num_eq_pages;
  2706. int ret = 0, eq_for_mcc;
  2707. struct be_queue_info *eq;
  2708. struct be_dma_mem *mem;
  2709. void *eq_vaddress;
  2710. dma_addr_t paddr;
  2711. num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
  2712. sizeof(struct be_eq_entry));
  2713. if (phba->msix_enabled)
  2714. eq_for_mcc = 1;
  2715. else
  2716. eq_for_mcc = 0;
  2717. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2718. eq = &phwi_context->be_eq[i].q;
  2719. mem = &eq->dma_mem;
  2720. phwi_context->be_eq[i].phba = phba;
  2721. eq_vaddress = pci_alloc_consistent(phba->pcidev,
  2722. num_eq_pages * PAGE_SIZE,
  2723. &paddr);
  2724. if (!eq_vaddress)
  2725. goto create_eq_error;
  2726. mem->va = eq_vaddress;
  2727. ret = be_fill_queue(eq, phba->params.num_eq_entries,
  2728. sizeof(struct be_eq_entry), eq_vaddress);
  2729. if (ret) {
  2730. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2731. "BM_%d : be_fill_queue Failed for EQ\n");
  2732. goto create_eq_error;
  2733. }
  2734. mem->dma = paddr;
  2735. ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
  2736. phwi_context->cur_eqd);
  2737. if (ret) {
  2738. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2739. "BM_%d : beiscsi_cmd_eq_create"
  2740. "Failed for EQ\n");
  2741. goto create_eq_error;
  2742. }
  2743. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2744. "BM_%d : eqid = %d\n",
  2745. phwi_context->be_eq[i].q.id);
  2746. }
  2747. return 0;
  2748. create_eq_error:
  2749. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2750. eq = &phwi_context->be_eq[i].q;
  2751. mem = &eq->dma_mem;
  2752. if (mem->va)
  2753. pci_free_consistent(phba->pcidev, num_eq_pages
  2754. * PAGE_SIZE,
  2755. mem->va, mem->dma);
  2756. }
  2757. return ret;
  2758. }
  2759. static int beiscsi_create_cqs(struct beiscsi_hba *phba,
  2760. struct hwi_context_memory *phwi_context)
  2761. {
  2762. unsigned int i, num_cq_pages;
  2763. int ret = 0;
  2764. struct be_queue_info *cq, *eq;
  2765. struct be_dma_mem *mem;
  2766. struct be_eq_obj *pbe_eq;
  2767. void *cq_vaddress;
  2768. dma_addr_t paddr;
  2769. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2770. sizeof(struct sol_cqe));
  2771. for (i = 0; i < phba->num_cpus; i++) {
  2772. cq = &phwi_context->be_cq[i];
  2773. eq = &phwi_context->be_eq[i].q;
  2774. pbe_eq = &phwi_context->be_eq[i];
  2775. pbe_eq->cq = cq;
  2776. pbe_eq->phba = phba;
  2777. mem = &cq->dma_mem;
  2778. cq_vaddress = pci_alloc_consistent(phba->pcidev,
  2779. num_cq_pages * PAGE_SIZE,
  2780. &paddr);
  2781. if (!cq_vaddress)
  2782. goto create_cq_error;
  2783. ret = be_fill_queue(cq, phba->params.num_cq_entries,
  2784. sizeof(struct sol_cqe), cq_vaddress);
  2785. if (ret) {
  2786. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2787. "BM_%d : be_fill_queue Failed "
  2788. "for ISCSI CQ\n");
  2789. goto create_cq_error;
  2790. }
  2791. mem->dma = paddr;
  2792. ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
  2793. false, 0);
  2794. if (ret) {
  2795. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2796. "BM_%d : beiscsi_cmd_eq_create"
  2797. "Failed for ISCSI CQ\n");
  2798. goto create_cq_error;
  2799. }
  2800. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2801. "BM_%d : iscsi cq_id is %d for eq_id %d\n"
  2802. "iSCSI CQ CREATED\n", cq->id, eq->id);
  2803. }
  2804. return 0;
  2805. create_cq_error:
  2806. for (i = 0; i < phba->num_cpus; i++) {
  2807. cq = &phwi_context->be_cq[i];
  2808. mem = &cq->dma_mem;
  2809. if (mem->va)
  2810. pci_free_consistent(phba->pcidev, num_cq_pages
  2811. * PAGE_SIZE,
  2812. mem->va, mem->dma);
  2813. }
  2814. return ret;
  2815. }
  2816. static int
  2817. beiscsi_create_def_hdr(struct beiscsi_hba *phba,
  2818. struct hwi_context_memory *phwi_context,
  2819. struct hwi_controller *phwi_ctrlr,
  2820. unsigned int def_pdu_ring_sz)
  2821. {
  2822. unsigned int idx;
  2823. int ret;
  2824. struct be_queue_info *dq, *cq;
  2825. struct be_dma_mem *mem;
  2826. struct be_mem_descriptor *mem_descr;
  2827. void *dq_vaddress;
  2828. idx = 0;
  2829. dq = &phwi_context->be_def_hdrq;
  2830. cq = &phwi_context->be_cq[0];
  2831. mem = &dq->dma_mem;
  2832. mem_descr = phba->init_mem;
  2833. mem_descr += HWI_MEM_ASYNC_HEADER_RING;
  2834. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2835. ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
  2836. sizeof(struct phys_addr),
  2837. sizeof(struct phys_addr), dq_vaddress);
  2838. if (ret) {
  2839. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2840. "BM_%d : be_fill_queue Failed for DEF PDU HDR\n");
  2841. return ret;
  2842. }
  2843. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2844. bus_address.u.a64.address;
  2845. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
  2846. def_pdu_ring_sz,
  2847. phba->params.defpdu_hdr_sz);
  2848. if (ret) {
  2849. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2850. "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR\n");
  2851. return ret;
  2852. }
  2853. phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
  2854. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2855. "BM_%d : iscsi def pdu id is %d\n",
  2856. phwi_context->be_def_hdrq.id);
  2857. hwi_post_async_buffers(phba, 1);
  2858. return 0;
  2859. }
  2860. static int
  2861. beiscsi_create_def_data(struct beiscsi_hba *phba,
  2862. struct hwi_context_memory *phwi_context,
  2863. struct hwi_controller *phwi_ctrlr,
  2864. unsigned int def_pdu_ring_sz)
  2865. {
  2866. unsigned int idx;
  2867. int ret;
  2868. struct be_queue_info *dataq, *cq;
  2869. struct be_dma_mem *mem;
  2870. struct be_mem_descriptor *mem_descr;
  2871. void *dq_vaddress;
  2872. idx = 0;
  2873. dataq = &phwi_context->be_def_dataq;
  2874. cq = &phwi_context->be_cq[0];
  2875. mem = &dataq->dma_mem;
  2876. mem_descr = phba->init_mem;
  2877. mem_descr += HWI_MEM_ASYNC_DATA_RING;
  2878. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2879. ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
  2880. sizeof(struct phys_addr),
  2881. sizeof(struct phys_addr), dq_vaddress);
  2882. if (ret) {
  2883. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2884. "BM_%d : be_fill_queue Failed for DEF PDU DATA\n");
  2885. return ret;
  2886. }
  2887. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  2888. bus_address.u.a64.address;
  2889. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
  2890. def_pdu_ring_sz,
  2891. phba->params.defpdu_data_sz);
  2892. if (ret) {
  2893. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2894. "BM_%d be_cmd_create_default_pdu_queue"
  2895. " Failed for DEF PDU DATA\n");
  2896. return ret;
  2897. }
  2898. phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
  2899. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2900. "BM_%d : iscsi def data id is %d\n",
  2901. phwi_context->be_def_dataq.id);
  2902. hwi_post_async_buffers(phba, 0);
  2903. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2904. "BM_%d : DEFAULT PDU DATA RING CREATED\n");
  2905. return 0;
  2906. }
  2907. static int
  2908. beiscsi_post_pages(struct beiscsi_hba *phba)
  2909. {
  2910. struct be_mem_descriptor *mem_descr;
  2911. struct mem_array *pm_arr;
  2912. unsigned int page_offset, i;
  2913. struct be_dma_mem sgl;
  2914. int status;
  2915. mem_descr = phba->init_mem;
  2916. mem_descr += HWI_MEM_SGE;
  2917. pm_arr = mem_descr->mem_array;
  2918. page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
  2919. phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
  2920. for (i = 0; i < mem_descr->num_elements; i++) {
  2921. hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
  2922. status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
  2923. page_offset,
  2924. (pm_arr->size / PAGE_SIZE));
  2925. page_offset += pm_arr->size / PAGE_SIZE;
  2926. if (status != 0) {
  2927. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2928. "BM_%d : post sgl failed.\n");
  2929. return status;
  2930. }
  2931. pm_arr++;
  2932. }
  2933. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2934. "BM_%d : POSTED PAGES\n");
  2935. return 0;
  2936. }
  2937. static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
  2938. {
  2939. struct be_dma_mem *mem = &q->dma_mem;
  2940. if (mem->va) {
  2941. pci_free_consistent(phba->pcidev, mem->size,
  2942. mem->va, mem->dma);
  2943. mem->va = NULL;
  2944. }
  2945. }
  2946. static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
  2947. u16 len, u16 entry_size)
  2948. {
  2949. struct be_dma_mem *mem = &q->dma_mem;
  2950. memset(q, 0, sizeof(*q));
  2951. q->len = len;
  2952. q->entry_size = entry_size;
  2953. mem->size = len * entry_size;
  2954. mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
  2955. if (!mem->va)
  2956. return -ENOMEM;
  2957. memset(mem->va, 0, mem->size);
  2958. return 0;
  2959. }
  2960. static int
  2961. beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
  2962. struct hwi_context_memory *phwi_context,
  2963. struct hwi_controller *phwi_ctrlr)
  2964. {
  2965. unsigned int wrb_mem_index, offset, size, num_wrb_rings;
  2966. u64 pa_addr_lo;
  2967. unsigned int idx, num, i;
  2968. struct mem_array *pwrb_arr;
  2969. void *wrb_vaddr;
  2970. struct be_dma_mem sgl;
  2971. struct be_mem_descriptor *mem_descr;
  2972. struct hwi_wrb_context *pwrb_context;
  2973. int status;
  2974. idx = 0;
  2975. mem_descr = phba->init_mem;
  2976. mem_descr += HWI_MEM_WRB;
  2977. pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
  2978. GFP_KERNEL);
  2979. if (!pwrb_arr) {
  2980. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2981. "BM_%d : Memory alloc failed in create wrb ring.\n");
  2982. return -ENOMEM;
  2983. }
  2984. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  2985. pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
  2986. num_wrb_rings = mem_descr->mem_array[idx].size /
  2987. (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
  2988. for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
  2989. if (num_wrb_rings) {
  2990. pwrb_arr[num].virtual_address = wrb_vaddr;
  2991. pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
  2992. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  2993. sizeof(struct iscsi_wrb);
  2994. wrb_vaddr += pwrb_arr[num].size;
  2995. pa_addr_lo += pwrb_arr[num].size;
  2996. num_wrb_rings--;
  2997. } else {
  2998. idx++;
  2999. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  3000. pa_addr_lo = mem_descr->mem_array[idx].\
  3001. bus_address.u.a64.address;
  3002. num_wrb_rings = mem_descr->mem_array[idx].size /
  3003. (phba->params.wrbs_per_cxn *
  3004. sizeof(struct iscsi_wrb));
  3005. pwrb_arr[num].virtual_address = wrb_vaddr;
  3006. pwrb_arr[num].bus_address.u.a64.address\
  3007. = pa_addr_lo;
  3008. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  3009. sizeof(struct iscsi_wrb);
  3010. wrb_vaddr += pwrb_arr[num].size;
  3011. pa_addr_lo += pwrb_arr[num].size;
  3012. num_wrb_rings--;
  3013. }
  3014. }
  3015. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3016. wrb_mem_index = 0;
  3017. offset = 0;
  3018. size = 0;
  3019. hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
  3020. status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
  3021. &phwi_context->be_wrbq[i]);
  3022. if (status != 0) {
  3023. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3024. "BM_%d : wrbq create failed.");
  3025. kfree(pwrb_arr);
  3026. return status;
  3027. }
  3028. pwrb_context = &phwi_ctrlr->wrb_context[i];
  3029. pwrb_context->cid = phwi_context->be_wrbq[i].id;
  3030. BE_SET_CID_TO_CRI(i, pwrb_context->cid);
  3031. }
  3032. kfree(pwrb_arr);
  3033. return 0;
  3034. }
  3035. static void free_wrb_handles(struct beiscsi_hba *phba)
  3036. {
  3037. unsigned int index;
  3038. struct hwi_controller *phwi_ctrlr;
  3039. struct hwi_wrb_context *pwrb_context;
  3040. phwi_ctrlr = phba->phwi_ctrlr;
  3041. for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
  3042. pwrb_context = &phwi_ctrlr->wrb_context[index];
  3043. kfree(pwrb_context->pwrb_handle_base);
  3044. kfree(pwrb_context->pwrb_handle_basestd);
  3045. }
  3046. }
  3047. static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
  3048. {
  3049. struct be_queue_info *q;
  3050. struct be_ctrl_info *ctrl = &phba->ctrl;
  3051. q = &phba->ctrl.mcc_obj.q;
  3052. if (q->created)
  3053. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
  3054. be_queue_free(phba, q);
  3055. q = &phba->ctrl.mcc_obj.cq;
  3056. if (q->created)
  3057. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  3058. be_queue_free(phba, q);
  3059. }
  3060. static void hwi_cleanup(struct beiscsi_hba *phba)
  3061. {
  3062. struct be_queue_info *q;
  3063. struct be_ctrl_info *ctrl = &phba->ctrl;
  3064. struct hwi_controller *phwi_ctrlr;
  3065. struct hwi_context_memory *phwi_context;
  3066. struct hwi_async_pdu_context *pasync_ctx;
  3067. int i, eq_num;
  3068. phwi_ctrlr = phba->phwi_ctrlr;
  3069. phwi_context = phwi_ctrlr->phwi_ctxt;
  3070. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3071. q = &phwi_context->be_wrbq[i];
  3072. if (q->created)
  3073. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
  3074. }
  3075. kfree(phwi_context->be_wrbq);
  3076. free_wrb_handles(phba);
  3077. q = &phwi_context->be_def_hdrq;
  3078. if (q->created)
  3079. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  3080. q = &phwi_context->be_def_dataq;
  3081. if (q->created)
  3082. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  3083. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  3084. for (i = 0; i < (phba->num_cpus); i++) {
  3085. q = &phwi_context->be_cq[i];
  3086. if (q->created)
  3087. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  3088. }
  3089. if (phba->msix_enabled)
  3090. eq_num = 1;
  3091. else
  3092. eq_num = 0;
  3093. for (i = 0; i < (phba->num_cpus + eq_num); i++) {
  3094. q = &phwi_context->be_eq[i].q;
  3095. if (q->created)
  3096. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
  3097. }
  3098. be_mcc_queues_destroy(phba);
  3099. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
  3100. kfree(pasync_ctx->async_entry);
  3101. be_cmd_fw_uninit(ctrl);
  3102. }
  3103. static int be_mcc_queues_create(struct beiscsi_hba *phba,
  3104. struct hwi_context_memory *phwi_context)
  3105. {
  3106. struct be_queue_info *q, *cq;
  3107. struct be_ctrl_info *ctrl = &phba->ctrl;
  3108. /* Alloc MCC compl queue */
  3109. cq = &phba->ctrl.mcc_obj.cq;
  3110. if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
  3111. sizeof(struct be_mcc_compl)))
  3112. goto err;
  3113. /* Ask BE to create MCC compl queue; */
  3114. if (phba->msix_enabled) {
  3115. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
  3116. [phba->num_cpus].q, false, true, 0))
  3117. goto mcc_cq_free;
  3118. } else {
  3119. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
  3120. false, true, 0))
  3121. goto mcc_cq_free;
  3122. }
  3123. /* Alloc MCC queue */
  3124. q = &phba->ctrl.mcc_obj.q;
  3125. if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
  3126. goto mcc_cq_destroy;
  3127. /* Ask BE to create MCC queue */
  3128. if (beiscsi_cmd_mccq_create(phba, q, cq))
  3129. goto mcc_q_free;
  3130. return 0;
  3131. mcc_q_free:
  3132. be_queue_free(phba, q);
  3133. mcc_cq_destroy:
  3134. beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
  3135. mcc_cq_free:
  3136. be_queue_free(phba, cq);
  3137. err:
  3138. return -ENOMEM;
  3139. }
  3140. /**
  3141. * find_num_cpus()- Get the CPU online count
  3142. * @phba: ptr to priv structure
  3143. *
  3144. * CPU count is used for creating EQ.
  3145. **/
  3146. static void find_num_cpus(struct beiscsi_hba *phba)
  3147. {
  3148. int num_cpus = 0;
  3149. num_cpus = num_online_cpus();
  3150. switch (phba->generation) {
  3151. case BE_GEN2:
  3152. case BE_GEN3:
  3153. phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
  3154. BEISCSI_MAX_NUM_CPUS : num_cpus;
  3155. break;
  3156. case BE_GEN4:
  3157. phba->num_cpus = (num_cpus > OC_SKH_MAX_NUM_CPUS) ?
  3158. OC_SKH_MAX_NUM_CPUS : num_cpus;
  3159. break;
  3160. default:
  3161. phba->num_cpus = 1;
  3162. }
  3163. }
  3164. static int hwi_init_port(struct beiscsi_hba *phba)
  3165. {
  3166. struct hwi_controller *phwi_ctrlr;
  3167. struct hwi_context_memory *phwi_context;
  3168. unsigned int def_pdu_ring_sz;
  3169. struct be_ctrl_info *ctrl = &phba->ctrl;
  3170. int status;
  3171. def_pdu_ring_sz =
  3172. phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
  3173. phwi_ctrlr = phba->phwi_ctrlr;
  3174. phwi_context = phwi_ctrlr->phwi_ctxt;
  3175. phwi_context->max_eqd = 0;
  3176. phwi_context->min_eqd = 0;
  3177. phwi_context->cur_eqd = 64;
  3178. be_cmd_fw_initialize(&phba->ctrl);
  3179. status = beiscsi_create_eqs(phba, phwi_context);
  3180. if (status != 0) {
  3181. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3182. "BM_%d : EQ not created\n");
  3183. goto error;
  3184. }
  3185. status = be_mcc_queues_create(phba, phwi_context);
  3186. if (status != 0)
  3187. goto error;
  3188. status = mgmt_check_supported_fw(ctrl, phba);
  3189. if (status != 0) {
  3190. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3191. "BM_%d : Unsupported fw version\n");
  3192. goto error;
  3193. }
  3194. status = beiscsi_create_cqs(phba, phwi_context);
  3195. if (status != 0) {
  3196. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3197. "BM_%d : CQ not created\n");
  3198. goto error;
  3199. }
  3200. status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
  3201. def_pdu_ring_sz);
  3202. if (status != 0) {
  3203. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3204. "BM_%d : Default Header not created\n");
  3205. goto error;
  3206. }
  3207. status = beiscsi_create_def_data(phba, phwi_context,
  3208. phwi_ctrlr, def_pdu_ring_sz);
  3209. if (status != 0) {
  3210. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3211. "BM_%d : Default Data not created\n");
  3212. goto error;
  3213. }
  3214. status = beiscsi_post_pages(phba);
  3215. if (status != 0) {
  3216. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3217. "BM_%d : Post SGL Pages Failed\n");
  3218. goto error;
  3219. }
  3220. status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
  3221. if (status != 0) {
  3222. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3223. "BM_%d : WRB Rings not created\n");
  3224. goto error;
  3225. }
  3226. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3227. "BM_%d : hwi_init_port success\n");
  3228. return 0;
  3229. error:
  3230. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3231. "BM_%d : hwi_init_port failed");
  3232. hwi_cleanup(phba);
  3233. return status;
  3234. }
  3235. static int hwi_init_controller(struct beiscsi_hba *phba)
  3236. {
  3237. struct hwi_controller *phwi_ctrlr;
  3238. phwi_ctrlr = phba->phwi_ctrlr;
  3239. if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
  3240. phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
  3241. init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
  3242. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3243. "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
  3244. phwi_ctrlr->phwi_ctxt);
  3245. } else {
  3246. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3247. "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
  3248. "than one element.Failing to load\n");
  3249. return -ENOMEM;
  3250. }
  3251. iscsi_init_global_templates(phba);
  3252. if (beiscsi_init_wrb_handle(phba))
  3253. return -ENOMEM;
  3254. if (hwi_init_async_pdu_ctx(phba)) {
  3255. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3256. "BM_%d : hwi_init_async_pdu_ctx failed\n");
  3257. return -ENOMEM;
  3258. }
  3259. if (hwi_init_port(phba) != 0) {
  3260. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3261. "BM_%d : hwi_init_controller failed\n");
  3262. return -ENOMEM;
  3263. }
  3264. return 0;
  3265. }
  3266. static void beiscsi_free_mem(struct beiscsi_hba *phba)
  3267. {
  3268. struct be_mem_descriptor *mem_descr;
  3269. int i, j;
  3270. mem_descr = phba->init_mem;
  3271. i = 0;
  3272. j = 0;
  3273. for (i = 0; i < SE_MEM_MAX; i++) {
  3274. for (j = mem_descr->num_elements; j > 0; j--) {
  3275. pci_free_consistent(phba->pcidev,
  3276. mem_descr->mem_array[j - 1].size,
  3277. mem_descr->mem_array[j - 1].virtual_address,
  3278. (unsigned long)mem_descr->mem_array[j - 1].
  3279. bus_address.u.a64.address);
  3280. }
  3281. kfree(mem_descr->mem_array);
  3282. mem_descr++;
  3283. }
  3284. kfree(phba->init_mem);
  3285. kfree(phba->phwi_ctrlr->wrb_context);
  3286. kfree(phba->phwi_ctrlr);
  3287. }
  3288. static int beiscsi_init_controller(struct beiscsi_hba *phba)
  3289. {
  3290. int ret = -ENOMEM;
  3291. ret = beiscsi_get_memory(phba);
  3292. if (ret < 0) {
  3293. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3294. "BM_%d : beiscsi_dev_probe -"
  3295. "Failed in beiscsi_alloc_memory\n");
  3296. return ret;
  3297. }
  3298. ret = hwi_init_controller(phba);
  3299. if (ret)
  3300. goto free_init;
  3301. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3302. "BM_%d : Return success from beiscsi_init_controller");
  3303. return 0;
  3304. free_init:
  3305. beiscsi_free_mem(phba);
  3306. return ret;
  3307. }
  3308. static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
  3309. {
  3310. struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
  3311. struct sgl_handle *psgl_handle;
  3312. struct iscsi_sge *pfrag;
  3313. unsigned int arr_index, i, idx;
  3314. phba->io_sgl_hndl_avbl = 0;
  3315. phba->eh_sgl_hndl_avbl = 0;
  3316. mem_descr_sglh = phba->init_mem;
  3317. mem_descr_sglh += HWI_MEM_SGLH;
  3318. if (1 == mem_descr_sglh->num_elements) {
  3319. phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  3320. phba->params.ios_per_ctrl,
  3321. GFP_KERNEL);
  3322. if (!phba->io_sgl_hndl_base) {
  3323. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3324. "BM_%d : Mem Alloc Failed. Failing to load\n");
  3325. return -ENOMEM;
  3326. }
  3327. phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  3328. (phba->params.icds_per_ctrl -
  3329. phba->params.ios_per_ctrl),
  3330. GFP_KERNEL);
  3331. if (!phba->eh_sgl_hndl_base) {
  3332. kfree(phba->io_sgl_hndl_base);
  3333. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3334. "BM_%d : Mem Alloc Failed. Failing to load\n");
  3335. return -ENOMEM;
  3336. }
  3337. } else {
  3338. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3339. "BM_%d : HWI_MEM_SGLH is more than one element."
  3340. "Failing to load\n");
  3341. return -ENOMEM;
  3342. }
  3343. arr_index = 0;
  3344. idx = 0;
  3345. while (idx < mem_descr_sglh->num_elements) {
  3346. psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
  3347. for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
  3348. sizeof(struct sgl_handle)); i++) {
  3349. if (arr_index < phba->params.ios_per_ctrl) {
  3350. phba->io_sgl_hndl_base[arr_index] = psgl_handle;
  3351. phba->io_sgl_hndl_avbl++;
  3352. arr_index++;
  3353. } else {
  3354. phba->eh_sgl_hndl_base[arr_index -
  3355. phba->params.ios_per_ctrl] =
  3356. psgl_handle;
  3357. arr_index++;
  3358. phba->eh_sgl_hndl_avbl++;
  3359. }
  3360. psgl_handle++;
  3361. }
  3362. idx++;
  3363. }
  3364. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3365. "BM_%d : phba->io_sgl_hndl_avbl=%d"
  3366. "phba->eh_sgl_hndl_avbl=%d\n",
  3367. phba->io_sgl_hndl_avbl,
  3368. phba->eh_sgl_hndl_avbl);
  3369. mem_descr_sg = phba->init_mem;
  3370. mem_descr_sg += HWI_MEM_SGE;
  3371. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3372. "\n BM_%d : mem_descr_sg->num_elements=%d\n",
  3373. mem_descr_sg->num_elements);
  3374. arr_index = 0;
  3375. idx = 0;
  3376. while (idx < mem_descr_sg->num_elements) {
  3377. pfrag = mem_descr_sg->mem_array[idx].virtual_address;
  3378. for (i = 0;
  3379. i < (mem_descr_sg->mem_array[idx].size) /
  3380. (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
  3381. i++) {
  3382. if (arr_index < phba->params.ios_per_ctrl)
  3383. psgl_handle = phba->io_sgl_hndl_base[arr_index];
  3384. else
  3385. psgl_handle = phba->eh_sgl_hndl_base[arr_index -
  3386. phba->params.ios_per_ctrl];
  3387. psgl_handle->pfrag = pfrag;
  3388. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
  3389. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
  3390. pfrag += phba->params.num_sge_per_io;
  3391. psgl_handle->sgl_index =
  3392. phba->fw_config.iscsi_icd_start + arr_index++;
  3393. }
  3394. idx++;
  3395. }
  3396. phba->io_sgl_free_index = 0;
  3397. phba->io_sgl_alloc_index = 0;
  3398. phba->eh_sgl_free_index = 0;
  3399. phba->eh_sgl_alloc_index = 0;
  3400. return 0;
  3401. }
  3402. static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
  3403. {
  3404. int i;
  3405. phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
  3406. GFP_KERNEL);
  3407. if (!phba->cid_array) {
  3408. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3409. "BM_%d : Failed to allocate memory in "
  3410. "hba_setup_cid_tbls\n");
  3411. return -ENOMEM;
  3412. }
  3413. phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
  3414. phba->params.cxns_per_ctrl, GFP_KERNEL);
  3415. if (!phba->ep_array) {
  3416. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3417. "BM_%d : Failed to allocate memory in "
  3418. "hba_setup_cid_tbls\n");
  3419. kfree(phba->cid_array);
  3420. phba->cid_array = NULL;
  3421. return -ENOMEM;
  3422. }
  3423. phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
  3424. phba->params.cxns_per_ctrl, GFP_KERNEL);
  3425. if (!phba->conn_table) {
  3426. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3427. "BM_%d : Failed to allocate memory in"
  3428. "hba_setup_cid_tbls\n");
  3429. kfree(phba->cid_array);
  3430. kfree(phba->ep_array);
  3431. phba->cid_array = NULL;
  3432. phba->ep_array = NULL;
  3433. return -ENOMEM;
  3434. }
  3435. for (i = 0; i < phba->params.cxns_per_ctrl; i++)
  3436. phba->cid_array[i] = phba->phwi_ctrlr->wrb_context[i].cid;
  3437. phba->avlbl_cids = phba->params.cxns_per_ctrl;
  3438. return 0;
  3439. }
  3440. static void hwi_enable_intr(struct beiscsi_hba *phba)
  3441. {
  3442. struct be_ctrl_info *ctrl = &phba->ctrl;
  3443. struct hwi_controller *phwi_ctrlr;
  3444. struct hwi_context_memory *phwi_context;
  3445. struct be_queue_info *eq;
  3446. u8 __iomem *addr;
  3447. u32 reg, i;
  3448. u32 enabled;
  3449. phwi_ctrlr = phba->phwi_ctrlr;
  3450. phwi_context = phwi_ctrlr->phwi_ctxt;
  3451. addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
  3452. PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
  3453. reg = ioread32(addr);
  3454. enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3455. if (!enabled) {
  3456. reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3457. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3458. "BM_%d : reg =x%08x addr=%p\n", reg, addr);
  3459. iowrite32(reg, addr);
  3460. }
  3461. if (!phba->msix_enabled) {
  3462. eq = &phwi_context->be_eq[0].q;
  3463. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3464. "BM_%d : eq->id=%d\n", eq->id);
  3465. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3466. } else {
  3467. for (i = 0; i <= phba->num_cpus; i++) {
  3468. eq = &phwi_context->be_eq[i].q;
  3469. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3470. "BM_%d : eq->id=%d\n", eq->id);
  3471. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3472. }
  3473. }
  3474. }
  3475. static void hwi_disable_intr(struct beiscsi_hba *phba)
  3476. {
  3477. struct be_ctrl_info *ctrl = &phba->ctrl;
  3478. u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
  3479. u32 reg = ioread32(addr);
  3480. u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3481. if (enabled) {
  3482. reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3483. iowrite32(reg, addr);
  3484. } else
  3485. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  3486. "BM_%d : In hwi_disable_intr, Already Disabled\n");
  3487. }
  3488. /**
  3489. * beiscsi_get_boot_info()- Get the boot session info
  3490. * @phba: The device priv structure instance
  3491. *
  3492. * Get the boot target info and store in driver priv structure
  3493. *
  3494. * return values
  3495. * Success: 0
  3496. * Failure: Non-Zero Value
  3497. **/
  3498. static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
  3499. {
  3500. struct be_cmd_get_session_resp *session_resp;
  3501. struct be_dma_mem nonemb_cmd;
  3502. unsigned int tag;
  3503. unsigned int s_handle;
  3504. int ret = -ENOMEM;
  3505. /* Get the session handle of the boot target */
  3506. ret = be_mgmt_get_boot_shandle(phba, &s_handle);
  3507. if (ret) {
  3508. beiscsi_log(phba, KERN_ERR,
  3509. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3510. "BM_%d : No boot session\n");
  3511. return ret;
  3512. }
  3513. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  3514. sizeof(*session_resp),
  3515. &nonemb_cmd.dma);
  3516. if (nonemb_cmd.va == NULL) {
  3517. beiscsi_log(phba, KERN_ERR,
  3518. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3519. "BM_%d : Failed to allocate memory for"
  3520. "beiscsi_get_session_info\n");
  3521. return -ENOMEM;
  3522. }
  3523. memset(nonemb_cmd.va, 0, sizeof(*session_resp));
  3524. tag = mgmt_get_session_info(phba, s_handle,
  3525. &nonemb_cmd);
  3526. if (!tag) {
  3527. beiscsi_log(phba, KERN_ERR,
  3528. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3529. "BM_%d : beiscsi_get_session_info"
  3530. " Failed\n");
  3531. goto boot_freemem;
  3532. }
  3533. ret = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
  3534. if (ret) {
  3535. beiscsi_log(phba, KERN_ERR,
  3536. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3537. "BM_%d : beiscsi_get_session_info Failed");
  3538. goto boot_freemem;
  3539. }
  3540. session_resp = nonemb_cmd.va ;
  3541. memcpy(&phba->boot_sess, &session_resp->session_info,
  3542. sizeof(struct mgmt_session_info));
  3543. ret = 0;
  3544. boot_freemem:
  3545. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  3546. nonemb_cmd.va, nonemb_cmd.dma);
  3547. return ret;
  3548. }
  3549. static void beiscsi_boot_release(void *data)
  3550. {
  3551. struct beiscsi_hba *phba = data;
  3552. scsi_host_put(phba->shost);
  3553. }
  3554. static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
  3555. {
  3556. struct iscsi_boot_kobj *boot_kobj;
  3557. /* get boot info using mgmt cmd */
  3558. if (beiscsi_get_boot_info(phba))
  3559. /* Try to see if we can carry on without this */
  3560. return 0;
  3561. phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
  3562. if (!phba->boot_kset)
  3563. return -ENOMEM;
  3564. /* get a ref because the show function will ref the phba */
  3565. if (!scsi_host_get(phba->shost))
  3566. goto free_kset;
  3567. boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
  3568. beiscsi_show_boot_tgt_info,
  3569. beiscsi_tgt_get_attr_visibility,
  3570. beiscsi_boot_release);
  3571. if (!boot_kobj)
  3572. goto put_shost;
  3573. if (!scsi_host_get(phba->shost))
  3574. goto free_kset;
  3575. boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
  3576. beiscsi_show_boot_ini_info,
  3577. beiscsi_ini_get_attr_visibility,
  3578. beiscsi_boot_release);
  3579. if (!boot_kobj)
  3580. goto put_shost;
  3581. if (!scsi_host_get(phba->shost))
  3582. goto free_kset;
  3583. boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
  3584. beiscsi_show_boot_eth_info,
  3585. beiscsi_eth_get_attr_visibility,
  3586. beiscsi_boot_release);
  3587. if (!boot_kobj)
  3588. goto put_shost;
  3589. return 0;
  3590. put_shost:
  3591. scsi_host_put(phba->shost);
  3592. free_kset:
  3593. iscsi_boot_destroy_kset(phba->boot_kset);
  3594. return -ENOMEM;
  3595. }
  3596. static int beiscsi_init_port(struct beiscsi_hba *phba)
  3597. {
  3598. int ret;
  3599. ret = beiscsi_init_controller(phba);
  3600. if (ret < 0) {
  3601. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3602. "BM_%d : beiscsi_dev_probe - Failed in"
  3603. "beiscsi_init_controller\n");
  3604. return ret;
  3605. }
  3606. ret = beiscsi_init_sgl_handle(phba);
  3607. if (ret < 0) {
  3608. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3609. "BM_%d : beiscsi_dev_probe - Failed in"
  3610. "beiscsi_init_sgl_handle\n");
  3611. goto do_cleanup_ctrlr;
  3612. }
  3613. if (hba_setup_cid_tbls(phba)) {
  3614. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3615. "BM_%d : Failed in hba_setup_cid_tbls\n");
  3616. kfree(phba->io_sgl_hndl_base);
  3617. kfree(phba->eh_sgl_hndl_base);
  3618. goto do_cleanup_ctrlr;
  3619. }
  3620. return ret;
  3621. do_cleanup_ctrlr:
  3622. hwi_cleanup(phba);
  3623. return ret;
  3624. }
  3625. static void hwi_purge_eq(struct beiscsi_hba *phba)
  3626. {
  3627. struct hwi_controller *phwi_ctrlr;
  3628. struct hwi_context_memory *phwi_context;
  3629. struct be_queue_info *eq;
  3630. struct be_eq_entry *eqe = NULL;
  3631. int i, eq_msix;
  3632. unsigned int num_processed;
  3633. phwi_ctrlr = phba->phwi_ctrlr;
  3634. phwi_context = phwi_ctrlr->phwi_ctxt;
  3635. if (phba->msix_enabled)
  3636. eq_msix = 1;
  3637. else
  3638. eq_msix = 0;
  3639. for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
  3640. eq = &phwi_context->be_eq[i].q;
  3641. eqe = queue_tail_node(eq);
  3642. num_processed = 0;
  3643. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  3644. & EQE_VALID_MASK) {
  3645. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  3646. queue_tail_inc(eq);
  3647. eqe = queue_tail_node(eq);
  3648. num_processed++;
  3649. }
  3650. if (num_processed)
  3651. hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
  3652. }
  3653. }
  3654. static void beiscsi_clean_port(struct beiscsi_hba *phba)
  3655. {
  3656. int mgmt_status;
  3657. mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
  3658. if (mgmt_status)
  3659. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  3660. "BM_%d : mgmt_epfw_cleanup FAILED\n");
  3661. hwi_purge_eq(phba);
  3662. hwi_cleanup(phba);
  3663. kfree(phba->io_sgl_hndl_base);
  3664. kfree(phba->eh_sgl_hndl_base);
  3665. kfree(phba->cid_array);
  3666. kfree(phba->ep_array);
  3667. kfree(phba->conn_table);
  3668. }
  3669. /**
  3670. * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
  3671. * @beiscsi_conn: ptr to the conn to be cleaned up
  3672. * @task: ptr to iscsi_task resource to be freed.
  3673. *
  3674. * Free driver mgmt resources binded to CXN.
  3675. **/
  3676. void
  3677. beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
  3678. struct iscsi_task *task)
  3679. {
  3680. struct beiscsi_io_task *io_task;
  3681. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3682. struct hwi_wrb_context *pwrb_context;
  3683. struct hwi_controller *phwi_ctrlr;
  3684. uint16_t cri_index = BE_GET_CRI_FROM_CID(
  3685. beiscsi_conn->beiscsi_conn_cid);
  3686. phwi_ctrlr = phba->phwi_ctrlr;
  3687. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  3688. io_task = task->dd_data;
  3689. if (io_task->pwrb_handle) {
  3690. memset(io_task->pwrb_handle->pwrb, 0,
  3691. sizeof(struct iscsi_wrb));
  3692. free_wrb_handle(phba, pwrb_context,
  3693. io_task->pwrb_handle);
  3694. io_task->pwrb_handle = NULL;
  3695. }
  3696. if (io_task->psgl_handle) {
  3697. spin_lock_bh(&phba->mgmt_sgl_lock);
  3698. free_mgmt_sgl_handle(phba,
  3699. io_task->psgl_handle);
  3700. io_task->psgl_handle = NULL;
  3701. spin_unlock_bh(&phba->mgmt_sgl_lock);
  3702. }
  3703. if (io_task->mtask_addr)
  3704. pci_unmap_single(phba->pcidev,
  3705. io_task->mtask_addr,
  3706. io_task->mtask_data_count,
  3707. PCI_DMA_TODEVICE);
  3708. }
  3709. /**
  3710. * beiscsi_cleanup_task()- Free driver resources of the task
  3711. * @task: ptr to the iscsi task
  3712. *
  3713. **/
  3714. static void beiscsi_cleanup_task(struct iscsi_task *task)
  3715. {
  3716. struct beiscsi_io_task *io_task = task->dd_data;
  3717. struct iscsi_conn *conn = task->conn;
  3718. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3719. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3720. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3721. struct hwi_wrb_context *pwrb_context;
  3722. struct hwi_controller *phwi_ctrlr;
  3723. uint16_t cri_index = BE_GET_CRI_FROM_CID(
  3724. beiscsi_conn->beiscsi_conn_cid);
  3725. phwi_ctrlr = phba->phwi_ctrlr;
  3726. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  3727. if (io_task->cmd_bhs) {
  3728. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3729. io_task->bhs_pa.u.a64.address);
  3730. io_task->cmd_bhs = NULL;
  3731. }
  3732. if (task->sc) {
  3733. if (io_task->pwrb_handle) {
  3734. free_wrb_handle(phba, pwrb_context,
  3735. io_task->pwrb_handle);
  3736. io_task->pwrb_handle = NULL;
  3737. }
  3738. if (io_task->psgl_handle) {
  3739. spin_lock(&phba->io_sgl_lock);
  3740. free_io_sgl_handle(phba, io_task->psgl_handle);
  3741. spin_unlock(&phba->io_sgl_lock);
  3742. io_task->psgl_handle = NULL;
  3743. }
  3744. } else {
  3745. if (!beiscsi_conn->login_in_progress)
  3746. beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
  3747. }
  3748. }
  3749. void
  3750. beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
  3751. struct beiscsi_offload_params *params)
  3752. {
  3753. struct wrb_handle *pwrb_handle;
  3754. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3755. struct iscsi_task *task = beiscsi_conn->task;
  3756. struct iscsi_session *session = task->conn->session;
  3757. u32 doorbell = 0;
  3758. /*
  3759. * We can always use 0 here because it is reserved by libiscsi for
  3760. * login/startup related tasks.
  3761. */
  3762. beiscsi_conn->login_in_progress = 0;
  3763. spin_lock_bh(&session->lock);
  3764. beiscsi_cleanup_task(task);
  3765. spin_unlock_bh(&session->lock);
  3766. pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid);
  3767. /* Check for the adapter family */
  3768. if (is_chip_be2_be3r(phba))
  3769. beiscsi_offload_cxn_v0(params, pwrb_handle,
  3770. phba->init_mem);
  3771. else
  3772. beiscsi_offload_cxn_v2(params, pwrb_handle);
  3773. be_dws_le_to_cpu(pwrb_handle->pwrb,
  3774. sizeof(struct iscsi_target_context_update_wrb));
  3775. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3776. doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
  3777. << DB_DEF_PDU_WRB_INDEX_SHIFT;
  3778. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3779. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3780. }
  3781. static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
  3782. int *index, int *age)
  3783. {
  3784. *index = (int)itt;
  3785. if (age)
  3786. *age = conn->session->age;
  3787. }
  3788. /**
  3789. * beiscsi_alloc_pdu - allocates pdu and related resources
  3790. * @task: libiscsi task
  3791. * @opcode: opcode of pdu for task
  3792. *
  3793. * This is called with the session lock held. It will allocate
  3794. * the wrb and sgl if needed for the command. And it will prep
  3795. * the pdu's itt. beiscsi_parse_pdu will later translate
  3796. * the pdu itt to the libiscsi task itt.
  3797. */
  3798. static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  3799. {
  3800. struct beiscsi_io_task *io_task = task->dd_data;
  3801. struct iscsi_conn *conn = task->conn;
  3802. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3803. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3804. struct hwi_wrb_context *pwrb_context;
  3805. struct hwi_controller *phwi_ctrlr;
  3806. itt_t itt;
  3807. uint16_t cri_index = 0;
  3808. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  3809. dma_addr_t paddr;
  3810. io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
  3811. GFP_ATOMIC, &paddr);
  3812. if (!io_task->cmd_bhs)
  3813. return -ENOMEM;
  3814. io_task->bhs_pa.u.a64.address = paddr;
  3815. io_task->libiscsi_itt = (itt_t)task->itt;
  3816. io_task->conn = beiscsi_conn;
  3817. task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
  3818. task->hdr_max = sizeof(struct be_cmd_bhs);
  3819. io_task->psgl_handle = NULL;
  3820. io_task->pwrb_handle = NULL;
  3821. if (task->sc) {
  3822. spin_lock(&phba->io_sgl_lock);
  3823. io_task->psgl_handle = alloc_io_sgl_handle(phba);
  3824. spin_unlock(&phba->io_sgl_lock);
  3825. if (!io_task->psgl_handle) {
  3826. beiscsi_log(phba, KERN_ERR,
  3827. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  3828. "BM_%d : Alloc of IO_SGL_ICD Failed"
  3829. "for the CID : %d\n",
  3830. beiscsi_conn->beiscsi_conn_cid);
  3831. goto free_hndls;
  3832. }
  3833. io_task->pwrb_handle = alloc_wrb_handle(phba,
  3834. beiscsi_conn->beiscsi_conn_cid);
  3835. if (!io_task->pwrb_handle) {
  3836. beiscsi_log(phba, KERN_ERR,
  3837. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  3838. "BM_%d : Alloc of WRB_HANDLE Failed"
  3839. "for the CID : %d\n",
  3840. beiscsi_conn->beiscsi_conn_cid);
  3841. goto free_io_hndls;
  3842. }
  3843. } else {
  3844. io_task->scsi_cmnd = NULL;
  3845. if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
  3846. beiscsi_conn->task = task;
  3847. if (!beiscsi_conn->login_in_progress) {
  3848. spin_lock(&phba->mgmt_sgl_lock);
  3849. io_task->psgl_handle = (struct sgl_handle *)
  3850. alloc_mgmt_sgl_handle(phba);
  3851. spin_unlock(&phba->mgmt_sgl_lock);
  3852. if (!io_task->psgl_handle) {
  3853. beiscsi_log(phba, KERN_ERR,
  3854. BEISCSI_LOG_IO |
  3855. BEISCSI_LOG_CONFIG,
  3856. "BM_%d : Alloc of MGMT_SGL_ICD Failed"
  3857. "for the CID : %d\n",
  3858. beiscsi_conn->
  3859. beiscsi_conn_cid);
  3860. goto free_hndls;
  3861. }
  3862. beiscsi_conn->login_in_progress = 1;
  3863. beiscsi_conn->plogin_sgl_handle =
  3864. io_task->psgl_handle;
  3865. io_task->pwrb_handle =
  3866. alloc_wrb_handle(phba,
  3867. beiscsi_conn->beiscsi_conn_cid);
  3868. if (!io_task->pwrb_handle) {
  3869. beiscsi_log(phba, KERN_ERR,
  3870. BEISCSI_LOG_IO |
  3871. BEISCSI_LOG_CONFIG,
  3872. "BM_%d : Alloc of WRB_HANDLE Failed"
  3873. "for the CID : %d\n",
  3874. beiscsi_conn->
  3875. beiscsi_conn_cid);
  3876. goto free_mgmt_hndls;
  3877. }
  3878. beiscsi_conn->plogin_wrb_handle =
  3879. io_task->pwrb_handle;
  3880. } else {
  3881. io_task->psgl_handle =
  3882. beiscsi_conn->plogin_sgl_handle;
  3883. io_task->pwrb_handle =
  3884. beiscsi_conn->plogin_wrb_handle;
  3885. }
  3886. } else {
  3887. spin_lock(&phba->mgmt_sgl_lock);
  3888. io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
  3889. spin_unlock(&phba->mgmt_sgl_lock);
  3890. if (!io_task->psgl_handle) {
  3891. beiscsi_log(phba, KERN_ERR,
  3892. BEISCSI_LOG_IO |
  3893. BEISCSI_LOG_CONFIG,
  3894. "BM_%d : Alloc of MGMT_SGL_ICD Failed"
  3895. "for the CID : %d\n",
  3896. beiscsi_conn->
  3897. beiscsi_conn_cid);
  3898. goto free_hndls;
  3899. }
  3900. io_task->pwrb_handle =
  3901. alloc_wrb_handle(phba,
  3902. beiscsi_conn->beiscsi_conn_cid);
  3903. if (!io_task->pwrb_handle) {
  3904. beiscsi_log(phba, KERN_ERR,
  3905. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  3906. "BM_%d : Alloc of WRB_HANDLE Failed"
  3907. "for the CID : %d\n",
  3908. beiscsi_conn->beiscsi_conn_cid);
  3909. goto free_mgmt_hndls;
  3910. }
  3911. }
  3912. }
  3913. itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
  3914. wrb_index << 16) | (unsigned int)
  3915. (io_task->psgl_handle->sgl_index));
  3916. io_task->pwrb_handle->pio_handle = task;
  3917. io_task->cmd_bhs->iscsi_hdr.itt = itt;
  3918. return 0;
  3919. free_io_hndls:
  3920. spin_lock(&phba->io_sgl_lock);
  3921. free_io_sgl_handle(phba, io_task->psgl_handle);
  3922. spin_unlock(&phba->io_sgl_lock);
  3923. goto free_hndls;
  3924. free_mgmt_hndls:
  3925. spin_lock(&phba->mgmt_sgl_lock);
  3926. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  3927. io_task->psgl_handle = NULL;
  3928. spin_unlock(&phba->mgmt_sgl_lock);
  3929. free_hndls:
  3930. phwi_ctrlr = phba->phwi_ctrlr;
  3931. cri_index = BE_GET_CRI_FROM_CID(
  3932. beiscsi_conn->beiscsi_conn_cid);
  3933. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  3934. if (io_task->pwrb_handle)
  3935. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  3936. io_task->pwrb_handle = NULL;
  3937. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  3938. io_task->bhs_pa.u.a64.address);
  3939. io_task->cmd_bhs = NULL;
  3940. return -ENOMEM;
  3941. }
  3942. int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
  3943. unsigned int num_sg, unsigned int xferlen,
  3944. unsigned int writedir)
  3945. {
  3946. struct beiscsi_io_task *io_task = task->dd_data;
  3947. struct iscsi_conn *conn = task->conn;
  3948. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3949. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3950. struct iscsi_wrb *pwrb = NULL;
  3951. unsigned int doorbell = 0;
  3952. pwrb = io_task->pwrb_handle->pwrb;
  3953. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  3954. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  3955. if (writedir) {
  3956. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
  3957. INI_WR_CMD);
  3958. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
  3959. } else {
  3960. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
  3961. INI_RD_CMD);
  3962. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
  3963. }
  3964. io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
  3965. type, pwrb);
  3966. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
  3967. cpu_to_be16(*(unsigned short *)
  3968. &io_task->cmd_bhs->iscsi_hdr.lun));
  3969. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
  3970. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
  3971. io_task->pwrb_handle->wrb_index);
  3972. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
  3973. be32_to_cpu(task->cmdsn));
  3974. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
  3975. io_task->psgl_handle->sgl_index);
  3976. hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
  3977. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
  3978. io_task->pwrb_handle->nxt_wrb_index);
  3979. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  3980. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  3981. doorbell |= (io_task->pwrb_handle->wrb_index &
  3982. DB_DEF_PDU_WRB_INDEX_MASK) <<
  3983. DB_DEF_PDU_WRB_INDEX_SHIFT;
  3984. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  3985. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  3986. return 0;
  3987. }
  3988. static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
  3989. unsigned int num_sg, unsigned int xferlen,
  3990. unsigned int writedir)
  3991. {
  3992. struct beiscsi_io_task *io_task = task->dd_data;
  3993. struct iscsi_conn *conn = task->conn;
  3994. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  3995. struct beiscsi_hba *phba = beiscsi_conn->phba;
  3996. struct iscsi_wrb *pwrb = NULL;
  3997. unsigned int doorbell = 0;
  3998. pwrb = io_task->pwrb_handle->pwrb;
  3999. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  4000. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  4001. if (writedir) {
  4002. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  4003. INI_WR_CMD);
  4004. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  4005. } else {
  4006. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  4007. INI_RD_CMD);
  4008. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  4009. }
  4010. io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
  4011. type, pwrb);
  4012. AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
  4013. cpu_to_be16(*(unsigned short *)
  4014. &io_task->cmd_bhs->iscsi_hdr.lun));
  4015. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
  4016. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  4017. io_task->pwrb_handle->wrb_index);
  4018. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  4019. be32_to_cpu(task->cmdsn));
  4020. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  4021. io_task->psgl_handle->sgl_index);
  4022. hwi_write_sgl(pwrb, sg, num_sg, io_task);
  4023. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  4024. io_task->pwrb_handle->nxt_wrb_index);
  4025. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  4026. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  4027. doorbell |= (io_task->pwrb_handle->wrb_index &
  4028. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  4029. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  4030. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  4031. return 0;
  4032. }
  4033. static int beiscsi_mtask(struct iscsi_task *task)
  4034. {
  4035. struct beiscsi_io_task *io_task = task->dd_data;
  4036. struct iscsi_conn *conn = task->conn;
  4037. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  4038. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4039. struct iscsi_wrb *pwrb = NULL;
  4040. unsigned int doorbell = 0;
  4041. unsigned int cid;
  4042. unsigned int pwrb_typeoffset = 0;
  4043. cid = beiscsi_conn->beiscsi_conn_cid;
  4044. pwrb = io_task->pwrb_handle->pwrb;
  4045. memset(pwrb, 0, sizeof(*pwrb));
  4046. if (is_chip_be2_be3r(phba)) {
  4047. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  4048. be32_to_cpu(task->cmdsn));
  4049. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  4050. io_task->pwrb_handle->wrb_index);
  4051. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  4052. io_task->psgl_handle->sgl_index);
  4053. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
  4054. task->data_count);
  4055. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  4056. io_task->pwrb_handle->nxt_wrb_index);
  4057. pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
  4058. } else {
  4059. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
  4060. be32_to_cpu(task->cmdsn));
  4061. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
  4062. io_task->pwrb_handle->wrb_index);
  4063. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
  4064. io_task->psgl_handle->sgl_index);
  4065. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
  4066. task->data_count);
  4067. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
  4068. io_task->pwrb_handle->nxt_wrb_index);
  4069. pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
  4070. }
  4071. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  4072. case ISCSI_OP_LOGIN:
  4073. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
  4074. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  4075. hwi_write_buffer(pwrb, task);
  4076. break;
  4077. case ISCSI_OP_NOOP_OUT:
  4078. if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
  4079. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  4080. if (is_chip_be2_be3r(phba))
  4081. AMAP_SET_BITS(struct amap_iscsi_wrb,
  4082. dmsg, pwrb, 1);
  4083. else
  4084. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  4085. dmsg, pwrb, 1);
  4086. } else {
  4087. ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
  4088. if (is_chip_be2_be3r(phba))
  4089. AMAP_SET_BITS(struct amap_iscsi_wrb,
  4090. dmsg, pwrb, 0);
  4091. else
  4092. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  4093. dmsg, pwrb, 0);
  4094. }
  4095. hwi_write_buffer(pwrb, task);
  4096. break;
  4097. case ISCSI_OP_TEXT:
  4098. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  4099. hwi_write_buffer(pwrb, task);
  4100. break;
  4101. case ISCSI_OP_SCSI_TMFUNC:
  4102. ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
  4103. hwi_write_buffer(pwrb, task);
  4104. break;
  4105. case ISCSI_OP_LOGOUT:
  4106. ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
  4107. hwi_write_buffer(pwrb, task);
  4108. break;
  4109. default:
  4110. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4111. "BM_%d : opcode =%d Not supported\n",
  4112. task->hdr->opcode & ISCSI_OPCODE_MASK);
  4113. return -EINVAL;
  4114. }
  4115. /* Set the task type */
  4116. io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
  4117. AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
  4118. AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
  4119. doorbell |= cid & DB_WRB_POST_CID_MASK;
  4120. doorbell |= (io_task->pwrb_handle->wrb_index &
  4121. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  4122. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  4123. iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
  4124. return 0;
  4125. }
  4126. static int beiscsi_task_xmit(struct iscsi_task *task)
  4127. {
  4128. struct beiscsi_io_task *io_task = task->dd_data;
  4129. struct scsi_cmnd *sc = task->sc;
  4130. struct beiscsi_hba *phba = NULL;
  4131. struct scatterlist *sg;
  4132. int num_sg;
  4133. unsigned int writedir = 0, xferlen = 0;
  4134. phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba;
  4135. if (!sc)
  4136. return beiscsi_mtask(task);
  4137. io_task->scsi_cmnd = sc;
  4138. num_sg = scsi_dma_map(sc);
  4139. if (num_sg < 0) {
  4140. struct iscsi_conn *conn = task->conn;
  4141. struct beiscsi_hba *phba = NULL;
  4142. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  4143. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_IO,
  4144. "BM_%d : scsi_dma_map Failed\n");
  4145. return num_sg;
  4146. }
  4147. xferlen = scsi_bufflen(sc);
  4148. sg = scsi_sglist(sc);
  4149. if (sc->sc_data_direction == DMA_TO_DEVICE)
  4150. writedir = 1;
  4151. else
  4152. writedir = 0;
  4153. return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
  4154. }
  4155. /**
  4156. * beiscsi_bsg_request - handle bsg request from ISCSI transport
  4157. * @job: job to handle
  4158. */
  4159. static int beiscsi_bsg_request(struct bsg_job *job)
  4160. {
  4161. struct Scsi_Host *shost;
  4162. struct beiscsi_hba *phba;
  4163. struct iscsi_bsg_request *bsg_req = job->request;
  4164. int rc = -EINVAL;
  4165. unsigned int tag;
  4166. struct be_dma_mem nonemb_cmd;
  4167. struct be_cmd_resp_hdr *resp;
  4168. struct iscsi_bsg_reply *bsg_reply = job->reply;
  4169. unsigned short status, extd_status;
  4170. shost = iscsi_job_to_shost(job);
  4171. phba = iscsi_host_priv(shost);
  4172. switch (bsg_req->msgcode) {
  4173. case ISCSI_BSG_HST_VENDOR:
  4174. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  4175. job->request_payload.payload_len,
  4176. &nonemb_cmd.dma);
  4177. if (nonemb_cmd.va == NULL) {
  4178. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4179. "BM_%d : Failed to allocate memory for "
  4180. "beiscsi_bsg_request\n");
  4181. return -ENOMEM;
  4182. }
  4183. tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
  4184. &nonemb_cmd);
  4185. if (!tag) {
  4186. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4187. "BM_%d : MBX Tag Allocation Failed\n");
  4188. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  4189. nonemb_cmd.va, nonemb_cmd.dma);
  4190. return -EAGAIN;
  4191. }
  4192. rc = wait_event_interruptible_timeout(
  4193. phba->ctrl.mcc_wait[tag],
  4194. phba->ctrl.mcc_numtag[tag],
  4195. msecs_to_jiffies(
  4196. BEISCSI_HOST_MBX_TIMEOUT));
  4197. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  4198. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  4199. free_mcc_tag(&phba->ctrl, tag);
  4200. resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
  4201. sg_copy_from_buffer(job->reply_payload.sg_list,
  4202. job->reply_payload.sg_cnt,
  4203. nonemb_cmd.va, (resp->response_length
  4204. + sizeof(*resp)));
  4205. bsg_reply->reply_payload_rcv_len = resp->response_length;
  4206. bsg_reply->result = status;
  4207. bsg_job_done(job, bsg_reply->result,
  4208. bsg_reply->reply_payload_rcv_len);
  4209. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  4210. nonemb_cmd.va, nonemb_cmd.dma);
  4211. if (status || extd_status) {
  4212. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4213. "BM_%d : MBX Cmd Failed"
  4214. " status = %d extd_status = %d\n",
  4215. status, extd_status);
  4216. return -EIO;
  4217. } else {
  4218. rc = 0;
  4219. }
  4220. break;
  4221. default:
  4222. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4223. "BM_%d : Unsupported bsg command: 0x%x\n",
  4224. bsg_req->msgcode);
  4225. break;
  4226. }
  4227. return rc;
  4228. }
  4229. void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
  4230. {
  4231. /* Set the logging parameter */
  4232. beiscsi_log_enable_init(phba, beiscsi_log_enable);
  4233. }
  4234. /*
  4235. * beiscsi_quiesce()- Cleanup Driver resources
  4236. * @phba: Instance Priv structure
  4237. *
  4238. * Free the OS and HW resources held by the driver
  4239. **/
  4240. static void beiscsi_quiesce(struct beiscsi_hba *phba)
  4241. {
  4242. struct hwi_controller *phwi_ctrlr;
  4243. struct hwi_context_memory *phwi_context;
  4244. struct be_eq_obj *pbe_eq;
  4245. unsigned int i, msix_vec;
  4246. phwi_ctrlr = phba->phwi_ctrlr;
  4247. phwi_context = phwi_ctrlr->phwi_ctxt;
  4248. hwi_disable_intr(phba);
  4249. if (phba->msix_enabled) {
  4250. for (i = 0; i <= phba->num_cpus; i++) {
  4251. msix_vec = phba->msix_entries[i].vector;
  4252. free_irq(msix_vec, &phwi_context->be_eq[i]);
  4253. kfree(phba->msi_name[i]);
  4254. }
  4255. } else
  4256. if (phba->pcidev->irq)
  4257. free_irq(phba->pcidev->irq, phba);
  4258. pci_disable_msix(phba->pcidev);
  4259. destroy_workqueue(phba->wq);
  4260. if (blk_iopoll_enabled)
  4261. for (i = 0; i < phba->num_cpus; i++) {
  4262. pbe_eq = &phwi_context->be_eq[i];
  4263. blk_iopoll_disable(&pbe_eq->iopoll);
  4264. }
  4265. beiscsi_clean_port(phba);
  4266. beiscsi_free_mem(phba);
  4267. beiscsi_unmap_pci_function(phba);
  4268. pci_free_consistent(phba->pcidev,
  4269. phba->ctrl.mbox_mem_alloced.size,
  4270. phba->ctrl.mbox_mem_alloced.va,
  4271. phba->ctrl.mbox_mem_alloced.dma);
  4272. cancel_delayed_work_sync(&phba->beiscsi_hw_check_task);
  4273. }
  4274. static void beiscsi_remove(struct pci_dev *pcidev)
  4275. {
  4276. struct beiscsi_hba *phba = NULL;
  4277. phba = pci_get_drvdata(pcidev);
  4278. if (!phba) {
  4279. dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
  4280. return;
  4281. }
  4282. beiscsi_destroy_def_ifaces(phba);
  4283. beiscsi_quiesce(phba);
  4284. iscsi_boot_destroy_kset(phba->boot_kset);
  4285. iscsi_host_remove(phba->shost);
  4286. pci_dev_put(phba->pcidev);
  4287. iscsi_host_free(phba->shost);
  4288. pci_disable_device(pcidev);
  4289. }
  4290. static void beiscsi_shutdown(struct pci_dev *pcidev)
  4291. {
  4292. struct beiscsi_hba *phba = NULL;
  4293. phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
  4294. if (!phba) {
  4295. dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
  4296. return;
  4297. }
  4298. beiscsi_quiesce(phba);
  4299. pci_disable_device(pcidev);
  4300. }
  4301. static void beiscsi_msix_enable(struct beiscsi_hba *phba)
  4302. {
  4303. int i, status;
  4304. for (i = 0; i <= phba->num_cpus; i++)
  4305. phba->msix_entries[i].entry = i;
  4306. status = pci_enable_msix(phba->pcidev, phba->msix_entries,
  4307. (phba->num_cpus + 1));
  4308. if (!status)
  4309. phba->msix_enabled = true;
  4310. return;
  4311. }
  4312. /*
  4313. * beiscsi_hw_health_check()- Check adapter health
  4314. * @work: work item to check HW health
  4315. *
  4316. * Check if adapter in an unrecoverable state or not.
  4317. **/
  4318. static void
  4319. beiscsi_hw_health_check(struct work_struct *work)
  4320. {
  4321. struct beiscsi_hba *phba =
  4322. container_of(work, struct beiscsi_hba,
  4323. beiscsi_hw_check_task.work);
  4324. beiscsi_ue_detect(phba);
  4325. schedule_delayed_work(&phba->beiscsi_hw_check_task,
  4326. msecs_to_jiffies(1000));
  4327. }
  4328. static int beiscsi_dev_probe(struct pci_dev *pcidev,
  4329. const struct pci_device_id *id)
  4330. {
  4331. struct beiscsi_hba *phba = NULL;
  4332. struct hwi_controller *phwi_ctrlr;
  4333. struct hwi_context_memory *phwi_context;
  4334. struct be_eq_obj *pbe_eq;
  4335. int ret, i;
  4336. ret = beiscsi_enable_pci(pcidev);
  4337. if (ret < 0) {
  4338. dev_err(&pcidev->dev,
  4339. "beiscsi_dev_probe - Failed to enable pci device\n");
  4340. return ret;
  4341. }
  4342. phba = beiscsi_hba_alloc(pcidev);
  4343. if (!phba) {
  4344. dev_err(&pcidev->dev,
  4345. "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
  4346. goto disable_pci;
  4347. }
  4348. /* Initialize Driver configuration Paramters */
  4349. beiscsi_hba_attrs_init(phba);
  4350. phba->fw_timeout = false;
  4351. switch (pcidev->device) {
  4352. case BE_DEVICE_ID1:
  4353. case OC_DEVICE_ID1:
  4354. case OC_DEVICE_ID2:
  4355. phba->generation = BE_GEN2;
  4356. phba->iotask_fn = beiscsi_iotask;
  4357. break;
  4358. case BE_DEVICE_ID2:
  4359. case OC_DEVICE_ID3:
  4360. phba->generation = BE_GEN3;
  4361. phba->iotask_fn = beiscsi_iotask;
  4362. break;
  4363. case OC_SKH_ID1:
  4364. phba->generation = BE_GEN4;
  4365. phba->iotask_fn = beiscsi_iotask_v2;
  4366. break;
  4367. default:
  4368. phba->generation = 0;
  4369. }
  4370. if (enable_msix)
  4371. find_num_cpus(phba);
  4372. else
  4373. phba->num_cpus = 1;
  4374. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  4375. "BM_%d : num_cpus = %d\n",
  4376. phba->num_cpus);
  4377. if (enable_msix) {
  4378. beiscsi_msix_enable(phba);
  4379. if (!phba->msix_enabled)
  4380. phba->num_cpus = 1;
  4381. }
  4382. ret = be_ctrl_init(phba, pcidev);
  4383. if (ret) {
  4384. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4385. "BM_%d : beiscsi_dev_probe-"
  4386. "Failed in be_ctrl_init\n");
  4387. goto hba_free;
  4388. }
  4389. ret = beiscsi_cmd_reset_function(phba);
  4390. if (ret) {
  4391. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4392. "BM_%d : Reset Failed. Aborting Crashdump\n");
  4393. goto hba_free;
  4394. }
  4395. ret = be_chk_reset_complete(phba);
  4396. if (ret) {
  4397. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4398. "BM_%d : Failed to get out of reset."
  4399. "Aborting Crashdump\n");
  4400. goto hba_free;
  4401. }
  4402. spin_lock_init(&phba->io_sgl_lock);
  4403. spin_lock_init(&phba->mgmt_sgl_lock);
  4404. spin_lock_init(&phba->isr_lock);
  4405. ret = mgmt_get_fw_config(&phba->ctrl, phba);
  4406. if (ret != 0) {
  4407. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4408. "BM_%d : Error getting fw config\n");
  4409. goto free_port;
  4410. }
  4411. phba->shost->max_id = phba->fw_config.iscsi_cid_count;
  4412. beiscsi_get_params(phba);
  4413. phba->shost->can_queue = phba->params.ios_per_ctrl;
  4414. ret = beiscsi_init_port(phba);
  4415. if (ret < 0) {
  4416. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4417. "BM_%d : beiscsi_dev_probe-"
  4418. "Failed in beiscsi_init_port\n");
  4419. goto free_port;
  4420. }
  4421. for (i = 0; i < MAX_MCC_CMD ; i++) {
  4422. init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
  4423. phba->ctrl.mcc_tag[i] = i + 1;
  4424. phba->ctrl.mcc_numtag[i + 1] = 0;
  4425. phba->ctrl.mcc_tag_available++;
  4426. }
  4427. phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
  4428. snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
  4429. phba->shost->host_no);
  4430. phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
  4431. if (!phba->wq) {
  4432. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4433. "BM_%d : beiscsi_dev_probe-"
  4434. "Failed to allocate work queue\n");
  4435. goto free_twq;
  4436. }
  4437. INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task,
  4438. beiscsi_hw_health_check);
  4439. phwi_ctrlr = phba->phwi_ctrlr;
  4440. phwi_context = phwi_ctrlr->phwi_ctxt;
  4441. if (blk_iopoll_enabled) {
  4442. for (i = 0; i < phba->num_cpus; i++) {
  4443. pbe_eq = &phwi_context->be_eq[i];
  4444. blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
  4445. be_iopoll);
  4446. blk_iopoll_enable(&pbe_eq->iopoll);
  4447. }
  4448. i = (phba->msix_enabled) ? i : 0;
  4449. /* Work item for MCC handling */
  4450. pbe_eq = &phwi_context->be_eq[i];
  4451. INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
  4452. } else {
  4453. if (phba->msix_enabled) {
  4454. for (i = 0; i <= phba->num_cpus; i++) {
  4455. pbe_eq = &phwi_context->be_eq[i];
  4456. INIT_WORK(&pbe_eq->work_cqs,
  4457. beiscsi_process_all_cqs);
  4458. }
  4459. } else {
  4460. pbe_eq = &phwi_context->be_eq[0];
  4461. INIT_WORK(&pbe_eq->work_cqs,
  4462. beiscsi_process_all_cqs);
  4463. }
  4464. }
  4465. ret = beiscsi_init_irqs(phba);
  4466. if (ret < 0) {
  4467. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4468. "BM_%d : beiscsi_dev_probe-"
  4469. "Failed to beiscsi_init_irqs\n");
  4470. goto free_blkenbld;
  4471. }
  4472. hwi_enable_intr(phba);
  4473. if (beiscsi_setup_boot_info(phba))
  4474. /*
  4475. * log error but continue, because we may not be using
  4476. * iscsi boot.
  4477. */
  4478. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4479. "BM_%d : Could not set up "
  4480. "iSCSI boot info.\n");
  4481. beiscsi_create_def_ifaces(phba);
  4482. schedule_delayed_work(&phba->beiscsi_hw_check_task,
  4483. msecs_to_jiffies(1000));
  4484. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  4485. "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
  4486. return 0;
  4487. free_blkenbld:
  4488. destroy_workqueue(phba->wq);
  4489. if (blk_iopoll_enabled)
  4490. for (i = 0; i < phba->num_cpus; i++) {
  4491. pbe_eq = &phwi_context->be_eq[i];
  4492. blk_iopoll_disable(&pbe_eq->iopoll);
  4493. }
  4494. free_twq:
  4495. beiscsi_clean_port(phba);
  4496. beiscsi_free_mem(phba);
  4497. free_port:
  4498. pci_free_consistent(phba->pcidev,
  4499. phba->ctrl.mbox_mem_alloced.size,
  4500. phba->ctrl.mbox_mem_alloced.va,
  4501. phba->ctrl.mbox_mem_alloced.dma);
  4502. beiscsi_unmap_pci_function(phba);
  4503. hba_free:
  4504. if (phba->msix_enabled)
  4505. pci_disable_msix(phba->pcidev);
  4506. iscsi_host_remove(phba->shost);
  4507. pci_dev_put(phba->pcidev);
  4508. iscsi_host_free(phba->shost);
  4509. disable_pci:
  4510. pci_disable_device(pcidev);
  4511. return ret;
  4512. }
  4513. struct iscsi_transport beiscsi_iscsi_transport = {
  4514. .owner = THIS_MODULE,
  4515. .name = DRV_NAME,
  4516. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
  4517. CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
  4518. .create_session = beiscsi_session_create,
  4519. .destroy_session = beiscsi_session_destroy,
  4520. .create_conn = beiscsi_conn_create,
  4521. .bind_conn = beiscsi_conn_bind,
  4522. .destroy_conn = iscsi_conn_teardown,
  4523. .attr_is_visible = be2iscsi_attr_is_visible,
  4524. .set_iface_param = be2iscsi_iface_set_param,
  4525. .get_iface_param = be2iscsi_iface_get_param,
  4526. .set_param = beiscsi_set_param,
  4527. .get_conn_param = iscsi_conn_get_param,
  4528. .get_session_param = iscsi_session_get_param,
  4529. .get_host_param = beiscsi_get_host_param,
  4530. .start_conn = beiscsi_conn_start,
  4531. .stop_conn = iscsi_conn_stop,
  4532. .send_pdu = iscsi_conn_send_pdu,
  4533. .xmit_task = beiscsi_task_xmit,
  4534. .cleanup_task = beiscsi_cleanup_task,
  4535. .alloc_pdu = beiscsi_alloc_pdu,
  4536. .parse_pdu_itt = beiscsi_parse_pdu,
  4537. .get_stats = beiscsi_conn_get_stats,
  4538. .get_ep_param = beiscsi_ep_get_param,
  4539. .ep_connect = beiscsi_ep_connect,
  4540. .ep_poll = beiscsi_ep_poll,
  4541. .ep_disconnect = beiscsi_ep_disconnect,
  4542. .session_recovery_timedout = iscsi_session_recovery_timedout,
  4543. .bsg_request = beiscsi_bsg_request,
  4544. };
  4545. static struct pci_driver beiscsi_pci_driver = {
  4546. .name = DRV_NAME,
  4547. .probe = beiscsi_dev_probe,
  4548. .remove = beiscsi_remove,
  4549. .shutdown = beiscsi_shutdown,
  4550. .id_table = beiscsi_pci_id_table
  4551. };
  4552. static int __init beiscsi_module_init(void)
  4553. {
  4554. int ret;
  4555. beiscsi_scsi_transport =
  4556. iscsi_register_transport(&beiscsi_iscsi_transport);
  4557. if (!beiscsi_scsi_transport) {
  4558. printk(KERN_ERR
  4559. "beiscsi_module_init - Unable to register beiscsi transport.\n");
  4560. return -ENOMEM;
  4561. }
  4562. printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
  4563. &beiscsi_iscsi_transport);
  4564. ret = pci_register_driver(&beiscsi_pci_driver);
  4565. if (ret) {
  4566. printk(KERN_ERR
  4567. "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
  4568. goto unregister_iscsi_transport;
  4569. }
  4570. return 0;
  4571. unregister_iscsi_transport:
  4572. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  4573. return ret;
  4574. }
  4575. static void __exit beiscsi_module_exit(void)
  4576. {
  4577. pci_unregister_driver(&beiscsi_pci_driver);
  4578. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  4579. }
  4580. module_init(beiscsi_module_init);
  4581. module_exit(beiscsi_module_exit);