vxge-config.c 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104
  1. /******************************************************************************
  2. * This software may be used and distributed according to the terms of
  3. * the GNU General Public License (GPL), incorporated herein by reference.
  4. * Drivers based on or derived from this code fall under the GPL and must
  5. * retain the authorship, copyright and license notice. This file is not
  6. * a complete program and may only be used when the entire operating
  7. * system is licensed under the GPL.
  8. * See the file COPYING in this distribution for more information.
  9. *
  10. * vxge-config.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
  11. * Virtualized Server Adapter.
  12. * Copyright(c) 2002-2010 Exar Corp.
  13. ******************************************************************************/
  14. #include <linux/vmalloc.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include "vxge-traffic.h"
  19. #include "vxge-config.h"
  20. #include "vxge-main.h"
  21. #define VXGE_HW_VPATH_STATS_PIO_READ(offset) { \
  22. status = __vxge_hw_vpath_stats_access(vpath, \
  23. VXGE_HW_STATS_OP_READ, \
  24. offset, \
  25. &val64); \
  26. if (status != VXGE_HW_OK) \
  27. return status; \
  28. }
  29. static void
  30. vxge_hw_vpath_set_zero_rx_frm_len(struct vxge_hw_vpath_reg __iomem *vp_reg)
  31. {
  32. u64 val64;
  33. val64 = readq(&vp_reg->rxmac_vcfg0);
  34. val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
  35. writeq(val64, &vp_reg->rxmac_vcfg0);
  36. val64 = readq(&vp_reg->rxmac_vcfg0);
  37. }
  38. /*
  39. * vxge_hw_vpath_wait_receive_idle - Wait for Rx to become idle
  40. */
  41. int vxge_hw_vpath_wait_receive_idle(struct __vxge_hw_device *hldev, u32 vp_id)
  42. {
  43. struct vxge_hw_vpath_reg __iomem *vp_reg;
  44. struct __vxge_hw_virtualpath *vpath;
  45. u64 val64, rxd_count, rxd_spat;
  46. int count = 0, total_count = 0;
  47. vpath = &hldev->virtual_paths[vp_id];
  48. vp_reg = vpath->vp_reg;
  49. vxge_hw_vpath_set_zero_rx_frm_len(vp_reg);
  50. /* Check that the ring controller for this vpath has enough free RxDs
  51. * to send frames to the host. This is done by reading the
  52. * PRC_RXD_DOORBELL_VPn register and comparing the read value to the
  53. * RXD_SPAT value for the vpath.
  54. */
  55. val64 = readq(&vp_reg->prc_cfg6);
  56. rxd_spat = VXGE_HW_PRC_CFG6_GET_RXD_SPAT(val64) + 1;
  57. /* Use a factor of 2 when comparing rxd_count against rxd_spat for some
  58. * leg room.
  59. */
  60. rxd_spat *= 2;
  61. do {
  62. mdelay(1);
  63. rxd_count = readq(&vp_reg->prc_rxd_doorbell);
  64. /* Check that the ring controller for this vpath does
  65. * not have any frame in its pipeline.
  66. */
  67. val64 = readq(&vp_reg->frm_in_progress_cnt);
  68. if ((rxd_count <= rxd_spat) || (val64 > 0))
  69. count = 0;
  70. else
  71. count++;
  72. total_count++;
  73. } while ((count < VXGE_HW_MIN_SUCCESSIVE_IDLE_COUNT) &&
  74. (total_count < VXGE_HW_MAX_POLLING_COUNT));
  75. if (total_count >= VXGE_HW_MAX_POLLING_COUNT)
  76. printk(KERN_ALERT "%s: Still Receiving traffic. Abort wait\n",
  77. __func__);
  78. return total_count;
  79. }
  80. /* vxge_hw_device_wait_receive_idle - This function waits until all frames
  81. * stored in the frame buffer for each vpath assigned to the given
  82. * function (hldev) have been sent to the host.
  83. */
  84. void vxge_hw_device_wait_receive_idle(struct __vxge_hw_device *hldev)
  85. {
  86. int i, total_count = 0;
  87. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  88. if (!(hldev->vpaths_deployed & vxge_mBIT(i)))
  89. continue;
  90. total_count += vxge_hw_vpath_wait_receive_idle(hldev, i);
  91. if (total_count >= VXGE_HW_MAX_POLLING_COUNT)
  92. break;
  93. }
  94. }
  95. /*
  96. * __vxge_hw_device_register_poll
  97. * Will poll certain register for specified amount of time.
  98. * Will poll until masked bit is not cleared.
  99. */
  100. static enum vxge_hw_status
  101. __vxge_hw_device_register_poll(void __iomem *reg, u64 mask, u32 max_millis)
  102. {
  103. u64 val64;
  104. u32 i = 0;
  105. udelay(10);
  106. do {
  107. val64 = readq(reg);
  108. if (!(val64 & mask))
  109. return VXGE_HW_OK;
  110. udelay(100);
  111. } while (++i <= 9);
  112. i = 0;
  113. do {
  114. val64 = readq(reg);
  115. if (!(val64 & mask))
  116. return VXGE_HW_OK;
  117. mdelay(1);
  118. } while (++i <= max_millis);
  119. return VXGE_HW_FAIL;
  120. }
  121. static inline enum vxge_hw_status
  122. __vxge_hw_pio_mem_write64(u64 val64, void __iomem *addr,
  123. u64 mask, u32 max_millis)
  124. {
  125. __vxge_hw_pio_mem_write32_lower((u32)vxge_bVALn(val64, 32, 32), addr);
  126. wmb();
  127. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32), addr);
  128. wmb();
  129. return __vxge_hw_device_register_poll(addr, mask, max_millis);
  130. }
  131. static enum vxge_hw_status
  132. vxge_hw_vpath_fw_api(struct __vxge_hw_virtualpath *vpath, u32 action,
  133. u32 fw_memo, u32 offset, u64 *data0, u64 *data1,
  134. u64 *steer_ctrl)
  135. {
  136. struct vxge_hw_vpath_reg __iomem *vp_reg = vpath->vp_reg;
  137. enum vxge_hw_status status;
  138. u64 val64;
  139. u32 retry = 0, max_retry = 3;
  140. spin_lock(&vpath->lock);
  141. if (!vpath->vp_open) {
  142. spin_unlock(&vpath->lock);
  143. max_retry = 100;
  144. }
  145. writeq(*data0, &vp_reg->rts_access_steer_data0);
  146. writeq(*data1, &vp_reg->rts_access_steer_data1);
  147. wmb();
  148. val64 = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION(action) |
  149. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL(fw_memo) |
  150. VXGE_HW_RTS_ACCESS_STEER_CTRL_OFFSET(offset) |
  151. VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE |
  152. *steer_ctrl;
  153. status = __vxge_hw_pio_mem_write64(val64,
  154. &vp_reg->rts_access_steer_ctrl,
  155. VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE,
  156. VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  157. /* The __vxge_hw_device_register_poll can udelay for a significant
  158. * amount of time, blocking other process from the CPU. If it delays
  159. * for ~5secs, a NMI error can occur. A way around this is to give up
  160. * the processor via msleep, but this is not allowed is under lock.
  161. * So, only allow it to sleep for ~4secs if open. Otherwise, delay for
  162. * 1sec and sleep for 10ms until the firmware operation has completed
  163. * or timed-out.
  164. */
  165. while ((status != VXGE_HW_OK) && retry++ < max_retry) {
  166. if (!vpath->vp_open)
  167. msleep(20);
  168. status = __vxge_hw_device_register_poll(
  169. &vp_reg->rts_access_steer_ctrl,
  170. VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE,
  171. VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  172. }
  173. if (status != VXGE_HW_OK)
  174. goto out;
  175. val64 = readq(&vp_reg->rts_access_steer_ctrl);
  176. if (val64 & VXGE_HW_RTS_ACCESS_STEER_CTRL_RMACJ_STATUS) {
  177. *data0 = readq(&vp_reg->rts_access_steer_data0);
  178. *data1 = readq(&vp_reg->rts_access_steer_data1);
  179. *steer_ctrl = val64;
  180. } else
  181. status = VXGE_HW_FAIL;
  182. out:
  183. if (vpath->vp_open)
  184. spin_unlock(&vpath->lock);
  185. return status;
  186. }
  187. enum vxge_hw_status
  188. vxge_hw_upgrade_read_version(struct __vxge_hw_device *hldev, u32 *major,
  189. u32 *minor, u32 *build)
  190. {
  191. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  192. struct __vxge_hw_virtualpath *vpath;
  193. enum vxge_hw_status status;
  194. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  195. status = vxge_hw_vpath_fw_api(vpath,
  196. VXGE_HW_FW_UPGRADE_ACTION,
  197. VXGE_HW_FW_UPGRADE_MEMO,
  198. VXGE_HW_FW_UPGRADE_OFFSET_READ,
  199. &data0, &data1, &steer_ctrl);
  200. if (status != VXGE_HW_OK)
  201. return status;
  202. *major = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0);
  203. *minor = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0);
  204. *build = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0);
  205. return status;
  206. }
  207. enum vxge_hw_status vxge_hw_flash_fw(struct __vxge_hw_device *hldev)
  208. {
  209. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  210. struct __vxge_hw_virtualpath *vpath;
  211. enum vxge_hw_status status;
  212. u32 ret;
  213. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  214. status = vxge_hw_vpath_fw_api(vpath,
  215. VXGE_HW_FW_UPGRADE_ACTION,
  216. VXGE_HW_FW_UPGRADE_MEMO,
  217. VXGE_HW_FW_UPGRADE_OFFSET_COMMIT,
  218. &data0, &data1, &steer_ctrl);
  219. if (status != VXGE_HW_OK) {
  220. vxge_debug_init(VXGE_ERR, "%s: FW upgrade failed", __func__);
  221. goto exit;
  222. }
  223. ret = VXGE_HW_RTS_ACCESS_STEER_CTRL_GET_ACTION(steer_ctrl) & 0x7F;
  224. if (ret != 1) {
  225. vxge_debug_init(VXGE_ERR, "%s: FW commit failed with error %d",
  226. __func__, ret);
  227. status = VXGE_HW_FAIL;
  228. }
  229. exit:
  230. return status;
  231. }
  232. enum vxge_hw_status
  233. vxge_update_fw_image(struct __vxge_hw_device *hldev, const u8 *fwdata, int size)
  234. {
  235. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  236. struct __vxge_hw_virtualpath *vpath;
  237. enum vxge_hw_status status;
  238. int ret_code, sec_code;
  239. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  240. /* send upgrade start command */
  241. status = vxge_hw_vpath_fw_api(vpath,
  242. VXGE_HW_FW_UPGRADE_ACTION,
  243. VXGE_HW_FW_UPGRADE_MEMO,
  244. VXGE_HW_FW_UPGRADE_OFFSET_START,
  245. &data0, &data1, &steer_ctrl);
  246. if (status != VXGE_HW_OK) {
  247. vxge_debug_init(VXGE_ERR, " %s: Upgrade start cmd failed",
  248. __func__);
  249. return status;
  250. }
  251. /* Transfer fw image to adapter 16 bytes at a time */
  252. for (; size > 0; size -= VXGE_HW_FW_UPGRADE_BLK_SIZE) {
  253. steer_ctrl = 0;
  254. /* The next 128bits of fwdata to be loaded onto the adapter */
  255. data0 = *((u64 *)fwdata);
  256. data1 = *((u64 *)fwdata + 1);
  257. status = vxge_hw_vpath_fw_api(vpath,
  258. VXGE_HW_FW_UPGRADE_ACTION,
  259. VXGE_HW_FW_UPGRADE_MEMO,
  260. VXGE_HW_FW_UPGRADE_OFFSET_SEND,
  261. &data0, &data1, &steer_ctrl);
  262. if (status != VXGE_HW_OK) {
  263. vxge_debug_init(VXGE_ERR, "%s: Upgrade send failed",
  264. __func__);
  265. goto out;
  266. }
  267. ret_code = VXGE_HW_UPGRADE_GET_RET_ERR_CODE(data0);
  268. switch (ret_code) {
  269. case VXGE_HW_FW_UPGRADE_OK:
  270. /* All OK, send next 16 bytes. */
  271. break;
  272. case VXGE_FW_UPGRADE_BYTES2SKIP:
  273. /* skip bytes in the stream */
  274. fwdata += (data0 >> 8) & 0xFFFFFFFF;
  275. break;
  276. case VXGE_HW_FW_UPGRADE_DONE:
  277. goto out;
  278. case VXGE_HW_FW_UPGRADE_ERR:
  279. sec_code = VXGE_HW_UPGRADE_GET_SEC_ERR_CODE(data0);
  280. switch (sec_code) {
  281. case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_1:
  282. case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_7:
  283. printk(KERN_ERR
  284. "corrupted data from .ncf file\n");
  285. break;
  286. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_3:
  287. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_4:
  288. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_5:
  289. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_6:
  290. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_8:
  291. printk(KERN_ERR "invalid .ncf file\n");
  292. break;
  293. case VXGE_HW_FW_UPGRADE_ERR_BUFFER_OVERFLOW:
  294. printk(KERN_ERR "buffer overflow\n");
  295. break;
  296. case VXGE_HW_FW_UPGRADE_ERR_FAILED_TO_FLASH:
  297. printk(KERN_ERR "failed to flash the image\n");
  298. break;
  299. case VXGE_HW_FW_UPGRADE_ERR_GENERIC_ERROR_UNKNOWN:
  300. printk(KERN_ERR
  301. "generic error. Unknown error type\n");
  302. break;
  303. default:
  304. printk(KERN_ERR "Unknown error of type %d\n",
  305. sec_code);
  306. break;
  307. }
  308. status = VXGE_HW_FAIL;
  309. goto out;
  310. default:
  311. printk(KERN_ERR "Unknown FW error: %d\n", ret_code);
  312. status = VXGE_HW_FAIL;
  313. goto out;
  314. }
  315. /* point to next 16 bytes */
  316. fwdata += VXGE_HW_FW_UPGRADE_BLK_SIZE;
  317. }
  318. out:
  319. return status;
  320. }
  321. enum vxge_hw_status
  322. vxge_hw_vpath_eprom_img_ver_get(struct __vxge_hw_device *hldev,
  323. struct eprom_image *img)
  324. {
  325. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  326. struct __vxge_hw_virtualpath *vpath;
  327. enum vxge_hw_status status;
  328. int i;
  329. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  330. for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
  331. data0 = VXGE_HW_RTS_ACCESS_STEER_ROM_IMAGE_INDEX(i);
  332. data1 = steer_ctrl = 0;
  333. status = vxge_hw_vpath_fw_api(vpath,
  334. VXGE_HW_FW_API_GET_EPROM_REV,
  335. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  336. 0, &data0, &data1, &steer_ctrl);
  337. if (status != VXGE_HW_OK)
  338. break;
  339. img[i].is_valid = VXGE_HW_GET_EPROM_IMAGE_VALID(data0);
  340. img[i].index = VXGE_HW_GET_EPROM_IMAGE_INDEX(data0);
  341. img[i].type = VXGE_HW_GET_EPROM_IMAGE_TYPE(data0);
  342. img[i].version = VXGE_HW_GET_EPROM_IMAGE_REV(data0);
  343. }
  344. return status;
  345. }
  346. /*
  347. * __vxge_hw_channel_free - Free memory allocated for channel
  348. * This function deallocates memory from the channel and various arrays
  349. * in the channel
  350. */
  351. static void __vxge_hw_channel_free(struct __vxge_hw_channel *channel)
  352. {
  353. kfree(channel->work_arr);
  354. kfree(channel->free_arr);
  355. kfree(channel->reserve_arr);
  356. kfree(channel->orig_arr);
  357. kfree(channel);
  358. }
  359. /*
  360. * __vxge_hw_channel_initialize - Initialize a channel
  361. * This function initializes a channel by properly setting the
  362. * various references
  363. */
  364. static enum vxge_hw_status
  365. __vxge_hw_channel_initialize(struct __vxge_hw_channel *channel)
  366. {
  367. u32 i;
  368. struct __vxge_hw_virtualpath *vpath;
  369. vpath = channel->vph->vpath;
  370. if ((channel->reserve_arr != NULL) && (channel->orig_arr != NULL)) {
  371. for (i = 0; i < channel->length; i++)
  372. channel->orig_arr[i] = channel->reserve_arr[i];
  373. }
  374. switch (channel->type) {
  375. case VXGE_HW_CHANNEL_TYPE_FIFO:
  376. vpath->fifoh = (struct __vxge_hw_fifo *)channel;
  377. channel->stats = &((struct __vxge_hw_fifo *)
  378. channel)->stats->common_stats;
  379. break;
  380. case VXGE_HW_CHANNEL_TYPE_RING:
  381. vpath->ringh = (struct __vxge_hw_ring *)channel;
  382. channel->stats = &((struct __vxge_hw_ring *)
  383. channel)->stats->common_stats;
  384. break;
  385. default:
  386. break;
  387. }
  388. return VXGE_HW_OK;
  389. }
  390. /*
  391. * __vxge_hw_channel_reset - Resets a channel
  392. * This function resets a channel by properly setting the various references
  393. */
  394. static enum vxge_hw_status
  395. __vxge_hw_channel_reset(struct __vxge_hw_channel *channel)
  396. {
  397. u32 i;
  398. for (i = 0; i < channel->length; i++) {
  399. if (channel->reserve_arr != NULL)
  400. channel->reserve_arr[i] = channel->orig_arr[i];
  401. if (channel->free_arr != NULL)
  402. channel->free_arr[i] = NULL;
  403. if (channel->work_arr != NULL)
  404. channel->work_arr[i] = NULL;
  405. }
  406. channel->free_ptr = channel->length;
  407. channel->reserve_ptr = channel->length;
  408. channel->reserve_top = 0;
  409. channel->post_index = 0;
  410. channel->compl_index = 0;
  411. return VXGE_HW_OK;
  412. }
  413. /*
  414. * __vxge_hw_device_pci_e_init
  415. * Initialize certain PCI/PCI-X configuration registers
  416. * with recommended values. Save config space for future hw resets.
  417. */
  418. static void __vxge_hw_device_pci_e_init(struct __vxge_hw_device *hldev)
  419. {
  420. u16 cmd = 0;
  421. /* Set the PErr Repconse bit and SERR in PCI command register. */
  422. pci_read_config_word(hldev->pdev, PCI_COMMAND, &cmd);
  423. cmd |= 0x140;
  424. pci_write_config_word(hldev->pdev, PCI_COMMAND, cmd);
  425. pci_save_state(hldev->pdev);
  426. }
  427. /* __vxge_hw_device_vpath_reset_in_prog_check - Check if vpath reset
  428. * in progress
  429. * This routine checks the vpath reset in progress register is turned zero
  430. */
  431. static enum vxge_hw_status
  432. __vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem *vpath_rst_in_prog)
  433. {
  434. enum vxge_hw_status status;
  435. status = __vxge_hw_device_register_poll(vpath_rst_in_prog,
  436. VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG(0x1ffff),
  437. VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  438. return status;
  439. }
  440. /*
  441. * _hw_legacy_swapper_set - Set the swapper bits for the legacy secion.
  442. * Set the swapper bits appropriately for the lagacy section.
  443. */
  444. static enum vxge_hw_status
  445. __vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg)
  446. {
  447. u64 val64;
  448. enum vxge_hw_status status = VXGE_HW_OK;
  449. val64 = readq(&legacy_reg->toc_swapper_fb);
  450. wmb();
  451. switch (val64) {
  452. case VXGE_HW_SWAPPER_INITIAL_VALUE:
  453. return status;
  454. case VXGE_HW_SWAPPER_BYTE_SWAPPED_BIT_FLIPPED:
  455. writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE,
  456. &legacy_reg->pifm_rd_swap_en);
  457. writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE,
  458. &legacy_reg->pifm_rd_flip_en);
  459. writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE,
  460. &legacy_reg->pifm_wr_swap_en);
  461. writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE,
  462. &legacy_reg->pifm_wr_flip_en);
  463. break;
  464. case VXGE_HW_SWAPPER_BYTE_SWAPPED:
  465. writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE,
  466. &legacy_reg->pifm_rd_swap_en);
  467. writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE,
  468. &legacy_reg->pifm_wr_swap_en);
  469. break;
  470. case VXGE_HW_SWAPPER_BIT_FLIPPED:
  471. writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE,
  472. &legacy_reg->pifm_rd_flip_en);
  473. writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE,
  474. &legacy_reg->pifm_wr_flip_en);
  475. break;
  476. }
  477. wmb();
  478. val64 = readq(&legacy_reg->toc_swapper_fb);
  479. if (val64 != VXGE_HW_SWAPPER_INITIAL_VALUE)
  480. status = VXGE_HW_ERR_SWAPPER_CTRL;
  481. return status;
  482. }
  483. /*
  484. * __vxge_hw_device_toc_get
  485. * This routine sets the swapper and reads the toc pointer and returns the
  486. * memory mapped address of the toc
  487. */
  488. static struct vxge_hw_toc_reg __iomem *
  489. __vxge_hw_device_toc_get(void __iomem *bar0)
  490. {
  491. u64 val64;
  492. struct vxge_hw_toc_reg __iomem *toc = NULL;
  493. enum vxge_hw_status status;
  494. struct vxge_hw_legacy_reg __iomem *legacy_reg =
  495. (struct vxge_hw_legacy_reg __iomem *)bar0;
  496. status = __vxge_hw_legacy_swapper_set(legacy_reg);
  497. if (status != VXGE_HW_OK)
  498. goto exit;
  499. val64 = readq(&legacy_reg->toc_first_pointer);
  500. toc = bar0 + val64;
  501. exit:
  502. return toc;
  503. }
  504. /*
  505. * __vxge_hw_device_reg_addr_get
  506. * This routine sets the swapper and reads the toc pointer and initializes the
  507. * register location pointers in the device object. It waits until the ric is
  508. * completed initializing registers.
  509. */
  510. static enum vxge_hw_status
  511. __vxge_hw_device_reg_addr_get(struct __vxge_hw_device *hldev)
  512. {
  513. u64 val64;
  514. u32 i;
  515. enum vxge_hw_status status = VXGE_HW_OK;
  516. hldev->legacy_reg = hldev->bar0;
  517. hldev->toc_reg = __vxge_hw_device_toc_get(hldev->bar0);
  518. if (hldev->toc_reg == NULL) {
  519. status = VXGE_HW_FAIL;
  520. goto exit;
  521. }
  522. val64 = readq(&hldev->toc_reg->toc_common_pointer);
  523. hldev->common_reg = hldev->bar0 + val64;
  524. val64 = readq(&hldev->toc_reg->toc_mrpcim_pointer);
  525. hldev->mrpcim_reg = hldev->bar0 + val64;
  526. for (i = 0; i < VXGE_HW_TITAN_SRPCIM_REG_SPACES; i++) {
  527. val64 = readq(&hldev->toc_reg->toc_srpcim_pointer[i]);
  528. hldev->srpcim_reg[i] = hldev->bar0 + val64;
  529. }
  530. for (i = 0; i < VXGE_HW_TITAN_VPMGMT_REG_SPACES; i++) {
  531. val64 = readq(&hldev->toc_reg->toc_vpmgmt_pointer[i]);
  532. hldev->vpmgmt_reg[i] = hldev->bar0 + val64;
  533. }
  534. for (i = 0; i < VXGE_HW_TITAN_VPATH_REG_SPACES; i++) {
  535. val64 = readq(&hldev->toc_reg->toc_vpath_pointer[i]);
  536. hldev->vpath_reg[i] = hldev->bar0 + val64;
  537. }
  538. val64 = readq(&hldev->toc_reg->toc_kdfc);
  539. switch (VXGE_HW_TOC_GET_KDFC_INITIAL_BIR(val64)) {
  540. case 0:
  541. hldev->kdfc = hldev->bar0 + VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64) ;
  542. break;
  543. default:
  544. break;
  545. }
  546. status = __vxge_hw_device_vpath_reset_in_prog_check(
  547. (u64 __iomem *)&hldev->common_reg->vpath_rst_in_prog);
  548. exit:
  549. return status;
  550. }
  551. /*
  552. * __vxge_hw_device_access_rights_get: Get Access Rights of the driver
  553. * This routine returns the Access Rights of the driver
  554. */
  555. static u32
  556. __vxge_hw_device_access_rights_get(u32 host_type, u32 func_id)
  557. {
  558. u32 access_rights = VXGE_HW_DEVICE_ACCESS_RIGHT_VPATH;
  559. switch (host_type) {
  560. case VXGE_HW_NO_MR_NO_SR_NORMAL_FUNCTION:
  561. if (func_id == 0) {
  562. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM |
  563. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  564. }
  565. break;
  566. case VXGE_HW_MR_NO_SR_VH0_BASE_FUNCTION:
  567. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM |
  568. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  569. break;
  570. case VXGE_HW_NO_MR_SR_VH0_FUNCTION0:
  571. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM |
  572. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  573. break;
  574. case VXGE_HW_NO_MR_SR_VH0_VIRTUAL_FUNCTION:
  575. case VXGE_HW_SR_VH_VIRTUAL_FUNCTION:
  576. case VXGE_HW_MR_SR_VH0_INVALID_CONFIG:
  577. break;
  578. case VXGE_HW_SR_VH_FUNCTION0:
  579. case VXGE_HW_VH_NORMAL_FUNCTION:
  580. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  581. break;
  582. }
  583. return access_rights;
  584. }
  585. /*
  586. * __vxge_hw_device_is_privilaged
  587. * This routine checks if the device function is privilaged or not
  588. */
  589. enum vxge_hw_status
  590. __vxge_hw_device_is_privilaged(u32 host_type, u32 func_id)
  591. {
  592. if (__vxge_hw_device_access_rights_get(host_type,
  593. func_id) &
  594. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)
  595. return VXGE_HW_OK;
  596. else
  597. return VXGE_HW_ERR_PRIVILEGED_OPERATION;
  598. }
  599. /*
  600. * __vxge_hw_vpath_func_id_get - Get the function id of the vpath.
  601. * Returns the function number of the vpath.
  602. */
  603. static u32
  604. __vxge_hw_vpath_func_id_get(struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg)
  605. {
  606. u64 val64;
  607. val64 = readq(&vpmgmt_reg->vpath_to_func_map_cfg1);
  608. return
  609. (u32)VXGE_HW_VPATH_TO_FUNC_MAP_CFG1_GET_VPATH_TO_FUNC_MAP_CFG1(val64);
  610. }
  611. /*
  612. * __vxge_hw_device_host_info_get
  613. * This routine returns the host type assignments
  614. */
  615. static void __vxge_hw_device_host_info_get(struct __vxge_hw_device *hldev)
  616. {
  617. u64 val64;
  618. u32 i;
  619. val64 = readq(&hldev->common_reg->host_type_assignments);
  620. hldev->host_type =
  621. (u32)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64);
  622. hldev->vpath_assignments = readq(&hldev->common_reg->vpath_assignments);
  623. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  624. if (!(hldev->vpath_assignments & vxge_mBIT(i)))
  625. continue;
  626. hldev->func_id =
  627. __vxge_hw_vpath_func_id_get(hldev->vpmgmt_reg[i]);
  628. hldev->access_rights = __vxge_hw_device_access_rights_get(
  629. hldev->host_type, hldev->func_id);
  630. hldev->virtual_paths[i].vp_open = VXGE_HW_VP_NOT_OPEN;
  631. hldev->virtual_paths[i].vp_reg = hldev->vpath_reg[i];
  632. hldev->first_vp_id = i;
  633. break;
  634. }
  635. }
  636. /*
  637. * __vxge_hw_verify_pci_e_info - Validate the pci-e link parameters such as
  638. * link width and signalling rate.
  639. */
  640. static enum vxge_hw_status
  641. __vxge_hw_verify_pci_e_info(struct __vxge_hw_device *hldev)
  642. {
  643. struct pci_dev *dev = hldev->pdev;
  644. u16 lnk;
  645. /* Get the negotiated link width and speed from PCI config space */
  646. pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnk);
  647. if ((lnk & PCI_EXP_LNKSTA_CLS) != 1)
  648. return VXGE_HW_ERR_INVALID_PCI_INFO;
  649. switch ((lnk & PCI_EXP_LNKSTA_NLW) >> 4) {
  650. case PCIE_LNK_WIDTH_RESRV:
  651. case PCIE_LNK_X1:
  652. case PCIE_LNK_X2:
  653. case PCIE_LNK_X4:
  654. case PCIE_LNK_X8:
  655. break;
  656. default:
  657. return VXGE_HW_ERR_INVALID_PCI_INFO;
  658. }
  659. return VXGE_HW_OK;
  660. }
  661. /*
  662. * __vxge_hw_device_initialize
  663. * Initialize Titan-V hardware.
  664. */
  665. static enum vxge_hw_status
  666. __vxge_hw_device_initialize(struct __vxge_hw_device *hldev)
  667. {
  668. enum vxge_hw_status status = VXGE_HW_OK;
  669. if (VXGE_HW_OK == __vxge_hw_device_is_privilaged(hldev->host_type,
  670. hldev->func_id)) {
  671. /* Validate the pci-e link width and speed */
  672. status = __vxge_hw_verify_pci_e_info(hldev);
  673. if (status != VXGE_HW_OK)
  674. goto exit;
  675. }
  676. exit:
  677. return status;
  678. }
  679. /*
  680. * __vxge_hw_vpath_fw_ver_get - Get the fw version
  681. * Returns FW Version
  682. */
  683. static enum vxge_hw_status
  684. __vxge_hw_vpath_fw_ver_get(struct __vxge_hw_virtualpath *vpath,
  685. struct vxge_hw_device_hw_info *hw_info)
  686. {
  687. struct vxge_hw_device_version *fw_version = &hw_info->fw_version;
  688. struct vxge_hw_device_date *fw_date = &hw_info->fw_date;
  689. struct vxge_hw_device_version *flash_version = &hw_info->flash_version;
  690. struct vxge_hw_device_date *flash_date = &hw_info->flash_date;
  691. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  692. enum vxge_hw_status status;
  693. status = vxge_hw_vpath_fw_api(vpath,
  694. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY,
  695. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  696. 0, &data0, &data1, &steer_ctrl);
  697. if (status != VXGE_HW_OK)
  698. goto exit;
  699. fw_date->day =
  700. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_DAY(data0);
  701. fw_date->month =
  702. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MONTH(data0);
  703. fw_date->year =
  704. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_YEAR(data0);
  705. snprintf(fw_date->date, VXGE_HW_FW_STRLEN, "%2.2d/%2.2d/%4.4d",
  706. fw_date->month, fw_date->day, fw_date->year);
  707. fw_version->major =
  708. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0);
  709. fw_version->minor =
  710. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0);
  711. fw_version->build =
  712. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0);
  713. snprintf(fw_version->version, VXGE_HW_FW_STRLEN, "%d.%d.%d",
  714. fw_version->major, fw_version->minor, fw_version->build);
  715. flash_date->day =
  716. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_DAY(data1);
  717. flash_date->month =
  718. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MONTH(data1);
  719. flash_date->year =
  720. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_YEAR(data1);
  721. snprintf(flash_date->date, VXGE_HW_FW_STRLEN, "%2.2d/%2.2d/%4.4d",
  722. flash_date->month, flash_date->day, flash_date->year);
  723. flash_version->major =
  724. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MAJOR(data1);
  725. flash_version->minor =
  726. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MINOR(data1);
  727. flash_version->build =
  728. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_BUILD(data1);
  729. snprintf(flash_version->version, VXGE_HW_FW_STRLEN, "%d.%d.%d",
  730. flash_version->major, flash_version->minor,
  731. flash_version->build);
  732. exit:
  733. return status;
  734. }
  735. /*
  736. * __vxge_hw_vpath_card_info_get - Get the serial numbers,
  737. * part number and product description.
  738. */
  739. static enum vxge_hw_status
  740. __vxge_hw_vpath_card_info_get(struct __vxge_hw_virtualpath *vpath,
  741. struct vxge_hw_device_hw_info *hw_info)
  742. {
  743. enum vxge_hw_status status;
  744. u64 data0, data1 = 0, steer_ctrl = 0;
  745. u8 *serial_number = hw_info->serial_number;
  746. u8 *part_number = hw_info->part_number;
  747. u8 *product_desc = hw_info->product_desc;
  748. u32 i, j = 0;
  749. data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_SERIAL_NUMBER;
  750. status = vxge_hw_vpath_fw_api(vpath,
  751. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY,
  752. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  753. 0, &data0, &data1, &steer_ctrl);
  754. if (status != VXGE_HW_OK)
  755. return status;
  756. ((u64 *)serial_number)[0] = be64_to_cpu(data0);
  757. ((u64 *)serial_number)[1] = be64_to_cpu(data1);
  758. data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_PART_NUMBER;
  759. data1 = steer_ctrl = 0;
  760. status = vxge_hw_vpath_fw_api(vpath,
  761. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY,
  762. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  763. 0, &data0, &data1, &steer_ctrl);
  764. if (status != VXGE_HW_OK)
  765. return status;
  766. ((u64 *)part_number)[0] = be64_to_cpu(data0);
  767. ((u64 *)part_number)[1] = be64_to_cpu(data1);
  768. for (i = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_0;
  769. i <= VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_3; i++) {
  770. data0 = i;
  771. data1 = steer_ctrl = 0;
  772. status = vxge_hw_vpath_fw_api(vpath,
  773. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY,
  774. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  775. 0, &data0, &data1, &steer_ctrl);
  776. if (status != VXGE_HW_OK)
  777. return status;
  778. ((u64 *)product_desc)[j++] = be64_to_cpu(data0);
  779. ((u64 *)product_desc)[j++] = be64_to_cpu(data1);
  780. }
  781. return status;
  782. }
  783. /*
  784. * __vxge_hw_vpath_pci_func_mode_get - Get the pci mode
  785. * Returns pci function mode
  786. */
  787. static enum vxge_hw_status
  788. __vxge_hw_vpath_pci_func_mode_get(struct __vxge_hw_virtualpath *vpath,
  789. struct vxge_hw_device_hw_info *hw_info)
  790. {
  791. u64 data0, data1 = 0, steer_ctrl = 0;
  792. enum vxge_hw_status status;
  793. data0 = 0;
  794. status = vxge_hw_vpath_fw_api(vpath,
  795. VXGE_HW_FW_API_GET_FUNC_MODE,
  796. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  797. 0, &data0, &data1, &steer_ctrl);
  798. if (status != VXGE_HW_OK)
  799. return status;
  800. hw_info->function_mode = VXGE_HW_GET_FUNC_MODE_VAL(data0);
  801. return status;
  802. }
  803. /*
  804. * __vxge_hw_vpath_addr_get - Get the hw address entry for this vpath
  805. * from MAC address table.
  806. */
  807. static enum vxge_hw_status
  808. __vxge_hw_vpath_addr_get(struct __vxge_hw_virtualpath *vpath,
  809. u8 *macaddr, u8 *macaddr_mask)
  810. {
  811. u64 action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_FIRST_ENTRY,
  812. data0 = 0, data1 = 0, steer_ctrl = 0;
  813. enum vxge_hw_status status;
  814. int i;
  815. do {
  816. status = vxge_hw_vpath_fw_api(vpath, action,
  817. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA,
  818. 0, &data0, &data1, &steer_ctrl);
  819. if (status != VXGE_HW_OK)
  820. goto exit;
  821. data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_DA_MAC_ADDR(data0);
  822. data1 = VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_DA_MAC_ADDR_MASK(
  823. data1);
  824. for (i = ETH_ALEN; i > 0; i--) {
  825. macaddr[i - 1] = (u8) (data0 & 0xFF);
  826. data0 >>= 8;
  827. macaddr_mask[i - 1] = (u8) (data1 & 0xFF);
  828. data1 >>= 8;
  829. }
  830. action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_NEXT_ENTRY;
  831. data0 = 0, data1 = 0, steer_ctrl = 0;
  832. } while (!is_valid_ether_addr(macaddr));
  833. exit:
  834. return status;
  835. }
  836. /**
  837. * vxge_hw_device_hw_info_get - Get the hw information
  838. * Returns the vpath mask that has the bits set for each vpath allocated
  839. * for the driver, FW version information, and the first mac address for
  840. * each vpath
  841. */
  842. enum vxge_hw_status
  843. vxge_hw_device_hw_info_get(void __iomem *bar0,
  844. struct vxge_hw_device_hw_info *hw_info)
  845. {
  846. u32 i;
  847. u64 val64;
  848. struct vxge_hw_toc_reg __iomem *toc;
  849. struct vxge_hw_mrpcim_reg __iomem *mrpcim_reg;
  850. struct vxge_hw_common_reg __iomem *common_reg;
  851. struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg;
  852. enum vxge_hw_status status;
  853. struct __vxge_hw_virtualpath vpath;
  854. memset(hw_info, 0, sizeof(struct vxge_hw_device_hw_info));
  855. toc = __vxge_hw_device_toc_get(bar0);
  856. if (toc == NULL) {
  857. status = VXGE_HW_ERR_CRITICAL;
  858. goto exit;
  859. }
  860. val64 = readq(&toc->toc_common_pointer);
  861. common_reg = bar0 + val64;
  862. status = __vxge_hw_device_vpath_reset_in_prog_check(
  863. (u64 __iomem *)&common_reg->vpath_rst_in_prog);
  864. if (status != VXGE_HW_OK)
  865. goto exit;
  866. hw_info->vpath_mask = readq(&common_reg->vpath_assignments);
  867. val64 = readq(&common_reg->host_type_assignments);
  868. hw_info->host_type =
  869. (u32)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64);
  870. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  871. if (!((hw_info->vpath_mask) & vxge_mBIT(i)))
  872. continue;
  873. val64 = readq(&toc->toc_vpmgmt_pointer[i]);
  874. vpmgmt_reg = bar0 + val64;
  875. hw_info->func_id = __vxge_hw_vpath_func_id_get(vpmgmt_reg);
  876. if (__vxge_hw_device_access_rights_get(hw_info->host_type,
  877. hw_info->func_id) &
  878. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM) {
  879. val64 = readq(&toc->toc_mrpcim_pointer);
  880. mrpcim_reg = bar0 + val64;
  881. writeq(0, &mrpcim_reg->xgmac_gen_fw_memo_mask);
  882. wmb();
  883. }
  884. val64 = readq(&toc->toc_vpath_pointer[i]);
  885. spin_lock_init(&vpath.lock);
  886. vpath.vp_reg = bar0 + val64;
  887. vpath.vp_open = VXGE_HW_VP_NOT_OPEN;
  888. status = __vxge_hw_vpath_pci_func_mode_get(&vpath, hw_info);
  889. if (status != VXGE_HW_OK)
  890. goto exit;
  891. status = __vxge_hw_vpath_fw_ver_get(&vpath, hw_info);
  892. if (status != VXGE_HW_OK)
  893. goto exit;
  894. status = __vxge_hw_vpath_card_info_get(&vpath, hw_info);
  895. if (status != VXGE_HW_OK)
  896. goto exit;
  897. break;
  898. }
  899. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  900. if (!((hw_info->vpath_mask) & vxge_mBIT(i)))
  901. continue;
  902. val64 = readq(&toc->toc_vpath_pointer[i]);
  903. vpath.vp_reg = bar0 + val64;
  904. vpath.vp_open = VXGE_HW_VP_NOT_OPEN;
  905. status = __vxge_hw_vpath_addr_get(&vpath,
  906. hw_info->mac_addrs[i],
  907. hw_info->mac_addr_masks[i]);
  908. if (status != VXGE_HW_OK)
  909. goto exit;
  910. }
  911. exit:
  912. return status;
  913. }
  914. /*
  915. * __vxge_hw_blockpool_destroy - Deallocates the block pool
  916. */
  917. static void __vxge_hw_blockpool_destroy(struct __vxge_hw_blockpool *blockpool)
  918. {
  919. struct __vxge_hw_device *hldev;
  920. struct list_head *p, *n;
  921. if (!blockpool)
  922. return;
  923. hldev = blockpool->hldev;
  924. list_for_each_safe(p, n, &blockpool->free_block_list) {
  925. pci_unmap_single(hldev->pdev,
  926. ((struct __vxge_hw_blockpool_entry *)p)->dma_addr,
  927. ((struct __vxge_hw_blockpool_entry *)p)->length,
  928. PCI_DMA_BIDIRECTIONAL);
  929. vxge_os_dma_free(hldev->pdev,
  930. ((struct __vxge_hw_blockpool_entry *)p)->memblock,
  931. &((struct __vxge_hw_blockpool_entry *)p)->acc_handle);
  932. list_del(&((struct __vxge_hw_blockpool_entry *)p)->item);
  933. kfree(p);
  934. blockpool->pool_size--;
  935. }
  936. list_for_each_safe(p, n, &blockpool->free_entry_list) {
  937. list_del(&((struct __vxge_hw_blockpool_entry *)p)->item);
  938. kfree((void *)p);
  939. }
  940. return;
  941. }
  942. /*
  943. * __vxge_hw_blockpool_create - Create block pool
  944. */
  945. static enum vxge_hw_status
  946. __vxge_hw_blockpool_create(struct __vxge_hw_device *hldev,
  947. struct __vxge_hw_blockpool *blockpool,
  948. u32 pool_size,
  949. u32 pool_max)
  950. {
  951. u32 i;
  952. struct __vxge_hw_blockpool_entry *entry = NULL;
  953. void *memblock;
  954. dma_addr_t dma_addr;
  955. struct pci_dev *dma_handle;
  956. struct pci_dev *acc_handle;
  957. enum vxge_hw_status status = VXGE_HW_OK;
  958. if (blockpool == NULL) {
  959. status = VXGE_HW_FAIL;
  960. goto blockpool_create_exit;
  961. }
  962. blockpool->hldev = hldev;
  963. blockpool->block_size = VXGE_HW_BLOCK_SIZE;
  964. blockpool->pool_size = 0;
  965. blockpool->pool_max = pool_max;
  966. blockpool->req_out = 0;
  967. INIT_LIST_HEAD(&blockpool->free_block_list);
  968. INIT_LIST_HEAD(&blockpool->free_entry_list);
  969. for (i = 0; i < pool_size + pool_max; i++) {
  970. entry = kzalloc(sizeof(struct __vxge_hw_blockpool_entry),
  971. GFP_KERNEL);
  972. if (entry == NULL) {
  973. __vxge_hw_blockpool_destroy(blockpool);
  974. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  975. goto blockpool_create_exit;
  976. }
  977. list_add(&entry->item, &blockpool->free_entry_list);
  978. }
  979. for (i = 0; i < pool_size; i++) {
  980. memblock = vxge_os_dma_malloc(
  981. hldev->pdev,
  982. VXGE_HW_BLOCK_SIZE,
  983. &dma_handle,
  984. &acc_handle);
  985. if (memblock == NULL) {
  986. __vxge_hw_blockpool_destroy(blockpool);
  987. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  988. goto blockpool_create_exit;
  989. }
  990. dma_addr = pci_map_single(hldev->pdev, memblock,
  991. VXGE_HW_BLOCK_SIZE, PCI_DMA_BIDIRECTIONAL);
  992. if (unlikely(pci_dma_mapping_error(hldev->pdev,
  993. dma_addr))) {
  994. vxge_os_dma_free(hldev->pdev, memblock, &acc_handle);
  995. __vxge_hw_blockpool_destroy(blockpool);
  996. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  997. goto blockpool_create_exit;
  998. }
  999. if (!list_empty(&blockpool->free_entry_list))
  1000. entry = (struct __vxge_hw_blockpool_entry *)
  1001. list_first_entry(&blockpool->free_entry_list,
  1002. struct __vxge_hw_blockpool_entry,
  1003. item);
  1004. if (entry == NULL)
  1005. entry =
  1006. kzalloc(sizeof(struct __vxge_hw_blockpool_entry),
  1007. GFP_KERNEL);
  1008. if (entry != NULL) {
  1009. list_del(&entry->item);
  1010. entry->length = VXGE_HW_BLOCK_SIZE;
  1011. entry->memblock = memblock;
  1012. entry->dma_addr = dma_addr;
  1013. entry->acc_handle = acc_handle;
  1014. entry->dma_handle = dma_handle;
  1015. list_add(&entry->item,
  1016. &blockpool->free_block_list);
  1017. blockpool->pool_size++;
  1018. } else {
  1019. __vxge_hw_blockpool_destroy(blockpool);
  1020. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1021. goto blockpool_create_exit;
  1022. }
  1023. }
  1024. blockpool_create_exit:
  1025. return status;
  1026. }
  1027. /*
  1028. * __vxge_hw_device_fifo_config_check - Check fifo configuration.
  1029. * Check the fifo configuration
  1030. */
  1031. static enum vxge_hw_status
  1032. __vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config *fifo_config)
  1033. {
  1034. if ((fifo_config->fifo_blocks < VXGE_HW_MIN_FIFO_BLOCKS) ||
  1035. (fifo_config->fifo_blocks > VXGE_HW_MAX_FIFO_BLOCKS))
  1036. return VXGE_HW_BADCFG_FIFO_BLOCKS;
  1037. return VXGE_HW_OK;
  1038. }
  1039. /*
  1040. * __vxge_hw_device_vpath_config_check - Check vpath configuration.
  1041. * Check the vpath configuration
  1042. */
  1043. static enum vxge_hw_status
  1044. __vxge_hw_device_vpath_config_check(struct vxge_hw_vp_config *vp_config)
  1045. {
  1046. enum vxge_hw_status status;
  1047. if ((vp_config->min_bandwidth < VXGE_HW_VPATH_BANDWIDTH_MIN) ||
  1048. (vp_config->min_bandwidth > VXGE_HW_VPATH_BANDWIDTH_MAX))
  1049. return VXGE_HW_BADCFG_VPATH_MIN_BANDWIDTH;
  1050. status = __vxge_hw_device_fifo_config_check(&vp_config->fifo);
  1051. if (status != VXGE_HW_OK)
  1052. return status;
  1053. if ((vp_config->mtu != VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU) &&
  1054. ((vp_config->mtu < VXGE_HW_VPATH_MIN_INITIAL_MTU) ||
  1055. (vp_config->mtu > VXGE_HW_VPATH_MAX_INITIAL_MTU)))
  1056. return VXGE_HW_BADCFG_VPATH_MTU;
  1057. if ((vp_config->rpa_strip_vlan_tag !=
  1058. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT) &&
  1059. (vp_config->rpa_strip_vlan_tag !=
  1060. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE) &&
  1061. (vp_config->rpa_strip_vlan_tag !=
  1062. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_DISABLE))
  1063. return VXGE_HW_BADCFG_VPATH_RPA_STRIP_VLAN_TAG;
  1064. return VXGE_HW_OK;
  1065. }
  1066. /*
  1067. * __vxge_hw_device_config_check - Check device configuration.
  1068. * Check the device configuration
  1069. */
  1070. static enum vxge_hw_status
  1071. __vxge_hw_device_config_check(struct vxge_hw_device_config *new_config)
  1072. {
  1073. u32 i;
  1074. enum vxge_hw_status status;
  1075. if ((new_config->intr_mode != VXGE_HW_INTR_MODE_IRQLINE) &&
  1076. (new_config->intr_mode != VXGE_HW_INTR_MODE_MSIX) &&
  1077. (new_config->intr_mode != VXGE_HW_INTR_MODE_MSIX_ONE_SHOT) &&
  1078. (new_config->intr_mode != VXGE_HW_INTR_MODE_DEF))
  1079. return VXGE_HW_BADCFG_INTR_MODE;
  1080. if ((new_config->rts_mac_en != VXGE_HW_RTS_MAC_DISABLE) &&
  1081. (new_config->rts_mac_en != VXGE_HW_RTS_MAC_ENABLE))
  1082. return VXGE_HW_BADCFG_RTS_MAC_EN;
  1083. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1084. status = __vxge_hw_device_vpath_config_check(
  1085. &new_config->vp_config[i]);
  1086. if (status != VXGE_HW_OK)
  1087. return status;
  1088. }
  1089. return VXGE_HW_OK;
  1090. }
  1091. /*
  1092. * vxge_hw_device_initialize - Initialize Titan device.
  1093. * Initialize Titan device. Note that all the arguments of this public API
  1094. * are 'IN', including @hldev. Driver cooperates with
  1095. * OS to find new Titan device, locate its PCI and memory spaces.
  1096. *
  1097. * When done, the driver allocates sizeof(struct __vxge_hw_device) bytes for HW
  1098. * to enable the latter to perform Titan hardware initialization.
  1099. */
  1100. enum vxge_hw_status
  1101. vxge_hw_device_initialize(
  1102. struct __vxge_hw_device **devh,
  1103. struct vxge_hw_device_attr *attr,
  1104. struct vxge_hw_device_config *device_config)
  1105. {
  1106. u32 i;
  1107. u32 nblocks = 0;
  1108. struct __vxge_hw_device *hldev = NULL;
  1109. enum vxge_hw_status status = VXGE_HW_OK;
  1110. status = __vxge_hw_device_config_check(device_config);
  1111. if (status != VXGE_HW_OK)
  1112. goto exit;
  1113. hldev = vzalloc(sizeof(struct __vxge_hw_device));
  1114. if (hldev == NULL) {
  1115. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1116. goto exit;
  1117. }
  1118. hldev->magic = VXGE_HW_DEVICE_MAGIC;
  1119. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_ALL);
  1120. /* apply config */
  1121. memcpy(&hldev->config, device_config,
  1122. sizeof(struct vxge_hw_device_config));
  1123. hldev->bar0 = attr->bar0;
  1124. hldev->pdev = attr->pdev;
  1125. hldev->uld_callbacks = attr->uld_callbacks;
  1126. __vxge_hw_device_pci_e_init(hldev);
  1127. status = __vxge_hw_device_reg_addr_get(hldev);
  1128. if (status != VXGE_HW_OK) {
  1129. vfree(hldev);
  1130. goto exit;
  1131. }
  1132. __vxge_hw_device_host_info_get(hldev);
  1133. /* Incrementing for stats blocks */
  1134. nblocks++;
  1135. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1136. if (!(hldev->vpath_assignments & vxge_mBIT(i)))
  1137. continue;
  1138. if (device_config->vp_config[i].ring.enable ==
  1139. VXGE_HW_RING_ENABLE)
  1140. nblocks += device_config->vp_config[i].ring.ring_blocks;
  1141. if (device_config->vp_config[i].fifo.enable ==
  1142. VXGE_HW_FIFO_ENABLE)
  1143. nblocks += device_config->vp_config[i].fifo.fifo_blocks;
  1144. nblocks++;
  1145. }
  1146. if (__vxge_hw_blockpool_create(hldev,
  1147. &hldev->block_pool,
  1148. device_config->dma_blockpool_initial + nblocks,
  1149. device_config->dma_blockpool_max + nblocks) != VXGE_HW_OK) {
  1150. vxge_hw_device_terminate(hldev);
  1151. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1152. goto exit;
  1153. }
  1154. status = __vxge_hw_device_initialize(hldev);
  1155. if (status != VXGE_HW_OK) {
  1156. vxge_hw_device_terminate(hldev);
  1157. goto exit;
  1158. }
  1159. *devh = hldev;
  1160. exit:
  1161. return status;
  1162. }
  1163. /*
  1164. * vxge_hw_device_terminate - Terminate Titan device.
  1165. * Terminate HW device.
  1166. */
  1167. void
  1168. vxge_hw_device_terminate(struct __vxge_hw_device *hldev)
  1169. {
  1170. vxge_assert(hldev->magic == VXGE_HW_DEVICE_MAGIC);
  1171. hldev->magic = VXGE_HW_DEVICE_DEAD;
  1172. __vxge_hw_blockpool_destroy(&hldev->block_pool);
  1173. vfree(hldev);
  1174. }
  1175. /*
  1176. * __vxge_hw_vpath_stats_access - Get the statistics from the given location
  1177. * and offset and perform an operation
  1178. */
  1179. static enum vxge_hw_status
  1180. __vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath *vpath,
  1181. u32 operation, u32 offset, u64 *stat)
  1182. {
  1183. u64 val64;
  1184. enum vxge_hw_status status = VXGE_HW_OK;
  1185. struct vxge_hw_vpath_reg __iomem *vp_reg;
  1186. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1187. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1188. goto vpath_stats_access_exit;
  1189. }
  1190. vp_reg = vpath->vp_reg;
  1191. val64 = VXGE_HW_XMAC_STATS_ACCESS_CMD_OP(operation) |
  1192. VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE |
  1193. VXGE_HW_XMAC_STATS_ACCESS_CMD_OFFSET_SEL(offset);
  1194. status = __vxge_hw_pio_mem_write64(val64,
  1195. &vp_reg->xmac_stats_access_cmd,
  1196. VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE,
  1197. vpath->hldev->config.device_poll_millis);
  1198. if ((status == VXGE_HW_OK) && (operation == VXGE_HW_STATS_OP_READ))
  1199. *stat = readq(&vp_reg->xmac_stats_access_data);
  1200. else
  1201. *stat = 0;
  1202. vpath_stats_access_exit:
  1203. return status;
  1204. }
  1205. /*
  1206. * __vxge_hw_vpath_xmac_tx_stats_get - Get the TX Statistics of a vpath
  1207. */
  1208. static enum vxge_hw_status
  1209. __vxge_hw_vpath_xmac_tx_stats_get(struct __vxge_hw_virtualpath *vpath,
  1210. struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats)
  1211. {
  1212. u64 *val64;
  1213. int i;
  1214. u32 offset = VXGE_HW_STATS_VPATH_TX_OFFSET;
  1215. enum vxge_hw_status status = VXGE_HW_OK;
  1216. val64 = (u64 *)vpath_tx_stats;
  1217. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1218. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1219. goto exit;
  1220. }
  1221. for (i = 0; i < sizeof(struct vxge_hw_xmac_vpath_tx_stats) / 8; i++) {
  1222. status = __vxge_hw_vpath_stats_access(vpath,
  1223. VXGE_HW_STATS_OP_READ,
  1224. offset, val64);
  1225. if (status != VXGE_HW_OK)
  1226. goto exit;
  1227. offset++;
  1228. val64++;
  1229. }
  1230. exit:
  1231. return status;
  1232. }
  1233. /*
  1234. * __vxge_hw_vpath_xmac_rx_stats_get - Get the RX Statistics of a vpath
  1235. */
  1236. static enum vxge_hw_status
  1237. __vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath *vpath,
  1238. struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats)
  1239. {
  1240. u64 *val64;
  1241. enum vxge_hw_status status = VXGE_HW_OK;
  1242. int i;
  1243. u32 offset = VXGE_HW_STATS_VPATH_RX_OFFSET;
  1244. val64 = (u64 *) vpath_rx_stats;
  1245. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1246. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1247. goto exit;
  1248. }
  1249. for (i = 0; i < sizeof(struct vxge_hw_xmac_vpath_rx_stats) / 8; i++) {
  1250. status = __vxge_hw_vpath_stats_access(vpath,
  1251. VXGE_HW_STATS_OP_READ,
  1252. offset >> 3, val64);
  1253. if (status != VXGE_HW_OK)
  1254. goto exit;
  1255. offset += 8;
  1256. val64++;
  1257. }
  1258. exit:
  1259. return status;
  1260. }
  1261. /*
  1262. * __vxge_hw_vpath_stats_get - Get the vpath hw statistics.
  1263. */
  1264. static enum vxge_hw_status
  1265. __vxge_hw_vpath_stats_get(struct __vxge_hw_virtualpath *vpath,
  1266. struct vxge_hw_vpath_stats_hw_info *hw_stats)
  1267. {
  1268. u64 val64;
  1269. enum vxge_hw_status status = VXGE_HW_OK;
  1270. struct vxge_hw_vpath_reg __iomem *vp_reg;
  1271. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1272. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1273. goto exit;
  1274. }
  1275. vp_reg = vpath->vp_reg;
  1276. val64 = readq(&vp_reg->vpath_debug_stats0);
  1277. hw_stats->ini_num_mwr_sent =
  1278. (u32)VXGE_HW_VPATH_DEBUG_STATS0_GET_INI_NUM_MWR_SENT(val64);
  1279. val64 = readq(&vp_reg->vpath_debug_stats1);
  1280. hw_stats->ini_num_mrd_sent =
  1281. (u32)VXGE_HW_VPATH_DEBUG_STATS1_GET_INI_NUM_MRD_SENT(val64);
  1282. val64 = readq(&vp_reg->vpath_debug_stats2);
  1283. hw_stats->ini_num_cpl_rcvd =
  1284. (u32)VXGE_HW_VPATH_DEBUG_STATS2_GET_INI_NUM_CPL_RCVD(val64);
  1285. val64 = readq(&vp_reg->vpath_debug_stats3);
  1286. hw_stats->ini_num_mwr_byte_sent =
  1287. VXGE_HW_VPATH_DEBUG_STATS3_GET_INI_NUM_MWR_BYTE_SENT(val64);
  1288. val64 = readq(&vp_reg->vpath_debug_stats4);
  1289. hw_stats->ini_num_cpl_byte_rcvd =
  1290. VXGE_HW_VPATH_DEBUG_STATS4_GET_INI_NUM_CPL_BYTE_RCVD(val64);
  1291. val64 = readq(&vp_reg->vpath_debug_stats5);
  1292. hw_stats->wrcrdtarb_xoff =
  1293. (u32)VXGE_HW_VPATH_DEBUG_STATS5_GET_WRCRDTARB_XOFF(val64);
  1294. val64 = readq(&vp_reg->vpath_debug_stats6);
  1295. hw_stats->rdcrdtarb_xoff =
  1296. (u32)VXGE_HW_VPATH_DEBUG_STATS6_GET_RDCRDTARB_XOFF(val64);
  1297. val64 = readq(&vp_reg->vpath_genstats_count01);
  1298. hw_stats->vpath_genstats_count0 =
  1299. (u32)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT0(
  1300. val64);
  1301. val64 = readq(&vp_reg->vpath_genstats_count01);
  1302. hw_stats->vpath_genstats_count1 =
  1303. (u32)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT1(
  1304. val64);
  1305. val64 = readq(&vp_reg->vpath_genstats_count23);
  1306. hw_stats->vpath_genstats_count2 =
  1307. (u32)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT2(
  1308. val64);
  1309. val64 = readq(&vp_reg->vpath_genstats_count01);
  1310. hw_stats->vpath_genstats_count3 =
  1311. (u32)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT3(
  1312. val64);
  1313. val64 = readq(&vp_reg->vpath_genstats_count4);
  1314. hw_stats->vpath_genstats_count4 =
  1315. (u32)VXGE_HW_VPATH_GENSTATS_COUNT4_GET_PPIF_VPATH_GENSTATS_COUNT4(
  1316. val64);
  1317. val64 = readq(&vp_reg->vpath_genstats_count5);
  1318. hw_stats->vpath_genstats_count5 =
  1319. (u32)VXGE_HW_VPATH_GENSTATS_COUNT5_GET_PPIF_VPATH_GENSTATS_COUNT5(
  1320. val64);
  1321. status = __vxge_hw_vpath_xmac_tx_stats_get(vpath, &hw_stats->tx_stats);
  1322. if (status != VXGE_HW_OK)
  1323. goto exit;
  1324. status = __vxge_hw_vpath_xmac_rx_stats_get(vpath, &hw_stats->rx_stats);
  1325. if (status != VXGE_HW_OK)
  1326. goto exit;
  1327. VXGE_HW_VPATH_STATS_PIO_READ(
  1328. VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM0_OFFSET);
  1329. hw_stats->prog_event_vnum0 =
  1330. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM0(val64);
  1331. hw_stats->prog_event_vnum1 =
  1332. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM1(val64);
  1333. VXGE_HW_VPATH_STATS_PIO_READ(
  1334. VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM2_OFFSET);
  1335. hw_stats->prog_event_vnum2 =
  1336. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM2(val64);
  1337. hw_stats->prog_event_vnum3 =
  1338. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM3(val64);
  1339. val64 = readq(&vp_reg->rx_multi_cast_stats);
  1340. hw_stats->rx_multi_cast_frame_discard =
  1341. (u16)VXGE_HW_RX_MULTI_CAST_STATS_GET_FRAME_DISCARD(val64);
  1342. val64 = readq(&vp_reg->rx_frm_transferred);
  1343. hw_stats->rx_frm_transferred =
  1344. (u32)VXGE_HW_RX_FRM_TRANSFERRED_GET_RX_FRM_TRANSFERRED(val64);
  1345. val64 = readq(&vp_reg->rxd_returned);
  1346. hw_stats->rxd_returned =
  1347. (u16)VXGE_HW_RXD_RETURNED_GET_RXD_RETURNED(val64);
  1348. val64 = readq(&vp_reg->dbg_stats_rx_mpa);
  1349. hw_stats->rx_mpa_len_fail_frms =
  1350. (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_LEN_FAIL_FRMS(val64);
  1351. hw_stats->rx_mpa_mrk_fail_frms =
  1352. (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_MRK_FAIL_FRMS(val64);
  1353. hw_stats->rx_mpa_crc_fail_frms =
  1354. (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_CRC_FAIL_FRMS(val64);
  1355. val64 = readq(&vp_reg->dbg_stats_rx_fau);
  1356. hw_stats->rx_permitted_frms =
  1357. (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_PERMITTED_FRMS(val64);
  1358. hw_stats->rx_vp_reset_discarded_frms =
  1359. (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_VP_RESET_DISCARDED_FRMS(val64);
  1360. hw_stats->rx_wol_frms =
  1361. (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_WOL_FRMS(val64);
  1362. val64 = readq(&vp_reg->tx_vp_reset_discarded_frms);
  1363. hw_stats->tx_vp_reset_discarded_frms =
  1364. (u16)VXGE_HW_TX_VP_RESET_DISCARDED_FRMS_GET_TX_VP_RESET_DISCARDED_FRMS(
  1365. val64);
  1366. exit:
  1367. return status;
  1368. }
  1369. /*
  1370. * vxge_hw_device_stats_get - Get the device hw statistics.
  1371. * Returns the vpath h/w stats for the device.
  1372. */
  1373. enum vxge_hw_status
  1374. vxge_hw_device_stats_get(struct __vxge_hw_device *hldev,
  1375. struct vxge_hw_device_stats_hw_info *hw_stats)
  1376. {
  1377. u32 i;
  1378. enum vxge_hw_status status = VXGE_HW_OK;
  1379. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1380. if (!(hldev->vpaths_deployed & vxge_mBIT(i)) ||
  1381. (hldev->virtual_paths[i].vp_open ==
  1382. VXGE_HW_VP_NOT_OPEN))
  1383. continue;
  1384. memcpy(hldev->virtual_paths[i].hw_stats_sav,
  1385. hldev->virtual_paths[i].hw_stats,
  1386. sizeof(struct vxge_hw_vpath_stats_hw_info));
  1387. status = __vxge_hw_vpath_stats_get(
  1388. &hldev->virtual_paths[i],
  1389. hldev->virtual_paths[i].hw_stats);
  1390. }
  1391. memcpy(hw_stats, &hldev->stats.hw_dev_info_stats,
  1392. sizeof(struct vxge_hw_device_stats_hw_info));
  1393. return status;
  1394. }
  1395. /*
  1396. * vxge_hw_driver_stats_get - Get the device sw statistics.
  1397. * Returns the vpath s/w stats for the device.
  1398. */
  1399. enum vxge_hw_status vxge_hw_driver_stats_get(
  1400. struct __vxge_hw_device *hldev,
  1401. struct vxge_hw_device_stats_sw_info *sw_stats)
  1402. {
  1403. memcpy(sw_stats, &hldev->stats.sw_dev_info_stats,
  1404. sizeof(struct vxge_hw_device_stats_sw_info));
  1405. return VXGE_HW_OK;
  1406. }
  1407. /*
  1408. * vxge_hw_mrpcim_stats_access - Access the statistics from the given location
  1409. * and offset and perform an operation
  1410. * Get the statistics from the given location and offset.
  1411. */
  1412. enum vxge_hw_status
  1413. vxge_hw_mrpcim_stats_access(struct __vxge_hw_device *hldev,
  1414. u32 operation, u32 location, u32 offset, u64 *stat)
  1415. {
  1416. u64 val64;
  1417. enum vxge_hw_status status = VXGE_HW_OK;
  1418. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1419. hldev->func_id);
  1420. if (status != VXGE_HW_OK)
  1421. goto exit;
  1422. val64 = VXGE_HW_XMAC_STATS_SYS_CMD_OP(operation) |
  1423. VXGE_HW_XMAC_STATS_SYS_CMD_STROBE |
  1424. VXGE_HW_XMAC_STATS_SYS_CMD_LOC_SEL(location) |
  1425. VXGE_HW_XMAC_STATS_SYS_CMD_OFFSET_SEL(offset);
  1426. status = __vxge_hw_pio_mem_write64(val64,
  1427. &hldev->mrpcim_reg->xmac_stats_sys_cmd,
  1428. VXGE_HW_XMAC_STATS_SYS_CMD_STROBE,
  1429. hldev->config.device_poll_millis);
  1430. if ((status == VXGE_HW_OK) && (operation == VXGE_HW_STATS_OP_READ))
  1431. *stat = readq(&hldev->mrpcim_reg->xmac_stats_sys_data);
  1432. else
  1433. *stat = 0;
  1434. exit:
  1435. return status;
  1436. }
  1437. /*
  1438. * vxge_hw_device_xmac_aggr_stats_get - Get the Statistics on aggregate port
  1439. * Get the Statistics on aggregate port
  1440. */
  1441. static enum vxge_hw_status
  1442. vxge_hw_device_xmac_aggr_stats_get(struct __vxge_hw_device *hldev, u32 port,
  1443. struct vxge_hw_xmac_aggr_stats *aggr_stats)
  1444. {
  1445. u64 *val64;
  1446. int i;
  1447. u32 offset = VXGE_HW_STATS_AGGRn_OFFSET;
  1448. enum vxge_hw_status status = VXGE_HW_OK;
  1449. val64 = (u64 *)aggr_stats;
  1450. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1451. hldev->func_id);
  1452. if (status != VXGE_HW_OK)
  1453. goto exit;
  1454. for (i = 0; i < sizeof(struct vxge_hw_xmac_aggr_stats) / 8; i++) {
  1455. status = vxge_hw_mrpcim_stats_access(hldev,
  1456. VXGE_HW_STATS_OP_READ,
  1457. VXGE_HW_STATS_LOC_AGGR,
  1458. ((offset + (104 * port)) >> 3), val64);
  1459. if (status != VXGE_HW_OK)
  1460. goto exit;
  1461. offset += 8;
  1462. val64++;
  1463. }
  1464. exit:
  1465. return status;
  1466. }
  1467. /*
  1468. * vxge_hw_device_xmac_port_stats_get - Get the Statistics on a port
  1469. * Get the Statistics on port
  1470. */
  1471. static enum vxge_hw_status
  1472. vxge_hw_device_xmac_port_stats_get(struct __vxge_hw_device *hldev, u32 port,
  1473. struct vxge_hw_xmac_port_stats *port_stats)
  1474. {
  1475. u64 *val64;
  1476. enum vxge_hw_status status = VXGE_HW_OK;
  1477. int i;
  1478. u32 offset = 0x0;
  1479. val64 = (u64 *) port_stats;
  1480. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1481. hldev->func_id);
  1482. if (status != VXGE_HW_OK)
  1483. goto exit;
  1484. for (i = 0; i < sizeof(struct vxge_hw_xmac_port_stats) / 8; i++) {
  1485. status = vxge_hw_mrpcim_stats_access(hldev,
  1486. VXGE_HW_STATS_OP_READ,
  1487. VXGE_HW_STATS_LOC_AGGR,
  1488. ((offset + (608 * port)) >> 3), val64);
  1489. if (status != VXGE_HW_OK)
  1490. goto exit;
  1491. offset += 8;
  1492. val64++;
  1493. }
  1494. exit:
  1495. return status;
  1496. }
  1497. /*
  1498. * vxge_hw_device_xmac_stats_get - Get the XMAC Statistics
  1499. * Get the XMAC Statistics
  1500. */
  1501. enum vxge_hw_status
  1502. vxge_hw_device_xmac_stats_get(struct __vxge_hw_device *hldev,
  1503. struct vxge_hw_xmac_stats *xmac_stats)
  1504. {
  1505. enum vxge_hw_status status = VXGE_HW_OK;
  1506. u32 i;
  1507. status = vxge_hw_device_xmac_aggr_stats_get(hldev,
  1508. 0, &xmac_stats->aggr_stats[0]);
  1509. if (status != VXGE_HW_OK)
  1510. goto exit;
  1511. status = vxge_hw_device_xmac_aggr_stats_get(hldev,
  1512. 1, &xmac_stats->aggr_stats[1]);
  1513. if (status != VXGE_HW_OK)
  1514. goto exit;
  1515. for (i = 0; i <= VXGE_HW_MAC_MAX_MAC_PORT_ID; i++) {
  1516. status = vxge_hw_device_xmac_port_stats_get(hldev,
  1517. i, &xmac_stats->port_stats[i]);
  1518. if (status != VXGE_HW_OK)
  1519. goto exit;
  1520. }
  1521. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1522. if (!(hldev->vpaths_deployed & vxge_mBIT(i)))
  1523. continue;
  1524. status = __vxge_hw_vpath_xmac_tx_stats_get(
  1525. &hldev->virtual_paths[i],
  1526. &xmac_stats->vpath_tx_stats[i]);
  1527. if (status != VXGE_HW_OK)
  1528. goto exit;
  1529. status = __vxge_hw_vpath_xmac_rx_stats_get(
  1530. &hldev->virtual_paths[i],
  1531. &xmac_stats->vpath_rx_stats[i]);
  1532. if (status != VXGE_HW_OK)
  1533. goto exit;
  1534. }
  1535. exit:
  1536. return status;
  1537. }
  1538. /*
  1539. * vxge_hw_device_debug_set - Set the debug module, level and timestamp
  1540. * This routine is used to dynamically change the debug output
  1541. */
  1542. void vxge_hw_device_debug_set(struct __vxge_hw_device *hldev,
  1543. enum vxge_debug_level level, u32 mask)
  1544. {
  1545. if (hldev == NULL)
  1546. return;
  1547. #if defined(VXGE_DEBUG_TRACE_MASK) || \
  1548. defined(VXGE_DEBUG_ERR_MASK)
  1549. hldev->debug_module_mask = mask;
  1550. hldev->debug_level = level;
  1551. #endif
  1552. #if defined(VXGE_DEBUG_ERR_MASK)
  1553. hldev->level_err = level & VXGE_ERR;
  1554. #endif
  1555. #if defined(VXGE_DEBUG_TRACE_MASK)
  1556. hldev->level_trace = level & VXGE_TRACE;
  1557. #endif
  1558. }
  1559. /*
  1560. * vxge_hw_device_error_level_get - Get the error level
  1561. * This routine returns the current error level set
  1562. */
  1563. u32 vxge_hw_device_error_level_get(struct __vxge_hw_device *hldev)
  1564. {
  1565. #if defined(VXGE_DEBUG_ERR_MASK)
  1566. if (hldev == NULL)
  1567. return VXGE_ERR;
  1568. else
  1569. return hldev->level_err;
  1570. #else
  1571. return 0;
  1572. #endif
  1573. }
  1574. /*
  1575. * vxge_hw_device_trace_level_get - Get the trace level
  1576. * This routine returns the current trace level set
  1577. */
  1578. u32 vxge_hw_device_trace_level_get(struct __vxge_hw_device *hldev)
  1579. {
  1580. #if defined(VXGE_DEBUG_TRACE_MASK)
  1581. if (hldev == NULL)
  1582. return VXGE_TRACE;
  1583. else
  1584. return hldev->level_trace;
  1585. #else
  1586. return 0;
  1587. #endif
  1588. }
  1589. /*
  1590. * vxge_hw_getpause_data -Pause frame frame generation and reception.
  1591. * Returns the Pause frame generation and reception capability of the NIC.
  1592. */
  1593. enum vxge_hw_status vxge_hw_device_getpause_data(struct __vxge_hw_device *hldev,
  1594. u32 port, u32 *tx, u32 *rx)
  1595. {
  1596. u64 val64;
  1597. enum vxge_hw_status status = VXGE_HW_OK;
  1598. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  1599. status = VXGE_HW_ERR_INVALID_DEVICE;
  1600. goto exit;
  1601. }
  1602. if (port > VXGE_HW_MAC_MAX_MAC_PORT_ID) {
  1603. status = VXGE_HW_ERR_INVALID_PORT;
  1604. goto exit;
  1605. }
  1606. if (!(hldev->access_rights & VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) {
  1607. status = VXGE_HW_ERR_PRIVILEGED_OPERATION;
  1608. goto exit;
  1609. }
  1610. val64 = readq(&hldev->mrpcim_reg->rxmac_pause_cfg_port[port]);
  1611. if (val64 & VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN)
  1612. *tx = 1;
  1613. if (val64 & VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN)
  1614. *rx = 1;
  1615. exit:
  1616. return status;
  1617. }
  1618. /*
  1619. * vxge_hw_device_setpause_data - set/reset pause frame generation.
  1620. * It can be used to set or reset Pause frame generation or reception
  1621. * support of the NIC.
  1622. */
  1623. enum vxge_hw_status vxge_hw_device_setpause_data(struct __vxge_hw_device *hldev,
  1624. u32 port, u32 tx, u32 rx)
  1625. {
  1626. u64 val64;
  1627. enum vxge_hw_status status = VXGE_HW_OK;
  1628. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  1629. status = VXGE_HW_ERR_INVALID_DEVICE;
  1630. goto exit;
  1631. }
  1632. if (port > VXGE_HW_MAC_MAX_MAC_PORT_ID) {
  1633. status = VXGE_HW_ERR_INVALID_PORT;
  1634. goto exit;
  1635. }
  1636. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1637. hldev->func_id);
  1638. if (status != VXGE_HW_OK)
  1639. goto exit;
  1640. val64 = readq(&hldev->mrpcim_reg->rxmac_pause_cfg_port[port]);
  1641. if (tx)
  1642. val64 |= VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN;
  1643. else
  1644. val64 &= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN;
  1645. if (rx)
  1646. val64 |= VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN;
  1647. else
  1648. val64 &= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN;
  1649. writeq(val64, &hldev->mrpcim_reg->rxmac_pause_cfg_port[port]);
  1650. exit:
  1651. return status;
  1652. }
  1653. u16 vxge_hw_device_link_width_get(struct __vxge_hw_device *hldev)
  1654. {
  1655. struct pci_dev *dev = hldev->pdev;
  1656. u16 lnk;
  1657. pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnk);
  1658. return (lnk & VXGE_HW_PCI_EXP_LNKCAP_LNK_WIDTH) >> 4;
  1659. }
  1660. /*
  1661. * __vxge_hw_ring_block_memblock_idx - Return the memblock index
  1662. * This function returns the index of memory block
  1663. */
  1664. static inline u32
  1665. __vxge_hw_ring_block_memblock_idx(u8 *block)
  1666. {
  1667. return (u32)*((u64 *)(block + VXGE_HW_RING_MEMBLOCK_IDX_OFFSET));
  1668. }
  1669. /*
  1670. * __vxge_hw_ring_block_memblock_idx_set - Sets the memblock index
  1671. * This function sets index to a memory block
  1672. */
  1673. static inline void
  1674. __vxge_hw_ring_block_memblock_idx_set(u8 *block, u32 memblock_idx)
  1675. {
  1676. *((u64 *)(block + VXGE_HW_RING_MEMBLOCK_IDX_OFFSET)) = memblock_idx;
  1677. }
  1678. /*
  1679. * __vxge_hw_ring_block_next_pointer_set - Sets the next block pointer
  1680. * in RxD block
  1681. * Sets the next block pointer in RxD block
  1682. */
  1683. static inline void
  1684. __vxge_hw_ring_block_next_pointer_set(u8 *block, dma_addr_t dma_next)
  1685. {
  1686. *((u64 *)(block + VXGE_HW_RING_NEXT_BLOCK_POINTER_OFFSET)) = dma_next;
  1687. }
  1688. /*
  1689. * __vxge_hw_ring_first_block_address_get - Returns the dma address of the
  1690. * first block
  1691. * Returns the dma address of the first RxD block
  1692. */
  1693. static u64 __vxge_hw_ring_first_block_address_get(struct __vxge_hw_ring *ring)
  1694. {
  1695. struct vxge_hw_mempool_dma *dma_object;
  1696. dma_object = ring->mempool->memblocks_dma_arr;
  1697. vxge_assert(dma_object != NULL);
  1698. return dma_object->addr;
  1699. }
  1700. /*
  1701. * __vxge_hw_ring_item_dma_addr - Return the dma address of an item
  1702. * This function returns the dma address of a given item
  1703. */
  1704. static dma_addr_t __vxge_hw_ring_item_dma_addr(struct vxge_hw_mempool *mempoolh,
  1705. void *item)
  1706. {
  1707. u32 memblock_idx;
  1708. void *memblock;
  1709. struct vxge_hw_mempool_dma *memblock_dma_object;
  1710. ptrdiff_t dma_item_offset;
  1711. /* get owner memblock index */
  1712. memblock_idx = __vxge_hw_ring_block_memblock_idx(item);
  1713. /* get owner memblock by memblock index */
  1714. memblock = mempoolh->memblocks_arr[memblock_idx];
  1715. /* get memblock DMA object by memblock index */
  1716. memblock_dma_object = mempoolh->memblocks_dma_arr + memblock_idx;
  1717. /* calculate offset in the memblock of this item */
  1718. dma_item_offset = (u8 *)item - (u8 *)memblock;
  1719. return memblock_dma_object->addr + dma_item_offset;
  1720. }
  1721. /*
  1722. * __vxge_hw_ring_rxdblock_link - Link the RxD blocks
  1723. * This function returns the dma address of a given item
  1724. */
  1725. static void __vxge_hw_ring_rxdblock_link(struct vxge_hw_mempool *mempoolh,
  1726. struct __vxge_hw_ring *ring, u32 from,
  1727. u32 to)
  1728. {
  1729. u8 *to_item , *from_item;
  1730. dma_addr_t to_dma;
  1731. /* get "from" RxD block */
  1732. from_item = mempoolh->items_arr[from];
  1733. vxge_assert(from_item);
  1734. /* get "to" RxD block */
  1735. to_item = mempoolh->items_arr[to];
  1736. vxge_assert(to_item);
  1737. /* return address of the beginning of previous RxD block */
  1738. to_dma = __vxge_hw_ring_item_dma_addr(mempoolh, to_item);
  1739. /* set next pointer for this RxD block to point on
  1740. * previous item's DMA start address */
  1741. __vxge_hw_ring_block_next_pointer_set(from_item, to_dma);
  1742. }
  1743. /*
  1744. * __vxge_hw_ring_mempool_item_alloc - Allocate List blocks for RxD
  1745. * block callback
  1746. * This function is callback passed to __vxge_hw_mempool_create to create memory
  1747. * pool for RxD block
  1748. */
  1749. static void
  1750. __vxge_hw_ring_mempool_item_alloc(struct vxge_hw_mempool *mempoolh,
  1751. u32 memblock_index,
  1752. struct vxge_hw_mempool_dma *dma_object,
  1753. u32 index, u32 is_last)
  1754. {
  1755. u32 i;
  1756. void *item = mempoolh->items_arr[index];
  1757. struct __vxge_hw_ring *ring =
  1758. (struct __vxge_hw_ring *)mempoolh->userdata;
  1759. /* format rxds array */
  1760. for (i = 0; i < ring->rxds_per_block; i++) {
  1761. void *rxdblock_priv;
  1762. void *uld_priv;
  1763. struct vxge_hw_ring_rxd_1 *rxdp;
  1764. u32 reserve_index = ring->channel.reserve_ptr -
  1765. (index * ring->rxds_per_block + i + 1);
  1766. u32 memblock_item_idx;
  1767. ring->channel.reserve_arr[reserve_index] = ((u8 *)item) +
  1768. i * ring->rxd_size;
  1769. /* Note: memblock_item_idx is index of the item within
  1770. * the memblock. For instance, in case of three RxD-blocks
  1771. * per memblock this value can be 0, 1 or 2. */
  1772. rxdblock_priv = __vxge_hw_mempool_item_priv(mempoolh,
  1773. memblock_index, item,
  1774. &memblock_item_idx);
  1775. rxdp = ring->channel.reserve_arr[reserve_index];
  1776. uld_priv = ((u8 *)rxdblock_priv + ring->rxd_priv_size * i);
  1777. /* pre-format Host_Control */
  1778. rxdp->host_control = (u64)(size_t)uld_priv;
  1779. }
  1780. __vxge_hw_ring_block_memblock_idx_set(item, memblock_index);
  1781. if (is_last) {
  1782. /* link last one with first one */
  1783. __vxge_hw_ring_rxdblock_link(mempoolh, ring, index, 0);
  1784. }
  1785. if (index > 0) {
  1786. /* link this RxD block with previous one */
  1787. __vxge_hw_ring_rxdblock_link(mempoolh, ring, index - 1, index);
  1788. }
  1789. }
  1790. /*
  1791. * __vxge_hw_ring_replenish - Initial replenish of RxDs
  1792. * This function replenishes the RxDs from reserve array to work array
  1793. */
  1794. static enum vxge_hw_status
  1795. vxge_hw_ring_replenish(struct __vxge_hw_ring *ring)
  1796. {
  1797. void *rxd;
  1798. struct __vxge_hw_channel *channel;
  1799. enum vxge_hw_status status = VXGE_HW_OK;
  1800. channel = &ring->channel;
  1801. while (vxge_hw_channel_dtr_count(channel) > 0) {
  1802. status = vxge_hw_ring_rxd_reserve(ring, &rxd);
  1803. vxge_assert(status == VXGE_HW_OK);
  1804. if (ring->rxd_init) {
  1805. status = ring->rxd_init(rxd, channel->userdata);
  1806. if (status != VXGE_HW_OK) {
  1807. vxge_hw_ring_rxd_free(ring, rxd);
  1808. goto exit;
  1809. }
  1810. }
  1811. vxge_hw_ring_rxd_post(ring, rxd);
  1812. }
  1813. status = VXGE_HW_OK;
  1814. exit:
  1815. return status;
  1816. }
  1817. /*
  1818. * __vxge_hw_channel_allocate - Allocate memory for channel
  1819. * This function allocates required memory for the channel and various arrays
  1820. * in the channel
  1821. */
  1822. static struct __vxge_hw_channel *
  1823. __vxge_hw_channel_allocate(struct __vxge_hw_vpath_handle *vph,
  1824. enum __vxge_hw_channel_type type,
  1825. u32 length, u32 per_dtr_space,
  1826. void *userdata)
  1827. {
  1828. struct __vxge_hw_channel *channel;
  1829. struct __vxge_hw_device *hldev;
  1830. int size = 0;
  1831. u32 vp_id;
  1832. hldev = vph->vpath->hldev;
  1833. vp_id = vph->vpath->vp_id;
  1834. switch (type) {
  1835. case VXGE_HW_CHANNEL_TYPE_FIFO:
  1836. size = sizeof(struct __vxge_hw_fifo);
  1837. break;
  1838. case VXGE_HW_CHANNEL_TYPE_RING:
  1839. size = sizeof(struct __vxge_hw_ring);
  1840. break;
  1841. default:
  1842. break;
  1843. }
  1844. channel = kzalloc(size, GFP_KERNEL);
  1845. if (channel == NULL)
  1846. goto exit0;
  1847. INIT_LIST_HEAD(&channel->item);
  1848. channel->common_reg = hldev->common_reg;
  1849. channel->first_vp_id = hldev->first_vp_id;
  1850. channel->type = type;
  1851. channel->devh = hldev;
  1852. channel->vph = vph;
  1853. channel->userdata = userdata;
  1854. channel->per_dtr_space = per_dtr_space;
  1855. channel->length = length;
  1856. channel->vp_id = vp_id;
  1857. channel->work_arr = kcalloc(length, sizeof(void *), GFP_KERNEL);
  1858. if (channel->work_arr == NULL)
  1859. goto exit1;
  1860. channel->free_arr = kcalloc(length, sizeof(void *), GFP_KERNEL);
  1861. if (channel->free_arr == NULL)
  1862. goto exit1;
  1863. channel->free_ptr = length;
  1864. channel->reserve_arr = kcalloc(length, sizeof(void *), GFP_KERNEL);
  1865. if (channel->reserve_arr == NULL)
  1866. goto exit1;
  1867. channel->reserve_ptr = length;
  1868. channel->reserve_top = 0;
  1869. channel->orig_arr = kcalloc(length, sizeof(void *), GFP_KERNEL);
  1870. if (channel->orig_arr == NULL)
  1871. goto exit1;
  1872. return channel;
  1873. exit1:
  1874. __vxge_hw_channel_free(channel);
  1875. exit0:
  1876. return NULL;
  1877. }
  1878. /*
  1879. * vxge_hw_blockpool_block_add - callback for vxge_os_dma_malloc_async
  1880. * Adds a block to block pool
  1881. */
  1882. static void vxge_hw_blockpool_block_add(struct __vxge_hw_device *devh,
  1883. void *block_addr,
  1884. u32 length,
  1885. struct pci_dev *dma_h,
  1886. struct pci_dev *acc_handle)
  1887. {
  1888. struct __vxge_hw_blockpool *blockpool;
  1889. struct __vxge_hw_blockpool_entry *entry = NULL;
  1890. dma_addr_t dma_addr;
  1891. blockpool = &devh->block_pool;
  1892. if (block_addr == NULL) {
  1893. blockpool->req_out--;
  1894. goto exit;
  1895. }
  1896. dma_addr = pci_map_single(devh->pdev, block_addr, length,
  1897. PCI_DMA_BIDIRECTIONAL);
  1898. if (unlikely(pci_dma_mapping_error(devh->pdev, dma_addr))) {
  1899. vxge_os_dma_free(devh->pdev, block_addr, &acc_handle);
  1900. blockpool->req_out--;
  1901. goto exit;
  1902. }
  1903. if (!list_empty(&blockpool->free_entry_list))
  1904. entry = (struct __vxge_hw_blockpool_entry *)
  1905. list_first_entry(&blockpool->free_entry_list,
  1906. struct __vxge_hw_blockpool_entry,
  1907. item);
  1908. if (entry == NULL)
  1909. entry = vmalloc(sizeof(struct __vxge_hw_blockpool_entry));
  1910. else
  1911. list_del(&entry->item);
  1912. if (entry) {
  1913. entry->length = length;
  1914. entry->memblock = block_addr;
  1915. entry->dma_addr = dma_addr;
  1916. entry->acc_handle = acc_handle;
  1917. entry->dma_handle = dma_h;
  1918. list_add(&entry->item, &blockpool->free_block_list);
  1919. blockpool->pool_size++;
  1920. }
  1921. blockpool->req_out--;
  1922. exit:
  1923. return;
  1924. }
  1925. static inline void
  1926. vxge_os_dma_malloc_async(struct pci_dev *pdev, void *devh, unsigned long size)
  1927. {
  1928. gfp_t flags;
  1929. void *vaddr;
  1930. if (in_interrupt())
  1931. flags = GFP_ATOMIC | GFP_DMA;
  1932. else
  1933. flags = GFP_KERNEL | GFP_DMA;
  1934. vaddr = kmalloc((size), flags);
  1935. vxge_hw_blockpool_block_add(devh, vaddr, size, pdev, pdev);
  1936. }
  1937. /*
  1938. * __vxge_hw_blockpool_blocks_add - Request additional blocks
  1939. */
  1940. static
  1941. void __vxge_hw_blockpool_blocks_add(struct __vxge_hw_blockpool *blockpool)
  1942. {
  1943. u32 nreq = 0, i;
  1944. if ((blockpool->pool_size + blockpool->req_out) <
  1945. VXGE_HW_MIN_DMA_BLOCK_POOL_SIZE) {
  1946. nreq = VXGE_HW_INCR_DMA_BLOCK_POOL_SIZE;
  1947. blockpool->req_out += nreq;
  1948. }
  1949. for (i = 0; i < nreq; i++)
  1950. vxge_os_dma_malloc_async(
  1951. (blockpool->hldev)->pdev,
  1952. blockpool->hldev, VXGE_HW_BLOCK_SIZE);
  1953. }
  1954. /*
  1955. * __vxge_hw_blockpool_malloc - Allocate a memory block from pool
  1956. * Allocates a block of memory of given size, either from block pool
  1957. * or by calling vxge_os_dma_malloc()
  1958. */
  1959. static void *__vxge_hw_blockpool_malloc(struct __vxge_hw_device *devh, u32 size,
  1960. struct vxge_hw_mempool_dma *dma_object)
  1961. {
  1962. struct __vxge_hw_blockpool_entry *entry = NULL;
  1963. struct __vxge_hw_blockpool *blockpool;
  1964. void *memblock = NULL;
  1965. blockpool = &devh->block_pool;
  1966. if (size != blockpool->block_size) {
  1967. memblock = vxge_os_dma_malloc(devh->pdev, size,
  1968. &dma_object->handle,
  1969. &dma_object->acc_handle);
  1970. if (!memblock)
  1971. goto exit;
  1972. dma_object->addr = pci_map_single(devh->pdev, memblock, size,
  1973. PCI_DMA_BIDIRECTIONAL);
  1974. if (unlikely(pci_dma_mapping_error(devh->pdev,
  1975. dma_object->addr))) {
  1976. vxge_os_dma_free(devh->pdev, memblock,
  1977. &dma_object->acc_handle);
  1978. memblock = NULL;
  1979. goto exit;
  1980. }
  1981. } else {
  1982. if (!list_empty(&blockpool->free_block_list))
  1983. entry = (struct __vxge_hw_blockpool_entry *)
  1984. list_first_entry(&blockpool->free_block_list,
  1985. struct __vxge_hw_blockpool_entry,
  1986. item);
  1987. if (entry != NULL) {
  1988. list_del(&entry->item);
  1989. dma_object->addr = entry->dma_addr;
  1990. dma_object->handle = entry->dma_handle;
  1991. dma_object->acc_handle = entry->acc_handle;
  1992. memblock = entry->memblock;
  1993. list_add(&entry->item,
  1994. &blockpool->free_entry_list);
  1995. blockpool->pool_size--;
  1996. }
  1997. if (memblock != NULL)
  1998. __vxge_hw_blockpool_blocks_add(blockpool);
  1999. }
  2000. exit:
  2001. return memblock;
  2002. }
  2003. /*
  2004. * __vxge_hw_blockpool_blocks_remove - Free additional blocks
  2005. */
  2006. static void
  2007. __vxge_hw_blockpool_blocks_remove(struct __vxge_hw_blockpool *blockpool)
  2008. {
  2009. struct list_head *p, *n;
  2010. list_for_each_safe(p, n, &blockpool->free_block_list) {
  2011. if (blockpool->pool_size < blockpool->pool_max)
  2012. break;
  2013. pci_unmap_single(
  2014. (blockpool->hldev)->pdev,
  2015. ((struct __vxge_hw_blockpool_entry *)p)->dma_addr,
  2016. ((struct __vxge_hw_blockpool_entry *)p)->length,
  2017. PCI_DMA_BIDIRECTIONAL);
  2018. vxge_os_dma_free(
  2019. (blockpool->hldev)->pdev,
  2020. ((struct __vxge_hw_blockpool_entry *)p)->memblock,
  2021. &((struct __vxge_hw_blockpool_entry *)p)->acc_handle);
  2022. list_del(&((struct __vxge_hw_blockpool_entry *)p)->item);
  2023. list_add(p, &blockpool->free_entry_list);
  2024. blockpool->pool_size--;
  2025. }
  2026. }
  2027. /*
  2028. * __vxge_hw_blockpool_free - Frees the memory allcoated with
  2029. * __vxge_hw_blockpool_malloc
  2030. */
  2031. static void __vxge_hw_blockpool_free(struct __vxge_hw_device *devh,
  2032. void *memblock, u32 size,
  2033. struct vxge_hw_mempool_dma *dma_object)
  2034. {
  2035. struct __vxge_hw_blockpool_entry *entry = NULL;
  2036. struct __vxge_hw_blockpool *blockpool;
  2037. enum vxge_hw_status status = VXGE_HW_OK;
  2038. blockpool = &devh->block_pool;
  2039. if (size != blockpool->block_size) {
  2040. pci_unmap_single(devh->pdev, dma_object->addr, size,
  2041. PCI_DMA_BIDIRECTIONAL);
  2042. vxge_os_dma_free(devh->pdev, memblock, &dma_object->acc_handle);
  2043. } else {
  2044. if (!list_empty(&blockpool->free_entry_list))
  2045. entry = (struct __vxge_hw_blockpool_entry *)
  2046. list_first_entry(&blockpool->free_entry_list,
  2047. struct __vxge_hw_blockpool_entry,
  2048. item);
  2049. if (entry == NULL)
  2050. entry = vmalloc(sizeof(
  2051. struct __vxge_hw_blockpool_entry));
  2052. else
  2053. list_del(&entry->item);
  2054. if (entry != NULL) {
  2055. entry->length = size;
  2056. entry->memblock = memblock;
  2057. entry->dma_addr = dma_object->addr;
  2058. entry->acc_handle = dma_object->acc_handle;
  2059. entry->dma_handle = dma_object->handle;
  2060. list_add(&entry->item,
  2061. &blockpool->free_block_list);
  2062. blockpool->pool_size++;
  2063. status = VXGE_HW_OK;
  2064. } else
  2065. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2066. if (status == VXGE_HW_OK)
  2067. __vxge_hw_blockpool_blocks_remove(blockpool);
  2068. }
  2069. }
  2070. /*
  2071. * vxge_hw_mempool_destroy
  2072. */
  2073. static void __vxge_hw_mempool_destroy(struct vxge_hw_mempool *mempool)
  2074. {
  2075. u32 i, j;
  2076. struct __vxge_hw_device *devh = mempool->devh;
  2077. for (i = 0; i < mempool->memblocks_allocated; i++) {
  2078. struct vxge_hw_mempool_dma *dma_object;
  2079. vxge_assert(mempool->memblocks_arr[i]);
  2080. vxge_assert(mempool->memblocks_dma_arr + i);
  2081. dma_object = mempool->memblocks_dma_arr + i;
  2082. for (j = 0; j < mempool->items_per_memblock; j++) {
  2083. u32 index = i * mempool->items_per_memblock + j;
  2084. /* to skip last partially filled(if any) memblock */
  2085. if (index >= mempool->items_current)
  2086. break;
  2087. }
  2088. vfree(mempool->memblocks_priv_arr[i]);
  2089. __vxge_hw_blockpool_free(devh, mempool->memblocks_arr[i],
  2090. mempool->memblock_size, dma_object);
  2091. }
  2092. vfree(mempool->items_arr);
  2093. vfree(mempool->memblocks_dma_arr);
  2094. vfree(mempool->memblocks_priv_arr);
  2095. vfree(mempool->memblocks_arr);
  2096. vfree(mempool);
  2097. }
  2098. /*
  2099. * __vxge_hw_mempool_grow
  2100. * Will resize mempool up to %num_allocate value.
  2101. */
  2102. static enum vxge_hw_status
  2103. __vxge_hw_mempool_grow(struct vxge_hw_mempool *mempool, u32 num_allocate,
  2104. u32 *num_allocated)
  2105. {
  2106. u32 i, first_time = mempool->memblocks_allocated == 0 ? 1 : 0;
  2107. u32 n_items = mempool->items_per_memblock;
  2108. u32 start_block_idx = mempool->memblocks_allocated;
  2109. u32 end_block_idx = mempool->memblocks_allocated + num_allocate;
  2110. enum vxge_hw_status status = VXGE_HW_OK;
  2111. *num_allocated = 0;
  2112. if (end_block_idx > mempool->memblocks_max) {
  2113. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2114. goto exit;
  2115. }
  2116. for (i = start_block_idx; i < end_block_idx; i++) {
  2117. u32 j;
  2118. u32 is_last = ((end_block_idx - 1) == i);
  2119. struct vxge_hw_mempool_dma *dma_object =
  2120. mempool->memblocks_dma_arr + i;
  2121. void *the_memblock;
  2122. /* allocate memblock's private part. Each DMA memblock
  2123. * has a space allocated for item's private usage upon
  2124. * mempool's user request. Each time mempool grows, it will
  2125. * allocate new memblock and its private part at once.
  2126. * This helps to minimize memory usage a lot. */
  2127. mempool->memblocks_priv_arr[i] =
  2128. vzalloc(array_size(mempool->items_priv_size, n_items));
  2129. if (mempool->memblocks_priv_arr[i] == NULL) {
  2130. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2131. goto exit;
  2132. }
  2133. /* allocate DMA-capable memblock */
  2134. mempool->memblocks_arr[i] =
  2135. __vxge_hw_blockpool_malloc(mempool->devh,
  2136. mempool->memblock_size, dma_object);
  2137. if (mempool->memblocks_arr[i] == NULL) {
  2138. vfree(mempool->memblocks_priv_arr[i]);
  2139. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2140. goto exit;
  2141. }
  2142. (*num_allocated)++;
  2143. mempool->memblocks_allocated++;
  2144. memset(mempool->memblocks_arr[i], 0, mempool->memblock_size);
  2145. the_memblock = mempool->memblocks_arr[i];
  2146. /* fill the items hash array */
  2147. for (j = 0; j < n_items; j++) {
  2148. u32 index = i * n_items + j;
  2149. if (first_time && index >= mempool->items_initial)
  2150. break;
  2151. mempool->items_arr[index] =
  2152. ((char *)the_memblock + j*mempool->item_size);
  2153. /* let caller to do more job on each item */
  2154. if (mempool->item_func_alloc != NULL)
  2155. mempool->item_func_alloc(mempool, i,
  2156. dma_object, index, is_last);
  2157. mempool->items_current = index + 1;
  2158. }
  2159. if (first_time && mempool->items_current ==
  2160. mempool->items_initial)
  2161. break;
  2162. }
  2163. exit:
  2164. return status;
  2165. }
  2166. /*
  2167. * vxge_hw_mempool_create
  2168. * This function will create memory pool object. Pool may grow but will
  2169. * never shrink. Pool consists of number of dynamically allocated blocks
  2170. * with size enough to hold %items_initial number of items. Memory is
  2171. * DMA-able but client must map/unmap before interoperating with the device.
  2172. */
  2173. static struct vxge_hw_mempool *
  2174. __vxge_hw_mempool_create(struct __vxge_hw_device *devh,
  2175. u32 memblock_size,
  2176. u32 item_size,
  2177. u32 items_priv_size,
  2178. u32 items_initial,
  2179. u32 items_max,
  2180. const struct vxge_hw_mempool_cbs *mp_callback,
  2181. void *userdata)
  2182. {
  2183. enum vxge_hw_status status = VXGE_HW_OK;
  2184. u32 memblocks_to_allocate;
  2185. struct vxge_hw_mempool *mempool = NULL;
  2186. u32 allocated;
  2187. if (memblock_size < item_size) {
  2188. status = VXGE_HW_FAIL;
  2189. goto exit;
  2190. }
  2191. mempool = vzalloc(sizeof(struct vxge_hw_mempool));
  2192. if (mempool == NULL) {
  2193. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2194. goto exit;
  2195. }
  2196. mempool->devh = devh;
  2197. mempool->memblock_size = memblock_size;
  2198. mempool->items_max = items_max;
  2199. mempool->items_initial = items_initial;
  2200. mempool->item_size = item_size;
  2201. mempool->items_priv_size = items_priv_size;
  2202. mempool->item_func_alloc = mp_callback->item_func_alloc;
  2203. mempool->userdata = userdata;
  2204. mempool->memblocks_allocated = 0;
  2205. mempool->items_per_memblock = memblock_size / item_size;
  2206. mempool->memblocks_max = (items_max + mempool->items_per_memblock - 1) /
  2207. mempool->items_per_memblock;
  2208. /* allocate array of memblocks */
  2209. mempool->memblocks_arr =
  2210. vzalloc(array_size(sizeof(void *), mempool->memblocks_max));
  2211. if (mempool->memblocks_arr == NULL) {
  2212. __vxge_hw_mempool_destroy(mempool);
  2213. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2214. mempool = NULL;
  2215. goto exit;
  2216. }
  2217. /* allocate array of private parts of items per memblocks */
  2218. mempool->memblocks_priv_arr =
  2219. vzalloc(array_size(sizeof(void *), mempool->memblocks_max));
  2220. if (mempool->memblocks_priv_arr == NULL) {
  2221. __vxge_hw_mempool_destroy(mempool);
  2222. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2223. mempool = NULL;
  2224. goto exit;
  2225. }
  2226. /* allocate array of memblocks DMA objects */
  2227. mempool->memblocks_dma_arr =
  2228. vzalloc(array_size(sizeof(struct vxge_hw_mempool_dma),
  2229. mempool->memblocks_max));
  2230. if (mempool->memblocks_dma_arr == NULL) {
  2231. __vxge_hw_mempool_destroy(mempool);
  2232. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2233. mempool = NULL;
  2234. goto exit;
  2235. }
  2236. /* allocate hash array of items */
  2237. mempool->items_arr = vzalloc(array_size(sizeof(void *),
  2238. mempool->items_max));
  2239. if (mempool->items_arr == NULL) {
  2240. __vxge_hw_mempool_destroy(mempool);
  2241. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2242. mempool = NULL;
  2243. goto exit;
  2244. }
  2245. /* calculate initial number of memblocks */
  2246. memblocks_to_allocate = (mempool->items_initial +
  2247. mempool->items_per_memblock - 1) /
  2248. mempool->items_per_memblock;
  2249. /* pre-allocate the mempool */
  2250. status = __vxge_hw_mempool_grow(mempool, memblocks_to_allocate,
  2251. &allocated);
  2252. if (status != VXGE_HW_OK) {
  2253. __vxge_hw_mempool_destroy(mempool);
  2254. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2255. mempool = NULL;
  2256. goto exit;
  2257. }
  2258. exit:
  2259. return mempool;
  2260. }
  2261. /*
  2262. * __vxge_hw_ring_abort - Returns the RxD
  2263. * This function terminates the RxDs of ring
  2264. */
  2265. static enum vxge_hw_status __vxge_hw_ring_abort(struct __vxge_hw_ring *ring)
  2266. {
  2267. void *rxdh;
  2268. struct __vxge_hw_channel *channel;
  2269. channel = &ring->channel;
  2270. for (;;) {
  2271. vxge_hw_channel_dtr_try_complete(channel, &rxdh);
  2272. if (rxdh == NULL)
  2273. break;
  2274. vxge_hw_channel_dtr_complete(channel);
  2275. if (ring->rxd_term)
  2276. ring->rxd_term(rxdh, VXGE_HW_RXD_STATE_POSTED,
  2277. channel->userdata);
  2278. vxge_hw_channel_dtr_free(channel, rxdh);
  2279. }
  2280. return VXGE_HW_OK;
  2281. }
  2282. /*
  2283. * __vxge_hw_ring_reset - Resets the ring
  2284. * This function resets the ring during vpath reset operation
  2285. */
  2286. static enum vxge_hw_status __vxge_hw_ring_reset(struct __vxge_hw_ring *ring)
  2287. {
  2288. enum vxge_hw_status status = VXGE_HW_OK;
  2289. struct __vxge_hw_channel *channel;
  2290. channel = &ring->channel;
  2291. __vxge_hw_ring_abort(ring);
  2292. status = __vxge_hw_channel_reset(channel);
  2293. if (status != VXGE_HW_OK)
  2294. goto exit;
  2295. if (ring->rxd_init) {
  2296. status = vxge_hw_ring_replenish(ring);
  2297. if (status != VXGE_HW_OK)
  2298. goto exit;
  2299. }
  2300. exit:
  2301. return status;
  2302. }
  2303. /*
  2304. * __vxge_hw_ring_delete - Removes the ring
  2305. * This function freeup the memory pool and removes the ring
  2306. */
  2307. static enum vxge_hw_status
  2308. __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp)
  2309. {
  2310. struct __vxge_hw_ring *ring = vp->vpath->ringh;
  2311. __vxge_hw_ring_abort(ring);
  2312. if (ring->mempool)
  2313. __vxge_hw_mempool_destroy(ring->mempool);
  2314. vp->vpath->ringh = NULL;
  2315. __vxge_hw_channel_free(&ring->channel);
  2316. return VXGE_HW_OK;
  2317. }
  2318. /*
  2319. * __vxge_hw_ring_create - Create a Ring
  2320. * This function creates Ring and initializes it.
  2321. */
  2322. static enum vxge_hw_status
  2323. __vxge_hw_ring_create(struct __vxge_hw_vpath_handle *vp,
  2324. struct vxge_hw_ring_attr *attr)
  2325. {
  2326. enum vxge_hw_status status = VXGE_HW_OK;
  2327. struct __vxge_hw_ring *ring;
  2328. u32 ring_length;
  2329. struct vxge_hw_ring_config *config;
  2330. struct __vxge_hw_device *hldev;
  2331. u32 vp_id;
  2332. static const struct vxge_hw_mempool_cbs ring_mp_callback = {
  2333. .item_func_alloc = __vxge_hw_ring_mempool_item_alloc,
  2334. };
  2335. if ((vp == NULL) || (attr == NULL)) {
  2336. status = VXGE_HW_FAIL;
  2337. goto exit;
  2338. }
  2339. hldev = vp->vpath->hldev;
  2340. vp_id = vp->vpath->vp_id;
  2341. config = &hldev->config.vp_config[vp_id].ring;
  2342. ring_length = config->ring_blocks *
  2343. vxge_hw_ring_rxds_per_block_get(config->buffer_mode);
  2344. ring = (struct __vxge_hw_ring *)__vxge_hw_channel_allocate(vp,
  2345. VXGE_HW_CHANNEL_TYPE_RING,
  2346. ring_length,
  2347. attr->per_rxd_space,
  2348. attr->userdata);
  2349. if (ring == NULL) {
  2350. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2351. goto exit;
  2352. }
  2353. vp->vpath->ringh = ring;
  2354. ring->vp_id = vp_id;
  2355. ring->vp_reg = vp->vpath->vp_reg;
  2356. ring->common_reg = hldev->common_reg;
  2357. ring->stats = &vp->vpath->sw_stats->ring_stats;
  2358. ring->config = config;
  2359. ring->callback = attr->callback;
  2360. ring->rxd_init = attr->rxd_init;
  2361. ring->rxd_term = attr->rxd_term;
  2362. ring->buffer_mode = config->buffer_mode;
  2363. ring->tim_rti_cfg1_saved = vp->vpath->tim_rti_cfg1_saved;
  2364. ring->tim_rti_cfg3_saved = vp->vpath->tim_rti_cfg3_saved;
  2365. ring->rxds_limit = config->rxds_limit;
  2366. ring->rxd_size = vxge_hw_ring_rxd_size_get(config->buffer_mode);
  2367. ring->rxd_priv_size =
  2368. sizeof(struct __vxge_hw_ring_rxd_priv) + attr->per_rxd_space;
  2369. ring->per_rxd_space = attr->per_rxd_space;
  2370. ring->rxd_priv_size =
  2371. ((ring->rxd_priv_size + VXGE_CACHE_LINE_SIZE - 1) /
  2372. VXGE_CACHE_LINE_SIZE) * VXGE_CACHE_LINE_SIZE;
  2373. /* how many RxDs can fit into one block. Depends on configured
  2374. * buffer_mode. */
  2375. ring->rxds_per_block =
  2376. vxge_hw_ring_rxds_per_block_get(config->buffer_mode);
  2377. /* calculate actual RxD block private size */
  2378. ring->rxdblock_priv_size = ring->rxd_priv_size * ring->rxds_per_block;
  2379. ring->mempool = __vxge_hw_mempool_create(hldev,
  2380. VXGE_HW_BLOCK_SIZE,
  2381. VXGE_HW_BLOCK_SIZE,
  2382. ring->rxdblock_priv_size,
  2383. ring->config->ring_blocks,
  2384. ring->config->ring_blocks,
  2385. &ring_mp_callback,
  2386. ring);
  2387. if (ring->mempool == NULL) {
  2388. __vxge_hw_ring_delete(vp);
  2389. return VXGE_HW_ERR_OUT_OF_MEMORY;
  2390. }
  2391. status = __vxge_hw_channel_initialize(&ring->channel);
  2392. if (status != VXGE_HW_OK) {
  2393. __vxge_hw_ring_delete(vp);
  2394. goto exit;
  2395. }
  2396. /* Note:
  2397. * Specifying rxd_init callback means two things:
  2398. * 1) rxds need to be initialized by driver at channel-open time;
  2399. * 2) rxds need to be posted at channel-open time
  2400. * (that's what the initial_replenish() below does)
  2401. * Currently we don't have a case when the 1) is done without the 2).
  2402. */
  2403. if (ring->rxd_init) {
  2404. status = vxge_hw_ring_replenish(ring);
  2405. if (status != VXGE_HW_OK) {
  2406. __vxge_hw_ring_delete(vp);
  2407. goto exit;
  2408. }
  2409. }
  2410. /* initial replenish will increment the counter in its post() routine,
  2411. * we have to reset it */
  2412. ring->stats->common_stats.usage_cnt = 0;
  2413. exit:
  2414. return status;
  2415. }
  2416. /*
  2417. * vxge_hw_device_config_default_get - Initialize device config with defaults.
  2418. * Initialize Titan device config with default values.
  2419. */
  2420. enum vxge_hw_status
  2421. vxge_hw_device_config_default_get(struct vxge_hw_device_config *device_config)
  2422. {
  2423. u32 i;
  2424. device_config->dma_blockpool_initial =
  2425. VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
  2426. device_config->dma_blockpool_max = VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
  2427. device_config->intr_mode = VXGE_HW_INTR_MODE_DEF;
  2428. device_config->rth_en = VXGE_HW_RTH_DEFAULT;
  2429. device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_DEFAULT;
  2430. device_config->device_poll_millis = VXGE_HW_DEF_DEVICE_POLL_MILLIS;
  2431. device_config->rts_mac_en = VXGE_HW_RTS_MAC_DEFAULT;
  2432. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  2433. device_config->vp_config[i].vp_id = i;
  2434. device_config->vp_config[i].min_bandwidth =
  2435. VXGE_HW_VPATH_BANDWIDTH_DEFAULT;
  2436. device_config->vp_config[i].ring.enable = VXGE_HW_RING_DEFAULT;
  2437. device_config->vp_config[i].ring.ring_blocks =
  2438. VXGE_HW_DEF_RING_BLOCKS;
  2439. device_config->vp_config[i].ring.buffer_mode =
  2440. VXGE_HW_RING_RXD_BUFFER_MODE_DEFAULT;
  2441. device_config->vp_config[i].ring.scatter_mode =
  2442. VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT;
  2443. device_config->vp_config[i].ring.rxds_limit =
  2444. VXGE_HW_DEF_RING_RXDS_LIMIT;
  2445. device_config->vp_config[i].fifo.enable = VXGE_HW_FIFO_ENABLE;
  2446. device_config->vp_config[i].fifo.fifo_blocks =
  2447. VXGE_HW_MIN_FIFO_BLOCKS;
  2448. device_config->vp_config[i].fifo.max_frags =
  2449. VXGE_HW_MAX_FIFO_FRAGS;
  2450. device_config->vp_config[i].fifo.memblock_size =
  2451. VXGE_HW_DEF_FIFO_MEMBLOCK_SIZE;
  2452. device_config->vp_config[i].fifo.alignment_size =
  2453. VXGE_HW_DEF_FIFO_ALIGNMENT_SIZE;
  2454. device_config->vp_config[i].fifo.intr =
  2455. VXGE_HW_FIFO_QUEUE_INTR_DEFAULT;
  2456. device_config->vp_config[i].fifo.no_snoop_bits =
  2457. VXGE_HW_FIFO_NO_SNOOP_DEFAULT;
  2458. device_config->vp_config[i].tti.intr_enable =
  2459. VXGE_HW_TIM_INTR_DEFAULT;
  2460. device_config->vp_config[i].tti.btimer_val =
  2461. VXGE_HW_USE_FLASH_DEFAULT;
  2462. device_config->vp_config[i].tti.timer_ac_en =
  2463. VXGE_HW_USE_FLASH_DEFAULT;
  2464. device_config->vp_config[i].tti.timer_ci_en =
  2465. VXGE_HW_USE_FLASH_DEFAULT;
  2466. device_config->vp_config[i].tti.timer_ri_en =
  2467. VXGE_HW_USE_FLASH_DEFAULT;
  2468. device_config->vp_config[i].tti.rtimer_val =
  2469. VXGE_HW_USE_FLASH_DEFAULT;
  2470. device_config->vp_config[i].tti.util_sel =
  2471. VXGE_HW_USE_FLASH_DEFAULT;
  2472. device_config->vp_config[i].tti.ltimer_val =
  2473. VXGE_HW_USE_FLASH_DEFAULT;
  2474. device_config->vp_config[i].tti.urange_a =
  2475. VXGE_HW_USE_FLASH_DEFAULT;
  2476. device_config->vp_config[i].tti.uec_a =
  2477. VXGE_HW_USE_FLASH_DEFAULT;
  2478. device_config->vp_config[i].tti.urange_b =
  2479. VXGE_HW_USE_FLASH_DEFAULT;
  2480. device_config->vp_config[i].tti.uec_b =
  2481. VXGE_HW_USE_FLASH_DEFAULT;
  2482. device_config->vp_config[i].tti.urange_c =
  2483. VXGE_HW_USE_FLASH_DEFAULT;
  2484. device_config->vp_config[i].tti.uec_c =
  2485. VXGE_HW_USE_FLASH_DEFAULT;
  2486. device_config->vp_config[i].tti.uec_d =
  2487. VXGE_HW_USE_FLASH_DEFAULT;
  2488. device_config->vp_config[i].rti.intr_enable =
  2489. VXGE_HW_TIM_INTR_DEFAULT;
  2490. device_config->vp_config[i].rti.btimer_val =
  2491. VXGE_HW_USE_FLASH_DEFAULT;
  2492. device_config->vp_config[i].rti.timer_ac_en =
  2493. VXGE_HW_USE_FLASH_DEFAULT;
  2494. device_config->vp_config[i].rti.timer_ci_en =
  2495. VXGE_HW_USE_FLASH_DEFAULT;
  2496. device_config->vp_config[i].rti.timer_ri_en =
  2497. VXGE_HW_USE_FLASH_DEFAULT;
  2498. device_config->vp_config[i].rti.rtimer_val =
  2499. VXGE_HW_USE_FLASH_DEFAULT;
  2500. device_config->vp_config[i].rti.util_sel =
  2501. VXGE_HW_USE_FLASH_DEFAULT;
  2502. device_config->vp_config[i].rti.ltimer_val =
  2503. VXGE_HW_USE_FLASH_DEFAULT;
  2504. device_config->vp_config[i].rti.urange_a =
  2505. VXGE_HW_USE_FLASH_DEFAULT;
  2506. device_config->vp_config[i].rti.uec_a =
  2507. VXGE_HW_USE_FLASH_DEFAULT;
  2508. device_config->vp_config[i].rti.urange_b =
  2509. VXGE_HW_USE_FLASH_DEFAULT;
  2510. device_config->vp_config[i].rti.uec_b =
  2511. VXGE_HW_USE_FLASH_DEFAULT;
  2512. device_config->vp_config[i].rti.urange_c =
  2513. VXGE_HW_USE_FLASH_DEFAULT;
  2514. device_config->vp_config[i].rti.uec_c =
  2515. VXGE_HW_USE_FLASH_DEFAULT;
  2516. device_config->vp_config[i].rti.uec_d =
  2517. VXGE_HW_USE_FLASH_DEFAULT;
  2518. device_config->vp_config[i].mtu =
  2519. VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU;
  2520. device_config->vp_config[i].rpa_strip_vlan_tag =
  2521. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT;
  2522. }
  2523. return VXGE_HW_OK;
  2524. }
  2525. /*
  2526. * __vxge_hw_vpath_swapper_set - Set the swapper bits for the vpath.
  2527. * Set the swapper bits appropriately for the vpath.
  2528. */
  2529. static enum vxge_hw_status
  2530. __vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem *vpath_reg)
  2531. {
  2532. #ifndef __BIG_ENDIAN
  2533. u64 val64;
  2534. val64 = readq(&vpath_reg->vpath_general_cfg1);
  2535. wmb();
  2536. val64 |= VXGE_HW_VPATH_GENERAL_CFG1_CTL_BYTE_SWAPEN;
  2537. writeq(val64, &vpath_reg->vpath_general_cfg1);
  2538. wmb();
  2539. #endif
  2540. return VXGE_HW_OK;
  2541. }
  2542. /*
  2543. * __vxge_hw_kdfc_swapper_set - Set the swapper bits for the kdfc.
  2544. * Set the swapper bits appropriately for the vpath.
  2545. */
  2546. static enum vxge_hw_status
  2547. __vxge_hw_kdfc_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg,
  2548. struct vxge_hw_vpath_reg __iomem *vpath_reg)
  2549. {
  2550. u64 val64;
  2551. val64 = readq(&legacy_reg->pifm_wr_swap_en);
  2552. if (val64 == VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE) {
  2553. val64 = readq(&vpath_reg->kdfcctl_cfg0);
  2554. wmb();
  2555. val64 |= VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO0 |
  2556. VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO1 |
  2557. VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO2;
  2558. writeq(val64, &vpath_reg->kdfcctl_cfg0);
  2559. wmb();
  2560. }
  2561. return VXGE_HW_OK;
  2562. }
  2563. /*
  2564. * vxge_hw_mgmt_reg_read - Read Titan register.
  2565. */
  2566. enum vxge_hw_status
  2567. vxge_hw_mgmt_reg_read(struct __vxge_hw_device *hldev,
  2568. enum vxge_hw_mgmt_reg_type type,
  2569. u32 index, u32 offset, u64 *value)
  2570. {
  2571. enum vxge_hw_status status = VXGE_HW_OK;
  2572. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  2573. status = VXGE_HW_ERR_INVALID_DEVICE;
  2574. goto exit;
  2575. }
  2576. switch (type) {
  2577. case vxge_hw_mgmt_reg_type_legacy:
  2578. if (offset > sizeof(struct vxge_hw_legacy_reg) - 8) {
  2579. status = VXGE_HW_ERR_INVALID_OFFSET;
  2580. break;
  2581. }
  2582. *value = readq((void __iomem *)hldev->legacy_reg + offset);
  2583. break;
  2584. case vxge_hw_mgmt_reg_type_toc:
  2585. if (offset > sizeof(struct vxge_hw_toc_reg) - 8) {
  2586. status = VXGE_HW_ERR_INVALID_OFFSET;
  2587. break;
  2588. }
  2589. *value = readq((void __iomem *)hldev->toc_reg + offset);
  2590. break;
  2591. case vxge_hw_mgmt_reg_type_common:
  2592. if (offset > sizeof(struct vxge_hw_common_reg) - 8) {
  2593. status = VXGE_HW_ERR_INVALID_OFFSET;
  2594. break;
  2595. }
  2596. *value = readq((void __iomem *)hldev->common_reg + offset);
  2597. break;
  2598. case vxge_hw_mgmt_reg_type_mrpcim:
  2599. if (!(hldev->access_rights &
  2600. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) {
  2601. status = VXGE_HW_ERR_PRIVILEGED_OPERATION;
  2602. break;
  2603. }
  2604. if (offset > sizeof(struct vxge_hw_mrpcim_reg) - 8) {
  2605. status = VXGE_HW_ERR_INVALID_OFFSET;
  2606. break;
  2607. }
  2608. *value = readq((void __iomem *)hldev->mrpcim_reg + offset);
  2609. break;
  2610. case vxge_hw_mgmt_reg_type_srpcim:
  2611. if (!(hldev->access_rights &
  2612. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM)) {
  2613. status = VXGE_HW_ERR_PRIVILEGED_OPERATION;
  2614. break;
  2615. }
  2616. if (index > VXGE_HW_TITAN_SRPCIM_REG_SPACES - 1) {
  2617. status = VXGE_HW_ERR_INVALID_INDEX;
  2618. break;
  2619. }
  2620. if (offset > sizeof(struct vxge_hw_srpcim_reg) - 8) {
  2621. status = VXGE_HW_ERR_INVALID_OFFSET;
  2622. break;
  2623. }
  2624. *value = readq((void __iomem *)hldev->srpcim_reg[index] +
  2625. offset);
  2626. break;
  2627. case vxge_hw_mgmt_reg_type_vpmgmt:
  2628. if ((index > VXGE_HW_TITAN_VPMGMT_REG_SPACES - 1) ||
  2629. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2630. status = VXGE_HW_ERR_INVALID_INDEX;
  2631. break;
  2632. }
  2633. if (offset > sizeof(struct vxge_hw_vpmgmt_reg) - 8) {
  2634. status = VXGE_HW_ERR_INVALID_OFFSET;
  2635. break;
  2636. }
  2637. *value = readq((void __iomem *)hldev->vpmgmt_reg[index] +
  2638. offset);
  2639. break;
  2640. case vxge_hw_mgmt_reg_type_vpath:
  2641. if ((index > VXGE_HW_TITAN_VPATH_REG_SPACES - 1) ||
  2642. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2643. status = VXGE_HW_ERR_INVALID_INDEX;
  2644. break;
  2645. }
  2646. if (index > VXGE_HW_TITAN_VPATH_REG_SPACES - 1) {
  2647. status = VXGE_HW_ERR_INVALID_INDEX;
  2648. break;
  2649. }
  2650. if (offset > sizeof(struct vxge_hw_vpath_reg) - 8) {
  2651. status = VXGE_HW_ERR_INVALID_OFFSET;
  2652. break;
  2653. }
  2654. *value = readq((void __iomem *)hldev->vpath_reg[index] +
  2655. offset);
  2656. break;
  2657. default:
  2658. status = VXGE_HW_ERR_INVALID_TYPE;
  2659. break;
  2660. }
  2661. exit:
  2662. return status;
  2663. }
  2664. /*
  2665. * vxge_hw_vpath_strip_fcs_check - Check for FCS strip.
  2666. */
  2667. enum vxge_hw_status
  2668. vxge_hw_vpath_strip_fcs_check(struct __vxge_hw_device *hldev, u64 vpath_mask)
  2669. {
  2670. struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg;
  2671. int i = 0, j = 0;
  2672. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  2673. if (!((vpath_mask) & vxge_mBIT(i)))
  2674. continue;
  2675. vpmgmt_reg = hldev->vpmgmt_reg[i];
  2676. for (j = 0; j < VXGE_HW_MAC_MAX_MAC_PORT_ID; j++) {
  2677. if (readq(&vpmgmt_reg->rxmac_cfg0_port_vpmgmt_clone[j])
  2678. & VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_STRIP_FCS)
  2679. return VXGE_HW_FAIL;
  2680. }
  2681. }
  2682. return VXGE_HW_OK;
  2683. }
  2684. /*
  2685. * vxge_hw_mgmt_reg_Write - Write Titan register.
  2686. */
  2687. enum vxge_hw_status
  2688. vxge_hw_mgmt_reg_write(struct __vxge_hw_device *hldev,
  2689. enum vxge_hw_mgmt_reg_type type,
  2690. u32 index, u32 offset, u64 value)
  2691. {
  2692. enum vxge_hw_status status = VXGE_HW_OK;
  2693. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  2694. status = VXGE_HW_ERR_INVALID_DEVICE;
  2695. goto exit;
  2696. }
  2697. switch (type) {
  2698. case vxge_hw_mgmt_reg_type_legacy:
  2699. if (offset > sizeof(struct vxge_hw_legacy_reg) - 8) {
  2700. status = VXGE_HW_ERR_INVALID_OFFSET;
  2701. break;
  2702. }
  2703. writeq(value, (void __iomem *)hldev->legacy_reg + offset);
  2704. break;
  2705. case vxge_hw_mgmt_reg_type_toc:
  2706. if (offset > sizeof(struct vxge_hw_toc_reg) - 8) {
  2707. status = VXGE_HW_ERR_INVALID_OFFSET;
  2708. break;
  2709. }
  2710. writeq(value, (void __iomem *)hldev->toc_reg + offset);
  2711. break;
  2712. case vxge_hw_mgmt_reg_type_common:
  2713. if (offset > sizeof(struct vxge_hw_common_reg) - 8) {
  2714. status = VXGE_HW_ERR_INVALID_OFFSET;
  2715. break;
  2716. }
  2717. writeq(value, (void __iomem *)hldev->common_reg + offset);
  2718. break;
  2719. case vxge_hw_mgmt_reg_type_mrpcim:
  2720. if (!(hldev->access_rights &
  2721. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) {
  2722. status = VXGE_HW_ERR_PRIVILEGED_OPERATION;
  2723. break;
  2724. }
  2725. if (offset > sizeof(struct vxge_hw_mrpcim_reg) - 8) {
  2726. status = VXGE_HW_ERR_INVALID_OFFSET;
  2727. break;
  2728. }
  2729. writeq(value, (void __iomem *)hldev->mrpcim_reg + offset);
  2730. break;
  2731. case vxge_hw_mgmt_reg_type_srpcim:
  2732. if (!(hldev->access_rights &
  2733. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM)) {
  2734. status = VXGE_HW_ERR_PRIVILEGED_OPERATION;
  2735. break;
  2736. }
  2737. if (index > VXGE_HW_TITAN_SRPCIM_REG_SPACES - 1) {
  2738. status = VXGE_HW_ERR_INVALID_INDEX;
  2739. break;
  2740. }
  2741. if (offset > sizeof(struct vxge_hw_srpcim_reg) - 8) {
  2742. status = VXGE_HW_ERR_INVALID_OFFSET;
  2743. break;
  2744. }
  2745. writeq(value, (void __iomem *)hldev->srpcim_reg[index] +
  2746. offset);
  2747. break;
  2748. case vxge_hw_mgmt_reg_type_vpmgmt:
  2749. if ((index > VXGE_HW_TITAN_VPMGMT_REG_SPACES - 1) ||
  2750. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2751. status = VXGE_HW_ERR_INVALID_INDEX;
  2752. break;
  2753. }
  2754. if (offset > sizeof(struct vxge_hw_vpmgmt_reg) - 8) {
  2755. status = VXGE_HW_ERR_INVALID_OFFSET;
  2756. break;
  2757. }
  2758. writeq(value, (void __iomem *)hldev->vpmgmt_reg[index] +
  2759. offset);
  2760. break;
  2761. case vxge_hw_mgmt_reg_type_vpath:
  2762. if ((index > VXGE_HW_TITAN_VPATH_REG_SPACES-1) ||
  2763. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2764. status = VXGE_HW_ERR_INVALID_INDEX;
  2765. break;
  2766. }
  2767. if (offset > sizeof(struct vxge_hw_vpath_reg) - 8) {
  2768. status = VXGE_HW_ERR_INVALID_OFFSET;
  2769. break;
  2770. }
  2771. writeq(value, (void __iomem *)hldev->vpath_reg[index] +
  2772. offset);
  2773. break;
  2774. default:
  2775. status = VXGE_HW_ERR_INVALID_TYPE;
  2776. break;
  2777. }
  2778. exit:
  2779. return status;
  2780. }
  2781. /*
  2782. * __vxge_hw_fifo_abort - Returns the TxD
  2783. * This function terminates the TxDs of fifo
  2784. */
  2785. static enum vxge_hw_status __vxge_hw_fifo_abort(struct __vxge_hw_fifo *fifo)
  2786. {
  2787. void *txdlh;
  2788. for (;;) {
  2789. vxge_hw_channel_dtr_try_complete(&fifo->channel, &txdlh);
  2790. if (txdlh == NULL)
  2791. break;
  2792. vxge_hw_channel_dtr_complete(&fifo->channel);
  2793. if (fifo->txdl_term) {
  2794. fifo->txdl_term(txdlh,
  2795. VXGE_HW_TXDL_STATE_POSTED,
  2796. fifo->channel.userdata);
  2797. }
  2798. vxge_hw_channel_dtr_free(&fifo->channel, txdlh);
  2799. }
  2800. return VXGE_HW_OK;
  2801. }
  2802. /*
  2803. * __vxge_hw_fifo_reset - Resets the fifo
  2804. * This function resets the fifo during vpath reset operation
  2805. */
  2806. static enum vxge_hw_status __vxge_hw_fifo_reset(struct __vxge_hw_fifo *fifo)
  2807. {
  2808. enum vxge_hw_status status = VXGE_HW_OK;
  2809. __vxge_hw_fifo_abort(fifo);
  2810. status = __vxge_hw_channel_reset(&fifo->channel);
  2811. return status;
  2812. }
  2813. /*
  2814. * __vxge_hw_fifo_delete - Removes the FIFO
  2815. * This function freeup the memory pool and removes the FIFO
  2816. */
  2817. static enum vxge_hw_status
  2818. __vxge_hw_fifo_delete(struct __vxge_hw_vpath_handle *vp)
  2819. {
  2820. struct __vxge_hw_fifo *fifo = vp->vpath->fifoh;
  2821. __vxge_hw_fifo_abort(fifo);
  2822. if (fifo->mempool)
  2823. __vxge_hw_mempool_destroy(fifo->mempool);
  2824. vp->vpath->fifoh = NULL;
  2825. __vxge_hw_channel_free(&fifo->channel);
  2826. return VXGE_HW_OK;
  2827. }
  2828. /*
  2829. * __vxge_hw_fifo_mempool_item_alloc - Allocate List blocks for TxD
  2830. * list callback
  2831. * This function is callback passed to __vxge_hw_mempool_create to create memory
  2832. * pool for TxD list
  2833. */
  2834. static void
  2835. __vxge_hw_fifo_mempool_item_alloc(
  2836. struct vxge_hw_mempool *mempoolh,
  2837. u32 memblock_index, struct vxge_hw_mempool_dma *dma_object,
  2838. u32 index, u32 is_last)
  2839. {
  2840. u32 memblock_item_idx;
  2841. struct __vxge_hw_fifo_txdl_priv *txdl_priv;
  2842. struct vxge_hw_fifo_txd *txdp =
  2843. (struct vxge_hw_fifo_txd *)mempoolh->items_arr[index];
  2844. struct __vxge_hw_fifo *fifo =
  2845. (struct __vxge_hw_fifo *)mempoolh->userdata;
  2846. void *memblock = mempoolh->memblocks_arr[memblock_index];
  2847. vxge_assert(txdp);
  2848. txdp->host_control = (u64) (size_t)
  2849. __vxge_hw_mempool_item_priv(mempoolh, memblock_index, txdp,
  2850. &memblock_item_idx);
  2851. txdl_priv = __vxge_hw_fifo_txdl_priv(fifo, txdp);
  2852. vxge_assert(txdl_priv);
  2853. fifo->channel.reserve_arr[fifo->channel.reserve_ptr - 1 - index] = txdp;
  2854. /* pre-format HW's TxDL's private */
  2855. txdl_priv->dma_offset = (char *)txdp - (char *)memblock;
  2856. txdl_priv->dma_addr = dma_object->addr + txdl_priv->dma_offset;
  2857. txdl_priv->dma_handle = dma_object->handle;
  2858. txdl_priv->memblock = memblock;
  2859. txdl_priv->first_txdp = txdp;
  2860. txdl_priv->next_txdl_priv = NULL;
  2861. txdl_priv->alloc_frags = 0;
  2862. }
  2863. /*
  2864. * __vxge_hw_fifo_create - Create a FIFO
  2865. * This function creates FIFO and initializes it.
  2866. */
  2867. static enum vxge_hw_status
  2868. __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
  2869. struct vxge_hw_fifo_attr *attr)
  2870. {
  2871. enum vxge_hw_status status = VXGE_HW_OK;
  2872. struct __vxge_hw_fifo *fifo;
  2873. struct vxge_hw_fifo_config *config;
  2874. u32 txdl_size, txdl_per_memblock;
  2875. struct vxge_hw_mempool_cbs fifo_mp_callback;
  2876. struct __vxge_hw_virtualpath *vpath;
  2877. if ((vp == NULL) || (attr == NULL)) {
  2878. status = VXGE_HW_ERR_INVALID_HANDLE;
  2879. goto exit;
  2880. }
  2881. vpath = vp->vpath;
  2882. config = &vpath->hldev->config.vp_config[vpath->vp_id].fifo;
  2883. txdl_size = config->max_frags * sizeof(struct vxge_hw_fifo_txd);
  2884. txdl_per_memblock = config->memblock_size / txdl_size;
  2885. fifo = (struct __vxge_hw_fifo *)__vxge_hw_channel_allocate(vp,
  2886. VXGE_HW_CHANNEL_TYPE_FIFO,
  2887. config->fifo_blocks * txdl_per_memblock,
  2888. attr->per_txdl_space, attr->userdata);
  2889. if (fifo == NULL) {
  2890. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2891. goto exit;
  2892. }
  2893. vpath->fifoh = fifo;
  2894. fifo->nofl_db = vpath->nofl_db;
  2895. fifo->vp_id = vpath->vp_id;
  2896. fifo->vp_reg = vpath->vp_reg;
  2897. fifo->stats = &vpath->sw_stats->fifo_stats;
  2898. fifo->config = config;
  2899. /* apply "interrupts per txdl" attribute */
  2900. fifo->interrupt_type = VXGE_HW_FIFO_TXD_INT_TYPE_UTILZ;
  2901. fifo->tim_tti_cfg1_saved = vpath->tim_tti_cfg1_saved;
  2902. fifo->tim_tti_cfg3_saved = vpath->tim_tti_cfg3_saved;
  2903. if (fifo->config->intr)
  2904. fifo->interrupt_type = VXGE_HW_FIFO_TXD_INT_TYPE_PER_LIST;
  2905. fifo->no_snoop_bits = config->no_snoop_bits;
  2906. /*
  2907. * FIFO memory management strategy:
  2908. *
  2909. * TxDL split into three independent parts:
  2910. * - set of TxD's
  2911. * - TxD HW private part
  2912. * - driver private part
  2913. *
  2914. * Adaptative memory allocation used. i.e. Memory allocated on
  2915. * demand with the size which will fit into one memory block.
  2916. * One memory block may contain more than one TxDL.
  2917. *
  2918. * During "reserve" operations more memory can be allocated on demand
  2919. * for example due to FIFO full condition.
  2920. *
  2921. * Pool of memory memblocks never shrinks except in __vxge_hw_fifo_close
  2922. * routine which will essentially stop the channel and free resources.
  2923. */
  2924. /* TxDL common private size == TxDL private + driver private */
  2925. fifo->priv_size =
  2926. sizeof(struct __vxge_hw_fifo_txdl_priv) + attr->per_txdl_space;
  2927. fifo->priv_size = ((fifo->priv_size + VXGE_CACHE_LINE_SIZE - 1) /
  2928. VXGE_CACHE_LINE_SIZE) * VXGE_CACHE_LINE_SIZE;
  2929. fifo->per_txdl_space = attr->per_txdl_space;
  2930. /* recompute txdl size to be cacheline aligned */
  2931. fifo->txdl_size = txdl_size;
  2932. fifo->txdl_per_memblock = txdl_per_memblock;
  2933. fifo->txdl_term = attr->txdl_term;
  2934. fifo->callback = attr->callback;
  2935. if (fifo->txdl_per_memblock == 0) {
  2936. __vxge_hw_fifo_delete(vp);
  2937. status = VXGE_HW_ERR_INVALID_BLOCK_SIZE;
  2938. goto exit;
  2939. }
  2940. fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
  2941. fifo->mempool =
  2942. __vxge_hw_mempool_create(vpath->hldev,
  2943. fifo->config->memblock_size,
  2944. fifo->txdl_size,
  2945. fifo->priv_size,
  2946. (fifo->config->fifo_blocks * fifo->txdl_per_memblock),
  2947. (fifo->config->fifo_blocks * fifo->txdl_per_memblock),
  2948. &fifo_mp_callback,
  2949. fifo);
  2950. if (fifo->mempool == NULL) {
  2951. __vxge_hw_fifo_delete(vp);
  2952. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2953. goto exit;
  2954. }
  2955. status = __vxge_hw_channel_initialize(&fifo->channel);
  2956. if (status != VXGE_HW_OK) {
  2957. __vxge_hw_fifo_delete(vp);
  2958. goto exit;
  2959. }
  2960. vxge_assert(fifo->channel.reserve_ptr);
  2961. exit:
  2962. return status;
  2963. }
  2964. /*
  2965. * __vxge_hw_vpath_pci_read - Read the content of given address
  2966. * in pci config space.
  2967. * Read from the vpath pci config space.
  2968. */
  2969. static enum vxge_hw_status
  2970. __vxge_hw_vpath_pci_read(struct __vxge_hw_virtualpath *vpath,
  2971. u32 phy_func_0, u32 offset, u32 *val)
  2972. {
  2973. u64 val64;
  2974. enum vxge_hw_status status = VXGE_HW_OK;
  2975. struct vxge_hw_vpath_reg __iomem *vp_reg = vpath->vp_reg;
  2976. val64 = VXGE_HW_PCI_CONFIG_ACCESS_CFG1_ADDRESS(offset);
  2977. if (phy_func_0)
  2978. val64 |= VXGE_HW_PCI_CONFIG_ACCESS_CFG1_SEL_FUNC0;
  2979. writeq(val64, &vp_reg->pci_config_access_cfg1);
  2980. wmb();
  2981. writeq(VXGE_HW_PCI_CONFIG_ACCESS_CFG2_REQ,
  2982. &vp_reg->pci_config_access_cfg2);
  2983. wmb();
  2984. status = __vxge_hw_device_register_poll(
  2985. &vp_reg->pci_config_access_cfg2,
  2986. VXGE_HW_INTR_MASK_ALL, VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  2987. if (status != VXGE_HW_OK)
  2988. goto exit;
  2989. val64 = readq(&vp_reg->pci_config_access_status);
  2990. if (val64 & VXGE_HW_PCI_CONFIG_ACCESS_STATUS_ACCESS_ERR) {
  2991. status = VXGE_HW_FAIL;
  2992. *val = 0;
  2993. } else
  2994. *val = (u32)vxge_bVALn(val64, 32, 32);
  2995. exit:
  2996. return status;
  2997. }
  2998. /**
  2999. * vxge_hw_device_flick_link_led - Flick (blink) link LED.
  3000. * @hldev: HW device.
  3001. * @on_off: TRUE if flickering to be on, FALSE to be off
  3002. *
  3003. * Flicker the link LED.
  3004. */
  3005. enum vxge_hw_status
  3006. vxge_hw_device_flick_link_led(struct __vxge_hw_device *hldev, u64 on_off)
  3007. {
  3008. struct __vxge_hw_virtualpath *vpath;
  3009. u64 data0, data1 = 0, steer_ctrl = 0;
  3010. enum vxge_hw_status status;
  3011. if (hldev == NULL) {
  3012. status = VXGE_HW_ERR_INVALID_DEVICE;
  3013. goto exit;
  3014. }
  3015. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  3016. data0 = on_off;
  3017. status = vxge_hw_vpath_fw_api(vpath,
  3018. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LED_CONTROL,
  3019. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  3020. 0, &data0, &data1, &steer_ctrl);
  3021. exit:
  3022. return status;
  3023. }
  3024. /*
  3025. * __vxge_hw_vpath_rts_table_get - Get the entries from RTS access tables
  3026. */
  3027. enum vxge_hw_status
  3028. __vxge_hw_vpath_rts_table_get(struct __vxge_hw_vpath_handle *vp,
  3029. u32 action, u32 rts_table, u32 offset,
  3030. u64 *data0, u64 *data1)
  3031. {
  3032. enum vxge_hw_status status;
  3033. u64 steer_ctrl = 0;
  3034. if (vp == NULL) {
  3035. status = VXGE_HW_ERR_INVALID_HANDLE;
  3036. goto exit;
  3037. }
  3038. if ((rts_table ==
  3039. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT) ||
  3040. (rts_table ==
  3041. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT) ||
  3042. (rts_table ==
  3043. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MASK) ||
  3044. (rts_table ==
  3045. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_KEY)) {
  3046. steer_ctrl = VXGE_HW_RTS_ACCESS_STEER_CTRL_TABLE_SEL;
  3047. }
  3048. status = vxge_hw_vpath_fw_api(vp->vpath, action, rts_table, offset,
  3049. data0, data1, &steer_ctrl);
  3050. if (status != VXGE_HW_OK)
  3051. goto exit;
  3052. if ((rts_table != VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA) &&
  3053. (rts_table !=
  3054. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT))
  3055. *data1 = 0;
  3056. exit:
  3057. return status;
  3058. }
  3059. /*
  3060. * __vxge_hw_vpath_rts_table_set - Set the entries of RTS access tables
  3061. */
  3062. enum vxge_hw_status
  3063. __vxge_hw_vpath_rts_table_set(struct __vxge_hw_vpath_handle *vp, u32 action,
  3064. u32 rts_table, u32 offset, u64 steer_data0,
  3065. u64 steer_data1)
  3066. {
  3067. u64 data0, data1 = 0, steer_ctrl = 0;
  3068. enum vxge_hw_status status;
  3069. if (vp == NULL) {
  3070. status = VXGE_HW_ERR_INVALID_HANDLE;
  3071. goto exit;
  3072. }
  3073. data0 = steer_data0;
  3074. if ((rts_table == VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA) ||
  3075. (rts_table ==
  3076. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT))
  3077. data1 = steer_data1;
  3078. status = vxge_hw_vpath_fw_api(vp->vpath, action, rts_table, offset,
  3079. &data0, &data1, &steer_ctrl);
  3080. exit:
  3081. return status;
  3082. }
  3083. /*
  3084. * vxge_hw_vpath_rts_rth_set - Set/configure RTS hashing.
  3085. */
  3086. enum vxge_hw_status vxge_hw_vpath_rts_rth_set(
  3087. struct __vxge_hw_vpath_handle *vp,
  3088. enum vxge_hw_rth_algoritms algorithm,
  3089. struct vxge_hw_rth_hash_types *hash_type,
  3090. u16 bucket_size)
  3091. {
  3092. u64 data0, data1;
  3093. enum vxge_hw_status status = VXGE_HW_OK;
  3094. if (vp == NULL) {
  3095. status = VXGE_HW_ERR_INVALID_HANDLE;
  3096. goto exit;
  3097. }
  3098. status = __vxge_hw_vpath_rts_table_get(vp,
  3099. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY,
  3100. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG,
  3101. 0, &data0, &data1);
  3102. if (status != VXGE_HW_OK)
  3103. goto exit;
  3104. data0 &= ~(VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(0xf) |
  3105. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(0x3));
  3106. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_EN |
  3107. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(bucket_size) |
  3108. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(algorithm);
  3109. if (hash_type->hash_type_tcpipv4_en)
  3110. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV4_EN;
  3111. if (hash_type->hash_type_ipv4_en)
  3112. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV4_EN;
  3113. if (hash_type->hash_type_tcpipv6_en)
  3114. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EN;
  3115. if (hash_type->hash_type_ipv6_en)
  3116. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EN;
  3117. if (hash_type->hash_type_tcpipv6ex_en)
  3118. data0 |=
  3119. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EX_EN;
  3120. if (hash_type->hash_type_ipv6ex_en)
  3121. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EX_EN;
  3122. if (VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_RTH_GEN_ACTIVE_TABLE(data0))
  3123. data0 &= ~VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE;
  3124. else
  3125. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE;
  3126. status = __vxge_hw_vpath_rts_table_set(vp,
  3127. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY,
  3128. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG,
  3129. 0, data0, 0);
  3130. exit:
  3131. return status;
  3132. }
  3133. static void
  3134. vxge_hw_rts_rth_data0_data1_get(u32 j, u64 *data0, u64 *data1,
  3135. u16 flag, u8 *itable)
  3136. {
  3137. switch (flag) {
  3138. case 1:
  3139. *data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_NUM(j)|
  3140. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_ENTRY_EN |
  3141. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_DATA(
  3142. itable[j]);
  3143. /* fall through */
  3144. case 2:
  3145. *data0 |=
  3146. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_NUM(j)|
  3147. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_ENTRY_EN |
  3148. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_DATA(
  3149. itable[j]);
  3150. /* fall through */
  3151. case 3:
  3152. *data1 = VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_NUM(j)|
  3153. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_ENTRY_EN |
  3154. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_DATA(
  3155. itable[j]);
  3156. /* fall through */
  3157. case 4:
  3158. *data1 |=
  3159. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_NUM(j)|
  3160. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_ENTRY_EN |
  3161. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_DATA(
  3162. itable[j]);
  3163. default:
  3164. return;
  3165. }
  3166. }
  3167. /*
  3168. * vxge_hw_vpath_rts_rth_itable_set - Set/configure indirection table (IT).
  3169. */
  3170. enum vxge_hw_status vxge_hw_vpath_rts_rth_itable_set(
  3171. struct __vxge_hw_vpath_handle **vpath_handles,
  3172. u32 vpath_count,
  3173. u8 *mtable,
  3174. u8 *itable,
  3175. u32 itable_size)
  3176. {
  3177. u32 i, j, action, rts_table;
  3178. u64 data0;
  3179. u64 data1;
  3180. u32 max_entries;
  3181. enum vxge_hw_status status = VXGE_HW_OK;
  3182. struct __vxge_hw_vpath_handle *vp = vpath_handles[0];
  3183. if (vp == NULL) {
  3184. status = VXGE_HW_ERR_INVALID_HANDLE;
  3185. goto exit;
  3186. }
  3187. max_entries = (((u32)1) << itable_size);
  3188. if (vp->vpath->hldev->config.rth_it_type
  3189. == VXGE_HW_RTH_IT_TYPE_SOLO_IT) {
  3190. action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY;
  3191. rts_table =
  3192. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT;
  3193. for (j = 0; j < max_entries; j++) {
  3194. data1 = 0;
  3195. data0 =
  3196. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA(
  3197. itable[j]);
  3198. status = __vxge_hw_vpath_rts_table_set(vpath_handles[0],
  3199. action, rts_table, j, data0, data1);
  3200. if (status != VXGE_HW_OK)
  3201. goto exit;
  3202. }
  3203. for (j = 0; j < max_entries; j++) {
  3204. data1 = 0;
  3205. data0 =
  3206. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_ENTRY_EN |
  3207. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA(
  3208. itable[j]);
  3209. status = __vxge_hw_vpath_rts_table_set(
  3210. vpath_handles[mtable[itable[j]]], action,
  3211. rts_table, j, data0, data1);
  3212. if (status != VXGE_HW_OK)
  3213. goto exit;
  3214. }
  3215. } else {
  3216. action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY;
  3217. rts_table =
  3218. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT;
  3219. for (i = 0; i < vpath_count; i++) {
  3220. for (j = 0; j < max_entries;) {
  3221. data0 = 0;
  3222. data1 = 0;
  3223. while (j < max_entries) {
  3224. if (mtable[itable[j]] != i) {
  3225. j++;
  3226. continue;
  3227. }
  3228. vxge_hw_rts_rth_data0_data1_get(j,
  3229. &data0, &data1, 1, itable);
  3230. j++;
  3231. break;
  3232. }
  3233. while (j < max_entries) {
  3234. if (mtable[itable[j]] != i) {
  3235. j++;
  3236. continue;
  3237. }
  3238. vxge_hw_rts_rth_data0_data1_get(j,
  3239. &data0, &data1, 2, itable);
  3240. j++;
  3241. break;
  3242. }
  3243. while (j < max_entries) {
  3244. if (mtable[itable[j]] != i) {
  3245. j++;
  3246. continue;
  3247. }
  3248. vxge_hw_rts_rth_data0_data1_get(j,
  3249. &data0, &data1, 3, itable);
  3250. j++;
  3251. break;
  3252. }
  3253. while (j < max_entries) {
  3254. if (mtable[itable[j]] != i) {
  3255. j++;
  3256. continue;
  3257. }
  3258. vxge_hw_rts_rth_data0_data1_get(j,
  3259. &data0, &data1, 4, itable);
  3260. j++;
  3261. break;
  3262. }
  3263. if (data0 != 0) {
  3264. status = __vxge_hw_vpath_rts_table_set(
  3265. vpath_handles[i],
  3266. action, rts_table,
  3267. 0, data0, data1);
  3268. if (status != VXGE_HW_OK)
  3269. goto exit;
  3270. }
  3271. }
  3272. }
  3273. }
  3274. exit:
  3275. return status;
  3276. }
  3277. /**
  3278. * vxge_hw_vpath_check_leak - Check for memory leak
  3279. * @ringh: Handle to the ring object used for receive
  3280. *
  3281. * If PRC_RXD_DOORBELL_VPn.NEW_QW_CNT is larger or equal to
  3282. * PRC_CFG6_VPn.RXD_SPAT then a leak has occurred.
  3283. * Returns: VXGE_HW_FAIL, if leak has occurred.
  3284. *
  3285. */
  3286. enum vxge_hw_status
  3287. vxge_hw_vpath_check_leak(struct __vxge_hw_ring *ring)
  3288. {
  3289. enum vxge_hw_status status = VXGE_HW_OK;
  3290. u64 rxd_new_count, rxd_spat;
  3291. if (ring == NULL)
  3292. return status;
  3293. rxd_new_count = readl(&ring->vp_reg->prc_rxd_doorbell);
  3294. rxd_spat = readq(&ring->vp_reg->prc_cfg6);
  3295. rxd_spat = VXGE_HW_PRC_CFG6_RXD_SPAT(rxd_spat);
  3296. if (rxd_new_count >= rxd_spat)
  3297. status = VXGE_HW_FAIL;
  3298. return status;
  3299. }
  3300. /*
  3301. * __vxge_hw_vpath_mgmt_read
  3302. * This routine reads the vpath_mgmt registers
  3303. */
  3304. static enum vxge_hw_status
  3305. __vxge_hw_vpath_mgmt_read(
  3306. struct __vxge_hw_device *hldev,
  3307. struct __vxge_hw_virtualpath *vpath)
  3308. {
  3309. u32 i, mtu = 0, max_pyld = 0;
  3310. u64 val64;
  3311. for (i = 0; i < VXGE_HW_MAC_MAX_MAC_PORT_ID; i++) {
  3312. val64 = readq(&vpath->vpmgmt_reg->
  3313. rxmac_cfg0_port_vpmgmt_clone[i]);
  3314. max_pyld =
  3315. (u32)
  3316. VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_GET_MAX_PYLD_LEN
  3317. (val64);
  3318. if (mtu < max_pyld)
  3319. mtu = max_pyld;
  3320. }
  3321. vpath->max_mtu = mtu + VXGE_HW_MAC_HEADER_MAX_SIZE;
  3322. val64 = readq(&vpath->vpmgmt_reg->xmac_vsport_choices_vp);
  3323. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3324. if (val64 & vxge_mBIT(i))
  3325. vpath->vsport_number = i;
  3326. }
  3327. val64 = readq(&vpath->vpmgmt_reg->xgmac_gen_status_vpmgmt_clone);
  3328. if (val64 & VXGE_HW_XGMAC_GEN_STATUS_VPMGMT_CLONE_XMACJ_NTWK_OK)
  3329. VXGE_HW_DEVICE_LINK_STATE_SET(vpath->hldev, VXGE_HW_LINK_UP);
  3330. else
  3331. VXGE_HW_DEVICE_LINK_STATE_SET(vpath->hldev, VXGE_HW_LINK_DOWN);
  3332. return VXGE_HW_OK;
  3333. }
  3334. /*
  3335. * __vxge_hw_vpath_reset_check - Check if resetting the vpath completed
  3336. * This routine checks the vpath_rst_in_prog register to see if
  3337. * adapter completed the reset process for the vpath
  3338. */
  3339. static enum vxge_hw_status
  3340. __vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath)
  3341. {
  3342. enum vxge_hw_status status;
  3343. status = __vxge_hw_device_register_poll(
  3344. &vpath->hldev->common_reg->vpath_rst_in_prog,
  3345. VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG(
  3346. 1 << (16 - vpath->vp_id)),
  3347. vpath->hldev->config.device_poll_millis);
  3348. return status;
  3349. }
  3350. /*
  3351. * __vxge_hw_vpath_reset
  3352. * This routine resets the vpath on the device
  3353. */
  3354. static enum vxge_hw_status
  3355. __vxge_hw_vpath_reset(struct __vxge_hw_device *hldev, u32 vp_id)
  3356. {
  3357. u64 val64;
  3358. val64 = VXGE_HW_CMN_RSTHDLR_CFG0_SW_RESET_VPATH(1 << (16 - vp_id));
  3359. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32),
  3360. &hldev->common_reg->cmn_rsthdlr_cfg0);
  3361. return VXGE_HW_OK;
  3362. }
  3363. /*
  3364. * __vxge_hw_vpath_sw_reset
  3365. * This routine resets the vpath structures
  3366. */
  3367. static enum vxge_hw_status
  3368. __vxge_hw_vpath_sw_reset(struct __vxge_hw_device *hldev, u32 vp_id)
  3369. {
  3370. enum vxge_hw_status status = VXGE_HW_OK;
  3371. struct __vxge_hw_virtualpath *vpath;
  3372. vpath = &hldev->virtual_paths[vp_id];
  3373. if (vpath->ringh) {
  3374. status = __vxge_hw_ring_reset(vpath->ringh);
  3375. if (status != VXGE_HW_OK)
  3376. goto exit;
  3377. }
  3378. if (vpath->fifoh)
  3379. status = __vxge_hw_fifo_reset(vpath->fifoh);
  3380. exit:
  3381. return status;
  3382. }
  3383. /*
  3384. * __vxge_hw_vpath_prc_configure
  3385. * This routine configures the prc registers of virtual path using the config
  3386. * passed
  3387. */
  3388. static void
  3389. __vxge_hw_vpath_prc_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3390. {
  3391. u64 val64;
  3392. struct __vxge_hw_virtualpath *vpath;
  3393. struct vxge_hw_vp_config *vp_config;
  3394. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3395. vpath = &hldev->virtual_paths[vp_id];
  3396. vp_reg = vpath->vp_reg;
  3397. vp_config = vpath->vp_config;
  3398. if (vp_config->ring.enable == VXGE_HW_RING_DISABLE)
  3399. return;
  3400. val64 = readq(&vp_reg->prc_cfg1);
  3401. val64 |= VXGE_HW_PRC_CFG1_RTI_TINT_DISABLE;
  3402. writeq(val64, &vp_reg->prc_cfg1);
  3403. val64 = readq(&vpath->vp_reg->prc_cfg6);
  3404. val64 |= VXGE_HW_PRC_CFG6_DOORBELL_MODE_EN;
  3405. writeq(val64, &vpath->vp_reg->prc_cfg6);
  3406. val64 = readq(&vp_reg->prc_cfg7);
  3407. if (vpath->vp_config->ring.scatter_mode !=
  3408. VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT) {
  3409. val64 &= ~VXGE_HW_PRC_CFG7_SCATTER_MODE(0x3);
  3410. switch (vpath->vp_config->ring.scatter_mode) {
  3411. case VXGE_HW_RING_SCATTER_MODE_A:
  3412. val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE(
  3413. VXGE_HW_PRC_CFG7_SCATTER_MODE_A);
  3414. break;
  3415. case VXGE_HW_RING_SCATTER_MODE_B:
  3416. val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE(
  3417. VXGE_HW_PRC_CFG7_SCATTER_MODE_B);
  3418. break;
  3419. case VXGE_HW_RING_SCATTER_MODE_C:
  3420. val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE(
  3421. VXGE_HW_PRC_CFG7_SCATTER_MODE_C);
  3422. break;
  3423. }
  3424. }
  3425. writeq(val64, &vp_reg->prc_cfg7);
  3426. writeq(VXGE_HW_PRC_CFG5_RXD0_ADD(
  3427. __vxge_hw_ring_first_block_address_get(
  3428. vpath->ringh) >> 3), &vp_reg->prc_cfg5);
  3429. val64 = readq(&vp_reg->prc_cfg4);
  3430. val64 |= VXGE_HW_PRC_CFG4_IN_SVC;
  3431. val64 &= ~VXGE_HW_PRC_CFG4_RING_MODE(0x3);
  3432. val64 |= VXGE_HW_PRC_CFG4_RING_MODE(
  3433. VXGE_HW_PRC_CFG4_RING_MODE_ONE_BUFFER);
  3434. if (hldev->config.rth_en == VXGE_HW_RTH_DISABLE)
  3435. val64 |= VXGE_HW_PRC_CFG4_RTH_DISABLE;
  3436. else
  3437. val64 &= ~VXGE_HW_PRC_CFG4_RTH_DISABLE;
  3438. writeq(val64, &vp_reg->prc_cfg4);
  3439. }
  3440. /*
  3441. * __vxge_hw_vpath_kdfc_configure
  3442. * This routine configures the kdfc registers of virtual path using the
  3443. * config passed
  3444. */
  3445. static enum vxge_hw_status
  3446. __vxge_hw_vpath_kdfc_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3447. {
  3448. u64 val64;
  3449. u64 vpath_stride;
  3450. enum vxge_hw_status status = VXGE_HW_OK;
  3451. struct __vxge_hw_virtualpath *vpath;
  3452. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3453. vpath = &hldev->virtual_paths[vp_id];
  3454. vp_reg = vpath->vp_reg;
  3455. status = __vxge_hw_kdfc_swapper_set(hldev->legacy_reg, vp_reg);
  3456. if (status != VXGE_HW_OK)
  3457. goto exit;
  3458. val64 = readq(&vp_reg->kdfc_drbl_triplet_total);
  3459. vpath->max_kdfc_db =
  3460. (u32)VXGE_HW_KDFC_DRBL_TRIPLET_TOTAL_GET_KDFC_MAX_SIZE(
  3461. val64+1)/2;
  3462. if (vpath->vp_config->fifo.enable == VXGE_HW_FIFO_ENABLE) {
  3463. vpath->max_nofl_db = vpath->max_kdfc_db;
  3464. if (vpath->max_nofl_db <
  3465. ((vpath->vp_config->fifo.memblock_size /
  3466. (vpath->vp_config->fifo.max_frags *
  3467. sizeof(struct vxge_hw_fifo_txd))) *
  3468. vpath->vp_config->fifo.fifo_blocks)) {
  3469. return VXGE_HW_BADCFG_FIFO_BLOCKS;
  3470. }
  3471. val64 = VXGE_HW_KDFC_FIFO_TRPL_PARTITION_LENGTH_0(
  3472. (vpath->max_nofl_db*2)-1);
  3473. }
  3474. writeq(val64, &vp_reg->kdfc_fifo_trpl_partition);
  3475. writeq(VXGE_HW_KDFC_FIFO_TRPL_CTRL_TRIPLET_ENABLE,
  3476. &vp_reg->kdfc_fifo_trpl_ctrl);
  3477. val64 = readq(&vp_reg->kdfc_trpl_fifo_0_ctrl);
  3478. val64 &= ~(VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE(0x3) |
  3479. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0xFF));
  3480. val64 |= VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE(
  3481. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE_NON_OFFLOAD_ONLY) |
  3482. #ifndef __BIG_ENDIAN
  3483. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SWAP_EN |
  3484. #endif
  3485. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0);
  3486. writeq(val64, &vp_reg->kdfc_trpl_fifo_0_ctrl);
  3487. writeq((u64)0, &vp_reg->kdfc_trpl_fifo_0_wb_address);
  3488. wmb();
  3489. vpath_stride = readq(&hldev->toc_reg->toc_kdfc_vpath_stride);
  3490. vpath->nofl_db =
  3491. (struct __vxge_hw_non_offload_db_wrapper __iomem *)
  3492. (hldev->kdfc + (vp_id *
  3493. VXGE_HW_TOC_KDFC_VPATH_STRIDE_GET_TOC_KDFC_VPATH_STRIDE(
  3494. vpath_stride)));
  3495. exit:
  3496. return status;
  3497. }
  3498. /*
  3499. * __vxge_hw_vpath_mac_configure
  3500. * This routine configures the mac of virtual path using the config passed
  3501. */
  3502. static enum vxge_hw_status
  3503. __vxge_hw_vpath_mac_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3504. {
  3505. u64 val64;
  3506. struct __vxge_hw_virtualpath *vpath;
  3507. struct vxge_hw_vp_config *vp_config;
  3508. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3509. vpath = &hldev->virtual_paths[vp_id];
  3510. vp_reg = vpath->vp_reg;
  3511. vp_config = vpath->vp_config;
  3512. writeq(VXGE_HW_XMAC_VSPORT_CHOICE_VSPORT_NUMBER(
  3513. vpath->vsport_number), &vp_reg->xmac_vsport_choice);
  3514. if (vp_config->ring.enable == VXGE_HW_RING_ENABLE) {
  3515. val64 = readq(&vp_reg->xmac_rpa_vcfg);
  3516. if (vp_config->rpa_strip_vlan_tag !=
  3517. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT) {
  3518. if (vp_config->rpa_strip_vlan_tag)
  3519. val64 |= VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG;
  3520. else
  3521. val64 &= ~VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG;
  3522. }
  3523. writeq(val64, &vp_reg->xmac_rpa_vcfg);
  3524. val64 = readq(&vp_reg->rxmac_vcfg0);
  3525. if (vp_config->mtu !=
  3526. VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU) {
  3527. val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
  3528. if ((vp_config->mtu +
  3529. VXGE_HW_MAC_HEADER_MAX_SIZE) < vpath->max_mtu)
  3530. val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(
  3531. vp_config->mtu +
  3532. VXGE_HW_MAC_HEADER_MAX_SIZE);
  3533. else
  3534. val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(
  3535. vpath->max_mtu);
  3536. }
  3537. writeq(val64, &vp_reg->rxmac_vcfg0);
  3538. val64 = readq(&vp_reg->rxmac_vcfg1);
  3539. val64 &= ~(VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE(0x3) |
  3540. VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE);
  3541. if (hldev->config.rth_it_type ==
  3542. VXGE_HW_RTH_IT_TYPE_MULTI_IT) {
  3543. val64 |= VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE(
  3544. 0x2) |
  3545. VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE;
  3546. }
  3547. writeq(val64, &vp_reg->rxmac_vcfg1);
  3548. }
  3549. return VXGE_HW_OK;
  3550. }
  3551. /*
  3552. * __vxge_hw_vpath_tim_configure
  3553. * This routine configures the tim registers of virtual path using the config
  3554. * passed
  3555. */
  3556. static enum vxge_hw_status
  3557. __vxge_hw_vpath_tim_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3558. {
  3559. u64 val64;
  3560. struct __vxge_hw_virtualpath *vpath;
  3561. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3562. struct vxge_hw_vp_config *config;
  3563. vpath = &hldev->virtual_paths[vp_id];
  3564. vp_reg = vpath->vp_reg;
  3565. config = vpath->vp_config;
  3566. writeq(0, &vp_reg->tim_dest_addr);
  3567. writeq(0, &vp_reg->tim_vpath_map);
  3568. writeq(0, &vp_reg->tim_bitmap);
  3569. writeq(0, &vp_reg->tim_remap);
  3570. if (config->ring.enable == VXGE_HW_RING_ENABLE)
  3571. writeq(VXGE_HW_TIM_RING_ASSN_INT_NUM(
  3572. (vp_id * VXGE_HW_MAX_INTR_PER_VP) +
  3573. VXGE_HW_VPATH_INTR_RX), &vp_reg->tim_ring_assn);
  3574. val64 = readq(&vp_reg->tim_pci_cfg);
  3575. val64 |= VXGE_HW_TIM_PCI_CFG_ADD_PAD;
  3576. writeq(val64, &vp_reg->tim_pci_cfg);
  3577. if (config->fifo.enable == VXGE_HW_FIFO_ENABLE) {
  3578. val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]);
  3579. if (config->tti.btimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3580. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3581. 0x3ffffff);
  3582. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3583. config->tti.btimer_val);
  3584. }
  3585. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN;
  3586. if (config->tti.timer_ac_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3587. if (config->tti.timer_ac_en)
  3588. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3589. else
  3590. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3591. }
  3592. if (config->tti.timer_ci_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3593. if (config->tti.timer_ci_en)
  3594. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3595. else
  3596. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3597. }
  3598. if (config->tti.urange_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3599. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f);
  3600. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(
  3601. config->tti.urange_a);
  3602. }
  3603. if (config->tti.urange_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3604. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f);
  3605. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(
  3606. config->tti.urange_b);
  3607. }
  3608. if (config->tti.urange_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3609. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f);
  3610. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(
  3611. config->tti.urange_c);
  3612. }
  3613. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]);
  3614. vpath->tim_tti_cfg1_saved = val64;
  3615. val64 = readq(&vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_TX]);
  3616. if (config->tti.uec_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3617. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff);
  3618. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(
  3619. config->tti.uec_a);
  3620. }
  3621. if (config->tti.uec_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3622. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff);
  3623. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(
  3624. config->tti.uec_b);
  3625. }
  3626. if (config->tti.uec_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3627. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff);
  3628. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(
  3629. config->tti.uec_c);
  3630. }
  3631. if (config->tti.uec_d != VXGE_HW_USE_FLASH_DEFAULT) {
  3632. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff);
  3633. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(
  3634. config->tti.uec_d);
  3635. }
  3636. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_TX]);
  3637. val64 = readq(&vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_TX]);
  3638. if (config->tti.timer_ri_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3639. if (config->tti.timer_ri_en)
  3640. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3641. else
  3642. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3643. }
  3644. if (config->tti.rtimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3645. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3646. 0x3ffffff);
  3647. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3648. config->tti.rtimer_val);
  3649. }
  3650. if (config->tti.util_sel != VXGE_HW_USE_FLASH_DEFAULT) {
  3651. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f);
  3652. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(vp_id);
  3653. }
  3654. if (config->tti.ltimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3655. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3656. 0x3ffffff);
  3657. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3658. config->tti.ltimer_val);
  3659. }
  3660. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_TX]);
  3661. vpath->tim_tti_cfg3_saved = val64;
  3662. }
  3663. if (config->ring.enable == VXGE_HW_RING_ENABLE) {
  3664. val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_RX]);
  3665. if (config->rti.btimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3666. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3667. 0x3ffffff);
  3668. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3669. config->rti.btimer_val);
  3670. }
  3671. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN;
  3672. if (config->rti.timer_ac_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3673. if (config->rti.timer_ac_en)
  3674. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3675. else
  3676. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3677. }
  3678. if (config->rti.timer_ci_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3679. if (config->rti.timer_ci_en)
  3680. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3681. else
  3682. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3683. }
  3684. if (config->rti.urange_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3685. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f);
  3686. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(
  3687. config->rti.urange_a);
  3688. }
  3689. if (config->rti.urange_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3690. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f);
  3691. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(
  3692. config->rti.urange_b);
  3693. }
  3694. if (config->rti.urange_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3695. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f);
  3696. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(
  3697. config->rti.urange_c);
  3698. }
  3699. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_RX]);
  3700. vpath->tim_rti_cfg1_saved = val64;
  3701. val64 = readq(&vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_RX]);
  3702. if (config->rti.uec_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3703. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff);
  3704. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(
  3705. config->rti.uec_a);
  3706. }
  3707. if (config->rti.uec_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3708. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff);
  3709. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(
  3710. config->rti.uec_b);
  3711. }
  3712. if (config->rti.uec_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3713. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff);
  3714. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(
  3715. config->rti.uec_c);
  3716. }
  3717. if (config->rti.uec_d != VXGE_HW_USE_FLASH_DEFAULT) {
  3718. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff);
  3719. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(
  3720. config->rti.uec_d);
  3721. }
  3722. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_RX]);
  3723. val64 = readq(&vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_RX]);
  3724. if (config->rti.timer_ri_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3725. if (config->rti.timer_ri_en)
  3726. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3727. else
  3728. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3729. }
  3730. if (config->rti.rtimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3731. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3732. 0x3ffffff);
  3733. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3734. config->rti.rtimer_val);
  3735. }
  3736. if (config->rti.util_sel != VXGE_HW_USE_FLASH_DEFAULT) {
  3737. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f);
  3738. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(vp_id);
  3739. }
  3740. if (config->rti.ltimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3741. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3742. 0x3ffffff);
  3743. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3744. config->rti.ltimer_val);
  3745. }
  3746. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_RX]);
  3747. vpath->tim_rti_cfg3_saved = val64;
  3748. }
  3749. val64 = 0;
  3750. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_EINTA]);
  3751. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_EINTA]);
  3752. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_EINTA]);
  3753. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_BMAP]);
  3754. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_BMAP]);
  3755. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_BMAP]);
  3756. val64 = VXGE_HW_TIM_WRKLD_CLC_WRKLD_EVAL_PRD(150);
  3757. val64 |= VXGE_HW_TIM_WRKLD_CLC_WRKLD_EVAL_DIV(0);
  3758. val64 |= VXGE_HW_TIM_WRKLD_CLC_CNT_RX_TX(3);
  3759. writeq(val64, &vp_reg->tim_wrkld_clc);
  3760. return VXGE_HW_OK;
  3761. }
  3762. /*
  3763. * __vxge_hw_vpath_initialize
  3764. * This routine is the final phase of init which initializes the
  3765. * registers of the vpath using the configuration passed.
  3766. */
  3767. static enum vxge_hw_status
  3768. __vxge_hw_vpath_initialize(struct __vxge_hw_device *hldev, u32 vp_id)
  3769. {
  3770. u64 val64;
  3771. u32 val32;
  3772. enum vxge_hw_status status = VXGE_HW_OK;
  3773. struct __vxge_hw_virtualpath *vpath;
  3774. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3775. vpath = &hldev->virtual_paths[vp_id];
  3776. if (!(hldev->vpath_assignments & vxge_mBIT(vp_id))) {
  3777. status = VXGE_HW_ERR_VPATH_NOT_AVAILABLE;
  3778. goto exit;
  3779. }
  3780. vp_reg = vpath->vp_reg;
  3781. status = __vxge_hw_vpath_swapper_set(vpath->vp_reg);
  3782. if (status != VXGE_HW_OK)
  3783. goto exit;
  3784. status = __vxge_hw_vpath_mac_configure(hldev, vp_id);
  3785. if (status != VXGE_HW_OK)
  3786. goto exit;
  3787. status = __vxge_hw_vpath_kdfc_configure(hldev, vp_id);
  3788. if (status != VXGE_HW_OK)
  3789. goto exit;
  3790. status = __vxge_hw_vpath_tim_configure(hldev, vp_id);
  3791. if (status != VXGE_HW_OK)
  3792. goto exit;
  3793. val64 = readq(&vp_reg->rtdma_rd_optimization_ctrl);
  3794. /* Get MRRS value from device control */
  3795. status = __vxge_hw_vpath_pci_read(vpath, 1, 0x78, &val32);
  3796. if (status == VXGE_HW_OK) {
  3797. val32 = (val32 & VXGE_HW_PCI_EXP_DEVCTL_READRQ) >> 12;
  3798. val64 &=
  3799. ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(7));
  3800. val64 |=
  3801. VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(val32);
  3802. val64 |= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_WAIT_FOR_SPACE;
  3803. }
  3804. val64 &= ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY(7));
  3805. val64 |=
  3806. VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY(
  3807. VXGE_HW_MAX_PAYLOAD_SIZE_512);
  3808. val64 |= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY_EN;
  3809. writeq(val64, &vp_reg->rtdma_rd_optimization_ctrl);
  3810. exit:
  3811. return status;
  3812. }
  3813. /*
  3814. * __vxge_hw_vp_terminate - Terminate Virtual Path structure
  3815. * This routine closes all channels it opened and freeup memory
  3816. */
  3817. static void __vxge_hw_vp_terminate(struct __vxge_hw_device *hldev, u32 vp_id)
  3818. {
  3819. struct __vxge_hw_virtualpath *vpath;
  3820. vpath = &hldev->virtual_paths[vp_id];
  3821. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN)
  3822. goto exit;
  3823. VXGE_HW_DEVICE_TIM_INT_MASK_RESET(vpath->hldev->tim_int_mask0,
  3824. vpath->hldev->tim_int_mask1, vpath->vp_id);
  3825. hldev->stats.hw_dev_info_stats.vpath_info[vpath->vp_id] = NULL;
  3826. /* If the whole struct __vxge_hw_virtualpath is zeroed, nothing will
  3827. * work after the interface is brought down.
  3828. */
  3829. spin_lock(&vpath->lock);
  3830. vpath->vp_open = VXGE_HW_VP_NOT_OPEN;
  3831. spin_unlock(&vpath->lock);
  3832. vpath->vpmgmt_reg = NULL;
  3833. vpath->nofl_db = NULL;
  3834. vpath->max_mtu = 0;
  3835. vpath->vsport_number = 0;
  3836. vpath->max_kdfc_db = 0;
  3837. vpath->max_nofl_db = 0;
  3838. vpath->ringh = NULL;
  3839. vpath->fifoh = NULL;
  3840. memset(&vpath->vpath_handles, 0, sizeof(struct list_head));
  3841. vpath->stats_block = NULL;
  3842. vpath->hw_stats = NULL;
  3843. vpath->hw_stats_sav = NULL;
  3844. vpath->sw_stats = NULL;
  3845. exit:
  3846. return;
  3847. }
  3848. /*
  3849. * __vxge_hw_vp_initialize - Initialize Virtual Path structure
  3850. * This routine is the initial phase of init which resets the vpath and
  3851. * initializes the software support structures.
  3852. */
  3853. static enum vxge_hw_status
  3854. __vxge_hw_vp_initialize(struct __vxge_hw_device *hldev, u32 vp_id,
  3855. struct vxge_hw_vp_config *config)
  3856. {
  3857. struct __vxge_hw_virtualpath *vpath;
  3858. enum vxge_hw_status status = VXGE_HW_OK;
  3859. if (!(hldev->vpath_assignments & vxge_mBIT(vp_id))) {
  3860. status = VXGE_HW_ERR_VPATH_NOT_AVAILABLE;
  3861. goto exit;
  3862. }
  3863. vpath = &hldev->virtual_paths[vp_id];
  3864. spin_lock_init(&vpath->lock);
  3865. vpath->vp_id = vp_id;
  3866. vpath->vp_open = VXGE_HW_VP_OPEN;
  3867. vpath->hldev = hldev;
  3868. vpath->vp_config = config;
  3869. vpath->vp_reg = hldev->vpath_reg[vp_id];
  3870. vpath->vpmgmt_reg = hldev->vpmgmt_reg[vp_id];
  3871. __vxge_hw_vpath_reset(hldev, vp_id);
  3872. status = __vxge_hw_vpath_reset_check(vpath);
  3873. if (status != VXGE_HW_OK) {
  3874. memset(vpath, 0, sizeof(struct __vxge_hw_virtualpath));
  3875. goto exit;
  3876. }
  3877. status = __vxge_hw_vpath_mgmt_read(hldev, vpath);
  3878. if (status != VXGE_HW_OK) {
  3879. memset(vpath, 0, sizeof(struct __vxge_hw_virtualpath));
  3880. goto exit;
  3881. }
  3882. INIT_LIST_HEAD(&vpath->vpath_handles);
  3883. vpath->sw_stats = &hldev->stats.sw_dev_info_stats.vpath_info[vp_id];
  3884. VXGE_HW_DEVICE_TIM_INT_MASK_SET(hldev->tim_int_mask0,
  3885. hldev->tim_int_mask1, vp_id);
  3886. status = __vxge_hw_vpath_initialize(hldev, vp_id);
  3887. if (status != VXGE_HW_OK)
  3888. __vxge_hw_vp_terminate(hldev, vp_id);
  3889. exit:
  3890. return status;
  3891. }
  3892. /*
  3893. * vxge_hw_vpath_mtu_set - Set MTU.
  3894. * Set new MTU value. Example, to use jumbo frames:
  3895. * vxge_hw_vpath_mtu_set(my_device, 9600);
  3896. */
  3897. enum vxge_hw_status
  3898. vxge_hw_vpath_mtu_set(struct __vxge_hw_vpath_handle *vp, u32 new_mtu)
  3899. {
  3900. u64 val64;
  3901. enum vxge_hw_status status = VXGE_HW_OK;
  3902. struct __vxge_hw_virtualpath *vpath;
  3903. if (vp == NULL) {
  3904. status = VXGE_HW_ERR_INVALID_HANDLE;
  3905. goto exit;
  3906. }
  3907. vpath = vp->vpath;
  3908. new_mtu += VXGE_HW_MAC_HEADER_MAX_SIZE;
  3909. if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > vpath->max_mtu))
  3910. status = VXGE_HW_ERR_INVALID_MTU_SIZE;
  3911. val64 = readq(&vpath->vp_reg->rxmac_vcfg0);
  3912. val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
  3913. val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(new_mtu);
  3914. writeq(val64, &vpath->vp_reg->rxmac_vcfg0);
  3915. vpath->vp_config->mtu = new_mtu - VXGE_HW_MAC_HEADER_MAX_SIZE;
  3916. exit:
  3917. return status;
  3918. }
  3919. /*
  3920. * vxge_hw_vpath_stats_enable - Enable vpath h/wstatistics.
  3921. * Enable the DMA vpath statistics. The function is to be called to re-enable
  3922. * the adapter to update stats into the host memory
  3923. */
  3924. static enum vxge_hw_status
  3925. vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle *vp)
  3926. {
  3927. enum vxge_hw_status status = VXGE_HW_OK;
  3928. struct __vxge_hw_virtualpath *vpath;
  3929. vpath = vp->vpath;
  3930. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  3931. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  3932. goto exit;
  3933. }
  3934. memcpy(vpath->hw_stats_sav, vpath->hw_stats,
  3935. sizeof(struct vxge_hw_vpath_stats_hw_info));
  3936. status = __vxge_hw_vpath_stats_get(vpath, vpath->hw_stats);
  3937. exit:
  3938. return status;
  3939. }
  3940. /*
  3941. * __vxge_hw_blockpool_block_allocate - Allocates a block from block pool
  3942. * This function allocates a block from block pool or from the system
  3943. */
  3944. static struct __vxge_hw_blockpool_entry *
  3945. __vxge_hw_blockpool_block_allocate(struct __vxge_hw_device *devh, u32 size)
  3946. {
  3947. struct __vxge_hw_blockpool_entry *entry = NULL;
  3948. struct __vxge_hw_blockpool *blockpool;
  3949. blockpool = &devh->block_pool;
  3950. if (size == blockpool->block_size) {
  3951. if (!list_empty(&blockpool->free_block_list))
  3952. entry = (struct __vxge_hw_blockpool_entry *)
  3953. list_first_entry(&blockpool->free_block_list,
  3954. struct __vxge_hw_blockpool_entry,
  3955. item);
  3956. if (entry != NULL) {
  3957. list_del(&entry->item);
  3958. blockpool->pool_size--;
  3959. }
  3960. }
  3961. if (entry != NULL)
  3962. __vxge_hw_blockpool_blocks_add(blockpool);
  3963. return entry;
  3964. }
  3965. /*
  3966. * vxge_hw_vpath_open - Open a virtual path on a given adapter
  3967. * This function is used to open access to virtual path of an
  3968. * adapter for offload, GRO operations. This function returns
  3969. * synchronously.
  3970. */
  3971. enum vxge_hw_status
  3972. vxge_hw_vpath_open(struct __vxge_hw_device *hldev,
  3973. struct vxge_hw_vpath_attr *attr,
  3974. struct __vxge_hw_vpath_handle **vpath_handle)
  3975. {
  3976. struct __vxge_hw_virtualpath *vpath;
  3977. struct __vxge_hw_vpath_handle *vp;
  3978. enum vxge_hw_status status;
  3979. vpath = &hldev->virtual_paths[attr->vp_id];
  3980. if (vpath->vp_open == VXGE_HW_VP_OPEN) {
  3981. status = VXGE_HW_ERR_INVALID_STATE;
  3982. goto vpath_open_exit1;
  3983. }
  3984. status = __vxge_hw_vp_initialize(hldev, attr->vp_id,
  3985. &hldev->config.vp_config[attr->vp_id]);
  3986. if (status != VXGE_HW_OK)
  3987. goto vpath_open_exit1;
  3988. vp = vzalloc(sizeof(struct __vxge_hw_vpath_handle));
  3989. if (vp == NULL) {
  3990. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  3991. goto vpath_open_exit2;
  3992. }
  3993. vp->vpath = vpath;
  3994. if (vpath->vp_config->fifo.enable == VXGE_HW_FIFO_ENABLE) {
  3995. status = __vxge_hw_fifo_create(vp, &attr->fifo_attr);
  3996. if (status != VXGE_HW_OK)
  3997. goto vpath_open_exit6;
  3998. }
  3999. if (vpath->vp_config->ring.enable == VXGE_HW_RING_ENABLE) {
  4000. status = __vxge_hw_ring_create(vp, &attr->ring_attr);
  4001. if (status != VXGE_HW_OK)
  4002. goto vpath_open_exit7;
  4003. __vxge_hw_vpath_prc_configure(hldev, attr->vp_id);
  4004. }
  4005. vpath->fifoh->tx_intr_num =
  4006. (attr->vp_id * VXGE_HW_MAX_INTR_PER_VP) +
  4007. VXGE_HW_VPATH_INTR_TX;
  4008. vpath->stats_block = __vxge_hw_blockpool_block_allocate(hldev,
  4009. VXGE_HW_BLOCK_SIZE);
  4010. if (vpath->stats_block == NULL) {
  4011. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  4012. goto vpath_open_exit8;
  4013. }
  4014. vpath->hw_stats = vpath->stats_block->memblock;
  4015. memset(vpath->hw_stats, 0,
  4016. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4017. hldev->stats.hw_dev_info_stats.vpath_info[attr->vp_id] =
  4018. vpath->hw_stats;
  4019. vpath->hw_stats_sav =
  4020. &hldev->stats.hw_dev_info_stats.vpath_info_sav[attr->vp_id];
  4021. memset(vpath->hw_stats_sav, 0,
  4022. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4023. writeq(vpath->stats_block->dma_addr, &vpath->vp_reg->stats_cfg);
  4024. status = vxge_hw_vpath_stats_enable(vp);
  4025. if (status != VXGE_HW_OK)
  4026. goto vpath_open_exit8;
  4027. list_add(&vp->item, &vpath->vpath_handles);
  4028. hldev->vpaths_deployed |= vxge_mBIT(vpath->vp_id);
  4029. *vpath_handle = vp;
  4030. attr->fifo_attr.userdata = vpath->fifoh;
  4031. attr->ring_attr.userdata = vpath->ringh;
  4032. return VXGE_HW_OK;
  4033. vpath_open_exit8:
  4034. if (vpath->ringh != NULL)
  4035. __vxge_hw_ring_delete(vp);
  4036. vpath_open_exit7:
  4037. if (vpath->fifoh != NULL)
  4038. __vxge_hw_fifo_delete(vp);
  4039. vpath_open_exit6:
  4040. vfree(vp);
  4041. vpath_open_exit2:
  4042. __vxge_hw_vp_terminate(hldev, attr->vp_id);
  4043. vpath_open_exit1:
  4044. return status;
  4045. }
  4046. /**
  4047. * vxge_hw_vpath_rx_doorbell_post - Close the handle got from previous vpath
  4048. * (vpath) open
  4049. * @vp: Handle got from previous vpath open
  4050. *
  4051. * This function is used to close access to virtual path opened
  4052. * earlier.
  4053. */
  4054. void vxge_hw_vpath_rx_doorbell_init(struct __vxge_hw_vpath_handle *vp)
  4055. {
  4056. struct __vxge_hw_virtualpath *vpath = vp->vpath;
  4057. struct __vxge_hw_ring *ring = vpath->ringh;
  4058. struct vxgedev *vdev = netdev_priv(vpath->hldev->ndev);
  4059. u64 new_count, val64, val164;
  4060. if (vdev->titan1) {
  4061. new_count = readq(&vpath->vp_reg->rxdmem_size);
  4062. new_count &= 0x1fff;
  4063. } else
  4064. new_count = ring->config->ring_blocks * VXGE_HW_BLOCK_SIZE / 8;
  4065. val164 = VXGE_HW_RXDMEM_SIZE_PRC_RXDMEM_SIZE(new_count);
  4066. writeq(VXGE_HW_PRC_RXD_DOORBELL_NEW_QW_CNT(val164),
  4067. &vpath->vp_reg->prc_rxd_doorbell);
  4068. readl(&vpath->vp_reg->prc_rxd_doorbell);
  4069. val164 /= 2;
  4070. val64 = readq(&vpath->vp_reg->prc_cfg6);
  4071. val64 = VXGE_HW_PRC_CFG6_RXD_SPAT(val64);
  4072. val64 &= 0x1ff;
  4073. /*
  4074. * Each RxD is of 4 qwords
  4075. */
  4076. new_count -= (val64 + 1);
  4077. val64 = min(val164, new_count) / 4;
  4078. ring->rxds_limit = min(ring->rxds_limit, val64);
  4079. if (ring->rxds_limit < 4)
  4080. ring->rxds_limit = 4;
  4081. }
  4082. /*
  4083. * __vxge_hw_blockpool_block_free - Frees a block from block pool
  4084. * @devh: Hal device
  4085. * @entry: Entry of block to be freed
  4086. *
  4087. * This function frees a block from block pool
  4088. */
  4089. static void
  4090. __vxge_hw_blockpool_block_free(struct __vxge_hw_device *devh,
  4091. struct __vxge_hw_blockpool_entry *entry)
  4092. {
  4093. struct __vxge_hw_blockpool *blockpool;
  4094. blockpool = &devh->block_pool;
  4095. if (entry->length == blockpool->block_size) {
  4096. list_add(&entry->item, &blockpool->free_block_list);
  4097. blockpool->pool_size++;
  4098. }
  4099. __vxge_hw_blockpool_blocks_remove(blockpool);
  4100. }
  4101. /*
  4102. * vxge_hw_vpath_close - Close the handle got from previous vpath (vpath) open
  4103. * This function is used to close access to virtual path opened
  4104. * earlier.
  4105. */
  4106. enum vxge_hw_status vxge_hw_vpath_close(struct __vxge_hw_vpath_handle *vp)
  4107. {
  4108. struct __vxge_hw_virtualpath *vpath = NULL;
  4109. struct __vxge_hw_device *devh = NULL;
  4110. u32 vp_id = vp->vpath->vp_id;
  4111. u32 is_empty = TRUE;
  4112. enum vxge_hw_status status = VXGE_HW_OK;
  4113. vpath = vp->vpath;
  4114. devh = vpath->hldev;
  4115. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  4116. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  4117. goto vpath_close_exit;
  4118. }
  4119. list_del(&vp->item);
  4120. if (!list_empty(&vpath->vpath_handles)) {
  4121. list_add(&vp->item, &vpath->vpath_handles);
  4122. is_empty = FALSE;
  4123. }
  4124. if (!is_empty) {
  4125. status = VXGE_HW_FAIL;
  4126. goto vpath_close_exit;
  4127. }
  4128. devh->vpaths_deployed &= ~vxge_mBIT(vp_id);
  4129. if (vpath->ringh != NULL)
  4130. __vxge_hw_ring_delete(vp);
  4131. if (vpath->fifoh != NULL)
  4132. __vxge_hw_fifo_delete(vp);
  4133. if (vpath->stats_block != NULL)
  4134. __vxge_hw_blockpool_block_free(devh, vpath->stats_block);
  4135. vfree(vp);
  4136. __vxge_hw_vp_terminate(devh, vp_id);
  4137. vpath_close_exit:
  4138. return status;
  4139. }
  4140. /*
  4141. * vxge_hw_vpath_reset - Resets vpath
  4142. * This function is used to request a reset of vpath
  4143. */
  4144. enum vxge_hw_status vxge_hw_vpath_reset(struct __vxge_hw_vpath_handle *vp)
  4145. {
  4146. enum vxge_hw_status status;
  4147. u32 vp_id;
  4148. struct __vxge_hw_virtualpath *vpath = vp->vpath;
  4149. vp_id = vpath->vp_id;
  4150. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  4151. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  4152. goto exit;
  4153. }
  4154. status = __vxge_hw_vpath_reset(vpath->hldev, vp_id);
  4155. if (status == VXGE_HW_OK)
  4156. vpath->sw_stats->soft_reset_cnt++;
  4157. exit:
  4158. return status;
  4159. }
  4160. /*
  4161. * vxge_hw_vpath_recover_from_reset - Poll for reset complete and re-initialize.
  4162. * This function poll's for the vpath reset completion and re initializes
  4163. * the vpath.
  4164. */
  4165. enum vxge_hw_status
  4166. vxge_hw_vpath_recover_from_reset(struct __vxge_hw_vpath_handle *vp)
  4167. {
  4168. struct __vxge_hw_virtualpath *vpath = NULL;
  4169. enum vxge_hw_status status;
  4170. struct __vxge_hw_device *hldev;
  4171. u32 vp_id;
  4172. vp_id = vp->vpath->vp_id;
  4173. vpath = vp->vpath;
  4174. hldev = vpath->hldev;
  4175. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  4176. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  4177. goto exit;
  4178. }
  4179. status = __vxge_hw_vpath_reset_check(vpath);
  4180. if (status != VXGE_HW_OK)
  4181. goto exit;
  4182. status = __vxge_hw_vpath_sw_reset(hldev, vp_id);
  4183. if (status != VXGE_HW_OK)
  4184. goto exit;
  4185. status = __vxge_hw_vpath_initialize(hldev, vp_id);
  4186. if (status != VXGE_HW_OK)
  4187. goto exit;
  4188. if (vpath->ringh != NULL)
  4189. __vxge_hw_vpath_prc_configure(hldev, vp_id);
  4190. memset(vpath->hw_stats, 0,
  4191. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4192. memset(vpath->hw_stats_sav, 0,
  4193. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4194. writeq(vpath->stats_block->dma_addr,
  4195. &vpath->vp_reg->stats_cfg);
  4196. status = vxge_hw_vpath_stats_enable(vp);
  4197. exit:
  4198. return status;
  4199. }
  4200. /*
  4201. * vxge_hw_vpath_enable - Enable vpath.
  4202. * This routine clears the vpath reset thereby enabling a vpath
  4203. * to start forwarding frames and generating interrupts.
  4204. */
  4205. void
  4206. vxge_hw_vpath_enable(struct __vxge_hw_vpath_handle *vp)
  4207. {
  4208. struct __vxge_hw_device *hldev;
  4209. u64 val64;
  4210. hldev = vp->vpath->hldev;
  4211. val64 = VXGE_HW_CMN_RSTHDLR_CFG1_CLR_VPATH_RESET(
  4212. 1 << (16 - vp->vpath->vp_id));
  4213. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32),
  4214. &hldev->common_reg->cmn_rsthdlr_cfg1);
  4215. }